/** * Content-addressable cache for tool responses. * Enables reuse of tool call results and LLM analysis across personas. */ /** * Cache entry with metadata. */ export interface CacheEntry { /** The cached value */ value: T; /** When the entry was created */ createdAt: Date; /** When the entry was last accessed */ lastAccessedAt: Date; /** When the entry expires */ expiresAt: Date; /** Cache key (hash) */ key: string; /** Human-readable description of what's cached */ description?: string; /** Number of times this entry has been accessed */ hitCount: number; } /** * Cache statistics. */ export interface CacheStats { /** Total number of cache hits */ hits: number; /** Total number of cache misses */ misses: number; /** Current number of entries */ entries: number; /** Total bytes used (approximate) */ sizeBytes: number; /** Hit rate as percentage */ hitRate: number; } /** * Cache configuration. */ export interface CacheConfig { /** Default TTL in milliseconds (default: 3600000 = 1 hour) */ defaultTTLMs?: number; /** Maximum number of entries (default: 1000) */ maxEntries?: number; /** Maximum total size in bytes (default: 50MB) */ maxSizeBytes?: number; /** Whether to enable cache (default: true) */ enabled?: boolean; /** Optional cache directory for persistence */ dir?: string; } /** * In-memory content-addressable cache. */ export declare class ResponseCache { private cache; private config; private stats; private totalSizeBytes; private cacheDir?; constructor(config?: CacheConfig); /** * Generate a cache key from input data. */ generateKey(...parts: unknown[]): string; /** * Get an entry from cache. */ get(key: string): T | undefined; /** * Set an entry in cache. */ set(key: string, value: T, options?: { ttlMs?: number; description?: string; }): void; /** * Check if key exists and is not expired. */ has(key: string): boolean; /** * Delete an entry. */ delete(key: string): boolean; /** * Clear all entries. */ clear(): void; /** * Get cache statistics. */ getStats(): CacheStats; /** * Get or compute a value. */ getOrCompute(key: string, compute: () => Promise, options?: { ttlMs?: number; description?: string; }): Promise; /** * Evict entries if needed to make room. */ private evictIfNeeded; /** * Evict the least recently used entry (LRU based on last access time). */ private evictLeastRecentlyUsed; /** * Estimate the size of a value in bytes. */ private estimateSize; private ensureCacheDir; private getCachePath; private saveToDisk; private loadFromDisk; private deleteFromDisk; } /** * Specialized cache for tool responses. */ export declare class ToolResponseCache extends ResponseCache { /** * Generate key for a tool call. */ toolCallKey(toolName: string, args: Record): string; /** * Get cached tool response. */ getToolResponse(toolName: string, args: Record): T | undefined; /** * Cache a tool response. */ setToolResponse(toolName: string, args: Record, response: T, ttlMs?: number): void; /** * Generate key for LLM analysis. */ analysisKey(toolName: string, args: Record, responseHash: string): string; /** * Get cached analysis. */ getAnalysis(toolName: string, args: Record, responseHash: string): string | undefined; /** * Cache an analysis. */ setAnalysis(toolName: string, args: Record, responseHash: string, analysis: string, ttlMs?: number): void; /** * Hash a response for use in analysis key. */ hashResponse(response: unknown): string; } /** * Get or create the global cache instance. */ export declare function getGlobalCache(config?: CacheConfig): ToolResponseCache; /** * Reset the global cache (for testing). */ export declare function resetGlobalCache(): void; //# sourceMappingURL=response-cache.d.ts.map