import type { AuthAccountPolicyConfig } from "./auth-broker/discover.js"; import type { AuthCredentialStore } from "./auth/store.js"; import type { AuthApiKeyOptions, AuthStorageOptions, BlocksApi, CredentialsApi, HealthApi, KeysApi, LimitsApi, OAuthApi, ResetsApi, SessionsApi, UsageApi } from "./auth/types.js"; export { isSameOAuthAccount, isSqliteBusyError, isSqliteCorruptionError, matchesReplacementCredential, resolveCredentialIdentityKey, SqliteAuthCredentialStore, } from "./auth/sqlite-credential-store.js"; export * from "./auth/store.js"; export * from "./auth/types.js"; /** * Everything an {@link AuthStorage} delegates to: the namespaces plus store * lifecycle. The local backend composes the `./auth/` modules over an * {@link AuthCredentialStore}. Any other implementation passed to the * {@link AuthStorage} constructor is the cross-thread seam: e.g. a worker * thread's backend forwards every call to the main thread's `AuthStorage`. * * Namespace getters may return a different object after * {@link AuthStorageBackend.replaceStore}; callers re-read them per use. */ export interface AuthStorageBackend { /** Stored credential rows, change/disable events, broker snapshot. */ readonly credentials: CredentialsApi; /** Provider auth cascade and key overrides. */ readonly keys: KeysApi; /** OAuth login, account access, listings, refresh. */ readonly oauth: OAuthApi; /** Session → account pins and restrictions. */ readonly sessions: SessionsApi; /** Usage reports, header ingestion, history. */ readonly usage: UsageApi; /** Model pool health and per-credential probes. */ readonly health: HealthApi; /** Usage-limit marking and credential rotation. */ readonly limits: LimitsApi; /** Saved rate-limit resets. */ readonly resets: ResetsApi; /** Persisted rate-limit blocks (auth-broker server seam). */ readonly blocks: BlocksApi; /** See {@link AuthStorage.setAccountPolicies}. */ setAccountPolicies(config: AuthAccountPolicyConfig): void; /** See {@link AuthStorage.replaceStore}. */ replaceStore(store: AuthCredentialStore, options?: { sourceLabel?: string; }): Promise; /** See {@link AuthStorage.close}. */ close(): void; } /** * Credential management over an {@link AuthCredentialStore}: multi-account * selection with usage-aware ranking, rate-limit blocks, OAuth refresh, and * usage reporting. See the module doc for the namespace layout. * * Namespaces resolve against the current store on every access, so holders of * this instance follow {@link AuthStorage.replaceStore} without re-wiring. */ export declare class AuthStorage { #private; /** Serve every namespace from `backend` (cross-thread seam; see {@link AuthStorageBackend}). */ constructor(backend: AuthStorageBackend); /** Compose the credential modules over `store` (the local, single-process path). */ constructor(store: AuthCredentialStore, options?: AuthStorageOptions); /** Stored credential rows, change/disable events, broker snapshot. */ get credentials(): CredentialsApi; /** Provider auth cascade and key overrides. */ get keys(): KeysApi; /** OAuth login, account access, listings, refresh. */ get oauth(): OAuthApi; /** Session → account pins. */ get sessions(): SessionsApi; /** Usage reports, header ingestion, history. */ get usage(): UsageApi; /** Model pool health and per-credential probes. */ get health(): HealthApi; /** Usage-limit marking and credential rotation. */ get limits(): LimitsApi; /** Saved rate-limit resets. */ get resets(): ResetsApi; /** Persisted rate-limit blocks (auth-broker server seam). */ get blocks(): BlocksApi; /** * Apply new account routing policy (live `auth.accountPolicies` / * `retry.usageReservePct` change). Throws a configuration error, leaving the * active policy untouched, when a policy is malformed, a selector matches * several stored OAuth accounts, or two policies claim the same account; a * policy naming an absent account stays inactive and logs a warning. */ setAccountPolicies(config: AuthAccountPolicyConfig): void; /** * Swap the backing credential store in place (live `auth.broker.url` change). * Loads `store` into fresh store-bound state — pins, blocks, and usage caches are * keyed by the old store's row ids — then retires the previous store like * {@link AuthStorage.close}. Runtime key overrides, account policies, session * account restrictions, usage-provider overrides, and credential event * subscribers carry over. On a load failure * `store` is closed and the current store stays active. */ replaceStore(store: AuthCredentialStore, options?: { sourceLabel?: string; }): Promise; /** Open the SQLite store at `dbPath` and wrap it (standalone use, e.g. the pi-ai CLI). */ static create(dbPath: string, options?: AuthStorageOptions): Promise; /** * Close the underlying credential store; the instance must not be reused. * New OAuth refreshes are refused at once; a token exchange already under way * keeps the store open until it has saved the rotated token. */ close(): void; /** * Legacy redirect for callers of the pre-namespace flat API (e.g. repo scripts). * @deprecated Use {@link AuthStorage.keys}`.get`. */ getApiKey(provider: string, sessionId?: string, options?: AuthApiKeyOptions): Promise; /** * Legacy redirect for callers of the pre-namespace flat API (e.g. repo scripts). * @deprecated Use {@link AuthStorage.credentials}`.reload`. */ reload(): Promise; }