@code-yeongyu/senpi-ai 2026.9.21 → 2026.9.22-3
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.
- package/README.md +4 -4
- package/dist/api/azure-openai-responses.js +1 -1
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/openai-codex-responses/fallback-state.d.ts +3 -3
- package/dist/api/openai-codex-responses/fallback-state.d.ts.map +1 -1
- package/dist/api/openai-codex-responses/fallback-state.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts +5 -5
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +24 -66
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-prompt-cache.d.ts +1 -1
- package/dist/api/openai-prompt-cache.d.ts.map +1 -1
- package/dist/api/openai-prompt-cache.js +1 -1
- package/dist/api/openai-prompt-cache.js.map +1 -1
- package/dist/api/openai-responses-shared.js +1 -1
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +19 -28
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/websocket-transport-failure.d.ts +40 -0
- package/dist/api/websocket-transport-failure.d.ts.map +1 -0
- package/dist/api/websocket-transport-failure.js +102 -0
- package/dist/api/websocket-transport-failure.js.map +1 -0
- package/dist/auth/oauth/{openai-codex.d.ts → chatgpt-subscription.d.ts} +3 -3
- package/dist/auth/oauth/chatgpt-subscription.d.ts.map +1 -0
- package/dist/auth/oauth/{openai-codex.js → chatgpt-subscription.js} +35 -35
- package/dist/auth/oauth/chatgpt-subscription.js.map +1 -0
- package/dist/auth/oauth/kimi-coding.d.ts +4 -3
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/dist/auth/oauth/kimi-coding.js +28 -14
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/auth/oauth/kimi-region.d.ts +44 -0
- package/dist/auth/oauth/kimi-region.d.ts.map +1 -0
- package/dist/auth/oauth/kimi-region.js +120 -0
- package/dist/auth/oauth/kimi-region.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +2 -2
- package/dist/auth/oauth/load.d.ts.map +1 -1
- package/dist/auth/oauth/load.js +4 -3
- package/dist/auth/oauth/load.js.map +1 -1
- package/dist/auth/pool/failover.d.ts +2 -2
- package/dist/auth/pool/failover.d.ts.map +1 -1
- package/dist/auth/pool/failover.js +2 -2
- package/dist/auth/pool/failover.js.map +1 -1
- package/dist/auth/pool/slots.d.ts +10 -0
- package/dist/auth/pool/slots.d.ts.map +1 -1
- package/dist/auth/pool/slots.js +41 -17
- package/dist/auth/pool/slots.js.map +1 -1
- package/dist/bun-oauth.js +2 -2
- package/dist/bun-oauth.js.map +1 -1
- package/dist/compat.d.ts +1 -0
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +1 -0
- package/dist/compat.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy-provider-ids.d.ts +28 -0
- package/dist/legacy-provider-ids.d.ts.map +1 -0
- package/dist/legacy-provider-ids.js +82 -0
- package/dist/legacy-provider-ids.js.map +1 -0
- package/dist/models.generated.d.ts +2 -2
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +2 -2
- package/dist/models.generated.js.map +1 -1
- package/dist/providers/all.d.ts.map +1 -1
- package/dist/providers/all.js +2 -2
- package/dist/providers/all.js.map +1 -1
- package/dist/providers/chatgpt-subscription.d.ts +3 -0
- package/dist/providers/chatgpt-subscription.d.ts.map +1 -0
- package/dist/providers/chatgpt-subscription.js +22 -0
- package/dist/providers/chatgpt-subscription.js.map +1 -0
- package/dist/providers/chatgpt-subscription.models.d.ts +4 -0
- package/dist/providers/chatgpt-subscription.models.d.ts.map +1 -0
- package/dist/providers/chatgpt-subscription.models.js +6 -0
- package/dist/providers/chatgpt-subscription.models.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/chatgpt-subscription.json +1 -0
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/venice.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/providers/data/xiaomi.json +1 -1
- package/dist/providers/kimi-coding-auth.d.ts +9 -0
- package/dist/providers/kimi-coding-auth.d.ts.map +1 -0
- package/dist/providers/kimi-coding-auth.js +43 -0
- package/dist/providers/kimi-coding-auth.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +3 -2
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/{openai-codex-auth.d.ts → chatgpt-subscription-auth.d.ts} +3 -3
- package/dist/utils/chatgpt-subscription-auth.d.ts.map +1 -0
- package/dist/utils/{openai-codex-auth.js → chatgpt-subscription-auth.js} +4 -4
- package/dist/utils/chatgpt-subscription-auth.js.map +1 -0
- package/dist/utils/provider-failure-description.d.ts +19 -0
- package/dist/utils/provider-failure-description.d.ts.map +1 -0
- package/dist/utils/provider-failure-description.js +63 -0
- package/dist/utils/provider-failure-description.js.map +1 -0
- package/dist/utils/retry-profile/classifiers.d.ts.map +1 -1
- package/dist/utils/retry-profile/classifiers.js +5 -1
- package/dist/utils/retry-profile/classifiers.js.map +1 -1
- package/dist/utils/retry.d.ts +17 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +22 -1
- package/dist/utils/retry.js.map +1 -1
- package/package.json +3 -3
- package/dist/auth/oauth/openai-codex.d.ts.map +0 -1
- package/dist/auth/oauth/openai-codex.js.map +0 -1
- package/dist/providers/data/openai-codex.json +0 -1
- package/dist/providers/openai-codex.d.ts +0 -3
- package/dist/providers/openai-codex.d.ts.map +0 -1
- package/dist/providers/openai-codex.js +0 -22
- package/dist/providers/openai-codex.js.map +0 -1
- package/dist/providers/openai-codex.models.d.ts +0 -4
- package/dist/providers/openai-codex.models.d.ts.map +0 -1
- package/dist/providers/openai-codex.models.js +0 -6
- package/dist/providers/openai-codex.models.js.map +0 -1
- package/dist/utils/openai-codex-auth.d.ts.map +0 -1
- package/dist/utils/openai-codex-auth.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses-shared.js","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AAgBA,OAAO,EACN,wBAAwB,EAExB,4BAA4B,EAC5B,oBAAoB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiB7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACN,+BAA+B,EAE/B,mBAAmB,EACnB,2BAA2B,EAC3B,iCAAiC,EACjC,+BAA+B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,gFAAgF;AAChF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EAAE,MAAM,EAAE,CAAC;QAC/B,KAAK,YAAY;YAChB,IAAI,gBAAgB,KAAK,mBAAmB,EAAE,CAAC;gBAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;YACjC,CAAC;YACD,OAAO;gBACN,UAAU,EAAE,OAAO;gBACnB,YAAY,EAAE,gBAAgB;oBAC7B,CAAC,CAAC,wBAAwB,gBAAgB,EAAE;oBAC5C,CAAC,CAAC,+CAA+C;aAClD,CAAC;QACH,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACf,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QAChC,0BAA0B;QAC1B,KAAK,aAAa,CAAC;QACnB,KAAK,QAAQ;YACZ,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAC/B,SAAS,CAAC;YACT,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type OpenAI from \"openai\";\nimport type {\n\tResponseInputItem as OpenAIResponseInputItem,\n\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseFunctionCallOutputItemList,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputText,\n\tResponseOutputItem,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n\tResponseStreamEvent,\n\tResponseToolSearchOutputItemParam,\n} from \"openai/resources/responses/responses.js\";\nimport {\n\tCONTEXT_PROVENANCE_FIELD,\n\ttype ContextProvenance,\n\tcontextProvenanceFingerprint,\n\tgetContextProvenance,\n} from \"../context-provenance.ts\";\nimport { calculateCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tImageContent,\n\tModel,\n\tProviderNativeContent,\n\tStopReason,\n\tTextContent,\n\tTextSignatureV1,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport type { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { shortHash } from \"../utils/hash.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport {\n\tappendGrammarToolInputJsonDelta,\n\ttype GrammarToolInputJsonBuffer,\n\tgetGrammarToolInput,\n\tgetJsonSchemaToolParameters,\n\tresolveGrammarConstrainedSampling,\n\tresolveJsonSchemaStrictSampling,\n} from \"./constrained-sampling.ts\";\nimport { withResponsesCompletionGrace } from \"./responses-completion-grace.ts\";\nimport { transformMessages } from \"./transform-messages.ts\";\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nfunction encodeTextSignatureV1(id: string, phase?: TextSignatureV1[\"phase\"]): string {\n\tconst payload: TextSignatureV1 = { v: 1, id };\n\tif (phase) payload.phase = phase;\n\treturn JSON.stringify(payload);\n}\n\nfunction parseTextSignature(\n\tsignature: string | undefined,\n): { id: string; phase?: TextSignatureV1[\"phase\"] } | undefined {\n\tif (!signature) return undefined;\n\tif (signature.startsWith(\"{\")) {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\t\tif (parsed.v === 1 && typeof parsed.id === \"string\") {\n\t\t\t\tif (parsed.phase === \"commentary\" || parsed.phase === \"final_answer\") {\n\t\t\t\t\treturn { id: parsed.id, phase: parsed.phase };\n\t\t\t\t}\n\t\t\t\treturn { id: parsed.id };\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to legacy plain-string handling.\n\t\t}\n\t}\n\treturn { id: signature };\n}\n\n/**\n * Parse a persisted reasoning-item signature, rejecting anything that is not a\n * genuine Responses reasoning item. Foreign providers store non-JSON markers\n * (Kimi's \"reasoning_content\") or opaque payloads (Anthropic signatures) in\n * the same field; an unguarded JSON.parse turns a provenance mix-up into a\n * client-side throw, and blindly pushing the parsed value leaks invalid items.\n */\nfunction parseReasoningSignature(signature: string | undefined): ResponseReasoningItem | undefined {\n\tif (!signature) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as ResponseReasoningItem;\n\t\treturn parsed?.type === \"reasoning\" ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype ToolResultOutputContent = Array<ResponseInputText | ResponseInputImage>;\n\nfunction convertToolResultOutput<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontent: readonly (TextContent | ImageContent)[],\n): string | ToolResultOutputContent {\n\tconst textResult = content\n\t\t.filter((c): c is TextContent => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\");\n\tconst images = content.filter((c): c is ImageContent => c.type === \"image\");\n\tconst hasText = textResult.length > 0;\n\n\tif (images.length === 0 || !model.input.includes(\"image\")) {\n\t\treturn sanitizeSurrogates(hasText ? textResult : images.length > 0 ? \"(see attached image)\" : \"(no tool output)\");\n\t}\n\n\tconst output: ToolResultOutputContent = [];\n\tif (hasText) {\n\t\toutput.push({ type: \"input_text\", text: sanitizeSurrogates(textResult) });\n\t}\n\tfor (const image of images) {\n\t\toutput.push({\n\t\t\ttype: \"input_image\",\n\t\t\tdetail: \"auto\",\n\t\t\timage_url: `data:${image.mimeType};base64,${image.data}`,\n\t\t});\n\t}\n\treturn output;\n}\n\nexport interface OpenAIResponsesStreamOptions {\n\tserviceTier?: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\";\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tresolveServiceTier?: (\n\t\tresponseServiceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t\trequestServiceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t) => ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined;\n\tapplyServiceTierPricing?: (\n\t\tusage: Usage,\n\t\tserviceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t) => void;\n}\n\nexport interface ConvertResponsesMessagesOptions {\n\tincludeSystemPrompt?: boolean;\n\tpreserveThinking?: boolean;\n\tpreserveTextSignatures?: boolean;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tdeferredTools?: ReadonlyMap<string, Tool>;\n\tdeferredToolsMode?: \"additional-tools\" | \"tool-search\";\n\ttoolOptions?: ConvertResponsesToolsOptions;\n\t/** Internal request-local provenance sealing pass. Never serialized to provider payloads. */\n\tsealContextProvenance?: boolean;\n}\n\nexport interface ConvertResponsesToolsOptions {\n\tstrict?: boolean | null;\n\tsupportsStrictMode?: boolean;\n\tsupportsOpenAIGrammarTools?: boolean;\n\tdeferLoading?: boolean;\n}\n\ntype ResponseCustomToolCallItem = {\n\ttype: \"custom_tool_call\";\n\tid?: string;\n\tcall_id: string;\n\tname: string;\n\tinput?: string;\n\tnamespace?: string;\n};\n\ntype ResponseCustomToolCallOutputItem = {\n\ttype: \"custom_tool_call_output\";\n\tcall_id: string;\n\tname?: string;\n\toutput: string | ResponseFunctionCallOutputItemList;\n};\n\ntype AdditionalToolsInputItem = {\n\ttype: \"additional_tools\";\n\trole: \"developer\";\n\ttools: OpenAITool[];\n};\n\ntype ResponseInputItem =\n\t| OpenAIResponseInputItem\n\t| ResponseCustomToolCallItem\n\t| ResponseCustomToolCallOutputItem\n\t| AdditionalToolsInputItem\n\t| { type: \"configuration_update\"; reasoning: { effort: string } };\n\nexport const CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL = \"custom\";\n\ntype ResponseFunctionTool = Extract<OpenAITool, { type: \"function\" }>;\n\nfunction isResponseCustomToolCallItem(item: { type?: string }): item is ResponseCustomToolCallItem {\n\treturn item.type === \"custom_tool_call\";\n}\n\nfunction isFreeformTool(tool: Tool): boolean {\n\treturn tool.freeform !== undefined;\n}\n\nfunction isFreeformToolName(toolName: string, tools: Tool[] | undefined): boolean {\n\treturn tools?.some((tool) => tool.name === toolName && isFreeformTool(tool)) ?? false;\n}\n\nfunction getFreeformToolInput(argumentsValue: Record<string, unknown>): string {\n\treturn typeof argumentsValue.input === \"string\" ? argumentsValue.input : JSON.stringify(argumentsValue);\n}\n\nfunction contextProvenanceForInput(message: unknown, seal: boolean | undefined): ContextProvenance | undefined {\n\tconst provenance = getContextProvenance(message);\n\tif (!provenance) return undefined;\n\tconst fingerprint = contextProvenanceFingerprint(message);\n\tif (fingerprint === undefined) return undefined;\n\tconst stored = provenance.integrity;\n\tif (stored === undefined && seal) {\n\t\tprovenance.integrity = fingerprint;\n\t\treturn provenance;\n\t}\n\treturn stored === fingerprint ? provenance : undefined;\n}\n\nfunction withContextProvenance<T extends object>(item: T, message: unknown, seal: boolean | undefined): T {\n\tconst provenance = contextProvenanceForInput(message, seal);\n\tif (provenance) {\n\t\tObject.defineProperty(item, CONTEXT_PROVENANCE_FIELD, {\n\t\t\tvalue: provenance,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\treturn item;\n}\n// =============================================================================\n// Message conversion\n// =============================================================================\n\nexport function convertResponsesMessages<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\tallowedToolCallProviders: ReadonlySet<string>,\n\toptions?: ConvertResponsesMessagesOptions,\n): ResponseInput {\n\tconst messages: ResponseInputItem[] = [];\n\tconst loadedToolNames = new Set<string>();\n\n\tconst normalizeIdPart = (part: string): string => {\n\t\tconst sanitized = part.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n\t\tconst normalized = sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;\n\t\treturn normalized.replace(/_+$/, \"\");\n\t};\n\n\tconst buildForeignResponsesItemId = (itemId: string): string => {\n\t\tconst normalized = `fc_${shortHash(itemId)}`;\n\t\treturn normalized.length > 64 ? normalized.slice(0, 64) : normalized;\n\t};\n\n\tconst normalizeToolCallId = (id: string, _targetModel: Model<TApi>, source: AssistantMessage): string => {\n\t\tif (!id.includes(\"|\")) return normalizeIdPart(id);\n\t\tconst [callId, itemId] = id.split(\"|\");\n\t\tconst normalizedCallId = normalizeIdPart(callId);\n\t\tif (itemId === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL) {\n\t\t\treturn `${normalizedCallId}|${CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL}`;\n\t\t}\n\t\tif (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);\n\t\tconst isForeignToolCall = source.provider !== model.provider || source.api !== model.api;\n\t\tlet normalizedItemId = isForeignToolCall ? buildForeignResponsesItemId(itemId) : normalizeIdPart(itemId);\n\t\t// OpenAI Responses API requires item id to start with \"fc\"\n\t\tif (!normalizedItemId.startsWith(\"fc_\")) {\n\t\t\tnormalizedItemId = normalizeIdPart(`fc_${normalizedItemId}`);\n\t\t}\n\t\treturn `${normalizedCallId}|${normalizedItemId}`;\n\t};\n\n\tconst transformedMessages = transformMessages(context.messages, model, normalizeToolCallId, {\n\t\tpreserveThinking: options?.preserveThinking,\n\t\tpreserveTextSignatures: options?.preserveTextSignatures,\n\t});\n\n\tconst includeSystemPrompt = options?.includeSystemPrompt ?? true;\n\tif (includeSystemPrompt && context.systemPrompt) {\n\t\tconst compat = model.compat as { supportsDeveloperRole?: boolean } | undefined;\n\t\tconst role = model.reasoning && compat?.supportsDeveloperRole !== false ? \"developer\" : \"system\";\n\t\tmessages.push({\n\t\t\trole,\n\t\t\tcontent: sanitizeSurrogates(context.systemPrompt),\n\t\t});\n\t}\n\n\tlet msgIndex = 0;\n\tfor (const msg of transformedMessages) {\n\t\tif (msg.role === \"configurationUpdate\") {\n\t\t\tif (model.id !== \"gpt-6-astra\" || ![\"openai\", \"openai-codex\"].includes(model.provider)) continue;\n\t\t\tconst previous = messages[messages.length - 1];\n\t\t\tif (previous?.type === \"configuration_update\") {\n\t\t\t\tmessages[messages.length - 1] = {\n\t\t\t\t\ttype: \"configuration_update\",\n\t\t\t\t\treasoning: { effort: msg.effort },\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmessages.push({ type: \"configuration_update\", reasoning: { effort: msg.effort } });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\tcontent: [{ type: \"input_text\", text: sanitizeSurrogates(msg.content) }],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t});\n\t\t\t\tif (content.length === 0) continue;\n\t\t\t\tmessages.push(withContextProvenance({ role: \"user\", content }, msg, options?.sealContextProvenance));\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInputItem[] = [];\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameProviderAndApi = assistantMsg.provider === model.provider && assistantMsg.api === model.api;\n\t\t\tconst isSameModel = isSameProviderAndApi && assistantMsg.model === model.id;\n\t\t\tconst isDifferentModel = isSameProviderAndApi && assistantMsg.model !== model.id;\n\t\t\tlet textBlockIndex = 0;\n\n\t\t\tconst pushAssistantText = (text: string, textSignature?: string): void => {\n\t\t\t\tconst parsedSignature = parseTextSignature(textSignature);\n\t\t\t\tconst fallbackMessageId =\n\t\t\t\t\ttextBlockIndex === 0 ? `msg_pi_${msgIndex}` : `msg_pi_${msgIndex}_${textBlockIndex}`;\n\t\t\t\ttextBlockIndex++;\n\t\t\t\t// OpenAI requires id to be max 64 characters\n\t\t\t\tlet msgId = parsedSignature?.id;\n\t\t\t\tif (!msgId) {\n\t\t\t\t\tmsgId = fallbackMessageId;\n\t\t\t\t} else if (msgId.length > 64) {\n\t\t\t\t\tmsgId = `msg_${shortHash(msgId)}`;\n\t\t\t\t}\n\t\t\t\toutput.push({\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\tcontent: [{ type: \"output_text\", text: sanitizeSurrogates(text), annotations: [] }],\n\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\tid: msgId,\n\t\t\t\t\tphase: parsedSignature?.phase,\n\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t};\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tconst reasoningItem = parseReasoningSignature(block.thinkingSignature);\n\t\t\t\t\tif (reasoningItem) {\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t} else if (block.thinkingSignature && block.thinking.trim() !== \"\") {\n\t\t\t\t\t\t// A signed thinking block whose signature is not a real reasoning\n\t\t\t\t\t\t// item (foreign provenance or corrupted state): demote to plain\n\t\t\t\t\t\t// text, mirroring the cross-model policy in transformMessages.\n\t\t\t\t\t\tpushAssistantText(block.thinking);\n\t\t\t\t\t}\n\t\t\t\t\t// Signed foreign blocks with no text are intentionally dropped.\n\t\t\t\t} else if (block.type === \"providerNative\") {\n\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\tpushAssistantText(textBlock.text, textBlock.textSignature);\n\t\t\t\t} else if (block.type === \"toolCall\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tconst [callId, itemIdRaw] = toolCall.id.split(\"|\");\n\t\t\t\t\tconst customInputProperty = options?.grammarToolInputProperties?.get(toolCall.name);\n\t\t\t\t\tconst isPersistedFreeform = itemIdRaw === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL;\n\t\t\t\t\tconst isFreeform = isFreeformToolName(toolCall.name, context.tools) || isPersistedFreeform;\n\t\t\t\t\tlet itemId: string | undefined = isPersistedFreeform ? undefined : itemIdRaw;\n\n\t\t\t\t\t// An active grammar declaration wins over sentinel recovery below: its\n\t\t\t\t\t// named input property is richer than the persisted freeform fallback.\n\n\t\t\t\t\t// For different-model messages, set id to undefined to avoid pairing validation.\n\t\t\t\t\t// OpenAI tracks which fc_xxx IDs were paired with rs_xxx reasoning items.\n\t\t\t\t\t// By omitting the id, we avoid triggering that validation (like cross-provider does).\n\t\t\t\t\t// Function-call item ids must begin with fc_ while freeform calls can replay\n\t\t\t\t\t// without the local <call_id>|custom sentinel.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(isDifferentModel && itemId?.startsWith(\"fc_\")) ||\n\t\t\t\t\t\t(!isFreeform && customInputProperty === undefined && !itemId?.startsWith(\"fc_\"))\n\t\t\t\t\t) {\n\t\t\t\t\t\titemId = undefined;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst canReplayNamespace = isSameModel || options?.deferredTools?.has(toolCall.name) === true;\n\n\t\t\t\t\tif (customInputProperty !== undefined) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"custom_tool_call\",\n\t\t\t\t\t\t\t...(itemId !== undefined ? { id: itemId } : {}),\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\tinput: sanitizeSurrogates(\n\t\t\t\t\t\t\t\tgetGrammarToolInput(toolCall.name, toolCall.arguments, customInputProperty),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallItem);\n\t\t\t\t\t} else if (isFreeform) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"custom_tool_call\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\tinput: getFreeformToolInput(toolCall.arguments),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallItem);\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\t\t...(itemId?.startsWith(\"fc_\") ? { id: itemId } : {}),\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\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}\n\t\t\tif (output.length === 0) continue;\n\t\t\tmessages.push(...output.map((item) => withContextProvenance(item, msg, options?.sealContextProvenance)));\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst [callId, itemIdRaw] = msg.toolCallId.split(\"|\");\n\t\t\tconst output = convertToolResultOutput(model, msg.content);\n\t\t\tconst customInputProperty = options?.grammarToolInputProperties?.get(msg.toolName);\n\t\t\tconst isPersistedFreeform = itemIdRaw === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL;\n\n\t\t\tif (customInputProperty !== undefined) {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallOutputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (isFreeformToolName(msg.toolName, context.tools) || isPersistedFreeform) {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: msg.toolName,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallOutputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{ type: \"function_call_output\", call_id: callId, output },\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst deferredTools: Tool[] = [];\n\t\t\tfor (const name of msg.addedToolNames ?? []) {\n\t\t\t\tconst tool = options?.deferredTools?.get(name);\n\t\t\t\tif (!tool || loadedToolNames.has(name)) continue;\n\t\t\t\tloadedToolNames.add(name);\n\t\t\t\tdeferredTools.push(tool);\n\t\t\t}\n\t\t\tif (deferredTools.length > 0 && options?.deferredToolsMode === \"additional-tools\") {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"additional_tools\",\n\t\t\t\t\t\t\trole: \"developer\",\n\t\t\t\t\t\t\ttools: convertResponsesTools(deferredTools, options.toolOptions),\n\t\t\t\t\t\t} satisfies ResponseInputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (deferredTools.length > 0 && options?.deferredToolsMode === \"tool-search\") {\n\t\t\t\tconst names = deferredTools.map((tool) => tool.name);\n\t\t\t\tconst searchCallId = `pi_tool_load_${shortHash(`${msg.toolCallId}:${names.join(\",\")}`)}`;\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"tool_search_call\",\n\t\t\t\t\t\t\tcall_id: searchCallId,\n\t\t\t\t\t\t\texecution: \"client\",\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\targuments: { query: names.join(\" \"), limit: names.length },\n\t\t\t\t\t\t} satisfies ResponseInputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"tool_search_output\",\n\t\t\t\t\t\t\tcall_id: searchCallId,\n\t\t\t\t\t\t\texecution: \"client\",\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\ttools: convertResponsesTools(deferredTools, {\n\t\t\t\t\t\t\t\t...options?.toolOptions,\n\t\t\t\t\t\t\t\tdeferLoading: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t} satisfies ResponseToolSearchOutputItemParam,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tmsgIndex++;\n\t}\n\n\treturn messages as ResponseInput;\n}\n\n// =============================================================================\n// Tool conversion\n// =============================================================================\n\nexport function convertResponsesTools(tools: readonly Tool[], options?: ConvertResponsesToolsOptions): OpenAITool[] {\n\tconst defaultStrict = options?.strict === undefined ? false : options.strict;\n\tconst supportsStrictMode = options?.supportsStrictMode ?? true;\n\tconst supportsOpenAIGrammarTools = options?.supportsOpenAIGrammarTools ?? false;\n\n\treturn tools.map((tool) => {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\treturn {\n\t\t\t\ttype: \"custom\",\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tformat: {\n\t\t\t\t\ttype: \"grammar\",\n\t\t\t\t\tsyntax: grammar.format,\n\t\t\t\t\tdefinition: grammar.definition,\n\t\t\t\t},\n\t\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t\t} satisfies OpenAITool;\n\t\t}\n\t\tif (tool.freeform) {\n\t\t\treturn {\n\t\t\t\ttype: \"custom\",\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tformat: tool.freeform,\n\t\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t\t} as OpenAITool;\n\t\t}\n\n\t\tconst constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);\n\t\tconst strict = constrainedStrict ?? defaultStrict;\n\t\tconst functionTool: Omit<ResponseFunctionTool, \"strict\"> & {\n\t\t\tstrict?: ResponseFunctionTool[\"strict\"];\n\t\t} = {\n\t\t\ttype: \"function\",\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: getJsonSchemaToolParameters(tool, strict === true) as ResponseFunctionTool[\"parameters\"],\n\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t};\n\t\tif (supportsStrictMode) {\n\t\t\tfunctionTool.strict = strict;\n\t\t}\n\t\treturn functionTool as OpenAITool;\n\t});\n}\n\n// =============================================================================\n// Stream processing\n// =============================================================================\n\ntype StreamingToolCall = ToolCall & {\n\tpartialJson?: string;\n\tcustomInput?: {\n\t\tproperty: string;\n\t\tjsonBuffer: GrammarToolInputJsonBuffer;\n\t};\n};\n\nfunction getCustomToolCallInput(block: StreamingToolCall): string {\n\tconst property = block.customInput?.property;\n\tif (property === undefined) return \"\";\n\tconst value = block.arguments[property];\n\treturn typeof value === \"string\" ? value : \"\";\n}\n\nfunction appendCustomToolCallInput(block: StreamingToolCall, nextInput: string, close: boolean): string | undefined {\n\tconst customInput = block.customInput;\n\tif (!customInput) return undefined;\n\tconst delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);\n\tblock.arguments = { [customInput.property]: nextInput };\n\treturn delta;\n}\n\ntype ResponsesOutputSlot =\n\t| { type: \"thinking\"; block: ThinkingContent; contentIndex: number }\n\t| { type: \"text\"; block: TextContent; contentIndex: number }\n\t| { type: \"toolCall\"; block: StreamingToolCall; contentIndex: number }\n\t| { type: \"providerNative\"; block: ProviderNativeContent; contentIndex: number };\n\ntype ToolCallOutputSlot = Extract<ResponsesOutputSlot, { type: \"toolCall\" }>;\n\ntype NativeImageGenerationCall = {\n\ttype: \"image_generation_call\";\n\tid?: string;\n\tstatus: string;\n\tresult?: string | null;\n\trevised_prompt?: string;\n};\n\nconst MAX_NATIVE_IMAGE_BASE64_CHARS = 24 * 1024 * 1024;\n\nfunction readNativeImageGenerationCall(value: unknown): NativeImageGenerationCall | undefined {\n\tif (typeof value !== \"object\" || value === null || !(\"type\" in value) || !(\"status\" in value)) return undefined;\n\tif (value.type !== \"image_generation_call\" || typeof value.status !== \"string\") return undefined;\n\treturn {\n\t\ttype: \"image_generation_call\",\n\t\t...(\"id\" in value && typeof value.id === \"string\" ? { id: value.id } : {}),\n\t\tstatus: value.status,\n\t\t...(\"result\" in value && (typeof value.result === \"string\" || value.result === null)\n\t\t\t? { result: value.result }\n\t\t\t: {}),\n\t\t...(\"revised_prompt\" in value && typeof value.revised_prompt === \"string\"\n\t\t\t? { revised_prompt: value.revised_prompt }\n\t\t\t: {}),\n\t};\n}\n\nfunction isValidBase64(value: string): boolean {\n\treturn value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(value);\n}\n\nfunction reconcileNativeImageGenerationCall(item: NativeImageGenerationCall): NativeImageGenerationCall {\n\tif (item.status !== \"completed\") {\n\t\treturn {\n\t\t\ttype: \"image_generation_call\",\n\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\tstatus: item.status,\n\t\t};\n\t}\n\tif (typeof item.result !== \"string\" || !isValidBase64(item.result)) {\n\t\treturn {\n\t\t\ttype: \"image_generation_call\",\n\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\tstatus: \"malformed\",\n\t\t};\n\t}\n\treturn {\n\t\ttype: \"image_generation_call\",\n\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\tstatus: \"completed\",\n\t\tresult: item.result,\n\t\t...(item.revised_prompt?.trim() ? { revised_prompt: item.revised_prompt } : {}),\n\t};\n}\n\nexport async function processResponsesStream<TApi extends Api>(\n\topenaiStream: AsyncIterable<ResponseStreamEvent>,\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n\tmodel: Model<TApi>,\n\toptions?: OpenAIResponsesStreamOptions,\n): Promise<void> {\n\tlet sawTerminalResponseEvent = false;\n\tlet nativeImageBase64Chars = 0;\n\tconst outputSlots = new Map<number, ResponsesOutputSlot>();\n\tconst reasoningBlocksById = new Map<string, ThinkingContent>();\n\tconst nativeImageCharsByOutputIndex = new Map<number, number>();\n\tconst finalizedNativeImageOutputIndexes = new Set<number>();\n\tconst applyMessagePhaseStopReason = (item: ResponseOutputItem): void => {\n\t\tif (item.type === \"message\" && item.phase === \"final_answer\") {\n\t\t\toutput.stopReason = \"stop\";\n\t\t}\n\t};\n\tconst getSlot = <TType extends ResponsesOutputSlot[\"type\"]>(\n\t\toutputIndex: number,\n\t\ttype: TType,\n\t): Extract<ResponsesOutputSlot, { type: TType }> | undefined => {\n\t\tconst slot = outputSlots.get(outputIndex);\n\t\treturn slot?.type === type ? (slot as Extract<ResponsesOutputSlot, { type: TType }>) : undefined;\n\t};\n\tconst pushToolCallDelta = (slot: ToolCallOutputSlot, delta: string | undefined): void => {\n\t\tif (delta === undefined) return;\n\t\tstream.push({\n\t\t\ttype: \"toolcall_delta\",\n\t\t\tcontentIndex: slot.contentIndex,\n\t\t\tdelta,\n\t\t\tpartial: output,\n\t\t});\n\t};\n\tconst createSlot = (\n\t\toutputIndex: number,\n\t\titem: ResponseOutputItem | ResponseCustomToolCallItem,\n\t): ResponsesOutputSlot | undefined => {\n\t\tif (item.type === \"reasoning\") {\n\t\t\tconst block: ThinkingContent = { type: \"thinking\", thinking: \"\" };\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"thinking\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"thinking_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (item.type === \"message\") {\n\t\t\tapplyMessagePhaseStopReason(item);\n\t\t\tconst block: TextContent = { type: \"text\", text: \"\" };\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = { type: \"text\", block, contentIndex: output.content.length - 1 } satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"text_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (item.type === \"function_call\") {\n\t\t\tconst block: StreamingToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: `${item.call_id}|${item.id}`,\n\t\t\t\tname: item.name,\n\t\t\t\targuments: {},\n\t\t\t\t...(item.namespace !== undefined ? { namespace: item.namespace } : {}),\n\t\t\t\tpartialJson: item.arguments || \"\",\n\t\t\t};\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (isResponseCustomToolCallItem(item)) {\n\t\t\tconst inputProperty = options?.grammarToolInputProperties?.get(item.name) ?? \"input\";\n\t\t\tconst input = item.input || \"\";\n\t\t\tconst block: StreamingToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: `${item.call_id}|${item.id ?? CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL}`,\n\t\t\t\tname: item.name,\n\t\t\t\targuments: { [inputProperty]: input },\n\t\t\t\t...(item.namespace !== undefined ? { namespace: item.namespace } : {}),\n\t\t\t\tcustomInput: {\n\t\t\t\t\tproperty: inputProperty,\n\t\t\t\t\tjsonBuffer: { input: \"\", started: false, closed: false },\n\t\t\t\t},\n\t\t\t};\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tconst imageItem = readNativeImageGenerationCall(item);\n\t\tconst block = {\n\t\t\ttype: \"providerNative\",\n\t\t\tsubtype: item.type,\n\t\t\traw: imageItem ? reconcileNativeImageGenerationCall(imageItem) : item,\n\t\t} satisfies ProviderNativeContent;\n\t\tconst slot = {\n\t\t\ttype: \"providerNative\",\n\t\t\tblock,\n\t\t\tcontentIndex: output.content.length,\n\t\t} satisfies ResponsesOutputSlot;\n\t\tif (imageItem) reconcileNativeImageSlot(outputIndex, slot, imageItem);\n\t\toutput.content.push(block);\n\t\toutputSlots.set(outputIndex, slot);\n\t\treturn slot;\n\t};\n\tconst getOrCreateSlot = (\n\t\toutputIndex: number,\n\t\titem: ResponseOutputItem | ResponseCustomToolCallItem,\n\t): ResponsesOutputSlot | undefined => {\n\t\treturn outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);\n\t};\n\tfunction scrubNativeImageResults(): void {\n\t\tfor (const block of output.content) {\n\t\t\tif (block.type !== \"providerNative\" || block.subtype !== \"image_generation_call\") continue;\n\t\t\tconst item = readNativeImageGenerationCall(block.raw);\n\t\t\tif (typeof item?.result !== \"string\") continue;\n\t\t\tblock.raw = {\n\t\t\t\ttype: \"image_generation_call\",\n\t\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\t\tstatus: \"malformed\",\n\t\t\t};\n\t\t}\n\t\tnativeImageBase64Chars = 0;\n\t\tnativeImageCharsByOutputIndex.clear();\n\t}\n\tfunction reconcileNativeImageSlot(\n\t\toutputIndex: number,\n\t\tslot: Extract<ResponsesOutputSlot, { type: \"providerNative\" }>,\n\t\titem: NativeImageGenerationCall,\n\t): void {\n\t\tconst reconciled = reconcileNativeImageGenerationCall(item);\n\t\tconst previousChars = nativeImageCharsByOutputIndex.get(outputIndex) ?? 0;\n\t\tconst nextChars = typeof reconciled.result === \"string\" ? reconciled.result.length : 0;\n\t\tconst nextTotal = nativeImageBase64Chars - previousChars + nextChars;\n\t\tif (nextTotal > MAX_NATIVE_IMAGE_BASE64_CHARS) {\n\t\t\tscrubNativeImageResults();\n\t\t\tthrow new Error(\"Native image generation results exceed the 24 MiB base64 limit\");\n\t\t}\n\t\tnativeImageBase64Chars = nextTotal;\n\t\tif (nextChars > 0) nativeImageCharsByOutputIndex.set(outputIndex, nextChars);\n\t\telse nativeImageCharsByOutputIndex.delete(outputIndex);\n\t\tslot.block.subtype = \"image_generation_call\";\n\t\tslot.block.raw = reconciled;\n\t}\n\tconst backfillNativeImageGenerationCalls = (responseOutput: readonly ResponseOutputItem[]): void => {\n\t\tfor (const [outputIndex, outputItem] of responseOutput.entries()) {\n\t\t\tif (finalizedNativeImageOutputIndexes.has(outputIndex)) continue;\n\t\t\tconst imageItem = readNativeImageGenerationCall(outputItem);\n\t\t\tif (!imageItem) continue;\n\t\t\tconst existingSlot = getSlot(outputIndex, \"providerNative\");\n\t\t\tif (existingSlot) reconcileNativeImageSlot(outputIndex, existingSlot, imageItem);\n\t\t\telse createSlot(outputIndex, outputItem);\n\t\t\toutputSlots.delete(outputIndex);\n\t\t}\n\t};\n\t// Azure OpenAI can omit reasoning.encrypted_content from response.output_item.done\n\t// and provide it only in response.completed.response.output. Backfill the\n\t// persisted reasoning signature from the terminal response to keep store:false\n\t// multi-turn replay stateless. See https://github.com/earendil-works/pi/issues/6409.\n\tconst backfillReasoningSignatures = (responseOutput: ResponseOutputItem[]): void => {\n\t\tfor (const item of responseOutput) {\n\t\t\tif (item.type !== \"reasoning\" || !item.encrypted_content) continue;\n\t\t\tconst block = reasoningBlocksById.get(item.id);\n\t\t\tif (!block?.thinkingSignature) continue;\n\n\t\t\tconst storedItem = parseReasoningSignature(block.thinkingSignature);\n\t\t\tif (!storedItem || storedItem.encrypted_content) continue;\n\t\t\tblock.thinkingSignature = JSON.stringify({\n\t\t\t\t...storedItem,\n\t\t\t\tencrypted_content: item.encrypted_content,\n\t\t\t});\n\t\t}\n\t};\n\tconst finalizeResponse = (\n\t\tresponse: Extract<ResponseStreamEvent, { type: \"response.completed\" | \"response.incomplete\" }>[\"response\"],\n\t) => {\n\t\tsawTerminalResponseEvent = true;\n\t\tbackfillReasoningSignatures(response.output ?? []);\n\t\tbackfillNativeImageGenerationCalls(response.output ?? []);\n\t\tif (response?.id) {\n\t\t\toutput.responseId = response.id;\n\t\t}\n\t\tif (response?.usage) {\n\t\t\tconst inputDetails = response.usage.input_tokens_details as\n\t\t\t\t| { cached_tokens?: number; cache_write_tokens?: number }\n\t\t\t\t| undefined;\n\t\t\tconst cachedTokens = inputDetails?.cached_tokens || 0;\n\t\t\tconst cacheWriteTokens = inputDetails?.cache_write_tokens || 0;\n\t\t\toutput.usage = {\n\t\t\t\t// OpenAI includes cached and cache-write tokens in input_tokens, so subtract both.\n\t\t\t\tinput: Math.max(0, (response.usage.input_tokens || 0) - cachedTokens - cacheWriteTokens),\n\t\t\t\toutput: response.usage.output_tokens || 0,\n\t\t\t\tcacheRead: cachedTokens,\n\t\t\t\tcacheWrite: cacheWriteTokens,\n\t\t\t\treasoning: response.usage.output_tokens_details?.reasoning_tokens || 0,\n\t\t\t\ttotalTokens: response.usage.total_tokens || 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t};\n\t\t}\n\t\tcalculateCost(model, output.usage);\n\t\tif (options?.applyServiceTierPricing) {\n\t\t\tconst serviceTier = options.resolveServiceTier\n\t\t\t\t? options.resolveServiceTier(response?.service_tier, options.serviceTier)\n\t\t\t\t: (response?.service_tier ?? options.serviceTier);\n\t\t\toptions.applyServiceTierPricing(output.usage, serviceTier);\n\t\t}\n\t\t// Map status to stop reason. For incomplete responses, retain the provider's\n\t\t// specific reason so max-output truncation and content filtering stay distinct.\n\t\tconst status = response?.status;\n\t\tconst incompleteDetails = response?.incomplete_details as { reason?: unknown } | null | undefined;\n\t\tconst incompleteReason = typeof incompleteDetails?.reason === \"string\" ? incompleteDetails.reason : undefined;\n\t\toutput.rawStopReason = incompleteReason ? `${status}.${incompleteReason}` : status;\n\t\tconst mappedStop = mapStopReason(status, incompleteReason);\n\t\toutput.stopReason = mappedStop.stopReason;\n\t\tif (mappedStop.errorMessage === undefined) delete output.errorMessage;\n\t\telse output.errorMessage = mappedStop.errorMessage;\n\t\tif (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n\t\t\toutput.stopReason = \"toolUse\";\n\t\t}\n\t};\n\n\tfor await (const event of withResponsesCompletionGrace(openaiStream)) {\n\t\tif (event.type === \"response.created\") {\n\t\t\toutput.responseId = event.response.id;\n\t\t} else if (event.type === \"response.output_item.added\") {\n\t\t\tcreateSlot(event.output_index, event.item);\n\t\t} else if (event.type === \"response.reasoning_summary_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.reasoning_summary_part.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += \"\\n\\n\";\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: \"\\n\\n\",\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.reasoning_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.output_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"text\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.text += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.refusal.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"text\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.text += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.function_call_arguments.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot || slot.block.partialJson === undefined) continue;\n\t\t\tslot.block.partialJson += event.delta;\n\t\t\tslot.block.arguments = parseStreamingJson(slot.block.partialJson);\n\t\t\tpushToolCallDelta(slot, event.delta);\n\t\t} else if (event.type === \"response.function_call_arguments.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot || slot.block.partialJson === undefined) continue;\n\t\t\tconst previousPartialJson = slot.block.partialJson;\n\t\t\tslot.block.partialJson = event.arguments;\n\t\t\tslot.block.arguments = parseStreamingJson(slot.block.partialJson);\n\n\t\t\tif (event.arguments.startsWith(previousPartialJson)) {\n\t\t\t\tconst delta = event.arguments.slice(previousPartialJson.length);\n\t\t\t\tif (delta.length > 0) pushToolCallDelta(slot, delta);\n\t\t\t}\n\t\t} else if (event.type === \"response.custom_tool_call_input.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot?.block.customInput) continue;\n\t\t\tpushToolCallDelta(\n\t\t\t\tslot,\n\t\t\t\tappendCustomToolCallInput(slot.block, getCustomToolCallInput(slot.block) + event.delta, false),\n\t\t\t);\n\t\t} else if (event.type === \"response.custom_tool_call_input.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot?.block.customInput) continue;\n\t\t\tpushToolCallDelta(slot, appendCustomToolCallInput(slot.block, event.input, true));\n\t\t} else if (event.type === \"response.output_item.done\") {\n\t\t\tconst item = event.item;\n\t\t\tapplyMessagePhaseStopReason(item);\n\t\t\tconst slot = getOrCreateSlot(event.output_index, item);\n\t\t\tconst imageItem = readNativeImageGenerationCall(item);\n\n\t\t\tif (imageItem && slot?.type === \"providerNative\") {\n\t\t\t\treconcileNativeImageSlot(event.output_index, slot, imageItem);\n\t\t\t\tfinalizedNativeImageOutputIndexes.add(event.output_index);\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"reasoning\" && slot?.type === \"thinking\") {\n\t\t\t\tconst summaryText = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\tconst contentText = item.content?.map((c) => c.text).join(\"\\n\\n\") || \"\";\n\t\t\t\tslot.block.thinking = summaryText || contentText || slot.block.thinking;\n\t\t\t\tslot.block.thinkingSignature = JSON.stringify(item);\n\t\t\t\treasoningBlocksById.set(item.id, slot.block);\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\tcontent: slot.block.thinking,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"message\" && slot?.type === \"text\") {\n\t\t\t\tslot.block.text = item.content?.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\") || \"\";\n\t\t\t\tslot.block.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\tcontent: slot.block.text,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (\n\t\t\t\titem.type === \"function_call\" &&\n\t\t\t\tslot?.type === \"toolCall\" &&\n\t\t\t\tslot.block.partialJson !== undefined\n\t\t\t) {\n\t\t\t\tslot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || \"{}\");\n\t\t\t\tif (item.namespace !== undefined) slot.block.namespace = item.namespace;\n\t\t\t\t// Finalize in-place and strip the scratch buffer so replay only\n\t\t\t\t// carries parsed arguments.\n\t\t\t\tdelete slot.block.partialJson;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"custom_tool_call\" && slot?.type === \"toolCall\" && slot.block.customInput) {\n\t\t\t\tpushToolCallDelta(\n\t\t\t\t\tslot,\n\t\t\t\t\tappendCustomToolCallInput(slot.block, item.input ?? getCustomToolCallInput(slot.block), true),\n\t\t\t\t);\n\t\t\t\tif (item.namespace !== undefined) slot.block.namespace = item.namespace;\n\t\t\t\tdelete slot.block.customInput;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (isResponseCustomToolCallItem(item) && slot?.type === \"toolCall\") {\n\t\t\t\tconst input = typeof item.input === \"string\" ? item.input : \"\";\n\t\t\t\tslot.block.arguments = { input };\n\t\t\t\tdelete (slot.block as { partialJson?: string }).partialJson;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (slot?.type === \"providerNative\") {\n\t\t\t\tslot.block.subtype = item.type;\n\t\t\t\tslot.block.raw = item;\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t}\n\t\t} else if (event.type === \"response.completed\" || event.type === \"response.incomplete\") {\n\t\t\tfinalizeResponse(event.response);\n\t\t} else if (event.type === \"error\") {\n\t\t\tthrow new Error(`Error Code ${event.code}: ${event.message}` || \"Unknown error\");\n\t\t} else if (event.type === \"response.failed\") {\n\t\t\tsawTerminalResponseEvent = true;\n\t\t\toutput.rawStopReason = event.response?.status;\n\t\t\tconst error = event.response?.error;\n\t\t\tconst details = event.response?.incomplete_details;\n\t\t\tconst msg = error\n\t\t\t\t? `${error.code || \"unknown\"}: ${error.message || \"no message\"}`\n\t\t\t\t: details?.reason\n\t\t\t\t\t? `incomplete: ${details.reason}`\n\t\t\t\t\t: \"Unknown error (no error details in response)\";\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\tconst hasFinalizedToolCall = output.content.some((block) => block.type === \"toolCall\" && !(\"partialJson\" in block));\n\tif (!sawTerminalResponseEvent && !hasFinalizedToolCall) {\n\t\tthrow new Error(\"OpenAI Responses stream ended before a terminal response event\");\n\t}\n}\n\nfunction mapStopReason(\n\tstatus: OpenAI.Responses.ResponseStatus | undefined,\n\tincompleteReason?: string,\n): { stopReason: StopReason; errorMessage?: string } {\n\tif (!status) return { stopReason: \"stop\" };\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tcase \"incomplete\":\n\t\t\tif (incompleteReason === \"max_output_tokens\") {\n\t\t\t\treturn { stopReason: \"length\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstopReason: \"error\",\n\t\t\t\terrorMessage: incompleteReason\n\t\t\t\t\t? `Response incomplete: ${incompleteReason}`\n\t\t\t\t\t: \"Response incomplete without a provider reason\",\n\t\t\t};\n\t\tcase \"failed\":\n\t\tcase \"cancelled\":\n\t\t\treturn { stopReason: \"error\" };\n\t\t// These two are wonky ...\n\t\tcase \"in_progress\":\n\t\tcase \"queued\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = status;\n\t\t\tthrow new Error(`Unhandled stop reason: ${_exhaustive}`);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"openai-responses-shared.js","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AAgBA,OAAO,EACN,wBAAwB,EAExB,4BAA4B,EAC5B,oBAAoB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiB7C,OAAO,EAAE,SAAS,EAA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I,CAAC,CAAC,aAAa,IAAI,KAAK,CAAC,CAAC,CAAC;IACpH,IAAI,CAAC,wBAAwB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACnF,CAAC;AACF,CAAC;AAED,SAAS,aAAa,CACrB,MAAmD,EACnD,gBAAyB;IAEzB,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAC3C,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,WAAW;YACf,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAC/B,KAAK,YAAY;YAChB,IAAI,gBAAgB,KAAK,mBAAmB,EAAE,CAAC;gBAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;YACjC,CAAC;YACD,OAAO;gBACN,UAAU,EAAE,OAAO;gBACnB,YAAY,EAAE,gBAAgB;oBAC7B,CAAC,CAAC,wBAAwB,gBAAgB,EAAE;oBAC5C,CAAC,CAAC,+CAA+C;aAClD,CAAC;QACH,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACf,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QAChC,0BAA0B;QAC1B,KAAK,aAAa,CAAC;QACnB,KAAK,QAAQ;YACZ,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAC/B,SAAS,CAAC;YACT,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type OpenAI from \"openai\";\nimport type {\n\tResponseInputItem as OpenAIResponseInputItem,\n\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseFunctionCallOutputItemList,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputText,\n\tResponseOutputItem,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n\tResponseStreamEvent,\n\tResponseToolSearchOutputItemParam,\n} from \"openai/resources/responses/responses.js\";\nimport {\n\tCONTEXT_PROVENANCE_FIELD,\n\ttype ContextProvenance,\n\tcontextProvenanceFingerprint,\n\tgetContextProvenance,\n} from \"../context-provenance.ts\";\nimport { calculateCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tImageContent,\n\tModel,\n\tProviderNativeContent,\n\tStopReason,\n\tTextContent,\n\tTextSignatureV1,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport type { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\nimport { shortHash } from \"../utils/hash.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport {\n\tappendGrammarToolInputJsonDelta,\n\ttype GrammarToolInputJsonBuffer,\n\tgetGrammarToolInput,\n\tgetJsonSchemaToolParameters,\n\tresolveGrammarConstrainedSampling,\n\tresolveJsonSchemaStrictSampling,\n} from \"./constrained-sampling.ts\";\nimport { withResponsesCompletionGrace } from \"./responses-completion-grace.ts\";\nimport { transformMessages } from \"./transform-messages.ts\";\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nfunction encodeTextSignatureV1(id: string, phase?: TextSignatureV1[\"phase\"]): string {\n\tconst payload: TextSignatureV1 = { v: 1, id };\n\tif (phase) payload.phase = phase;\n\treturn JSON.stringify(payload);\n}\n\nfunction parseTextSignature(\n\tsignature: string | undefined,\n): { id: string; phase?: TextSignatureV1[\"phase\"] } | undefined {\n\tif (!signature) return undefined;\n\tif (signature.startsWith(\"{\")) {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\t\tif (parsed.v === 1 && typeof parsed.id === \"string\") {\n\t\t\t\tif (parsed.phase === \"commentary\" || parsed.phase === \"final_answer\") {\n\t\t\t\t\treturn { id: parsed.id, phase: parsed.phase };\n\t\t\t\t}\n\t\t\t\treturn { id: parsed.id };\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to legacy plain-string handling.\n\t\t}\n\t}\n\treturn { id: signature };\n}\n\n/**\n * Parse a persisted reasoning-item signature, rejecting anything that is not a\n * genuine Responses reasoning item. Foreign providers store non-JSON markers\n * (Kimi's \"reasoning_content\") or opaque payloads (Anthropic signatures) in\n * the same field; an unguarded JSON.parse turns a provenance mix-up into a\n * client-side throw, and blindly pushing the parsed value leaks invalid items.\n */\nfunction parseReasoningSignature(signature: string | undefined): ResponseReasoningItem | undefined {\n\tif (!signature) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as ResponseReasoningItem;\n\t\treturn parsed?.type === \"reasoning\" ? parsed : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype ToolResultOutputContent = Array<ResponseInputText | ResponseInputImage>;\n\nfunction convertToolResultOutput<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontent: readonly (TextContent | ImageContent)[],\n): string | ToolResultOutputContent {\n\tconst textResult = content\n\t\t.filter((c): c is TextContent => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\");\n\tconst images = content.filter((c): c is ImageContent => c.type === \"image\");\n\tconst hasText = textResult.length > 0;\n\n\tif (images.length === 0 || !model.input.includes(\"image\")) {\n\t\treturn sanitizeSurrogates(hasText ? textResult : images.length > 0 ? \"(see attached image)\" : \"(no tool output)\");\n\t}\n\n\tconst output: ToolResultOutputContent = [];\n\tif (hasText) {\n\t\toutput.push({ type: \"input_text\", text: sanitizeSurrogates(textResult) });\n\t}\n\tfor (const image of images) {\n\t\toutput.push({\n\t\t\ttype: \"input_image\",\n\t\t\tdetail: \"auto\",\n\t\t\timage_url: `data:${image.mimeType};base64,${image.data}`,\n\t\t});\n\t}\n\treturn output;\n}\n\nexport interface OpenAIResponsesStreamOptions {\n\tserviceTier?: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\";\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tresolveServiceTier?: (\n\t\tresponseServiceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t\trequestServiceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t) => ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined;\n\tapplyServiceTierPricing?: (\n\t\tusage: Usage,\n\t\tserviceTier: ResponseCreateParamsStreaming[\"service_tier\"] | \"fast\" | undefined,\n\t) => void;\n}\n\nexport interface ConvertResponsesMessagesOptions {\n\tincludeSystemPrompt?: boolean;\n\tpreserveThinking?: boolean;\n\tpreserveTextSignatures?: boolean;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tdeferredTools?: ReadonlyMap<string, Tool>;\n\tdeferredToolsMode?: \"additional-tools\" | \"tool-search\";\n\ttoolOptions?: ConvertResponsesToolsOptions;\n\t/** Internal request-local provenance sealing pass. Never serialized to provider payloads. */\n\tsealContextProvenance?: boolean;\n}\n\nexport interface ConvertResponsesToolsOptions {\n\tstrict?: boolean | null;\n\tsupportsStrictMode?: boolean;\n\tsupportsOpenAIGrammarTools?: boolean;\n\tdeferLoading?: boolean;\n}\n\ntype ResponseCustomToolCallItem = {\n\ttype: \"custom_tool_call\";\n\tid?: string;\n\tcall_id: string;\n\tname: string;\n\tinput?: string;\n\tnamespace?: string;\n};\n\ntype ResponseCustomToolCallOutputItem = {\n\ttype: \"custom_tool_call_output\";\n\tcall_id: string;\n\tname?: string;\n\toutput: string | ResponseFunctionCallOutputItemList;\n};\n\ntype AdditionalToolsInputItem = {\n\ttype: \"additional_tools\";\n\trole: \"developer\";\n\ttools: OpenAITool[];\n};\n\ntype ResponseInputItem =\n\t| OpenAIResponseInputItem\n\t| ResponseCustomToolCallItem\n\t| ResponseCustomToolCallOutputItem\n\t| AdditionalToolsInputItem\n\t| { type: \"configuration_update\"; reasoning: { effort: string } };\n\nexport const CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL = \"custom\";\n\ntype ResponseFunctionTool = Extract<OpenAITool, { type: \"function\" }>;\n\nfunction isResponseCustomToolCallItem(item: { type?: string }): item is ResponseCustomToolCallItem {\n\treturn item.type === \"custom_tool_call\";\n}\n\nfunction isFreeformTool(tool: Tool): boolean {\n\treturn tool.freeform !== undefined;\n}\n\nfunction isFreeformToolName(toolName: string, tools: Tool[] | undefined): boolean {\n\treturn tools?.some((tool) => tool.name === toolName && isFreeformTool(tool)) ?? false;\n}\n\nfunction getFreeformToolInput(argumentsValue: Record<string, unknown>): string {\n\treturn typeof argumentsValue.input === \"string\" ? argumentsValue.input : JSON.stringify(argumentsValue);\n}\n\nfunction contextProvenanceForInput(message: unknown, seal: boolean | undefined): ContextProvenance | undefined {\n\tconst provenance = getContextProvenance(message);\n\tif (!provenance) return undefined;\n\tconst fingerprint = contextProvenanceFingerprint(message);\n\tif (fingerprint === undefined) return undefined;\n\tconst stored = provenance.integrity;\n\tif (stored === undefined && seal) {\n\t\tprovenance.integrity = fingerprint;\n\t\treturn provenance;\n\t}\n\treturn stored === fingerprint ? provenance : undefined;\n}\n\nfunction withContextProvenance<T extends object>(item: T, message: unknown, seal: boolean | undefined): T {\n\tconst provenance = contextProvenanceForInput(message, seal);\n\tif (provenance) {\n\t\tObject.defineProperty(item, CONTEXT_PROVENANCE_FIELD, {\n\t\t\tvalue: provenance,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\treturn item;\n}\n// =============================================================================\n// Message conversion\n// =============================================================================\n\nexport function convertResponsesMessages<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\tallowedToolCallProviders: ReadonlySet<string>,\n\toptions?: ConvertResponsesMessagesOptions,\n): ResponseInput {\n\tconst messages: ResponseInputItem[] = [];\n\tconst loadedToolNames = new Set<string>();\n\n\tconst normalizeIdPart = (part: string): string => {\n\t\tconst sanitized = part.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n\t\tconst normalized = sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;\n\t\treturn normalized.replace(/_+$/, \"\");\n\t};\n\n\tconst buildForeignResponsesItemId = (itemId: string): string => {\n\t\tconst normalized = `fc_${shortHash(itemId)}`;\n\t\treturn normalized.length > 64 ? normalized.slice(0, 64) : normalized;\n\t};\n\n\tconst normalizeToolCallId = (id: string, _targetModel: Model<TApi>, source: AssistantMessage): string => {\n\t\tif (!id.includes(\"|\")) return normalizeIdPart(id);\n\t\tconst [callId, itemId] = id.split(\"|\");\n\t\tconst normalizedCallId = normalizeIdPart(callId);\n\t\tif (itemId === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL) {\n\t\t\treturn `${normalizedCallId}|${CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL}`;\n\t\t}\n\t\tif (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);\n\t\tconst isForeignToolCall = source.provider !== model.provider || source.api !== model.api;\n\t\tlet normalizedItemId = isForeignToolCall ? buildForeignResponsesItemId(itemId) : normalizeIdPart(itemId);\n\t\t// OpenAI Responses API requires item id to start with \"fc\"\n\t\tif (!normalizedItemId.startsWith(\"fc_\")) {\n\t\t\tnormalizedItemId = normalizeIdPart(`fc_${normalizedItemId}`);\n\t\t}\n\t\treturn `${normalizedCallId}|${normalizedItemId}`;\n\t};\n\n\tconst transformedMessages = transformMessages(context.messages, model, normalizeToolCallId, {\n\t\tpreserveThinking: options?.preserveThinking,\n\t\tpreserveTextSignatures: options?.preserveTextSignatures,\n\t});\n\n\tconst includeSystemPrompt = options?.includeSystemPrompt ?? true;\n\tif (includeSystemPrompt && context.systemPrompt) {\n\t\tconst compat = model.compat as { supportsDeveloperRole?: boolean } | undefined;\n\t\tconst role = model.reasoning && compat?.supportsDeveloperRole !== false ? \"developer\" : \"system\";\n\t\tmessages.push({\n\t\t\trole,\n\t\t\tcontent: sanitizeSurrogates(context.systemPrompt),\n\t\t});\n\t}\n\n\tlet msgIndex = 0;\n\tfor (const msg of transformedMessages) {\n\t\tif (msg.role === \"configurationUpdate\") {\n\t\t\tif (model.id !== \"gpt-6-astra\" || ![\"openai\", \"chatgpt-subscription\"].includes(model.provider)) continue;\n\t\t\tconst previous = messages[messages.length - 1];\n\t\t\tif (previous?.type === \"configuration_update\") {\n\t\t\t\tmessages[messages.length - 1] = {\n\t\t\t\t\ttype: \"configuration_update\",\n\t\t\t\t\treasoning: { effort: msg.effort },\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmessages.push({ type: \"configuration_update\", reasoning: { effort: msg.effort } });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\tcontent: [{ type: \"input_text\", text: sanitizeSurrogates(msg.content) }],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: sanitizeSurrogates(item.text),\n\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t});\n\t\t\t\tif (content.length === 0) continue;\n\t\t\t\tmessages.push(withContextProvenance({ role: \"user\", content }, msg, options?.sealContextProvenance));\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInputItem[] = [];\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\t\t\tconst isSameProviderAndApi = assistantMsg.provider === model.provider && assistantMsg.api === model.api;\n\t\t\tconst isSameModel = isSameProviderAndApi && assistantMsg.model === model.id;\n\t\t\tconst isDifferentModel = isSameProviderAndApi && assistantMsg.model !== model.id;\n\t\t\tlet textBlockIndex = 0;\n\n\t\t\tconst pushAssistantText = (text: string, textSignature?: string): void => {\n\t\t\t\tconst parsedSignature = parseTextSignature(textSignature);\n\t\t\t\tconst fallbackMessageId =\n\t\t\t\t\ttextBlockIndex === 0 ? `msg_pi_${msgIndex}` : `msg_pi_${msgIndex}_${textBlockIndex}`;\n\t\t\t\ttextBlockIndex++;\n\t\t\t\t// OpenAI requires id to be max 64 characters\n\t\t\t\tlet msgId = parsedSignature?.id;\n\t\t\t\tif (!msgId) {\n\t\t\t\t\tmsgId = fallbackMessageId;\n\t\t\t\t} else if (msgId.length > 64) {\n\t\t\t\t\tmsgId = `msg_${shortHash(msgId)}`;\n\t\t\t\t}\n\t\t\t\toutput.push({\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\tcontent: [{ type: \"output_text\", text: sanitizeSurrogates(text), annotations: [] }],\n\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\tid: msgId,\n\t\t\t\t\tphase: parsedSignature?.phase,\n\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t};\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tconst reasoningItem = parseReasoningSignature(block.thinkingSignature);\n\t\t\t\t\tif (reasoningItem) {\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t} else if (block.thinkingSignature && block.thinking.trim() !== \"\") {\n\t\t\t\t\t\t// A signed thinking block whose signature is not a real reasoning\n\t\t\t\t\t\t// item (foreign provenance or corrupted state): demote to plain\n\t\t\t\t\t\t// text, mirroring the cross-model policy in transformMessages.\n\t\t\t\t\t\tpushAssistantText(block.thinking);\n\t\t\t\t\t}\n\t\t\t\t\t// Signed foreign blocks with no text are intentionally dropped.\n\t\t\t\t} else if (block.type === \"providerNative\") {\n\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\tpushAssistantText(textBlock.text, textBlock.textSignature);\n\t\t\t\t} else if (block.type === \"toolCall\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\tconst [callId, itemIdRaw] = toolCall.id.split(\"|\");\n\t\t\t\t\tconst customInputProperty = options?.grammarToolInputProperties?.get(toolCall.name);\n\t\t\t\t\tconst isPersistedFreeform = itemIdRaw === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL;\n\t\t\t\t\tconst isFreeform = isFreeformToolName(toolCall.name, context.tools) || isPersistedFreeform;\n\t\t\t\t\tlet itemId: string | undefined = isPersistedFreeform ? undefined : itemIdRaw;\n\n\t\t\t\t\t// An active grammar declaration wins over sentinel recovery below: its\n\t\t\t\t\t// named input property is richer than the persisted freeform fallback.\n\n\t\t\t\t\t// For different-model messages, set id to undefined to avoid pairing validation.\n\t\t\t\t\t// OpenAI tracks which fc_xxx IDs were paired with rs_xxx reasoning items.\n\t\t\t\t\t// By omitting the id, we avoid triggering that validation (like cross-provider does).\n\t\t\t\t\t// Function-call item ids must begin with fc_ while freeform calls can replay\n\t\t\t\t\t// without the local <call_id>|custom sentinel.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(isDifferentModel && itemId?.startsWith(\"fc_\")) ||\n\t\t\t\t\t\t(!isFreeform && customInputProperty === undefined && !itemId?.startsWith(\"fc_\"))\n\t\t\t\t\t) {\n\t\t\t\t\t\titemId = undefined;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst canReplayNamespace = isSameModel || options?.deferredTools?.has(toolCall.name) === true;\n\n\t\t\t\t\tif (customInputProperty !== undefined) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"custom_tool_call\",\n\t\t\t\t\t\t\t...(itemId !== undefined ? { id: itemId } : {}),\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\tinput: sanitizeSurrogates(\n\t\t\t\t\t\t\t\tgetGrammarToolInput(toolCall.name, toolCall.arguments, customInputProperty),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallItem);\n\t\t\t\t\t} else if (isFreeform) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"custom_tool_call\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\tinput: getFreeformToolInput(toolCall.arguments),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallItem);\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\t\t...(itemId?.startsWith(\"fc_\") ? { id: itemId } : {}),\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t\t...(canReplayNamespace && toolCall.namespace !== undefined\n\t\t\t\t\t\t\t\t? { namespace: toolCall.namespace }\n\t\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}\n\t\t\tif (output.length === 0) continue;\n\t\t\tmessages.push(...output.map((item) => withContextProvenance(item, msg, options?.sealContextProvenance)));\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst [callId, itemIdRaw] = msg.toolCallId.split(\"|\");\n\t\t\tconst output = convertToolResultOutput(model, msg.content);\n\t\t\tconst customInputProperty = options?.grammarToolInputProperties?.get(msg.toolName);\n\t\t\tconst isPersistedFreeform = itemIdRaw === CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL;\n\n\t\t\tif (customInputProperty !== undefined) {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallOutputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (isFreeformToolName(msg.toolName, context.tools) || isPersistedFreeform) {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\tname: msg.toolName,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t} satisfies ResponseCustomToolCallOutputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{ type: \"function_call_output\", call_id: callId, output },\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst deferredTools: Tool[] = [];\n\t\t\tfor (const name of msg.addedToolNames ?? []) {\n\t\t\t\tconst tool = options?.deferredTools?.get(name);\n\t\t\t\tif (!tool || loadedToolNames.has(name)) continue;\n\t\t\t\tloadedToolNames.add(name);\n\t\t\t\tdeferredTools.push(tool);\n\t\t\t}\n\t\t\tif (deferredTools.length > 0 && options?.deferredToolsMode === \"additional-tools\") {\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"additional_tools\",\n\t\t\t\t\t\t\trole: \"developer\",\n\t\t\t\t\t\t\ttools: convertResponsesTools(deferredTools, options.toolOptions),\n\t\t\t\t\t\t} satisfies ResponseInputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (deferredTools.length > 0 && options?.deferredToolsMode === \"tool-search\") {\n\t\t\t\tconst names = deferredTools.map((tool) => tool.name);\n\t\t\t\tconst searchCallId = `pi_tool_load_${shortHash(`${msg.toolCallId}:${names.join(\",\")}`)}`;\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"tool_search_call\",\n\t\t\t\t\t\t\tcall_id: searchCallId,\n\t\t\t\t\t\t\texecution: \"client\",\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\targuments: { query: names.join(\" \"), limit: names.length },\n\t\t\t\t\t\t} satisfies ResponseInputItem,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tmessages.push(\n\t\t\t\t\twithContextProvenance(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"tool_search_output\",\n\t\t\t\t\t\t\tcall_id: searchCallId,\n\t\t\t\t\t\t\texecution: \"client\",\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\ttools: convertResponsesTools(deferredTools, {\n\t\t\t\t\t\t\t\t...options?.toolOptions,\n\t\t\t\t\t\t\t\tdeferLoading: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t} satisfies ResponseToolSearchOutputItemParam,\n\t\t\t\t\t\tmsg,\n\t\t\t\t\t\toptions?.sealContextProvenance,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tmsgIndex++;\n\t}\n\n\treturn messages as ResponseInput;\n}\n\n// =============================================================================\n// Tool conversion\n// =============================================================================\n\nexport function convertResponsesTools(tools: readonly Tool[], options?: ConvertResponsesToolsOptions): OpenAITool[] {\n\tconst defaultStrict = options?.strict === undefined ? false : options.strict;\n\tconst supportsStrictMode = options?.supportsStrictMode ?? true;\n\tconst supportsOpenAIGrammarTools = options?.supportsOpenAIGrammarTools ?? false;\n\n\treturn tools.map((tool) => {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\treturn {\n\t\t\t\ttype: \"custom\",\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tformat: {\n\t\t\t\t\ttype: \"grammar\",\n\t\t\t\t\tsyntax: grammar.format,\n\t\t\t\t\tdefinition: grammar.definition,\n\t\t\t\t},\n\t\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t\t} satisfies OpenAITool;\n\t\t}\n\t\tif (tool.freeform) {\n\t\t\treturn {\n\t\t\t\ttype: \"custom\",\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tformat: tool.freeform,\n\t\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t\t} as OpenAITool;\n\t\t}\n\n\t\tconst constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);\n\t\tconst strict = constrainedStrict ?? defaultStrict;\n\t\tconst functionTool: Omit<ResponseFunctionTool, \"strict\"> & {\n\t\t\tstrict?: ResponseFunctionTool[\"strict\"];\n\t\t} = {\n\t\t\ttype: \"function\",\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: getJsonSchemaToolParameters(tool, strict === true) as ResponseFunctionTool[\"parameters\"],\n\t\t\t...(options?.deferLoading ? { defer_loading: true } : {}),\n\t\t};\n\t\tif (supportsStrictMode) {\n\t\t\tfunctionTool.strict = strict;\n\t\t}\n\t\treturn functionTool as OpenAITool;\n\t});\n}\n\n// =============================================================================\n// Stream processing\n// =============================================================================\n\ntype StreamingToolCall = ToolCall & {\n\tpartialJson?: string;\n\tcustomInput?: {\n\t\tproperty: string;\n\t\tjsonBuffer: GrammarToolInputJsonBuffer;\n\t};\n};\n\nfunction getCustomToolCallInput(block: StreamingToolCall): string {\n\tconst property = block.customInput?.property;\n\tif (property === undefined) return \"\";\n\tconst value = block.arguments[property];\n\treturn typeof value === \"string\" ? value : \"\";\n}\n\nfunction appendCustomToolCallInput(block: StreamingToolCall, nextInput: string, close: boolean): string | undefined {\n\tconst customInput = block.customInput;\n\tif (!customInput) return undefined;\n\tconst delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);\n\tblock.arguments = { [customInput.property]: nextInput };\n\treturn delta;\n}\n\ntype ResponsesOutputSlot =\n\t| { type: \"thinking\"; block: ThinkingContent; contentIndex: number }\n\t| { type: \"text\"; block: TextContent; contentIndex: number }\n\t| { type: \"toolCall\"; block: StreamingToolCall; contentIndex: number }\n\t| { type: \"providerNative\"; block: ProviderNativeContent; contentIndex: number };\n\ntype ToolCallOutputSlot = Extract<ResponsesOutputSlot, { type: \"toolCall\" }>;\n\ntype NativeImageGenerationCall = {\n\ttype: \"image_generation_call\";\n\tid?: string;\n\tstatus: string;\n\tresult?: string | null;\n\trevised_prompt?: string;\n};\n\nconst MAX_NATIVE_IMAGE_BASE64_CHARS = 24 * 1024 * 1024;\n\nfunction readNativeImageGenerationCall(value: unknown): NativeImageGenerationCall | undefined {\n\tif (typeof value !== \"object\" || value === null || !(\"type\" in value) || !(\"status\" in value)) return undefined;\n\tif (value.type !== \"image_generation_call\" || typeof value.status !== \"string\") return undefined;\n\treturn {\n\t\ttype: \"image_generation_call\",\n\t\t...(\"id\" in value && typeof value.id === \"string\" ? { id: value.id } : {}),\n\t\tstatus: value.status,\n\t\t...(\"result\" in value && (typeof value.result === \"string\" || value.result === null)\n\t\t\t? { result: value.result }\n\t\t\t: {}),\n\t\t...(\"revised_prompt\" in value && typeof value.revised_prompt === \"string\"\n\t\t\t? { revised_prompt: value.revised_prompt }\n\t\t\t: {}),\n\t};\n}\n\nfunction isValidBase64(value: string): boolean {\n\treturn value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(value);\n}\n\nfunction reconcileNativeImageGenerationCall(item: NativeImageGenerationCall): NativeImageGenerationCall {\n\tif (item.status !== \"completed\") {\n\t\treturn {\n\t\t\ttype: \"image_generation_call\",\n\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\tstatus: item.status,\n\t\t};\n\t}\n\tif (typeof item.result !== \"string\" || !isValidBase64(item.result)) {\n\t\treturn {\n\t\t\ttype: \"image_generation_call\",\n\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\tstatus: \"malformed\",\n\t\t};\n\t}\n\treturn {\n\t\ttype: \"image_generation_call\",\n\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\tstatus: \"completed\",\n\t\tresult: item.result,\n\t\t...(item.revised_prompt?.trim() ? { revised_prompt: item.revised_prompt } : {}),\n\t};\n}\n\nexport async function processResponsesStream<TApi extends Api>(\n\topenaiStream: AsyncIterable<ResponseStreamEvent>,\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n\tmodel: Model<TApi>,\n\toptions?: OpenAIResponsesStreamOptions,\n): Promise<void> {\n\tlet sawTerminalResponseEvent = false;\n\tlet nativeImageBase64Chars = 0;\n\tconst outputSlots = new Map<number, ResponsesOutputSlot>();\n\tconst reasoningBlocksById = new Map<string, ThinkingContent>();\n\tconst nativeImageCharsByOutputIndex = new Map<number, number>();\n\tconst finalizedNativeImageOutputIndexes = new Set<number>();\n\tconst applyMessagePhaseStopReason = (item: ResponseOutputItem): void => {\n\t\tif (item.type === \"message\" && item.phase === \"final_answer\") {\n\t\t\toutput.stopReason = \"stop\";\n\t\t}\n\t};\n\tconst getSlot = <TType extends ResponsesOutputSlot[\"type\"]>(\n\t\toutputIndex: number,\n\t\ttype: TType,\n\t): Extract<ResponsesOutputSlot, { type: TType }> | undefined => {\n\t\tconst slot = outputSlots.get(outputIndex);\n\t\treturn slot?.type === type ? (slot as Extract<ResponsesOutputSlot, { type: TType }>) : undefined;\n\t};\n\tconst pushToolCallDelta = (slot: ToolCallOutputSlot, delta: string | undefined): void => {\n\t\tif (delta === undefined) return;\n\t\tstream.push({\n\t\t\ttype: \"toolcall_delta\",\n\t\t\tcontentIndex: slot.contentIndex,\n\t\t\tdelta,\n\t\t\tpartial: output,\n\t\t});\n\t};\n\tconst createSlot = (\n\t\toutputIndex: number,\n\t\titem: ResponseOutputItem | ResponseCustomToolCallItem,\n\t): ResponsesOutputSlot | undefined => {\n\t\tif (item.type === \"reasoning\") {\n\t\t\tconst block: ThinkingContent = { type: \"thinking\", thinking: \"\" };\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"thinking\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"thinking_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (item.type === \"message\") {\n\t\t\tapplyMessagePhaseStopReason(item);\n\t\t\tconst block: TextContent = { type: \"text\", text: \"\" };\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = { type: \"text\", block, contentIndex: output.content.length - 1 } satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"text_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (item.type === \"function_call\") {\n\t\t\tconst block: StreamingToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: `${item.call_id}|${item.id}`,\n\t\t\t\tname: item.name,\n\t\t\t\targuments: {},\n\t\t\t\t...(item.namespace !== undefined ? { namespace: item.namespace } : {}),\n\t\t\t\tpartialJson: item.arguments || \"\",\n\t\t\t};\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tif (isResponseCustomToolCallItem(item)) {\n\t\t\tconst inputProperty = options?.grammarToolInputProperties?.get(item.name) ?? \"input\";\n\t\t\tconst input = item.input || \"\";\n\t\t\tconst block: StreamingToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: `${item.call_id}|${item.id ?? CUSTOM_TOOL_CALL_ITEM_ID_SENTINEL}`,\n\t\t\t\tname: item.name,\n\t\t\t\targuments: { [inputProperty]: input },\n\t\t\t\t...(item.namespace !== undefined ? { namespace: item.namespace } : {}),\n\t\t\t\tcustomInput: {\n\t\t\t\t\tproperty: inputProperty,\n\t\t\t\t\tjsonBuffer: { input: \"\", started: false, closed: false },\n\t\t\t\t},\n\t\t\t};\n\t\t\toutput.content.push(block);\n\t\t\tconst slot = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tblock,\n\t\t\t\tcontentIndex: output.content.length - 1,\n\t\t\t} satisfies ResponsesOutputSlot;\n\t\t\toutputSlots.set(outputIndex, slot);\n\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n\t\t\treturn slot;\n\t\t}\n\t\tconst imageItem = readNativeImageGenerationCall(item);\n\t\tconst block = {\n\t\t\ttype: \"providerNative\",\n\t\t\tsubtype: item.type,\n\t\t\traw: imageItem ? reconcileNativeImageGenerationCall(imageItem) : item,\n\t\t} satisfies ProviderNativeContent;\n\t\tconst slot = {\n\t\t\ttype: \"providerNative\",\n\t\t\tblock,\n\t\t\tcontentIndex: output.content.length,\n\t\t} satisfies ResponsesOutputSlot;\n\t\tif (imageItem) reconcileNativeImageSlot(outputIndex, slot, imageItem);\n\t\toutput.content.push(block);\n\t\toutputSlots.set(outputIndex, slot);\n\t\treturn slot;\n\t};\n\tconst getOrCreateSlot = (\n\t\toutputIndex: number,\n\t\titem: ResponseOutputItem | ResponseCustomToolCallItem,\n\t): ResponsesOutputSlot | undefined => {\n\t\treturn outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);\n\t};\n\tfunction scrubNativeImageResults(): void {\n\t\tfor (const block of output.content) {\n\t\t\tif (block.type !== \"providerNative\" || block.subtype !== \"image_generation_call\") continue;\n\t\t\tconst item = readNativeImageGenerationCall(block.raw);\n\t\t\tif (typeof item?.result !== \"string\") continue;\n\t\t\tblock.raw = {\n\t\t\t\ttype: \"image_generation_call\",\n\t\t\t\t...(item.id !== undefined ? { id: item.id } : {}),\n\t\t\t\tstatus: \"malformed\",\n\t\t\t};\n\t\t}\n\t\tnativeImageBase64Chars = 0;\n\t\tnativeImageCharsByOutputIndex.clear();\n\t}\n\tfunction reconcileNativeImageSlot(\n\t\toutputIndex: number,\n\t\tslot: Extract<ResponsesOutputSlot, { type: \"providerNative\" }>,\n\t\titem: NativeImageGenerationCall,\n\t): void {\n\t\tconst reconciled = reconcileNativeImageGenerationCall(item);\n\t\tconst previousChars = nativeImageCharsByOutputIndex.get(outputIndex) ?? 0;\n\t\tconst nextChars = typeof reconciled.result === \"string\" ? reconciled.result.length : 0;\n\t\tconst nextTotal = nativeImageBase64Chars - previousChars + nextChars;\n\t\tif (nextTotal > MAX_NATIVE_IMAGE_BASE64_CHARS) {\n\t\t\tscrubNativeImageResults();\n\t\t\tthrow new Error(\"Native image generation results exceed the 24 MiB base64 limit\");\n\t\t}\n\t\tnativeImageBase64Chars = nextTotal;\n\t\tif (nextChars > 0) nativeImageCharsByOutputIndex.set(outputIndex, nextChars);\n\t\telse nativeImageCharsByOutputIndex.delete(outputIndex);\n\t\tslot.block.subtype = \"image_generation_call\";\n\t\tslot.block.raw = reconciled;\n\t}\n\tconst backfillNativeImageGenerationCalls = (responseOutput: readonly ResponseOutputItem[]): void => {\n\t\tfor (const [outputIndex, outputItem] of responseOutput.entries()) {\n\t\t\tif (finalizedNativeImageOutputIndexes.has(outputIndex)) continue;\n\t\t\tconst imageItem = readNativeImageGenerationCall(outputItem);\n\t\t\tif (!imageItem) continue;\n\t\t\tconst existingSlot = getSlot(outputIndex, \"providerNative\");\n\t\t\tif (existingSlot) reconcileNativeImageSlot(outputIndex, existingSlot, imageItem);\n\t\t\telse createSlot(outputIndex, outputItem);\n\t\t\toutputSlots.delete(outputIndex);\n\t\t}\n\t};\n\t// Azure OpenAI can omit reasoning.encrypted_content from response.output_item.done\n\t// and provide it only in response.completed.response.output. Backfill the\n\t// persisted reasoning signature from the terminal response to keep store:false\n\t// multi-turn replay stateless. See https://github.com/earendil-works/pi/issues/6409.\n\tconst backfillReasoningSignatures = (responseOutput: ResponseOutputItem[]): void => {\n\t\tfor (const item of responseOutput) {\n\t\t\tif (item.type !== \"reasoning\" || !item.encrypted_content) continue;\n\t\t\tconst block = reasoningBlocksById.get(item.id);\n\t\t\tif (!block?.thinkingSignature) continue;\n\n\t\t\tconst storedItem = parseReasoningSignature(block.thinkingSignature);\n\t\t\tif (!storedItem || storedItem.encrypted_content) continue;\n\t\t\tblock.thinkingSignature = JSON.stringify({\n\t\t\t\t...storedItem,\n\t\t\t\tencrypted_content: item.encrypted_content,\n\t\t\t});\n\t\t}\n\t};\n\tconst finalizeResponse = (\n\t\tresponse: Extract<ResponseStreamEvent, { type: \"response.completed\" | \"response.incomplete\" }>[\"response\"],\n\t) => {\n\t\tsawTerminalResponseEvent = true;\n\t\tbackfillReasoningSignatures(response.output ?? []);\n\t\tbackfillNativeImageGenerationCalls(response.output ?? []);\n\t\tif (response?.id) {\n\t\t\toutput.responseId = response.id;\n\t\t}\n\t\tif (response?.usage) {\n\t\t\tconst inputDetails = response.usage.input_tokens_details as\n\t\t\t\t| { cached_tokens?: number; cache_write_tokens?: number }\n\t\t\t\t| undefined;\n\t\t\tconst cachedTokens = inputDetails?.cached_tokens || 0;\n\t\t\tconst cacheWriteTokens = inputDetails?.cache_write_tokens || 0;\n\t\t\toutput.usage = {\n\t\t\t\t// OpenAI includes cached and cache-write tokens in input_tokens, so subtract both.\n\t\t\t\tinput: Math.max(0, (response.usage.input_tokens || 0) - cachedTokens - cacheWriteTokens),\n\t\t\t\toutput: response.usage.output_tokens || 0,\n\t\t\t\tcacheRead: cachedTokens,\n\t\t\t\tcacheWrite: cacheWriteTokens,\n\t\t\t\treasoning: response.usage.output_tokens_details?.reasoning_tokens || 0,\n\t\t\t\ttotalTokens: response.usage.total_tokens || 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t};\n\t\t}\n\t\tcalculateCost(model, output.usage);\n\t\tif (options?.applyServiceTierPricing) {\n\t\t\tconst serviceTier = options.resolveServiceTier\n\t\t\t\t? options.resolveServiceTier(response?.service_tier, options.serviceTier)\n\t\t\t\t: (response?.service_tier ?? options.serviceTier);\n\t\t\toptions.applyServiceTierPricing(output.usage, serviceTier);\n\t\t}\n\t\t// Map status to stop reason. For incomplete responses, retain the provider's\n\t\t// specific reason so max-output truncation and content filtering stay distinct.\n\t\tconst status = response?.status;\n\t\tconst incompleteDetails = response?.incomplete_details as { reason?: unknown } | null | undefined;\n\t\tconst incompleteReason = typeof incompleteDetails?.reason === \"string\" ? incompleteDetails.reason : undefined;\n\t\toutput.rawStopReason = incompleteReason ? `${status}.${incompleteReason}` : status;\n\t\tconst mappedStop = mapStopReason(status, incompleteReason);\n\t\toutput.stopReason = mappedStop.stopReason;\n\t\tif (mappedStop.errorMessage === undefined) delete output.errorMessage;\n\t\telse output.errorMessage = mappedStop.errorMessage;\n\t\tif (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n\t\t\toutput.stopReason = \"toolUse\";\n\t\t}\n\t};\n\n\tfor await (const event of withResponsesCompletionGrace(openaiStream)) {\n\t\tif (event.type === \"response.created\") {\n\t\t\toutput.responseId = event.response.id;\n\t\t} else if (event.type === \"response.output_item.added\") {\n\t\t\tcreateSlot(event.output_index, event.item);\n\t\t} else if (event.type === \"response.reasoning_summary_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.reasoning_summary_part.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += \"\\n\\n\";\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: \"\\n\\n\",\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.reasoning_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"thinking\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.thinking += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.output_text.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"text\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.text += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.refusal.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"text\");\n\t\t\tif (!slot) continue;\n\t\t\tslot.block.text += event.delta;\n\t\t\tstream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\tdelta: event.delta,\n\t\t\t\tpartial: output,\n\t\t\t});\n\t\t} else if (event.type === \"response.function_call_arguments.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot || slot.block.partialJson === undefined) continue;\n\t\t\tslot.block.partialJson += event.delta;\n\t\t\tslot.block.arguments = parseStreamingJson(slot.block.partialJson);\n\t\t\tpushToolCallDelta(slot, event.delta);\n\t\t} else if (event.type === \"response.function_call_arguments.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot || slot.block.partialJson === undefined) continue;\n\t\t\tconst previousPartialJson = slot.block.partialJson;\n\t\t\tslot.block.partialJson = event.arguments;\n\t\t\tslot.block.arguments = parseStreamingJson(slot.block.partialJson);\n\n\t\t\tif (event.arguments.startsWith(previousPartialJson)) {\n\t\t\t\tconst delta = event.arguments.slice(previousPartialJson.length);\n\t\t\t\tif (delta.length > 0) pushToolCallDelta(slot, delta);\n\t\t\t}\n\t\t} else if (event.type === \"response.custom_tool_call_input.delta\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot?.block.customInput) continue;\n\t\t\tpushToolCallDelta(\n\t\t\t\tslot,\n\t\t\t\tappendCustomToolCallInput(slot.block, getCustomToolCallInput(slot.block) + event.delta, false),\n\t\t\t);\n\t\t} else if (event.type === \"response.custom_tool_call_input.done\") {\n\t\t\tconst slot = getSlot(event.output_index, \"toolCall\");\n\t\t\tif (!slot?.block.customInput) continue;\n\t\t\tpushToolCallDelta(slot, appendCustomToolCallInput(slot.block, event.input, true));\n\t\t} else if (event.type === \"response.output_item.done\") {\n\t\t\tconst item = event.item;\n\t\t\tapplyMessagePhaseStopReason(item);\n\t\t\tconst slot = getOrCreateSlot(event.output_index, item);\n\t\t\tconst imageItem = readNativeImageGenerationCall(item);\n\n\t\t\tif (imageItem && slot?.type === \"providerNative\") {\n\t\t\t\treconcileNativeImageSlot(event.output_index, slot, imageItem);\n\t\t\t\tfinalizedNativeImageOutputIndexes.add(event.output_index);\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"reasoning\" && slot?.type === \"thinking\") {\n\t\t\t\tconst summaryText = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\tconst contentText = item.content?.map((c) => c.text).join(\"\\n\\n\") || \"\";\n\t\t\t\tslot.block.thinking = summaryText || contentText || slot.block.thinking;\n\t\t\t\tslot.block.thinkingSignature = JSON.stringify(item);\n\t\t\t\treasoningBlocksById.set(item.id, slot.block);\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\tcontent: slot.block.thinking,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"message\" && slot?.type === \"text\") {\n\t\t\t\tslot.block.text = item.content?.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\") || \"\";\n\t\t\t\tslot.block.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\tcontent: slot.block.text,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (\n\t\t\t\titem.type === \"function_call\" &&\n\t\t\t\tslot?.type === \"toolCall\" &&\n\t\t\t\tslot.block.partialJson !== undefined\n\t\t\t) {\n\t\t\t\tslot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || \"{}\");\n\t\t\t\tif (item.namespace !== undefined) slot.block.namespace = item.namespace;\n\t\t\t\t// Finalize in-place and strip the scratch buffer so replay only\n\t\t\t\t// carries parsed arguments.\n\t\t\t\tdelete slot.block.partialJson;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (item.type === \"custom_tool_call\" && slot?.type === \"toolCall\" && slot.block.customInput) {\n\t\t\t\tpushToolCallDelta(\n\t\t\t\t\tslot,\n\t\t\t\t\tappendCustomToolCallInput(slot.block, item.input ?? getCustomToolCallInput(slot.block), true),\n\t\t\t\t);\n\t\t\t\tif (item.namespace !== undefined) slot.block.namespace = item.namespace;\n\t\t\t\tdelete slot.block.customInput;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (isResponseCustomToolCallItem(item) && slot?.type === \"toolCall\") {\n\t\t\t\tconst input = typeof item.input === \"string\" ? item.input : \"\";\n\t\t\t\tslot.block.arguments = { input };\n\t\t\t\tdelete (slot.block as { partialJson?: string }).partialJson;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tcontentIndex: slot.contentIndex,\n\t\t\t\t\ttoolCall: slot.block,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t} else if (slot?.type === \"providerNative\") {\n\t\t\t\tslot.block.subtype = item.type;\n\t\t\t\tslot.block.raw = item;\n\t\t\t\toutputSlots.delete(event.output_index);\n\t\t\t}\n\t\t} else if (event.type === \"response.completed\" || event.type === \"response.incomplete\") {\n\t\t\tfinalizeResponse(event.response);\n\t\t} else if (event.type === \"error\") {\n\t\t\tthrow new Error(`Error Code ${event.code}: ${event.message}` || \"Unknown error\");\n\t\t} else if (event.type === \"response.failed\") {\n\t\t\tsawTerminalResponseEvent = true;\n\t\t\toutput.rawStopReason = event.response?.status;\n\t\t\tconst error = event.response?.error;\n\t\t\tconst details = event.response?.incomplete_details;\n\t\t\tconst msg = error\n\t\t\t\t? `${error.code || \"unknown\"}: ${error.message || \"no message\"}`\n\t\t\t\t: details?.reason\n\t\t\t\t\t? `incomplete: ${details.reason}`\n\t\t\t\t\t: \"Unknown error (no error details in response)\";\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\tconst hasFinalizedToolCall = output.content.some((block) => block.type === \"toolCall\" && !(\"partialJson\" in block));\n\tif (!sawTerminalResponseEvent && !hasFinalizedToolCall) {\n\t\tthrow new Error(\"OpenAI Responses stream ended before a terminal response event\");\n\t}\n}\n\nfunction mapStopReason(\n\tstatus: OpenAI.Responses.ResponseStatus | undefined,\n\tincompleteReason?: string,\n): { stopReason: StopReason; errorMessage?: string } {\n\tif (!status) return { stopReason: \"stop\" };\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tcase \"incomplete\":\n\t\t\tif (incompleteReason === \"max_output_tokens\") {\n\t\t\t\treturn { stopReason: \"length\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstopReason: \"error\",\n\t\t\t\terrorMessage: incompleteReason\n\t\t\t\t\t? `Response incomplete: ${incompleteReason}`\n\t\t\t\t\t: \"Response incomplete without a provider reason\",\n\t\t\t};\n\t\tcase \"failed\":\n\t\tcase \"cancelled\":\n\t\t\treturn { stopReason: \"error\" };\n\t\t// These two are wonky ...\n\t\tcase \"in_progress\":\n\t\tcase \"queued\":\n\t\t\treturn { stopReason: \"stop\" };\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = status;\n\t\t\tthrow new Error(`Unhandled stop reason: ${_exhaustive}`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAuB,MAAM,yCAAyC,CAAC;AAElH,OAAO,KAAK,EASX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAEb,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"openai-responses.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAuB,MAAM,yCAAyC,CAAC;AAElH,OAAO,KAAK,EASX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAEb,MAAM,aAAa,CAAC;AAyBrB,KAAK,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AACnF,KAAK,iBAAiB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAElD,UAAU,aAAa;IACtB,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC9E,mBAAmB,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACjF;AAED,MAAM,WAAW,yBAAyB;IACzC,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;CAC1C;AAyID,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC5D,eAAe,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;IAC1E,gBAAgB,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1D,WAAW,CAAC,EAAE,6BAA6B,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;IACrE,UAAU,CAAC,EAAE,6BAA6B,CAAC,aAAa,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,kBAAkB,EAAE,sBAAsB,CA8I7E,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,kBAAkB,EAAE,mBAAmB,CAwBhF,CAAC;AAiLF;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAmBxG;AAED,mEAAmE;AACnE,wBAAgB,oCAAoC,IAAI,MAAM,CAE7D"}
|
|
@@ -15,7 +15,8 @@ import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
|
|
|
15
15
|
import { convertResponsesMessages, convertResponsesTools, processResponsesStream } from "./openai-responses-shared.js";
|
|
16
16
|
import { buildBaseOptions, clampMaxForOpenAI, OPENAI_RESPONSES_RESERVED_BODY_KEYS } from "./simple-options.js";
|
|
17
17
|
import { startWebSocketLiveness } from "./websocket-liveness.js";
|
|
18
|
-
|
|
18
|
+
import { createWebSocketTransportFailure } from "./websocket-transport-failure.js";
|
|
19
|
+
const OPENAI_TOOL_CALL_PROVIDERS = new Set(["openai", "chatgpt-subscription", "opencode"]);
|
|
19
20
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
20
21
|
const OPENAI_WEB_SEARCH_SOURCES_INCLUDE = "web_search_call.action.sources";
|
|
21
22
|
const SESSION_WEBSOCKET_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
@@ -428,6 +429,7 @@ async function connectWebSocket(url, headers, signal) {
|
|
|
428
429
|
let settled = false;
|
|
429
430
|
let socket;
|
|
430
431
|
const cleanup = () => {
|
|
432
|
+
transportFailure.dispose();
|
|
431
433
|
socket.removeEventListener("open", onOpen);
|
|
432
434
|
socket.removeEventListener("error", onError);
|
|
433
435
|
socket.removeEventListener("close", onClose);
|
|
@@ -440,6 +442,7 @@ async function connectWebSocket(url, headers, signal) {
|
|
|
440
442
|
cleanup();
|
|
441
443
|
reject(error);
|
|
442
444
|
};
|
|
445
|
+
const transportFailure = createWebSocketTransportFailure(settleReject);
|
|
443
446
|
const onOpen = () => {
|
|
444
447
|
if (settled)
|
|
445
448
|
return;
|
|
@@ -448,10 +451,10 @@ async function connectWebSocket(url, headers, signal) {
|
|
|
448
451
|
resolve(socket);
|
|
449
452
|
};
|
|
450
453
|
const onError = (event) => {
|
|
451
|
-
|
|
454
|
+
transportFailure.onError(event);
|
|
452
455
|
};
|
|
453
456
|
const onClose = (event) => {
|
|
454
|
-
|
|
457
|
+
transportFailure.onClose(event);
|
|
455
458
|
};
|
|
456
459
|
const onAbort = () => {
|
|
457
460
|
if (settled)
|
|
@@ -525,25 +528,6 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
525
528
|
},
|
|
526
529
|
};
|
|
527
530
|
}
|
|
528
|
-
function extractWebSocketError(event) {
|
|
529
|
-
if (event && typeof event === "object" && "message" in event) {
|
|
530
|
-
const message = event.message;
|
|
531
|
-
if (typeof message === "string" && message.length > 0) {
|
|
532
|
-
return new Error(message);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return new Error("WebSocket error");
|
|
536
|
-
}
|
|
537
|
-
function extractWebSocketCloseError(event) {
|
|
538
|
-
if (event && typeof event === "object") {
|
|
539
|
-
const code = "code" in event ? event.code : undefined;
|
|
540
|
-
const reason = "reason" in event ? event.reason : undefined;
|
|
541
|
-
const codeText = typeof code === "number" ? ` ${code}` : "";
|
|
542
|
-
const reasonText = typeof reason === "string" && reason.length > 0 ? ` ${reason}` : "";
|
|
543
|
-
return new Error(`WebSocket closed${codeText}${reasonText}`.trim());
|
|
544
|
-
}
|
|
545
|
-
return new Error("WebSocket closed");
|
|
546
|
-
}
|
|
547
531
|
async function decodeWebSocketData(data) {
|
|
548
532
|
if (typeof data === "string")
|
|
549
533
|
return data;
|
|
@@ -598,17 +582,23 @@ async function* parseWebSocket(socket, signal) {
|
|
|
598
582
|
catch { }
|
|
599
583
|
})();
|
|
600
584
|
};
|
|
601
|
-
const
|
|
602
|
-
|
|
585
|
+
const transportFailure = createWebSocketTransportFailure((error) => {
|
|
586
|
+
if (!failed)
|
|
587
|
+
failed = error;
|
|
603
588
|
done = true;
|
|
604
589
|
wake();
|
|
590
|
+
});
|
|
591
|
+
const onError = (event) => {
|
|
592
|
+
transportFailure.onError(event);
|
|
605
593
|
};
|
|
606
594
|
const onClose = (event) => {
|
|
607
|
-
if (
|
|
608
|
-
|
|
595
|
+
if (sawCompletion) {
|
|
596
|
+
transportFailure.dispose();
|
|
597
|
+
done = true;
|
|
598
|
+
wake();
|
|
599
|
+
return;
|
|
609
600
|
}
|
|
610
|
-
|
|
611
|
-
wake();
|
|
601
|
+
transportFailure.onClose(event);
|
|
612
602
|
};
|
|
613
603
|
const onAbort = () => {
|
|
614
604
|
failed = new Error("Request was aborted");
|
|
@@ -642,6 +632,7 @@ async function* parseWebSocket(socket, signal) {
|
|
|
642
632
|
}
|
|
643
633
|
finally {
|
|
644
634
|
liveness.stop();
|
|
635
|
+
transportFailure.dispose();
|
|
645
636
|
socket.removeEventListener("message", onMessage);
|
|
646
637
|
socket.removeEventListener("error", onError);
|
|
647
638
|
socket.removeEventListener("close", onClose);
|