@openclaw/ai 2026.9.6 → 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.
- package/dist/{anthropic-DZQ_7gD1.mjs → anthropic-Cw2pgccz.mjs} +37 -66
- package/dist/{anthropic-payload-policy-DyfwikYJ.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +7 -5
- package/dist/{anthropic-stream-reducer-D6ZI1wwj.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +192 -261
- package/dist/{api-registry-C2T3lTV7.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
- package/dist/{azure-openai-responses-DS86GYzq.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
- package/dist/{base64-CPmadnUf.mjs → base64-C1PsYcRQ.mjs} +15 -9
- package/dist/{diagnostics-CH8j2wIG.mjs → diagnostics-CJaB6g8J.mjs} +3 -3
- package/dist/diagnostics.d.mts +4 -4
- package/dist/diagnostics.mjs +2 -2
- package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
- package/dist/event-stream-CMQfX_yr.d.mts +1 -0
- package/dist/{event-stream-CjnIZZst.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
- package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-BZJFjhuC.mjs → google-BfapkS_K.mjs} +8 -11
- package/dist/google-interactions-DW3iXzjc.mjs +574 -0
- package/dist/{google-messages-DB7GKkDk.mjs → google-messages-CtjVtVot.mjs} +35 -71
- package/dist/{google-shared-Bok4I6zB.mjs → google-shared-Y2YfotEu.mjs} +43 -47
- package/dist/{google-vertex-3eVNR2qW.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
- package/dist/{host-yTvBrYM2.mjs → host-CHi3X87F.mjs} +29 -188
- package/dist/{host-policy-DZO3oPPk.mjs → host-policy-BOAwRg_M.mjs} +2 -14
- package/dist/{host-DH-Z-LDb.d.mts → host-rxlNaBwm.d.mts} +9 -3
- package/dist/{index-C25RT6bP.d.mts → index-D6KsSE74.d.mts} +28 -8
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +8 -7
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +31 -8
- package/dist/internal/openai.mjs +13 -13
- package/dist/internal/runtime.d.mts +31 -70
- package/dist/internal/runtime.mjs +10 -65
- package/dist/internal/shared.d.mts +14 -12
- package/dist/internal/shared.mjs +5 -4
- package/dist/internal/tool-schema.d.mts +1 -1
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-C_13dVBn.mjs → mistral-RS6mboC-.mjs} +46 -93
- package/dist/{openai-chatgpt-responses-sTxPl4zM.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +26 -30
- package/dist/{openai-completions-BO6D_hrB.mjs → openai-completions-D14ihPYk.mjs} +14 -12
- package/dist/{openai-completions-compat-CUollwl6.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
- package/dist/{openai-completions-compat-DfJG1wSO.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
- package/dist/{openai-completions-stream-BpuJ0ZOA.mjs → openai-completions-stream-CDCuw3DP.mjs} +101 -173
- package/dist/{openai-prompt-cache-C4RHdN4n.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
- package/dist/{openai-prompt-cache-CjV_2IRI.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
- package/dist/{openai-provider-client-BP8J1aeg.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
- package/dist/{openai-reasoning-effort-ash8dPrd.mjs → openai-reasoning-effort-ConhwkeX.mjs} +2 -1
- package/dist/{openai-responses-BJ_IEoMU.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
- package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
- package/dist/{openai-responses-compaction-window-BiNCT0bS.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
- package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
- package/dist/{openai-responses-contracts-B1ENJFpI.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
- package/dist/{openai-responses-prompt-observer-internal-DPHWgbBH.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +12 -12
- package/dist/{openai-responses-request-lifecycle-DFuyO1pQ.mjs → openai-responses-request-lifecycle-Fsag-IGZ.mjs} +1 -1
- package/dist/{openai-responses-shared-DvSqtJ6_.mjs → openai-responses-shared-DL4ulQn7.mjs} +312 -122
- package/dist/{openai-responses-terminal-usage-BNFbvY9f.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
- package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
- package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
- package/dist/{openai-tool-schema-D4BMcj2D.mjs → openai-tool-schema-vsl-cE-n.mjs} +243 -383
- package/dist/{openai-transport-params-DZKOTSfH.mjs → openai-transport-params-BwlpzX-2.mjs} +60 -105
- package/dist/{positive-integer-BiUxrd71.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
- package/dist/{provider-error-CRhW7lkJ.mjs → provider-error-CwT_j2v0.mjs} +43 -4
- package/dist/{provider-options-DZYq53lj.d.mts → provider-options-Df7ov0K1.d.mts} +2 -2
- package/dist/{provider-replay-context-DPr3w20a.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
- package/dist/{provider-transcript-transform-BTocjCRs.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
- package/dist/{provider-transport-turn-state-lrXEFkYr.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
- package/dist/{provider-types-w1rEqrGP.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +15 -11
- package/dist/{reasoning-tag-text-partitioner-Di38crhI.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +47 -71
- package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
- package/dist/simple-options-CGAkCwtM.mjs +349 -0
- package/dist/{src-DwGYYyZp.mjs → src-H4aXcFuX.mjs} +43 -25
- package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
- package/dist/{stream-first-event-timeout-BeptfRL6.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
- package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
- package/dist/{transport-stream-shared-B5RioB_Q.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +62 -28
- package/dist/{transport-stream-shared-B7Z9oCYg.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +12 -6
- package/dist/{transport-utils-03Qi0CN2.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
- package/dist/transports.d.mts +36 -32
- package/dist/transports.mjs +160 -216
- package/dist/types-CB-_vNyI.d.mts +1 -0
- package/dist/{types-qZFbaDbK.d.mts → types-CLLR3eB4.d.mts} +3 -1
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
- package/dist/{validation-DhQhmt6t.d.mts → validation-Cat2wQsc.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/assistant-output-DM1JBNs1.mjs +0 -16
- package/dist/event-stream-C0nsgbj2.d.mts +0 -1
- package/dist/simple-options-np1XPuhm.mjs +0 -175
- package/dist/types-DTvddOfm.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
package/dist/{openai-completions-stream-BpuJ0ZOA.mjs → openai-completions-stream-CDCuw3DP.mjs}
RENAMED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { r as appendAssistantThinking } from "./event-stream-
|
|
2
|
-
import { o as isRecord } from "./record-coerce-
|
|
3
|
-
import {
|
|
1
|
+
import { r as appendAssistantThinking } from "./event-stream-vd9UnCAU.mjs";
|
|
2
|
+
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
3
|
+
import { k as isImageWithMediaPayload, n as getAiTransportHost } from "./host-CHi3X87F.mjs";
|
|
4
|
+
import { n as isOpenAIGpt55Model, r as isOpenAIGpt56Model, t as isOpenAIGpt54MiniModel } from "./openai-reasoning-effort-ConhwkeX.mjs";
|
|
4
5
|
import { r as uniqueStrings } from "./string-normalization-J9ZiLfGO.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { r as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { c as
|
|
11
|
-
import {
|
|
12
|
-
import { i as resolveProviderEndpoint, r as resolveOpenAIStrictToolSetting } from "./host-policy-DZO3oPPk.mjs";
|
|
6
|
+
import { o as truncateUtf16Safe } from "./provider-error-CwT_j2v0.mjs";
|
|
7
|
+
import { r as resolveOpenAIPromptCacheParams } from "./openai-prompt-cache-D2V7MqR7.mjs";
|
|
8
|
+
import { r as emitModelTransportDebug } from "./diagnostics-CJaB6g8J.mjs";
|
|
9
|
+
import { i as asNonNegativeFiniteNumber } from "./base64-C1PsYcRQ.mjs";
|
|
10
|
+
import { c as supportsModelTools, r as estimateStringChars } from "./transport-utils-C-4bf2Ok.mjs";
|
|
11
|
+
import { c as shouldOmitOllamaCompatResponseFormat, n as isNativeOpenAIEndpoint, s as resolveOpenAICompletionsResponseFormat, t as detectOpenAICompletionsCompat } from "./openai-completions-compat-BOVWBZDn.mjs";
|
|
12
|
+
import { r as resolveProviderEndpoint } from "./host-policy-BOAwRg_M.mjs";
|
|
13
13
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { E as
|
|
14
|
+
import { E as createToolArgumentPreviewSchedule, O as parseStreamingJson, d as iterateModelStream, j as sanitizeSurrogates, l as finalizeTerminalToolCallArguments, y as throwIfModelStreamAborted } from "./transport-stream-shared-Dh5qKJ8e.mjs";
|
|
15
|
+
import { C as stripSystemPromptCacheBoundary, D as sortPromptCacheToolsByName, S as splitSystemPromptRelocatableBoundary, d as describeToolResultMediaPlaceholder, m as extractToolResultText, w as stripSystemPromptRelocatableBoundary, x as splitSystemPromptCacheBoundary } from "./simple-options-CGAkCwtM.mjs";
|
|
16
|
+
import { C as log, D as readOpenAICompletionsReasoningBatch, E as readOpenAICompletionsContentDeltas, S as isOpenAICompletionsThinkingEnabled, T as parseOpenAICompletionsUsage, d as prepareOpenAITools, f as projectOpenAITools, g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, k as resolvePromptCacheKey, p as reconcileOpenAICompletionsToolChoice, s as getCompat, u as resolveOpenAIStrictToolFlagWithDiagnostics, v as GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, w as measureUtf8AppendBytes } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
17
17
|
import { a as tagUnresolvedTextAsCommentary, i as tagPendingCommentaryText, n as rememberPendingCommentaryTags, r as tagInterruptedTextPhases, t as clearPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
18
18
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { f as withPreparedToolSchemaNormalization, r as normalizeOpenAIStrictToolParameters } from "./openai-tool-schema-
|
|
19
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-JbFbHV8h.mjs";
|
|
20
|
+
import { a as withFirstStreamEventTimeout } from "./stream-first-event-timeout-B9o0S4SZ.mjs";
|
|
21
|
+
import { f as withPreparedToolSchemaNormalization, r as normalizeOpenAIStrictToolParameters } from "./openai-tool-schema-vsl-cE-n.mjs";
|
|
22
22
|
import { isGoogleGemini3FlashModel, isGoogleGemini3ProModel } from "./internal/google-model-family.mjs";
|
|
23
|
-
import { t as mapOpenAIStopReason } from "./openai-stop-reason-
|
|
24
|
-
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-
|
|
23
|
+
import { t as mapOpenAIStopReason } from "./openai-stop-reason-8s70vDXj.mjs";
|
|
24
|
+
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-B6FIIBt6.mjs";
|
|
25
25
|
import { randomUUID } from "node:crypto";
|
|
26
26
|
//#region packages/ai/src/transports/deepseek-dsml-grammar.ts
|
|
27
27
|
const DEEPSEEK_DSML_MARKERS = [
|
|
@@ -30,6 +30,25 @@ const DEEPSEEK_DSML_MARKERS = [
|
|
|
30
30
|
"||"
|
|
31
31
|
].map((bar) => `${bar}DSML${bar}`);
|
|
32
32
|
const DEEPSEEK_DSML_MARKER_PATTERN = `(${DEEPSEEK_DSML_MARKERS.map((marker) => marker.replaceAll("|", "\\|")).join("|")})`;
|
|
33
|
+
function findEarliestDsmlToken(text, tokens, fromIndex = 0) {
|
|
34
|
+
let best = null;
|
|
35
|
+
for (const token of tokens) {
|
|
36
|
+
const index = text.indexOf(token, fromIndex);
|
|
37
|
+
if (index !== -1 && (!best || index < best.index)) best = {
|
|
38
|
+
index,
|
|
39
|
+
token
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return best;
|
|
43
|
+
}
|
|
44
|
+
function longestDsmlTokenPrefixSuffixLength(text, tokens, maxTokenLength) {
|
|
45
|
+
const maxLength = Math.min(text.length, maxTokenLength - 1);
|
|
46
|
+
for (let length = maxLength; length > 0; length--) {
|
|
47
|
+
const suffix = text.slice(text.length - length);
|
|
48
|
+
if (tokens.some((token) => token.startsWith(suffix))) return length;
|
|
49
|
+
}
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
33
52
|
//#endregion
|
|
34
53
|
//#region packages/ai/src/transports/deepseek-text-filter.ts
|
|
35
54
|
/**
|
|
@@ -67,7 +86,7 @@ function createDeepSeekTextFilter() {
|
|
|
67
86
|
if (final) closeToken = void 0;
|
|
68
87
|
return output;
|
|
69
88
|
}
|
|
70
|
-
const open =
|
|
89
|
+
const open = findEarliestDsmlToken(buffer, DSML_OPEN_TOKENS);
|
|
71
90
|
if (open) {
|
|
72
91
|
emit(buffer.slice(0, open.index));
|
|
73
92
|
buffer = buffer.slice(open.index + open.token.length);
|
|
@@ -79,7 +98,7 @@ function createDeepSeekTextFilter() {
|
|
|
79
98
|
buffer = "";
|
|
80
99
|
return output;
|
|
81
100
|
}
|
|
82
|
-
const keep =
|
|
101
|
+
const keep = longestDsmlTokenPrefixSuffixLength(buffer, DSML_OPEN_TOKENS, MAX_OPEN_TOKEN_LEN);
|
|
83
102
|
const emitLength = buffer.length - keep;
|
|
84
103
|
if (emitLength <= 0) return output;
|
|
85
104
|
emit(buffer.slice(0, emitLength));
|
|
@@ -98,25 +117,6 @@ function createDeepSeekTextFilter() {
|
|
|
98
117
|
}
|
|
99
118
|
};
|
|
100
119
|
}
|
|
101
|
-
function findEarliestToken(text, tokens) {
|
|
102
|
-
let best = null;
|
|
103
|
-
for (const token of tokens) {
|
|
104
|
-
const index = text.indexOf(token);
|
|
105
|
-
if (index !== -1 && (!best || index < best.index)) best = {
|
|
106
|
-
index,
|
|
107
|
-
token
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
return best;
|
|
111
|
-
}
|
|
112
|
-
function longestDsmlOpenPrefixSuffixLength(text) {
|
|
113
|
-
const maxLength = Math.min(text.length, MAX_OPEN_TOKEN_LEN - 1);
|
|
114
|
-
for (let length = maxLength; length > 0; length--) {
|
|
115
|
-
const suffix = text.slice(text.length - length);
|
|
116
|
-
if (DSML_OPEN_TOKENS.some((token) => token.startsWith(suffix))) return length;
|
|
117
|
-
}
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region packages/ai/src/transports/model-max-tokens-params.ts
|
|
122
122
|
/**
|
|
@@ -466,7 +466,7 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
466
466
|
if (model.provider === "openai") return id.length > 40 ? truncateUtf16Safe(id, 40) : id;
|
|
467
467
|
return id;
|
|
468
468
|
};
|
|
469
|
-
const transformedMessages = transformProviderMessages(context.messages, model,
|
|
469
|
+
const transformedMessages = transformProviderMessages(context.messages, model, normalizeToolCallId);
|
|
470
470
|
let relocatableSplit;
|
|
471
471
|
let systemParamIndex;
|
|
472
472
|
if (context.systemPrompt) {
|
|
@@ -493,15 +493,12 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
493
493
|
content: "I have processed the tool results."
|
|
494
494
|
});
|
|
495
495
|
if (msg.role === "user") {
|
|
496
|
-
|
|
497
|
-
if (typeof msg.content === "string") {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
if (isRuntimeContextCarrier) options.cacheOptOutIndexes?.add(params.length);
|
|
503
|
-
params.push(userParam);
|
|
504
|
-
} else {
|
|
496
|
+
let userParam;
|
|
497
|
+
if (typeof msg.content === "string") userParam = {
|
|
498
|
+
role: "user",
|
|
499
|
+
content: sanitizeSurrogates(msg.content)
|
|
500
|
+
};
|
|
501
|
+
else {
|
|
505
502
|
const content = msg.content.map((item) => {
|
|
506
503
|
if (item.type === "text") return {
|
|
507
504
|
type: "text",
|
|
@@ -517,13 +514,13 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
517
514
|
};
|
|
518
515
|
});
|
|
519
516
|
if (content.length === 0) continue;
|
|
520
|
-
|
|
517
|
+
userParam = {
|
|
521
518
|
role: "user",
|
|
522
519
|
content
|
|
523
520
|
};
|
|
524
|
-
if (isRuntimeContextCarrier) options.cacheOptOutIndexes?.add(params.length);
|
|
525
|
-
params.push(userParam);
|
|
526
521
|
}
|
|
522
|
+
if (msg.runtimeContextCarrier === true) options.cacheOptOutIndexes?.add(params.length);
|
|
523
|
+
params.push(userParam);
|
|
527
524
|
} else if (msg.role === "assistant") {
|
|
528
525
|
const assistantMsg = {
|
|
529
526
|
role: "assistant",
|
|
@@ -872,19 +869,18 @@ function resolveOpenAICompletionsModelMaxTokens(model) {
|
|
|
872
869
|
const OPENAI_COMPLETIONS_INPUT_TOKEN_SAFETY_MARGIN = 1.25;
|
|
873
870
|
const OPENAI_COMPLETIONS_IMAGE_CHAR_ESTIMATE = 8e3;
|
|
874
871
|
const MIN_USEFUL_OUTPUT_TOKENS = 16;
|
|
872
|
+
function estimateJsonChars(value, fallback) {
|
|
873
|
+
try {
|
|
874
|
+
return estimateStringChars(JSON.stringify(value));
|
|
875
|
+
} catch {
|
|
876
|
+
return fallback;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
875
879
|
function estimateOpenAICompletionsInputTokens(payload) {
|
|
876
880
|
let adjustedChars = 0;
|
|
877
881
|
adjustedChars += estimateOpenAICompletionsMessagesChars(payload.messages);
|
|
878
|
-
if (Array.isArray(payload.tools) && payload.tools.length > 0)
|
|
879
|
-
|
|
880
|
-
} catch {
|
|
881
|
-
adjustedChars += 1024;
|
|
882
|
-
}
|
|
883
|
-
if (payload.response_format !== void 0) try {
|
|
884
|
-
adjustedChars += estimateStringChars(JSON.stringify(payload.response_format));
|
|
885
|
-
} catch {
|
|
886
|
-
adjustedChars += 256;
|
|
887
|
-
}
|
|
882
|
+
if (Array.isArray(payload.tools) && payload.tools.length > 0) adjustedChars += estimateJsonChars(payload.tools, 1024);
|
|
883
|
+
if (payload.response_format !== void 0) adjustedChars += estimateJsonChars(payload.response_format, 256);
|
|
888
884
|
return Math.ceil(adjustedChars / 4 * OPENAI_COMPLETIONS_INPUT_TOKEN_SAFETY_MARGIN);
|
|
889
885
|
}
|
|
890
886
|
function estimateOpenAICompletionsMessagesChars(messages) {
|
|
@@ -895,11 +891,7 @@ function estimateOpenAICompletionsMessagesChars(messages) {
|
|
|
895
891
|
const record = message;
|
|
896
892
|
adjustedChars += estimateOpenAICompletionsContentChars(record.content);
|
|
897
893
|
for (const field of COMPLETIONS_REASONING_REPLAY_FIELDS) adjustedChars += estimateOpenAICompletionsContentChars(record[field]);
|
|
898
|
-
if (record.tool_calls !== void 0)
|
|
899
|
-
adjustedChars += estimateStringChars(JSON.stringify(record.tool_calls));
|
|
900
|
-
} catch {
|
|
901
|
-
adjustedChars += 256;
|
|
902
|
-
}
|
|
894
|
+
if (record.tool_calls !== void 0) adjustedChars += estimateJsonChars(record.tool_calls, 256);
|
|
903
895
|
}
|
|
904
896
|
return adjustedChars;
|
|
905
897
|
}
|
|
@@ -919,11 +911,7 @@ function estimateOpenAICompletionsContentChars(value) {
|
|
|
919
911
|
adjustedChars += estimateStringChars(text);
|
|
920
912
|
continue;
|
|
921
913
|
}
|
|
922
|
-
|
|
923
|
-
adjustedChars += estimateStringChars(JSON.stringify(block));
|
|
924
|
-
} catch {
|
|
925
|
-
adjustedChars += 256;
|
|
926
|
-
}
|
|
914
|
+
adjustedChars += estimateJsonChars(block, 256);
|
|
927
915
|
}
|
|
928
916
|
return adjustedChars;
|
|
929
917
|
}
|
|
@@ -960,7 +948,7 @@ function convertTools(tools, compat, model, mode) {
|
|
|
960
948
|
const prepared = mode === "managed" ? prepareOpenAITools(tools) : void 0;
|
|
961
949
|
const projection = prepared?.projection ?? projectOpenAITools(tools);
|
|
962
950
|
const convert = () => {
|
|
963
|
-
const strict = mode === "direct" ? compat.supportsStrictMode ? false : void 0 : resolveOpenAIStrictToolFlagWithDiagnostics(projection, resolveOpenAIStrictToolSetting(model, {
|
|
951
|
+
const strict = mode === "direct" ? compat.supportsStrictMode ? false : void 0 : resolveOpenAIStrictToolFlagWithDiagnostics(projection, getAiTransportHost().resolveOpenAIStrictToolSetting(model, {
|
|
964
952
|
transport: "stream",
|
|
965
953
|
supportsStrictMode: compat?.supportsStrictMode
|
|
966
954
|
}), {
|
|
@@ -1061,6 +1049,15 @@ function buildOpenAICompletionsRequest(model, context, options, policy) {
|
|
|
1061
1049
|
const toolChoice = reconcileOpenAICompletionsToolChoice(options.toolChoice, directToolProjection ?? projectOpenAITools([]));
|
|
1062
1050
|
if (toolChoice !== void 0) params.tool_choice = toolChoice;
|
|
1063
1051
|
}
|
|
1052
|
+
const isOpenRouter = compat.thinkingFormat === "openrouter";
|
|
1053
|
+
const usesBinaryOpenRouterThinking = isOpenRouter && (model.compat?.supportsReasoningEffort === false || model.compat?.supportedReasoningEfforts?.length === 0);
|
|
1054
|
+
const simpleReasoning = options?.reasoning;
|
|
1055
|
+
const requestedEffort = policy.mode === "direct" ? options?.reasoningEffort : options?.reasoningEffort ?? (simpleReasoning === "none" ? "none" : resolveOpenAISimpleReasoningEffort({
|
|
1056
|
+
...model,
|
|
1057
|
+
compat: model.compat ?? void 0
|
|
1058
|
+
}, simpleReasoning)) ?? (usesBinaryOpenRouterThinking ? void 0 : "high");
|
|
1059
|
+
const reasoning = resolveOpenAIRequestReasoning(model, requestedEffort);
|
|
1060
|
+
const { effort, thinkingEnabled } = reasoning;
|
|
1064
1061
|
{
|
|
1065
1062
|
const maxTokenBudget = policy.mode === "direct" ? {
|
|
1066
1063
|
maxTokens: options?.maxTokens,
|
|
@@ -1080,7 +1077,10 @@ function buildOpenAICompletionsRequest(model, context, options, policy) {
|
|
|
1080
1077
|
if (clampedMaxTokens > remainingBudget) {
|
|
1081
1078
|
clampedMaxTokens = remainingBudget;
|
|
1082
1079
|
emitModelTransportDebug(log, `[completions] clamp_max_tokens provider=${model.provider} api=${model.api} model=${model.id} requested=${effectiveMaxTokens} output=${clampedMaxTokens} effectiveContext=${effectiveContextTokens} estimatedInput=${estimatedInputTokens}`);
|
|
1083
|
-
if (remainingBudget < MIN_USEFUL_OUTPUT_TOKENS)
|
|
1080
|
+
if (remainingBudget < MIN_USEFUL_OUTPUT_TOKENS) {
|
|
1081
|
+
if (model.reasoning && thinkingEnabled !== false) throw Object.assign(/* @__PURE__ */ new Error(`Context window exceeded: estimated input ${estimatedInputTokens} leaves only ${remainingBudget} output tokens within the ${effectiveContextTokens}-token context.`), { code: "context_length_exceeded" });
|
|
1082
|
+
log.warn(`[completions] insufficient_output_budget provider=${model.provider} api=${model.api} model=${model.id} output=${clampedMaxTokens} effectiveContext=${effectiveContextTokens} estimatedInput=${estimatedInputTokens}`);
|
|
1083
|
+
}
|
|
1084
1084
|
}
|
|
1085
1085
|
}
|
|
1086
1086
|
if (policy.mode === "direct" ? options?.maxTokens : clampedMaxTokens) {
|
|
@@ -1088,15 +1088,6 @@ function buildOpenAICompletionsRequest(model, context, options, policy) {
|
|
|
1088
1088
|
else params.max_completion_tokens = clampedMaxTokens;
|
|
1089
1089
|
}
|
|
1090
1090
|
}
|
|
1091
|
-
const isOpenRouter = compat.thinkingFormat === "openrouter";
|
|
1092
|
-
const usesBinaryOpenRouterThinking = isOpenRouter && (model.compat?.supportsReasoningEffort === false || model.compat?.supportedReasoningEfforts?.length === 0);
|
|
1093
|
-
const simpleReasoning = options?.reasoning;
|
|
1094
|
-
const requestedEffort = policy.mode === "direct" ? options?.reasoningEffort : options?.reasoningEffort ?? (simpleReasoning === "none" ? "none" : resolveOpenAISimpleReasoningEffort({
|
|
1095
|
-
...model,
|
|
1096
|
-
compat: model.compat ?? void 0
|
|
1097
|
-
}, simpleReasoning)) ?? (usesBinaryOpenRouterThinking ? void 0 : "high");
|
|
1098
|
-
const reasoning = resolveOpenAIRequestReasoning(model, requestedEffort);
|
|
1099
|
-
const { effort, thinkingEnabled } = reasoning;
|
|
1100
1091
|
if (isOpenRouter && model.reasoning) {
|
|
1101
1092
|
if (usesBinaryOpenRouterThinking && thinkingEnabled !== void 0) params.reasoning = { enabled: thinkingEnabled };
|
|
1102
1093
|
else if (effort !== void 0) params.reasoning = { effort };
|
|
@@ -1132,6 +1123,7 @@ const DEEPSEEK_DSML_TOOL_MAX_OPEN_TOKEN_LEN = Math.max(...DEEPSEEK_DSML_TOOL_OPE
|
|
|
1132
1123
|
const DEEPSEEK_DSML_RECOVERY_MAX_BOUNDARY_LEN = Math.max(...DEEPSEEK_DSML_TOOL_OPEN_TOKENS.map((token) => token.length + 1), ...DEEPSEEK_DSML_INVOKE_OPEN_PREFIXES.map((token) => token.length + 2));
|
|
1133
1124
|
const MAX_DSML_RECOVERY_BUFFER_BYTES = 256e3;
|
|
1134
1125
|
const DEEPSEEK_DSML_SCAN_BATCH_CHARS = 65536;
|
|
1126
|
+
const DSML_NAME_ATTRIBUTE_RE = /\bname=("([^"]*)"|'([^']*)'|([^\s>]+))/;
|
|
1135
1127
|
function createDsmlRecoverer() {
|
|
1136
1128
|
let buffer = "";
|
|
1137
1129
|
let bufferBytes = 0;
|
|
@@ -1150,7 +1142,7 @@ function createDsmlRecoverer() {
|
|
|
1150
1142
|
const open = activeOpenToken ? {
|
|
1151
1143
|
index: 0,
|
|
1152
1144
|
token: activeOpenToken
|
|
1153
|
-
} :
|
|
1145
|
+
} : findEarliestDsmlToken(buffer, DEEPSEEK_DSML_TOOL_OPEN_TOKENS);
|
|
1154
1146
|
if (!open) {
|
|
1155
1147
|
resetBlockScan();
|
|
1156
1148
|
if (final) {
|
|
@@ -1163,7 +1155,7 @@ function createDsmlRecoverer() {
|
|
|
1163
1155
|
bufferEndsWithHighSurrogate = false;
|
|
1164
1156
|
return output;
|
|
1165
1157
|
}
|
|
1166
|
-
const keep =
|
|
1158
|
+
const keep = longestDsmlTokenPrefixSuffixLength(buffer, DEEPSEEK_DSML_TOOL_OPEN_TOKENS, DEEPSEEK_DSML_TOOL_MAX_OPEN_TOKEN_LEN);
|
|
1167
1159
|
const emitLength = buffer.length - keep;
|
|
1168
1160
|
if (emitLength > 0) {
|
|
1169
1161
|
const emitted = buffer.slice(0, emitLength);
|
|
@@ -1249,7 +1241,7 @@ function parseDeepSeekDsmlToolCallBlock(body) {
|
|
|
1249
1241
|
if (invokeCloseIndex === -1) break;
|
|
1250
1242
|
const invokeBody = body.slice(invokeBodyStart, invokeCloseIndex);
|
|
1251
1243
|
invokeOpenRegex.lastIndex = invokeCloseIndex + invokeCloseToken.length;
|
|
1252
|
-
const invokeName =
|
|
1244
|
+
const invokeName = parseDsmlNameAttribute(openMatch[2] ?? "");
|
|
1253
1245
|
if (!invokeName) continue;
|
|
1254
1246
|
const parsedArguments = parseDeepSeekDsmlInvokeArguments(invokeBody);
|
|
1255
1247
|
if (!parsedArguments) continue;
|
|
@@ -1267,7 +1259,7 @@ function parseDeepSeekDsmlInvokeArguments(body) {
|
|
|
1267
1259
|
const parameterRegex = new RegExp(`<${DEEPSEEK_DSML_MARKER_PATTERN}parameter\\b([^>]*)>([\\s\\S]*?)</\\1parameter>`, "g");
|
|
1268
1260
|
let parameterMatch;
|
|
1269
1261
|
while ((parameterMatch = parameterRegex.exec(body)) !== null) {
|
|
1270
|
-
const name =
|
|
1262
|
+
const name = parseDsmlNameAttribute(parameterMatch[2] ?? "");
|
|
1271
1263
|
if (!name) continue;
|
|
1272
1264
|
const rawValue = parameterMatch[3] ?? "";
|
|
1273
1265
|
if (rawValue.length === 0) continue;
|
|
@@ -1284,34 +1276,14 @@ function parseDeepSeekDsmlInvokeArguments(body) {
|
|
|
1284
1276
|
}
|
|
1285
1277
|
return null;
|
|
1286
1278
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
const cached = xmlAttributeRegexCache.get(name);
|
|
1290
|
-
if (cached) return cached;
|
|
1291
|
-
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1292
|
-
const pattern = new RegExp(`\\b${escaped}=("([^"]*)"|'([^']*)'|([^\\s>]+))`);
|
|
1293
|
-
xmlAttributeRegexCache.set(name, pattern);
|
|
1294
|
-
return pattern;
|
|
1295
|
-
}
|
|
1296
|
-
function parseXmlAttribute(attributes, name) {
|
|
1297
|
-
const match = xmlAttributeRegex(name).exec(attributes);
|
|
1279
|
+
function parseDsmlNameAttribute(attributes) {
|
|
1280
|
+
const match = DSML_NAME_ATTRIBUTE_RE.exec(attributes);
|
|
1298
1281
|
const value = match?.[2] ?? match?.[3] ?? match?.[4];
|
|
1299
1282
|
return value ? decodeDeepSeekDsmlText(value) : null;
|
|
1300
1283
|
}
|
|
1301
1284
|
function decodeDeepSeekDsmlText(value) {
|
|
1302
1285
|
return value.replaceAll(""", "\"").replaceAll("'", "'").replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&");
|
|
1303
1286
|
}
|
|
1304
|
-
function findEarliestStringToken(text, tokens, fromIndex = 0) {
|
|
1305
|
-
let best = null;
|
|
1306
|
-
for (const token of tokens) {
|
|
1307
|
-
const index = text.indexOf(token, fromIndex);
|
|
1308
|
-
if (index !== -1 && (!best || index < best.index)) best = {
|
|
1309
|
-
index,
|
|
1310
|
-
token
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
return best;
|
|
1314
|
-
}
|
|
1315
1287
|
function scanDeepSeekDsmlToolBlock(text, closeToken, contentStartIndex, state) {
|
|
1316
1288
|
while (state.offset < text.length) {
|
|
1317
1289
|
if (state.invoke?.kind === "open") {
|
|
@@ -1350,9 +1322,9 @@ function scanDeepSeekDsmlToolBlock(text, closeToken, contentStartIndex, state) {
|
|
|
1350
1322
|
state.invoke = void 0;
|
|
1351
1323
|
continue;
|
|
1352
1324
|
}
|
|
1353
|
-
const toolOpen =
|
|
1325
|
+
const toolOpen = findEarliestDsmlToken(text, DEEPSEEK_DSML_TOOL_OPEN_TOKENS, state.offset);
|
|
1354
1326
|
const toolCloseIndex = text.indexOf(closeToken, state.offset);
|
|
1355
|
-
const invokeOpen =
|
|
1327
|
+
const invokeOpen = findEarliestDsmlToken(text, DEEPSEEK_DSML_INVOKE_OPEN_PREFIXES, state.offset);
|
|
1356
1328
|
const next = [
|
|
1357
1329
|
toolOpen ? {
|
|
1358
1330
|
kind: "nested-open",
|
|
@@ -1384,14 +1356,6 @@ function scanDeepSeekDsmlToolBlock(text, closeToken, contentStartIndex, state) {
|
|
|
1384
1356
|
}
|
|
1385
1357
|
return { kind: "incomplete" };
|
|
1386
1358
|
}
|
|
1387
|
-
function longestDeepSeekDsmlToolOpenPrefixSuffixLength(text) {
|
|
1388
|
-
const maxLength = Math.min(text.length, DEEPSEEK_DSML_TOOL_MAX_OPEN_TOKEN_LEN - 1);
|
|
1389
|
-
for (let length = maxLength; length > 0; length -= 1) {
|
|
1390
|
-
const suffix = text.slice(text.length - length);
|
|
1391
|
-
if (DEEPSEEK_DSML_TOOL_OPEN_TOKENS.some((token) => token.startsWith(suffix))) return length;
|
|
1392
|
-
}
|
|
1393
|
-
return 0;
|
|
1394
|
-
}
|
|
1395
1359
|
//#endregion
|
|
1396
1360
|
//#region packages/ai/src/transports/openai-completions-stream.ts
|
|
1397
1361
|
function extractToolCallThoughtSignature(toolCall) {
|
|
@@ -1436,29 +1400,20 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1436
1400
|
let finishReason;
|
|
1437
1401
|
let sawNativeToolCallDelta = false;
|
|
1438
1402
|
const blockIndex = () => directMode && currentBlock && currentBlock.type !== "toolCall" ? contentBlockIndices.get(currentBlock) ?? output.content.length - 1 : output.content.length - 1;
|
|
1439
|
-
const measureUtf8Bytes = (text) => Buffer.byteLength(text, "utf8");
|
|
1440
1403
|
let chunkPushedEvent = false;
|
|
1441
1404
|
const pushStreamEvent = (event) => {
|
|
1442
1405
|
chunkPushedEvent = true;
|
|
1443
1406
|
stream.push(event);
|
|
1444
1407
|
};
|
|
1445
1408
|
const queuePostToolCallDelta = (next) => {
|
|
1446
|
-
const nextBytes =
|
|
1409
|
+
const nextBytes = Buffer.byteLength(next.text, "utf8");
|
|
1447
1410
|
if (pendingPostToolCallBytes + nextBytes > MAX_POST_TOOL_CALL_BUFFER_BYTES) throw new Error("Exceeded post-tool-call delta buffer limit");
|
|
1448
1411
|
pendingPostToolCallBytes += nextBytes;
|
|
1449
1412
|
const previous = pendingPostToolCallDeltas[pendingPostToolCallDeltas.length - 1];
|
|
1450
|
-
if (!previous || previous.kind !== next.kind || previous.kind === "text" && next.kind === "text" && previous.source !== next.source) {
|
|
1413
|
+
if (!previous || previous.kind !== next.kind || previous.kind === "text" && next.kind === "text" && previous.source !== next.source || previous.kind === "thinking" && next.kind === "thinking" && previous.signature !== next.signature) {
|
|
1451
1414
|
pendingPostToolCallDeltas.push(next);
|
|
1452
1415
|
return;
|
|
1453
1416
|
}
|
|
1454
|
-
if (next.kind === "thinking" && previous.kind === "thinking") {
|
|
1455
|
-
if (previous.signature !== next.signature) {
|
|
1456
|
-
pendingPostToolCallDeltas.push(next);
|
|
1457
|
-
return;
|
|
1458
|
-
}
|
|
1459
|
-
previous.text += next.text;
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
1417
|
previous.text += next.text;
|
|
1463
1418
|
};
|
|
1464
1419
|
const appendThinkingDeltaInternal = (reasoningDelta) => {
|
|
@@ -1595,11 +1550,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1595
1550
|
partial: output
|
|
1596
1551
|
});
|
|
1597
1552
|
};
|
|
1598
|
-
const
|
|
1599
|
-
const recoveredParts = deepSeekToolCallRecoverer?.push(text) ?? [{
|
|
1600
|
-
kind: "text",
|
|
1601
|
-
text
|
|
1602
|
-
}];
|
|
1553
|
+
const appendRecoveredParts = (recoveredParts) => {
|
|
1603
1554
|
for (const recoveredPart of recoveredParts) {
|
|
1604
1555
|
if (recoveredPart.kind === "toolCall") {
|
|
1605
1556
|
appendRecoveredToolCall(recoveredPart);
|
|
@@ -1609,31 +1560,11 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1609
1560
|
for (const part of parts) appendVisibleTextDelta(part);
|
|
1610
1561
|
}
|
|
1611
1562
|
};
|
|
1612
|
-
const
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
appendRecoveredToolCall(recoveredPart);
|
|
1618
|
-
continue;
|
|
1619
|
-
}
|
|
1620
|
-
const parts = deepSeekTextFilter?.push(recoveredPart.text) ?? [recoveredPart.text];
|
|
1621
|
-
for (const part of parts) appendVisibleTextDelta(part);
|
|
1622
|
-
}
|
|
1623
|
-
};
|
|
1624
|
-
const flushDeepSeekTextFilterAtEnd = () => {
|
|
1625
|
-
const parts = deepSeekTextFilter?.flush();
|
|
1626
|
-
if (!parts) return;
|
|
1627
|
-
for (const part of parts) appendVisibleTextDelta(part);
|
|
1628
|
-
};
|
|
1629
|
-
const appendRoutedContentDelta = (delta) => {
|
|
1630
|
-
if (delta.kind === "text") {
|
|
1631
|
-
appendFilteredVisibleTextDelta(delta.text);
|
|
1632
|
-
return;
|
|
1633
|
-
}
|
|
1634
|
-
if (!emitReasoning) return;
|
|
1635
|
-
if (currentBlock?.type === "toolCall" && !directMode) queuePostToolCallDelta(delta);
|
|
1636
|
-
else appendThinkingDelta(delta);
|
|
1563
|
+
const appendFilteredVisibleTextDelta = (text) => {
|
|
1564
|
+
appendRecoveredParts(deepSeekToolCallRecoverer?.push(text) ?? [{
|
|
1565
|
+
kind: "text",
|
|
1566
|
+
text
|
|
1567
|
+
}]);
|
|
1637
1568
|
};
|
|
1638
1569
|
const appendPartitionedVisibleDelta = (delta) => {
|
|
1639
1570
|
if (delta.kind === "text") appendFilteredVisibleTextDelta(delta.text);
|
|
@@ -1665,7 +1596,6 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1665
1596
|
if (forceStrict || reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
|
|
1666
1597
|
if (!hasFollowingVisibleText || !reasoningTagTextPartitioner.hasPendingSyntax()) sealTextBeforeReasoning();
|
|
1667
1598
|
};
|
|
1668
|
-
const cooperativeScheduler = directMode ? void 0 : createModelStreamCooperativeScheduler(options?.signal);
|
|
1669
1599
|
const guardedStream = withFirstStreamEventTimeout(responseStream, {
|
|
1670
1600
|
provider: model.provider,
|
|
1671
1601
|
api: model.api,
|
|
@@ -1676,13 +1606,11 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1676
1606
|
onTimeout: options?.onFirstEventTimeout,
|
|
1677
1607
|
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."
|
|
1678
1608
|
});
|
|
1679
|
-
|
|
1609
|
+
const events = directMode ? guardedStream : iterateModelStream(guardedStream, options?.signal);
|
|
1610
|
+
for await (const rawChunk of events) {
|
|
1680
1611
|
throwIfModelStreamAborted(options?.signal);
|
|
1681
1612
|
chunkPushedEvent = false;
|
|
1682
|
-
if (!rawChunk || typeof rawChunk !== "object")
|
|
1683
|
-
if (cooperativeScheduler) await cooperativeScheduler.afterEvent();
|
|
1684
|
-
continue;
|
|
1685
|
-
}
|
|
1613
|
+
if (!rawChunk || typeof rawChunk !== "object") continue;
|
|
1686
1614
|
notifyLlmRequestActivity(options?.signal);
|
|
1687
1615
|
const chunk = rawChunk;
|
|
1688
1616
|
output.responseId ||= chunk.id;
|
|
@@ -1695,7 +1623,6 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1695
1623
|
const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
|
|
1696
1624
|
if (!choice) {
|
|
1697
1625
|
emitReasoningUsageActivity(hasReasoningUsageActivity);
|
|
1698
|
-
if (cooperativeScheduler) await cooperativeScheduler.afterEvent();
|
|
1699
1626
|
continue;
|
|
1700
1627
|
}
|
|
1701
1628
|
const choiceUsage = choice.usage;
|
|
@@ -1712,7 +1639,6 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1712
1639
|
const rawChoiceDelta = choice.delta ?? choice.message;
|
|
1713
1640
|
if (!rawChoiceDelta) {
|
|
1714
1641
|
emitReasoningUsageActivity(hasReasoningUsageActivity);
|
|
1715
|
-
if (cooperativeScheduler) await cooperativeScheduler.afterEvent();
|
|
1716
1642
|
continue;
|
|
1717
1643
|
}
|
|
1718
1644
|
for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
|
|
@@ -1733,7 +1659,10 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1733
1659
|
for (const routedDelta of routedDeltas) appendPartitionedVisibleDelta(routedDelta);
|
|
1734
1660
|
} else {
|
|
1735
1661
|
beginReasoning(contentDeltaIndex < lastVisibleTextIndex);
|
|
1736
|
-
|
|
1662
|
+
if (emitReasoning) {
|
|
1663
|
+
if (currentBlock?.type === "toolCall" && !directMode) queuePostToolCallDelta(contentDelta);
|
|
1664
|
+
else appendThinkingDelta(contentDelta);
|
|
1665
|
+
}
|
|
1737
1666
|
}
|
|
1738
1667
|
if (!hasReasoningThinking) appendReasoningDeltas(reasoningDeltas);
|
|
1739
1668
|
const toolCallDeltas = normalizedDelta.toolCalls;
|
|
@@ -1800,13 +1729,12 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
1800
1729
|
}
|
|
1801
1730
|
flushPendingPostToolCallDeltas();
|
|
1802
1731
|
emitReasoningUsageActivity(hasReasoningUsageActivity);
|
|
1803
|
-
if (cooperativeScheduler) await cooperativeScheduler.afterEvent();
|
|
1804
1732
|
}
|
|
1805
1733
|
throwIfModelStreamAborted(options?.signal);
|
|
1806
1734
|
if (!finishReason && (directMode || options?.sawStreamDONE?.() === false)) throw new Error("Stream ended without finish_reason");
|
|
1807
1735
|
flushReasoningTagTextPartitioner();
|
|
1808
|
-
|
|
1809
|
-
|
|
1736
|
+
appendRecoveredParts(deepSeekToolCallRecoverer?.flush() ?? []);
|
|
1737
|
+
for (const part of deepSeekTextFilter?.flush() ?? []) appendVisibleTextDelta(part);
|
|
1810
1738
|
currentBlock = null;
|
|
1811
1739
|
flushPendingPostToolCallDeltas();
|
|
1812
1740
|
finalizeOpenAICompletionsToolCalls(output, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as OpenAICompletionsCompat, O as Model, l as CacheRetention } from "./types-
|
|
2
|
-
import "./types-
|
|
1
|
+
import { M as OpenAICompletionsCompat, O as Model, l as CacheRetention } from "./types-CLLR3eB4.mjs";
|
|
2
|
+
import "./types-CB-_vNyI.mjs";
|
|
3
3
|
//#region packages/ai/src/providers/openai-prompt-cache.d.ts
|
|
4
4
|
/** Selects documented lifetime fields shared by Responses and Chat Completions. */
|
|
5
5
|
declare function resolveOpenAIPromptCacheParams(model: Pick<Model, "id" | "provider" | "baseUrl">, cacheRetention: CacheRetention, compat: Required<Pick<OpenAICompletionsCompat, "supportsPromptCacheKey" | "supportsLongCacheRetention">>): {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as isNativeOpenAIEndpoint } from "./openai-completions-compat-
|
|
1
|
+
import { n as isNativeOpenAIEndpoint } from "./openai-completions-compat-BOVWBZDn.mjs";
|
|
2
2
|
//#region packages/normalization-core/src/code-points.ts
|
|
3
3
|
/** Truncates to a nonnegative code-point budget; grapheme clusters may be split. */
|
|
4
4
|
function truncateCodePoints(text, maxCodePoints) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
-
import {
|
|
1
|
+
import { n as getAiTransportHost } from "./host-CHi3X87F.mjs";
|
|
2
|
+
import { O as resolveOpenAIClientBaseUrl } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
3
3
|
import { i as resolveCloudflareBaseUrl, r as isCloudflareProvider } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
4
4
|
import OpenAI from "openai";
|
|
5
5
|
//#region packages/ai/src/providers/openai-provider-client.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { i as asOptionalRecord } from "./record-coerce-CNDovvft.mjs";
|
|
1
2
|
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import { i as asOptionalRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
3
3
|
import { n as normalizeUniqueTrimmedStringList } from "./string-normalization-J9ZiLfGO.mjs";
|
|
4
4
|
//#region packages/llm-core/src/model-data.ts
|
|
5
5
|
const MODEL_DATA_APIS = [
|
|
@@ -8,6 +8,7 @@ const MODEL_DATA_APIS = [
|
|
|
8
8
|
"openai-chatgpt-responses",
|
|
9
9
|
"anthropic-messages",
|
|
10
10
|
"google-generative-ai",
|
|
11
|
+
"google-interactions",
|
|
11
12
|
"google-vertex",
|
|
12
13
|
"github-copilot",
|
|
13
14
|
"bedrock-converse-stream",
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey, r as resolveOpenAIPromptCacheParams } from "./openai-prompt-cache-
|
|
4
|
-
import { i as resolveOpenAICompletionsCompat } from "./openai-completions-compat-
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-vd9UnCAU.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey, r as resolveOpenAIPromptCacheParams } from "./openai-prompt-cache-D2V7MqR7.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 } from "./simple-options-
|
|
7
|
-
import { g as resolveOpenAISimpleReasoningEffort } from "./openai-transport-params-
|
|
8
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
9
|
-
import { n as
|
|
10
|
-
import {
|
|
6
|
+
import { n as buildBaseOptions } from "./simple-options-CGAkCwtM.mjs";
|
|
7
|
+
import { g as resolveOpenAISimpleReasoningEffort } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
8
|
+
import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
|
|
9
|
+
import { n as createAssistantOutput } from "./provider-transcript-transform-JbFbHV8h.mjs";
|
|
10
|
+
import { n as resolveProviderSimpleCompletionHeaders } from "./provider-transport-turn-state-BheUi_hl.mjs";
|
|
11
|
+
import { P as convertProviderResponsesMessages, n as applyResponsesServiceTierPricing, r as runResponsesStreamLifecycle, t as applyCommonResponsesParams } from "./openai-responses-shared-DL4ulQn7.mjs";
|
|
11
12
|
import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
12
|
-
import { t as createOpenAIProviderClient } from "./openai-provider-client-
|
|
13
|
+
import { t as createOpenAIProviderClient } from "./openai-provider-client-CwfsGBbA.mjs";
|
|
13
14
|
//#region packages/ai/src/providers/openai-responses.ts
|
|
14
15
|
var openai_responses_exports = /* @__PURE__ */ __exportAll({
|
|
15
16
|
streamOpenAIResponses: () => streamOpenAIResponses,
|
|
@@ -24,7 +25,7 @@ function getCompat(model) {
|
|
|
24
25
|
}
|
|
25
26
|
const streamOpenAIResponses = (model, context, options) => {
|
|
26
27
|
const stream = new AssistantMessageEventStream();
|
|
27
|
-
const output =
|
|
28
|
+
const output = createAssistantOutput(model);
|
|
28
29
|
runResponsesStreamLifecycle({
|
|
29
30
|
stream,
|
|
30
31
|
model,
|
|
@@ -74,7 +75,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
|
74
75
|
return createOpenAIProviderClient(model, apiKey, headers, optionsHeaders);
|
|
75
76
|
}
|
|
76
77
|
function buildParams(model, context, options, replayMode = "checkpoint") {
|
|
77
|
-
const messages =
|
|
78
|
+
const messages = convertProviderResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
|
|
78
79
|
replayResponsesItemIds: options?.replayResponsesItemIds ?? false,
|
|
79
80
|
sessionId: options?.sessionId,
|
|
80
81
|
authProfileId: options?.authProfileId,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./index-D6KsSE74.mjs";
|
|
2
|
+
import { O as Model, a as AssistantMessage } from "./types-CLLR3eB4.mjs";
|
|
3
|
+
import "./provider-options-Df7ov0K1.mjs";
|
|
4
|
+
import { i as ReplayableResponseCompactionItem, r as OpenAIResponsesReasoningReplayMetadata, s as OpenAIResponsesCompactionOutput } from "./openai-responses-contracts-D1iZ0njF.mjs";
|
|
5
|
+
import "openai/resources/responses/responses.js";
|
|
6
|
+
//#region packages/ai/src/transports/openai-responses-compaction-replay.d.ts
|
|
7
|
+
declare function captureOpenAIResponsesCompaction(output: Pick<AssistantMessage, "providerReplay">, item: ReplayableResponseCompactionItem, boundary: number | "retained-users", model: Model, captureMetadata?: OpenAIResponsesReasoningReplayMetadata, compactedOutput?: OpenAIResponsesCompactionOutput): void;
|
|
8
|
+
declare class CompactionReplayRefreshRequiredError extends Error {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { captureOpenAIResponsesCompaction as n, CompactionReplayRefreshRequiredError as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
1
2
|
import { i as normalizeOptionalLowercaseString, n as normalizeLowercaseStringOrEmpty, s as readStringValue } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
6
|
-
import { i as OPENAI_RESPONSES_APIS } from "./openai-responses-contracts-DWrfMODE.mjs";
|
|
3
|
+
import { u as supportsOpenAIReasoningEffort } from "./openai-reasoning-effort-ConhwkeX.mjs";
|
|
4
|
+
import { t as canonicalizeBase64 } from "./base64-C1PsYcRQ.mjs";
|
|
5
|
+
import { t as parsePositiveInteger } from "./positive-integer-CjN5OJbH.mjs";
|
|
6
|
+
import { i as OPENAI_RESPONSES_APIS } from "./openai-responses-contracts-CLxnqS9p.mjs";
|
|
7
7
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
8
8
|
//#region packages/model-catalog-core/src/provider-id.ts
|
|
9
9
|
function normalizeProviderId(provider) {
|