Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Room thread beside the feed keeps its Thinking readout; UI tests follow the feed
milind-soni2634e76817cf
diff --git a/scripts/testing/room-pages-ui.e2e.test.ts b/scripts/testing/room-pages-ui.e2e.test.tsindex f7e5682844..93d608fabe 100644--- a/scripts/testing/room-pages-ui.e2e.test.ts+++ b/scripts/testing/room-pages-ui.e2e.test.ts@@ -121,9 +121,9 @@ async function until<T>(probe: () => Promise<T> | T, what: string, timeoutMs = 3await evaluate(`document.querySelector('${row}').click(); true`);await until(() => evaluate(`Boolean(document.querySelector('${row}[aria-current="page"]'))`), "the room to open");- // Pepper answers the room and shows a page there through the same internal route show_html uses.- await ui("type", "--name", "Message Launch room", "--text", "Pepper, show us the coffee counter");- await ui("press", "--keys", "Enter");+ // Pepper answers the room's thread and shows a page there through the same internal route show_html uses. The room+ // is its feed, whose composer starts a new thread, so the line goes to the room's own thread by the room's route.+ await api("POST", `/api/groups/${room.id}/messages`, { text: "Pepper, show us the coffee counter", threadId: room.threadId, sendId: "room-pages-ui-send-0000" });const pepper = await roomTurn(info.botId);const shown = await card(pepper.token, { tool: "show_html", html: PAGE, title: "Coffee counter", height: 180 });expect(shown, JSON.stringify(shown.body)).toMatchObject({ status: 201, body: { messageId: expect.any(String) } });@@ -153,9 +153,19 @@ async function until<T>(probe: () => Promise<T> | T, what: string, timeoutMs = 3expect(pageDoc).toMatchObject({ room: true, can: { message: false, modelContext: false, serverTools: false, openLinks: true } });expect(await api("GET", `/api/threads/${room.threadId}/messages/${boardRow.id}/app`)).toMatchObject({ room: true, can: { serverTools: false, serverResources: false, message: false } });- // Both rows render in the room for the person, view-only. The page is a card that keeps its tools for when it is open.+ // The room's thread opens beside its feed, where both rows render for the person, view-only. The page is a card that+ // keeps its tools for when it is open.+ await until(() => evaluate(`Boolean(document.querySelector('[data-feed-thread="${room.threadId}"]'))`), "the thread's row in the feed");+ await evaluate(`document.querySelector('[data-feed-thread="${room.threadId}"] > button:first-child').click(); true`);+ await until(() => evaluate(`Boolean(document.querySelector('[data-thread-panel="${room.threadId}"]'))`), "the thread beside the feed");const live = (id: string) => `[data-app="${id}"][data-app-room][data-app-state="live"] iframe[data-app-frame]`;- await until(() => evaluate(`Boolean(document.querySelector('${live(pageId)}') && document.querySelector('${live(boardRow.id)}'))`), "both frames to go live", 30_000);+ // The panel is narrower than the chat, so each frame is brought into view to go live.+ for (const id of [pageId, boardRow.id]) {+ await until(async () => {+ await evaluate(`document.querySelector('[data-app="${id}"]')?.scrollIntoView({ block: "center" }); true`);+ return evaluate(`Boolean(document.querySelector('${live(id)}'))`);+ }, `the frame of ${id} to go live`, 30_000);+ }expect(await evaluate(`Boolean(document.querySelector('[data-app="${pageId}"] [data-page-tools]'))`)).toBe(false);mkdirSync(evidenceDir, { recursive: true });diff --git a/scripts/testing/thinking-timer-ui.e2e.test.ts b/scripts/testing/thinking-timer-ui.e2e.test.tsindex caa4335c1e..13ca4bcc22 100644--- a/scripts/testing/thinking-timer-ui.e2e.test.ts+++ b/scripts/testing/thinking-timer-ui.e2e.test.ts@@ -234,9 +234,18 @@ describe("the thinking timer stays anchored across a thread switch", () => {await selectRow(groupRow);await waitUntil(() => isCurrentRow(groupRow), 10_000, "the group to become current");- await ui("type", info.ui, "--name", "Message Timer group", "--text", "hello group");- await ui("press", info.ui, "--keys", "Enter");+ // The room is its feed, whose composer starts a new thread: the line goes to the room's own thread by the room's+ // route, and that thread opens beside the feed, where its readout is.const sentAt = Date.now();+ await api("POST", `/api/groups/${groupId}/messages`, { text: "hello group", threadId: group.threadId });+ const openThread = async () => {+ await waitUntil(() => evaluate(`Boolean(document.querySelector('[data-feed-thread="${group.threadId}"]'))`), 10_000, "the thread's row in the feed");+ if (!(await evaluate(`Boolean(document.querySelector('[data-thread-panel="${group.threadId}"]'))`))) {+ await evaluate(`document.querySelector('[data-feed-thread="${group.threadId}"] > button:first-child').click(); true`);+ }+ await waitUntil(() => evaluate(`Boolean(document.querySelector('[data-thread-panel="${group.threadId}"]'))`), 10_000, "the thread beside the feed");+ };+ await openThread();const busy = await waitUntil(async () => {const claimed = await groupState();@@ -257,6 +266,7 @@ describe("the thinking timer stays anchored across a thread switch", () => {await new Promise((done) => setTimeout(done, 3_000));await selectRow(groupRow);await waitUntil(() => isCurrentRow(groupRow), 10_000, "the group to become current again");+ await openThread();// A restart would show single digits after a 13+ second turn.const resumed = await waitUntil(timerText, 10_000, "the group's thinking readout to appear again");diff --git a/src/components/ForkPanel.tsx b/src/components/ForkPanel.tsxindex 766fd532cb..b6afe0ba0c 100644--- a/src/components/ForkPanel.tsx+++ b/src/components/ForkPanel.tsx@@ -8,6 +8,7 @@ import { ChatView } from "./ChatView";import { GroupView } from "./GroupView";import { ThreadPanelHeading } from "./room-feed/ThreadPanelHeading";import { useRoomFeedHere } from "./room-feed/use-room-feed";+import { useThreadTurnStart } from "./room-feed/thread-turn-start";import { PANEL_MIN_WIDTH, useComputerPanelResize } from "./computer-panel-resize";const BESIDE_INBOX_MAX = 400;@@ -29,6 +30,8 @@ export function ForkPanel() {focusedLoad.current = panel.loadId;(aside.querySelector<HTMLTextAreaElement>('[data-tour="composer"] textarea:not([disabled])') ?? aside).focus();}, [panel?.focusComposer, panel?.loadId, panel?.loading]);+ const panelGroup = panel?.kind === "group" ? state.groups.find((candidate) => candidate.id === panel.ownerId) : undefined;+ const turnStartedAt = useThreadTurnStart(panelGroup, panelGroup?.tasks?.find((candidate) => candidate.threadId === panel?.threadId));if (!panel) return null;const bot = panel.kind === "bot" ? state.bots.find((candidate) => candidate.id === panel.ownerId) : undefined;const group = panel.kind === "group" ? state.groups.find((candidate) => candidate.id === panel.ownerId) : undefined;@@ -38,7 +41,7 @@ export function ForkPanel() {const openedBot = bot && botTask ? { ...currentTaskBot(bot, panel.threadId), messages: panel.messages, activeLeafId: panel.activeLeafId, hasMore: false } : null;const openedGroup = group && groupTask ? { ...group, threadId: panel.threadId, messages: panel.messages, hasMore: false,working: groupTask.working ?? false, busyBotId: groupTask.busyBotId ?? null,- turnStartedAt: null, pinnedCwd: groupTask.pinnedCwd, pinnedMessageId: groupTask.pinnedMessageId } : null;+ turnStartedAt, pinnedCwd: groupTask.pinnedCwd, pinnedMessageId: groupTask.pinnedMessageId } : null;const fork = !beside || Boolean(task?.origin);const label = fork ? t("chat.forkPanel") : t("room.thread.panel");const close = () => dispatch({ type: "closeForkPanel" });diff --git a/src/components/room-feed/thread-turn-start.test.ts b/src/components/room-feed/thread-turn-start.test.tsnew file mode 100644index 0000000000..b8e5ce74a6--- /dev/null+++ b/src/components/room-feed/thread-turn-start.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from "vitest";+import { threadTurnStart } from "./thread-turn-start";++const room = { threadId: "current", busyBotId: "kiwi", turnStartedAt: 1_000 };++describe("a room thread's Thinking readout beside the feed", () => {+ it("counts the room's current thread from the server's stamp", () => {+ expect(threadTurnStart(room, { threadId: "current", working: true, busyBotId: "kiwi" }, new Map(), 9_000)).toBe(1_000);+ });++ it("counts another thread from when this window first saw it working, and starts again after it settles", () => {+ const seen = new Map<string, number>();+ const other = { threadId: "other", working: true, busyBotId: "pip" };+ expect(threadTurnStart(room, other, seen, 5_000)).toBe(5_000);+ expect(threadTurnStart(room, other, seen, 7_000)).toBe(5_000);+ expect(threadTurnStart(room, { threadId: "other", working: false, busyBotId: null }, seen, 8_000)).toBeNull();+ expect(threadTurnStart(room, other, seen, 9_000)).toBe(9_000);+ });++ it("does not take the room's stamp for its current thread when another member speaks there", () => {+ expect(threadTurnStart(room, { threadId: "current", working: true, busyBotId: "pip" }, new Map(), 4_000)).toBe(4_000);+ });+});diff --git a/src/components/room-feed/thread-turn-start.ts b/src/components/room-feed/thread-turn-start.tsnew file mode 100644index 0000000000..b81e91049d--- /dev/null+++ b/src/components/room-feed/thread-turn-start.ts@@ -0,0 +1,25 @@+import { useRef } from "react";+import type { Group, GroupTask } from "@/state/store";++type Room = Pick<Group, "threadId" | "busyBotId" | "turnStartedAt">;+type Thread = Pick<GroupTask, "threadId" | "working" | "busyBotId">;++/** When the turn running in a room's thread beside its feed started, for its Thinking readout: the room's own stamp+ * for its current thread (the server keeps one per room, for that thread's speaker), otherwise when this window first+ * saw the thread working. Null while nothing runs there. `seen` keeps those first sightings between renders. */+export function threadTurnStart(room: Room, thread: Thread, seen: Map<string, number>, now = Date.now()): number | null {+ const speaker = thread.busyBotId ?? null;+ const key = `${thread.threadId}:${speaker ?? ""}`;+ if (!thread.working && !speaker) {+ for (const old of seen.keys()) if (old.startsWith(`${thread.threadId}:`)) seen.delete(old);+ return null;+ }+ if (thread.threadId === room.threadId && typeof room.turnStartedAt === "number" && (!speaker || room.busyBotId === speaker)) return room.turnStartedAt;+ if (!seen.has(key)) seen.set(key, now);+ return seen.get(key)!;+}++export function useThreadTurnStart(room: Room | undefined, thread: Thread | undefined): number | null {+ const seen = useRef(new Map<string, number>()).current;+ return room && thread ? threadTurnStart(room, thread, seen) : null;+}