( customTool: CustomToolDefinition, customToolId: string )
| 295 | |
| 296 | // Helper function to create a tool config from a custom tool |
| 297 | export function createToolConfig( |
| 298 | customTool: CustomToolDefinition, |
| 299 | customToolId: string |
| 300 | ): ToolConfig { |
| 301 | // Create a parameter schema from the custom tool schema |
| 302 | const params = createParamSchema(customTool) |
| 303 | |
| 304 | // Create a tool config for the custom tool |
| 305 | return { |
| 306 | id: customToolId, |
| 307 | name: customTool.title, |
| 308 | description: customTool.schema.function?.description || '', |
| 309 | version: '1.0.0', |
| 310 | params, |
| 311 | |
| 312 | // Request configuration - for custom tools we'll use the execute endpoint |
| 313 | request: { |
| 314 | url: '/api/function/execute', |
| 315 | method: 'POST', |
| 316 | headers: () => ({ 'Content-Type': 'application/json' }), |
| 317 | body: createCustomToolRequestBody(customTool, true), |
| 318 | }, |
| 319 | |
| 320 | // Standard response handling for custom tools |
| 321 | transformResponse: async (response: Response) => { |
| 322 | const data = await response.json() |
| 323 | |
| 324 | if (!data.success) { |
| 325 | throw new Error(data.error || 'Custom tool execution failed') |
| 326 | } |
| 327 | |
| 328 | return { |
| 329 | success: true, |
| 330 | output: data.output.result || data.output, |
| 331 | error: undefined, |
| 332 | } |
| 333 | }, |
| 334 | } |
| 335 | } |
no test coverage detected