@openclaw/ai 2026.10.5 → 2026.10.10-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/README.md +11 -0
- package/dist/{anthropic-DIIiiz99.mjs → anthropic-D6spfBri.mjs} +16 -18
- package/dist/{anthropic-payload-policy-DGblkHL5.d.mts → anthropic-payload-policy-Cr8xjazC.d.mts} +6 -3
- package/dist/{anthropic-stream-reducer-DfMVFm-r.mjs → anthropic-stream-reducer-CzPXOaLM.mjs} +55 -227
- package/dist/anthropic-tool-projection-BdAS3rtJ.mjs +165 -0
- package/dist/anthropic-tool-projection-DKH-aEWU.d.mts +51 -0
- package/dist/{api-registry-BhXXYdRA.d.mts → api-registry-gDt0faai.d.mts} +2 -2
- package/dist/{assistant-output-BuhRpLeD.mjs → assistant-output-6iFA1nbC.mjs} +2 -2
- package/dist/{azure-openai-responses-DGQnXRMs.mjs → azure-openai-responses-0TqHwnlD.mjs} +8 -8
- package/dist/{cloudflare-5qSGvIUH.mjs → cloudflare-Dttf8jKq.mjs} +1 -1
- package/dist/{credential-redaction-BHxruEH6.d.mts → credential-redaction-XvsPf7Yi.d.mts} +1 -0
- package/dist/{diagnostics-tQasYct1.mjs → diagnostics-Cv7cW3pS.mjs} +3 -3
- package/dist/diagnostics.d.mts +6 -6
- package/dist/diagnostics.mjs +2 -2
- package/dist/{env-api-keys-CrxwdylR.mjs → env-api-keys-Xd8dm_aV.mjs} +10 -34
- package/dist/event-stream-CDpFza-M.d.mts +1 -0
- package/dist/{event-stream-BcqWLo_u.d.mts → event-stream-CzpE1g_o.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{github-copilot-request-facts-DEE6gcB9.mjs → github-copilot-request-facts-F-EmvkpW.mjs} +1 -1
- package/dist/{google-interactions-zIz70M2e.mjs → google-interactions-DVQ7AaSF.mjs} +29 -50
- package/dist/{google-messages-CNbUJK5E.mjs → google-messages-DfpHVTaD.mjs} +15 -5
- package/dist/{google-provider-stream-Cn0XF1MG.mjs → google-provider-stream-DJ8ANfsS.mjs} +6 -6
- package/dist/{google-shared-BPnWP4tT.mjs → google-shared-VTcCJLW3.mjs} +21 -29
- package/dist/{google-vertex-XQ7OQtaM.mjs → google-vertex-Bkfizj7M.mjs} +3 -3
- package/dist/{google-BlbTC1Xp.mjs → google-zWpkDSeN.mjs} +4 -4
- package/dist/{host-Bf3NjYNj.mjs → host-B2gk-d1H.mjs} +5 -11
- package/dist/{host-CTDz7LXD.d.mts → host-jJOffdlW.d.mts} +4 -6
- package/dist/{host-policy-BzZluO6_.mjs → host-policy-mpqGhbeM.mjs} +1 -1
- package/dist/{index-BYDvopUB.d.mts → index-DSprYWaz.d.mts} +7 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +7 -53
- package/dist/internal/anthropic.mjs +6 -5
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -3
- package/dist/internal/openai.d.mts +17 -26
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +1 -1
- package/dist/internal/retry-after.mjs +80 -55
- package/dist/internal/runtime.d.mts +9 -31
- package/dist/internal/runtime.mjs +10 -116
- package/dist/internal/shared.d.mts +9 -7
- package/dist/internal/shared.mjs +8 -6
- package/dist/internal/tool-schema.d.mts +83 -5
- package/dist/internal/tool-schema.mjs +4 -3
- package/dist/{mistral-dCDCR5ur.mjs → mistral-CATJrwne.mjs} +32 -35
- package/dist/model-request-body-BD5vy4rP.d.mts +17 -0
- package/dist/{number-coercion-C3hztWoY.mjs → number-coercion-37gmNkuA.mjs} +1 -1
- package/dist/{openai-chatgpt-responses-D8-q7cgy.mjs → openai-chatgpt-responses-CtdnpWwe.mjs} +95 -63
- package/dist/{openai-completions-CMN24pza.mjs → openai-completions-B6sET3oI.mjs} +10 -8
- package/dist/{openai-completions-compat-i-nLZxFy.d.mts → openai-completions-compat-1gsjP-KO.d.mts} +6 -3
- package/dist/{openai-completions-compat-CYX18uDk.mjs → openai-completions-compat-CFhQ3UVU.mjs} +7 -2
- package/dist/{openai-completions-transport-DuXQOxrH.mjs → openai-completions-transport-DviPEqw3.mjs} +369 -237
- package/dist/{openai-prompt-cache-r93BJhjm.mjs → openai-prompt-cache-DJ_P143P.mjs} +1 -1
- package/dist/{openai-prompt-cache-DIPMrMFy.d.mts → openai-prompt-cache-DgjD-UL5.d.mts} +2 -2
- package/dist/{openai-responses-BMxoJdTC.mjs → openai-responses-BXsJK-mD.mjs} +13 -15
- package/dist/{openai-responses-compaction-replay-B2FE4Nw8.d.mts → openai-responses-compaction-replay-Cvnl_nCq.d.mts} +5 -5
- package/dist/{openai-responses-contracts-DlKMMTxK.mjs → openai-responses-contracts-Bx-16mnf.mjs} +45 -6
- package/dist/{openai-responses-contracts-DKqMJ1Ct.d.mts → openai-responses-contracts-CQ4_AWjL.d.mts} +20 -8
- package/dist/{openai-responses-endpoint-CinGh4VZ.mjs → openai-responses-endpoint-D4v-eeYy.mjs} +55 -22
- package/dist/{openai-responses-payload-policy-C7GsA1y0.d.mts → openai-responses-payload-policy-BzM52TTH.d.mts} +9 -3
- package/dist/openai-responses-request-lifecycle-CTdAb2v1.mjs +246 -0
- package/dist/{openai-responses-shared-afo9-s16.mjs → openai-responses-shared-Bv_1NtH9.mjs} +284 -173
- package/dist/{openai-responses-terminal-usage-BygjiAdi.d.mts → openai-responses-terminal-usage-CpVjkqn-.d.mts} +2 -2
- package/dist/{openai-tool-schema-DDPXsvJP.mjs → openai-tool-schema-Buv0GXFb.mjs} +170 -237
- package/dist/overflow-DJHXTNBQ.mjs +117 -0
- package/dist/{positive-integer-CqWjqSi9.mjs → positive-integer-Bb4Evc7L.mjs} +1 -1
- package/dist/prompt-cache-stability-D_MeCQFI.mjs +32 -0
- package/dist/{provider-error-xumb1V3F.d.mts → provider-error-CnaWYTRY.d.mts} +1 -0
- package/dist/{provider-error-CF9GWCs2.mjs → provider-error-qtZD2inE.mjs} +75 -13
- package/dist/{provider-options-CVrXZBtA.d.mts → provider-options-DeYeaflL.d.mts} +52 -6
- package/dist/{transport-utils-34BQoXq3.mjs → provider-replay-context-J6CfU3m1.mjs} +28 -5
- package/dist/{provider-transport-turn-state-BYrELw8H.mjs → provider-transport-turn-state-Jxppzuc2.mjs} +5 -5
- package/dist/{provider-types-CHtRx0dI.d.mts → provider-types-ODq57rG_.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-CpOy9-IQ.mjs → reasoning-tag-text-partitioner-DzlRubwU.mjs} +134 -47
- package/dist/{required-api-key-CFJvcFy_.mjs → required-api-key-D088S4Cd.mjs} +1 -1
- package/dist/{retry-after-CdCURCVg.d.mts → retry-after-sw-XX8aC.d.mts} +1 -1
- package/dist/sanitize-unicode-CRGuMONI.mjs +8 -0
- package/dist/sanitize-unicode-ZqVLLEKC.d.mts +27 -0
- package/dist/{session-resources-D1wgDQ8C.mjs → session-resources-vKvGIE3J.mjs} +1 -10
- package/dist/{simple-options-BAu4B54D.mjs → simple-options-BYgC6kse.mjs} +68 -79
- package/dist/{src-C44MKrW5.mjs → src-CyA0zJnt.mjs} +6 -2
- package/dist/{stream-Dd8DwRFL.mjs → stream-DLBirT0e.mjs} +8 -47
- package/dist/{stream-first-event-timeout-Dc42hKv6.mjs → stream-first-event-timeout-D_TfJHRJ.mjs} +1 -1
- package/dist/{string-coerce-CtgOVOSv.mjs → string-coerce-Cj8sqWHx.mjs} +26 -1
- package/dist/tool-schema-json-projection-B0hHDV7N.mjs +492 -0
- package/dist/{transport-stream-shared-BmpzDtdQ.d.mts → transport-stream-shared-8ru8eX4s.d.mts} +5 -5
- package/dist/{transport-stream-shared-CWGOuLcA.mjs → transport-stream-shared-CzQlAzJH.mjs} +27 -75
- package/dist/transports.d.mts +33 -28
- package/dist/transports.mjs +42 -48
- package/dist/{types-CQc6JNG4.mjs → types-BXd0kI8-.mjs} +1 -1
- package/dist/types-CBJthzJX.d.mts +1 -0
- package/dist/{types-Bd2T86VJ.d.mts → types-CVYzKrMl.d.mts} +20 -3
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/{validation-ZX_sPVV0.mjs → validation-9FSkE8T-.mjs} +22 -3
- package/dist/{validation-DdGB1yy3.d.mts → validation-BQ5u20Ru.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +3 -3
- package/dist/assistant-text-phase-mvdMcrY-.mjs +0 -50
- package/dist/event-stream-6UNs-AhN.d.mts +0 -1
- package/dist/expect-lbe3Hgrh.mjs +0 -8
- package/dist/json-schema-Bp07Qui3.mjs +0 -22
- package/dist/openai-responses-request-lifecycle-NSIJo9jY.mjs +0 -67
- package/dist/openai-tool-projection-793cE3QX.d.mts +0 -37
- package/dist/openai-tool-schema-a5ysBBga.d.mts +0 -32
- package/dist/rolldown-runtime-BhDjJH2R.mjs +0 -15
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +0 -5
- package/dist/string-normalization-I3ux50s9.mjs +0 -28
- package/dist/text-signature-CUXnvk_c.mjs +0 -34
- package/dist/tool-schema-json-projection-B8sG1I9v.mjs +0 -180
- package/dist/types-Kdfw_04V.d.mts +0 -1
package/README.md
CHANGED
|
@@ -26,12 +26,23 @@ runtime-local policy can use `createNodeLlmRuntime`; it preserves that host acro
|
|
|
26
26
|
provider work without replacing the process default. `createLlmRuntime` continues
|
|
27
27
|
to use the process-default host.
|
|
28
28
|
|
|
29
|
+
OpenAI HTTP adapters report rejected response status and headers through
|
|
30
|
+
`onResponse` before consuming the error body. Successful streaming responses
|
|
31
|
+
invoke the callback before the first event. Retry and failover policy remains
|
|
32
|
+
with the application.
|
|
33
|
+
|
|
29
34
|
Hosts that attach request state to async contexts should supply
|
|
30
35
|
`runInDetachedAsyncContext` from a context-free root initialized before requests
|
|
31
36
|
start. Retained HTTP continuation timers use it at creation so completed caller
|
|
32
37
|
state can be collected while the response remains reusable for 90 minutes.
|
|
33
38
|
The default host runs the callback directly, including in browsers.
|
|
34
39
|
|
|
40
|
+
Tool-call stream producers expose cumulative argument text as `partialJson` on
|
|
41
|
+
the active content block while emitting `toolcall_delta`. This transient buffer
|
|
42
|
+
supports input progress; completed tool calls retain only parsed `arguments`.
|
|
43
|
+
It is the live block, not a per-event snapshot: a consumer that lags behind the
|
|
44
|
+
producer reads the latest value, or none once the call has finished.
|
|
45
|
+
|
|
35
46
|
The explicit `@openclaw/ai/internal/anthropic`, `google-model-family`, `openai`,
|
|
36
47
|
`openai-completions-compat`, `openai-responses-payload-policy`, `retry-after`, `runtime`, `shared`, and
|
|
37
48
|
`tool-schema` subpaths exist for the OpenClaw application itself.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { w as supportsClaudeAdaptiveThinking } from "./src-
|
|
1
|
+
import { n as __exportAll } from "./reasoning-tag-text-partitioner-DzlRubwU.mjs";
|
|
2
|
+
import { w as supportsClaudeAdaptiveThinking } from "./src-CyA0zJnt.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
4
|
-
import { T as usesClaudeStreamingRefusalContract, _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, b as prepareClaudeNoPrefillRequestContext, r as getAiTransportHost } from "./host-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { i as resolveCacheRetention, n as resolveCloudflareBaseUrl, r as buildCopilotDynamicHeaders } from "./cloudflare-
|
|
8
|
-
import {
|
|
9
|
-
import { n as
|
|
10
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
4
|
+
import { T as usesClaudeStreamingRefusalContract, _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, b as prepareClaudeNoPrefillRequestContext, r as getAiTransportHost } from "./host-B2gk-d1H.mjs";
|
|
5
|
+
import { u as streamFragmentError } from "./provider-replay-context-J6CfU3m1.mjs";
|
|
6
|
+
import { F as supportsAnthropicServerSideFallback, H as isAnthropicOAuthApiKey, O as isDirectAnthropicModel, U as omitFoundryBearerCredentialHeaders, W as usesFoundryBearerAuth, d as applyAnthropicThinkingOptions, l as buildAnthropicRequest, t as consumeAnthropicStream, u as prepareAnthropicRequest, x as suppressAnthropicCompaction, y as isAnthropicReplayRejection } from "./anthropic-stream-reducer-CzPXOaLM.mjs";
|
|
7
|
+
import { i as resolveCacheRetention, n as resolveCloudflareBaseUrl, r as buildCopilotDynamicHeaders } from "./cloudflare-Dttf8jKq.mjs";
|
|
8
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-BYgC6kse.mjs";
|
|
9
|
+
import { D as parseJsonWithRepair, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, u as finalizeTransportStream } from "./transport-stream-shared-CzQlAzJH.mjs";
|
|
10
|
+
import { n as getEnvApiKey } from "./env-api-keys-Xd8dm_aV.mjs";
|
|
11
11
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
12
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
12
|
+
import { t as createAssistantOutput } from "./assistant-output-6iFA1nbC.mjs";
|
|
13
13
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-CfMuh5cC.mjs";
|
|
14
14
|
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-DA4WHv1h.mjs";
|
|
15
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
15
|
+
import { t as requireApiKey } from "./required-api-key-D088S4Cd.mjs";
|
|
16
16
|
import Anthropic from "@anthropic-ai/sdk";
|
|
17
17
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
18
18
|
//#region packages/ai/src/providers/anthropic.ts
|
|
@@ -59,11 +59,11 @@ const streamAnthropic = (model, context, options) => {
|
|
|
59
59
|
(async () => {
|
|
60
60
|
const output = createAssistantOutput(model);
|
|
61
61
|
const refusalBuffer = usesClaudeStreamingRefusalContract(model) ? createDeferredEventBuffer(stream) : void 0;
|
|
62
|
-
let
|
|
62
|
+
let replayedCompaction;
|
|
63
63
|
try {
|
|
64
64
|
const { client, isOAuthToken, serverSideFallback, directApiKeyBetaHeader, claudeCodeVersion } = createClient(model, requestContext, requestOptions);
|
|
65
65
|
const builtParams = await buildAnthropicRequest(model, requestContext, requestOptions, "provider", isOAuthToken, serverSideFallback, claudeCodeVersion);
|
|
66
|
-
|
|
66
|
+
replayedCompaction = builtParams.replayedCompaction;
|
|
67
67
|
const { params, headers } = await prepareAnthropicRequest(builtParams.params, model, requestOptions, directApiKeyBetaHeader);
|
|
68
68
|
const sdkRequestOptions = {
|
|
69
69
|
...requestOptions?.signal ? { signal: requestOptions.signal } : {},
|
|
@@ -98,15 +98,12 @@ const streamAnthropic = (model, context, options) => {
|
|
|
98
98
|
} catch (error) {
|
|
99
99
|
const terminal = assignTransportErrorDetails(output, error, requestOptions?.signal);
|
|
100
100
|
output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
101
|
-
for (const block of output.content)
|
|
102
|
-
delete block.index;
|
|
103
|
-
delete block.partialJson;
|
|
104
|
-
}
|
|
101
|
+
for (const block of output.content) delete block.index;
|
|
105
102
|
if (refusalBuffer) {
|
|
106
103
|
refusalBuffer.discard();
|
|
107
104
|
output.content = [];
|
|
108
105
|
}
|
|
109
|
-
if (
|
|
106
|
+
if (replayedCompaction && isAnthropicReplayRejection(error)) suppressAnthropicCompaction(output, model, requestOptions, replayedCompaction);
|
|
110
107
|
stream.push({
|
|
111
108
|
type: "error",
|
|
112
109
|
reason: terminal.stopReason,
|
|
@@ -135,6 +132,7 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
135
132
|
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
136
133
|
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
137
134
|
cacheTtlPruning: options?.cacheTtlPruning,
|
|
135
|
+
onCompactionRejected: options?.onCompactionRejected,
|
|
138
136
|
authProfileId: options?.authProfileId,
|
|
139
137
|
maxTokens: clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens),
|
|
140
138
|
toolChoice: options?.toolChoice,
|
package/dist/{anthropic-payload-policy-DGblkHL5.d.mts → anthropic-payload-policy-Cr8xjazC.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { k as Model } from "./types-
|
|
3
|
-
import { t as AnthropicContextManagementOptions } from "./provider-options-
|
|
1
|
+
import "./index-DSprYWaz.mjs";
|
|
2
|
+
import { k as Model } from "./types-CVYzKrMl.mjs";
|
|
3
|
+
import { t as AnthropicContextManagementOptions } from "./provider-options-DeYeaflL.mjs";
|
|
4
4
|
import { TextBlockParam } from "@anthropic-ai/sdk/resources/messages.js";
|
|
5
5
|
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
6
6
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
@@ -26,9 +26,12 @@ type AnthropicPayloadPolicyInput = {
|
|
|
26
26
|
type AnthropicPayloadPolicy = ReturnType<typeof resolveAnthropicPayloadPolicy>;
|
|
27
27
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
28
28
|
declare function resolveAnthropicServerCompactionPlan(model: {
|
|
29
|
+
id?: string;
|
|
30
|
+
params?: Record<string, unknown>;
|
|
29
31
|
provider?: unknown;
|
|
30
32
|
api?: unknown;
|
|
31
33
|
baseUrl?: string;
|
|
34
|
+
contextTokens?: unknown;
|
|
32
35
|
contextWindow?: unknown;
|
|
33
36
|
}, extraParams?: Record<string, unknown>, apiKey?: string): {
|
|
34
37
|
enabled: boolean;
|
package/dist/{anthropic-stream-reducer-DfMVFm-r.mjs → anthropic-stream-reducer-CzPXOaLM.mjs}
RENAMED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { E as supportsClaudeInHistorySystemMessages, O as supportsClaudeNativeXhighEffort, S as resolveClaudeSonnet5ModelIdentity, b as resolveClaudeOpus5ModelIdentity, d as requiresClaudeBetweenToolsThinking, g as resolveClaudeModelIdentity, h as resolveClaudeHaiku55ModelIdentity, m as resolveClaudeFable5ModelIdentity, u as bindsClaudeThinkingPrefix, w as supportsClaudeAdaptiveThinking, x as resolveClaudeSonnet55ModelIdentity, y as resolveClaudeOpus55ModelIdentity } from "./src-
|
|
2
|
-
import { f as hasRuntimeContextMarker } from "./types-
|
|
1
|
+
import { E as supportsClaudeInHistorySystemMessages, O as supportsClaudeNativeXhighEffort, S as resolveClaudeSonnet5ModelIdentity, b as resolveClaudeOpus5ModelIdentity, d as requiresClaudeBetweenToolsThinking, g as resolveClaudeModelIdentity, h as resolveClaudeHaiku55ModelIdentity, k as supportsClaudeServerCompaction, m as resolveClaudeFable5ModelIdentity, u as bindsClaudeThinkingPrefix, w as supportsClaudeAdaptiveThinking, x as resolveClaudeSonnet55ModelIdentity, y as resolveClaudeOpus55ModelIdentity } from "./src-CyA0zJnt.mjs";
|
|
2
|
+
import { f as hasRuntimeContextMarker } from "./types-BXd0kI8-.mjs";
|
|
3
3
|
import { r as appendAssistantThinking } from "./event-stream-X2gmsUWv.mjs";
|
|
4
4
|
import { a as asRecord, o as isRecord, r as asOptionalObjectRecord, s as readStringField } from "./record-coerce-CNDovvft.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { n as asNonNegativeFiniteNumber } from "./number-coercion-
|
|
7
|
-
import { N as isImageWithMediaPayload, O as calculateCost, S as resolveAnthropicThinkingEffort, g as applyClaudeRequestContract, h as ANTHROPIC_CLAUDE_CODE_VERSION, r as getAiTransportHost, u as STREAM_ERROR_FALLBACK_TEXT, v as defaultsClaudeAdaptiveThinking, w as usesClaudeFable5MessagesContract, x as requiresClaudeAdaptiveThinking, y as mapAnthropicStopReason } from "./host-
|
|
8
|
-
import "./
|
|
5
|
+
import { a as normalizeOptionalLowercaseString, i as normalizeNullableString } from "./string-coerce-Cj8sqWHx.mjs";
|
|
6
|
+
import { n as asNonNegativeFiniteNumber } from "./number-coercion-37gmNkuA.mjs";
|
|
7
|
+
import { N as isImageWithMediaPayload, O as calculateCost, S as resolveAnthropicThinkingEffort, g as applyClaudeRequestContract, h as ANTHROPIC_CLAUDE_CODE_VERSION, r as getAiTransportHost, u as STREAM_ERROR_FALLBACK_TEXT, v as defaultsClaudeAdaptiveThinking, w as usesClaudeFable5MessagesContract, x as requiresClaudeAdaptiveThinking, y as mapAnthropicStopReason } from "./host-B2gk-d1H.mjs";
|
|
8
|
+
import { n as isProviderReplayContext, r as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-J6CfU3m1.mjs";
|
|
9
9
|
import { n as estimateBase64DecodedBytes } from "./base64-C8CdcsjU.mjs";
|
|
10
|
-
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-
|
|
11
|
-
import { i as resolveCacheRetention } from "./cloudflare-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { n as transformProviderMessages } from "./assistant-output-
|
|
17
|
-
import { i as
|
|
18
|
-
import { i as tagPendingCommentaryText } from "./assistant-text-phase-mvdMcrY-.mjs";
|
|
10
|
+
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-mpqGhbeM.mjs";
|
|
11
|
+
import { i as resolveCacheRetention } from "./cloudflare-Dttf8jKq.mjs";
|
|
12
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
13
|
+
import { S as splitSystemPromptCacheBoundary, T as stripSystemPromptRelocatableBoundary, d as extractToolResultBlockText, f as extractToolResultText, h as preparedRequestSuffix, l as describeToolResultMediaPlaceholder, t as adjustMaxTokensForThinking, w as stripSystemPromptCacheBoundary } from "./simple-options-BYgC6kse.mjs";
|
|
14
|
+
import { C as parseJsonObjectPreservingUnsafeIntegers, E as createToolArgumentPreviewSchedule, O as parseStreamingJson, b as transportAbortError, d as iterateModelStream, i as copyProviderAcceptanceObserver, l as finalizeTerminalToolCallArguments, r as coerceTransportToolCallArguments, v as sanitizeTransportPayloadText } from "./transport-stream-shared-CzQlAzJH.mjs";
|
|
15
|
+
import { t as parsePositiveInteger } from "./positive-integer-Bb4Evc7L.mjs";
|
|
16
|
+
import { n as transformProviderMessages } from "./assistant-output-6iFA1nbC.mjs";
|
|
17
|
+
import { a as reconcileAnthropicToolChoice, i as projectAnthropicTools, n as normalizeAnthropicToolChoice, o as resolveOriginalAnthropicToolName, s as toClaudeCodeToolName, t as normalizeAnthropicToolCallId } from "./anthropic-tool-projection-BdAS3rtJ.mjs";
|
|
19
18
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-CfMuh5cC.mjs";
|
|
20
19
|
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
21
20
|
/** Inspect resolved credential shape for auth routing without exposing its value. */
|
|
@@ -122,19 +121,22 @@ function applyAnthropicFallbackBoundary(params) {
|
|
|
122
121
|
//#region packages/ai/src/transports/anthropic-payload-policy.ts
|
|
123
122
|
const ANTHROPIC_CACHE_CONTROL_LIMIT = 4;
|
|
124
123
|
const ANTHROPIC_COMPACT_THRESHOLD_MIN = 5e4;
|
|
124
|
+
const ANTHROPIC_COMPACTION_INSTRUCTIONS = "Summarize the transcript inside <summary></summary> tags. Include the current state, decisions, and next steps needed to continue the task in the next context window. Do not call any tools while writing this summary; respond with text only.";
|
|
125
125
|
/** Resolve the Anthropic input-token trigger, including the API's minimum. */
|
|
126
|
-
function resolveAnthropicCompactThreshold(
|
|
126
|
+
function resolveAnthropicCompactThreshold(model, configured) {
|
|
127
127
|
const configuredThreshold = parsePositiveInteger(configured);
|
|
128
128
|
if (configuredThreshold !== void 0) return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, configuredThreshold);
|
|
129
|
-
const
|
|
130
|
-
|
|
129
|
+
const contextTokens = parsePositiveInteger(model.contextTokens);
|
|
130
|
+
const contextWindow = parsePositiveInteger(model.contextWindow);
|
|
131
|
+
return Math.max(ANTHROPIC_COMPACT_THRESHOLD_MIN, Math.floor((contextTokens && contextWindow ? Math.min(contextTokens, contextWindow) : contextTokens ?? contextWindow ?? 0) * .7));
|
|
131
132
|
}
|
|
132
133
|
/** Resolve the server-compaction gate and effective threshold for an Anthropic route. */
|
|
133
134
|
function resolveAnthropicServerCompactionPlan(model, extraParams, apiKey) {
|
|
134
|
-
const
|
|
135
|
+
const configured = extraParams?.anthropicServerCompaction;
|
|
136
|
+
const enabled = configured !== false && (configured === true || supportsClaudeServerCompaction(model)) && !isAnthropicOAuthApiKey(apiKey) && normalizeOptionalLowercaseString(model.api) === "anthropic-messages" && isDirectAnthropicModel(model);
|
|
135
137
|
return {
|
|
136
138
|
enabled,
|
|
137
|
-
...enabled ? { threshold: resolveAnthropicCompactThreshold(model
|
|
139
|
+
...enabled ? { threshold: resolveAnthropicCompactThreshold(model, extraParams?.anthropicCompactThreshold) } : {}
|
|
138
140
|
};
|
|
139
141
|
}
|
|
140
142
|
function isDirectAnthropicModel(model, env = process.env) {
|
|
@@ -252,12 +254,12 @@ function normalizeAnthropicSystemBlocks(system, cacheControl) {
|
|
|
252
254
|
/** Apply one shared deepest-stable-message cache breakpoint policy. */
|
|
253
255
|
function applyAnthropicCacheControlToMessages(messages, cacheControl, markerLimit, cacheBreakpointOptOutMessageIndexes) {
|
|
254
256
|
if (!Array.isArray(messages) || messages.length === 0 || markerLimit <= 0) return;
|
|
255
|
-
let
|
|
256
|
-
for (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const record =
|
|
260
|
-
if (record.role !== "user"
|
|
257
|
+
let stableEnd = messages.length;
|
|
258
|
+
for (const index of cacheBreakpointOptOutMessageIndexes) stableEnd = Math.min(stableEnd, index);
|
|
259
|
+
let marked = 0;
|
|
260
|
+
for (let i = stableEnd - 1; i >= 0 && marked < Math.min(markerLimit, 2); i--) {
|
|
261
|
+
const record = messages[i];
|
|
262
|
+
if (!isRecord(record) || record.role !== "user") continue;
|
|
261
263
|
const content = record.content;
|
|
262
264
|
const blocks = typeof content === "string" ? [{
|
|
263
265
|
type: "text",
|
|
@@ -265,23 +267,16 @@ function applyAnthropicCacheControlToMessages(messages, cacheControl, markerLimi
|
|
|
265
267
|
}] : content;
|
|
266
268
|
if (!Array.isArray(blocks)) continue;
|
|
267
269
|
for (let j = blocks.length - 1; j >= 0; j--) {
|
|
268
|
-
const
|
|
269
|
-
if (!
|
|
270
|
-
|
|
271
|
-
if (blockRecord.type === "text" || blockRecord.type === "image") {
|
|
272
|
-
if (fallbackToolResult && markerLimit === 1) {
|
|
273
|
-
fallbackToolResult.cache_control = cacheControl;
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
270
|
+
const blockRecord = blocks[j];
|
|
271
|
+
if (!isRecord(blockRecord)) continue;
|
|
272
|
+
if (blockRecord.type === "text" || blockRecord.type === "image" || blockRecord.type === "tool_result") {
|
|
276
273
|
blockRecord.cache_control = cacheControl;
|
|
277
274
|
if (typeof content === "string") record.content = blocks;
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
marked++;
|
|
276
|
+
break;
|
|
280
277
|
}
|
|
281
|
-
if (blockRecord.type === "tool_result" && fallbackToolResult === void 0) fallbackToolResult = blockRecord;
|
|
282
278
|
}
|
|
283
279
|
}
|
|
284
|
-
if (fallbackToolResult) fallbackToolResult.cache_control = cacheControl;
|
|
285
280
|
}
|
|
286
281
|
function countAnthropicCacheControlMarkers(blocks) {
|
|
287
282
|
if (!Array.isArray(blocks)) return 0;
|
|
@@ -302,7 +297,7 @@ function resolveAnthropicPayloadPolicy(input, model) {
|
|
|
302
297
|
return {
|
|
303
298
|
allowsServiceTier: capabilities.allowsAnthropicServiceTier,
|
|
304
299
|
cacheControl: input.enableCacheControl === true ? resolveAnthropicEphemeralCacheControl(input.baseUrl, input.cacheRetention) : void 0,
|
|
305
|
-
compactThreshold: serverCompactionPlan.threshold ?? resolveAnthropicCompactThreshold(input
|
|
300
|
+
compactThreshold: serverCompactionPlan.threshold ?? resolveAnthropicCompactThreshold(input, input.extraParams?.anthropicCompactThreshold),
|
|
306
301
|
serviceTier: input.serviceTier,
|
|
307
302
|
useServerCompaction: input.enableServerCompaction === true && serverCompactionPlan.enabled,
|
|
308
303
|
...input.cacheTtlPruning && normalizeOptionalLowercaseString(input.api) === "anthropic-messages" && isDirectAnthropicModel(input) ? { toolClearing: {
|
|
@@ -355,7 +350,8 @@ function applyAnthropicContextManagementEdits(payload, policy) {
|
|
|
355
350
|
trigger: {
|
|
356
351
|
type: "input_tokens",
|
|
357
352
|
value: policy.compactThreshold
|
|
358
|
-
}
|
|
353
|
+
},
|
|
354
|
+
instructions: ANTHROPIC_COMPACTION_INSTRUCTIONS
|
|
359
355
|
});
|
|
360
356
|
if (edits.length > 0) payload.context_management = { edits };
|
|
361
357
|
}
|
|
@@ -364,7 +360,7 @@ function applyAnthropicContextManagementToRequest(payload, model, options, direc
|
|
|
364
360
|
applyAnthropicContextManagementEdits(payload, resolveAnthropicPayloadPolicy({
|
|
365
361
|
...model,
|
|
366
362
|
api: "anthropic-messages",
|
|
367
|
-
enableServerCompaction: true,
|
|
363
|
+
enableServerCompaction: options?.anthropicServerCompaction === true,
|
|
368
364
|
extraParams: { ...options },
|
|
369
365
|
cacheTtlPruning: options?.cacheTtlPruning
|
|
370
366
|
}));
|
|
@@ -488,7 +484,11 @@ function captureAnthropicCompaction(output, capture, model, options) {
|
|
|
488
484
|
baseUrlHash: context.baseUrlHash
|
|
489
485
|
};
|
|
490
486
|
}
|
|
491
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Record a rejected replay on the failed output and notify the transcript owner, which must
|
|
489
|
+
* durably strip the checkpoint: hosts may persist failed turns without their replay state.
|
|
490
|
+
*/
|
|
491
|
+
function suppressAnthropicCompaction(output, model, options, rejected) {
|
|
492
492
|
const context = buildProviderReplayContext(model, options);
|
|
493
493
|
if (!context.baseUrlHash) return;
|
|
494
494
|
output.providerReplay = {
|
|
@@ -498,6 +498,7 @@ function suppressAnthropicCompaction(output, model, options) {
|
|
|
498
498
|
...context,
|
|
499
499
|
baseUrlHash: context.baseUrlHash
|
|
500
500
|
};
|
|
501
|
+
options?.onCompactionRejected?.({ data: rejected.content });
|
|
501
502
|
}
|
|
502
503
|
function resolveNewestAnthropicCompaction(messages, model, options) {
|
|
503
504
|
const context = buildProviderReplayContext(model, options);
|
|
@@ -636,168 +637,6 @@ function findActiveAnthropicToolTurnAssistantIndex(messages) {
|
|
|
636
637
|
return [...toolResultIds].every((toolCallId) => toolCallIds.has(toolCallId)) ? index : -1;
|
|
637
638
|
}
|
|
638
639
|
//#endregion
|
|
639
|
-
//#region packages/ai/src/providers/anthropic-tool-projection.ts
|
|
640
|
-
const CLAUDE_CODE_TOOL_LOOKUP = new Map([
|
|
641
|
-
"Read",
|
|
642
|
-
"Write",
|
|
643
|
-
"Edit",
|
|
644
|
-
"Bash",
|
|
645
|
-
"Grep",
|
|
646
|
-
"Glob",
|
|
647
|
-
"AskUserQuestion",
|
|
648
|
-
"EnterPlanMode",
|
|
649
|
-
"ExitPlanMode",
|
|
650
|
-
"KillShell",
|
|
651
|
-
"NotebookEdit",
|
|
652
|
-
"Skill",
|
|
653
|
-
"Task",
|
|
654
|
-
"TaskOutput",
|
|
655
|
-
"TodoWrite",
|
|
656
|
-
"WebFetch",
|
|
657
|
-
"WebSearch"
|
|
658
|
-
].map((name) => [name.toLowerCase(), name]));
|
|
659
|
-
/** Preserve Claude Code's canonical tool casing for subscription OAuth requests. */
|
|
660
|
-
function toClaudeCodeToolName(name) {
|
|
661
|
-
return CLAUDE_CODE_TOOL_LOOKUP.get(name.toLowerCase()) ?? name;
|
|
662
|
-
}
|
|
663
|
-
/** Anthropic rejects forced tools while extended thinking is enabled. */
|
|
664
|
-
function normalizeAnthropicToolChoice(thinkingEnabled, toolChoice) {
|
|
665
|
-
if (thinkingEnabled && (toolChoice === "any" || typeof toolChoice === "object" && toolChoice.type === "tool")) return { type: "auto" };
|
|
666
|
-
return typeof toolChoice === "string" ? { type: toolChoice } : toolChoice;
|
|
667
|
-
}
|
|
668
|
-
/** Anthropic tool identifiers accept only ASCII word characters and dashes. */
|
|
669
|
-
function normalizeAnthropicToolCallId(id) {
|
|
670
|
-
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
671
|
-
}
|
|
672
|
-
function isProviderSupportedViolation(violation) {
|
|
673
|
-
return violation.endsWith(".$dynamicRef") || violation.endsWith(".$dynamicAnchor");
|
|
674
|
-
}
|
|
675
|
-
const schemaValueKeywords = /* @__PURE__ */ new Set([
|
|
676
|
-
"additionalProperties",
|
|
677
|
-
"contains",
|
|
678
|
-
"contentSchema",
|
|
679
|
-
"else",
|
|
680
|
-
"if",
|
|
681
|
-
"items",
|
|
682
|
-
"not",
|
|
683
|
-
"propertyNames",
|
|
684
|
-
"then",
|
|
685
|
-
"unevaluatedItems",
|
|
686
|
-
"unevaluatedProperties"
|
|
687
|
-
]);
|
|
688
|
-
const schemaArrayKeywords = /* @__PURE__ */ new Set([
|
|
689
|
-
"allOf",
|
|
690
|
-
"anyOf",
|
|
691
|
-
"oneOf",
|
|
692
|
-
"prefixItems"
|
|
693
|
-
]);
|
|
694
|
-
/** Normalize the detached JSON projection and report tuple changes to enclosing schemas. */
|
|
695
|
-
function normalizeAnthropicJsonSchema(schema) {
|
|
696
|
-
if (!isRecord(schema)) return false;
|
|
697
|
-
let changed = false;
|
|
698
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
699
|
-
if (schemaValueKeywords.has(key) && !Array.isArray(value)) {
|
|
700
|
-
changed = normalizeAnthropicJsonSchema(value) || changed;
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
if (schemaArrayKeywords.has(key) && Array.isArray(value)) {
|
|
704
|
-
for (const entry of value) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const entry of Object.values(value)) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
708
|
-
}
|
|
709
|
-
if (Array.isArray(schema.items)) {
|
|
710
|
-
for (const entry of schema.items) normalizeAnthropicJsonSchema(entry);
|
|
711
|
-
schema.prefixItems = schema.items;
|
|
712
|
-
const additionalItems = schema.additionalItems;
|
|
713
|
-
if (typeof additionalItems === "boolean" || isRecord(additionalItems)) {
|
|
714
|
-
normalizeAnthropicJsonSchema(additionalItems);
|
|
715
|
-
schema.items = additionalItems;
|
|
716
|
-
} else delete schema.items;
|
|
717
|
-
delete schema.additionalItems;
|
|
718
|
-
changed = true;
|
|
719
|
-
}
|
|
720
|
-
if (changed) delete schema.$schema;
|
|
721
|
-
return changed;
|
|
722
|
-
}
|
|
723
|
-
/** Snapshots direct/custom tool descriptors before Anthropic payload construction. */
|
|
724
|
-
function projectAnthropicTools(tools, toWireName) {
|
|
725
|
-
const projectedTools = [];
|
|
726
|
-
const originalNameByWireName = /* @__PURE__ */ new Map();
|
|
727
|
-
const unavailableOriginalNames = /* @__PURE__ */ new Set();
|
|
728
|
-
for (const tool of tools) {
|
|
729
|
-
let projectedTool;
|
|
730
|
-
let originalName;
|
|
731
|
-
try {
|
|
732
|
-
const name = tool.name;
|
|
733
|
-
originalName = name;
|
|
734
|
-
if (!name) continue;
|
|
735
|
-
const schemaProjection = projectRuntimeToolInputSchema(tool.parameters, `${name}.parameters`);
|
|
736
|
-
if (!isRecord(schemaProjection.schema) || schemaProjection.violations.some((violation) => !isProviderSupportedViolation(violation))) {
|
|
737
|
-
unavailableOriginalNames.add(name);
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
const anthropicSchema = schemaProjection.schema;
|
|
741
|
-
normalizeAnthropicJsonSchema(anthropicSchema);
|
|
742
|
-
const properties = anthropicSchema.properties;
|
|
743
|
-
const required = anthropicSchema.required;
|
|
744
|
-
if (properties !== void 0 && properties !== null && !isRecord(properties) || required !== void 0 && required !== null && (!Array.isArray(required) || required.some((entry) => typeof entry !== "string"))) {
|
|
745
|
-
unavailableOriginalNames.add(name);
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
let description;
|
|
749
|
-
try {
|
|
750
|
-
description = typeof tool.description === "string" ? tool.description : void 0;
|
|
751
|
-
} catch {}
|
|
752
|
-
projectedTool = {
|
|
753
|
-
originalName: name,
|
|
754
|
-
wireName: toWireName(name),
|
|
755
|
-
...description ? { description } : {},
|
|
756
|
-
inputSchema: {
|
|
757
|
-
...anthropicSchema,
|
|
758
|
-
type: "object",
|
|
759
|
-
properties: properties ?? {},
|
|
760
|
-
required: required ?? []
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
} catch {
|
|
764
|
-
if (originalName) unavailableOriginalNames.add(originalName);
|
|
765
|
-
continue;
|
|
766
|
-
}
|
|
767
|
-
const conflictingName = originalNameByWireName.get(projectedTool.wireName);
|
|
768
|
-
if (conflictingName !== void 0 && conflictingName !== projectedTool.originalName) throw new Error(`Anthropic tool names "${conflictingName}" and "${projectedTool.originalName}" both map to "${projectedTool.wireName}"`);
|
|
769
|
-
originalNameByWireName.set(projectedTool.wireName, projectedTool.originalName);
|
|
770
|
-
projectedTools.push(projectedTool);
|
|
771
|
-
}
|
|
772
|
-
return {
|
|
773
|
-
inputToolCount: tools.length,
|
|
774
|
-
unavailableOriginalNames,
|
|
775
|
-
tools: sortPromptCacheToolsByName(projectedTools)
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
/** Keeps forced Anthropic tool choices aligned with the projected wire names. */
|
|
779
|
-
function reconcileAnthropicToolChoice(choice, projection) {
|
|
780
|
-
if (projection.inputToolCount === 0) return choice;
|
|
781
|
-
if (choice.type === "tool") {
|
|
782
|
-
const requestedName = choice.name;
|
|
783
|
-
const matchedTool = projection.tools.find((tool) => tool.originalName === requestedName) ?? (projection.unavailableOriginalNames.has(requestedName) ? void 0 : projection.tools.find((tool) => tool.wireName === requestedName));
|
|
784
|
-
if (!matchedTool) throw new Error(`Anthropic tool_choice requested unavailable tool "${requestedName}" after schema conversion`);
|
|
785
|
-
return {
|
|
786
|
-
...choice,
|
|
787
|
-
name: matchedTool.wireName
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
if (projection.tools.length === 0) {
|
|
791
|
-
if (choice.type === "auto") return;
|
|
792
|
-
if (choice.type === "any") throw new Error("Anthropic tool_choice requires a tool, but no tools survived schema conversion");
|
|
793
|
-
}
|
|
794
|
-
return choice;
|
|
795
|
-
}
|
|
796
|
-
/** Maps Claude Code wire names without trusting every direct/custom descriptor. */
|
|
797
|
-
function resolveOriginalAnthropicToolName(name, projection) {
|
|
798
|
-
return projection?.tools.find((tool) => tool.wireName === name)?.originalName ?? name;
|
|
799
|
-
}
|
|
800
|
-
//#endregion
|
|
801
640
|
//#region packages/ai/src/transports/anthropic-transport-options.ts
|
|
802
641
|
const ANTHROPIC_MESSAGES_DEFAULT_MAX_TOKENS = 4096;
|
|
803
642
|
const ANTHROPIC_MESSAGES_FALLBACK_CONTEXT_DIVISOR = 4;
|
|
@@ -1063,7 +902,7 @@ async function convertAnthropicMessages(transformedMessages, model, isOAuthToken
|
|
|
1063
902
|
if (nextMsg?.role !== "toolResult") break;
|
|
1064
903
|
toolResults.push({
|
|
1065
904
|
type: "tool_result",
|
|
1066
|
-
tool_use_id: nextMsg.toolCallId,
|
|
905
|
+
tool_use_id: preparedRequestSuffix.has(options.context) ? preparedRequestSuffix.toolCallId(options.context, nextMsg.toolCallId, normalizeAnthropicToolCallId(nextMsg.toolCallId)) : nextMsg.toolCallId,
|
|
1067
906
|
content: await convertContentBlocks(nextMsg.content, model, imageBudget, options.profile, nextMsg.isError),
|
|
1068
907
|
is_error: nextMsg.isError
|
|
1069
908
|
});
|
|
@@ -1142,8 +981,9 @@ async function buildAnthropicRequest(model, context, options, profile, isOAuthTo
|
|
|
1142
981
|
sessionId: options?.sessionId
|
|
1143
982
|
});
|
|
1144
983
|
const cacheBreakpointOptOutMessageIndexes = /* @__PURE__ */ new Set();
|
|
1145
|
-
const messages = await convertAnthropicMessages(managed ? getAiTransportHost().transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId,
|
|
984
|
+
const messages = await convertAnthropicMessages(managed ? getAiTransportHost().transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId, { preserveUnframedToolResults: preparedRequestSuffix.has(context) }) : transformProviderMessages(replayPlan.messages, model, normalizeAnthropicToolCallId), model, isOAuthToken, {
|
|
1146
985
|
profile,
|
|
986
|
+
context,
|
|
1147
987
|
allowReasoningContentReplay: managed && resolveProviderEndpoint(model).endpointClass === "xiaomi-native",
|
|
1148
988
|
allowEmptySignature: model.compat?.allowEmptySignature,
|
|
1149
989
|
compaction: replayPlan.compaction,
|
|
@@ -1173,7 +1013,7 @@ async function buildAnthropicRequest(model, context, options, profile, isOAuthTo
|
|
|
1173
1013
|
return {
|
|
1174
1014
|
params,
|
|
1175
1015
|
toolProjection,
|
|
1176
|
-
|
|
1016
|
+
replayedCompaction: replayPlan.compaction
|
|
1177
1017
|
};
|
|
1178
1018
|
}
|
|
1179
1019
|
/** Apply caller payload edits before restoring required request contracts and beta headers. */
|
|
@@ -1366,21 +1206,13 @@ async function consumeAnthropicStream(params) {
|
|
|
1366
1206
|
let sawMessageStart = false;
|
|
1367
1207
|
let sawMessageStop = false;
|
|
1368
1208
|
let sawStopReason = false;
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
if (managed && classifyToolTurn && (output.stopReason === "toolUse" || output.content.some((block) => block.type === "toolCall"))) tagPendingCommentaryText(output.content);
|
|
1372
|
-
for (const event of pendingTextEnds) eventSink.push(event);
|
|
1373
|
-
pendingTextEnds.length = 0;
|
|
1374
|
-
};
|
|
1375
|
-
const emitContentEnd = (block, contentIndex, deferText) => {
|
|
1376
|
-
const event = {
|
|
1209
|
+
const emitContentEnd = (block, contentIndex) => {
|
|
1210
|
+
eventSink.push({
|
|
1377
1211
|
type: `${block.type}_end`,
|
|
1378
1212
|
contentIndex,
|
|
1379
1213
|
content: block.type === "thinking" ? block.thinking : block.text,
|
|
1380
1214
|
partial: output
|
|
1381
|
-
};
|
|
1382
|
-
if (managed && deferText && event.type === "text_end") pendingTextEnds.push(event);
|
|
1383
|
-
else eventSink.push(event);
|
|
1215
|
+
});
|
|
1384
1216
|
};
|
|
1385
1217
|
const emitContentStart = (kind, contentIndex, delta = "") => {
|
|
1386
1218
|
eventSink.push({
|
|
@@ -1440,7 +1272,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1440
1272
|
if (contentIndex === void 0) continue;
|
|
1441
1273
|
indexes.delete(key);
|
|
1442
1274
|
const block = output.content[contentIndex];
|
|
1443
|
-
if (block?.type === kind) emitContentEnd(block, contentIndex
|
|
1275
|
+
if (block?.type === kind) emitContentEnd(block, contentIndex);
|
|
1444
1276
|
}
|
|
1445
1277
|
};
|
|
1446
1278
|
for await (const rawEvent of iterateModelStream(params.events, options.signal)) {
|
|
@@ -1477,7 +1309,6 @@ async function consumeAnthropicStream(params) {
|
|
|
1477
1309
|
if (fallbackBoundary) {
|
|
1478
1310
|
refusalBuffer?.discard();
|
|
1479
1311
|
sealedToolCalls.length = 0;
|
|
1480
|
-
pendingTextEnds.length = 0;
|
|
1481
1312
|
blockIndexes.clear();
|
|
1482
1313
|
pendingThinkingSignatures.clear();
|
|
1483
1314
|
applyAnthropicFallbackBoundary({
|
|
@@ -1502,7 +1333,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1502
1333
|
if (block.type !== "text") continue;
|
|
1503
1334
|
delete block.index;
|
|
1504
1335
|
emitContentStart("text", i, block.text);
|
|
1505
|
-
emitContentEnd(block, i
|
|
1336
|
+
emitContentEnd(block, i);
|
|
1506
1337
|
}
|
|
1507
1338
|
continue;
|
|
1508
1339
|
}
|
|
@@ -1532,8 +1363,6 @@ async function consumeAnthropicStream(params) {
|
|
|
1532
1363
|
continue;
|
|
1533
1364
|
}
|
|
1534
1365
|
if (contentBlock?.type === "tool_use") {
|
|
1535
|
-
if (managed) tagPendingCommentaryText(output.content);
|
|
1536
|
-
flushPendingTextEnds();
|
|
1537
1366
|
const block = {
|
|
1538
1367
|
type: "toolCall",
|
|
1539
1368
|
id: typeof contentBlock.id === "string" ? contentBlock.id : "",
|
|
@@ -1635,7 +1464,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1635
1464
|
block,
|
|
1636
1465
|
contentIndex: index
|
|
1637
1466
|
});
|
|
1638
|
-
else emitContentEnd(block, index
|
|
1467
|
+
else emitContentEnd(block, index);
|
|
1639
1468
|
finishReasoningContentSidecars(event.index);
|
|
1640
1469
|
continue;
|
|
1641
1470
|
}
|
|
@@ -1649,8 +1478,8 @@ async function consumeAnthropicStream(params) {
|
|
|
1649
1478
|
else output.stopReason = mapAnthropicStopReason(delta.stop_reason);
|
|
1650
1479
|
}
|
|
1651
1480
|
applyAnthropicMessageDeltaUsage(output.usage, usage, messageStartPromptUsage);
|
|
1481
|
+
if (sawStopReason && messageStartPromptUsage && typeof usage?.output_tokens === "number") output.usage.usageReport = { state: "available" };
|
|
1652
1482
|
calculateCost(costModel, output.usage);
|
|
1653
|
-
flushPendingTextEnds(true);
|
|
1654
1483
|
}
|
|
1655
1484
|
}
|
|
1656
1485
|
if ((isDirectAnthropicModel(model) || !managed && refusalBuffer) && !sawMessageStop) throw new Error("Anthropic stream ended before message_stop");
|
|
@@ -1669,10 +1498,9 @@ async function consumeAnthropicStream(params) {
|
|
|
1669
1498
|
});
|
|
1670
1499
|
}
|
|
1671
1500
|
refusalBuffer?.flush();
|
|
1672
|
-
flushPendingTextEnds(true);
|
|
1673
1501
|
} finally {
|
|
1674
1502
|
logAnthropicThinkingDrops(inputTransformations);
|
|
1675
1503
|
}
|
|
1676
1504
|
}
|
|
1677
1505
|
//#endregion
|
|
1678
|
-
export {
|
|
1506
|
+
export { resolveAnthropicCacheOptions as A, readAnthropicFallbackBoundary as B, applyAnthropicEphemeralCacheControlMarkers as C, isAnthropicServerToolClearingEnabled as D, buildAnthropicSystemBlocks as E, supportsAnthropicServerSideFallback as F, isAnthropicOAuthApiKey as H, ANTHROPIC_SERVER_SIDE_FALLBACKS as I, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA as L, resolveAnthropicPayloadPolicy as M, resolveAnthropicRequestBetaHeader as N, isDirectAnthropicModel as O, resolveAnthropicServerCompactionPlan as P, CLAUDE_OPUS_FALLBACK_MODEL_COST as R, applyAnthropicContextManagementToRequest as S, applyAnthropicRequestCacheControl as T, omitFoundryBearerCredentialHeaders as U, resolveAnthropicFallbackServingModelCost as V, usesFoundryBearerAuth as W, logAnthropicThinkingDrops as _, readAnthropicPromptUsageSnapshot as a, resolveNewestAnthropicCompaction as b, applyAnthropicRefusal as c, applyAnthropicThinkingOptions as d, resolveAnthropicTransportOptions as f, findActiveAnthropicToolTurnAssistantIndex as g, applyAnthropicThinkingBindingControls as h, readAnthropicCacheWriteUsage as i, resolveAnthropicEphemeralCacheControl as j, logAnthropicContextEdits as k, buildAnthropicRequest as l, ANTHROPIC_OMITTED_REASONING_TEXT as m, applyAnthropicMessageDeltaUsage as n, readAnthropicUsageTokenCount as o, resolveCompletionTokenReservation as p, applyAnthropicMessageStartUsage as r, readLastAnthropicIterationUsage as s, consumeAnthropicStream as t, prepareAnthropicRequest as u, readAnthropicInputTransformations as v, applyAnthropicPayloadPolicyToParams as w, suppressAnthropicCompaction as x, isAnthropicReplayRejection as y, applyAnthropicFallbackBoundary as z };
|