fix(ollama): add try/catch to JSON.parse in buildAssistantMessage
Responds to Greptile review feedback: add try/catch around JSON.parse in buildAssistantMessage to match extractToolCalls, preventing potential crash if Ollama returns malformed JSON string.
This commit is contained in:
parent
1ce0a6f025
commit
55f97ef257
@ -367,7 +367,13 @@ export function buildAssistantMessage(
|
||||
const rawArgs = tc.function.arguments;
|
||||
const normalizedArgs =
|
||||
typeof rawArgs === "string"
|
||||
? (JSON.parse(rawArgs) as Record<string, unknown>)
|
||||
? (() => {
|
||||
try {
|
||||
return JSON.parse(rawArgs) as Record<string, unknown>;
|
||||
} catch {
|
||||
return {} as Record<string, unknown>;
|
||||
}
|
||||
})()
|
||||
: (rawArgs ?? {});
|
||||
content.push({
|
||||
type: "toolCall",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user