@openclaw/ai 2026.8.1-beta.2 → 2026.9.1-beta.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 (82) hide show
  1. package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
  2. package/dist/{anthropic-B6dLpq5L.mjs → anthropic-DI4PZKKB.mjs} +46 -34
  3. package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-nhKaCXu6.mjs} +17 -22
  4. package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-B_0n0enE.d.mts} +3 -1
  5. package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-CTd8NzcD.d.mts} +2 -1
  6. package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-D8dI0ekg.mjs} +3 -3
  7. package/dist/diagnostics.d.mts +0 -1
  8. package/dist/diagnostics.mjs +1 -1
  9. package/dist/event-stream-BKp4fOt_.d.mts +1 -0
  10. package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-LiXePESD.d.mts} +1 -2
  11. package/dist/event-stream.d.mts +2 -1
  12. package/dist/{google-C7h2QzDX.mjs → google-Od-LLdVK.mjs} +3 -3
  13. package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-Bgr9lFPw.mjs} +22 -8
  14. package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-aerRSXc4.mjs} +4 -4
  15. package/dist/{host-DTqNc7ad.mjs → host-D51fmkH6.mjs} +40 -33
  16. package/dist/{host-vWgMMhiJ.d.mts → host-DsbPMFU6.d.mts} +7 -7
  17. package/dist/index-Qbej8io0.d.mts +3 -0
  18. package/dist/index.d.mts +8 -8
  19. package/dist/index.mjs +2 -3
  20. package/dist/internal/anthropic.d.mts +13 -6
  21. package/dist/internal/anthropic.mjs +4 -4
  22. package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
  23. package/dist/internal/openai-responses-payload-policy.mjs +2 -2
  24. package/dist/internal/openai.d.mts +6 -6
  25. package/dist/internal/openai.mjs +10 -8
  26. package/dist/internal/runtime.d.mts +18 -5
  27. package/dist/internal/runtime.mjs +8 -7
  28. package/dist/internal/shared.d.mts +18 -4
  29. package/dist/internal/shared.mjs +4 -4
  30. package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
  31. package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
  32. package/dist/{mistral-CEWoQI_g.mjs → mistral-EiHdymeb.mjs} +59 -49
  33. package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-DHpF9o1e.mjs} +42 -17
  34. package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-EFPiUGfS.mjs} +60 -257
  35. package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-BefmHT26.d.mts} +3 -3
  36. package/dist/openai-completions-stream-DUlGwRMz.mjs +1621 -0
  37. package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-BogP8OjX.mjs} +6 -5
  38. package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-Dvj_UtPy.d.mts} +3 -3
  39. package/dist/{openai-responses-contracts-CyfIkQi5.mjs → openai-responses-contracts-QUY12X0B.mjs} +6 -26
  40. package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-CNGFT9zr.d.mts} +1 -0
  41. package/dist/{openai-responses-payload-policy-BDxV-W0c.mjs → openai-responses-payload-policy-D8EdimYe.mjs} +6 -8
  42. package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-Cd4hJG-S.mjs} +3 -3
  43. package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-DJThc6jW.mjs} +205 -1472
  44. package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
  45. package/dist/openai-tool-schema-ho-hIkQf.mjs +1695 -0
  46. package/dist/{provider-error-BUwEnjXq.mjs → provider-error-DDOs_Bz0.mjs} +20 -27
  47. package/dist/provider-options-AvldWZt8.mjs +21 -0
  48. package/dist/{provider-options-B96RdNpH.d.mts → provider-options-MdMBLzlU.d.mts} +15 -4
  49. package/dist/provider-transcript-transform-C01bQ5a3.mjs +32 -0
  50. package/dist/provider-types.d.mts +7 -5
  51. package/dist/providers.d.mts +1 -2
  52. package/dist/providers.mjs +9 -9
  53. package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +3 -0
  54. package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
  55. package/dist/{simple-options-D58D5Kvw.mjs → simple-options-CFj7x3J4.mjs} +5 -4
  56. package/dist/{anthropic-JsNA5KCu.mjs → src-Bu3FiFAG.mjs} +1 -1
  57. package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
  58. package/dist/string-normalization--fwJ4S2q.mjs +16 -0
  59. package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-qvTEs5Am.mjs} +17 -8
  60. package/dist/transport-stream-shared-ljShVIZB.mjs +342 -0
  61. package/dist/transport-stream-shared-rvaCyFYt.d.mts +138 -0
  62. package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-LJ1_rbi-.mjs} +8 -5
  63. package/dist/transports.d.mts +45 -106
  64. package/dist/transports.mjs +134 -1089
  65. package/dist/{types-BHNrPS1l.d.mts → types-DhLoJbFm.d.mts} +49 -17
  66. package/dist/types-GiAjXatj.d.mts +1 -0
  67. package/dist/types.d.mts +6 -5
  68. package/dist/types.mjs +1 -2
  69. package/dist/utf16-slice-qz3nsy87.mjs +84 -0
  70. package/dist/{validation-DT9SrFn3.d.mts → validation-Dk7q7NMN.d.mts} +1 -2
  71. package/dist/validation.d.mts +1 -1
  72. package/package.json +5 -5
  73. package/dist/index-BVVgDSdq.d.mts +0 -1
  74. package/dist/openai-stop-reason-BkFkqqK0.mjs +0 -563
  75. package/dist/openai-tool-projection-CY04OcvQ.mjs +0 -338
  76. package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
  77. package/dist/record-coerce-DdXsgUd_.mjs +0 -23
  78. package/dist/src-D2H6yKkH.mjs +0 -2
  79. package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
  80. package/dist/string-coerce-fsri9iCu.mjs +0 -34
  81. package/dist/types-BVVgDSdq.d.mts +0 -1
  82. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -1,18 +1,15 @@
