@cortexkit/anthropic-auth-core 1.22.0 → 1.23.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 (48) hide show
  1. package/dist/accounts.d.ts +59 -2
  2. package/dist/accounts.js +666 -115
  3. package/dist/auth.js +3 -0
  4. package/dist/cachekeep.d.ts +18 -1
  5. package/dist/cachekeep.js +108 -82
  6. package/dist/cch.d.ts +11 -1
  7. package/dist/cch.js +48 -3
  8. package/dist/claude-code.d.ts +7 -1
  9. package/dist/claude-code.js +18 -3
  10. package/dist/claustrum-enrollment-registry.d.ts +17 -0
  11. package/dist/claustrum-enrollment-registry.js +194 -0
  12. package/dist/claustrum-enrollment.d.ts +70 -0
  13. package/dist/claustrum-enrollment.js +485 -0
  14. package/dist/claustrum-scoped-roster.d.ts +23 -0
  15. package/dist/claustrum-scoped-roster.js +194 -0
  16. package/dist/claustrum-scoped-runtime.d.ts +28 -0
  17. package/dist/claustrum-scoped-runtime.js +230 -0
  18. package/dist/claustrum-scoped.d.ts +39 -0
  19. package/dist/claustrum-scoped.js +193 -0
  20. package/dist/claustrum.d.ts +149 -6
  21. package/dist/claustrum.js +990 -48
  22. package/dist/commands/account.d.ts +40 -12
  23. package/dist/commands/account.js +138 -9
  24. package/dist/constants.d.ts +3 -2
  25. package/dist/constants.js +3 -2
  26. package/dist/custom-headers.d.ts +3 -0
  27. package/dist/custom-headers.js +102 -0
  28. package/dist/fast.js +1 -1
  29. package/dist/index.d.ts +7 -0
  30. package/dist/index.js +7 -0
  31. package/dist/logger.js +3 -1
  32. package/dist/model-remap.d.ts +27 -0
  33. package/dist/model-remap.js +72 -0
  34. package/dist/models.d.ts +19 -0
  35. package/dist/models.js +48 -12
  36. package/dist/oauth-profile.d.ts +2 -1
  37. package/dist/oauth-profile.js +6 -0
  38. package/dist/prime.d.ts +11 -3
  39. package/dist/prime.js +25 -7
  40. package/dist/quota-header-feed.d.ts +13 -0
  41. package/dist/quota-header-feed.js +60 -8
  42. package/dist/quota-manager.d.ts +15 -1
  43. package/dist/quota-manager.js +73 -22
  44. package/dist/relay.d.ts +8 -0
  45. package/dist/relay.js +72 -12
  46. package/dist/sticky-routing.d.ts +2 -0
  47. package/dist/sticky-routing.js +19 -1
  48. package/package.json +3 -2
@@ -1,5 +1,8 @@
1
+ import type { ProviderAccountUuid } from './claude-code.ts';
2
+ import { type CustodyHandleResolution } from './claustrum.ts';
1
3
  import { type Cache1hMode } from './constants.ts';
2
4
  import { type LogLevel } from './logger.ts';
5
+ export type { ProviderAccountUuid } from './claude-code.ts';
3
6
  export declare const ACCOUNT_FILE_NAME = "anthropic-auth.json";
4
7
  export declare const ACCOUNT_STATE_FILE_NAME = "anthropic-auth-state.json";
5
8
  export declare const QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
