/** * @module memory/database * @description Thread-safe SQLite database manager for the SAP MCP agent memory subsystem. * * Uses better-sqlite3 (synchronous, native, FTS5-enabled) with WAL mode for * concurrent read access. The database is a singleton — one connection per process. * * Design principles: * - Synchronous I/O: better-sqlite3 is synchronous, no async overhead, no callback hell. * - WAL mode: readers don't block writers, crash-safe via WAL journal. * - Prepared statements: cached for performance, reused across calls. * - FTS5: inverted full-text index for relevance-ranked retrieval. * - Schema versioning: idempotent migrations on init. * - Graceful degradation: if the DB can't be opened, tools return empty results. */ import type { Database as DatabaseType, Statement } from 'better-sqlite3'; import type { MemoryConfig } from './types.js'; /** * @name DEFAULT_CONFIG * @description Default memory configuration. The DB is stored in * ~/.config/mcp-sap/memory/ which is the standard SAP MCP config directory. */ export declare const DEFAULT_CONFIG: MemoryConfig; /** * @name MemoryDatabase * @description Thread-safe singleton managing the SQLite connection for agent memory. * * The class lazily initializes the database on first access and caches prepared * statements for performance. All methods are synchronous (better-sqlite3 is * synchronous by design). The database runs in WAL mode for concurrent reads. * * If the database cannot be opened (e.g. disk full, permissions), the instance * enters a degraded mode where all queries return empty results instead of * crashing the MCP server. */ export declare class MemoryDatabase { private db; private readonly config; private degraded; private initialized; private statements; constructor(config?: Partial); /** * @name init * @description Initializes the database connection, creates the schema, and * enables WAL mode. Called lazily on first query. */ init(): void; /** * @name getDb * @description Returns the underlying Database instance. Throws if degraded. * @internal */ getDb(): DatabaseType; /** * @name isDegraded * @description Returns true if the database is in degraded mode (init failed). */ isDegraded(): boolean; /** * @name getStatement * @description Returns a cached prepared statement by key. * @internal */ getStatement(key: string): Statement | undefined; /** * @name close * @description Closes the database connection gracefully. */ close(): void; /** * @name getDbSize * @description Returns the database file size in bytes. */ getDbSize(): number; /** * @name runMigrations * @description Runs idempotent schema migrations. Each migration checks if * the current schema version is below the target and applies changes. * @internal */ private runMigrations; /** * @name migrateToV1 * @description Creates the initial schema: tool_calls, agent_memory, * stream_buffers, and their FTS5 indexes. * @internal */ private migrateToV1; /** * @name prepareStatements * @description Pre-compiles and caches frequently used SQL statements. * @internal */ private prepareStatements; } /** * @name memoryDatabase * @description Singleton instance of the memory database. * Lazily initialized on first access. Shared across all memory tools. */ export declare const memoryDatabase: MemoryDatabase; //# sourceMappingURL=database.d.ts.map