@openclaw/ai 2026.9.6 → 2026.9.8
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-CTXJlfnS.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-DrsBCsFY.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-BBxv4QVI.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-B3HEK0Ag.mjs} +8 -11
- package/dist/google-interactions-vMlEfPAA.mjs +574 -0
- package/dist/{google-messages-DB7GKkDk.mjs → google-messages-Dz2dAnGo.mjs} +35 -71
- package/dist/{google-shared-Bok4I6zB.mjs → google-shared-B58i3c8H.mjs} +43 -47
- package/dist/{google-vertex-3eVNR2qW.mjs → google-vertex-DYFXzEbh.mjs} +16 -30
- package/dist/{host-yTvBrYM2.mjs → host-DwBmNMCC.mjs} +29 -188
- package/dist/{host-policy-DZO3oPPk.mjs → host-policy-wK-ay_RK.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-7wDWcjfF.mjs} +46 -93
- package/dist/{openai-chatgpt-responses-sTxPl4zM.mjs → openai-chatgpt-responses-Bc7NZrQR.mjs} +26 -30
- package/dist/{openai-completions-BO6D_hrB.mjs → openai-completions-CHnwIV-W.mjs} +14 -12
- package/dist/{openai-completions-compat-CUollwl6.mjs → openai-completions-compat-BJf57ZxN.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-dju_5F3P.mjs} +101 -173
- package/dist/{openai-prompt-cache-CjV_2IRI.mjs → openai-prompt-cache-BTMs80_O.mjs} +1 -1
- package/dist/{openai-prompt-cache-C4RHdN4n.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
- package/dist/{openai-provider-client-BP8J1aeg.mjs → openai-provider-client-G8Otsq2Q.mjs} +2 -2
- package/dist/{openai-reasoning-effort-ash8dPrd.mjs → openai-reasoning-effort-C_0p3psG.mjs} +5 -4
- package/dist/{openai-responses-BJ_IEoMU.mjs → openai-responses-DbPe3-Py.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-CYGCjAQz.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-BX3QTNSv.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-CIEHiKx7.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-DyFJ4cgR.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-Bs5aWE1d.mjs} +1 -1
- package/dist/{provider-transcript-transform-BTocjCRs.mjs → provider-transcript-transform-DjA5Fk2P.mjs} +17 -2
- package/dist/{provider-transport-turn-state-lrXEFkYr.mjs → provider-transport-turn-state-Dw7OtYUs.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-BkDPMuxw.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-BU5pwY6W.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-CqXzku3R.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/{anthropic-stream-reducer-D6ZI1wwj.mjs → anthropic-stream-reducer-DrsBCsFY.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { S as supportsClaudeNativeXhighEffort,
|
|
2
|
-
import { r as appendAssistantThinking } from "./event-stream-
|
|
1
|
+
import { S as supportsClaudeAdaptiveThinking, T as supportsClaudeNativeXhighEffort, _ as resolveClaudeOpus55ModelIdentity, l as bindsClaudeThinkingPrefix, m as resolveClaudeModelIdentity, p as resolveClaudeFable5ModelIdentity, u as requiresClaudeBetweenToolsThinking, v as resolveClaudeOpus5ModelIdentity, y as resolveClaudeSonnet55ModelIdentity } from "./src-H4aXcFuX.mjs";
|
|
2
|
+
import { r as appendAssistantThinking } from "./event-stream-vd9UnCAU.mjs";
|
|
3
|
+
import { a as asRecord, o as isRecord, r as asOptionalObjectRecord, s as readStringField } from "./record-coerce-CNDovvft.mjs";
|
|
4
|
+
import { _ as requiresClaudeAdaptiveThinking, d as ANTHROPIC_CLAUDE_CODE_VERSION, h as mapAnthropicStopReason, k as isImageWithMediaPayload, n as getAiTransportHost, v as resolveAnthropicThinkingEffort, w as calculateCost } from "./host-DwBmNMCC.mjs";
|
|
3
5
|
import { i as normalizeOptionalLowercaseString, r as normalizeNullableString } from "./string-coerce-fsri9iCu.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { i as
|
|
7
|
-
import "./transport-utils-03Qi0CN2.mjs";
|
|
8
|
-
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-DZO3oPPk.mjs";
|
|
6
|
+
import { i as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-C1PsYcRQ.mjs";
|
|
7
|
+
import "./transport-utils-CqXzku3R.mjs";
|
|
8
|
+
import { i as resolveProviderRequestCapabilities, r as resolveProviderEndpoint } from "./host-policy-wK-ay_RK.mjs";
|
|
9
9
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-
|
|
10
|
+
import { C as parseJsonObjectPreservingUnsafeIntegers, E as createToolArgumentPreviewSchedule, O as parseStreamingJson, _ as sanitizeNonEmptyTransportPayloadText, b as transportAbortError, d as iterateModelStream, j as sanitizeSurrogates, l as finalizeTerminalToolCallArguments, r as coerceTransportToolCallArguments, v as sanitizeTransportPayloadText } from "./transport-stream-shared-BU5pwY6W.mjs";
|
|
11
|
+
import { C as stripSystemPromptCacheBoundary, D as sortPromptCacheToolsByName, d as describeToolResultMediaPlaceholder, m as extractToolResultText, p as extractToolResultBlockText, w as stripSystemPromptRelocatableBoundary, x as splitSystemPromptCacheBoundary } from "./simple-options-BkDPMuxw.mjs";
|
|
12
|
+
import { t as parsePositiveInteger } from "./positive-integer-CjN5OJbH.mjs";
|
|
13
|
+
import { i as SCHEMA_MAP_KEYS, n as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-Ct8SeBeJ.mjs";
|
|
14
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-Bs5aWE1d.mjs";
|
|
15
15
|
import { i as tagPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
16
16
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
17
17
|
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
@@ -37,12 +37,90 @@ function omitFoundryBearerCredentialHeaders(headers) {
|
|
|
37
37
|
return Object.keys(next).length > 0 ? next : void 0;
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region packages/ai/src/
|
|
40
|
+
//#region packages/ai/src/providers/anthropic-server-fallback.ts
|
|
41
|
+
/** Anthropic beta that re-serves safety refusals on an allowed fallback model. */
|
|
42
|
+
const ANTHROPIC_SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
43
|
+
/** Let Anthropic select the recommended model for each refusal category. */
|
|
44
|
+
const ANTHROPIC_SERVER_SIDE_FALLBACKS = "default";
|
|
45
|
+
const CLAUDE_OPUS_FALLBACK_MODEL_COST = {
|
|
46
|
+
input: 5,
|
|
47
|
+
output: 25,
|
|
48
|
+
cacheRead: .5,
|
|
49
|
+
cacheWrite: 6.25
|
|
50
|
+
};
|
|
51
|
+
const CLAUDE_OPUS_55_FALLBACK_MODEL_COST = {
|
|
52
|
+
input: 4,
|
|
53
|
+
output: 20,
|
|
54
|
+
cacheRead: .2,
|
|
55
|
+
cacheWrite: 5
|
|
56
|
+
};
|
|
57
|
+
function resolveFallbackModelIdentity(modelId) {
|
|
58
|
+
if (!modelId?.trim()) return null;
|
|
59
|
+
const ref = { id: modelId };
|
|
60
|
+
const normalized = resolveClaudeModelIdentity(ref);
|
|
61
|
+
if (resolveClaudeOpus55ModelIdentity(ref)) return "claude-opus-5-5";
|
|
62
|
+
if (normalized === "opus" || normalized === "opus-5" || resolveClaudeOpus5ModelIdentity(ref)) return "claude-opus-5";
|
|
63
|
+
if (resolveClaudeFable5ModelIdentity(ref)) return "claude-fable-5";
|
|
64
|
+
if (/^claude-opus-4-8(?=$|[^a-z0-9])/.test(normalized)) return "claude-opus-4-8";
|
|
65
|
+
return normalized || null;
|
|
66
|
+
}
|
|
67
|
+
function resolveClaudeOpusFallbackCost(modelId) {
|
|
68
|
+
if (modelId === "claude-opus-5-5") return CLAUDE_OPUS_55_FALLBACK_MODEL_COST;
|
|
69
|
+
return modelId === "claude-opus-5" || modelId === "claude-opus-4-8" ? CLAUDE_OPUS_FALLBACK_MODEL_COST : void 0;
|
|
70
|
+
}
|
|
71
|
+
/** Resolve billed rates from the serving model reported by Anthropic's fallback stream. */
|
|
72
|
+
function resolveAnthropicFallbackServingModelCost(params) {
|
|
73
|
+
const requestedModelId = resolveFallbackModelIdentity(params.requestedModelId);
|
|
74
|
+
const servingModelId = resolveFallbackModelIdentity(params.servingModelId);
|
|
75
|
+
const servingCost = resolveClaudeOpusFallbackCost(servingModelId);
|
|
76
|
+
if (!servingCost || servingModelId === requestedModelId) return params.requestedCost;
|
|
77
|
+
const requestedCost = resolveClaudeOpusFallbackCost(requestedModelId);
|
|
78
|
+
if (requestedCost === servingCost) return params.requestedCost;
|
|
79
|
+
if (!requestedCost) return servingCost;
|
|
80
|
+
return {
|
|
81
|
+
input: params.requestedCost.input / requestedCost.input * servingCost.input,
|
|
82
|
+
output: params.requestedCost.output / requestedCost.output * servingCost.output,
|
|
83
|
+
cacheRead: params.requestedCost.cacheRead / requestedCost.cacheRead * servingCost.cacheRead,
|
|
84
|
+
cacheWrite: params.requestedCost.cacheWrite / requestedCost.cacheWrite * servingCost.cacheWrite
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function readBoundaryModel(value) {
|
|
88
|
+
if (!value || typeof value !== "object") return null;
|
|
89
|
+
const model = value.model;
|
|
90
|
+
return typeof model === "string" && model.trim() ? model : null;
|
|
91
|
+
}
|
|
92
|
+
/** Reads a `fallback` content block marking where one model's output gives way to the next. */
|
|
93
|
+
function readAnthropicFallbackBoundary(block) {
|
|
94
|
+
if (!block || typeof block !== "object") return null;
|
|
95
|
+
const record = block;
|
|
96
|
+
if (record.type !== "fallback") return null;
|
|
97
|
+
return {
|
|
98
|
+
fromModel: readBoundaryModel(record.from),
|
|
99
|
+
toModel: readBoundaryModel(record.to)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
41
102
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* capabilities allow them.
|
|
103
|
+
* Drops pre-fallback thinking/tool calls while preserving the text prefix that
|
|
104
|
+
* the serving model continued. Dropped tool calls must never execute or replay.
|
|
45
105
|
*/
|
|
106
|
+
function applyAnthropicFallbackBoundary(params) {
|
|
107
|
+
const { output, boundary } = params;
|
|
108
|
+
const survivors = output.content.filter((block) => block.type === "text");
|
|
109
|
+
for (const survivor of survivors) delete survivor.textSignature;
|
|
110
|
+
output.content.splice(0, output.content.length, ...survivors);
|
|
111
|
+
if (boundary.toModel) output.responseModel = boundary.toModel;
|
|
112
|
+
output.diagnostics = [...output.diagnostics ?? [], {
|
|
113
|
+
type: "provider_fallback",
|
|
114
|
+
timestamp: Date.now(),
|
|
115
|
+
details: {
|
|
116
|
+
provider: params.provider,
|
|
117
|
+
fromModel: boundary.fromModel,
|
|
118
|
+
toModel: boundary.toModel
|
|
119
|
+
}
|
|
120
|
+
}];
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
46
124
|
const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
|
|
47
125
|
const ANTHROPIC_COMPACT_THRESHOLD_MIN = 5e4;
|
|
48
126
|
/** Resolve the Anthropic input-token trigger, including the API's minimum. */
|
|
@@ -50,7 +128,7 @@ function resolveAnthropicCompactThreshold(contextWindow, configured) {
|
|
|
50
128
|
const configuredThreshold = parsePositiveInteger(configured);
|
|
51
129
|
if (configuredThreshold !== void 0) return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, configuredThreshold);
|
|
52
130
|
const resolvedContextWindow = parsePositiveInteger(contextWindow);
|
|
53
|
-
return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN,
|
|
131
|
+
return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, Math.floor((resolvedContextWindow ?? 0) * .7));
|
|
54
132
|
}
|
|
55
133
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
56
134
|
function resolveAnthropicServerCompactionPlan(model, extraParams, apiKey) {
|
|
@@ -309,10 +387,11 @@ function applyAnthropicContextManagementToRequest(payload, model, options, direc
|
|
|
309
387
|
cacheTtlPruning: options?.cacheTtlPruning
|
|
310
388
|
}));
|
|
311
389
|
}
|
|
312
|
-
function
|
|
313
|
-
if (directApiKeyBetaHeader === void 0
|
|
314
|
-
const edits = payload.context_management.edits;
|
|
390
|
+
function resolveAnthropicRequestBetaHeader(payload, directApiKeyBetaHeader) {
|
|
391
|
+
if (directApiKeyBetaHeader === void 0) return directApiKeyBetaHeader;
|
|
392
|
+
const edits = isRecord(payload.context_management) ? payload.context_management.edits : void 0;
|
|
315
393
|
const betas = new Set(directApiKeyBetaHeader.split(",").map((beta) => beta.trim()).filter(Boolean));
|
|
394
|
+
if (payload.fallbacks === "default") betas.add(ANTHROPIC_SERVER_SIDE_FALLBACK_BETA);
|
|
316
395
|
for (const edit of Array.isArray(edits) ? edits : []) {
|
|
317
396
|
if (!isRecord(edit)) continue;
|
|
318
397
|
if (edit.type === "clear_tool_uses_20250919") betas.add("context-management-2025-06-27");
|
|
@@ -372,89 +451,6 @@ function applyAnthropicEphemeralCacheControlMarkers(payloadObj, cacheControl = {
|
|
|
372
451
|
}
|
|
373
452
|
}
|
|
374
453
|
//#endregion
|
|
375
|
-
//#region packages/ai/src/providers/anthropic-server-fallback.ts
|
|
376
|
-
/** Anthropic beta that re-serves safety refusals on an allowed fallback model. */
|
|
377
|
-
const ANTHROPIC_SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
378
|
-
/** Let Anthropic select the recommended model for each refusal category. */
|
|
379
|
-
const ANTHROPIC_SERVER_SIDE_FALLBACKS = "default";
|
|
380
|
-
const CLAUDE_OPUS_FALLBACK_MODEL_COST = {
|
|
381
|
-
input: 5,
|
|
382
|
-
output: 25,
|
|
383
|
-
cacheRead: .5,
|
|
384
|
-
cacheWrite: 6.25
|
|
385
|
-
};
|
|
386
|
-
const CLAUDE_OPUS_55_FALLBACK_MODEL_COST = {
|
|
387
|
-
input: 4,
|
|
388
|
-
output: 20,
|
|
389
|
-
cacheRead: .2,
|
|
390
|
-
cacheWrite: 5
|
|
391
|
-
};
|
|
392
|
-
function resolveFallbackModelIdentity(modelId) {
|
|
393
|
-
if (!modelId?.trim()) return null;
|
|
394
|
-
const ref = { id: modelId };
|
|
395
|
-
const normalized = resolveClaudeModelIdentity(ref);
|
|
396
|
-
if (resolveClaudeOpus55ModelIdentity(ref)) return "claude-opus-5-5";
|
|
397
|
-
if (normalized === "opus" || normalized === "opus-5" || resolveClaudeOpus5ModelIdentity(ref)) return "claude-opus-5";
|
|
398
|
-
if (resolveClaudeFable5ModelIdentity(ref)) return "claude-fable-5";
|
|
399
|
-
if (/^claude-opus-4-8(?=$|[^a-z0-9])/.test(normalized)) return "claude-opus-4-8";
|
|
400
|
-
return normalized || null;
|
|
401
|
-
}
|
|
402
|
-
function resolveClaudeOpusFallbackCost(modelId) {
|
|
403
|
-
if (modelId === "claude-opus-5-5") return CLAUDE_OPUS_55_FALLBACK_MODEL_COST;
|
|
404
|
-
return modelId === "claude-opus-5" || modelId === "claude-opus-4-8" ? CLAUDE_OPUS_FALLBACK_MODEL_COST : void 0;
|
|
405
|
-
}
|
|
406
|
-
/** Resolve billed rates from the serving model reported by Anthropic's fallback stream. */
|
|
407
|
-
function resolveAnthropicFallbackServingModelCost(params) {
|
|
408
|
-
const requestedModelId = resolveFallbackModelIdentity(params.requestedModelId);
|
|
409
|
-
const servingModelId = resolveFallbackModelIdentity(params.servingModelId);
|
|
410
|
-
const servingCost = resolveClaudeOpusFallbackCost(servingModelId);
|
|
411
|
-
if (!servingCost || servingModelId === requestedModelId) return params.requestedCost;
|
|
412
|
-
const requestedCost = resolveClaudeOpusFallbackCost(requestedModelId);
|
|
413
|
-
if (requestedCost === servingCost) return params.requestedCost;
|
|
414
|
-
if (!requestedCost) return servingCost;
|
|
415
|
-
return {
|
|
416
|
-
input: params.requestedCost.input / requestedCost.input * servingCost.input,
|
|
417
|
-
output: params.requestedCost.output / requestedCost.output * servingCost.output,
|
|
418
|
-
cacheRead: params.requestedCost.cacheRead / requestedCost.cacheRead * servingCost.cacheRead,
|
|
419
|
-
cacheWrite: params.requestedCost.cacheWrite / requestedCost.cacheWrite * servingCost.cacheWrite
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
function readBoundaryModel(value) {
|
|
423
|
-
if (!value || typeof value !== "object") return null;
|
|
424
|
-
const model = value.model;
|
|
425
|
-
return typeof model === "string" && model.trim() ? model : null;
|
|
426
|
-
}
|
|
427
|
-
/** Reads a `fallback` content block marking where one model's output gives way to the next. */
|
|
428
|
-
function readAnthropicFallbackBoundary(block) {
|
|
429
|
-
if (!block || typeof block !== "object") return null;
|
|
430
|
-
const record = block;
|
|
431
|
-
if (record.type !== "fallback") return null;
|
|
432
|
-
return {
|
|
433
|
-
fromModel: readBoundaryModel(record.from),
|
|
434
|
-
toModel: readBoundaryModel(record.to)
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Drops pre-fallback thinking/tool calls while preserving the text prefix that
|
|
439
|
-
* the serving model continued. Dropped tool calls must never execute or replay.
|
|
440
|
-
*/
|
|
441
|
-
function applyAnthropicFallbackBoundary(params) {
|
|
442
|
-
const { output, boundary } = params;
|
|
443
|
-
const survivors = output.content.filter((block) => block.type === "text");
|
|
444
|
-
for (const survivor of survivors) delete survivor.textSignature;
|
|
445
|
-
output.content.splice(0, output.content.length, ...survivors);
|
|
446
|
-
if (boundary.toModel) output.responseModel = boundary.toModel;
|
|
447
|
-
output.diagnostics = [...output.diagnostics ?? [], {
|
|
448
|
-
type: "provider_fallback",
|
|
449
|
-
timestamp: Date.now(),
|
|
450
|
-
details: {
|
|
451
|
-
provider: params.provider,
|
|
452
|
-
fromModel: boundary.fromModel,
|
|
453
|
-
toModel: boundary.toModel
|
|
454
|
-
}
|
|
455
|
-
}];
|
|
456
|
-
}
|
|
457
|
-
//#endregion
|
|
458
454
|
//#region packages/ai/src/providers/anthropic-thinking-replay.ts
|
|
459
455
|
const ANTHROPIC_OMITTED_REASONING_TEXT = "[assistant reasoning omitted]";
|
|
460
456
|
function applyAnthropicThinkingBindingControls(params, directApiKeyBetaHeader) {
|
|
@@ -557,14 +553,6 @@ const schemaArrayKeywords = /* @__PURE__ */ new Set([
|
|
|
557
553
|
"oneOf",
|
|
558
554
|
"prefixItems"
|
|
559
555
|
]);
|
|
560
|
-
const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
561
|
-
"$defs",
|
|
562
|
-
"definitions",
|
|
563
|
-
"dependencies",
|
|
564
|
-
"dependentSchemas",
|
|
565
|
-
"patternProperties",
|
|
566
|
-
"properties"
|
|
567
|
-
]);
|
|
568
556
|
/** Normalize the detached JSON projection and report tuple changes to enclosing schemas. */
|
|
569
557
|
function normalizeAnthropicJsonSchema(schema) {
|
|
570
558
|
if (!isRecord(schema)) return false;
|
|
@@ -578,7 +566,7 @@ function normalizeAnthropicJsonSchema(schema) {
|
|
|
578
566
|
for (const entry of value) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
579
567
|
continue;
|
|
580
568
|
}
|
|
581
|
-
if (
|
|
569
|
+
if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const entry of Object.values(value)) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
582
570
|
}
|
|
583
571
|
if (Array.isArray(schema.items)) {
|
|
584
572
|
for (const entry of schema.items) normalizeAnthropicJsonSchema(entry);
|
|
@@ -659,8 +647,7 @@ function reconcileAnthropicToolChoice(choice, projection) {
|
|
|
659
647
|
...choice,
|
|
660
648
|
name: originalMatch.wireName
|
|
661
649
|
};
|
|
662
|
-
|
|
663
|
-
const matchedTool = projection.tools.find((tool) => tool.wireName === requestedName);
|
|
650
|
+
const matchedTool = projection.unavailableOriginalNames.has(requestedName) ? void 0 : projection.tools.find((tool) => tool.wireName === requestedName);
|
|
664
651
|
if (!matchedTool) throw new Error(`Anthropic tool_choice requested unavailable tool "${requestedName}" after schema conversion`);
|
|
665
652
|
return {
|
|
666
653
|
...choice,
|
|
@@ -873,7 +860,7 @@ async function convertContentBlocks(content, model, imageBudget, profile, isErro
|
|
|
873
860
|
}
|
|
874
861
|
async function convertAnthropicMessages(transformedMessages, model, isOAuthToken, options) {
|
|
875
862
|
const params = [];
|
|
876
|
-
const
|
|
863
|
+
const modelRetainsRuntimeContext = bindsClaudeThinkingPrefix(model);
|
|
877
864
|
const imageBudget = createAnthropicInlineImageBudget();
|
|
878
865
|
const allowReasoningContentReplay = options.allowReasoningContentReplay === true;
|
|
879
866
|
const replayThinkingEnabled = options.replayThinkingEnabled !== false;
|
|
@@ -883,40 +870,32 @@ async function convertAnthropicMessages(transformedMessages, model, isOAuthToken
|
|
|
883
870
|
const msg = transformedMessages[i];
|
|
884
871
|
if (!msg) continue;
|
|
885
872
|
if (msg.role === "user") {
|
|
873
|
+
let content;
|
|
886
874
|
if (typeof msg.content === "string") {
|
|
887
|
-
if (msg.content.trim().length
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
875
|
+
if (msg.content.trim().length === 0) continue;
|
|
876
|
+
content = sanitizeTransportPayloadText(msg.content);
|
|
877
|
+
} else {
|
|
878
|
+
content = (!managed || model.input.includes("image") ? await normalizeAnthropicInlineContent(msg.content, imageBudget) : msg.content.map((item) => item.type === "image" ? {
|
|
879
|
+
type: "text",
|
|
880
|
+
text: NON_VISION_USER_IMAGE_PLACEHOLDER
|
|
881
|
+
} : item)).map((item) => item.type === "text" ? {
|
|
882
|
+
type: "text",
|
|
883
|
+
text: sanitizeTransportPayloadText(item.text)
|
|
884
|
+
} : {
|
|
885
|
+
type: "image",
|
|
886
|
+
source: {
|
|
887
|
+
type: "base64",
|
|
888
|
+
media_type: resolveAnthropicImageMediaType(item.mimeType),
|
|
889
|
+
data: item.data
|
|
890
|
+
}
|
|
891
|
+
}).filter((block) => block.type === "text" ? block.text.trim().length > 0 : !managed || model.input.includes("image"));
|
|
892
|
+
if (content.length === 0) continue;
|
|
896
893
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
text: NON_VISION_USER_IMAGE_PLACEHOLDER
|
|
900
|
-
} : item)).map((item) => item.type === "text" ? {
|
|
901
|
-
type: "text",
|
|
902
|
-
text: sanitizeTransportPayloadText(item.text)
|
|
903
|
-
} : {
|
|
904
|
-
type: "image",
|
|
905
|
-
source: {
|
|
906
|
-
type: "base64",
|
|
907
|
-
media_type: resolveAnthropicImageMediaType(item.mimeType),
|
|
908
|
-
data: item.data
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
let filteredBlocks = !managed || model.input.includes("image") ? blocks : blocks.filter((block) => block.type !== "image");
|
|
912
|
-
filteredBlocks = filteredBlocks.filter((block) => block.type !== "text" || block.text.trim().length > 0);
|
|
913
|
-
if (filteredBlocks.length === 0) continue;
|
|
914
|
-
if (msg.runtimeContextCarrier && !retainRuntimeContext) options.cacheBreakpointOptOutMessageIndexes?.add(params.length);
|
|
915
|
-
const userParam = {
|
|
894
|
+
if (msg.runtimeContextCarrier && !(msg.runtimeContextCarrierRetained ?? modelRetainsRuntimeContext)) options.cacheBreakpointOptOutMessageIndexes?.add(params.length);
|
|
895
|
+
params.push({
|
|
916
896
|
role: "user",
|
|
917
|
-
content
|
|
918
|
-
};
|
|
919
|
-
params.push(userParam);
|
|
897
|
+
content
|
|
898
|
+
});
|
|
920
899
|
continue;
|
|
921
900
|
}
|
|
922
901
|
if (msg.role === "assistant") {
|
|
@@ -952,24 +931,14 @@ async function convertAnthropicMessages(transformedMessages, model, isOAuthToken
|
|
|
952
931
|
type: "text",
|
|
953
932
|
text: sanitizeTransportPayloadText(block.thinking)
|
|
954
933
|
});
|
|
955
|
-
else {
|
|
956
|
-
const thinking =
|
|
957
|
-
if (thinkingSignature === "reasoning_content") {
|
|
958
|
-
if (allowReasoningContentReplay) {
|
|
959
|
-
blocks.push({
|
|
960
|
-
type: "thinking",
|
|
961
|
-
thinking,
|
|
962
|
-
signature: thinkingSignature ?? ""
|
|
963
|
-
});
|
|
964
|
-
reasoningContent.push(thinking);
|
|
965
|
-
}
|
|
966
|
-
continue;
|
|
967
|
-
}
|
|
934
|
+
else if (!isReasoningContent || allowReasoningContentReplay) {
|
|
935
|
+
const thinking = isReasoningContent ? sanitizeTransportPayloadText(block.thinking) : block.thinking;
|
|
968
936
|
blocks.push({
|
|
969
937
|
type: "thinking",
|
|
970
938
|
thinking,
|
|
971
939
|
signature: thinkingSignature ?? ""
|
|
972
940
|
});
|
|
941
|
+
if (isReasoningContent) reasoningContent.push(thinking);
|
|
973
942
|
}
|
|
974
943
|
continue;
|
|
975
944
|
}
|
|
@@ -1044,14 +1013,14 @@ function buildAnthropicGenerationParams({ model, options, tools, toolProjection,
|
|
|
1044
1013
|
budget_tokens: options?.thinkingBudgetTokens ?? 1024,
|
|
1045
1014
|
...profile === "provider" ? { display } : {}
|
|
1046
1015
|
};
|
|
1047
|
-
} else if (options?.thinkingEnabled === false) params.thinking = { type: "disabled" };
|
|
1016
|
+
} else if (options?.thinkingEnabled === false) params.thinking = requiresClaudeBetweenToolsThinking(model) ? { type: "between_tools" } : { type: "disabled" };
|
|
1048
1017
|
}
|
|
1049
1018
|
if (options?.metadata) {
|
|
1050
1019
|
const userId = options.metadata.user_id;
|
|
1051
1020
|
if (typeof userId === "string") params.metadata = { user_id: userId };
|
|
1052
1021
|
}
|
|
1053
1022
|
if (options?.toolChoice) {
|
|
1054
|
-
const normalizedToolChoice = normalizeAnthropicToolChoice(mandatoryAdaptiveThinking || options?.thinkingEnabled === true, options.toolChoice);
|
|
1023
|
+
const normalizedToolChoice = normalizeAnthropicToolChoice(mandatoryAdaptiveThinking || options?.thinkingEnabled === true || resolveClaudeSonnet55ModelIdentity(model) !== void 0, options.toolChoice);
|
|
1055
1024
|
const projectedToolChoice = toolProjection ? reconcileAnthropicToolChoice(normalizedToolChoice, toolProjection) : normalizedToolChoice;
|
|
1056
1025
|
if (projectedToolChoice) params.tool_choice = projectedToolChoice;
|
|
1057
1026
|
}
|
|
@@ -1059,19 +1028,17 @@ function buildAnthropicGenerationParams({ model, options, tools, toolProjection,
|
|
|
1059
1028
|
}
|
|
1060
1029
|
function convertAnthropicTools(tools, isOAuthTokenLocal, supportsEagerToolInputStreaming = false) {
|
|
1061
1030
|
const projection = projectAnthropicTools(tools, (name) => isOAuthTokenLocal ? toClaudeCodeToolName(name) : name);
|
|
1062
|
-
const convertedTools = [];
|
|
1063
|
-
for (const tool of projection.tools) {
|
|
1064
|
-
const convertedTool = {
|
|
1065
|
-
name: tool.wireName,
|
|
1066
|
-
description: tool.description,
|
|
1067
|
-
input_schema: tool.inputSchema
|
|
1068
|
-
};
|
|
1069
|
-
if (supportsEagerToolInputStreaming) convertedTool.eager_input_streaming = true;
|
|
1070
|
-
convertedTools.push(convertedTool);
|
|
1071
|
-
}
|
|
1072
1031
|
return {
|
|
1073
1032
|
projection,
|
|
1074
|
-
tools:
|
|
1033
|
+
tools: projection.tools.map((tool) => {
|
|
1034
|
+
const projected = {
|
|
1035
|
+
name: tool.wireName,
|
|
1036
|
+
description: tool.description,
|
|
1037
|
+
input_schema: tool.inputSchema
|
|
1038
|
+
};
|
|
1039
|
+
if (supportsEagerToolInputStreaming) projected.eager_input_streaming = true;
|
|
1040
|
+
return projected;
|
|
1041
|
+
})
|
|
1075
1042
|
};
|
|
1076
1043
|
}
|
|
1077
1044
|
//#endregion
|
|
@@ -1214,11 +1181,16 @@ function applyAnthropicMessageDeltaUsage(target, usage, messageStartPromptUsage)
|
|
|
1214
1181
|
cacheWrite: cacheWriteTokens,
|
|
1215
1182
|
cacheWrite1h: readAnthropicCacheWriteUsage(usage).cacheWrite1h
|
|
1216
1183
|
};
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1184
|
+
for (const key of [
|
|
1185
|
+
"input",
|
|
1186
|
+
"output",
|
|
1187
|
+
"cacheRead",
|
|
1188
|
+
"cacheWrite",
|
|
1189
|
+
"cacheWrite1h"
|
|
1190
|
+
]) {
|
|
1191
|
+
const value = resolved[key];
|
|
1192
|
+
if (value !== void 0) target[key] = value;
|
|
1193
|
+
}
|
|
1222
1194
|
target.totalTokens = target.input + target.output + target.cacheRead + target.cacheWrite;
|
|
1223
1195
|
const iterationUsage = readLastAnthropicIterationUsage(usage);
|
|
1224
1196
|
if (iterationUsage.state === "valid") target.contextUsage = {
|
|
@@ -1246,7 +1218,6 @@ async function consumeAnthropicStream(params) {
|
|
|
1246
1218
|
let costModel = model;
|
|
1247
1219
|
let messageStartPromptUsage;
|
|
1248
1220
|
let inputTransformations;
|
|
1249
|
-
const anthropicStream = params.events;
|
|
1250
1221
|
try {
|
|
1251
1222
|
const blocks = output.content;
|
|
1252
1223
|
const blockIndexes = /* @__PURE__ */ new Map();
|
|
@@ -1256,8 +1227,10 @@ async function consumeAnthropicStream(params) {
|
|
|
1256
1227
|
const compactionCapture = createCompactionCapture(output, model, options);
|
|
1257
1228
|
const pendingThinkingSignatures = /* @__PURE__ */ new Map();
|
|
1258
1229
|
const allowReasoningContentReplay = managed && resolveProviderEndpoint(model).endpointClass === "xiaomi-native";
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1230
|
+
const reasoningContentBlocks = {
|
|
1231
|
+
thinking: /* @__PURE__ */ new Map(),
|
|
1232
|
+
text: /* @__PURE__ */ new Map()
|
|
1233
|
+
};
|
|
1261
1234
|
let sawMessageStart = false;
|
|
1262
1235
|
let sawMessageStop = false;
|
|
1263
1236
|
let sawStopReason = false;
|
|
@@ -1271,64 +1244,39 @@ async function consumeAnthropicStream(params) {
|
|
|
1271
1244
|
else eventSink.push(event);
|
|
1272
1245
|
};
|
|
1273
1246
|
const eventIndexKey = (eventIndex) => typeof eventIndex === "number" ? eventIndex : -1;
|
|
1274
|
-
const
|
|
1247
|
+
const appendReasoningContentDelta = (kind, eventIndex, rawText) => {
|
|
1275
1248
|
if (typeof rawText !== "string") return false;
|
|
1276
1249
|
const text = sanitizeTransportPayloadText(rawText);
|
|
1277
1250
|
if (text.length === 0) return false;
|
|
1251
|
+
const indexes = reasoningContentBlocks[kind];
|
|
1278
1252
|
const key = eventIndexKey(eventIndex);
|
|
1279
|
-
let contentIndex =
|
|
1253
|
+
let contentIndex = indexes.get(key);
|
|
1280
1254
|
let block = contentIndex === void 0 ? void 0 : blocks[contentIndex];
|
|
1281
|
-
if (!block || block.type !==
|
|
1282
|
-
block = {
|
|
1255
|
+
if (!block || block.type !== kind) {
|
|
1256
|
+
block = kind === "thinking" ? {
|
|
1283
1257
|
type: "thinking",
|
|
1284
1258
|
thinking: "",
|
|
1285
1259
|
thinkingSignature: "reasoning_content"
|
|
1286
|
-
}
|
|
1287
|
-
output.content.push(block);
|
|
1288
|
-
contentIndex = output.content.length - 1;
|
|
1289
|
-
reasoningContentThinkingBlocks.set(key, contentIndex);
|
|
1290
|
-
eventSink.push({
|
|
1291
|
-
type: "thinking_start",
|
|
1292
|
-
contentIndex,
|
|
1293
|
-
partial: output
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
if (contentIndex === void 0) return false;
|
|
1297
|
-
appendAssistantThinking(block, text);
|
|
1298
|
-
block.thinkingSignature = "reasoning_content";
|
|
1299
|
-
eventSink.push({
|
|
1300
|
-
type: "thinking_delta",
|
|
1301
|
-
contentIndex,
|
|
1302
|
-
delta: text,
|
|
1303
|
-
partial: output
|
|
1304
|
-
});
|
|
1305
|
-
return true;
|
|
1306
|
-
};
|
|
1307
|
-
const appendReasoningContentTextDelta = (eventIndex, rawText) => {
|
|
1308
|
-
if (typeof rawText !== "string") return false;
|
|
1309
|
-
const text = sanitizeTransportPayloadText(rawText);
|
|
1310
|
-
if (text.length === 0) return false;
|
|
1311
|
-
const key = eventIndexKey(eventIndex);
|
|
1312
|
-
let contentIndex = reasoningContentTextBlocks.get(key);
|
|
1313
|
-
let block = contentIndex === void 0 ? void 0 : blocks[contentIndex];
|
|
1314
|
-
if (!block || block.type !== "text") {
|
|
1315
|
-
block = {
|
|
1260
|
+
} : {
|
|
1316
1261
|
type: "text",
|
|
1317
1262
|
text: ""
|
|
1318
1263
|
};
|
|
1319
1264
|
output.content.push(block);
|
|
1320
1265
|
contentIndex = output.content.length - 1;
|
|
1321
|
-
|
|
1266
|
+
indexes.set(key, contentIndex);
|
|
1322
1267
|
eventSink.push({
|
|
1323
|
-
type:
|
|
1268
|
+
type: `${kind}_start`,
|
|
1324
1269
|
contentIndex,
|
|
1325
1270
|
partial: output
|
|
1326
1271
|
});
|
|
1327
1272
|
}
|
|
1328
1273
|
if (contentIndex === void 0) return false;
|
|
1329
|
-
block.
|
|
1274
|
+
if (block.type === "thinking") {
|
|
1275
|
+
appendAssistantThinking(block, text);
|
|
1276
|
+
block.thinkingSignature = "reasoning_content";
|
|
1277
|
+
} else if (block.type === "text") block.text += text;
|
|
1330
1278
|
eventSink.push({
|
|
1331
|
-
type:
|
|
1279
|
+
type: `${kind}_delta`,
|
|
1332
1280
|
contentIndex,
|
|
1333
1281
|
delta: text,
|
|
1334
1282
|
partial: output
|
|
@@ -1337,29 +1285,21 @@ async function consumeAnthropicStream(params) {
|
|
|
1337
1285
|
};
|
|
1338
1286
|
const finishReasoningContentSidecars = (eventIndex) => {
|
|
1339
1287
|
const key = eventIndexKey(eventIndex);
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1288
|
+
for (const kind of ["thinking", "text"]) {
|
|
1289
|
+
const indexes = reasoningContentBlocks[kind];
|
|
1290
|
+
const contentIndex = indexes.get(key);
|
|
1291
|
+
if (contentIndex === void 0) continue;
|
|
1292
|
+
indexes.delete(key);
|
|
1293
|
+
const block = output.content[contentIndex];
|
|
1294
|
+
if (block?.type === kind) eventSink.push({
|
|
1295
|
+
type: `${kind}_end`,
|
|
1296
|
+
contentIndex,
|
|
1297
|
+
content: block.type === "thinking" ? block.thinking : block.text,
|
|
1348
1298
|
partial: output
|
|
1349
1299
|
});
|
|
1350
1300
|
}
|
|
1351
|
-
const textContentIndex = reasoningContentTextBlocks.get(key);
|
|
1352
|
-
if (textContentIndex === void 0) return;
|
|
1353
|
-
reasoningContentTextBlocks.delete(key);
|
|
1354
|
-
const block = output.content[textContentIndex];
|
|
1355
|
-
if (block?.type === "text") eventSink.push({
|
|
1356
|
-
type: "text_end",
|
|
1357
|
-
contentIndex: textContentIndex,
|
|
1358
|
-
content: block.text,
|
|
1359
|
-
partial: output
|
|
1360
|
-
});
|
|
1361
1301
|
};
|
|
1362
|
-
for await (const rawEvent of
|
|
1302
|
+
for await (const rawEvent of iterateModelStream(params.events, options.signal)) {
|
|
1363
1303
|
const event = asRecord(rawEvent);
|
|
1364
1304
|
inputTransformations = readAnthropicInputTransformations(event) ?? inputTransformations;
|
|
1365
1305
|
if (managed) notifyLlmRequestActivity(options.signal);
|
|
@@ -1532,7 +1472,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1532
1472
|
let index = eventIndex === void 0 ? void 0 : blockIndexes.get(eventIndex);
|
|
1533
1473
|
let block = index === void 0 ? void 0 : blocks[index];
|
|
1534
1474
|
if (allowReasoningContentReplay) {
|
|
1535
|
-
const appendedThinking =
|
|
1475
|
+
const appendedThinking = appendReasoningContentDelta("thinking", event.index, delta?.reasoning_content);
|
|
1536
1476
|
const hasNativeAnthropicDelta = delta?.type === "text_delta" && typeof delta.text === "string" || delta?.type === "thinking_delta" && typeof delta.thinking === "string" || delta?.type === "input_json_delta" && typeof delta.partial_json === "string" || delta?.type === "signature_delta" && typeof delta.signature === "string";
|
|
1537
1477
|
let appendedContent = false;
|
|
1538
1478
|
if (!hasNativeAnthropicDelta && typeof delta?.content === "string" && delta.content.length > 0) {
|
|
@@ -1547,7 +1487,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1547
1487
|
partial: output
|
|
1548
1488
|
});
|
|
1549
1489
|
appendedContent = true;
|
|
1550
|
-
} else appendedContent =
|
|
1490
|
+
} else appendedContent = appendReasoningContentDelta("text", event.index, text);
|
|
1551
1491
|
}
|
|
1552
1492
|
}
|
|
1553
1493
|
if ((appendedThinking || appendedContent) && !hasNativeAnthropicDelta) continue;
|
|
@@ -1623,17 +1563,13 @@ async function consumeAnthropicStream(params) {
|
|
|
1623
1563
|
}
|
|
1624
1564
|
blockIndexes.delete(eventIndex);
|
|
1625
1565
|
delete block.index;
|
|
1626
|
-
if (block.type === "text") {
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
finishReasoningContentSidecars(event.index);
|
|
1634
|
-
continue;
|
|
1635
|
-
}
|
|
1636
|
-
if (block.type === "thinking") {
|
|
1566
|
+
if (block.type === "text") emitTextEnd({
|
|
1567
|
+
type: "text_end",
|
|
1568
|
+
contentIndex: index,
|
|
1569
|
+
content: block.text,
|
|
1570
|
+
partial: output
|
|
1571
|
+
});
|
|
1572
|
+
else if (block.type === "thinking") {
|
|
1637
1573
|
if (pendingSignature !== void 0) block.thinkingSignature = pendingSignature;
|
|
1638
1574
|
eventSink.push({
|
|
1639
1575
|
type: "thinking_end",
|
|
@@ -1641,16 +1577,11 @@ async function consumeAnthropicStream(params) {
|
|
|
1641
1577
|
content: block.thinking,
|
|
1642
1578
|
partial: output
|
|
1643
1579
|
});
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
block,
|
|
1650
|
-
contentIndex: index
|
|
1651
|
-
});
|
|
1652
|
-
finishReasoningContentSidecars(event.index);
|
|
1653
|
-
}
|
|
1580
|
+
} else if (block.type === "toolCall") sealedToolCalls.push({
|
|
1581
|
+
block,
|
|
1582
|
+
contentIndex: index
|
|
1583
|
+
});
|
|
1584
|
+
finishReasoningContentSidecars(event.index);
|
|
1654
1585
|
continue;
|
|
1655
1586
|
}
|
|
1656
1587
|
if (event.type === "message_delta") {
|
|
@@ -1691,4 +1622,4 @@ async function consumeAnthropicStream(params) {
|
|
|
1691
1622
|
}
|
|
1692
1623
|
}
|
|
1693
1624
|
//#endregion
|
|
1694
|
-
export {
|
|
1625
|
+
export { applyAnthropicRequestCacheControl as A, ANTHROPIC_SERVER_SIDE_FALLBACKS as B, applyAnthropicThinkingBindingControls as C, applyAnthropicContextManagementToRequest as D, readAnthropicInputTransformations as E, resolveAnthropicCacheOptions as F, resolveAnthropicFallbackServingModelCost as G, CLAUDE_OPUS_FALLBACK_MODEL_COST as H, resolveAnthropicEphemeralCacheControl as I, usesFoundryBearerAuth as J, isAnthropicOAuthApiKey as K, resolveAnthropicPayloadPolicy as L, isAnthropicServerToolClearingEnabled as M, isDirectAnthropicModel as N, applyAnthropicEphemeralCacheControlMarkers as O, logAnthropicContextEdits as P, resolveAnthropicRequestBetaHeader as R, ANTHROPIC_OMITTED_REASONING_TEXT as S, logAnthropicThinkingDrops as T, applyAnthropicFallbackBoundary as U, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as V, readAnthropicFallbackBoundary as W, normalizeAnthropicToolChoice as _, readAnthropicPromptUsageSnapshot as a, resolveOriginalAnthropicToolName as b, applyAnthropicRefusal as c, convertAnthropicTools as d, buildAnthropicReplayPlan as f, normalizeAnthropicToolCallId as g, suppressAnthropicCompaction as h, readAnthropicCacheWriteUsage as i, buildAnthropicSystemBlocks as j, applyAnthropicPayloadPolicyToParams as k, buildAnthropicGenerationParams as l, resolveNewestAnthropicCompaction as m, applyAnthropicMessageDeltaUsage as n, readAnthropicUsageTokenCount as o, isAnthropicReplayRejection as p, omitFoundryBearerCredentialHeaders as q, applyAnthropicMessageStartUsage as r, readLastAnthropicIterationUsage as s, consumeAnthropicStream as t, convertAnthropicMessages as u, projectAnthropicTools as v, findActiveAnthropicToolTurnAssistantIndex as w, toClaudeCodeToolName as x, reconcileAnthropicToolChoice as y, resolveAnthropicServerCompactionPlan as z };
|