@openclaw/ai 2026.9.5 → 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-COtDvgtt.mjs → anthropic-Cw2pgccz.mjs} +59 -88
- package/dist/{anthropic-payload-policy-5Erq1Nzy.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +8 -6
- package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +194 -247
- package/dist/{api-registry-Ba2Cv-ut.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
- package/dist/{azure-openai-responses-YrgnD583.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
- package/dist/{base64-BQOzsvUH.mjs → base64-C1PsYcRQ.mjs} +22 -16
- package/dist/{diagnostics-Dm4bisWG.mjs → diagnostics-CJaB6g8J.mjs} +55 -10
- package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
- package/dist/diagnostics.d.mts +11 -5
- package/dist/diagnostics.mjs +4 -4
- 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-CCoa-qSI.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-BuhpRO9r.mjs → google-BfapkS_K.mjs} +8 -11
- package/dist/google-interactions-DW3iXzjc.mjs +574 -0
- package/dist/{google-messages-CyWnYlh0.mjs → google-messages-CtjVtVot.mjs} +35 -71
- package/dist/{google-shared-BT5ZeNer.mjs → google-shared-Y2YfotEu.mjs} +43 -47
- package/dist/{google-vertex-C7EplRvt.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
- package/dist/{host-B4MeUNBc.mjs → host-CHi3X87F.mjs} +64 -189
- package/dist/{host-policy-DUnXSx0I.mjs → host-policy-BOAwRg_M.mjs} +2 -14
- package/dist/{host-FZ1RA_qD.d.mts → host-rxlNaBwm.d.mts} +9 -3
- package/dist/{index-DaF2QbwS.d.mts → index-D6KsSE74.d.mts} +57 -9
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -7
- package/dist/internal/anthropic.d.mts +13 -8
- 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 +46 -9
- package/dist/internal/openai.mjs +13 -12
- package/dist/internal/runtime.d.mts +31 -70
- package/dist/internal/runtime.mjs +11 -66
- package/dist/internal/shared.d.mts +16 -13
- package/dist/internal/shared.mjs +6 -5
- package/dist/internal/tool-schema.d.mts +2 -2
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-moA-mbwl.mjs → mistral-RS6mboC-.mjs} +46 -93
- package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
- package/dist/{openai-chatgpt-responses-DWID3EFO.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +118 -99
- package/dist/{openai-completions-DJ1Vm-CD.mjs → openai-completions-D14ihPYk.mjs} +14 -12
- package/dist/{openai-completions-compat-CkwdxTZx.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
- package/dist/{openai-completions-compat-JE7gqxb9.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
- package/dist/{openai-completions-stream-Bu98b0Hv.mjs → openai-completions-stream-CDCuw3DP.mjs} +124 -183
- package/dist/{openai-prompt-cache-CJ_xEevu.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
- package/dist/{openai-prompt-cache-1wfaIszn.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
- package/dist/{openai-provider-client-DPo0Hmak.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
- package/dist/{openai-reasoning-effort-NlFZmfEu.mjs → openai-reasoning-effort-ConhwkeX.mjs} +14 -5
- package/dist/{openai-responses-BejZzQCP.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-D6P5oZP5.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-Dflvrfa8.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
- package/dist/{openai-responses-prompt-observer-internal-C15_-OwV.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +16 -13
- package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +36 -0
- package/dist/{openai-responses-shared-CwsziD_m.mjs → openai-responses-shared-DL4ulQn7.mjs} +838 -577
- package/dist/{openai-responses-terminal-usage-Dl3J6zrf.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-BO8rwyAD.mjs → openai-tool-schema-vsl-cE-n.mjs} +365 -429
- package/dist/{openai-transport-params-DQeuAvBl.mjs → openai-transport-params-BwlpzX-2.mjs} +61 -106
- package/dist/{positive-integer-DtjCkbue.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
- package/dist/{provider-error-DDqw9Qda.mjs → provider-error-CwT_j2v0.mjs} +82 -10
- package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
- package/dist/{provider-options-DprLsWh9.d.mts → provider-options-Df7ov0K1.d.mts} +6 -4
- package/dist/{provider-replay-context-CnUSOwhr.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
- package/dist/{provider-transcript-transform-BsRAhuWJ.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
- package/dist/{provider-transport-turn-state-CkGToCD2.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
- package/dist/{provider-types-CAKRC7N5.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-Dy9IO8Dc.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +193 -98
- package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
- package/dist/simple-options-CGAkCwtM.mjs +349 -0
- package/dist/{src-DeKjbE8I.mjs → src-H4aXcFuX.mjs} +53 -26
- package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
- package/dist/{stream-first-event-timeout-C9ZadkJW.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-D-6FQSHm.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +63 -37
- package/dist/{transport-stream-shared-BbUkFaHi.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +13 -7
- package/dist/{transport-utils-1cyq5Y7x.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
- package/dist/transports.d.mts +37 -33
- package/dist/transports.mjs +208 -239
- package/dist/types-CB-_vNyI.d.mts +1 -0
- package/dist/{types-4_uVs5WH.d.mts → types-CLLR3eB4.d.mts} +5 -1
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -5
- package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
- package/dist/{validation-Ctzu2DhF.d.mts → validation-Cat2wQsc.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +6 -6
- package/dist/assistant-output-BsEkB-vU.mjs +0 -16
- package/dist/event-stream-DmSCpi1T.d.mts +0 -1
- package/dist/simple-options-C6cFWj_f.mjs +0 -175
- package/dist/types-DkJfb4W3.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
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-CHi3X87F.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-1cyq5Y7x.mjs";
|
|
8
|
-
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-DUnXSx0I.mjs";
|
|
6
|
+
import { i as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-C1PsYcRQ.mjs";
|
|
7
|
+
import "./transport-utils-C-4bf2Ok.mjs";
|
|
8
|
+
import { i as resolveProviderRequestCapabilities, r as resolveProviderEndpoint } from "./host-policy-BOAwRg_M.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-Dh5qKJ8e.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-CGAkCwtM.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-DsyI5jOP.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) {
|
|
@@ -104,7 +182,7 @@ function resolveAnthropicCacheOptions(model, cacheRetention) {
|
|
|
104
182
|
supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? model.provider !== "fireworks"
|
|
105
183
|
};
|
|
106
184
|
}
|
|
107
|
-
function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl) {
|
|
185
|
+
function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion = ANTHROPIC_CLAUDE_CODE_VERSION) {
|
|
108
186
|
const blocks = systemPrompt ? [{
|
|
109
187
|
type: "text",
|
|
110
188
|
text: sanitizeSurrogates(systemPrompt)
|
|
@@ -119,7 +197,7 @@ function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl) {
|
|
|
119
197
|
const identityCacheControl = blocks.some((block) => block.cache_control) ? void 0 : cacheControl;
|
|
120
198
|
blocks.unshift({
|
|
121
199
|
type: "text",
|
|
122
|
-
text:
|
|
200
|
+
text: `x-anthropic-billing-header: cc_version=${claudeCodeVersion}; cc_entrypoint=sdk-cli;`
|
|
123
201
|
}, {
|
|
124
202
|
type: "text",
|
|
125
203
|
text: "You are Claude Code, Anthropic's official CLI for Claude.",
|
|
@@ -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,73 +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
|
-
function resolveFallbackModelIdentity(modelId) {
|
|
387
|
-
if (!modelId?.trim()) return null;
|
|
388
|
-
const ref = { id: modelId };
|
|
389
|
-
const normalized = resolveClaudeModelIdentity(ref);
|
|
390
|
-
if (normalized === "opus" || normalized === "opus-5" || resolveClaudeOpus5ModelIdentity(ref)) return "claude-opus-5";
|
|
391
|
-
if (resolveClaudeFable5ModelIdentity(ref)) return "claude-fable-5";
|
|
392
|
-
if (/^claude-opus-4-8(?=$|[^a-z0-9])/.test(normalized)) return "claude-opus-4-8";
|
|
393
|
-
return normalized || null;
|
|
394
|
-
}
|
|
395
|
-
function isClaudeOpusFallbackModel(modelId) {
|
|
396
|
-
return modelId === "claude-opus-5" || modelId === "claude-opus-4-8";
|
|
397
|
-
}
|
|
398
|
-
/** Resolve billed rates from the serving model reported by Anthropic's fallback stream. */
|
|
399
|
-
function resolveAnthropicFallbackServingModelCost(params) {
|
|
400
|
-
const requestedModelId = resolveFallbackModelIdentity(params.requestedModelId);
|
|
401
|
-
const servingModelId = resolveFallbackModelIdentity(params.servingModelId);
|
|
402
|
-
if (!servingModelId || servingModelId === requestedModelId || !isClaudeOpusFallbackModel(servingModelId)) return params.requestedCost;
|
|
403
|
-
if (requestedModelId && isClaudeOpusFallbackModel(requestedModelId)) return params.requestedCost;
|
|
404
|
-
return CLAUDE_OPUS_FALLBACK_MODEL_COST;
|
|
405
|
-
}
|
|
406
|
-
function readBoundaryModel(value) {
|
|
407
|
-
if (!value || typeof value !== "object") return null;
|
|
408
|
-
const model = value.model;
|
|
409
|
-
return typeof model === "string" && model.trim() ? model : null;
|
|
410
|
-
}
|
|
411
|
-
/** Reads a `fallback` content block marking where one model's output gives way to the next. */
|
|
412
|
-
function readAnthropicFallbackBoundary(block) {
|
|
413
|
-
if (!block || typeof block !== "object") return null;
|
|
414
|
-
const record = block;
|
|
415
|
-
if (record.type !== "fallback") return null;
|
|
416
|
-
return {
|
|
417
|
-
fromModel: readBoundaryModel(record.from),
|
|
418
|
-
toModel: readBoundaryModel(record.to)
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Drops pre-fallback thinking/tool calls while preserving the text prefix that
|
|
423
|
-
* the serving model continued. Dropped tool calls must never execute or replay.
|
|
424
|
-
*/
|
|
425
|
-
function applyAnthropicFallbackBoundary(params) {
|
|
426
|
-
const { output, boundary } = params;
|
|
427
|
-
const survivors = output.content.filter((block) => block.type === "text");
|
|
428
|
-
for (const survivor of survivors) delete survivor.textSignature;
|
|
429
|
-
output.content.splice(0, output.content.length, ...survivors);
|
|
430
|
-
if (boundary.toModel) output.responseModel = boundary.toModel;
|
|
431
|
-
output.diagnostics = [...output.diagnostics ?? [], {
|
|
432
|
-
type: "provider_fallback",
|
|
433
|
-
timestamp: Date.now(),
|
|
434
|
-
details: {
|
|
435
|
-
provider: params.provider,
|
|
436
|
-
fromModel: boundary.fromModel,
|
|
437
|
-
toModel: boundary.toModel
|
|
438
|
-
}
|
|
439
|
-
}];
|
|
440
|
-
}
|
|
441
|
-
//#endregion
|
|
442
454
|
//#region packages/ai/src/providers/anthropic-thinking-replay.ts
|
|
443
455
|
const ANTHROPIC_OMITTED_REASONING_TEXT = "[assistant reasoning omitted]";
|
|
444
456
|
function applyAnthropicThinkingBindingControls(params, directApiKeyBetaHeader) {
|
|
@@ -541,14 +553,6 @@ const schemaArrayKeywords = /* @__PURE__ */ new Set([
|
|
|
541
553
|
"oneOf",
|
|
542
554
|
"prefixItems"
|
|
543
555
|
]);
|
|
544
|
-
const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
545
|
-
"$defs",
|
|
546
|
-
"definitions",
|
|
547
|
-
"dependencies",
|
|
548
|
-
"dependentSchemas",
|
|
549
|
-
"patternProperties",
|
|
550
|
-
"properties"
|
|
551
|
-
]);
|
|
552
556
|
/** Normalize the detached JSON projection and report tuple changes to enclosing schemas. */
|
|
553
557
|
function normalizeAnthropicJsonSchema(schema) {
|
|
554
558
|
if (!isRecord(schema)) return false;
|
|
@@ -562,7 +566,7 @@ function normalizeAnthropicJsonSchema(schema) {
|
|
|
562
566
|
for (const entry of value) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
563
567
|
continue;
|
|
564
568
|
}
|
|
565
|
-
if (
|
|
569
|
+
if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const entry of Object.values(value)) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
566
570
|
}
|
|
567
571
|
if (Array.isArray(schema.items)) {
|
|
568
572
|
for (const entry of schema.items) normalizeAnthropicJsonSchema(entry);
|
|
@@ -643,8 +647,7 @@ function reconcileAnthropicToolChoice(choice, projection) {
|
|
|
643
647
|
...choice,
|
|
644
648
|
name: originalMatch.wireName
|
|
645
649
|
};
|
|
646
|
-
|
|
647
|
-
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);
|
|
648
651
|
if (!matchedTool) throw new Error(`Anthropic tool_choice requested unavailable tool "${requestedName}" after schema conversion`);
|
|
649
652
|
return {
|
|
650
653
|
...choice,
|
|
@@ -857,7 +860,7 @@ async function convertContentBlocks(content, model, imageBudget, profile, isErro
|
|
|
857
860
|
}
|
|
858
861
|
async function convertAnthropicMessages(transformedMessages, model, isOAuthToken, options) {
|
|
859
862
|
const params = [];
|
|
860
|
-
const
|
|
863
|
+
const modelRetainsRuntimeContext = bindsClaudeThinkingPrefix(model);
|
|
861
864
|
const imageBudget = createAnthropicInlineImageBudget();
|
|
862
865
|
const allowReasoningContentReplay = options.allowReasoningContentReplay === true;
|
|
863
866
|
const replayThinkingEnabled = options.replayThinkingEnabled !== false;
|
|
@@ -867,40 +870,32 @@ async function convertAnthropicMessages(transformedMessages, model, isOAuthToken
|
|
|
867
870
|
const msg = transformedMessages[i];
|
|
868
871
|
if (!msg) continue;
|
|
869
872
|
if (msg.role === "user") {
|
|
873
|
+
let content;
|
|
870
874
|
if (typeof msg.content === "string") {
|
|
871
|
-
if (msg.content.trim().length
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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;
|
|
880
893
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
text: NON_VISION_USER_IMAGE_PLACEHOLDER
|
|
884
|
-
} : item)).map((item) => item.type === "text" ? {
|
|
885
|
-
type: "text",
|
|
886
|
-
text: sanitizeTransportPayloadText(item.text)
|
|
887
|
-
} : {
|
|
888
|
-
type: "image",
|
|
889
|
-
source: {
|
|
890
|
-
type: "base64",
|
|
891
|
-
media_type: resolveAnthropicImageMediaType(item.mimeType),
|
|
892
|
-
data: item.data
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
let filteredBlocks = !managed || model.input.includes("image") ? blocks : blocks.filter((block) => block.type !== "image");
|
|
896
|
-
filteredBlocks = filteredBlocks.filter((block) => block.type !== "text" || block.text.trim().length > 0);
|
|
897
|
-
if (filteredBlocks.length === 0) continue;
|
|
898
|
-
if (msg.runtimeContextCarrier && !retainRuntimeContext) options.cacheBreakpointOptOutMessageIndexes?.add(params.length);
|
|
899
|
-
const userParam = {
|
|
894
|
+
if (msg.runtimeContextCarrier && !(msg.runtimeContextCarrierRetained ?? modelRetainsRuntimeContext)) options.cacheBreakpointOptOutMessageIndexes?.add(params.length);
|
|
895
|
+
params.push({
|
|
900
896
|
role: "user",
|
|
901
|
-
content
|
|
902
|
-
};
|
|
903
|
-
params.push(userParam);
|
|
897
|
+
content
|
|
898
|
+
});
|
|
904
899
|
continue;
|
|
905
900
|
}
|
|
906
901
|
if (msg.role === "assistant") {
|
|
@@ -936,24 +931,14 @@ async function convertAnthropicMessages(transformedMessages, model, isOAuthToken
|
|
|
936
931
|
type: "text",
|
|
937
932
|
text: sanitizeTransportPayloadText(block.thinking)
|
|
938
933
|
});
|
|
939
|
-
else {
|
|
940
|
-
const thinking =
|
|
941
|
-
if (thinkingSignature === "reasoning_content") {
|
|
942
|
-
if (allowReasoningContentReplay) {
|
|
943
|
-
blocks.push({
|
|
944
|
-
type: "thinking",
|
|
945
|
-
thinking,
|
|
946
|
-
signature: thinkingSignature ?? ""
|
|
947
|
-
});
|
|
948
|
-
reasoningContent.push(thinking);
|
|
949
|
-
}
|
|
950
|
-
continue;
|
|
951
|
-
}
|
|
934
|
+
else if (!isReasoningContent || allowReasoningContentReplay) {
|
|
935
|
+
const thinking = isReasoningContent ? sanitizeTransportPayloadText(block.thinking) : block.thinking;
|
|
952
936
|
blocks.push({
|
|
953
937
|
type: "thinking",
|
|
954
938
|
thinking,
|
|
955
939
|
signature: thinkingSignature ?? ""
|
|
956
940
|
});
|
|
941
|
+
if (isReasoningContent) reasoningContent.push(thinking);
|
|
957
942
|
}
|
|
958
943
|
continue;
|
|
959
944
|
}
|
|
@@ -1028,14 +1013,14 @@ function buildAnthropicGenerationParams({ model, options, tools, toolProjection,
|
|
|
1028
1013
|
budget_tokens: options?.thinkingBudgetTokens ?? 1024,
|
|
1029
1014
|
...profile === "provider" ? { display } : {}
|
|
1030
1015
|
};
|
|
1031
|
-
} else if (options?.thinkingEnabled === false) params.thinking = { type: "disabled" };
|
|
1016
|
+
} else if (options?.thinkingEnabled === false) params.thinking = requiresClaudeBetweenToolsThinking(model) ? { type: "between_tools" } : { type: "disabled" };
|
|
1032
1017
|
}
|
|
1033
1018
|
if (options?.metadata) {
|
|
1034
1019
|
const userId = options.metadata.user_id;
|
|
1035
1020
|
if (typeof userId === "string") params.metadata = { user_id: userId };
|
|
1036
1021
|
}
|
|
1037
1022
|
if (options?.toolChoice) {
|
|
1038
|
-
const normalizedToolChoice = normalizeAnthropicToolChoice(mandatoryAdaptiveThinking || options?.thinkingEnabled === true, options.toolChoice);
|
|
1023
|
+
const normalizedToolChoice = normalizeAnthropicToolChoice(mandatoryAdaptiveThinking || options?.thinkingEnabled === true || resolveClaudeSonnet55ModelIdentity(model) !== void 0, options.toolChoice);
|
|
1039
1024
|
const projectedToolChoice = toolProjection ? reconcileAnthropicToolChoice(normalizedToolChoice, toolProjection) : normalizedToolChoice;
|
|
1040
1025
|
if (projectedToolChoice) params.tool_choice = projectedToolChoice;
|
|
1041
1026
|
}
|
|
@@ -1043,19 +1028,17 @@ function buildAnthropicGenerationParams({ model, options, tools, toolProjection,
|
|
|
1043
1028
|
}
|
|
1044
1029
|
function convertAnthropicTools(tools, isOAuthTokenLocal, supportsEagerToolInputStreaming = false) {
|
|
1045
1030
|
const projection = projectAnthropicTools(tools, (name) => isOAuthTokenLocal ? toClaudeCodeToolName(name) : name);
|
|
1046
|
-
const convertedTools = [];
|
|
1047
|
-
for (const tool of projection.tools) {
|
|
1048
|
-
const convertedTool = {
|
|
1049
|
-
name: tool.wireName,
|
|
1050
|
-
description: tool.description,
|
|
1051
|
-
input_schema: tool.inputSchema
|
|
1052
|
-
};
|
|
1053
|
-
if (supportsEagerToolInputStreaming) convertedTool.eager_input_streaming = true;
|
|
1054
|
-
convertedTools.push(convertedTool);
|
|
1055
|
-
}
|
|
1056
1031
|
return {
|
|
1057
1032
|
projection,
|
|
1058
|
-
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
|
+
})
|
|
1059
1042
|
};
|
|
1060
1043
|
}
|
|
1061
1044
|
//#endregion
|
|
@@ -1198,11 +1181,16 @@ function applyAnthropicMessageDeltaUsage(target, usage, messageStartPromptUsage)
|
|
|
1198
1181
|
cacheWrite: cacheWriteTokens,
|
|
1199
1182
|
cacheWrite1h: readAnthropicCacheWriteUsage(usage).cacheWrite1h
|
|
1200
1183
|
};
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
+
}
|
|
1206
1194
|
target.totalTokens = target.input + target.output + target.cacheRead + target.cacheWrite;
|
|
1207
1195
|
const iterationUsage = readLastAnthropicIterationUsage(usage);
|
|
1208
1196
|
if (iterationUsage.state === "valid") target.contextUsage = {
|
|
@@ -1230,7 +1218,6 @@ async function consumeAnthropicStream(params) {
|
|
|
1230
1218
|
let costModel = model;
|
|
1231
1219
|
let messageStartPromptUsage;
|
|
1232
1220
|
let inputTransformations;
|
|
1233
|
-
const anthropicStream = params.events;
|
|
1234
1221
|
try {
|
|
1235
1222
|
const blocks = output.content;
|
|
1236
1223
|
const blockIndexes = /* @__PURE__ */ new Map();
|
|
@@ -1240,8 +1227,10 @@ async function consumeAnthropicStream(params) {
|
|
|
1240
1227
|
const compactionCapture = createCompactionCapture(output, model, options);
|
|
1241
1228
|
const pendingThinkingSignatures = /* @__PURE__ */ new Map();
|
|
1242
1229
|
const allowReasoningContentReplay = managed && resolveProviderEndpoint(model).endpointClass === "xiaomi-native";
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1230
|
+
const reasoningContentBlocks = {
|
|
1231
|
+
thinking: /* @__PURE__ */ new Map(),
|
|
1232
|
+
text: /* @__PURE__ */ new Map()
|
|
1233
|
+
};
|
|
1245
1234
|
let sawMessageStart = false;
|
|
1246
1235
|
let sawMessageStop = false;
|
|
1247
1236
|
let sawStopReason = false;
|
|
@@ -1255,64 +1244,39 @@ async function consumeAnthropicStream(params) {
|
|
|
1255
1244
|
else eventSink.push(event);
|
|
1256
1245
|
};
|
|
1257
1246
|
const eventIndexKey = (eventIndex) => typeof eventIndex === "number" ? eventIndex : -1;
|
|
1258
|
-
const
|
|
1247
|
+
const appendReasoningContentDelta = (kind, eventIndex, rawText) => {
|
|
1259
1248
|
if (typeof rawText !== "string") return false;
|
|
1260
1249
|
const text = sanitizeTransportPayloadText(rawText);
|
|
1261
1250
|
if (text.length === 0) return false;
|
|
1251
|
+
const indexes = reasoningContentBlocks[kind];
|
|
1262
1252
|
const key = eventIndexKey(eventIndex);
|
|
1263
|
-
let contentIndex =
|
|
1253
|
+
let contentIndex = indexes.get(key);
|
|
1264
1254
|
let block = contentIndex === void 0 ? void 0 : blocks[contentIndex];
|
|
1265
|
-
if (!block || block.type !==
|
|
1266
|
-
block = {
|
|
1255
|
+
if (!block || block.type !== kind) {
|
|
1256
|
+
block = kind === "thinking" ? {
|
|
1267
1257
|
type: "thinking",
|
|
1268
1258
|
thinking: "",
|
|
1269
1259
|
thinkingSignature: "reasoning_content"
|
|
1270
|
-
}
|
|
1271
|
-
output.content.push(block);
|
|
1272
|
-
contentIndex = output.content.length - 1;
|
|
1273
|
-
reasoningContentThinkingBlocks.set(key, contentIndex);
|
|
1274
|
-
eventSink.push({
|
|
1275
|
-
type: "thinking_start",
|
|
1276
|
-
contentIndex,
|
|
1277
|
-
partial: output
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
if (contentIndex === void 0) return false;
|
|
1281
|
-
appendAssistantThinking(block, text);
|
|
1282
|
-
block.thinkingSignature = "reasoning_content";
|
|
1283
|
-
eventSink.push({
|
|
1284
|
-
type: "thinking_delta",
|
|
1285
|
-
contentIndex,
|
|
1286
|
-
delta: text,
|
|
1287
|
-
partial: output
|
|
1288
|
-
});
|
|
1289
|
-
return true;
|
|
1290
|
-
};
|
|
1291
|
-
const appendReasoningContentTextDelta = (eventIndex, rawText) => {
|
|
1292
|
-
if (typeof rawText !== "string") return false;
|
|
1293
|
-
const text = sanitizeTransportPayloadText(rawText);
|
|
1294
|
-
if (text.length === 0) return false;
|
|
1295
|
-
const key = eventIndexKey(eventIndex);
|
|
1296
|
-
let contentIndex = reasoningContentTextBlocks.get(key);
|
|
1297
|
-
let block = contentIndex === void 0 ? void 0 : blocks[contentIndex];
|
|
1298
|
-
if (!block || block.type !== "text") {
|
|
1299
|
-
block = {
|
|
1260
|
+
} : {
|
|
1300
1261
|
type: "text",
|
|
1301
1262
|
text: ""
|
|
1302
1263
|
};
|
|
1303
1264
|
output.content.push(block);
|
|
1304
1265
|
contentIndex = output.content.length - 1;
|
|
1305
|
-
|
|
1266
|
+
indexes.set(key, contentIndex);
|
|
1306
1267
|
eventSink.push({
|
|
1307
|
-
type:
|
|
1268
|
+
type: `${kind}_start`,
|
|
1308
1269
|
contentIndex,
|
|
1309
1270
|
partial: output
|
|
1310
1271
|
});
|
|
1311
1272
|
}
|
|
1312
1273
|
if (contentIndex === void 0) return false;
|
|
1313
|
-
block.
|
|
1274
|
+
if (block.type === "thinking") {
|
|
1275
|
+
appendAssistantThinking(block, text);
|
|
1276
|
+
block.thinkingSignature = "reasoning_content";
|
|
1277
|
+
} else if (block.type === "text") block.text += text;
|
|
1314
1278
|
eventSink.push({
|
|
1315
|
-
type:
|
|
1279
|
+
type: `${kind}_delta`,
|
|
1316
1280
|
contentIndex,
|
|
1317
1281
|
delta: text,
|
|
1318
1282
|
partial: output
|
|
@@ -1321,29 +1285,21 @@ async function consumeAnthropicStream(params) {
|
|
|
1321
1285
|
};
|
|
1322
1286
|
const finishReasoningContentSidecars = (eventIndex) => {
|
|
1323
1287
|
const key = eventIndexKey(eventIndex);
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
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,
|
|
1332
1298
|
partial: output
|
|
1333
1299
|
});
|
|
1334
1300
|
}
|
|
1335
|
-
const textContentIndex = reasoningContentTextBlocks.get(key);
|
|
1336
|
-
if (textContentIndex === void 0) return;
|
|
1337
|
-
reasoningContentTextBlocks.delete(key);
|
|
1338
|
-
const block = output.content[textContentIndex];
|
|
1339
|
-
if (block?.type === "text") eventSink.push({
|
|
1340
|
-
type: "text_end",
|
|
1341
|
-
contentIndex: textContentIndex,
|
|
1342
|
-
content: block.text,
|
|
1343
|
-
partial: output
|
|
1344
|
-
});
|
|
1345
1301
|
};
|
|
1346
|
-
for await (const rawEvent of
|
|
1302
|
+
for await (const rawEvent of iterateModelStream(params.events, options.signal)) {
|
|
1347
1303
|
const event = asRecord(rawEvent);
|
|
1348
1304
|
inputTransformations = readAnthropicInputTransformations(event) ?? inputTransformations;
|
|
1349
1305
|
if (managed) notifyLlmRequestActivity(options.signal);
|
|
@@ -1516,7 +1472,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1516
1472
|
let index = eventIndex === void 0 ? void 0 : blockIndexes.get(eventIndex);
|
|
1517
1473
|
let block = index === void 0 ? void 0 : blocks[index];
|
|
1518
1474
|
if (allowReasoningContentReplay) {
|
|
1519
|
-
const appendedThinking =
|
|
1475
|
+
const appendedThinking = appendReasoningContentDelta("thinking", event.index, delta?.reasoning_content);
|
|
1520
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";
|
|
1521
1477
|
let appendedContent = false;
|
|
1522
1478
|
if (!hasNativeAnthropicDelta && typeof delta?.content === "string" && delta.content.length > 0) {
|
|
@@ -1531,7 +1487,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1531
1487
|
partial: output
|
|
1532
1488
|
});
|
|
1533
1489
|
appendedContent = true;
|
|
1534
|
-
} else appendedContent =
|
|
1490
|
+
} else appendedContent = appendReasoningContentDelta("text", event.index, text);
|
|
1535
1491
|
}
|
|
1536
1492
|
}
|
|
1537
1493
|
if ((appendedThinking || appendedContent) && !hasNativeAnthropicDelta) continue;
|
|
@@ -1607,17 +1563,13 @@ async function consumeAnthropicStream(params) {
|
|
|
1607
1563
|
}
|
|
1608
1564
|
blockIndexes.delete(eventIndex);
|
|
1609
1565
|
delete block.index;
|
|
1610
|
-
if (block.type === "text") {
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
finishReasoningContentSidecars(event.index);
|
|
1618
|
-
continue;
|
|
1619
|
-
}
|
|
1620
|
-
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") {
|
|
1621
1573
|
if (pendingSignature !== void 0) block.thinkingSignature = pendingSignature;
|
|
1622
1574
|
eventSink.push({
|
|
1623
1575
|
type: "thinking_end",
|
|
@@ -1625,16 +1577,11 @@ async function consumeAnthropicStream(params) {
|
|
|
1625
1577
|
content: block.thinking,
|
|
1626
1578
|
partial: output
|
|
1627
1579
|
});
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
block,
|
|
1634
|
-
contentIndex: index
|
|
1635
|
-
});
|
|
1636
|
-
finishReasoningContentSidecars(event.index);
|
|
1637
|
-
}
|
|
1580
|
+
} else if (block.type === "toolCall") sealedToolCalls.push({
|
|
1581
|
+
block,
|
|
1582
|
+
contentIndex: index
|
|
1583
|
+
});
|
|
1584
|
+
finishReasoningContentSidecars(event.index);
|
|
1638
1585
|
continue;
|
|
1639
1586
|
}
|
|
1640
1587
|
if (event.type === "message_delta") {
|
|
@@ -1675,4 +1622,4 @@ async function consumeAnthropicStream(params) {
|
|
|
1675
1622
|
}
|
|
1676
1623
|
}
|
|
1677
1624
|
//#endregion
|
|
1678
|
-
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 };
|