/**
 * LLM Response Cache
 *
 * Implements intelligent caching for LLM API responses using semantic similarity.
 * Key features:
 * - Semantic matching using n-gram embeddings
 * - Prompt prefix matching for context-aware caching
 * - Cost tracking and savings estimation
 * - Automatic invalidation for stale entries
 *
 * Research shows 60-70% API call reduction with semantic caching.
 */
import { EventEmitter } from 'events';
import type { CodeBuddyMessage } from '../codebuddy/client.js';
export interface LLMCacheEntry {
    key: string;
    queryHash: string;
    queryPrefix: string;
    embedding: number[];
    response: {
        content: string | null;
        toolCalls?: unknown[];
        usage?: {
            promptTokens: number;
            completionTokens: number;
        };
    };
    model: string;
    timestamp: number;
    expiresAt: number;
    hits: number;
    tokensSaved: number;
    metadata?: {
        systemPromptHash?: string;
        toolsHash?: string;
        messageCount?: number;
    };
}
export interface LLMCacheConfig {
    enabled: boolean;
    ttlMs: number;
    maxEntries: number;
    similarityThreshold: number;
    minTokensToCache: number;
    costPerMillion: number;
    persistToDisk: boolean;
    cachePath: string;
    prefixLength: number;
    embeddingDim: number;
    ngramSize: number;
}
export interface LLMCacheStats {
    totalEntries: number;
    hits: number;
    misses: number;
    hitRate: number;
    semanticHits: number;
    exactHits: number;
    tokensSaved: number;
    estimatedCostSaved: number;
    evictions: number;
    avgSimilarity: number;
    cacheSize: number;
}
export declare class LLMResponseCache extends EventEmitter {
    private cache;
    private config;
    private stats;
    private similarityScores;
    private saveTimeout;
    private readonly saveDebounceMs;
    constructor(config?: Partial<LLMCacheConfig>);
    /**
     * Try to get a cached response for the given messages
     */
    get(messages: CodeBuddyMessage[], model: string, options?: {
        systemPromptHash?: string;
        toolsHash?: string;
    }): Promise<LLMCacheEntry | null>;
    /**
     * Store a response in the cache
     */
    set(messages: CodeBuddyMessage[], response: LLMCacheEntry['response'], model: string, options?: {
        systemPromptHash?: string;
        toolsHash?: string;
    }): void;
    /**
     * Extract query from messages (typically last user message)
     */
    private extractQuery;
    /**
     * Create exact match key
     */
    private createExactKey;
    /**
     * Find semantic match in cache
     */
    private findSemanticMatch;
    /**
     * Compute n-gram based embedding
     */
    private computeEmbedding;
    /**
     * Compute cosine similarity
     */
    private cosineSimilarity;
    /**
     * Quick prefix similarity (Jaccard of words)
     */
    private prefixSimilarity;
    /**
     * Simple hash function
     */
    private simpleHash;
    /**
     * Hash string using SHA256
     */
    private hashString;
    /**
     * Check if entry is expired
     */
    private isExpired;
    /**
     * Evict entries if at capacity
     */
    private evictIfNeeded;
    /**
     * Update statistics
     */
    private updateStats;
    /**
     * Get cache statistics
     */
    getStats(): LLMCacheStats;
    /**
     * Format statistics for display
     */
    formatStats(): string;
    /**
     * Clear cache
     */
    clear(): void;
    /**
     * Invalidate entries matching pattern
     */
    invalidate(pattern: RegExp): number;
    /**
     * Schedule debounced save
     */
    private scheduleSave;
    /**
     * Save to disk
     */
    private saveToDisk;
    /**
     * Load from disk
     */
    private loadFromDisk;
    /**
     * Dispose resources
     */
    dispose(): void;
}
export declare function getLLMResponseCache(config?: Partial<LLMCacheConfig>): LLMResponseCache;
export declare function resetLLMResponseCache(): void;
