handle empty string json args

This commit is contained in:
Dallin Romney 2025-06-26 10:35:24 -07:00
parent 07a1792a40
commit c073a1e07c
3 changed files with 7 additions and 3 deletions

View file

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

View file

@ -10,7 +10,11 @@ const ResultGroup = memo(function ResultGroup({ group }: ResultGroupProps) {
return (
<>
{group.map((result, i) => (
<Result key={i} result={result} prevResult={group[i - 1]}></Result>
<Result
key={`${result.timestamp}-${i}`}
result={result}
prevResult={group[i - 1]}
></Result>
))}
</>
);

View file

@ -3,7 +3,7 @@ export function safeParseArgs(
errorId?: string,
): Record<string, any> {
try {
return JSON.parse(args ?? "{}");
return JSON.parse(args?.trim() || "{}");
} catch (e) {
const identifier = errorId ? `Call: ${errorId}\nArgs:${args}\n` : "";
console.error(