@bastani/pi-ai 0.9.38-alpha.6 → 0.9.38-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +5 -5
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +32 -23
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/bedrock-converse-stream.js +14 -16
  7. package/dist/api/bedrock-converse-stream.js.map +1 -1
  8. package/dist/api/google-shared.js +1 -1
  9. package/dist/api/google-shared.js.map +1 -1
  10. package/dist/api/openai-codex-responses.d.ts +1 -0
  11. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  12. package/dist/api/openai-codex-responses.js +2 -1
  13. package/dist/api/openai-codex-responses.js.map +1 -1
  14. package/dist/api/openai-completions.js +1 -1
  15. package/dist/api/openai-completions.js.map +1 -1
  16. package/dist/api/openai-responses-shared.js +1 -1
  17. package/dist/api/openai-responses-shared.js.map +1 -1
  18. package/dist/api/transform-messages.d.ts +16 -1
  19. package/dist/api/transform-messages.d.ts.map +1 -1
  20. package/dist/api/transform-messages.js +28 -15
  21. package/dist/api/transform-messages.js.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/providers/compat-schema.d.ts +156 -0
  27. package/dist/providers/compat-schema.d.ts.map +1 -1
  28. package/dist/providers/compat-schema.js +4 -2
  29. package/dist/providers/compat-schema.js.map +1 -1
  30. package/dist/providers/data/.manifest.json +1 -1
  31. package/dist/providers/data/anthropic.json +1 -1
  32. package/dist/providers/data/opencode.json +1 -1
  33. package/dist/providers/data/openrouter.json +1 -1
  34. package/dist/providers/data/radius.json +1 -1
  35. package/dist/providers/data/together.json +1 -1
  36. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  37. package/dist/providers/model-schema.d.ts.map +1 -1
  38. package/dist/providers/model-schema.js +4 -2
  39. package/dist/providers/model-schema.js.map +1 -1
  40. package/dist/utils/retry.d.ts.map +1 -1
  41. package/dist/utils/retry.js +7 -1
  42. package/dist/utils/retry.js.map +1 -1
  43. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"transform-messages.js","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAaxD,MAAM,iCAAiC,GAAG,gDAAgD,CAAC;AAC3F,MAAM,iCAAiC,GAAG,qDAAqD,CAAC;AAChG,MAAM,6BAA6B,GAAG,2DAA2D,CAAC;AAElG;;;;;;;;;;;;;;GAcG;AACH,SAAS,6BAA6B,CAAmB,KAAkB;IAC1E,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB;QAAE,OAAO,KAAK,CAAC;IACrD,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,OAAO,MAAM,EAAE,6BAA6B,KAAK,IAAI,CAAC;AACvD,CAAC;AAED,+FAA+F;AAC/F,0EAA0E;AAC1E,SAAS,4BAA4B,CACpC,OAAiB,EACjB,WAAmB;IAEnB,MAAM,MAAM,GAAoD,EAAE,CAAC;IACnE,IAAI,sBAAsB,GAAG,KAAK,CAAC;IAEnC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5B,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,sBAAsB,GAAG,IAAI,CAAC;YAC9B,SAAS;QACV,CAAC;QAED,MAAM,IAAI,GAAG,KAAsC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,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C,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACtC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACjC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChC,qFAAqF;YACrF,qBAAqB,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;IAED,+EAA+E;IAC/E,qBAAqB,EAAE,CAAC;IAExB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { normalizeProviderId } from \"../provider-id.ts\";\nimport type {\n\tAnthropicMessagesCompat,\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tModel,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.ts\";\n\nconst NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nconst NON_DOCUMENT_USER_PLACEHOLDER = \"(document omitted: model does not support document input)\";\n\n/**\n * Whether the target model's API adjudicates thinking-block model binding itself.\n *\n * Anthropic's preserved-thinking rules make the API, not the client, the authority on which\n * thinking blocks a model may read: \"Pass blocks back unchanged. Send every assistant turn\n * exactly as you received it, thinking blocks included, and let the API decide which blocks the\n * model can use\", and \"A block that fails the model check is always dropped\" before the prompt\n * reaches the model, unbilled.\n * https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking\n *\n * Flattening those blocks into visible text client-side is both lossy (a newer model that is\n * allowed to read them loses the reasoning) and destabilizing (it rewrites the conversation\n * prefix that later thinking-block signatures are bound to). Models whose generated metadata\n * sets this flag replay foreign signed blocks unchanged instead.\n */\nfunction delegatesThinkingModelBinding<TApi extends Api>(model: Model<TApi>): boolean {\n\tif (model.api !== \"anthropic-messages\") return false;\n\tconst compat = model.compat as AnthropicMessagesCompat | undefined;\n\treturn compat?.delegatesThinkingModelBinding === true;\n}\n\n// Preserves the caller's block union minus images, so a user message keeps its document blocks\n// while a tool result — which cannot carry one — keeps its narrower type.\nfunction replaceImagesWithPlaceholder<TBlock extends { type: string }>(\n\tcontent: TBlock[],\n\tplaceholder: string,\n): (Exclude<TBlock, ImageContent> | TextContent)[] {\n\tconst result: (Exclude<TBlock, ImageContent> | TextContent)[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\") {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst kept = block as Exclude<TBlock, ImageContent>;\n\t\tresult.push(kept);\n\t\tpreviousWasPlaceholder = kept.type === \"text\" && (kept as unknown as TextContent).text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction downgradeUnsupportedImages<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tif (model.input.includes(\"image\")) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg): Message => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\treturn {\n\t\t\t\t...msg,\n\t\t\t\tcontent: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER),\n\t\t\t};\n\t\t}\n\n\t\tif (msg.role === \"toolResult\") {\n\t\t\treturn {\n\t\t\t\t...msg,\n\t\t\t\tcontent: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER),\n\t\t\t};\n\t\t}\n\n\t\treturn msg;\n\t});\n}\n\n/**\n * Replace document blocks with a visible placeholder for models that cannot receive one.\n *\n * Mirrors the image downgrade: only the Anthropic Messages and Amazon Bedrock Converse paths can\n * serialize a document, so every other provider — and any Claude mirror whose generated `input`\n * omits `\"pdf\"` — gets a marker rather than a silently missing attachment or a rejected request.\n * Documents only ever appear in user messages; tool results stay text/image-only.\n */\nfunction downgradeUnsupportedDocuments<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tif (model.input.includes(\"pdf\")) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg) => {\n\t\tif (msg.role !== \"user\" || !Array.isArray(msg.content)) return msg;\n\t\tif (!msg.content.some((block) => block.type === \"document\")) return msg;\n\n\t\tconst content: (TextContent | ImageContent)[] = [];\n\t\tlet previousWasPlaceholder = false;\n\t\tfor (const block of msg.content) {\n\t\t\tif (block.type === \"document\") {\n\t\t\t\tif (!previousWasPlaceholder) content.push({ type: \"text\", text: NON_DOCUMENT_USER_PLACEHOLDER });\n\t\t\t\tpreviousWasPlaceholder = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcontent.push(block);\n\t\t\tpreviousWasPlaceholder = block.type === \"text\" && block.text === NON_DOCUMENT_USER_PLACEHOLDER;\n\t\t}\n\t\treturn { ...msg, content };\n\t});\n}\n\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages<TApi extends Api>(\n\tmessages: Message[],\n\tmodel: Model<TApi>,\n\tnormalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string,\n): Message[] {\n\t// Build a map of original tool call IDs to normalized IDs\n\tconst toolCallIdMap = new Map<string, string>();\n\t// Tool calls dropped for preceding a fallback boundary. Their results must go too: a\n\t// `tool_result` whose `tool_use` is absent is rejected, and `ToolResultMessage` is a separate\n\t// top-level message so removing the call alone would orphan it.\n\tconst droppedToolCallIds = new Set<string>();\n\t// Normalize null/undefined content from untyped callers (custom tools, hand-built\n\t// histories, old session files) so downstream code can rely on the type contract.\n\tconst normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n\tconst imageAwareMessages = downgradeUnsupportedDocuments(\n\t\tdowngradeUnsupportedImages(normalizedMessages, model),\n\t\tmodel,\n\t);\n\n\t// First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n\tconst transformed = imageAwareMessages.map((msg) => {\n\t\t// System and user messages pass through unchanged\n\t\tif (msg.role === \"system\" || msg.role === \"user\") {\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Handle toolResult messages - normalize toolCallId if we have a mapping\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tconst normalizedId = toolCallIdMap.get(msg.toolCallId);\n\t\t\tif (normalizedId && normalizedId !== msg.toolCallId) {\n\t\t\t\treturn { ...msg, toolCallId: normalizedId };\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Assistant messages need transformation check\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameModel =\n\t\t\t\tnormalizeProviderId(assistantMsg.provider) === normalizeProviderId(model.provider) &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tassistantMsg.model === model.id;\n\t\t\t// A different model on the same provider and API whose API adjudicates model binding\n\t\t\t// itself. Its signed blocks replay unchanged; the API keeps the ones the target model\n\t\t\t// may read and silently drops the rest.\n\t\t\tconst canReplayForeignThinking =\n\t\t\t\t!isSameModel &&\n\t\t\t\tnormalizeProviderId(assistantMsg.provider) === normalizeProviderId(model.provider) &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tdelegatesThinkingModelBinding(model);\n\t\t\tconst preservesThinking = isSameModel || canReplayForeignThinking;\n\n\t\t\t// After a mid-output server-side fallback the turn holds output from two models either\n\t\t\t// side of a `fallback` marker. Anthropic's replay rules: keep the marker \"exactly where\n\t\t\t// it appeared\", keep `text` and everything after it, and drop `thinking`,\n\t\t\t// `redacted_thinking`, and client-side `tool_use` that precede the final marker. A\n\t\t\t// request that echoes thinking from both sides is rejected outright, so this is a\n\t\t\t// correctness requirement rather than a token saving — and it applies even when the\n\t\t\t// blocks would otherwise be replayable.\n\t\t\t// https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback\n\t\t\t// `findLastIndex` needs ES2023; this package targets ES2022.\n\t\t\tlet finalFallbackIndex = -1;\n\t\t\tfor (let i = assistantMsg.content.length - 1; i >= 0; i--) {\n\t\t\t\tif (assistantMsg.content[i].type === \"fallback\") {\n\t\t\t\t\tfinalFallbackIndex = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst transformedContent = assistantMsg.content.flatMap((block, blockIndex) => {\n\t\t\t\tconst precedesFallbackBoundary = finalFallbackIndex >= 0 && blockIndex < finalFallbackIndex;\n\n\t\t\t\tif (block.type === \"fallback\") {\n\t\t\t\t\t// Only the final marker is load-bearing for validation, but earlier ones are\n\t\t\t\t\t// equally \"where they appeared\", so every marker is preserved in place.\n\t\t\t\t\treturn block;\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (precedesFallbackBoundary) return [];\n\t\t\t\t\t// Redacted thinking is opaque encrypted content the client cannot rewrite.\n\t\t\t\t\t// Replay it where the API adjudicates it; otherwise drop it to avoid API errors.\n\t\t\t\t\tif (block.redacted) {\n\t\t\t\t\t\treturn preservesThinking ? block : [];\n\t\t\t\t\t}\n\t\t\t\t\t// Keep signed thinking blocks for replay even when the thinking text is empty\n\t\t\t\t\t// (OpenAI encrypted reasoning, or Anthropic `display: \"omitted\"`).\n\t\t\t\t\tif (preservesThinking && block.thinkingSignature) return block;\n\t\t\t\t\t// Skip empty thinking blocks, convert others to plain text\n\t\t\t\t\tif (!block.thinking || block.thinking.trim() === \"\") return [];\n\t\t\t\t\tif (preservesThinking) return block;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.thinking,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (isSameModel) return block;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.text,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t// Client-side `tool_use` before the final fallback marker must be dropped: the\n\t\t\t\t\t// declining model's tool call was never executed by the model that continued.\n\t\t\t\t\t// Record the id so its `toolResult` message is dropped alongside it.\n\t\t\t\t\tif (precedesFallbackBoundary) {\n\t\t\t\t\t\tdroppedToolCallIds.add(block.id);\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tlet normalizedToolCall: ToolCall = toolCall;\n\n\t\t\t\t\tif (!isSameModel && toolCall.thoughtSignature) {\n\t\t\t\t\t\tnormalizedToolCall = { ...toolCall };\n\t\t\t\t\t\tdelete (normalizedToolCall as { thoughtSignature?: string }).thoughtSignature;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!isSameModel && normalizeToolCallId) {\n\t\t\t\t\t\tconst normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n\t\t\t\t\t\tif (normalizedId !== toolCall.id) {\n\t\t\t\t\t\t\ttoolCallIdMap.set(toolCall.id, normalizedId);\n\t\t\t\t\t\t\tnormalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn normalizedToolCall;\n\t\t\t\t}\n\n\t\t\t\treturn block;\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...assistantMsg,\n\t\t\t\tcontent: transformedContent,\n\t\t\t};\n\t\t}\n\t\treturn msg;\n\t});\n\n\t// Drop the tool results whose calls were removed at a fallback boundary. Anthropic rejects a\n\t// `tool_result` with no matching `tool_use`, so removing the call without its result would\n\t// trade one rejection for another.\n\tconst boundaryFiltered =\n\t\tdroppedToolCallIds.size === 0\n\t\t\t? transformed\n\t\t\t: transformed.filter((msg) => msg.role !== \"toolResult\" || !droppedToolCallIds.has(msg.toolCallId));\n\n\t// Second pass: insert synthetic empty tool results for orphaned tool calls\n\t// This preserves thinking signatures and satisfies API requirements\n\tconst result: Message[] = [];\n\tlet pendingToolCalls: ToolCall[] = [];\n\tlet existingToolResultIds = new Set<string>();\n\t// System messages are transparent to tool-call accounting: one that lands between a tool\n\t// call and its results is held back and emitted after the results (synthetic ones\n\t// included), so it never causes a duplicate result for a call that is answered later.\n\tconst heldSystemMessages: Message[] = [];\n\tconst closePendingToolCalls = () => {\n\t\tif (pendingToolCalls.length > 0) {\n\t\t\tfor (const tc of pendingToolCalls) {\n\t\t\t\tif (!existingToolResultIds.has(tc.id)) {\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\trole: \"toolResult\",\n\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\ttoolName: tc.name,\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t} as ToolResultMessage);\n\t\t\t\t}\n\t\t\t}\n\t\t\tpendingToolCalls = [];\n\t\t\texistingToolResultIds = new Set();\n\t\t}\n\t\tresult.push(...heldSystemMessages);\n\t\theldSystemMessages.length = 0;\n\t};\n\n\tfor (let i = 0; i < boundaryFiltered.length; i++) {\n\t\tconst msg = boundaryFiltered[i];\n\n\t\tif (msg.role === \"assistant\") {\n\t\t\t// If we have pending orphaned tool calls from a previous assistant, insert synthetic results now\n\t\t\tclosePendingToolCalls();\n\n\t\t\t// Skip errored/aborted assistant messages entirely.\n\t\t\t// These are incomplete turns that shouldn't be replayed:\n\t\t\t// - May have partial content (reasoning without message, incomplete tool calls)\n\t\t\t// - Replaying them can cause API errors (e.g., OpenAI \"reasoning without following item\")\n\t\t\t// - The model should retry from the last valid state\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tif (assistantMsg.stopReason === \"error\" || assistantMsg.stopReason === \"aborted\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Track tool calls from this assistant message\n\t\t\tconst toolCalls = assistantMsg.content.filter((b) => b.type === \"toolCall\") as ToolCall[];\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tpendingToolCalls = toolCalls;\n\t\t\t\texistingToolResultIds = new Set();\n\t\t\t}\n\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\texistingToolResultIds.add(msg.toolCallId);\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"system\") {\n\t\t\tif (pendingToolCalls.length > 0) {\n\t\t\t\theldSystemMessages.push(msg);\n\t\t\t} else {\n\t\t\t\tresult.push(msg);\n\t\t\t}\n\t\t} else if (msg.role === \"user\") {\n\t\t\t// A new user turn interrupts tool flow - insert synthetic results for orphaned calls\n\t\t\tclosePendingToolCalls();\n\t\t\tresult.push(msg);\n\t\t} else {\n\t\t\tresult.push(msg);\n\t\t}\n\t}\n\n\t// If the conversation ends with unresolved tool calls, synthesize results now.\n\tclosePendingToolCalls();\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"transform-messages.js","sourceRoot":"","sources":["../../src/api/transform-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAaxD,MAAM,iCAAiC,GAAG,gDAAgD,CAAC;AAC3F,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C,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACtC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACjC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChC,qFAAqF;YACrF,qBAAqB,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;IAED,+EAA+E;IAC/E,qBAAqB,EAAE,CAAC;IAExB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { normalizeProviderId } from \"../provider-id.ts\";\nimport type {\n\tAnthropicMessagesCompat,\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tModel,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.ts\";\n\nconst NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nconst NON_DOCUMENT_USER_PLACEHOLDER = \"(document omitted: model does not support document input)\";\nconst ERROR_TOOL_IMAGE_PLACEHOLDER = \"(image attached after the tool results)\";\n\n/**\n * Whether the target model's API adjudicates thinking-block model binding itself.\n *\n * Anthropic's preserved-thinking rules make the API, not the client, the authority on which\n * thinking blocks a model may read: \"Pass blocks back unchanged. Send every assistant turn\n * exactly as you received it, thinking blocks included, and let the API decide which blocks the\n * model can use\", and \"A block that fails the model check is always dropped\" before the prompt\n * reaches the model, unbilled.\n * https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking\n *\n * Flattening those blocks into visible text client-side is both lossy (a newer model that is\n * allowed to read them loses the reasoning) and destabilizing (it rewrites the conversation\n * prefix that later thinking-block signatures are bound to). Models whose generated metadata\n * sets this flag replay foreign signed blocks unchanged instead.\n */\nfunction delegatesThinkingModelBinding<TApi extends Api>(model: Model<TApi>): boolean {\n\tif (model.api !== \"anthropic-messages\") return false;\n\tconst compat = model.compat as AnthropicMessagesCompat | undefined;\n\treturn compat?.delegatesThinkingModelBinding === true;\n}\n\n/** An error tool result split into a text-only result and the images to send after the tool results. */\nexport interface SplitErrorToolResult {\n\t/** The result content with each run of images replaced by a note. */\n\tcontent: TextContent[];\n\t/** Text naming the tool call, to send before `images`. */\n\tcaption: string;\n\timages: ImageContent[];\n}\n\n/**\n * Split the images out of an error tool result, for APIs that reject images in error results\n * (Anthropic, and Claude on Bedrock). Send the returned content as the tool result and the caption and\n * images after all tool results of the turn, in the same user message. Returns undefined for results\n * that need no split (#10794).\n */\nexport function splitErrorToolResultImages(msg: ToolResultMessage): SplitErrorToolResult | undefined {\n\tif (!msg.isError) return undefined;\n\tconst images = msg.content.filter((block): block is ImageContent => block.type === \"image\");\n\tif (images.length === 0) return undefined;\n\treturn {\n\t\tcontent: replaceImagesWithPlaceholder(msg.content, ERROR_TOOL_IMAGE_PLACEHOLDER),\n\t\tcaption: `Images from the error result of tool call ${msg.toolCallId} (${msg.toolName}):`,\n\t\timages,\n\t};\n}\n\n// Preserves the caller's block union minus images, so a user message keeps its document blocks\n// while a tool result — which cannot carry one — keeps its narrower type.\nfunction replaceImagesWithPlaceholder<TBlock extends { type: string }>(\n\tcontent: TBlock[],\n\tplaceholder: string,\n): (Exclude<TBlock, ImageContent> | TextContent)[] {\n\tconst result: (Exclude<TBlock, ImageContent> | TextContent)[] = [];\n\tlet previousWasPlaceholder = false;\n\n\tfor (const block of content) {\n\t\tif (block.type === \"image\") {\n\t\t\tif (!previousWasPlaceholder) {\n\t\t\t\tresult.push({ type: \"text\", text: placeholder });\n\t\t\t}\n\t\t\tpreviousWasPlaceholder = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst kept = block as Exclude<TBlock, ImageContent>;\n\t\tresult.push(kept);\n\t\tpreviousWasPlaceholder = kept.type === \"text\" && (kept as unknown as TextContent).text === placeholder;\n\t}\n\n\treturn result;\n}\n\nfunction downgradeUnsupportedImages<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tif (model.input.includes(\"image\")) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg): Message => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\treturn {\n\t\t\t\t...msg,\n\t\t\t\tcontent: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER),\n\t\t\t};\n\t\t}\n\n\t\tif (msg.role === \"toolResult\") {\n\t\t\treturn {\n\t\t\t\t...msg,\n\t\t\t\tcontent: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER),\n\t\t\t};\n\t\t}\n\n\t\treturn msg;\n\t});\n}\n\n/**\n * Replace document blocks with a visible placeholder for models that cannot receive one.\n *\n * Mirrors the image downgrade: only the Anthropic Messages and Amazon Bedrock Converse paths can\n * serialize a document, so every other provider — and any Claude mirror whose generated `input`\n * omits `\"pdf\"` — gets a marker rather than a silently missing attachment or a rejected request.\n * Documents only ever appear in user messages; tool results stay text/image-only.\n */\nfunction downgradeUnsupportedDocuments<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\tif (model.input.includes(\"pdf\")) {\n\t\treturn messages;\n\t}\n\n\treturn messages.map((msg) => {\n\t\tif (msg.role !== \"user\" || !Array.isArray(msg.content)) return msg;\n\t\tif (!msg.content.some((block) => block.type === \"document\")) return msg;\n\n\t\tconst content: (TextContent | ImageContent)[] = [];\n\t\tlet previousWasPlaceholder = false;\n\t\tfor (const block of msg.content) {\n\t\t\tif (block.type === \"document\") {\n\t\t\t\tif (!previousWasPlaceholder) content.push({ type: \"text\", text: NON_DOCUMENT_USER_PLACEHOLDER });\n\t\t\t\tpreviousWasPlaceholder = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcontent.push(block);\n\t\t\tpreviousWasPlaceholder = block.type === \"text\" && block.text === NON_DOCUMENT_USER_PLACEHOLDER;\n\t\t}\n\t\treturn { ...msg, content };\n\t});\n}\n\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages<TApi extends Api>(\n\tmessages: Message[],\n\tmodel: Model<TApi>,\n\tnormalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string,\n): Message[] {\n\t// Build a map of original tool call IDs to normalized IDs\n\tconst toolCallIdMap = new Map<string, string>();\n\t// Tool calls dropped for preceding a fallback boundary. Their results must go too: a\n\t// `tool_result` whose `tool_use` is absent is rejected, and `ToolResultMessage` is a separate\n\t// top-level message so removing the call alone would orphan it.\n\tconst droppedToolCallIds = new Set<string>();\n\t// Normalize null/undefined content from untyped callers (custom tools, hand-built\n\t// histories, old session files) so downstream code can rely on the type contract.\n\tconst normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n\tconst imageAwareMessages = downgradeUnsupportedDocuments(\n\t\tdowngradeUnsupportedImages(normalizedMessages, model),\n\t\tmodel,\n\t);\n\n\t// First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n\tconst transformed = imageAwareMessages.map((msg) => {\n\t\t// System and user messages pass through unchanged\n\t\tif (msg.role === \"system\" || msg.role === \"user\") {\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Handle toolResult messages - normalize toolCallId if we have a mapping\n\t\tif (msg.role === \"toolResult\") {\n\t\t\tconst normalizedId = toolCallIdMap.get(msg.toolCallId);\n\t\t\tif (normalizedId && normalizedId !== msg.toolCallId) {\n\t\t\t\treturn { ...msg, toolCallId: normalizedId };\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Assistant messages need transformation check\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameModel =\n\t\t\t\tnormalizeProviderId(assistantMsg.provider) === normalizeProviderId(model.provider) &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tassistantMsg.model === model.id;\n\t\t\t// A different model on the same provider and API whose API adjudicates model binding\n\t\t\t// itself. Its signed blocks replay unchanged; the API keeps the ones the target model\n\t\t\t// may read and silently drops the rest.\n\t\t\tconst canReplayForeignThinking =\n\t\t\t\t!isSameModel &&\n\t\t\t\tnormalizeProviderId(assistantMsg.provider) === normalizeProviderId(model.provider) &&\n\t\t\t\tassistantMsg.api === model.api &&\n\t\t\t\tdelegatesThinkingModelBinding(model);\n\t\t\tconst preservesThinking = isSameModel || canReplayForeignThinking;\n\n\t\t\t// After a mid-output server-side fallback the turn holds output from two models either\n\t\t\t// side of a `fallback` marker. Anthropic's replay rules: keep the marker \"exactly where\n\t\t\t// it appeared\", keep `text` and everything after it, and drop `thinking`,\n\t\t\t// `redacted_thinking`, and client-side `tool_use` that precede the final marker. A\n\t\t\t// request that echoes thinking from both sides is rejected outright, so this is a\n\t\t\t// correctness requirement rather than a token saving — and it applies even when the\n\t\t\t// blocks would otherwise be replayable.\n\t\t\t// https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback\n\t\t\t// `findLastIndex` needs ES2023; this package targets ES2022.\n\t\t\tlet finalFallbackIndex = -1;\n\t\t\tfor (let i = assistantMsg.content.length - 1; i >= 0; i--) {\n\t\t\t\tif (assistantMsg.content[i].type === \"fallback\") {\n\t\t\t\t\tfinalFallbackIndex = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst transformedContent = assistantMsg.content.flatMap((block, blockIndex) => {\n\t\t\t\tconst precedesFallbackBoundary = finalFallbackIndex >= 0 && blockIndex < finalFallbackIndex;\n\n\t\t\t\tif (block.type === \"fallback\") {\n\t\t\t\t\t// Only the final marker is load-bearing for validation, but earlier ones are\n\t\t\t\t\t// equally \"where they appeared\", so every marker is preserved in place.\n\t\t\t\t\treturn block;\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (precedesFallbackBoundary) return [];\n\t\t\t\t\t// Thinking from another model is dropped unless the API adjudicates it. Signatures and\n\t\t\t\t\t// encrypted reasoning are only valid for the model that produced them, and sending\n\t\t\t\t\t// readable thinking as plain text makes the new model treat it as part of the visible reply.\n\t\t\t\t\tif (!preservesThinking) return [];\n\t\t\t\t\t// Keep redacted and signed blocks even if the thinking text is empty\n\t\t\t\t\t// (OpenAI encrypted reasoning, or Anthropic `display: \"omitted\"`); they are needed for replay.\n\t\t\t\t\tif (block.redacted || block.thinkingSignature) return block;\n\t\t\t\t\tif (!block.thinking || block.thinking.trim() === \"\") return [];\n\t\t\t\t\treturn block;\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\tif (isSameModel) return block;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: block.text,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t// Client-side `tool_use` before the final fallback marker must be dropped: the\n\t\t\t\t\t// declining model's tool call was never executed by the model that continued.\n\t\t\t\t\t// Record the id so its `toolResult` message is dropped alongside it.\n\t\t\t\t\tif (precedesFallbackBoundary) {\n\t\t\t\t\t\tdroppedToolCallIds.add(block.id);\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tlet normalizedToolCall: ToolCall = toolCall;\n\n\t\t\t\t\tif (!isSameModel && toolCall.thoughtSignature) {\n\t\t\t\t\t\tnormalizedToolCall = { ...toolCall };\n\t\t\t\t\t\tdelete (normalizedToolCall as { thoughtSignature?: string }).thoughtSignature;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!isSameModel && normalizeToolCallId) {\n\t\t\t\t\t\tconst normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n\t\t\t\t\t\tif (normalizedId !== toolCall.id) {\n\t\t\t\t\t\t\ttoolCallIdMap.set(toolCall.id, normalizedId);\n\t\t\t\t\t\t\tnormalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn normalizedToolCall;\n\t\t\t\t}\n\n\t\t\t\treturn block;\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...assistantMsg,\n\t\t\t\tcontent: transformedContent,\n\t\t\t};\n\t\t}\n\t\treturn msg;\n\t});\n\n\t// Drop the tool results whose calls were removed at a fallback boundary. Anthropic rejects a\n\t// `tool_result` with no matching `tool_use`, so removing the call without its result would\n\t// trade one rejection for another.\n\tconst boundaryFiltered =\n\t\tdroppedToolCallIds.size === 0\n\t\t\t? transformed\n\t\t\t: transformed.filter((msg) => msg.role !== \"toolResult\" || !droppedToolCallIds.has(msg.toolCallId));\n\n\t// Second pass: insert synthetic empty tool results for orphaned tool calls\n\t// This preserves thinking signatures and satisfies API requirements\n\tconst result: Message[] = [];\n\tlet pendingToolCalls: ToolCall[] = [];\n\tlet existingToolResultIds = new Set<string>();\n\t// System messages are transparent to tool-call accounting: one that lands between a tool\n\t// call and its results is held back and emitted after the results (synthetic ones\n\t// included), so it never causes a duplicate result for a call that is answered later.\n\tconst heldSystemMessages: Message[] = [];\n\tconst closePendingToolCalls = () => {\n\t\tif (pendingToolCalls.length > 0) {\n\t\t\tfor (const tc of pendingToolCalls) {\n\t\t\t\tif (!existingToolResultIds.has(tc.id)) {\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\trole: \"toolResult\",\n\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\ttoolName: tc.name,\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t} as ToolResultMessage);\n\t\t\t\t}\n\t\t\t}\n\t\t\tpendingToolCalls = [];\n\t\t\texistingToolResultIds = new Set();\n\t\t}\n\t\tresult.push(...heldSystemMessages);\n\t\theldSystemMessages.length = 0;\n\t};\n\n\tfor (let i = 0; i < boundaryFiltered.length; i++) {\n\t\tconst msg = boundaryFiltered[i];\n\n\t\tif (msg.role === \"assistant\") {\n\t\t\t// If we have pending orphaned tool calls from a previous assistant, insert synthetic results now\n\t\t\tclosePendingToolCalls();\n\n\t\t\t// Skip errored/aborted assistant messages entirely.\n\t\t\t// These are incomplete turns that shouldn't be replayed:\n\t\t\t// - May have partial content (reasoning without message, incomplete tool calls)\n\t\t\t// - Replaying them can cause API errors (e.g., OpenAI \"reasoning without following item\")\n\t\t\t// - The model should retry from the last valid state\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tif (assistantMsg.stopReason === \"error\" || assistantMsg.stopReason === \"aborted\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Track tool calls from this assistant message\n\t\t\tconst toolCalls = assistantMsg.content.filter((b) => b.type === \"toolCall\") as ToolCall[];\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tpendingToolCalls = toolCalls;\n\t\t\t\texistingToolResultIds = new Set();\n\t\t\t}\n\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\texistingToolResultIds.add(msg.toolCallId);\n\t\t\tresult.push(msg);\n\t\t} else if (msg.role === \"system\") {\n\t\t\tif (pendingToolCalls.length > 0) {\n\t\t\t\theldSystemMessages.push(msg);\n\t\t\t} else {\n\t\t\t\tresult.push(msg);\n\t\t\t}\n\t\t} else if (msg.role === \"user\") {\n\t\t\t// A new user turn interrupts tool flow - insert synthetic results for orphaned calls\n\t\t\tclosePendingToolCalls();\n\t\t\tresult.push(msg);\n\t\t} else {\n\t\t\tresult.push(msg);\n\t\t}\n\t}\n\n\t// If the conversation ends with unresolved tool calls, synthesize results now.\n\tclosePendingToolCalls();\n\n\treturn result;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./session-resources.ts";
