* Parse the accumulated streaming arguments for a tool call. Throws a clear * error if the JSON is malformed — silently substituting `{}` would let a * tool fire with empty inputs, masking truncated streams or mis-shaped output.
(toolCall: {
id: string
name: string
arguments: string
})
| 49 | * tool fire with empty inputs, masking truncated streams or mis-shaped output. |
| 50 | */ |
| 51 | function parseToolCallInput(toolCall: { |
| 52 | id: string |
| 53 | name: string |
| 54 | arguments: string |
| 55 | }): unknown { |
| 56 | if (!toolCall.arguments) return {} |
| 57 | try { |
| 58 | return transformNullsToUndefined(JSON.parse(toolCall.arguments)) |
| 59 | } catch (cause) { |
| 60 | const preview = toolCall.arguments.slice(0, 200) |
| 61 | const ellipsis = toolCall.arguments.length > 200 ? '...' : '' |
| 62 | throw new Error( |
| 63 | `Failed to parse tool call arguments for tool '${toolCall.name}' (id: ${toolCall.id}). Arguments: ${preview}${ellipsis}`, |
| 64 | { cause }, |
| 65 | ) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Configuration for Mistral text adapter. |
no test coverage detected