( toolId: string, tool: ToolConfig | undefined, params: Record<string, any>, parameterNameMap?: Record<string, string> )
| 159 | * user-or-llm parameters are present after the merge process |
| 160 | */ |
| 161 | export function validateRequiredParametersAfterMerge( |
| 162 | toolId: string, |
| 163 | tool: ToolConfig | undefined, |
| 164 | params: Record<string, any>, |
| 165 | parameterNameMap?: Record<string, string> |
| 166 | ): void { |
| 167 | if (!tool) { |
| 168 | throw new Error(`Tool not found: ${toolId}`) |
| 169 | } |
| 170 | |
| 171 | // Validate all required user-or-llm parameters after merge |
| 172 | // user-only parameters should have been validated earlier during serialization |
| 173 | for (const [paramName, paramConfig] of Object.entries(tool.params)) { |
| 174 | if ( |
| 175 | (paramConfig as any).visibility === 'user-or-llm' && |
| 176 | paramConfig.required && |
| 177 | (!(paramName in params) || |
| 178 | params[paramName] === null || |
| 179 | params[paramName] === undefined || |
| 180 | params[paramName] === '') |
| 181 | ) { |
| 182 | // Create a more user-friendly error message |
| 183 | const toolName = tool.name || toolId |
| 184 | const friendlyParamName = |
| 185 | parameterNameMap?.[paramName] || formatParameterNameForError(paramName) |
| 186 | throw new Error(`${friendlyParamName} is required for ${toolName}`) |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Creates parameter schema from custom tool schema |
no test coverage detected