Some models (e.g., via google-antigravity) omit the 'arguments' field
for tools with no required parameters. When this happens, pi-ai passes
undefined to Anthropic's 'input' field, causing API rejection with:
'messages.N.content.M.tool_use.input: Field required'
This fix adds normalizeToolCallArguments() which ensures arguments is
always an object (defaulting to {}) before messages reach the API.
Fixes tool calls for:
- memory_status
- load_memory (without trigger)
- Any tool with optional-only or no parameters
- Add ToolCallIdMode type ('standard' | 'strict') for provider compatibility
- Standard mode (default): allows [a-zA-Z0-9_-] for readable session logs
- Strict mode: only [a-zA-Z0-9] for Mistral via OpenRouter
- Update sanitizeSessionMessagesImages to accept toolCallIdMode option
- Export ToolCallIdMode from pi-embedded-helpers barrel
Addresses review feedback on PR #1372 about readability.
Some providers like Mistral via OpenRouter require strictly alphanumeric
tool call IDs. The error message indicates: "Tool call id was
whatsapp_login_1768799841527_1 but must be a-z, A-Z, 0-9, with a length
of 9."
Changes:
- Update sanitizeToolCallId to strip all non-alphanumeric characters
(previously allowed underscores and hyphens)
- Update makeUniqueToolId to use alphanumeric suffixes (x2, x3, etc.)
instead of underscores
- Update isValidCloudCodeAssistToolId to validate alphanumeric-only IDs
- Update tests to reflect stricter sanitization
Fixes#1359
Co-Authored-By: Claude <noreply@anthropic.com>