/**
 * Tool Executor Module
 *
 * Handles execution of all tools (built-in, MCP, and external).
 * Extracted from CodeBuddyAgent for better modularity and testability.
 *
 * Features:
 * - Parallel execution for independent read-only operations
 * - Configurable concurrency limits with semaphore
 * - Automatic read-only tool identification based on categories
 * - Dependency-aware sequential execution for write operations
 * - Partial error handling with graceful degradation
 * - Detailed parallelization metrics
 */
import { TextEditorTool, BashTool, SearchTool, TodoTool, ImageTool, WebSearchTool, MorphEditorTool } from "../tools/index.js";
import { ToolResult } from "../types/index.js";
import { CheckpointManager } from "../checkpoints/checkpoint-manager.js";
import { ToolCategory } from "../tools/types.js";
/**
 * Tool call structure from OpenAI/CodeBuddy API
 */
export interface CodeBuddyToolCall {
    id: string;
    type: "function";
    function: {
        name: string;
        arguments: string;
    };
}
/**
 * Dependencies required by ToolExecutor
 */
export interface ToolExecutorDependencies {
    textEditor: TextEditorTool;
    bash: BashTool;
    search: SearchTool;
    todoTool: TodoTool;
    imageTool: ImageTool;
    webSearch: WebSearchTool;
    checkpointManager: CheckpointManager;
    morphEditor?: MorphEditorTool | null;
}
/**
 * Configuration for parallel execution
 */
export interface ParallelExecutionConfig {
    /** Enable parallel execution (default: true) */
    enabled: boolean;
    /** Maximum concurrent executions (default: 5) */
    maxConcurrency: number;
    /** Timeout per tool in ms (default: 30000) */
    toolTimeout: number;
    /** Categories considered read-only and safe for parallel execution */
    readOnlyCategories: ToolCategory[];
    /** Additional tool names to treat as read-only */
    additionalReadOnlyTools: string[];
    /** Tool names to always execute sequentially */
    forceSequentialTools: string[];
}
/**
 * Default configuration for parallel execution
 */
export declare const DEFAULT_PARALLEL_CONFIG: ParallelExecutionConfig;
/**
 * Result of a parallel execution batch
 */
export interface ParallelExecutionResult {
    results: Map<string, ToolResult>;
    metrics: ParallelExecutionMetrics;
}
/**
 * Metrics specific to parallel execution
 */
export interface ParallelExecutionMetrics {
    /** Total tools in the batch */
    totalTools: number;
    /** Number executed in parallel */
    parallelCount: number;
    /** Number executed sequentially */
    sequentialCount: number;
    /** Total wall-clock time for the batch */
    wallClockTime: number;
    /** Sum of individual tool execution times */
    totalToolTime: number;
    /** Time saved by parallelization */
    timeSaved: number;
    /** Parallelization efficiency (0-1) */
    efficiency: number;
    /** Number of partial failures */
    partialFailures: number;
}
/**
 * Metrics for tool execution
 */
export interface ToolMetrics {
    toolRequestCounts: Map<string, number>;
    totalExecutions: number;
    successfulExecutions: number;
    failedExecutions: number;
    totalExecutionTime: number;
    parallelBatches: number;
    totalParallelTools: number;
    totalSequentialTools: number;
    totalTimeSaved: number;
    averageEfficiency: number;
}
/**
 * ToolExecutor handles the execution of all tools in the agent.
 * It provides a centralized place for tool dispatch and MCP integration.
 */
export declare class ToolExecutor {
    private textEditor;
    private bash;
    private search;
    private todoTool;
    private imageTool;
    private webSearch;
    private checkpointManager;
    private morphEditor?;
    private parallelConfig;
    private semaphore;
    private toolRequestCounts;
    private totalExecutions;
    private successfulExecutions;
    private failedExecutions;
    private totalExecutionTime;
    private parallelBatches;
    private totalParallelTools;
    private totalSequentialTools;
    private totalTimeSaved;
    private efficiencySum;
    constructor(deps: ToolExecutorDependencies, config?: Partial<ParallelExecutionConfig>);
    /**
     * Update parallel execution configuration
     */
    setParallelConfig(config: Partial<ParallelExecutionConfig>): void;
    /**
     * Get current parallel execution configuration
     */
    getParallelConfig(): ParallelExecutionConfig;
    /**
     * Record a tool request for metrics tracking
     */
    recordToolRequest(toolName: string): void;
    /**
     * Execute a tool call and return the result
     */
    execute(toolCall: CodeBuddyToolCall): Promise<ToolResult>;
    /**
     * Dispatch tool execution to the appropriate handler
     */
    private dispatchTool;
    /**
     * Execute an MCP tool
     */
    private executeMCPTool;
    /**
     * Determine the category of a tool
     */
    private getToolCategory;
    /**
     * Check if a tool can be executed in parallel (read-only)
     * Uses category-based detection with configuration overrides
     */
    canExecuteInParallel(toolName: string): boolean;
    /**
     * Execute a single tool with timeout protection
     */
    private executeWithTimeout;
    /**
     * Execute multiple tools with intelligent parallelization
     *
     * Features:
     * - Automatic read-only detection based on tool categories
     * - Semaphore-limited concurrency
     * - Partial error handling (continues on individual failures)
     * - Detailed execution metrics
     */
    executeParallel(toolCalls: CodeBuddyToolCall[]): Promise<Map<string, ToolResult>>;
    /**
     * Execute multiple tools with detailed parallelization metrics
     */
    executeParallelWithMetrics(toolCalls: CodeBuddyToolCall[]): Promise<ParallelExecutionResult>;
    /**
     * Get execution metrics
     */
    getMetrics(): ToolMetrics;
    /**
     * Get tool request counts as a formatted object
     */
    getToolRequestCountsFormatted(): Record<string, number>;
    /**
     * Reset metrics
     */
    resetMetrics(): void;
    /**
     * Check if a tool is read-only (safe for parallel execution)
     * @deprecated Use canExecuteInParallel() for more accurate detection
     */
    isReadOnlyTool(toolName: string): boolean;
    /**
     * Get parallelization statistics summary
     */
    getParallelizationStats(): {
        enabled: boolean;
        maxConcurrency: number;
        totalBatches: number;
        parallelToolsExecuted: number;
        sequentialToolsExecuted: number;
        totalTimeSavedMs: number;
        averageEfficiency: number;
    };
    /**
     * Get the bash tool instance
     */
    getBashTool(): BashTool;
    /**
     * Get the image tool instance
     */
    getImageTool(): ImageTool;
    /**
     * Get the checkpoint manager
     */
    getCheckpointManager(): CheckpointManager;
}
