/**
 * Timeout Wrapper - Protects tool execution from hanging
 *
 * Wraps tool execution with timeout protection to prevent:
 * - Infinite loops in shell commands
 * - Network requests hanging forever
 * - Resource exhaustion
 */
export interface TimeoutConfig {
    defaultTimeoutMs: number;
    shellTimeoutMs: number;
    readTimeoutMs: number;
    writeTimeoutMs: number;
    networkTimeoutMs: number;
    gracefulShutdownMs: number;
}
declare const DEFAULT_CONFIG: TimeoutConfig;
export interface TimeoutResult<T> {
    success: boolean;
    result?: T;
    error?: Error;
    timedOut: boolean;
    executionTimeMs: number;
}
export interface ToolTimeoutConfig {
    toolName: string;
    timeoutMs?: number;
    description?: string;
}
/**
 * Execute function with timeout protection
 *
 * @example
 * ```typescript
 * const result = await executeWithTimeout(
 *   () => shell.exec('long-running-command'),
 *   { toolName: 'shell', timeoutMs: 60000 }
 * );
 * ```
 */
export declare function executeWithTimeout<T>(operation: () => Promise<T>, config: ToolTimeoutConfig): Promise<T>;
/**
 * Execute with timeout and return detailed result
 */
export declare function executeWithTimeoutResult<T>(operation: () => Promise<T>, config: ToolTimeoutConfig): Promise<TimeoutResult<T>>;
/**
 * Custom timeout error
 */
export declare class TimeoutError extends Error {
    readonly toolName: string;
    readonly timeoutMs: number;
    readonly executionTimeMs: number;
    readonly description?: string;
    constructor(toolName: string, timeoutMs: number, description?: string, executionTimeMs?: number);
    /**
     * Get user-friendly error message with suggestions
     */
    getUserMessage(): string;
}
/**
 * Wrap a function with timeout protection
 */
export declare function withTimeout<T extends (...args: any[]) => Promise<any>>(fn: T, config: Omit<ToolTimeoutConfig, 'description'> & {
    description?: string | ((...args: Parameters<T>) => string);
}): (...args: Parameters<T>) => Promise<ReturnType<T>>;
/**
 * Timeout manager for tracking execution statistics
 */
export declare class TimeoutManager {
    private config;
    private executions;
    constructor(config?: Partial<TimeoutConfig>);
    /**
     * Execute with timeout and track statistics
     */
    execute<T>(operation: () => Promise<T>, toolConfig: ToolTimeoutConfig): Promise<T>;
    /**
     * Get execution statistics
     */
    getStats(): {
        totalExecutions: number;
        timeoutCount: number;
        timeoutRate: number;
        averageExecutionTimeMs: number;
        byTool: Record<string, {
            count: number;
            timeouts: number;
            avgExecutionTimeMs: number;
        }>;
    };
    /**
     * Clean up old execution records
     */
    cleanup(maxAgeMs?: number): void;
}
export { DEFAULT_CONFIG as DEFAULT_TIMEOUT_CONFIG };
