@cortexkit/anthropic-auth-core 1.23.0 → 2.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.
Files changed (134) hide show
  1. package/README.md +2 -0
  2. package/dist/accounts.d.ts +3 -16
  3. package/dist/cachekeep.d.ts +9 -0
  4. package/dist/claude-code.d.ts +16 -0
  5. package/dist/claustrum-enrollment.d.ts +2 -0
  6. package/dist/claustrum-scoped-roster.d.ts +4 -0
  7. package/dist/claustrum-scoped-runtime.d.ts +3 -0
  8. package/dist/claustrum-scoped.d.ts +14 -0
  9. package/dist/claustrum.d.ts +0 -209
  10. package/dist/commands/account.d.ts +2 -3
  11. package/dist/index.d.ts +44 -1
  12. package/dist/index.js +29700 -38
  13. package/dist/internal-types/LICENSE +21 -0
  14. package/dist/internal-types/commands/builtins.d.ts +71 -0
  15. package/dist/internal-types/commands/index.d.ts +10 -0
  16. package/dist/internal-types/commands/menu.d.ts +61 -0
  17. package/dist/internal-types/commands/model.d.ts +238 -0
  18. package/dist/internal-types/commands/pi.d.ts +23 -0
  19. package/dist/internal-types/commands/seam.d.ts +72 -0
  20. package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
  21. package/dist/internal-types/logger/capture-sink.d.ts +14 -0
  22. package/dist/internal-types/logger/engine.d.ts +100 -0
  23. package/dist/internal-types/logger/index.d.ts +6 -0
  24. package/dist/internal-types/logger/redact.d.ts +11 -0
  25. package/dist/internal-types/pi-slot/index.d.ts +3 -0
  26. package/dist/internal-types/pi-slot/slot.d.ts +49 -0
  27. package/dist/internal-types/quota/codec.d.ts +11 -0
  28. package/dist/internal-types/quota/format.d.ts +46 -0
  29. package/dist/internal-types/quota/index.d.ts +10 -0
  30. package/dist/internal-types/quota/map.d.ts +63 -0
  31. package/dist/internal-types/quota/merge.d.ts +48 -0
  32. package/dist/internal-types/quota/projection.d.ts +64 -0
  33. package/dist/internal-types/store/attribution.d.ts +28 -0
  34. package/dist/internal-types/store/errors.d.ts +55 -0
  35. package/dist/internal-types/store/hooks.d.ts +12 -0
  36. package/dist/internal-types/store/identity.d.ts +39 -0
  37. package/dist/internal-types/store/index.d.ts +21 -0
  38. package/dist/internal-types/store/mutate.d.ts +189 -0
  39. package/dist/internal-types/store/pool.d.ts +196 -0
  40. package/dist/internal-types/store/provider-state.d.ts +131 -0
  41. package/dist/internal-types/store/publication.d.ts +47 -0
  42. package/dist/internal-types/store/pull.d.ts +36 -0
  43. package/dist/internal-types/store/refresh-lock.d.ts +63 -0
  44. package/dist/internal-types/store/refresh.d.ts +72 -0
  45. package/dist/internal-types/store/rows.d.ts +313 -0
  46. package/dist/internal-types/store/runtime.d.ts +36 -0
  47. package/dist/internal-types/store/schema.d.ts +443 -0
  48. package/dist/internal-types/store/settings.d.ts +63 -0
  49. package/dist/internal-types/store/torn.d.ts +78 -0
  50. package/dist/migration-source.d.ts +33 -0
  51. package/dist/models.d.ts +41 -0
  52. package/dist/native-account-runtime.d.ts +121 -0
  53. package/dist/native-account-view.d.ts +126 -0
  54. package/dist/native-command-effects.d.ts +59 -0
  55. package/dist/native-credential-validation.d.ts +42 -0
  56. package/dist/native-custody-activation.d.ts +45 -0
  57. package/dist/native-custody.d.ts +114 -0
  58. package/dist/native-enrollment-authority.d.ts +2 -0
  59. package/dist/native-host-auth-read.d.ts +3 -0
  60. package/dist/native-host-auth-write.d.ts +51 -0
  61. package/dist/native-host-auth.d.ts +12 -0
  62. package/dist/native-local-credential-service.d.ts +76 -0
  63. package/dist/native-local-runtime-readers.d.ts +22 -0
  64. package/dist/native-lock-observer.d.ts +12 -0
  65. package/dist/native-menu-executor.d.ts +243 -0
  66. package/dist/native-menu-model.d.ts +142 -0
  67. package/dist/native-migration-proof.d.ts +28 -0
  68. package/dist/native-migration-source.d.ts +47 -0
  69. package/dist/native-migration.d.ts +66 -0
  70. package/dist/native-quota-codec.d.ts +32 -0
  71. package/dist/native-refresh-coordinator.d.ts +240 -0
  72. package/dist/native-roster-seed.d.ts +115 -0
  73. package/dist/native-runtime-registry.d.ts +19 -0
  74. package/dist/native-runtime.d.ts +204 -0
  75. package/dist/native-transient-account.d.ts +38 -0
  76. package/dist/native-ui.d.ts +45 -0
  77. package/dist/native-usage-publication.d.ts +11 -0
  78. package/dist/native-vault-admission.d.ts +8 -0
  79. package/dist/native-vault-connection.d.ts +33 -0
  80. package/dist/native-vault-paths.d.ts +13 -0
  81. package/dist/native-vault-runtime.d.ts +102 -0
  82. package/dist/native-vault-seed.d.ts +16 -0
  83. package/dist/pool-authority.d.ts +159 -0
  84. package/dist/pool-binding.d.ts +32 -0
  85. package/dist/pool-paths.d.ts +21 -0
  86. package/dist/pool-store.d.ts +32 -0
  87. package/dist/provider-error.d.ts +139 -0
  88. package/dist/quota-manager.d.ts +18 -7
  89. package/dist/relay.d.ts +14 -1
  90. package/dist/request-history.d.ts +34 -0
  91. package/dist/sse.d.ts +81 -0
  92. package/dist/sticky-routing.d.ts +27 -0
  93. package/package.json +9 -4
  94. package/dist/accounts.js +0 -3881
  95. package/dist/auth.js +0 -185
  96. package/dist/cache1h.js +0 -97
  97. package/dist/cachekeep-registry.js +0 -124
  98. package/dist/cachekeep.js +0 -604
  99. package/dist/cch.js +0 -172
  100. package/dist/claude-code.js +0 -403
  101. package/dist/claustrum-enrollment-registry.d.ts +0 -17
  102. package/dist/claustrum-enrollment-registry.js +0 -194
  103. package/dist/claustrum-enrollment.js +0 -485
  104. package/dist/claustrum-scoped-roster.js +0 -194
  105. package/dist/claustrum-scoped-runtime.js +0 -230
  106. package/dist/claustrum-scoped.js +0 -193
  107. package/dist/claustrum.js +0 -1471
  108. package/dist/commands/account.js +0 -368
  109. package/dist/constants.js +0 -83
  110. package/dist/custom-headers.js +0 -102
  111. package/dist/dump.js +0 -616
  112. package/dist/fast.js +0 -66
  113. package/dist/json.js +0 -10
  114. package/dist/killswitch.js +0 -132
  115. package/dist/logger.js +0 -288
  116. package/dist/logging.js +0 -59
  117. package/dist/mid-conversation-output-config.js +0 -89
  118. package/dist/model-remap.js +0 -72
  119. package/dist/models.js +0 -177
  120. package/dist/network-errors.js +0 -27
  121. package/dist/oauth-profile.js +0 -60
  122. package/dist/pkce.js +0 -17
  123. package/dist/prime.js +0 -841
  124. package/dist/provider.js +0 -0
  125. package/dist/quota-header-feed.js +0 -331
  126. package/dist/quota-headers.js +0 -121
  127. package/dist/quota-manager.js +0 -856
  128. package/dist/quotas.js +0 -141
  129. package/dist/relay.js +0 -1303
  130. package/dist/routing.js +0 -94
  131. package/dist/start.js +0 -29
  132. package/dist/sticky-routing.js +0 -541
  133. package/dist/thinking-binding.js +0 -54
  134. package/dist/token-fingerprint.js +0 -8