@@ -18,7 +21,11 @@ export type AccountBase = {
18
21
  export type OAuthAccount = AccountBase & {
19
22
  type: 'oauth';
20
23
  authLineageId?: string;
24
+ anthropicAccountUuid?: ProviderAccountUuid;
21
25
  claustrumHandle?: string;
26
+ /** Non-secret scoped identity; never a capability handle or bearer token. */
27
+ claustrumScopedCredentialId?: string;
28
+ claustrumScopedState?: string;
22
29
  access?: string;
23
30
  refresh: string;
24
31
  expires?: number;
@@ -33,6 +40,10 @@ export type OAuthAccount = AccountBase & {
33
40
  */
34
41
  prime?: PrimeUsageCounters;
35
42
  };
43
+ export declare function hasNoLocalCredential(account: {
44
+ access?: unknown;
45
+ refresh?: unknown;
46
+ }): boolean;
36
47
  export type ApiKeyAccount = AccountBase & {
37
48
  type: 'api';
38
49
  apiKey?: string;
@@ -43,7 +54,20 @@ export type FallbackAccount = OAuthAccount | ApiKeyAccount;
43
54
  export type ClaustrumAccountGate = {
44
55
  enabled?: boolean;
45
56
  };
57
+ export type ClaustrumMode = 'local' | 'claustrum';
46
58
  export type ClaustrumConfig = {
59
+ mode?: ClaustrumMode;
60
+ handlesFile?: string;
61
+ /** Set by authoritative scoped discovery, not an authentication toggle. */
62
+ scopedRoster?: true;
63
+ /** Authoritative, non-secret primary identity from scoped discovery. */
64
+ primaryAccount?: {
65
+ credentialId: string;
66
+ accountId: ProviderAccountUuid;
67
+ state: string;
68
+ };
69
+ /** Preserve explicit exclusions when a vaulted account disappears and returns. */
70
+ disabledAccountIdentities?: string[];
47
71
  accounts?: Record<string, ClaustrumAccountGate>;
48
72
  };
49
73
  export declare function isOAuthAccount(account: FallbackAccount): account is OAuthAccount;
@@ -105,6 +129,7 @@ export type OAuthAccountProfile = {
105
129
  checkedAt: number;
106
130
  /** Stable account identity; tokenFingerprint remains loadable for legacy state. */
107
131
  accountIdentity?: string;
132
+ providerAccountUuid?: ProviderAccountUuid;
108
133
  tokenFingerprint?: string;
109
134
  };
110
135
  export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWindow>> & {
@@ -244,10 +269,11 @@ export type AccountStorage = {
244
269
  * (to display the provider's real model costs).
245
270
  */
246
271
  export declare function isCostZeroingEnabled(storage: Pick<AccountStorage, 'costZeroing'>): boolean;
247
- export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'authLineageId' | 'claustrumHandle' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile' | 'prime'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
272
+ export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'authLineageId' | 'anthropicAccountUuid' | 'claustrumScopedCredentialId' | 'claustrumScopedState' | 'claustrumHandle' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile' | 'prime'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
248
273
  export type AccountRuntimeState = {
249
274
  version: 1;
250
275
  main?: {
276
+ scopedAccountIdentity?: string;
251
277
  profile?: OAuthAccountProfile;
252
278
  profileToken?: string;
253
279
  quota?: OAuthQuotaSnapshot;
@@ -273,6 +299,7 @@ export type AccountStateSaveScope = {
273
299
  mainRefresh?: boolean;
274
300
  mainPrime?: boolean;
275
301
  accounts?: true | string[];
302
+ setClaustrumHandleAccountIds?: readonly string[];
276
303
  };
277
304
  export type AccountManagerOptions = {
278
305
  now?: () => number;
@@ -305,14 +332,34 @@ export declare function loadAccounts(path?: string): Promise<AccountStorage | nu
305
332
  export declare function quotaSnapshotCheckedAt(quota: OAuthQuotaSnapshot | undefined): number;
306
333
  export declare function quotaFieldSource(snapshot: OAuthQuotaSnapshot | undefined, field: QuotaFieldName): QuotaFieldSource | undefined;
307
334
  export declare function mergeHeaderQuotaForPersistence(existing: OAuthQuotaSnapshot | undefined, incoming: OAuthQuotaSnapshot): OAuthQuotaSnapshot;
308
- export declare function isClaustrumEnabledForAccount(storage: AccountStorage, accountId: string): boolean;
335
+ export declare function getClaustrumMode(storage: AccountStorage | null): ClaustrumMode;
336
+ export declare function isOAuthAccountVaultOwned(storage: AccountStorage | null, account: FallbackAccount, binding?: CustodyHandleResolution | undefined): boolean;
337
+ export declare function setClaustrumModePersistent(mode: ClaustrumMode, path?: string): Promise<'changed' | 'unchanged'>;
338
+ export declare function clearClaustrumHandlePersistent(input: {
339
+ id: string;
340
+ path?: string;
341
+ }): Promise<'updated' | 'missing' | 'ineligible'>;
309
342
  export interface SaveAccountsOptions {
310
343
  /** Account ids intentionally removed by this mutation. */
311
344
  removedAccountIds?: readonly string[];
312
345
  /** Preserve disk order when a stale snapshot is missing newer accounts. */
313
346
  preserveExistingAccountOrder?: boolean;
347
+ setClaustrumHandleAccountIds?: readonly string[];
314
348
  }
315
349
  export declare function saveAccounts(storage: AccountStorage, path?: string, options?: SaveAccountsOptions): Promise<void>;
350
+ /** Read-modify-write account configuration under the existing config/state lock order.
351
+ * The callback is synchronous: network discovery must happen under its own outer
352
+ * lease, never while holding the config lock. Do not call another persistence API
353
+ * from the callback.
354
+ */
355
+ export declare function mutateAccountsPersistent<T>(path: string, mutate: (storage: AccountStorage) => {
356
+ storage: AccountStorage;
357
+ result: T;
358
+ options?: SaveAccountsOptions;
359
+ save?: boolean;
360
+ }, options?: {
361
+ assertAuthority?: () => Promise<void>;
362
+ }): Promise<T>;
316
363
  export declare function getOrCreateMainAccountId(path?: string, createId?: () => string): Promise<string>;
317
364
  export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
318
365
  export declare function saveOAuthProfileState(input: {
@@ -331,6 +378,7 @@ export declare function acquireRefreshFileLock(options: {
331
378
  onStep?: (step: 'stale-marker-stat' | 'stale-marker-claimed' | 'stale-lock-confirmed' | 'eviction-marker-acquired') => void | Promise<void>;
332
379
  }): Promise<{
333
380
  release: () => Promise<void>;
381
+ assertOwned: () => Promise<void>;
334
382
  } | null>;
335
383
  export declare function isCache1hPersistentlyEnabled(storage: AccountStorage | null): boolean;
336
384
  export declare function getCache1hPersistentMode(storage: AccountStorage | null): Cache1hMode;
@@ -459,6 +507,13 @@ export declare function fetchOAuthQuotaSnapshot(input: {
459
507
  now?: () => number;
460
508
  }): Promise<OAuthQuotaSnapshot>;
461
509
  export declare function upsertAccount(storage: AccountStorage, account: FallbackAccount): void;
510
+ export declare function persistFallbackQuotaHeaderPersistent(input: {
511
+ accountId: string;
512
+ authLineageId?: string;
513
+ quota: OAuthQuotaSnapshot;
514
+ anthropicAccountUuid?: ProviderAccountUuid;
515
+ }, path?: string): Promise<boolean>;
516
+ export declare function fallbackAccountUuidForLineage(account: OAuthAccount | undefined, authLineageId?: string): string | null;
462
517
  export declare function removeAccount(storage: AccountStorage, id: string): boolean;
463
518
  export declare function reorderAccounts(storage: AccountStorage, orderedIds: string[]): void;
464
519
  export declare function setAccountEnabled(storage: AccountStorage, id: string, enabled: boolean): boolean;
@@ -467,6 +522,7 @@ export declare class FallbackAccountManager {
467
522
  private readonly fetchImpl;
468
523
  private readonly configPath;
469
524
  private readonly refreshPromises;
525
+ private readonly custodyVerificationAccounts;
470
526
  private refreshTimer;
471
527
  private quotaTimer;
472
528
  readonly quotaManager: import('./quota-manager.ts').QuotaManager | null;
@@ -487,6 +543,7 @@ export declare class FallbackAccountManager {
487
543
  save(storage: AccountStorage, accountIds?: string[]): Promise<void>;
488
544
  startBackgroundRefresh(): Promise<void>;
489
545
  stopBackgroundRefresh(): void;
546
+ withAccountRefreshLock<T>(accountId: string, fn: () => Promise<T>): Promise<T>;
490
547
  getUsableFallbackAccounts(existingStorage?: AccountStorage | null, options?: {
491
548
  modelId?: string;
492
549
  }): Promise<OAuthAccount[]>;