@cortexkit/anthropic-auth-core 1.10.3 → 1.11.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 +52 -0
- package/dist/accounts.js +392 -94
- package/dist/auth.d.ts +8 -0
- package/dist/auth.js +8 -1
- package/dist/cachekeep.d.ts +3 -1
- package/dist/cachekeep.js +34 -7
- package/dist/commands/account.d.ts +56 -0
- package/dist/commands/account.js +219 -0
- package/dist/dump.js +3 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/logger.d.ts +25 -1
- package/dist/logger.js +238 -18
- package/dist/logging.d.ts +19 -0
- package/dist/logging.js +59 -0
- package/dist/provider.d.ts +19 -0
- package/dist/provider.js +0 -0
- package/dist/quota-manager.d.ts +1 -0
- package/dist/quota-manager.js +16 -7
- package/dist/routing.js +2 -6
- package/package.json +1 -1
package/dist/accounts.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Cache1hMode } from './constants.ts';
|
|
2
|
+
import { type LogLevel } from './logger.ts';
|
|
2
3
|
export declare const ACCOUNT_FILE_NAME = "anthropic-auth.json";
|
|
3
4
|
export declare const ACCOUNT_STATE_FILE_NAME = "anthropic-auth-state.json";
|
|
4
5
|
export declare const QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
@@ -36,6 +37,22 @@ export type AccountOperationError = {
|
|
|
36
37
|
nextRetryAt?: number;
|
|
37
38
|
retryCount?: number;
|
|
38
39
|
tokenHash?: string;
|
|
40
|
+
/**
|
|
41
|
+
* HTTP status of the underlying refresh/quota failure, when known. Lets
|
|
42
|
+
* consumers distinguish a permanently-dead token (400 invalid_grant →
|
|
43
|
+
* re-login) from a transient failure (429/5xx → recovers) without a delay
|
|
44
|
+
* heuristic. Absent on errors persisted before this field existed.
|
|
45
|
+
*/
|
|
46
|
+
status?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Explicit dead-token discriminator, set at construction. True ONLY when the
|
|
49
|
+
* refresh endpoint returned 400 invalid_grant (token is genuinely dead →
|
|
50
|
+
* re-login). False for transient failures AND for retry-exhausted/network
|
|
51
|
+
* errors that get a long backoff but are NOT dead — so they are not nagged
|
|
52
|
+
* for re-login. Absent on errors persisted before this field existed (those
|
|
53
|
+
* fall back to status / the 24h-delay heuristic).
|
|
54
|
+
*/
|
|
55
|
+
permanent?: boolean;
|
|
39
56
|
};
|
|
40
57
|
export type AccountQuotaWindow = {
|
|
41
58
|
usedPercent: number;
|
|
@@ -91,6 +108,9 @@ export type AccountStorage = {
|
|
|
91
108
|
dump?: {
|
|
92
109
|
enabled?: boolean;
|
|
93
110
|
};
|
|
111
|
+
logging?: {
|
|
112
|
+
level?: LogLevel;
|
|
113
|
+
};
|
|
94
114
|
claudeFast?: {
|
|
95
115
|
enabled?: boolean;
|
|
96
116
|
};
|
|
@@ -106,6 +126,7 @@ export type AccountStorage = {
|
|
|
106
126
|
enabled?: boolean;
|
|
107
127
|
startHour?: number;
|
|
108
128
|
endHour?: number;
|
|
129
|
+
subagents?: boolean;
|
|
109
130
|
};
|
|
110
131
|
relay?: {
|
|
111
132
|
enabled?: boolean;
|
|
@@ -157,6 +178,7 @@ export type AccountRefreshError = {
|
|
|
157
178
|
};
|
|
158
179
|
export declare function getAccountStoragePath(): string;
|
|
159
180
|
export declare function getAccountStatePath(configPath?: string): string;
|
|
181
|
+
export declare function createEmptyStorage(): AccountStorage;
|
|
160
182
|
export declare function loadAccounts(path?: string): Promise<AccountStorage | null>;
|
|
161
183
|
export declare function saveAccounts(storage: AccountStorage, path?: string): Promise<void>;
|
|
162
184
|
export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
|
|
@@ -167,6 +189,7 @@ export declare function acquireRefreshFileLock(options: {
|
|
|
167
189
|
now?: () => number;
|
|
168
190
|
renew?: boolean;
|
|
169
191
|
renewIntervalMs?: number;
|
|
192
|
+
onStep?: (step: 'stale-marker-stat' | 'stale-marker-claimed' | 'stale-lock-confirmed' | 'eviction-marker-acquired') => void | Promise<void>;
|
|
170
193
|
}): Promise<{
|
|
171
194
|
release: () => Promise<void>;
|
|
172
195
|
} | null>;
|
|
@@ -180,6 +203,8 @@ export declare function isFastModePersistentlyEnabled(storage: AccountStorage |
|
|
|
180
203
|
export declare function setFastModePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
181
204
|
export declare function setCacheKeepPersistentWindow(startHour: number, endHour: number, path?: string): Promise<AccountStorage>;
|
|
182
205
|
export declare function setCacheKeepPersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
206
|
+
export declare function isCacheKeepSubagentsEnabled(storage: AccountStorage | null): boolean;
|
|
207
|
+
export declare function setCacheKeepSubagentsEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
183
208
|
export declare function shouldFallbackStatus(status: number, storage: AccountStorage | null): boolean;
|
|
184
209
|
export declare function getRefreshIntervalMs(storage: AccountStorage | null): number;
|
|
185
210
|
export declare function hashRefreshToken(refreshToken: string): string;
|
|
@@ -189,8 +214,25 @@ export declare function buildRefreshOperationError(input: {
|
|
|
189
214
|
refreshToken: string;
|
|
190
215
|
previous?: AccountOperationError;
|
|
191
216
|
}): AccountOperationError;
|
|
217
|
+
/**
|
|
218
|
+
* True when a refresh error means the token is permanently dead and the account
|
|
219
|
+
* needs a re-login (vs a transient failure that recovers).
|
|
220
|
+
*
|
|
221
|
+
* Precedence:
|
|
222
|
+
* 1. the explicit `permanent` flag (set at construction from 400 invalid_grant)
|
|
223
|
+
* — the authoritative signal; correctly classifies a retry-exhausted/network
|
|
224
|
+
* error (long backoff, but NOT dead) as non-permanent;
|
|
225
|
+
* 2. else the captured HTTP `status` — 400 (for errors built before `permanent`
|
|
226
|
+
* existed but after `status`);
|
|
227
|
+
* 3. else the legacy 24h-delay heuristic — back-compat ONLY for errors persisted
|
|
228
|
+
* before either field existed (e.g. an operator's already-dead token: no
|
|
229
|
+
* status, ~24h backoff). It still flags those until the next refresh restamps
|
|
230
|
+
* the error with the explicit field.
|
|
231
|
+
*/
|
|
232
|
+
export declare function isPermanentRefreshError(error: AccountOperationError | undefined): boolean;
|
|
192
233
|
export declare function refreshBackoffActive(error: AccountOperationError | undefined, refreshToken: string | undefined, now: number): boolean;
|
|
193
234
|
export declare function formatRefreshBackoffMessage(error: AccountOperationError, now: number): string;
|
|
235
|
+
export declare function isQuotaPolicyAuthError(error: unknown): boolean;
|
|
194
236
|
export declare function buildQuotaOperationError(input: {
|
|
195
237
|
error: unknown;
|
|
196
238
|
now: number;
|
|
@@ -199,6 +241,8 @@ export declare function buildQuotaOperationError(input: {
|
|
|
199
241
|
export declare function quotaBackoffActive(error: AccountOperationError | undefined, now: number): boolean;
|
|
200
242
|
export declare function formatQuotaBackoffMessage(error: AccountOperationError, now: number): string;
|
|
201
243
|
export declare function getQuotaCheckIntervalMs(storage: AccountStorage | null): number;
|
|
244
|
+
export declare function getPersistedLogLevel(storage: AccountStorage | null): LogLevel | undefined;
|
|
245
|
+
export declare function setLogLevelPersistent(level: LogLevel, path?: string): Promise<void>;
|
|
202
246
|
export declare function getPersistedMainQuota(storage: AccountStorage | null): {
|
|
203
247
|
quota: OAuthQuotaSnapshot;
|
|
204
248
|
checkedAt: number;
|
|
@@ -226,6 +270,10 @@ export declare function killswitchRetryAfterSeconds(mainQuota: OAuthQuotaSnapsho
|
|
|
226
270
|
}>, now: number): number;
|
|
227
271
|
export declare function getKillswitchConfig(storage: AccountStorage | null): KillswitchConfig;
|
|
228
272
|
export declare function setKillswitchPersistent(config: KillswitchConfig, path?: string): Promise<AccountStorage>;
|
|
273
|
+
export declare function removeAccountPersistent(id: string, path?: string): Promise<boolean>;
|
|
274
|
+
export declare function reorderAccountsPersistent(orderedIds: string[], path?: string): Promise<void>;
|
|
275
|
+
export declare function setAccountEnabledPersistent(id: string, enabled: boolean, path?: string): Promise<boolean>;
|
|
276
|
+
export declare function addAccountPersistent(account: FallbackAccount, path?: string): Promise<void>;
|
|
229
277
|
export declare function getQuotaNextRefreshAt(quota: OAuthQuotaSnapshot | undefined, storage: AccountStorage | null, now: number): number;
|
|
230
278
|
export declare function fetchOAuthQuotaSnapshot(input: {
|
|
231
279
|
accessToken: string;
|
|
@@ -235,6 +283,10 @@ export declare function fetchOAuthQuotaSnapshot(input: {
|
|
|
235
283
|
five_hour: AccountQuotaWindow | undefined;
|
|
236
284
|
seven_day: AccountQuotaWindow | undefined;
|
|
237
285
|
}>;
|
|
286
|
+
export declare function upsertAccount(storage: AccountStorage, account: FallbackAccount): void;
|
|
287
|
+
export declare function removeAccount(storage: AccountStorage, id: string): boolean;
|
|
288
|
+
export declare function reorderAccounts(storage: AccountStorage, orderedIds: string[]): void;
|
|
289
|
+
export declare function setAccountEnabled(storage: AccountStorage, id: string, enabled: boolean): boolean;
|
|
238
290
|
export declare class FallbackAccountManager {
|
|
239
291
|
private readonly now;
|
|
240
292
|
private readonly fetchImpl;
|