@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/dist/quota-manager.d.ts
CHANGED
|
@@ -21,20 +21,25 @@ export type QuotaManagerOptions = {
|
|
|
21
21
|
storage: AccountStorage | null;
|
|
22
22
|
fetchImpl?: typeof fetch;
|
|
23
23
|
now?: () => number;
|
|
24
|
-
onMainQuotaFetched?: (quota: OAuthQuotaSnapshot, checkedAt: number, tokenFingerprint: string, fetchStartedAt: number) => void;
|
|
25
|
-
onApiError?: (error: AccountOperationError) => void;
|
|
24
|
+
onMainQuotaFetched?: (quota: OAuthQuotaSnapshot, checkedAt: number, tokenFingerprint: string, fetchStartedAt: number, quotaErrorGeneration: number, quotaErrorClearedAt: number | undefined) => void;
|
|
25
|
+
onApiError?: (error: AccountOperationError, quotaErrorGeneration: number) => void;
|
|
26
26
|
};
|
|
27
27
|
export declare class QuotaManager {
|
|
28
28
|
private main;
|
|
29
|
-
private
|
|
29
|
+
private mainAccountId;
|
|
30
|
+
private mainQuotaIdentityKnown;
|
|
31
|
+
private mainQuotaIdentityStrict;
|
|
32
|
+
private mainGeneration;
|
|
33
|
+
private mainQuotaErrorGeneration;
|
|
34
|
+
private mainQuotaErrorClearedAt;
|
|
30
35
|
private fallbacks;
|
|
31
|
-
private
|
|
36
|
+
private fallbackAuthLineages;
|
|
37
|
+
private fallbackGenerations;
|
|
32
38
|
private inflightMain;
|
|
33
|
-
private
|
|
39
|
+
private inflightMainAccountId;
|
|
34
40
|
private inflightFallbacks;
|
|
35
41
|
private mainLastApiError;
|
|
36
42
|
private fallbackApiErrors;
|
|
37
|
-
private fallbackErrorTokenFps;
|
|
38
43
|
private apiGate;
|
|
39
44
|
private lastApiCallAt;
|
|
40
45
|
private storage;
|
|
@@ -44,28 +49,26 @@ export declare class QuotaManager {
|
|
|
44
49
|
private readonly onApiError;
|
|
45
50
|
constructor(opts: QuotaManagerOptions);
|
|
46
51
|
/**
|
|
47
|
-
* Cached main quota entry
|
|
48
|
-
*
|
|
49
|
-
* account switched), it is dropped and null is returned so the caller
|
|
50
|
-
* refetches for the current account. Called without a token (e.g. for
|
|
51
|
-
* display) it returns whatever is cached.
|
|
52
|
+
* Cached main quota entry, scoped to the account behind the main credential.
|
|
53
|
+
* An unresolved identity keeps a retained cache unverified rather than exposing it.
|
|
52
54
|
*/
|
|
53
|
-
getMain(
|
|
55
|
+
getMain(mainAccountId?: string): QuotaEntry | null;
|
|
54
56
|
/**
|
|
55
|
-
* Cached fallback quota entry
|
|
56
|
-
* binding: if the entry was produced by a different token (account re-login),
|
|
57
|
-
* it is dropped and null is returned so the caller refetches.
|
|
57
|
+
* Cached fallback quota entry, scoped to the configured account id.
|
|
58
58
|
*/
|
|
59
|
-
getFallback(accountId: string,
|
|
59
|
+
getFallback(accountId: string, account?: Pick<OAuthAccount, 'authLineageId'>): QuotaEntry | null;
|
|
60
60
|
getAllFallbacks(): Map<string, QuotaEntry>;
|
|
61
|
-
setMain(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
setMain(mainAccountId: string | undefined, entry: QuotaEntry): void;
|
|
62
|
+
/** Bind quota state to the account behind the current main credential. */
|
|
63
|
+
setMainQuotaAccountIdentity(accountIdentity: string | undefined, strict?: boolean): number | undefined;
|
|
64
|
+
setFallback(accountId: string, entry: QuotaEntry, account: Pick<OAuthAccount, 'authLineageId'> | undefined): void;
|
|
65
|
+
clearFallback(accountId: string): void;
|
|
66
|
+
pushMainFromHeaders(mainAccountId: string | undefined, incoming: OAuthQuotaSnapshot): QuotaEntry;
|
|
67
|
+
pushFallbackFromHeaders(accountId: string, incoming: OAuthQuotaSnapshot, account: Pick<OAuthAccount, 'authLineageId'> | undefined): QuotaEntry | null;
|
|
68
|
+
refreshMain(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number): Promise<OAuthQuotaSnapshot>;
|
|
69
|
+
refreshMainWithMetadata(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number): Promise<QuotaRefreshResult>;
|
|
70
|
+
refreshFallback(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined): Promise<OAuthQuotaSnapshot>;
|
|
71
|
+
refreshFallbackWithMetadata(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined): Promise<QuotaRefreshResult>;
|
|
69
72
|
refreshAllFallbacks(accounts: OAuthAccount[]): Promise<void>;
|
|
70
73
|
/**
|
|
71
74
|
* Fire-and-forget refresh. Does not await, swallows errors.
|
|
@@ -73,7 +76,7 @@ export declare class QuotaManager {
|
|
|
73
76
|
refreshMainInBackground(accessToken: string): void;
|
|
74
77
|
private scopedWindowIsStale;
|
|
75
78
|
isMainStale(modelId?: string): boolean;
|
|
76
|
-
isFallbackStale(accountId: string,
|
|
79
|
+
isFallbackStale(accountId: string, _accessToken?: string, modelId?: string, account?: Pick<OAuthAccount, 'authLineageId'>): boolean;
|
|
77
80
|
shouldRefreshOnRequestCount(requestCount: number): boolean;
|
|
78
81
|
/**
|
|
79
82
|
* Combined check: should a refresh happen right now?
|
|
@@ -87,7 +90,7 @@ export declare class QuotaManager {
|
|
|
87
90
|
* can stop this process from showing "checking…" or making a redundant quota
|
|
88
91
|
* API call.
|
|
89
92
|
*/
|
|
90
|
-
seedMainFromStorage(storage: AccountStorage | null,
|
|
93
|
+
seedMainFromStorage(storage: AccountStorage | null, mainAccountId?: string): void;
|
|
91
94
|
private seedMainBackoffFromStorage;
|
|
92
95
|
/**
|
|
93
96
|
* Seed fallback cache entries from persisted account.quota data.
|
|
@@ -103,12 +106,18 @@ export declare class QuotaManager {
|
|
|
103
106
|
/**
|
|
104
107
|
* Whether a specific fallback account's quota API is in backoff.
|
|
105
108
|
*/
|
|
106
|
-
isFallbackBackedOff(accountId: string
|
|
109
|
+
isFallbackBackedOff(accountId: string): boolean;
|
|
107
110
|
getLastApiError(): AccountOperationError | undefined;
|
|
111
|
+
getMainQuotaErrorGeneration(): number;
|
|
112
|
+
getMainQuotaIdentityGeneration(): number;
|
|
113
|
+
getMainQuotaErrorClearedAt(): number | undefined;
|
|
114
|
+
clearMainBackoff(): number | undefined;
|
|
108
115
|
/** Minimum gap between consecutive quota API calls (ms). */
|
|
109
116
|
private static readonly API_CALL_GAP_MS;
|
|
110
117
|
private static fallbackInflightKey;
|
|
111
118
|
private static quotaLockName;
|
|
119
|
+
private bindFallbackLineage;
|
|
120
|
+
private acceptFallbackQuotaObservation;
|
|
112
121
|
/**
|
|
113
122
|
* Serialize API calls through a shared gate so only one
|
|
114
123
|
* quota API request runs at a time, with a minimum gap
|