1
1
  import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.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-DDOs_Bz0.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 { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-CFj7x3J4.mjs";
9
+ import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-ljShVIZB.mjs";
10
+ 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-DUlGwRMz.mjs";
11
+ import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-ho-hIkQf.mjs";
12
+ import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
16
13
  import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
17
14
  import OpenAI from "openai";
18
15
  //#region packages/ai/src/providers/openai-completions.ts
@@ -21,11 +18,6 @@ var openai_completions_exports = /* @__PURE__ */ __exportAll({
21
18
  streamOpenAICompletions: () => streamOpenAICompletions,
22
19
  streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
23
20
  });
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
21
  const streamOpenAICompletions = (model, context, options) => {
30
22
  const stream = new AssistantMessageEventStream();
31
23
  (async () => {
@@ -57,6 +49,7 @@ const streamOpenAICompletions = (model, context, options) => {
57
49
  try {
58
50
  const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
59
51
  const compat = resolveOpenAICompletionsCompat(model);
52
+ const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
60
53
  const cacheRetention = resolveCacheRetention(options?.cacheRetention);
61
54
  const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
62
55
  const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
@@ -74,267 +67,75 @@ const streamOpenAICompletions = (model, context, options) => {
74
67
  stream: openaiStream,
75
68
  signal: firstEventAbort.signal,
76
69
  abort: firstEventAbort.abort,
77
- hook: createOpenAIResponseHook(options?.onResponse, response, model),
70
+ hook: createOpenAIProviderAcceptanceHook(options, response, model),
78
71
  onReady: () => stream.push({
79
72
  type: "start",
80
73
  partial: output
81
74
  })
82
75
  });
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
76
  const finishedBlocks = /* @__PURE__ */ new Set();
93
77
  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
- };
78
+ let openTextBlock;
79
+ let openThinkingBlock;
108
80
  const finishBlock = (block) => {
109
- const contentIndex = getContentIndex(block);
110
- if (contentIndex === -1 || finishedBlocks.has(block)) return;
81
+ const contentIndex = contentIndices.get(block);
82
+ if (contentIndex === void 0 || finishedBlocks.has(block)) return;
111
83
  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);
84
+ if (block.type === "text") {
85
+ openTextBlock = void 0;
138
86
  stream.push({
139
- type: "text_start",
140
- contentIndex: getContentIndex(textBlock),
87
+ type: "text_end",
88
+ contentIndex,
89
+ content: block.text,
141
90
  partial: output
142
91
  });
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);
92
+ } else if (block.type === "thinking") {
93
+ openThinkingBlock = void 0;
154
94
  stream.push({
155
- type: "thinking_start",
156
- contentIndex: getContentIndex(thinkingBlock),
95
+ type: "thinking_end",
96
+ contentIndex,
97
+ content: block.thinking,
157
98
  partial: output
158
99
  });
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,
100
+ } else if (block.type === "toolCall") stream.push({
101
+ type: "toolcall_end",
102
+ contentIndex,
103
+ toolCall: block,
186
104
  partial: output
187
105
  });
188
106
  };
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);
107
+ const directEventStream = { push(event) {
108
+ if (event.type === "text_start" || event.type === "thinking_start" || event.type === "toolcall_start") {
109
+ const block = output.content[event.contentIndex];
110
+ if (block) {
111
+ contentIndices.set(block, event.contentIndex);
112
+ if (block.type === "text") openTextBlock = block;
113
+ else if (block.type === "thinking") openThinkingBlock = block;
206
114
  }
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
115
  }
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"));
116
+ stream.push(event);
117
+ } };
118
+ try {
119
+ await processCompletionsStream(hookedOpenAIStream, output, model, directEventStream, {
120
+ mode: "direct",
121
+ beforeContentBlock(nextType) {
122
+ if (openThinkingBlock) finishBlock(openThinkingBlock);
123
+ if (openTextBlock && nextType !== "toolCall") finishBlock(openTextBlock);
124
+ },
125
+ provisionalCommentaryTags,
126
+ signal: options?.signal,
127
+ emitReasoning: shouldEmitReasoning,
128
+ firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
129
+ abortFirstEventStream: firstEventAbort.abort,
130
+ onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
131
+ });
132
+ if (options?.signal?.aborted) throw transportAbortError(options.signal);
133
+ if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
134
+ } catch (error) {
135
+ for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
136
+ throw error;
334
137
  }
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);
138
+ for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
338
139
  stream.push({
339
140
  type: "done",
340
141
  reason: output.stopReason,
@@ -345,6 +146,8 @@ const streamOpenAICompletions = (model, context, options) => {
345
146
  const terminal = projectProviderError(error, options?.signal);
346
147
  Object.assign(output, terminal);
347
148
  finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
149
+ clearPendingCommentaryText(provisionalCommentaryTags);
150
+ tagUnresolvedTextAsCommentary(output);
348
151
  for (const block of output.content) {
349
152
  delete block.index;
350
153
  delete block.partialArgs;
@@ -400,7 +203,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
400
203
  } : headers;
401
204
  return new OpenAI({
402
205
  apiKey,
403
- baseURL: isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl,
206
+ baseURL: resolveOpenAIClientBaseUrl(model, isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl),
404
207
  dangerouslyAllowBrowser: true,
405
208
  defaultHeaders,
406
209
  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 { D as Model, k as OpenAICompletionsCompat } from "./types-DhLoJbFm.mjs";
2
+ import "./index-Qbej8io0.mjs";
3
+ import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DsbPMFU6.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";