/**
 * Session Lanes Module
 *
 * Provides queue-based message processing to prevent message interleaving
 * when multiple requests are in-flight for the same session.
 */
import { EventEmitter } from 'events';
/**
 * Lane item with message and metadata
 */
export interface LaneItem<T> {
    /** Unique message ID */
    id: string;
    /** The message/request payload */
    payload: T;
    /** Timestamp when enqueued */
    enqueuedAt: number;
    /** Timestamp when processing started */
    startedAt?: number;
    /** Timestamp when processing completed */
    completedAt?: number;
    /** Priority (lower = higher priority) */
    priority: number;
    /** Metadata */
    metadata?: Record<string, unknown>;
}
/**
 * Lane status
 */
export type LaneStatus = 'idle' | 'processing' | 'paused' | 'draining';
/**
 * Lane events
 */
export interface LaneEvents<T> {
    'enqueue': (item: LaneItem<T>) => void;
    'start': (item: LaneItem<T>) => void;
    'complete': (item: LaneItem<T>, result: unknown) => void;
    'error': (item: LaneItem<T>, error: Error) => void;
    'drain': () => void;
    'pause': () => void;
    'resume': () => void;
}
/**
 * Lane configuration
 */
export interface LaneConfig {
    /** Maximum queue size (0 = unlimited) */
    maxQueueSize: number;
    /** Processing timeout in ms (0 = unlimited) */
    processingTimeoutMs: number;
    /** Whether to process in FIFO order */
    fifo: boolean;
    /** Whether to auto-start processing on enqueue */
    autoStart: boolean;
}
/**
 * Default lane configuration
 */
export declare const DEFAULT_LANE_CONFIG: LaneConfig;
/**
 * A lane for processing messages in order
 */
export declare class SessionLane<T> extends EventEmitter {
    private config;
    private queue;
    private status;
    private currentItem;
    private processor;
    private processingPromise;
    private idCounter;
    constructor(config?: Partial<LaneConfig>);
    /**
     * Set the message processor
     */
    setProcessor(processor: (item: LaneItem<T>) => Promise<unknown>): void;
    /**
     * Enqueue a message for processing
     */
    enqueue(payload: T, options?: {
        priority?: number;
        metadata?: Record<string, unknown>;
    }): LaneItem<T>;
    /**
     * Start processing the queue
     */
    startProcessing(): void;
    /**
     * Process the queue
     */
    private processQueue;
    /**
     * Pause processing
     */
    pause(): void;
    /**
     * Resume processing
     */
    resume(): void;
    /**
     * Drain the queue (finish current and process remaining)
     */
    drain(): Promise<void>;
    /**
     * Clear the queue (cancel pending items)
     */
    clear(): LaneItem<T>[];
    /**
     * Get current lane status
     */
    getStatus(): LaneStatus;
    /**
     * Get queue length
     */
    getQueueLength(): number;
    /**
     * Get current processing item
     */
    getCurrentItem(): LaneItem<T> | null;
    /**
     * Get all pending items
     */
    getPendingItems(): LaneItem<T>[];
    /**
     * Get lane statistics
     */
    getStats(): {
        status: LaneStatus;
        queueLength: number;
        isProcessing: boolean;
        currentItemId: string | null;
    };
}
/**
 * Manages multiple session lanes
 */
export declare class LaneManager<T> {
    private lanes;
    private config;
    private defaultProcessor;
    constructor(config?: Partial<LaneConfig>);
    /**
     * Set default processor for new lanes
     */
    setDefaultProcessor(processor: (item: LaneItem<T>) => Promise<unknown>): void;
    /**
     * Get or create a lane for a session
     */
    getLane(sessionId: string): SessionLane<T>;
    /**
     * Check if a lane exists
     */
    hasLane(sessionId: string): boolean;
    /**
     * Remove a lane
     */
    removeLane(sessionId: string): boolean;
    /**
     * Enqueue a message to a session's lane
     */
    enqueue(sessionId: string, payload: T, options?: {
        priority?: number;
        metadata?: Record<string, unknown>;
    }): LaneItem<T>;
    /**
     * Get all active session IDs
     */
    getActiveSessions(): string[];
    /**
     * Get total pending items across all lanes
     */
    getTotalPending(): number;
    /**
     * Pause all lanes
     */
    pauseAll(): void;
    /**
     * Resume all lanes
     */
    resumeAll(): void;
    /**
     * Drain all lanes
     */
    drainAll(): Promise<void>;
    /**
     * Clear all lanes
     */
    clearAll(): void;
    /**
     * Get statistics for all lanes
     */
    getStats(): {
        totalLanes: number;
        totalPending: number;
        processingCount: number;
        lanes: Record<string, ReturnType<SessionLane<T>['getStats']>>;
    };
}
/**
 * Get the singleton lane manager
 */
export declare function getLaneManager<T = unknown>(config?: Partial<LaneConfig>): LaneManager<T>;
/**
 * Reset the singleton lane manager
 */
export declare function resetLaneManager(): void;
/**
 * Execute a function with lane ordering for a session
 */
export declare function withLane<T, R>(sessionId: string, payload: T, processor: (payload: T) => Promise<R>, config?: Partial<LaneConfig>): Promise<R>;
/**
 * Create a lane-ordered async function
 */
export declare function createLanedFunction<T, R>(getSessionId: (payload: T) => string, processor: (payload: T) => Promise<R>, config?: Partial<LaneConfig>): (payload: T) => Promise<R>;
