/** * 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 { success: boolean; result?: T; error?: Error; timedOut: boolean; executionTimeMs: number; } export interface ToolTimeoutConfig { toolName: string; timeoutMs?: number; description?: string; signal?: AbortSignal; onTimeout?: (error: TimeoutError) => void; } /** * Execute function with timeout protection * * @example * ```typescript * const result = await executeWithTimeout( * () => execCommand('long-running-command'), * { toolName: 'exec_command', timeoutMs: 60000 } * ); * ``` */ export declare function executeWithTimeout(operation: () => Promise, config: ToolTimeoutConfig): Promise; /** * Execute with timeout and return detailed result */ export declare function executeWithTimeoutResult(operation: () => Promise, config: ToolTimeoutConfig): Promise>; /** * 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 Promise>(fn: T, config: Omit & { description?: string | ((...args: Parameters) => string); }): (...args: Parameters) => Promise>; /** * Timeout manager for tracking execution statistics */ export declare class TimeoutManager { private executions; constructor(_config?: Partial); /** * Execute with timeout and track statistics */ execute(operation: () => Promise, toolConfig: ToolTimeoutConfig): Promise; /** * Get execution statistics */ getStats(): { totalExecutions: number; timeoutCount: number; timeoutRate: number; averageExecutionTimeMs: number; byTool: Record; }; /** * Clean up old execution records */ cleanup(maxAgeMs?: number): void; } export { DEFAULT_CONFIG as DEFAULT_TIMEOUT_CONFIG };