@openclaw/ai 2026.8.1-beta.1 → 2026.8.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-CE-7SkF6.mjs → anthropic-B6dLpq5L.mjs} +37 -22
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-8lJNKXOE.mjs} +225 -102
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-BP6AWT8j.d.mts} +3 -1
- package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CGQu21aw.mjs → google-C7h2QzDX.mjs} +4 -4
- package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-B0Qr9OR7.mjs} +9 -18
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-Bhc3TjDl.mjs} +5 -4
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/{host-Bl7Kgddo.mjs → host-DTqNc7ad.mjs} +227 -168
- package/dist/{host-Dn4_SZI2.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +13 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -4
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-Dx6VzNjf.mjs → mistral-CEWoQI_g.mjs} +26 -45
- package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +225 -144
- package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-BPnt4Sml.mjs} +28 -43
- package/dist/openai-completions-compat-Dt3dcawL.d.mts +43 -0
- package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-DhIKtOup.mjs} +17 -24
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-DgNTYnRY.mjs} +3 -3
- package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-DXIt3iY5.mjs} +1211 -908
- package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-BkFkqqK0.mjs} +198 -172
- package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CY04OcvQ.mjs} +151 -128
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-C5kYML7i.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BYqrYtC_.mjs} +28 -2
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +5 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +135 -178
- package/dist/transports.mjs +1732 -1294
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-CH7ReIcU.d.mts → types-BHNrPS1l.d.mts} +19 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-CcPcuEbR.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
- package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
- package/dist/provider-error-DI0Ts28U.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
- package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
- package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
1
|
+
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, l as isImageWithMediaPayload, s as extractToolResultText } from "./host-DTqNc7ad.mjs";
|
|
4
|
+
import { a as isRecord, r as asOptionalObjectRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
5
|
+
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
6
|
+
import { l as stripSystemPromptCacheBoundary } from "./simple-options-D58D5Kvw.mjs";
|
|
7
|
+
import { o as resolveProviderRequestCapabilities } from "./tool-schema-json-projection-q5d7QX5c.mjs";
|
|
8
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
9
|
+
import { l as measureUtf8AppendBytes } from "./openai-tool-projection-CY04OcvQ.mjs";
|
|
5
10
|
import { randomUUID } from "node:crypto";
|
|
6
11
|
//#region packages/ai/src/utils/assistant-text-phase.ts
|
|
7
12
|
function isAssistantTextPhaseBlock(block) {
|
|
@@ -175,7 +180,161 @@ function resolveOpenAICompletionsCompat(model, resolveCapabilities = resolveProv
|
|
|
175
180
|
requiresNonEmptyUserOrAssistantMessage: defaults.requiresNonEmptyUserOrAssistantMessage
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
|
-
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region packages/ai/src/providers/openai-completions-tool-calls.ts
|
|
185
|
+
const MAX_BUFFERED_TOOL_CALL_ARGUMENT_BYTES = 256e3;
|
|
186
|
+
const MAX_BUFFERED_LEGACY_FOLLOWING_DELTA_BYTES = 256e3;
|
|
187
|
+
const MAX_BUFFERED_LEGACY_FOLLOWING_DELTAS = 1024;
|
|
188
|
+
/** Normalize the SDK's legacy single-function lane into its modern tool-call shape. */
|
|
189
|
+
function createOpenAICompletionsToolCallDeltaNormalizer() {
|
|
190
|
+
let sawModernToolCall = false;
|
|
191
|
+
let pendingLegacyArgumentBytes = 0;
|
|
192
|
+
let pendingFollowingDeltaBytes = 0;
|
|
193
|
+
let pendingLegacyToolCall;
|
|
194
|
+
const modernArguments = /* @__PURE__ */ new Map();
|
|
195
|
+
const pendingFollowingDeltas = [];
|
|
196
|
+
const takePendingFollowingDeltas = () => {
|
|
197
|
+
pendingFollowingDeltaBytes = 0;
|
|
198
|
+
return pendingFollowingDeltas.splice(0).map((delta) => ({
|
|
199
|
+
delta,
|
|
200
|
+
toolCalls: []
|
|
201
|
+
}));
|
|
202
|
+
};
|
|
203
|
+
const bufferFollowingDelta = (delta) => {
|
|
204
|
+
const nextDeltaBytes = Buffer.byteLength(JSON.stringify(delta), "utf8");
|
|
205
|
+
if (pendingFollowingDeltaBytes + nextDeltaBytes > MAX_BUFFERED_LEGACY_FOLLOWING_DELTA_BYTES || pendingFollowingDeltas.length >= MAX_BUFFERED_LEGACY_FOLLOWING_DELTAS) throw new Error("Exceeded legacy tool-call content buffer limit");
|
|
206
|
+
pendingFollowingDeltaBytes += nextDeltaBytes;
|
|
207
|
+
pendingFollowingDeltas.push(delta);
|
|
208
|
+
};
|
|
209
|
+
const withoutToolCalls = (delta) => {
|
|
210
|
+
const ordinaryDelta = { ...delta };
|
|
211
|
+
delete ordinaryDelta.function_call;
|
|
212
|
+
delete ordinaryDelta.tool_calls;
|
|
213
|
+
return ordinaryDelta;
|
|
214
|
+
};
|
|
215
|
+
const hasObservableContent = (value) => {
|
|
216
|
+
if (typeof value === "string") return value.length > 0;
|
|
217
|
+
if (Array.isArray(value)) return value.some(hasObservableContent);
|
|
218
|
+
if (isRecord(value)) return Object.entries(value).some(([field, nestedValue]) => field !== "type" && field !== "id" && field !== "index" && hasObservableContent(nestedValue));
|
|
219
|
+
return false;
|
|
220
|
+
};
|
|
221
|
+
const hasOrdinaryContent = (delta) => Object.entries(delta).some(([field, value]) => field !== "role" && hasObservableContent(value));
|
|
222
|
+
return (delta, finishReason) => {
|
|
223
|
+
const ordinaryDelta = withoutToolCalls(delta);
|
|
224
|
+
if (delta.tool_calls && delta.tool_calls.length > 0) {
|
|
225
|
+
for (const toolCall of delta.tool_calls) {
|
|
226
|
+
const index = typeof toolCall.index === "number" ? toolCall.index : void 0;
|
|
227
|
+
const state = (index === void 0 ? void 0 : modernArguments.get(index)) ?? (toolCall.id ? modernArguments.get(toolCall.id) : void 0) ?? {
|
|
228
|
+
bytes: 0,
|
|
229
|
+
pendingHighSurrogate: false
|
|
230
|
+
};
|
|
231
|
+
if (index !== void 0) modernArguments.set(index, state);
|
|
232
|
+
if (toolCall.id) modernArguments.set(toolCall.id, state);
|
|
233
|
+
const argumentDelta = toolCall.function?.arguments ?? "";
|
|
234
|
+
const append = measureUtf8AppendBytes(state.pendingHighSurrogate, argumentDelta);
|
|
235
|
+
state.bytes += append.bytes;
|
|
236
|
+
if (state.bytes > MAX_BUFFERED_TOOL_CALL_ARGUMENT_BYTES) throw new Error("Exceeded tool-call argument buffer limit");
|
|
237
|
+
state.pendingHighSurrogate = append.endsWithHighSurrogate;
|
|
238
|
+
}
|
|
239
|
+
const precedingDeltas = takePendingFollowingDeltas();
|
|
240
|
+
sawModernToolCall = true;
|
|
241
|
+
pendingLegacyArgumentBytes = 0;
|
|
242
|
+
pendingLegacyToolCall = void 0;
|
|
243
|
+
return [...precedingDeltas, {
|
|
244
|
+
delta: ordinaryDelta,
|
|
245
|
+
toolCalls: delta.tool_calls
|
|
246
|
+
}];
|
|
247
|
+
}
|
|
248
|
+
const functionCall = delta.function_call;
|
|
249
|
+
if (sawModernToolCall) return [{
|
|
250
|
+
delta: ordinaryDelta,
|
|
251
|
+
toolCalls: []
|
|
252
|
+
}];
|
|
253
|
+
const hadPendingLegacyCall = pendingLegacyToolCall !== void 0;
|
|
254
|
+
const leadingDeltas = [];
|
|
255
|
+
if (hasOrdinaryContent(ordinaryDelta)) if (hadPendingLegacyCall) bufferFollowingDelta(ordinaryDelta);
|
|
256
|
+
else leadingDeltas.push({
|
|
257
|
+
delta: ordinaryDelta,
|
|
258
|
+
toolCalls: []
|
|
259
|
+
});
|
|
260
|
+
if (functionCall && (functionCall.name || functionCall.arguments)) {
|
|
261
|
+
const nextFunctionName = pendingLegacyToolCall?.function?.name ? void 0 : functionCall.name;
|
|
262
|
+
const nextArgumentBytes = Buffer.byteLength(functionCall.arguments ?? "", "utf8") + Buffer.byteLength(nextFunctionName ?? "", "utf8");
|
|
263
|
+
if (pendingLegacyArgumentBytes + nextArgumentBytes > MAX_BUFFERED_TOOL_CALL_ARGUMENT_BYTES) throw new Error("Exceeded tool-call argument buffer limit");
|
|
264
|
+
pendingLegacyArgumentBytes += nextArgumentBytes;
|
|
265
|
+
pendingLegacyToolCall ??= {
|
|
266
|
+
index: 0,
|
|
267
|
+
id: `call_${randomUUID().replaceAll("-", "").slice(0, 24)}`,
|
|
268
|
+
type: "function",
|
|
269
|
+
function: {}
|
|
270
|
+
};
|
|
271
|
+
const pendingFunction = pendingLegacyToolCall.function ??= {};
|
|
272
|
+
if (nextFunctionName) pendingFunction.name = nextFunctionName;
|
|
273
|
+
if (functionCall.arguments) pendingFunction.arguments = (pendingFunction.arguments ?? "") + functionCall.arguments;
|
|
274
|
+
}
|
|
275
|
+
if (!pendingLegacyToolCall) return leadingDeltas.length > 0 ? leadingDeltas : [{
|
|
276
|
+
delta: ordinaryDelta,
|
|
277
|
+
toolCalls: []
|
|
278
|
+
}];
|
|
279
|
+
if (finishReason === "function_call") {
|
|
280
|
+
const confirmedLegacyToolCall = pendingLegacyToolCall;
|
|
281
|
+
pendingLegacyToolCall = void 0;
|
|
282
|
+
pendingLegacyArgumentBytes = 0;
|
|
283
|
+
return [
|
|
284
|
+
...leadingDeltas,
|
|
285
|
+
{
|
|
286
|
+
delta: {},
|
|
287
|
+
toolCalls: [confirmedLegacyToolCall]
|
|
288
|
+
},
|
|
289
|
+
...takePendingFollowingDeltas()
|
|
290
|
+
];
|
|
291
|
+
}
|
|
292
|
+
if (finishReason) {
|
|
293
|
+
pendingLegacyArgumentBytes = 0;
|
|
294
|
+
pendingLegacyToolCall = void 0;
|
|
295
|
+
return [...leadingDeltas, ...takePendingFollowingDeltas()];
|
|
296
|
+
}
|
|
297
|
+
return leadingDeltas;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** Publish only executable calls; streaming scratch state never belongs in replay. */
|
|
301
|
+
function finalizeOpenAICompletionsToolCalls(output, options = {}) {
|
|
302
|
+
const isToolCall = (block) => block.type === "toolCall";
|
|
303
|
+
const hasToolCalls = output.content.some(isToolCall);
|
|
304
|
+
if (output.stopReason === "toolUse" && !hasToolCalls) output.stopReason = "stop";
|
|
305
|
+
if (output.stopReason === "stop" && hasToolCalls && options.allowSilentToolCallPromotion !== false && !output.content.some((block) => {
|
|
306
|
+
const candidate = block;
|
|
307
|
+
return candidate.type === "text" && typeof candidate.text === "string" && candidate.text.trim().length > 0;
|
|
308
|
+
})) output.stopReason = "toolUse";
|
|
309
|
+
if (output.stopReason !== "toolUse") {
|
|
310
|
+
if (hasToolCalls) output.content = output.content.filter((block) => !isToolCall(block));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
for (const block of output.content) {
|
|
314
|
+
if (!isToolCall(block)) continue;
|
|
315
|
+
const toolCall = block;
|
|
316
|
+
let completeArguments;
|
|
317
|
+
try {
|
|
318
|
+
completeArguments = typeof toolCall.partialArgs === "string" && toolCall.partialArgs.trim().length > 0 ? JSON.parse(toolCall.partialArgs) : void 0;
|
|
319
|
+
} catch {
|
|
320
|
+
completeArguments = void 0;
|
|
321
|
+
}
|
|
322
|
+
if (typeof toolCall.name !== "string" || toolCall.name.trim().length === 0 || !isRecord(completeArguments)) {
|
|
323
|
+
output.stopReason = "error";
|
|
324
|
+
output.errorMessage = "Provider returned an incomplete or malformed tool call";
|
|
325
|
+
output.content = output.content.filter((candidate) => !isToolCall(candidate));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
toolCall.arguments = completeArguments;
|
|
329
|
+
}
|
|
330
|
+
for (let contentIndex = 0; contentIndex < output.content.length; contentIndex += 1) {
|
|
331
|
+
const block = output.content[contentIndex];
|
|
332
|
+
if (!block || !isToolCall(block)) continue;
|
|
333
|
+
delete block.partialArgs;
|
|
334
|
+
delete block.streamIndex;
|
|
335
|
+
options.onConfirmedToolCall?.(block, contentIndex);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
179
338
|
//#endregion
|
|
180
339
|
//#region packages/ai/src/openai-completions-messages.ts
|
|
181
340
|
const EMPTY_TOOL_RESULT_TEXT = "(no output)";
|
|
@@ -192,6 +351,10 @@ function sanitizeToolResultText(text, fallback) {
|
|
|
192
351
|
const sanitized = sanitizeSurrogates(text);
|
|
193
352
|
return sanitized.trim().length > 0 ? sanitized : fallback;
|
|
194
353
|
}
|
|
354
|
+
/** Whether replayed messages require a tools marker for proxy compatibility. */
|
|
355
|
+
function hasToolCallHistory(messages) {
|
|
356
|
+
return messages.some((message) => message.role === "toolResult" || message.role === "assistant" && Array.isArray(message.content) && message.content.some((block) => block.type === "toolCall"));
|
|
357
|
+
}
|
|
195
358
|
/** Convert a normalized transcript to OpenAI Chat Completions messages. */
|
|
196
359
|
function convertMessages(model, context, compat, options = {}) {
|
|
197
360
|
const params = [];
|
|
@@ -200,7 +363,7 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
200
363
|
if (model.provider === "openai") return id.length > 40 ? truncateUtf16Safe(id, 40) : id;
|
|
201
364
|
return id;
|
|
202
365
|
};
|
|
203
|
-
const transformedMessages =
|
|
366
|
+
const transformedMessages = transformProviderMessages(context.messages, model, (id) => normalizeToolCallId(id));
|
|
204
367
|
if (context.systemPrompt) {
|
|
205
368
|
const role = model.reasoning && compat.supportsDeveloperRole ? "developer" : "system";
|
|
206
369
|
const systemPrompt = options.preserveSystemPromptCacheBoundary ? context.systemPrompt : stripSystemPromptCacheBoundary(context.systemPrompt);
|
|
@@ -232,6 +395,10 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
232
395
|
type: "text",
|
|
233
396
|
text: sanitizeSurrogates(item.text)
|
|
234
397
|
};
|
|
398
|
+
if (item.type === "video") return {
|
|
399
|
+
type: "video_url",
|
|
400
|
+
video_url: { url: `data:${item.mimeType};base64,${item.data}` }
|
|
401
|
+
};
|
|
235
402
|
return {
|
|
236
403
|
type: "image_url",
|
|
237
404
|
image_url: { url: `data:${item.mimeType};base64,${item.data}` }
|
|
@@ -339,144 +506,31 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
339
506
|
return params;
|
|
340
507
|
}
|
|
341
508
|
//#endregion
|
|
342
|
-
//#region packages/ai/src/
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const takePendingFollowingDeltas = () => {
|
|
354
|
-
pendingFollowingDeltaBytes = 0;
|
|
355
|
-
return pendingFollowingDeltas.splice(0).map((delta) => ({
|
|
356
|
-
delta,
|
|
357
|
-
toolCalls: []
|
|
358
|
-
}));
|
|
359
|
-
};
|
|
360
|
-
const bufferFollowingDelta = (delta) => {
|
|
361
|
-
const nextDeltaBytes = Buffer.byteLength(JSON.stringify(delta), "utf8");
|
|
362
|
-
if (pendingFollowingDeltaBytes + nextDeltaBytes > MAX_BUFFERED_LEGACY_FOLLOWING_DELTA_BYTES || pendingFollowingDeltas.length >= MAX_BUFFERED_LEGACY_FOLLOWING_DELTAS) throw new Error("Exceeded legacy tool-call content buffer limit");
|
|
363
|
-
pendingFollowingDeltaBytes += nextDeltaBytes;
|
|
364
|
-
pendingFollowingDeltas.push(delta);
|
|
365
|
-
};
|
|
366
|
-
const withoutToolCalls = (delta) => {
|
|
367
|
-
const ordinaryDelta = { ...delta };
|
|
368
|
-
delete ordinaryDelta.function_call;
|
|
369
|
-
delete ordinaryDelta.tool_calls;
|
|
370
|
-
return ordinaryDelta;
|
|
371
|
-
};
|
|
372
|
-
const hasObservableContent = (value) => {
|
|
373
|
-
if (typeof value === "string") return value.length > 0;
|
|
374
|
-
if (Array.isArray(value)) return value.some(hasObservableContent);
|
|
375
|
-
if (isRecord(value)) return Object.entries(value).some(([field, nestedValue]) => field !== "type" && field !== "id" && field !== "index" && hasObservableContent(nestedValue));
|
|
376
|
-
return false;
|
|
377
|
-
};
|
|
378
|
-
const hasOrdinaryContent = (delta) => Object.entries(delta).some(([field, value]) => field !== "role" && hasObservableContent(value));
|
|
379
|
-
return (delta, finishReason) => {
|
|
380
|
-
const ordinaryDelta = withoutToolCalls(delta);
|
|
381
|
-
if (delta.tool_calls && delta.tool_calls.length > 0) {
|
|
382
|
-
const precedingDeltas = takePendingFollowingDeltas();
|
|
383
|
-
sawModernToolCall = true;
|
|
384
|
-
pendingLegacyArgumentBytes = 0;
|
|
385
|
-
pendingLegacyToolCall = void 0;
|
|
386
|
-
return [...precedingDeltas, {
|
|
387
|
-
delta: ordinaryDelta,
|
|
388
|
-
toolCalls: delta.tool_calls
|
|
389
|
-
}];
|
|
390
|
-
}
|
|
391
|
-
const functionCall = delta.function_call;
|
|
392
|
-
if (sawModernToolCall) return [{
|
|
393
|
-
delta: ordinaryDelta,
|
|
394
|
-
toolCalls: []
|
|
395
|
-
}];
|
|
396
|
-
const hadPendingLegacyCall = pendingLegacyToolCall !== void 0;
|
|
397
|
-
const leadingDeltas = [];
|
|
398
|
-
if (hasOrdinaryContent(ordinaryDelta)) if (hadPendingLegacyCall) bufferFollowingDelta(ordinaryDelta);
|
|
399
|
-
else leadingDeltas.push({
|
|
400
|
-
delta: ordinaryDelta,
|
|
401
|
-
toolCalls: []
|
|
402
|
-
});
|
|
403
|
-
if (functionCall && (functionCall.name || functionCall.arguments)) {
|
|
404
|
-
const nextFunctionName = pendingLegacyToolCall?.function?.name ? void 0 : functionCall.name;
|
|
405
|
-
const nextArgumentBytes = Buffer.byteLength(functionCall.arguments ?? "", "utf8") + Buffer.byteLength(nextFunctionName ?? "", "utf8");
|
|
406
|
-
if (pendingLegacyArgumentBytes + nextArgumentBytes > MAX_BUFFERED_LEGACY_TOOL_CALL_ARGUMENT_BYTES) throw new Error("Exceeded tool-call argument buffer limit");
|
|
407
|
-
pendingLegacyArgumentBytes += nextArgumentBytes;
|
|
408
|
-
pendingLegacyToolCall ??= {
|
|
409
|
-
index: 0,
|
|
410
|
-
id: `call_${randomUUID().replaceAll("-", "").slice(0, 24)}`,
|
|
411
|
-
type: "function",
|
|
412
|
-
function: {}
|
|
413
|
-
};
|
|
414
|
-
const pendingFunction = pendingLegacyToolCall.function ??= {};
|
|
415
|
-
if (nextFunctionName) pendingFunction.name = nextFunctionName;
|
|
416
|
-
if (functionCall.arguments) pendingFunction.arguments = (pendingFunction.arguments ?? "") + functionCall.arguments;
|
|
417
|
-
}
|
|
418
|
-
if (!pendingLegacyToolCall) return leadingDeltas.length > 0 ? leadingDeltas : [{
|
|
419
|
-
delta: ordinaryDelta,
|
|
420
|
-
toolCalls: []
|
|
421
|
-
}];
|
|
422
|
-
if (finishReason === "function_call") {
|
|
423
|
-
const confirmedLegacyToolCall = pendingLegacyToolCall;
|
|
424
|
-
pendingLegacyToolCall = void 0;
|
|
425
|
-
pendingLegacyArgumentBytes = 0;
|
|
426
|
-
return [
|
|
427
|
-
...leadingDeltas,
|
|
428
|
-
{
|
|
429
|
-
delta: {},
|
|
430
|
-
toolCalls: [confirmedLegacyToolCall]
|
|
431
|
-
},
|
|
432
|
-
...takePendingFollowingDeltas()
|
|
433
|
-
];
|
|
434
|
-
}
|
|
435
|
-
if (finishReason) {
|
|
436
|
-
pendingLegacyArgumentBytes = 0;
|
|
437
|
-
pendingLegacyToolCall = void 0;
|
|
438
|
-
return [...leadingDeltas, ...takePendingFollowingDeltas()];
|
|
439
|
-
}
|
|
440
|
-
return leadingDeltas;
|
|
441
|
-
};
|
|
509
|
+
//#region packages/ai/src/transports/openai-reasoning-compat.ts
|
|
510
|
+
/**
|
|
511
|
+
* OpenAI reasoning-effort compatibility helpers.
|
|
512
|
+
*
|
|
513
|
+
* Keeps provider metadata and built-in model exceptions on one path before request payloads are built.
|
|
514
|
+
*/
|
|
515
|
+
const OPENAI_MEDIUM_ONLY_REASONING_MODEL_IDS = /* @__PURE__ */ new Set(["gpt-5.1-codex-mini"]);
|
|
516
|
+
function readCompatReasoningEffortMap(compat) {
|
|
517
|
+
const rawMap = asOptionalObjectRecord(asOptionalObjectRecord(compat)?.reasoningEffortMap);
|
|
518
|
+
if (!rawMap) return {};
|
|
519
|
+
return Object.fromEntries(Object.entries(rawMap).filter((entry) => typeof entry[0] === "string" && typeof entry[1] === "string"));
|
|
442
520
|
}
|
|
443
|
-
/**
|
|
444
|
-
function
|
|
445
|
-
const
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
for (const block of output.content) {
|
|
457
|
-
if (!isToolCall(block)) continue;
|
|
458
|
-
const toolCall = block;
|
|
459
|
-
let completeArguments;
|
|
460
|
-
try {
|
|
461
|
-
completeArguments = typeof toolCall.partialArgs === "string" && toolCall.partialArgs.trim().length > 0 ? JSON.parse(toolCall.partialArgs) : void 0;
|
|
462
|
-
} catch {
|
|
463
|
-
completeArguments = void 0;
|
|
464
|
-
}
|
|
465
|
-
if (typeof toolCall.name !== "string" || toolCall.name.trim().length === 0 || !isRecord(completeArguments)) {
|
|
466
|
-
output.stopReason = "error";
|
|
467
|
-
output.errorMessage = "Provider returned an incomplete or malformed tool call";
|
|
468
|
-
output.content = output.content.filter((candidate) => !isToolCall(candidate));
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
toolCall.arguments = completeArguments;
|
|
472
|
-
}
|
|
473
|
-
for (let contentIndex = 0; contentIndex < output.content.length; contentIndex += 1) {
|
|
474
|
-
const block = output.content[contentIndex];
|
|
475
|
-
if (!block || !isToolCall(block)) continue;
|
|
476
|
-
delete block.partialArgs;
|
|
477
|
-
delete block.streamIndex;
|
|
478
|
-
options.onConfirmedToolCall?.(block, contentIndex);
|
|
479
|
-
}
|
|
521
|
+
/** Resolves the reasoning effort remap for an OpenAI-compatible model. */
|
|
522
|
+
function resolveOpenAIReasoningEffortMap(model, fallbackMap = {}) {
|
|
523
|
+
const provider = normalizeLowercaseStringOrEmpty(model.provider ?? "");
|
|
524
|
+
const id = normalizeLowercaseStringOrEmpty(model.id ?? "");
|
|
525
|
+
const builtinMap = provider === "openai" && OPENAI_MEDIUM_ONLY_REASONING_MODEL_IDS.has(id) ? {
|
|
526
|
+
minimal: "medium",
|
|
527
|
+
low: "medium"
|
|
528
|
+
} : {};
|
|
529
|
+
return {
|
|
530
|
+
...fallbackMap,
|
|
531
|
+
...builtinMap,
|
|
532
|
+
...readCompatReasoningEffortMap(model.compat)
|
|
533
|
+
};
|
|
480
534
|
}
|
|
481
535
|
//#endregion
|
|
482
536
|
//#region packages/ai/src/providers/openai-stop-reason.ts
|
|
@@ -506,32 +560,4 @@ function mapOpenAIStopReason(reason, options) {
|
|
|
506
560
|
};
|
|
507
561
|
}
|
|
508
562
|
//#endregion
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* OpenAI reasoning-effort compatibility helpers.
|
|
512
|
-
*
|
|
513
|
-
* Keeps provider metadata and built-in model exceptions on one path before request payloads are built.
|
|
514
|
-
*/
|
|
515
|
-
const OPENAI_MEDIUM_ONLY_REASONING_MODEL_IDS = /* @__PURE__ */ new Set(["gpt-5.1-codex-mini"]);
|
|
516
|
-
function readCompatReasoningEffortMap(compat) {
|
|
517
|
-
if (!compat || typeof compat !== "object") return {};
|
|
518
|
-
const rawMap = compat.reasoningEffortMap;
|
|
519
|
-
if (!rawMap || typeof rawMap !== "object") return {};
|
|
520
|
-
return Object.fromEntries(Object.entries(rawMap).filter((entry) => typeof entry[0] === "string" && typeof entry[1] === "string"));
|
|
521
|
-
}
|
|
522
|
-
/** Resolves the reasoning effort remap for an OpenAI-compatible model. */
|
|
523
|
-
function resolveOpenAIReasoningEffortMap(model, fallbackMap = {}) {
|
|
524
|
-
const provider = normalizeLowercaseStringOrEmpty(model.provider ?? "");
|
|
525
|
-
const id = normalizeLowercaseStringOrEmpty(model.id ?? "");
|
|
526
|
-
const builtinMap = provider === "openai" && OPENAI_MEDIUM_ONLY_REASONING_MODEL_IDS.has(id) ? {
|
|
527
|
-
minimal: "medium",
|
|
528
|
-
low: "medium"
|
|
529
|
-
} : {};
|
|
530
|
-
return {
|
|
531
|
-
...fallbackMap,
|
|
532
|
-
...builtinMap,
|
|
533
|
-
...readCompatReasoningEffortMap(model.compat)
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
//#endregion
|
|
537
|
-
export { convertMessages as a, resolveOpenAICompletionsResponseFormat as c, rememberPendingCommentaryTags as d, tagPendingCommentaryText as f, finalizeOpenAICompletionsToolCalls as i, shouldOmitOllamaCompatResponseFormat as l, mapOpenAIStopReason as n, detectOpenAICompletionsCompat as o, createOpenAICompletionsToolCallDeltaNormalizer as r, resolveOpenAICompletionsCompat as s, resolveOpenAIReasoningEffortMap as t, clearPendingCommentaryText as u };
|
|
563
|
+
export { createOpenAICompletionsToolCallDeltaNormalizer as a, resolveOpenAICompletionsCompat as c, clearPendingCommentaryText as d, rememberPendingCommentaryTags as f, hasToolCallHistory as i, resolveOpenAICompletionsResponseFormat as l, resolveOpenAIReasoningEffortMap as n, finalizeOpenAICompletionsToolCalls as o, tagPendingCommentaryText as p, convertMessages as r, detectOpenAICompletionsCompat as s, mapOpenAIStopReason as t, shouldOmitOllamaCompatResponseFormat as u };
|