28
28
  export * from "./types.ts";
29
29
  export * from "./utils/diagnostics.ts";
30
30
  export * from "./utils/event-stream.ts";
31
+ export { AssistantMessageEventStream } from "./utils/event-stream.ts";
31
32
  export * from "./utils/json-parse.ts";
32
33
  export * from "./utils/overflow.ts";
33
34
  export * from "./utils/retry.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACnF,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/F,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAClG,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EAAE,2BAA2B,EAAE,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AAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export * from "./session-resources.js";
14
14
  export * from "./types.js";
15
15
  export * from "./utils/diagnostics.js";
16
16
  export * from "./utils/event-stream.js";
17
+ export { AssistantMessageEventStream } from "./utils/event-stream.js";
17
18
  export * from "./utils/json-parse.js";
18
19
  export * from "./utils/overflow.js";
19
20
  export * from "./utils/retry.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAO9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@bastani/pi-ai/providers/*\", API implementations under\n// \"@bastani/pi-ai/api/*\", the old global API under\n// \"@bastani/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleApiThinkingLevel, ResolvedGoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport type { OpenAIImagesOptions } from \"./api/openai-images.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./decision-models.ts\";\nexport { containsKnownEnvCredential } from \"./env-api-keys.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport { normalizeProviderId } from \"./provider-id.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/stream-deadline.ts\";\nexport { contentText, getSystemMessageText, renderSystemMessageUpdate } from \"./utils/text.ts\";\nexport * from \"./utils/transcript.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport { uuidv7 } from \"./utils/uuid.ts\";\nexport * from \"./utils/validation.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAO9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@bastani/pi-ai/providers/*\", API implementations under\n// \"@bastani/pi-ai/api/*\", the old global API under\n// \"@bastani/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleApiThinkingLevel, ResolvedGoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport type { OpenAIImagesOptions } from \"./api/openai-images.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./decision-models.ts\";\nexport { containsKnownEnvCredential } from \"./env-api-keys.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport { normalizeProviderId } from \"./provider-id.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport { AssistantMessageEventStream } from \"./utils/event-stream.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/stream-deadline.ts\";\nexport { contentText, getSystemMessageText, renderSystemMessageUpdate } from \"./utils/text.ts\";\nexport * from \"./utils/transcript.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport { uuidv7 } from \"./utils/uuid.ts\";\nexport * from \"./utils/validation.ts\";\n"]}
