Skip to content

Commit 2c8e2c1

Browse files
committed
chore: error handling tools parameters
1 parent df4b645 commit 2c8e2c1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

web-app/src/lib/completion.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ export const postMessageProcessing = async (
329329
message: ThreadMessage,
330330
abortController: AbortController,
331331
approvedTools: Record<string, string[]> = {},
332-
showModal?: (toolName: string, threadId: string, toolParameters?: object) => Promise<boolean>,
332+
showModal?: (
333+
toolName: string,
334+
threadId: string,
335+
toolParameters?: object
336+
) => Promise<boolean>,
333337
allowAllMCPPermissions: boolean = false
334338
) => {
335339
// Handle completed tool calls
@@ -358,14 +362,23 @@ export const postMessageProcessing = async (
358362
}
359363

360364
// Check if tool is approved or show modal for approval
361-
const toolParameters = toolCall.function.arguments.length
362-
? JSON.parse(toolCall.function.arguments)
363-
: {}
365+
let toolParameters = {}
366+
if (toolCall.function.arguments.length) {
367+
try {
368+
toolParameters = JSON.parse(toolCall.function.arguments)
369+
} catch (error) {
370+
console.error('Failed to parse tool arguments:', error)
371+
}
372+
}
364373
const approved =
365374
allowAllMCPPermissions ||
366375
approvedTools[message.thread_id]?.includes(toolCall.function.name) ||
367376
(showModal
368-
? await showModal(toolCall.function.name, message.thread_id, toolParameters)
377+
? await showModal(
378+
toolCall.function.name,
379+
message.thread_id,
380+
toolParameters
381+
)
369382
: true)
370383

371384
let result = approved

0 commit comments

Comments
 (0)