continue-custom/core/tools/parseArgs.ts

14 lines
405 B
TypeScript

import { ToolCallDelta } from "..";
export function safeParseToolCallArgs(
toolCall: ToolCallDelta,
): Record<string, any> {
try {
return JSON.parse(toolCall.function?.arguments ?? "{}");
} catch (e) {
console.error(
`Failed to parse tool call arguments:\nTool call: ${toolCall.function?.name + " " + toolCall.id}\nArgs:${toolCall.function?.arguments}\n`,
);
return {};
}
}