import { type AuthCredential, type StoredAuthCredential } from "@oh-my-pi/pi-ai"; import type { RawSettings as Settings } from "../config/settings"; /** * Unified SQLite storage for agent settings, model usage, and auth credentials. * Delegates auth credential operations to AuthCredentialStore from @oh-my-pi/pi-ai. * Uses singleton pattern per database path; access via AgentStorage.open(). */ export declare class AgentStorage { #private; private constructor(); /** * Returns singleton instance for the given database path, creating if needed. * Retries on SQLITE_BUSY with exponential backoff. * @param dbPath - Path to the SQLite database file (defaults to config path) * @returns AgentStorage instance for the given path */ static open(dbPath?: string): Promise; /** * Retrieves all settings from storage (legacy, for migration only). * Settings are now stored in config.yml. This method is only used * during migration from agent.db to config.yml. * @returns Settings object, or null if no settings are stored * @deprecated Use config.yml instead. This is only for migration. */ getSettings(): Settings | null; /** * @deprecated Settings are now stored in config.yml, not agent.db. * This method is kept for backward compatibility but does nothing. */ saveSettings(settings: Settings): void; /** * Records model usage, updating the last-used timestamp. * @param modelKey - Model key in "provider/modelId" format */ recordModelUsage(modelKey: string): void; /** * Gets model keys ordered by most recently used. * Results are cached until recordModelUsage is called. * @returns Array of model keys ("provider/modelId") in MRU order */ getModelUsageOrder(): string[]; /** * Checks if any auth credentials exist in storage. * @returns True if at least one credential is stored */ hasAuthCredentials(): boolean; /** * Lists auth credentials, optionally filtered by provider. * Only returns active (non-disabled) credentials by default. * @param provider - Optional provider name to filter by * @param includeDisabled - If true, includes disabled credentials * @returns Array of stored credentials with their database IDs */ listAuthCredentials(provider?: string, includeDisabled?: boolean): StoredAuthCredential[]; /** * Atomically replaces all credentials for a provider. * Useful for OAuth token refresh where old tokens should be discarded. * @param provider - Provider name (e.g., "anthropic", "openai") * @param credentials - New credentials to store * @returns Array of newly stored credentials with their database IDs */ replaceAuthCredentialsForProvider(provider: string, credentials: AuthCredential[]): StoredAuthCredential[]; /** * Updates an existing auth credential by ID. * @param id - Database row ID of the credential to update * @param credential - New credential data */ updateAuthCredential(id: number, credential: AuthCredential): void; /** * Disables an auth credential by ID with a persisted cause. * @param id - Database row ID of the credential to disable * @param disabledCause - Human-readable cause stored with the disabled row */ deleteAuthCredential(id: number, disabledCause: string): void; /** * Disables all auth credentials for a provider with a persisted cause. * @param provider - Provider name whose credentials should be disabled * @param disabledCause - Human-readable cause stored with the disabled rows */ deleteAuthCredentialsForProvider(provider: string, disabledCause: string): void; /** * Gets a cached value by key. Returns null if not found or expired. */ getCache(key: string): string | null; /** * Sets a cached value with expiry time (unix seconds). */ setCache(key: string, value: string, expiresAtSec: number): void; /** * Deletes expired cache entries. Call periodically for cleanup. */ cleanExpiredCache(): void; }