continue-custom/core/tools/parseArgs.ts
2025-06-04 15:16:41 -07:00

26 lines
597 B
TypeScript

import { ToolCallDelta } from "..";
function safeParseArgs(
args: string | undefined,
errorId?: string,
): Record<string, any> {
try {
return JSON.parse(args ?? "{}");
} catch (e) {
const identifier = errorId ? `Call: ${errorId}\nArgs:${args}\n` : "";
console.error(
`Failed to parse tool call arguments\n${identifier}Error:`,
e,
);
return {};
}
}
export function safeParseToolCallArgs(
toolCall: ToolCallDelta,
): Record<string, any> {
return safeParseArgs(
toolCall.function?.arguments,
`${toolCall.function?.name} ${toolCall.id}`,
);
}