/**
 * AI Flow Protection System
 *
 * Comprehensive protection against attacks targeting the AI conversation flow:
 *
 * 1. Prompt Injection Defense - Detect and neutralize injection attempts
 * 2. Flow Continuity Protection - Prevent conversation interruption attacks
 * 3. UI Stability Armor - Protect rendering from error-inducing payloads
 * 4. Context Poisoning Prevention - Detect attempts to corrupt AI context
 * 5. Response Hijacking Defense - Prevent response manipulation
 * 6. State Corruption Protection - Guard conversation state integrity
 * 7. Rate Limiting - Prevent DoS through rapid message flooding
 * 8. Escape Sequence Sanitization - Neutralize terminal escape attacks
 *
 * @module flowProtection
 */
import { EventEmitter } from 'events';
/** Injection detection result */
export interface InjectionAnalysis {
    detected: boolean;
    confidence: number;
    type: InjectionType | null;
    sanitized: string;
    originalLength: number;
    sanitizedLength: number;
    blockedPatterns: string[];
}
/** Types of injection attacks */
export type InjectionType = 'prompt_override' | 'role_injection' | 'context_manipulation' | 'escape_sequence' | 'unicode_attack' | 'delimiter_injection' | 'instruction_leak' | 'jailbreak' | 'flow_termination' | 'ui_corruption';
/** Configuration options */
export interface FlowProtectionConfig {
    /** Enable prompt injection detection (default: true) */
    detectInjection?: boolean;
    /** Injection confidence threshold to block (default: 70) */
    injectionThreshold?: number;
    /** Enable flow continuity protection (default: true) */
    protectFlow?: boolean;
    /** Enable UI stability protection (default: true) */
    protectUI?: boolean;
    /** Rate limit messages per second (default: 10) */
    rateLimitPerSecond?: number;
    /** Maximum message length (default: 100000) */
    maxMessageLength?: number;
    /** Enable verbose logging (default: false) */
    verbose?: boolean;
    /** Callback on injection detection */
    onInjectionDetected?: (analysis: InjectionAnalysis) => void;
    /** Callback on flow error */
    onFlowError?: (error: Error, recovered: boolean) => void;
}
/**
 * Flow Protection System
 */
export declare class FlowProtection extends EventEmitter {
    private config;
    private flowState;
    private messageTimestamps;
    private blockedInjections;
    private recoveredFlows;
    private uiErrorsBlocked;
    private readonly injectionPatterns;
    private readonly unicodePatterns;
    constructor(config?: FlowProtectionConfig);
    /**
     * Analyze and sanitize a prompt for injection attempts
     */
    analyzePrompt(prompt: string): InjectionAnalysis;
    /**
     * Normalize unicode to prevent attacks
     */
    private normalizeUnicode;
    /**
     * Check rate limiting
     */
    checkRateLimit(): boolean;
    /**
     * Process a message through all protections
     */
    processMessage(message: string): {
        allowed: boolean;
        sanitized: string;
        reason?: string;
    };
    /**
     * Protect UI rendering from malicious content
     */
    sanitizeForUI(content: string): string;
    /**
     * Remove unsafe escape sequences while preserving safe formatting
     */
    private removeUnsafeEscapeSequences;
    /**
     * Wrap an async operation with flow protection
     */
    protectFlow<T>(operation: () => Promise<T>, context?: string): Promise<T>;
    /**
     * Check if an error appears to be attack-induced
     */
    private isAttackInducedError;
    /**
     * Helper delay function
     */
    private delay;
    /**
     * Save flow state checkpoint
     */
    saveCheckpoint(state: string): void;
    /**
     * Restore from last checkpoint
     */
    restoreCheckpoint(): string | null;
    /**
     * Verify context integrity
     */
    verifyContextIntegrity(context: string): boolean;
    /**
     * Simple string hash for integrity checks
     */
    private hashString;
    /**
     * Get protection statistics
     */
    getStats(): {
        blockedInjections: number;
        recoveredFlows: number;
        uiErrorsBlocked: number;
        messageCount: number;
        errorCount: number;
    };
    /**
     * Internal logging
     */
    private log;
}
/**
 * Initialize global flow protection (singleton)
 */
export declare function initializeFlowProtection(config?: FlowProtectionConfig): FlowProtection;
/**
 * Get flow protection instance
 */
export declare function getFlowProtection(): FlowProtection | null;
/**
 * Quick sanitize function for prompts
 */
export declare function sanitizePrompt(prompt: string): {
    sanitized: string;
    blocked: boolean;
};
/**
 * Quick sanitize function for UI output
 */
export declare function sanitizeForDisplay(content: string): string;
//# sourceMappingURL=flowProtection.d.ts.map