(toolCall)
| 74 | * Execute a tool call |
| 75 | */ |
| 76 | export async function executeToolCall(toolCall) { |
| 77 | const { name, arguments: argsString } = toolCall.function; |
| 78 | |
| 79 | try { |
| 80 | // Parse arguments from JSON string |
| 81 | let args; |
| 82 | try { |
| 83 | args = typeof argsString === 'string' ? JSON.parse(argsString) : argsString; |
| 84 | } catch (parseError) { |
| 85 | throw new Error(`Invalid JSON arguments for ${name}: ${parseError.message}`); |
| 86 | } |
| 87 | |
| 88 | switch (name) { |
| 89 | case 'search_games': |
| 90 | return await searchGames(args); |
| 91 | case 'get_search_suggestions': |
| 92 | return await getSearchSuggestions(args); |
| 93 | default: |
| 94 | throw new Error(`Unknown tool: ${name}`); |
| 95 | } |
| 96 | } catch (error) { |
| 97 | console.error(`Tool execution error for ${name}:`, error); |
| 98 | return { |
| 99 | error: `Failed to execute ${name}: ${error.message}` |
| 100 | }; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Search for games using the existing search infrastructure |
no test coverage detected