Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(rooms): name the hand-off's own holder, not a sibling thread's speaker
erywim99ba60a521ea
diff --git a/server/host/room-queued-reason.test.ts b/server/host/room-queued-reason.test.tsnew file mode 100644index 0000000000..d1592f9e5e--- /dev/null+++ b/server/host/room-queued-reason.test.ts@@ -0,0 +1,44 @@+import { describe, expect, it } from "vitest";++import { roomQueuedReason, type RoomQueuedReasonDeps } from "./room-queued-reason.ts";++const ROOM_X = { id: "gx", name: "Room X", threadId: "x" };+const ROOM_Y = { id: "gy", name: "Room Y", threadId: "y" };+const rooms = new Map([[ROOM_X.id, ROOM_X], [ROOM_Y.id, ROOM_Y]]);+const threads = new Map([["x", ROOM_X], ["x1", ROOM_X], ["x2", ROOM_X], ["y", ROOM_Y], ["y1", ROOM_Y]]);+const speaker = (botId: string, name: string) => ({ botId, name });++function fixture(speakers: Record<string, { botId: string; name: string }>): RoomQueuedReasonDeps {+ const map = new Map(Object.entries(speakers));+ return { group: (id) => rooms.get(id), roomOfThread: (id) => threads.get(id), speaker: (id) => map.get(id), speakers: () => map };+}++const node = (over: Partial<{ groupId: string; botId: string; threadId: string }> = {}) =>+ ({ groupId: ROOM_X.id, botId: "bot-bob", threadId: "x2", ...over });++describe("a queued room hand-off's reason", () => {+ it("names the speaker in the hand-off's own thread", () => {+ expect(roomQueuedReason(node(), fixture({ x2: speaker("bot-alice", "Alice") })))+ .toBe("waiting for Alice to finish its turn in this room");+ });++ it("names the room where the hand-off's own teammate is speaking, not a sibling thread's speaker", () => {+ expect(roomQueuedReason(node(), fixture({ x1: speaker("bot-alice", "Alice"), y1: speaker("bot-bob", "Bob") })))+ .toBe('waiting for Bob to finish its turn in the room "Room Y"');+ });++ it("names the teammate's own turn in this room when it is another thread of the same room", () => {+ expect(roomQueuedReason(node(), fixture({ x1: speaker("bot-bob", "Bob") })))+ .toBe("waiting for Bob to finish its turn in this room");+ });++ it("keeps the caller's generic line when only another member speaks, or nobody does", () => {+ expect(roomQueuedReason(node(), fixture({ x1: speaker("bot-alice", "Alice") }))).toBeUndefined();+ expect(roomQueuedReason(node(), fixture({}))).toBeUndefined();+ });++ it("leaves a non-room hand-off, and a room that is gone, to the caller", () => {+ expect(roomQueuedReason(node({ groupId: undefined }), fixture({ x2: speaker("bot-alice", "Alice") }))).toBeUndefined();+ expect(roomQueuedReason(node({ groupId: "gone" }), fixture({ x2: speaker("bot-alice", "Alice") }))).toBeUndefined();+ });+});diff --git a/server/host/room-queued-reason.ts b/server/host/room-queued-reason.tsnew file mode 100644index 0000000000..343d69d002--- /dev/null+++ b/server/host/room-queued-reason.ts@@ -0,0 +1,43 @@+/** What the queue can see of a room and the turns holding it. */+export interface RoomQueuedReasonDeps {+ group(groupId: string): { id: string; name: string; threadId: string } | undefined;+ /** The room a thread belongs to, its own thread or one of its task threads. */+ roomOfThread(threadId: string): { id: string; name: string } | undefined;+ speaker(threadId: string): { botId: string; name: string } | undefined;+ speakers(): Iterable<[string, { botId: string; name: string }]>;+}++/** The live store and speaker map, as `roomReasonFor` reads them. */+export interface RoomReasonSource {+ group(groupId: string): { id: string; name: string; threadId: string } | undefined;+ groupByThread(threadId: string): { id: string; name: string } | undefined;+ speakers: ReadonlyMap<string, { botId: string; name: string }>;+}++/** The `roomReason` dependency of `createQueuedReason`, over a store and the server's room speakers. */+export function roomReasonFor(source: RoomReasonSource): (node: { groupId?: string; botId: string; threadId: string }) => string | undefined {+ return (node) => roomQueuedReason(node, {+ group: (id) => source.group(id),+ roomOfThread: (id) => source.groupByThread(id),+ speaker: (id) => source.speakers.get(id),+ speakers: () => source.speakers,+ });+}++/** A busy room node is held either by a speaker in its own thread, or by its own teammate speaking somewhere else. Name+ * that holder; a room reservation with no turn behind it is not enough, and the caller's generic line covers the rest. */+export function roomQueuedReason(node: { groupId?: string; botId: string; threadId: string }, deps: RoomQueuedReasonDeps): string | undefined {+ if (!node.groupId) return undefined;+ const group = deps.group(node.groupId);+ if (!group) return undefined;+ const here = deps.speaker(node.threadId);+ if (here) return `waiting for ${here.name} to finish its turn in this room`;+ for (const [threadId, speaker] of deps.speakers()) {+ if (speaker.botId !== node.botId) continue;+ const room = deps.roomOfThread(threadId);+ return !room || room.id === group.id+ ? `waiting for ${speaker.name} to finish its turn in this room`+ : `waiting for ${speaker.name} to finish its turn in the room ${JSON.stringify(room.name)}`;+ }+ return undefined;+}diff --git a/server/index.ts b/server/index.tsindex 2e43682abc..f36918aacc 100644--- a/server/index.ts+++ b/server/index.ts@@ -302,7 +302,7 @@ import { CONSENT_RULE, continuedOrigin, escapeNotes, labelledLine, OUTSIDE, peerimport { decideRoomPost, emptyRoomPostBudget, type RoomPostAttempt, type RoomPostBudget } from "./room-post-budget.ts";import { messagePages, pageMessage, pageSize, slimMessage } from "./host/message-pages.ts"; import { SUGGESTION_MAX_AGE_MS, suggestedSelection } from "./host/suggested-selection.ts"; import { otherProviderSelection } from "./checker-model.ts"; import { checkWorkFile, createCheckWork } from "./host/check-work.ts";import { coordinateResultMessage, createAsksActingPerson, createTeammatePrompts } from "./host/teammate-prompts.ts"; import { createPersonalReach } from "./host/personal-reach.ts"; import { createMausBotOwnChat } from "./host/mausbot-own-chat.ts"; import { moveMemoryLayer } from "./memory-move.ts";-import { createQueuedReason } from "./host/queued-reason.ts";+import { createQueuedReason } from "./host/queued-reason.ts"; import { roomReasonFor } from "./host/room-queued-reason.ts";import { ReplayBuffer } from "./host/sse-replay.ts";import {mentionedBots,@@ -3705,31 +3705,12 @@ function coordinationSystemInstructions(): string {}const threadReadableFrom = (threadId: string) => (other: string): boolean => !proactive.fence.confines(other) && !botApiThread(other) && (CLOUD_TEAM ? teamHost.readableFrom(threadId)(other) : !CLOUD_HOME || cloudOwnerOnlyThread(other));-const queuedDeps = { botName: (id: string) => store.bot(id)?.name, threadBusy, groupTurn: (id: string) => Boolean(activeGroupTurnForBot(id)), behindPerson: queuedBehindPerson,- roomReason: roomQueuedReason,+const queuedDeps = { botName: (id: string) => store.bot(id)?.name, threadBusy, groupTurn: (id: string) => Boolean(activeGroupTurnForBot(id)), behindPerson: queuedBehindPerson, roomReason: roomReasonFor({ group: (id: string) => store.group(id), groupByThread: (id: string) => store.groupByThread(id), speakers: groupSpeakers }),waitsForComputer: (node: HandoffView) => parkedSeatTaken(node.id),slots: (id: string) => ({ busy: store.tasks(id).filter((task) => threadBusy(id, task.threadId)).map(({ threadId, title }) => ({ threadId, title })), limit: maxConcurrentChildThreads(cfg, botThreadsHost(cloudPlanTier.starter())) }) }; const queuedStatus = createQueuedReason(queuedDeps), queuedNotes = createQueuedNotes({ ...queuedDeps, now: Date.now, language: (threadId) => threadLanguage(threadId), parent: (node) => node.parentId ? coordinator.node(node.parentId) : undefined, node: (id) => coordinator.node(id), post: (parent, node, line) => { const bot = store.bot(node.botId), title = store.taskByThread(node.botId, node.threadId)?.title; store.appendMessage(parent.threadId, { role: "bot", kind: "activity", ...(bot ? { from: { botId: bot.id, name: bot.name, color: bot.color } } : {}), tool: { name: line, ok: true }, ...(title ? { threadRef: { botId: node.botId, threadId: node.threadId, title } } : {}) }); } });const asksActingPerson = createAsksActingPerson({ team: Boolean(CLOUD_TEAM), requester: (threadId, generation) => actingPeople.requester(threadId, generation), askedPerson: (botId, threadId) => teamOwners.routing.askedPerson(botId, threadId) });const teammatePrompts = createTeammatePrompts({ store, asksActingPerson, outstandingDirect: (threadId) => coordinator.outstandingDirect(threadId), openPersonCard, queuedStatus, isUnattended, fullAccess: fullAccessForSource, startedOutside, guestDriven: cloudGuestDriven, confined: (threadId) => proactive.fence.confines(threadId), readableFrom: threadReadableFrom, waitingForPerson: (chief, teammates, readable) => questionRouting.waitingForPerson(chief, teammates, readable) });-/** A room hand-off waits on whatever holds that room, so name it instead of leaving every room node with the same line. */-function roomQueuedReason(node: HandoffView): string | undefined {- if (!node.groupId) return undefined;- const group = store.group(node.groupId);- if (!group) return undefined;- const ownsThread = (threadId: string) => group.dm ? threadId === group.threadId : Boolean(store.groupTaskByThread(group.id, threadId));- const speaker = groupSpeakers.get(node.threadId)- ?? groupSpeakers.get(group.threadId)- ?? [...groupSpeakers].find(([threadId]) => ownsThread(threadId))?.[1];- if (speaker) return `waiting for ${speaker.name} to finish its turn in this room`;- const held = activeGroupTurnForBot(node.botId);- if (!held) return undefined;- const name = store.bot(node.botId)?.name ?? "that teammate";- return held.group.id === group.id- ? `waiting for ${name} to finish its turn in this room`- : `waiting for ${name} to finish its turn in the room ${JSON.stringify(held.group.name)}`;-}-function queuedBehindPerson(node: HandoffView): { threadId: string; kind: PersonWaitKind; title: string } | undefined {if (node.groupId || node.status !== "queued" || threadBusy(node.botId, node.threadId) || !botAtThreadCapacity(node.botId, undefined, true)) return undefined;for (const task of store.tasks(node.botId)) {