@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.
@@ -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 mainTokenFp;
29
+ private mainAccountId;
30
+ private mainQuotaIdentityKnown;
31
+ private mainQuotaIdentityStrict;
32
+ private mainGeneration;
33
+ private mainQuotaErrorGeneration;
34
+ private mainQuotaErrorClearedAt;
30
35
  private fallbacks;
31
- private fallbackTokenFps;
36
+ private fallbackAuthLineages;
37
+ private fallbackGenerations;
32
38
  private inflightMain;
33
- private inflightMainFp;
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. Pass the live access token to enforce token
48
- * binding: if the cached entry was produced by a different token (main
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(accessToken?: string): QuotaEntry | null;
55
+ getMain(mainAccountId?: string): QuotaEntry | null;
54
56
  /**
55
- * Cached fallback quota entry. Pass the live access token to enforce token
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, accessToken?: string): QuotaEntry | null;
59
+ getFallback(accountId: string, account?: Pick<OAuthAccount, 'authLineageId'>): QuotaEntry | null;
60
60
  getAllFallbacks(): Map<string, QuotaEntry>;
61
- setMain(accessToken: string, entry: QuotaEntry): void;
62
- setFallback(accountId: string, entry: QuotaEntry, accessToken?: string): void;
63
- pushMainFromHeaders(accessToken: string, incoming: OAuthQuotaSnapshot): QuotaEntry;
64
- pushFallbackFromHeaders(accountId: string, accessToken: string, incoming: OAuthQuotaSnapshot): QuotaEntry;
65
- refreshMain(accessToken: string): Promise<OAuthQuotaSnapshot>;
66
- refreshMainWithMetadata(accessToken: string): Promise<QuotaRefreshResult>;
67
- refreshFallback(accountId: string, accessToken: string): Promise<OAuthQuotaSnapshot>;
68
- refreshFallbackWithMetadata(accountId: string, accessToken: string): Promise<QuotaRefreshResult>;
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, accessToken?: string, modelId?: string): boolean;
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, accessToken?: string): void;
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, accessToken?: string): boolean;
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