@openclaw/ai 2026.8.1-beta.2 → 2026.8.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.
Files changed (87) hide show
  1. package/dist/{anthropic-B6dLpq5L.mjs → anthropic-Djj7L1rx.mjs} +49 -39
  2. package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-CY4tkD4V.mjs} +42 -44
  3. package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-i_5_inWe.d.mts} +4 -2
  4. package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-C9-wZd_W.d.mts} +2 -1
  5. package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Bj3czHNa.mjs} +4 -4
  6. package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
  7. package/dist/diagnostics.d.mts +2 -3
  8. package/dist/diagnostics.mjs +1 -1
  9. package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
  10. package/dist/event-stream-C988TSLe.d.mts +1 -0
  11. package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-UhnxHuqt.d.mts} +1 -2
  12. package/dist/event-stream.d.mts +2 -1
  13. package/dist/{google-C7h2QzDX.mjs → google-0Ca6TYbw.mjs} +4 -4
  14. package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-DVfL9COU.mjs} +22 -8
  15. package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-5dAMxprN.mjs} +4 -4
  16. package/dist/{host-DTqNc7ad.mjs → host-D51fmkH6.mjs} +40 -33
  17. package/dist/{host-vWgMMhiJ.d.mts → host-DoPJJ1KD.d.mts} +7 -7
  18. package/dist/index-N3zr6__t.d.mts +105 -0
  19. package/dist/index.d.mts +9 -10
  20. package/dist/index.mjs +2 -3
  21. package/dist/internal/anthropic.d.mts +57 -49
  22. package/dist/internal/anthropic.mjs +5 -5
  23. package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
  24. package/dist/internal/openai-responses-payload-policy.mjs +2 -3
  25. package/dist/internal/openai.d.mts +65 -63
  26. package/dist/internal/openai.mjs +10 -8
  27. package/dist/internal/retry-after.d.mts +2 -3
  28. package/dist/internal/runtime.d.mts +53 -40
  29. package/dist/internal/runtime.mjs +10 -9
  30. package/dist/internal/shared.d.mts +37 -23
  31. package/dist/internal/shared.mjs +4 -4
  32. package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
  33. package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
  34. package/dist/{mistral-CEWoQI_g.mjs → mistral-BCnrI-kV.mjs} +64 -53
  35. package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-CGBGWSqr.mjs} +45 -20
  36. package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-BaTuwID7.mjs} +63 -258
  37. package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-DB7FFq7k.d.mts} +3 -3
  38. package/dist/openai-completions-stream-Bpns6uNc.mjs +1622 -0
  39. package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-1GBcQujk.mjs} +8 -6
  40. package/dist/openai-responses-compaction-window-DwydGZI8.mjs +686 -0
  41. package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-DgaR3t5T.d.mts} +14 -5
  42. package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +2 -0
  43. package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-_nhGTn2b.mjs} +3 -3
  44. package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-zPmKnhF5.mjs} +345 -1553
  45. package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
  46. package/dist/openai-tool-schema-Dgl4H2MU.mjs +1695 -0
  47. package/dist/{provider-error-BUwEnjXq.mjs → provider-error-jZP5NMTZ.mjs} +3 -82
  48. package/dist/{provider-options-B96RdNpH.d.mts → provider-options-HvA_slFa.d.mts} +23 -4
  49. package/dist/provider-transcript-transform-C01bQ5a3.mjs +32 -0
  50. package/dist/provider-types.d.mts +18 -17
  51. package/dist/providers.d.mts +5 -6
  52. package/dist/providers.mjs +9 -9
  53. package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-CwzKb0bA.mjs} +4 -1
  54. package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
  55. package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
  56. package/dist/{simple-options-D58D5Kvw.mjs → simple-options-DKx86yX9.mjs} +42 -4
  57. package/dist/{anthropic-JsNA5KCu.mjs → src-Bu3FiFAG.mjs} +1 -1
  58. package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
  59. package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
  60. package/dist/string-normalization--fwJ4S2q.mjs +16 -0
  61. package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-qvTEs5Am.mjs} +17 -8
  62. package/dist/transport-stream-shared-CT5ycdzn.mjs +342 -0
  63. package/dist/transport-stream-shared-NjwWNaRY.d.mts +138 -0
  64. package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-BHx9z8Cl.mjs} +9 -9
  65. package/dist/transports.d.mts +140 -169
  66. package/dist/transports.mjs +269 -1262
  67. package/dist/types-DtGu2d3C.d.mts +1 -0
  68. package/dist/{types-BHNrPS1l.d.mts → types-h38Azne1.d.mts} +53 -17
  69. package/dist/types.d.mts +6 -5
  70. package/dist/types.mjs +1 -2
  71. package/dist/utf16-slice-qz3nsy87.mjs +84 -0
  72. package/dist/{validation-DT9SrFn3.d.mts → validation-C68lP2uy.d.mts} +1 -2
  73. package/dist/validation.d.mts +1 -1
  74. package/package.json +6 -6
  75. package/dist/anthropic-SrGtwsJu.d.mts +0 -100
  76. package/dist/index-BVVgDSdq.d.mts +0 -1
  77. package/dist/openai-responses-contracts-CyfIkQi5.mjs +0 -253
  78. package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +0 -206
  79. package/dist/openai-stop-reason-BkFkqqK0.mjs +0 -563
  80. package/dist/openai-tool-projection-CY04OcvQ.mjs +0 -338
  81. package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
  82. package/dist/record-coerce-DdXsgUd_.mjs +0 -23
  83. package/dist/src-D2H6yKkH.mjs +0 -2
  84. package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
  85. package/dist/string-coerce-fsri9iCu.mjs +0 -34
  86. package/dist/types-BVVgDSdq.d.mts +0 -1
  87. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -1,18 +1,16 @@
