import { createSessionFsAdapter } from "./sessionFsProvider.js";
function convertMcpCallToolResult(callResult) {
  const textParts = [];
  const binaryResults = [];
  for (const block of callResult.content) {
    switch (block.type) {
      case "text":
        if (typeof block.text === "string") {
          textParts.push(block.text);
        }
        break;
      case "image":
        if (typeof block.data === "string" && block.data && typeof block.mimeType === "string") {
          binaryResults.push({
            data: block.data,
            mimeType: block.mimeType,
            type: "image"
          });
        }
        break;
      case "resource": {
        if (block.resource?.text) {
          textParts.push(block.resource.text);
        }
        if (block.resource?.blob) {
          const mimeType = block.resource.mimeType;
          binaryResults.push({
            data: block.resource.blob,
            mimeType: typeof mimeType === "string" && mimeType ? mimeType : "application/octet-stream",
            type: "resource",
            description: block.resource.uri
          });
        }
        break;
      }
    }
  }
  return {
    textResultForLlm: textParts.join("\n"),
    resultType: callResult.isError ? "failure" : "success",
    ...binaryResults.length > 0 ? { binaryResultsForLlm: binaryResults } : {}
  };
}
function defineTool(name, config) {
  return { name, ...config };
}
const SYSTEM_PROMPT_SECTIONS = {
  identity: { description: "Agent identity preamble and mode statement" },
  tone: { description: "Response style, conciseness rules, output formatting preferences" },
  tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
  environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
  code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
  guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
  safety: { description: "Environment limitations, prohibited actions, security policies" },
  tool_instructions: { description: "Per-tool usage instructions" },
  custom_instructions: { description: "Repository and organization custom instructions" },
  last_instructions: {
    description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
  }
};
const approveAll = () => ({ kind: "approve-once" });
const defaultJoinSessionPermissionHandler = () => ({
  kind: "no-result"
});
export {
  SYSTEM_PROMPT_SECTIONS,
  approveAll,
  convertMcpCallToolResult,
  createSessionFsAdapter,
  defaultJoinSessionPermissionHandler,
  defineTool
};
