@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,4 +1,5 @@
1
1
  import { type BindIdentity, type CatalogEntry, type CloseRouteOptions, type ManagedCallOptions, type ManagedCloseRouteOptions, type RequestOptions, type RouteHandle, type RouteOpenOptions, type RouteTarget, SubcClient, type SubscribeOptions, type Subscription } from '@cortexkit/subc-client';
2
+ import type { ClaustrumConfig, OAuthAccount } from './accounts.ts';
2
3
  export type ClaustrumEndpoint = {
3
4
  host: string;
4
5
  port: number;
@@ -16,10 +17,22 @@ export type ClaustrumDetection = {
16
17
  path: string;
17
18
  reason: string;
18
19
  };
19
- export declare function getDefaultClaustrumConnectionPath(): string;
20
- export declare function detectClaustrumConnection(path?: string): Promise<ClaustrumDetection>;
20
+ export declare const PRODUCTION_CLAUSTRUM_CONNECTION_FILE_NAME = "subc-connection.json";
21
+ export declare function findExistingClaustrumConnectionPath(env?: NodeJS.ProcessEnv): string | undefined;
22
+ export declare function getDefaultClaustrumConnectionPath(env?: NodeJS.ProcessEnv): string;
23
+ export declare function resolveClaustrumConnectionPath(explicit?: string, env?: NodeJS.ProcessEnv): string;
24
+ type CustodyHandlesEnvironment = Readonly<Record<string, string | undefined>>;
25
+ export declare function resolveCustodyHandlesPath(config: Pick<ClaustrumConfig, 'handlesFile'> | undefined, env: CustodyHandlesEnvironment): string;
26
+ export declare function getDefaultClaustrumHandlesPath(): string;
27
+ export declare function detectClaustrumConnection(explicitPath?: string): Promise<ClaustrumDetection>;
21
28
  export declare const CUSTODY_TOMBSTONE_PREFIX = "claustrum-tombstone:v1:";
22
29
  export declare function custodyTombstoneKey(provider: string): string;
30
+ export declare function custodyTombstoneOAuth(provider: string): {
31
+ type: 'oauth';
32
+ access: '';
33
+ refresh: string;
34
+ expires: 0;
35
+ };
23
36
  export declare function isCustodyTombstoneValue(value: unknown): value is string;
24
37
  export declare function isCustodyTombstoneOAuth(auth: unknown, provider: string): boolean;
25
38
  export declare class CustodyTombstoneRefreshError extends Error {
@@ -27,6 +40,11 @@ export declare class CustodyTombstoneRefreshError extends Error {
27
40
  readonly code = "custody_tombstone_refresh";
28
41
  constructor(provider: string);
29
42
  }
43
+ export declare class CustodyTombstoneLoginError extends Error {
44
+ readonly provider: string;
45
+ readonly code = "custody_tombstone_login";
46
+ constructor(provider: string);
47
+ }
30
48
  export declare function assertNotCustodyTombstone(refreshToken: unknown, provider: string): void;
31
49
  export type CustodyHandleAccount = {
32
50
  label: string;
@@ -34,13 +52,133 @@ export type CustodyHandleAccount = {
34
52
  credentialId: string;
35
53
  };
36
54
  export type CustodyHandleManifest = {
55
+ version: 1;
56
+ provider: 'anthropic';
57
+ serve: 'anthropic-auth';
58
+ accounts: ReadonlyArray<CustodyHandleAccount>;
59
+ superseded: ReadonlySet<string>;
60
+ corruptLabels?: ReadonlySet<string>;
61
+ };
62
+ export type CustodyHandleResolution = {
63
+ status: 'resolved';
64
+ source: 'manifest';
65
+ handle: string;
66
+ credentialId: string;
67
+ } | {
68
+ status: 'resolved';
69
+ source: 'legacy';
70
+ handle: string;
71
+ } | {
72
+ status: 'unresolved';
73
+ reason: 'missing-label' | 'invalid-label' | 'duplicate-label' | 'missing-entry' | 'foreign-serve' | 'superseded' | 'corrupt-binding' | 'unknown-identity';
74
+ };
75
+ type ParsedCustodyHandleManifest = {
76
+ version: 1;
37
77
  provider: string;
38
78
  serve: string;
39
- shape: string;
40
- accounts: CustodyHandleAccount[];
79
+ accounts: ReadonlyArray<CustodyHandleAccount>;
80
+ superseded: ReadonlySet<string>;
81
+ corruptLabels: ReadonlySet<string>;
41
82
  };
83
+ export declare function isValidCustodyLabel(value: unknown): value is string;
42
84
  export declare function isValidCustodyHandle(value: unknown): value is string;
43
- export declare function readCustodyHandles(json: unknown, provider: string): CustodyHandleManifest;
85
+ export declare function custodyCredentialId(label: string): string;
86
+ export declare function custodyCredentialIdFromResolution(resolution: CustodyHandleResolution, label: string): string;
87
+ /**
88
+ * | manifest state | legacy handle | result |
89
+ * | --- | --- | --- |
90
+ * | matching ready entry | any | manifest handle |
91
+ * | absent or invalid | present | legacy handle |
92
+ * | no matching ready entry | present | legacy handle |
93
+ * | foreign serve | any | unresolved |
94
+ * | superseded matching entry | any | unresolved |
95
+ */
96
+ export declare function resolveCustodyHandle(input: {
97
+ account: OAuthAccount;
98
+ manifest: CustodyHandleManifest | undefined;
99
+ duplicateOAuthLabels?: ReadonlySet<string>;
100
+ }): CustodyHandleResolution;
101
+ export declare function readCustodyHandles(json: unknown, provider: string, serve: string): ParsedCustodyHandleManifest;
102
+ type CustodyHandleManifestReadResult = {
103
+ status: 'ready';
104
+ manifest: CustodyHandleManifest;
105
+ } | {
106
+ status: 'absent';
107
+ } | {
108
+ status: 'ignored';
109
+ reason: 'foreign-serve' | 'missing-provider';
110
+ } | {
111
+ status: 'invalid';
112
+ reason: string;
113
+ };
114
+ export declare const CUSTODY_MANIFEST_SELECTION_ERROR_CODES: readonly ['foreign-serve', 'invalid-label', 'missing-provider'];
115
+ type CustodyManifestSelectionErrorCode = (typeof CUSTODY_MANIFEST_SELECTION_ERROR_CODES)[number];
116
+ export declare class CustodyManifestSelectionError extends Error {
117
+ readonly code: CustodyManifestSelectionErrorCode;
118
+ constructor(code: CustodyManifestSelectionErrorCode);
119
+ }
120
+ export declare class CustodyHandleManifestReader {
121
+ #private;
122
+ constructor(options: {
123
+ path: string;
124
+ provider: 'anthropic';
125
+ serve: 'anthropic-auth';
126
+ expectedUid?: number;
127
+ });
128
+ read(): Promise<CustodyHandleManifestReadResult>;
129
+ }
130
+ export type CustodyHandleManifestWriteResult = {
131
+ status: 'written' | 'unchanged';
132
+ } | {
133
+ status: 'refused';
134
+ reason: string;
135
+ code?: CustodyManifestLockErrorCode;
136
+ };
137
+ export type CustodyHandleManifestRemovalResult = 'removed' | 'missing' | {
138
+ status: 'refused';
139
+ code?: CustodyManifestLockErrorCode;
140
+ };
141
+ export declare const CUSTODY_MANIFEST_LOCK_TTL_MS = 30000;
142
+ export declare const CUSTODY_MANIFEST_LOCK_RENEW_MS = 10000;
143
+ export declare const CUSTODY_MANIFEST_LOCK_RETRY_MIN_MS = 50;
144
+ export declare const CUSTODY_MANIFEST_LOCK_RETRY_MAX_MS = 150;
145
+ export type CustodyManifestLockTestOptions = Partial<{
146
+ ttlMs: number;
147
+ retryMinMs: number;
148
+ retryMaxMs: number;
149
+ renewalIntervalMs: number;
150
+ now: () => number;
151
+ setIntervalImpl: typeof globalThis.setInterval;
152
+ clearIntervalImpl: typeof globalThis.clearInterval;
153
+ afterStaleOwnerRead: () => void | Promise<void>;
154
+ beforeRename: () => void | Promise<void>;
155
+ }>;
156
+ export declare function __setCustodyManifestLockTestOptions(options?: CustodyManifestLockTestOptions): void;
157
+ export declare const CUSTODY_MANIFEST_LOCK_ERROR_CODES: readonly ['lock_busy', 'owner_invalid', 'renewal_failed'];
158
+ export type CustodyManifestLockErrorCode = (typeof CUSTODY_MANIFEST_LOCK_ERROR_CODES)[number];
159
+ export declare class CustodyManifestLockError extends Error {
160
+ readonly code: CustodyManifestLockErrorCode;
161
+ constructor(message: string, code: CustodyManifestLockErrorCode);
162
+ }
163
+ export declare class CustodyManifestLockBusyError extends CustodyManifestLockError {
164
+ constructor(message: string);
165
+ }
166
+ export declare class CustodyManifestLockOwnerInvalidError extends CustodyManifestLockError {
167
+ constructor(message: string);
168
+ }
169
+ export declare class CustodyManifestLockLeaseLostError extends CustodyManifestLockError {
170
+ constructor(message: string);
171
+ }
172
+ export declare function __deriveCustodyManifestStaleLockPrefix(lockPath: string, pathBasename: (path: string) => string): string;
173
+ export declare function withCustodyManifestLock<T>(path: string, fn: (assertLease: () => Promise<void>, nonce: string) => Promise<T>): Promise<T>;
174
+ type CustodyHandleManifestWriteInput = {
175
+ path: string;
176
+ entry: CustodyHandleAccount;
177
+ expectedUid?: number;
178
+ };
179
+ export declare function writeCustodyHandleManifestEntry(input: CustodyHandleManifestWriteInput): Promise<CustodyHandleManifestWriteResult>;
180
+ export declare function removeCustodyHandleManifestEntry(input: CustodyHandleManifestWriteInput): Promise<CustodyHandleManifestRemovalResult>;
181
+ export declare function writeCustodyHandleManifestEntryLocked(input: CustodyHandleManifestWriteInput, assertLease: () => Promise<void>, lockNonce: string): Promise<CustodyHandleManifestWriteResult>;
44
182
  export type ClaustrumClientOptions = {
45
183
  connectionFile?: string;
46
184
  handshakeTimeoutMs?: number;
@@ -77,6 +215,7 @@ export type ClaustrumCredential = {
77
215
  recordVersion: number;
78
216
  projectId?: string;
79
217
  accountId?: string;
218
+ credentialId?: string;
80
219
  };
81
220
  export type ClaustrumServedCredential = Pick<ClaustrumCredential, 'recordVersion'>;
82
221
  export type ClaustrumReporterSource = 'direct' | 'relay_status_field' | 'relay_message_parse';
@@ -94,8 +233,11 @@ export type ClaustrumCredentialCacheOptions = {
94
233
  export declare class ClaustrumCredentialCache {
95
234
  #private;
96
235
  constructor(client: ClaustrumClient, options?: ClaustrumCredentialCacheOptions);
97
- get(handle: string, minTtlMs?: number): Promise<ClaustrumCredential>;
236
+ get(handle: string, minTtlMs?: number, options?: {
237
+ cacheIf?: () => boolean;
238
+ }): Promise<ClaustrumCredential>;
98
239
  peek(handle: string): ClaustrumCredential | undefined;
240
+ abandonPending(handle: string): void;
99
241
  seedForTest(handle: string, credential: ClaustrumCredential): void;
100
242
  reduceMinTtlMs(): number;
101
243
  reportAuthFailure(handle: string, providerStatus: number, servedCredential: ClaustrumServedCredential, reporterSource?: ClaustrumReporterSource): Promise<void>;
@@ -107,3 +249,4 @@ export type ConnectClaustrumCredentialCacheOptions = ClaustrumClientOptions & Cl
107
249
  enabled?: boolean;
108
250
  };
109
251
  export declare function connectClaustrumCredentialCache(options?: ConnectClaustrumCredentialCacheOptions): Promise<ClaustrumCredentialCache | null>;
252
+ export {};