/** * Tool Utilities Module - Helper functions for tool/function call handling * * Features: * - Validates tool/function call names before execution * - Filters out calls with empty or missing names * - Creates error tool results for malformed calls * - Emits SSE events for tool errors * - Universal parameter validation for all tool types * * Implementation Details: * - Uses minimal fallback ID generator to avoid external dependencies * - Creates role='tool' messages for conversation history * - Publishes tool-error SSE events to surface problems * - Best-effort error reporting to avoid cascading failures * - Consistent parameter validation for both MCP and built-in tools * * Recent Changes: * - 2026-03-11: Strip workingDirectory/working_directory from shell_cmd args in normalizeKnownParameterAliases; these are context fields the LLM echoes from the system prompt, not tool parameters. * - 2026-03-11: Emit system error event in wrapToolWithValidation when tool parameter validation fails so errors surface in the UI. * - 2026-03-01: Added backward-compatible normalization for `.includePattern` -> `includePattern` in `list_files` and `grep`. * - 2026-02-20: Enforced JSON-schema `additionalProperties: false` by rejecting unknown tool arguments during validation. * - 2026-02-27: Added backward-compat cleanup for removed HITL confirmation args by stripping them before schema validation. * - 2026-02-27: Removed deprecated `human_intervention_request` confirmation argument alias normalization; kept `prompt` -> `question` and `default_option` -> `defaultOption`. * - 2026-02-20: Added `create_agent` alias normalization for `auto-reply`/`auto_reply` -> `autoReply` and `next agent` variants -> `nextAgent`. * - 2026-02-19: Added parameter alias normalization for `read_file`/`read_files` (`path` -> `filePath`) and `grep` path aliases (`path` -> `directoryPath`) to align with shell-style path handling. * - 2026-02-06: Removed legacy manual tool-intervention functionality * - Simplified wrapToolWithValidation to focus on parameter validation only * - Initial implementation for empty/missing name validation */ import { World, Agent, ChatMessage } from './types.js'; /** * Minimal fallback ID generator * Generates a simple unique identifier without external dependencies * Exported for use in non-streaming handlers */ export declare function generateFallbackId(): string; /** * Function call interface for validation */ interface FunctionCall { id?: string; type?: string; function?: { name?: string; arguments?: string; }; } /** * Filter and handle function calls with empty or missing names * * @param functionCalls - Array of function calls to validate * @param world - World context for event publishing * @param agent - Agent making the calls * @param messageId - Message ID for tracking * @param chatId - Explicit chat scope for tool-error event publication * @returns Object with validCalls array and toolResults array for invalid calls */ export declare function filterAndHandleEmptyNamedFunctionCalls(functionCalls: FunctionCall[], world: World, agent: Agent, messageId: string, chatId: string): { validCalls: FunctionCall[]; toolResults: ChatMessage[]; }; /** * Validate tool parameters against schema before execution * Provides consistent validation for both MCP and built-in tools * * @param args - Tool arguments to validate * @param toolSchema - Tool parameter schema with type and required information * @param toolName - Name of the tool (for logging) * @returns Validation result with corrected args or error details */ export declare function validateToolParameters(args: any, toolSchema: any, toolName: string): { valid: boolean; correctedArgs?: any; error?: string; }; /** * Wrap tool execution with universal parameter validation * Provides a standardized validation layer for all tools * * @param tool - Tool object with execute function and parameters schema * @param toolName - Name of the tool (for logging and error reporting) * @returns Wrapped tool with validation */ export declare function wrapToolWithValidation(tool: any, toolName: string): any; export {};