opencode-anthropic-fix 0.5.0 → 1.0.0
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 +30 -3
- package/index.mjs +271 -184
- package/lib/betas.mjs +131 -0
- package/lib/diagnose.mjs +4 -2
- package/lib/mimicry/adapter-input.mjs +131 -29
- package/lib/mimicry/headers.mjs +143 -15
- package/lib/mimicry/request-body.mjs +51 -14
- package/lib/mimicry/system-prompt.mjs +72 -293
- package/lib/mimicry/wire-compat.mjs +148 -96
- package/lib/oauth.mjs +3 -2
- package/lib/passthrough-headers.mjs +152 -0
- package/package.json +1 -1
- package/lib/mimicry/models.mjs +0 -146
- package/lib/request-headers.mjs +0 -303
package/lib/request-headers.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure header/mimicry helpers extracted from index.mjs.
|
|
3
|
-
* No runtime state, no imports needed - all values are self-contained constants
|
|
4
|
-
* or derive from process.env at call time.
|
|
5
|
-
*
|
|
6
|
-
* Exported:
|
|
7
|
-
* - Version/build/SDK constants and CLI_TO_SDK_VERSION map
|
|
8
|
-
* - getSdkVersion(cliVersion)
|
|
9
|
-
* - EXPERIMENTAL_BETA_FLAGS (Set<string>)
|
|
10
|
-
* - BETA_SHORTCUTS (Map<string, string>)
|
|
11
|
-
* - resolveBetaShortcut(value)
|
|
12
|
-
* - buildExtendedUserAgent(version)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// Version / build / SDK constants
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
// Tracks the CLI version of the wire-compat package's DEFAULT_PROFILE (see
|
|
20
|
-
// lib/mimicry/adapter-input.mjs PROFILE_CLI_VERSION). Bump both together when
|
|
21
|
-
// the package ships a newer default profile.
|
|
22
|
-
export const FALLBACK_CLAUDE_CLI_VERSION = "2.1.233";
|
|
23
|
-
export const CLAUDE_CODE_NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
24
|
-
// Real build markers extracted from the 2.1.195 native binary
|
|
25
|
-
// (Bun-embedded JS): `BUILD_TIME:"2026-06-26T01:00:56Z"`,
|
|
26
|
-
// `GIT_SHA:"4603aa3f2ea164bd0974f82eb413ae7acc99a7ee"`.
|
|
27
|
-
// (Prior 2.1.159 linux-x64: BUILD_TIME 2026-05-31T16:22:50Z,
|
|
28
|
-
// GIT_SHA dd8c11fc8d05cea0b2b9fc8f5a99a5c5c5dffc9b.)
|
|
29
|
-
export const CLAUDE_CODE_BUILD_TIME = "2026-06-26T01:00:56Z";
|
|
30
|
-
export const CLAUDE_CODE_GIT_SHA = "4603aa3f2ea164bd0974f82eb413ae7acc99a7ee";
|
|
31
|
-
|
|
32
|
-
// The @anthropic-ai/sdk version bundled with Claude Code.
|
|
33
|
-
// This is distinct from the CLI version and goes in X-Stainless-Package-Version.
|
|
34
|
-
// v2.1.107 switched from @anthropic-ai/sdk v0.208.0 to v0.81.0 (confirmed via bundle var x$H="0.81.0").
|
|
35
|
-
// Still 0.81.0 in v2.1.143 (verified by binary string extraction of win32-x64 native binary:
|
|
36
|
-
// 2.1.134-2.1.143 are telemetry / subagent-header / mid-conversation-system additions with
|
|
37
|
-
// no SDK version bump; mid-conversation-system-2026-04-07 registered in 2.1.143 but not
|
|
38
|
-
// auto-emitted; two new conditional x- headers x-claude-code-agent-id /
|
|
39
|
-
// x-claude-code-parent-agent-id are only emitted in subagent dispatch contexts).
|
|
40
|
-
export const ANTHROPIC_SDK_VERSION = "0.94.0";
|
|
41
|
-
|
|
42
|
-
// Map of CLI version to bundled SDK version (update when CLI version changes)
|
|
43
|
-
export const CLI_TO_SDK_VERSION = new Map([
|
|
44
|
-
// 2.1.233: the wire-compat package's DEFAULT_PROFILE
|
|
45
|
-
// (`claude-code-2.1.233-sdk-0.112.1`) declares sdkVersion 0.112.1, so the
|
|
46
|
-
// legacy header path stays consistent with the adapter path when the tracked
|
|
47
|
-
// CLI version is the profile baseline.
|
|
48
|
-
["2.1.233", "0.112.1"],
|
|
49
|
-
// 2.1.160-2.1.195: refusal-fallback feature (server-side-fallback /
|
|
50
|
-
// fallback-credit betas) is opt-in/GrowthBook-gated and never emitted on a
|
|
51
|
-
// default /v1/messages turn; no wire SDK bump (binary-verified:
|
|
52
|
-
// x-stainless-package-version still "0.94.0" in 2.1.195).
|
|
53
|
-
["2.1.195", "0.94.0"],
|
|
54
|
-
["2.1.194", "0.94.0"],
|
|
55
|
-
["2.1.193", "0.94.0"],
|
|
56
|
-
["2.1.192", "0.94.0"],
|
|
57
|
-
["2.1.191", "0.94.0"],
|
|
58
|
-
["2.1.190", "0.94.0"],
|
|
59
|
-
["2.1.189", "0.94.0"],
|
|
60
|
-
["2.1.188", "0.94.0"],
|
|
61
|
-
["2.1.187", "0.94.0"],
|
|
62
|
-
["2.1.186", "0.94.0"],
|
|
63
|
-
["2.1.185", "0.94.0"],
|
|
64
|
-
["2.1.184", "0.94.0"],
|
|
65
|
-
["2.1.183", "0.94.0"],
|
|
66
|
-
["2.1.182", "0.94.0"],
|
|
67
|
-
["2.1.181", "0.94.0"],
|
|
68
|
-
["2.1.180", "0.94.0"],
|
|
69
|
-
["2.1.179", "0.94.0"],
|
|
70
|
-
["2.1.178", "0.94.0"],
|
|
71
|
-
["2.1.177", "0.94.0"],
|
|
72
|
-
["2.1.176", "0.94.0"],
|
|
73
|
-
["2.1.175", "0.94.0"],
|
|
74
|
-
["2.1.174", "0.94.0"],
|
|
75
|
-
["2.1.173", "0.94.0"],
|
|
76
|
-
["2.1.172", "0.94.0"],
|
|
77
|
-
["2.1.171", "0.94.0"],
|
|
78
|
-
["2.1.170", "0.94.0"],
|
|
79
|
-
["2.1.169", "0.94.0"],
|
|
80
|
-
["2.1.168", "0.94.0"],
|
|
81
|
-
["2.1.167", "0.94.0"],
|
|
82
|
-
["2.1.166", "0.94.0"],
|
|
83
|
-
["2.1.165", "0.94.0"],
|
|
84
|
-
["2.1.164", "0.94.0"],
|
|
85
|
-
["2.1.163", "0.94.0"],
|
|
86
|
-
["2.1.162", "0.94.0"],
|
|
87
|
-
["2.1.161", "0.94.0"],
|
|
88
|
-
["2.1.160", "0.94.0"],
|
|
89
|
-
// 2.1.155-2.1.159: only wire change is the revival of
|
|
90
|
-
// summarize-connector-text-2026-03-13 (label narration_summaries), gated by
|
|
91
|
-
// GrowthBook pewter_owl_header (default-off) — not always-on. SDK still 0.94.0
|
|
92
|
-
// (binary-verified: x-stainless-package-version NQ="0.94.0" in 2.1.159).
|
|
93
|
-
["2.1.159", "0.94.0"],
|
|
94
|
-
["2.1.158", "0.94.0"],
|
|
95
|
-
["2.1.157", "0.94.0"],
|
|
96
|
-
["2.1.156", "0.94.0"],
|
|
97
|
-
["2.1.155", "0.94.0"],
|
|
98
|
-
// 2.1.151-2.1.154: Opus 4.8 launch (2026-05-28). npm now ships a native
|
|
99
|
-
// binary (no JS bundle), so the bundled SDK version can't be string-extracted;
|
|
100
|
-
// no SDK bump was observed across 2.1.150->2.1.154, so we carry 0.94.0 forward.
|
|
101
|
-
["2.1.154", "0.94.0"],
|
|
102
|
-
["2.1.153", "0.94.0"],
|
|
103
|
-
["2.1.152", "0.94.0"],
|
|
104
|
-
["2.1.151", "0.94.0"],
|
|
105
|
-
["2.1.150", "0.94.0"],
|
|
106
|
-
["2.1.143", "0.81.0"],
|
|
107
|
-
["2.1.142", "0.81.0"],
|
|
108
|
-
["2.1.141", "0.81.0"],
|
|
109
|
-
["2.1.140", "0.81.0"],
|
|
110
|
-
["2.1.139", "0.81.0"],
|
|
111
|
-
["2.1.138", "0.81.0"],
|
|
112
|
-
["2.1.137", "0.81.0"],
|
|
113
|
-
["2.1.136", "0.81.0"],
|
|
114
|
-
["2.1.134", "0.81.0"],
|
|
115
|
-
["2.1.133", "0.81.0"],
|
|
116
|
-
["2.1.132", "0.81.0"],
|
|
117
|
-
["2.1.131", "0.81.0"],
|
|
118
|
-
["2.1.130", "0.81.0"],
|
|
119
|
-
["2.1.129", "0.81.0"],
|
|
120
|
-
["2.1.128", "0.81.0"],
|
|
121
|
-
["2.1.127", "0.81.0"],
|
|
122
|
-
["2.1.126", "0.81.0"],
|
|
123
|
-
["2.1.125", "0.81.0"],
|
|
124
|
-
["2.1.124", "0.81.0"],
|
|
125
|
-
["2.1.123", "0.81.0"],
|
|
126
|
-
["2.1.122", "0.81.0"],
|
|
127
|
-
["2.1.121", "0.81.0"],
|
|
128
|
-
["2.1.120", "0.81.0"],
|
|
129
|
-
["2.1.119", "0.81.0"],
|
|
130
|
-
["2.1.117", "0.81.0"],
|
|
131
|
-
["2.1.116", "0.81.0"],
|
|
132
|
-
["2.1.115", "0.81.0"],
|
|
133
|
-
["2.1.114", "0.81.0"],
|
|
134
|
-
["2.1.113", "0.81.0"],
|
|
135
|
-
["2.1.112", "0.81.0"],
|
|
136
|
-
["2.1.111", "0.81.0"],
|
|
137
|
-
["2.1.110", "0.81.0"],
|
|
138
|
-
["2.1.109", "0.81.0"],
|
|
139
|
-
["2.1.108", "0.81.0"],
|
|
140
|
-
["2.1.107", "0.81.0"],
|
|
141
|
-
["2.1.105", "0.81.0"],
|
|
142
|
-
["2.1.97", "0.208.0"],
|
|
143
|
-
["2.1.96", "0.208.0"],
|
|
144
|
-
["2.1.95", "0.208.0"],
|
|
145
|
-
["2.1.94", "0.208.0"],
|
|
146
|
-
["2.1.93", "0.208.0"],
|
|
147
|
-
["2.1.92", "0.208.0"],
|
|
148
|
-
["2.1.91", "0.208.0"],
|
|
149
|
-
["2.1.90", "0.208.0"],
|
|
150
|
-
["2.1.89", "0.208.0"],
|
|
151
|
-
["2.1.88", "0.208.0"],
|
|
152
|
-
["2.1.87", "0.208.0"],
|
|
153
|
-
["2.1.86", "0.208.0"],
|
|
154
|
-
["2.1.85", "0.208.0"],
|
|
155
|
-
["2.1.84", "0.208.0"],
|
|
156
|
-
["2.1.83", "0.208.0"],
|
|
157
|
-
["2.1.81", "0.208.0"],
|
|
158
|
-
["2.1.80", "0.208.0"],
|
|
159
|
-
]);
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Get the SDK version corresponding to a CLI version.
|
|
163
|
-
* Falls back to ANTHROPIC_SDK_VERSION constant.
|
|
164
|
-
* @param {string | null | undefined} cliVersion
|
|
165
|
-
* @returns {string}
|
|
166
|
-
*/
|
|
167
|
-
export function getSdkVersion(cliVersion) {
|
|
168
|
-
return CLI_TO_SDK_VERSION.get(cliVersion) ?? ANTHROPIC_SDK_VERSION;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// ---------------------------------------------------------------------------
|
|
172
|
-
// Beta flag registries
|
|
173
|
-
// ---------------------------------------------------------------------------
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Set of all known experimental/optional beta flags.
|
|
177
|
-
* Used to filter betas when CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1.
|
|
178
|
-
* WARNING: this set intentionally overlaps with always-on betas - only use
|
|
179
|
-
* it with the disable-experimental guard, never unconditionally.
|
|
180
|
-
*/
|
|
181
|
-
export const EXPERIMENTAL_BETA_FLAGS = new Set([
|
|
182
|
-
"adaptive-thinking-2026-01-28",
|
|
183
|
-
"advanced-tool-use-2025-11-20",
|
|
184
|
-
"advisor-tool-2026-03-01",
|
|
185
|
-
"afk-mode-2026-01-31",
|
|
186
|
-
"cache-diagnosis-2026-04-07",
|
|
187
|
-
// CCR bring-your-own-cloud beta. Registered in the 2.1.154 binary's _W() table
|
|
188
|
-
// but not emitted on /v1/messages; kept here for the disable-experimental guard.
|
|
189
|
-
"ccr-byoc-2025-07-29",
|
|
190
|
-
"code-execution-2025-08-25",
|
|
191
|
-
"compact-2026-01-12",
|
|
192
|
-
"context-1m-2025-08-07",
|
|
193
|
-
"context-hint-2026-04-09",
|
|
194
|
-
"context-management-2025-06-27",
|
|
195
|
-
"environments-2025-11-01",
|
|
196
|
-
"extended-cache-ttl-2025-04-11",
|
|
197
|
-
// Refusal-fallback credit beta from the upstream Udd registry (CC 2.1.195).
|
|
198
|
-
// Opt-in/GrowthBook-gated; never auto-emitted on a default /v1/messages turn.
|
|
199
|
-
// Listed here for the disable-experimental guard + manual opt-in ONLY.
|
|
200
|
-
"fallback-credit-2026-06-01",
|
|
201
|
-
"fast-mode-2026-02-01",
|
|
202
|
-
"files-api-2025-04-14",
|
|
203
|
-
"interleaved-thinking-2025-05-14",
|
|
204
|
-
// Registered in the 2.1.154 binary's _W() table (mcp_servers label). Plugin
|
|
205
|
-
// proxies MCP tool calls inline and does not emit this on chat completions.
|
|
206
|
-
"mcp-servers-2025-12-04",
|
|
207
|
-
// Registered in CC v2.1.143 but NOT in real CC's always-on emission set
|
|
208
|
-
// (master registry only, not in the always-on subset). Likely GrowthBook-gated
|
|
209
|
-
// pending server rollout. Paired telemetry: tengu_mid_conv_system_fallback_retry.
|
|
210
|
-
"mid-conversation-system-2026-04-07",
|
|
211
|
-
"prompt-caching-scope-2026-01-05",
|
|
212
|
-
"redact-thinking-2026-02-12",
|
|
213
|
-
// Server-side refusal-fallback beta from the upstream Udd registry (CC 2.1.195).
|
|
214
|
-
// Opt-in/GrowthBook-gated; never auto-emitted on a default /v1/messages turn.
|
|
215
|
-
// Listed here for the disable-experimental guard + manual opt-in ONLY.
|
|
216
|
-
"server-side-fallback-2026-06-01",
|
|
217
|
-
"structured-outputs-2025-12-15",
|
|
218
|
-
// Revived in CC 2.1.159 as registry label `narration_summaries` (it was a dead
|
|
219
|
-
// slot from v2.1.90-2.1.154). Real CC emits it only when GrowthBook flag
|
|
220
|
-
// `pewter_owl_header` is on (default-off), first-party, and NOT in fast-mode.
|
|
221
|
-
// Listed here for the disable-guard + manual opt-in ONLY; never emitted always-on.
|
|
222
|
-
"summarize-connector-text-2026-03-13",
|
|
223
|
-
"task-budgets-2026-03-13",
|
|
224
|
-
"tool-search-tool-2025-10-19",
|
|
225
|
-
// SDK admin route beta (used for /v1/user_profiles* endpoints). Registered for
|
|
226
|
-
// forward-compat; the plugin proxies /v1/messages only and does NOT emit this
|
|
227
|
-
// on chat completions.
|
|
228
|
-
"user-profiles-2026-03-24",
|
|
229
|
-
"web-search-2025-03-05",
|
|
230
|
-
]);
|
|
231
|
-
|
|
232
|
-
/** Friendly shortcut aliases for config.custom_betas values. */
|
|
233
|
-
export const BETA_SHORTCUTS = new Map([
|
|
234
|
-
["1m", "context-1m-2025-08-07"],
|
|
235
|
-
["1m-context", "context-1m-2025-08-07"],
|
|
236
|
-
["context-1m", "context-1m-2025-08-07"],
|
|
237
|
-
["cache-diagnosis", "cache-diagnosis-2026-04-07"],
|
|
238
|
-
["cache-diag", "cache-diagnosis-2026-04-07"],
|
|
239
|
-
["cache-ttl", "extended-cache-ttl-2025-04-11"],
|
|
240
|
-
["context-hint", "context-hint-2026-04-09"],
|
|
241
|
-
["environments", "environments-2025-11-01"],
|
|
242
|
-
["extended-cache-ttl", "extended-cache-ttl-2025-04-11"],
|
|
243
|
-
["hint", "context-hint-2026-04-09"],
|
|
244
|
-
["fast", "fast-mode-2026-02-01"],
|
|
245
|
-
["fast-mode", "fast-mode-2026-02-01"],
|
|
246
|
-
["opus-fast", "fast-mode-2026-02-01"],
|
|
247
|
-
["task-budgets", "task-budgets-2026-03-13"],
|
|
248
|
-
["budgets", "task-budgets-2026-03-13"],
|
|
249
|
-
["redact-thinking", "redact-thinking-2026-02-12"],
|
|
250
|
-
["mid-conv-system", "mid-conversation-system-2026-04-07"],
|
|
251
|
-
["mid-system", "mid-conversation-system-2026-04-07"],
|
|
252
|
-
["context-management", "context-management-2025-06-27"],
|
|
253
|
-
["structured-outputs", "structured-outputs-2025-12-15"],
|
|
254
|
-
["web-search", "web-search-2025-03-05"],
|
|
255
|
-
["advanced-tool-use", "advanced-tool-use-2025-11-20"],
|
|
256
|
-
["tool-search-tool", "tool-search-tool-2025-10-19"],
|
|
257
|
-
["effort", "effort-2025-11-24"],
|
|
258
|
-
["prompt-caching-scope", "prompt-caching-scope-2026-01-05"],
|
|
259
|
-
["thinking-token-count", "thinking-token-count-2026-05-13"],
|
|
260
|
-
["afk-mode", "afk-mode-2026-01-31"],
|
|
261
|
-
["advisor-tool", "advisor-tool-2026-03-01"],
|
|
262
|
-
["mcp-servers", "mcp-servers-2025-12-04"],
|
|
263
|
-
["ccr-byoc", "ccr-byoc-2025-07-29"],
|
|
264
|
-
["connector-text", "summarize-connector-text-2026-03-13"],
|
|
265
|
-
["narration-summaries", "summarize-connector-text-2026-03-13"],
|
|
266
|
-
["summarize-connector-text", "summarize-connector-text-2026-03-13"],
|
|
267
|
-
["server-side-fallback", "server-side-fallback-2026-06-01"],
|
|
268
|
-
["fallback", "server-side-fallback-2026-06-01"],
|
|
269
|
-
["fallback-credit", "fallback-credit-2026-06-01"],
|
|
270
|
-
]);
|
|
271
|
-
|
|
272
|
-
// ---------------------------------------------------------------------------
|
|
273
|
-
// Helper functions
|
|
274
|
-
// ---------------------------------------------------------------------------
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Resolve a beta shortcut alias to its canonical flag name.
|
|
278
|
-
* Returns the value unchanged if no alias matches.
|
|
279
|
-
* @param {string | null | undefined} value
|
|
280
|
-
* @returns {string}
|
|
281
|
-
*/
|
|
282
|
-
export function resolveBetaShortcut(value) {
|
|
283
|
-
if (!value) return "";
|
|
284
|
-
const trimmed = value.trim();
|
|
285
|
-
const mapped = BETA_SHORTCUTS.get(trimmed.toLowerCase());
|
|
286
|
-
return mapped || trimmed;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Build the extended User-Agent for API calls.
|
|
291
|
-
* Real CC v96 sends "claude-cli/{version} (external, {entrypoint})" - confirmed via
|
|
292
|
-
* proxy capture of real CC on Windows/Node.js.
|
|
293
|
-
* @param {string} version
|
|
294
|
-
* @returns {string}
|
|
295
|
-
*/
|
|
296
|
-
export function buildExtendedUserAgent(version) {
|
|
297
|
-
const entrypoint = process.env.CLAUDE_CODE_ENTRYPOINT ?? "cli";
|
|
298
|
-
const sdkVersion = process.env.CLAUDE_AGENT_SDK_VERSION ? `, agent-sdk/${process.env.CLAUDE_AGENT_SDK_VERSION}` : "";
|
|
299
|
-
const clientApp = process.env.CLAUDE_AGENT_SDK_CLIENT_APP
|
|
300
|
-
? `, client-app/${process.env.CLAUDE_AGENT_SDK_CLIENT_APP}`
|
|
301
|
-
: "";
|
|
302
|
-
return `claude-cli/${version} (external, ${entrypoint}${sdkVersion}${clientApp})`;
|
|
303
|
-
}
|