1
- import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
2
  import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
3
- import { i as clampThinkingLevel } from "./sanitize-unicode-BYqrYtC_.mjs";
4
- import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
5
- import { n as projectProviderError } from "./provider-error-BUwEnjXq.mjs";
3
+ import { i as clampThinkingLevel } from "./sanitize-unicode-DCkltN94.mjs";
4
+ import { n as getAiTransportHost } from "./host-D51fmkH6.mjs";
5
+ import { n as projectProviderError } from "./provider-error-jZP5NMTZ.mjs";
6
6
  import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
7
7
  import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
8
- import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-D58D5Kvw.mjs";
9
- import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as tagPendingCommentaryText, r as convertMessages, t as mapOpenAIStopReason, u as shouldOmitOllamaCompatResponseFormat } from "./openai-stop-reason-BkFkqqK0.mjs";
10
- import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
11
- import { n as notifyLlmRequestActivity } from "./headers-DdOQtGuU.mjs";
12
- import { f as transportAbortError, p as withProviderResponseHook } from "./provider-transcript-transform-ePx-Bbfr.mjs";
13
- import { d as readOpenAICompletionsContentDeltas, n as reconcileOpenAICompletionsToolChoice, o as createOpenAIResponseHook, s as isOpenAICompletionsThinkingEnabled, t as projectOpenAITools, u as parseOpenAICompletionsUsage } from "./openai-tool-projection-CY04OcvQ.mjs";
14
- import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
15
- import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-rnPwX2pg.mjs";
8
+ import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-DKx86yX9.mjs";
9
+ import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
10
+ import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-CT5ycdzn.mjs";
11
+ import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-Bpns6uNc.mjs";
12
+ import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-Dgl4H2MU.mjs";
13
+ import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
16
14
  import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
17
15
  import OpenAI from "openai";
18
16
  //#region packages/ai/src/providers/openai-completions.ts
@@ -21,11 +19,6 @@ var openai_completions_exports = /* @__PURE__ */ __exportAll({
21
19
  streamOpenAICompletions: () => streamOpenAICompletions,
22
20
  streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
23
21
  });
