Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(openai-chat): quote non-object tool arguments back too

AdityaUmale952049a316cf
diff --git a/server/drivers/openai-chat-protocol.ts b/server/drivers/openai-chat-protocol.ts
index b8e7448142..568abbc790 100644
--- a/server/drivers/openai-chat-protocol.ts
+++ b/server/drivers/openai-chat-protocol.ts
@@ -30,7 +30,7 @@ export function toolArguments(text: string): Record<string, unknown> {
try { args = JSON.parse(text.trim() || "{}"); }
catch { throw new ChatProtocolError(`tool arguments are not complete JSON; you sent ${text.length} characters: ${shownArguments(text)}`); }
const found = object(args);
- if (!found) throw new ChatProtocolError("tool arguments must be a JSON object");
+ if (!found) throw new ChatProtocolError(`tool arguments must be a JSON object; you sent ${text.length} characters: ${shownArguments(text)}`);
return found;
}
diff --git a/server/drivers/openai-chat.test.ts b/server/drivers/openai-chat.test.ts
index 71694825be..23a2f4ca4c 100644
--- a/server/drivers/openai-chat.test.ts
+++ b/server/drivers/openai-chat.test.ts
@@ -437,6 +437,7 @@ describe("createOpenAIChatRuntime tool approvals", () => {
it.each([
["not JSON", '{"path":"a.md","content":"cut off', "{}", 'tool arguments are not complete JSON; you sent 33 characters: {"path":"a.md","content":"cut off'],
+ ["a JSON array", '[{"path":"a.md"}]', "{}", 'tool arguments must be a JSON object; you sent 17 characters: [{"path":"a.md"}]'],
["empty", "", "{}", undefined],
["blank", " ", "{}", undefined],
["led by a byte-order mark", '\uFEFF{"n":1}', '{"n":1}', undefined],