@cortexkit/anthropic-auth-core 1.21.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 (59) hide show
  1. package/README.md +1 -1
  2. package/dist/accounts.d.ts +100 -3
  3. package/dist/accounts.js +1099 -169
  4. package/dist/auth.js +6 -10
  5. package/dist/cachekeep.d.ts +18 -1
  6. package/dist/cachekeep.js +108 -82
  7. package/dist/cch.d.ts +23 -9
  8. package/dist/cch.js +104 -21
  9. package/dist/claude-code.d.ts +8 -3
  10. package/dist/claude-code.js +24 -7
  11. package/dist/claustrum-enrollment-registry.d.ts +17 -0
  12. package/dist/claustrum-enrollment-registry.js +194 -0
  13. package/dist/claustrum-enrollment.d.ts +70 -0
  14. package/dist/claustrum-enrollment.js +485 -0
  15. package/dist/claustrum-scoped-roster.d.ts +23 -0
  16. package/dist/claustrum-scoped-roster.js +194 -0
  17. package/dist/claustrum-scoped-runtime.d.ts +28 -0
  18. package/dist/claustrum-scoped-runtime.js +230 -0
  19. package/dist/claustrum-scoped.d.ts +39 -0
  20. package/dist/claustrum-scoped.js +193 -0
  21. package/dist/claustrum.d.ts +252 -0
  22. package/dist/claustrum.js +1471 -0
  23. package/dist/commands/account.d.ts +43 -11
  24. package/dist/commands/account.js +147 -4
  25. package/dist/constants.d.ts +5 -5
  26. package/dist/constants.js +5 -5
  27. package/dist/custom-headers.d.ts +3 -0
  28. package/dist/custom-headers.js +102 -0
  29. package/dist/dump.js +2 -1
  30. package/dist/fast.js +1 -1
  31. package/dist/index.d.ts +11 -0
  32. package/dist/index.js +11 -0
  33. package/dist/json.d.ts +1 -0
  34. package/dist/json.js +10 -0
  35. package/dist/logger.js +3 -1
  36. package/dist/mid-conversation-output-config.d.ts +13 -0
  37. package/dist/mid-conversation-output-config.js +89 -0
  38. package/dist/model-remap.d.ts +27 -0
  39. package/dist/model-remap.js +72 -0
  40. package/dist/models.d.ts +46 -1
  41. package/dist/models.js +87 -8
  42. package/dist/network-errors.d.ts +1 -0
  43. package/dist/network-errors.js +27 -0
  44. package/dist/oauth-profile.d.ts +2 -1
  45. package/dist/oauth-profile.js +6 -0
  46. package/dist/prime.d.ts +11 -3
  47. package/dist/prime.js +25 -7
  48. package/dist/quota-header-feed.d.ts +32 -7
  49. package/dist/quota-header-feed.js +93 -10
  50. package/dist/quota-headers.js +59 -6
  51. package/dist/quota-manager.d.ts +20 -2
  52. package/dist/quota-manager.js +101 -24
  53. package/dist/relay.d.ts +8 -0
  54. package/dist/relay.js +72 -12
  55. package/dist/sticky-routing.d.ts +2 -0
  56. package/dist/sticky-routing.js +19 -1
  57. package/dist/thinking-binding.d.ts +7 -0
  58. package/dist/thinking-binding.js +54 -0
  59. package/package.json +4 -1
