@ex-machina/opencode-anthropic-auth 2.0.0-next.0 → 2.0.0-next.2
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 +102 -37
- package/dist/auth.d.ts +3 -3
- package/dist/auth.js +161 -82
- package/dist/bounded.d.ts +8 -0
- package/dist/bounded.js +59 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.js +78 -0
- package/dist/constants.d.ts +10 -2
- package/dist/constants.js +12 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +535 -51
- package/dist/json-response-stream.d.ts +10 -0
- package/dist/json-response-stream.js +638 -0
- package/dist/rate-limit.d.ts +18 -0
- package/dist/rate-limit.js +354 -0
- package/dist/transform.d.ts +42 -14
- package/dist/transform.js +595 -326
- package/package.json +4 -2
package/dist/config.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CLAUDE_CODE_VERSION } from "./constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* Environment variable that overrides the reported Claude Code version.
|
|
4
|
+
*
|
|
5
|
+
* Anthropic gates model access on the reported version server-side, and that
|
|
6
|
+
* gate moves on Anthropic's schedule rather than this plugin's release
|
|
7
|
+
* schedule. The override lets users unblock a newly-gated model without
|
|
8
|
+
* waiting for a published bump.
|
|
9
|
+
*/
|
|
10
|
+
export const ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR = 'ANTHROPIC_CLAUDE_CODE_VERSION';
|
|
11
|
+
/**
|
|
12
|
+
* Claude Code releases are `major.minor.patch` with numeric components.
|
|
13
|
+
*
|
|
14
|
+
* Leading zeros are rejected: `02.1.275` is not a release Anthropic publishes,
|
|
15
|
+
* so accepting it would report a version string no server-side gate expects.
|
|
16
|
+
*/
|
|
17
|
+
const VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
18
|
+
const MAX_VERSION_LENGTH = 64;
|
|
19
|
+
/**
|
|
20
|
+
* Is `candidate` an older Claude Code release than `baseline`?
|
|
21
|
+
*
|
|
22
|
+
* Both arguments must already match `VERSION_PATTERN`. Components are compared
|
|
23
|
+
* numerically rather than lexically — `2.1.99` sorts after `2.1.275` as a
|
|
24
|
+
* string but is the older release — and as `BigInt`, so an unbounded component
|
|
25
|
+
* cannot silently lose precision the way `Number` would.
|
|
26
|
+
*/
|
|
27
|
+
function isOlderVersion(candidate, baseline) {
|
|
28
|
+
// The `0n` defaults are unreachable — `VERSION_PATTERN` guarantees exactly
|
|
29
|
+
// three components — but they keep the destructuring free of assertions.
|
|
30
|
+
const [major = 0n, minor = 0n, patch = 0n] = candidate
|
|
31
|
+
.split('.')
|
|
32
|
+
.map((part) => BigInt(part));
|
|
33
|
+
const [baseMajor = 0n, baseMinor = 0n, basePatch = 0n] = baseline
|
|
34
|
+
.split('.')
|
|
35
|
+
.map((part) => BigInt(part));
|
|
36
|
+
if (major !== baseMajor)
|
|
37
|
+
return major < baseMajor;
|
|
38
|
+
if (minor !== baseMinor)
|
|
39
|
+
return minor < baseMinor;
|
|
40
|
+
return patch < basePatch;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the Claude Code version to report to Anthropic.
|
|
44
|
+
*
|
|
45
|
+
* Returns the bundled version when the override is unset. A set override is
|
|
46
|
+
* trimmed and must look like a Claude Code release; anything else resolves to
|
|
47
|
+
* `invalid` with a message describing how to correct it. An override older
|
|
48
|
+
* than the bundled version resolves to `outdated`: it is still reported, since
|
|
49
|
+
* it was set deliberately, but it can lock the user out of newer models.
|
|
50
|
+
* Never throws.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveClaudeCodeVersion(raw = process.env[ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR]) {
|
|
53
|
+
if (raw === undefined) {
|
|
54
|
+
return { type: 'success', version: CLAUDE_CODE_VERSION };
|
|
55
|
+
}
|
|
56
|
+
const trimmed = raw.length <= MAX_VERSION_LENGTH ? raw.trim() : '';
|
|
57
|
+
if (!VERSION_PATTERN.test(trimmed)) {
|
|
58
|
+
return {
|
|
59
|
+
type: 'invalid',
|
|
60
|
+
error: `${ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR} is not a valid Claude Code version. ` +
|
|
61
|
+
`Expected major.minor.patch (for example, ${CLAUDE_CODE_VERSION}). ` +
|
|
62
|
+
`Reporting the bundled version ${CLAUDE_CODE_VERSION} instead; correct or unset ` +
|
|
63
|
+
`${ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR} and restart OpenCode to use the override.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (isOlderVersion(trimmed, CLAUDE_CODE_VERSION)) {
|
|
67
|
+
return {
|
|
68
|
+
type: 'outdated',
|
|
69
|
+
version: trimmed,
|
|
70
|
+
warning: `${ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR} is set to ${JSON.stringify(trimmed)}, which is older ` +
|
|
71
|
+
`than the bundled Claude Code version ${CLAUDE_CODE_VERSION}. Anthropic gates model access on ` +
|
|
72
|
+
`the reported version, so reporting an older one can make newer models reject the request. ` +
|
|
73
|
+
`Set ${ANTHROPIC_CLAUDE_CODE_VERSION_ENV_VAR} to ${CLAUDE_CODE_VERSION} or newer — or unset it ` +
|
|
74
|
+
`to use the bundled version — and restart OpenCode.`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { type: 'success', version: trimmed };
|
|
78
|
+
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -22,9 +22,17 @@ export declare const CCH_POSITIONS: number[];
|
|
|
22
22
|
* newer is required"). Keep this at or above the latest published
|
|
23
23
|
* `@anthropic-ai/claude-code` release, otherwise new models are unreachable.
|
|
24
24
|
*/
|
|
25
|
-
export declare const CLAUDE_CODE_VERSION = "2.1.
|
|
25
|
+
export declare const CLAUDE_CODE_VERSION = "2.1.275";
|
|
26
26
|
export declare const CLAUDE_CODE_ENTRYPOINT = "sdk-cli";
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Build the `user-agent` value for a reported Claude Code version.
|
|
29
|
+
*
|
|
30
|
+
* Both places we report the version (this header and the billing header's
|
|
31
|
+
* `cc_version`) must agree, so callers pass the same resolved version to each
|
|
32
|
+
* rather than reading a second, independently-derived constant.
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatUserAgent(version: string): string;
|
|
35
|
+
export declare const USER_AGENT: string;
|
|
28
36
|
/**
|
|
29
37
|
* Anchors that identify paragraphs to remove from the system prompt.
|
|
30
38
|
* Any paragraph (text between blank lines) containing one of these
|
package/dist/constants.js
CHANGED
|
@@ -32,9 +32,19 @@ export const CCH_POSITIONS = [4, 7, 20];
|
|
|
32
32
|
* newer is required"). Keep this at or above the latest published
|
|
33
33
|
* `@anthropic-ai/claude-code` release, otherwise new models are unreachable.
|
|
34
34
|
*/
|
|
35
|
-
export const CLAUDE_CODE_VERSION = '2.1.
|
|
35
|
+
export const CLAUDE_CODE_VERSION = '2.1.275';
|
|
36
36
|
export const CLAUDE_CODE_ENTRYPOINT = 'sdk-cli';
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Build the `user-agent` value for a reported Claude Code version.
|
|
39
|
+
*
|
|
40
|
+
* Both places we report the version (this header and the billing header's
|
|
41
|
+
* `cc_version`) must agree, so callers pass the same resolved version to each
|
|
42
|
+
* rather than reading a second, independently-derived constant.
|
|
43
|
+
*/
|
|
44
|
+
export function formatUserAgent(version) {
|
|
45
|
+
return `claude-cli/${version} (external, cli)`;
|
|
46
|
+
}
|
|
47
|
+
export const USER_AGENT = formatUserAgent(CLAUDE_CODE_VERSION);
|
|
38
48
|
/**
|
|
39
49
|
* Anchors that identify paragraphs to remove from the system prompt.
|
|
40
50
|
* Any paragraph (text between blank lines) containing one of these
|
package/dist/index.d.ts
CHANGED