Skip to content

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

fix(drivers): resolve both group_id spellings in coordinate_bots

Saim Shafiqueb3e8f8457696
diff --git a/server/drivers/agents-call.test.ts b/server/drivers/agents-call.test.ts
index 9a0425137c..970117a0a8 100644
--- a/server/drivers/agents-call.test.ts
+++ b/server/drivers/agents-call.test.ts
@@ -430,4 +430,34 @@ it("rejects a non-string group_id instead of delegating to the current room", as
expect(result.isError).toBeFalsy();
expect(calls[0].body).not.toHaveProperty("groupId");
});
+
+it("falls back to a nonblank camelCase groupId when group_id is blank", async () => {
+ const { result, calls } = await coordinate({ ...BASE, group_id: "", groupId: "room-9" });
+ expect(result.isError).toBeFalsy();
+ expect(calls[0].body.groupId).toBe("room-9");
+ });
+
+ it("falls back to a nonblank camelCase groupId when group_id is null", async () => {
+ const { result, calls } = await coordinate({ ...BASE, group_id: null, groupId: "room-9" });
+ expect(result.isError).toBeFalsy();
+ expect(calls[0].body.groupId).toBe("room-9");
+ });
+
+ it("rejects conflicting nonblank group_id and groupId destinations", async () => {
+ const { result, calls } = await coordinate({ ...BASE, group_id: "room-1", groupId: "room-9" });
+ expect(result.isError).toBe(true);
+ expect(calls).toEqual([]);
+ });
+
+ it("rejects a non-string camelCase groupId alongside a real group_id", async () => {
+ const { result, calls } = await coordinate({ ...BASE, group_id: "room-1", groupId: 42 });
+ expect(result.isError).toBe(true);
+ expect(calls).toEqual([]);
+ });
+
+ it("accepts the same destination in both spellings", async () => {
+ const { result, calls } = await coordinate({ ...BASE, group_id: "room-9", groupId: "room-9" });
+ expect(result.isError).toBeFalsy();
+ expect(calls[0].body.groupId).toBe("room-9");
+ });
});
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index 07389cc775..7720ba9845 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -264,7 +264,17 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
delete canonical.groupId;
delete canonical.doneWhen;
if (canonical.bot_ids === undefined) canonical.bot_ids = args.botIds;
- if (canonical.group_id === undefined) canonical.group_id = args.groupId;
+ // Both destination spellings are accepted. A blank group_id must not
+ // mask a nonblank groupId, and two different nonblank destinations
+ // conflict; resolve both spellings before the check below.
+ const snakeBlank = canonical.group_id === undefined || canonical.group_id === null
+ || (typeof canonical.group_id === "string" && canonical.group_id.trim() === "");
+ const camelBlank = args.groupId === undefined || args.groupId === null
+ || (typeof args.groupId === "string" && args.groupId.trim() === "");
+ const destinationConflict = !snakeBlank && !camelBlank
+ && typeof canonical.group_id === "string" && typeof args.groupId === "string"
+ && canonical.group_id.trim() !== args.groupId.trim();
+ if (snakeBlank && !camelBlank && typeof args.groupId === "string") canonical.group_id = args.groupId;
if (canonical.done_when === undefined) canonical.done_when = args.doneWhen;
const ids = canonical.bot_ids;
const optional = (key: string, type: "boolean" | "string") => canonical[key] === undefined || typeof canonical[key] === type;
@@ -274,7 +284,9 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
&& (canonical.reply === undefined || canonical.reply === "resume" || canonical.reply === "none")
&& optional("consult", "boolean") && optional("in_my_folder", "boolean")
&& optional("done_when", "string") && optional("reason", "string") && optional("title", "string") && optional("answers", "string")
- && (canonical.group_id === undefined || canonical.group_id === null || typeof canonical.group_id === "string");
+ && (canonical.group_id === undefined || canonical.group_id === null || typeof canonical.group_id === "string")
+ && (args.groupId === undefined || args.groupId === null || typeof args.groupId === "string")
+ && !destinationConflict;
if (!usable) {
return {
text: `coordinate_bots takes snake_case arguments: bot_ids (an array of 1-4 teammate ids) and message are required; group_id, reason, rework, title, thread ("standing", "new" or the id of a thread you opened on that teammate), reply ("resume" or "none"), consult (true or false), in_my_folder (true or false), done_when and answers are optional. Received: ${Object.keys(args).join(", ") || "none"}.`,