UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

134 lines 3.26 kB
/** * AI Response Cache System * Phase 5, Checkpoint E1 - Intelligent caching to avoid regeneration and improve performance */ export interface CacheEntry { key: string; prompt: string; response: any; model: string; timestamp: Date; ttl: number; metadata: { responseTime: number; tokenCount?: number; quality?: number; usage_count: number; last_accessed: Date; }; tags: string[]; } export interface CacheOptions { ttl?: number; maxSize?: number; persistToDisk?: boolean; cacheDirectory?: string; compressionEnabled?: boolean; qualityThreshold?: number; } export interface CacheStats { totalEntries: number; hitRate: number; missRate: number; totalSize: number; oldestEntry?: Date; newestEntry?: Date; averageResponseTime: number; topTags: Array<{ tag: string; count: number; }>; } export interface SearchOptions { tags?: string[]; model?: string; minQuality?: number; dateRange?: { from: Date; to: Date; }; limit?: number; sortBy?: 'timestamp' | 'quality' | 'usage' | 'relevance'; } export declare class AIResponseCache { private cache; private options; private stats; constructor(options?: CacheOptions); /** * Get cached response for a prompt */ get(prompt: string, model?: string, tags?: string[]): Promise<any | null>; /** * Store response in cache */ set(prompt: string, response: any, model: string, responseTime: number, options?: { ttl?: number; tags?: string[]; quality?: number; tokenCount?: number; }): Promise<boolean>; /** * Search cached entries */ search(query: string, options?: SearchOptions): CacheEntry[]; /** * Get similar cached responses using basic text similarity */ findSimilar(prompt: string, threshold?: number, limit?: number): CacheEntry[]; /** * Clear cache entries by criteria */ clear(criteria?: { tags?: string[]; model?: string; olderThan?: Date; qualityBelow?: number; }): number; /** * Get cache statistics */ getStats(): CacheStats; /** * Export cache to file */ exportCache(filePath: string): Promise<void>; /** * Import cache from file */ importCache(filePath: string, merge?: boolean): Promise<void>; /** * Private: Generate cache key */ private generateKey; /** * Private: Check if entry has expired */ private isExpired; /** * Private: Initialize cache from disk */ private initializeCache; /** * Private: Persist entry to disk */ private persistEntry; /** * Private: Evict least recently used entries */ private evictLeastUsed; /** * Private: Calculate basic text similarity */ private calculateSimilarity; /** * Private: Start cleanup interval for expired entries */ private startCleanupInterval; /** * Destroy cache and cleanup */ destroy(): void; } export declare const aiCache: AIResponseCache; //# sourceMappingURL=response-cache.d.ts.map