@vacbo/opencode-anthropic-fix 0.1.7 → 0.1.9
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 +88 -88
- package/dist/opencode-anthropic-auth-cli.mjs +804 -507
- package/dist/opencode-anthropic-auth-plugin.js +4751 -4109
- package/package.json +67 -59
- package/src/__tests__/billing-edge-cases.test.ts +59 -59
- package/src/__tests__/bun-proxy.parallel.test.ts +388 -382
- package/src/__tests__/cc-comparison.test.ts +87 -87
- package/src/__tests__/cc-credentials.test.ts +254 -250
- package/src/__tests__/cch-drift-checker.test.ts +51 -51
- package/src/__tests__/cch-native-style.test.ts +56 -56
- package/src/__tests__/debug-gating.test.ts +42 -42
- package/src/__tests__/decomposition-smoke.test.ts +68 -68
- package/src/__tests__/fingerprint-regression.test.ts +575 -566
- package/src/__tests__/helpers/conversation-history.smoke.test.ts +271 -271
- package/src/__tests__/helpers/conversation-history.ts +119 -119
- package/src/__tests__/helpers/deferred.smoke.test.ts +103 -103
- package/src/__tests__/helpers/deferred.ts +69 -69
- package/src/__tests__/helpers/in-memory-storage.smoke.test.ts +155 -155
- package/src/__tests__/helpers/in-memory-storage.ts +88 -88
- package/src/__tests__/helpers/mock-bun-proxy.smoke.test.ts +68 -68
- package/src/__tests__/helpers/mock-bun-proxy.ts +189 -189
- package/src/__tests__/helpers/plugin-fetch-harness.smoke.test.ts +273 -273
- package/src/__tests__/helpers/plugin-fetch-harness.ts +288 -288
- package/src/__tests__/helpers/sse.smoke.test.ts +236 -236
- package/src/__tests__/helpers/sse.ts +209 -209
- package/src/__tests__/index.parallel.test.ts +605 -595
- package/src/__tests__/sanitization-regex.test.ts +112 -112
- package/src/__tests__/state-bounds.test.ts +90 -90
- package/src/account-identity.test.ts +197 -192
- package/src/account-identity.ts +69 -67
- package/src/account-state.test.ts +86 -86
- package/src/account-state.ts +25 -25
- package/src/accounts/matching.test.ts +335 -0
- package/src/accounts/matching.ts +167 -0
- package/src/accounts/persistence.test.ts +345 -0
- package/src/accounts/persistence.ts +432 -0
- package/src/accounts/repair.test.ts +276 -0
- package/src/accounts/repair.ts +407 -0
- package/src/accounts.dedup.test.ts +621 -621
- package/src/accounts.test.ts +933 -929
- package/src/accounts.ts +633 -989
- package/src/backoff.test.ts +345 -345
- package/src/backoff.ts +219 -219
- package/src/betas.ts +124 -124
- package/src/bun-fetch.test.ts +345 -342
- package/src/bun-fetch.ts +424 -424
- package/src/bun-proxy.test.ts +25 -25
- package/src/bun-proxy.ts +209 -209
- package/src/cc-credentials.ts +111 -111
- package/src/circuit-breaker.test.ts +184 -184
- package/src/circuit-breaker.ts +169 -169
- package/src/cli/commands/auth.ts +963 -0
- package/src/cli/commands/config.ts +547 -0
- package/src/cli/formatting.test.ts +406 -0
- package/src/cli/formatting.ts +219 -0
- package/src/cli.ts +255 -2022
- package/src/commands/handlers/betas.ts +100 -0
- package/src/commands/handlers/config.ts +99 -0
- package/src/commands/handlers/files.ts +375 -0
- package/src/commands/oauth-flow.ts +181 -166
- package/src/commands/prompts.ts +61 -61
- package/src/commands/router.test.ts +421 -0
- package/src/commands/router.ts +143 -635
- package/src/config.test.ts +482 -482
- package/src/config.ts +412 -404
- package/src/constants.ts +48 -48
- package/src/drift/cch-constants.ts +95 -95
- package/src/env.ts +111 -105
- package/src/headers/billing.ts +33 -33
- package/src/headers/builder.ts +130 -130
- package/src/headers/cch.ts +75 -75
- package/src/headers/stainless.ts +25 -25
- package/src/headers/user-agent.ts +23 -23
- package/src/index.ts +436 -828
- package/src/models.ts +27 -27
- package/src/oauth.test.ts +102 -102
- package/src/oauth.ts +178 -178
- package/src/parent-pid-watcher.test.ts +148 -148
- package/src/parent-pid-watcher.ts +69 -69
- package/src/plugin-helpers.ts +82 -82
- package/src/refresh-helpers.ts +145 -139
- package/src/refresh-lock.test.ts +94 -94
- package/src/refresh-lock.ts +93 -93
- package/src/request/body.history.test.ts +579 -571
- package/src/request/body.ts +255 -255
- package/src/request/metadata.ts +65 -65
- package/src/request/retry.test.ts +156 -156
- package/src/request/retry.ts +67 -67
- package/src/request/url.ts +21 -21
- package/src/request-orchestration-helpers.ts +648 -0
- package/src/response/index.ts +5 -5
- package/src/response/mcp.ts +58 -58
- package/src/response/streaming.test.ts +313 -311
- package/src/response/streaming.ts +412 -410
- package/src/rotation.test.ts +304 -301
- package/src/rotation.ts +205 -205
- package/src/storage.test.ts +547 -547
- package/src/storage.ts +315 -291
- package/src/system-prompt/builder.ts +38 -38
- package/src/system-prompt/index.ts +5 -5
- package/src/system-prompt/normalize.ts +60 -60
- package/src/system-prompt/sanitize.ts +30 -30
- package/src/thinking.ts +21 -20
- package/src/token-refresh.test.ts +265 -265
- package/src/token-refresh.ts +219 -214
- package/src/types.ts +30 -30
- package/dist/bun-proxy.mjs +0 -291
package/package.json
CHANGED
|
@@ -1,62 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
],
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public",
|
|
17
|
-
"registry": "https://registry.npmjs.org/"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "bun scripts/build.ts",
|
|
21
|
-
"prepublishOnly": "npm run build && npm test",
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"check:cch-drift": "bun scripts/drift-checker/check-cch-constants.ts --fail-on-drift",
|
|
24
|
-
"check:cch-drift:npm": "bun scripts/drift-checker/check-cch-constants.ts --npm-version latest --fail-on-drift",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"lint": "eslint .",
|
|
27
|
-
"lint:fix": "eslint --fix .",
|
|
28
|
-
"format": "prettier --write .",
|
|
29
|
-
"format:check": "prettier --check .",
|
|
30
|
-
"install:link": "bun scripts/install.ts link",
|
|
31
|
-
"install:copy": "npm run build && bun scripts/install.ts copy",
|
|
32
|
-
"uninstall": "bun scripts/install.ts uninstall",
|
|
33
|
-
"prepare": "husky"
|
|
34
|
-
},
|
|
35
|
-
"lint-staged": {
|
|
36
|
-
"*.ts": [
|
|
37
|
-
"prettier --write",
|
|
38
|
-
"eslint --fix"
|
|
2
|
+
"name": "@vacbo/opencode-anthropic-fix",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"main": "dist/opencode-anthropic-auth-plugin.js",
|
|
5
|
+
"bin": {
|
|
6
|
+
"opencode-anthropic-auth": "dist/opencode-anthropic-auth-cli.mjs",
|
|
7
|
+
"oaa": "dist/opencode-anthropic-auth-cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**",
|
|
11
|
+
"src/**/*.ts",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
39
14
|
],
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/Vacbo/opencode-anthropic-fix"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/Vacbo/opencode-anthropic-fix#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Vacbo/opencode-anthropic-fix/issues"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun scripts/build.ts",
|
|
29
|
+
"prepublishOnly": "npm run build && npm test",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"check:cch-drift": "bun scripts/drift-checker/check-cch-constants.ts --fail-on-drift",
|
|
32
|
+
"check:cch-drift:npm": "bun scripts/drift-checker/check-cch-constants.ts --npm-version latest --fail-on-drift",
|
|
33
|
+
"test:watch": "vitest",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"lint:fix": "eslint --fix .",
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"format:check": "prettier --check .",
|
|
38
|
+
"install:link": "bun scripts/install.ts link",
|
|
39
|
+
"install:copy": "npm run build && bun scripts/install.ts copy",
|
|
40
|
+
"uninstall": "bun scripts/install.ts uninstall",
|
|
41
|
+
"prepare": "husky"
|
|
42
|
+
},
|
|
43
|
+
"lint-staged": {
|
|
44
|
+
"*.ts": [
|
|
45
|
+
"prettier --write",
|
|
46
|
+
"eslint --fix"
|
|
47
|
+
],
|
|
48
|
+
"*.{json,md}": [
|
|
49
|
+
"prettier --write"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^10.0.1",
|
|
54
|
+
"@opencode-ai/plugin": "^0.4.45",
|
|
55
|
+
"@types/node": "^25.6.0",
|
|
56
|
+
"bun-types": "^1.3.12",
|
|
57
|
+
"esbuild": "^0.27.7",
|
|
58
|
+
"eslint": "^10.2.0",
|
|
59
|
+
"husky": "^9.1.7",
|
|
60
|
+
"jiti": "^2.6.1",
|
|
61
|
+
"lint-staged": "^16.4.0",
|
|
62
|
+
"prettier": "^3.8.2",
|
|
63
|
+
"typescript": "^5.9.3",
|
|
64
|
+
"typescript-eslint": "^8.58.1",
|
|
65
|
+
"vitest": "^4.1.4"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"@clack/prompts": "^1.2.0"
|
|
69
|
+
}
|
|
62
70
|
}
|
|
@@ -10,75 +10,75 @@ import { describe, it, expect, afterEach } from "vitest";
|
|
|
10
10
|
import { buildAnthropicBillingHeader } from "../headers/billing.js";
|
|
11
11
|
|
|
12
12
|
describe("buildAnthropicBillingHeader cc_entrypoint nullish coalescing", () => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const originalEntrypoint = process.env.CLAUDE_CODE_ENTRYPOINT;
|
|
14
|
+
const originalAttribution = process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
if (originalEntrypoint === undefined) {
|
|
18
|
+
delete process.env.CLAUDE_CODE_ENTRYPOINT;
|
|
19
|
+
} else {
|
|
20
|
+
process.env.CLAUDE_CODE_ENTRYPOINT = originalEntrypoint;
|
|
21
|
+
}
|
|
22
|
+
if (originalAttribution === undefined) {
|
|
23
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
24
|
+
} else {
|
|
25
|
+
process.env.CLAUDE_CODE_ATTRIBUTION_HEADER = originalAttribution;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
it("defaults to 'cli' when CLAUDE_CODE_ENTRYPOINT is unset", () => {
|
|
30
|
+
delete process.env.CLAUDE_CODE_ENTRYPOINT;
|
|
31
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
32
|
+
const header = buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "hello" }]);
|
|
33
|
+
expect(header).toContain("cc_entrypoint=cli");
|
|
34
|
+
});
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
it("uses explicit value when CLAUDE_CODE_ENTRYPOINT is set to non-empty string", () => {
|
|
37
|
+
process.env.CLAUDE_CODE_ENTRYPOINT = "slash";
|
|
38
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
39
|
+
const header = buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "hello" }]);
|
|
40
|
+
expect(header).toContain("cc_entrypoint=slash");
|
|
41
|
+
});
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
it("preserves empty string when CLAUDE_CODE_ENTRYPOINT is set to '' (?? not ||)", () => {
|
|
44
|
+
// With logical OR (||), empty string would fall through to "cli".
|
|
45
|
+
// With nullish coalescing (??), empty string is kept as-is.
|
|
46
|
+
process.env.CLAUDE_CODE_ENTRYPOINT = "";
|
|
47
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
48
|
+
const header = buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "hello" }]);
|
|
49
|
+
expect(header).not.toContain("cc_entrypoint=cli");
|
|
50
|
+
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
describe("buildAnthropicBillingHeader version suffix edge cases", () => {
|
|
54
|
-
|
|
54
|
+
const originalAttribution = process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
if (originalAttribution === undefined) {
|
|
58
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
59
|
+
} else {
|
|
60
|
+
process.env.CLAUDE_CODE_ATTRIBUTION_HEADER = originalAttribution;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
it("handles empty message content without crashing", () => {
|
|
65
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
66
|
+
expect(() => buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "" }])).not.toThrow();
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
it("handles single-character message", () => {
|
|
70
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
71
|
+
expect(() => buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "x" }])).not.toThrow();
|
|
72
|
+
});
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
it("handles empty messages array", () => {
|
|
75
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
76
|
+
expect(() => buildAnthropicBillingHeader("2.1.98", [])).not.toThrow();
|
|
77
|
+
});
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
it("includes the CC version in the header output", () => {
|
|
80
|
+
delete process.env.CLAUDE_CODE_ATTRIBUTION_HEADER;
|
|
81
|
+
const header = buildAnthropicBillingHeader("2.1.98", [{ role: "user", content: "hello world" }]);
|
|
82
|
+
expect(header).toContain("2.1.98");
|
|
83
|
+
});
|
|
84
84
|
});
|