{"version":3,"file":"tools.cjs","names":["z"],"sources":["../../src/utils/tools.ts"],"sourcesContent":["import type { Anthropic } from \"@anthropic-ai/sdk\";\nimport * as z from \"zod/v4\";\nimport { AnthropicToolChoice } from \"../types.js\";\n\nconst TOP_LEVEL_SCHEMA_COMPOSITION_KEYS = [\"oneOf\", \"anyOf\", \"allOf\"] as const;\n\n/**\n * Returns root-level JSON Schema composition keys that Anthropic rejects for\n * custom tool input schemas. Nested composition keys remain supported.\n */\nexport function getTopLevelSchemaCompositionKeys(\n  tool: Anthropic.Messages.Tool\n): string[] {\n  if (typeof tool.input_schema !== \"object\" || tool.input_schema === null) {\n    return [];\n  }\n  return TOP_LEVEL_SCHEMA_COMPOSITION_KEYS.filter((key) =>\n    Object.prototype.hasOwnProperty.call(tool.input_schema, key)\n  );\n}\n\nexport function handleToolChoice(\n  toolChoice?: AnthropicToolChoice\n):\n  | Anthropic.Messages.ToolChoiceAuto\n  | Anthropic.Messages.ToolChoiceAny\n  | Anthropic.Messages.ToolChoiceTool\n  | Anthropic.Messages.ToolChoiceNone\n  | undefined {\n  if (!toolChoice) {\n    return undefined;\n  } else if (toolChoice === \"any\" || toolChoice === \"required\") {\n    // \"required\" is OpenAI-style, map to Anthropic's \"any\" which forces tool use\n    return {\n      type: \"any\",\n    };\n  } else if (toolChoice === \"auto\") {\n    return {\n      type: \"auto\",\n    };\n  } else if (toolChoice === \"none\") {\n    return {\n      type: \"none\",\n    };\n  } else if (typeof toolChoice === \"string\") {\n    return {\n      type: \"tool\",\n      name: toolChoice,\n    };\n  } else {\n    return toolChoice;\n  }\n}\n\nexport const AnthropicToolExtrasSchema = z.object({\n  cache_control: z\n    .custom<Anthropic.Messages.CacheControlEphemeral>()\n    .optional()\n    .nullable(),\n  defer_loading: z.boolean().optional(),\n  input_examples: z.array(z.unknown()).optional(),\n  allowed_callers: z.array(z.unknown()).optional(),\n  strict: z.boolean().optional(),\n});\n\n/**\n * Mapping of Anthropic tool types to their required beta feature flags.\n *\n * This constant defines which beta header is needed for specific tool types\n * when making requests to the Anthropic API. Beta features are experimental\n * capabilities that may change or be removed.\n */\nexport const ANTHROPIC_TOOL_BETAS: Record<string, string> = {\n  tool_search_tool_regex_20251119: \"advanced-tool-use-2025-11-20\",\n  tool_search_tool_bm25_20251119: \"advanced-tool-use-2025-11-20\",\n  memory_20250818: \"context-management-2025-06-27\",\n  web_fetch_20250910: \"web-fetch-2025-09-10\",\n  code_execution_20250825: \"code-execution-2025-08-25\",\n  computer_20251124: \"computer-use-2025-11-24\",\n  computer_20250124: \"computer-use-2025-01-24\",\n  mcp_toolset: \"mcp-client-2025-11-20\",\n};\n"],"mappings":";;;;AAIA,MAAM,oCAAoC;CAAC;CAAS;CAAS;AAAO;;;;;AAMpE,SAAgB,iCACd,MACU;CACV,IAAI,OAAO,KAAK,iBAAiB,YAAY,KAAK,iBAAiB,MACjE,OAAO,CAAC;CAEV,OAAO,kCAAkC,QAAQ,QAC/C,OAAO,UAAU,eAAe,KAAK,KAAK,cAAc,GAAG,CAC7D;AACF;AAEA,SAAgB,iBACd,YAMY;CACZ,IAAI,CAAC,YACH;MACK,IAAI,eAAe,SAAS,eAAe,YAEhD,OAAO,EACL,MAAM,MACR;MACK,IAAI,eAAe,QACxB,OAAO,EACL,MAAM,OACR;MACK,IAAI,eAAe,QACxB,OAAO,EACL,MAAM,OACR;MACK,IAAI,OAAO,eAAe,UAC/B,OAAO;EACL,MAAM;EACN,MAAM;CACR;MAEA,OAAO;AAEX;AAEA,MAAa,4BAA4BA,OAAE,OAAO;CAChD,eAAeA,OACZ,OAAiD,CAAC,CAClD,SAAS,CAAC,CACV,SAAS;CACZ,eAAeA,OAAE,QAAQ,CAAC,CAAC,SAAS;CACpC,gBAAgBA,OAAE,MAAMA,OAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;CAC9C,iBAAiBA,OAAE,MAAMA,OAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;CAC/C,QAAQA,OAAE,QAAQ,CAAC,CAAC,SAAS;AAC/B,CAAC;;;;;;;;AASD,MAAa,uBAA+C;CAC1D,iCAAiC;CACjC,gCAAgC;CAChC,iBAAiB;CACjB,oBAAoB;CACpB,yBAAyB;CACzB,mBAAmB;CACnB,mBAAmB;CACnB,aAAa;AACf"}