@cortexkit/anthropic-auth-core 1.19.0 → 1.20.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/dist/accounts.d.ts +72 -2
- package/dist/accounts.js +390 -26
- package/dist/auth.d.ts +3 -0
- package/dist/auth.js +5 -3
- package/dist/cache1h.d.ts +1 -1
- package/dist/cache1h.js +1 -1
- package/dist/cachekeep.d.ts +22 -2
- package/dist/cachekeep.js +137 -30
- package/dist/cch.d.ts +1 -0
- package/dist/cch.js +6 -1
- package/dist/claude-code.d.ts +2 -1
- package/dist/claude-code.js +3 -3
- package/dist/commands/account.js +1 -1
- package/dist/constants.d.ts +3 -3
- package/dist/dump.d.ts +12 -1
- package/dist/dump.js +166 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.js +26 -24
- package/dist/killswitch.js +1 -1
- package/dist/models.d.ts +22 -6
- package/dist/models.js +16 -0
- package/dist/oauth-profile.js +1 -1
- package/dist/prime.d.ts +219 -0
- package/dist/prime.js +823 -0
- package/dist/quota-manager.d.ts +7 -0
- package/dist/quota-manager.js +24 -15
- package/dist/quotas.d.ts +4 -4
- package/dist/quotas.js +2 -2
- package/dist/relay.d.ts +4 -0
- package/dist/relay.js +29 -18
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +1 -1
- package/dist/start.d.ts +13 -0
- package/dist/start.js +29 -0
- package/dist/sticky-routing.d.ts +13 -1
- package/dist/sticky-routing.js +58 -2
- package/package.json +1 -1
package/dist/accounts.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type AccountBase = {
|
|
|
13
13
|
};
|
|
14
14
|
export type OAuthAccount = AccountBase & {
|
|
15
15
|
type: 'oauth';
|
|
16
|
+
authLineageId?: string;
|
|
16
17
|
access?: string;
|
|
17
18
|
refresh: string;
|
|
18
19
|
expires?: number;
|
|
@@ -21,6 +22,11 @@ export type OAuthAccount = AccountBase & {
|
|
|
21
22
|
lastQuotaRefreshError?: AccountOperationError;
|
|
22
23
|
quota?: OAuthQuotaSnapshot;
|
|
23
24
|
profile?: OAuthAccountProfile;
|
|
25
|
+
/**
|
|
26
|
+
* Per-fallback cumulative prime counters. Lives in the runtime-state file
|
|
27
|
+
* (scoped under `accounts[id].prime`) and never in `anthropic-auth.json`.
|
|
28
|
+
*/
|
|
29
|
+
prime?: PrimeUsageCounters;
|
|
24
30
|
};
|
|
25
31
|
export type ApiKeyAccount = AccountBase & {
|
|
26
32
|
type: 'api';
|
|
@@ -94,6 +100,27 @@ export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWin
|
|
|
94
100
|
source?: 'poll' | 'headers';
|
|
95
101
|
checkedAt?: number;
|
|
96
102
|
};
|
|
103
|
+
export type PrimeUsageCounters = {
|
|
104
|
+
count: number;
|
|
105
|
+
inputTokens: number;
|
|
106
|
+
outputTokens: number;
|
|
107
|
+
since: number;
|
|
108
|
+
};
|
|
109
|
+
export type PrimeUsageDelta = {
|
|
110
|
+
inputTokens?: number;
|
|
111
|
+
outputTokens?: number;
|
|
112
|
+
};
|
|
113
|
+
export type PrimeRuntimeState = {
|
|
114
|
+
enabled?: boolean;
|
|
115
|
+
mainAuthLineageId?: string;
|
|
116
|
+
mainAuthLineageRefreshTokenFingerprint?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Main account prime counters. Persisted only on the main side of the
|
|
119
|
+
* runtime-state file — `configFromStorage()` never writes them to the config
|
|
120
|
+
* file so they cannot leak into `anthropic-auth.json`.
|
|
121
|
+
*/
|
|
122
|
+
main?: PrimeUsageCounters;
|
|
123
|
+
};
|
|
97
124
|
export type RoutingMode = 'main-first' | 'fallback-first' | 'sticky-balanced';
|
|
98
125
|
export type KillswitchThresholds = Partial<Record<QuotaWindowName | '5h' | '1w' | 'scoped', number>>;
|
|
99
126
|
export type KillswitchConfig = {
|
|
@@ -164,6 +191,13 @@ export type AccountStorage = {
|
|
|
164
191
|
endHour?: number;
|
|
165
192
|
subagents?: boolean;
|
|
166
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Opt-in flag and runtime metadata for `/claude-prime`. The `enabled` flag
|
|
196
|
+
* belongs on the config side; counters and main lineage bindings live in the
|
|
197
|
+
* state file and must never appear in `anthropic-auth.json`. See
|
|
198
|
+
* `configFromStorage()` for the write-side filter.
|
|
199
|
+
*/
|
|
200
|
+
prime?: PrimeRuntimeState;
|
|
167
201
|
relay?: {
|
|
168
202
|
enabled?: boolean;
|
|
169
203
|
url?: string;
|
|
@@ -180,7 +214,7 @@ export type AccountStorage = {
|
|
|
180
214
|
* (to display the provider's real model costs).
|
|
181
215
|
*/
|
|
182
216
|
export declare function isCostZeroingEnabled(storage: Pick<AccountStorage, 'costZeroing'>): boolean;
|
|
183
|
-
export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
|
|
217
|
+
export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'authLineageId' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile' | 'prime'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
|
|
184
218
|
export type AccountRuntimeState = {
|
|
185
219
|
version: 1;
|
|
186
220
|
main?: {
|
|
@@ -194,6 +228,9 @@ export type AccountRuntimeState = {
|
|
|
194
228
|
refreshLeaseId?: string;
|
|
195
229
|
refreshLeaseUntil?: number;
|
|
196
230
|
refreshLeaseTokenHash?: string;
|
|
231
|
+
prime?: PrimeUsageCounters;
|
|
232
|
+
primeAuthLineageId?: string;
|
|
233
|
+
primeAuthLineageRefreshTokenFingerprint?: string;
|
|
197
234
|
};
|
|
198
235
|
accounts?: Record<string, AccountRuntimeEntry>;
|
|
199
236
|
};
|
|
@@ -201,6 +238,7 @@ export type AccountStateSaveScope = {
|
|
|
201
238
|
mainProfile?: boolean;
|
|
202
239
|
mainQuota?: boolean;
|
|
203
240
|
mainRefresh?: boolean;
|
|
241
|
+
mainPrime?: boolean;
|
|
204
242
|
accounts?: true | string[];
|
|
205
243
|
};
|
|
206
244
|
export type AccountManagerOptions = {
|
|
@@ -209,6 +247,8 @@ export type AccountManagerOptions = {
|
|
|
209
247
|
configPath?: string;
|
|
210
248
|
quotaManager?: import('./quota-manager.ts').QuotaManager;
|
|
211
249
|
onFallbackStorageChanged?: () => void;
|
|
250
|
+
setIntervalImpl?: typeof globalThis.setInterval;
|
|
251
|
+
clearIntervalImpl?: typeof globalThis.clearInterval;
|
|
212
252
|
};
|
|
213
253
|
export type AccountRefreshError = {
|
|
214
254
|
accountId: string;
|
|
@@ -218,6 +258,8 @@ export declare function getAccountStoragePath(): string;
|
|
|
218
258
|
export declare function getAccountStatePath(configPath?: string): string;
|
|
219
259
|
export declare function createEmptyStorage(): AccountStorage;
|
|
220
260
|
export declare function loadAccounts(path?: string): Promise<AccountStorage | null>;
|
|
261
|
+
/** Returns the latest timestamp carried by any quota snapshot window. */
|
|
262
|
+
export declare function quotaSnapshotCheckedAt(quota: OAuthQuotaSnapshot | undefined): number;
|
|
221
263
|
export interface SaveAccountsOptions {
|
|
222
264
|
/** Account ids intentionally removed by this mutation. */
|
|
223
265
|
removedAccountIds?: readonly string[];
|
|
@@ -255,6 +297,28 @@ export declare function setCacheKeepPersistentAlways(path?: string): Promise<Acc
|
|
|
255
297
|
export declare function setCacheKeepPersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
256
298
|
export declare function isCacheKeepSubagentsEnabled(storage: AccountStorage | null): boolean;
|
|
257
299
|
export declare function setCacheKeepSubagentsEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
300
|
+
export declare function isPrimePersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
301
|
+
export declare function setPrimePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
302
|
+
/**
|
|
303
|
+
* Return the stable prime marker identity for an OAuth account, seeding it in
|
|
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>;
|
|
313
|
+
/**
|
|
314
|
+
* Atomically increment an account's cumulative prime counters and persist via
|
|
315
|
+
* the scoped runtime-state path. The `main` account lives at state.main.prime;
|
|
316
|
+
* every other account lives at state.accounts[id].prime. Config-side writes
|
|
317
|
+
* are intentionally NOT triggered so prime counters cannot leak into
|
|
318
|
+
* `anthropic-auth.json`. Callers should not depend on this function to mutate
|
|
319
|
+
* the caller's storage object.
|
|
320
|
+
*/
|
|
321
|
+
export declare function incrementPrimeUsagePersistent(accountId: 'main' | string, usage: PrimeUsageDelta, path?: string, now?: number): Promise<PrimeUsageCounters>;
|
|
258
322
|
export declare function shouldFallbackStatus(status: number, storage: AccountStorage | null): boolean;
|
|
259
323
|
export declare function getQuotaMinimumRemainingThresholds(storage: AccountStorage | null): {
|
|
260
324
|
five_hour: number;
|
|
@@ -286,6 +350,7 @@ export declare function buildRefreshOperationError(input: {
|
|
|
286
350
|
export declare function isPermanentRefreshError(error: AccountOperationError | undefined): boolean;
|
|
287
351
|
export declare function refreshBackoffActive(error: AccountOperationError | undefined, refreshToken: string | undefined, now: number): boolean;
|
|
288
352
|
export declare function formatRefreshBackoffMessage(error: AccountOperationError, now: number): string;
|
|
353
|
+
export declare function getFallbackReauthLabels(storage: AccountStorage | null | undefined): string[];
|
|
289
354
|
export declare function isQuotaPolicyAuthError(error: unknown): boolean;
|
|
290
355
|
export declare function buildQuotaOperationError(input: {
|
|
291
356
|
error: unknown;
|
|
@@ -362,6 +427,8 @@ export declare class FallbackAccountManager {
|
|
|
362
427
|
private quotaTimer;
|
|
363
428
|
readonly quotaManager: import('./quota-manager.ts').QuotaManager | null;
|
|
364
429
|
private readonly onFallbackStorageChanged;
|
|
430
|
+
private readonly setIntervalImpl;
|
|
431
|
+
private readonly clearIntervalImpl;
|
|
365
432
|
constructor(options?: AccountManagerOptions);
|
|
366
433
|
/**
|
|
367
434
|
* Seed QuotaManager from persisted account.quota if no cache entry exists
|
|
@@ -399,5 +466,8 @@ export declare class FallbackAccountManager {
|
|
|
399
466
|
}): Promise<OAuthAccount>;
|
|
400
467
|
private waitForConcurrentFallbackRefresh;
|
|
401
468
|
private refreshAccountNow;
|
|
402
|
-
refreshAccountQuota(account: OAuthAccount, storage: AccountStorage): Promise<
|
|
469
|
+
refreshAccountQuota(account: OAuthAccount, storage: AccountStorage): Promise<{
|
|
470
|
+
account: OAuthAccount;
|
|
471
|
+
fetched: boolean;
|
|
472
|
+
}>;
|
|
403
473
|
}
|