@openclaw/ai 2026.9.4 → 2026.9.6
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 +1 -1
- package/dist/{anthropic-C4Qu4H0Z.mjs → anthropic-DZQ_7gD1.mjs} +37 -38
- package/dist/{anthropic-payload-policy-BZ8umAbk.d.mts → anthropic-payload-policy-DyfwikYJ.d.mts} +4 -4
- package/dist/{anthropic-stream-reducer-CILWF7JD.mjs → anthropic-stream-reducer-D6ZI1wwj.mjs} +70 -50
- package/dist/{api-registry-ByUwIR0e.d.mts → api-registry-C2T3lTV7.d.mts} +2 -2
- package/dist/{assistant-output-tLt4H-iQ.mjs → assistant-output-DM1JBNs1.mjs} +1 -1
- package/dist/{azure-openai-responses-BAlqlKKc.mjs → azure-openai-responses-DS86GYzq.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-CPmadnUf.mjs} +12 -12
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-QuErwCIl.mjs → diagnostics-CH8j2wIG.mjs} +139 -7
- package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
- package/dist/diagnostics.d.mts +11 -24
- package/dist/diagnostics.mjs +4 -4
- package/dist/event-stream-C0nsgbj2.d.mts +1 -0
- package/dist/{event-stream-Bt5Y4Pav.d.mts → event-stream-CjnIZZst.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-DPBAOaOW.mjs → google-BZJFjhuC.mjs} +6 -9
- package/dist/{google-messages-6JkpHrhJ.mjs → google-messages-DB7GKkDk.mjs} +3 -3
- package/dist/{google-shared-BvBeW9aq.mjs → google-shared-Bok4I6zB.mjs} +13 -13
- package/dist/{google-vertex-k-TMCAYD.mjs → google-vertex-3eVNR2qW.mjs} +5 -8
- package/dist/{host-4atIX-2V.d.mts → host-DH-Z-LDb.d.mts} +5 -3
- package/dist/{host-policy-Zcg_cNz8.mjs → host-policy-DZO3oPPk.mjs} +1 -1
- package/dist/{host-B8YfDGd4.mjs → host-yTvBrYM2.mjs} +63 -31
- package/dist/{index-DdD3qerf.d.mts → index-C25RT6bP.d.mts} +37 -14
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -6
- package/dist/internal/anthropic.d.mts +13 -10
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +24 -53
- package/dist/internal/openai.mjs +12 -9
- package/dist/internal/runtime.d.mts +6 -8
- package/dist/internal/runtime.mjs +6 -10
- package/dist/internal/shared.d.mts +7 -5
- package/dist/internal/shared.mjs +4 -3
- package/dist/internal/tool-schema.d.mts +4 -4
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-CxUZ1jUb.mjs → mistral-C_13dVBn.mjs} +9 -13
- package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
- package/dist/{openai-chatgpt-responses-CgO6kZfo.mjs → openai-chatgpt-responses-sTxPl4zM.mjs} +150 -83
- package/dist/{openai-completions-yJuk7eis.mjs → openai-completions-BO6D_hrB.mjs} +11 -12
- package/dist/{openai-prompt-cache-Bds-n_9Q.mjs → openai-completions-compat-CUollwl6.mjs} +5 -50
- package/dist/{openai-completions-compat-eHgh5UPE.d.mts → openai-completions-compat-DfJG1wSO.d.mts} +4 -4
- package/dist/{openai-completions-stream-Da2vvl-S.mjs → openai-completions-stream-BpuJ0ZOA.mjs} +117 -106
- package/dist/{openai-prompt-cache-B4eYo2-I.d.mts → openai-prompt-cache-C4RHdN4n.d.mts} +2 -2
- package/dist/openai-prompt-cache-CjV_2IRI.mjs +46 -0
- package/dist/{openai-provider-client-S2gCrM2Z.mjs → openai-provider-client-BP8J1aeg.mjs} +2 -2
- package/dist/openai-reasoning-effort-ash8dPrd.mjs +243 -0
- package/dist/{openai-responses-DaYwH05E.mjs → openai-responses-BJ_IEoMU.mjs} +8 -12
- package/dist/{openai-responses-compaction-window-CIhBAkkq.mjs → openai-responses-compaction-window-BiNCT0bS.mjs} +20 -62
- package/dist/{openai-responses-contracts-BjBAqAg_.d.mts → openai-responses-contracts-B1ENJFpI.d.mts} +9 -5
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-DPHWgbBH.mjs +198 -0
- package/dist/openai-responses-request-lifecycle-DFuyO1pQ.mjs +36 -0
- package/dist/{openai-responses-shared-B8RdBPCv.mjs → openai-responses-shared-DvSqtJ6_.mjs} +859 -581
- package/dist/openai-responses-terminal-usage-BNFbvY9f.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-D4BMcj2D.mjs} +262 -162
- package/dist/{openai-transport-params-9aPuV5YY.mjs → openai-transport-params-DZKOTSfH.mjs} +157 -47
- package/dist/{positive-integer-41zhOdcV.mjs → positive-integer-BiUxrd71.mjs} +1 -1
- package/dist/{provider-error-BA-v_tKd.mjs → provider-error-CRhW7lkJ.mjs} +139 -44
- package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
- package/dist/{provider-options-Ceqv1OKk.d.mts → provider-options-DZYq53lj.d.mts} +12 -7
- package/dist/{provider-replay-context-CJ_YvcEW.mjs → provider-replay-context-DPr3w20a.mjs} +1 -1
- package/dist/{provider-transcript-transform-V5YzU9zh.mjs → provider-transcript-transform-BTocjCRs.mjs} +1 -1
- package/dist/{provider-transport-turn-state-D5EXOFL2.mjs → provider-transport-turn-state-lrXEFkYr.mjs} +1 -1
- package/dist/{provider-types-CVjKjsuq.d.mts → provider-types-w1rEqrGP.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BcR5pztD.mjs → reasoning-tag-text-partitioner-Di38crhI.mjs} +167 -40
- package/dist/{simple-options-BQbb4yQL.mjs → simple-options-np1XPuhm.mjs} +5 -3
- package/dist/{usage-cost-BNWbbXav.mjs → src-DwGYYyZp.mjs} +18 -11
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-BeptfRL6.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-zHll9BxO.mjs → transport-stream-shared-B5RioB_Q.mjs} +16 -24
- package/dist/{transport-stream-shared-DNvmoWnv.d.mts → transport-stream-shared-B7Z9oCYg.d.mts} +5 -5
- package/dist/{transport-utils-zrYjICLZ.mjs → transport-utils-03Qi0CN2.mjs} +3 -3
- package/dist/transports.d.mts +27 -13
- package/dist/transports.mjs +168 -462
- package/dist/types-DTvddOfm.d.mts +1 -0
- package/dist/{types-Ntv5z2g2.d.mts → types-qZFbaDbK.d.mts} +49 -3
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -5
- package/dist/{validation-B0t_G2H6.d.mts → validation-DhQhmt6t.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +11 -6
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-C3WGFsum.d.mts +0 -1
- package/dist/openai-responses-contracts-DDOHA62Y.mjs +0 -245
- package/dist/openai-responses-prompt-observer-internal-f8J7wpsk.mjs +0 -32
- package/dist/src-DDmEryvj.mjs +0 -2
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-DlfwzH3T.d.mts +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ provider plugin hooks, and diagnostics logging) can be injected with
|
|
|
24
24
|
`configureAiTransportHost`; the defaults are inert.
|
|
25
25
|
|
|
26
26
|
The explicit `@openclaw/ai/internal/anthropic`, `google-model-family`, `openai`,
|
|
27
|
-
`openai-responses-payload-policy`, `retry-after`, `runtime`, `shared`, and
|
|
27
|
+
`openai-completions-compat`, `openai-responses-payload-policy`, `retry-after`, `runtime`, `shared`, and
|
|
28
28
|
`tool-schema` subpaths exist for the OpenClaw application itself.
|
|
29
29
|
They carry no semver guarantee and can change or disappear in any release; do
|
|
30
30
|
not depend on them outside OpenClaw.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import { _ as
|
|
2
|
+
import { _ as resolveClaudeSonnet5ModelIdentity, g as resolveClaudeOpus5ModelIdentity, y as supportsClaudeAdaptiveThinking } from "./src-DwGYYyZp.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
4
|
-
import { E as resolveAnthropicThinkingEffort, O as usesClaudeFable5MessagesContract, T as requiresClaudeAdaptiveThinking, b as
|
|
5
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
6
|
-
import { C as applyAnthropicThinkingBindingControls, D as ANTHROPIC_SERVER_SIDE_FALLBACKS, H as resolveAnthropicContextManagementBetaHeader, I as applyAnthropicRequestCacheControl, J as usesFoundryBearerAuth, K as isAnthropicOAuthApiKey, L as buildAnthropicSystemBlocks, N as applyAnthropicContextManagementToRequest, O as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, V as resolveAnthropicCacheOptions, d as convertAnthropicTools, f as buildAnthropicReplayPlan, g as normalizeAnthropicToolCallId, h as suppressAnthropicCompaction, l as buildAnthropicGenerationParams, p as isAnthropicReplayRejection, q as omitFoundryBearerCredentialHeaders, t as consumeAnthropicStream, u as convertAnthropicMessages, z as isDirectAnthropicModel } from "./anthropic-stream-reducer-
|
|
4
|
+
import { E as resolveAnthropicThinkingEffort, O as usesClaudeFable5MessagesContract, T as requiresClaudeAdaptiveThinking, b as applyClaudeRequestContract, k as usesClaudeStreamingRefusalContract, n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, w as prepareClaudeNoPrefillRequestContext, x as buildAnthropicClaudeCodeIdentity } from "./host-yTvBrYM2.mjs";
|
|
5
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-03Qi0CN2.mjs";
|
|
6
|
+
import { C as applyAnthropicThinkingBindingControls, D as ANTHROPIC_SERVER_SIDE_FALLBACKS, H as resolveAnthropicContextManagementBetaHeader, I as applyAnthropicRequestCacheControl, J as usesFoundryBearerAuth, K as isAnthropicOAuthApiKey, L as buildAnthropicSystemBlocks, N as applyAnthropicContextManagementToRequest, O as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, V as resolveAnthropicCacheOptions, d as convertAnthropicTools, f as buildAnthropicReplayPlan, g as normalizeAnthropicToolCallId, h as suppressAnthropicCompaction, l as buildAnthropicGenerationParams, p as isAnthropicReplayRejection, q as omitFoundryBearerCredentialHeaders, t as consumeAnthropicStream, u as convertAnthropicMessages, z as isDirectAnthropicModel } from "./anthropic-stream-reducer-D6ZI1wwj.mjs";
|
|
7
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
8
|
-
import { n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "./simple-options-
|
|
8
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "./simple-options-np1XPuhm.mjs";
|
|
9
9
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
-
import { T as parseJsonWithRepair, l as finalizeTransportStream, n as assignTransportErrorDetails, p as notifyProviderHttpResponse } from "./transport-stream-shared-
|
|
10
|
+
import { T as parseJsonWithRepair, l as finalizeTransportStream, n as assignTransportErrorDetails, p as notifyProviderHttpResponse } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
11
11
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
12
12
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
13
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
13
|
+
import { t as createAssistantOutput } from "./assistant-output-DM1JBNs1.mjs";
|
|
14
14
|
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-Bcunsn4I.mjs";
|
|
15
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
15
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BTocjCRs.mjs";
|
|
16
16
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
17
17
|
import Anthropic from "@anthropic-ai/sdk";
|
|
18
18
|
import { Stream } from "@anthropic-ai/sdk/core/streaming.js";
|
|
@@ -73,6 +73,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
73
73
|
let isOAuth;
|
|
74
74
|
let serverSideFallback = false;
|
|
75
75
|
let directApiKeyBetaHeader;
|
|
76
|
+
let claudeCodeVersion;
|
|
76
77
|
if (requestOptions?.client) {
|
|
77
78
|
client = requestOptions.client;
|
|
78
79
|
isOAuth = false;
|
|
@@ -92,8 +93,9 @@ const streamAnthropic = (model, context, options) => {
|
|
|
92
93
|
isOAuth = created.isOAuthToken;
|
|
93
94
|
serverSideFallback = created.serverSideFallback;
|
|
94
95
|
directApiKeyBetaHeader = created.directApiKeyBetaHeader;
|
|
96
|
+
claudeCodeVersion = created.claudeCodeVersion;
|
|
95
97
|
}
|
|
96
|
-
const builtParams = await buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback);
|
|
98
|
+
const builtParams = await buildParams(model, requestContext, isOAuth, requestOptions, serverSideFallback, claudeCodeVersion);
|
|
97
99
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
98
100
|
let params = builtParams.params;
|
|
99
101
|
const toolProjection = builtParams.toolProjection;
|
|
@@ -186,12 +188,11 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
186
188
|
if (resolveClaudeOpus5ModelIdentity(model) || resolveClaudeSonnet5ModelIdentity(model)) return streamAnthropic(model, context, {
|
|
187
189
|
...base,
|
|
188
190
|
thinkingEnabled: true,
|
|
189
|
-
effort: resolveAnthropicThinkingEffort(model, reasoning
|
|
191
|
+
effort: resolveAnthropicThinkingEffort(model, reasoning)
|
|
190
192
|
});
|
|
191
193
|
if (!reasoning) return streamAnthropic(model, context, {
|
|
192
194
|
...base,
|
|
193
|
-
thinkingEnabled: mandatoryAdaptiveThinking
|
|
194
|
-
...mandatoryAdaptiveThinking ? { effort: "high" } : {}
|
|
195
|
+
thinkingEnabled: mandatoryAdaptiveThinking
|
|
195
196
|
});
|
|
196
197
|
if (supportsClaudeAdaptiveThinking(model)) {
|
|
197
198
|
const effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
@@ -201,7 +202,7 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
201
202
|
effort
|
|
202
203
|
});
|
|
203
204
|
}
|
|
204
|
-
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, reasoning, options?.thinkingBudgets);
|
|
205
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens ?? base.maxTokens, reasoning, options?.thinkingBudgets);
|
|
205
206
|
const thinkingEnabled = adjusted.thinkingBudget >= ANTHROPIC_MIN_THINKING_BUDGET_TOKENS;
|
|
206
207
|
const maxTokens = thinkingEnabled ? adjusted.maxTokens : clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens);
|
|
207
208
|
return streamAnthropic(model, context, {
|
|
@@ -282,29 +283,27 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
282
283
|
isOAuthToken: false,
|
|
283
284
|
serverSideFallback: false
|
|
284
285
|
};
|
|
285
|
-
if (isAnthropicOAuthApiKey(apiKey))
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
serverSideFallback: false
|
|
307
|
-
};
|
|
286
|
+
if (isAnthropicOAuthApiKey(apiKey)) {
|
|
287
|
+
const identity = buildAnthropicClaudeCodeIdentity([
|
|
288
|
+
"claude-code-20250219",
|
|
289
|
+
"oauth-2025-04-20",
|
|
290
|
+
...betaFeatures
|
|
291
|
+
].join(","), model.headers, optionsHeaders);
|
|
292
|
+
return {
|
|
293
|
+
client: new Anthropic({
|
|
294
|
+
apiKey: null,
|
|
295
|
+
authToken: apiKey,
|
|
296
|
+
baseURL: model.baseUrl,
|
|
297
|
+
dangerouslyAllowBrowser: true,
|
|
298
|
+
defaultHeaders: identity.headers,
|
|
299
|
+
fetch,
|
|
300
|
+
maxRetries: 0
|
|
301
|
+
}),
|
|
302
|
+
isOAuthToken: true,
|
|
303
|
+
serverSideFallback: false,
|
|
304
|
+
claudeCodeVersion: identity.version
|
|
305
|
+
};
|
|
306
|
+
}
|
|
308
307
|
const serverSideFallback = supportsAnthropicServerSideFallback(model);
|
|
309
308
|
if (serverSideFallback) betaFeatures.push(ANTHROPIC_SERVER_SIDE_FALLBACK_BETA);
|
|
310
309
|
const sessionAffinityHeaders = sessionId && getAnthropicCompat(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {};
|
|
@@ -328,10 +327,10 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
328
327
|
directApiKeyBetaHeader: isDirectAnthropicModel(model) ? Object.entries(defaultHeaders).findLast(([name]) => name.toLowerCase() === "anthropic-beta")?.[1] ?? "" : void 0
|
|
329
328
|
};
|
|
330
329
|
}
|
|
331
|
-
async function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false) {
|
|
330
|
+
async function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false, claudeCodeVersion) {
|
|
332
331
|
const replayThinkingEnabled = requiresClaudeAdaptiveThinking(model) || options?.thinkingEnabled === true;
|
|
333
332
|
const { cacheControl, supportsCacheControlOnTools } = resolveAnthropicCacheOptions(model, options?.cacheRetention);
|
|
334
|
-
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthTokenResult, cacheControl);
|
|
333
|
+
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthTokenResult, cacheControl, claudeCodeVersion);
|
|
335
334
|
const compat = getAnthropicCompat(model);
|
|
336
335
|
const convertedTools = context.tools ? convertAnthropicTools(context.tools, isOAuthTokenResult, compat.supportsEagerToolInputStreaming) : void 0;
|
|
337
336
|
const tools = convertedTools?.tools;
|
package/dist/{anthropic-payload-policy-BZ8umAbk.d.mts → anthropic-payload-policy-DyfwikYJ.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { O as Model } from "./types-
|
|
3
|
-
import { t as AnthropicContextManagementOptions } from "./provider-options-
|
|
1
|
+
import "./index-C25RT6bP.mjs";
|
|
2
|
+
import { O as Model } from "./types-qZFbaDbK.mjs";
|
|
3
|
+
import { t as AnthropicContextManagementOptions } from "./provider-options-DZYq53lj.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. */
|
|
@@ -60,7 +60,7 @@ declare function resolveAnthropicCacheOptions(model: Model<"anthropic-messages">
|
|
|
60
60
|
cacheControl: AnthropicEphemeralCacheControl | undefined;
|
|
61
61
|
supportsCacheControlOnTools: boolean;
|
|
62
62
|
};
|
|
63
|
-
declare function buildAnthropicSystemBlocks(systemPrompt: string | undefined, isOAuthToken: boolean, cacheControl: AnthropicEphemeralCacheControl | undefined): TextBlockParam[] | undefined;
|
|
63
|
+
declare function buildAnthropicSystemBlocks(systemPrompt: string | undefined, isOAuthToken: boolean, cacheControl: AnthropicEphemeralCacheControl | undefined, claudeCodeVersion?: string): TextBlockParam[] | undefined;
|
|
64
64
|
/** Allocate tool and history checkpoints around the prepared stable system blocks. */
|
|
65
65
|
declare function applyAnthropicRequestCacheControl(payload: {
|
|
66
66
|
system?: unknown;
|
package/dist/{anthropic-stream-reducer-CILWF7JD.mjs → anthropic-stream-reducer-D6ZI1wwj.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as supportsClaudeNativeXhighEffort, c as bindsClaudeThinkingPrefix, d as resolveClaudeFable5ModelIdentity, f as resolveClaudeModelIdentity, g as resolveClaudeOpus5ModelIdentity, h as resolveClaudeOpus55ModelIdentity, y as supportsClaudeAdaptiveThinking } from "./src-DwGYYyZp.mjs";
|
|
2
2
|
import { r as appendAssistantThinking } from "./event-stream-D8PARQfL.mjs";
|
|
3
3
|
import { i as normalizeOptionalLowercaseString, r as normalizeNullableString } from "./string-coerce-fsri9iCu.mjs";
|
|
4
|
-
import { C as mapAnthropicStopReason, T as requiresClaudeAdaptiveThinking, _ as isImageWithMediaPayload, d as describeToolResultMediaPlaceholder, j as calculateCost, m as extractToolResultText, n as getAiTransportHost, p as extractToolResultBlockText, v as sanitizeSurrogates, y as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK } from "./host-B8YfDGd4.mjs";
|
|
5
4
|
import { a as asRecord, o as isRecord, r as asOptionalObjectRecord, s as readStringField } from "./record-coerce-DwRYMj3t.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import "./
|
|
8
|
-
import
|
|
5
|
+
import { C as mapAnthropicStopReason, E as resolveAnthropicThinkingEffort, M as calculateCost, T as requiresClaudeAdaptiveThinking, _ as isImageWithMediaPayload, d as describeToolResultMediaPlaceholder, m as extractToolResultText, n as getAiTransportHost, p as extractToolResultBlockText, v as sanitizeSurrogates, y as ANTHROPIC_CLAUDE_CODE_VERSION } from "./host-yTvBrYM2.mjs";
|
|
6
|
+
import { i as asNonNegativeFiniteNumber, n as estimateBase64DecodedBytes } from "./base64-CPmadnUf.mjs";
|
|
7
|
+
import "./transport-utils-03Qi0CN2.mjs";
|
|
8
|
+
import { a as resolveProviderRequestCapabilities, i as resolveProviderEndpoint } from "./host-policy-DZO3oPPk.mjs";
|
|
9
9
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
10
|
-
import { f as splitSystemPromptCacheBoundary, h as stripSystemPromptRelocatableBoundary, m as stripSystemPromptCacheBoundary, v as sortPromptCacheToolsByName } from "./simple-options-
|
|
11
|
-
import { t as parsePositiveInteger } from "./positive-integer-
|
|
12
|
-
import {
|
|
13
|
-
import { E as parseStreamingJson, _ as sanitizeTransportPayloadText, c as finalizeTerminalToolCallArguments, g as sanitizeNonEmptyTransportPayloadText, r as coerceTransportToolCallArguments, v as transportAbortError, w as createToolArgumentPreviewSchedule, x as parseJsonObjectPreservingUnsafeIntegers } from "./transport-stream-shared-
|
|
14
|
-
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-
|
|
10
|
+
import { f as splitSystemPromptCacheBoundary, h as stripSystemPromptRelocatableBoundary, m as stripSystemPromptCacheBoundary, v as sortPromptCacheToolsByName } from "./simple-options-np1XPuhm.mjs";
|
|
11
|
+
import { t as parsePositiveInteger } from "./positive-integer-BiUxrd71.mjs";
|
|
12
|
+
import { n as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-CD9c_fK8.mjs";
|
|
13
|
+
import { E as parseStreamingJson, _ as sanitizeTransportPayloadText, c as finalizeTerminalToolCallArguments, g as sanitizeNonEmptyTransportPayloadText, r as coerceTransportToolCallArguments, v as transportAbortError, w as createToolArgumentPreviewSchedule, x as parseJsonObjectPreservingUnsafeIntegers } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
14
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-DPr3w20a.mjs";
|
|
15
15
|
import { i as tagPendingCommentaryText } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
16
16
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
17
17
|
//#region packages/ai/src/providers/anthropic-auth-headers.ts
|
|
@@ -104,7 +104,7 @@ function resolveAnthropicCacheOptions(model, cacheRetention) {
|
|
|
104
104
|
supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? model.provider !== "fireworks"
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
-
function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl) {
|
|
107
|
+
function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion = ANTHROPIC_CLAUDE_CODE_VERSION) {
|
|
108
108
|
const blocks = systemPrompt ? [{
|
|
109
109
|
type: "text",
|
|
110
110
|
text: sanitizeSurrogates(systemPrompt)
|
|
@@ -119,7 +119,7 @@ function buildAnthropicSystemBlocks(systemPrompt, isOAuthToken, cacheControl) {
|
|
|
119
119
|
const identityCacheControl = blocks.some((block) => block.cache_control) ? void 0 : cacheControl;
|
|
120
120
|
blocks.unshift({
|
|
121
121
|
type: "text",
|
|
122
|
-
text:
|
|
122
|
+
text: `x-anthropic-billing-header: cc_version=${claudeCodeVersion}; cc_entrypoint=sdk-cli;`
|
|
123
123
|
}, {
|
|
124
124
|
type: "text",
|
|
125
125
|
text: "You are Claude Code, Anthropic's official CLI for Claude.",
|
|
@@ -383,25 +383,41 @@ const CLAUDE_OPUS_FALLBACK_MODEL_COST = {
|
|
|
383
383
|
cacheRead: .5,
|
|
384
384
|
cacheWrite: 6.25
|
|
385
385
|
};
|
|
386
|
+
const CLAUDE_OPUS_55_FALLBACK_MODEL_COST = {
|
|
387
|
+
input: 4,
|
|
388
|
+
output: 20,
|
|
389
|
+
cacheRead: .2,
|
|
390
|
+
cacheWrite: 5
|
|
391
|
+
};
|
|
386
392
|
function resolveFallbackModelIdentity(modelId) {
|
|
387
393
|
if (!modelId?.trim()) return null;
|
|
388
394
|
const ref = { id: modelId };
|
|
389
395
|
const normalized = resolveClaudeModelIdentity(ref);
|
|
396
|
+
if (resolveClaudeOpus55ModelIdentity(ref)) return "claude-opus-5-5";
|
|
390
397
|
if (normalized === "opus" || normalized === "opus-5" || resolveClaudeOpus5ModelIdentity(ref)) return "claude-opus-5";
|
|
391
398
|
if (resolveClaudeFable5ModelIdentity(ref)) return "claude-fable-5";
|
|
392
399
|
if (/^claude-opus-4-8(?=$|[^a-z0-9])/.test(normalized)) return "claude-opus-4-8";
|
|
393
400
|
return normalized || null;
|
|
394
401
|
}
|
|
395
|
-
function
|
|
396
|
-
|
|
402
|
+
function resolveClaudeOpusFallbackCost(modelId) {
|
|
403
|
+
if (modelId === "claude-opus-5-5") return CLAUDE_OPUS_55_FALLBACK_MODEL_COST;
|
|
404
|
+
return modelId === "claude-opus-5" || modelId === "claude-opus-4-8" ? CLAUDE_OPUS_FALLBACK_MODEL_COST : void 0;
|
|
397
405
|
}
|
|
398
406
|
/** Resolve billed rates from the serving model reported by Anthropic's fallback stream. */
|
|
399
407
|
function resolveAnthropicFallbackServingModelCost(params) {
|
|
400
408
|
const requestedModelId = resolveFallbackModelIdentity(params.requestedModelId);
|
|
401
409
|
const servingModelId = resolveFallbackModelIdentity(params.servingModelId);
|
|
402
|
-
|
|
403
|
-
if (
|
|
404
|
-
|
|
410
|
+
const servingCost = resolveClaudeOpusFallbackCost(servingModelId);
|
|
411
|
+
if (!servingCost || servingModelId === requestedModelId) return params.requestedCost;
|
|
412
|
+
const requestedCost = resolveClaudeOpusFallbackCost(requestedModelId);
|
|
413
|
+
if (requestedCost === servingCost) return params.requestedCost;
|
|
414
|
+
if (!requestedCost) return servingCost;
|
|
415
|
+
return {
|
|
416
|
+
input: params.requestedCost.input / requestedCost.input * servingCost.input,
|
|
417
|
+
output: params.requestedCost.output / requestedCost.output * servingCost.output,
|
|
418
|
+
cacheRead: params.requestedCost.cacheRead / requestedCost.cacheRead * servingCost.cacheRead,
|
|
419
|
+
cacheWrite: params.requestedCost.cacheWrite / requestedCost.cacheWrite * servingCost.cacheWrite
|
|
420
|
+
};
|
|
405
421
|
}
|
|
406
422
|
function readBoundaryModel(value) {
|
|
407
423
|
if (!value || typeof value !== "object") return null;
|
|
@@ -549,39 +565,34 @@ const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
|
549
565
|
"patternProperties",
|
|
550
566
|
"properties"
|
|
551
567
|
]);
|
|
568
|
+
/** Normalize the detached JSON projection and report tuple changes to enclosing schemas. */
|
|
552
569
|
function normalizeAnthropicJsonSchema(schema) {
|
|
553
|
-
if (!isRecord(schema)) return
|
|
570
|
+
if (!isRecord(schema)) return false;
|
|
554
571
|
let changed = false;
|
|
555
|
-
const normalized = { ...schema };
|
|
556
572
|
for (const [key, value] of Object.entries(schema)) {
|
|
557
573
|
if (schemaValueKeywords.has(key) && !Array.isArray(value)) {
|
|
558
|
-
|
|
559
|
-
normalized[key] = next;
|
|
560
|
-
changed ||= next !== value;
|
|
574
|
+
changed = normalizeAnthropicJsonSchema(value) || changed;
|
|
561
575
|
continue;
|
|
562
576
|
}
|
|
563
577
|
if (schemaArrayKeywords.has(key) && Array.isArray(value)) {
|
|
564
|
-
const
|
|
565
|
-
normalized[key] = next;
|
|
566
|
-
changed ||= next.some((entry, index) => entry !== value[index]);
|
|
578
|
+
for (const entry of value) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
567
579
|
continue;
|
|
568
580
|
}
|
|
569
|
-
if (schemaMapKeywords.has(key) && isRecord(value))
|
|
570
|
-
const next = Object.fromEntries(Object.entries(value).map(([entryKey, entryValue]) => [entryKey, normalizeAnthropicJsonSchema(entryValue)]));
|
|
571
|
-
normalized[key] = next;
|
|
572
|
-
changed ||= Object.entries(value).some(([entryKey, entryValue]) => next[entryKey] !== entryValue);
|
|
573
|
-
}
|
|
581
|
+
if (schemaMapKeywords.has(key) && isRecord(value)) for (const entry of Object.values(value)) changed = normalizeAnthropicJsonSchema(entry) || changed;
|
|
574
582
|
}
|
|
575
583
|
if (Array.isArray(schema.items)) {
|
|
576
|
-
|
|
584
|
+
for (const entry of schema.items) normalizeAnthropicJsonSchema(entry);
|
|
585
|
+
schema.prefixItems = schema.items;
|
|
577
586
|
const additionalItems = schema.additionalItems;
|
|
578
|
-
if (typeof additionalItems === "boolean" || isRecord(additionalItems))
|
|
579
|
-
|
|
580
|
-
|
|
587
|
+
if (typeof additionalItems === "boolean" || isRecord(additionalItems)) {
|
|
588
|
+
normalizeAnthropicJsonSchema(additionalItems);
|
|
589
|
+
schema.items = additionalItems;
|
|
590
|
+
} else delete schema.items;
|
|
591
|
+
delete schema.additionalItems;
|
|
581
592
|
changed = true;
|
|
582
593
|
}
|
|
583
|
-
if (changed) delete
|
|
584
|
-
return changed
|
|
594
|
+
if (changed) delete schema.$schema;
|
|
595
|
+
return changed;
|
|
585
596
|
}
|
|
586
597
|
/** Snapshots direct/custom tool descriptors before Anthropic payload construction. */
|
|
587
598
|
function projectAnthropicTools(tools, toWireName) {
|
|
@@ -600,11 +611,8 @@ function projectAnthropicTools(tools, toWireName) {
|
|
|
600
611
|
unavailableOriginalNames.add(name);
|
|
601
612
|
continue;
|
|
602
613
|
}
|
|
603
|
-
const anthropicSchema =
|
|
604
|
-
|
|
605
|
-
unavailableOriginalNames.add(name);
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
614
|
+
const anthropicSchema = schemaProjection.schema;
|
|
615
|
+
normalizeAnthropicJsonSchema(anthropicSchema);
|
|
608
616
|
const properties = anthropicSchema.properties;
|
|
609
617
|
const required = anthropicSchema.required;
|
|
610
618
|
if (properties !== void 0 && properties !== null && !isRecord(properties) || required !== void 0 && required !== null && (!Array.isArray(required) || required.some((entry) => typeof entry !== "string"))) {
|
|
@@ -682,21 +690,23 @@ function createCompactionCapture(output, model, options) {
|
|
|
682
690
|
const content = typeof block.content === "string" ? block.content : "";
|
|
683
691
|
pending.set(index, {
|
|
684
692
|
content,
|
|
685
|
-
replayIndex
|
|
693
|
+
replayIndex,
|
|
694
|
+
...typeof block.encrypted_content === "string" || block.encrypted_content === null ? { encryptedContent: block.encrypted_content } : {}
|
|
686
695
|
});
|
|
687
696
|
return true;
|
|
688
697
|
},
|
|
689
698
|
delta(index, delta) {
|
|
690
699
|
const capture = pending.get(index);
|
|
691
700
|
if (!capture || delta?.type !== "compaction_delta") return false;
|
|
692
|
-
|
|
701
|
+
if (typeof delta.content === "string") capture.content += delta.content;
|
|
702
|
+
if (typeof delta.encrypted_content === "string" || delta.encrypted_content === null) capture.encryptedContent = delta.encrypted_content;
|
|
693
703
|
return true;
|
|
694
704
|
},
|
|
695
705
|
complete(index) {
|
|
696
706
|
const capture = pending.get(index);
|
|
697
707
|
if (!capture) return false;
|
|
698
708
|
pending.delete(index);
|
|
699
|
-
captureAnthropicCompaction(output, capture
|
|
709
|
+
captureAnthropicCompaction(output, capture, model, options);
|
|
700
710
|
return true;
|
|
701
711
|
}
|
|
702
712
|
};
|
|
@@ -704,18 +714,20 @@ function createCompactionCapture(output, model, options) {
|
|
|
704
714
|
function isAnthropicCompactionState(state) {
|
|
705
715
|
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 false;
|
|
706
716
|
if (state.type === ANTHROPIC_COMPACTION_SUPPRESSION_TYPE) return state.data === ANTHROPIC_COMPACTION_SUPPRESSION_DATA;
|
|
707
|
-
return state.type === ANTHROPIC_COMPACTION_REPLAY_TYPE && state.data.length > 0 && (state.replayIndex === void 0 || typeof state.replayIndex === "number" && Number.isSafeInteger(state.replayIndex) && state.replayIndex >= 0);
|
|
717
|
+
return state.type === ANTHROPIC_COMPACTION_REPLAY_TYPE && state.data.length > 0 && (state.encryptedContent === void 0 || state.encryptedContent === null || typeof state.encryptedContent === "string") && (state.replayIndex === void 0 || typeof state.replayIndex === "number" && Number.isSafeInteger(state.replayIndex) && state.replayIndex >= 0);
|
|
708
718
|
}
|
|
709
719
|
function readAnthropicCompactionState(value) {
|
|
710
720
|
return isRecord(value) && isAnthropicCompactionState(value) ? value : void 0;
|
|
711
721
|
}
|
|
712
|
-
function captureAnthropicCompaction(output,
|
|
722
|
+
function captureAnthropicCompaction(output, capture, model, options) {
|
|
723
|
+
const { content: summary, replayIndex, encryptedContent } = capture;
|
|
713
724
|
const context = buildProviderReplayContext(model, options);
|
|
714
725
|
if (!summary || !context.baseUrlHash || !Number.isSafeInteger(replayIndex) || replayIndex < 0) return;
|
|
715
726
|
output.providerReplay = {
|
|
716
727
|
v: 1,
|
|
717
728
|
type: ANTHROPIC_COMPACTION_REPLAY_TYPE,
|
|
718
729
|
data: summary,
|
|
730
|
+
...encryptedContent !== void 0 ? { encryptedContent } : {},
|
|
719
731
|
replayIndex,
|
|
720
732
|
...context,
|
|
721
733
|
baseUrlHash: context.baseUrlHash
|
|
@@ -748,7 +760,8 @@ function resolveNewestAnthropicCompaction(messages, model, options) {
|
|
|
748
760
|
return {
|
|
749
761
|
owner: message,
|
|
750
762
|
replayIndex: replayState.replayIndex ?? 0,
|
|
751
|
-
summary: replayState.data
|
|
763
|
+
summary: replayState.data,
|
|
764
|
+
...replayState.encryptedContent !== void 0 ? { encryptedContent: replayState.encryptedContent } : {}
|
|
752
765
|
};
|
|
753
766
|
}
|
|
754
767
|
}
|
|
@@ -764,7 +777,8 @@ function buildAnthropicReplayPlan(messages, model, options) {
|
|
|
764
777
|
}, ...messages.slice(ownerIndex + 1)],
|
|
765
778
|
compaction: {
|
|
766
779
|
type: "compaction",
|
|
767
|
-
content: checkpoint.summary
|
|
780
|
+
content: checkpoint.summary,
|
|
781
|
+
...checkpoint.encryptedContent !== void 0 ? { encrypted_content: checkpoint.encryptedContent } : {}
|
|
768
782
|
}
|
|
769
783
|
};
|
|
770
784
|
}
|
|
@@ -774,12 +788,13 @@ function isAnthropicReplayRejection(error) {
|
|
|
774
788
|
const record = error;
|
|
775
789
|
const nested = record.error && typeof record.error === "object" && !Array.isArray(record.error) ? record.error : void 0;
|
|
776
790
|
const text = [
|
|
791
|
+
record.errorMessage,
|
|
777
792
|
record.message,
|
|
778
793
|
record.code,
|
|
779
794
|
nested?.message,
|
|
780
795
|
nested?.code
|
|
781
796
|
].filter((value) => typeof value === "string").join(" ").toLowerCase();
|
|
782
|
-
return (record.status === 400 || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
797
|
+
return (record.status === 400 || record.errorCode === "400" || text.startsWith("http 400:")) && (text.includes("compaction") || text.includes("context_management"));
|
|
783
798
|
}
|
|
784
799
|
//#endregion
|
|
785
800
|
//#region packages/ai/src/internal/anthropic-inline-images.ts
|
|
@@ -1022,7 +1037,7 @@ function buildAnthropicGenerationParams({ model, options, tools, toolProjection,
|
|
|
1022
1037
|
type: "adaptive",
|
|
1023
1038
|
display
|
|
1024
1039
|
};
|
|
1025
|
-
const effort = options?.effort ?? (mandatoryAdaptiveThinking ?
|
|
1040
|
+
const effort = options?.effort ?? (mandatoryAdaptiveThinking ? resolveAnthropicThinkingEffort(model, void 0) : void 0);
|
|
1026
1041
|
if (effort) params.output_config = { effort };
|
|
1027
1042
|
} else params.thinking = {
|
|
1028
1043
|
type: "enabled",
|
|
@@ -1243,7 +1258,9 @@ async function consumeAnthropicStream(params) {
|
|
|
1243
1258
|
const allowReasoningContentReplay = managed && resolveProviderEndpoint(model).endpointClass === "xiaomi-native";
|
|
1244
1259
|
const reasoningContentThinkingBlocks = /* @__PURE__ */ new Map();
|
|
1245
1260
|
const reasoningContentTextBlocks = /* @__PURE__ */ new Map();
|
|
1261
|
+
let sawMessageStart = false;
|
|
1246
1262
|
let sawMessageStop = false;
|
|
1263
|
+
let sawStopReason = false;
|
|
1247
1264
|
const pendingTextEnds = [];
|
|
1248
1265
|
const flushPendingTextEnds = () => {
|
|
1249
1266
|
for (const event of pendingTextEnds) eventSink.push(event);
|
|
@@ -1351,6 +1368,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1351
1368
|
throw new Error(readStringField(error, "message") || "Anthropic Messages stream failed");
|
|
1352
1369
|
}
|
|
1353
1370
|
if (event.type === "message_start") {
|
|
1371
|
+
sawMessageStart = true;
|
|
1354
1372
|
const message = asOptionalObjectRecord(event.message);
|
|
1355
1373
|
const usage = asRecord(message?.usage);
|
|
1356
1374
|
output.responseId = typeof message?.id === "string" ? message.id : void 0;
|
|
@@ -1640,6 +1658,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1640
1658
|
const delta = asOptionalObjectRecord(event.delta);
|
|
1641
1659
|
const usage = asOptionalObjectRecord(event.usage);
|
|
1642
1660
|
if (typeof delta?.stop_reason === "string" && delta.stop_reason) {
|
|
1661
|
+
sawStopReason = true;
|
|
1643
1662
|
if (delta.stop_reason === "refusal") applyAnthropicRefusal(output, delta.stop_details, model.provider);
|
|
1644
1663
|
else output.stopReason = mapAnthropicStopReason(delta.stop_reason);
|
|
1645
1664
|
}
|
|
@@ -1653,6 +1672,7 @@ async function consumeAnthropicStream(params) {
|
|
|
1653
1672
|
if (options.signal?.aborted) throw transportAbortError(options.signal);
|
|
1654
1673
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
1655
1674
|
if ([...blockIndexes.values()].some((index) => blocks[index]?.type === "toolCall")) throw new Error("Provider completed stream with an incomplete tool call");
|
|
1675
|
+
if ((sawMessageStart || blocks.length > 0) && !sawMessageStop && !sawStopReason) throw new Error("Anthropic stream ended before a terminal event");
|
|
1656
1676
|
finalizeTerminalToolCallArguments(sealedToolCalls.map(({ block }) => block), (block) => block.partialJson && block.partialJson.length > 0 ? block.partialJson : seededToolArguments.get(block), void 0, { repairStringLiterals: true });
|
|
1657
1677
|
for (const sealed of sealedToolCalls) {
|
|
1658
1678
|
delete sealed.block.partialJson;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { G as SimpleStreamOptions, J as StreamFunction, O as Model, Y as StreamOptions, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import "./index-C25RT6bP.mjs";
|
|
2
|
+
import { G as SimpleStreamOptions, J as StreamFunction, O as Model, Y as StreamOptions, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "./types-qZFbaDbK.mjs";
|
|
3
3
|
//#region packages/ai/src/api-registry.d.ts
|
|
4
4
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
5
5
|
type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createEmptyTransportUsage } from "./transport-stream-shared-
|
|
1
|
+
import { a as createEmptyTransportUsage } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
2
2
|
//#region packages/ai/src/transports/assistant-output.ts
|
|
3
3
|
function createAssistantOutput(model, api = model.api) {
|
|
4
4
|
return {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
2
|
+
import { n as getAiTransportHost } from "./host-yTvBrYM2.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CjV_2IRI.mjs";
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-np1XPuhm.mjs";
|
|
5
|
+
import { g as resolveOpenAISimpleReasoningEffort } from "./openai-transport-params-DZKOTSfH.mjs";
|
|
5
6
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import { a as
|
|
7
|
+
import { a as runResponsesStreamLifecycle, i as createResponsesAssistantOutput, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-DvSqtJ6_.mjs";
|
|
7
8
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
8
9
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
9
10
|
//#region packages/ai/src/providers/azure-openai-responses.ts
|
|
@@ -20,9 +21,6 @@ function resolveDeploymentName(model, options) {
|
|
|
20
21
|
deploymentMap: process.env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Generate function for Azure OpenAI Responses API
|
|
25
|
-
*/
|
|
26
24
|
const streamAzureOpenAIResponses = (model, context, options) => {
|
|
27
25
|
const stream = new AssistantMessageEventStream();
|
|
28
26
|
const output = createResponsesAssistantOutput(model, "azure-openai-responses");
|
|
@@ -50,11 +48,10 @@ const streamSimpleAzureOpenAIResponses = (model, context, options) => {
|
|
|
50
48
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
51
49
|
const base = buildBaseOptions(model, options, apiKey);
|
|
52
50
|
const authProfileId = options?.authProfileId;
|
|
53
|
-
const reasoningEffort = resolveResponsesReasoningEffort(model, options?.reasoning);
|
|
54
51
|
return streamAzureOpenAIResponses(model, context, {
|
|
55
52
|
...base,
|
|
56
53
|
authProfileId,
|
|
57
|
-
reasoningEffort:
|
|
54
|
+
reasoningEffort: resolveOpenAISimpleReasoningEffort(model, options?.reasoning)
|
|
58
55
|
});
|
|
59
56
|
};
|
|
60
57
|
function normalizeAzureBaseUrl(baseUrl) {
|
|
@@ -45,10 +45,10 @@ function parseStrictPositiveInteger(value) {
|
|
|
45
45
|
//#region packages/media-core/src/base64.ts
|
|
46
46
|
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
47
47
|
function estimateBase64DecodedBytes(base64) {
|
|
48
|
-
let effectiveLen =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
let effectiveLen = base64.length;
|
|
49
|
+
const firstWhitespace = base64.search(/[\x00-\x20]/);
|
|
50
|
+
if (firstWhitespace !== -1) {
|
|
51
|
+
for (let i = firstWhitespace; i < base64.length; i += 1) if (base64.charCodeAt(i) <= 32) effectiveLen -= 1;
|
|
52
52
|
}
|
|
53
53
|
if (effectiveLen === 0) return 0;
|
|
54
54
|
let padding = 0;
|
|
@@ -63,14 +63,11 @@ function estimateBase64DecodedBytes(base64) {
|
|
|
63
63
|
const estimated = Math.floor(effectiveLen * 3 / 4) - padding;
|
|
64
64
|
return Math.max(0, estimated);
|
|
65
65
|
}
|
|
66
|
-
function isBase64DataChar(code) {
|
|
67
|
-
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47;
|
|
68
|
-
}
|
|
69
66
|
function base64DataValue(code) {
|
|
70
67
|
if (code >= 65 && code <= 90) return code - 65;
|
|
71
68
|
if (code >= 97 && code <= 122) return code - 97 + 26;
|
|
72
69
|
if (code >= 48 && code <= 57) return code - 48 + 52;
|
|
73
|
-
return code === 43 ? 62 : 63;
|
|
70
|
+
return code === 43 ? 62 : code === 47 ? 63 : -1;
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
76
73
|
* Normalizes and validates a base64 string, returning canonical no-whitespace
|
|
@@ -81,7 +78,7 @@ function canonicalizeBase64(base64) {
|
|
|
81
78
|
let outLen = 0;
|
|
82
79
|
let padding = 0;
|
|
83
80
|
let sawPadding = false;
|
|
84
|
-
let
|
|
81
|
+
let lastDataValue = 0;
|
|
85
82
|
for (let i = 0; i < base64.length; i += 1) {
|
|
86
83
|
const code = base64.charCodeAt(i);
|
|
87
84
|
if (code <= 32) {
|
|
@@ -96,8 +93,11 @@ function canonicalizeBase64(base64) {
|
|
|
96
93
|
padding += 1;
|
|
97
94
|
if (padding > 2) return;
|
|
98
95
|
sawPadding = true;
|
|
99
|
-
} else
|
|
100
|
-
|
|
96
|
+
} else {
|
|
97
|
+
const value = base64DataValue(code);
|
|
98
|
+
if (sawPadding || value < 0) return;
|
|
99
|
+
lastDataValue = value;
|
|
100
|
+
}
|
|
101
101
|
if (out !== void 0) {
|
|
102
102
|
out[outLen] = code;
|
|
103
103
|
outLen += 1;
|
|
@@ -109,7 +109,7 @@ function canonicalizeBase64(base64) {
|
|
|
109
109
|
if (remainder !== 0 && (sawPadding || remainder === 1)) return;
|
|
110
110
|
const effectivePadding = remainder === 0 ? padding : 4 - remainder;
|
|
111
111
|
const padBitMask = effectivePadding === 2 ? 15 : effectivePadding === 1 ? 3 : 0;
|
|
112
|
-
if (padBitMask !== 0 && (
|
|
112
|
+
if (padBitMask !== 0 && (lastDataValue & padBitMask) !== 0) return;
|
|
113
113
|
const cleaned = out === void 0 ? base64 : out.subarray(0, outLen).toString("latin1");
|
|
114
114
|
return remainder === 0 ? cleaned : cleaned + "=".repeat(4 - remainder);
|
|
115
115
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region packages/ai/src/utils/credential-redaction.d.ts
|
|
2
|
+
type DiagnosticMediaField = {
|
|
3
|
+
kind: "context";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "redacted";
|
|
6
|
+
bytes?: number;
|
|
7
|
+
source?: string | Uint8Array;
|
|
8
|
+
};
|
|
9
|
+
type DiagnosticProjectionPolicy = {
|
|
10
|
+
omitField?: (key: string) => boolean;
|
|
11
|
+
propertyScope?: "enumerable" | "error";
|
|
12
|
+
projectBinary?: (binary: Uint8Array) => unknown;
|
|
13
|
+
projectMedia?: (key: string, media: Extract<DiagnosticMediaField, {
|
|
14
|
+
kind: "redacted";
|
|
15
|
+
}>) => Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
/** Fresh records need no native-object probe while their prototype stays ordinary. */
|
|
18
|
+
declare function createDiagnosticRecord(): Record<string, unknown>;
|
|
19
|
+
declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
|
|
20
|
+
changed: boolean;
|
|
21
|
+
nodesRemaining: number;
|
|
22
|
+
}): unknown;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createDiagnosticRecord as n, projectDiagnosticValue as r, DiagnosticProjectionPolicy as t };
|