@cortexkit/anthropic-auth-core 2.0.0 → 2.0.2
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 +16 -1
- package/dist/accounts.d.ts +1 -147
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2010 -3883
- package/dist/internal-types/fs/refresh-file-lock.d.ts +1 -1
- package/dist/internal-types/logger/engine.d.ts +6 -8
- package/dist/internal-types/pi-slot/slot.d.ts +2 -0
- package/dist/internal-types/quota/codec.d.ts +2 -0
- package/dist/internal-types/quota/index.d.ts +2 -2
- package/dist/internal-types/quota/map.d.ts +11 -0
- package/dist/internal-types/quota/merge.d.ts +3 -1
- package/dist/internal-types/quota/projection.d.ts +2 -1
- package/dist/internal-types/store/pool.d.ts +1 -0
- package/dist/internal-types/store/refresh-lock.d.ts +4 -0
- package/dist/internal-types/store/schema.d.ts +2 -0
- package/dist/native-account-view.d.ts +3 -1
- package/dist/native-settings.d.ts +6 -0
- package/dist/native-usage-publication.d.ts +1 -0
- package/dist/pool-authority.d.ts +1 -1
- package/dist/routing.d.ts +1 -2
- package/dist/sticky-routing.d.ts +4 -0
- package/package.json +5 -3
- package/dist/claustrum-scoped-roster.d.ts +0 -27
- package/dist/claustrum-scoped-runtime.d.ts +0 -31
- package/dist/claustrum-scoped.d.ts +0 -53
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# @cortexkit/anthropic-auth-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internal implementation package for CortexKit's OpenCode and Pi integrations. Apart from the named public surface below, exports are internal host-support APIs with **no stability promise**.
|
|
4
|
+
|
|
5
|
+
## Public, stable surface
|
|
6
|
+
|
|
7
|
+
These root exports are public and stable for external callers, including Synapse's Anthropic request client:
|
|
8
|
+
|
|
9
|
+
- `resolveClaudeCodeIdentity`
|
|
10
|
+
- `buildBillingHeaderValue`
|
|
11
|
+
- `CLAUDE_CODE_ENTRYPOINT`
|
|
12
|
+
- `CLAUDE_CODE_IDENTITY`
|
|
13
|
+
- `applyClaudeCodeMetadata`
|
|
14
|
+
- `applyClaudeCodeHeaders`
|
|
15
|
+
- `signRequestBody`
|
|
16
|
+
- `orderClaudeCodeBody`
|
|
17
|
+
|
|
18
|
+
The export-manifest test pins these names to the actual root barrel. Legacy sidecar writers and pre-native scoped runtime APIs are removed; host credentials and settings use native storage. Upgrade migration and one-time vault seeding still read the old sidecar format.
|
|
4
19
|
|
|
5
20
|
User-facing packages:
|
|
6
21
|
|
package/dist/accounts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderAccountUuid } from './claude-code.ts';
|
|
2
2
|
import { type Cache1hMode } from './constants.ts';
|
|
3
|
-
import {
|
|
3
|
+
import type { LogLevel } from './logger.ts';
|
|
4
4
|
export type { ProviderAccountUuid } from './claude-code.ts';
|
|
5
5
|
export declare const ACCOUNT_FILE_NAME = "anthropic-auth.json";
|
|
6
6
|
export declare const ACCOUNT_STATE_FILE_NAME = "anthropic-auth-state.json";
|
|
@@ -295,66 +295,17 @@ export type AccountStateSaveScope = {
|
|
|
295
295
|
mainPrime?: boolean;
|
|
296
296
|
accounts?: true | string[];
|
|
297
297
|
};
|
|
298
|
-
export type AccountManagerOptions = {
|
|
299
|
-
now?: () => number;
|
|
300
|
-
fetchImpl?: typeof fetch;
|
|
301
|
-
configPath?: string;
|
|
302
|
-
quotaManager?: import('./quota-manager.ts').QuotaManager;
|
|
303
|
-
isFallbackAccountVaultServed?: (accountId: string, storage: AccountStorage) => boolean;
|
|
304
|
-
isFallbackAccountVaultEnabled?: (accountId: string, storage: AccountStorage) => boolean;
|
|
305
|
-
resolveFallbackAccessToken?: (account: OAuthAccount, storage: AccountStorage) => {
|
|
306
|
-
token: string;
|
|
307
|
-
source: 'vault' | 'sidecar';
|
|
308
|
-
} | undefined;
|
|
309
|
-
onBackgroundRefresh?: (initial?: boolean) => Promise<void> | void;
|
|
310
|
-
onFallbackStorageChanged?: () => void;
|
|
311
|
-
setIntervalImpl?: typeof globalThis.setInterval;
|
|
312
|
-
clearIntervalImpl?: typeof globalThis.clearInterval;
|
|
313
|
-
};
|
|
314
|
-
export type AccountRefreshError = {
|
|
315
|
-
accountId: string;
|
|
316
|
-
message: string;
|
|
317
|
-
};
|
|
318
298
|
export declare const FALLBACK_BACKGROUND_TICK_MS = 60000;
|
|
319
299
|
export declare function getAccountStoragePath(): string;
|
|
320
300
|
export declare function getAccountStatePath(configPath?: string): string;
|
|
321
301
|
export declare function createEmptyStorage(): AccountStorage;
|
|
322
302
|
export declare function mergeMainQuotaErrorClearedAt(existing: number | undefined, incoming: number | undefined): number | undefined;
|
|
323
303
|
export declare function mergeMainRefreshErrorClearedAt(existing: number | undefined, incoming: number | undefined): number | undefined;
|
|
324
|
-
export declare function loadAccounts(path?: string): Promise<AccountStorage | null>;
|
|
325
304
|
/** Returns the latest timestamp carried by any quota snapshot window. */
|
|
326
305
|
export declare function quotaSnapshotCheckedAt(quota: OAuthQuotaSnapshot | undefined): number;
|
|
327
306
|
export declare function quotaFieldSource(snapshot: OAuthQuotaSnapshot | undefined, field: QuotaFieldName): QuotaFieldSource | undefined;
|
|
328
307
|
export declare function mergeHeaderQuotaForPersistence(existing: OAuthQuotaSnapshot | undefined, incoming: OAuthQuotaSnapshot): OAuthQuotaSnapshot;
|
|
329
308
|
export declare function getClaustrumMode(storage: AccountStorage | null): ClaustrumMode;
|
|
330
|
-
export declare function setClaustrumModePersistent(mode: ClaustrumMode, path?: string): Promise<'changed' | 'unchanged'>;
|
|
331
|
-
export interface SaveAccountsOptions {
|
|
332
|
-
/** Account ids intentionally removed by this mutation. */
|
|
333
|
-
removedAccountIds?: readonly string[];
|
|
334
|
-
/** Preserve disk order when a stale snapshot is missing newer accounts. */
|
|
335
|
-
preserveExistingAccountOrder?: boolean;
|
|
336
|
-
}
|
|
337
|
-
export declare function saveAccounts(storage: AccountStorage, path?: string, options?: SaveAccountsOptions): Promise<void>;
|
|
338
|
-
/** Read-modify-write account configuration under the existing config/state lock order.
|
|
339
|
-
* The callback is synchronous: network discovery must happen under its own outer
|
|
340
|
-
* lease, never while holding the config lock. Do not call another persistence API
|
|
341
|
-
* from the callback.
|
|
342
|
-
*/
|
|
343
|
-
export declare function mutateAccountsPersistent<T>(path: string, mutate: (storage: AccountStorage) => {
|
|
344
|
-
storage: AccountStorage;
|
|
345
|
-
result: T;
|
|
346
|
-
options?: SaveAccountsOptions;
|
|
347
|
-
save?: boolean;
|
|
348
|
-
}, options?: {
|
|
349
|
-
assertAuthority?: () => Promise<void>;
|
|
350
|
-
}): Promise<T>;
|
|
351
|
-
export declare function getOrCreateMainAccountId(path?: string, createId?: () => string): Promise<string>;
|
|
352
|
-
export declare function saveAccountState(storage: AccountStorage, path?: string, scope?: AccountStateSaveScope): Promise<void>;
|
|
353
|
-
export declare function saveOAuthProfileState(input: {
|
|
354
|
-
accountId: 'main' | string;
|
|
355
|
-
profile: OAuthAccountProfile | undefined;
|
|
356
|
-
accountIdentity?: string;
|
|
357
|
-
}, path?: string): Promise<boolean>;
|
|
358
309
|
export declare function acquireRefreshFileLock(options: {
|
|
359
310
|
name: string;
|
|
360
311
|
ttlMs: number;
|
|
@@ -369,30 +320,10 @@ export declare function acquireRefreshFileLock(options: {
|
|
|
369
320
|
} | null>;
|
|
370
321
|
export declare function isCache1hPersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
371
322
|
export declare function getCache1hPersistentMode(storage: AccountStorage | null): Cache1hMode;
|
|
372
|
-
export declare function setCache1hPersistentEnabled(enabled: boolean, mode?: Cache1hMode, path?: string): Promise<AccountStorage>;
|
|
373
|
-
export declare function setCache1hPersistentMode(mode: Cache1hMode, path?: string): Promise<AccountStorage>;
|
|
374
323
|
export declare function isDumpPersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
375
|
-
export declare function setDumpPersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
376
324
|
export declare function isFastModePersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
377
|
-
export declare function setFastModePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
378
|
-
export declare function setCacheKeepPersistentWindow(startHour: number, endHour: number, path?: string): Promise<AccountStorage>;
|
|
379
|
-
export declare function setCacheKeepPersistentAlways(path?: string): Promise<AccountStorage>;
|
|
380
|
-
export declare function setCacheKeepPersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
381
325
|
export declare function isCacheKeepSubagentsEnabled(storage: AccountStorage | null): boolean;
|
|
382
|
-
export declare function setCacheKeepSubagentsEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
383
326
|
export declare function isPrimePersistentlyEnabled(storage: AccountStorage | null): boolean;
|
|
384
|
-
export declare function setPrimePersistentEnabled(enabled: boolean, path?: string): Promise<AccountStorage>;
|
|
385
|
-
/** Return the stable prime marker identity for an OAuth account. */
|
|
386
|
-
export declare function getOrCreatePrimeAuthLineageId(accountId: 'main' | string, path?: string): Promise<string | undefined>;
|
|
387
|
-
/**
|
|
388
|
-
* Atomically increment an account's cumulative prime counters and persist via
|
|
389
|
-
* the scoped runtime-state path. The `main` account lives at state.main.prime;
|
|
390
|
-
* every other account lives at state.accounts[id].prime. Config-side writes
|
|
391
|
-
* are intentionally NOT triggered so prime counters cannot leak into
|
|
392
|
-
* `anthropic-auth.json`. Callers should not depend on this function to mutate
|
|
393
|
-
* the caller's storage object.
|
|
394
|
-
*/
|
|
395
|
-
export declare function incrementPrimeUsagePersistent(accountId: 'main' | string, usage: PrimeUsageDelta, path?: string, now?: number): Promise<PrimeUsageCounters>;
|
|
396
327
|
export declare function shouldFallbackStatus(status: number, storage: AccountStorage | null): boolean;
|
|
397
328
|
export declare function getQuotaMinimumRemainingThresholds(storage: AccountStorage | null): {
|
|
398
329
|
five_hour: number;
|
|
@@ -438,7 +369,6 @@ export declare function quotaBackoffActive(error: AccountOperationError | undefi
|
|
|
438
369
|
export declare function formatQuotaBackoffMessage(error: AccountOperationError, now: number): string;
|
|
439
370
|
export declare function getQuotaCheckIntervalMs(storage: AccountStorage | null): number;
|
|
440
371
|
export declare function getPersistedLogLevel(storage: AccountStorage | null): LogLevel | undefined;
|
|
441
|
-
export declare function setLogLevelPersistent(level: LogLevel, path?: string): Promise<void>;
|
|
442
372
|
export declare function getPersistedMainQuota(storage: AccountStorage | null): {
|
|
443
373
|
quota: OAuthQuotaSnapshot;
|
|
444
374
|
checkedAt: number;
|
|
@@ -482,86 +412,10 @@ export declare function killswitchRetryAfterSeconds(mainQuota: OAuthQuotaSnapsho
|
|
|
482
412
|
quota?: OAuthQuotaSnapshot;
|
|
483
413
|
}>, now: number, scopedModelId?: string): number;
|
|
484
414
|
export declare function getKillswitchConfig(storage: AccountStorage | null): KillswitchConfig;
|
|
485
|
-
export declare function setKillswitchPersistent(config: KillswitchConfig, path?: string): Promise<AccountStorage>;
|
|
486
|
-
export declare function removeAccountPersistent(id: string, path?: string): Promise<boolean>;
|
|
487
|
-
export declare function reorderAccountsPersistent(orderedIds: string[], path?: string): Promise<void>;
|
|
488
|
-
export declare function setAccountEnabledPersistent(id: string, enabled: boolean, path?: string): Promise<boolean>;
|
|
489
|
-
export declare function addAccountPersistent(account: FallbackAccount, path?: string): Promise<void>;
|
|
490
415
|
export declare function getQuotaNextRefreshAt(quota: OAuthQuotaSnapshot | undefined, storage: AccountStorage | null, now: number): number;
|
|
491
416
|
export declare function fetchOAuthQuotaSnapshot(input: {
|
|
492
417
|
accessToken: string;
|
|
493
418
|
fetchImpl?: typeof fetch;
|
|
494
419
|
now?: () => number;
|
|
495
420
|
}): Promise<OAuthQuotaSnapshot>;
|
|
496
|
-
export declare function upsertAccount(storage: AccountStorage, account: FallbackAccount): void;
|
|
497
|
-
export declare function persistFallbackQuotaHeaderPersistent(input: {
|
|
498
|
-
accountId: string;
|
|
499
|
-
authLineageId?: string;
|
|
500
|
-
quota: OAuthQuotaSnapshot;
|
|
501
|
-
anthropicAccountUuid?: ProviderAccountUuid;
|
|
502
|
-
}, path?: string): Promise<boolean>;
|
|
503
421
|
export declare function fallbackAccountUuidForLineage(account: OAuthAccount | undefined, authLineageId?: string): string | null;
|
|
504
|
-
export declare function removeAccount(storage: AccountStorage, id: string): boolean;
|
|
505
|
-
export declare function reorderAccounts(storage: AccountStorage, orderedIds: string[]): void;
|
|
506
|
-
export declare function setAccountEnabled(storage: AccountStorage, id: string, enabled: boolean): boolean;
|
|
507
|
-
export declare class FallbackAccountManager {
|
|
508
|
-
private readonly now;
|
|
509
|
-
private readonly fetchImpl;
|
|
510
|
-
private readonly configPath;
|
|
511
|
-
private readonly refreshPromises;
|
|
512
|
-
private readonly custodyVerificationAccounts;
|
|
513
|
-
private refreshTimer;
|
|
514
|
-
private quotaTimer;
|
|
515
|
-
readonly quotaManager: import('./quota-manager.ts').QuotaManager | null;
|
|
516
|
-
private readonly isFallbackAccountVaultServed;
|
|
517
|
-
private readonly isFallbackAccountVaultEnabled;
|
|
518
|
-
private readonly resolveFallbackAccessToken;
|
|
519
|
-
private readonly onBackgroundRefresh;
|
|
520
|
-
private readonly onFallbackStorageChanged;
|
|
521
|
-
private readonly setIntervalImpl;
|
|
522
|
-
private readonly clearIntervalImpl;
|
|
523
|
-
constructor(options?: AccountManagerOptions);
|
|
524
|
-
/**
|
|
525
|
-
* Seed QuotaManager from persisted account.quota if no cache entry exists
|
|
526
|
-
* yet. Prevents unnecessary API calls when the on-disk snapshot is fresh.
|
|
527
|
-
*/
|
|
528
|
-
private seedFallbackQuota;
|
|
529
|
-
load(): Promise<AccountStorage | null>;
|
|
530
|
-
save(storage: AccountStorage, accountIds?: string[]): Promise<void>;
|
|
531
|
-
startBackgroundRefresh(): Promise<void>;
|
|
532
|
-
stopBackgroundRefresh(): void;
|
|
533
|
-
withAccountRefreshLock<T>(accountId: string, fn: () => Promise<T>): Promise<T>;
|
|
534
|
-
getUsableFallbackAccounts(existingStorage?: AccountStorage | null, options?: {
|
|
535
|
-
modelId?: string;
|
|
536
|
-
}): Promise<OAuthAccount[]>;
|
|
537
|
-
markUsed(account: FallbackAccount): Promise<void>;
|
|
538
|
-
accountPassesQuotaPolicy(account: OAuthAccount, storage: AccountStorage | null, options?: {
|
|
539
|
-
modelId?: string;
|
|
540
|
-
}): boolean;
|
|
541
|
-
/**
|
|
542
|
-
* Return the account with its quota overlaid from the unified QuotaManager
|
|
543
|
-
* cache (token-bound) when available, so quota-policy decisions use the same
|
|
544
|
-
* source of truth as the staleness check. Falls back to the stored
|
|
545
|
-
* account.quota when no manager is wired or the cache has no entry.
|
|
546
|
-
*/
|
|
547
|
-
private quotaPolicyAccount;
|
|
548
|
-
refreshDueAccounts(): Promise<void>;
|
|
549
|
-
refreshQuotaForDueAccounts(): Promise<void>;
|
|
550
|
-
refreshQuotaForAllAccounts(options?: {
|
|
551
|
-
force?: boolean;
|
|
552
|
-
}): Promise<{
|
|
553
|
-
storage: AccountStorage | null;
|
|
554
|
-
errors: AccountRefreshError[];
|
|
555
|
-
}>;
|
|
556
|
-
refreshAccount(account: OAuthAccount, storage: AccountStorage, options?: {
|
|
557
|
-
force?: boolean;
|
|
558
|
-
persistError?: boolean;
|
|
559
|
-
}): Promise<OAuthAccount>;
|
|
560
|
-
private waitForConcurrentFallbackRefresh;
|
|
561
|
-
private refreshAccountNow;
|
|
562
|
-
refreshAccountQuota(account: OAuthAccount, storage: AccountStorage): Promise<{
|
|
563
|
-
account: OAuthAccount;
|
|
564
|
-
fetched: boolean;
|
|
565
|
-
changed: boolean;
|
|
566
|
-
}>;
|
|
567
|
-
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,6 @@ export * from './cch.ts';
|
|
|
7
7
|
export * from './claude-code.ts';
|
|
8
8
|
export * from './claustrum.ts';
|
|
9
9
|
export * from './claustrum-enrollment.ts';
|
|
10
|
-
export * from './claustrum-scoped.ts';
|
|
11
|
-
export * from './claustrum-scoped-roster.ts';
|
|
12
|
-
export * from './claustrum-scoped-runtime.ts';
|
|
13
10
|
export * from './commands/account.ts';
|
|
14
11
|
export * from './constants.ts';
|
|
15
12
|
export * from './custom-headers.ts';
|
|
@@ -46,6 +43,7 @@ export { NativeMigrationError, prepareNativeMigration, releaseNativeMigrationPre
|
|
|
46
43
|
export type { NativeCommittedMaterial, NativeIdentityBootstrap, NativeRefreshContext, NativeRefreshDispatchVersion, NativeRefreshFailure, NativeRefreshHandoff, NativeRefreshObservation, NativeRefreshRequest, NativeRefreshRestriction, NativeRefreshResult, NativeRefreshSubject, NativeServingAdmission, } from './native-refresh-coordinator.ts';
|
|
47
44
|
export type { NativeLocalFailureAttribution, NativeLocalFailurePolicy, NativeLocalFailureSkipReason, } from './native-runtime.ts';
|
|
48
45
|
export { nativeRuntimeOptionIdentity } from './native-runtime-registry.ts';
|
|
46
|
+
export * from './native-settings.ts';
|
|
49
47
|
export { isNativeTransientAccountError, NativeTransientAccountError, } from './native-transient-account.ts';
|
|
50
48
|
export type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, CommandMenu, CommandMenuModel, KnobValue, KnobValues, MenuAction, MenuItem, MenuKnob, MenuSection, NativeUiOptions, NotifyKind, SectionSlot, } from './native-ui.ts';
|
|
51
49
|
export { createNativeUi, parseApplyRequest, runPiCommandMenu, } from './native-ui.ts';
|