@cortexkit/anthropic-auth-core 1.20.0 → 1.21.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.
- package/README.md +1 -1
- package/dist/accounts.d.ts +24 -14
- package/dist/accounts.js +234 -143
- package/dist/claude-code.d.ts +3 -1
- package/dist/claude-code.js +124 -21
- package/dist/dump.d.ts +1 -0
- package/dist/dump.js +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/oauth-profile.d.ts +2 -1
- package/dist/oauth-profile.js +10 -4
- package/dist/quota-header-feed.d.ts +40 -0
- package/dist/quota-header-feed.js +248 -0
- package/dist/quota-headers.js +6 -4
- package/dist/quota-manager.d.ts +36 -27
- package/dist/quota-manager.js +375 -144
- package/dist/sticky-routing.d.ts +14 -2
- package/dist/sticky-routing.js +30 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @cortexkit/anthropic-auth-core
|
|
2
2
|
|
|
3
|
-
Shared Anthropic OAuth, quota, routing, cache, cache-keepalive, fast mode, relay, dump, and request-signing helpers used by CortexKit's OpenCode and Pi integrations.
|
|
3
|
+
Shared Anthropic OAuth, stable account identity, quota, host-local quota feed, routing, cache, cache-keepalive, fast mode, relay, dump, and request-signing helpers used by CortexKit's OpenCode and Pi integrations.
|
|
4
4
|
|
|
5
5
|
User-facing packages:
|
|
6
6
|
|
package/dist/accounts.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type AccountOperationError = {
|
|
|
43
43
|
checkedAt: number;
|
|
44
44
|
nextRetryAt?: number;
|
|
45
45
|
retryCount?: number;
|
|
46
|
+
accountIdentity?: string;
|
|
46
47
|
tokenHash?: string;
|
|
47
48
|
/**
|
|
48
49
|
* HTTP status of the underlying refresh/quota failure, when known. Lets
|
|
@@ -89,9 +90,13 @@ export type OAuthAccountProfile = {
|
|
|
89
90
|
tier: string;
|
|
90
91
|
orgType: string;
|
|
91
92
|
checkedAt: number;
|
|
93
|
+
/** Stable account identity; tokenFingerprint remains loadable for legacy state. */
|
|
94
|
+
accountIdentity?: string;
|
|
92
95
|
tokenFingerprint?: string;
|
|
93
96
|
};
|
|
94
97
|
export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWindow>> & {
|
|
98
|
+
/** Stable main/fallback account identity; access tokens are fetch credentials only. */
|
|
99
|
+
accountIdentity?: string;
|
|
95
100
|
scoped?: AccountScopedQuotaWindow[];
|
|
96
101
|
extraUsage?: OAuthExtraUsageSnapshot;
|
|
97
102
|
bindingWindow?: string;
|
|
@@ -132,6 +137,7 @@ export type KillswitchConfig = {
|
|
|
132
137
|
};
|
|
133
138
|
export type AccountStorage = {
|
|
134
139
|
version: 1;
|
|
140
|
+
mainAccountId?: string;
|
|
135
141
|
main?: {
|
|
136
142
|
type: 'opencode';
|
|
137
143
|
provider: 'anthropic';
|
|
@@ -162,6 +168,11 @@ export type AccountStorage = {
|
|
|
162
168
|
mainQuotaCheckedAt?: number;
|
|
163
169
|
mainQuotaToken?: string;
|
|
164
170
|
mainLastQuotaApiError?: AccountOperationError;
|
|
171
|
+
mainQuotaErrorGeneration?: number;
|
|
172
|
+
mainQuotaErrorClearedAt?: number;
|
|
173
|
+
};
|
|
174
|
+
quotaHeaderFeed?: {
|
|
175
|
+
enabled?: boolean;
|
|
165
176
|
};
|
|
166
177
|
claudeCache?: {
|
|
167
178
|
enabled?: boolean;
|
|
@@ -224,6 +235,8 @@ export type AccountRuntimeState = {
|
|
|
224
235
|
quotaCheckedAt?: number;
|
|
225
236
|
quotaToken?: string;
|
|
226
237
|
lastQuotaApiError?: AccountOperationError;
|
|
238
|
+
quotaErrorGeneration?: number;
|
|
239
|
+
quotaErrorClearedAt?: number;
|
|
227
240
|
lastRefreshError?: AccountOperationError;
|
|
228
241
|
refreshLeaseId?: string;
|
|
229
242
|
refreshLeaseUntil?: number;
|
|
@@ -257,9 +270,11 @@ export type AccountRefreshError = {
|
|
|
257
270
|
export declare function getAccountStoragePath(): string;
|
|
258
271
|
export declare function getAccountStatePath(configPath?: string): string;
|
|
259
272
|
export declare function createEmptyStorage(): AccountStorage;
|
|
273
|
+
export declare function mergeMainQuotaErrorClearedAt(existing: number | undefined, incoming: number | undefined): number | undefined;
|
|
260
274
|
export declare function loadAccounts(path?: string): Promise<AccountStorage | null>;
|
|
261
275
|
/** Returns the latest timestamp carried by any quota snapshot window. */
|
|
262
276
|
export declare function quotaSnapshotCheckedAt(quota: OAuthQuotaSnapshot | undefined): number;
|
|
277
|
+
export declare function mergeHeaderQuotaForPersistence(existing: OAuthQuotaSnapshot | undefined, incoming: OAuthQuotaSnapshot): OAuthQuotaSnapshot;
|
|
263
278
|
export interface SaveAccountsOptions {
|
|
264
279
|
/** Account ids intentionally removed by this mutation. */
|
|
265
280
|
removedAccountIds?: readonly string[];
|
|
@@ -267,11 +282,12 @@ export interface SaveAccountsOptions {
|
|
|
267
282
|
preserveExistingAccountOrder?: boolean;
|
|
268
283
|
}
|
|
269
284
|
export declare function saveAccounts(storage: AccountStorage, path?: string, options?: SaveAccountsOptions): Promise<void>;
|
|
285
|
+
export declare function getOrCreateMainAccountId(path?: string, createId?: () => string): Promise<string>;
|
|
270
286
|
export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
|
|
271
287
|
export declare function saveOAuthProfileState(input: {
|
|
272
288
|
accountId: 'main' | string;
|
|
273
289
|
profile: OAuthAccountProfile | undefined;
|
|
274
|
-
|
|
290
|
+
accountIdentity?: string;
|
|
275
291
|
}, path?: string): Promise<boolean>;
|
|
276
292
|
export declare function acquireRefreshFileLock(options: {
|
|
277
293
|
name: string;
|
|
@@ -299,17 +315,8 @@ export declare function isCacheKeepSubagentsEnabled(storage: AccountStorage | nu
|
|
|
299
315
|
export declare function setCacheKeepSubagentsEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
300
316
|
export declare function isPrimePersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
301
317
|
export declare function setPrimePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
302
|
-
/**
|
|
303
|
-
|
|
304
|
-
* runtime state when older storage has no lineage yet. Main lookups return
|
|
305
|
-
* undefined when the live refresh token is unavailable and no lineage exists.
|
|
306
|
-
*/
|
|
307
|
-
export declare function getOrCreatePrimeAuthLineageId(accountId: 'main' | string, path?: string, mainRefreshToken?: string): Promise<string | undefined>;
|
|
308
|
-
/** Advance a main lineage across a refresh performed by this plugin. */
|
|
309
|
-
export declare function continueMainPrimeAuthLineageAfterRefresh(input: {
|
|
310
|
-
previousRefreshToken: string;
|
|
311
|
-
currentRefreshToken: string;
|
|
312
|
-
}, path?: string): Promise<void>;
|
|
318
|
+
/** Return the stable prime marker identity for an OAuth account. */
|
|
319
|
+
export declare function getOrCreatePrimeAuthLineageId(accountId: 'main' | string, path?: string): Promise<string | undefined>;
|
|
313
320
|
/**
|
|
314
321
|
* Atomically increment an account's cumulative prime counters and persist via
|
|
315
322
|
* the scoped runtime-state path. The `main` account lives at state.main.prime;
|
|
@@ -329,7 +336,7 @@ export declare function hashRefreshToken(refreshToken: string): string;
|
|
|
329
336
|
export declare function buildRefreshOperationError(input: {
|
|
330
337
|
error: unknown;
|
|
331
338
|
now: number;
|
|
332
|
-
|
|
339
|
+
accountIdentity: string | undefined;
|
|
333
340
|
previous?: AccountOperationError;
|
|
334
341
|
}): AccountOperationError;
|
|
335
342
|
/**
|
|
@@ -348,13 +355,14 @@ export declare function buildRefreshOperationError(input: {
|
|
|
348
355
|
* the error with the explicit field.
|
|
349
356
|
*/
|
|
350
357
|
export declare function isPermanentRefreshError(error: AccountOperationError | undefined): boolean;
|
|
351
|
-
export declare function refreshBackoffActive(error: AccountOperationError | undefined,
|
|
358
|
+
export declare function refreshBackoffActive(error: AccountOperationError | undefined, accountIdentity: string | undefined, now: number): boolean;
|
|
352
359
|
export declare function formatRefreshBackoffMessage(error: AccountOperationError, now: number): string;
|
|
353
360
|
export declare function getFallbackReauthLabels(storage: AccountStorage | null | undefined): string[];
|
|
354
361
|
export declare function isQuotaPolicyAuthError(error: unknown): boolean;
|
|
355
362
|
export declare function buildQuotaOperationError(input: {
|
|
356
363
|
error: unknown;
|
|
357
364
|
now: number;
|
|
365
|
+
accountIdentity?: string;
|
|
358
366
|
previous?: AccountOperationError;
|
|
359
367
|
}): AccountOperationError;
|
|
360
368
|
export declare function quotaBackoffActive(error: AccountOperationError | undefined, now: number): boolean;
|
|
@@ -366,6 +374,7 @@ export declare function getPersistedMainQuota(storage: AccountStorage | null): {
|
|
|
366
374
|
quota: OAuthQuotaSnapshot;
|
|
367
375
|
checkedAt: number;
|
|
368
376
|
tokenFingerprint?: string;
|
|
377
|
+
accountIdentity?: string;
|
|
369
378
|
} | null;
|
|
370
379
|
/**
|
|
371
380
|
* How often (in requests) to force a quota refresh, independent of the timer.
|
|
@@ -376,6 +385,7 @@ export declare function getScopedQuotaWindowForModel(quota: OAuthQuotaSnapshot |
|
|
|
376
385
|
export declare function quotaSnapshotModelScopeIsExhausted(quota: OAuthQuotaSnapshot | undefined, model: unknown): boolean;
|
|
377
386
|
export declare function quotaSnapshotPassesModelScope(quota: OAuthQuotaSnapshot | undefined, model: unknown): boolean;
|
|
378
387
|
export declare function quotaSnapshotPassesPolicy(quota: OAuthQuotaSnapshot | undefined, storage: AccountStorage | null): boolean;
|
|
388
|
+
export declare function quotaSnapshotHasStandardWindows(quota: OAuthQuotaSnapshot | undefined): quota is OAuthQuotaSnapshot;
|
|
379
389
|
export declare const DEFAULT_KILLSWITCH_THRESHOLDS: Record<QuotaWindowName | 'scoped', number>;
|
|
380
390
|
export declare function normalizeKillswitchThresholds(thresholds: KillswitchThresholds | undefined): Record<QuotaWindowName | 'scoped', number>;
|
|
381
391
|
export declare function isKillswitchEnabled(storage: AccountStorage | null): boolean;
|