@bastani/pi-ai 0.9.25-alpha.5 → 0.9.26-alpha.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,43 @@ This package is a Bastani fork of `@earendil-works/pi-ai`. Upstream history at t
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.9.26-alpha.1] - 2026-10-01
8
+
9
+ ### Changed
10
+
11
+ - OAuth browser pages now show the Atomic logo in color instead of white.
12
+
13
+ ### Fixed
14
+
15
+ - Fixed OpenAI Responses requests failing with `Expected an ID that begins with 'ctc'` when replaying grammar tool calls, such as `codemode`, from another provider or a gateway.
16
+ - Fixed Together's `deepseek-ai/DeepSeek-V4-Pro-0813` (the renamed DeepSeek V4 Pro) losing its `high` reasoning control after the model catalog refreshed.
17
+
18
+ ## [0.9.25] - 2026-10-01
19
+
20
+ ### Added
21
+
22
+ - Added Anthropic workload identity federation from the Anthropic SDK environment variables `ANTHROPIC_FEDERATION_RULE_ID`, `ANTHROPIC_ORGANIZATION_ID`, and `ANTHROPIC_IDENTITY_TOKEN_FILE` (plus optional `ANTHROPIC_SERVICE_ACCOUNT_ID` and `ANTHROPIC_WORKSPACE_ID`). API keys and `ANTHROPIC_AUTH_TOKEN` take precedence ([#10177](https://github.com/earendil-works/pi/issues/10177), [#10242](https://github.com/earendil-works/pi/pull/10242) by [@philfreo](https://github.com/philfreo)).
23
+ - Anthropic subscription login now offers a copy-code method for remote or headless machines, alongside the default browser callback method ([#10194](https://github.com/earendil-works/pi/pull/10194) by [@lucasmeijer](https://github.com/lucasmeijer)).
24
+ - Added GPT-6.1 Sol for OpenAI and Codex with supported reasoning efforts, prompt-cache and tool capabilities, and long-context pricing metadata.
25
+ - Added GPT-6.1 Sol to the GitHub Copilot catalog with Copilot's Responses endpoint, supported reasoning efforts, and provider-published context and output limits. Availability remains subject to the account's model policy.
26
+ - Added **Sign in with ChatGPT** for the OpenAI Responses API alongside API-key authentication, separate from Codex subscription login.
27
+ - Added Jev classifiers on Vercel AI Gateway and OpenCode Zen, and provider-reported classifier usage and costs, including billed responses with invalid answers.
28
+ - Added the lightweight `@bastani/pi-ai/models` entry point for model catalog consumers.
29
+ - Added `Model.serviceTiers` and `getServiceTierCost()` for the Fast and Ultrafast tiers a model advertises and their published rates. The OpenAI catalog follows OpenAI's Fast and Ultrafast pricing tables. The Codex catalog follows Codex's per-model tiers: Fast for every model except GPT-5.3 Codex Spark, and Ultrafast for GPT-6 Astra.
30
+ - The OpenAI Responses adapter can send GPT-6 Astra's `ultrafast` tier.
31
+
32
+ ### Changed
33
+
34
+ - The Codex Responses adapter sends `service_tier` only when the model advertises it, following Codex: `flex` always passes through, `default` sends no tier, and an unadvertised tier is left out instead of failing.
35
+ - The OpenAI Responses adapter leaves out a Fast or Ultrafast tier the model doesn't advertise. It sends other tiers as requested.
36
+ - Fast and Ultrafast usage is priced at the served tier's published rates. A model without tier metadata keeps the previous Fast multiplier.
37
+
38
+ ### Fixed
39
+
40
+ - Fixed context overflow detection for Z.AI CN endpoint `Prompt exceeds max length` errors ([#10208](https://github.com/earendil-works/pi/issues/10208)).
41
+ - Anthropic `strict: "prefer"` tools now fall back to non-strict mode for unsupported string formats and additional array/object constraints instead of rejecting the request. Supported string length and pattern constraints remain strict ([#9953](https://github.com/earendil-works/pi/issues/9953)).
42
+ - Provider retries now use exponential backoff when `Retry-After` or `retry-after-ms` cannot be parsed as a finite delay ([#9571](https://github.com/earendil-works/pi/issues/9571)).
43
+
7
44
  ## [0.9.25-alpha.3] - 2026-09-30
8
45
 
9
46
  ### Added
package/NOTICE.md CHANGED
@@ -6,7 +6,7 @@ monorepo at `packages/ai` and publishes at the same version as `@bastani/atomic`
6
6
 
7
7
  - Upstream package: [`@earendil-works/pi-ai`](https://www.npmjs.com/package/@earendil-works/pi-ai)
8
8
  - Original fork point: `v0.84.2` (`914cf1472e715297caa30db4b9535d534a9eb718`)
9
- - Applicable Pi AI fixes synced through audited upstream `main`: `earendil-works/pi@7a11fe1c723b942fa093edb8b00f051ddb9b6627`, with remaining registry Pi packages at `0.99.2`. Atomic retains its adaptations and does not enable upstream virtual models.
9
+ - Applicable Pi AI fixes synced through audited upstream `main`: `earendil-works/pi@86dfceec402ad77e563bf4feab5f26c42d5f5db6`, with remaining registry Pi packages at `1.0.0`. Atomic retains its adaptations and does not enable upstream virtual models.
10
10
  - Catalog JSON under `src/providers/data/` is generated at build time from models.dev, matching upstream. It is not committed.
11
11
 
12
12
  Original work is Copyright (c) 2025 Mario Zechner and is licensed under the MIT License.
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses-shared.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,IAAI,IAAI,UAAU,EAClB,6BAA6B,EAC7B,aAAa,EAQb,mBAAmB,EAEnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAEhB,KAAK,EAGL,aAAa,EAKb,IAAI,EAEJ,iBAAiB,EACjB,KAAK,EACL,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AA6E5E;;;;;;;;;;;;;;;GAeG;AACH,kFAAkF;AAClF,MAAM,MAAM,oBAAoB,GAAG,6BAA6B,CAAC,cAAc,CAAC,GAAG,WAAW,CAAC;AAE/F,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EACpC,kBAAkB,EAAE,oBAAoB,GAAG,SAAS,GAClD,oBAAoB,GAAG,SAAS,CAElC;AAOD;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,EACvC,WAAW,EAAE,oBAAoB,GAC/B,OAAO,CAKT;AAED,+GAA+G;AAC/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OAAO,GAAG,IAAI,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAMD,wBAAgB,wBAAwB,CAAC,IAAI,SAAS,GAAG,EACxD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,iBAAiB,EAC1B,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAAC,EAC7C,OAAO,CAAC,EAAE,+BAA+B,GACvC,aAAa,CA4Mf;AAMD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,UAAU,EAAE,CAqClH;AAoCD,wBAAsB,sBAAsB,CAAC,IAAI,SAAS,GAAG,EAC5D,YAAY,EAAE,aAAa,CAAC,mBAAmB,CAAC,EAChD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,2BAA2B,EACnC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,CAAC,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAkVf"}
@@ -317,12 +317,13 @@ export function convertResponsesMessages(model, context, allowedToolCallProvider
317
317
  const customInputProperty = options?.grammarToolInputProperties?.get(toolCall.name);
318
318
  let itemId = itemIdRaw;
319
319
  // For different-model messages, set id to undefined to avoid pairing validation.
320
- // OpenAI tracks which fc_xxx IDs were paired with rs_xxx reasoning items.
320
+ // OpenAI tracks which item IDs were paired with rs_xxx reasoning items.
321
321
  // By omitting the id, we avoid triggering that validation (like cross-provider does).
322
- // When replaying custom-tool calls as a function_call, also drop non-fc_* ids such as
323
- // ctc_* custom-tool ids because function_call item ids must be fc_*.
324
- if ((isDifferentModel && itemId?.startsWith("fc_")) ||
325
- (customInputProperty === undefined && !itemId?.startsWith("fc_"))) {
322
+ // Also drop ids that do not match the replayed item type: function_call ids must be fc_*
323
+ // and custom_tool_call ids must be ctc_*. Foreign tool call ids are normalized to fc_*, and
324
+ // a call can switch between the two types when grammar tool support differs.
325
+ const itemIdPrefix = customInputProperty === undefined ? "fc_" : "ctc_";
326
+ if (isDifferentModel || !itemId?.startsWith(itemIdPrefix)) {
326
327
  itemId = undefined;
327
328
  }
328
329
  if (customInputProperty !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses-shared.js","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAmBjE,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,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EACN,+BAA+B,EAE/B,mBAAmB,EACnB,2BAA2B,EAC3B,iCAAiC,EACjC,+BAA+B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,SAAS,qBAAqB,CAAC,EAAU,EAAE,KAAgC;IAC1E,MAAM,OAAO,GAAoB,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAC9C,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,kBAAkB,CAC1B,SAA6B;IAE7B,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,IAAI,SAAS,C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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\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputItem,\n\tResponseInputText,\n\tResponseOutputItem,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n\tResponseStreamEvent,\n\tResponseToolSearchOutputItemParam,\n} from \"openai/resources/responses/responses.js\";\nimport { calculateCost, getServiceTierCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tModel,\n\tModelServiceTierId,\n\tStopReason,\n\tStreamOptions,\n\tSystemMessage,\n\tTextContent,\n\tTextSignatureV1,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tTranscriptContext,\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 { getSystemMessageText, renderSystemMessageUpdate } from \"../utils/text.ts\";\nimport { resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport {\n\tappendGrammarToolInputJsonDelta,\n\ttype GrammarToolInputJsonBuffer,\n\tgetGrammarToolInput,\n\tgetJsonSchemaToolParameters,\n\tresolveGrammarConstrainedSampling,\n\tresolveJsonSchemaStrictSampling,\n} from \"./constrained-sampling.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\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\n/**\n * The service tier this request should carry.\n *\n * The **presence** of `fastRoute` is the discriminator, and its declared tier is the value. Fast\n * versus normal is model identity, so a caller who wants a different tier selects the normal sibling\n * rather than downgrading the fast one; letting a per-request option win would let a model selected,\n * recorded, persisted, and billed as `-fast` route as an ordinary request — and, because the Codex\n * routing identity keys on the final payload's tier, silently drop `originator: codex_cli_rs` too.\n *\n * A route that declares **no** tier means *no tier*, not \"fall through to the caller\". A GitHub\n * Copilot fast variant is exactly that case: it sends its own advertised `-fast` model ID and must\n * carry no OpenAI service-tier field at all, whatever the caller asks for.\n *\n * A normal model has no route, so an explicit `serviceTier` still applies there exactly as it did\n * before fast variants existed.\n */\n/** Codex accepts an additional tier not yet represented by the OpenAI API SDK. */\nexport type ResponsesServiceTier = ResponseCreateParamsStreaming[\"service_tier\"] | \"ultrafast\";\n\nexport function resolveRequestedServiceTier(\n\tmodel: Pick<Model<Api>, \"fastRoute\">,\n\toptionsServiceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn model.fastRoute ? model.fastRoute.serviceTier : optionsServiceTier;\n}\n\nfunction advertisedServiceTierId(serviceTier: ResponsesServiceTier | undefined): ModelServiceTierId | undefined {\n\tif (serviceTier === \"priority\" || serviceTier === \"fast\") return \"priority\";\n\treturn serviceTier === \"ultrafast\" ? \"ultrafast\" : undefined;\n}\n\n/**\n * Whether the model offers a Fast or Ultrafast tier. A model without tier metadata keeps offering Fast\n * but never Ultrafast. Other tiers (`flex`, `default`, `auto`, `scale`) need no advertisement.\n */\nexport function supportsServiceTier(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier,\n): boolean {\n\tconst advertisedId = advertisedServiceTierId(serviceTier);\n\tif (advertisedId === undefined) return true;\n\tif (model.serviceTiers === undefined) return advertisedId !== \"ultrafast\";\n\treturn getServiceTierCost(model, advertisedId) !== undefined;\n}\n\n/** OpenAI API: drop a Fast or Ultrafast tier the model does not advertise and send any other tier as asked. */\nexport function openAIServiceTierForRequest(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn serviceTier !== undefined && supportsServiceTier(model, serviceTier) ? serviceTier : undefined;\n}\n\n/**\n * Codex's `service_tier_for_request`: send `flex` or an advertised tier, and omit `default` and every\n * tier the model does not advertise.\n */\nexport function codexServiceTierForRequest(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\tif (serviceTier === \"flex\") return serviceTier;\n\treturn advertisedServiceTierId(serviceTier) !== undefined && supportsServiceTier(model, serviceTier)\n\t\t? serviceTier\n\t\t: undefined;\n}\n\n/**\n * Reprice usage at the tier that actually served the request, using the advertised tier's published\n * rates. A model without tier metadata keeps the documented Fast multiplier.\n */\nexport function applyServiceTierPricing(\n\tusage: Usage,\n\tserviceTier: ResponsesServiceTier | undefined,\n\tmodel: Model<Api>,\n): void {\n\tif (serviceTier === \"flex\") {\n\t\tscaleUsageCost(usage, 0.5);\n\t\treturn;\n\t}\n\tconst advertisedId = advertisedServiceTierId(serviceTier);\n\tif (advertisedId === undefined) return;\n\tconst tierCost = getServiceTierCost(model, advertisedId);\n\tif (tierCost) {\n\t\tcalculateCost({ ...model, cost: tierCost }, usage);\n\t\treturn;\n\t}\n\tif (advertisedId === \"priority\") {\n\t\tscaleUsageCost(usage, (model.fastRoute?.baseModelId ?? model.id) === \"gpt-5.5\" ? 2.5 : 2);\n\t}\n}\n\nfunction scaleUsageCost(usage: Usage, multiplier: number): void {\n\tusage.cost.input *= multiplier;\n\tusage.cost.output *= multiplier;\n\tusage.cost.cacheRead *= multiplier;\n\tusage.cost.cacheWrite *= multiplier;\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n}\n\ntype ServiceTier = NonNullable<ResponsesServiceTier>;\n\nexport function normalizeResponseServiceTier(serviceTier: string | null | undefined): ServiceTier | undefined {\n\tif (serviceTier === null || serviceTier === undefined) return undefined;\n\treturn serviceTier === \"fast\" ? \"priority\" : (serviceTier as ServiceTier);\n}\n\n/**\n * Reject a payload hook that rewrote a field the model's route owns.\n *\n * A fast variant is a distinct selected, recorded, persisted, and billed identity, and the objective\n * requires it to send its route's upstream model ID and tier. A hook that changes either would send a\n * different model — or an ordinary-tier request — under the `-fast` identity Atomic recorded, and the\n * Codex routing identity would faithfully advertise whatever the hook left behind.\n *\n * Following the repository's precedent for discarded caller instructions, this rejects loudly rather\n * than silently restoring the route's values, so a misconfigured hook surfaces instead of hiding. A\n * hook may still rewrite every other field, and a model without a route keeps unrestricted freedom.\n */\nexport function assertPayloadPreservesFastRoute(\n\tmodel: Pick<Model<Api>, \"fastRoute\" | \"id\" | \"provider\" | \"serviceTiers\">,\n\tpayload: unknown,\n): void {\n\tconst fastRoute = model.fastRoute;\n\tif (!fastRoute) return;\n\tif (typeof payload !== \"object\" || payload === null || Array.isArray(payload)) {\n\t\tthrow new Error(\n\t\t\t`A request hook changed payload for fast model \"${model.provider}/${model.id}\" to a value that cannot carry ` +\n\t\t\t\t`the route's upstream model and service tier. A fast model variant must send its route's upstream model and ` +\n\t\t\t\t`service tier, because it is recorded, persisted, and billed under its own identity. Select the normal model ` +\n\t\t\t\t`\"${model.provider}/${fastRoute.baseModelId}\" if the request needs different routing, or return an object that ` +\n\t\t\t\t`preserves those fields.`,\n\t\t);\n\t}\n\tconst record = payload as Record<string, unknown>;\n\tconst conflicts: string[] = [];\n\tif (record.model !== fastRoute.upstreamModelId) {\n\t\tconflicts.push(`model (expected \"${fastRoute.upstreamModelId}\", got ${JSON.stringify(record.model)})`);\n\t}\n\tconst expectedServiceTier =\n\t\tfastRoute.serviceTier !== undefined && supportsServiceTier(model, fastRoute.serviceTier)\n\t\t\t? fastRoute.serviceTier\n\t\t\t: undefined;\n\tif (record.service_tier !== expectedServiceTier) {\n\t\tconflicts.push(\n\t\t\t`service_tier (expected ${JSON.stringify(expectedServiceTier)}, got ${JSON.stringify(record.service_tier)})`,\n\t\t);\n\t}\n\tif (conflicts.length === 0) return;\n\tthrow new Error(\n\t\t`A request hook changed ${conflicts.join(\" and \")} for fast model \"${model.provider}/${model.id}\". ` +\n\t\t\t`A fast model variant must send its route's upstream model and service tier, because it is ` +\n\t\t\t`recorded, persisted, and billed under its own identity. Select the normal model \"${model.provider}/${fastRoute.baseModelId}\" ` +\n\t\t\t`if the request needs different routing, or stop rewriting those fields.`,\n\t);\n}\n\nexport interface OpenAIResponsesStreamOptions {\n\tonProviderStreamEvent?: StreamOptions[\"onProviderStreamEvent\"];\n\tserviceTier?: ResponsesServiceTier;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tresolveServiceTier?: (\n\t\tresponseServiceTier: ResponsesServiceTier | undefined,\n\t\trequestServiceTier: ResponsesServiceTier | undefined,\n\t) => ResponsesServiceTier | undefined;\n\tapplyServiceTierPricing?: (usage: Usage, serviceTier: ResponsesServiceTier | undefined) => void;\n}\n\nexport interface ConvertResponsesMessagesOptions {\n\tincludeSystemPrompt?: boolean;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\t/** Whether later system messages are sent in place; otherwise they are folded into the leading prompt. */\n\tsupportsMidConvoSystemMessages?: boolean;\n\tsupportsAdditionalTools?: boolean;\n\tsupportsToolSearch?: boolean;\n\ttoolOptions?: ConvertResponsesToolsOptions;\n}\n\nexport interface ConvertResponsesToolsOptions {\n\tstrict?: boolean | null;\n\tsupportsStrictMode?: boolean;\n\tsupportsOpenAIGrammarTools?: boolean;\n\ttoolSearchResult?: boolean;\n}\n\n// =============================================================================\n// Message conversion\n// =============================================================================\n\nexport function convertResponsesMessages<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: TranscriptContext,\n\tallowedToolCallProviders: ReadonlySet<string>,\n\toptions?: ConvertResponsesMessagesOptions,\n): ResponseInput {\n\tconst normalizedContext = resolveTranscript(context, options?.supportsMidConvoSystemMessages);\n\tconst messages: ResponseInput = [];\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 (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);\n\t\tif (!id.includes(\"|\")) return normalizeIdPart(id);\n\t\tconst [callId, itemId] = id.split(\"|\");\n\t\tconst normalizedCallId = normalizeIdPart(callId);\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(normalizedContext.messages, model, normalizeToolCallId);\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tnormalizedContext.messages,\n\t\t(options?.supportsAdditionalTools ?? false) || (options?.supportsToolSearch ?? false),\n\t);\n\tconst appendSystemToolAdditions = (message: SystemMessage, seed: string): void => {\n\t\tconst tools = transcriptTools.anchorsAdditions ? (message.toolsAdded ?? []) : [];\n\t\tif (tools.length === 0) return;\n\t\tif (options?.supportsAdditionalTools) {\n\t\t\tmessages.push({\n\t\t\t\ttype: \"additional_tools\",\n\t\t\t\trole: \"developer\",\n\t\t\t\ttools: convertResponsesTools(tools, options.toolOptions),\n\t\t\t} satisfies ResponseInputItem);\n\t\t\treturn;\n\t\t}\n\t\tif (!options?.supportsToolSearch) return;\n\t\tconst names = tools.map((tool) => tool.name);\n\t\tconst callId = `pi_tool_load_${shortHash(`${seed}:${names.join(\",\")}`)}`;\n\t\tmessages.push({\n\t\t\ttype: \"tool_search_call\",\n\t\t\tcall_id: callId,\n\t\t\texecution: \"client\",\n\t\t\tstatus: \"completed\",\n\t\t\targuments: { query: names.join(\" \"), limit: names.length },\n\t\t} satisfies ResponseInputItem);\n\t\tmessages.push({\n\t\t\ttype: \"tool_search_output\",\n\t\t\tcall_id: callId,\n\t\t\texecution: \"client\",\n\t\t\tstatus: \"completed\",\n\t\t\ttools: convertResponsesTools(tools, { ...options.toolOptions, toolSearchResult: true }),\n\t\t} satisfies ResponseToolSearchOutputItemParam);\n\t};\n\tconst includeInitialSystemMessage = options?.includeSystemPrompt ?? true;\n\tconst compat = model.compat as { supportsDeveloperRole?: boolean } | undefined;\n\tconst instructionRole = model.reasoning && compat?.supportsDeveloperRole !== false ? \"developer\" : \"system\";\n\n\tlet msgIndex = 0;\n\tlet sourceIndex = 0;\n\tfor (const msg of transformedMessages) {\n\t\tconst isLeadingSystemMessage = sourceIndex++ === 0 && msg.role === \"system\";\n\t\tif (msg.role === \"system\") {\n\t\t\tif (!isLeadingSystemMessage) appendSystemToolAdditions(msg, `system:${msgIndex}`);\n\t\t\tif (!isLeadingSystemMessage || includeInitialSystemMessage) {\n\t\t\t\tconst text = isLeadingSystemMessage ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);\n\t\t\t\tif (text.length > 0) {\n\t\t\t\t\tmessages.push({ role: instructionRole, content: sanitizeSurrogates(text) });\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: sanitizeSurrogates(msg.content) }],\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({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInput = [];\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\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature) as ResponseReasoningItem;\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t}\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\tconst parsedSignature = parseTextSignature(textBlock.textSignature);\n\t\t\t\t\tconst fallbackMessageId =\n\t\t\t\t\t\ttextBlockIndex === 0 ? `msg_pi_${msgIndex}` : `msg_pi_${msgIndex}_${textBlockIndex}`;\n\t\t\t\t\ttextBlockIndex++;\n\t\t\t\t\t// OpenAI requires id to be max 64 characters\n\t\t\t\t\tlet msgId = parsedSignature?.id;\n\t\t\t\t\tif (!msgId) {\n\t\t\t\t\t\tmsgId = fallbackMessageId;\n\t\t\t\t\t} else if (msgId.length > 64) {\n\t\t\t\t\t\tmsgId = `msg_${shortHash(msgId)}`;\n\t\t\t\t\t}\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: sanitizeSurrogates(textBlock.text), annotations: [] }],\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tid: msgId,\n\t\t\t\t\t\tphase: parsedSignature?.phase,\n\t\t\t\t\t} satisfies ResponseOutputMessage);\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\tlet itemId: string | undefined = itemIdRaw;\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// When replaying custom-tool calls as a function_call, also drop non-fc_* ids such as\n\t\t\t\t\t// ctc_* custom-tool ids because function_call item ids must be fc_*.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(isDifferentModel && itemId?.startsWith(\"fc_\")) ||\n\t\t\t\t\t\t(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\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\tid: 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...(isSameModel && toolCall.namespace !== undefined ? { namespace: toolCall.namespace } : {}),\n\t\t\t\t\t\t} satisfies ResponseOutputItem);\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\tid: 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...(isSameModel && toolCall.namespace !== undefined ? { namespace: toolCall.namespace } : {}),\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);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst [callId] = msg.toolCallId.split(\"|\");\n\t\t\tconst output = convertToolResultOutput(model, msg.content);\n\n\t\t\tif (options?.grammarToolInputProperties?.has(msg.toolName)) {\n\t\t\t\tmessages.push({\n\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\tcall_id: callId,\n\t\t\t\t\toutput,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tmessages.push({\n\t\t\t\t\ttype: \"function_call_output\",\n\t\t\t\t\tcall_id: callId,\n\t\t\t\t\toutput,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (!isLeadingSystemMessage) msgIndex++;\n\t}\n\n\treturn messages;\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?.toolSearchResult ? { defer_loading: true } : {}),\n\t\t\t} satisfies OpenAITool;\n\t\t}\n\n\t\tconst constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);\n\t\tconst strict = constrainedStrict ?? defaultStrict;\n\t\tconst functionTool: Omit<Extract<OpenAITool, { type: \"function\" }>, \"strict\"> & {\n\t\t\tstrict?: Extract<OpenAITool, { type: \"function\" }>[\"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 Record<string, unknown>,\n\t\t\t...(options?.toolSearchResult ? { 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\ntype ToolCallOutputSlot = Extract<ResponsesOutputSlot, { type: \"toolCall\" }>;\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\tconst outputSlots = new Map<number, ResponsesOutputSlot>();\n\tconst reasoningBlocksById = new Map<string, ThinkingContent>();\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 = (outputIndex: number, item: ResponseOutputItem): 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 (item.type === \"custom_tool_call\") {\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}`,\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\treturn undefined;\n\t};\n\tconst getOrCreateSlot = (outputIndex: number, item: ResponseOutputItem): ResponsesOutputSlot | undefined => {\n\t\treturn outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);\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 = JSON.parse(block.thinkingSignature) as ResponseReasoningItem;\n\t\t\tif (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): void => {\n\t\tsawTerminalResponseEvent = true;\n\t\tbackfillReasoningSignatures(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 responseServiceTier = normalizeResponseServiceTier(response?.service_tier);\n\t\t\tconst serviceTier = options.resolveServiceTier\n\t\t\t\t? options.resolveServiceTier(responseServiceTier, options.serviceTier)\n\t\t\t\t: (responseServiceTier ?? 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\toutput.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 openaiStream) {\n\t\tawait options?.onProviderStreamEvent?.(event, model);\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 || !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 || !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\n\t\t\tif (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}\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\tif (!sawTerminalResponseEvent) {\n\t\tthrow new Error(\"OpenAI Responses stream ended before a terminal response event\");\n\t}\n\t// The agent runs every tool call in the final message. Refuse to hand over calls whose\n\t// output_item.done never arrived: their arguments may be cut off or mixed up, e.g. when a\n\t// non-compliant server omits output_index. Finished calls have their scratch buffers removed.\n\tif (output.stopReason === \"toolUse\") {\n\t\tfor (const block of output.content) {\n\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\tconst toolCall = block as StreamingToolCall;\n\t\t\tif (toolCall.partialJson !== undefined || toolCall.customInput !== undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`OpenAI Responses stream completed with an unfinished tool call: ${toolCall.name} (${toolCall.id})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\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":"AAeA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAmBjE,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,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EACN,+BAA+B,EAE/B,mBAAmB,EACnB,2BAA2B,EAC3B,iCAAiC,EACjC,+BAA+B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,SAAS,qBAAqB,CAAC,EAAU,EAAE,KAAgC;IAC1E,MAAM,OAAO,GAAoB,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAC9C,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IACjC,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,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9E,MAAM,IAAI,KAAK,CACd,mEAAmE,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,GAAG,CACnG,CAAC;YACH,CAAC;QACF,CAAC;IACF,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\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputItem,\n\tResponseInputText,\n\tResponseOutputItem,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n\tResponseStreamEvent,\n\tResponseToolSearchOutputItemParam,\n} from \"openai/resources/responses/responses.js\";\nimport { calculateCost, getServiceTierCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tImageContent,\n\tModel,\n\tModelServiceTierId,\n\tStopReason,\n\tStreamOptions,\n\tSystemMessage,\n\tTextContent,\n\tTextSignatureV1,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tTranscriptContext,\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 { getSystemMessageText, renderSystemMessageUpdate } from \"../utils/text.ts\";\nimport { resolveTranscript, resolveTranscriptTools } from \"../utils/transcript.ts\";\nimport {\n\tappendGrammarToolInputJsonDelta,\n\ttype GrammarToolInputJsonBuffer,\n\tgetGrammarToolInput,\n\tgetJsonSchemaToolParameters,\n\tresolveGrammarConstrainedSampling,\n\tresolveJsonSchemaStrictSampling,\n} from \"./constrained-sampling.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\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\n/**\n * The service tier this request should carry.\n *\n * The **presence** of `fastRoute` is the discriminator, and its declared tier is the value. Fast\n * versus normal is model identity, so a caller who wants a different tier selects the normal sibling\n * rather than downgrading the fast one; letting a per-request option win would let a model selected,\n * recorded, persisted, and billed as `-fast` route as an ordinary request — and, because the Codex\n * routing identity keys on the final payload's tier, silently drop `originator: codex_cli_rs` too.\n *\n * A route that declares **no** tier means *no tier*, not \"fall through to the caller\". A GitHub\n * Copilot fast variant is exactly that case: it sends its own advertised `-fast` model ID and must\n * carry no OpenAI service-tier field at all, whatever the caller asks for.\n *\n * A normal model has no route, so an explicit `serviceTier` still applies there exactly as it did\n * before fast variants existed.\n */\n/** Codex accepts an additional tier not yet represented by the OpenAI API SDK. */\nexport type ResponsesServiceTier = ResponseCreateParamsStreaming[\"service_tier\"] | \"ultrafast\";\n\nexport function resolveRequestedServiceTier(\n\tmodel: Pick<Model<Api>, \"fastRoute\">,\n\toptionsServiceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn model.fastRoute ? model.fastRoute.serviceTier : optionsServiceTier;\n}\n\nfunction advertisedServiceTierId(serviceTier: ResponsesServiceTier | undefined): ModelServiceTierId | undefined {\n\tif (serviceTier === \"priority\" || serviceTier === \"fast\") return \"priority\";\n\treturn serviceTier === \"ultrafast\" ? \"ultrafast\" : undefined;\n}\n\n/**\n * Whether the model offers a Fast or Ultrafast tier. A model without tier metadata keeps offering Fast\n * but never Ultrafast. Other tiers (`flex`, `default`, `auto`, `scale`) need no advertisement.\n */\nexport function supportsServiceTier(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier,\n): boolean {\n\tconst advertisedId = advertisedServiceTierId(serviceTier);\n\tif (advertisedId === undefined) return true;\n\tif (model.serviceTiers === undefined) return advertisedId !== \"ultrafast\";\n\treturn getServiceTierCost(model, advertisedId) !== undefined;\n}\n\n/** OpenAI API: drop a Fast or Ultrafast tier the model does not advertise and send any other tier as asked. */\nexport function openAIServiceTierForRequest(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\treturn serviceTier !== undefined && supportsServiceTier(model, serviceTier) ? serviceTier : undefined;\n}\n\n/**\n * Codex's `service_tier_for_request`: send `flex` or an advertised tier, and omit `default` and every\n * tier the model does not advertise.\n */\nexport function codexServiceTierForRequest(\n\tmodel: Pick<Model<Api>, \"serviceTiers\">,\n\tserviceTier: ResponsesServiceTier | undefined,\n): ResponsesServiceTier | undefined {\n\tif (serviceTier === \"flex\") return serviceTier;\n\treturn advertisedServiceTierId(serviceTier) !== undefined && supportsServiceTier(model, serviceTier)\n\t\t? serviceTier\n\t\t: undefined;\n}\n\n/**\n * Reprice usage at the tier that actually served the request, using the advertised tier's published\n * rates. A model without tier metadata keeps the documented Fast multiplier.\n */\nexport function applyServiceTierPricing(\n\tusage: Usage,\n\tserviceTier: ResponsesServiceTier | undefined,\n\tmodel: Model<Api>,\n): void {\n\tif (serviceTier === \"flex\") {\n\t\tscaleUsageCost(usage, 0.5);\n\t\treturn;\n\t}\n\tconst advertisedId = advertisedServiceTierId(serviceTier);\n\tif (advertisedId === undefined) return;\n\tconst tierCost = getServiceTierCost(model, advertisedId);\n\tif (tierCost) {\n\t\tcalculateCost({ ...model, cost: tierCost }, usage);\n\t\treturn;\n\t}\n\tif (advertisedId === \"priority\") {\n\t\tscaleUsageCost(usage, (model.fastRoute?.baseModelId ?? model.id) === \"gpt-5.5\" ? 2.5 : 2);\n\t}\n}\n\nfunction scaleUsageCost(usage: Usage, multiplier: number): void {\n\tusage.cost.input *= multiplier;\n\tusage.cost.output *= multiplier;\n\tusage.cost.cacheRead *= multiplier;\n\tusage.cost.cacheWrite *= multiplier;\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n}\n\ntype ServiceTier = NonNullable<ResponsesServiceTier>;\n\nexport function normalizeResponseServiceTier(serviceTier: string | null | undefined): ServiceTier | undefined {\n\tif (serviceTier === null || serviceTier === undefined) return undefined;\n\treturn serviceTier === \"fast\" ? \"priority\" : (serviceTier as ServiceTier);\n}\n\n/**\n * Reject a payload hook that rewrote a field the model's route owns.\n *\n * A fast variant is a distinct selected, recorded, persisted, and billed identity, and the objective\n * requires it to send its route's upstream model ID and tier. A hook that changes either would send a\n * different model — or an ordinary-tier request — under the `-fast` identity Atomic recorded, and the\n * Codex routing identity would faithfully advertise whatever the hook left behind.\n *\n * Following the repository's precedent for discarded caller instructions, this rejects loudly rather\n * than silently restoring the route's values, so a misconfigured hook surfaces instead of hiding. A\n * hook may still rewrite every other field, and a model without a route keeps unrestricted freedom.\n */\nexport function assertPayloadPreservesFastRoute(\n\tmodel: Pick<Model<Api>, \"fastRoute\" | \"id\" | \"provider\" | \"serviceTiers\">,\n\tpayload: unknown,\n): void {\n\tconst fastRoute = model.fastRoute;\n\tif (!fastRoute) return;\n\tif (typeof payload !== \"object\" || payload === null || Array.isArray(payload)) {\n\t\tthrow new Error(\n\t\t\t`A request hook changed payload for fast model \"${model.provider}/${model.id}\" to a value that cannot carry ` +\n\t\t\t\t`the route's upstream model and service tier. A fast model variant must send its route's upstream model and ` +\n\t\t\t\t`service tier, because it is recorded, persisted, and billed under its own identity. Select the normal model ` +\n\t\t\t\t`\"${model.provider}/${fastRoute.baseModelId}\" if the request needs different routing, or return an object that ` +\n\t\t\t\t`preserves those fields.`,\n\t\t);\n\t}\n\tconst record = payload as Record<string, unknown>;\n\tconst conflicts: string[] = [];\n\tif (record.model !== fastRoute.upstreamModelId) {\n\t\tconflicts.push(`model (expected \"${fastRoute.upstreamModelId}\", got ${JSON.stringify(record.model)})`);\n\t}\n\tconst expectedServiceTier =\n\t\tfastRoute.serviceTier !== undefined && supportsServiceTier(model, fastRoute.serviceTier)\n\t\t\t? fastRoute.serviceTier\n\t\t\t: undefined;\n\tif (record.service_tier !== expectedServiceTier) {\n\t\tconflicts.push(\n\t\t\t`service_tier (expected ${JSON.stringify(expectedServiceTier)}, got ${JSON.stringify(record.service_tier)})`,\n\t\t);\n\t}\n\tif (conflicts.length === 0) return;\n\tthrow new Error(\n\t\t`A request hook changed ${conflicts.join(\" and \")} for fast model \"${model.provider}/${model.id}\". ` +\n\t\t\t`A fast model variant must send its route's upstream model and service tier, because it is ` +\n\t\t\t`recorded, persisted, and billed under its own identity. Select the normal model \"${model.provider}/${fastRoute.baseModelId}\" ` +\n\t\t\t`if the request needs different routing, or stop rewriting those fields.`,\n\t);\n}\n\nexport interface OpenAIResponsesStreamOptions {\n\tonProviderStreamEvent?: StreamOptions[\"onProviderStreamEvent\"];\n\tserviceTier?: ResponsesServiceTier;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tresolveServiceTier?: (\n\t\tresponseServiceTier: ResponsesServiceTier | undefined,\n\t\trequestServiceTier: ResponsesServiceTier | undefined,\n\t) => ResponsesServiceTier | undefined;\n\tapplyServiceTierPricing?: (usage: Usage, serviceTier: ResponsesServiceTier | undefined) => void;\n}\n\nexport interface ConvertResponsesMessagesOptions {\n\tincludeSystemPrompt?: boolean;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\t/** Whether later system messages are sent in place; otherwise they are folded into the leading prompt. */\n\tsupportsMidConvoSystemMessages?: boolean;\n\tsupportsAdditionalTools?: boolean;\n\tsupportsToolSearch?: boolean;\n\ttoolOptions?: ConvertResponsesToolsOptions;\n}\n\nexport interface ConvertResponsesToolsOptions {\n\tstrict?: boolean | null;\n\tsupportsStrictMode?: boolean;\n\tsupportsOpenAIGrammarTools?: boolean;\n\ttoolSearchResult?: boolean;\n}\n\n// =============================================================================\n// Message conversion\n// =============================================================================\n\nexport function convertResponsesMessages<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: TranscriptContext,\n\tallowedToolCallProviders: ReadonlySet<string>,\n\toptions?: ConvertResponsesMessagesOptions,\n): ResponseInput {\n\tconst normalizedContext = resolveTranscript(context, options?.supportsMidConvoSystemMessages);\n\tconst messages: ResponseInput = [];\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 (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);\n\t\tif (!id.includes(\"|\")) return normalizeIdPart(id);\n\t\tconst [callId, itemId] = id.split(\"|\");\n\t\tconst normalizedCallId = normalizeIdPart(callId);\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(normalizedContext.messages, model, normalizeToolCallId);\n\tconst transcriptTools = resolveTranscriptTools(\n\t\tnormalizedContext.messages,\n\t\t(options?.supportsAdditionalTools ?? false) || (options?.supportsToolSearch ?? false),\n\t);\n\tconst appendSystemToolAdditions = (message: SystemMessage, seed: string): void => {\n\t\tconst tools = transcriptTools.anchorsAdditions ? (message.toolsAdded ?? []) : [];\n\t\tif (tools.length === 0) return;\n\t\tif (options?.supportsAdditionalTools) {\n\t\t\tmessages.push({\n\t\t\t\ttype: \"additional_tools\",\n\t\t\t\trole: \"developer\",\n\t\t\t\ttools: convertResponsesTools(tools, options.toolOptions),\n\t\t\t} satisfies ResponseInputItem);\n\t\t\treturn;\n\t\t}\n\t\tif (!options?.supportsToolSearch) return;\n\t\tconst names = tools.map((tool) => tool.name);\n\t\tconst callId = `pi_tool_load_${shortHash(`${seed}:${names.join(\",\")}`)}`;\n\t\tmessages.push({\n\t\t\ttype: \"tool_search_call\",\n\t\t\tcall_id: callId,\n\t\t\texecution: \"client\",\n\t\t\tstatus: \"completed\",\n\t\t\targuments: { query: names.join(\" \"), limit: names.length },\n\t\t} satisfies ResponseInputItem);\n\t\tmessages.push({\n\t\t\ttype: \"tool_search_output\",\n\t\t\tcall_id: callId,\n\t\t\texecution: \"client\",\n\t\t\tstatus: \"completed\",\n\t\t\ttools: convertResponsesTools(tools, { ...options.toolOptions, toolSearchResult: true }),\n\t\t} satisfies ResponseToolSearchOutputItemParam);\n\t};\n\tconst includeInitialSystemMessage = options?.includeSystemPrompt ?? true;\n\tconst compat = model.compat as { supportsDeveloperRole?: boolean } | undefined;\n\tconst instructionRole = model.reasoning && compat?.supportsDeveloperRole !== false ? \"developer\" : \"system\";\n\n\tlet msgIndex = 0;\n\tlet sourceIndex = 0;\n\tfor (const msg of transformedMessages) {\n\t\tconst isLeadingSystemMessage = sourceIndex++ === 0 && msg.role === \"system\";\n\t\tif (msg.role === \"system\") {\n\t\t\tif (!isLeadingSystemMessage) appendSystemToolAdditions(msg, `system:${msgIndex}`);\n\t\t\tif (!isLeadingSystemMessage || includeInitialSystemMessage) {\n\t\t\t\tconst text = isLeadingSystemMessage ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);\n\t\t\t\tif (text.length > 0) {\n\t\t\t\t\tmessages.push({ role: instructionRole, content: sanitizeSurrogates(text) });\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: sanitizeSurrogates(msg.content) }],\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({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInput = [];\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\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature) as ResponseReasoningItem;\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t}\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\tconst parsedSignature = parseTextSignature(textBlock.textSignature);\n\t\t\t\t\tconst fallbackMessageId =\n\t\t\t\t\t\ttextBlockIndex === 0 ? `msg_pi_${msgIndex}` : `msg_pi_${msgIndex}_${textBlockIndex}`;\n\t\t\t\t\ttextBlockIndex++;\n\t\t\t\t\t// OpenAI requires id to be max 64 characters\n\t\t\t\t\tlet msgId = parsedSignature?.id;\n\t\t\t\t\tif (!msgId) {\n\t\t\t\t\t\tmsgId = fallbackMessageId;\n\t\t\t\t\t} else if (msgId.length > 64) {\n\t\t\t\t\t\tmsgId = `msg_${shortHash(msgId)}`;\n\t\t\t\t\t}\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: sanitizeSurrogates(textBlock.text), annotations: [] }],\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tid: msgId,\n\t\t\t\t\t\tphase: parsedSignature?.phase,\n\t\t\t\t\t} satisfies ResponseOutputMessage);\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\tlet itemId: string | undefined = itemIdRaw;\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 item 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// Also drop ids that do not match the replayed item type: function_call ids must be fc_*\n\t\t\t\t\t// and custom_tool_call ids must be ctc_*. Foreign tool call ids are normalized to fc_*, and\n\t\t\t\t\t// a call can switch between the two types when grammar tool support differs.\n\t\t\t\t\tconst itemIdPrefix = customInputProperty === undefined ? \"fc_\" : \"ctc_\";\n\t\t\t\t\tif (isDifferentModel || !itemId?.startsWith(itemIdPrefix)) {\n\t\t\t\t\t\titemId = undefined;\n\t\t\t\t\t}\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\tid: 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...(isSameModel && toolCall.namespace !== undefined ? { namespace: toolCall.namespace } : {}),\n\t\t\t\t\t\t} satisfies ResponseOutputItem);\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\tid: 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...(isSameModel && toolCall.namespace !== undefined ? { namespace: toolCall.namespace } : {}),\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);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst [callId] = msg.toolCallId.split(\"|\");\n\t\t\tconst output = convertToolResultOutput(model, msg.content);\n\n\t\t\tif (options?.grammarToolInputProperties?.has(msg.toolName)) {\n\t\t\t\tmessages.push({\n\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\tcall_id: callId,\n\t\t\t\t\toutput,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tmessages.push({\n\t\t\t\t\ttype: \"function_call_output\",\n\t\t\t\t\tcall_id: callId,\n\t\t\t\t\toutput,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (!isLeadingSystemMessage) msgIndex++;\n\t}\n\n\treturn messages;\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?.toolSearchResult ? { defer_loading: true } : {}),\n\t\t\t} satisfies OpenAITool;\n\t\t}\n\n\t\tconst constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);\n\t\tconst strict = constrainedStrict ?? defaultStrict;\n\t\tconst functionTool: Omit<Extract<OpenAITool, { type: \"function\" }>, \"strict\"> & {\n\t\t\tstrict?: Extract<OpenAITool, { type: \"function\" }>[\"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 Record<string, unknown>,\n\t\t\t...(options?.toolSearchResult ? { 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\ntype ToolCallOutputSlot = Extract<ResponsesOutputSlot, { type: \"toolCall\" }>;\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\tconst outputSlots = new Map<number, ResponsesOutputSlot>();\n\tconst reasoningBlocksById = new Map<string, ThinkingContent>();\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 = (outputIndex: number, item: ResponseOutputItem): 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 (item.type === \"custom_tool_call\") {\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}`,\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\treturn undefined;\n\t};\n\tconst getOrCreateSlot = (outputIndex: number, item: ResponseOutputItem): ResponsesOutputSlot | undefined => {\n\t\treturn outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);\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 = JSON.parse(block.thinkingSignature) as ResponseReasoningItem;\n\t\t\tif (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): void => {\n\t\tsawTerminalResponseEvent = true;\n\t\tbackfillReasoningSignatures(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 responseServiceTier = normalizeResponseServiceTier(response?.service_tier);\n\t\t\tconst serviceTier = options.resolveServiceTier\n\t\t\t\t? options.resolveServiceTier(responseServiceTier, options.serviceTier)\n\t\t\t\t: (responseServiceTier ?? 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\toutput.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 openaiStream) {\n\t\tawait options?.onProviderStreamEvent?.(event, model);\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 || !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 || !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\n\t\t\tif (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}\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\tif (!sawTerminalResponseEvent) {\n\t\tthrow new Error(\"OpenAI Responses stream ended before a terminal response event\");\n\t}\n\t// The agent runs every tool call in the final message. Refuse to hand over calls whose\n\t// output_item.done never arrived: their arguments may be cut off or mixed up, e.g. when a\n\t// non-compliant server omits output_index. Finished calls have their scratch buffers removed.\n\tif (output.stopReason === \"toolUse\") {\n\t\tfor (const block of output.content) {\n\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\tconst toolCall = block as StreamingToolCall;\n\t\t\tif (toolCall.partialJson !== undefined || toolCall.customInput !== undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`OpenAI Responses stream completed with an unfinished tool call: ${toolCall.name} (${toolCall.id})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\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,4 +1,4 @@
1
- const LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" aria-hidden="true"><text x="40" y="62" text-anchor="middle" font-family="monospace" font-size="72" fill="#fff">∀</text></svg>`;
1
+ const LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" aria-hidden="true"><text x="40" y="62" text-anchor="middle" font-family="monospace" font-size="72" fill="#89b4fa">∀</text></svg>`;
2
2
  function escapeHtml(value) {
3
3
  return value
4
4
  .replaceAll("&", "&amp;")
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-page.js","sourceRoot":"","sources":["../../../src/auth/oauth/oauth-page.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,2LAA2L,CAAC;AAE7M,SAAS,UAAU,CAAC,KAAa;IAChC,OAAO,KAAK;SACV,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,UAAU,CAAC,OAA8E;IACjG,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,OAAO;;;;;WAKG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DQ,QAAQ;UACtB,OAAO;SACR,OAAO;MACV,OAAO,CAAC,CAAC,CAAC,wBAAwB,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE;;;QAGpD,CAAC;AACT,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,OAAO,UAAU,CAAC;QACjB,KAAK,EAAE,2BAA2B;QAClC,OAAO,EAAE,2BAA2B;QACpC,OAAO;KACP,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,OAAgB;IAC/D,OAAO,UAAU,CAAC;QACjB,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,uBAAuB;QAChC,OAAO;QACP,OAAO;KACP,CAAC,CAAC;AACJ,CAAC","sourcesContent":["const LOGO_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 80 80\" aria-hidden=\"true\"><text x=\"40\" y=\"62\" text-anchor=\"middle\" font-family=\"monospace\" font-size=\"72\" fill=\"#fff\">∀</text></svg>`;\n\nfunction escapeHtml(value: string): string {\n\treturn value\n\t\t.replaceAll(\"&\", \"&amp;\")\n\t\t.replaceAll(\"<\", \"&lt;\")\n\t\t.replaceAll(\">\", \"&gt;\")\n\t\t.replaceAll('\"', \"&quot;\")\n\t\t.replaceAll(\"'\", \"&#39;\");\n}\n\nfunction renderPage(options: { title: string; heading: string; message: string; details?: string }): string {\n\tconst title = escapeHtml(options.title);\n\tconst heading = escapeHtml(options.heading);\n\tconst message = escapeHtml(options.message);\n\tconst details = options.details ? escapeHtml(options.details) : undefined;\n\n\treturn `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${title}</title>\n <style>\n :root {\n --text: #fafafa;\n --text-dim: #a1a1aa;\n --page-bg: #09090b;\n --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\n --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;\n }\n * { box-sizing: border-box; }\n html { color-scheme: dark; }\n body {\n margin: 0;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n background: var(--page-bg);\n color: var(--text);\n font-family: var(--font-sans);\n text-align: center;\n }\n main {\n width: 100%;\n max-width: 560px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n .logo {\n width: 72px;\n height: 72px;\n display: block;\n margin-bottom: 24px;\n }\n h1 {\n margin: 0 0 10px;\n font-size: 28px;\n line-height: 1.15;\n font-weight: 650;\n color: var(--text);\n }\n p {\n margin: 0;\n line-height: 1.7;\n color: var(--text-dim);\n font-size: 15px;\n }\n .details {\n margin-top: 16px;\n font-family: var(--font-mono);\n font-size: 13px;\n color: var(--text-dim);\n white-space: pre-wrap;\n word-break: break-word;\n }\n </style>\n</head>\n<body>\n <main>\n <div class=\"logo\">${LOGO_SVG}</div>\n <h1>${heading}</h1>\n <p>${message}</p>\n ${details ? `<div class=\"details\">${details}</div>` : \"\"}\n </main>\n</body>\n</html>`;\n}\n\nexport function oauthSuccessHtml(message: string): string {\n\treturn renderPage({\n\t\ttitle: \"Authentication successful\",\n\t\theading: \"Authentication successful\",\n\t\tmessage,\n\t});\n}\n\nexport function oauthErrorHtml(message: string, details?: string): string {\n\treturn renderPage({\n\t\ttitle: \"Authentication failed\",\n\t\theading: \"Authentication failed\",\n\t\tmessage,\n\t\tdetails,\n\t});\n}\n"]}
1
+ {"version":3,"file":"oauth-page.js","sourceRoot":"","sources":["../../../src/auth/oauth/oauth-page.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,8LAA8L,CAAC;AAEhN,SAAS,UAAU,CAAC,KAAa;IAChC,OAAO,KAAK;SACV,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,UAAU,CAAC,OAA8E;IACjG,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,OAAO;;;;;WAKG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DQ,QAAQ;UACtB,OAAO;SACR,OAAO;MACV,OAAO,CAAC,CAAC,CAAC,wBAAwB,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE;;;QAGpD,CAAC;AACT,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,OAAO,UAAU,CAAC;QACjB,KAAK,EAAE,2BAA2B;QAClC,OAAO,EAAE,2BAA2B;QACpC,OAAO;KACP,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,OAAgB;IAC/D,OAAO,UAAU,CAAC;QACjB,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,uBAAuB;QAChC,OAAO;QACP,OAAO;KACP,CAAC,CAAC;AACJ,CAAC","sourcesContent":["const LOGO_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 80 80\" aria-hidden=\"true\"><text x=\"40\" y=\"62\" text-anchor=\"middle\" font-family=\"monospace\" font-size=\"72\" fill=\"#89b4fa\">∀</text></svg>`;\n\nfunction escapeHtml(value: string): string {\n\treturn value\n\t\t.replaceAll(\"&\", \"&amp;\")\n\t\t.replaceAll(\"<\", \"&lt;\")\n\t\t.replaceAll(\">\", \"&gt;\")\n\t\t.replaceAll('\"', \"&quot;\")\n\t\t.replaceAll(\"'\", \"&#39;\");\n}\n\nfunction renderPage(options: { title: string; heading: string; message: string; details?: string }): string {\n\tconst title = escapeHtml(options.title);\n\tconst heading = escapeHtml(options.heading);\n\tconst message = escapeHtml(options.message);\n\tconst details = options.details ? escapeHtml(options.details) : undefined;\n\n\treturn `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${title}</title>\n <style>\n :root {\n --text: #fafafa;\n --text-dim: #a1a1aa;\n --page-bg: #09090b;\n --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\n --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;\n }\n * { box-sizing: border-box; }\n html { color-scheme: dark; }\n body {\n margin: 0;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n background: var(--page-bg);\n color: var(--text);\n font-family: var(--font-sans);\n text-align: center;\n }\n main {\n width: 100%;\n max-width: 560px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n .logo {\n width: 72px;\n height: 72px;\n display: block;\n margin-bottom: 24px;\n }\n h1 {\n margin: 0 0 10px;\n font-size: 28px;\n line-height: 1.15;\n font-weight: 650;\n color: var(--text);\n }\n p {\n margin: 0;\n line-height: 1.7;\n color: var(--text-dim);\n font-size: 15px;\n }\n .details {\n margin-top: 16px;\n font-family: var(--font-mono);\n font-size: 13px;\n color: var(--text-dim);\n white-space: pre-wrap;\n word-break: break-word;\n }\n </style>\n</head>\n<body>\n <main>\n <div class=\"logo\">${LOGO_SVG}</div>\n <h1>${heading}</h1>\n <p>${message}</p>\n ${details ? `<div class=\"details\">${details}</div>` : \"\"}\n </main>\n</body>\n</html>`;\n}\n\nexport function oauthSuccessHtml(message: string): string {\n\treturn renderPage({\n\t\ttitle: \"Authentication successful\",\n\t\theading: \"Authentication successful\",\n\t\tmessage,\n\t});\n}\n\nexport function oauthErrorHtml(message: string, details?: string): string {\n\treturn renderPage({\n\t\ttitle: \"Authentication failed\",\n\t\theading: \"Authentication failed\",\n\t\tmessage,\n\t\tdetails,\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"schemaVersion":6,"generatedAt":"2026-10-01T06:35:41.989Z","structureHash":"7e7d30a1b6928717084b8353551167ce311e599ec347a8f5086cf1c8300e0934","files":{"amazon-bedrock.json":"d1e91cffcaa338ce0574ecfae1a52271c4c4944b3e8e7581c5d7bc4154a396bb","ant-ling.json":"628feab3ef6c7d80ce96f75999804e1d9f05fec3851e5302e30fff3b69db90f6","anthropic.json":"c436c0f1f984e0a04f9d472533c20ce38c8da101d23484d6d7fe7892cdaa6830","azure-openai-responses.json":"bddff8380252746bbf6ee9901d6299e00ec0cc38facb6013b46b43c6ef231fdd","baseten.json":"b04d1423d6958bec857ffccc36726f091ec1a8f3a09cf0836b64cc94b0ee697d","cerebras.json":"3eccb58c5de3d0dc7ba49dc6e477ba29f00cb3150ce0a35cc90d59e6b5ab368e","cloudflare-ai-gateway.json":"5f9dbc3e5f4ef2ea7aa659f3fa28d77b5127e309305906bae47b25638931ba73","cloudflare-workers-ai.json":"b9f76cc83756a05920a8a7046c515919a1de918331b860a211f309bb716c4bb0","deepseek.json":"10a296fb3e898f7715c80890c8af0af4f5fd58f22dbcd6612fdc5d762157ccdc","fireworks.json":"d6144ba451bd7a0617669527bec1898f97a633f7d7ea5035d8e03234550340c0","github-copilot.json":"2362c7f129b6fca87ac45e06463ddb0f080477f820fd4eba55c150b0aeb99cba","google-vertex.json":"40090c680538bc867f2624d986a449f361be4dfa6ba96d7a27402050f036e009","google.json":"c0f5a633e5e5a5044432db3e537f4bc674d4de18df09325c6349547fcc13cabe","groq.json":"910952ad9dad07856983459d63fce0148dba1203edd7b10d801a77c5824f3405","huggingface.json":"1b8604bd31a5e05fe43a40ec1ec6dfc1a51a28b0b020151ef057fab43f57c923","kimi-coding.json":"582250b920454d98940da3e7e99d30b807edbea28f2eb8ac15f658d2ef41e8fc","meta.json":"0c7e9a370a7005c5a89dc94f0f93bc67b8935c3f802de324f11af6ff56fff429","minimax-cn.json":"f962c20ee6a6a342820f778e9dc363a18a524bf11998f6e2c57f2989915d62e5","minimax.json":"17a432f80d0ea6dd26eade80a4314250d3a855678601728a5f70dd8fa0d21dd2","mistral.json":"10f33bff9adf1248f7e6848e5890c265399f1f94e5b42cfdc28c109d547af98d","moonshotai-cn.json":"79c9585dc84ee525ebaebbc78b3c55f3d369ec884d4f943488f1e0b14e3587f5","moonshotai.json":"1da2c4e34f22aef17a07c974d85bdee8e1b68b6dc712e3769c935b3f1e7dadca","nvidia.json":"3b4e7b799bf3eaacd1af0491eef77fe33147ea7f72a3a9fa54d77af0e7eacf4c","openai-codex.json":"0c6c33c094d3175641a64a13215aa3b8c229964bb2c896e04cac1e2d2edf4a63","openai.json":"31e704f9e0ce46d0c2265eacd51a8d80e64ac52d5f3ca9679880fc0e0d79e057","opencode-go.json":"d05b3eb87b81c6e5a94801484e668e660fe60c68f06a972b716d581c3bbd7c25","opencode.json":"7996b45788b8c3892d474194661a70dc63a4f59470ea50b00cbd902859a262b5","openrouter.json":"12ecd7f9dcdbbbe7ce8346ab28c98877949e4174fed789fcc7602e53672b925b","qwen-token-plan-cn.json":"2469a4091c474ec3db0a49a9962d8d2726c074ad9065b96bc4e0c87861c4c6c5","qwen-token-plan-individual.json":"0fb7cf64faf39d1a3b0a884210a86c87084b805eda15644f5f39293287b959dd","qwen-token-plan.json":"eff10620cb577142de4ec02698d5961a71fda2fe4f6ae7ea9432bad9d6844176","radius.json":"d9158329af6688b83afb5bdf3916dc91115af2a85f97bfffa72449a29450a52f","together.json":"94ec3839972061405885d64f5fdbde48eb1f29a159be5e607e9770befd54e28e","typesafe.json":"a4429a2f696d5cc5273969af61a7310bda07d6bdcd27bf9ac9c76c534cc43716","vercel-ai-gateway.json":"7fe350a842ebf8f4beba713057770d3372249a089f175397e467fdfa39e2c46f","xai.json":"879c49b78b663a52a220ac4ee013e726b10c4f50aaa03bc58ee53a4b54c76928","xiaomi-token-plan-ams.json":"ca65178f4525d9705bc8d085ed136cecbe149c4080e857ea6a64ae643d2ac00a","xiaomi-token-plan-cn.json":"b065326926681c2262084e59c1c19ebdaf146c07107b5242c76b456becf74db0","xiaomi-token-plan-sgp.json":"92c3d6d707f81fd9cd2b6d1fb57dc431d90ba51e10fe49d97bc8806035c23492","xiaomi.json":"b81d01a374f7b558728c78d81f4168efa9c8996e6e2b5618409a8094b083c759","zai-coding-cn.json":"ee5ee705fb6e413a6088db5e3616c27fce802a8ece6c355f1db35490d787f610","zai.json":"58e6642fdfb736f0b9a4a277c760c536a3cea66a030abbfb2615f7b2851d5c6f"}}
1
+ {"schemaVersion":6,"generatedAt":"2026-10-02T05:42:01.684Z","structureHash":"e6db10109d3768f68ea5ceb49124a9a095c55a1d288aa7cea19e98e2a46a871b","files":{"amazon-bedrock.json":"d1e91cffcaa338ce0574ecfae1a52271c4c4944b3e8e7581c5d7bc4154a396bb","ant-ling.json":"628feab3ef6c7d80ce96f75999804e1d9f05fec3851e5302e30fff3b69db90f6","anthropic.json":"c436c0f1f984e0a04f9d472533c20ce38c8da101d23484d6d7fe7892cdaa6830","azure-openai-responses.json":"bddff8380252746bbf6ee9901d6299e00ec0cc38facb6013b46b43c6ef231fdd","baseten.json":"b04d1423d6958bec857ffccc36726f091ec1a8f3a09cf0836b64cc94b0ee697d","cerebras.json":"3eccb58c5de3d0dc7ba49dc6e477ba29f00cb3150ce0a35cc90d59e6b5ab368e","cloudflare-ai-gateway.json":"5f9dbc3e5f4ef2ea7aa659f3fa28d77b5127e309305906bae47b25638931ba73","cloudflare-workers-ai.json":"b9f76cc83756a05920a8a7046c515919a1de918331b860a211f309bb716c4bb0","deepseek.json":"10a296fb3e898f7715c80890c8af0af4f5fd58f22dbcd6612fdc5d762157ccdc","fireworks.json":"8db3c11f65a5d76260d5040a5dc5a9ef0f35b92de8505a30907c2355c2837b36","github-copilot.json":"2362c7f129b6fca87ac45e06463ddb0f080477f820fd4eba55c150b0aeb99cba","google-vertex.json":"40090c680538bc867f2624d986a449f361be4dfa6ba96d7a27402050f036e009","google.json":"c0f5a633e5e5a5044432db3e537f4bc674d4de18df09325c6349547fcc13cabe","groq.json":"910952ad9dad07856983459d63fce0148dba1203edd7b10d801a77c5824f3405","huggingface.json":"1b8604bd31a5e05fe43a40ec1ec6dfc1a51a28b0b020151ef057fab43f57c923","kimi-coding.json":"582250b920454d98940da3e7e99d30b807edbea28f2eb8ac15f658d2ef41e8fc","meta.json":"0c7e9a370a7005c5a89dc94f0f93bc67b8935c3f802de324f11af6ff56fff429","minimax-cn.json":"f962c20ee6a6a342820f778e9dc363a18a524bf11998f6e2c57f2989915d62e5","minimax.json":"17a432f80d0ea6dd26eade80a4314250d3a855678601728a5f70dd8fa0d21dd2","mistral.json":"10f33bff9adf1248f7e6848e5890c265399f1f94e5b42cfdc28c109d547af98d","moonshotai-cn.json":"79c9585dc84ee525ebaebbc78b3c55f3d369ec884d4f943488f1e0b14e3587f5","moonshotai.json":"1da2c4e34f22aef17a07c974d85bdee8e1b68b6dc712e3769c935b3f1e7dadca","nvidia.json":"a75e963dc81779e3eec01c051b12277c15ec37c5b94ab51ece9e9ccb3b16407c","openai-codex.json":"0c6c33c094d3175641a64a13215aa3b8c229964bb2c896e04cac1e2d2edf4a63","openai.json":"31e704f9e0ce46d0c2265eacd51a8d80e64ac52d5f3ca9679880fc0e0d79e057","opencode-go.json":"d05b3eb87b81c6e5a94801484e668e660fe60c68f06a972b716d581c3bbd7c25","opencode.json":"920238188bd2683e9bf616982d17c5ecb67fd61692a3064128af42ad2dc792b5","openrouter.json":"fe5efa92669832c260d5005816a5d999ed012c6184e37b1d48b6d1cee03dc3a0","qwen-token-plan-cn.json":"2469a4091c474ec3db0a49a9962d8d2726c074ad9065b96bc4e0c87861c4c6c5","qwen-token-plan-individual.json":"0fb7cf64faf39d1a3b0a884210a86c87084b805eda15644f5f39293287b959dd","qwen-token-plan.json":"eff10620cb577142de4ec02698d5961a71fda2fe4f6ae7ea9432bad9d6844176","radius.json":"d9158329af6688b83afb5bdf3916dc91115af2a85f97bfffa72449a29450a52f","together.json":"52293df62191c8e799ae3632f8ab1b3f52ee626aee0280677086627b32864bf7","typesafe.json":"a4429a2f696d5cc5273969af61a7310bda07d6bdcd27bf9ac9c76c534cc43716","vercel-ai-gateway.json":"ab93dd9bc260c85cb0082be8bd4a55021d6773f7a459a63a4b6491eeb69a988b","xai.json":"879c49b78b663a52a220ac4ee013e726b10c4f50aaa03bc58ee53a4b54c76928","xiaomi-token-plan-ams.json":"ca65178f4525d9705bc8d085ed136cecbe149c4080e857ea6a64ae643d2ac00a","xiaomi-token-plan-cn.json":"b065326926681c2262084e59c1c19ebdaf146c07107b5242c76b456becf74db0","xiaomi-token-plan-sgp.json":"92c3d6d707f81fd9cd2b6d1fb57dc431d90ba51e10fe49d97bc8806035c23492","xiaomi.json":"b81d01a374f7b558728c78d81f4168efa9c8996e6e2b5618409a8094b083c759","zai-coding-cn.json":"ee5ee705fb6e413a6088db5e3616c27fce802a8ece6c355f1db35490d787f610","zai.json":"58e6642fdfb736f0b9a4a277c760c536a3cea66a030abbfb2615f7b2851d5c6f"}}