24
- function isEncryptedReasoningDetail(detail) {
25
- if (typeof detail !== "object" || detail === null) return false;
26
- const candidate = detail;
27
- return candidate.type === "reasoning.encrypted" && typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.data === "string" && candidate.data.length > 0;
28
- }
29
22
  const streamOpenAICompletions = (model, context, options) => {
30
23
  const stream = new AssistantMessageEventStream();
31
24
  (async () => {
@@ -57,6 +50,7 @@ const streamOpenAICompletions = (model, context, options) => {
57
50
  try {
58
51
  const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
59
52
  const compat = resolveOpenAICompletionsCompat(model);
53
+ const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
60
54
  const cacheRetention = resolveCacheRetention(options?.cacheRetention);
61
55
  const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
62
56
  const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
@@ -74,267 +68,76 @@ const streamOpenAICompletions = (model, context, options) => {
74
68
  stream: openaiStream,
75
69
  signal: firstEventAbort.signal,
76
70
  abort: firstEventAbort.abort,
77
- hook: createOpenAIResponseHook(options?.onResponse, response, model),
71
+ hook: createOpenAIProviderAcceptanceHook(options, response, model),
78
72
  onReady: () => stream.push({
79
73
  type: "start",
80
74
  partial: output
81
75
  })
82
76
  });
83
- let textBlock = null;
84
- let thinkingBlock = null;
85
- let hasFinishReason = false;
86
- const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
87
- const toolCallBlocksById = /* @__PURE__ */ new Map();
88
- const toolCallBlocksByFirstId = /* @__PURE__ */ new Map();
89
- const normalizeToolCallDeltas = createOpenAICompletionsToolCallDeltaNormalizer();
90
- const pendingReasoningDetailsByToolCallId = /* @__PURE__ */ new Map();
91
- const blocks = output.content;
92
77
  const finishedBlocks = /* @__PURE__ */ new Set();
93
78
  const contentIndices = /* @__PURE__ */ new WeakMap();
94
- const appendBlock = (block) => {
95
- contentIndices.set(block, blocks.length);
96
- blocks.push(block);
97
- };
98
- const getContentIndex = (block) => contentIndices.get(block) ?? -1;
99
- const rememberFirstToolCallById = (id, block) => {
100
- if (toolCallBlocksByFirstId.has(id)) return;
101
- toolCallBlocksByFirstId.set(id, block);
102
- const pendingDetail = pendingReasoningDetailsByToolCallId.get(id);
103
- if (pendingDetail) {
104
- block.thoughtSignature = pendingDetail;
105
- pendingReasoningDetailsByToolCallId.delete(id);
106
- }
107
- };
79
+ let openTextBlock;
80
+ let openThinkingBlock;
108
81
  const finishBlock = (block) => {
109
- const contentIndex = getContentIndex(block);
110
- if (contentIndex === -1 || finishedBlocks.has(block)) return;
82
+ const contentIndex = contentIndices.get(block);
83
+ if (contentIndex === void 0 || finishedBlocks.has(block)) return;
111
84
  finishedBlocks.add(block);
112
- if (block.type === "text") stream.push({
113
- type: "text_end",
114
- contentIndex,
115
- content: block.text,
116
- partial: output
117
- });
118
- else if (block.type === "thinking") stream.push({
119
- type: "thinking_end",
120
- contentIndex,
121
- content: block.thinking,
122
- partial: output
123
- });
124
- else if (block.type === "toolCall") stream.push({
125
- type: "toolcall_end",
126
- contentIndex,
127
- toolCall: block,
128
- partial: output
129
- });
130
- };
131
- const ensureTextBlock = () => {
132
- if (!textBlock) {
133
- textBlock = {
134
- type: "text",
135
- text: ""
136
- };
137
- appendBlock(textBlock);
85
+ if (block.type === "text") {
86
+ openTextBlock = void 0;
138
87
  stream.push({
139
- type: "text_start",
140
- contentIndex: getContentIndex(textBlock),
88
+ type: "text_end",
89
+ contentIndex,
90
+ content: block.text,
141
91
  partial: output
142
92
  });
143
- }
144
- return textBlock;
145
- };
146
- const ensureThinkingBlock = (thinkingSignature) => {
147
- if (!thinkingBlock) {
148
- thinkingBlock = {
149
- type: "thinking",
150
- thinking: "",
151
- ...thinkingSignature ? { thinkingSignature } : {}
152
- };
153
- appendBlock(thinkingBlock);
93
+ } else if (block.type === "thinking") {
94
+ openThinkingBlock = void 0;
154
95
  stream.push({
155
- type: "thinking_start",
156
- contentIndex: getContentIndex(thinkingBlock),
96
+ type: "thinking_end",
97
+ contentIndex,
98
+ content: block.thinking,
157
99
  partial: output
158
100
  });
159
- }
160
- return thinkingBlock;
161
- };
162
- const sealNativeReasoningBeforeText = () => {
163
- if (thinkingBlock && !reasoningTagTextPartitioner.isInsideReasoning()) {
164
- finishBlock(thinkingBlock);
165
- thinkingBlock = null;
166
- }
167
- };
168
- const appendTextDelta = (delta) => {
169
- sealNativeReasoningBeforeText();
170
- const block = ensureTextBlock();
171
- block.text += delta;
172
- stream.push({
173
- type: "text_delta",
174
- contentIndex: getContentIndex(block),
175
- delta,
176
- partial: output
177
- });
178
- };
179
- const appendThinkingDelta = (thinkingSignature, delta) => {
180
- const block = ensureThinkingBlock(thinkingSignature);
181
- block.thinking += delta;
182
- stream.push({
183
- type: "thinking_delta",
184
- contentIndex: getContentIndex(block),
185
- delta,
101
+ } else if (block.type === "toolCall") stream.push({
102
+ type: "toolcall_end",
103
+ contentIndex,
104
+ toolCall: block,
186
105
  partial: output
187
106
  });
188
107
  };
189
- const ensureToolCallBlock = (toolCall) => {
190
- const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
191
- let block = streamIndex !== void 0 ? toolCallBlocksByIndex.get(streamIndex) : void 0;
192
- if (!block && toolCall.id) block = toolCallBlocksById.get(toolCall.id);
193
- if (!block) {
194
- block = {
195
- type: "toolCall",
196
- id: toolCall.id || "",
197
- name: toolCall.function?.name || "",
198
- arguments: {},
199
- partialArgs: "",
200
- streamIndex
201
- };
202
- if (streamIndex !== void 0) toolCallBlocksByIndex.set(streamIndex, block);
203
- if (toolCall.id) {
204
- toolCallBlocksById.set(toolCall.id, block);
205
- rememberFirstToolCallById(toolCall.id, block);
108
+ const directEventStream = { push(event) {
109
+ if (event.type === "text_start" || event.type === "thinking_start" || event.type === "toolcall_start") {
110
+ const block = output.content[event.contentIndex];
111
+ if (block) {
112
+ contentIndices.set(block, event.contentIndex);
113
+ if (block.type === "text") openTextBlock = block;
114
+ else if (block.type === "thinking") openThinkingBlock = block;
206
115
  }
207
- appendBlock(block);
208
- stream.push({
209
- type: "toolcall_start",
210
- contentIndex: getContentIndex(block),
211
- partial: output
212
- });
213
- }
214
- if (streamIndex !== void 0 && block.streamIndex === void 0) {
215
- block.streamIndex = streamIndex;
216
- toolCallBlocksByIndex.set(streamIndex, block);
217
116
  }
218
- if (toolCall.id) toolCallBlocksById.set(toolCall.id, block);
219
- return block;
220
- };
221
- const reasoningTagTextPartitioner = createReasoningTagTextPartitioner();
222
- const appendPartitionedContent = (text, hasMirroredReasoning) => {
223
- const routedDeltas = hasMirroredReasoning ? reasoningTagTextPartitioner.push(text) : reasoningTagTextPartitioner.pushVisible(text);
224
- for (const delta of routedDeltas) if (delta.kind === "text") appendTextDelta(delta.text);
225
- };
226
- const flushPartitionedContent = () => {
227
- for (const delta of reasoningTagTextPartitioner.flush()) if (delta.kind === "text") appendTextDelta(delta.text);
228
- };
229
- const guardedOpenaiStream = withFirstStreamEventTimeout(hookedOpenAIStream, {
230
- provider: model.provider,
231
- api: model.api,
232
- model: model.id,
233
- timeoutMs: getFirstStreamEventTimeoutMs(options) ?? 0,
234
- stage: "completions",
235
- abort: firstEventAbort.abort,
236
- onTimeout: getFirstStreamEventTimeoutHandler(options),
237
- hint: "The provider may be stalled while parsing the tool payload; retry with a smaller tool surface or enable OPENCLAW_DEBUG_MODEL_PAYLOAD=tools to inspect exposed tools."
238
- });
239
- for await (const chunk of guardedOpenaiStream) {
240
- if (!chunk || typeof chunk !== "object") continue;
241
- notifyLlmRequestActivity(options?.signal);
242
- output.responseId ||= chunk.id;
243
- if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
244
- if (chunk.usage) output.usage = parseOpenAICompletionsUsage(chunk.usage, model, { includeReasoningTokens: false });
245
- const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
246
- if (!choice) continue;
247
- const choiceUsage = choice.usage;
248
- if (!chunk.usage && choiceUsage) output.usage = parseOpenAICompletionsUsage(choiceUsage, model, { includeReasoningTokens: false });
249
- if (choice.finish_reason) {
250
- const finishReasonResult = mapOpenAIStopReason(choice.finish_reason);
251
- output.stopReason = finishReasonResult.stopReason;
252
- if (finishReasonResult.errorMessage) output.errorMessage = finishReasonResult.errorMessage;
253
- hasFinishReason = true;
254
- }
255
- const rawChoiceDelta = choice.delta ?? choice.message;
256
- if (rawChoiceDelta) for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
257
- const choiceDelta = normalizedDelta.delta;
258
- const reasoningFields = [
259
- "reasoning_content",
260
- "reasoning",
261
- "reasoning_text"
262
- ];
263
- const deltaFields = choiceDelta;
264
- const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
265
- let foundReasoningField = null;
266
- for (const field of reasoningFields) {
267
- const value = deltaFields[field];
268
- if (typeof value === "string" && value.length > 0) {
269
- foundReasoningField = field;
270
- break;
271
- }
272
- }
273
- if (foundReasoningField) reasoningTagTextPartitioner.markStrict();
274
- if (shouldEmitReasoning && foundReasoningField) {
275
- const delta = deltaFields[foundReasoningField];
276
- if (typeof delta === "string" && delta.length > 0) appendThinkingDelta(model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField, delta);
277
- }
278
- for (const contentDelta of readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal, foundReasoningField ? [deltaFields[foundReasoningField]] : [])) if (contentDelta.kind === "thinking") {
279
- if (reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
280
- if (shouldEmitReasoning) appendThinkingDelta(contentDelta.signature, contentDelta.text);
281
- } else appendPartitionedContent(contentDelta.text, Boolean(foundReasoningField));
282
- const toolCallDeltas = normalizedDelta.toolCalls;
283
- if (toolCallDeltas.length > 0) {
284
- flushPartitionedContent();
285
- sealNativeReasoningBeforeText();
286
- rememberPendingCommentaryTags(provisionalCommentaryTags, tagPendingCommentaryText(output.content));
287
- for (const toolCall of toolCallDeltas) {
288
- const block = ensureToolCallBlock(toolCall);
289
- if (!block.id && toolCall.id) {
290
- block.id = toolCall.id;
291
- toolCallBlocksById.set(toolCall.id, block);
292
- rememberFirstToolCallById(toolCall.id, block);
293
- }
294
- if (!block.name && toolCall.function?.name) block.name = toolCall.function.name;
295
- let delta = "";
296
- if (toolCall.function?.arguments) {
297
- delta = toolCall.function.arguments;
298
- block.partialArgs = (block.partialArgs ?? "") + toolCall.function.arguments;
299
- block.arguments = parseStreamingJson(block.partialArgs);
300
- }
301
- stream.push({
302
- type: "toolcall_delta",
303
- contentIndex: getContentIndex(block),
304
- delta,
305
- partial: output
306
- });
307
- }
308
- }
309
- const reasoningDetails = choiceDelta.reasoning_details;
310
- if (Array.isArray(reasoningDetails)) {
311
- for (const detail of reasoningDetails) if (isEncryptedReasoningDetail(detail)) {
312
- const serializedDetail = JSON.stringify(detail);
313
- const matchingToolCall = toolCallBlocksByFirstId.get(detail.id);
314
- if (matchingToolCall) matchingToolCall.thoughtSignature = serializedDetail;
315
- else pendingReasoningDetailsByToolCallId.set(detail.id, serializedDetail);
316
- }
317
- }
318
- }
319
- }
320
- flushPartitionedContent();
321
- let terminalError;
322
- if (options?.signal?.aborted) terminalError = transportAbortError(options.signal);
323
- else if (output.stopReason === "aborted") terminalError = /* @__PURE__ */ new Error("Request was aborted");
324
- else if (output.stopReason === "error") terminalError = new Error(output.errorMessage || "Provider returned an error stop reason");
325
- else if (!hasFinishReason) terminalError = /* @__PURE__ */ new Error("Stream ended without finish_reason");
326
- if (terminalError) {
327
- for (const block of blocks) if (block.type !== "toolCall") finishBlock(block);
328
- throw terminalError;
329
- }
330
- finalizeOpenAICompletionsToolCalls(output);
331
- if (output.stopReason === "aborted" || output.stopReason === "error") {
332
- for (const block of blocks) if (block.type !== "toolCall") finishBlock(block);
333
- throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
117
+ stream.push(event);
118
+ } };
119
+ try {
120
+ await processCompletionsStream(hookedOpenAIStream, output, model, directEventStream, {
121
+ mode: "direct",
122
+ beforeContentBlock(nextType) {
123
+ if (openThinkingBlock) finishBlock(openThinkingBlock);
124
+ if (openTextBlock && nextType !== "toolCall") finishBlock(openTextBlock);
125
+ },
126
+ provisionalCommentaryTags,
127
+ signal: options?.signal,
128
+ emitReasoning: shouldEmitReasoning,
129
+ strictReasoningTags: reasoningTagTextPolicy.isStrict(options),
130
+ firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
131
+ abortFirstEventStream: firstEventAbort.abort,
132
+ onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
133
+ });
134
+ if (options?.signal?.aborted) throw transportAbortError(options.signal);
135
+ if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
136
+ } catch (error) {
137
+ for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
138
+ throw error;
334
139
  }
335
- for (const block of blocks) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
336
- if (output.stopReason !== "toolUse") clearPendingCommentaryText(provisionalCommentaryTags);
337
- if (output.stopReason === "toolUse") tagPendingCommentaryText(output.content);
140
+ for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
338
141
  stream.push({
339
142
  type: "done",
340
143
  reason: output.stopReason,
@@ -345,6 +148,8 @@ const streamOpenAICompletions = (model, context, options) => {
345
148
  const terminal = projectProviderError(error, options?.signal);
346
149
  Object.assign(output, terminal);
347
150
  finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
151
+ clearPendingCommentaryText(provisionalCommentaryTags);
152
+ tagUnresolvedTextAsCommentary(output);
348
153
  for (const block of output.content) {
349
154
  delete block.index;
350
155
  delete block.partialArgs;
@@ -400,7 +205,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
400
205
  } : headers;
401
206
  return new OpenAI({
402
207
  apiKey,
403
- baseURL: isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl,
208
+ baseURL: resolveOpenAIClientBaseUrl(model, isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl),
404
209
  dangerouslyAllowBrowser: true,
405
210
  defaultHeaders,
406
211
  fetch: getAiTransportHost().buildModelFetch(model)
@@ -1,6 +1,6 @@
1
- import { E as Model, O as OpenAICompletionsCompat } from "./types-BHNrPS1l.mjs";
2
- import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-vWgMMhiJ.mjs";
3
-
1
+ import "./index-N3zr6__t.mjs";
2
+ import { D as Model, k as OpenAICompletionsCompat } from "./types-h38Azne1.mjs";
3
+ import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DoPJJ1KD.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";