@openclaw/ai 2026.9.8 → 2026.10.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/{anthropic-CTXJlfnS.mjs → anthropic-CZv6XFER.mjs} +52 -147
- package/dist/{anthropic-payload-policy-NIPVYXPq.d.mts → anthropic-payload-policy-BhCcgNdm.d.mts} +7 -4
- package/dist/{anthropic-stream-reducer-DrsBCsFY.mjs → anthropic-stream-reducer-BQ1tjd7x.mjs} +369 -233
- package/dist/{api-registry-D-nbmSqr.d.mts → api-registry-DpU0Rj-I.d.mts} +4 -4
- package/dist/{provider-transcript-transform-DjA5Fk2P.mjs → assistant-output-OLm-Oln0.mjs} +17 -17
- package/dist/{assistant-text-phase-C20rxWwP.mjs → assistant-text-phase-Bl1aDCB7.mjs} +2 -8
- package/dist/{azure-openai-responses-BBxv4QVI.mjs → azure-openai-responses-DH7bd3QT.mjs} +12 -17
- package/dist/{azure-openai-responses-client-compat-C7K7QfUE.mjs → azure-openai-responses-client-compat-D0dvJMbZ.mjs} +3 -10
- package/dist/{base64-C1PsYcRQ.mjs → base64-C8CdcsjU.mjs} +3 -45
- package/dist/cloudflare-5qSGvIUH.mjs +39 -0
- package/dist/{diagnostics-CJaB6g8J.mjs → diagnostics-Caj-4RBA.mjs} +19 -37
- package/dist/diagnostics.d.mts +4 -4
- package/dist/diagnostics.mjs +2 -2
- package/dist/{event-stream-vd9UnCAU.mjs → event-stream-C5AbCAaZ.mjs} +29 -1
- package/dist/event-stream-DqDQWqiy.d.mts +1 -0
- package/dist/{event-stream-DOPFYVqs.d.mts → event-stream-DrRM_90c.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-request-facts-BTEBMeOv.mjs → github-copilot-request-facts-DEE6gcB9.mjs} +3 -1
- package/dist/{google-B3HEK0Ag.mjs → google-1WLOtb8w.mjs} +12 -9
- package/dist/{google-interactions-vMlEfPAA.mjs → google-interactions-wrnE6MLw.mjs} +39 -49
- package/dist/{google-messages-Dz2dAnGo.mjs → google-messages-BwPPycw6.mjs} +11 -17
- package/dist/{google-shared-B58i3c8H.mjs → google-shared-Eql1OMPU.mjs} +5 -6
- package/dist/{google-vertex-DYFXzEbh.mjs → google-vertex-0LrlRoO3.mjs} +11 -11
- package/dist/{host-rxlNaBwm.d.mts → host-BinBeGcQ.d.mts} +12 -4
- package/dist/{host-DwBmNMCC.mjs → host-DCW52iHe.mjs} +57 -9
- package/dist/{host-policy-wK-ay_RK.mjs → host-policy-B3jc4Rpn.mjs} +9 -2
- package/dist/{index-D6KsSE74.d.mts → index-a8e_oKnu.d.mts} +7 -5
- package/dist/index.d.mts +23 -7
- package/dist/index.mjs +7 -7
- package/dist/internal/anthropic.d.mts +6 -6
- package/dist/internal/anthropic.mjs +5 -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 +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -10
- package/dist/internal/openai.mjs +12 -12
- package/dist/internal/runtime.d.mts +18 -9
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +6 -4
- package/dist/internal/shared.mjs +6 -6
- package/dist/internal/tool-schema.mjs +1 -1
- package/dist/json-schema-Bp07Qui3.mjs +22 -0
- package/dist/{llm-request-activity-BjtkplhG.mjs → llm-request-activity-D8f_oxHj.mjs} +1 -2
- package/dist/{mistral-7wDWcjfF.mjs → mistral-DSt4vQAO.mjs} +18 -29
- package/dist/number-coercion-V8-BhME4.mjs +47 -0
- package/dist/{openai-chatgpt-responses-Bc7NZrQR.mjs → openai-chatgpt-responses-BC2x0Oqx.mjs} +215 -164
- package/dist/openai-completions-DNyHnXKg.mjs +25 -0
- package/dist/{openai-completions-compat-qJjmqQ71.d.mts → openai-completions-compat-BYdYpXhU.d.mts} +3 -3
- package/dist/{openai-completions-compat-BJf57ZxN.mjs → openai-completions-compat-BdmlhD4u.mjs} +30 -23
- package/dist/{openai-completions-stream-dju_5F3P.mjs → openai-completions-transport-DWM2mQDB.mjs} +389 -76
- package/dist/{openai-prompt-cache-CouErLh7.d.mts → openai-prompt-cache-45-AH_xv.d.mts} +2 -2
- package/dist/{openai-prompt-cache-BTMs80_O.mjs → openai-prompt-cache-I8YQTzf8.mjs} +1 -1
- package/dist/{openai-responses-compaction-replay-DiYn-gFM.d.mts → openai-responses-compaction-replay-BClApUIf.d.mts} +4 -4
- package/dist/{openai-responses-compaction-window-CYGCjAQz.mjs → openai-responses-compaction-window-m878aVpU.mjs} +25 -83
- package/dist/{openai-reasoning-effort-C_0p3psG.mjs → openai-responses-contracts-BKu8O7l4.mjs} +103 -4
- package/dist/{openai-responses-contracts-D1iZ0njF.d.mts → openai-responses-contracts-Br5IIw_h.d.mts} +16 -5
- package/dist/openai-responses-prompt-observer-internal-CCg7B6l4.mjs +32 -0
- package/dist/{openai-responses-shared-CIEHiKx7.mjs → openai-responses-shared-C7oVyjED.mjs} +297 -312
- package/dist/{openai-responses-terminal-usage-BE7lf7nW.d.mts → openai-responses-terminal-usage-DgImcyJu.d.mts} +2 -2
- package/dist/{openai-responses-DbPe3-Py.mjs → openai-responses-uZ5oWSp7.mjs} +12 -21
- package/dist/{openai-tool-schema-vsl-cE-n.mjs → openai-tool-schema-DYNePiF8.mjs} +66 -36
- package/dist/{openai-transport-params-DyFJ4cgR.mjs → openai-transport-params-JFsnIyto.mjs} +25 -30
- package/dist/openai-web-search-tools-Cfu0uLyN.mjs +14 -0
- package/dist/{positive-integer-CjN5OJbH.mjs → positive-integer-CwLi8LUL.mjs} +1 -1
- package/dist/{provider-error-CwT_j2v0.mjs → provider-error-DQBE1bUQ.mjs} +17 -28
- package/dist/{provider-options-Df7ov0K1.d.mts → provider-options-D5ABCV_l.d.mts} +2 -2
- package/dist/{provider-replay-context-Bs5aWE1d.mjs → provider-replay-context-C7Bmi84a.mjs} +6 -2
- package/dist/{provider-transport-turn-state-Dw7OtYUs.mjs → provider-transport-turn-state-_M2kLdUE.mjs} +25 -3
- package/dist/{provider-types-d4XnoZMd.d.mts → provider-types-F8Mqc9Ma.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +14 -26
- package/dist/{reasoning-tag-text-partitioner-B6FIIBt6.mjs → reasoning-tag-text-partitioner-Ju9VpUGl.mjs} +23 -37
- package/dist/required-api-key-D4kn3252.mjs +9 -0
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +5 -0
- package/dist/{session-affinity-Bcunsn4I.mjs → session-affinity-DA4WHv1h.mjs} +2 -6
- package/dist/session-resources-D1wgDQ8C.mjs +40 -0
- package/dist/{simple-options-BkDPMuxw.mjs → simple-options-BkKTXxhp.mjs} +7 -11
- package/dist/{src-H4aXcFuX.mjs → src-B0NIt2UK.mjs} +7 -4
- package/dist/stream-DSdzKsDK.mjs +275 -0
- package/dist/{stream-first-event-timeout-B9o0S4SZ.mjs → stream-first-event-timeout-D9ZmL_s9.mjs} +3 -3
- package/dist/{string-coerce-fsri9iCu.mjs → string-coerce-CtgOVOSv.mjs} +5 -1
- package/dist/{string-normalization-J9ZiLfGO.mjs → string-normalization-PN10hf6d.mjs} +1 -1
- package/dist/{transport-utils-CqXzku3R.mjs → text-signature-MLwfi6fq.mjs} +18 -18
- package/dist/{transport-stream-shared-yYhXa4kX.d.mts → transport-stream-shared-BcAKh2XH.d.mts} +6 -19
- package/dist/{transport-stream-shared-BU5pwY6W.mjs → transport-stream-shared-CxXXz_Dd.mjs} +171 -56
- package/dist/transports.d.mts +22 -23
- package/dist/transports.mjs +251 -495
- package/dist/types-BuiEBM3u.d.mts +1 -0
- package/dist/types-CQc6JNG4.mjs +69 -0
- package/dist/{types-CLLR3eB4.d.mts → types-DvzmWW8J.d.mts} +58 -6
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -5
- package/dist/usage-CJH5D6Ea.mjs +19 -0
- package/dist/{validation-Cat2wQsc.d.mts → validation-B3lQt_VE.d.mts} +1 -1
- package/dist/{validation-BFZc40Ig.mjs → validation-DbqlIfDn.mjs} +15 -30
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +4 -4
- package/dist/cache-retention-0x979a5V.mjs +0 -12
- package/dist/event-stream-CMQfX_yr.d.mts +0 -1
- package/dist/github-copilot-headers-B37TB3rB.mjs +0 -30
- package/dist/openai-completions-CHnwIV-W.mjs +0 -188
- package/dist/openai-provider-client-G8Otsq2Q.mjs +0 -24
- package/dist/openai-responses-contracts-CLxnqS9p.mjs +0 -81
- package/dist/openai-responses-prompt-observer-internal-BX3QTNSv.mjs +0 -198
- package/dist/sanitize-unicode-BZiVbGwK.d.mts +0 -24
- package/dist/session-resources-CkR4WWy1.mjs +0 -21
- package/dist/stream-DDsCBgd-.mjs +0 -68
- package/dist/types-CB-_vNyI.d.mts +0 -1
- package/dist/types-LFWwv0cF.mjs +0 -8
package/README.md
CHANGED
|
@@ -21,7 +21,10 @@ Provider ids, credentials, model catalogs, retries, and failover remain
|
|
|
21
21
|
application concerns. OpenClaw supplies those policies around this package.
|
|
22
22
|
Host policy (request fetch guarding, secret redaction, strict-tool defaults,
|
|
23
23
|
provider plugin hooks, and diagnostics logging) can be injected with
|
|
24
|
-
`configureAiTransportHost`; the defaults are inert.
|
|
24
|
+
`configureAiTransportHost`; the defaults are inert. Node callers that need
|
|
25
|
+
runtime-local policy can use `createNodeLlmRuntime`; it preserves that host across
|
|
26
|
+
provider work without replacing the process default. `createLlmRuntime` continues
|
|
27
|
+
to use the process-default host.
|
|
25
28
|
|
|
26
29
|
The explicit `@openclaw/ai/internal/anthropic`, `google-model-family`, `openai`,
|
|
27
30
|
`openai-completions-compat`, `openai-responses-payload-policy`, `retry-after`, `runtime`, `shared`, and
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import { S as supportsClaudeAdaptiveThinking, b as resolveClaudeSonnet5ModelIdentity, v as resolveClaudeOpus5ModelIdentity
|
|
3
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { D as parseJsonWithRepair, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, u as finalizeTransportStream } from "./transport-stream-shared-
|
|
9
|
-
import { n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "./simple-options-
|
|
2
|
+
import { S as supportsClaudeAdaptiveThinking, b as resolveClaudeSonnet5ModelIdentity, v as resolveClaudeOpus5ModelIdentity } from "./src-B0NIt2UK.mjs";
|
|
3
|
+
import { t as AssistantMessageEventStream } from "./event-stream-C5AbCAaZ.mjs";
|
|
4
|
+
import { S as resolveAnthropicThinkingEffort, T as usesClaudeStreamingRefusalContract, _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, b as prepareClaudeNoPrefillRequestContext, r as getAiTransportHost, x as requiresClaudeAdaptiveThinking } from "./host-DCW52iHe.mjs";
|
|
5
|
+
import { n as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./text-signature-MLwfi6fq.mjs";
|
|
6
|
+
import { C as isAnthropicReplayRejection, J as usesFoundryBearerAuth, K as isAnthropicOAuthApiKey, M as isDirectAnthropicModel, T as suppressAnthropicCompaction, l as buildAnthropicRequest, q as omitFoundryBearerCredentialHeaders, t as consumeAnthropicStream, u as prepareAnthropicRequest, z as supportsAnthropicServerSideFallback } from "./anthropic-stream-reducer-BQ1tjd7x.mjs";
|
|
7
|
+
import { i as resolveCacheRetention, n as resolveCloudflareBaseUrl, r as buildCopilotDynamicHeaders } from "./cloudflare-5qSGvIUH.mjs";
|
|
8
|
+
import { D as parseJsonWithRepair, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, u as finalizeTransportStream } from "./transport-stream-shared-CxXXz_Dd.mjs";
|
|
9
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "./simple-options-BkKTXxhp.mjs";
|
|
10
10
|
import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
|
|
11
11
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
12
|
-
import { t as
|
|
13
|
-
import {
|
|
14
|
-
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-
|
|
15
|
-
import {
|
|
12
|
+
import { t as createAssistantOutput } from "./assistant-output-OLm-Oln0.mjs";
|
|
13
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-D8f_oxHj.mjs";
|
|
14
|
+
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-DA4WHv1h.mjs";
|
|
15
|
+
import { t as requireApiKey } from "./required-api-key-D4kn3252.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
|
|
@@ -28,13 +28,9 @@ function getAnthropicCompat(model) {
|
|
|
28
28
|
const isCloudflareAiGatewayAnthropic = model.provider === "cloudflare-ai-gateway" && model.baseUrl.includes("anthropic");
|
|
29
29
|
return {
|
|
30
30
|
supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? !isFireworks,
|
|
31
|
-
sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? (isFireworks || isCloudflareAiGatewayAnthropic)
|
|
32
|
-
allowEmptySignature: model.compat?.allowEmptySignature ?? false
|
|
31
|
+
sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? (isFireworks || isCloudflareAiGatewayAnthropic)
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
|
-
function mergeHeaders(...headerSources) {
|
|
36
|
-
return Object.assign({}, ...headerSources);
|
|
37
|
-
}
|
|
38
34
|
const ANTHROPIC_MESSAGE_EVENTS = /* @__PURE__ */ new Set([
|
|
39
35
|
"message_start",
|
|
40
36
|
"message_delta",
|
|
@@ -76,36 +72,23 @@ const streamAnthropic = (model, context, options) => {
|
|
|
76
72
|
isOAuth = false;
|
|
77
73
|
} else {
|
|
78
74
|
const apiKey = requestOptions?.apiKey ?? getEnvApiKey(model.provider) ?? "";
|
|
79
|
-
|
|
80
|
-
if (model.provider === "github-copilot") {
|
|
81
|
-
const hasImages = hasCopilotVisionInput(requestContext.messages);
|
|
82
|
-
copilotDynamicHeaders = buildCopilotDynamicHeaders({
|
|
83
|
-
messages: requestContext.messages,
|
|
84
|
-
hasImages
|
|
85
|
-
});
|
|
86
|
-
}
|
|
75
|
+
const copilotDynamicHeaders = model.provider === "github-copilot" ? buildCopilotDynamicHeaders(requestContext.messages) : void 0;
|
|
87
76
|
const cacheSessionId = (requestOptions?.cacheRetention ?? resolveCacheRetention()) === "none" ? void 0 : requestOptions?.sessionId;
|
|
88
|
-
const created = createClient(model, apiKey, requestOptions?.thinkingEnabled === true, requestOptions?.interleavedThinking ?? true,
|
|
77
|
+
const created = createClient(model, apiKey, requestOptions?.thinkingEnabled === true, requestOptions?.interleavedThinking ?? true, Boolean(requestContext.tools?.length) && !getAnthropicCompat(model).supportsEagerToolInputStreaming, resolveOpencodeSessionHeaders(model, requestOptions), copilotDynamicHeaders, cacheSessionId);
|
|
89
78
|
client = created.client;
|
|
90
79
|
isOAuth = created.isOAuthToken;
|
|
91
80
|
serverSideFallback = created.serverSideFallback;
|
|
92
81
|
directApiKeyBetaHeader = created.directApiKeyBetaHeader;
|
|
93
82
|
claudeCodeVersion = created.claudeCodeVersion;
|
|
94
83
|
}
|
|
95
|
-
const builtParams = await
|
|
84
|
+
const builtParams = await buildAnthropicRequest(model, requestContext, requestOptions, "provider", isOAuth, serverSideFallback, claudeCodeVersion);
|
|
96
85
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
97
|
-
|
|
98
|
-
const toolProjection = builtParams.toolProjection;
|
|
99
|
-
applyAnthropicContextManagementToRequest(params, model, requestOptions, directApiKeyBetaHeader);
|
|
100
|
-
const nextParams = await requestOptions?.onPayload?.(params, model);
|
|
101
|
-
if (nextParams !== void 0) params = nextParams;
|
|
102
|
-
applyClaudeRequestContract(params, model);
|
|
103
|
-
const betaHeader = resolveAnthropicRequestBetaHeader(params, directApiKeyBetaHeader);
|
|
86
|
+
const { params, headers } = await prepareAnthropicRequest(builtParams.params, model, requestOptions, directApiKeyBetaHeader);
|
|
104
87
|
const sdkRequestOptions = {
|
|
105
88
|
...requestOptions?.signal ? { signal: requestOptions.signal } : {},
|
|
106
89
|
...requestOptions?.timeoutMs !== void 0 ? { timeout: requestOptions.timeoutMs } : {},
|
|
107
90
|
maxRetries: 0,
|
|
108
|
-
headers
|
|
91
|
+
headers
|
|
109
92
|
};
|
|
110
93
|
const response = await client.messages.create({
|
|
111
94
|
...params,
|
|
@@ -124,7 +107,7 @@ const streamAnthropic = (model, context, options) => {
|
|
|
124
107
|
stream,
|
|
125
108
|
refusalBuffer,
|
|
126
109
|
isOAuthToken: isOAuth,
|
|
127
|
-
toolProjection,
|
|
110
|
+
toolProjection: builtParams.toolProjection,
|
|
128
111
|
profile: "provider"
|
|
129
112
|
});
|
|
130
113
|
finalizeTransportStream({
|
|
@@ -165,8 +148,7 @@ function normalizeAnthropicThinkingOptions(model, options) {
|
|
|
165
148
|
};
|
|
166
149
|
}
|
|
167
150
|
const streamSimpleAnthropic = (model, context, options) => {
|
|
168
|
-
const apiKey =
|
|
169
|
-
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
151
|
+
const apiKey = requireApiKey(model.provider, options?.apiKey);
|
|
170
152
|
const base = {
|
|
171
153
|
...buildBaseOptions(model, options, apiKey),
|
|
172
154
|
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
@@ -182,8 +164,8 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
182
164
|
...base,
|
|
183
165
|
thinkingEnabled: false
|
|
184
166
|
});
|
|
185
|
-
const reasoning = options?.reasoning === "off" ?
|
|
186
|
-
if (resolveClaudeOpus5ModelIdentity(model) || resolveClaudeSonnet5ModelIdentity(model)) return streamAnthropic(model, context, {
|
|
167
|
+
const reasoning = options?.reasoning === "off" ? "low" : options?.reasoning;
|
|
168
|
+
if (resolveClaudeOpus5ModelIdentity(model) || resolveClaudeSonnet5ModelIdentity(model) || reasoning && supportsClaudeAdaptiveThinking(model)) return streamAnthropic(model, context, {
|
|
187
169
|
...base,
|
|
188
170
|
thinkingEnabled: true,
|
|
189
171
|
effort: resolveAnthropicThinkingEffort(model, reasoning)
|
|
@@ -192,14 +174,6 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
192
174
|
...base,
|
|
193
175
|
thinkingEnabled: mandatoryAdaptiveThinking
|
|
194
176
|
});
|
|
195
|
-
if (supportsClaudeAdaptiveThinking(model)) {
|
|
196
|
-
const effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
197
|
-
return streamAnthropic(model, context, {
|
|
198
|
-
...base,
|
|
199
|
-
thinkingEnabled: true,
|
|
200
|
-
effort
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
177
|
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens ?? base.maxTokens, reasoning, options?.thinkingBudgets);
|
|
204
178
|
const thinkingEnabled = adjusted.thinkingBudget >= ANTHROPIC_MIN_THINKING_BUDGET_TOKENS;
|
|
205
179
|
const maxTokens = thinkingEnabled ? adjusted.maxTokens : clampMaxTokensToModel(model, options?.maxTokens ?? model.maxTokens);
|
|
@@ -210,15 +184,6 @@ const streamSimpleAnthropic = (model, context, options) => {
|
|
|
210
184
|
thinkingBudgetTokens: thinkingEnabled ? adjusted.thinkingBudget : void 0
|
|
211
185
|
});
|
|
212
186
|
};
|
|
213
|
-
/**
|
|
214
|
-
* Server-side refusal fallback is a first-party Claude API beta: proxies and
|
|
215
|
-
* Bedrock/Vertex/Foundry reject the `fallbacks` param, and OAuth (Claude Code
|
|
216
|
-
* identity) requests are excluded until the beta is verified there.
|
|
217
|
-
*/
|
|
218
|
-
function supportsAnthropicServerSideFallback(model) {
|
|
219
|
-
if (!usesClaudeFable5MessagesContract(model) && resolveClaudeOpus5ModelIdentity(model) === void 0 && resolveClaudeSonnet55ModelIdentity(model) === void 0 || model.provider !== "anthropic") return false;
|
|
220
|
-
return isDirectAnthropicModel(model);
|
|
221
|
-
}
|
|
222
187
|
function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFineGrainedToolStreamingBeta, optionsHeaders, dynamicHeaders, sessionId) {
|
|
223
188
|
const needsInterleavedBeta = interleavedThinking && !supportsClaudeAdaptiveThinking(model);
|
|
224
189
|
const betaFeatures = [];
|
|
@@ -236,112 +201,52 @@ function createClient(model, apiKey, thinkingEnabled, interleavedThinking, useFi
|
|
|
236
201
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
237
202
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
238
203
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
accept: baseHeaders.accept,
|
|
247
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
248
|
-
Authorization: null,
|
|
249
|
-
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
250
|
-
}, model.headers, optionsHeaders)
|
|
251
|
-
}),
|
|
252
|
-
isOAuthToken: false,
|
|
253
|
-
serverSideFallback: false
|
|
254
|
-
};
|
|
204
|
+
let configuredApiKey = apiKey;
|
|
205
|
+
let authToken = null;
|
|
206
|
+
let defaultHeaders;
|
|
207
|
+
let isOAuthToken = false;
|
|
208
|
+
let serverSideFallback = false;
|
|
209
|
+
let directApiKeyBetaHeader;
|
|
210
|
+
let claudeCodeVersion;
|
|
255
211
|
const isCopilot = model.provider === "github-copilot";
|
|
256
|
-
if (
|
|
212
|
+
if (model.provider === "cloudflare-ai-gateway") {
|
|
213
|
+
clientOptions.baseURL = resolveCloudflareBaseUrl(model);
|
|
214
|
+
defaultHeaders = Object.assign({}, baseHeaders, { Authorization: null }, model.headers, optionsHeaders);
|
|
215
|
+
} else if (isCopilot || usesFoundryBearerAuth({
|
|
257
216
|
...model,
|
|
258
217
|
headers: resolveAiTransportHeaderSentinels(model.headers)
|
|
259
|
-
}))
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
defaultHeaders: mergeHeaders(baseHeaders, isCopilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), dynamicHeaders, optionsHeaders)
|
|
265
|
-
}),
|
|
266
|
-
isOAuthToken: false,
|
|
267
|
-
serverSideFallback: false
|
|
268
|
-
};
|
|
269
|
-
if (isAnthropicOAuthApiKey(apiKey)) {
|
|
218
|
+
})) {
|
|
219
|
+
configuredApiKey = null;
|
|
220
|
+
authToken = apiKey;
|
|
221
|
+
defaultHeaders = Object.assign({}, baseHeaders, isCopilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), dynamicHeaders, optionsHeaders);
|
|
222
|
+
} else if (isAnthropicOAuthApiKey(apiKey)) {
|
|
270
223
|
const identity = buildAnthropicClaudeCodeIdentity([
|
|
271
224
|
"claude-code-20250219",
|
|
272
225
|
"oauth-2025-04-20",
|
|
273
226
|
...betaFeatures
|
|
274
227
|
].join(","), model.headers, optionsHeaders);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
claudeCodeVersion: identity.version
|
|
285
|
-
};
|
|
228
|
+
configuredApiKey = null;
|
|
229
|
+
authToken = apiKey;
|
|
230
|
+
defaultHeaders = identity.headers;
|
|
231
|
+
isOAuthToken = true;
|
|
232
|
+
claudeCodeVersion = identity.version;
|
|
233
|
+
} else {
|
|
234
|
+
serverSideFallback = model.provider === "anthropic" && supportsAnthropicServerSideFallback(model);
|
|
235
|
+
defaultHeaders = Object.assign({}, baseHeaders, sessionId && getAnthropicCompat(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {}, model.headers, optionsHeaders);
|
|
236
|
+
if (isDirectAnthropicModel(model)) directApiKeyBetaHeader = Object.entries(defaultHeaders).findLast(([name]) => name.toLowerCase() === "anthropic-beta")?.[1] ?? "";
|
|
286
237
|
}
|
|
287
|
-
const serverSideFallback = supportsAnthropicServerSideFallback(model);
|
|
288
|
-
const defaultHeaders = mergeHeaders(baseHeaders, sessionId && getAnthropicCompat(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {}, model.headers, optionsHeaders);
|
|
289
238
|
return {
|
|
290
239
|
client: new Anthropic({
|
|
291
240
|
...clientOptions,
|
|
292
|
-
apiKey,
|
|
293
|
-
authToken
|
|
241
|
+
apiKey: configuredApiKey,
|
|
242
|
+
authToken,
|
|
294
243
|
defaultHeaders
|
|
295
244
|
}),
|
|
296
|
-
isOAuthToken
|
|
245
|
+
isOAuthToken,
|
|
297
246
|
serverSideFallback,
|
|
298
|
-
directApiKeyBetaHeader
|
|
247
|
+
directApiKeyBetaHeader,
|
|
248
|
+
claudeCodeVersion
|
|
299
249
|
};
|
|
300
250
|
}
|
|
301
|
-
async function buildParams(model, context, isOAuthTokenResult, options, serverSideFallback = false, claudeCodeVersion) {
|
|
302
|
-
const replayThinkingEnabled = requiresClaudeAdaptiveThinking(model) || options?.thinkingEnabled === true;
|
|
303
|
-
const { cacheControl, supportsCacheControlOnTools } = resolveAnthropicCacheOptions(model, options?.cacheRetention);
|
|
304
|
-
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthTokenResult, cacheControl, claudeCodeVersion);
|
|
305
|
-
const compat = getAnthropicCompat(model);
|
|
306
|
-
const convertedTools = context.tools ? convertAnthropicTools(context.tools, isOAuthTokenResult, compat.supportsEagerToolInputStreaming) : void 0;
|
|
307
|
-
const tools = convertedTools?.tools;
|
|
308
|
-
const toolProjection = convertedTools?.projection;
|
|
309
|
-
const replayPlan = buildAnthropicReplayPlan(context.messages, model, {
|
|
310
|
-
enabled: !isOAuthTokenResult && options?.anthropicServerCompaction === true,
|
|
311
|
-
authProfileId: options?.authProfileId,
|
|
312
|
-
sessionId: options?.sessionId
|
|
313
|
-
});
|
|
314
|
-
const cacheBreakpointOptOutMessageIndexes = /* @__PURE__ */ new Set();
|
|
315
|
-
const params = {
|
|
316
|
-
model: model.id,
|
|
317
|
-
messages: await convertAnthropicMessages(transformProviderMessages(replayPlan.messages, model, normalizeAnthropicToolCallId), model, isOAuthTokenResult, {
|
|
318
|
-
profile: "provider",
|
|
319
|
-
allowEmptySignature: compat.allowEmptySignature,
|
|
320
|
-
compaction: replayPlan.compaction,
|
|
321
|
-
replayThinkingEnabled,
|
|
322
|
-
cacheBreakpointOptOutMessageIndexes
|
|
323
|
-
}),
|
|
324
|
-
max_tokens: options?.maxTokens ?? model.maxTokens,
|
|
325
|
-
stream: true
|
|
326
|
-
};
|
|
327
|
-
if (system) params.system = system;
|
|
328
|
-
if (serverSideFallback) params.fallbacks = ANTHROPIC_SERVER_SIDE_FALLBACKS;
|
|
329
|
-
Object.assign(params, buildAnthropicGenerationParams({
|
|
330
|
-
model,
|
|
331
|
-
options,
|
|
332
|
-
tools,
|
|
333
|
-
toolProjection,
|
|
334
|
-
profile: "provider"
|
|
335
|
-
}));
|
|
336
|
-
applyAnthropicRequestCacheControl(params, cacheControl, supportsCacheControlOnTools, cacheBreakpointOptOutMessageIndexes);
|
|
337
|
-
return {
|
|
338
|
-
params,
|
|
339
|
-
toolProjection,
|
|
340
|
-
usedCompactionReplay: replayPlan.compaction !== void 0
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function shouldUseFineGrainedToolStreamingBeta(model, context) {
|
|
344
|
-
return Boolean(context.tools?.length) && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
345
|
-
}
|
|
346
251
|
//#endregion
|
|
347
252
|
export { streamAnthropic as n, streamSimpleAnthropic as r, anthropic_exports as t };
|
package/dist/{anthropic-payload-policy-NIPVYXPq.d.mts → anthropic-payload-policy-BhCcgNdm.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { t as AnthropicContextManagementOptions } from "./provider-options-
|
|
1
|
+
import "./index-a8e_oKnu.mjs";
|
|
2
|
+
import { k as Model } from "./types-DvzmWW8J.mjs";
|
|
3
|
+
import { t as AnthropicContextManagementOptions } from "./provider-options-D5ABCV_l.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. */
|
|
@@ -48,7 +48,10 @@ declare function resolveAnthropicServerCompactionPlan(model: {
|
|
|
48
48
|
declare function isDirectAnthropicModel(model: {
|
|
49
49
|
provider?: unknown;
|
|
50
50
|
baseUrl?: string;
|
|
51
|
+
}, env?: {
|
|
52
|
+
ANTHROPIC_BASE_URL?: string;
|
|
51
53
|
}): boolean;
|
|
54
|
+
declare function supportsAnthropicServerSideFallback(model: Model<"anthropic-messages">): boolean;
|
|
52
55
|
declare function isAnthropicServerToolClearingEnabled(model: {
|
|
53
56
|
provider?: unknown;
|
|
54
57
|
api?: unknown;
|
|
@@ -84,4 +87,4 @@ declare function applyAnthropicPayloadPolicyToParams(payloadObj: Record<string,
|
|
|
84
87
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
85
88
|
declare function applyAnthropicEphemeralCacheControlMarkers(payloadObj: Record<string, unknown>, cacheControl?: AnthropicEphemeralCacheControl | null): void;
|
|
86
89
|
//#endregion
|
|
87
|
-
export { buildAnthropicSystemBlocks as a, logAnthropicContextEdits as c, resolveAnthropicPayloadPolicy as d, resolveAnthropicRequestBetaHeader as f, applyAnthropicRequestCacheControl as i, resolveAnthropicCacheOptions as l, applyAnthropicEphemeralCacheControlMarkers as n, isAnthropicServerToolClearingEnabled as o, resolveAnthropicServerCompactionPlan as p, applyAnthropicPayloadPolicyToParams as r, isDirectAnthropicModel as s, applyAnthropicContextManagementToRequest as t, resolveAnthropicEphemeralCacheControl as u };
|
|
90
|
+
export { buildAnthropicSystemBlocks as a, logAnthropicContextEdits as c, resolveAnthropicPayloadPolicy as d, resolveAnthropicRequestBetaHeader as f, applyAnthropicRequestCacheControl as i, resolveAnthropicCacheOptions as l, supportsAnthropicServerSideFallback as m, applyAnthropicEphemeralCacheControlMarkers as n, isAnthropicServerToolClearingEnabled as o, resolveAnthropicServerCompactionPlan as p, applyAnthropicPayloadPolicyToParams as r, isDirectAnthropicModel as s, applyAnthropicContextManagementToRequest as t, resolveAnthropicEphemeralCacheControl as u };
|