MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / fixToolCallInputs

Function fixToolCallInputs

frontend/app/api/chat/route.ts:100–125  ·  view source on GitHub ↗
(messages: any[])

Source from the content-addressed store, hash-verified

98// Helper function to fix tool call inputs for Bedrock API
99// Bedrock requires toolUse.input to be a JSON object, not a string
100function fixToolCallInputs(messages: any[]): any[] {
101 return messages.map((msg) => {
102 if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
103 return msg
104 }
105 const fixedContent = msg.content.map((part: any) => {
106 if (part.type === "tool-call") {
107 if (typeof part.input === "string") {
108 try {
109 const parsed = JSON.parse(part.input)
110 return { ...part, input: parsed }
111 } catch {
112 // If parsing fails, wrap the string in an object
113 return { ...part, input: { rawInput: part.input } }
114 }
115 }
116 // Input is already an object, but verify it's not null/undefined
117 if (part.input === null || part.input === undefined) {
118 return { ...part, input: {} }
119 }
120 }
121 return part
122 })
123 return { ...msg, content: fixedContent }
124 })
125}
126
127// Helper function to create cached stream response
128function createCachedStreamResponse(xml: string): Response {

Callers 1

handleChatRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected