UNPKG

@nanocollective/nanocoder

Version:

A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter

35 lines 1.24 kB
/** * Filters out invalid tool calls. * Returns valid tool calls and error results for invalid ones. * * Handles: * - Empty tool calls (missing id or function name) * - Tools that don't exist in the tool manager */ export const filterValidToolCalls = (toolCalls, toolManager) => { const validToolCalls = []; const errorResults = []; for (const toolCall of toolCalls) { // Filter out completely empty tool calls if (!toolCall.id || !toolCall.function?.name) { continue; } // Filter out tool calls with empty names if (toolCall.function.name.trim() === '') { continue; } // Filter out tool calls for tools that don't exist if (toolManager && !toolManager.hasTool(toolCall.function.name)) { errorResults.push({ tool_call_id: toolCall.id, role: 'tool', name: toolCall.function.name, content: `This tool does not exist. Please use only the tools that are available in the system.`, }); continue; } validToolCalls.push(toolCall); } return { validToolCalls, errorResults }; }; //# sourceMappingURL=tool-filters.js.map