import {
  buildFactoryArgs
} from "./chunk-TPMZO6S2.js";
import {
  buildFactoryAuthEnv,
  validateFactoryRuntime
} from "./chunk-3NYWS7JW.js";
import {
  prepareFactoryOnSandbox
} from "./chunk-AQHYCRTO.js";
import {
  createFactoryTranslator
} from "./chunk-7TSTCMII.js";
import {
  FACTORY_WRAPPER_PATH
} from "./chunk-KJ2GJLPQ.js";
import {
  wrapPromptWithSystem
} from "./chunk-YE2RMJY7.js";
import {
  ApiError
} from "./chunk-EZYKRG4W.js";

// src/backends/factory/index.ts
function buildTurn(input) {
  const { agent, backendSessionId, promptText, toolResults } = input;
  if (toolResults.length > 0) {
    throw new ApiError(
      400,
      "invalid_request_error",
      "factory backend does not support user.custom_tool_result re-entry in v1"
    );
  }
  const argv = buildFactoryArgs({ agent, backendSessionId });
  const env = buildFactoryAuthEnv();
  const wrappedPrompt = wrapPromptWithSystem(promptText, agent.system, agent.skills);
  return { argv, env, stdin: wrappedPrompt };
}
var factoryBackend = {
  name: "factory",
  wrapperPath: FACTORY_WRAPPER_PATH,
  buildTurn,
  createTranslator: (opts) => createFactoryTranslator(opts),
  prepareOnSandbox: (name, provider) => prepareFactoryOnSandbox(name, provider),
  validateRuntime: validateFactoryRuntime
};

export {
  factoryBackend
};
