opencode-anthropic-fix 0.0.28 → 0.0.30
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/index.mjs +46 -12
- package/lib/oauth.mjs +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2145,9 +2145,29 @@ export async function AnthropicAuthPlugin({ client, project, directory, worktree
|
|
|
2145
2145
|
try {
|
|
2146
2146
|
const parsedBody = JSON.parse(body);
|
|
2147
2147
|
if (Array.isArray(parsedBody.messages) && parsedBody.messages.length > 4) {
|
|
2148
|
-
// Keep first 2 messages (initial context) and last
|
|
2148
|
+
// Keep first 2 messages (initial context) and last N messages (recent work).
|
|
2149
|
+
// Ensure the trimmed array never ends with an assistant message (prefill),
|
|
2150
|
+
// which would cause "does not support assistant message prefill" errors.
|
|
2151
|
+
let tailCount = 2;
|
|
2152
|
+
const msgs = parsedBody.messages;
|
|
2153
|
+
// Expand tail if it would end with an assistant message
|
|
2154
|
+
while (
|
|
2155
|
+
tailCount < msgs.length - 2 &&
|
|
2156
|
+
msgs[msgs.length - tailCount]?.role !== "user" &&
|
|
2157
|
+
msgs.length - tailCount > 0
|
|
2158
|
+
) {
|
|
2159
|
+
tailCount++;
|
|
2160
|
+
}
|
|
2161
|
+
const tail = msgs.slice(-tailCount);
|
|
2162
|
+
// If tail still starts/ends badly, force a user wrapper
|
|
2163
|
+
if (tail.length > 0 && tail[tail.length - 1]?.role === "assistant") {
|
|
2164
|
+
tail.push({
|
|
2165
|
+
role: "user",
|
|
2166
|
+
content: [{ type: "text", text: "Continue." }],
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2149
2169
|
const trimmed = [
|
|
2150
|
-
...
|
|
2170
|
+
...msgs.slice(0, 2),
|
|
2151
2171
|
{
|
|
2152
2172
|
role: "user",
|
|
2153
2173
|
content: [
|
|
@@ -2157,7 +2177,7 @@ export async function AnthropicAuthPlugin({ client, project, directory, worktree
|
|
|
2157
2177
|
},
|
|
2158
2178
|
],
|
|
2159
2179
|
},
|
|
2160
|
-
...
|
|
2180
|
+
...tail,
|
|
2161
2181
|
];
|
|
2162
2182
|
parsedBody.messages = trimmed;
|
|
2163
2183
|
requestInit.body = JSON.stringify(parsedBody);
|
|
@@ -2875,18 +2895,19 @@ process.once("beforeExit", () => {
|
|
|
2875
2895
|
// Request building helpers (extracted from original fetch interceptor)
|
|
2876
2896
|
// ---------------------------------------------------------------------------
|
|
2877
2897
|
|
|
2878
|
-
const FALLBACK_CLAUDE_CLI_VERSION = "2.1.
|
|
2898
|
+
const FALLBACK_CLAUDE_CLI_VERSION = "2.1.83";
|
|
2879
2899
|
const CLAUDE_CODE_NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
2880
2900
|
|
|
2881
|
-
// The @anthropic-ai/sdk version bundled with Claude Code v2.1.
|
|
2901
|
+
// The @anthropic-ai/sdk version bundled with Claude Code v2.1.83.
|
|
2882
2902
|
// This is distinct from the CLI version and goes in X-Stainless-Package-Version.
|
|
2883
|
-
|
|
2903
|
+
// Verified by extracting VERSION="0.208.0" from the bundled cli.js of v2.1.80/2.1.81/2.1.83.
|
|
2904
|
+
const ANTHROPIC_SDK_VERSION = "0.208.0";
|
|
2884
2905
|
|
|
2885
2906
|
// Map of CLI version → bundled SDK version (update when CLI version changes)
|
|
2886
2907
|
const CLI_TO_SDK_VERSION = new Map([
|
|
2887
|
-
["2.1.
|
|
2888
|
-
["2.1.
|
|
2889
|
-
["2.1.
|
|
2908
|
+
["2.1.83", "0.208.0"],
|
|
2909
|
+
["2.1.81", "0.208.0"],
|
|
2910
|
+
["2.1.80", "0.208.0"],
|
|
2890
2911
|
]);
|
|
2891
2912
|
|
|
2892
2913
|
/**
|
|
@@ -3334,9 +3355,9 @@ function buildRequestMetadata(input) {
|
|
|
3334
3355
|
|
|
3335
3356
|
/**
|
|
3336
3357
|
* Build the billing header block for Claude Code system prompt injection.
|
|
3337
|
-
* Claude Code v2.1.81
|
|
3358
|
+
* Claude Code v2.1.81+: cch computed via NP1() from first user message, cc_version includes model ID.
|
|
3338
3359
|
*
|
|
3339
|
-
* @param {string} version - CLI version (e.g., "2.1.
|
|
3360
|
+
* @param {string} version - CLI version (e.g., "2.1.83")
|
|
3340
3361
|
* @param {string} [modelId] - Model ID to append (e.g., "claude-opus-4-6")
|
|
3341
3362
|
* @param {string} [firstUserMessage] - First user message text for cch hash computation
|
|
3342
3363
|
* @returns {string}
|
|
@@ -3659,7 +3680,7 @@ function buildAnthropicBetaHeader(
|
|
|
3659
3680
|
const haiku = isHaikuModel(model);
|
|
3660
3681
|
const isRoundRobin = strategy === "round-robin";
|
|
3661
3682
|
|
|
3662
|
-
// === ALWAYS-ON BETAS (Claude Code v2.1.
|
|
3683
|
+
// === ALWAYS-ON BETAS (Claude Code v2.1.83 base set) ===
|
|
3663
3684
|
// These are ALWAYS included regardless of env vars or feature flags.
|
|
3664
3685
|
if (!haiku) {
|
|
3665
3686
|
betas.push(CLAUDE_CODE_BETA_FLAG); // "claude-code-20250219"
|
|
@@ -4090,6 +4111,19 @@ function transformRequestBody(body, signature, runtime, betaHeader) {
|
|
|
4090
4111
|
if (fastModeEnabled && parsed.model && (isOpus46Model(parsed.model) || isSonnet46Model(parsed.model))) {
|
|
4091
4112
|
parsed.speed = "fast";
|
|
4092
4113
|
}
|
|
4114
|
+
|
|
4115
|
+
// Guard: ensure messages array never ends with an assistant message.
|
|
4116
|
+
// The API rejects this as "assistant message prefill" when extended thinking is active.
|
|
4117
|
+
if (Array.isArray(parsed.messages) && parsed.messages.length > 0) {
|
|
4118
|
+
const lastMsg = parsed.messages[parsed.messages.length - 1];
|
|
4119
|
+
if (lastMsg && lastMsg.role === "assistant") {
|
|
4120
|
+
parsed.messages.push({
|
|
4121
|
+
role: "user",
|
|
4122
|
+
content: [{ type: "text", text: "Continue." }],
|
|
4123
|
+
});
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
|
|
4093
4127
|
return JSON.stringify(parsed);
|
|
4094
4128
|
} catch {
|
|
4095
4129
|
// ignore parse errors
|
package/lib/oauth.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const OAUTH_TOKEN_URL = `https://${OAUTH_CONSOLE_HOST}/v1/oauth/token`;
|
|
|
13
13
|
const OAUTH_REVOKE_URL = `https://${OAUTH_CONSOLE_HOST}/v1/oauth/revoke`;
|
|
14
14
|
// Real Claude Code uses axios 1.13.6 for OAuth calls — axios sets User-Agent
|
|
15
15
|
// automatically and adds Accept header. We must match this fingerprint exactly.
|
|
16
|
-
// CLI version profile: 2.1.
|
|
16
|
+
// CLI version profile: 2.1.83 (for reference; not sent on OAuth calls)
|
|
17
17
|
const OAUTH_AXIOS_VERSION = "1.13.6";
|
|
18
18
|
const OAUTH_USER_AGENT = `axios/${OAUTH_AXIOS_VERSION}`;
|
|
19
19
|
const OAUTH_ACCEPT = "application/json, text/plain, */*";
|