( toolName: ToolName, mode: Mode, customModes?: ModeConfig[], toolRequirements?: Record<string, boolean>, toolParams?: Record<string, unknown>, experiments?: Record<string, boolean>, includedTools?: string[], )
| 30 | } |
| 31 | |
| 32 | export function validateToolUse( |
| 33 | toolName: ToolName, |
| 34 | mode: Mode, |
| 35 | customModes?: ModeConfig[], |
| 36 | toolRequirements?: Record<string, boolean>, |
| 37 | toolParams?: Record<string, unknown>, |
| 38 | experiments?: Record<string, boolean>, |
| 39 | includedTools?: string[], |
| 40 | ): void { |
| 41 | // First, check if the tool name is actually a valid/known tool |
| 42 | // This catches completely invalid tool names like "edit_file" that don't exist |
| 43 | if (!isValidToolName(toolName, experiments)) { |
| 44 | throw new Error( |
| 45 | `Unknown tool "${toolName}". This tool does not exist. Please use one of the available tools: ${validToolNames.join(", ")}.`, |
| 46 | ) |
| 47 | } |
| 48 | |
| 49 | // Then check if the tool is allowed for the current mode |
| 50 | if ( |
| 51 | !isToolAllowedForMode( |
| 52 | toolName, |
| 53 | mode, |
| 54 | customModes ?? [], |
| 55 | toolRequirements, |
| 56 | toolParams, |
| 57 | experiments, |
| 58 | includedTools, |
| 59 | ) |
| 60 | ) { |
| 61 | throw new Error(`Tool "${toolName}" is not allowed in ${mode} mode.`) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | const EDIT_OPERATION_PARAMS = [ |
| 66 | "diff", |
no test coverage detected