@openclaw/ai 2026.8.1-beta.1 → 2026.8.1-beta.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-CE-7SkF6.mjs → anthropic-B6dLpq5L.mjs} +37 -22
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-8lJNKXOE.mjs} +225 -102
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-BP6AWT8j.d.mts} +3 -1
- package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CGQu21aw.mjs → google-C7h2QzDX.mjs} +4 -4
- package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-B0Qr9OR7.mjs} +9 -18
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-Bhc3TjDl.mjs} +5 -4
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/{host-Bl7Kgddo.mjs → host-DTqNc7ad.mjs} +227 -168
- package/dist/{host-Dn4_SZI2.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +13 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -4
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-Dx6VzNjf.mjs → mistral-CEWoQI_g.mjs} +26 -45
- package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +225 -144
- package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-BPnt4Sml.mjs} +28 -43
- package/dist/openai-completions-compat-Dt3dcawL.d.mts +43 -0
- package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-DhIKtOup.mjs} +17 -24
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-DgNTYnRY.mjs} +3 -3
- package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-DXIt3iY5.mjs} +1211 -908
- package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-BkFkqqK0.mjs} +198 -172
- package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CY04OcvQ.mjs} +151 -128
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-C5kYML7i.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BYqrYtC_.mjs} +28 -2
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +5 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +135 -178
- package/dist/transports.mjs +1732 -1294
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-CH7ReIcU.d.mts → types-BHNrPS1l.d.mts} +19 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-CcPcuEbR.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
- package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
- package/dist/provider-error-DI0Ts28U.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
- package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
- package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./
|
|
3
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
2
|
+
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-JsNA5KCu.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
4
|
+
import { r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
5
|
+
import { _ as resolveAnthropicThinkingEffort, a as describeToolResultMediaPlaceholder, b as usesClaudeStreamingRefusalContract, d as ANTHROPIC_CLAUDE_CODE_VERSION, f as applyClaudeRequestContract, g as requiresClaudeAdaptiveThinking, h as prepareClaudeNoPrefillRequestContext, l as isImageWithMediaPayload, m as mapAnthropicStopReason, n as getAiTransportHost, o as extractToolResultBlockText, r as resolveAiTransportHeaderSentinels, s as extractToolResultText, u as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, y as usesClaudeFable5MessagesContract } from "./host-DTqNc7ad.mjs";
|
|
6
|
+
import { n as projectProviderError } from "./provider-error-BUwEnjXq.mjs";
|
|
6
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
7
|
-
import { t as
|
|
8
|
-
import { a as
|
|
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";
|
|
8
|
+
import { c as splitSystemPromptCacheBoundary, l as stripSystemPromptCacheBoundary, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "./simple-options-D58D5Kvw.mjs";
|
|
9
|
+
import { A as resolveAnthropicImageMediaType, C as readAnthropicFallbackBoundary, D as usesFoundryBearerAuth, E as omitFoundryBearerCredentialHeaders, O as createAnthropicInlineImageBudget, S as applyAnthropicFallbackBoundary, T as applyAnthropicRefusal, _ as ANTHROPIC_OMITTED_REASONING_TEXT, a as applyAnthropicMessageDeltaUsage, b as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, d as normalizeAnthropicToolCallId, f as normalizeAnthropicToolChoice, g as toClaudeCodeToolName, h as resolveOriginalAnthropicToolName, i as suppressAnthropicCompaction, j as applyAnthropicCacheControlToMessages, k as normalizeAnthropicInlineContent, m as reconcileAnthropicToolChoice, n as createCompactionCapture, o as applyAnthropicMessageStartUsage, p as projectAnthropicTools, r as isAnthropicReplayRejection, t as buildAnthropicReplayPlan, v as findActiveAnthropicToolTurnAssistantIndex, w as resolveAnthropicFallbackServingModelCost, y as ANTHROPIC_SERVER_SIDE_FALLBACKS } from "./anthropic-compaction-replay-8lJNKXOE.mjs";
|
|
10
10
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
11
|
-
import { n as parseStreamingJson, t as parseJsonWithRepair } from "./json-parse-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { t as
|
|
15
|
-
import { t as formatProviderError } from "./provider-error-DI0Ts28U.mjs";
|
|
11
|
+
import { n as parseStreamingJson, t as parseJsonWithRepair } from "./json-parse-CDnesDM_.mjs";
|
|
12
|
+
import { n as notifyLlmRequestActivity, t as headersToRecord } from "./headers-DdOQtGuU.mjs";
|
|
13
|
+
import { f as transportAbortError, t as transformProviderMessages } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
14
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-DJqkxbhC.mjs";
|
|
16
15
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
17
|
-
import "./transform-messages-DfjpNXNQ.mjs";
|
|
18
16
|
import Anthropic from "@anthropic-ai/sdk";
|
|
19
17
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
20
18
|
//#region packages/ai/src/providers/anthropic.ts
|
|
@@ -159,6 +157,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
159
157
|
const eventSink = refusalBuffer ?? stream;
|
|
160
158
|
let costModel = model;
|
|
161
159
|
let messageStartPromptUsage;
|
|
160
|
+
let usedCompactionReplay = false;
|
|
162
161
|
try {
|
|
163
162
|
let client;
|
|
164
163
|
let isOAuth;
|
|
@@ -183,6 +182,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
183
182
|
serverSideFallback = created.serverSideFallback;
|
|
184
183
|
}
|
|
185
184
|
const builtParams = await buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback);
|
|
185
|
+
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
186
186
|
let params = builtParams.params;
|
|
187
187
|
const toolProjection = builtParams.toolProjection;
|
|
188
188
|
const nextParams = await requestOptions?.onPayload?.(params, model);
|
|
@@ -203,6 +203,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
203
203
|
}, model);
|
|
204
204
|
const blocks = output.content;
|
|
205
205
|
const blockIndexes = /* @__PURE__ */ new Map();
|
|
206
|
+
const compactionCapture = createCompactionCapture(output, model, requestOptions);
|
|
206
207
|
for await (const event of iterateAnthropicEvents(response, refusalBuffer !== void 0)) if (event.type === "message_start") {
|
|
207
208
|
output.responseId = event.message.id;
|
|
208
209
|
output.responseModel = event.message.model;
|
|
@@ -213,6 +214,8 @@ const streamAnthropic = (model, context, options) => {
|
|
|
213
214
|
partial: output
|
|
214
215
|
});
|
|
215
216
|
} else if (event.type === "content_block_start") {
|
|
217
|
+
const rawContentBlock = event.content_block;
|
|
218
|
+
if (requestOptions?.anthropicServerCompaction === true && compactionCapture.begin(event.index, rawContentBlock, output.content.length)) continue;
|
|
216
219
|
const fallbackBoundary = refusalBuffer ? readAnthropicFallbackBoundary(event.content_block) : null;
|
|
217
220
|
if (fallbackBoundary) {
|
|
218
221
|
refusalBuffer?.discard();
|
|
@@ -316,7 +319,9 @@ const streamAnthropic = (model, context, options) => {
|
|
|
316
319
|
});
|
|
317
320
|
}
|
|
318
321
|
} else if (event.type === "content_block_delta") {
|
|
319
|
-
|
|
322
|
+
const rawDelta = event.delta;
|
|
323
|
+
if (compactionCapture.delta(event.index, rawDelta)) continue;
|
|
324
|
+
else if (event.delta.type === "text_delta") {
|
|
320
325
|
const index = blockIndexes.get(event.index);
|
|
321
326
|
const block = index === void 0 ? void 0 : blocks[index];
|
|
322
327
|
if (index !== void 0 && block?.type === "text") {
|
|
@@ -362,6 +367,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
362
367
|
}
|
|
363
368
|
}
|
|
364
369
|
} else if (event.type === "content_block_stop") {
|
|
370
|
+
if (compactionCapture.complete(event.index)) continue;
|
|
365
371
|
const index = blockIndexes.get(event.index);
|
|
366
372
|
const block = index === void 0 ? void 0 : blocks[index];
|
|
367
373
|
if (index !== void 0 && block) {
|
|
@@ -414,11 +420,12 @@ const streamAnthropic = (model, context, options) => {
|
|
|
414
420
|
refusalBuffer.discard();
|
|
415
421
|
output.content = [];
|
|
416
422
|
}
|
|
417
|
-
|
|
418
|
-
|
|
423
|
+
if (usedCompactionReplay && isAnthropicReplayRejection(error)) suppressAnthropicCompaction(output, model, requestOptions);
|
|
424
|
+
const terminal = projectProviderError(error, requestOptions?.signal);
|
|
425
|
+
Object.assign(output, terminal);
|
|
419
426
|
stream.push({
|
|
420
427
|
type: "error",
|
|
421
|
-
reason:
|
|
428
|
+
reason: terminal.stopReason,
|
|
422
429
|
error: output
|
|
423
430
|
});
|
|
424
431
|
stream.end();
|
|
@@ -442,6 +449,8 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
442
449
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
443
450
|
const base = {
|
|
444
451
|
...buildBaseOptions(model, options, apiKey),
|
|
452
|
+
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
453
|
+
authProfileId: options?.authProfileId,
|
|
445
454
|
maxTokens: clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens),
|
|
446
455
|
toolChoice: options?.toolChoice
|
|
447
456
|
};
|
|
@@ -612,9 +621,14 @@ async function buildParams(model, context, isOAuthTokenResult, options, serverSi
|
|
|
612
621
|
const systemCacheControlCount = countNativeCacheControlMarkers(system);
|
|
613
622
|
const toolCacheControlCount = countNativeCacheControlMarkers(tools);
|
|
614
623
|
const messageCacheControlLimit = Math.max(0, ANTHROPIC_CACHE_CONTROL_LIMIT - systemCacheControlCount - toolCacheControlCount);
|
|
624
|
+
const replayPlan = buildAnthropicReplayPlan(context.messages, model, {
|
|
625
|
+
enabled: !isOAuthTokenResult && options?.anthropicServerCompaction === true,
|
|
626
|
+
authProfileId: options?.authProfileId,
|
|
627
|
+
sessionId: options?.sessionId
|
|
628
|
+
});
|
|
615
629
|
const params = {
|
|
616
630
|
model: model.id,
|
|
617
|
-
messages: await convertMessages(
|
|
631
|
+
messages: await convertMessages(replayPlan.messages, model, isOAuthTokenResult, cacheControl, messageCacheControlLimit, replayThinkingEnabled, compat.allowEmptySignature, replayPlan.compaction),
|
|
618
632
|
max_tokens: options?.maxTokens ?? model.maxTokens,
|
|
619
633
|
stream: true
|
|
620
634
|
};
|
|
@@ -651,14 +665,15 @@ async function buildParams(model, context, isOAuthTokenResult, options, serverSi
|
|
|
651
665
|
}
|
|
652
666
|
return {
|
|
653
667
|
params,
|
|
654
|
-
toolProjection
|
|
668
|
+
toolProjection,
|
|
669
|
+
usedCompactionReplay: replayPlan.compaction !== void 0
|
|
655
670
|
};
|
|
656
671
|
}
|
|
657
|
-
async function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false) {
|
|
672
|
+
async function convertMessages(messages, model, isOAuthTokenValue, cacheControl, messageCacheControlLimit = 4, replayThinkingEnabled = true, allowEmptySignature = false, compaction) {
|
|
658
673
|
const params = [];
|
|
659
674
|
const imageBudget = createAnthropicInlineImageBudget();
|
|
660
675
|
const cacheBreakpointOptOutParamIndexes = /* @__PURE__ */ new Set();
|
|
661
|
-
const transformedMessages =
|
|
676
|
+
const transformedMessages = transformProviderMessages(messages, model, normalizeAnthropicToolCallId);
|
|
662
677
|
const activeToolTurnAssistantIndex = replayThinkingEnabled ? -1 : findActiveAnthropicToolTurnAssistantIndex(transformedMessages);
|
|
663
678
|
for (let i = 0; i < transformedMessages.length; i++) {
|
|
664
679
|
const msg = transformedMessages[i];
|
|
@@ -699,7 +714,7 @@ async function convertMessages(messages, model, isOAuthTokenValue, cacheControl,
|
|
|
699
714
|
});
|
|
700
715
|
}
|
|
701
716
|
} else if (msg.role === "assistant") {
|
|
702
|
-
const blocks = [];
|
|
717
|
+
const blocks = i === 0 && compaction ? [compaction] : [];
|
|
703
718
|
let omittedThinking = false;
|
|
704
719
|
for (const block of msg.content) if (block.type === "text") {
|
|
705
720
|
if (block.text.trim().length === 0) continue;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { o as resolveClaudeFable5ModelIdentity, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./
|
|
2
|
-
import {
|
|
1
|
+
import { o as resolveClaudeFable5ModelIdentity, s as resolveClaudeModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-JsNA5KCu.mjs";
|
|
2
|
+
import { i as normalizeOptionalLowercaseString, r as normalizeNullableString } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
+
import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
|
|
4
|
+
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
5
|
+
import { a as estimateBase64DecodedBytes } from "./provider-error-BUwEnjXq.mjs";
|
|
6
|
+
import { r as asNonNegativeFiniteNumber, s as parseStrictPositiveInteger } from "./number-coercion-H9qHik3g.mjs";
|
|
3
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-
|
|
8
|
+
import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, l as stripSystemPromptCacheBoundary } from "./simple-options-D58D5Kvw.mjs";
|
|
9
|
+
import { a as resolveProviderEndpoint, o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-q5d7QX5c.mjs";
|
|
10
|
+
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
6
11
|
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
7
12
|
/**
|
|
8
13
|
* Anthropic-family request payload policy helpers.
|
|
@@ -10,6 +15,29 @@ import { o as resolveProviderRequestCapabilities, t as projectRuntimeToolInputSc
|
|
|
10
15
|
* capabilities allow them.
|
|
11
16
|
*/
|
|
12
17
|
const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
|
|
18
|
+
const ANTHROPIC_COMPACT_THRESHOLD_MIN = 5e4;
|
|
19
|
+
function parsePositiveInteger(value) {
|
|
20
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
21
|
+
return typeof value === "string" ? parseStrictPositiveInteger(value) : void 0;
|
|
22
|
+
}
|
|
23
|
+
/** Resolve the Anthropic input-token trigger, including the API's minimum. */
|
|
24
|
+
function resolveAnthropicCompactThreshold(contextWindow, configured) {
|
|
25
|
+
const configuredThreshold = parsePositiveInteger(configured);
|
|
26
|
+
if (configuredThreshold !== void 0) return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, configuredThreshold);
|
|
27
|
+
const resolvedContextWindow = parsePositiveInteger(contextWindow);
|
|
28
|
+
return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, resolvedContextWindow === void 0 ? ANTHROPIC_COMPACT_THRESHOLD_MIN : Math.floor(resolvedContextWindow * .7));
|
|
29
|
+
}
|
|
30
|
+
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
31
|
+
function resolveAnthropicServerCompactionPlan(model, extraParams) {
|
|
32
|
+
const provider = normalizeOptionalLowercaseString(model.provider);
|
|
33
|
+
const api = normalizeOptionalLowercaseString(model.api);
|
|
34
|
+
const endpointClass = resolveProviderEndpoint(model.baseUrl).endpointClass;
|
|
35
|
+
const enabled = extraParams?.anthropicServerCompaction === true && provider === "anthropic" && api === "anthropic-messages" && (endpointClass === "default" || endpointClass === "anthropic-public");
|
|
36
|
+
return {
|
|
37
|
+
enabled,
|
|
38
|
+
...enabled ? { threshold: resolveAnthropicCompactThreshold(model.contextWindow, extraParams?.anthropicCompactThreshold) } : {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
13
41
|
function resolveBaseUrlHostname(baseUrl) {
|
|
14
42
|
try {
|
|
15
43
|
return new URL(baseUrl).hostname;
|
|
@@ -123,16 +151,20 @@ function countAnthropicCacheControlMarkers(blocks) {
|
|
|
123
151
|
}
|
|
124
152
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
125
153
|
function resolveAnthropicPayloadPolicy(input) {
|
|
154
|
+
const capabilities = resolveProviderRequestCapabilities({
|
|
155
|
+
provider: input.provider,
|
|
156
|
+
api: input.api,
|
|
157
|
+
baseUrl: input.baseUrl,
|
|
158
|
+
capability: "llm",
|
|
159
|
+
transport: "stream"
|
|
160
|
+
});
|
|
161
|
+
const serverCompactionPlan = resolveAnthropicServerCompactionPlan(input, input.extraParams);
|
|
126
162
|
return {
|
|
127
|
-
allowsServiceTier:
|
|
128
|
-
provider: input.provider,
|
|
129
|
-
api: input.api,
|
|
130
|
-
baseUrl: input.baseUrl,
|
|
131
|
-
capability: "llm",
|
|
132
|
-
transport: "stream"
|
|
133
|
-
}).allowsAnthropicServiceTier,
|
|
163
|
+
allowsServiceTier: capabilities.allowsAnthropicServiceTier,
|
|
134
164
|
cacheControl: input.enableCacheControl === true ? resolveAnthropicEphemeralCacheControl(input.baseUrl, input.cacheRetention) : void 0,
|
|
135
|
-
|
|
165
|
+
compactThreshold: serverCompactionPlan.threshold ?? resolveAnthropicCompactThreshold(input.contextWindow, input.extraParams?.anthropicCompactThreshold),
|
|
166
|
+
serviceTier: input.serviceTier,
|
|
167
|
+
useServerCompaction: input.enableServerCompaction === true && serverCompactionPlan.enabled
|
|
136
168
|
};
|
|
137
169
|
}
|
|
138
170
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
@@ -140,6 +172,13 @@ function applyAnthropicPayloadPolicyToParams(payloadObj, policy, cacheBreakpoint
|
|
|
140
172
|
if (policy.allowsServiceTier && policy.serviceTier !== void 0 && payloadObj.service_tier === void 0) payloadObj.service_tier = policy.serviceTier;
|
|
141
173
|
if (policy.cacheControl) applyAnthropicCacheControlToSystem(payloadObj.system, policy.cacheControl);
|
|
142
174
|
else stripAnthropicSystemPromptBoundary(payloadObj.system);
|
|
175
|
+
if (policy.useServerCompaction && payloadObj.context_management === void 0) payloadObj.context_management = { edits: [{
|
|
176
|
+
type: "compact_20260112",
|
|
177
|
+
trigger: {
|
|
178
|
+
type: "input_tokens",
|
|
179
|
+
value: policy.compactThreshold
|
|
180
|
+
}
|
|
181
|
+
}] };
|
|
143
182
|
if (!policy.cacheControl) return;
|
|
144
183
|
const usedMarkers = countAnthropicCacheControlMarkers(payloadObj.system) + countAnthropicCacheControlMarkers(payloadObj.tools);
|
|
145
184
|
applyAnthropicCacheControlToMessages(payloadObj.messages, policy.cacheControl, ANTHROPIC_CACHE_CONTROL_LIMIT - usedMarkers, cacheBreakpointOptOutMessageIndexes);
|
|
@@ -176,83 +215,6 @@ function applyAnthropicEphemeralCacheControlMarkers(payloadObj, cacheControl = {
|
|
|
176
215
|
}
|
|
177
216
|
}
|
|
178
217
|
//#endregion
|
|
179
|
-
//#region packages/media-core/src/base64.ts
|
|
180
|
-
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
181
|
-
function estimateBase64DecodedBytes(base64) {
|
|
182
|
-
let effectiveLen = 0;
|
|
183
|
-
for (let i = 0; i < base64.length; i += 1) {
|
|
184
|
-
if (base64.charCodeAt(i) <= 32) continue;
|
|
185
|
-
effectiveLen += 1;
|
|
186
|
-
}
|
|
187
|
-
if (effectiveLen === 0) return 0;
|
|
188
|
-
let padding = 0;
|
|
189
|
-
let end = base64.length - 1;
|
|
190
|
-
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
191
|
-
if (end >= 0 && base64[end] === "=") {
|
|
192
|
-
padding = 1;
|
|
193
|
-
end -= 1;
|
|
194
|
-
while (end >= 0 && base64.charCodeAt(end) <= 32) end -= 1;
|
|
195
|
-
if (end >= 0 && base64[end] === "=") padding = 2;
|
|
196
|
-
}
|
|
197
|
-
const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
|
|
198
|
-
return Math.max(0, estimated);
|
|
199
|
-
}
|
|
200
|
-
const CANONICALIZE_BASE64_CHUNK_SIZE = 8192;
|
|
201
|
-
function isBase64DataChar(code) {
|
|
202
|
-
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
|
|
203
|
-
}
|
|
204
|
-
function base64DataValue(code) {
|
|
205
|
-
if (code >= 65 && code <= 90) return code - 65;
|
|
206
|
-
if (code >= 97 && code <= 122) return code - 97 + 26;
|
|
207
|
-
if (code >= 48 && code <= 57) return code - 48 + 52;
|
|
208
|
-
return code === 43 ? 62 : 63;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Normalizes and validates a base64 string, returning canonical no-whitespace
|
|
212
|
-
* base64 only when the input has valid alphabet, padding, and length.
|
|
213
|
-
*/
|
|
214
|
-
function canonicalizeBase64(base64) {
|
|
215
|
-
const chunks = [];
|
|
216
|
-
let current = "";
|
|
217
|
-
let cleanedLength = 0;
|
|
218
|
-
let padding = 0;
|
|
219
|
-
let sawPadding = false;
|
|
220
|
-
let lastDataCode = 0;
|
|
221
|
-
const append = (char) => {
|
|
222
|
-
current += char;
|
|
223
|
-
cleanedLength += 1;
|
|
224
|
-
if (current.length >= CANONICALIZE_BASE64_CHUNK_SIZE) {
|
|
225
|
-
chunks.push(current);
|
|
226
|
-
current = "";
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
for (let i = 0; i < base64.length; i += 1) {
|
|
230
|
-
const code = base64.charCodeAt(i);
|
|
231
|
-
if (code <= 32) continue;
|
|
232
|
-
if (code === 61) {
|
|
233
|
-
padding += 1;
|
|
234
|
-
if (padding > 2) return;
|
|
235
|
-
sawPadding = true;
|
|
236
|
-
append("=");
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
if (sawPadding || !isBase64DataChar(code)) return;
|
|
240
|
-
lastDataCode = code;
|
|
241
|
-
append(base64[i] ?? "");
|
|
242
|
-
}
|
|
243
|
-
if (cleanedLength === 0) return;
|
|
244
|
-
const remainder = cleanedLength % 4;
|
|
245
|
-
if (remainder !== 0) {
|
|
246
|
-
if (sawPadding || remainder === 1) return;
|
|
247
|
-
current += "=".repeat(4 - remainder);
|
|
248
|
-
}
|
|
249
|
-
const effectivePadding = remainder === 0 ? padding : 4 - remainder;
|
|
250
|
-
const padBitMask = effectivePadding === 2 ? 15 : effectivePadding === 1 ? 3 : 0;
|
|
251
|
-
if (padBitMask !== 0 && (base64DataValue(lastDataCode) & padBitMask) !== 0) return;
|
|
252
|
-
if (current) chunks.push(current);
|
|
253
|
-
return chunks.join("");
|
|
254
|
-
}
|
|
255
|
-
//#endregion
|
|
256
218
|
//#region packages/ai/src/internal/anthropic-inline-images.ts
|
|
257
219
|
const ANTHROPIC_IMAGE_MEDIA_TYPE_SET = /* @__PURE__ */ new Set([
|
|
258
220
|
"image/jpeg",
|
|
@@ -307,9 +269,6 @@ function omitFoundryBearerCredentialHeaders(headers) {
|
|
|
307
269
|
}
|
|
308
270
|
//#endregion
|
|
309
271
|
//#region packages/ai/src/providers/anthropic-refusal.ts
|
|
310
|
-
function readNullableString(value) {
|
|
311
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
312
|
-
}
|
|
313
272
|
function readAnthropicRefusalDetails(value) {
|
|
314
273
|
if (!value || typeof value !== "object") return {
|
|
315
274
|
category: null,
|
|
@@ -317,8 +276,8 @@ function readAnthropicRefusalDetails(value) {
|
|
|
317
276
|
};
|
|
318
277
|
const details = value;
|
|
319
278
|
return {
|
|
320
|
-
category:
|
|
321
|
-
explanation:
|
|
279
|
+
category: normalizeNullableString(details.category),
|
|
280
|
+
explanation: normalizeNullableString(details.explanation)
|
|
322
281
|
};
|
|
323
282
|
}
|
|
324
283
|
function formatAnthropicRefusalMessage(details) {
|
|
@@ -618,7 +577,7 @@ function resolveOriginalAnthropicToolName(name, projection) {
|
|
|
618
577
|
//#endregion
|
|
619
578
|
//#region packages/ai/src/providers/anthropic-usage.ts
|
|
620
579
|
function readAnthropicUsageTokenCount(value) {
|
|
621
|
-
return
|
|
580
|
+
return asNonNegativeFiniteNumber(value);
|
|
622
581
|
}
|
|
623
582
|
function readAnthropicCacheWriteUsage(usage) {
|
|
624
583
|
if (!usage.cache_creation || typeof usage.cache_creation !== "object") return {};
|
|
@@ -661,6 +620,33 @@ function readLastAnthropicIterationUsage(usage) {
|
|
|
661
620
|
}
|
|
662
621
|
};
|
|
663
622
|
}
|
|
623
|
+
function readAnthropicCompactionBilledUsage(iterations) {
|
|
624
|
+
if (!Array.isArray(iterations) || iterations.length === 0) return;
|
|
625
|
+
let sawCompaction = false;
|
|
626
|
+
const billed = {
|
|
627
|
+
input: 0,
|
|
628
|
+
output: 0,
|
|
629
|
+
cacheRead: 0,
|
|
630
|
+
cacheWrite: 0,
|
|
631
|
+
cacheWrite1h: 0
|
|
632
|
+
};
|
|
633
|
+
for (const iteration of iterations) {
|
|
634
|
+
if (!iteration || typeof iteration !== "object" || Array.isArray(iteration)) return;
|
|
635
|
+
const record = iteration;
|
|
636
|
+
const input = readAnthropicUsageTokenCount(record.input_tokens);
|
|
637
|
+
const output = readAnthropicUsageTokenCount(record.output_tokens);
|
|
638
|
+
const cacheRead = readAnthropicUsageTokenCount(record.cache_read_input_tokens);
|
|
639
|
+
const cacheWrite = readAnthropicUsageTokenCount(record.cache_creation_input_tokens);
|
|
640
|
+
if (input === void 0 || output === void 0 || cacheRead === void 0 || cacheWrite === void 0) return;
|
|
641
|
+
sawCompaction ||= record.type === "compaction";
|
|
642
|
+
billed.input += input;
|
|
643
|
+
billed.output += output;
|
|
644
|
+
billed.cacheRead += cacheRead;
|
|
645
|
+
billed.cacheWrite += cacheWrite;
|
|
646
|
+
billed.cacheWrite1h += readAnthropicCacheWriteUsage(record).cacheWrite1h ?? 0;
|
|
647
|
+
}
|
|
648
|
+
return sawCompaction ? billed : void 0;
|
|
649
|
+
}
|
|
664
650
|
/** Record independent billing buckets without treating zero placeholders as context proof. */
|
|
665
651
|
function applyAnthropicMessageStartUsage(target, payload) {
|
|
666
652
|
const promptUsage = readAnthropicPromptUsageSnapshot(payload);
|
|
@@ -686,16 +672,23 @@ function applyAnthropicMessageStartUsage(target, payload) {
|
|
|
686
672
|
/** Keep cumulative billing separate from the final server-side iteration context. */
|
|
687
673
|
function applyAnthropicMessageDeltaUsage(target, payload, messageStartPromptUsage) {
|
|
688
674
|
const usage = payload ?? {};
|
|
675
|
+
const billedIterations = readAnthropicCompactionBilledUsage(usage.iterations);
|
|
689
676
|
const inputTokens = readAnthropicUsageTokenCount(usage.input_tokens);
|
|
690
|
-
if (inputTokens !== void 0) target.input = inputTokens;
|
|
691
677
|
const outputTokens = readAnthropicUsageTokenCount(usage.output_tokens);
|
|
692
|
-
if (outputTokens !== void 0) target.output = outputTokens;
|
|
693
678
|
const cacheReadTokens = readAnthropicUsageTokenCount(usage.cache_read_input_tokens);
|
|
694
|
-
if (cacheReadTokens !== void 0) target.cacheRead = cacheReadTokens;
|
|
695
679
|
const cacheWriteTokens = readAnthropicUsageTokenCount(usage.cache_creation_input_tokens);
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
680
|
+
const resolved = billedIterations ?? {
|
|
681
|
+
input: inputTokens,
|
|
682
|
+
output: outputTokens,
|
|
683
|
+
cacheRead: cacheReadTokens,
|
|
684
|
+
cacheWrite: cacheWriteTokens,
|
|
685
|
+
cacheWrite1h: readAnthropicCacheWriteUsage(usage).cacheWrite1h
|
|
686
|
+
};
|
|
687
|
+
if (resolved.input !== void 0) target.input = resolved.input;
|
|
688
|
+
if (resolved.output !== void 0) target.output = resolved.output;
|
|
689
|
+
if (resolved.cacheRead !== void 0) target.cacheRead = resolved.cacheRead;
|
|
690
|
+
if (resolved.cacheWrite !== void 0) target.cacheWrite = resolved.cacheWrite;
|
|
691
|
+
if (resolved.cacheWrite1h !== void 0) target.cacheWrite1h = resolved.cacheWrite1h;
|
|
699
692
|
target.totalTokens = target.input + target.output + target.cacheRead + target.cacheWrite;
|
|
700
693
|
const iterationUsage = readLastAnthropicIterationUsage(usage);
|
|
701
694
|
if (iterationUsage.state === "valid") target.contextUsage = {
|
|
@@ -714,4 +707,134 @@ function applyAnthropicMessageDeltaUsage(target, payload, messageStartPromptUsag
|
|
|
714
707
|
} else target.contextUsage = { state: "unavailable" };
|
|
715
708
|
}
|
|
716
709
|
//#endregion
|
|
717
|
-
|
|
710
|
+
//#region packages/ai/src/transports/anthropic-compaction-replay.ts
|
|
711
|
+
const ANTHROPIC_COMPACTION_REPLAY_TYPE = "anthropic-compaction";
|
|
712
|
+
const ANTHROPIC_COMPACTION_SUPPRESSION_TYPE = "anthropic-compaction-suppression";
|
|
713
|
+
const ANTHROPIC_COMPACTION_SUPPRESSION_DATA = "rejected";
|
|
714
|
+
function createCompactionCapture(output, model, options) {
|
|
715
|
+
const pending = /* @__PURE__ */ new Map();
|
|
716
|
+
return {
|
|
717
|
+
begin(index, block, replayIndex) {
|
|
718
|
+
if (block?.type !== "compaction") return false;
|
|
719
|
+
const content = typeof block.content === "string" ? block.content : "";
|
|
720
|
+
pending.set(index, {
|
|
721
|
+
content,
|
|
722
|
+
replayIndex
|
|
723
|
+
});
|
|
724
|
+
return true;
|
|
725
|
+
},
|
|
726
|
+
delta(index, delta) {
|
|
727
|
+
const capture = pending.get(index);
|
|
728
|
+
if (!capture || delta?.type !== "compaction_delta") return false;
|
|
729
|
+
capture.content = typeof delta.content === "string" ? delta.content : capture.content;
|
|
730
|
+
return true;
|
|
731
|
+
},
|
|
732
|
+
complete(index) {
|
|
733
|
+
const capture = pending.get(index);
|
|
734
|
+
if (!capture) return false;
|
|
735
|
+
pending.delete(index);
|
|
736
|
+
captureAnthropicCompaction(output, capture.content, capture.replayIndex, model, options);
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function hashReplayValue(value) {
|
|
742
|
+
const normalized = value?.trim();
|
|
743
|
+
return normalized ? shortHash(normalized) : void 0;
|
|
744
|
+
}
|
|
745
|
+
function buildAnthropicReplayContext(model, options) {
|
|
746
|
+
return {
|
|
747
|
+
provider: model.provider,
|
|
748
|
+
api: model.api,
|
|
749
|
+
model: model.id,
|
|
750
|
+
baseUrlHash: hashReplayValue(model.baseUrl),
|
|
751
|
+
sessionHash: hashReplayValue(options?.sessionId),
|
|
752
|
+
authProfileHash: hashReplayValue(options?.authProfileId)
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
function readAnthropicCompactionState(value) {
|
|
756
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
757
|
+
const state = value;
|
|
758
|
+
if (!(state.v === 1 && typeof state.data === "string" && typeof state.provider === "string" && typeof state.api === "string" && typeof state.model === "string" && typeof state.baseUrlHash === "string" && (state.sessionHash === void 0 || typeof state.sessionHash === "string") && (state.authProfileHash === void 0 || typeof state.authProfileHash === "string"))) return;
|
|
759
|
+
const replayState = state;
|
|
760
|
+
if (replayState.type === ANTHROPIC_COMPACTION_SUPPRESSION_TYPE) return replayState.data === ANTHROPIC_COMPACTION_SUPPRESSION_DATA ? replayState : void 0;
|
|
761
|
+
if (replayState.type !== ANTHROPIC_COMPACTION_REPLAY_TYPE || replayState.data.length === 0 || replayState.replayIndex !== void 0 && (!Number.isSafeInteger(replayState.replayIndex) || replayState.replayIndex < 0)) return;
|
|
762
|
+
return replayState;
|
|
763
|
+
}
|
|
764
|
+
function replayContextMatches(state, context) {
|
|
765
|
+
return state.provider === context.provider && state.api === context.api && state.model === context.model && state.baseUrlHash === context.baseUrlHash && state.sessionHash === context.sessionHash && state.authProfileHash === context.authProfileHash;
|
|
766
|
+
}
|
|
767
|
+
function captureAnthropicCompaction(output, summary, replayIndex, model, options) {
|
|
768
|
+
const context = buildAnthropicReplayContext(model, options);
|
|
769
|
+
if (!summary || !context.baseUrlHash || !Number.isSafeInteger(replayIndex) || replayIndex < 0) return;
|
|
770
|
+
output.providerReplay = {
|
|
771
|
+
v: 1,
|
|
772
|
+
type: ANTHROPIC_COMPACTION_REPLAY_TYPE,
|
|
773
|
+
data: summary,
|
|
774
|
+
replayIndex,
|
|
775
|
+
...context,
|
|
776
|
+
baseUrlHash: context.baseUrlHash
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function suppressAnthropicCompaction(output, model, options) {
|
|
780
|
+
const context = buildAnthropicReplayContext(model, options);
|
|
781
|
+
if (!context.baseUrlHash) return;
|
|
782
|
+
output.providerReplay = {
|
|
783
|
+
v: 1,
|
|
784
|
+
type: ANTHROPIC_COMPACTION_SUPPRESSION_TYPE,
|
|
785
|
+
data: ANTHROPIC_COMPACTION_SUPPRESSION_DATA,
|
|
786
|
+
...context,
|
|
787
|
+
baseUrlHash: context.baseUrlHash
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function resolveNewestAnthropicCompaction(messages, model, options) {
|
|
791
|
+
const context = buildAnthropicReplayContext(model, options);
|
|
792
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
793
|
+
const message = messages[index];
|
|
794
|
+
if (message?.role !== "assistant") continue;
|
|
795
|
+
const replayState = readAnthropicCompactionState(message.providerReplay);
|
|
796
|
+
if (replayState?.type === ANTHROPIC_COMPACTION_SUPPRESSION_TYPE) {
|
|
797
|
+
if (replayContextMatches(replayState, context)) return;
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if (message.providerReplay?.type !== ANTHROPIC_COMPACTION_REPLAY_TYPE) continue;
|
|
801
|
+
if (!replayState) return;
|
|
802
|
+
if (!replayContextMatches(replayState, context)) return;
|
|
803
|
+
return {
|
|
804
|
+
owner: message,
|
|
805
|
+
replayIndex: replayState.replayIndex ?? 0,
|
|
806
|
+
summary: replayState.data
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function buildAnthropicReplayPlan(messages, model, options) {
|
|
811
|
+
if (options?.enabled !== true) return { messages };
|
|
812
|
+
const checkpoint = resolveNewestAnthropicCompaction(messages, model, options);
|
|
813
|
+
if (!checkpoint) return { messages };
|
|
814
|
+
const ownerIndex = messages.indexOf(checkpoint.owner);
|
|
815
|
+
return {
|
|
816
|
+
messages: [{
|
|
817
|
+
...checkpoint.owner,
|
|
818
|
+
content: checkpoint.owner.content.slice(checkpoint.replayIndex)
|
|
819
|
+
}, ...messages.slice(ownerIndex + 1)],
|
|
820
|
+
compaction: {
|
|
821
|
+
type: "compaction",
|
|
822
|
+
content: checkpoint.summary
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
/** Match Anthropic's 400 response when a replay block is no longer accepted. */
|
|
827
|
+
function isAnthropicReplayRejection(error) {
|
|
828
|
+
if (!error || typeof error !== "object") return false;
|
|
829
|
+
const record = error;
|
|
830
|
+
const nested = record.error && typeof record.error === "object" && !Array.isArray(record.error) ? record.error : void 0;
|
|
831
|
+
const text = [
|
|
832
|
+
record.message,
|
|
833
|
+
record.code,
|
|
834
|
+
nested?.message,
|
|
835
|
+
nested?.code
|
|
836
|
+
].filter((value) => typeof value === "string").join(" ").toLowerCase();
|
|
837
|
+
return (record.status === 400 || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
838
|
+
}
|
|
839
|
+
//#endregion
|
|
840
|
+
export { resolveAnthropicImageMediaType as A, readAnthropicFallbackBoundary as C, usesFoundryBearerAuth as D, omitFoundryBearerCredentialHeaders as E, resolveAnthropicPayloadPolicy as F, resolveAnthropicServerCompactionPlan as I, applyAnthropicEphemeralCacheControlMarkers as M, applyAnthropicPayloadPolicyToParams as N, createAnthropicInlineImageBudget as O, resolveAnthropicEphemeralCacheControl as P, applyAnthropicFallbackBoundary as S, applyAnthropicRefusal as T, ANTHROPIC_OMITTED_REASONING_TEXT as _, applyAnthropicMessageDeltaUsage as a, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as b, readAnthropicPromptUsageSnapshot as c, normalizeAnthropicToolCallId as d, normalizeAnthropicToolChoice as f, toClaudeCodeToolName as g, resolveOriginalAnthropicToolName as h, suppressAnthropicCompaction as i, applyAnthropicCacheControlToMessages as j, normalizeAnthropicInlineContent as k, readAnthropicUsageTokenCount as l, reconcileAnthropicToolChoice as m, createCompactionCapture as n, applyAnthropicMessageStartUsage as o, projectAnthropicTools as p, isAnthropicReplayRejection as r, readAnthropicCacheWriteUsage as s, buildAnthropicReplayPlan as t, readLastAnthropicIterationUsage as u, findActiveAnthropicToolTurnAssistantIndex as v, resolveAnthropicFallbackServingModelCost as w, CLAUDE_OPUS_FALLBACK_MODEL_COST as x, ANTHROPIC_SERVER_SIDE_FALLBACKS as y };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
2
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
3
|
+
type AnthropicServiceTier = "auto" | "standard_only";
|
|
4
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
5
|
+
type AnthropicEphemeralCacheControl = {
|
|
6
|
+
type: "ephemeral";
|
|
7
|
+
ttl?: "1h" | "5m";
|
|
8
|
+
};
|
|
9
|
+
type AnthropicPayloadPolicyInput = {
|
|
10
|
+
api?: string;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
cacheRetention?: "short" | "long" | "none";
|
|
13
|
+
contextWindow?: unknown;
|
|
14
|
+
enableCacheControl?: boolean;
|
|
15
|
+
enableServerCompaction?: boolean;
|
|
16
|
+
extraParams?: Record<string, unknown>;
|
|
17
|
+
provider?: string;
|
|
18
|
+
serviceTier?: AnthropicServiceTier;
|
|
19
|
+
};
|
|
20
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
21
|
+
type AnthropicPayloadPolicy = {
|
|
22
|
+
allowsServiceTier: boolean;
|
|
23
|
+
cacheControl: AnthropicEphemeralCacheControl | undefined;
|
|
24
|
+
compactThreshold: number;
|
|
25
|
+
serviceTier: AnthropicServiceTier | undefined;
|
|
26
|
+
useServerCompaction: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
29
|
+
declare function resolveAnthropicServerCompactionPlan(model: {
|
|
30
|
+
provider?: unknown;
|
|
31
|
+
api?: unknown;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
contextWindow?: unknown;
|
|
34
|
+
}, extraParams?: Record<string, unknown>): {
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
threshold?: number;
|
|
37
|
+
};
|
|
38
|
+
/** Resolve Anthropic cache-control marker retention for a request endpoint. */
|
|
39
|
+
declare function resolveAnthropicEphemeralCacheControl(baseUrl: string | undefined, cacheRetention: AnthropicPayloadPolicyInput["cacheRetention"]): AnthropicEphemeralCacheControl | undefined;
|
|
40
|
+
/** Apply one shared deepest-stable-message cache breakpoint policy. */
|
|
41
|
+
declare function applyAnthropicCacheControlToMessages(messages: unknown, cacheControl: AnthropicEphemeralCacheControl, markerLimit: number, cacheBreakpointOptOutMessageIndexes: ReadonlySet<number>): void;
|
|
42
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
43
|
+
declare function resolveAnthropicPayloadPolicy(input: AnthropicPayloadPolicyInput): AnthropicPayloadPolicy;
|
|
44
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
45
|
+
declare function applyAnthropicPayloadPolicyToParams(payloadObj: Record<string, unknown>, policy: AnthropicPayloadPolicy, cacheBreakpointOptOutMessageIndexes: ReadonlySet<number>): void;
|
|
46
|
+
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
47
|
+
declare function applyAnthropicEphemeralCacheControlMarkers(payloadObj: Record<string, unknown>, cacheControl?: AnthropicEphemeralCacheControl | null): void;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { resolveAnthropicPayloadPolicy as a, resolveAnthropicEphemeralCacheControl as i, applyAnthropicEphemeralCacheControlMarkers as n, resolveAnthropicServerCompactionPlan as o, applyAnthropicPayloadPolicyToParams as r, applyAnthropicCacheControlToMessages as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as Model,
|
|
1
|
+
import { E as Model, H as StreamOptions, R as SimpleStreamOptions, V as StreamFunction, n as Api, o as AssistantMessageEventStreamContract, u as Context } from "./types-BHNrPS1l.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;
|