@cortexkit/anthropic-auth-core 1.22.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 (133) hide show
  1. package/README.md +2 -0
  2. package/dist/accounts.d.ts +52 -8
  3. package/dist/cachekeep.d.ts +27 -1
  4. package/dist/cch.d.ts +11 -1
  5. package/dist/claude-code.d.ts +23 -1
  6. package/dist/claustrum-enrollment.d.ts +72 -0
  7. package/dist/claustrum-scoped-roster.d.ts +27 -0
  8. package/dist/claustrum-scoped-runtime.d.ts +31 -0
  9. package/dist/claustrum-scoped.d.ts +53 -0
  10. package/dist/claustrum.d.ts +16 -82
  11. package/dist/commands/account.d.ts +38 -11
  12. package/dist/constants.d.ts +3 -2
  13. package/dist/custom-headers.d.ts +3 -0
  14. package/dist/index.d.ts +50 -0
  15. package/dist/index.js +29700 -31
  16. package/dist/internal-types/LICENSE +21 -0
  17. package/dist/internal-types/commands/builtins.d.ts +71 -0
  18. package/dist/internal-types/commands/index.d.ts +10 -0
  19. package/dist/internal-types/commands/menu.d.ts +61 -0
  20. package/dist/internal-types/commands/model.d.ts +238 -0
  21. package/dist/internal-types/commands/pi.d.ts +23 -0
  22. package/dist/internal-types/commands/seam.d.ts +72 -0
  23. package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
  24. package/dist/internal-types/logger/capture-sink.d.ts +14 -0
  25. package/dist/internal-types/logger/engine.d.ts +100 -0
  26. package/dist/internal-types/logger/index.d.ts +6 -0
  27. package/dist/internal-types/logger/redact.d.ts +11 -0
  28. package/dist/internal-types/pi-slot/index.d.ts +3 -0
  29. package/dist/internal-types/pi-slot/slot.d.ts +49 -0
  30. package/dist/internal-types/quota/codec.d.ts +11 -0
  31. package/dist/internal-types/quota/format.d.ts +46 -0
  32. package/dist/internal-types/quota/index.d.ts +10 -0
  33. package/dist/internal-types/quota/map.d.ts +63 -0
  34. package/dist/internal-types/quota/merge.d.ts +48 -0
  35. package/dist/internal-types/quota/projection.d.ts +64 -0
  36. package/dist/internal-types/store/attribution.d.ts +28 -0
  37. package/dist/internal-types/store/errors.d.ts +55 -0
  38. package/dist/internal-types/store/hooks.d.ts +12 -0
  39. package/dist/internal-types/store/identity.d.ts +39 -0
  40. package/dist/internal-types/store/index.d.ts +21 -0
  41. package/dist/internal-types/store/mutate.d.ts +189 -0
  42. package/dist/internal-types/store/pool.d.ts +196 -0
  43. package/dist/internal-types/store/provider-state.d.ts +131 -0
  44. package/dist/internal-types/store/publication.d.ts +47 -0
  45. package/dist/internal-types/store/pull.d.ts +36 -0
  46. package/dist/internal-types/store/refresh-lock.d.ts +63 -0
  47. package/dist/internal-types/store/refresh.d.ts +72 -0
  48. package/dist/internal-types/store/rows.d.ts +313 -0
  49. package/dist/internal-types/store/runtime.d.ts +36 -0
  50. package/dist/internal-types/store/schema.d.ts +443 -0
  51. package/dist/internal-types/store/settings.d.ts +63 -0
  52. package/dist/internal-types/store/torn.d.ts +78 -0
  53. package/dist/migration-source.d.ts +33 -0
  54. package/dist/model-remap.d.ts +27 -0
  55. package/dist/models.d.ts +60 -0
  56. package/dist/native-account-runtime.d.ts +121 -0
  57. package/dist/native-account-view.d.ts +126 -0
  58. package/dist/native-command-effects.d.ts +59 -0
  59. package/dist/native-credential-validation.d.ts +42 -0
  60. package/dist/native-custody-activation.d.ts +45 -0
  61. package/dist/native-custody.d.ts +114 -0
  62. package/dist/native-enrollment-authority.d.ts +2 -0
  63. package/dist/native-host-auth-read.d.ts +3 -0
  64. package/dist/native-host-auth-write.d.ts +51 -0
  65. package/dist/native-host-auth.d.ts +12 -0
  66. package/dist/native-local-credential-service.d.ts +76 -0
  67. package/dist/native-local-runtime-readers.d.ts +22 -0
  68. package/dist/native-lock-observer.d.ts +12 -0
  69. package/dist/native-menu-executor.d.ts +243 -0
  70. package/dist/native-menu-model.d.ts +142 -0
  71. package/dist/native-migration-proof.d.ts +28 -0
  72. package/dist/native-migration-source.d.ts +47 -0
  73. package/dist/native-migration.d.ts +66 -0
  74. package/dist/native-quota-codec.d.ts +32 -0
  75. package/dist/native-refresh-coordinator.d.ts +240 -0
  76. package/dist/native-roster-seed.d.ts +115 -0
  77. package/dist/native-runtime-registry.d.ts +19 -0
  78. package/dist/native-runtime.d.ts +204 -0
  79. package/dist/native-transient-account.d.ts +38 -0
  80. package/dist/native-ui.d.ts +45 -0
  81. package/dist/native-usage-publication.d.ts +11 -0
  82. package/dist/native-vault-admission.d.ts +8 -0
  83. package/dist/native-vault-connection.d.ts +33 -0
  84. package/dist/native-vault-paths.d.ts +13 -0
  85. package/dist/native-vault-runtime.d.ts +102 -0
  86. package/dist/native-vault-seed.d.ts +16 -0
  87. package/dist/oauth-profile.d.ts +2 -1
  88. package/dist/pool-authority.d.ts +159 -0
  89. package/dist/pool-binding.d.ts +32 -0
  90. package/dist/pool-paths.d.ts +21 -0
  91. package/dist/pool-store.d.ts +32 -0
  92. package/dist/prime.d.ts +11 -3
  93. package/dist/provider-error.d.ts +139 -0
  94. package/dist/quota-header-feed.d.ts +13 -0
  95. package/dist/quota-manager.d.ts +30 -5
  96. package/dist/relay.d.ts +22 -1
  97. package/dist/request-history.d.ts +34 -0
  98. package/dist/sse.d.ts +81 -0
  99. package/dist/sticky-routing.d.ts +29 -0
  100. package/package.json +9 -3
  101. package/dist/accounts.js +0 -3330
  102. package/dist/auth.js +0 -182
  103. package/dist/cache1h.js +0 -97
  104. package/dist/cachekeep-registry.js +0 -124
  105. package/dist/cachekeep.js +0 -578
  106. package/dist/cch.js +0 -127
  107. package/dist/claude-code.js +0 -388
  108. package/dist/claustrum.js +0 -529
  109. package/dist/commands/account.js +0 -239
  110. package/dist/constants.js +0 -82
  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 -286
  116. package/dist/logging.js +0 -59
  117. package/dist/mid-conversation-output-config.js +0 -89
  118. package/dist/models.js +0 -141
  119. package/dist/network-errors.js +0 -27
  120. package/dist/oauth-profile.js +0 -54
  121. package/dist/pkce.js +0 -17
  122. package/dist/prime.js +0 -823
  123. package/dist/provider.js +0 -0
  124. package/dist/quota-header-feed.js +0 -279
  125. package/dist/quota-headers.js +0 -121
  126. package/dist/quota-manager.js +0 -805
  127. package/dist/quotas.js +0 -141
  128. package/dist/relay.js +0 -1243
  129. package/dist/routing.js +0 -94
  130. package/dist/start.js +0 -29
  131. package/dist/sticky-routing.js +0 -523
  132. package/dist/thinking-binding.js +0 -54
  133. package/dist/token-fingerprint.js +0 -8
