zidane 6.5.4 → 6.5.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/dist/{acp-CIpD8UIw.js → acp-Dm95NwNM.js} +6 -6
- package/dist/{acp-CIpD8UIw.js.map → acp-Dm95NwNM.js.map} +1 -1
- package/dist/acp-cli.js +6 -6
- package/dist/acp.d.ts +1 -1
- package/dist/acp.js +1 -1
- package/dist/{agent-8kfGIDb_.js → agent-CcTWL-Z6.js} +231 -167
- package/dist/agent-CcTWL-Z6.js.map +1 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/{anthropic-qaw8XAc9.js → anthropic-DLc_Kw-1.js} +420 -25
- package/dist/anthropic-DLc_Kw-1.js.map +1 -0
- package/dist/{auth-BLy7X1SY.js → auth-BAclQnl3.js} +127 -35
- package/dist/{auth-BLy7X1SY.js.map → auth-BAclQnl3.js.map} +1 -1
- package/dist/chat/pure.d.ts +3 -3
- package/dist/chat/pure.js +2 -2
- package/dist/chat.d.ts +115 -9
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +8 -8
- package/dist/{context-segments-1mcqSCM3.js → context-segments-CJCtJ9sU.js} +16 -3
- package/dist/{context-segments-1mcqSCM3.js.map → context-segments-CJCtJ9sU.js.map} +1 -1
- package/dist/{context-transport-Bco9Wo0b.js → context-transport-D8yeGdpd.js} +2 -2
- package/dist/{context-transport-Bco9Wo0b.js.map → context-transport-D8yeGdpd.js.map} +1 -1
- package/dist/contexts/daytona.d.ts +1 -1
- package/dist/contexts/daytona.js +1 -1
- package/dist/contexts/e2b.d.ts +1 -1
- package/dist/{errors-BwBxu3zD.js → errors-DKiMrOKq.js} +61 -2
- package/dist/{errors-BwBxu3zD.js.map → errors-DKiMrOKq.js.map} +1 -1
- package/dist/errors.js +2 -2
- package/dist/eval.d.ts +1 -1
- package/dist/eval.js +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +1 -1
- package/dist/{fetch-url-B7aSg6Bp.js → fetch-url-ma-5_p0p.js} +2 -2
- package/dist/{fetch-url-B7aSg6Bp.js.map → fetch-url-ma-5_p0p.js.map} +1 -1
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +3 -3
- package/dist/{index-BSNr0OQn.d.ts → index-ZWibV230.d.ts} +100 -28
- package/dist/index-ZWibV230.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -13
- package/dist/{login-D3CKhgbI.js → login-CB23LyI1.js} +3 -3
- package/dist/{login-D3CKhgbI.js.map → login-CB23LyI1.js.map} +1 -1
- package/dist/{mcp-D9fqOQo5.js → mcp-CVtSQTWg.js} +3 -3
- package/dist/{mcp-D9fqOQo5.js.map → mcp-CVtSQTWg.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/{messages-C_H9soi5.js → messages-CZMUuKzo.js} +2 -2
- package/dist/{messages-C_H9soi5.js.map → messages-CZMUuKzo.js.map} +1 -1
- package/dist/{oauth-ZebH9NHb.js → oauth-C4GvY_p1.js} +27 -8
- package/dist/oauth-C4GvY_p1.js.map +1 -0
- package/dist/{openai-compat-CnHeo4Lz.js → openai-compat-BoTi-9fd.js} +9 -4
- package/dist/openai-compat-BoTi-9fd.js.map +1 -0
- package/dist/output/stream-json.d.ts +1 -1
- package/dist/output/terminal.d.ts +1 -1
- package/dist/{plugins-2PMTVcp-.js → plugins-onDvTHEm.js} +2 -2
- package/dist/{plugins-2PMTVcp-.js.map → plugins-onDvTHEm.js.map} +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -1
- package/dist/presets.d.ts +1 -1
- package/dist/presets.js +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/arcee.d.ts +1 -1
- package/dist/providers/arcee.js +1 -1
- package/dist/providers/baseten.d.ts +1 -1
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +1 -1
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/local.d.ts +1 -1
- package/dist/providers/local.js +1 -1
- package/dist/providers/openai-compat.d.ts +1 -1
- package/dist/providers/openai-compat.js +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +4 -4
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +2 -2
- package/dist/{providers-Bxs-XHir.js → providers-CmhdtD7w.js} +3 -3
- package/dist/{providers-Bxs-XHir.js.map → providers-CmhdtD7w.js.map} +1 -1
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +4 -4
- package/dist/restate.d.ts +1 -1
- package/dist/restate.js +2 -2
- package/dist/session/sqlite.d.ts +1 -1
- package/dist/session/sqlite.js +1 -1
- package/dist/{session-VpLrNaFQ.js → session-CyRLSsVa.js} +2 -2
- package/dist/{session-VpLrNaFQ.js.map → session-CyRLSsVa.js.map} +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.js +2 -2
- package/dist/{skills-Cp9vnBwd.js → skills-BMGH_KK1.js} +2 -2
- package/dist/{skills-Cp9vnBwd.js.map → skills-BMGH_KK1.js.map} +1 -1
- package/dist/skills.d.ts +1 -1
- package/dist/skills.js +1 -1
- package/dist/{timeout-BDetbuN6.js → timeout-CjOG2mea.js} +29 -2
- package/dist/timeout-CjOG2mea.js.map +1 -0
- package/dist/timeout-DEaqslLO.d.ts.map +1 -1
- package/dist/{tool-formatters-BfKqWm5N.d.ts → tool-formatters-D3wSS2zz.d.ts} +2 -2
- package/dist/{tool-formatters-BfKqWm5N.d.ts.map → tool-formatters-D3wSS2zz.d.ts.map} +1 -1
- package/dist/tools/fetch-url.d.ts +1 -1
- package/dist/tools/fetch-url.js +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tools/web-search.js +2 -2
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +1 -1
- package/dist/{transcript-anchors-Bv8HQ3S2.js → transcript-anchors-D-Yuimif.js} +177 -63
- package/dist/transcript-anchors-D-Yuimif.js.map +1 -0
- package/dist/{transcript-anchors-CNqDbrc9.d.ts → transcript-anchors-llwMrLRG.d.ts} +2 -2
- package/dist/{transcript-anchors-CNqDbrc9.d.ts.map → transcript-anchors-llwMrLRG.d.ts.map} +1 -1
- package/dist/tui.d.ts +24 -29
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +964 -244
- package/dist/tui.js.map +1 -1
- package/dist/{turn-operations-iGu5J08j.js → turn-operations-7_Ff7INF.js} +2 -2
- package/dist/{turn-operations-iGu5J08j.js.map → turn-operations-7_Ff7INF.js.map} +1 -1
- package/dist/{turn-operations-CnIpcenJ.d.ts → turn-operations-C_XvfBU3.d.ts} +3 -3
- package/dist/{turn-operations-CnIpcenJ.d.ts.map → turn-operations-C_XvfBU3.d.ts.map} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/docs/CHAT.md +1 -1
- package/docs/TUI.md +4 -4
- package/package.json +2 -1
- package/dist/agent-8kfGIDb_.js.map +0 -1
- package/dist/anthropic-qaw8XAc9.js.map +0 -1
- package/dist/index-BSNr0OQn.d.ts.map +0 -1
- package/dist/oauth-ZebH9NHb.js.map +0 -1
- package/dist/openai-compat-CnHeo4Lz.js.map +0 -1
- package/dist/timeout-BDetbuN6.js.map +0 -1
- package/dist/transcript-anchors-Bv8HQ3S2.js.map +0 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $h as hydrateReadStateFromSessionAsync, $r as createRunSummaryCollector, Bf as installCacheBreakLogger, Ff as CacheDimensionSnapshot, Gi as AgentHookMap, Gr as RunSummaryBudget, If as CacheDriftInfo, Jh as ReadStateEntry, Ji as McpConnector, Jr as RunSummaryCollectorOptions, Ki as AgentHooks, Kr as RunSummaryByModel, Lf as diffCacheDimensions, Mf as CacheBreakLoggerOptions, Nf as CacheDimensionDiff, Pf as CacheDimensionName, Qh as hydrateReadStateFromSession, Qr as RunSummaryValidation, Rf as fnv1a32, Ur as RunSummary, Vf as snapshotCacheDimensions, Wi as Agent, Wr as RunSummaryBlock, Xh as getReadState, Xi as McpToolWrap, Xr as RunSummaryRepeatGuard, Yh as ReadStateMap, Yi as McpToolMeta, Yr as RunSummaryError, Zi as createAgent, Zr as RunSummaryTokens, eg as readStateKey, jf as CacheBreakInfo, qh as HydrateReadStateOptions, qi as AgentOptions, qr as RunSummaryCollector, tg as resolveReadStateMap, zf as hashMessages } from "./index-ZWibV230.js";
|
|
2
2
|
export { type Agent, type AgentHookMap, type AgentHooks, type AgentOptions, type CacheBreakInfo, type CacheBreakLoggerOptions, type CacheDimensionDiff, type CacheDimensionName, type CacheDimensionSnapshot, type CacheDriftInfo, type HydrateReadStateOptions, type McpConnector, type McpToolMeta, type McpToolWrap, type ReadStateEntry, type ReadStateMap, type RunSummary, type RunSummaryBlock, type RunSummaryBudget, type RunSummaryByModel, type RunSummaryCollector, type RunSummaryCollectorOptions, type RunSummaryError, type RunSummaryRepeatGuard, type RunSummaryTokens, type RunSummaryValidation, createAgent, createRunSummaryCollector, diffCacheDimensions, fnv1a32, getReadState, hashMessages, hydrateReadStateFromSession, hydrateReadStateFromSessionAsync, installCacheBreakLogger, readStateKey, resolveReadStateMap, snapshotCacheDimensions };
|
package/dist/agent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bn as hydrateReadStateFromSessionAsync, Hn as resolveReadStateMap, Ln as getReadState, Vn as readStateKey, t as createAgent, zn as hydrateReadStateFromSession } from "./agent-CcTWL-Z6.js";
|
|
2
2
|
import { a as snapshotCacheDimensions, i as installCacheBreakLogger, n as fnv1a32, r as hashMessages, t as diffCacheDimensions } from "./cache-telemetry-ehVdWsg2.js";
|
|
3
3
|
import { t as createRunSummaryCollector } from "./run-summary-BU_NgwUT.js";
|
|
4
4
|
export { createAgent, createRunSummaryCollector, diffCacheDimensions, fnv1a32, getReadState, hashMessages, hydrateReadStateFromSession, hydrateReadStateFromSessionAsync, installCacheBreakLogger, readStateKey, resolveReadStateMap, snapshotCacheDimensions };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { F as unsupportedMediaError, S as resolvePromptCacheKey, b as sanitizeToolSpecs, k as lookupModel, v as createToolNameBoundary, w as fillEstimatedCost } from "./openai-compat-
|
|
1
|
+
import { F as unsupportedMediaError, S as resolvePromptCacheKey, b as sanitizeToolSpecs, k as lookupModel, v as createToolNameBoundary, w as fillEstimatedCost } from "./openai-compat-BoTi-9fd.js";
|
|
2
2
|
import { t as lazyAsync } from "./lazy-DLOurOC_.js";
|
|
3
|
-
import { f as isRetryableHttpStatus,
|
|
3
|
+
import { f as isRetryableHttpStatus, h as matchesToolPairingError, l as classifyErrorPrelude, m as matchesContextExceeded, u as errorMessage } from "./errors-DKiMrOKq.js";
|
|
4
4
|
import { renderSystemForWire, splitSystemPrompt } from "./prompt.js";
|
|
5
|
-
import { g as toAnthropic, u as fromAnthropic } from "./messages-
|
|
6
|
-
import { a as readOAuthCredentials, r as extractRuntimeCredentials, s as resolveOAuthApiKey } from "./oauth-
|
|
5
|
+
import { g as toAnthropic, u as fromAnthropic } from "./messages-CZMUuKzo.js";
|
|
6
|
+
import { a as readOAuthCredentials, r as extractRuntimeCredentials, s as resolveOAuthApiKey } from "./oauth-C4GvY_p1.js";
|
|
7
|
+
import { Buffer } from "node:buffer";
|
|
8
|
+
import { arch, homedir, hostname, platform, userInfo } from "node:os";
|
|
9
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
7
10
|
//#region src/chat/anthropic-models.ts
|
|
8
11
|
/**
|
|
9
12
|
* Anthropic "fast mode" — `speed: "fast"` on the Messages API. ~2.5× output
|
|
@@ -123,6 +126,324 @@ const ANTHROPIC_EXTRA_MODELS = [
|
|
|
123
126
|
}
|
|
124
127
|
];
|
|
125
128
|
//#endregion
|
|
129
|
+
//#region src/providers/anthropic-claude-code.ts
|
|
130
|
+
/**
|
|
131
|
+
* Claude Code client alignment for Anthropic subscription OAuth.
|
|
132
|
+
*
|
|
133
|
+
* Anthropic's subscription endpoint serves the Claude Code CLI. Requests that
|
|
134
|
+
* do not look like that client are, at best, treated as a different product; at
|
|
135
|
+
* worst they miss features the CLI relies on. This module holds every surface
|
|
136
|
+
* that has to match, in one file, so a client bump is one edit rather than a
|
|
137
|
+
* scavenger hunt through the provider.
|
|
138
|
+
*
|
|
139
|
+
* Modelled on `@pi-plugins/claude-oauth`, which maintains the same alignment
|
|
140
|
+
* for pi and verifies its pins against a live client trace. Everything here is
|
|
141
|
+
* scoped to the OAuth path — API-key, gateway-bearer and Bedrock requests never
|
|
142
|
+
* reach it.
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Pinned Claude Code client versions.
|
|
146
|
+
*
|
|
147
|
+
* These travel together: the billing fingerprint below hashes
|
|
148
|
+
* {@link CLAUDE_CODE_VERSION}, so bumping one without the others produces a
|
|
149
|
+
* value that does not correspond to any real client. Re-check all five against
|
|
150
|
+
* the upstream plugin's `constants.ts` when bumping.
|
|
151
|
+
*/
|
|
152
|
+
const CLAUDE_CODE_VERSION = "2.1.165";
|
|
153
|
+
const CLAUDE_AGENT_SDK_VERSION = "0.3.165";
|
|
154
|
+
const CLAUDE_CLIENT_VERSION = "1.11187.4";
|
|
155
|
+
const CLAUDE_CODE_STAINLESS_PACKAGE_VERSION = "0.94.0";
|
|
156
|
+
const CLAUDE_CODE_STAINLESS_RUNTIME_VERSION = "v24.3.0";
|
|
157
|
+
/**
|
|
158
|
+
* Claude Code caps requested output at 64k even where the model ceiling is
|
|
159
|
+
* higher (Opus allows 128k). Requests above the cap are clamped to match.
|
|
160
|
+
*/
|
|
161
|
+
const CLAUDE_CODE_MAX_OUTPUT_TOKENS = 64e3;
|
|
162
|
+
/**
|
|
163
|
+
* Tool names the Claude subscription backend reserves.
|
|
164
|
+
*
|
|
165
|
+
* A tool named exactly `todowrite` is classified as a paid Claude product
|
|
166
|
+
* surface: the otherwise-valid OAuth request is refused with "You're out of
|
|
167
|
+
* extra usage" when the account has no purchased usage credits. The same body
|
|
168
|
+
* succeeds when only that wire name changes.
|
|
169
|
+
*/
|
|
170
|
+
const CLAUDE_CODE_RESERVED_TOOL_NAMES = ["todowrite"];
|
|
171
|
+
const RESERVED_TOOL_ALIAS_PREFIX = "zidane_";
|
|
172
|
+
/**
|
|
173
|
+
* Request-local wire aliases that move reserved names out of the way, for
|
|
174
|
+
* Claude subscription OAuth only.
|
|
175
|
+
*
|
|
176
|
+
* Resolved against the request's FULL name set (history + current specs) rather
|
|
177
|
+
* than hardcoded, because the obvious alias is itself a legal tool name: an
|
|
178
|
+
* extension shipping `zidane_todowrite` alongside `todowrite` would otherwise
|
|
179
|
+
* make the boundary throw on a collision it can trivially avoid. Suffixing is
|
|
180
|
+
* deterministic, so the wire bytes — and the provider prompt cache — stay
|
|
181
|
+
* stable across turns with the same tool set.
|
|
182
|
+
*
|
|
183
|
+
* Canonical names are restored at the provider boundary, so dispatch, hooks,
|
|
184
|
+
* persistence, and other auth modes never see the alias.
|
|
185
|
+
*/
|
|
186
|
+
function claudeCodeToolAliases(names) {
|
|
187
|
+
let aliases;
|
|
188
|
+
const taken = new Set(names);
|
|
189
|
+
for (const reserved of CLAUDE_CODE_RESERVED_TOOL_NAMES) {
|
|
190
|
+
if (!names.has(reserved)) continue;
|
|
191
|
+
let candidate = `${RESERVED_TOOL_ALIAS_PREFIX}${reserved}`;
|
|
192
|
+
for (let n = 2; taken.has(candidate); n++) candidate = `${RESERVED_TOOL_ALIAS_PREFIX}${reserved}_${n}`;
|
|
193
|
+
taken.add(candidate);
|
|
194
|
+
aliases ??= {};
|
|
195
|
+
aliases[reserved] = candidate;
|
|
196
|
+
}
|
|
197
|
+
return aliases;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Beta set the Claude Code agent sends, in client order.
|
|
201
|
+
*
|
|
202
|
+
* Sent as one unit: the endpoint is configured for this combination, and
|
|
203
|
+
* trimming it to "the ones we think we use" is how a client stops looking like
|
|
204
|
+
* the client. Betas without matching request fields are inert.
|
|
205
|
+
*/
|
|
206
|
+
const CLAUDE_CODE_BETAS = [
|
|
207
|
+
"claude-code-20250219",
|
|
208
|
+
"oauth-2025-04-20",
|
|
209
|
+
"interleaved-thinking-2025-05-14",
|
|
210
|
+
"fine-grained-tool-streaming-2025-05-14",
|
|
211
|
+
"context-management-2025-06-27",
|
|
212
|
+
"prompt-caching-scope-2026-01-05",
|
|
213
|
+
"mid-conversation-system-2026-04-07",
|
|
214
|
+
"advanced-tool-use-2025-11-20",
|
|
215
|
+
"effort-2025-11-24",
|
|
216
|
+
"extended-cache-ttl-2025-04-11"
|
|
217
|
+
];
|
|
218
|
+
/** Billing-header pins. See {@link claudeCodeBillingText}. */
|
|
219
|
+
const BILLING_FINGERPRINT_SALT = "59cf53e54c78";
|
|
220
|
+
const BILLING_FINGERPRINT_INDICES = [
|
|
221
|
+
4,
|
|
222
|
+
7,
|
|
223
|
+
20
|
|
224
|
+
];
|
|
225
|
+
const BILLING_HEADER_PREFIX = "x-anthropic-billing-header:";
|
|
226
|
+
const CCH_PLACEHOLDER = "cch=00000";
|
|
227
|
+
const CCH_SEED = 5577024349156291176n;
|
|
228
|
+
/** `os.arch()` values mapped to the labels Stainless emits. */
|
|
229
|
+
function stainlessArch(value) {
|
|
230
|
+
switch (value.toLowerCase()) {
|
|
231
|
+
case "amd64":
|
|
232
|
+
case "x64": return "x64";
|
|
233
|
+
case "arm64":
|
|
234
|
+
case "aarch64": return "arm64";
|
|
235
|
+
case "386":
|
|
236
|
+
case "x86":
|
|
237
|
+
case "ia32": return "x86";
|
|
238
|
+
default: return `other::${value.toLowerCase()}`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** `os.platform()` values mapped to the labels Stainless emits. */
|
|
242
|
+
function stainlessOs(value) {
|
|
243
|
+
switch (value.toLowerCase()) {
|
|
244
|
+
case "darwin": return "MacOS";
|
|
245
|
+
case "win32":
|
|
246
|
+
case "windows": return "Windows";
|
|
247
|
+
case "linux": return "Linux";
|
|
248
|
+
case "freebsd": return "FreeBSD";
|
|
249
|
+
default: return `Other::${value.toLowerCase()}`;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Headers a Claude Code OAuth request carries.
|
|
254
|
+
*
|
|
255
|
+
* The `x-stainless-*` entries deliberately OVERRIDE the ones the Anthropic SDK
|
|
256
|
+
* generates about itself: left alone they advertise `Anthropic/JS <sdk version>`
|
|
257
|
+
* on a request claiming to be the CLI, which is a contradiction no real client
|
|
258
|
+
* produces.
|
|
259
|
+
*/
|
|
260
|
+
function buildClaudeCodeHeaders() {
|
|
261
|
+
return {
|
|
262
|
+
"user-agent": `claude-cli/${CLAUDE_CODE_VERSION} (external, local-agent, agent-sdk/${CLAUDE_AGENT_SDK_VERSION})`,
|
|
263
|
+
"x-app": "cli",
|
|
264
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
265
|
+
"x-stainless-retry-count": "0",
|
|
266
|
+
"x-stainless-runtime-version": CLAUDE_CODE_STAINLESS_RUNTIME_VERSION,
|
|
267
|
+
"x-stainless-package-version": CLAUDE_CODE_STAINLESS_PACKAGE_VERSION,
|
|
268
|
+
"x-stainless-runtime": "node",
|
|
269
|
+
"x-stainless-lang": "js",
|
|
270
|
+
"x-stainless-arch": stainlessArch(arch()),
|
|
271
|
+
"x-stainless-os": stainlessOs(platform()),
|
|
272
|
+
"x-stainless-timeout": "900",
|
|
273
|
+
"anthropic-client-platform": "desktop_app",
|
|
274
|
+
"anthropic-client-version": CLAUDE_CLIENT_VERSION
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Text of the `system[0]` billing block.
|
|
279
|
+
*
|
|
280
|
+
* The version suffix is `sha256(salt + msg[4] + msg[7] + msg[20] + version)`
|
|
281
|
+
* truncated to 3 hex chars, where the indices sample the first user message.
|
|
282
|
+
* Missing characters (a first message shorter than 21 chars) contribute `'0'`,
|
|
283
|
+
* matching the client rather than throwing.
|
|
284
|
+
*
|
|
285
|
+
* The `cch` field ships as {@link CCH_PLACEHOLDER} and is overwritten by
|
|
286
|
+
* {@link patchCch} once the body is serialized — it hashes those very bytes, so
|
|
287
|
+
* it cannot be computed here.
|
|
288
|
+
*/
|
|
289
|
+
function claudeCodeBillingText(firstUserMessage) {
|
|
290
|
+
const seed = BILLING_FINGERPRINT_INDICES.map((i) => firstUserMessage[i] ?? "0").join("");
|
|
291
|
+
const suffix = createHash("sha256").update(`${BILLING_FINGERPRINT_SALT}${seed}${CLAUDE_CODE_VERSION}`).digest("hex").slice(0, 3);
|
|
292
|
+
return `${BILLING_HEADER_PREFIX} cc_version=${CLAUDE_CODE_VERSION}.${suffix}; cc_entrypoint=local-agent; ${CCH_PLACEHOLDER};`;
|
|
293
|
+
}
|
|
294
|
+
/** Concatenated text of the first user message — the fingerprint's sample source. */
|
|
295
|
+
function firstUserMessageText(messages) {
|
|
296
|
+
const content = messages.find((m) => m.role === "user")?.content;
|
|
297
|
+
if (typeof content === "string") return content;
|
|
298
|
+
if (!Array.isArray(content)) return "";
|
|
299
|
+
return content.filter((b) => !!b && typeof b === "object" && b.type === "text" && typeof b.text === "string").map((b) => b.text).join("");
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Machine-stable device id + per-process session id, sent as
|
|
303
|
+
* `metadata.user_id`'s JSON envelope.
|
|
304
|
+
*
|
|
305
|
+
* `userInfo()` throws in locked-down sandboxes, so the seed degrades to the
|
|
306
|
+
* hostname rather than taking the process down.
|
|
307
|
+
*/
|
|
308
|
+
function machineSeed() {
|
|
309
|
+
try {
|
|
310
|
+
return `${hostname()}:${userInfo().username}:${homedir()}`;
|
|
311
|
+
} catch {
|
|
312
|
+
return `${hostname()}:zidane-claude-code-fallback`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const DEVICE_ID = createHash("sha256").update(`zidane-claude-code-device-v1:${machineSeed()}`).digest("hex");
|
|
316
|
+
const SESSION_ID = randomUUID();
|
|
317
|
+
/** The `metadata.user_id` envelope Claude Code sends. */
|
|
318
|
+
function claudeCodeUserId() {
|
|
319
|
+
return JSON.stringify({
|
|
320
|
+
device_id: DEVICE_ID,
|
|
321
|
+
session_id: SESSION_ID
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const MASK = (1n << 64n) - 1n;
|
|
325
|
+
const PRIME64_1 = 11400714785074694791n;
|
|
326
|
+
const PRIME64_2 = 14029467366897019727n;
|
|
327
|
+
const PRIME64_3 = 1609587929392839161n;
|
|
328
|
+
const PRIME64_4 = 9650029242287828579n;
|
|
329
|
+
const PRIME64_5 = 2870177450012600261n;
|
|
330
|
+
const rotl = (x, r) => (x << r | x >> 64n - r) & MASK;
|
|
331
|
+
function round(acc, input) {
|
|
332
|
+
const next = acc + input * PRIME64_2 & MASK;
|
|
333
|
+
return rotl(next, 31n) * PRIME64_1 & MASK;
|
|
334
|
+
}
|
|
335
|
+
function mergeRound(acc, val) {
|
|
336
|
+
return ((acc ^ round(0n, val)) * PRIME64_1 & MASK) + PRIME64_4 & MASK;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* XXH64, reproducing Claude Code's `cch` request-integrity value.
|
|
340
|
+
*
|
|
341
|
+
* Ported rather than delegated to `Bun.hash.xxHash64` so the result cannot
|
|
342
|
+
* drift with a runtime's hash implementation or seed handling, and so the
|
|
343
|
+
* provider still works off-Bun. Verified against published XXH64 vectors.
|
|
344
|
+
*/
|
|
345
|
+
function xxHash64(input, seed) {
|
|
346
|
+
const len = input.length;
|
|
347
|
+
const dv = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
348
|
+
let h64;
|
|
349
|
+
let p = 0;
|
|
350
|
+
if (len >= 32) {
|
|
351
|
+
let v1 = seed + PRIME64_1 + PRIME64_2 & MASK;
|
|
352
|
+
let v2 = seed + PRIME64_2 & MASK;
|
|
353
|
+
let v3 = seed & MASK;
|
|
354
|
+
let v4 = seed - PRIME64_1 & MASK;
|
|
355
|
+
const limit = len - 32;
|
|
356
|
+
while (p <= limit) {
|
|
357
|
+
v1 = round(v1, dv.getBigUint64(p, true));
|
|
358
|
+
p += 8;
|
|
359
|
+
v2 = round(v2, dv.getBigUint64(p, true));
|
|
360
|
+
p += 8;
|
|
361
|
+
v3 = round(v3, dv.getBigUint64(p, true));
|
|
362
|
+
p += 8;
|
|
363
|
+
v4 = round(v4, dv.getBigUint64(p, true));
|
|
364
|
+
p += 8;
|
|
365
|
+
}
|
|
366
|
+
h64 = rotl(v1, 1n) + rotl(v2, 7n) + rotl(v3, 12n) + rotl(v4, 18n) & MASK;
|
|
367
|
+
h64 = mergeRound(h64, v1);
|
|
368
|
+
h64 = mergeRound(h64, v2);
|
|
369
|
+
h64 = mergeRound(h64, v3);
|
|
370
|
+
h64 = mergeRound(h64, v4);
|
|
371
|
+
} else h64 = seed + PRIME64_5 & MASK;
|
|
372
|
+
h64 = h64 + BigInt(len) & MASK;
|
|
373
|
+
while (p + 8 <= len) {
|
|
374
|
+
h64 ^= round(0n, dv.getBigUint64(p, true));
|
|
375
|
+
h64 = rotl(h64, 27n) * PRIME64_1 & MASK;
|
|
376
|
+
h64 = h64 + PRIME64_4 & MASK;
|
|
377
|
+
p += 8;
|
|
378
|
+
}
|
|
379
|
+
if (p + 4 <= len) {
|
|
380
|
+
h64 ^= BigInt(dv.getUint32(p, true)) * PRIME64_1 & MASK;
|
|
381
|
+
h64 = rotl(h64, 23n) * PRIME64_2 & MASK;
|
|
382
|
+
h64 = h64 + PRIME64_3 & MASK;
|
|
383
|
+
p += 4;
|
|
384
|
+
}
|
|
385
|
+
while (p < len) {
|
|
386
|
+
h64 ^= BigInt(input[p] ?? 0) * PRIME64_5 & MASK;
|
|
387
|
+
h64 = rotl(h64, 11n) * PRIME64_1 & MASK;
|
|
388
|
+
p += 1;
|
|
389
|
+
}
|
|
390
|
+
h64 ^= h64 >> 33n;
|
|
391
|
+
h64 = h64 * PRIME64_2 & MASK;
|
|
392
|
+
h64 ^= h64 >> 29n;
|
|
393
|
+
h64 = h64 * PRIME64_3 & MASK;
|
|
394
|
+
h64 ^= h64 >> 32n;
|
|
395
|
+
return h64 & MASK;
|
|
396
|
+
}
|
|
397
|
+
const encoder = new TextEncoder();
|
|
398
|
+
/**
|
|
399
|
+
* Anchor for the placeholder search. The SDK serializes `messages` before
|
|
400
|
+
* `system`, so these bytes can only belong to the block we injected — user
|
|
401
|
+
* content that happens to contain `cch=00000` can never match.
|
|
402
|
+
*/
|
|
403
|
+
const BILLING_SYSTEM_MARKER = encoder.encode(`"system":[{"type":"text","text":"${BILLING_HEADER_PREFIX}`);
|
|
404
|
+
const CCH_PLACEHOLDER_BYTES = encoder.encode(CCH_PLACEHOLDER);
|
|
405
|
+
/** The placeholder must sit this close to the marker, else system[0] was reshaped. */
|
|
406
|
+
const CCH_SEARCH_WINDOW = 150;
|
|
407
|
+
/**
|
|
408
|
+
* Overwrite the `cch` placeholder with `XXH64(body) & 0xfffff`, in place.
|
|
409
|
+
*
|
|
410
|
+
* Returns the original bytes untouched when the placeholder is absent or not
|
|
411
|
+
* anchored to `system[0]` — a request that goes out with the placeholder intact
|
|
412
|
+
* is far better than one whose user content was corrupted by a stray patch.
|
|
413
|
+
*/
|
|
414
|
+
function patchCch(encoded) {
|
|
415
|
+
const view = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);
|
|
416
|
+
const markerIdx = view.indexOf(BILLING_SYSTEM_MARKER);
|
|
417
|
+
if (markerIdx === -1) return encoded;
|
|
418
|
+
const searchFrom = markerIdx + BILLING_SYSTEM_MARKER.length;
|
|
419
|
+
const placeholderIdx = view.indexOf(CCH_PLACEHOLDER_BYTES, searchFrom);
|
|
420
|
+
if (placeholderIdx === -1 || placeholderIdx - searchFrom > CCH_SEARCH_WINDOW) return encoded;
|
|
421
|
+
const cch = (xxHash64(encoded, CCH_SEED) & 1048575n).toString(16).padStart(5, "0");
|
|
422
|
+
for (let i = 0; i < 5; i++) encoded[placeholderIdx + 4 + i] = cch.charCodeAt(i);
|
|
423
|
+
return encoded;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Wrap a `fetch` so bodies carrying the placeholder get their attestation
|
|
427
|
+
* patched after serialization.
|
|
428
|
+
*
|
|
429
|
+
* Handed to the Anthropic SDK per client rather than installed on
|
|
430
|
+
* `globalThis` — every other request in the process stays untouched, and two
|
|
431
|
+
* providers cannot fight over the global.
|
|
432
|
+
*/
|
|
433
|
+
function wrapFetchForCch(base) {
|
|
434
|
+
const wrapped = (input, init) => {
|
|
435
|
+
const body = init?.body;
|
|
436
|
+
let finalBody = body;
|
|
437
|
+
if (typeof body === "string" && body.includes("cch=00000")) finalBody = patchCch(encoder.encode(body));
|
|
438
|
+
return base(input, finalBody === body ? init : {
|
|
439
|
+
...init,
|
|
440
|
+
body: finalBody
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
wrapped.preconnect = base.preconnect?.bind(base) ?? (() => {});
|
|
444
|
+
return wrapped;
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
126
447
|
//#region src/providers/anthropic.ts
|
|
127
448
|
const loadAnthropicSdk = lazyAsync(async () => {
|
|
128
449
|
try {
|
|
@@ -156,8 +477,15 @@ function normalizeBedrock(value) {
|
|
|
156
477
|
if (!value) return void 0;
|
|
157
478
|
return value === true ? {} : value;
|
|
158
479
|
}
|
|
159
|
-
/**
|
|
160
|
-
|
|
480
|
+
/**
|
|
481
|
+
* Beta flags sent unconditionally on the OAuth path (Claude Code parity).
|
|
482
|
+
*
|
|
483
|
+
* The full client set, sent as one unit — see `CLAUDE_CODE_BETAS`. Betas whose
|
|
484
|
+
* request fields we never populate are inert, so the cost of matching the
|
|
485
|
+
* client exactly is nil while the cost of guessing a subset is looking like a
|
|
486
|
+
* different client.
|
|
487
|
+
*/
|
|
488
|
+
const OAUTH_DEFAULT_BETAS = CLAUDE_CODE_BETAS;
|
|
161
489
|
/**
|
|
162
490
|
* Beta flag that enables the `speed: "fast"` request field (fast mode — up to
|
|
163
491
|
* 2.5× output tokens/sec at premium pricing; supported models are enumerated
|
|
@@ -170,7 +498,18 @@ const OAUTH_DEFAULT_BETAS = ["claude-code-20250219", "oauth-2025-04-20"];
|
|
|
170
498
|
const FAST_MODE_BETA = "fast-mode-2026-02-01";
|
|
171
499
|
const API_KEY_RESERVED_EXTRA_HEADER_NAMES = /* @__PURE__ */ new Set(["anthropic-beta"]);
|
|
172
500
|
const OAUTH_RESERVED_EXTRA_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
501
|
+
"accept",
|
|
173
502
|
"anthropic-beta",
|
|
503
|
+
"anthropic-client-platform",
|
|
504
|
+
"anthropic-client-version",
|
|
505
|
+
"x-stainless-arch",
|
|
506
|
+
"x-stainless-lang",
|
|
507
|
+
"x-stainless-os",
|
|
508
|
+
"x-stainless-package-version",
|
|
509
|
+
"x-stainless-retry-count",
|
|
510
|
+
"x-stainless-runtime",
|
|
511
|
+
"x-stainless-runtime-version",
|
|
512
|
+
"x-stainless-timeout",
|
|
174
513
|
"anthropic-dangerous-direct-browser-access",
|
|
175
514
|
"user-agent",
|
|
176
515
|
"x-app"
|
|
@@ -280,9 +619,8 @@ function buildAnthropicClientOptions(apiKey, auth, baseURL, extraBetas, extraHea
|
|
|
280
619
|
if (auth.claudeCode) {
|
|
281
620
|
const defaultHeaders = {
|
|
282
621
|
...filterReservedExtraHeaders(extraHeaders, OAUTH_RESERVED_EXTRA_HEADER_NAMES),
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
"x-app": "cli"
|
|
622
|
+
accept: "application/json",
|
|
623
|
+
...buildClaudeCodeHeaders()
|
|
286
624
|
};
|
|
287
625
|
if (betaHeader) defaultHeaders["anthropic-beta"] = betaHeader;
|
|
288
626
|
return {
|
|
@@ -290,6 +628,7 @@ function buildAnthropicClientOptions(apiKey, auth, baseURL, extraBetas, extraHea
|
|
|
290
628
|
authToken: apiKey,
|
|
291
629
|
dangerouslyAllowBrowser: true,
|
|
292
630
|
defaultHeaders,
|
|
631
|
+
fetch: wrapFetchForCch(globalThis.fetch),
|
|
293
632
|
...base
|
|
294
633
|
};
|
|
295
634
|
}
|
|
@@ -711,6 +1050,12 @@ function classifyAnthropicError(err) {
|
|
|
711
1050
|
...retryable !== void 0 ? { retryable } : {}
|
|
712
1051
|
};
|
|
713
1052
|
}
|
|
1053
|
+
/** True only for a provider authentication rejection eligible for one OAuth refresh retry. */
|
|
1054
|
+
function isAnthropicAuthenticationError(err) {
|
|
1055
|
+
if (!err || typeof err !== "object") return false;
|
|
1056
|
+
const candidate = err;
|
|
1057
|
+
return candidate.status === 401 || candidate.error?.type === "authentication_error" || candidate.error?.error?.type === "authentication_error";
|
|
1058
|
+
}
|
|
714
1059
|
function shouldFallbackFromFastMode(err) {
|
|
715
1060
|
const classified = classifyAnthropicError(err);
|
|
716
1061
|
if (classified?.kind === "provider_error" && classified.retryable === true) return true;
|
|
@@ -1063,7 +1408,7 @@ function anthropic(anthropicParams) {
|
|
|
1063
1408
|
...payload.messages
|
|
1064
1409
|
] : [...payload.messages];
|
|
1065
1410
|
const countTools = payload.tools;
|
|
1066
|
-
const countBoundary = createToolNameBoundary(messages, countTools.map((t) => t.name));
|
|
1411
|
+
const countBoundary = createToolNameBoundary(messages, countTools.map((t) => t.name), callIsOAuth ? claudeCodeToolAliases : void 0);
|
|
1067
1412
|
return (await client.messages.countTokens({
|
|
1068
1413
|
model: payload.model,
|
|
1069
1414
|
system,
|
|
@@ -1080,9 +1425,9 @@ function anthropic(anthropicParams) {
|
|
|
1080
1425
|
},
|
|
1081
1426
|
async stream(options, callbacks) {
|
|
1082
1427
|
let apiKey = "";
|
|
1083
|
-
|
|
1428
|
+
const resolveCallApiKey = async (forceRefresh = false, rejectedAccess) => {
|
|
1084
1429
|
const identity = credentialIdentity(anthropicParams);
|
|
1085
|
-
|
|
1430
|
+
return await resolveOAuthApiKey({
|
|
1086
1431
|
provider: identity.providerId,
|
|
1087
1432
|
providerId: identity.providerId,
|
|
1088
1433
|
params: runtimeCredentials ? {
|
|
@@ -1091,7 +1436,9 @@ function anthropic(anthropicParams) {
|
|
|
1091
1436
|
} : anthropicParams,
|
|
1092
1437
|
envKey: identity.envKey,
|
|
1093
1438
|
missingError: identity.missingError,
|
|
1094
|
-
refreshError: identity.refreshError
|
|
1439
|
+
refreshError: identity.refreshError,
|
|
1440
|
+
forceRefresh,
|
|
1441
|
+
rejectedAccess
|
|
1095
1442
|
}, {
|
|
1096
1443
|
...callbacks,
|
|
1097
1444
|
async onOAuthRefresh(ctx) {
|
|
@@ -1103,14 +1450,34 @@ function anthropic(anthropicParams) {
|
|
|
1103
1450
|
await callbacks.onOAuthRefresh?.(ctx);
|
|
1104
1451
|
}
|
|
1105
1452
|
});
|
|
1106
|
-
}
|
|
1453
|
+
};
|
|
1454
|
+
if (!bedrockConfig) apiKey = await resolveCallApiKey();
|
|
1107
1455
|
const callAuth = resolveAnthropicAuthShape(apiKey, bedrockConfig ? "api-key" : anthropicParams?.authMode);
|
|
1108
1456
|
const callIsOAuth = callAuth.claudeCode;
|
|
1109
|
-
|
|
1110
|
-
|
|
1457
|
+
/**
|
|
1458
|
+
* Whether a provider auth rejection on this call is worth ATTEMPTING one
|
|
1459
|
+
* forced credential rotation. A bearer-authenticated call MAY resolve its
|
|
1460
|
+
* token through the refreshable OAuth store — subscription OAuth and
|
|
1461
|
+
* `authMode: 'bearer'` gateways (`extensions/bolt`) both do — so a 401
|
|
1462
|
+
* arriving before the local expiry is recoverable for them. Deliberately
|
|
1463
|
+
* WIDER than {@link callIsOAuth}, which additionally means "wear the
|
|
1464
|
+
* Claude Code persona"; a gateway is not Claude Code but its token still
|
|
1465
|
+
* rotates.
|
|
1466
|
+
*
|
|
1467
|
+
* The ones that cannot rotate stop at the identical-credential guard in
|
|
1468
|
+
* the recovery below rather than being excluded here: a static bearer
|
|
1469
|
+
* token supplied as `apiKey` short-circuits `resolveOAuthApiKey` and never
|
|
1470
|
+
* reaches the store, so the re-resolve returns the same value and costs
|
|
1471
|
+
* nothing but a function call. API-key and Bedrock calls never get that
|
|
1472
|
+
* far — `callAuth.bearer` is false for both.
|
|
1473
|
+
*/
|
|
1474
|
+
const callCanRotateAuth = callAuth.bearer;
|
|
1475
|
+
const effectiveCacheTtl = options.cacheTtl ?? (callIsOAuth ? "1h" : void 0);
|
|
1476
|
+
const extendedTtl = options.cache !== false && effectiveCacheTtl === "1h" && !bedrockConfig;
|
|
1477
|
+
const conditionalBetas = [...options.modelOptions?.fast && !callIsOAuth ? [FAST_MODE_BETA] : [], ...extendedTtl ? [EXTENDED_CACHE_TTL_BETA] : []];
|
|
1111
1478
|
const requestBetas = conditionalBetas.length > 0 ? [...anthropicParams?.extraBetas ?? [], ...conditionalBetas] : anthropicParams?.extraBetas;
|
|
1112
1479
|
const resolvedExtraHeaders = await resolveExtraHeaders(anthropicParams?.extraHeaders);
|
|
1113
|
-
|
|
1480
|
+
let client = bedrockConfig ? await createBedrockClient(bedrockConfig, anthropicParams, resolvedExtraHeaders) : createClient(await loadAnthropicSdk(), apiKey, callAuth, anthropicParams?.baseURL, requestBetas, resolvedExtraHeaders);
|
|
1114
1481
|
const wireSystem = renderSystemForWire(options.system);
|
|
1115
1482
|
const system = callIsOAuth ? `You are Claude Code, Anthropic's official CLI for Claude.` : wireSystem;
|
|
1116
1483
|
const messages = callIsOAuth && options.system ? [
|
|
@@ -1132,7 +1499,7 @@ function anthropic(anthropicParams) {
|
|
|
1132
1499
|
] : [...options.messages];
|
|
1133
1500
|
const thinking = options.thinking ?? "off";
|
|
1134
1501
|
const inputTools = options.tools ?? [];
|
|
1135
|
-
const nameBoundary = createToolNameBoundary(messages, inputTools.map((t) => t.name));
|
|
1502
|
+
const nameBoundary = createToolNameBoundary(messages, inputTools.map((t) => t.name), callIsOAuth ? claudeCodeToolAliases : void 0);
|
|
1136
1503
|
const wireTools = nameBoundary.changed ? inputTools.map((t) => t.name === nameBoundary.toWire(t.name) ? t : {
|
|
1137
1504
|
...t,
|
|
1138
1505
|
name: nameBoundary.toWire(t.name)
|
|
@@ -1149,7 +1516,7 @@ function anthropic(anthropicParams) {
|
|
|
1149
1516
|
stream: true
|
|
1150
1517
|
};
|
|
1151
1518
|
if (anthropicParams?.contextManagement && !bedrockConfig) params.context_management = anthropicParams.contextManagement;
|
|
1152
|
-
if (options.cache !== false) applyAnthropicCacheBreakpoints(params, callIsOAuth ? void 0 : options.system, extendedTtl ?
|
|
1519
|
+
if (options.cache !== false) applyAnthropicCacheBreakpoints(params, callIsOAuth ? void 0 : options.system, extendedTtl ? effectiveCacheTtl : void 0);
|
|
1153
1520
|
const plan = planAnthropicThinking(thinking, options.thinkingBudget, options.taskBudget, options.effortHint !== false);
|
|
1154
1521
|
if (plan && bedrockConfig) {
|
|
1155
1522
|
const budget = plan.kind === "enabled" ? plan.budgetTokens : BEDROCK_THINKING_BUDGETS[plan.effort ?? "medium"];
|
|
@@ -1191,6 +1558,17 @@ function anthropic(anthropicParams) {
|
|
|
1191
1558
|
params.temperature = 1;
|
|
1192
1559
|
}
|
|
1193
1560
|
params.max_tokens = Math.min(params.max_tokens, modelMaxOutput);
|
|
1561
|
+
if (callIsOAuth) {
|
|
1562
|
+
params.max_tokens = Math.min(params.max_tokens, CLAUDE_CODE_MAX_OUTPUT_TOKENS);
|
|
1563
|
+
if (Array.isArray(params.system)) params.system = [{
|
|
1564
|
+
type: "text",
|
|
1565
|
+
text: claudeCodeBillingText(firstUserMessageText(params.messages))
|
|
1566
|
+
}, ...params.system];
|
|
1567
|
+
if (typeof params.metadata?.user_id !== "string") params.metadata = {
|
|
1568
|
+
...params.metadata,
|
|
1569
|
+
user_id: claudeCodeUserId()
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1194
1572
|
if (params.thinking?.type === "enabled" && params.thinking.budget_tokens >= params.max_tokens) {
|
|
1195
1573
|
const fitted = params.max_tokens - THINKING_RESPONSE_RESERVE_TOKENS;
|
|
1196
1574
|
if (fitted >= 1024) params.thinking.budget_tokens = fitted;
|
|
@@ -1199,7 +1577,7 @@ function anthropic(anthropicParams) {
|
|
|
1199
1577
|
delete params.temperature;
|
|
1200
1578
|
}
|
|
1201
1579
|
}
|
|
1202
|
-
if (options.modelOptions?.fast) params.speed = "fast";
|
|
1580
|
+
if (options.modelOptions?.fast && !callIsOAuth) params.speed = "fast";
|
|
1203
1581
|
if (options.toolChoice) if (options.toolChoice.type === "tool" && options.toolChoice.name) params.tool_choice = {
|
|
1204
1582
|
type: "tool",
|
|
1205
1583
|
name: nameBoundary.toWire(options.toolChoice.name)
|
|
@@ -1217,7 +1595,7 @@ function anthropic(anthropicParams) {
|
|
|
1217
1595
|
};
|
|
1218
1596
|
const affinityHeaderName = anthropicParams?.promptCacheKeyHeader?.toLowerCase();
|
|
1219
1597
|
const affinityHeader = anthropicParams?.promptCacheKeyHeader !== void 0 && promptCacheKey !== void 0 && !Object.keys(resolvedExtraHeaders ?? {}).some((k) => k.toLowerCase() === affinityHeaderName) ? { [anthropicParams.promptCacheKeyHeader]: promptCacheKey } : void 0;
|
|
1220
|
-
const runStream = async (requestParams, fastRequested, scrubPass = 0) => {
|
|
1598
|
+
const runStream = async (requestParams, fastRequested, scrubPass = 0, authPass = 0) => {
|
|
1221
1599
|
const s = client.messages.stream(requestParams, {
|
|
1222
1600
|
signal: options.signal,
|
|
1223
1601
|
...affinityHeader ? { headers: affinityHeader } : {}
|
|
@@ -1270,13 +1648,30 @@ function anthropic(anthropicParams) {
|
|
|
1270
1648
|
return await runStream({
|
|
1271
1649
|
...requestParams,
|
|
1272
1650
|
messages: scrubbed.messages
|
|
1273
|
-
}, fastRequested, scrubPass + 1);
|
|
1651
|
+
}, fastRequested, scrubPass + 1, authPass);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
if (callCanRotateAuth && authPass === 0 && !observedOutput && isAnthropicAuthenticationError(err)) {
|
|
1655
|
+
const rejectedAccess = apiKey;
|
|
1656
|
+
let refreshedApiKey;
|
|
1657
|
+
try {
|
|
1658
|
+
refreshedApiKey = await resolveCallApiKey(true, rejectedAccess);
|
|
1659
|
+
} catch (refreshErr) {
|
|
1660
|
+
if (err !== null && typeof err === "object" && err.cause === void 0) try {
|
|
1661
|
+
err.cause = refreshErr;
|
|
1662
|
+
} catch {}
|
|
1663
|
+
if (process.env.ZIDANE_DEBUG) process.stderr.write(`[zidane/anthropic] forced OAuth refresh after 401 failed: ${errorMessage(refreshErr)}\n`);
|
|
1664
|
+
throw err;
|
|
1274
1665
|
}
|
|
1666
|
+
if (refreshedApiKey === rejectedAccess) throw err;
|
|
1667
|
+
apiKey = refreshedApiKey;
|
|
1668
|
+
client = createClient(await loadAnthropicSdk(), apiKey, callAuth, anthropicParams?.baseURL, requestBetas, resolvedExtraHeaders);
|
|
1669
|
+
return await runStream(requestParams, fastRequested, scrubPass, authPass + 1);
|
|
1275
1670
|
}
|
|
1276
1671
|
if (fastRequested && !observedOutput && shouldFallbackFromFastMode(err)) {
|
|
1277
1672
|
const standardParams = { ...requestParams };
|
|
1278
1673
|
delete standardParams.speed;
|
|
1279
|
-
return await runStream(standardParams, false);
|
|
1674
|
+
return await runStream(standardParams, false, scrubPass, authPass);
|
|
1280
1675
|
}
|
|
1281
1676
|
throw err;
|
|
1282
1677
|
}
|
|
@@ -1312,11 +1707,11 @@ function anthropic(anthropicParams) {
|
|
|
1312
1707
|
usage
|
|
1313
1708
|
};
|
|
1314
1709
|
};
|
|
1315
|
-
return await runStream(params, options.modelOptions?.fast === true);
|
|
1710
|
+
return await runStream(params, options.modelOptions?.fast === true && !callIsOAuth);
|
|
1316
1711
|
}
|
|
1317
1712
|
};
|
|
1318
1713
|
}
|
|
1319
1714
|
//#endregion
|
|
1320
1715
|
export { classifyAnthropicError as a, planAnthropicThinking as c, resolveAnthropicMaxOutput as d, ANTHROPIC_EXTRA_MODELS as f, buildAnthropicClientOptions as i, resolveAnthropicAuthShape as l, anthropic as n, credentialIdentity as o, FAST_MODE_OPTIONS as p, applyAnthropicCacheBreakpoints as r, defaultAnthropicMaxTokens as s, EXTENDED_CACHE_TTL_BETA as t, resolveAnthropicBetas as u };
|
|
1321
1716
|
|
|
1322
|
-
//# sourceMappingURL=anthropic-
|
|
1717
|
+
//# sourceMappingURL=anthropic-DLc_Kw-1.js.map
|