/**
 * Latency Optimizer
 *
 * Research-based implementation for maintaining developer flow state.
 * Targets sub-500ms response times for common operations.
 *
 * Expected Impact:
 * - Preserved developer flow state
 * - Better user experience
 * - Reduced perceived latency
 *
 * Reference: Replit research, Human-AI Interaction studies (2024)
 */
import { EventEmitter } from "events";
/**
 * Latency thresholds (in milliseconds)
 */
export declare const LATENCY_THRESHOLDS: {
    /** Instant - no perceived delay */
    readonly INSTANT: 100;
    /** Fast - maintains flow state */
    readonly FAST: 300;
    /** Acceptable - still responsive */
    readonly ACCEPTABLE: 500;
    /** Slow - noticeable delay */
    readonly SLOW: 1000;
    /** Very slow - interrupts flow */
    readonly VERY_SLOW: 3000;
};
/**
 * Operation types with target latencies
 */
export declare const OPERATION_TARGETS: Record<string, number>;
/**
 * Latency measurement
 */
export interface LatencyMeasurement {
    operation: string;
    startTime: number;
    endTime?: number;
    duration?: number;
    target: number;
    status: "pending" | "met" | "exceeded";
}
/**
 * Latency optimizer class
 */
export declare class LatencyOptimizer extends EventEmitter {
    private measurements;
    private precomputeCache;
    private pendingPrecomputes;
    private warmupTasks;
    private isWarmingUp;
    private cleanupIntervalId;
    constructor();
    /**
     * Start measuring an operation
     */
    startOperation(operation: string): string;
    /**
     * End measuring an operation
     */
    endOperation(id: string): LatencyMeasurement | null;
    /**
     * Measure an async operation
     */
    measure<T>(operation: string, fn: () => Promise<T>): Promise<T>;
    /**
     * Pre-compute and cache a value for faster retrieval
     */
    precompute<T>(key: string, compute: () => Promise<T>, ttlMs?: number): Promise<T>;
    /**
     * Invalidate a cached value
     */
    invalidate(key: string): void;
    /**
     * Invalidate all cached values matching a pattern
     */
    invalidatePattern(pattern: RegExp): number;
    /**
     * Register a warmup task
     */
    registerWarmup(task: () => Promise<void>): void;
    /**
     * Execute all warmup tasks
     */
    warmup(): Promise<void>;
    /**
     * Get latency statistics
     */
    getStats(): {
        totalOperations: number;
        metTarget: number;
        exceededTarget: number;
        avgDuration: number;
        p50: number;
        p95: number;
        p99: number;
        byOperation: Record<string, {
            count: number;
            avg: number;
            met: number;
        }>;
    };
    /**
     * Get cache statistics
     */
    getCacheStats(): {
        size: number;
        totalAccesses: number;
        avgAccessCount: number;
    };
    /**
     * Clean old measurements and expired cache entries
     */
    cleanup(): void;
    /**
     * Start periodic cleanup
     */
    private startPeriodicCleanup;
    /**
     * Reset all measurements
     */
    reset(): void;
    /**
     * Dispose and clean up resources
     */
    dispose(): void;
}
/**
 * Streaming response optimizer
 * Ensures first token arrives quickly for better perceived latency
 */
export declare class StreamingOptimizer {
    private firstTokenTimes;
    private totalTokenTimes;
    /**
     * Record first token latency
     */
    recordFirstToken(latencyMs: number): void;
    /**
     * Record total streaming time
     */
    recordTotalTime(latencyMs: number): void;
    /**
     * Get streaming statistics
     */
    getStats(): {
        avgFirstToken: number;
        avgTotalTime: number;
        firstTokenP50: number;
        firstTokenP95: number;
        meetingTarget: number;
    };
    /**
     * Reset statistics
     */
    reset(): void;
}
/**
 * Get global latency optimizer
 */
export declare function getLatencyOptimizer(): LatencyOptimizer;
/**
 * Get global streaming optimizer
 */
export declare function getStreamingOptimizer(): StreamingOptimizer;
/**
 * Reset all singleton instances (for testing)
 */
export declare function resetOptimizers(): void;
/**
 * Convenience function for measuring operations
 */
export declare function measureLatency<T>(operation: string, fn: () => Promise<T>): Promise<T>;
/**
 * Convenience function for pre-computing values
 */
export declare function precompute<T>(key: string, compute: () => Promise<T>, ttlMs?: number): Promise<T>;
declare const _default: {
    LatencyOptimizer: typeof LatencyOptimizer;
    StreamingOptimizer: typeof StreamingOptimizer;
    getLatencyOptimizer: typeof getLatencyOptimizer;
    getStreamingOptimizer: typeof getStreamingOptimizer;
    resetOptimizers: typeof resetOptimizers;
    measureLatency: typeof measureLatency;
    precompute: typeof precompute;
    LATENCY_THRESHOLDS: {
        /** Instant - no perceived delay */
        readonly INSTANT: 100;
        /** Fast - maintains flow state */
        readonly FAST: 300;
        /** Acceptable - still responsive */
        readonly ACCEPTABLE: 500;
        /** Slow - noticeable delay */
        readonly SLOW: 1000;
        /** Very slow - interrupts flow */
        readonly VERY_SLOW: 3000;
    };
    OPERATION_TARGETS: Record<string, number>;
};
export default _default;
