Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Name a busy place only where the teammate is running, and keep an unnamed room wait
Bugfixer 2da7653253571
diff --git a/server/host/room-jobs.test.ts b/server/host/room-jobs.test.tsindex 6f2e20ba75..6cc11a754c 100644--- a/server/host/room-jobs.test.ts+++ b/server/host/room-jobs.test.ts@@ -5,12 +5,14 @@ import type { HandoffView } from "../coordinator.ts";import type { Store } from "../store.ts";import { createRoomJobs } from "./room-jobs.ts";-type Operation = { threadId: string; cancelled: boolean; botIds: Set<string> };+type Operation = { threadId: string; cancelled: boolean; botIds: Set<string>; line?: { current?: string; pending: string[] } };type Room = { id: string; name: string; threadId: string; busyBotId?: string | null };-function setup(input: { rooms: Room[]; operations?: Record<string, Operation[]>; busyThreads?: Record<string, string[]>; jobs: Partial<HandoffView>[] }) {+function setup(input: { rooms: Room[]; operations?: Record<string, Operation[]>; busyThreads?: Record<string, string[]>; running?: string[]; jobs: Partial<HandoffView>[] }) {+ const running = new Set([...(input.running ?? []), ...Object.keys(input.busyThreads ?? {})]);const store = {groups: input.rooms,+ bot: (botId: string) => ({ id: botId, busy: running.has(botId) }),tasks: (botId: string) => (input.busyThreads?.[botId] ?? []).map((threadId) => ({ threadId, title: threadId, busy: true })),} as unknown as Store;const active = input.jobs.map((job, index) => ({ id: `job-${index}`, parentId: "lead-turn", status: "queued", createdAt: index, ...job }) as HandoffView);@@ -25,7 +27,7 @@ describe("a room's queue names where a waiting member is busy", () => {const handedIn2 = { botId: "coder", groupId: "room-2", threadId: "g2" };it("marks a member queued here while its turn runs in another room", () => {- const jobs = setup({ rooms, operations: { "room-1": [{ threadId: "g1", cancelled: false, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });+ const jobs = setup({ rooms, running: ["coder"], operations: { "room-1": [{ threadId: "g1", cancelled: false, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });expect(jobs.roomLineOf(rooms[1] as never)).toEqual([{ botId: "coder", threadId: "g2", state: "queued", position: 1, of: 1, assignmentId: "job-0", busyIn: { groupId: "room-1", threadId: "g1" } },]);@@ -35,9 +37,19 @@ describe("a room's queue names where a waiting member is busy", () => {expect(setup({ rooms, busyThreads: { coder: ["own-chat"] }, jobs: [handedIn2] }).roomLineOf(rooms[1] as never)[0]?.busyIn).toEqual({ threadId: "own-chat" });expect(setup({ rooms, jobs: [handedIn2] }).roomLineOf(rooms[1] as never)[0]?.busyIn).toBeUndefined();- const sameRoom = setup({ rooms, operations: { "room-2": [{ threadId: "g2", cancelled: false, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });+ const sameRoom = setup({ rooms, running: ["coder"], operations: { "room-2": [{ threadId: "g2", cancelled: false, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });expect(sameRoom.roomLineOf(rooms[1] as never)[0]?.busyIn).toBeUndefined();- const cancelled = setup({ rooms, operations: { "room-1": [{ threadId: "g1", cancelled: true, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });+ const cancelled = setup({ rooms, running: ["coder"], operations: { "room-1": [{ threadId: "g1", cancelled: true, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });expect(cancelled.roomLineOf(rooms[1] as never)[0]?.busyIn).toBeUndefined();});++ it("names only the place a member is running: the host holds room hand-offs on that, not on a later turn in another room's round", () => {+ const pendingInRoom1 = { "room-1": [{ threadId: "g1", cancelled: false, botIds: new Set(["scout", "coder"]), line: { current: "scout", pending: ["coder"] } }] };+ // Only waiting for its turn in Group 1's round, not running: this room does not wait on Group 1.+ expect(setup({ rooms, operations: pendingInRoom1, jobs: [handedIn2] }).roomLineOf(rooms[1] as never)[0]?.busyIn).toBeUndefined();+ // Waiting in Group 1's round while it runs in Group 3: Group 3 is where it is busy.+ const three = [...rooms, { id: "room-3", name: "Group 3", threadId: "g3", busyBotId: "coder" }];+ expect(setup({ rooms: three, running: ["coder"], operations: pendingInRoom1, jobs: [handedIn2] }).roomLineOf(three[1] as never)[0]?.busyIn)+ .toEqual({ groupId: "room-3", threadId: "g3" });+ });});diff --git a/server/host/room-jobs.ts b/server/host/room-jobs.tsindex 0ff98d9a2f..761bb18f72 100644--- a/server/host/room-jobs.ts+++ b/server/host/room-jobs.ts@@ -25,11 +25,14 @@ export function parallelRoomJobsEnabled(cfg: AppConfig): boolean {const live = (n: HandoffView) => n.parentId !== undefined && (n.status === "queued" || n.status === "running");export function createRoomJobs({ store, coordinator, cfg, operations, speakerOf, laneRoomThread }: RoomJobsDeps) {- /** Where a member runs now outside this room, if anywhere: a turn in another room, else a busy thread of its own. */+ /** Where a member runs now outside this room, if anywhere: a turn in another room, else a busy thread of its own.+ * The host holds a room hand-off while the member runs (bot.busy), so being due later in another room's round is not busy. */function busyElsewhere(botId: string, roomId: string): RoomQueueEntry["busyIn"] {+ if (!store.bot(botId)?.busy) return undefined;for (const other of store.groups) {if (other.id === roomId) continue;- const turn = [...operations(other.id)].find(operation => !operation.cancelled && operation.botIds.has(botId));+ const turn = [...operations(other.id)].find(operation => !operation.cancelled && operation.botIds.has(botId)+ && (!operation.line || operation.line.current === botId || speakerOf(operation.threadId) === botId));if (turn) return { groupId: other.id, threadId: turn.threadId };if (other.busyBotId === botId || speakerOf(other.threadId) === botId) return { groupId: other.id, threadId: other.threadId };}diff --git a/src/lib/room-threads.test.ts b/src/lib/room-threads.test.tsindex dc80f4505b..5310fc9000 100644--- a/src/lib/room-threads.test.ts+++ b/src/lib/room-threads.test.ts@@ -88,7 +88,8 @@ describe("room queue labels", () => {const entry = { botId: "coder", threadId: "open", state: "queued" as const, position: 2, of: 2, waitingForBotId: "scout", busyIn: { groupId: "room-1", threadId: "g1" } };expect(roomQueueLabel(entry, () => "Scout", placeOf)).toBe("Busy in Group 1 · queued after Scout (2 of 2), starts when both finish");expect(roomQueueLabel(entry, () => "Scout")).toBe("Busy in another conversation · queued after Scout (2 of 2), starts when both finish");- // A waited-for member this viewer can't name falls back to the plain busy line.- expect(roomQueueLabel(entry, () => undefined, placeOf)).toBe("Busy in Group 1 · queued (2 of 2), starts when it finishes");+ // A waited-for member this viewer can't name still keeps the wait in this room.+ expect(roomQueueLabel(entry, () => undefined, placeOf)).toBe("Busy in Group 1 · queued after a teammate (2 of 2), starts when both finish");+ expect(roomQueueLabel(entry, () => undefined)).toBe("Busy in another conversation · queued after a teammate (2 of 2), starts when both finish");});});diff --git a/src/lib/room-threads.ts b/src/lib/room-threads.tsindex 13d712be8e..8f1fcf82c7 100644--- a/src/lib/room-threads.ts+++ b/src/lib/room-threads.ts@@ -56,7 +56,10 @@ export function roomQueueLabel(entry: RoomQueueEntry, nameOf: (botId: string) =>if (entry.busyIn) {const place = placeOf?.(entry);const slot = { position: entry.position, of: entry.of };- if (name) return place ? t("room.queue.busyInAfter", { place, name, ...slot }) : t("room.queue.busyElsewhereAfter", { name, ...slot });+ if (entry.waitingForBotId) {+ const after = name ?? t("room.queue.aTeammate");+ return place ? t("room.queue.busyInAfter", { place, name: after, ...slot }) : t("room.queue.busyElsewhereAfter", { name: after, ...slot });+ }return place ? t("room.queue.busyIn", { place, ...slot }) : t("room.queue.busyElsewhere", slot);}return namediff --git a/src/locales/en.json b/src/locales/en.jsonindex a176b4d746..4d1faad043 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -5237,6 +5237,7 @@"room.queue.busyElsewhere": "Busy in another conversation · queued ({position} of {of}), starts when it finishes","room.queue.busyInAfter": "Busy in {place} · queued after {name} ({position} of {of}), starts when both finish","room.queue.busyElsewhereAfter": "Busy in another conversation · queued after {name} ({position} of {of}), starts when both finish",+ "room.queue.aTeammate": "a teammate","room.queue.member": "{name}: {status}","room.responder.everyone": "Plain messages go to every group member; @mentions override this","room.responder.mentions": "Only explicitly @mentioned bots respond",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 314f136e78..13f01c4bd5 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -4919,6 +4919,7 @@"room.queue.busyElsewhere": "Ocupado em outra conversa · na fila ({position} de {of}), começa quando terminar","room.queue.busyInAfter": "Ocupado em {place} · na fila depois de {name} ({position} de {of}), começa quando os dois terminarem","room.queue.busyElsewhereAfter": "Ocupado em outra conversa · na fila depois de {name} ({position} de {of}), começa quando os dois terminarem",+ "room.queue.aTeammate": "um colega","room.queue.member": "{name}: {status}","room.responder.everyone": "Mensagens sem @menção vão para todos os membros do grupo; @menções têm prioridade","room.responder.mentions": "Só respondem os bots explicitamente @mencionados",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex 58b0c2fd3f..1cae685b83 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -37196,7 +37196,8 @@"room.queue.busyIn": "57c8a5a630dcea31ceae7b194162bcaaa5dcef4f7bb24eeaf532f5143cc791c7","room.queue.busyElsewhere": "ecdbe34c1cca24d6d0365a04bf672203b437647795ac4e358fbcf671ef345b97","room.queue.busyInAfter": "a944c189ff63871adf83e91509d65f6ec8044478de1969f5a8874a11d2f15847",- "room.queue.busyElsewhereAfter": "3432832abb792772c22e30806a674a4edcd22f660ee53d47ba4e2075121a79e8"+ "room.queue.busyElsewhereAfter": "3432832abb792772c22e30806a674a4edcd22f660ee53d47ba4e2075121a79e8",+ "room.queue.aTeammate": "1ca7804e31164a622443afee44c7ab79a97c1fb2e169b4df211bff0c10bd4a30"},"zh": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",