MCPcopy
hub / github.com/TanStack/ai / parseToolCallInput

Function parseToolCallInput

packages/ai-mistral/src/adapters/text.ts:51–67  ·  view source on GitHub ↗

* 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
})

Source from the content-addressed store, hash-verified

49 * tool fire with empty inputs, masking truncated streams or mis-shaped output.
50 */
51function 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.

Callers 1

Calls 2

parseMethod · 0.80

Tested by

no test coverage detected