@cortexkit/anthropic-auth-core 1.15.1 → 1.17.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.
@@ -20,6 +20,7 @@ export type OAuthAccount = AccountBase & {
20
20
  lastRefreshError?: AccountOperationError;
21
21
  lastQuotaRefreshError?: AccountOperationError;
22
22
  quota?: OAuthQuotaSnapshot;
23
+ profile?: OAuthAccountProfile;
23
24
  };
24
25
  export type ApiKeyAccount = AccountBase & {
25
26
  type: 'api';
@@ -66,11 +67,34 @@ export type AccountScopedQuotaWindow = AccountQuotaWindow & {
66
67
  modelId?: string;
67
68
  modelName: string;
68
69
  };
70
+ export type QuotaMoney = {
71
+ amountMinor: number;
72
+ currency: string;
73
+ exponent: number;
74
+ };
75
+ export type OAuthExtraUsageSnapshot = {
76
+ used: QuotaMoney;
77
+ limit: QuotaMoney;
78
+ utilizationPercent?: number;
79
+ severity?: string;
80
+ exhausted: boolean;
81
+ };
82
+ export type OAuthAccountProfile = {
83
+ tier: string;
84
+ orgType: string;
85
+ checkedAt: number;
86
+ tokenFingerprint?: string;
87
+ };
69
88
  export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWindow>> & {
70
89
  scoped?: AccountScopedQuotaWindow[];
90
+ extraUsage?: OAuthExtraUsageSnapshot;
91
+ bindingWindow?: string;
92
+ bindingWindowSource?: 'poll' | 'headers';
93
+ fallbackAdvised?: boolean;
94
+ source?: 'poll' | 'headers';
71
95
  checkedAt?: number;
72
96
  };
73
- export type RoutingMode = 'main-first' | 'fallback-first';
97
+ export type RoutingMode = 'main-first' | 'fallback-first' | 'sticky-balanced';
74
98
  export type KillswitchThresholds = Partial<Record<QuotaWindowName | '5h' | '1w' | 'scoped', number>>;
75
99
  export type KillswitchConfig = {
76
100
  enabled?: boolean;
@@ -84,6 +108,7 @@ export type AccountStorage = {
84
108
  main?: {
85
109
  type: 'opencode';
86
110
  provider: 'anthropic';
111
+ profile?: OAuthAccountProfile;
87
112
  };
88
113
  routing?: {
89
114
  mode?: RoutingMode;
@@ -134,6 +159,7 @@ export type AccountStorage = {
134
159
  };
135
160
  cacheKeep?: {
136
161
  enabled?: boolean;
162
+ always?: boolean;
137
163
  startHour?: number;
138
164
  endHour?: number;
139
165
  subagents?: boolean;
@@ -154,10 +180,12 @@ export type AccountStorage = {
154
180
  * (to display the provider's real model costs).
155
181
  */
156
182
  export declare function isCostZeroingEnabled(storage: Pick<AccountStorage, 'costZeroing'>): boolean;
157
- export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
183
+ export type AccountRuntimeEntry = Partial<Pick<OAuthAccount, 'access' | 'refresh' | 'expires' | 'lastUsed' | 'lastRefreshedAt' | 'lastRefreshError' | 'lastQuotaRefreshError' | 'quota' | 'profile'> & Pick<ApiKeyAccount, 'apiKey' | 'lastUsed'>>;
158
184
  export type AccountRuntimeState = {
159
185
  version: 1;
160
186
  main?: {
187
+ profile?: OAuthAccountProfile;
188
+ profileToken?: string;
161
189
  quota?: OAuthQuotaSnapshot;
162
190
  quotaCheckedAt?: number;
163
191
  quotaToken?: string;
@@ -170,6 +198,7 @@ export type AccountRuntimeState = {
170
198
  accounts?: Record<string, AccountRuntimeEntry>;
171
199
  };
172
200
  export type AccountStateSaveScope = {
201
+ mainProfile?: boolean;
173
202
  mainQuota?: boolean;
174
203
  mainRefresh?: boolean;
175
204
  accounts?: true | string[];
@@ -189,8 +218,19 @@ export declare function getAccountStoragePath(): string;
189
218
  export declare function getAccountStatePath(configPath?: string): string;
190
219
  export declare function createEmptyStorage(): AccountStorage;
191
220
  export declare function loadAccounts(path?: string): Promise<AccountStorage | null>;
192
- export declare function saveAccounts(storage: AccountStorage, path?: string): Promise<void>;
221
+ export interface SaveAccountsOptions {
222
+ /** Account ids intentionally removed by this mutation. */
223
+ removedAccountIds?: readonly string[];
224
+ /** Preserve disk order when a stale snapshot is missing newer accounts. */
225
+ preserveExistingAccountOrder?: boolean;
226
+ }
227
+ export declare function saveAccounts(storage: AccountStorage, path?: string, options?: SaveAccountsOptions): Promise<void>;
193
228
  export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
229
+ export declare function saveOAuthProfileState(input: {
230
+ accountId: 'main' | string;
231
+ profile: OAuthAccountProfile | undefined;
232
+ expectedTokenFingerprint: string;
233
+ }, path?: string): Promise<boolean>;
194
234
  export declare function acquireRefreshFileLock(options: {
195
235
  name: string;
196
236
  ttlMs: number;
@@ -211,10 +251,15 @@ export declare function setDumpPersistentEnabled(enabled: boolean, path?: string
211
251
  export declare function isFastModePersistentlyEnabled(storage: AccountStorage | null): boolean;
212
252
  export declare function setFastModePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
213
253
  export declare function setCacheKeepPersistentWindow(startHour: number, endHour: number, path?: string): Promise<AccountStorage>;
254
+ export declare function setCacheKeepPersistentAlways(path?: string): Promise<AccountStorage>;
214
255
  export declare function setCacheKeepPersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
215
256
  export declare function isCacheKeepSubagentsEnabled(storage: AccountStorage | null): boolean;
216
257
  export declare function setCacheKeepSubagentsEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
217
258
  export declare function shouldFallbackStatus(status: number, storage: AccountStorage | null): boolean;
259
+ export declare function getQuotaMinimumRemainingThresholds(storage: AccountStorage | null): {
260
+ five_hour: number;
261
+ seven_day: number;
262
+ };
218
263
  export declare function getRefreshIntervalMs(storage: AccountStorage | null): number;
219
264
  export declare function hashRefreshToken(refreshToken: string): string;
220
265
  export declare function buildRefreshOperationError(input: {