@openclaw/ai 2026.9.1-beta.1 → 2026.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-DI4PZKKB.mjs → anthropic-BDdqdVLK.mjs} +222 -216
- package/dist/{anthropic-compaction-replay-nhKaCXu6.mjs → anthropic-compaction-replay-DB2FGLQc.mjs} +160 -68
- package/dist/{anthropic-payload-policy-B_0n0enE.d.mts → anthropic-payload-policy-d46X2pR0.d.mts} +28 -4
- package/dist/{api-registry-CTd8NzcD.d.mts → api-registry-DWtPjzyn.d.mts} +2 -2
- package/dist/{azure-openai-responses-D8dI0ekg.mjs → azure-openai-responses-C5bZRfAP.mjs} +12 -9
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/{diagnostics-COpOtRwq.mjs → diagnostics-CPeq9F7y.mjs} +5 -1
- package/dist/diagnostics-DfFyKeX_.mjs +136 -0
- package/dist/{diagnostics-BaTA9eVl.d.mts → diagnostics-DnPnOui6.d.mts} +5 -1
- package/dist/diagnostics.d.mts +8 -3
- package/dist/diagnostics.mjs +4 -3
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-BgDvQeum.mjs} +3 -9
- package/dist/{event-stream-LiXePESD.d.mts → event-stream-BhT5T1Ay.d.mts} +1 -1
- package/dist/event-stream-zctLx0yr.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-Od-LLdVK.mjs → google-4qeuE8iX.mjs} +9 -7
- package/dist/{google-shared-Bgr9lFPw.mjs → google-shared-CWeG8RIl.mjs} +27 -23
- package/dist/{google-vertex-aerRSXc4.mjs → google-vertex-O9BcnB6X.mjs} +8 -6
- package/dist/{host-D51fmkH6.mjs → host-CEvLw30U.mjs} +54 -9
- package/dist/{host-DsbPMFU6.d.mts → host-DjzGmdZ2.d.mts} +3 -3
- package/dist/index-FnHM2FcI.d.mts +117 -0
- package/dist/index.d.mts +10 -11
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +59 -55
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +66 -64
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +43 -43
- package/dist/internal/runtime.mjs +10 -8
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +95 -4
- package/dist/{mistral-EiHdymeb.mjs → mistral-Tb6oalqH.mjs} +30 -23
- package/dist/{openai-chatgpt-responses-DHpF9o1e.mjs → openai-chatgpt-responses-yUXjPNfu.mjs} +76 -137
- package/dist/{openai-completions-EFPiUGfS.mjs → openai-completions-BIUV3RDT.mjs} +26 -22
- package/dist/{openai-completions-compat-BefmHT26.d.mts → openai-completions-compat-CpjYUArk.d.mts} +5 -5
- package/dist/{openai-completions-stream-DUlGwRMz.mjs → openai-completions-stream-BsrBe3Gg.mjs} +103 -96
- package/dist/openai-prompt-cache-CGnVB74a.mjs +21 -0
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +16 -0
- package/dist/{openai-responses-BogP8OjX.mjs → openai-responses-CCL41ALM.mjs} +15 -14
- package/dist/openai-responses-compaction-window-BMVHFOtq.mjs +697 -0
- package/dist/{openai-responses-contracts-Dvj_UtPy.d.mts → openai-responses-contracts-rF5DDRNS.d.mts} +23 -6
- package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-Cd4hJG-S.mjs → openai-responses-prompt-observer-internal-D0bhBfgL.mjs} +4 -18
- package/dist/{openai-responses-shared-DJThc6jW.mjs → openai-responses-shared-Bmma_3Qc.mjs} +438 -309
- package/dist/{openai-tool-schema-ho-hIkQf.mjs → openai-tool-schema-_pTAJqKF.mjs} +30 -40
- package/dist/{provider-error-DDOs_Bz0.mjs → provider-error-9TraxGvt.mjs} +20 -92
- package/dist/{provider-options-MdMBLzlU.d.mts → provider-options-Bcc_p-TU.d.mts} +26 -6
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-C01bQ5a3.mjs → provider-transcript-transform-BaMbI1hr.mjs} +1 -1
- package/dist/provider-types.d.mts +19 -20
- package/dist/providers.d.mts +6 -6
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-DLCNXki6.mjs} +158 -94
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-DCkltN94.mjs → sanitize-unicode-D6xUvZaS.mjs} +2 -8
- package/dist/{simple-options-CFj7x3J4.mjs → simple-options-BjHCCh4v.mjs} +42 -6
- package/dist/{src-Bu3FiFAG.mjs → src-2qBGKg8O.mjs} +83 -2
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{tool-schema-json-projection-qvTEs5Am.mjs → tool-schema-json-projection-mJhXDcyz.mjs} +21 -31
- package/dist/{transport-stream-shared-ljShVIZB.mjs → transport-stream-shared-CZqMhfIw.mjs} +19 -6
- package/dist/{transport-stream-shared-rvaCyFYt.d.mts → transport-stream-shared-xnaqxmbP.d.mts} +5 -5
- package/dist/{transport-utils-LJ1_rbi-.mjs → transport-utils-7il795_9.mjs} +5 -8
- package/dist/transports.d.mts +121 -85
- package/dist/transports.mjs +747 -464
- package/dist/types-3Lnm-QSJ.d.mts +1 -0
- package/dist/{types-DhLoJbFm.d.mts → types-CJ1-Ht7A.d.mts} +55 -19
- package/dist/types.d.mts +7 -7
- package/dist/types.mjs +5 -5
- package/dist/{validation-Dk7q7NMN.d.mts → validation-AKZBDGQd.d.mts} +1 -1
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +5 -5
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BKp4fOt_.d.mts +0 -1
- package/dist/index-Qbej8io0.d.mts +0 -3
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/openai-responses-contracts-QUY12X0B.mjs +0 -233
- package/dist/openai-responses-payload-policy-D8EdimYe.mjs +0 -204
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/types-GiAjXatj.d.mts +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { _ as supportsClaudeAdaptiveThinking, b as supportsClaudeNativeXhighEffort, h as resolveClaudeSonnet5ModelIdentity, m as resolveClaudeOpus5ModelIdentity } from "./src-2qBGKg8O.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
4
4
|
import { o as isRecord } from "./utf16-slice-qz3nsy87.mjs";
|
|
5
|
-
import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
6
|
-
import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-
|
|
7
|
-
import { n as
|
|
5
|
+
import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
6
|
+
import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-CEvLw30U.mjs";
|
|
7
|
+
import { A as createAnthropicInlineImageBudget, B as resolveAnthropicContextManagementBetaHeader, C as ANTHROPIC_SERVER_SIDE_FALLBACKS, D as readAnthropicFallbackBoundary, E as applyAnthropicFallbackBoundary, G as omitFoundryBearerCredentialHeaders, K as usesFoundryBearerAuth, M as resolveAnthropicImageMediaType, N as applyAnthropicCacheControlToMessages, O as resolveAnthropicFallbackServingModelCost, P as applyAnthropicContextManagementToRequest, R as isDirectAnthropicModel, S as readAnthropicInputTransformations, W as isAnthropicOAuthApiKey, _ as toClaudeCodeToolName, a as suppressAnthropicCompaction, b as findActiveAnthropicToolTurnAssistantIndex, f as normalizeAnthropicToolCallId, g as resolveOriginalAnthropicToolName, h as reconcileAnthropicToolChoice, j as normalizeAnthropicInlineContent, k as applyAnthropicRefusal, m as projectAnthropicTools, n as createCompactionCapture, o as applyAnthropicMessageDeltaUsage, p as normalizeAnthropicToolChoice, r as isAnthropicReplayRejection, s as applyAnthropicMessageStartUsage, t as buildAnthropicReplayPlan, v as ANTHROPIC_OMITTED_REASONING_TEXT, w as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, x as logAnthropicThinkingDrops, y as applyAnthropicThinkingBindingControls, z as logAnthropicContextEdits } from "./anthropic-compaction-replay-DB2FGLQc.mjs";
|
|
8
8
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
11
|
-
import {
|
|
12
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-
|
|
9
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "./simple-options-BjHCCh4v.mjs";
|
|
10
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-7il795_9.mjs";
|
|
11
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-CZqMhfIw.mjs";
|
|
13
13
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
14
14
|
import { n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
15
15
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
16
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
16
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BaMbI1hr.mjs";
|
|
17
17
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
18
18
|
import Anthropic from "@anthropic-ai/sdk";
|
|
19
19
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
@@ -108,11 +108,12 @@ const ANTHROPIC_MESSAGE_EVENTS = /* @__PURE__ */ new Set([
|
|
|
108
108
|
"content_block_delta",
|
|
109
109
|
"content_block_stop"
|
|
110
110
|
]);
|
|
111
|
-
async function* iterateAnthropicEvents(response, requireMessageStop = false) {
|
|
111
|
+
async function* iterateAnthropicEvents(response, requireMessageStop = false, signal) {
|
|
112
112
|
if (!response.body) throw new Error("Attempted to iterate over an Anthropic response with no body");
|
|
113
113
|
let sawMessageEnd = false;
|
|
114
114
|
for await (const sse of Stream.rawEvents(response)) {
|
|
115
115
|
if (sse.event === "error") throw new Error(sse.data);
|
|
116
|
+
notifyLlmRequestActivity(signal);
|
|
116
117
|
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) continue;
|
|
117
118
|
try {
|
|
118
119
|
const event = parseJsonWithRepair(sse.data);
|
|
@@ -153,15 +154,17 @@ const streamAnthropic = (model, context, options) => {
|
|
|
153
154
|
stopReason: "stop",
|
|
154
155
|
timestamp: Date.now()
|
|
155
156
|
};
|
|
156
|
-
const refusalBuffer = usesClaudeStreamingRefusalContract(model) ? createDeferredEventBuffer(stream
|
|
157
|
+
const refusalBuffer = usesClaudeStreamingRefusalContract(model) ? createDeferredEventBuffer(stream) : void 0;
|
|
157
158
|
const eventSink = refusalBuffer ?? stream;
|
|
158
159
|
let costModel = model;
|
|
159
160
|
let messageStartPromptUsage;
|
|
160
161
|
let usedCompactionReplay = false;
|
|
162
|
+
let inputTransformations;
|
|
161
163
|
try {
|
|
162
164
|
let client;
|
|
163
165
|
let isOAuth;
|
|
164
166
|
let serverSideFallback = false;
|
|
167
|
+
let directApiKeyBetaHeader;
|
|
165
168
|
if (requestOptions?.client) {
|
|
166
169
|
client = requestOptions.client;
|
|
167
170
|
isOAuth = false;
|
|
@@ -180,18 +183,22 @@ const streamAnthropic = (model, context, options) => {
|
|
|
180
183
|
client = created.client;
|
|
181
184
|
isOAuth = created.isOAuthToken;
|
|
182
185
|
serverSideFallback = created.serverSideFallback;
|
|
186
|
+
directApiKeyBetaHeader = created.directApiKeyBetaHeader;
|
|
183
187
|
}
|
|
184
188
|
const builtParams = await buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback);
|
|
185
189
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
186
190
|
let params = builtParams.params;
|
|
187
191
|
const toolProjection = builtParams.toolProjection;
|
|
192
|
+
applyAnthropicContextManagementToRequest(params, model, requestOptions, directApiKeyBetaHeader);
|
|
188
193
|
const nextParams = await requestOptions?.onPayload?.(params, model);
|
|
189
194
|
if (nextParams !== void 0) params = nextParams;
|
|
190
195
|
applyClaudeRequestContract(params, model);
|
|
196
|
+
const betaHeader = resolveAnthropicContextManagementBetaHeader(params, directApiKeyBetaHeader);
|
|
191
197
|
const sdkRequestOptions = {
|
|
192
198
|
...requestOptions?.signal ? { signal: requestOptions.signal } : {},
|
|
193
199
|
...requestOptions?.timeoutMs !== void 0 ? { timeout: requestOptions.timeoutMs } : {},
|
|
194
|
-
maxRetries:
|
|
200
|
+
maxRetries: 0,
|
|
201
|
+
headers: applyAnthropicThinkingBindingControls(params, betaHeader) ?? (betaHeader !== void 0 ? { "anthropic-beta": betaHeader } : void 0)
|
|
195
202
|
};
|
|
196
203
|
const response = await client.messages.create({
|
|
197
204
|
...params,
|
|
@@ -207,200 +214,206 @@ const streamAnthropic = (model, context, options) => {
|
|
|
207
214
|
const toolArgumentPreviewSchedules = /* @__PURE__ */ new WeakMap();
|
|
208
215
|
const sealedToolCalls = [];
|
|
209
216
|
const compactionCapture = createCompactionCapture(output, model, requestOptions);
|
|
210
|
-
const requireMessageStop = refusalBuffer !== void 0 ||
|
|
211
|
-
for await (const event of iterateAnthropicEvents(response, requireMessageStop))
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
type: "start",
|
|
218
|
-
partial: output
|
|
219
|
-
});
|
|
220
|
-
} else if (event.type === "content_block_start") {
|
|
221
|
-
const rawContentBlock = isRecord(event.content_block) ? event.content_block : void 0;
|
|
222
|
-
if (requestOptions?.anthropicServerCompaction === true && compactionCapture.begin(event.index, rawContentBlock, output.content.length)) continue;
|
|
223
|
-
const fallbackBoundary = refusalBuffer ? readAnthropicFallbackBoundary(event.content_block) : null;
|
|
224
|
-
if (fallbackBoundary) {
|
|
225
|
-
refusalBuffer?.discard();
|
|
226
|
-
sealedToolCalls.length = 0;
|
|
227
|
-
blockIndexes.clear();
|
|
228
|
-
applyAnthropicFallbackBoundary({
|
|
229
|
-
output,
|
|
230
|
-
boundary: fallbackBoundary,
|
|
231
|
-
provider: model.provider
|
|
232
|
-
});
|
|
233
|
-
costModel = {
|
|
234
|
-
...model,
|
|
235
|
-
cost: resolveAnthropicFallbackServingModelCost({
|
|
236
|
-
requestedModelId: model.id,
|
|
237
|
-
servingModelId: fallbackBoundary.toModel,
|
|
238
|
-
requestedCost: model.cost
|
|
239
|
-
})
|
|
240
|
-
};
|
|
217
|
+
const requireMessageStop = refusalBuffer !== void 0 || isDirectAnthropicModel(model);
|
|
218
|
+
for await (const event of iterateAnthropicEvents(response, requireMessageStop, requestOptions?.signal)) {
|
|
219
|
+
inputTransformations = readAnthropicInputTransformations(event) ?? inputTransformations;
|
|
220
|
+
if (event.type === "message_start") {
|
|
221
|
+
output.responseId = event.message.id;
|
|
222
|
+
output.responseModel = event.message.model;
|
|
223
|
+
messageStartPromptUsage = applyAnthropicMessageStartUsage(output.usage, event.message.usage);
|
|
241
224
|
calculateCost(costModel, output.usage);
|
|
242
225
|
eventSink.push({
|
|
243
226
|
type: "start",
|
|
244
227
|
partial: output
|
|
245
228
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
} else if (event.type === "content_block_start") {
|
|
230
|
+
const rawContentBlock = isRecord(event.content_block) ? event.content_block : void 0;
|
|
231
|
+
if (requestOptions?.anthropicServerCompaction === true && compactionCapture.begin(event.index, rawContentBlock, output.content.length)) continue;
|
|
232
|
+
const fallbackBoundary = refusalBuffer ? readAnthropicFallbackBoundary(event.content_block) : null;
|
|
233
|
+
if (fallbackBoundary) {
|
|
234
|
+
refusalBuffer?.discard();
|
|
235
|
+
sealedToolCalls.length = 0;
|
|
236
|
+
blockIndexes.clear();
|
|
237
|
+
applyAnthropicFallbackBoundary({
|
|
238
|
+
output,
|
|
239
|
+
boundary: fallbackBoundary,
|
|
240
|
+
provider: model.provider
|
|
241
|
+
});
|
|
242
|
+
costModel = {
|
|
243
|
+
...model,
|
|
244
|
+
cost: resolveAnthropicFallbackServingModelCost({
|
|
245
|
+
requestedModelId: model.id,
|
|
246
|
+
servingModelId: fallbackBoundary.toModel,
|
|
247
|
+
requestedCost: model.cost
|
|
248
|
+
})
|
|
249
|
+
};
|
|
250
|
+
calculateCost(costModel, output.usage);
|
|
251
|
+
eventSink.push({
|
|
252
|
+
type: "start",
|
|
253
|
+
partial: output
|
|
254
|
+
});
|
|
255
|
+
for (const [i, block] of blocks.entries()) {
|
|
256
|
+
if (block.type !== "text") continue;
|
|
257
|
+
delete block.index;
|
|
258
|
+
eventSink.push({
|
|
259
|
+
type: "text_start",
|
|
260
|
+
contentIndex: i,
|
|
261
|
+
partial: output
|
|
262
|
+
});
|
|
263
|
+
if (block.text) eventSink.push({
|
|
264
|
+
type: "text_delta",
|
|
265
|
+
contentIndex: i,
|
|
266
|
+
delta: block.text,
|
|
267
|
+
partial: output
|
|
268
|
+
});
|
|
269
|
+
eventSink.push({
|
|
270
|
+
type: "text_end",
|
|
271
|
+
contentIndex: i,
|
|
272
|
+
content: block.text,
|
|
273
|
+
partial: output
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
} else if (event.content_block.type === "text") {
|
|
277
|
+
const block = {
|
|
278
|
+
type: "text",
|
|
279
|
+
text: "",
|
|
280
|
+
index: event.index
|
|
281
|
+
};
|
|
282
|
+
output.content.push(block);
|
|
283
|
+
blockIndexes.set(event.index, output.content.length - 1);
|
|
249
284
|
eventSink.push({
|
|
250
285
|
type: "text_start",
|
|
251
|
-
contentIndex:
|
|
286
|
+
contentIndex: output.content.length - 1,
|
|
252
287
|
partial: output
|
|
253
288
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
289
|
+
} else if (event.content_block.type === "thinking") {
|
|
290
|
+
const block = {
|
|
291
|
+
type: "thinking",
|
|
292
|
+
thinking: "",
|
|
293
|
+
thinkingSignature: "",
|
|
294
|
+
index: event.index
|
|
295
|
+
};
|
|
296
|
+
output.content.push(block);
|
|
297
|
+
blockIndexes.set(event.index, output.content.length - 1);
|
|
298
|
+
eventSink.push({
|
|
299
|
+
type: "thinking_start",
|
|
300
|
+
contentIndex: output.content.length - 1,
|
|
258
301
|
partial: output
|
|
259
302
|
});
|
|
303
|
+
} else if (event.content_block.type === "redacted_thinking") {
|
|
304
|
+
const block = {
|
|
305
|
+
type: "thinking",
|
|
306
|
+
thinking: "[Reasoning redacted]",
|
|
307
|
+
thinkingSignature: event.content_block.data,
|
|
308
|
+
redacted: true,
|
|
309
|
+
index: event.index
|
|
310
|
+
};
|
|
311
|
+
output.content.push(block);
|
|
312
|
+
blockIndexes.set(event.index, output.content.length - 1);
|
|
260
313
|
eventSink.push({
|
|
261
|
-
type: "
|
|
262
|
-
contentIndex:
|
|
263
|
-
content: block.text,
|
|
314
|
+
type: "thinking_start",
|
|
315
|
+
contentIndex: output.content.length - 1,
|
|
264
316
|
partial: output
|
|
265
317
|
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
partial: output
|
|
279
|
-
});
|
|
280
|
-
} else if (event.content_block.type === "thinking") {
|
|
281
|
-
const block = {
|
|
282
|
-
type: "thinking",
|
|
283
|
-
thinking: "",
|
|
284
|
-
thinkingSignature: "",
|
|
285
|
-
index: event.index
|
|
286
|
-
};
|
|
287
|
-
output.content.push(block);
|
|
288
|
-
blockIndexes.set(event.index, output.content.length - 1);
|
|
289
|
-
eventSink.push({
|
|
290
|
-
type: "thinking_start",
|
|
291
|
-
contentIndex: output.content.length - 1,
|
|
292
|
-
partial: output
|
|
293
|
-
});
|
|
294
|
-
} else if (event.content_block.type === "redacted_thinking") {
|
|
295
|
-
const block = {
|
|
296
|
-
type: "thinking",
|
|
297
|
-
thinking: "[Reasoning redacted]",
|
|
298
|
-
thinkingSignature: event.content_block.data,
|
|
299
|
-
redacted: true,
|
|
300
|
-
index: event.index
|
|
301
|
-
};
|
|
302
|
-
output.content.push(block);
|
|
303
|
-
blockIndexes.set(event.index, output.content.length - 1);
|
|
304
|
-
eventSink.push({
|
|
305
|
-
type: "thinking_start",
|
|
306
|
-
contentIndex: output.content.length - 1,
|
|
307
|
-
partial: output
|
|
308
|
-
});
|
|
309
|
-
} else if (event.content_block.type === "tool_use") {
|
|
310
|
-
const block = {
|
|
311
|
-
type: "toolCall",
|
|
312
|
-
id: event.content_block.id,
|
|
313
|
-
name: isOAuth ? resolveOriginalAnthropicToolName(event.content_block.name, toolProjection) : event.content_block.name,
|
|
314
|
-
arguments: event.content_block.input ?? {},
|
|
315
|
-
partialJson: "",
|
|
316
|
-
index: event.index
|
|
317
|
-
};
|
|
318
|
-
output.content.push(block);
|
|
319
|
-
blockIndexes.set(event.index, output.content.length - 1);
|
|
320
|
-
toolArgumentPreviewSchedules.set(block, createToolArgumentPreviewSchedule());
|
|
321
|
-
eventSink.push({
|
|
322
|
-
type: "toolcall_start",
|
|
323
|
-
contentIndex: output.content.length - 1,
|
|
324
|
-
partial: output
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
} else if (event.type === "content_block_delta") {
|
|
328
|
-
const rawDelta = isRecord(event.delta) ? event.delta : void 0;
|
|
329
|
-
if (compactionCapture.delta(event.index, rawDelta)) continue;
|
|
330
|
-
else if (event.delta.type === "text_delta") {
|
|
331
|
-
const index = blockIndexes.get(event.index);
|
|
332
|
-
const block = index === void 0 ? void 0 : blocks[index];
|
|
333
|
-
if (index !== void 0 && block?.type === "text") {
|
|
334
|
-
block.text += event.delta.text;
|
|
318
|
+
} else if (event.content_block.type === "tool_use") {
|
|
319
|
+
const block = {
|
|
320
|
+
type: "toolCall",
|
|
321
|
+
id: event.content_block.id,
|
|
322
|
+
name: isOAuth ? resolveOriginalAnthropicToolName(event.content_block.name, toolProjection) : event.content_block.name,
|
|
323
|
+
arguments: event.content_block.input ?? {},
|
|
324
|
+
partialJson: "",
|
|
325
|
+
index: event.index
|
|
326
|
+
};
|
|
327
|
+
output.content.push(block);
|
|
328
|
+
blockIndexes.set(event.index, output.content.length - 1);
|
|
329
|
+
toolArgumentPreviewSchedules.set(block, createToolArgumentPreviewSchedule());
|
|
335
330
|
eventSink.push({
|
|
336
|
-
type: "
|
|
337
|
-
contentIndex:
|
|
338
|
-
delta: event.delta.text,
|
|
331
|
+
type: "toolcall_start",
|
|
332
|
+
contentIndex: output.content.length - 1,
|
|
339
333
|
partial: output
|
|
340
334
|
});
|
|
341
335
|
}
|
|
342
|
-
} else if (event.
|
|
336
|
+
} else if (event.type === "content_block_delta") {
|
|
337
|
+
const rawDelta = isRecord(event.delta) ? event.delta : void 0;
|
|
338
|
+
if (compactionCapture.delta(event.index, rawDelta)) continue;
|
|
339
|
+
else if (event.delta.type === "text_delta") {
|
|
340
|
+
const index = blockIndexes.get(event.index);
|
|
341
|
+
const block = index === void 0 ? void 0 : blocks[index];
|
|
342
|
+
if (index !== void 0 && block?.type === "text") {
|
|
343
|
+
block.text += event.delta.text;
|
|
344
|
+
eventSink.push({
|
|
345
|
+
type: "text_delta",
|
|
346
|
+
contentIndex: index,
|
|
347
|
+
delta: event.delta.text,
|
|
348
|
+
partial: output
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
} else if (event.delta.type === "thinking_delta") {
|
|
352
|
+
const index = blockIndexes.get(event.index);
|
|
353
|
+
const block = index === void 0 ? void 0 : blocks[index];
|
|
354
|
+
if (index !== void 0 && block?.type === "thinking") {
|
|
355
|
+
block.thinking += event.delta.thinking;
|
|
356
|
+
eventSink.push({
|
|
357
|
+
type: "thinking_delta",
|
|
358
|
+
contentIndex: index,
|
|
359
|
+
delta: event.delta.thinking,
|
|
360
|
+
partial: output
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
} else if (event.delta.type === "input_json_delta") {
|
|
364
|
+
const index = blockIndexes.get(event.index);
|
|
365
|
+
const block = index === void 0 ? void 0 : blocks[index];
|
|
366
|
+
if (index !== void 0 && block?.type === "toolCall") {
|
|
367
|
+
block.partialJson = (block.partialJson ?? "") + event.delta.partial_json;
|
|
368
|
+
if (toolArgumentPreviewSchedules.get(block)?.(block.partialJson.length)) block.arguments = parseStreamingJson(block.partialJson);
|
|
369
|
+
eventSink.push({
|
|
370
|
+
type: "toolcall_delta",
|
|
371
|
+
contentIndex: index,
|
|
372
|
+
delta: event.delta.partial_json,
|
|
373
|
+
partial: output
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
} else if (event.delta.type === "signature_delta") {
|
|
377
|
+
const index = blockIndexes.get(event.index);
|
|
378
|
+
const block = index === void 0 ? void 0 : blocks[index];
|
|
379
|
+
if (index !== void 0 && block?.type === "thinking") {
|
|
380
|
+
block.thinkingSignature = block.thinkingSignature || "";
|
|
381
|
+
block.thinkingSignature += event.delta.signature;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} else if (event.type === "content_block_stop") {
|
|
385
|
+
if (compactionCapture.complete(event.index)) continue;
|
|
343
386
|
const index = blockIndexes.get(event.index);
|
|
344
387
|
const block = index === void 0 ? void 0 : blocks[index];
|
|
345
|
-
if (index !== void 0 && block
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
388
|
+
if (index !== void 0 && block) {
|
|
389
|
+
blockIndexes.delete(event.index);
|
|
390
|
+
delete block.index;
|
|
391
|
+
if (block.type === "text") eventSink.push({
|
|
392
|
+
type: "text_end",
|
|
349
393
|
contentIndex: index,
|
|
350
|
-
|
|
394
|
+
content: block.text,
|
|
351
395
|
partial: output
|
|
352
396
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const index = blockIndexes.get(event.index);
|
|
356
|
-
const block = index === void 0 ? void 0 : blocks[index];
|
|
357
|
-
if (index !== void 0 && block?.type === "toolCall") {
|
|
358
|
-
block.partialJson = (block.partialJson ?? "") + event.delta.partial_json;
|
|
359
|
-
if (toolArgumentPreviewSchedules.get(block)?.(block.partialJson.length)) block.arguments = parseStreamingJson(block.partialJson);
|
|
360
|
-
eventSink.push({
|
|
361
|
-
type: "toolcall_delta",
|
|
397
|
+
else if (block.type === "thinking") eventSink.push({
|
|
398
|
+
type: "thinking_end",
|
|
362
399
|
contentIndex: index,
|
|
363
|
-
|
|
400
|
+
content: block.thinking,
|
|
364
401
|
partial: output
|
|
365
402
|
});
|
|
403
|
+
else if (block.type === "toolCall") sealedToolCalls.push({
|
|
404
|
+
block,
|
|
405
|
+
contentIndex: index
|
|
406
|
+
});
|
|
366
407
|
}
|
|
367
|
-
} else if (event.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
block.thinkingSignature += event.delta.signature;
|
|
408
|
+
} else if (event.type === "message_delta") {
|
|
409
|
+
logAnthropicContextEdits(event);
|
|
410
|
+
if (event.delta.stop_reason) {
|
|
411
|
+
if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
|
|
412
|
+
else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
|
|
373
413
|
}
|
|
414
|
+
applyAnthropicMessageDeltaUsage(output.usage, event.usage, messageStartPromptUsage);
|
|
415
|
+
calculateCost(costModel, output.usage);
|
|
374
416
|
}
|
|
375
|
-
} else if (event.type === "content_block_stop") {
|
|
376
|
-
if (compactionCapture.complete(event.index)) continue;
|
|
377
|
-
const index = blockIndexes.get(event.index);
|
|
378
|
-
const block = index === void 0 ? void 0 : blocks[index];
|
|
379
|
-
if (index !== void 0 && block) {
|
|
380
|
-
blockIndexes.delete(event.index);
|
|
381
|
-
delete block.index;
|
|
382
|
-
if (block.type === "text") eventSink.push({
|
|
383
|
-
type: "text_end",
|
|
384
|
-
contentIndex: index,
|
|
385
|
-
content: block.text,
|
|
386
|
-
partial: output
|
|
387
|
-
});
|
|
388
|
-
else if (block.type === "thinking") eventSink.push({
|
|
389
|
-
type: "thinking_end",
|
|
390
|
-
contentIndex: index,
|
|
391
|
-
content: block.thinking,
|
|
392
|
-
partial: output
|
|
393
|
-
});
|
|
394
|
-
else if (block.type === "toolCall") sealedToolCalls.push({
|
|
395
|
-
block,
|
|
396
|
-
contentIndex: index
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
} else if (event.type === "message_delta") {
|
|
400
|
-
if (event.delta.stop_reason) if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
|
|
401
|
-
else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
|
|
402
|
-
if (event.usage) applyAnthropicMessageDeltaUsage(output.usage, event.usage, messageStartPromptUsage);
|
|
403
|
-
calculateCost(costModel, output.usage);
|
|
404
417
|
}
|
|
405
418
|
if (requestOptions?.signal?.aborted) throw transportAbortError(requestOptions.signal);
|
|
406
419
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
@@ -423,6 +436,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
423
436
|
});
|
|
424
437
|
stream.end();
|
|
425
438
|
} catch (error) {
|
|
439
|
+
const terminal = assignTransportErrorDetails(output, error, requestOptions?.signal);
|
|
426
440
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
427
441
|
for (const block of output.content) {
|
|
428
442
|
delete block.index;
|
|
@@ -433,14 +447,14 @@ const streamAnthropic = (model, context, options) => {
|
|
|
433
447
|
output.content = [];
|
|
434
448
|
}
|
|
435
449
|
if (usedCompactionReplay && isAnthropicReplayRejection(error)) suppressAnthropicCompaction(output, model, requestOptions);
|
|
436
|
-
const terminal = projectProviderError(error, requestOptions?.signal);
|
|
437
|
-
Object.assign(output, terminal);
|
|
438
450
|
stream.push({
|
|
439
451
|
type: "error",
|
|
440
452
|
reason: terminal.stopReason,
|
|
441
453
|
error: output
|
|
442
454
|
});
|
|
443
455
|
stream.end();
|
|
456
|
+
} finally {
|
|
457
|
+
logAnthropicThinkingDrops(inputTransformations);
|
|
444
458
|
}
|
|
445
459
|
})();
|
|
446
460
|
return stream;
|
|
@@ -462,6 +476,8 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
462
476
|
const base = {
|
|
463
477
|
...buildBaseOptions(model, options, apiKey),
|
|
464
478
|
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
479
|
+
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
480
|
+
cacheTtlPruning: options?.cacheTtlPruning,
|
|
465
481
|
authProfileId: options?.authProfileId,
|
|
466
482
|
maxTokens: clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens),
|
|
467
483
|
toolChoice: options?.toolChoice
|
|
@@ -500,17 +516,6 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
500
516
|
thinkingBudgetTokens: thinkingEnabled ? adjusted.thinkingBudget : void 0
|
|
501
517
|
});
|
|
502
518
|
};
|
|
503
|
-
function isOAuthToken(apiKey) {
|
|
504
|
-
return getAiTransportHost().resolveSecretSentinel(apiKey).includes("sk-ant-oat");
|
|
505
|
-
}
|
|
506
|
-
function isAnthropicPublicEndpoint(baseUrl) {
|
|
507
|
-
if (!baseUrl) return true;
|
|
508
|
-
try {
|
|
509
|
-
return new URL(baseUrl).hostname.toLowerCase() === "api.anthropic.com";
|
|
510
|
-
} catch {
|
|
511
|
-
return false;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
519
|
/**
|
|
515
520
|
* Server-side refusal fallback is a first-party Claude API beta: proxies and
|
|
516
521
|
* Bedrock/Vertex/Foundry reject the `fallbacks` param, and OAuth (Claude Code
|
|
@@ -518,7 +523,7 @@ function isAnthropicPublicEndpoint(baseUrl) {
|
|
|
518
523
|
*/
|
|
519
524
|
function supportsAnthropicServerSideFallback(model) {
|
|
520
525
|
if (!usesClaudeFable5MessagesContract(model) && resolveClaudeOpus5ModelIdentity(model) === void 0 || model.provider !== "anthropic") return false;
|
|
521
|
-
return
|
|
526
|
+
return isDirectAnthropicModel(model);
|
|
522
527
|
}
|
|
523
528
|
function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFineGrainedToolStreamingBeta, optionsHeaders, dynamicHeaders, sessionId) {
|
|
524
529
|
const needsInterleavedBeta = interleavedThinking && !supportsClaudeAdaptiveThinking(model);
|
|
@@ -539,7 +544,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
539
544
|
Authorization: null,
|
|
540
545
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
541
546
|
}, model.headers, optionsHeaders),
|
|
542
|
-
fetch
|
|
547
|
+
fetch,
|
|
548
|
+
maxRetries: 0
|
|
543
549
|
}),
|
|
544
550
|
isOAuthToken: false,
|
|
545
551
|
serverSideFallback: false
|
|
@@ -555,7 +561,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
555
561
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
556
562
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
557
563
|
}, model.headers, dynamicHeaders, optionsHeaders),
|
|
558
|
-
fetch
|
|
564
|
+
fetch,
|
|
565
|
+
maxRetries: 0
|
|
559
566
|
}),
|
|
560
567
|
isOAuthToken: false,
|
|
561
568
|
serverSideFallback: false
|
|
@@ -574,12 +581,13 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
574
581
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
575
582
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
576
583
|
}, omitFoundryBearerCredentialHeaders(model.headers), dynamicHeaders, optionsHeaders),
|
|
577
|
-
fetch
|
|
584
|
+
fetch,
|
|
585
|
+
maxRetries: 0
|
|
578
586
|
}),
|
|
579
587
|
isOAuthToken: false,
|
|
580
588
|
serverSideFallback: false
|
|
581
589
|
};
|
|
582
|
-
if (
|
|
590
|
+
if (isAnthropicOAuthApiKey(apiKey)) return {
|
|
583
591
|
client: new Anthropic({
|
|
584
592
|
apiKey: null,
|
|
585
593
|
authToken: apiKey,
|
|
@@ -596,7 +604,8 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
596
604
|
"user-agent": `claude-cli/${ANTHROPIC_CLAUDE_CODE_VERSION}`,
|
|
597
605
|
"x-app": "cli"
|
|
598
606
|
}, model.headers, optionsHeaders),
|
|
599
|
-
fetch
|
|
607
|
+
fetch,
|
|
608
|
+
maxRetries: 0
|
|
600
609
|
}),
|
|
601
610
|
isOAuthToken: true,
|
|
602
611
|
serverSideFallback: false
|
|
@@ -604,21 +613,24 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
604
613
|
const serverSideFallback = supportsAnthropicServerSideFallback(model);
|
|
605
614
|
if (serverSideFallback) betaFeatures.push(ANTHROPIC_SERVER_SIDE_FALLBACK_BETA);
|
|
606
615
|
const sessionAffinityHeaders = sessionId && getAnthropicCompat(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {};
|
|
616
|
+
const defaultHeaders = mergeHeaders({
|
|
617
|
+
accept: "application/json",
|
|
618
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
619
|
+
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
620
|
+
}, sessionAffinityHeaders, model.headers, optionsHeaders);
|
|
607
621
|
return {
|
|
608
622
|
client: new Anthropic({
|
|
609
623
|
apiKey,
|
|
610
624
|
authToken: null,
|
|
611
625
|
baseURL: model.baseUrl,
|
|
612
626
|
dangerouslyAllowBrowser: true,
|
|
613
|
-
defaultHeaders
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
617
|
-
}, sessionAffinityHeaders, model.headers, optionsHeaders),
|
|
618
|
-
fetch
|
|
627
|
+
defaultHeaders,
|
|
628
|
+
fetch,
|
|
629
|
+
maxRetries: 0
|
|
619
630
|
}),
|
|
620
631
|
isOAuthToken: false,
|
|
621
|
-
serverSideFallback
|
|
632
|
+
serverSideFallback,
|
|
633
|
+
directApiKeyBetaHeader: isDirectAnthropicModel(model) ? Object.entries(defaultHeaders).findLast(([name]) => name.toLowerCase() === "anthropic-beta")?.[1] ?? "" : void 0
|
|
622
634
|
};
|
|
623
635
|
}
|
|
624
636
|
async function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false) {
|
|
@@ -684,22 +696,17 @@ async function buildParams(model, context, isOAuthTokenResult, options, serverSi
|
|
|
684
696
|
async function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false, compaction) {
|
|
685
697
|
const params = [];
|
|
686
698
|
const imageBudget = createAnthropicInlineImageBudget();
|
|
687
|
-
const cacheBreakpointOptOutParamIndexes = /* @__PURE__ */ new Set();
|
|
688
699
|
const transformedMessages = transformProviderMessages(messages, model, normalizeAnthropicToolCallId);
|
|
689
700
|
const activeToolTurnAssistantIndex = replayThinkingEnabled ? -1 : findActiveAnthropicToolTurnAssistantIndex(transformedMessages);
|
|
690
701
|
for (let i = 0; i < transformedMessages.length; i++) {
|
|
691
702
|
const msg = transformedMessages[i];
|
|
692
703
|
if (!msg) continue;
|
|
693
704
|
if (msg.role === "user") {
|
|
694
|
-
const isRuntimeContextCarrier = msg.runtimeContextCarrier === true;
|
|
695
705
|
if (typeof msg.content === "string") {
|
|
696
|
-
if (msg.content.trim().length > 0) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
content: sanitizeSurrogates(msg.content)
|
|
701
|
-
});
|
|
702
|
-
}
|
|
706
|
+
if (msg.content.trim().length > 0) params.push({
|
|
707
|
+
role: "user",
|
|
708
|
+
content: sanitizeSurrogates(msg.content)
|
|
709
|
+
});
|
|
703
710
|
} else {
|
|
704
711
|
const filteredBlocks = (await normalizeAnthropicInlineContent(msg.content, imageBudget)).map((item) => {
|
|
705
712
|
if (item.type === "text") return {
|
|
@@ -719,7 +726,6 @@ async function convertMessages(messages, model, isOAuthTokenValue, cacheControl,
|
|
|
719
726
|
return true;
|
|
720
727
|
});
|
|
721
728
|
if (filteredBlocks.length === 0) continue;
|
|
722
|
-
if (isRuntimeContextCarrier) cacheBreakpointOptOutParamIndexes.add(params.length);
|
|
723
729
|
params.push({
|
|
724
730
|
role: "user",
|
|
725
731
|
content: filteredBlocks
|
|
@@ -804,7 +810,7 @@ async function convertMessages(messages, model, isOAuthTokenValue, cacheControl,
|
|
|
804
810
|
});
|
|
805
811
|
}
|
|
806
812
|
}
|
|
807
|
-
if (cacheControl) applyAnthropicCacheControlToMessages(params, cacheControl, messageCacheControlLimit,
|
|
813
|
+
if (cacheControl) applyAnthropicCacheControlToMessages(params, cacheControl, messageCacheControlLimit, /* @__PURE__ */ new Set());
|
|
808
814
|
return params;
|
|
809
815
|
}
|
|
810
816
|
function buildAnthropicSystemBlocks(systemPrompt, isOAuthTokenResult, cacheControl) {
|