Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Name a room only when the member's turn there has started
Bugfixer 2fa4f3e664df0
diff --git a/server/host/room-jobs.test.ts b/server/host/room-jobs.test.tsindex 6cc11a754c..df955cc8c8 100644--- a/server/host/room-jobs.test.ts+++ b/server/host/room-jobs.test.ts@@ -8,7 +8,7 @@ import { createRoomJobs } from "./room-jobs.ts";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[]>; running?: string[]; jobs: Partial<HandoffView>[] }) {+function setup(input: { rooms: Room[]; operations?: Record<string, Operation[]>; busyThreads?: Record<string, string[]>; running?: string[]; speakers?: Record<string, string>; jobs: Partial<HandoffView>[] }) {const running = new Set([...(input.running ?? []), ...Object.keys(input.busyThreads ?? {})]);const store = {groups: input.rooms,@@ -18,7 +18,7 @@ function setup(input: { rooms: Room[]; operations?: Record<string, Operation[]>;const active = input.jobs.map((job, index) => ({ id: `job-${index}`, parentId: "lead-turn", status: "queued", createdAt: index, ...job }) as HandoffView);return createRoomJobs({store, cfg: {} as AppConfig, coordinator: { active: () => active },- operations: (groupId) => input.operations?.[groupId] ?? [], speakerOf: () => undefined, laneRoomThread: () => undefined,+ operations: (groupId) => input.operations?.[groupId] ?? [], speakerOf: (threadId) => input.speakers?.[threadId], laneRoomThread: () => undefined,});}@@ -27,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, running: ["coder"], operations: { "room-1": [{ threadId: "g1", cancelled: false, botIds: new Set(["coder"]) }] }, jobs: [handedIn2] });+ const jobs = setup({ rooms, running: ["coder"], speakers: { g1: "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" } },]);@@ -52,4 +52,10 @@ describe("a room's queue names where a waiting member is busy", () => {expect(setup({ rooms: three, running: ["coder"], operations: pendingInRoom1, jobs: [handedIn2] }).roomLineOf(three[1] as never)[0]?.busyIn).toEqual({ groupId: "room-3", threadId: "g3" });});++ it("does not name a room whose turn for the member has not started yet", () => {+ const queuedInRoom1 = { "room-1": [{ threadId: "g1", cancelled: false, botIds: new Set(["coder"]) }] };+ expect(setup({ rooms, busyThreads: { coder: ["own-chat"] }, operations: queuedInRoom1, jobs: [handedIn2] }).roomLineOf(rooms[1] as never)[0]?.busyIn)+ .toEqual({ threadId: "own-chat" });+ });});diff --git a/server/host/room-jobs.ts b/server/host/room-jobs.tsindex 761bb18f72..cf2ce0e8c9 100644--- a/server/host/room-jobs.ts+++ b/server/host/room-jobs.ts@@ -26,13 +26,13 @@ const live = (n: HandoffView) => n.parentId !== undefined && (n.status === "queuexport 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.- * 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. */+ * The host holds a room hand-off while the member runs (bot.busy), so a turn in another room that has not reached it yet 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)- && (!operation.line || operation.line.current === botId || speakerOf(operation.threadId) === botId));+ && (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 };}