Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(openai-compat): accept empty tool-call id on streamed continuation chunks
AdityaUmale65389fccea09
diff --git a/server/drivers/openai-chat-protocol.test.ts b/server/drivers/openai-chat-protocol.test.tsindex 9bb75efec9..c0a8461e1b 100644--- a/server/drivers/openai-chat-protocol.test.ts+++ b/server/drivers/openai-chat-protocol.test.ts@@ -18,6 +18,30 @@ describe("streamed chat tool calls", () => {expect(calls.finish("tool_calls", false)).toEqual([completeCall]);});+ it("treats an empty-string id or type on a continuation chunk as absent (DashScope/Qwen)", () => {+ const calls = new ChatToolCalls();+ calls.add([{ index: 0, ...completeCall, function: { ...completeCall.function, arguments: "" } }], true);+ calls.add([{ index: 0, id: "", type: "function", function: { arguments: "{" } }], true);+ calls.add([{ index: 0, id: "", type: "", function: { name: "", arguments: "}" } }], true);++ expect(calls.finish("tool_calls", false)).toEqual([completeCall]);+ });++ it("still rejects a streamed call that never gets an id, and an id that changes", () => {+ const noId = new ChatToolCalls();+ noId.add([{ index: 0, id: "", type: "function", function: { name: "echo", arguments: "{}" } }], true);+ expect(() => noId.finish("tool_calls", false)).toThrow(/incomplete or duplicate/);++ const changed = new ChatToolCalls();+ changed.add([{ index: 0, ...completeCall }], true);+ expect(() => changed.add([{ index: 0, id: "call_other" }], true)).toThrow(/changed or omitted/);+ });++ it("still rejects an empty id in a whole, non-streamed reply", () => {+ const calls = new ChatToolCalls();+ expect(() => calls.add([{ ...completeCall, id: "" }], false)).toThrow(/changed or omitted/);+ });+it("still rejects incomplete calls after null-only deltas", () => {const calls = new ChatToolCalls();calls.add([{ index: 0, id: null, type: null, function: { name: null, arguments: null } }], true);diff --git a/server/drivers/openai-chat-protocol.ts b/server/drivers/openai-chat-protocol.tsindex deef5f5a6a..1bb851436d 100644--- a/server/drivers/openai-chat-protocol.ts+++ b/server/drivers/openai-chat-protocol.ts@@ -75,7 +75,9 @@ export class ChatToolCalls {add(value: unknown, streaming: boolean): void {if (value === undefined || value === null) return;if (!Array.isArray(value)) throw new ChatProtocolError("provider returned invalid tool_calls");- const omitted = (field: unknown) => field === undefined || (streaming && field === null);+ // Streamed continuation chunks may repeat a field as null, or as "" (DashScope/Qwen sends the id only on a call's+ // first chunk); finish() still requires every call to end with an id.+ const omitted = (field: unknown) => field === undefined || (streaming && (field === null || field === ""));for (const [position, raw] of value.entries()) {const delta = object(raw);const index = !streaming ? position : delta?.index ?? this.slotOf(delta?.id);