import {
  prepareOpencodeOnSandbox
} from "./chunk-URNG7ZX2.js";
import {
  createOpencodeTranslator
} from "./chunk-ETWGCBIQ.js";
import {
  OPENCODE_WRAPPER_PATH
} from "./chunk-UY3VT3HQ.js";
import {
  buildOpencodeArgs
} from "./chunk-PDWLVL34.js";
import {
  buildOpencodeAuthEnv,
  validateOpencodeRuntime
} from "./chunk-YF3CVKQL.js";
import {
  buildOpencodeConfigEnv
} from "./chunk-V5DH3OAC.js";
import {
  wrapPromptWithSystem
} from "./chunk-YE2RMJY7.js";
import {
  ApiError
} from "./chunk-EZYKRG4W.js";

// src/backends/opencode/index.ts
function buildTurn(input) {
  const { agent, backendSessionId, promptText, toolResults } = input;
  if (toolResults.length > 0) {
    throw new ApiError(
      400,
      "invalid_request_error",
      "opencode backend does not support user.custom_tool_result re-entry in v1"
    );
  }
  const argv = buildOpencodeArgs({ agent, backendSessionId });
  const wrappedPrompt = wrapPromptWithSystem(promptText, agent.system, agent.skills);
  const env = {
    ...buildOpencodeAuthEnv(),
    ...buildOpencodeConfigEnv(agent)
  };
  return { argv, env, stdin: wrappedPrompt };
}
var opencodeBackend = {
  name: "opencode",
  wrapperPath: OPENCODE_WRAPPER_PATH,
  buildTurn,
  createTranslator: (opts) => createOpencodeTranslator(opts),
  prepareOnSandbox: (name, provider) => prepareOpencodeOnSandbox(name, provider),
  validateRuntime: validateOpencodeRuntime
};

export {
  opencodeBackend
};
