/** * Postgres-backed ContextStorage adapter. * * Provides production-grade persistence using Postgres with safe transactions * and best-effort recovery for corrupted rows. */ import type { Pool } from 'pg'; import type { ContextStorage, ConversationContext, SessionSummary } from '../context'; /** * Configuration options for PostgresContextStorage. */ export interface PostgresContextStorageOptions { /** * Connection string for Postgres (e.g., postgres://user:pass@host:5432/db). * Either connectionString or pool must be provided. */ connectionString?: string; /** * Pre-configured Pool instance for dependency injection (useful for testing). * Either connectionString or pool must be provided. */ pool?: Pool; } /** * Postgres-backed implementation of ContextStorage. * * Features: * - Lazy schema initialization with CREATE TABLE IF NOT EXISTS * - Transactional writes for data integrity * - Best-effort recovery with warnings for corrupted rows * - Support for both connection string and injected pool (for testing) */ export declare class PostgresContextStorage implements ContextStorage { private pool; private initialized; private initPromise; constructor(options: PostgresContextStorageOptions); /** * Lazily initialize the database schema. * Safe to call multiple times; only executes once. */ private ensureInitialized; private initializeSchema; /** * Get a conversation context by ID. * Returns null if the conversation doesn't exist. * Uses best-effort recovery, logging warnings for corrupted message rows. */ get(id: string): Promise; /** * Store a conversation context. * Uses a transaction to ensure atomic writes: * 1. Upsert conversation metadata * 2. Delete existing messages * 3. Insert new messages with sequence numbers */ set(id: string, context: ConversationContext): Promise; /** * List session summaries ordered by updated_at DESC. */ listSessions(): Promise; /** * Delete a conversation and all its messages. * Messages are automatically deleted via CASCADE. */ delete(id: string): Promise; /** * Clear all conversations and messages. */ clear(): Promise; /** * Close the connection pool. * Call this when shutting down to release resources. */ close(): Promise; } //# sourceMappingURL=postgres.d.ts.map