@openclaw/ai 2026.9.5 → 2026.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/{anthropic-COtDvgtt.mjs → anthropic-Cw2pgccz.mjs} +59 -88
  2. package/dist/{anthropic-payload-policy-5Erq1Nzy.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +8 -6
  3. package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +194 -247
  4. package/dist/{api-registry-Ba2Cv-ut.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
  5. package/dist/{azure-openai-responses-YrgnD583.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
  6. package/dist/{base64-BQOzsvUH.mjs → base64-C1PsYcRQ.mjs} +22 -16
  7. package/dist/{diagnostics-Dm4bisWG.mjs → diagnostics-CJaB6g8J.mjs} +55 -10
  8. package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
  9. package/dist/diagnostics.d.mts +11 -5
  10. package/dist/diagnostics.mjs +4 -4
  11. package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
  12. package/dist/event-stream-CMQfX_yr.d.mts +1 -0
  13. package/dist/{event-stream-CCoa-qSI.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
  14. package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
  15. package/dist/event-stream.d.mts +2 -2
  16. package/dist/event-stream.mjs +1 -1
  17. package/dist/{google-BuhpRO9r.mjs → google-BfapkS_K.mjs} +8 -11
  18. package/dist/google-interactions-DW3iXzjc.mjs +574 -0
  19. package/dist/{google-messages-CyWnYlh0.mjs → google-messages-CtjVtVot.mjs} +35 -71
  20. package/dist/{google-shared-BT5ZeNer.mjs → google-shared-Y2YfotEu.mjs} +43 -47
  21. package/dist/{google-vertex-C7EplRvt.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
  22. package/dist/{host-B4MeUNBc.mjs → host-CHi3X87F.mjs} +64 -189
  23. package/dist/{host-policy-DUnXSx0I.mjs → host-policy-BOAwRg_M.mjs} +2 -14
  24. package/dist/{host-FZ1RA_qD.d.mts → host-rxlNaBwm.d.mts} +9 -3
  25. package/dist/{index-DaF2QbwS.d.mts → index-D6KsSE74.d.mts} +57 -9
  26. package/dist/index.d.mts +7 -7
  27. package/dist/index.mjs +7 -7
  28. package/dist/internal/anthropic.d.mts +13 -8
  29. package/dist/internal/anthropic.mjs +5 -5
  30. package/dist/internal/openai-completions-compat.d.mts +1 -1
  31. package/dist/internal/openai-completions-compat.mjs +1 -1
  32. package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
  33. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  34. package/dist/internal/openai.d.mts +46 -9
  35. package/dist/internal/openai.mjs +13 -12
  36. package/dist/internal/runtime.d.mts +31 -70
  37. package/dist/internal/runtime.mjs +11 -66
  38. package/dist/internal/shared.d.mts +16 -13
  39. package/dist/internal/shared.mjs +6 -5
  40. package/dist/internal/tool-schema.d.mts +2 -2
  41. package/dist/internal/tool-schema.mjs +2 -2
  42. package/dist/{mistral-moA-mbwl.mjs → mistral-RS6mboC-.mjs} +46 -93
  43. package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
  44. package/dist/{openai-chatgpt-responses-DWID3EFO.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +118 -99
  45. package/dist/{openai-completions-DJ1Vm-CD.mjs → openai-completions-D14ihPYk.mjs} +14 -12
  46. package/dist/{openai-completions-compat-CkwdxTZx.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
  47. package/dist/{openai-completions-compat-JE7gqxb9.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
  48. package/dist/{openai-completions-stream-Bu98b0Hv.mjs → openai-completions-stream-CDCuw3DP.mjs} +124 -183
  49. package/dist/{openai-prompt-cache-CJ_xEevu.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
  50. package/dist/{openai-prompt-cache-1wfaIszn.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
  51. package/dist/{openai-provider-client-DPo0Hmak.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
  52. package/dist/{openai-reasoning-effort-NlFZmfEu.mjs → openai-reasoning-effort-ConhwkeX.mjs} +14 -5
  53. package/dist/{openai-responses-BejZzQCP.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
  54. package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
  55. package/dist/{openai-responses-compaction-window-D6P5oZP5.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
  56. package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
  57. package/dist/{openai-responses-contracts-Dflvrfa8.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
  58. package/dist/{openai-responses-prompt-observer-internal-C15_-OwV.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +16 -13
  59. package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +36 -0
  60. package/dist/{openai-responses-shared-CwsziD_m.mjs → openai-responses-shared-DL4ulQn7.mjs} +838 -577
  61. package/dist/{openai-responses-terminal-usage-Dl3J6zrf.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
  62. package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
  63. package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
  64. package/dist/{openai-tool-schema-BO8rwyAD.mjs → openai-tool-schema-vsl-cE-n.mjs} +365 -429
  65. package/dist/{openai-transport-params-DQeuAvBl.mjs → openai-transport-params-BwlpzX-2.mjs} +61 -106
  66. package/dist/{positive-integer-DtjCkbue.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
  67. package/dist/{provider-error-DDqw9Qda.mjs → provider-error-CwT_j2v0.mjs} +82 -10
  68. package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
  69. package/dist/{provider-options-DprLsWh9.d.mts → provider-options-Df7ov0K1.d.mts} +6 -4
  70. package/dist/{provider-replay-context-CnUSOwhr.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
  71. package/dist/{provider-transcript-transform-BsRAhuWJ.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
  72. package/dist/{provider-transport-turn-state-CkGToCD2.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
  73. package/dist/{provider-types-CAKRC7N5.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
  74. package/dist/provider-types.d.mts +6 -6
  75. package/dist/providers.d.mts +2 -2
  76. package/dist/providers.mjs +15 -11
  77. package/dist/{reasoning-tag-text-partitioner-Dy9IO8Dc.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +193 -98
  78. package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
  79. package/dist/simple-options-CGAkCwtM.mjs +349 -0
  80. package/dist/{src-DeKjbE8I.mjs → src-H4aXcFuX.mjs} +53 -26
  81. package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
  82. package/dist/{stream-first-event-timeout-C9ZadkJW.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
  83. package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
  84. package/dist/{transport-stream-shared-D-6FQSHm.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +63 -37
  85. package/dist/{transport-stream-shared-BbUkFaHi.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +13 -7
  86. package/dist/{transport-utils-1cyq5Y7x.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
  87. package/dist/transports.d.mts +37 -33
  88. package/dist/transports.mjs +208 -239
  89. package/dist/types-CB-_vNyI.d.mts +1 -0
  90. package/dist/{types-4_uVs5WH.d.mts → types-CLLR3eB4.d.mts} +5 -1
  91. package/dist/types.d.mts +6 -6
  92. package/dist/types.mjs +5 -5
  93. package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
  94. package/dist/{validation-Ctzu2DhF.d.mts → validation-Cat2wQsc.d.mts} +1 -1
  95. package/dist/validation.d.mts +1 -1
  96. package/dist/validation.mjs +1 -1
  97. package/package.json +6 -6
  98. package/dist/assistant-output-BsEkB-vU.mjs +0 -16
  99. package/dist/event-stream-DmSCpi1T.d.mts +0 -1
  100. package/dist/simple-options-C6cFWj_f.mjs +0 -175
  101. package/dist/types-DkJfb4W3.d.mts +0 -1
  102. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -1,12 +1,11 @@
1
- import { r as appendAssistantThinking, t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
2
- import { M as clampThinkingLevel, _ as isImageWithMediaPayload, d as describeToolResultMediaPlaceholder, h as formatToolResultText, j as calculateCost, m as extractToolResultText, n as getAiTransportHost, v as sanitizeSurrogates } from "./host-B4MeUNBc.mjs";
3
- import { m as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, v as sortPromptCacheToolsByName } from "./simple-options-C6cFWj_f.mjs";
4
- import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
5
- import { E as parseStreamingJson, c as finalizeTerminalToolCallArguments, k as shortHash, n as assignTransportErrorDetails, p as notifyProviderHttpResponse, v as transportAbortError, w as createToolArgumentPreviewSchedule } from "./transport-stream-shared-D-6FQSHm.mjs";
1
+ import { r as appendAssistantThinking, t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
2
+ import { T as clampThinkingLevel, k as isImageWithMediaPayload, n as getAiTransportHost, w as calculateCost } from "./host-CHi3X87F.mjs";
3
+ import { A as shortHash, E as createToolArgumentPreviewSchedule, O as parseStreamingJson, j as sanitizeSurrogates, l as finalizeTerminalToolCallArguments, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, u as finalizeTransportStream } from "./transport-stream-shared-Dh5qKJ8e.mjs";
4
+ import { C as stripSystemPromptCacheBoundary, D as sortPromptCacheToolsByName, d as describeToolResultMediaPlaceholder, h as formatToolResultText, m as extractToolResultText, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-CGAkCwtM.mjs";
5
+ import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
6
6
  import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
7
- import { t as createAssistantOutput } from "./assistant-output-BsEkB-vU.mjs";
8
- import { t as transformProviderMessages } from "./provider-transcript-transform-BsRAhuWJ.mjs";
9
- import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
7
+ import { n as createAssistantOutput, t as transformProviderMessages } from "./provider-transcript-transform-JbFbHV8h.mjs";
8
+ import { t as mapOpenAIStopReason } from "./openai-stop-reason-8s70vDXj.mjs";
10
9
  import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
11
10
  import { randomUUID } from "node:crypto";
12
11
  import { HTTPClient } from "@mistralai/mistralai/lib/http";
@@ -15,17 +14,7 @@ import { Chat } from "@mistralai/mistralai/sdk/chat";
15
14
  //#region packages/ai/src/providers/mistral.ts
16
15
  const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
17
16
  const MISTRAL_STREAM_BODY_MAX_BYTES = 16777216;
18
- /**
19
- * Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
20
- * on streamed response bodies. The wrapped `Response.body` exposes a
21
- * `ReadableStream` whose chunks flow through `createSseByteGuard`, so the
22
- * SDK's internal SSE parser (`EventStream` in
23
- * `@mistralai/mistralai/lib/event-streams.ts`) reads exactly as it would on
24
- * an unbounded body — but bounded.
25
- *
26
- * Bodyless responses (no `body` or no `getReader`) are returned unchanged so
27
- * the SDK's error-path `res.arrayBuffer()` call still works.
28
- */
17
+ /** Cap the SDK's response reader while preserving bodyless error responses. */
29
18
  function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, upstreamFetch = fetch) {
30
19
  return async (input, init) => {
31
20
  const response = init == null ? await upstreamFetch(input) : await upstreamFetch(input, init);
@@ -55,9 +44,6 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
55
44
  });
56
45
  };
57
46
  }
58
- /**
59
- * Stream responses from Mistral using `chat.stream`.
60
- */
61
47
  const streamMistral = (model, context, options) => {
62
48
  const stream = new AssistantMessageEventStream();
63
49
  (async () => {
@@ -87,7 +73,7 @@ const streamMistral = (model, context, options) => {
87
73
  retryConfig: { strategy: "none" }
88
74
  });
89
75
  const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
90
- let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
76
+ let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, normalizeMistralToolCallId), options);
91
77
  const nextPayload = await options?.onPayload?.(payload, model);
92
78
  if (nextPayload !== void 0) payload = nextPayload;
93
79
  const headers = {
@@ -110,14 +96,11 @@ const streamMistral = (model, context, options) => {
110
96
  partial: output
111
97
  });
112
98
  await consumeChatStream(model, output, stream, mistralStream, options?.signal);
113
- if (options?.signal?.aborted) throw transportAbortError(options.signal);
114
- if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
115
- stream.push({
116
- type: "done",
117
- reason: output.stopReason,
118
- message: output
99
+ finalizeTransportStream({
100
+ stream,
101
+ output,
102
+ signal: options?.signal
119
103
  });
120
- stream.end();
121
104
  } catch (error) {
122
105
  const terminal = assignTransportErrorDetails(output, error, options?.signal);
123
106
  output.content = output.content.filter((block) => block.type !== "toolCall");
@@ -131,9 +114,6 @@ const streamMistral = (model, context, options) => {
131
114
  })();
132
115
  return stream;
133
116
  };
134
- /**
135
- * Maps provider-agnostic `SimpleStreamOptions` to Mistral options.
136
- */
137
117
  const streamSimpleMistral = (model, context, options) => {
138
118
  const apiKey = options?.apiKey || getEnvApiKey(model.provider);
139
119
  if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
@@ -231,6 +211,10 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
231
211
  return candidates;
232
212
  };
233
213
  const intersectCandidates = (left, right) => new Set([...left].filter((contentIndex) => right.has(contentIndex)));
214
+ const filterIdentityCandidates = (candidates, matches) => new Set([...candidates].filter((contentIndex) => {
215
+ const identity = toolBlockIdentities.get(contentIndex);
216
+ return identity !== void 0 && matches(identity);
217
+ }));
234
218
  const requireSingleCandidate = (candidates) => {
235
219
  if (candidates.size > 1) throw new Error("Mistral streamed tool-call continuation is ambiguous; refusing to merge arguments");
236
220
  return candidates.values().next().value;
@@ -252,30 +236,18 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
252
236
  return requireExistingCandidate(candidates);
253
237
  }
254
238
  if (nameCandidates.size > 0) {
255
- const idCompatibleCandidates = new Set([...nameCandidates].filter((contentIndex) => {
256
- const identity = toolBlockIdentities.get(contentIndex);
257
- if (!identity) return false;
258
- return !explicitId || identity.explicitIds.size === 0;
259
- }));
239
+ const idCompatibleCandidates = filterIdentityCandidates(nameCandidates, (identity) => !explicitId || identity.explicitIds.size === 0);
260
240
  if (idCompatibleCandidates.size <= 1 && (toolCallIndex === void 0 || toolCallIndex === 0)) return requireSingleCandidate(idCompatibleCandidates);
261
- const indexCompatibleCandidates = new Set([...idCompatibleCandidates].filter((contentIndex) => {
262
- const identity = toolBlockIdentities.get(contentIndex);
263
- if (!identity) return false;
264
- return toolCallIndex === void 0 || identity.indexes.size === 0 || identity.indexes.has(toolCallIndex);
265
- }));
266
- if (indexCompatibleCandidates.size === 0) return;
241
+ const indexCompatibleCandidates = filterIdentityCandidates(idCompatibleCandidates, (identity) => toolCallIndex === void 0 || identity.indexes.size === 0 || identity.indexes.has(toolCallIndex));
267
242
  return requireSingleCandidate(indexCompatibleCandidates);
268
243
  }
269
244
  const indexCandidates = toolCallIndex === void 0 ? /* @__PURE__ */ new Set() : findIdentityCandidates((identity) => identity.indexes.has(toolCallIndex), params.usedContentIndexes);
270
245
  if (functionName) {
271
- const namelessCandidates = new Set([...indexCandidates].filter((contentIndex) => {
272
- const identity = toolBlockIdentities.get(contentIndex);
273
- return identity?.functionNames.size === 0 && (!explicitId || identity.explicitIds.size === 0);
274
- }));
246
+ const namelessCandidates = filterIdentityCandidates(indexCandidates, (identity) => identity.functionNames.size === 0 && (!explicitId || identity.explicitIds.size === 0));
275
247
  return requireSingleCandidate(namelessCandidates);
276
248
  }
277
249
  if (explicitId) {
278
- const idlessCandidates = new Set([...indexCandidates].filter((contentIndex) => toolBlockIdentities.get(contentIndex)?.explicitIds.size === 0));
250
+ const idlessCandidates = filterIdentityCandidates(indexCandidates, (identity) => identity.explicitIds.size === 0);
279
251
  return requireSingleCandidate(idlessCandidates);
280
252
  }
281
253
  return requireSingleCandidate(indexCandidates);
@@ -298,6 +270,29 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
298
270
  partial: output
299
271
  });
300
272
  };
273
+ const appendTextDelta = (text) => {
274
+ const textDelta = sanitizeSurrogates(text);
275
+ if (!currentBlock || currentBlock.type !== "text") {
276
+ finishCurrentBlock(currentBlock);
277
+ currentBlock = {
278
+ type: "text",
279
+ text: ""
280
+ };
281
+ output.content.push(currentBlock);
282
+ stream.push({
283
+ type: "text_start",
284
+ contentIndex: blockIndex(),
285
+ partial: output
286
+ });
287
+ }
288
+ currentBlock.text += textDelta;
289
+ stream.push({
290
+ type: "text_delta",
291
+ contentIndex: blockIndex(),
292
+ delta: textDelta,
293
+ partial: output
294
+ });
295
+ };
301
296
  for await (const event of mistralStream) {
302
297
  notifyLlmRequestActivity(signal);
303
298
  const chunk = event.data;
@@ -326,27 +321,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
326
321
  const contentItems = typeof delta.content === "string" ? [delta.content] : delta.content;
327
322
  for (const item of contentItems) {
328
323
  if (typeof item === "string") {
329
- const textDelta = sanitizeSurrogates(item);
330
- if (!currentBlock || currentBlock.type !== "text") {
331
- finishCurrentBlock(currentBlock);
332
- currentBlock = {
333
- type: "text",
334
- text: ""
335
- };
336
- output.content.push(currentBlock);
337
- stream.push({
338
- type: "text_start",
339
- contentIndex: blockIndex(),
340
- partial: output
341
- });
342
- }
343
- currentBlock.text += textDelta;
344
- stream.push({
345
- type: "text_delta",
346
- contentIndex: blockIndex(),
347
- delta: textDelta,
348
- partial: output
349
- });
324
+ appendTextDelta(item);
350
325
  continue;
351
326
  }
352
327
  if (item.type === "thinking") {
@@ -375,29 +350,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
375
350
  });
376
351
  continue;
377
352
  }
378
- if (item.type === "text") {
379
- const textDelta = sanitizeSurrogates(item.text);
380
- if (!currentBlock || currentBlock.type !== "text") {
381
- finishCurrentBlock(currentBlock);
382
- currentBlock = {
383
- type: "text",
384
- text: ""
385
- };
386
- output.content.push(currentBlock);
387
- stream.push({
388
- type: "text_start",
389
- contentIndex: blockIndex(),
390
- partial: output
391
- });
392
- }
393
- currentBlock.text += textDelta;
394
- stream.push({
395
- type: "text_delta",
396
- contentIndex: blockIndex(),
397
- delta: textDelta,
398
- partial: output
399
- });
400
- }
353
+ if (item.type === "text") appendTextDelta(item.text);
401
354
  }
402
355
  }
403
356
  const toolCalls = delta.toolCalls || [];
@@ -12,7 +12,7 @@ type ModelSseDebugMode = "off" | "events" | "peek";
12
12
  declare function resolveModelPayloadDebugMode(env?: ModelTransportDebugEnv): ModelPayloadDebugMode;
13
13
  /** Resolves SSE stream debug verbosity from `OPENCLAW_DEBUG_SSE`. */
14
14
  declare function resolveModelSseDebugMode(env?: ModelTransportDebugEnv): ModelSseDebugMode;
15
- /** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
15
+ /** Emits transport diagnostics at debug, promoted to info by explicit debug flags. */
16
16
  declare function emitModelTransportDebug(log: SubsystemLogger, message: string): void;
17
17
  //#endregion
18
18
  //#region packages/ai/src/transports/model-transport-url.d.ts
@@ -1,23 +1,87 @@
1
- import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
2
- import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
3
- import { u as supportsOpenAITemperature } from "./openai-reasoning-effort-NlFZmfEu.mjs";
4
- import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-B4MeUNBc.mjs";
5
- import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-1wfaIszn.mjs";
6
- import { m as toErrorObject, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, p as extractErrorCodeOrErrno } from "./diagnostics-Dm4bisWG.mjs";
7
- import { s as resolveTimerTimeoutMs } from "./base64-BQOzsvUH.mjs";
8
- import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-1cyq5Y7x.mjs";
1
+ import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
2
+ import { t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
3
+ import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
4
+ import { S as headersToRecord, n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CHi3X87F.mjs";
5
+ import { d as supportsOpenAITemperature } from "./openai-reasoning-effort-ConhwkeX.mjs";
6
+ import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-D2V7MqR7.mjs";
7
+ import { _ as extractErrorCodeOrErrno, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, v as toErrorObject } from "./diagnostics-CJaB6g8J.mjs";
8
+ import { s as resolveTimerTimeoutMs } from "./base64-C1PsYcRQ.mjs";
9
+ import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-C-4bf2Ok.mjs";
9
10
  import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
10
- import { m as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-C6cFWj_f.mjs";
11
- import { S as createResponseModelTracker, b as createOpenAIProviderAcceptanceHook, g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, x as createOpenAIResponseHook } from "./openai-transport-params-DQeuAvBl.mjs";
12
- import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
13
- import { O as headersToRecord, b as withProviderResponseHook, m as notifyProviderStreamOpened, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-D-6FQSHm.mjs";
14
- import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C9ZadkJW.mjs";
15
- import { h as responsesPromptObserver } from "./openai-responses-contracts-DWrfMODE.mjs";
16
- import { A as resolveNextResponsesEncryptedContentAttempt, E as commitResponsesEncryptedContentAttempt, K as buildOpenAIResponsesReasoningReplayMetadata, O as isInvalidEncryptedContentError, X as suppressOpenAIResponsesCompaction, c as processResponsesStream, i as createResponsesAssistantOutput, j as recordResponsesContextUsage, n as applyResponsesServiceTierPricing, o as convertResponsesToolPayload, r as convertResponsesMessages, u as ResponsesStreamFailure } from "./openai-responses-shared-CwsziD_m.mjs";
11
+ import { S as withProviderResponseHook, b as transportAbortError, h as notifyProviderStreamOpened, n as assignTransportErrorDetails } from "./transport-stream-shared-Dh5qKJ8e.mjs";
12
+ import { C as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-CGAkCwtM.mjs";
13
+ import { b as createOpenAIResponseHook, g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, x as createResponseModelTracker, y as createOpenAIProviderAcceptanceHook } from "./openai-transport-params-BwlpzX-2.mjs";
14
+ import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
15
+ import { n as createAssistantOutput } from "./provider-transcript-transform-JbFbHV8h.mjs";
16
+ import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-B9o0S4SZ.mjs";
17
+ import { h as responsesPromptObserver } from "./openai-responses-contracts-CLxnqS9p.mjs";
18
+ import { A as recordResponsesContextUsage, P as convertProviderResponsesMessages, S as isInvalidEncryptedContentError, T as ResponsesStreamFailure, Z as suppressOpenAIResponsesCompaction, b as commitResponsesEncryptedContentAttempt, i as convertResponsesToolPayload, n as applyResponsesServiceTierPricing, o as readOpenAIMisalignmentReview, q as buildOpenAIResponsesReasoningReplayMetadata, s as processResponsesStream, w as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-DL4ulQn7.mjs";
17
19
  import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
18
20
  import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
19
- import { i as resolveOpenAIResponsesTextFormat, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-C15_-OwV.mjs";
21
+ import { i as resolveOpenAIResponsesTextFormat, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-iAqLb4tk.mjs";
22
+ import { n as withResponsesRequestAcceptance, t as responsesRequestLifecycle } from "./openai-responses-request-lifecycle-Fsag-IGZ.mjs";
20
23
  import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
24
+ //#region packages/ai/src/providers/openai-chatgpt-responses-events.ts
25
+ var CodexApiError = class extends Error {
26
+ constructor(message, options) {
27
+ super(message);
28
+ this.name = "CodexApiError";
29
+ this.code = options?.code;
30
+ this.status = options?.status;
31
+ this.payload = options?.payload;
32
+ this.cause = options?.cause;
33
+ }
34
+ };
35
+ function extractCodexEventError(event) {
36
+ const nested = isRecord(event.error) ? event.error : void 0;
37
+ return {
38
+ code: typeof event.code === "string" ? event.code : typeof nested?.code === "string" ? nested.code : void 0,
39
+ message: typeof event.message === "string" ? event.message : typeof nested?.message === "string" ? nested.message : void 0
40
+ };
41
+ }
42
+ async function* mapCodexEvents(events, initialResponseHeaders, options) {
43
+ const responseModelTracker = createResponseModelTracker();
44
+ responseModelTracker.begin(initialResponseHeaders);
45
+ for await (const event of withResponsesRequestAcceptance(events, responsesRequestLifecycle.get(options), options?.signal)) {
46
+ responseModelTracker.observeEvent(event);
47
+ const type = typeof event.type === "string" ? event.type : void 0;
48
+ if (!type) continue;
49
+ if (type === "error") {
50
+ const { code, message } = extractCodexEventError(event);
51
+ throw new CodexApiError(`Codex error: ${message || code || JSON.stringify(event)}`, {
52
+ code,
53
+ payload: event
54
+ });
55
+ }
56
+ if (type === "response.done" || type === "response.completed" || type === "response.incomplete") {
57
+ const response = isRecord(event.response) ? event.response : void 0;
58
+ const normalizedResponse = response ? {
59
+ ...response,
60
+ status: normalizeCodexStatus(response.status),
61
+ model: responseModelTracker.resolve()
62
+ } : response;
63
+ yield {
64
+ ...event,
65
+ type: type === "response.done" ? "response.completed" : type,
66
+ response: normalizedResponse
67
+ };
68
+ return;
69
+ }
70
+ yield event;
71
+ }
72
+ }
73
+ function normalizeCodexStatus(status) {
74
+ switch (status) {
75
+ case "completed":
76
+ case "incomplete":
77
+ case "failed":
78
+ case "cancelled":
79
+ case "queued":
80
+ case "in_progress": return status;
81
+ default: return;
82
+ }
83
+ }
84
+ //#endregion
21
85
  //#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
22
86
  const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
23
87
  var CodexProtocolError = class extends Error {
@@ -99,14 +163,6 @@ const RETRYABLE_WEBSOCKET_CLOSE_CODES = /* @__PURE__ */ new Set([
99
163
  const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
100
164
  const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
101
165
  const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
102
- const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
103
- "completed",
104
- "incomplete",
105
- "failed",
106
- "cancelled",
107
- "queued",
108
- "in_progress"
109
- ]);
110
166
  function resolveRequestTimeoutMs(options) {
111
167
  const timeoutMs = options?.timeoutMs;
112
168
  return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? resolveTimerTimeoutMs(timeoutMs, 1) : void 0;
@@ -150,7 +206,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
150
206
  let requestTimeoutSignal;
151
207
  let activeSignal;
152
208
  let firstEventAbort;
153
- const output = createResponsesAssistantOutput(model);
209
+ const output = createAssistantOutput(model);
154
210
  try {
155
211
  const unresolvedApiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
156
212
  if (!unresolvedApiKey) throw new Error(`No API key for provider: ${model.provider}`);
@@ -251,6 +307,12 @@ const streamOpenAICodexResponses = (model, context, options) => {
251
307
  });
252
308
  let attemptResponse;
253
309
  try {
310
+ const lifecycle = responsesRequestLifecycle.get(options);
311
+ if (lifecycle) {
312
+ await lifecycle.beforeDispatch(activeSignal);
313
+ activeSignal?.throwIfAborted();
314
+ lifecycle.assertCurrent();
315
+ }
254
316
  attemptResponse = await fetch(resolveCodexUrl(model.baseUrl), {
255
317
  method: "POST",
256
318
  headers: sseHeaders,
@@ -293,7 +355,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
293
355
  semanticAttempt = nextSemanticAttempt;
294
356
  }
295
357
  const hookedResponseStream = withProviderResponseHook({
296
- stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response), response.headers),
358
+ stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response), response.headers, requestOptions),
297
359
  signal: firstEventAbort.signal,
298
360
  abort: firstEventAbort.abort,
299
361
  hook: createOpenAIProviderAcceptanceHook(options, response, model),
@@ -325,6 +387,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
325
387
  });
326
388
  stream.end();
327
389
  } catch (error) {
390
+ await responsesRequestLifecycle.get(options)?.settle().catch(() => void 0);
328
391
  const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
329
392
  const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
330
393
  for (const block of output.content) delete block.partialJson;
@@ -334,7 +397,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
334
397
  timestamp: Date.now(),
335
398
  details: {
336
399
  provider: "openai",
337
- category: providerRefusal.category
400
+ category: providerRefusal.category,
401
+ ...providerRefusal.review ? { review: providerRefusal.review } : {}
338
402
  }
339
403
  });
340
404
  const terminal = assignTransportErrorDetails(output, normalizedError, options?.signal);
@@ -368,10 +432,12 @@ const streamSimpleOpenAICodexResponses = (model, context, options) => {
368
432
  reasoningEffort: resolveOpenAISimpleReasoningEffort(model, options?.reasoning)
369
433
  };
370
434
  responsesPromptObserver.copy(options, resolvedOptions);
435
+ const lifecycle = responsesRequestLifecycle.get(options);
436
+ if (lifecycle) responsesRequestLifecycle.set(resolvedOptions, lifecycle);
371
437
  return streamOpenAICodexResponses(model, context, resolvedOptions);
372
438
  };
373
439
  function buildRequestBody(model, context, options, replayMode = "checkpoint") {
374
- const messages = convertResponsesMessages(model, context, CODEX_TOOL_CALL_PROVIDERS, {
440
+ const messages = convertProviderResponsesMessages(model, context, CODEX_TOOL_CALL_PROVIDERS, {
375
441
  includeSystemPrompt: false,
376
442
  replayResponsesItemIds: false,
377
443
  sessionId: options?.sessionId,
@@ -425,87 +491,36 @@ function resolveCodexWebSocketUrl(baseUrl) {
425
491
  if (url.protocol === "http:") url.protocol = "ws:";
426
492
  return url.toString();
427
493
  }
428
- function isJsonRecord(value) {
429
- return value !== null && typeof value === "object" && !Array.isArray(value);
430
- }
431
494
  /**
432
495
  * Structured refusal code carried by the OpenAI Responses transport. Every
433
496
  * terminal Responses path preserves it: a non-OK HTTP body parsed by
434
497
  * {@link parseErrorResponse}, an SSE/WebSocket `error` event mapped by
435
- * {@link extractCodexEventError}, and a `response.failed` event normalized into
498
+ * {@link mapCodexEvents}, and a `response.failed` event normalized into
436
499
  * {@link ResponsesStreamFailure}. Only the app-server surface carries the
437
500
  * `codexErrorInfo` discriminator, so both shapes must be read here.
438
501
  */
439
- const RESPONSES_CYBER_POLICY_ERROR_CODE = "cyber_policy";
440
502
  function readCodexProviderRefusal(error) {
441
- if (error instanceof ResponsesStreamFailure) return error.code === RESPONSES_CYBER_POLICY_ERROR_CODE ? { category: "cyber" } : void 0;
442
- if (!(error instanceof CodexApiError)) return;
443
- if (error.code === RESPONSES_CYBER_POLICY_ERROR_CODE) return { category: "cyber" };
444
- const payload = error.payload;
445
- const nested = isJsonRecord(payload?.error) ? payload.error : void 0;
503
+ if (!(error instanceof ResponsesStreamFailure || error instanceof CodexApiError)) return;
504
+ const payload = error instanceof CodexApiError ? error.payload : isRecord(error.response) ? error.response : void 0;
505
+ const nested = isRecord(payload?.error) ? payload.error : void 0;
446
506
  const codexErrorInfo = payload?.codexErrorInfo ?? nested?.codexErrorInfo;
447
- if (codexErrorInfo === "cyberPolicy") return { category: "cyber" };
448
- if (codexErrorInfo === "misalignmentPolicyViolation") return { category: "misalignment" };
507
+ if (error.code === "cyber_policy" || codexErrorInfo === "cyberPolicy") return { category: "cyber" };
508
+ if (error.code === "misalignment_policy_violation" || codexErrorInfo === "misalignmentPolicyViolation") {
509
+ const details = nested?.misalignment ?? payload?.misalignment;
510
+ const review = readOpenAIMisalignmentReview(details, true);
511
+ return {
512
+ category: "misalignment",
513
+ ...review ? { review } : {}
514
+ };
515
+ }
449
516
  return (typeof payload?.message === "string" ? payload.message : typeof nested?.message === "string" ? nested.message : "").startsWith("This content was flagged for possible biological risk.") ? { category: "bio" } : void 0;
450
517
  }
451
- var CodexApiError = class extends Error {
452
- constructor(message, options) {
453
- super(message);
454
- this.name = "CodexApiError";
455
- this.code = options?.code;
456
- this.status = options?.status;
457
- this.payload = options?.payload;
458
- this.cause = options?.cause;
459
- }
460
- };
461
518
  function isCodexNonTransportError(error) {
462
519
  return error instanceof CodexApiError || error instanceof CodexProtocolError || error instanceof ResponsesStreamFailure;
463
520
  }
464
521
  function isWebSocketConnectionLimitReachedError(error) {
465
522
  return error instanceof CodexApiError && error.code === WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE;
466
523
  }
467
- function extractCodexEventError(event) {
468
- const nested = event.error && typeof event.error === "object" ? event.error : void 0;
469
- return {
470
- code: typeof event.code === "string" ? event.code : typeof nested?.code === "string" ? nested.code : void 0,
471
- message: typeof event.message === "string" ? event.message : typeof nested?.message === "string" ? nested.message : void 0
472
- };
473
- }
474
- async function* mapCodexEvents(events, initialResponseHeaders) {
475
- const responseModelTracker = createResponseModelTracker();
476
- responseModelTracker.begin(initialResponseHeaders);
477
- for await (const event of events) {
478
- responseModelTracker.observeEvent(event);
479
- const type = typeof event.type === "string" ? event.type : void 0;
480
- if (!type) continue;
481
- if (type === "error") {
482
- const { code, message } = extractCodexEventError(event);
483
- throw new CodexApiError(`Codex error: ${message || code || JSON.stringify(event)}`, {
484
- code,
485
- payload: event
486
- });
487
- }
488
- if (type === "response.done" || type === "response.completed" || type === "response.incomplete") {
489
- const response = event.response;
490
- const normalizedResponse = response ? {
491
- ...response,
492
- status: normalizeCodexStatus(response.status),
493
- model: responseModelTracker.resolve()
494
- } : response;
495
- yield {
496
- ...event,
497
- type: type === "response.done" ? "response.completed" : type,
498
- response: normalizedResponse
499
- };
500
- return;
501
- }
502
- yield event;
503
- }
504
- }
505
- function normalizeCodexStatus(status) {
506
- if (typeof status !== "string") return;
507
- return CODEX_RESPONSE_STATUSES.has(status) ? status : void 0;
508
- }
509
524
  const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
510
525
  const SESSION_WEBSOCKET_CACHE_TTL_MS = 3e5;
511
526
  const SESSION_WEBSOCKET_MAX_AGE_MS = 33e5;
@@ -846,9 +861,6 @@ function requestBodyWithoutInput(body) {
846
861
  const { input: _input, previous_response_id: _previousResponseId, ...rest } = body;
847
862
  return rest;
848
863
  }
849
- function responseInputsEqual(a, b) {
850
- return JSON.stringify(a ?? []) === JSON.stringify(b ?? []);
851
- }
852
864
  function requestBodiesMatchExceptInput(a, b) {
853
865
  return JSON.stringify(requestBodyWithoutInput(a)) === JSON.stringify(requestBodyWithoutInput(b));
854
866
  }
@@ -857,7 +869,8 @@ function getCachedWebSocketInputDelta(body, continuation) {
857
869
  const currentInput = body.input ?? [];
858
870
  const baseline = [...continuation.lastRequestBody.input ?? [], ...continuation.lastResponseItems];
859
871
  if (currentInput.length < baseline.length) return;
860
- if (!responseInputsEqual(currentInput.slice(0, baseline.length), baseline)) return;
872
+ const prefix = currentInput.slice(0, baseline.length);
873
+ if (JSON.stringify(prefix) !== JSON.stringify(baseline)) return;
861
874
  return currentInput.slice(baseline.length);
862
875
  }
863
876
  function buildCachedWebSocketRequestBody(entry, body) {
@@ -902,12 +915,18 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
902
915
  egress: "native-codex-websocket",
903
916
  payloadVariant
904
917
  });
918
+ const lifecycle = responsesRequestLifecycle.get(options);
919
+ if (lifecycle) {
920
+ await lifecycle.beforeDispatch(options?.signal);
921
+ options?.signal?.throwIfAborted();
922
+ lifecycle.assertCurrent();
923
+ }
905
924
  socket.send(JSON.stringify({
906
925
  type: "response.create",
907
926
  ...requestBody
908
927
  }));
909
928
  onRequestSent?.();
910
- const terminal = await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream, onFirstProviderEvent, () => notifyProviderStreamOpened({
929
+ const terminal = await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal), void 0, options), output, stream, onFirstProviderEvent, () => notifyProviderStreamOpened({
911
930
  options,
912
931
  cancelStream: () => {
913
932
  keepConnection = false;
@@ -928,7 +947,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
928
947
  });
929
948
  if (options?.signal?.aborted) keepConnection = false;
930
949
  else if (useCachedContext && entry && output.responseId) {
931
- const responseItems = convertResponsesMessages(model, { messages: [output] }, CODEX_TOOL_CALL_PROVIDERS, {
950
+ const responseItems = convertProviderResponsesMessages(model, { messages: [output] }, CODEX_TOOL_CALL_PROVIDERS, {
932
951
  includeSystemPrompt: false,
933
952
  replayResponsesItemIds: false,
934
953
  sessionId: options?.sessionId,
@@ -1006,7 +1025,7 @@ function parseErrorResponse(raw, response) {
1006
1025
  let payload;
1007
1026
  try {
1008
1027
  const parsed = JSON.parse(raw);
1009
- payload = isJsonRecord(parsed) ? parsed : void 0;
1028
+ payload = isRecord(parsed) ? parsed : void 0;
1010
1029
  const err = parsed?.error;
1011
1030
  if (err) {
1012
1031
  code = err.code || err.type || void 0;
@@ -1,19 +1,19 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
3
- import { M as clampThinkingLevel } from "./host-B4MeUNBc.mjs";
4
- import { i as resolveOpenAICompletionsCompat } from "./openai-completions-compat-CkwdxTZx.mjs";
2
+ import { t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
3
+ import { T as clampThinkingLevel } from "./host-CHi3X87F.mjs";
4
+ import { i as resolveOpenAICompletionsCompat } from "./openai-completions-compat-BOVWBZDn.mjs";
5
5
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
6
- import { n as buildBaseOptions, o as reasoningTagTextPolicy } from "./simple-options-C6cFWj_f.mjs";
7
- import { C as isOpenAICompletionsThinkingEnabled, b as createOpenAIProviderAcceptanceHook } from "./openai-transport-params-DQeuAvBl.mjs";
8
- import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
9
- import { b as withProviderResponseHook, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-D-6FQSHm.mjs";
6
+ import { S as withProviderResponseHook, b as transportAbortError, n as assignTransportErrorDetails } from "./transport-stream-shared-Dh5qKJ8e.mjs";
7
+ import { n as buildBaseOptions, s as prepareModelRequestBody, u as reasoningTagTextPolicy } from "./simple-options-CGAkCwtM.mjs";
8
+ import { S as isOpenAICompletionsThinkingEnabled, y as createOpenAIProviderAcceptanceHook } from "./openai-transport-params-BwlpzX-2.mjs";
9
+ import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
10
10
  import { a as tagUnresolvedTextAsCommentary, t as clearPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
11
- import { t as createAssistantOutput } from "./assistant-output-BsEkB-vU.mjs";
12
- import { a as convertMessages, i as buildOpenAICompletionsRequest, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream } from "./openai-completions-stream-Bu98b0Hv.mjs";
13
- import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C9ZadkJW.mjs";
14
- import { n as resolveProviderSimpleCompletionHeaders } from "./provider-transport-turn-state-CkGToCD2.mjs";
11
+ import { n as createAssistantOutput } from "./provider-transcript-transform-JbFbHV8h.mjs";
12
+ import { a as convertMessages, i as buildOpenAICompletionsRequest, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream } from "./openai-completions-stream-CDCuw3DP.mjs";
13
+ import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-B9o0S4SZ.mjs";
14
+ import { n as resolveProviderSimpleCompletionHeaders } from "./provider-transport-turn-state-BheUi_hl.mjs";
15
15
  import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-B37TB3rB.mjs";
16
- import { t as createOpenAIProviderClient } from "./openai-provider-client-DPo0Hmak.mjs";
16
+ import { t as createOpenAIProviderClient } from "./openai-provider-client-CwfsGBbA.mjs";
17
17
  //#region packages/ai/src/providers/openai-completions.ts
18
18
  var openai_completions_exports = /* @__PURE__ */ __exportAll({
19
19
  convertMessages: () => convertMessages,
@@ -38,10 +38,12 @@ const streamOpenAICompletions = (model, context, options) => {
38
38
  compat,
39
39
  cacheRetention
40
40
  });
41
+ const encodeBody = prepareModelRequestBody(options);
41
42
  const nextParams = await options?.onPayload?.(params, model);
42
43
  if (nextParams !== void 0) params = nextParams;
43
44
  firstEventAbort = createFirstStreamEventAbortController(options?.signal);
44
45
  const requestOptions = {
46
+ ...await encodeBody(params),
45
47
  signal: firstEventAbort.signal,
46
48
  ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
47
49
  maxRetries: 0
@@ -1,5 +1,5 @@
1
- import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
2
- import { a as resolveProviderRequestCapabilities } from "./host-policy-DUnXSx0I.mjs";
1
+ import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
2
+ import { i as resolveProviderRequestCapabilities } from "./host-policy-BOAwRg_M.mjs";
3
3
  //#region packages/ai/src/providers/openai-response-format.ts
4
4
  const JSON_SCHEMA_RESPONSE_FORMAT_NAME = "openclaw_response";
5
5
  const OLLAMA_CLOUD_ORIGIN = "https://ollama.com";
@@ -28,9 +28,7 @@ function shouldOmitOllamaCompatResponseFormat(params) {
28
28
  */
29
29
  function resolveOpenAICompletionsResponseFormat(responseFormat, supportsJsonSchemaResponseFormat) {
30
30
  if (!responseFormat) return;
31
- if (responseFormat.type === "json_object") return responseFormat;
32
- if (responseFormat.type === "text") return responseFormat;
33
- if (responseFormat.type === "json_schema" && isRecord(responseFormat.json_schema)) return responseFormat;
31
+ if (responseFormat.type === "json_object" || responseFormat.type === "text" || responseFormat.type === "json_schema" && isRecord(responseFormat.json_schema)) return responseFormat;
34
32
  if (!supportsJsonSchemaResponseFormat) return;
35
33
  return {
36
34
  type: "json_schema",
@@ -1,6 +1,6 @@
1
- import "./index-DaF2QbwS.mjs";
2
- import { M as OpenAICompletionsCompat, O as Model } from "./types-4_uVs5WH.mjs";
3
- import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-FZ1RA_qD.mjs";
1
+ import "./index-D6KsSE74.mjs";
2
+ import { M as OpenAICompletionsCompat, O as Model } from "./types-CLLR3eB4.mjs";
3
+ import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-rxlNaBwm.mjs";
4
4
  //#region packages/ai/src/transports/openai-completions-compat.d.ts
5
5
  type ProviderRequestCapabilities = AiProviderRequestCapabilities;
6
6
  type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";