package/dist/models.js DELETED
@@ -1,141 +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
- /**
13
- * Per-million-token USD pricing for Haiku 4.5. Used to project the cumulative
14
- * cost of prime requests from persisted usage counters — never persisted on
15
- * disk; derive at display time so future pricing revisions land in one place.
16
- */
17
- export const CLAUDE_HAIKU_4_5_PRICING = {
18
- input: 1,
19
- output: 5,
20
- };
21
- export const CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS = [
22
- CLAUDE_FABLE_5_1_MODEL_ID,
23
- CLAUDE_MYTHOS_5_1_MODEL_ID,
24
- ];
25
- export const CLAUDE_FABLE_MYTHOS_5_MODEL_IDS = [
26
- CLAUDE_FABLE_5_MODEL_ID,
27
- CLAUDE_MYTHOS_5_MODEL_ID,
28
- ...CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS,
29
- ];
30
- export const CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING = {
31
- type: 'adaptive',
32
- display: 'summarized',
33
- };
34
- export const CLAUDE_FABLE_MYTHOS_5_PRICING = {
35
- input: 10,
36
- output: 50,
37
- cacheRead: 1,
38
- cacheWrite5m: 12.5,
39
- cacheWrite1h: 20,
40
- };
41
- export const CLAUDE_FABLE_MYTHOS_5_1_PRICING = {
42
- input: 10,
43
- output: 50,
44
- cacheRead: 0.25,
45
- cacheWrite5m: 12.5,
46
- cacheWrite1h: 20,
47
- };
48
- export const CLAUDE_FABLE_MYTHOS_5_CONTEXT_WINDOW = 1_000_000;
49
- export const CLAUDE_FABLE_MYTHOS_5_MAX_OUTPUT_TOKENS = 128_000;
50
- export const CLAUDE_FABLE_MYTHOS_5_RELEASE_DATE = '2026-06-09';
51
- export const CLAUDE_FABLE_MYTHOS_5_1_RELEASE_DATE = '2026-09-01';
52
- export const CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS = {
53
- [CLAUDE_FABLE_5_MODEL_ID]: {
54
- id: CLAUDE_FABLE_5_MODEL_ID,
55
- name: 'Claude Fable 5',
56
- },
57
- [CLAUDE_MYTHOS_5_MODEL_ID]: {
58
- id: CLAUDE_MYTHOS_5_MODEL_ID,
59
- name: 'Claude Mythos 5',
60
- limited: true,
61
- },
62
- [CLAUDE_FABLE_5_1_MODEL_ID]: {
63
- id: CLAUDE_FABLE_5_1_MODEL_ID,
64
- name: 'Claude Fable 5.1',
65
- },
66
- [CLAUDE_MYTHOS_5_1_MODEL_ID]: {
67
- id: CLAUDE_MYTHOS_5_1_MODEL_ID,
68
- name: 'Claude Mythos 5.1',
69
- limited: true,
70
- },
71
- };
72
- export const CLAUDE_FABLE_MYTHOS_5_1_MODEL_SPECS = {
73
- [CLAUDE_FABLE_5_1_MODEL_ID]: CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS[CLAUDE_FABLE_5_1_MODEL_ID],
74
- [CLAUDE_MYTHOS_5_1_MODEL_ID]: CLAUDE_FABLE_MYTHOS_5_MODEL_SPECS[CLAUDE_MYTHOS_5_1_MODEL_ID],
75
- };
76
- export function isClaudeFableOrMythos5Model(model) {
77
- return (typeof model === 'string' &&
78
- CLAUDE_FABLE_MYTHOS_5_MODEL_IDS.some((id) => model === id || model.startsWith(`${id}-`)));
79
- }
80
- export function isClaudeFableOrMythos51Model(model) {
81
- return (typeof model === 'string' &&
82
- CLAUDE_FABLE_MYTHOS_5_1_MODEL_IDS.some((id) => model === id || model.startsWith(`${id}-`)));
83
- }
84
- export function isClaudeFable51Model(model) {
85
- if (typeof model !== 'string')
86
- return false;
87
- return (model === CLAUDE_FABLE_5_1_MODEL_ID ||
88
- model.startsWith(`${CLAUDE_FABLE_5_1_MODEL_ID}-`));
89
- }
90
- export function getClaudeFableMythos5ReleaseDate(model) {
91
- return isClaudeFableOrMythos51Model(model)
92
- ? CLAUDE_FABLE_MYTHOS_5_1_RELEASE_DATE
93
- : CLAUDE_FABLE_MYTHOS_5_RELEASE_DATE;
94
- }
95
- export const CLAUDE_SONNET_5_MODEL_ID = 'claude-sonnet-5';
96
- /**
97
- * Sonnet 5 enables adaptive thinking by default but ships `display: "omitted"`,
98
- * so the `thinking` field returns empty and the user sees nothing. Injecting
99
- * this makes the adaptive thinking summary visible. Reuses the Fable/Mythos
100
- * shape because the API contract is identical.
101
- */
102
- export const CLAUDE_SONNET_5_ADAPTIVE_THINKING = CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING;
103
- export function isClaudeSonnet5Model(model) {
104
- return (typeof model === 'string' &&
105
- (model === CLAUDE_SONNET_5_MODEL_ID ||
106
- model.startsWith(`${CLAUDE_SONNET_5_MODEL_ID}-`)));
107
- }
108
- export const CLAUDE_OPUS_5_MODEL_ID = 'claude-opus-5';
109
- /**
110
- * Opus 5 has the same adaptive-thinking-by-default + `display: "omitted"`
111
- * shape as Sonnet 5, so the injected thinking must also be summarized to be
112
- * visible. Kept as its own constant per the PR #100 lesson — hook callers
113
- * should reference the per-family name (`CLAUDE_OPUS_5_ADAPTIVE_THINKING`,
114
- * not the Fable/Mythos alias) so a future divergence between the families
115
- * only changes this re-export, not every call site.
116
- */
117
- export const CLAUDE_OPUS_5_ADAPTIVE_THINKING = CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING;
118
- export function isClaudeOpus5Model(model) {
119
- return (typeof model === 'string' &&
120
- (model === CLAUDE_OPUS_5_MODEL_ID ||
121
- model.startsWith(`${CLAUDE_OPUS_5_MODEL_ID}-`)));
122
- }
123
- export function isOpenAIReasoningSignature(value) {
124
- if (typeof value !== 'string')
125
- return false;
126
- if (value.startsWith('gAAAA'))
127
- return true;
128
- if (!value.startsWith('{'))
129
- return false;
130
- try {
131
- const parsed = JSON.parse(value);
132
- return (parsed.type === 'reasoning' &&
133
- typeof parsed.id === 'string' &&
134
- parsed.id.startsWith('rs_') &&
135
- typeof parsed.encrypted_content === 'string' &&
136
- parsed.encrypted_content.startsWith('gAAAA'));
137
- }
138
- catch {
139
- return false;
140
- }
141
- }
@@ -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,54 +0,0 @@
1
- const PROFILE_URL = 'https://api.anthropic.com/api/oauth/profile';
2
- export const PROFILE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
3
- export async function fetchOAuthAccountProfile(input) {
4
- const response = await (input.fetchImpl ?? fetch)(PROFILE_URL, {
5
- method: 'GET',
6
- signal: input.signal,
7
- headers: {
8
- Authorization: `Bearer ${input.accessToken}`,
9
- Accept: 'application/json',
10
- 'anthropic-beta': 'oauth-2025-04-20',
11
- },
12
- });
13
- if (!response.ok) {
14
- throw new Error(`Claude profile check failed: ${response.status}`);
15
- }
16
- const value = (await response.json());
17
- const tier = value.organization?.rate_limit_tier;
18
- const orgType = value.organization?.organization_type;
19
- if (typeof tier !== 'string' ||
20
- tier.trim() === '' ||
21
- typeof orgType !== 'string' ||
22
- orgType.trim() === '') {
23
- throw new Error('Claude profile response is missing account metadata');
24
- }
25
- return {
26
- tier,
27
- orgType,
28
- checkedAt: input.now?.() ?? Date.now(),
29
- ...(input.accountIdentity !== undefined && {
30
- accountIdentity: input.accountIdentity,
31
- }),
32
- };
33
- }
34
- export function oauthProfileMatchesIdentity(profile, accountIdentity) {
35
- if (!profile)
36
- return false;
37
- if (accountIdentity === undefined)
38
- return true;
39
- return (profile.accountIdentity === undefined ||
40
- profile.accountIdentity === accountIdentity);
41
- }
42
- export function oauthProfileIsFresh(profile, now = Date.now()) {
43
- return Boolean(profile &&
44
- Number.isFinite(profile.checkedAt) &&
45
- now >= profile.checkedAt &&
46
- now - profile.checkedAt < PROFILE_TTL_MS);
47
- }
48
- export function formatOAuthAccountTier(profile) {
49
- const match = profile?.tier.match(/^default_claude_max_(\d+)x$/);
50
- if (!match)
51
- return undefined;
52
- const label = `Max ${match[1]}x`;
53
- return profile?.orgType === 'claude_team' ? `Team · ${label}` : label;
54
- }
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
- }