Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Rooms: a page is the same clean card, and opens over the room from anywhere on it
luishron123488232a44a83
diff --git a/scripts/testing/room-pages-ui.e2e.test.ts b/scripts/testing/room-pages-ui.e2e.test.tsindex 5dc1d1e8cd..f7e5682844 100644--- a/scripts/testing/room-pages-ui.e2e.test.ts+++ b/scripts/testing/room-pages-ui.e2e.test.ts@@ -28,7 +28,7 @@ const evidenceDir = process.env.OMB_UI_EVIDENCE_DIR ? resolve(ROOT, process.env.afterAll(async () => { if (!process.env.OMB_UI_EVIDENCE_DIR) await removeTempDir(evidenceDir); });/** The send button sits at a fixed place in the page, so a real mouse can find it inside the frame. What send() did- * shows in the page and in its height, which the host's frame follows: 300px when it resolved, 240px when refused. */+ * shows in the page. */const PAGE = `<!DOCTYPE html><html><head><meta charset="utf-8"><style>body{margin:0;font:15px/1.4 var(--font-sans);color:var(--color-text-primary)}#mode{position:absolute;left:16px;top:12px;margin:0}@@ -153,11 +153,10 @@ 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: Point (its pick goes to the page's bot), no Share.+ // 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.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);- expect(await evaluate(`[...document.querySelectorAll('[data-app="${pageId}"] button')].map((b) => b.textContent.trim()).filter((t) => t === "Point" || t === "Share")`)).toEqual(["Point"]);- expect(await evaluate(`Boolean([...document.querySelectorAll('[data-app="${pageId}"] button')].find((b) => b.getAttribute("aria-label") === "Full screen"))`)).toBe(true);+ expect(await evaluate(`Boolean(document.querySelector('[data-app="${pageId}"] [data-page-tools]'))`)).toBe(false);mkdirSync(evidenceDir, { recursive: true });// Every request the renderer makes goes through fetch: from here on each one is kept.@@ -179,14 +178,21 @@ async function until<T>(probe: () => Promise<T> | T, what: string, timeoutMs = 3};const sentBefore = (await transcript()).filter((message) => message.role === "user").length;- const page = await inView(pageId);- await ui("screenshot", "--out", join(evidenceDir, "room-pages-shown.png"));- await click(page, 146, 70);- // 300px: send() resolved in the page without asking the host; a refusal would leave it at 240px.- await until(async () => (await frameBox(pageId)).height === 300, "the page to show what its send did");- expect(await shows("Clicked: send() resolved and posted nothing")).toBe(true);await inView(pageId);+ await ui("screenshot", "--out", join(evidenceDir, "room-pages-shown.png"));+ // The card opens the page over the room, with Point (its pick goes to the page's bot) and no Share.+ const opened = `[data-page-fullscreen="${pageId}"]`;+ await evaluate(`document.querySelector('[data-app="${pageId}"] [data-page-open]').click(); true`);+ await until(() => evaluate(`Boolean(document.querySelector('${opened} iframe'))`), "the page to open over the room");+ expect(await evaluate(`[...document.querySelectorAll('${opened} button')].map((b) => b.textContent.trim()).filter((t) => t === "Point" || t === "Share")`)).toEqual(["Point"]);+ await until(async () => {+ const box = await evaluate(`(() => { const r = document.querySelector('${opened} iframe').getBoundingClientRect(); return { left: r.left, top: r.top }; })()`);+ await click(box, 146, 70);+ return shows("Clicked: send() resolved and posted nothing");+ }, "the page to show what its send did");await ui("screenshot", "--out", join(evidenceDir, "room-pages-clicked-send.png"));+ await evaluate(`document.querySelector('${opened} button[aria-label="Close full screen"]').click(); true`);+ await until(async () => !(await evaluate(`Boolean(document.querySelector('${opened}'))`)), "the page to close");await inView(boardRow.id);await ui("click", "--name", "Paint it red");diff --git a/src/components/app/AppMessage.compact.test.ts b/src/components/app/AppMessage.compact.test.tsindex 57e2cd7414..3eaf1d71c1 100644--- a/src/components/app/AppMessage.compact.test.ts+++ b/src/components/app/AppMessage.compact.test.ts@@ -1,5 +1,5 @@// @vitest-environment happy-dom-// A bot's page in its own chat: a compact card that opens the chat's page pane from anywhere on it.+// A bot's page: a compact card that opens from anywhere on it, in the chat's page pane or, in a room, over the window.import { act, createElement } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -24,11 +24,11 @@ let pane: HTMLDivElement;let root: Root;const settle = () => act(async () => { for (let i = 0; i < 8; i += 1) await new Promise((resolve) => setTimeout(resolve, 0)); });-const render = async (message: Message) => {+const render = async (message: Message, room = false) => {await act(async () => {root.render(createElement(BotEditorStore, { value: store, children:- createElement(PagePaneContext, { value: pane },- createElement(AppMessage, { botId: "pepper", botName: "Pepper", threadId: "t1", message, pool: createAppPool({ limit: 3 }) })) }));+ createElement(PagePaneContext, { value: room ? null : pane },+ createElement(AppMessage, { botId: "pepper", botName: "Pepper", threadId: "t1", message, room, pool: createAppPool({ limit: 3 }) })) }));});await settle();};@@ -87,4 +87,19 @@ describe("a bot's page as a compact card", () => {expect(card().querySelector("[data-app-info]")).not.toBeNull();expect(pane.querySelector("[data-page-pane]")).toBeNull();});++ it("is the same card in a room, where it opens over the window", async () => {+ await render(row(payload()), true);+ expect(card().querySelector<HTMLElement>("[data-app-box]")!.style.height).toBe(`${PAGE_PREVIEW_HEIGHT}px`);+ expect(card().querySelector("[data-page-footer]")!.textContent).toBe("PricingPage");+ expect(card().querySelector("[data-app-header]")).toBeNull();+ expect(card().querySelector("[data-page-tools]")).toBeNull();+ await press(opener());+ const opened = document.body.querySelector<HTMLElement>("[role=dialog][data-page-fullscreen=a1]")!;+ expect(opened.querySelector("[data-page-tools]")).not.toBeNull();+ expect(pane.querySelector("[data-page-pane]")).toBeNull();+ await act(async () => { window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })); });+ expect(document.body.querySelector("[data-page-fullscreen]")).toBeNull();+ expect(opener().getAttribute("aria-pressed")).toBe("false");+ });});diff --git a/src/components/app/AppMessage.test.ts b/src/components/app/AppMessage.test.tsindex dbda3612f2..93b9c0281f 100644--- a/src/components/app/AppMessage.test.ts+++ b/src/components/app/AppMessage.test.ts@@ -212,15 +212,13 @@ describe("a bot's page", () => {expect(frame().style.height).toBe("333px");});- it("in a room, shows the page to everyone with Full screen and Point but no Share, and the page sends nothing for anyone", async () => {+ it("in a room, shows the page to everyone as a card that opens with Point but no Share, and the page sends nothing for anyone", async () => {fetchMock.mockImplementation(async (path) => /\/app(\?|$)/.test(path) ? json(200, botHtmlDocument({ messageId: "a1", rev: 0, html: counter.html, room: true })) : json(202, { ok: true }));await mount(row(htmlPayload()), true);expect(find("[data-app]")!.hasAttribute("data-app-room")).toBe(true);expect(frame().getAttribute("sandbox")).toBe("allow-scripts allow-forms");expect(frame().getAttribute("srcdoc")).toContain("var room = true;");- expect(button("Point")).toBeTruthy();- expect(button("Share")).toBeUndefined();- expect(button("Full screen")).toBeTruthy();+ expect(find("[data-page-tools]")).toBeNull();await handshake();await engage();await fromView({ jsonrpc: "2.0", id: "m1", method: "ui/message", params: { role: "user", content: [{ type: "text", text: "I have had 3 cups." }] } });@@ -230,6 +228,11 @@ describe("a bot's page", () => {expect(toView.find((message) => message.id === "c1")).toEqual({ jsonrpc: "2.0", id: "c1", error: { code: -32000, message: ROOM_VIEW_ONLY } });expect(posts("/messages")).toEqual([]);expect(posts("/context")).toEqual([]);+ await act(async () => { button("Open page")!.click(); });+ const opened = Array.from(document.body.querySelectorAll<HTMLButtonElement>("[role=dialog][data-page-fullscreen] button"), (element) => element.textContent?.trim() || element.getAttribute("aria-label"));+ expect(opened).toContain("Point");+ expect(opened).toContain("Close full screen");+ expect(opened).not.toContain("Share");});it("opens a link the person clicked through the desktop's browser", async () => {diff --git a/src/components/app/AppMessage.tsx b/src/components/app/AppMessage.tsxindex b0c0f6c35b..7e4665557b 100644--- a/src/components/app/AppMessage.tsx+++ b/src/components/app/AppMessage.tsx@@ -104,9 +104,10 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {const frame = useRef<AppFrameHandle | null>(null);const wide = useRef<AppFrameHandle | null>(null);const [fullScreen, setFullScreen] = useState(false);- // In a bot chat a page is a compact card that opens in the chat's page pane; elsewhere it stays a full card.+ // A page is a compact card where it has somewhere to open: the chat's page pane, or over the window in a room.const paneSlot = useContext(PagePaneContext);const pane = page && !room ? paneSlot : null;+ const compact = Boolean(pane) || (page && Boolean(room));const paneOpen = Boolean(pane && fullScreen);const row = useRef<HTMLDivElement | null>(null);const mounted = useRef(true);@@ -223,17 +224,17 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {const infoId = `${uid}-info`;// The compact card clips the page at its natural size, so it reads as a preview of the real thing.- const boxHeight = pane ? Math.min(height, PAGE_PREVIEW_HEIGHT) : height;+ const boxHeight = compact ? Math.min(height, PAGE_PREVIEW_HEIGHT) : height;const body = collapsed ? null : fullScreen && current ? (- <div data-app-box className={cn("relative w-full", bordered && !pane && "border-t border-ink/[0.08]")} style={{ height: boxHeight }}>- {pane+ <div data-app-box className={cn("relative w-full", bordered && !compact && "border-t border-ink/[0.08]")} style={{ height: boxHeight }}>+ {compact? <AppPlaceholder height={boxHeight}><span className="ui-pill">{t("chat.preview.closePage")}</span></AppPlaceholder>: <AppPlaceholder height={boxHeight} open={() => setFullScreen(false)} label={t("chat.preview.exitFullScreen")} />}</div>) : noPage ? (- message.text ? <div dir="auto" className={cn("line-clamp-6 whitespace-pre-wrap text-[13px] leading-[18px] text-ink-secondary", pane ? "px-4 pt-3" : bordered ? "px-4 pb-3" : "pb-2")}>{message.text}</div> : null+ message.text ? <div dir="auto" className={cn("line-clamp-6 whitespace-pre-wrap text-[13px] leading-[18px] text-ink-secondary", compact ? "px-4 pt-3" : bordered ? "px-4 pb-3" : "pb-2")}>{message.text}</div> : null) : (- <div data-app-box className={cn("relative w-full", pane && "overflow-hidden", bordered && !pane && "border-t border-ink/[0.08]", point.pointing && "ring-2 ring-inset ring-accent/60")}+ <div data-app-box className={cn("relative w-full", compact && "overflow-hidden", bordered && !compact && "border-t border-ink/[0.08]", point.pointing && "ring-2 ring-inset ring-accent/60")}style={{ height: boxHeight }}>{current ? (<AppFrame@@ -255,9 +256,9 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {)}</div>);- const info = infoOpen && <AppInfo id={infoId} network={payload.network ?? { connect: [], resources: [] }} bytes={payload.bytes ?? 0} bordered={bordered || Boolean(pane)} />;+ const info = infoOpen && <AppInfo id={infoId} network={payload.network ?? { connect: [], resources: [] }} bytes={payload.bytes ?? 0} bordered={bordered || compact} />;const reopen = collapsed && (- <div className={cn("flex", bordered || pane ? "px-4 pb-3.5" : "pb-2", pane && "pt-3.5")}>+ <div className={cn("flex", bordered || compact ? "px-4 pb-3.5" : "pb-2", compact && "pt-3.5")}><AppOpenButton label={t("app.openAgain")} onClick={reloadNow} /></div>);@@ -275,7 +276,7 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {{...(room ? { "data-app-room": "" } : {})}className={cn("w-full text-start", WIDTH)}>- {pane ? (+ {compact ? (<div className={APP_SURFACE}><div className="group/page relative">{reopen}@@ -291,8 +292,8 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {reloading={fetching && Boolean(current)}/>{current && !point.pointing && (- <button type="button" data-page-open onClick={tools.fullScreen.toggle} aria-pressed={paneOpen}- aria-label={t(paneOpen ? "chat.preview.closePage" : "chat.preview.openPage")}+ <button type="button" data-page-open onClick={tools.fullScreen.toggle} aria-pressed={fullScreen}+ aria-label={t(fullScreen ? "chat.preview.closePage" : "chat.preview.openPage")}className="absolute inset-0 cursor-pointer rounded-2xl transition-colors duration-[120ms] hover:bg-ink/[0.04] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus motion-reduce:transition-none" />)}</div>