@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.1
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-CH4UUnZr.mjs → anthropic-CE-7SkF6.mjs} +28 -191
- package/dist/{anthropic-usage-DWU-x8MI.mjs → anthropic-usage-Ma4iX6uG.mjs} +262 -4
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-EpJoVwM1.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-Cc_kasye.mjs} +4 -4
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-CEV9t6da.mjs} +10 -2
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-DRmDMRHH.d.mts} +2 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-CGQu21aw.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-Cq2UKx1l.mjs} +151 -85
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-CusxWzvE.mjs} +10 -7
- package/dist/{host-Dog2WQiR.mjs → host-Bl7Kgddo.mjs} +40 -2
- package/dist/{host-B9GUmcra.d.mts → host-Dn4_SZI2.d.mts} +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +19 -3
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai.d.mts +4 -4
- package/dist/internal/openai.mjs +7 -7
- package/dist/internal/runtime.d.mts +2 -2
- package/dist/internal/runtime.mjs +3 -3
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +3 -4
- package/dist/{mistral-CWmpvWYh.mjs → mistral-Dx6VzNjf.mjs} +25 -9
- package/dist/model-utils-Dau5dlgm.mjs +64 -0
- package/dist/number-coercion-1Miyb5MO.mjs +66 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-SC9m0FSf.mjs} +94 -131
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BaIpl93j.mjs} +47 -66
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-reasoning-compat-DKebnIBL.mjs} +147 -6
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-Bdx3V_Yu.mjs} +6 -22
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +116 -0
- package/dist/openai-responses-prompt-observer-internal-DDZPxRfr.mjs +46 -0
- package/dist/{openai-responses-shared-pXl6Wd8S.mjs → openai-responses-shared-CCyMvg7M.mjs} +21 -10
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-stream-internal-Bl8YyVtF.mjs} +244 -81
- package/dist/{openai-tool-projection-OhX64DoP.mjs → openai-transport-shared-Cipt7egQ.mjs} +129 -29
- package/dist/{provider-error-CAEvRjry.mjs → provider-error-DI0Ts28U.mjs} +1 -1
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-C5kYML7i.d.mts} +1 -1
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +9 -9
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-BIBomOGq.mjs} +1 -1
- package/dist/{tool-result-text-CTpIRbYd.mjs → tool-result-text-Dvkp2Dus.mjs} +51 -2
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-B1b-XCn5.mjs} +28 -1
- package/dist/transform-messages-DfjpNXNQ.mjs +2 -0
- package/dist/{transport-stream-shared-D81p90xq.mjs → transport-stream-shared-CPNv7A3r.mjs} +4 -4
- package/dist/transports.d.mts +41 -73
- package/dist/transports.mjs +317 -601
- package/dist/{types-bzp5k29J.d.mts → types-CH7ReIcU.d.mts} +4 -0
- package/dist/types.d.mts +3 -3
- package/dist/types.mjs +1 -1
- package/dist/{validation-B-j7cOYp.d.mts → validation-CcPcuEbR.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -1
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +0 -43
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort,
|
|
3
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import { a as
|
|
2
|
+
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./src-QkygScBs.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-CEV9t6da.mjs";
|
|
4
|
+
import { a as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, d as requiresClaudeAdaptiveThinking, f as resolveAnthropicThinkingEffort, h as usesClaudeStreamingRefusalContract, i as transformMessages, l as mapAnthropicStopReason, m as usesClaudeFable5MessagesContract, n as getAiTransportHost, o as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as applyClaudeRequestContract, u as prepareClaudeNoPrefillRequestContext } from "./host-Bl7Kgddo.mjs";
|
|
5
|
+
import { n as calculateCost } from "./model-utils-Dau5dlgm.mjs";
|
|
5
6
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
7
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
7
|
-
import { a as isImageWithMediaPayload,
|
|
8
|
-
import {
|
|
9
|
-
import { c as calculateCost, l as clampThinkingLevel } from "./number-coercion-DvG7SNMg.mjs";
|
|
8
|
+
import { a as isImageWithMediaPayload, c as buildBaseOptions, h as stripSystemPromptCacheBoundary, l as clampMaxTokensToModel, m as splitSystemPromptCacheBoundary, n as extractToolResultBlockText, r as extractToolResultText, s as adjustMaxTokensForThinking, t as describeToolResultMediaPlaceholder } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
9
|
+
import { C as usesFoundryBearerAuth, E as resolveAnthropicImageMediaType, O as applyAnthropicCacheControlToMessages, S as omitFoundryBearerCredentialHeaders, T as normalizeAnthropicInlineContent, b as resolveAnthropicFallbackServingModelCost, c as normalizeAnthropicToolChoice, d as resolveOriginalAnthropicToolName, f as toClaudeCodeToolName, g as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, h as ANTHROPIC_SERVER_SIDE_FALLBACKS, l as projectAnthropicTools, m as findActiveAnthropicToolTurnAssistantIndex, n as applyAnthropicMessageStartUsage, p as ANTHROPIC_OMITTED_REASONING_TEXT, s as normalizeAnthropicToolCallId, t as applyAnthropicMessageDeltaUsage, u as reconcileAnthropicToolChoice, v as applyAnthropicFallbackBoundary, w as createAnthropicInlineImageBudget, x as applyAnthropicRefusal, y as readAnthropicFallbackBoundary } from "./anthropic-usage-Ma4iX6uG.mjs";
|
|
10
10
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
11
11
|
import { n as parseStreamingJson, t as parseJsonWithRepair } from "./json-parse-BvXNt1-7.mjs";
|
|
12
12
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
13
|
-
import { d as transportAbortError } from "./transport-stream-shared-
|
|
13
|
+
import { d as transportAbortError, f as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-stream-shared-CPNv7A3r.mjs";
|
|
14
14
|
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
15
|
-
import { t as formatProviderError } from "./provider-error-
|
|
15
|
+
import { t as formatProviderError } from "./provider-error-DI0Ts28U.mjs";
|
|
16
16
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
17
|
-
import
|
|
18
|
-
import "./transform-messages-C8mBqZxF.mjs";
|
|
17
|
+
import "./transform-messages-DfjpNXNQ.mjs";
|
|
19
18
|
import Anthropic from "@anthropic-ai/sdk";
|
|
20
19
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
21
20
|
//#region packages/ai/src/providers/anthropic.ts
|
|
@@ -37,28 +36,6 @@ function getCacheControl(model, cacheRetention) {
|
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
const claudeCodeVersion = "2.1.75";
|
|
41
|
-
const claudeCodeBillingSystemBlock = `x-anthropic-billing-header: cc_version=${claudeCodeVersion}; cc_entrypoint=sdk-cli;`;
|
|
42
|
-
const ccToolLookup = new Map([
|
|
43
|
-
"Read",
|
|
44
|
-
"Write",
|
|
45
|
-
"Edit",
|
|
46
|
-
"Bash",
|
|
47
|
-
"Grep",
|
|
48
|
-
"Glob",
|
|
49
|
-
"AskUserQuestion",
|
|
50
|
-
"EnterPlanMode",
|
|
51
|
-
"ExitPlanMode",
|
|
52
|
-
"KillShell",
|
|
53
|
-
"NotebookEdit",
|
|
54
|
-
"Skill",
|
|
55
|
-
"Task",
|
|
56
|
-
"TaskOutput",
|
|
57
|
-
"TodoWrite",
|
|
58
|
-
"WebFetch",
|
|
59
|
-
"WebSearch"
|
|
60
|
-
].map((t) => [t.toLowerCase(), t]));
|
|
61
|
-
const toClaudeCodeName = (name) => ccToolLookup.get(name.toLowerCase()) ?? name;
|
|
62
39
|
/**
|
|
63
40
|
* Convert content blocks to Anthropic API format
|
|
64
41
|
*/
|
|
@@ -144,8 +121,8 @@ async function* iterateAnthropicEvents(response, requireMessageStop = false) {
|
|
|
144
121
|
else if (event.type === "message_stop") sawMessageEnd = true;
|
|
145
122
|
yield event;
|
|
146
123
|
} catch (error) {
|
|
147
|
-
|
|
148
|
-
throw
|
|
124
|
+
if (error instanceof SyntaxError) throw new Error(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, { cause: error });
|
|
125
|
+
throw error;
|
|
149
126
|
}
|
|
150
127
|
}
|
|
151
128
|
if ((sawMessageStart || requireMessageStop) && !sawMessageEnd) throw new Error("Anthropic stream ended before message_stop");
|
|
@@ -229,25 +206,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
229
206
|
for await (const event of iterateAnthropicEvents(response, refusalBuffer !== void 0)) if (event.type === "message_start") {
|
|
230
207
|
output.responseId = event.message.id;
|
|
231
208
|
output.responseModel = event.message.model;
|
|
232
|
-
|
|
233
|
-
const messageStartPromptTokens = promptUsage ? promptUsage.input + promptUsage.cacheRead + promptUsage.cacheWrite : 0;
|
|
234
|
-
messageStartPromptUsage = messageStartPromptTokens > 0 ? promptUsage : void 0;
|
|
235
|
-
const inputTokens = readAnthropicUsageTokenCount(event.message.usage.input_tokens);
|
|
236
|
-
if (inputTokens !== void 0) output.usage.input = inputTokens;
|
|
237
|
-
const outputTokens = readAnthropicUsageTokenCount(event.message.usage.output_tokens);
|
|
238
|
-
if (outputTokens !== void 0) output.usage.output = outputTokens;
|
|
239
|
-
const cacheReadTokens = event.message.usage.cache_read_input_tokens == null ? 0 : readAnthropicUsageTokenCount(event.message.usage.cache_read_input_tokens);
|
|
240
|
-
if (cacheReadTokens !== void 0) output.usage.cacheRead = cacheReadTokens;
|
|
241
|
-
const cacheWriteTokens = event.message.usage.cache_creation_input_tokens == null ? 0 : readAnthropicUsageTokenCount(event.message.usage.cache_creation_input_tokens);
|
|
242
|
-
if (cacheWriteTokens !== void 0) output.usage.cacheWrite = cacheWriteTokens;
|
|
243
|
-
const cacheWriteUsage = readAnthropicCacheWriteUsage(event.message.usage);
|
|
244
|
-
if (cacheWriteUsage.cacheWrite1h !== void 0) output.usage.cacheWrite1h = cacheWriteUsage.cacheWrite1h;
|
|
245
|
-
output.usage.totalTokens = output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
246
|
-
if (messageStartPromptUsage && outputTokens !== void 0) output.usage.contextUsage = {
|
|
247
|
-
state: "available",
|
|
248
|
-
promptTokens: messageStartPromptTokens,
|
|
249
|
-
totalTokens: messageStartPromptTokens + output.usage.output
|
|
250
|
-
};
|
|
209
|
+
messageStartPromptUsage = applyAnthropicMessageStartUsage(output.usage, event.message.usage);
|
|
251
210
|
calculateCost(costModel, output.usage);
|
|
252
211
|
eventSink.push({
|
|
253
212
|
type: "start",
|
|
@@ -433,35 +392,8 @@ const streamAnthropic = (model, context, options) => {
|
|
|
433
392
|
}
|
|
434
393
|
} else if (event.type === "message_delta") {
|
|
435
394
|
if (event.delta.stop_reason) if (event.delta.stop_reason === "refusal") applyAnthropicRefusal(output, event.delta.stop_details, model.provider);
|
|
436
|
-
else output.stopReason =
|
|
437
|
-
if (event.usage)
|
|
438
|
-
const inputTokens = readAnthropicUsageTokenCount(event.usage.input_tokens);
|
|
439
|
-
if (inputTokens !== void 0) output.usage.input = inputTokens;
|
|
440
|
-
const outputTokens = readAnthropicUsageTokenCount(event.usage.output_tokens);
|
|
441
|
-
if (outputTokens !== void 0) output.usage.output = outputTokens;
|
|
442
|
-
const cacheReadTokens = readAnthropicUsageTokenCount(event.usage.cache_read_input_tokens);
|
|
443
|
-
if (cacheReadTokens !== void 0) output.usage.cacheRead = cacheReadTokens;
|
|
444
|
-
const cacheWriteTokens = readAnthropicUsageTokenCount(event.usage.cache_creation_input_tokens);
|
|
445
|
-
if (cacheWriteTokens !== void 0) output.usage.cacheWrite = cacheWriteTokens;
|
|
446
|
-
const cacheWriteUsage = readAnthropicCacheWriteUsage(event.usage);
|
|
447
|
-
if (cacheWriteUsage.cacheWrite1h !== void 0) output.usage.cacheWrite1h = cacheWriteUsage.cacheWrite1h;
|
|
448
|
-
output.usage.totalTokens = output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
449
|
-
const iterationUsage = readLastAnthropicIterationUsage(event.usage);
|
|
450
|
-
if (iterationUsage.state === "valid") output.usage.contextUsage = {
|
|
451
|
-
state: "available",
|
|
452
|
-
promptTokens: iterationUsage.usage.contextPromptTokens,
|
|
453
|
-
totalTokens: iterationUsage.usage.totalTokens
|
|
454
|
-
};
|
|
455
|
-
else if (iterationUsage.state === "invalid") output.usage.contextUsage = { state: "unavailable" };
|
|
456
|
-
else if (outputTokens !== void 0 && (messageStartPromptUsage !== void 0 || inputTokens !== void 0 && cacheReadTokens !== void 0 && cacheWriteTokens !== void 0)) {
|
|
457
|
-
const promptTokens = output.usage.input + output.usage.cacheRead + output.usage.cacheWrite;
|
|
458
|
-
output.usage.contextUsage = {
|
|
459
|
-
state: "available",
|
|
460
|
-
promptTokens,
|
|
461
|
-
totalTokens: promptTokens + output.usage.output
|
|
462
|
-
};
|
|
463
|
-
} else output.usage.contextUsage = { state: "unavailable" };
|
|
464
|
-
}
|
|
395
|
+
else output.stopReason = mapAnthropicStopReason(event.delta.stop_reason);
|
|
396
|
+
if (event.usage) applyAnthropicMessageDeltaUsage(output.usage, event.usage, messageStartPromptUsage);
|
|
465
397
|
calculateCost(costModel, output.usage);
|
|
466
398
|
}
|
|
467
399
|
if (requestOptions?.signal?.aborted) throw transportAbortError(requestOptions.signal);
|
|
@@ -494,18 +426,8 @@ const streamAnthropic = (model, context, options) => {
|
|
|
494
426
|
})();
|
|
495
427
|
return stream;
|
|
496
428
|
};
|
|
497
|
-
function normalizeAnthropicToolChoice(thinkingEnabled, toolChoice) {
|
|
498
|
-
if (thinkingEnabled && (toolChoice === "any" || typeof toolChoice === "object" && toolChoice.type === "tool")) return { type: "auto" };
|
|
499
|
-
return typeof toolChoice === "string" ? { type: toolChoice } : toolChoice;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Check if a model supports adaptive thinking (Fable 5, Opus 4.6+, Sonnet 4.6).
|
|
503
|
-
*/
|
|
504
|
-
function supportsAdaptiveThinking(model) {
|
|
505
|
-
return supportsClaudeAdaptiveThinking(model);
|
|
506
|
-
}
|
|
507
429
|
function normalizeAnthropicThinkingOptions(model, options) {
|
|
508
|
-
if (options?.thinkingEnabled !== true ||
|
|
430
|
+
if (options?.thinkingEnabled !== true || supportsClaudeAdaptiveThinking(model)) return options;
|
|
509
431
|
const budgetTokens = options.thinkingBudgetTokens ?? ANTHROPIC_MIN_THINKING_BUDGET_TOKENS;
|
|
510
432
|
const maxTokens = options.maxTokens ?? model.maxTokens;
|
|
511
433
|
if (budgetTokens >= ANTHROPIC_MIN_THINKING_BUDGET_TOKENS && budgetTokens < maxTokens) return options;
|
|
@@ -515,36 +437,6 @@ function normalizeAnthropicThinkingOptions(model, options) {
|
|
|
515
437
|
thinkingBudgetTokens: void 0
|
|
516
438
|
};
|
|
517
439
|
}
|
|
518
|
-
function supportsNativeXhighEffort(model) {
|
|
519
|
-
return supportsClaudeNativeXhighEffort(model);
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Map ThinkingLevel to Anthropic effort levels for adaptive thinking.
|
|
523
|
-
* Model metadata owns the provider-specific extended effort mapping.
|
|
524
|
-
*/
|
|
525
|
-
function mapThinkingLevelToEffort(model, level) {
|
|
526
|
-
const requestedLevel = level;
|
|
527
|
-
const hasCanonicalAlias = typeof model.params?.canonicalModelId === "string";
|
|
528
|
-
const thinkingLevelMap = resolveClaudeNativeThinkingLevelMap(model);
|
|
529
|
-
const clampModel = {
|
|
530
|
-
...model,
|
|
531
|
-
...hasCanonicalAlias ? { reasoning: true } : {},
|
|
532
|
-
...thinkingLevelMap ? { thinkingLevelMap } : {}
|
|
533
|
-
};
|
|
534
|
-
const clampedLevel = requestedLevel ? clampThinkingLevel(clampModel, requestedLevel) : requestedLevel;
|
|
535
|
-
const mapped = clampedLevel ? thinkingLevelMap?.[clampedLevel] : void 0;
|
|
536
|
-
if (typeof mapped === "string") return mapped;
|
|
537
|
-
switch (clampedLevel) {
|
|
538
|
-
case "off":
|
|
539
|
-
case "minimal":
|
|
540
|
-
case "low": return "low";
|
|
541
|
-
case "medium": return "medium";
|
|
542
|
-
case "high": return "high";
|
|
543
|
-
case "xhigh": return supportsNativeXhighEffort(model) ? "xhigh" : "high";
|
|
544
|
-
case "max": return supportsClaudeNativeMaxEffort(model) ? "max" : "high";
|
|
545
|
-
default: return "high";
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
440
|
const streamSimpleAnthropic = (model, context, options) => {
|
|
549
441
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
550
442
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
@@ -562,15 +454,15 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
562
454
|
if (resolveClaudeOpus5ModelIdentity(model) || resolveClaudeSonnet5ModelIdentity(model)) return streamAnthropic(model, context, {
|
|
563
455
|
...base,
|
|
564
456
|
thinkingEnabled: true,
|
|
565
|
-
effort:
|
|
457
|
+
effort: resolveAnthropicThinkingEffort(model, reasoning ?? "high")
|
|
566
458
|
});
|
|
567
459
|
if (!reasoning) return streamAnthropic(model, context, {
|
|
568
460
|
...base,
|
|
569
461
|
thinkingEnabled: mandatoryAdaptiveThinking,
|
|
570
462
|
...mandatoryAdaptiveThinking ? { effort: "high" } : {}
|
|
571
463
|
});
|
|
572
|
-
if (
|
|
573
|
-
const effort =
|
|
464
|
+
if (supportsClaudeAdaptiveThinking(model)) {
|
|
465
|
+
const effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
574
466
|
return streamAnthropic(model, context, {
|
|
575
467
|
...base,
|
|
576
468
|
thinkingEnabled: true,
|
|
@@ -608,7 +500,7 @@ function supportsAnthropicServerSideFallback(model) {
|
|
|
608
500
|
return isAnthropicPublicEndpoint(model.baseUrl);
|
|
609
501
|
}
|
|
610
502
|
function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFineGrainedToolStreamingBeta, optionsHeaders, dynamicHeaders, sessionId) {
|
|
611
|
-
const needsInterleavedBeta = interleavedThinking && !
|
|
503
|
+
const needsInterleavedBeta = interleavedThinking && !supportsClaudeAdaptiveThinking(model);
|
|
612
504
|
const betaFeatures = [];
|
|
613
505
|
if (useFineGrainedToolStreamingBeta) betaFeatures.push(FINE_GRAINED_TOOL_STREAMING_BETA);
|
|
614
506
|
if (needsInterleavedBeta) betaFeatures.push(INTERLEAVED_THINKING_BETA);
|
|
@@ -680,7 +572,7 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
680
572
|
"oauth-2025-04-20",
|
|
681
573
|
...betaFeatures
|
|
682
574
|
].join(","),
|
|
683
|
-
"user-agent": `claude-cli/${
|
|
575
|
+
"user-agent": `claude-cli/${ANTHROPIC_CLAUDE_CODE_VERSION}`,
|
|
684
576
|
"x-app": "cli"
|
|
685
577
|
}, model.headers, optionsHeaders),
|
|
686
578
|
fetch
|
|
@@ -728,13 +620,13 @@ async function buildParams(model, context, isOAuthTokenResult, options, serverSi
|
|
|
728
620
|
};
|
|
729
621
|
if (system) params.system = system;
|
|
730
622
|
if (serverSideFallback) params.fallbacks = ANTHROPIC_SERVER_SIDE_FALLBACKS;
|
|
731
|
-
if (options?.temperature !== void 0 && !options?.thinkingEnabled && !
|
|
623
|
+
if (options?.temperature !== void 0 && !options?.thinkingEnabled && !supportsClaudeNativeXhighEffort(model)) params.temperature = options.temperature;
|
|
732
624
|
if (options?.stop !== void 0 && options.stop.length > 0) params.stop_sequences = options.stop;
|
|
733
625
|
if (tools && tools.length > 0) params.tools = tools;
|
|
734
|
-
if (mandatoryAdaptiveThinking || model.reasoning ||
|
|
626
|
+
if (mandatoryAdaptiveThinking || model.reasoning || supportsClaudeAdaptiveThinking(model)) {
|
|
735
627
|
if (mandatoryAdaptiveThinking || options?.thinkingEnabled) {
|
|
736
628
|
const display = options?.thinkingDisplay ?? "summarized";
|
|
737
|
-
if (
|
|
629
|
+
if (supportsClaudeAdaptiveThinking(model)) {
|
|
738
630
|
params.thinking = {
|
|
739
631
|
type: "adaptive",
|
|
740
632
|
display
|
|
@@ -762,14 +654,11 @@ async function buildParams(model, context, isOAuthTokenResult, options, serverSi
|
|
|
762
654
|
toolProjection
|
|
763
655
|
};
|
|
764
656
|
}
|
|
765
|
-
function normalizeToolCallId(id) {
|
|
766
|
-
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
767
|
-
}
|
|
768
657
|
async function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false) {
|
|
769
658
|
const params = [];
|
|
770
659
|
const imageBudget = createAnthropicInlineImageBudget();
|
|
771
660
|
const cacheBreakpointOptOutParamIndexes = /* @__PURE__ */ new Set();
|
|
772
|
-
const transformedMessages = transformMessages(messages, model,
|
|
661
|
+
const transformedMessages = transformMessages(messages, model, normalizeAnthropicToolCallId);
|
|
773
662
|
const activeToolTurnAssistantIndex = replayThinkingEnabled ? -1 : findActiveAnthropicToolTurnAssistantIndex(transformedMessages);
|
|
774
663
|
for (let i = 0; i < transformedMessages.length; i++) {
|
|
775
664
|
const msg = transformedMessages[i];
|
|
@@ -849,7 +738,7 @@ async function convertMessages(messages, model, isOAuthTokenValue, cacheControl,
|
|
|
849
738
|
} else if (block.type === "toolCall") blocks.push({
|
|
850
739
|
type: "tool_use",
|
|
851
740
|
id: block.id,
|
|
852
|
-
name: isOAuthTokenValue ?
|
|
741
|
+
name: isOAuthTokenValue ? toClaudeCodeToolName(block.name) : block.name,
|
|
853
742
|
input: block.arguments ?? {}
|
|
854
743
|
});
|
|
855
744
|
if (blocks.length === 0 && omittedThinking) blocks.push({
|
|
@@ -888,55 +777,15 @@ async function convertMessages(messages, model, isOAuthTokenValue, cacheControl,
|
|
|
888
777
|
});
|
|
889
778
|
}
|
|
890
779
|
}
|
|
891
|
-
if (cacheControl
|
|
892
|
-
let fallbackToolResult;
|
|
893
|
-
for (let i = params.length - 1; i >= 0; i--) {
|
|
894
|
-
const message = params[i];
|
|
895
|
-
if (!message || message.role !== "user" || cacheBreakpointOptOutParamIndexes.has(i)) continue;
|
|
896
|
-
if (Array.isArray(message.content)) {
|
|
897
|
-
for (let j = message.content.length - 1; j >= 0; j--) {
|
|
898
|
-
const block = message.content[j];
|
|
899
|
-
if (!block) continue;
|
|
900
|
-
if (block.type === "text" || block.type === "image") {
|
|
901
|
-
if (fallbackToolResult && messageCacheControlLimit === 1) {
|
|
902
|
-
applyContentBlockCacheControl(fallbackToolResult, cacheControl);
|
|
903
|
-
return params;
|
|
904
|
-
}
|
|
905
|
-
applyContentBlockCacheControl(block, cacheControl);
|
|
906
|
-
if (fallbackToolResult && messageCacheControlLimit > 1) applyContentBlockCacheControl(fallbackToolResult, cacheControl);
|
|
907
|
-
return params;
|
|
908
|
-
}
|
|
909
|
-
if (block.type === "tool_result" && fallbackToolResult === void 0) fallbackToolResult = block;
|
|
910
|
-
}
|
|
911
|
-
continue;
|
|
912
|
-
}
|
|
913
|
-
if (typeof message.content === "string") {
|
|
914
|
-
if (fallbackToolResult && messageCacheControlLimit === 1) {
|
|
915
|
-
applyContentBlockCacheControl(fallbackToolResult, cacheControl);
|
|
916
|
-
return params;
|
|
917
|
-
}
|
|
918
|
-
message.content = [{
|
|
919
|
-
type: "text",
|
|
920
|
-
text: message.content,
|
|
921
|
-
cache_control: cacheControl
|
|
922
|
-
}];
|
|
923
|
-
if (fallbackToolResult && messageCacheControlLimit > 1) applyContentBlockCacheControl(fallbackToolResult, cacheControl);
|
|
924
|
-
return params;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
if (fallbackToolResult) applyContentBlockCacheControl(fallbackToolResult, cacheControl);
|
|
928
|
-
}
|
|
780
|
+
if (cacheControl) applyAnthropicCacheControlToMessages(params, cacheControl, messageCacheControlLimit, cacheBreakpointOptOutParamIndexes);
|
|
929
781
|
return params;
|
|
930
782
|
}
|
|
931
|
-
function applyContentBlockCacheControl(block, cacheControl) {
|
|
932
|
-
block.cache_control = cacheControl;
|
|
933
|
-
}
|
|
934
783
|
function buildAnthropicSystemBlocks(systemPrompt, isOAuthTokenResult, cacheControl) {
|
|
935
784
|
const blocks = [];
|
|
936
785
|
if (isOAuthTokenResult) {
|
|
937
786
|
blocks.push({
|
|
938
787
|
type: "text",
|
|
939
|
-
text:
|
|
788
|
+
text: ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK
|
|
940
789
|
});
|
|
941
790
|
blocks.push({
|
|
942
791
|
type: "text",
|
|
@@ -983,7 +832,7 @@ function shouldUseFineGrainedToolStreamingBeta(model, context) {
|
|
|
983
832
|
return Boolean(context.tools?.length) && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
984
833
|
}
|
|
985
834
|
function convertTools(tools, isOAuthTokenLocal, supportsEagerToolInputStreaming, cacheControl) {
|
|
986
|
-
const projection = projectAnthropicTools(tools, (name) => isOAuthTokenLocal ?
|
|
835
|
+
const projection = projectAnthropicTools(tools, (name) => isOAuthTokenLocal ? toClaudeCodeToolName(name) : name);
|
|
987
836
|
const convertedTools = [];
|
|
988
837
|
for (const [index, tool] of projection.tools.entries()) {
|
|
989
838
|
const convertedTool = {
|
|
@@ -1000,17 +849,5 @@ function convertTools(tools, isOAuthTokenLocal, supportsEagerToolInputStreaming,
|
|
|
1000
849
|
tools: convertedTools
|
|
1001
850
|
};
|
|
1002
851
|
}
|
|
1003
|
-
function mapStopReason(reason) {
|
|
1004
|
-
switch (reason) {
|
|
1005
|
-
case "end_turn": return "stop";
|
|
1006
|
-
case "max_tokens": return "length";
|
|
1007
|
-
case "tool_use": return "toolUse";
|
|
1008
|
-
case "refusal": return "error";
|
|
1009
|
-
case "pause_turn": return "stop";
|
|
1010
|
-
case "stop_sequence": return "stop";
|
|
1011
|
-
case "sensitive": return "error";
|
|
1012
|
-
default: throw new Error(`Unhandled stop reason: ${reason}`);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
852
|
//#endregion
|
|
1016
853
|
export { streamAnthropic as n, streamSimpleAnthropic as r, anthropic_exports as t };
|
|
@@ -1,7 +1,181 @@
|
|
|
1
1
|
import { o as resolveClaudeFable5ModelIdentity, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./src-QkygScBs.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { b as isRecord, n as getAiTransportHost } from "./host-Bl7Kgddo.mjs";
|
|
3
|
+
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
4
|
+
import { h as stripSystemPromptCacheBoundary, m as splitSystemPromptCacheBoundary, v as sortPromptCacheToolsByName } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
5
|
+
import { o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-B1b-XCn5.mjs";
|
|
6
|
+
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
7
|
+
/**
|
|
8
|
+
* Anthropic-family request payload policy helpers.
|
|
9
|
+
* Applies service-tier and cache-control markers only when provider endpoint
|
|
10
|
+
* capabilities allow them.
|
|
11
|
+
*/
|
|
12
|
+
const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
|
|
13
|
+
function resolveBaseUrlHostname(baseUrl) {
|
|
14
|
+
try {
|
|
15
|
+
return new URL(baseUrl).hostname;
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isLongTtlEligibleEndpoint(baseUrl) {
|
|
21
|
+
if (typeof baseUrl !== "string") return false;
|
|
22
|
+
const hostname = resolveBaseUrlHostname(baseUrl);
|
|
23
|
+
if (!hostname) return false;
|
|
24
|
+
return hostname === "api.anthropic.com" || hostname === "aiplatform.googleapis.com" || hostname === "aiplatform.us.rep.googleapis.com" || hostname === "aiplatform.eu.rep.googleapis.com" || hostname.endsWith("-aiplatform.googleapis.com");
|
|
25
|
+
}
|
|
26
|
+
/** Resolve Anthropic cache-control marker retention for a request endpoint. */
|
|
27
|
+
function resolveAnthropicEphemeralCacheControl(baseUrl, cacheRetention) {
|
|
28
|
+
const retention = resolveCacheRetention(cacheRetention);
|
|
29
|
+
if (retention === "none") return;
|
|
30
|
+
const ttl = retention === "long" && (cacheRetention === "long" || isLongTtlEligibleEndpoint(baseUrl)) ? "1h" : void 0;
|
|
31
|
+
return {
|
|
32
|
+
type: "ephemeral",
|
|
33
|
+
...ttl ? { ttl } : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function applyAnthropicCacheControlToSystem(system, cacheControl) {
|
|
37
|
+
if (!Array.isArray(system)) return;
|
|
38
|
+
const normalizedBlocks = [];
|
|
39
|
+
for (const block of system) {
|
|
40
|
+
if (!block || typeof block !== "object") {
|
|
41
|
+
normalizedBlocks.push(block);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const record = block;
|
|
45
|
+
if (record.type !== "text" || typeof record.text !== "string") {
|
|
46
|
+
normalizedBlocks.push(block);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const split = splitSystemPromptCacheBoundary(record.text);
|
|
50
|
+
if (!split) {
|
|
51
|
+
if (record.cache_control === void 0) record.cache_control = cacheControl;
|
|
52
|
+
normalizedBlocks.push(record);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const { cache_control: existingCacheControl, ...rest } = record;
|
|
56
|
+
if (split.stablePrefix) normalizedBlocks.push({
|
|
57
|
+
...rest,
|
|
58
|
+
text: split.stablePrefix,
|
|
59
|
+
cache_control: existingCacheControl ?? cacheControl
|
|
60
|
+
});
|
|
61
|
+
if (split.dynamicSuffix) normalizedBlocks.push({
|
|
62
|
+
...rest,
|
|
63
|
+
text: split.dynamicSuffix
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
system.splice(0, system.length, ...normalizedBlocks);
|
|
67
|
+
}
|
|
68
|
+
function stripAnthropicSystemPromptBoundary(system) {
|
|
69
|
+
if (!Array.isArray(system)) return;
|
|
70
|
+
for (const block of system) {
|
|
71
|
+
if (!block || typeof block !== "object") continue;
|
|
72
|
+
const record = block;
|
|
73
|
+
if (record.type === "text" && typeof record.text === "string") record.text = stripSystemPromptCacheBoundary(record.text);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Apply one shared deepest-stable-message cache breakpoint policy. */
|
|
77
|
+
function applyAnthropicCacheControlToMessages(messages, cacheControl, markerLimit, cacheBreakpointOptOutMessageIndexes) {
|
|
78
|
+
if (!Array.isArray(messages) || messages.length === 0 || markerLimit <= 0) return;
|
|
79
|
+
let fallbackToolResult;
|
|
80
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
81
|
+
const message = messages[i];
|
|
82
|
+
if (!message || typeof message !== "object") continue;
|
|
83
|
+
const record = message;
|
|
84
|
+
if (record.role !== "user" || cacheBreakpointOptOutMessageIndexes.has(i)) continue;
|
|
85
|
+
const content = record.content;
|
|
86
|
+
if (typeof content === "string") {
|
|
87
|
+
if (fallbackToolResult && markerLimit === 1) {
|
|
88
|
+
fallbackToolResult.cache_control = cacheControl;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
record.content = [{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: content,
|
|
94
|
+
cache_control: cacheControl
|
|
95
|
+
}];
|
|
96
|
+
if (fallbackToolResult && markerLimit > 1) fallbackToolResult.cache_control = cacheControl;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!Array.isArray(content)) continue;
|
|
100
|
+
for (let j = content.length - 1; j >= 0; j--) {
|
|
101
|
+
const block = content[j];
|
|
102
|
+
if (!block || typeof block !== "object") continue;
|
|
103
|
+
const blockRecord = block;
|
|
104
|
+
if (blockRecord.type === "text" || blockRecord.type === "image") {
|
|
105
|
+
if (fallbackToolResult && markerLimit === 1) {
|
|
106
|
+
fallbackToolResult.cache_control = cacheControl;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
blockRecord.cache_control = cacheControl;
|
|
110
|
+
if (fallbackToolResult && markerLimit > 1) fallbackToolResult.cache_control = cacheControl;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (blockRecord.type === "tool_result" && fallbackToolResult === void 0) fallbackToolResult = blockRecord;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (fallbackToolResult) fallbackToolResult.cache_control = cacheControl;
|
|
117
|
+
}
|
|
118
|
+
function countAnthropicCacheControlMarkers(blocks) {
|
|
119
|
+
if (!Array.isArray(blocks)) return 0;
|
|
120
|
+
let count = 0;
|
|
121
|
+
for (const block of blocks) if (block && typeof block === "object" && "cache_control" in block) count += 1;
|
|
122
|
+
return count;
|
|
123
|
+
}
|
|
124
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
125
|
+
function resolveAnthropicPayloadPolicy(input) {
|
|
126
|
+
return {
|
|
127
|
+
allowsServiceTier: resolveProviderRequestCapabilities({
|
|
128
|
+
provider: input.provider,
|
|
129
|
+
api: input.api,
|
|
130
|
+
baseUrl: input.baseUrl,
|
|
131
|
+
capability: "llm",
|
|
132
|
+
transport: "stream"
|
|
133
|
+
}).allowsAnthropicServiceTier,
|
|
134
|
+
cacheControl: input.enableCacheControl === true ? resolveAnthropicEphemeralCacheControl(input.baseUrl, input.cacheRetention) : void 0,
|
|
135
|
+
serviceTier: input.serviceTier
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
139
|
+
function applyAnthropicPayloadPolicyToParams(payloadObj, policy, cacheBreakpointOptOutMessageIndexes) {
|
|
140
|
+
if (policy.allowsServiceTier && policy.serviceTier !== void 0 && payloadObj.service_tier === void 0) payloadObj.service_tier = policy.serviceTier;
|
|
141
|
+
if (policy.cacheControl) applyAnthropicCacheControlToSystem(payloadObj.system, policy.cacheControl);
|
|
142
|
+
else stripAnthropicSystemPromptBoundary(payloadObj.system);
|
|
143
|
+
if (!policy.cacheControl) return;
|
|
144
|
+
const usedMarkers = countAnthropicCacheControlMarkers(payloadObj.system) + countAnthropicCacheControlMarkers(payloadObj.tools);
|
|
145
|
+
applyAnthropicCacheControlToMessages(payloadObj.messages, policy.cacheControl, ANTHROPIC_CACHE_CONTROL_LIMIT - usedMarkers, cacheBreakpointOptOutMessageIndexes);
|
|
146
|
+
}
|
|
147
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
148
|
+
function applyAnthropicEphemeralCacheControlMarkers(payloadObj, cacheControl = { type: "ephemeral" }) {
|
|
149
|
+
const messages = payloadObj.messages;
|
|
150
|
+
if (!Array.isArray(messages)) return;
|
|
151
|
+
for (const message of messages) {
|
|
152
|
+
if (message.role === "system" || message.role === "developer") {
|
|
153
|
+
if (!cacheControl) continue;
|
|
154
|
+
if (typeof message.content === "string") {
|
|
155
|
+
message.content = [{
|
|
156
|
+
type: "text",
|
|
157
|
+
text: message.content,
|
|
158
|
+
cache_control: cacheControl
|
|
159
|
+
}];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(message.content) && message.content.length > 0) {
|
|
163
|
+
const last = message.content[message.content.length - 1];
|
|
164
|
+
if (last && typeof last === "object") {
|
|
165
|
+
const record = last;
|
|
166
|
+
if (record.type !== "thinking" && record.type !== "redacted_thinking") record.cache_control = cacheControl;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (message.role === "assistant" && Array.isArray(message.content)) for (const block of message.content) {
|
|
172
|
+
if (!block || typeof block !== "object") continue;
|
|
173
|
+
const record = block;
|
|
174
|
+
if (record.type === "thinking" || record.type === "redacted_thinking") delete record.cache_control;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
5
179
|
//#region packages/media-core/src/base64.ts
|
|
6
180
|
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
7
181
|
function estimateBase64DecodedBytes(base64) {
|
|
@@ -263,6 +437,38 @@ function findActiveAnthropicToolTurnAssistantIndex(messages) {
|
|
|
263
437
|
}
|
|
264
438
|
//#endregion
|
|
265
439
|
//#region packages/ai/src/providers/anthropic-tool-projection.ts
|
|
440
|
+
const CLAUDE_CODE_TOOL_LOOKUP = new Map([
|
|
441
|
+
"Read",
|
|
442
|
+
"Write",
|
|
443
|
+
"Edit",
|
|
444
|
+
"Bash",
|
|
445
|
+
"Grep",
|
|
446
|
+
"Glob",
|
|
447
|
+
"AskUserQuestion",
|
|
448
|
+
"EnterPlanMode",
|
|
449
|
+
"ExitPlanMode",
|
|
450
|
+
"KillShell",
|
|
451
|
+
"NotebookEdit",
|
|
452
|
+
"Skill",
|
|
453
|
+
"Task",
|
|
454
|
+
"TaskOutput",
|
|
455
|
+
"TodoWrite",
|
|
456
|
+
"WebFetch",
|
|
457
|
+
"WebSearch"
|
|
458
|
+
].map((name) => [name.toLowerCase(), name]));
|
|
459
|
+
/** Preserve Claude Code's canonical tool casing for subscription OAuth requests. */
|
|
460
|
+
function toClaudeCodeToolName(name) {
|
|
461
|
+
return CLAUDE_CODE_TOOL_LOOKUP.get(name.toLowerCase()) ?? name;
|
|
462
|
+
}
|
|
463
|
+
/** Anthropic rejects forced tools while extended thinking is enabled. */
|
|
464
|
+
function normalizeAnthropicToolChoice(thinkingEnabled, toolChoice) {
|
|
465
|
+
if (thinkingEnabled && (toolChoice === "any" || typeof toolChoice === "object" && toolChoice.type === "tool")) return { type: "auto" };
|
|
466
|
+
return typeof toolChoice === "string" ? { type: toolChoice } : toolChoice;
|
|
467
|
+
}
|
|
468
|
+
/** Anthropic tool identifiers accept only ASCII word characters and dashes. */
|
|
469
|
+
function normalizeAnthropicToolCallId(id) {
|
|
470
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
471
|
+
}
|
|
266
472
|
function isProviderSupportedViolation(violation) {
|
|
267
473
|
return violation.endsWith(".$dynamicRef") || violation.endsWith(".$dynamicAnchor");
|
|
268
474
|
}
|
|
@@ -455,5 +661,57 @@ function readLastAnthropicIterationUsage(usage) {
|
|
|
455
661
|
}
|
|
456
662
|
};
|
|
457
663
|
}
|
|
664
|
+
/** Record independent billing buckets without treating zero placeholders as context proof. */
|
|
665
|
+
function applyAnthropicMessageStartUsage(target, payload) {
|
|
666
|
+
const promptUsage = readAnthropicPromptUsageSnapshot(payload);
|
|
667
|
+
const promptTokens = promptUsage ? promptUsage.input + promptUsage.cacheRead + promptUsage.cacheWrite : 0;
|
|
668
|
+
const inputTokens = readAnthropicUsageTokenCount(payload.input_tokens);
|
|
669
|
+
if (inputTokens !== void 0) target.input = inputTokens;
|
|
670
|
+
const outputTokens = readAnthropicUsageTokenCount(payload.output_tokens);
|
|
671
|
+
if (outputTokens !== void 0) target.output = outputTokens;
|
|
672
|
+
const cacheReadTokens = payload.cache_read_input_tokens == null ? 0 : readAnthropicUsageTokenCount(payload.cache_read_input_tokens);
|
|
673
|
+
if (cacheReadTokens !== void 0) target.cacheRead = cacheReadTokens;
|
|
674
|
+
const cacheWriteTokens = payload.cache_creation_input_tokens == null ? 0 : readAnthropicUsageTokenCount(payload.cache_creation_input_tokens);
|
|
675
|
+
if (cacheWriteTokens !== void 0) target.cacheWrite = cacheWriteTokens;
|
|
676
|
+
const { cacheWrite1h } = readAnthropicCacheWriteUsage(payload);
|
|
677
|
+
if (cacheWrite1h !== void 0) target.cacheWrite1h = cacheWrite1h;
|
|
678
|
+
target.totalTokens = target.input + target.output + target.cacheRead + target.cacheWrite;
|
|
679
|
+
if (promptTokens > 0 && outputTokens !== void 0) target.contextUsage = {
|
|
680
|
+
state: "available",
|
|
681
|
+
promptTokens,
|
|
682
|
+
totalTokens: promptTokens + target.output
|
|
683
|
+
};
|
|
684
|
+
return promptTokens > 0 ? promptUsage : void 0;
|
|
685
|
+
}
|
|
686
|
+
/** Keep cumulative billing separate from the final server-side iteration context. */
|
|
687
|
+
function applyAnthropicMessageDeltaUsage(target, payload, messageStartPromptUsage) {
|
|
688
|
+
const usage = payload ?? {};
|
|
689
|
+
const inputTokens = readAnthropicUsageTokenCount(usage.input_tokens);
|
|
690
|
+
if (inputTokens !== void 0) target.input = inputTokens;
|
|
691
|
+
const outputTokens = readAnthropicUsageTokenCount(usage.output_tokens);
|
|
692
|
+
if (outputTokens !== void 0) target.output = outputTokens;
|
|
693
|
+
const cacheReadTokens = readAnthropicUsageTokenCount(usage.cache_read_input_tokens);
|
|
694
|
+
if (cacheReadTokens !== void 0) target.cacheRead = cacheReadTokens;
|
|
695
|
+
const cacheWriteTokens = readAnthropicUsageTokenCount(usage.cache_creation_input_tokens);
|
|
696
|
+
if (cacheWriteTokens !== void 0) target.cacheWrite = cacheWriteTokens;
|
|
697
|
+
const { cacheWrite1h } = readAnthropicCacheWriteUsage(usage);
|
|
698
|
+
if (cacheWrite1h !== void 0) target.cacheWrite1h = cacheWrite1h;
|
|
699
|
+
target.totalTokens = target.input + target.output + target.cacheRead + target.cacheWrite;
|
|
700
|
+
const iterationUsage = readLastAnthropicIterationUsage(usage);
|
|
701
|
+
if (iterationUsage.state === "valid") target.contextUsage = {
|
|
702
|
+
state: "available",
|
|
703
|
+
promptTokens: iterationUsage.usage.contextPromptTokens,
|
|
704
|
+
totalTokens: iterationUsage.usage.totalTokens
|
|
705
|
+
};
|
|
706
|
+
else if (iterationUsage.state === "invalid") target.contextUsage = { state: "unavailable" };
|
|
707
|
+
else if (outputTokens !== void 0 && (messageStartPromptUsage !== void 0 || inputTokens !== void 0 && cacheReadTokens !== void 0 && cacheWriteTokens !== void 0)) {
|
|
708
|
+
const promptTokens = target.input + target.cacheRead + target.cacheWrite;
|
|
709
|
+
target.contextUsage = {
|
|
710
|
+
state: "available",
|
|
711
|
+
promptTokens,
|
|
712
|
+
totalTokens: promptTokens + target.output
|
|
713
|
+
};
|
|
714
|
+
} else target.contextUsage = { state: "unavailable" };
|
|
715
|
+
}
|
|
458
716
|
//#endregion
|
|
459
|
-
export { canonicalizeBase64 as
|
|
717
|
+
export { applyAnthropicPayloadPolicyToParams as A, usesFoundryBearerAuth as C, canonicalizeBase64 as D, resolveAnthropicImageMediaType as E, resolveAnthropicPayloadPolicy as M, applyAnthropicCacheControlToMessages as O, omitFoundryBearerCredentialHeaders as S, normalizeAnthropicInlineContent as T, CLAUDE_OPUS_FALLBACK_MODEL_COST as _, readAnthropicUsageTokenCount as a, resolveAnthropicFallbackServingModelCost as b, normalizeAnthropicToolChoice as c, resolveOriginalAnthropicToolName as d, toClaudeCodeToolName as f, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as g, ANTHROPIC_SERVER_SIDE_FALLBACKS as h, readAnthropicPromptUsageSnapshot as i, resolveAnthropicEphemeralCacheControl as j, applyAnthropicEphemeralCacheControlMarkers as k, projectAnthropicTools as l, findActiveAnthropicToolTurnAssistantIndex as m, applyAnthropicMessageStartUsage as n, readLastAnthropicIterationUsage as o, ANTHROPIC_OMITTED_REASONING_TEXT as p, readAnthropicCacheWriteUsage as r, normalizeAnthropicToolCallId as s, applyAnthropicMessageDeltaUsage as t, reconcileAnthropicToolChoice as u, applyAnthropicFallbackBoundary as v, createAnthropicInlineImageBudget as w, applyAnthropicRefusal as x, readAnthropicFallbackBoundary as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "./types-
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "./types-CH7ReIcU.mjs";
|
|
2
2
|
//#region packages/ai/src/api-registry.d.ts
|
|
3
3
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
4
4
|
type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
|