@@ -190,6 +190,162 @@ export declare const MistralConversationsCompatSchema: Type.TObject<{
190
190
  }>;
191
191
  type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
192
192
  type MergedCompatProperties<PropertyGroups extends readonly TProperties[], Overrides extends TProperties> = Omit<UnionToIntersection<PropertyGroups[number]>, keyof Overrides> & Overrides;
193
+ export declare const CompatSchemasByApi: {
194
+ readonly "openai-completions": Type.TObject<{
195
+ supportsStore: Type.TOptional<Type.TBoolean>;
196
+ supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
197
+ supportsReasoningEffort: Type.TOptional<Type.TBoolean>;
198
+ supportsTemperature: Type.TOptional<Type.TBoolean>;
199
+ supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
200
+ supportsUsageInStreaming: Type.TOptional<Type.TBoolean>;
201
+ supportsFinishReason: Type.TOptional<Type.TBoolean>;
202
+ maxTokensField: Type.TOptional<Type.TUnion<[Type.TLiteral<"max_completion_tokens">, Type.TLiteral<"max_tokens">]>>;
203
+ requiresToolResultName: Type.TOptional<Type.TBoolean>;
204
+ requiresAssistantAfterToolResult: Type.TOptional<Type.TBoolean>;
205
+ requiresThinkingAsText: Type.TOptional<Type.TBoolean>;
206
+ requiresReasoningContentOnAssistantMessages: Type.TOptional<Type.TBoolean>;
207
+ thinkingFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openrouter">, Type.TLiteral<"deepseek">, Type.TLiteral<"together">, Type.TLiteral<"baseten">, Type.TLiteral<"zai">, Type.TLiteral<"qwen">, Type.TLiteral<"chat-template">, Type.TLiteral<"qwen-chat-template">, Type.TLiteral<"string-thinking">, Type.TLiteral<"ant-ling">]>>;
208
+ chatTemplateKwargs: Type.TOptional<Type.TRecord<"^.*$", Type.TUnion<[Type.TString, Type.TNumber, Type.TBoolean, Type.TNull, Type.TObject<{
209
+ $var: Type.TUnion<[Type.TLiteral<"thinking.enabled">, Type.TLiteral<"thinking.effort">, Type.TLiteral<"thinking.budget">]>;
210
+ omitWhenOff: Type.TOptional<Type.TBoolean>;
211
+ }>]>>>;
212
+ chatTemplateArgs: Type.TOptional<Type.TRecord<"^.*$", Type.TUnion<[Type.TString, Type.TNumber, Type.TBoolean, Type.TNull, Type.TObject<{
213
+ $var: Type.TUnion<[Type.TLiteral<"thinking.enabled">, Type.TLiteral<"thinking.effort">, Type.TLiteral<"thinking.budget">]>;
214
+ omitWhenOff: Type.TOptional<Type.TBoolean>;
215
+ }>]>>>;
216
+ openRouterRouting: Type.TOptional<Type.TObject<{
217
+ allow_fallbacks: Type.TOptional<Type.TBoolean>;
218
+ require_parameters: Type.TOptional<Type.TBoolean>;
219
+ data_collection: Type.TOptional<Type.TUnion<[Type.TLiteral<"deny">, Type.TLiteral<"allow">]>>;
220
+ zdr: Type.TOptional<Type.TBoolean>;
221
+ enforce_distillable_text: Type.TOptional<Type.TBoolean>;
222
+ order: Type.TOptional<Type.TArray<Type.TString>>;
223
+ only: Type.TOptional<Type.TArray<Type.TString>>;
224
+ ignore: Type.TOptional<Type.TArray<Type.TString>>;
225
+ quantizations: Type.TOptional<Type.TArray<Type.TString>>;
226
+ sort: Type.TOptional<Type.TUnion<[Type.TString, Type.TObject<{
227
+ by: Type.TOptional<Type.TString>;
228
+ partition: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
229
+ }>]>>;
230
+ max_price: Type.TOptional<Type.TObject<{
231
+ prompt: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
232
+ completion: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
233
+ image: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
234
+ audio: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
235
+ request: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
236
+ }>>;
237
+ preferred_min_throughput: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TObject<{
238
+ p50: Type.TOptional<Type.TNumber>;
239
+ p75: Type.TOptional<Type.TNumber>;
240
+ p90: Type.TOptional<Type.TNumber>;
241
+ p99: Type.TOptional<Type.TNumber>;
242
+ }>]>>;
243
+ preferred_max_latency: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TObject<{
244
+ p50: Type.TOptional<Type.TNumber>;
245
+ p75: Type.TOptional<Type.TNumber>;
246
+ p90: Type.TOptional<Type.TNumber>;
247
+ p99: Type.TOptional<Type.TNumber>;
248
+ }>]>>;
249
+ }>>;
250
+ vercelGatewayRouting: Type.TOptional<Type.TObject<{
251
+ only: Type.TOptional<Type.TArray<Type.TString>>;
252
+ order: Type.TOptional<Type.TArray<Type.TString>>;
253
+ }>>;
254
+ zaiToolStream: Type.TOptional<Type.TBoolean>;
255
+ thinkingTokenBudgetField: Type.TOptional<Type.TUnion<[Type.TLiteral<"thinking_token_budget">, Type.TLiteral<"thinking_budget">, Type.TLiteral<"thinking_budget_tokens">]>>;
256
+ supportsThinkingTokenBudget: Type.TOptional<Type.TBoolean>;
257
+ supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
258
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
259
+ supportsMidConvoToolAdditions: Type.TOptional<Type.TBoolean>;
260
+ supportsStrictMode: Type.TOptional<Type.TBoolean>;
261
+ cacheControlFormat: Type.TOptional<Type.TLiteral<"anthropic">>;
262
+ sendSessionAffinityHeaders: Type.TOptional<Type.TBoolean>;
263
+ sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
264
+ supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
265
+ vllmPriority: Type.TOptional<Type.TNumber>;
266
+ }>;
267
+ readonly "openai-responses": Type.TObject<{
268
+ supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
269
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
270
+ sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
271
+ supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
272
+ supportsStrictMode: Type.TOptional<Type.TBoolean>;
273
+ supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
274
+ supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
275
+ supportsToolSearch: Type.TOptional<Type.TBoolean>;
276
+ supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
277
+ supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
278
+ supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
279
+ }>;
280
+ readonly "azure-openai-responses": Type.TObject<{
281
+ supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
282
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
283
+ sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
284
+ supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
285
+ supportsStrictMode: Type.TOptional<Type.TBoolean>;
286
+ supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
287
+ supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
288
+ supportsToolSearch: Type.TOptional<Type.TBoolean>;
289
+ supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
290
+ supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
291
+ supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
292
+ }>;
293
+ readonly "openai-codex-responses": Type.TObject<{
294
+ supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
295
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
296
+ sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
297
+ supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
298
+ supportsStrictMode: Type.TOptional<Type.TBoolean>;
299
+ supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
300
+ supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
301
+ supportsToolSearch: Type.TOptional<Type.TBoolean>;
302
+ supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
303
+ supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
304
+ supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
305
+ }>;
306
+ readonly "anthropic-messages": Type.TObject<{
307
+ supportsEagerToolInputStreaming: Type.TOptional<Type.TBoolean>;
308
+ supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
309
+ sendSessionAffinityHeaders: Type.TOptional<Type.TBoolean>;
310
+ sessionAffinityFormat: Type.TOptional<Type.TLiteral<"openrouter">>;
311
+ supportsCacheControlOnTools: Type.TOptional<Type.TBoolean>;
312
+ supportsTemperature: Type.TOptional<Type.TBoolean>;
313
+ forceAdaptiveThinking: Type.TOptional<Type.TBoolean>;
314
+ allowEmptySignature: Type.TOptional<Type.TBoolean>;
315
+ supportsStrictTools: Type.TOptional<Type.TBoolean>;
316
+ supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
317
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
318
+ supportsMidConvoToolChanges: Type.TOptional<Type.TBoolean>;
319
+ allowedFallbackModels: Type.TOptional<Type.TArray<Type.TObject<{
320
+ provider: Type.TString;
321
+ model: Type.TString;
322
+ cost: Type.TObject<{
323
+ input: Type.TNumber;
324
+ output: Type.TNumber;
325
+ cacheRead: Type.TNumber;
326
+ cacheWrite: Type.TNumber;
327
+ tiers: Type.TOptional<Type.TArray<Type.TObject<{
328
+ input: Type.TNumber;
329
+ output: Type.TNumber;
330
+ cacheRead: Type.TNumber;
331
+ cacheWrite: Type.TNumber;
332
+ inputTokensAbove: Type.TNumber;
333
+ }>>>;
334
+ }>;
335
+ }>>>;
336
+ enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
337
+ delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
338
+ supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
339
+ }>;
340
+ readonly "bedrock-converse-stream": Type.TObject<{
341
+ supportsStrictMode: Type.TOptional<Type.TBoolean>;
342
+ supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
343
+ supportsTemperature: Type.TOptional<Type.TBoolean>;
344
+ }>;
345
+ readonly "mistral-conversations": Type.TObject<{
346
+ supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
347
+ }>;
348
+ };
193
349
  export declare const ProviderCompatSchema: Type.TObject<MergedCompatProperties<({
194
350
  supportsStore: Type.TOptional<Type.TBoolean>;
195
351
  supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"compat-schema.d.ts","sourceRoot":"","sources":["../../src/providers/compat-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAuB,IAAI,EAAE,MAAM,SAAS,CAAC;AAOnF,eAAO,MAAM,2BAA2B,wGAEtC,CAAC;AASH,eAAO,MAAM,8BAA8B,kIAGzC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;IAavC,CAAC;AAWH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqGnC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;EAkBtC,CAAC;AAEF,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;EAO/C,CAAC;AAUF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4KzC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EA8DvC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwGzC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;EAkB/B,CAAC;AAEF,eAAO,MAAM,gCAAgC;;EAS5C,CAAC;AA6CF,KAAK,mBAAmB,CAAC,KAAK,IAAI,CAAC,KAAK,SAAS,OAAO,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAClG,KAAK,EAAE,MAAM,YAAY,KACrB,IAAI,GACN,YAAY,GACZ,KAAK,CAAC;AAET,KAAK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AAqE;AACrE,MAAM,WAAW,uBAAwB,SAAQ,MAAM,CAAC,OAAO,6BAA6B,CAAC;CAAG;AAChG,wDAAwD;AACxD,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,OAAO,mBAAmB,CAAC;CAAG;AAC5E,uDAAuD;AACvD,MAAM,WAAW,0BAA2B,SAAQ,MAAM,CAAC,OAAO,gCAAgC,CAAC;CAAG"}
@@ -404,14 +404,16 @@ function mergeCompatProperties(propertyGroups, overrides) {
404
404
  }
405
405
  return { ...merged, ...overrides };
406
406
  }
407
- const CompatSchemasByApi = {
407
+ export const CompatSchemasByApi = {
408
408
  "openai-completions": OpenAICompletionsCompatSchema,
409
409
  "openai-responses": OpenAIResponsesCompatSchema,
410
+ "azure-openai-responses": OpenAIResponsesCompatSchema,
411
+ "openai-codex-responses": OpenAIResponsesCompatSchema,
410
412
  "anthropic-messages": AnthropicMessagesCompatSchema,
411
413
  "bedrock-converse-stream": BedrockCompatSchema,
412
414
  "mistral-conversations": MistralConversationsCompatSchema,
413
415
  };
414
- const ProviderCompatProperties = mergeCompatProperties(Object.values(CompatSchemasByApi).map((schema) => schema.properties), ProviderCompatPropertyOverrides);
416
+ const ProviderCompatProperties = mergeCompatProperties([...new Set(Object.values(CompatSchemasByApi))].map((schema) => schema.properties), ProviderCompatPropertyOverrides);
415
417
  export const ProviderCompatSchema = Type.Object(ProviderCompatProperties, {
416
418
  description: "Provider and model compatibility overrides.",
417
419
  additionalProperties: true,
@@ -1 +1 @@
1
- {"version":3,"file":"compat-schema.js","sourceRoot":"","sources":["../../src/providers/compat-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,IAAI,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,SAAS,qBAAqB,CAAC,OAAwB;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,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BAA+B,CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE;IACzE,WAAW,EAAE,6CAA6C;IAC1D,oBAAoB,EAAE,IAAI;CAC1B,CAAC,CAAC","sourcesContent":["import { type Static, type TProperties, type TSchemaOptions, Type } from \"typebox\";\nimport { ModelCostSchema } from \"./model-schema.ts\";\n\nfunction sessionAffinityFormat(options?: TSchemaOptions) {\n\treturn Type.Union([Type.Literal(\"openai\"), Type.Literal(\"openai-nosession\"), Type.Literal(\"openrouter\")], options);\n}\n\nexport const SessionAffinityFormatSchema = sessionAffinityFormat({\n\tdescription: \"Session-affinity header format used to route related requests consistently.\",\n});\n\nfunction thinkingTokenBudgetField(options?: TSchemaOptions) {\n\treturn Type.Union(\n\t\t[Type.Literal(\"thinking_token_budget\"), Type.Literal(\"thinking_budget\"), Type.Literal(\"thinking_budget_tokens\")],\n\t\toptions,\n\t);\n}\n\nexport const ThinkingTokenBudgetFieldSchema = thinkingTokenBudgetField({\n\tdescription:\n\t\t'Top-level request field name used by OpenAI-compatible endpoints to cap reasoning tokens. \"thinking_token_budget\" is used by vLLM, \"thinking_budget\" by Qwen, DashScope, or SGLang, and \"thinking_budget_tokens\" by llama.cpp.',\n});\n\nexport const ChatTemplateKwargValueSchema = Type.Union([\n\tType.String(),\n\tType.Number(),\n\tType.Boolean(),\n\tType.Null(),\n\tType.Object({\n\t\t$var: Type.Union([\n\t\t\tType.Literal(\"thinking.enabled\"),\n\t\t\tType.Literal(\"thinking.effort\"),\n\t\t\tType.Literal(\"thinking.budget\"),\n\t\t]),\n\t\tomitWhenOff: Type.Optional(Type.Boolean()),\n\t}),\n]);\n\nfunction percentileCutoffs(metric: string) {\n\treturn Type.Object({\n\t\tp50: Type.Optional(Type.Number({ description: `${metric} at the 50th percentile.` })),\n\t\tp75: Type.Optional(Type.Number({ description: `${metric} at the 75th percentile.` })),\n\t\tp90: Type.Optional(Type.Number({ description: `${metric} at the 90th percentile.` })),\n\t\tp99: Type.Optional(Type.Number({ description: `${metric} at the 99th percentile.` })),\n\t});\n}\n\nexport const OpenRouterRoutingSchema = Type.Object(\n\t{\n\t\tallow_fallbacks: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to allow backup providers to serve requests.\", default: true }),\n\t\t),\n\t\trequire_parameters: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether to filter providers to only those that support all parameters in the request.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tdata_collection: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"deny\"), Type.Literal(\"allow\")], {\n\t\t\t\tdescription:\n\t\t\t\t\t'Data collection setting. \"allow\": allow providers that may store or train on data. \"deny\": only use providers that do not collect user data.',\n\t\t\t\tdefault: \"allow\",\n\t\t\t}),\n\t\t),\n\t\tzdr: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.\" }),\n\t\t),\n\t\tenforce_distillable_text: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to restrict routing to only models that allow text distillation.\" }),\n\t\t),\n\t\torder: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t\"An ordered list of provider names or slugs to try in sequence, falling back to the next if unavailable.\",\n\t\t\t}),\n\t\t),\n\t\tonly: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription: \"List of provider names or slugs to exclusively allow for this request.\",\n\t\t\t}),\n\t\t),\n\t\tignore: Type.Optional(\n\t\t\tType.Array(Type.String(), { description: \"List of provider names or slugs to skip for this request.\" }),\n\t\t),\n\t\tquantizations: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t'A list of quantization levels to filter providers by, for example [\"fp16\", \"bf16\", \"fp8\", \"fp6\", \"int8\", \"int4\", \"fp4\", \"fp32\"].',\n\t\t\t}),\n\t\t),\n\t\tsort: Type.Optional(\n\t\t\tType.Union(\n\t\t\t\t[\n\t\t\t\t\tType.String(),\n\t\t\t\t\tType.Object({\n\t\t\t\t\t\tby: Type.Optional(\n\t\t\t\t\t\t\tType.String({ description: 'The sorting metric, such as \"price\", \"throughput\", or \"latency\".' }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tpartition: Type.Optional(\n\t\t\t\t\t\t\tType.Union([Type.String(), Type.Null()], {\n\t\t\t\t\t\t\t\tdescription: 'Partitioning strategy: \"model\" or \"none\".',\n\t\t\t\t\t\t\t\tdefault: \"model\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Sorting strategy. Can be a string such as \"price\", \"throughput\", or \"latency\", or an object.',\n\t\t\t\t},\n\t\t\t),\n\t\t),\n\t\tmax_price: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tprompt: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per million prompt tokens.\" }),\n\t\t\t\t\t),\n\t\t\t\t\tcompletion: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per million completion tokens.\" }),\n\t\t\t\t\t),\n\t\t\t\t\timage: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: \"Price per image.\" })),\n\t\t\t\t\taudio: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per audio unit.\" }),\n\t\t\t\t\t),\n\t\t\t\t\trequest: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per request.\" }),\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{ description: \"Maximum price per million tokens in USD.\" },\n\t\t\t),\n\t\t),\n\t\tpreferred_min_throughput: Type.Optional(\n\t\t\tType.Union([Type.Number(), percentileCutoffs(\"Minimum tokens per second\")], {\n\t\t\t\tdescription: \"Preferred minimum throughput in tokens per second. A number applies to p50.\",\n\t\t\t}),\n\t\t),\n\t\tpreferred_max_latency: Type.Optional(\n\t\t\tType.Union([Type.Number(), percentileCutoffs(\"Maximum latency in seconds\")], {\n\t\t\t\tdescription: \"Preferred maximum latency in seconds. A number applies to p50.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"OpenRouter provider routing preferences. Controls which upstream providers OpenRouter routes requests to. Sent as the provider field in the OpenRouter API request body. See https://openrouter.ai/docs/guides/routing/provider-selection.\",\n\t},\n);\n\nexport const VercelGatewayRoutingSchema = Type.Object(\n\t{\n\t\tonly: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t'List of provider slugs to exclusively use for this request, for example [\"bedrock\", \"anthropic\"].',\n\t\t\t}),\n\t\t),\n\t\torder: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription: 'List of provider slugs to try in order, for example [\"anthropic\", \"openai\"].',\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"Vercel AI Gateway routing preferences. Controls which upstream providers the gateway routes requests to. See https://vercel.com/docs/ai-gateway/models-and-providers/provider-options.\",\n\t},\n);\n\nexport const AnthropicAllowedFallbackModelSchema = Type.Object(\n\t{\n\t\tprovider: Type.String({ minLength: 1 }),\n\t\tmodel: Type.String({ minLength: 1 }),\n\t\tcost: ModelCostSchema,\n\t},\n\t{ description: \"An Anthropic server-side refusal fallback model with local pricing metadata.\" },\n);\n\nfunction optionalCompatBoolean(options?: TSchemaOptions) {\n\treturn Type.Optional(Type.Boolean(options));\n}\n\nfunction optionalSessionAffinityFormat(options?: TSchemaOptions) {\n\treturn Type.Optional(sessionAffinityFormat(options));\n}\n\nexport const OpenAICompletionsCompatSchema = Type.Object(\n\t{\n\t\tsupportsStore: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider supports the store field. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports the developer role instead of system. Default: auto-detected from URL.\",\n\t\t}),\n\t\tsupportsReasoningEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider supports reasoning_effort. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsTemperature: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the model accepts the temperature request field. When false, the provider omits temperature and also strips temperature, top_p, and top_k from samplingParams.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (tool_choice \"required\" or a specific function). When false, the provider rejects a forced choice with an error instead of sending a request the model cannot honor. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsUsageInStreaming: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports stream_options.include_usage for token usage in streaming responses.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsFinishReason: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether streamed responses include finish_reason. When false, pi infers stop or toolUse when the stream ends.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tmaxTokensField: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"max_completion_tokens\"), Type.Literal(\"max_tokens\")], {\n\t\t\t\tdescription: \"Which field to use for max tokens. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresToolResultName: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether tool results require the name field. Default: auto-detected from URL.\" }),\n\t\t),\n\t\trequiresAssistantAfterToolResult: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresThinkingAsText: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresReasoningContentOnAssistantMessages: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether all replayed assistant messages must include an empty reasoning_content field when reasoning is enabled. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tthinkingFormat: Type.Optional(\n\t\t\tType.Union(\n\t\t\t\t[\n\t\t\t\t\tType.Literal(\"openai\"),\n\t\t\t\t\tType.Literal(\"openrouter\"),\n\t\t\t\t\tType.Literal(\"deepseek\"),\n\t\t\t\t\tType.Literal(\"together\"),\n\t\t\t\t\tType.Literal(\"baseten\"),\n\t\t\t\t\tType.Literal(\"zai\"),\n\t\t\t\t\tType.Literal(\"qwen\"),\n\t\t\t\t\tType.Literal(\"chat-template\"),\n\t\t\t\t\tType.Literal(\"qwen-chat-template\"),\n\t\t\t\t\tType.Literal(\"string-thinking\"),\n\t\t\t\t\tType.Literal(\"ant-ling\"),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Format for reasoning or thinking parameters. When omitted, Pi auto-detects the format from the provider URL. \"openai\" uses reasoning_effort, \"openrouter\" uses reasoning.effort, \"deepseek\" uses thinking.type plus reasoning_effort when supported, \"together\" uses reasoning.enabled plus reasoning_effort when supported, \"baseten\" uses configurable chat_template_args plus reasoning_effort when supported, \"zai\" uses thinking.type, \"qwen\" uses top-level enable_thinking, \"qwen-chat-template\" uses chat_template_kwargs.enable_thinking and preserve_thinking, \"chat-template\" uses configurable chat_template_kwargs, \"string-thinking\" uses top-level thinking, and \"ant-ling\" uses reasoning.effort only when the mapped effort is non-null.',\n\t\t\t\t},\n\t\t\t),\n\t\t),\n\t\tchatTemplateKwargs: Type.Optional(\n\t\t\tType.Record(Type.String(), ChatTemplateKwargValueSchema, {\n\t\t\t\tdescription:\n\t\t\t\t\t'Kwargs sent as chat_template_kwargs when thinkingFormat is \"chat-template\". Use $var with \"thinking.enabled\", \"thinking.effort\", or \"thinking.budget\" for pi-controlled values.',\n\t\t\t}),\n\t\t),\n\t\tchatTemplateArgs: Type.Optional(\n\t\t\tType.Record(Type.String(), ChatTemplateKwargValueSchema, {\n\t\t\t\tdescription:\n\t\t\t\t\t'Arguments sent as chat_template_args when thinkingFormat is \"baseten\". Use $var with \"thinking.enabled\", \"thinking.effort\", or \"thinking.budget\" for pi-controlled values.',\n\t\t\t}),\n\t\t),\n\t\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\t\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n\t\tzaiToolStream: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether z.ai supports top-level tool_stream for streaming tool call deltas.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tthinkingTokenBudgetField: Type.Optional(\n\t\t\tthinkingTokenBudgetField({\n\t\t\t\tdescription:\n\t\t\t\t\t'Top-level request field used to cap reasoning tokens from thinkingBudgets. Reasoning and the answer share max_tokens on these endpoints. \"thinking_token_budget\" is vLLM, \"thinking_budget\" is Qwen, DashScope, or SGLang, and \"thinking_budget_tokens\" is llama.cpp. Off by default and not set on the generated catalog.',\n\t\t\t}),\n\t\t),\n\t\tsupportsThinkingTokenBudget: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t'Alias for thinkingTokenBudgetField: \"thinking_token_budget\" (vLLM). Prefer thinkingTokenBudgetField.',\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. The generated catalog enables this for capable models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system or developer messages after the conversation has started. When false, later system messages are folded into the leading system message. The generated catalog enables this for verified models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoToolAdditions: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether system messages can introduce additional tools mid-conversation. Requires supportsMidConvoSystemMessages. The generated catalog enables this for capable models.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports the strict field in tool definitions. Generated capable models enable it explicitly.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tcacheControlFormat: Type.Optional(\n\t\t\tType.Literal(\"anthropic\", {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Cache control convention for prompt caching. Anthropic applies cache_control markers to the system prompt, last tool definition, and last user, assistant, or tool-result text content.\",\n\t\t\t}),\n\t\t),\n\t\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to send session-affinity data from options.sessionId. Default: true for OpenRouter endpoints, false otherwise.\",\n\t\t}),\n\t\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\t\tdescription:\n\t\t\t\t\"Session-affinity header format. openai sends session_id, x-client-request-id, and x-session-affinity; openai-nosession sends x-client-request-id and x-session-affinity; openrouter sends x-session-id. Does not affect prompt_cache_key. Default: auto-detected.\",\n\t\t}),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the provider supports long prompt cache retention (prompt_cache_retention: \"24h\" or Anthropic-style cache_control.ttl: \"1h\", depending on format). Default: auto-detected from provider and URL.',\n\t\t}),\n\t\tvllmPriority: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription:\n\t\t\t\t\t\"vLLM scheduler priority sent as the top-level priority request field. Lower values are handled earlier and the server default is 0. Only meaningful with --scheduling-policy priority. Off by default and not set on the generated catalog.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"Compatibility settings for OpenAI-compatible completions APIs. Use this to override URL-based auto-detection for custom providers.\",\n\t\tadditionalProperties: true,\n\t},\n);\n\nexport const OpenAIResponsesCompatSchema = Type.Object(\n\t{\n\t\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the provider supports the developer role instead of system.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts developer or system messages after the conversation has started. When false, later system messages are folded into the leading system message. The generated catalog enables this for verified models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\t\tdescription:\n\t\t\t\t\"Session-affinity header format. openai sends session_id and x-client-request-id; openai-nosession sends x-client-request-id; openrouter sends x-session-id. Does not affect prompt_cache_key. Default: auto-detected.\",\n\t\t}),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the provider supports long prompt cache retention. This uses prompt_cache_options.ttl: \"30m\" on GPT-5.6+ and prompt_cache_retention: \"24h\" on earlier models.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports strict JSON-schema function tools. Defaults are API-specific; generated OpenAI models enable it explicitly.\",\n\t\t}),\n\t\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to emit OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. The generated catalog enables this for capable models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsAdditionalTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model supports message-anchored additional_tools input items.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsToolSearch: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model supports client-executed tool search for transcript-anchored additions.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsExplicitPromptCacheMode: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model accepts prompt_cache_options. Older OpenAI models reject the parameter.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether thinking level changes are sent as configuration_update input items instead of changing reasoning.effort, so a change keeps the prompt cache. Only used by the openai-responses API, and ignored with Sign in with ChatGPT on the openai provider.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMaxOutputTokens: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider accepts max_output_tokens. Some Codex-protocol gateways reject it.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t},\n\t{ description: \"Compatibility settings for OpenAI Responses APIs.\", additionalProperties: true },\n);\n\nexport const AnthropicMessagesCompatSchema = Type.Object(\n\t{\n\t\tsupportsEagerToolInputStreaming: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider accepts per-tool eager_input_streaming. When false, the Anthropic provider omits tools[].eager_input_streaming and sends the legacy fine-grained-tool-streaming-2025-05-14 beta header for tool-enabled requests.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the provider supports Anthropic long cache retention through cache_control.ttl.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to send x-session-affinity from options.sessionId when caching is enabled. Required for providers like Fireworks that use session affinity for prompt cache routing; requests to the same replica maximize cache hits. Default: true for OpenRouter endpoints, false otherwise.\",\n\t\t}),\n\t\tsessionAffinityFormat: Type.Optional(\n\t\t\tType.Literal(\"openrouter\", {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Session-affinity format. openrouter sends x-session-id; when unset, sends x-session-affinity.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsCacheControlOnTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports Anthropic-style cache_control markers on tool definitions. When false, cache_control is omitted from tool parameters. Some Anthropic-compatible providers, such as Fireworks, do not support this field on tools and may reject or ignore it.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsTemperature: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the model accepts the Anthropic temperature request field. Claude Opus 4.7+ rejects non-default values.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tforceAdaptiveThinking: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether to force adaptive thinking (thinking.type: adaptive plus output_config.effort) regardless of model ID. Built-in models that require adaptive thinking set this in generated metadata. Custom Anthropic-compatible providers can set this to true for any model whose upstream requires the adaptive format. Set false to opt out on overridden built-in models.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tallowEmptySignature: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether to replay empty thinking signatures instead of converting thinking to text.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsStrictTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports Anthropic strict tool schemas. Generated Anthropic models enable it explicitly.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the exact model transport supports effort-only system messages and thinking binding controls.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system-role messages inside the conversation. When false, later system messages are folded into the top-level system prompt.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoToolChanges: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the exact model accepts mid-conversation tool_addition and tool_removal blocks. Requires supportsMidConvoSystemMessages.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tallowedFallbackModels: Type.Optional(\n\t\t\tType.Array(AnthropicAllowedFallbackModelSchema, {\n\t\t\t\tmaxItems: 3,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Models Anthropic accepts for server-side refusal fallback, with local pricing metadata for returned fallback responses. When absent or empty, callers must omit fallbacks; Anthropic rejects the field for models with no permitted fallback targets.\",\n\t\t\t}),\n\t\t),\n\t\tenforcesPreservedThinkingBinding: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether the model runs the Anthropic preserved-thinking conversation check, which rejects a request whose system prompt, tools, or earlier messages changed since a replayed thinking block was produced. When true, the provider sends the thinking-binding-controls-2026-08-01 beta header and thinking.block_binding.prefix_mismatch_behavior: \"drop_block\", so a changed prefix drops the affected thinking blocks instead of failing the request.',\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tdelegatesThinkingModelBinding: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the API adjudicates thinking-block model binding itself, always dropping a block the target model cannot read. When true, an assistant turn produced by a different model on the same provider and API replays its signed thinking and redacted_thinking blocks unchanged instead of being rewritten into plain text.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (tool_choice \"any\" or a specific tool). When false, the provider rejects a forced choice with an error instead of sending a request the model is guaranteed to refuse. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for Anthropic Messages-compatible APIs.\", additionalProperties: true },\n);\n\nexport const BedrockCompatSchema = Type.Object(\n\t{\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the model supports Bedrock strict tool schemas.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (toolChoice \"any\" or a specific tool). When false, the provider rejects a forced choice with an error instead of sending a request that is guaranteed to fail. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsTemperature: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the model accepts inferenceConfig.temperature. When false, the provider omits the field.\",\n\t\t\tdefault: true,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for Amazon Bedrock models.\", additionalProperties: true },\n);\n\nexport const MistralConversationsCompatSchema = Type.Object(\n\t{\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system messages after the conversation has started. When false, later system messages are folded into the leading system message.\",\n\t\t\tdefault: false,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for the Mistral chat API.\", additionalProperties: true },\n);\n\nconst ProviderCompatPropertyOverrides = {\n\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\tdescription: \"Whether the provider supports the developer role instead of system. Defaults are API-specific.\",\n\t}),\n\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the exact model accepts system or developer messages after the conversation has started. When false, later system messages are folded into the leading system message.\",\n\t\tdefault: false,\n\t}),\n\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\tdescription: \"Session-affinity header format. Defaults are API-specific or auto-detected.\",\n\t}),\n\tsupportsMidConvoEffort: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether thinking level changes are sent inside the conversation instead of changing the request's effort, so a change keeps the prompt cache. Used by the anthropic-messages and openai-responses APIs.\",\n\t\tdefault: false,\n\t}),\n\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the provider supports long prompt cache retention. Defaults are API-specific or auto-detected.\",\n\t}),\n\tsupportsStrictMode: optionalCompatBoolean({\n\t\tdescription: \"Whether the provider supports strict tool schemas. Defaults are API-specific.\",\n\t}),\n\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the provider supports OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools.\",\n\t\tdefault: false,\n\t}),\n\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\tdescription: \"Whether to send session-affinity data from options.sessionId. Defaults are API-specific.\",\n\t}),\n\tsupportsTemperature: optionalCompatBoolean({\n\t\tdescription: \"Whether the model accepts the temperature request field. Defaults to true.\",\n\t\tdefault: true,\n\t}),\n\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t'Whether the model accepts forced tool use. When false, the provider rejects a forced choice with an error. \"auto\" and \"none\" are never altered. Defaults to true.',\n\t\tdefault: true,\n\t}),\n} satisfies TProperties;\n\ntype UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (\n\tvalue: infer Intersection,\n) => void\n\t? Intersection\n\t: never;\n\ntype MergedCompatProperties<PropertyGroups extends readonly TProperties[], Overrides extends TProperties> = Omit<\n\tUnionToIntersection<PropertyGroups[number]>,\n\tkeyof Overrides\n> &\n\tOverrides;\n\n/**\n * Provider-level models.json compatibility is API-agnostic, so it needs one superset. Every\n * duplicate property requires explicit generic metadata, while API-specific schemas retain their\n * own defaults and descriptions.\n */\nfunction mergeCompatProperties<\n\tconst PropertyGroups extends readonly TProperties[],\n\tconst Overrides extends TProperties,\n>(propertyGroups: PropertyGroups, overrides: Overrides): MergedCompatProperties<PropertyGroups, Overrides> {\n\tconst merged: TProperties = {};\n\tconst duplicateNames = new Set<string>();\n\n\tfor (const properties of propertyGroups) {\n\t\tfor (const [name, schema] of Object.entries(properties)) {\n\t\t\tif (merged[name] !== undefined) {\n\t\t\t\tduplicateNames.add(name);\n\t\t\t\tif (!(name in overrides)) {\n\t\t\t\t\tthrow new Error(`Duplicate compatibility schema property requires an override: ${name}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmerged[name] = schema;\n\t\t}\n\t}\n\n\tfor (const name of Object.keys(overrides)) {\n\t\tif (!duplicateNames.has(name)) {\n\t\t\tthrow new Error(`Compatibility schema override does not resolve a duplicate property: ${name}`);\n\t\t}\n\t}\n\n\treturn { ...merged, ...overrides } as MergedCompatProperties<PropertyGroups, Overrides>;\n}\n\nconst CompatSchemasByApi = {\n\t\"openai-completions\": OpenAICompletionsCompatSchema,\n\t\"openai-responses\": OpenAIResponsesCompatSchema,\n\t\"anthropic-messages\": AnthropicMessagesCompatSchema,\n\t\"bedrock-converse-stream\": BedrockCompatSchema,\n\t\"mistral-conversations\": MistralConversationsCompatSchema,\n} as const;\n\nconst ProviderCompatProperties = mergeCompatProperties(\n\tObject.values(CompatSchemasByApi).map((schema) => schema.properties),\n\tProviderCompatPropertyOverrides,\n);\n\nexport const ProviderCompatSchema = Type.Object(ProviderCompatProperties, {\n\tdescription: \"Provider and model compatibility overrides.\",\n\tadditionalProperties: true,\n});\n\nexport type ChatTemplateKwargValue = Static<typeof ChatTemplateKwargValueSchema>;\n/** Top-level request field used to cap reasoning tokens on OpenAI-compatible servers. */\nexport type ThinkingTokenBudgetField = Static<typeof ThinkingTokenBudgetFieldSchema>;\nexport type SessionAffinityFormat = Static<typeof SessionAffinityFormatSchema>;\n/** OpenRouter provider routing preferences. */\nexport interface OpenRouterRouting extends Static<typeof OpenRouterRoutingSchema> {}\n/** Vercel AI Gateway routing preferences. */\nexport interface VercelGatewayRouting extends Static<typeof VercelGatewayRoutingSchema> {}\n/** An Anthropic server-side refusal fallback model with local pricing metadata. */\nexport interface AnthropicAllowedFallbackModel extends Static<typeof AnthropicAllowedFallbackModelSchema> {}\n\n/** Compatibility settings for OpenAI-compatible completions APIs. */\nexport interface OpenAICompletionsCompat extends Static<typeof OpenAICompletionsCompatSchema> {}\n/** Compatibility settings for OpenAI Responses APIs. */\nexport interface OpenAIResponsesCompat extends Static<typeof OpenAIResponsesCompatSchema> {}\n/** Compatibility settings for Anthropic Messages-compatible APIs. */\nexport interface AnthropicMessagesCompat extends Static<typeof AnthropicMessagesCompatSchema> {}\n/** Compatibility settings for Amazon Bedrock models. */\nexport interface BedrockCompat extends Static<typeof BedrockCompatSchema> {}\n/** Compatibility settings for the Mistral chat API. */\nexport interface MistralConversationsCompat extends Static<typeof MistralConversationsCompatSchema> {}\n"]}
1
+ {"version":3,"file":"compat-schema.js","sourceRoot":"","sources":["../../src/providers/compat-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,IAAI,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,SAAS,qBAAqB,CAAC,OAAwB;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,OAAO,CAA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,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAClF,+BAA+B,CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE;IACzE,WAAW,EAAE,6CAA6C;IAC1D,oBAAoB,EAAE,IAAI;CAC1B,CAAC,CAAC","sourcesContent":["import { type Static, type TProperties, type TSchemaOptions, Type } from \"typebox\";\nimport { ModelCostSchema } from \"./model-schema.ts\";\n\nfunction sessionAffinityFormat(options?: TSchemaOptions) {\n\treturn Type.Union([Type.Literal(\"openai\"), Type.Literal(\"openai-nosession\"), Type.Literal(\"openrouter\")], options);\n}\n\nexport const SessionAffinityFormatSchema = sessionAffinityFormat({\n\tdescription: \"Session-affinity header format used to route related requests consistently.\",\n});\n\nfunction thinkingTokenBudgetField(options?: TSchemaOptions) {\n\treturn Type.Union(\n\t\t[Type.Literal(\"thinking_token_budget\"), Type.Literal(\"thinking_budget\"), Type.Literal(\"thinking_budget_tokens\")],\n\t\toptions,\n\t);\n}\n\nexport const ThinkingTokenBudgetFieldSchema = thinkingTokenBudgetField({\n\tdescription:\n\t\t'Top-level request field name used by OpenAI-compatible endpoints to cap reasoning tokens. \"thinking_token_budget\" is used by vLLM, \"thinking_budget\" by Qwen, DashScope, or SGLang, and \"thinking_budget_tokens\" by llama.cpp.',\n});\n\nexport const ChatTemplateKwargValueSchema = Type.Union([\n\tType.String(),\n\tType.Number(),\n\tType.Boolean(),\n\tType.Null(),\n\tType.Object({\n\t\t$var: Type.Union([\n\t\t\tType.Literal(\"thinking.enabled\"),\n\t\t\tType.Literal(\"thinking.effort\"),\n\t\t\tType.Literal(\"thinking.budget\"),\n\t\t]),\n\t\tomitWhenOff: Type.Optional(Type.Boolean()),\n\t}),\n]);\n\nfunction percentileCutoffs(metric: string) {\n\treturn Type.Object({\n\t\tp50: Type.Optional(Type.Number({ description: `${metric} at the 50th percentile.` })),\n\t\tp75: Type.Optional(Type.Number({ description: `${metric} at the 75th percentile.` })),\n\t\tp90: Type.Optional(Type.Number({ description: `${metric} at the 90th percentile.` })),\n\t\tp99: Type.Optional(Type.Number({ description: `${metric} at the 99th percentile.` })),\n\t});\n}\n\nexport const OpenRouterRoutingSchema = Type.Object(\n\t{\n\t\tallow_fallbacks: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to allow backup providers to serve requests.\", default: true }),\n\t\t),\n\t\trequire_parameters: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether to filter providers to only those that support all parameters in the request.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tdata_collection: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"deny\"), Type.Literal(\"allow\")], {\n\t\t\t\tdescription:\n\t\t\t\t\t'Data collection setting. \"allow\": allow providers that may store or train on data. \"deny\": only use providers that do not collect user data.',\n\t\t\t\tdefault: \"allow\",\n\t\t\t}),\n\t\t),\n\t\tzdr: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.\" }),\n\t\t),\n\t\tenforce_distillable_text: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether to restrict routing to only models that allow text distillation.\" }),\n\t\t),\n\t\torder: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t\"An ordered list of provider names or slugs to try in sequence, falling back to the next if unavailable.\",\n\t\t\t}),\n\t\t),\n\t\tonly: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription: \"List of provider names or slugs to exclusively allow for this request.\",\n\t\t\t}),\n\t\t),\n\t\tignore: Type.Optional(\n\t\t\tType.Array(Type.String(), { description: \"List of provider names or slugs to skip for this request.\" }),\n\t\t),\n\t\tquantizations: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t'A list of quantization levels to filter providers by, for example [\"fp16\", \"bf16\", \"fp8\", \"fp6\", \"int8\", \"int4\", \"fp4\", \"fp32\"].',\n\t\t\t}),\n\t\t),\n\t\tsort: Type.Optional(\n\t\t\tType.Union(\n\t\t\t\t[\n\t\t\t\t\tType.String(),\n\t\t\t\t\tType.Object({\n\t\t\t\t\t\tby: Type.Optional(\n\t\t\t\t\t\t\tType.String({ description: 'The sorting metric, such as \"price\", \"throughput\", or \"latency\".' }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tpartition: Type.Optional(\n\t\t\t\t\t\t\tType.Union([Type.String(), Type.Null()], {\n\t\t\t\t\t\t\t\tdescription: 'Partitioning strategy: \"model\" or \"none\".',\n\t\t\t\t\t\t\t\tdefault: \"model\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Sorting strategy. Can be a string such as \"price\", \"throughput\", or \"latency\", or an object.',\n\t\t\t\t},\n\t\t\t),\n\t\t),\n\t\tmax_price: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tprompt: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per million prompt tokens.\" }),\n\t\t\t\t\t),\n\t\t\t\t\tcompletion: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per million completion tokens.\" }),\n\t\t\t\t\t),\n\t\t\t\t\timage: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: \"Price per image.\" })),\n\t\t\t\t\taudio: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per audio unit.\" }),\n\t\t\t\t\t),\n\t\t\t\t\trequest: Type.Optional(\n\t\t\t\t\t\tType.Union([Type.Number(), Type.String()], { description: \"Price per request.\" }),\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{ description: \"Maximum price per million tokens in USD.\" },\n\t\t\t),\n\t\t),\n\t\tpreferred_min_throughput: Type.Optional(\n\t\t\tType.Union([Type.Number(), percentileCutoffs(\"Minimum tokens per second\")], {\n\t\t\t\tdescription: \"Preferred minimum throughput in tokens per second. A number applies to p50.\",\n\t\t\t}),\n\t\t),\n\t\tpreferred_max_latency: Type.Optional(\n\t\t\tType.Union([Type.Number(), percentileCutoffs(\"Maximum latency in seconds\")], {\n\t\t\t\tdescription: \"Preferred maximum latency in seconds. A number applies to p50.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"OpenRouter provider routing preferences. Controls which upstream providers OpenRouter routes requests to. Sent as the provider field in the OpenRouter API request body. See https://openrouter.ai/docs/guides/routing/provider-selection.\",\n\t},\n);\n\nexport const VercelGatewayRoutingSchema = Type.Object(\n\t{\n\t\tonly: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription:\n\t\t\t\t\t'List of provider slugs to exclusively use for this request, for example [\"bedrock\", \"anthropic\"].',\n\t\t\t}),\n\t\t),\n\t\torder: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription: 'List of provider slugs to try in order, for example [\"anthropic\", \"openai\"].',\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"Vercel AI Gateway routing preferences. Controls which upstream providers the gateway routes requests to. See https://vercel.com/docs/ai-gateway/models-and-providers/provider-options.\",\n\t},\n);\n\nexport const AnthropicAllowedFallbackModelSchema = Type.Object(\n\t{\n\t\tprovider: Type.String({ minLength: 1 }),\n\t\tmodel: Type.String({ minLength: 1 }),\n\t\tcost: ModelCostSchema,\n\t},\n\t{ description: \"An Anthropic server-side refusal fallback model with local pricing metadata.\" },\n);\n\nfunction optionalCompatBoolean(options?: TSchemaOptions) {\n\treturn Type.Optional(Type.Boolean(options));\n}\n\nfunction optionalSessionAffinityFormat(options?: TSchemaOptions) {\n\treturn Type.Optional(sessionAffinityFormat(options));\n}\n\nexport const OpenAICompletionsCompatSchema = Type.Object(\n\t{\n\t\tsupportsStore: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider supports the store field. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports the developer role instead of system. Default: auto-detected from URL.\",\n\t\t}),\n\t\tsupportsReasoningEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider supports reasoning_effort. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsTemperature: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the model accepts the temperature request field. When false, the provider omits temperature and also strips temperature, top_p, and top_k from samplingParams.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (tool_choice \"required\" or a specific function). When false, the provider rejects a forced choice with an error instead of sending a request the model cannot honor. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsUsageInStreaming: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports stream_options.include_usage for token usage in streaming responses.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsFinishReason: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether streamed responses include finish_reason. When false, pi infers stop or toolUse when the stream ends.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tmaxTokensField: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"max_completion_tokens\"), Type.Literal(\"max_tokens\")], {\n\t\t\t\tdescription: \"Which field to use for max tokens. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresToolResultName: Type.Optional(\n\t\t\tType.Boolean({ description: \"Whether tool results require the name field. Default: auto-detected from URL.\" }),\n\t\t),\n\t\trequiresAssistantAfterToolResult: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresThinkingAsText: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\trequiresReasoningContentOnAssistantMessages: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether all replayed assistant messages must include an empty reasoning_content field when reasoning is enabled. Default: auto-detected from URL.\",\n\t\t\t}),\n\t\t),\n\t\tthinkingFormat: Type.Optional(\n\t\t\tType.Union(\n\t\t\t\t[\n\t\t\t\t\tType.Literal(\"openai\"),\n\t\t\t\t\tType.Literal(\"openrouter\"),\n\t\t\t\t\tType.Literal(\"deepseek\"),\n\t\t\t\t\tType.Literal(\"together\"),\n\t\t\t\t\tType.Literal(\"baseten\"),\n\t\t\t\t\tType.Literal(\"zai\"),\n\t\t\t\t\tType.Literal(\"qwen\"),\n\t\t\t\t\tType.Literal(\"chat-template\"),\n\t\t\t\t\tType.Literal(\"qwen-chat-template\"),\n\t\t\t\t\tType.Literal(\"string-thinking\"),\n\t\t\t\t\tType.Literal(\"ant-ling\"),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Format for reasoning or thinking parameters. When omitted, Pi auto-detects the format from the provider URL. \"openai\" uses reasoning_effort, \"openrouter\" uses reasoning.effort, \"deepseek\" uses thinking.type plus reasoning_effort when supported, \"together\" uses reasoning.enabled plus reasoning_effort when supported, \"baseten\" uses configurable chat_template_args plus reasoning_effort when supported, \"zai\" uses thinking.type, \"qwen\" uses top-level enable_thinking, \"qwen-chat-template\" uses chat_template_kwargs.enable_thinking and preserve_thinking, \"chat-template\" uses configurable chat_template_kwargs, \"string-thinking\" uses top-level thinking, and \"ant-ling\" uses reasoning.effort only when the mapped effort is non-null.',\n\t\t\t\t},\n\t\t\t),\n\t\t),\n\t\tchatTemplateKwargs: Type.Optional(\n\t\t\tType.Record(Type.String(), ChatTemplateKwargValueSchema, {\n\t\t\t\tdescription:\n\t\t\t\t\t'Kwargs sent as chat_template_kwargs when thinkingFormat is \"chat-template\". Use $var with \"thinking.enabled\", \"thinking.effort\", or \"thinking.budget\" for pi-controlled values.',\n\t\t\t}),\n\t\t),\n\t\tchatTemplateArgs: Type.Optional(\n\t\t\tType.Record(Type.String(), ChatTemplateKwargValueSchema, {\n\t\t\t\tdescription:\n\t\t\t\t\t'Arguments sent as chat_template_args when thinkingFormat is \"baseten\". Use $var with \"thinking.enabled\", \"thinking.effort\", or \"thinking.budget\" for pi-controlled values.',\n\t\t\t}),\n\t\t),\n\t\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\t\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n\t\tzaiToolStream: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether z.ai supports top-level tool_stream for streaming tool call deltas.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tthinkingTokenBudgetField: Type.Optional(\n\t\t\tthinkingTokenBudgetField({\n\t\t\t\tdescription:\n\t\t\t\t\t'Top-level request field used to cap reasoning tokens from thinkingBudgets. Reasoning and the answer share max_tokens on these endpoints. \"thinking_token_budget\" is vLLM, \"thinking_budget\" is Qwen, DashScope, or SGLang, and \"thinking_budget_tokens\" is llama.cpp. Off by default and not set on the generated catalog.',\n\t\t\t}),\n\t\t),\n\t\tsupportsThinkingTokenBudget: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t'Alias for thinkingTokenBudgetField: \"thinking_token_budget\" (vLLM). Prefer thinkingTokenBudgetField.',\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. The generated catalog enables this for capable models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system or developer messages after the conversation has started. When false, later system messages are folded into the leading system message. The generated catalog enables this for verified models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoToolAdditions: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether system messages can introduce additional tools mid-conversation. Requires supportsMidConvoSystemMessages. The generated catalog enables this for capable models.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports the strict field in tool definitions. Generated capable models enable it explicitly.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tcacheControlFormat: Type.Optional(\n\t\t\tType.Literal(\"anthropic\", {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Cache control convention for prompt caching. Anthropic applies cache_control markers to the system prompt, last tool definition, and last user, assistant, or tool-result text content.\",\n\t\t\t}),\n\t\t),\n\t\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to send session-affinity data from options.sessionId. Default: true for OpenRouter endpoints, false otherwise.\",\n\t\t}),\n\t\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\t\tdescription:\n\t\t\t\t\"Session-affinity header format. openai sends session_id, x-client-request-id, and x-session-affinity; openai-nosession sends x-client-request-id and x-session-affinity; openrouter sends x-session-id. Does not affect prompt_cache_key. Default: auto-detected.\",\n\t\t}),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the provider supports long prompt cache retention (prompt_cache_retention: \"24h\" or Anthropic-style cache_control.ttl: \"1h\", depending on format). Default: auto-detected from provider and URL.',\n\t\t}),\n\t\tvllmPriority: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription:\n\t\t\t\t\t\"vLLM scheduler priority sent as the top-level priority request field. Lower values are handled earlier and the server default is 0. Only meaningful with --scheduling-policy priority. Off by default and not set on the generated catalog.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{\n\t\tdescription:\n\t\t\t\"Compatibility settings for OpenAI-compatible completions APIs. Use this to override URL-based auto-detection for custom providers.\",\n\t\tadditionalProperties: true,\n\t},\n);\n\nexport const OpenAIResponsesCompatSchema = Type.Object(\n\t{\n\t\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the provider supports the developer role instead of system.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts developer or system messages after the conversation has started. When false, later system messages are folded into the leading system message. The generated catalog enables this for verified models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\t\tdescription:\n\t\t\t\t\"Session-affinity header format. openai sends session_id and x-client-request-id; openai-nosession sends x-client-request-id; openrouter sends x-session-id. Does not affect prompt_cache_key. Default: auto-detected.\",\n\t\t}),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the provider supports long prompt cache retention. This uses prompt_cache_options.ttl: \"30m\" on GPT-5.6+ and prompt_cache_retention: \"24h\" on earlier models.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the provider supports strict JSON-schema function tools. Defaults are API-specific; generated OpenAI models enable it explicitly.\",\n\t\t}),\n\t\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to emit OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools. The generated catalog enables this for capable models.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsAdditionalTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model supports message-anchored additional_tools input items.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsToolSearch: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model supports client-executed tool search for transcript-anchored additions.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsExplicitPromptCacheMode: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the model accepts prompt_cache_options. Older OpenAI models reject the parameter.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether thinking level changes are sent as configuration_update input items instead of changing reasoning.effort, so a change keeps the prompt cache. Only used by the openai-responses API, and ignored with Sign in with ChatGPT on the openai provider.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMaxOutputTokens: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether the provider accepts max_output_tokens. Some Codex-protocol gateways reject it.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t},\n\t{ description: \"Compatibility settings for OpenAI Responses APIs.\", additionalProperties: true },\n);\n\nexport const AnthropicMessagesCompatSchema = Type.Object(\n\t{\n\t\tsupportsEagerToolInputStreaming: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider accepts per-tool eager_input_streaming. When false, the Anthropic provider omits tools[].eager_input_streaming and sends the legacy fine-grained-tool-streaming-2025-05-14 beta header for tool-enabled requests.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the provider supports Anthropic long cache retention through cache_control.ttl.\",\n\t\t\tdefault: true,\n\t\t}),\n\t\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether to send x-session-affinity from options.sessionId when caching is enabled. Required for providers like Fireworks that use session affinity for prompt cache routing; requests to the same replica maximize cache hits. Default: true for OpenRouter endpoints, false otherwise.\",\n\t\t}),\n\t\tsessionAffinityFormat: Type.Optional(\n\t\t\tType.Literal(\"openrouter\", {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Session-affinity format. openrouter sends x-session-id; when unset, sends x-session-affinity.\",\n\t\t\t}),\n\t\t),\n\t\tsupportsCacheControlOnTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports Anthropic-style cache_control markers on tool definitions. When false, cache_control is omitted from tool parameters. Some Anthropic-compatible providers, such as Fireworks, do not support this field on tools and may reject or ignore it.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tsupportsTemperature: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the model accepts the Anthropic temperature request field. Claude Opus 4.7+ rejects non-default values.\",\n\t\t\t\tdefault: true,\n\t\t\t}),\n\t\t),\n\t\tforceAdaptiveThinking: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether to force adaptive thinking (thinking.type: adaptive plus output_config.effort) regardless of model ID. Built-in models that require adaptive thinking set this in generated metadata. Custom Anthropic-compatible providers can set this to true for any model whose upstream requires the adaptive format. Set false to opt out on overridden built-in models.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tallowEmptySignature: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Whether to replay empty thinking signatures instead of converting thinking to text.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsStrictTools: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the provider supports Anthropic strict tool schemas. Generated Anthropic models enable it explicitly.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoEffort: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the exact model transport supports effort-only system messages and thinking binding controls.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system-role messages inside the conversation. When false, later system messages are folded into the top-level system prompt.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsMidConvoToolChanges: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the exact model accepts mid-conversation tool_addition and tool_removal blocks. Requires supportsMidConvoSystemMessages.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tallowedFallbackModels: Type.Optional(\n\t\t\tType.Array(AnthropicAllowedFallbackModelSchema, {\n\t\t\t\tmaxItems: 3,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Models Anthropic accepts for server-side refusal fallback, with local pricing metadata for returned fallback responses. When absent or empty, callers must omit fallbacks; Anthropic rejects the field for models with no permitted fallback targets.\",\n\t\t\t}),\n\t\t),\n\t\tenforcesPreservedThinkingBinding: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether the model runs the Anthropic preserved-thinking conversation check, which rejects a request whose system prompt, tools, or earlier messages changed since a replayed thinking block was produced. When true, the provider sends the thinking-binding-controls-2026-08-01 beta header and thinking.block_binding.prefix_mismatch_behavior: \"drop_block\", so a changed prefix drops the affected thinking blocks instead of failing the request.',\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tdelegatesThinkingModelBinding: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Whether the API adjudicates thinking-block model binding itself, always dropping a block the target model cannot read. When true, an assistant turn produced by a different model on the same provider and API replays its signed thinking and redacted_thinking blocks unchanged instead of being rewritten into plain text.\",\n\t\t\t\tdefault: false,\n\t\t\t}),\n\t\t),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (tool_choice \"any\" or a specific tool). When false, the provider rejects a forced choice with an error instead of sending a request the model is guaranteed to refuse. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for Anthropic Messages-compatible APIs.\", additionalProperties: true },\n);\n\nexport const BedrockCompatSchema = Type.Object(\n\t{\n\t\tsupportsStrictMode: optionalCompatBoolean({\n\t\t\tdescription: \"Whether the model supports Bedrock strict tool schemas.\",\n\t\t\tdefault: false,\n\t\t}),\n\t\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t'Whether the model accepts forced tool use (toolChoice \"any\" or a specific tool). When false, the provider rejects a forced choice with an error instead of sending a request that is guaranteed to fail. \"auto\" and \"none\" are never altered.',\n\t\t\tdefault: true,\n\t\t}),\n\t\tsupportsTemperature: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the model accepts inferenceConfig.temperature. When false, the provider omits the field.\",\n\t\t\tdefault: true,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for Amazon Bedrock models.\", additionalProperties: true },\n);\n\nexport const MistralConversationsCompatSchema = Type.Object(\n\t{\n\t\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\t\tdescription:\n\t\t\t\t\"Whether the exact model accepts system messages after the conversation has started. When false, later system messages are folded into the leading system message.\",\n\t\t\tdefault: false,\n\t\t}),\n\t},\n\t{ description: \"Compatibility settings for the Mistral chat API.\", additionalProperties: true },\n);\n\nconst ProviderCompatPropertyOverrides = {\n\tsupportsDeveloperRole: optionalCompatBoolean({\n\t\tdescription: \"Whether the provider supports the developer role instead of system. Defaults are API-specific.\",\n\t}),\n\tsupportsMidConvoSystemMessages: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the exact model accepts system or developer messages after the conversation has started. When false, later system messages are folded into the leading system message.\",\n\t\tdefault: false,\n\t}),\n\tsessionAffinityFormat: optionalSessionAffinityFormat({\n\t\tdescription: \"Session-affinity header format. Defaults are API-specific or auto-detected.\",\n\t}),\n\tsupportsMidConvoEffort: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether thinking level changes are sent inside the conversation instead of changing the request's effort, so a change keeps the prompt cache. Used by the anthropic-messages and openai-responses APIs.\",\n\t\tdefault: false,\n\t}),\n\tsupportsLongCacheRetention: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the provider supports long prompt cache retention. Defaults are API-specific or auto-detected.\",\n\t}),\n\tsupportsStrictMode: optionalCompatBoolean({\n\t\tdescription: \"Whether the provider supports strict tool schemas. Defaults are API-specific.\",\n\t}),\n\tsupportsOpenAIGrammarTools: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t\"Whether the provider supports OpenAI custom tools with Lark or regex grammar formats. When false, grammar-constrained tools fall back to normal function tools.\",\n\t\tdefault: false,\n\t}),\n\tsendSessionAffinityHeaders: optionalCompatBoolean({\n\t\tdescription: \"Whether to send session-affinity data from options.sessionId. Defaults are API-specific.\",\n\t}),\n\tsupportsTemperature: optionalCompatBoolean({\n\t\tdescription: \"Whether the model accepts the temperature request field. Defaults to true.\",\n\t\tdefault: true,\n\t}),\n\tsupportsForcedToolChoice: optionalCompatBoolean({\n\t\tdescription:\n\t\t\t'Whether the model accepts forced tool use. When false, the provider rejects a forced choice with an error. \"auto\" and \"none\" are never altered. Defaults to true.',\n\t\tdefault: true,\n\t}),\n} satisfies TProperties;\n\ntype UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (\n\tvalue: infer Intersection,\n) => void\n\t? Intersection\n\t: never;\n\ntype MergedCompatProperties<PropertyGroups extends readonly TProperties[], Overrides extends TProperties> = Omit<\n\tUnionToIntersection<PropertyGroups[number]>,\n\tkeyof Overrides\n> &\n\tOverrides;\n\n/**\n * Provider-level models.json compatibility is API-agnostic, so it needs one superset. Every\n * duplicate property requires explicit generic metadata, while API-specific schemas retain their\n * own defaults and descriptions.\n */\nfunction mergeCompatProperties<\n\tconst PropertyGroups extends readonly TProperties[],\n\tconst Overrides extends TProperties,\n>(propertyGroups: PropertyGroups, overrides: Overrides): MergedCompatProperties<PropertyGroups, Overrides> {\n\tconst merged: TProperties = {};\n\tconst duplicateNames = new Set<string>();\n\n\tfor (const properties of propertyGroups) {\n\t\tfor (const [name, schema] of Object.entries(properties)) {\n\t\t\tif (merged[name] !== undefined) {\n\t\t\t\tduplicateNames.add(name);\n\t\t\t\tif (!(name in overrides)) {\n\t\t\t\t\tthrow new Error(`Duplicate compatibility schema property requires an override: ${name}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmerged[name] = schema;\n\t\t}\n\t}\n\n\tfor (const name of Object.keys(overrides)) {\n\t\tif (!duplicateNames.has(name)) {\n\t\t\tthrow new Error(`Compatibility schema override does not resolve a duplicate property: ${name}`);\n\t\t}\n\t}\n\n\treturn { ...merged, ...overrides } as MergedCompatProperties<PropertyGroups, Overrides>;\n}\n\nexport const CompatSchemasByApi = {\n\t\"openai-completions\": OpenAICompletionsCompatSchema,\n\t\"openai-responses\": OpenAIResponsesCompatSchema,\n\t\"azure-openai-responses\": OpenAIResponsesCompatSchema,\n\t\"openai-codex-responses\": OpenAIResponsesCompatSchema,\n\t\"anthropic-messages\": AnthropicMessagesCompatSchema,\n\t\"bedrock-converse-stream\": BedrockCompatSchema,\n\t\"mistral-conversations\": MistralConversationsCompatSchema,\n} as const;\n\nconst ProviderCompatProperties = mergeCompatProperties(\n\t[...new Set(Object.values(CompatSchemasByApi))].map((schema) => schema.properties),\n\tProviderCompatPropertyOverrides,\n);\n\nexport const ProviderCompatSchema = Type.Object(ProviderCompatProperties, {\n\tdescription: \"Provider and model compatibility overrides.\",\n\tadditionalProperties: true,\n});\n\nexport type ChatTemplateKwargValue = Static<typeof ChatTemplateKwargValueSchema>;\n/** Top-level request field used to cap reasoning tokens on OpenAI-compatible servers. */\nexport type ThinkingTokenBudgetField = Static<typeof ThinkingTokenBudgetFieldSchema>;\nexport type SessionAffinityFormat = Static<typeof SessionAffinityFormatSchema>;\n/** OpenRouter provider routing preferences. */\nexport interface OpenRouterRouting extends Static<typeof OpenRouterRoutingSchema> {}\n/** Vercel AI Gateway routing preferences. */\nexport interface VercelGatewayRouting extends Static<typeof VercelGatewayRoutingSchema> {}\n/** An Anthropic server-side refusal fallback model with local pricing metadata. */\nexport interface AnthropicAllowedFallbackModel extends Static<typeof AnthropicAllowedFallbackModelSchema> {}\n\n/** Compatibility settings for OpenAI-compatible completions APIs. */\nexport interface OpenAICompletionsCompat extends Static<typeof OpenAICompletionsCompatSchema> {}\n/** Compatibility settings for OpenAI Responses APIs. */\nexport interface OpenAIResponsesCompat extends Static<typeof OpenAIResponsesCompatSchema> {}\n/** Compatibility settings for Anthropic Messages-compatible APIs. */\nexport interface AnthropicMessagesCompat extends Static<typeof AnthropicMessagesCompatSchema> {}\n/** Compatibility settings for Amazon Bedrock models. */\nexport interface BedrockCompat extends Static<typeof BedrockCompatSchema> {}\n/** Compatibility settings for the Mistral chat API. */\nexport interface MistralConversationsCompat extends Static<typeof MistralConversationsCompatSchema> {}\n"]}