/**
 * Offline Mode System
 *
 * Features:
 * - Response caching for offline use
 * - Local LLM fallback (Ollama, llama.cpp)
 * - Embedding cache for semantic search
 * - Queue requests when offline
 * - Automatic sync when back online
 * - Offline-capable tools
 *
 * Allows Code Buddy to function without internet connectivity.
 */
import { EventEmitter } from 'events';
import { LocalProviderManager } from '../providers/local-llm-provider.js';
export interface OfflineConfig {
    enabled: boolean;
    cacheEnabled: boolean;
    cacheMaxSize: number;
    cacheMaxAge: number;
    localLLMEnabled: boolean;
    localLLMProvider: 'ollama' | 'llamacpp' | 'local-llama' | 'webllm' | 'none';
    localLLMModel: string;
    localLLMEndpoint?: string;
    localLLMModelPath?: string;
    localLLMGpuLayers?: number;
    embeddingCacheEnabled: boolean;
    queueRequestsWhenOffline: boolean;
    autoSyncOnReconnect: boolean;
    checkInternetInterval: number;
}
export interface CachedResponse {
    id: string;
    query: string;
    queryHash: string;
    response: string;
    model: string;
    tokensUsed: number;
    createdAt: Date;
    accessedAt: Date;
    accessCount: number;
    similarity?: number;
}
export interface CachedEmbedding {
    id: string;
    text: string;
    textHash: string;
    embedding: number[];
    model: string;
    createdAt: Date;
}
export interface QueuedRequest {
    id: string;
    type: 'chat' | 'embedding' | 'tool';
    payload: unknown;
    createdAt: Date;
    retries: number;
    priority: number;
}
export interface OfflineStats {
    cacheHits: number;
    cacheMisses: number;
    localLLMCalls: number;
    queuedRequests: number;
    cacheSize: number;
    isOnline: boolean;
    lastOnline?: Date;
}
export declare class OfflineMode extends EventEmitter {
    private config;
    private dataDir;
    private cacheDir;
    private responseCache;
    private embeddingCache;
    private requestQueue;
    private isOnline;
    private lastOnline;
    private stats;
    private checkInternetTimer;
    private localLLMProcess;
    private localProviderManager;
    constructor(config?: Partial<OfflineConfig>);
    /**
     * Initialize offline mode
     */
    private initialize;
    /**
     * Load caches from disk
     */
    private loadCaches;
    /**
     * Load request queue
     */
    private loadQueue;
    /**
     * Save request queue
     */
    private saveQueue;
    /**
     * Save cache indexes
     */
    private saveCacheIndexes;
    /**
     * Calculate cache size
     */
    private calculateCacheSize;
    /**
     * Check internet connectivity
     */
    checkInternet(): Promise<boolean>;
    /**
     * Start internet connectivity checker
     */
    private startInternetCheck;
    /**
     * Hash a string for cache lookup
     */
    private hash;
    /**
     * Cache a response
     */
    cacheResponse(query: string, response: string, model: string, tokensUsed: number): Promise<void>;
    /**
     * Get cached response
     */
    getCachedResponse(query: string): Promise<CachedResponse | null>;
    /**
     * Find similar cached responses using embedding similarity
     */
    findSimilarResponses(query: string, threshold?: number): Promise<CachedResponse[]>;
    /**
     * Cosine similarity between two vectors
     */
    private cosineSimilarity;
    /**
     * Cache an embedding
     */
    cacheEmbedding(text: string, embedding: number[], model: string): Promise<void>;
    /**
     * Get cached embedding
     */
    getEmbedding(text: string): Promise<number[] | null>;
    /**
     * Remove cached response
     */
    private removeCachedResponse;
    /**
     * Cleanup cache if needed
     */
    private cleanupCacheIfNeeded;
    /**
     * Queue a request for later processing
     */
    queueRequest(type: QueuedRequest['type'], payload: unknown, priority?: number): string;
    /**
     * Process queued requests
     */
    processQueue(): Promise<void>;
    /**
     * Process a single request
     */
    private processRequest;
    /**
     * Call local LLM using the new provider system
     */
    callLocalLLM(prompt: string, options?: {
        model?: string;
        maxTokens?: number;
        temperature?: number;
    }): Promise<string | null>;
    /**
     * Call new provider system (node-llama-cpp, WebLLM)
     */
    private callNewProvider;
    /**
     * Stream local LLM response (new provider system)
     */
    streamLocalLLM(prompt: string, options?: {
        model?: string;
        maxTokens?: number;
        temperature?: number;
    }): AsyncIterable<string>;
    /**
     * Call Ollama API
     */
    private callOllama;
    /**
     * Call llama.cpp server
     */
    private callLlamaCpp;
    /**
     * Check if local LLM is available
     */
    isLocalLLMAvailable(): Promise<boolean>;
    /**
     * Get provider manager instance
     */
    getLocalProviderManager(): LocalProviderManager | null;
    /**
     * Get available provider types
     */
    getAvailableProviders(): Promise<string[]>;
    /**
     * Get available local models
     */
    getLocalModels(): Promise<string[]>;
    /**
     * Get stats
     */
    getStats(): OfflineStats;
    /**
     * Get config
     */
    getConfig(): OfflineConfig;
    /**
     * Update config
     */
    updateConfig(config: Partial<OfflineConfig>): void;
    /**
     * Save config
     */
    private saveConfig;
    /**
     * Clear cache
     */
    clearCache(): Promise<void>;
    /**
     * Clear queue
     */
    clearQueue(): Promise<void>;
    /**
     * Format status
     */
    formatStatus(): string;
    /**
     * Dispose
     */
    dispose(): void;
}
export declare function getOfflineMode(config?: Partial<OfflineConfig>): OfflineMode;
export declare function resetOfflineMode(): void;