package/dist/models.js DELETED
@@ -1,177 +0,0 @@
1
- export const CLAUDE_FABLE_5_MODEL_ID = 'claude-fable-5';
2
- export const CLAUDE_MYTHOS_5_MODEL_ID = 'claude-mythos-5';
3
- export const CLAUDE_FABLE_5_1_MODEL_ID = 'claude-fable-5-1';
4
- export const CLAUDE_MYTHOS_5_1_MODEL_ID = 'claude-mythos-5-1';
5
- /**
6
- * Haiku 4.5 model identifier used by `/claude-prime` to start each OAuth
7
- * account's five-hour quota window with a minimal request. Usage is measured
8
- * from response accounting. Kept distinct from the Fable/Mythos pricing block
9
- * above so per-million-token cost estimation does not conflate families.
10
- */
11
- export const CLAUDE_HAIKU_4_5_MODEL_ID = 'claude-haiku-4-5';
12
- /** Remove OpenCode's context-window qualifier before model-family checks. */
13
- export function normalizeAnthropicModelId(model) {
14
- return model.endsWith('[1m]') ? model.slice(0, -4) : model;
15
- }
16
- /**
17
- * Per-million-token USD pricing for Haiku 4.5. Used to project the cumulative
18
- * cost of prime requests from persisted usage counters — never persisted on
19
- * disk; derive at display time so future pricing revisions land in one place.
20
- */
21
- export const CLAUDE_HAIKU_4_5_PRICING = {
22
- input: 1,
23
- output: 5,
24
- };
25
- export const CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS = [
26
- CLAUDE_FABLE_5_1_MODEL_ID,
27
- CLAUDE_MYTHOS_5_1_MODEL_ID,
28
- ];
29
- export const CLAUDE_FABLE_MYTHOS_5_MODEL_IDS = [
30
- CLAUDE_FABLE_5_MODEL_ID,
31
- CLAUDE_MYTHOS_5_MODEL_ID,
32
- ...CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS,
33
- ];
34
- export const CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING = {
35
- type: 'adaptive',
36
- display: 'summarized',
37
- };
38
- export const CLAUDE_FABLE_MYTHOS_5_PRICING = {
39
- input: 10,
40
- output: 50,
41
- cacheRead: 1,
42
- cacheWrite5m: 12.5,
43
- cacheWrite1h: 20,
44
- };
45
- export const CLAUDE_FABLE_MYTHOS_5_1_PRICING = {
46
- input: 10,
47
- output: 50,
48
- cacheRead: 0.25,
49
- cacheWrite5m: 12.5,
50
- cacheWrite1h: 20,
51
- };
52
- export const CLAUDE_FABLE_MYTHOS_5_CONTEXT_WINDOW = 1_000_000;
53
- export const CLAUDE_FABLE_MYTHOS_5_MAX_OUTPUT_TOKENS = 128_000;
54
- export const CLAUDE_FABLE_MYTHOS_5_RELEASE_DATE = '2026-06-09';
55
- export const CLAUDE_FABLE_MYTHOS_5_1_RELEASE_DATE = '2026-09-01';
56
- export const CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS = {
57
- [CLAUDE_FABLE_5_MODEL_ID]: {
58
- id: CLAUDE_FABLE_5_MODEL_ID,
59
- name: 'Claude Fable 5',
60
- },
61
- [CLAUDE_MYTHOS_5_MODEL_ID]: {
62
- id: CLAUDE_MYTHOS_5_MODEL_ID,
63
- name: 'Claude Mythos 5',
64
- limited: true,
65
- },
66
- [CLAUDE_FABLE_5_1_MODEL_ID]: {
67
- id: CLAUDE_FABLE_5_1_MODEL_ID,
68
- name: 'Claude Fable 5.1',
69
- },
70
- [CLAUDE_MYTHOS_5_1_MODEL_ID]: {
71
- id: CLAUDE_MYTHOS_5_1_MODEL_ID,
72
- name: 'Claude Mythos 5.1',
73
- limited: true,
74
- },
75
- };
76
- export const CLAUDE_FABLE_MYTHOS_5_1_MODEL_SPECS = {
77
- [CLAUDE_FABLE_5_1_MODEL_ID]: CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS[CLAUDE_FABLE_5_1_MODEL_ID],
78
- [CLAUDE_MYTHOS_5_1_MODEL_ID]: CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS[CLAUDE_MYTHOS_5_1_MODEL_ID],
79
- };
80
- export function isClaudeFableOrMythos5Model(model) {
81
- if (typeof model !== 'string')
82
- return false;
83
- const normalized = normalizeAnthropicModelId(model);
84
- return CLAUDE_FABLE_MYTHOS_5_MODEL_IDS.some((id) => normalized === id || normalized.startsWith(`${id}-`));
85
- }
86
- export function isClaudeFableOrMythos51Model(model) {
87
- if (typeof model !== 'string')
88
- return false;
89
- const normalized = normalizeAnthropicModelId(model);
90
- return CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS.some((id) => normalized === id || normalized.startsWith(`${id}-`));
91
- }
92
- export function isClaudeFable51Model(model) {
93
- if (typeof model !== 'string')
94
- return false;
95
- const normalized = normalizeAnthropicModelId(model);
96
- return (normalized === CLAUDE_FABLE_5_1_MODEL_ID ||
97
- normalized.startsWith(`${CLAUDE_FABLE_5_1_MODEL_ID}-`));
98
- }
99
- export function getClaudeFableMythos5ReleaseDate(model) {
100
- return isClaudeFableOrMythos51Model(model)
101
- ? CLAUDE_FABLE_MYTHOS_5_1_RELEASE_DATE
102
- : CLAUDE_FABLE_MYTHOS_5_RELEASE_DATE;
103
- }
104
- export const CLAUDE_SONNET_5_MODEL_ID = 'claude-sonnet-5';
105
- /**
106
- * Sonnet 5 enables adaptive thinking by default but ships `display: "omitted"`,
107
- * so the `thinking` field returns empty and the user sees nothing. Injecting
108
- * this makes the adaptive thinking summary visible. Reuses the Fable/Mythos
109
- * shape because the API contract is identical.
110
- */
111
- export const CLAUDE_SONNET_5_ADAPTIVE_THINKING = CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING;
112
- export function isClaudeSonnet5Model(model) {
113
- if (typeof model !== 'string')
114
- return false;
115
- const normalized = normalizeAnthropicModelId(model);
116
- return (normalized === CLAUDE_SONNET_5_MODEL_ID ||
117
- normalized.startsWith(`${CLAUDE_SONNET_5_MODEL_ID}-`));
118
- }
119
- export const CLAUDE_OPUS_5_MODEL_ID = 'claude-opus-5';
120
- /**
121
- * Opus 5 has the same adaptive-thinking-by-default + `display: "omitted"`
122
- * shape as Sonnet 5, so the injected thinking must also be summarized to be
123
- * visible. Kept as its own constant per the PR #100 lesson — hook callers
124
- * should reference the per-family name (`CLAUDE_OPUS_5_ADAPTIVE_THINKING`,
125
- * not the Fable/Mythos alias) so a future divergence between the families
126
- * only changes this re-export, not every call site.
127
- */
128
- export const CLAUDE_OPUS_5_ADAPTIVE_THINKING = CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING;
129
- export function isClaudeOpus5Model(model) {
130
- if (typeof model !== 'string')
131
- return false;
132
- const normalized = normalizeAnthropicModelId(model);
133
- return (!isClaudeOpus55Model(normalized) &&
134
- (normalized === CLAUDE_OPUS_5_MODEL_ID ||
135
- normalized.startsWith(`${CLAUDE_OPUS_5_MODEL_ID}-`)));
136
- }
137
- export const CLAUDE_OPUS_5_5_MODEL_ID = 'claude-opus-5-5';
138
- export const CLAUDE_OPUS_5_5_RELEASE_DATE = '2026-09-18';
139
- export const CLAUDE_OPUS_5_5_CONTEXT_WINDOW = 1_000_000;
140
- export const CLAUDE_OPUS_5_5_MAX_OUTPUT_TOKENS = 128_000;
141
- export const CLAUDE_OPUS_5_5_PRICING = {
142
- input: 4,
143
- output: 20,
144
- cacheRead: 0.2,
145
- cacheWrite5m: 5,
146
- cacheWrite1h: 8,
147
- };
148
- export const CLAUDE_OPUS_5_5_ADAPTIVE_THINKING = CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING;
149
- export function isClaudeOpus55Model(model) {
150
- if (typeof model !== 'string')
151
- return false;
152
- const normalized = normalizeAnthropicModelId(model);
153
- return (normalized === CLAUDE_OPUS_5_5_MODEL_ID ||
154
- normalized.startsWith(`${CLAUDE_OPUS_5_5_MODEL_ID}-`));
155
- }
156
- export function isClaudeOpus5FamilyModel(model) {
157
- return isClaudeOpus5Model(model) || isClaudeOpus55Model(model);
158
- }
159
- export function isOpenAIReasoningSignature(value) {
160
- if (typeof value !== 'string')
161
- return false;
162
- if (value.startsWith('gAAAA'))
163
- return true;
164
- if (!value.startsWith('{'))
165
- return false;
166
- try {
167
- const parsed = JSON.parse(value);
168
- return (parsed.type === 'reasoning' &&
169
- typeof parsed.id === 'string' &&
170
- parsed.id.startsWith('rs_') &&
171
- typeof parsed.encrypted_content === 'string' &&
172
- parsed.encrypted_content.startsWith('gAAAA'));
173
- }
174
- catch {
175
- return false;
176
- }
177
- }
@@ -1,27 +0,0 @@
1
- const TRANSIENT_NETWORK_ERROR_CODES = new Set([
2
- 'EAI_AGAIN',
3
- 'ECONNREFUSED',
4
- 'ECONNRESET',
5
- 'EHOSTUNREACH',
6
- 'ENETUNREACH',
7
- 'ENOTFOUND',
8
- 'ETIMEDOUT',
9
- 'UND_ERR_CONNECT_TIMEOUT',
10
- ]);
11
- function errorField(error, field) {
12
- if (!error || typeof error !== 'object')
13
- return undefined;
14
- const value = error[field];
15
- return typeof value === 'string' ? value : undefined;
16
- }
17
- export function isTransientNetworkError(error) {
18
- const code = errorField(error, 'code');
19
- if (code && TRANSIENT_NETWORK_ERROR_CODES.has(code))
20
- return true;
21
- const message = error instanceof Error
22
- ? error.message
23
- : (errorField(error, 'message') ?? String(error));
24
- if (message.includes('fetch failed'))
25
- return true;
26
- return [...TRANSIENT_NETWORK_ERROR_CODES].some((candidate) => message.includes(candidate));
27
- }
@@ -1,60 +0,0 @@
1
- import { assertNotCustodyTombstone } from './claustrum.js';
2
- const PROFILE_URL = 'https://api.anthropic.com/api/oauth/profile';
3
- export const PROFILE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
4
- export async function fetchOAuthAccountProfile(input) {
5
- // The bearer value is guarded where it becomes a header, like every other builder.
6
- assertNotCustodyTombstone(input.accessToken, 'anthropic');
7
- const response = await (input.fetchImpl ?? fetch)(PROFILE_URL, {
8
- method: 'GET',
9
- signal: input.signal,
10
- headers: {
11
- Authorization: `Bearer ${input.accessToken}`,
12
- Accept: 'application/json',
13
- 'anthropic-beta': 'oauth-2025-04-20',
14
- },
15
- });
16
- if (!response.ok) {
17
- throw new Error(`Claude profile check failed: ${response.status}`);
18
- }
19
- const value = (await response.json());
20
- const tier = value.organization?.rate_limit_tier;
21
- const orgType = value.organization?.organization_type;
22
- if (typeof tier !== 'string' ||
23
- tier.trim() === '' ||
24
- typeof orgType !== 'string' ||
25
- orgType.trim() === '') {
26
- throw new Error('Claude profile response is missing account metadata');
27
- }
28
- return {
29
- tier,
30
- orgType,
31
- checkedAt: input.now?.() ?? Date.now(),
32
- ...(input.accountIdentity !== undefined && {
33
- accountIdentity: input.accountIdentity,
34
- }),
35
- ...(input.providerAccountUuid !== undefined && {
36
- providerAccountUuid: input.providerAccountUuid,
37
- }),
38
- };
39
- }
40
- export function oauthProfileMatchesIdentity(profile, accountIdentity) {
41
- if (!profile)
42
- return false;
43
- if (accountIdentity === undefined)
44
- return true;
45
- return (profile.accountIdentity === undefined ||
46
- profile.accountIdentity === accountIdentity);
47
- }
48
- export function oauthProfileIsFresh(profile, now = Date.now()) {
49
- return Boolean(profile &&
50
- Number.isFinite(profile.checkedAt) &&
51
- now >= profile.checkedAt &&
52
- now - profile.checkedAt < PROFILE_TTL_MS);
53
- }
54
- export function formatOAuthAccountTier(profile) {
55
- const match = profile?.tier.match(/^default_claude_max_(\d+)x$/);
56
- if (!match)
57
- return undefined;
58
- const label = `Max ${match[1]}x`;
59
- return profile?.orgType === 'claude_team' ? `Team · ${label}` : label;
60
- }
package/dist/pkce.js DELETED
@@ -1,17 +0,0 @@
1
- function base64UrlEncode(bytes) {
2
- let bin = '';
3
- for (const byte of bytes)
4
- bin += String.fromCharCode(byte);
5
- return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
6
- }
7
- export async function generatePKCE() {
8
- const buf = new Uint8Array(64);
9
- crypto.getRandomValues(buf);
10
- const verifier = base64UrlEncode(buf);
11
- const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));
12
- return {
13
- verifier,
14
- challenge: base64UrlEncode(new Uint8Array(digest)),
15
- method: 'S256',
16
- };
17
- }