import {
  buildPiArgs
} from "./chunk-6SD6MC2B.js";
import {
  buildPiAuthEnv,
  validatePiRuntime
} from "./chunk-KUXEAQFY.js";
import {
  preparePiOnSandbox
} from "./chunk-CMOU2OFW.js";
import {
  PI_WRAPPER_PATH
} from "./chunk-OGA7KDQZ.js";
import {
  createPiTranslator
} from "./chunk-B6E6BVNK.js";
import {
  wrapPromptWithSystem
} from "./chunk-YE2RMJY7.js";
import {
  ApiError
} from "./chunk-EZYKRG4W.js";

// src/backends/pi/index.ts
function buildTurn(input) {
  const { agent, backendSessionId, promptText, toolResults } = input;
  if (toolResults.length > 0) {
    throw new ApiError(
      400,
      "invalid_request_error",
      "pi backend does not support user.custom_tool_result re-entry in v1"
    );
  }
  const wrappedPrompt = wrapPromptWithSystem(promptText, agent.system, agent.skills);
  const argv = buildPiArgs({ agent, backendSessionId, prompt: wrappedPrompt });
  const env = buildPiAuthEnv();
  return { argv, env, stdin: "" };
}
var piBackend = {
  name: "pi",
  wrapperPath: PI_WRAPPER_PATH,
  buildTurn,
  createTranslator: (opts) => createPiTranslator(opts),
  prepareOnSandbox: (name, provider) => preparePiOnSandbox(name, provider),
  validateRuntime: validatePiRuntime
};

export {
  piBackend
};