@@ -0,0 +1,252 @@
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';
3
+ export type ClaustrumEndpoint = {
4
+ host: string;
5
+ port: number;
6
+ };
7
+ export type ClaustrumDetection = {
8
+ status: 'available';
9
+ schema: number;
10
+ wireVersion: number;
11
+ endpoints: ClaustrumEndpoint[];
12
+ } | {
13
+ status: 'absent';
14
+ path: string;
15
+ } | {
16
+ status: 'malformed';
17
+ path: string;
18
+ reason: string;
19
+ };
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>;
28
+ export declare const CUSTODY_TOMBSTONE_PREFIX = "claustrum-tombstone:v1:";
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
+ };
36
+ export declare function isCustodyTombstoneValue(value: unknown): value is string;
37
+ export declare function isCustodyTombstoneOAuth(auth: unknown, provider: string): boolean;
38
+ export declare class CustodyTombstoneRefreshError extends Error {
39
+ readonly provider: string;
40
+ readonly code = "custody_tombstone_refresh";
41
+ constructor(provider: string);
42
+ }
43
+ export declare class CustodyTombstoneLoginError extends Error {
44
+ readonly provider: string;
45
+ readonly code = "custody_tombstone_login";
46
+ constructor(provider: string);
47
+ }
48
+ export declare function assertNotCustodyTombstone(refreshToken: unknown, provider: string): void;
49
+ export type CustodyHandleAccount = {
50
+ label: string;
51
+ handle: string;
52
+ credentialId: string;
53
+ };
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;
77
+ provider: string;
78
+ serve: string;
79
+ accounts: ReadonlyArray<CustodyHandleAccount>;
80
+ superseded: ReadonlySet<string>;
81
+ corruptLabels: ReadonlySet<string>;
82
+ };
83
+ export declare function isValidCustodyLabel(value: unknown): value is string;
84
+ export declare function isValidCustodyHandle(value: unknown): value is string;
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>;
182
+ export type ClaustrumClientOptions = {
183
+ connectionFile?: string;
184
+ handshakeTimeoutMs?: number;
185
+ connector?: ClaustrumConnector;
186
+ };
187
+ export type ClaustrumConnector = (options: {
188
+ connectionFile: string;
189
+ handshakeTimeoutMs?: number;
190
+ }) => Promise<SubcClient>;
191
+ export declare class ClaustrumClient {
192
+ #private;
193
+ private constructor();
194
+ static connect(options?: ClaustrumClientOptions): Promise<ClaustrumClient>;
195
+ catalogList(moduleId?: string): Promise<CatalogEntry[]>;
196
+ routeOpen(target: RouteTarget, identity: BindIdentity, options?: Omit<RouteOpenOptions, 'consumerIdentity'>): Promise<RouteHandle>;
197
+ request(handle: RouteHandle, body: unknown, options?: RequestOptions): Promise<unknown>;
198
+ call<Response = unknown>(moduleId: string, method: string, params?: unknown, options?: Omit<ManagedCallOptions, 'consumerIdentity'>): Promise<Response>;
199
+ subscribe(handle: RouteHandle, body: unknown, onEvent: (event: Uint8Array) => void, options?: SubscribeOptions): Subscription;
200
+ closeRoute(handle: RouteHandle, options?: CloseRouteOptions): Promise<void>;
201
+ closeManagedRoute(target: Extract<RouteTarget, {
202
+ kind: 'management_surface' | 'tool_provider';
203
+ }>, identity: BindIdentity, options?: Omit<ManagedCloseRouteOptions, 'consumerIdentity'>): Promise<void>;
204
+ close(): void;
205
+ }
206
+ export declare function connectClaustrumClient(options?: ClaustrumClientOptions): Promise<ClaustrumClient>;
207
+ export declare const CLAUSTRUM_MODULE_ID = "claustrum";
208
+ export declare const DEFAULT_CLAUSTRUM_CREDENTIAL_MIN_TTL_MS = 120000;
209
+ export declare const ERROR_CLASS_WIRE_SET: readonly ['transient', 'permanent', 'auth_required', 'context_overflow'];
210
+ export type ClaustrumCredentialErrorClass = (typeof ERROR_CLASS_WIRE_SET)[number];
211
+ export type ClaustrumCredentialErrorAction = 'gone' | 'reauth' | 'retry' | 'reduce_and_retry';
212
+ export type ClaustrumCredential = {
213
+ payload: string;
214
+ expiresAtMs: number | null;
215
+ recordVersion: number;
216
+ projectId?: string;
217
+ accountId?: string;
218
+ credentialId?: string;
219
+ };
220
+ export type ClaustrumServedCredential = Pick<ClaustrumCredential, 'recordVersion'>;
221
+ export type ClaustrumReporterSource = 'direct' | 'relay_status_field' | 'relay_message_parse';
222
+ export declare class ClaustrumCredentialError extends Error {
223
+ readonly code: string;
224
+ readonly action: ClaustrumCredentialErrorAction;
225
+ readonly errorClass: ClaustrumCredentialErrorClass;
226
+ constructor(message: string, code: string, errorClass: ClaustrumCredentialErrorClass, action: ClaustrumCredentialErrorAction);
227
+ }
228
+ export type ClaustrumCredentialCacheOptions = {
229
+ identity?: BindIdentity;
230
+ now?: () => number;
231
+ minTtlMs?: number;
232
+ };
233
+ export declare class ClaustrumCredentialCache {
234
+ #private;
235
+ constructor(client: ClaustrumClient, options?: ClaustrumCredentialCacheOptions);
236
+ get(handle: string, minTtlMs?: number, options?: {
237
+ cacheIf?: () => boolean;
238
+ }): Promise<ClaustrumCredential>;
239
+ peek(handle: string): ClaustrumCredential | undefined;
240
+ abandonPending(handle: string): void;
241
+ seedForTest(handle: string, credential: ClaustrumCredential): void;
242
+ reduceMinTtlMs(): number;
243
+ reportAuthFailure(handle: string, providerStatus: number, servedCredential: ClaustrumServedCredential, reporterSource?: ClaustrumReporterSource): Promise<void>;
244
+ reportAuthFailure(handle: string, servedCredential: ClaustrumServedCredential, providerStatus?: number, reporterSource?: ClaustrumReporterSource): Promise<void>;
245
+ invalidate(handle: string, recordVersion?: number): void;
246
+ close(): void;
247
+ }
248
+ export type ConnectClaustrumCredentialCacheOptions = ClaustrumClientOptions & ClaustrumCredentialCacheOptions & {
249
+ enabled?: boolean;
250
+ };
251
+ export declare function connectClaustrumCredentialCache(options?: ConnectClaustrumCredentialCacheOptions): Promise<ClaustrumCredentialCache | null>;
252
+ export {};