/** * Storage Factory * * Logger Category: storage.init * Purpose: Storage initialization and configuration * * Enable with: LOG_STORAGE_INIT=info npm run server * * What you'll see: * - Storage path and type selection * - Module loading and initialization * - Default data creation * - Environment detection * * Unified, type-safe interface for file-based, SQLite-based, and memory-based storage backends. * Provides environment detection, dynamic loading, caching, and NoOp browser implementations. * * Features: * - Environment detection (Node.js vs browser) with dynamic module loading * - Storage type selection (file/SQLite/memory) via configuration or environment variables * - Instance caching for performance and resource management * - Complete chat CRUD operations with strict type safety * - Memory storage for unit tests and browser environments * - Default SQLite storage in Node.js environments * * Implementation: * - File storage: Dynamic imports with disk-based JSON files * - SQLite storage: Schema-based with context and migration helpers * - Memory storage: In-memory Maps with full feature parity * - Browser: Memory storage with graceful environment detection * - Centralized environment detection and error handling * * Changes: * - 2026-03-05: Added bounded retry fallback for wrapper-level `loadAgent`/`loadAgentWithRetry` to tolerate transient storage read/consistency failures, while treating `null` loads as terminal not-found (no retry-delay penalty). * - 2026-03-05: Switched storage retry/timeout constants to shared reliability config. * - 2026-03-12: Removed dormant world-chat snapshot wrapper surface; chat persistence now uses metadata plus aggregated agent memory only. * - 2026-02-13: Added compare-and-set chat title helper wiring (`updateChatNameIfCurrent`) across wrappers and backends. * - 2025-08-07: Added memory storage for non-Node environments * - 2025-08-05: Consolidated code and removed redundant comments * - 2025-08-01: Added full chat CRUD and snapshot support * - 2025-07-27: Changed default storage type to SQLite * - 2025-10-31: Updated to structured logging (storage.init category) */ import type { StorageAPI } from '../types.js'; import { SQLiteConfig } from './sqlite-schema.js'; export type { StorageAPI } from '../types.js'; export interface StorageConfig { type: 'file' | 'sqlite' | 'memory'; rootPath: string; sqlite?: SQLiteConfig; } /** * Creates storage wrappers that implement StorageAPI and delegate to storage instance. * Provides unified interface across all storage backends with graceful NoOp fallbacks. */ export declare function createStorageWrappers(storageInstance: StorageAPI | null): StorageAPI; /** * Creates storage with environment-aware wrappers for browser/Node.js compatibility. */ export declare function createStorageWithWrappers(): Promise; export declare function createStorage(config: StorageConfig): Promise; export declare function getDefaultRootPath(): string; export declare function createStorageFromEnv(): Promise;