/**
* SQLite Memory Manager with Fallback Support
*
* Implements 12 specialized tables for persistent memory coordination
* across agent swarms with optimized performance and cross-platform compatibility
*
* Fallback hierarchy:
* 1. better-sqlite3 (performance optimized)
* 2. sqlite3 (Node.js compatible)
* 3. sql.js (WASM cross-platform)
*/
///
import { EventEmitter } from "events";
import { SQLiteImplementation } from "./sqlite-adapter.js";
export interface MemoryEntry {
id?: number;
key: string;
value: any;
namespace: string;
metadata?: any;
ttl?: number;
created_at?: number;
updated_at?: number;
access_count?: number;
}
export interface NamespaceInfo {
namespace: string;
keyCount: number;
totalSize: number;
lastAccessed: number;
created: number;
}
export interface NamespaceOperations {
store(entry: MemoryEntry): Promise;
retrieve(key: string, namespace?: string): Promise;
delete(key: string, namespace?: string): Promise;
search(pattern: string, namespace?: string, options?: SearchOptions): Promise;
list(namespace?: string, includeMetadata?: boolean): Promise;
cleanup(namespace?: string): Promise;
getNamespaceInfo(namespace?: string): Promise;
deleteNamespace(namespace: string): Promise;
}
export interface SearchOptions {
limit?: number;
sortBy?: "created_at" | "updated_at" | "access_count" | "key";
sortOrder?: "asc" | "desc";
includeExpired?: boolean;
keyPattern?: string;
valuePattern?: string;
}
export declare class NamespaceUtils {
/**
* Validates namespace format (hierarchical paths allowed)
*/
static validateNamespace(namespace: string): boolean;
/**
* Normalizes namespace path (removes duplicates slashes, trims)
*/
static normalizeNamespace(namespace: string): string;
/**
* Gets parent namespace from hierarchical path
*/
static getParentNamespace(namespace: string): string | null;
/**
* Gets namespace depth (number of levels)
*/
static getNamespaceDepth(namespace: string): number;
/**
* Checks if namespace matches pattern (supports wildcards)
*/
static matchesPattern(namespace: string, pattern: string): boolean;
/**
* Lists all child namespaces
*/
static getChildNamespaces(parentNamespace: string, allNamespaces: string[]): string[];
}
export declare class SQLiteMemoryManager extends EventEmitter implements NamespaceOperations {
private db;
private logger;
private cleanupInterval?;
private implementation;
private constructor();
/**
* Create a new SQLiteMemoryManager instance with fallback support
*/
static create(dbPath?: string, preferredImpl?: SQLiteImplementation): Promise;
/**
* Initialize all 12 specialized tables
*/
private initializeTables;
/**
* Store memory entry with namespace validation and hierarchy support
*/
store(entry: MemoryEntry): Promise;
/**
* Retrieve memory entry with namespace support and wildcard matching
*/
retrieve(key: string, namespace?: string): Promise;
/**
* Enhanced search with namespace patterns and advanced filtering
*/
search(pattern: string, namespace?: string, options?: SearchOptions): Promise;
/**
* Record metric
*/
recordMetric(name: string, value: number, unit?: string, tags?: any): Promise;
/**
* Get metrics summary
*/
getMetricsSummary(name: string, timeRange?: number): Promise;
/**
* Cleanup expired entries
*/
private startCleanupTask;
/**
* Get current implementation info
*/
getImplementationInfo(): Promise<{
name: SQLiteImplementation;
available: SQLiteImplementation[];
}>;
/**
* Test database connection and functionality
*/
testConnection(): Promise;
/**
* Delete a specific memory entry
*/
delete(key: string, namespace?: string): Promise;
/**
* List all entries in a namespace
*/
list(namespace?: string, includeMetadata?: boolean): Promise;
/**
* Cleanup expired entries in a namespace
*/
cleanup(namespace?: string): Promise;
/**
* Get namespace information and statistics
*/
getNamespaceInfo(namespace?: string): Promise;
/**
* Delete entire namespace and all its entries
*/
deleteNamespace(namespace: string): Promise;
/**
* Get namespace-specific metrics and analytics
*/
getNamespaceMetrics(namespace?: string, timeRange?: number): Promise;
/**
* Close database connection
*/
close(): void;
}
//# sourceMappingURL=sqlite-manager.d.ts.map