Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Show a Watch button while a bot uses its screen (#4731) (#4801)

Aditya Umalec753bd7c88ea
diff --git a/src/components/ChatView.controls.test.ts b/src/components/ChatView.controls.test.ts
index cf5f14c269..e65d5c4a9b 100644
--- a/src/components/ChatView.controls.test.ts
+++ b/src/components/ChatView.controls.test.ts
@@ -276,6 +276,22 @@ describe("header name", () => {
expect(button(pinned)).toContain('data-testid="computer-button-live"');
});
+ it("offers a Watch button only while a running tool uses the bot's screen", () => {
+ const working = (tool: string, busy = true, computer: Bot["computer"] | "auto" = "cloud", ok?: boolean) => renderToStaticMarkup(createElement(ChatView, {
+ bot: { ...bot, computer: computer === "auto" ? undefined : computer, busy, turnStartedAt: 1, tasks: (bot.tasks ?? []).map((task) => ({ ...task, busy, turnStartedAt: 1 })), messages: [
+ { id: "ask", role: "user", kind: "text", at: 1, text: "Check the site" },
+ { id: "tool", role: "bot", kind: "activity", at: 2, tool: { name: tool, ok } },
+ ] } as Bot,
+ }));
+ const watch = (markup: string) => markup.match(/<button[^>]*data-testid="watch-screen"[^>]*>[\s\S]*?<\/button>/)?.[0] ?? "";
+ expect(watch(working("mcp__computer__click"))).toContain(">Watch<");
+ expect(watch(working("mcp__browser__browser_snapshot", true, "auto"))).toContain(">Watch<");
+ expect(watch(working("mcp__computer__click", false))).toBe("");
+ expect(watch(working("Bash"))).toBe("");
+ expect(watch(working("screenshot", true, "auto"))).toBe("");
+ expect(watch(working("mcp__browser__browser_snapshot", true, "cloud", true))).toBe("");
+ });
+
it("centres the bot in the header's middle column, with the controls in the last", () => {
const markup = renderToStaticMarkup(createElement(ChatView, { bot }));
const row = markup.match(/data-chathead-row="true" class="([^"]*)"/)?.[1] ?? "";
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 60bc869e25..b011980f16 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -73,7 +73,7 @@ import { useColorUserBubbles } from "@/lib/user-bubble-preference";
import { userBubbleStyle } from "@/lib/user-bubble-tone";
import { ToolActivity } from "./ToolActivity";
import { DataResultChip } from "./DataResultChip"; import { PublishedPageCard } from "./PublishedPageCard";
-import { ThreadRefText } from "./ThreadRefs";
+import { ThreadRefText } from "./ThreadRefs"; import { WatchScreenButton } from "./WatchScreenButton";
import { optionsCardRow } from "./OptionsCardRow";
import { MessageBoundary } from "./MessageBoundary";
import { RichMessageRow, UserLineNote, richRowKind } from "./RichMessageRow"; import { SetupOffer } from "./SetupOffer"; import { SavedStepsChip } from "./SavedStepsChip";
@@ -1114,7 +1114,7 @@ export function ChatView({ bot: profile }: { bot: Bot }) {
{phone && <UsageAlert engine={bot.modelSelection?.instanceId} />}
{/* The model and the bot's computer stay in view in both modes; Simple mode moves only ⋯ into the bot panel. */}
{!phone && <ModelPicker key={bot.threadId} bot={bot} threadId={bot.threadId} />}
- <LiveCallChip currentBotId={bot.id} onOpen={(botId, threadId) => openThread(dispatch, { botId, threadId }, state, showThreads)} />
+ <LiveCallChip currentBotId={bot.id} onOpen={(botId, threadId) => openThread(dispatch, { botId, threadId }, state, showThreads)} />{!phoneMenu && <WatchScreenButton botId={bot.id} messages={messages} liveTools={liveTools} place={place} />}
{!phoneMenu && <button
data-tour="computer"
onClick={(event) => { if (!state.computerOpen) rememberComputerPanelOpen({ botId: bot.id, opener: event.currentTarget, tabs: event.detail === 0 }); dispatch({ type: "toggleComputer" }); }}
diff --git a/src/components/WatchScreenButton.tsx b/src/components/WatchScreenButton.tsx
new file mode 100644
index 0000000000..dbbde67362
--- /dev/null
+++ b/src/components/WatchScreenButton.tsx
@@ -0,0 +1,28 @@
+import { Monitor } from "lucide-react";
+import { useStore, type Message } from "@/state/store";
+import { rememberComputerPanelOpen } from "@/lib/computer-panel-focus";
+import { writeComputerPanelView } from "@/lib/computer-panel-view";
+import { liveScreenPlace, type EffectivePlace } from "@/lib/place";
+import { COMPACT_BUBBLE } from "@/lib/compact-chip";
+import { cn } from "@/lib/cn";
+import { t } from "@/lib/i18n";
+
+/** A "Watch" pill in the chat header while a running tool call is using the bot's screen and the Screen panel is
+ * closed, so the person can see what the bot is doing without hunting for the monitor button. It opens the panel on
+ * the tab that shows that tool (Browser or Screen), not the tab last viewed. */
+export function WatchScreenButton({ botId, messages, liveTools, place }: { botId: string; messages: readonly Message[]; liveTools: ReadonlySet<string>; place: EffectivePlace }) {
+ const { state, dispatch } = useStore();
+ const screen = state.computerOpen ? null : liveScreenPlace(messages, liveTools, place);
+ if (!screen) return null;
+ return (
+ <button
+ data-testid="watch-screen"
+ onClick={(event) => { writeComputerPanelView(botId, screen === "browser" ? "browser" : "computer"); rememberComputerPanelOpen({ botId, opener: event.currentTarget, tabs: event.detail === 0, browser: screen === "browser" }); dispatch({ type: "toggleComputer", open: true }); }}
+ className={cn("flex items-center gap-1.5 rounded-full border border-hairline/40 bg-raised/60 px-2.5 py-1 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink", COMPACT_BUBBLE)}
+ title={t("chat.watchScreenHint")}
+ >
+ <Monitor size={13} aria-hidden="true" />
+ <span>{t("chat.watchScreen")}</span>
+ </button>
+ );
+}
diff --git a/src/components/remote-desktop-panel.focus.test.ts b/src/components/remote-desktop-panel.focus.test.ts
index 3eef9ab4ef..51a9469678 100644
--- a/src/components/remote-desktop-panel.focus.test.ts
+++ b/src/components/remote-desktop-panel.focus.test.ts
@@ -114,4 +114,15 @@ describe("remote desktop panel entry focus", () => {
flushSync(() => close.click());
expect(document.activeElement).toBe(opener);
});
+
+ it("opens on the Browser view only when Watch asked for it during a browser call", async () => {
+ const pressed = () => document.querySelector<HTMLElement>('[aria-pressed="true"]')?.textContent;
+ rememberComputerPanelOpen({ botId: "scout", opener: null, tabs: false, browser: true });
+ await open(makeBot());
+ expect(pressed()).toBe("Browser");
+ root!.unmount();
+ rememberComputerPanelOpen({ botId: "scout", opener: null, tabs: false });
+ await open(makeBot());
+ expect(pressed()).toBe("Desktop");
+ });
});
diff --git a/src/components/remote-desktop-panel.tsx b/src/components/remote-desktop-panel.tsx
index 7cbcd0b312..fa84e9a229 100644
--- a/src/components/remote-desktop-panel.tsx
+++ b/src/components/remote-desktop-panel.tsx
@@ -10,7 +10,7 @@ import type { Routine } from "@/lib/routines";
import { dayName, scheduleLabel } from "@/lib/schedule-label";
import { intlLocale, t } from "@/lib/i18n";
import { api, ApiError, useStore, type Bot } from "@/state/store";
-import { releaseComputerPanelFocus, useComputerPanelEntry } from "@/lib/computer-panel-focus";
+import { releaseComputerPanelFocus, takeComputerPanelBrowserView, useComputerPanelEntry } from "@/lib/computer-panel-focus";
import { RoutineEditor } from "./RoutinesPage";
import { BrowserPanel, type BrowserSignIn } from "./BrowserPanel";
import { SignInBanner } from "./SignInRequestCard";
@@ -76,7 +76,7 @@ export function RemoteDesktopPanel({ bot }: { bot: Bot }) {
const previewBusy = useRef(bot.busy);
useEffect(() => { previewBusy.current = bot.busy; }, [bot.busy]);
const [creatingRoutine, setCreatingRoutine] = useState(false);
- const [view, setView] = useState<"desktop" | "browser">("desktop");
+ const [view, setView] = useState<"desktop" | "browser">(() => takeComputerPanelBrowserView(bot.id) ? "browser" : "desktop");
const [signIn, setSignIn] = useState<BrowserSignIn>();
const help = state.computerControl[bot.id]?.help ?? null;
const asker = help ? state.bots.find((candidate) => candidate.id === help.botId)?.name ?? bot.name : bot.name;
diff --git a/src/lib/computer-panel-focus.ts b/src/lib/computer-panel-focus.ts
index 5a3a83c5c2..3e8871790d 100644
--- a/src/lib/computer-panel-focus.ts
+++ b/src/lib/computer-panel-focus.ts
@@ -9,14 +9,25 @@ export type ComputerPanelOpen = {
opener: HTMLElement | null;
/** The activation came from the keyboard, so the panel takes focus. */
tabs: boolean;
+ /** Open on the Browser view (the chat's Watch button during a browser call). */
+ browser?: boolean;
};
let pendingTabFocus: string | null = null;
+let pendingBrowserView: string | null = null;
let opener: { botId: string; element: HTMLElement | null } | null = null;
export function rememberComputerPanelOpen(open: ComputerPanelOpen): void {
opener = { botId: open.botId, element: open.opener };
pendingTabFocus = open.tabs ? open.botId : null;
+ pendingBrowserView = open.browser ? open.botId : null;
+}
+
+/** One shot per open, like the tab focus: whether this open asked for the Browser view. */
+export function takeComputerPanelBrowserView(botId: string): boolean {
+ if (pendingBrowserView !== botId) return false;
+ pendingBrowserView = null;
+ return true;
}
/** One shot per open: a panel that remounts for the same bot (a bot switch, or
diff --git a/src/lib/place.test.ts b/src/lib/place.test.ts
index 0708f00904..892d212989 100644
--- a/src/lib/place.test.ts
+++ b/src/lib/place.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { effectivePlace, isComputerPlace, PLACES, placeLabelKey, placeOffered, toolPlace } from "./place";
+import { effectivePlace, isComputerPlace, PLACES, placeLabelKey, placeOffered, liveScreenPlace, toolPlace } from "./place";
import { toolSurfaceKind } from "../../shared/tool-surface";
describe("where a conversation works", () => {
@@ -41,6 +41,24 @@ describe("where a conversation works", () => {
}
});
+ it("knows when a running tool call is using the bot's screen", () => {
+ const messages = [
+ { id: "old-click", tool: { name: "mcp__computer__click" } },
+ { id: "text" },
+ { id: "bash", tool: { name: "Bash" } },
+ { id: "snap", tool: { name: "mcp__browser__browser_snapshot" } },
+ { id: "shot", tool: { name: "screenshot" } },
+ { id: "done", tool: { name: "mcp__browser__browser_navigate", ok: true } },
+ ];
+ expect(liveScreenPlace(messages, new Set(), "cloud")).toBeNull();
+ expect(liveScreenPlace(messages, new Set(["bash"]), "cloud")).toBeNull();
+ expect(liveScreenPlace(messages, new Set(["bash", "snap"]), "auto")).toBe("browser");
+ expect(liveScreenPlace(messages, new Set(["shot"]), "cloud")).toBe("cloud");
+ expect(liveScreenPlace(messages, new Set(["shot"]), "auto")).toBeNull();
+ expect(liveScreenPlace(messages, new Set(["text"]), "cloud")).toBeNull();
+ expect(liveScreenPlace(messages, new Set(["done", "bash"]), "cloud")).toBeNull();
+ });
+
it("classifies tool names without guessing computer for unrelated tools", () => {
expect(toolSurfaceKind("agent_browser_open")).toBe("browser");
expect(toolSurfaceKind("browser__snapshot")).toBe("browser");
diff --git a/src/lib/place.ts b/src/lib/place.ts
index 2e3a5d1fb8..3413882f4b 100644
--- a/src/lib/place.ts
+++ b/src/lib/place.ts
@@ -35,3 +35,18 @@ export function toolPlace(toolName: string, effective: EffectivePlace): Place |
if (kind === "computer") return isComputerPlace(effective) ? effective : null;
return null;
}
+
+/** Where a running tool call is using the bot's screen right now (its browser or its computer), so the chat can offer
+ * to watch it; null when none is. Only the live calls matter, and they sit at the end of the transcript. A call that
+ * already finished (ok set) does not count, even while the turn goes on. */
+export function liveScreenPlace(messages: readonly { id: string; tool?: { name: string; ok?: boolean } | null }[], liveTools: ReadonlySet<string>, effective: EffectivePlace): Place | null {
+ let left = liveTools.size;
+ for (let index = messages.length - 1; index >= 0 && left > 0; index--) {
+ const message = messages[index];
+ if (!liveTools.has(message.id)) continue;
+ left--;
+ const place = message.tool && message.tool.ok === undefined ? toolPlace(message.tool.name, effective) : null;
+ if (place) return place;
+ }
+ return null;
+}
diff --git a/src/locales/de.json b/src/locales/de.json
index 19a2513036..673bfb1519 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -1001,6 +1001,8 @@
"chat.stop": "Stopp",
"chat.stopTurn": "Diesen Zug stoppen",
"chat.computer": "Bildschirm des Bots",
+ "chat.watchScreen": "Zusehen",
+ "chat.watchScreenHint": "Zusehen, was der Bot auf seinem Bildschirm macht",
"chat.inspector": "Inspektor",
"chat.inspectorHint": "Inspektor — Laufzeitereignisse und Rohprotokoll dieses Verlaufs",
"chat.conversationWith": "Unterhaltung mit {name}",
diff --git a/src/locales/en.json b/src/locales/en.json
index 8fc6f643a9..6e572bc3d3 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2589,6 +2589,8 @@
"chat.stop": "Stop",
"chat.stopTurn": "Stop this turn",
"chat.computer": "Bot's screen",
+ "chat.watchScreen": "Watch",
+ "chat.watchScreenHint": "Watch what the bot is doing on its screen",
"chat.advancedOnly": "In Advanced mode",
"chat.inspector": "Inspector",
"chat.inspectorHint": "Inspector: runtime events and raw protocol for this thread",
diff --git a/src/locales/es.json b/src/locales/es.json
index b1654a1e63..8bbf7c4b2e 100644
--- a/src/locales/es.json
+++ b/src/locales/es.json
@@ -2016,6 +2016,8 @@
"chat.stop": "Detener",
"chat.stopTurn": "Detener este turno",
"chat.computer": "Pantalla del bot",
+ "chat.watchScreen": "Ver",
+ "chat.watchScreenHint": "Ver lo que hace el bot en su pantalla",
"chat.advancedOnly": "En el modo avanzado",
"chat.inspector": "Inspector",
"chat.inspectorHint": "Inspector: eventos de ejecución y protocolo en bruto de esta conversación",
diff --git a/src/locales/fr.json b/src/locales/fr.json
index f4521d5a4e..ba23b397ee 100644
--- a/src/locales/fr.json
+++ b/src/locales/fr.json
@@ -871,6 +871,8 @@
"chat.stop": "Arrêter",
"chat.stopTurn": "Arrêter ce tour",
"chat.computer": "Écran du bot",
+ "chat.watchScreen": "Regarder",
+ "chat.watchScreenHint": "Regarder ce que fait le bot sur son écran",
"chat.inspector": "Inspecteur",
"chat.inspectorHint": "Inspecteur — événements d'exécution et protocole brut de ce fil",
"chat.conversationWith": "Conversation avec {name}",
diff --git a/src/locales/hi.json b/src/locales/hi.json
index 6967b826b7..f25a47363b 100644
--- a/src/locales/hi.json
+++ b/src/locales/hi.json
@@ -871,6 +871,8 @@
"chat.stop": "रोकें",
"chat.stopTurn": "यह बारी रोकें",
"chat.computer": "बॉट की स्क्रीन",
+ "chat.watchScreen": "देखें",
+ "chat.watchScreenHint": "देखें कि बॉट अपनी स्क्रीन पर क्या कर रहा है",
"chat.inspector": "इंस्पेक्टर",
"chat.inspectorHint": "इंस्पेक्टर — इस बातचीत के रनटाइम इवेंट और कच्चा प्रोटोकॉल",
"chat.conversationWith": "{name} के साथ बातचीत",
diff --git a/src/locales/it.json b/src/locales/it.json
index 97ecc09c10..60ed2f2a8d 100644
--- a/src/locales/it.json
+++ b/src/locales/it.json
@@ -2097,6 +2097,8 @@
"chat.stop": "Interrompi",
"chat.stopTurn": "Interrompi questo turno",
"chat.computer": "Schermo del bot",
+ "chat.watchScreen": "Guarda",
+ "chat.watchScreenHint": "Guarda cosa fa il bot sul suo schermo",
"chat.advancedOnly": "In modalità avanzata",
"chat.inspector": "Ispettore",
"chat.inspectorHint": "Ispettore — eventi di esecuzione e protocollo grezzo di questa discussione",
diff --git a/src/locales/ja.json b/src/locales/ja.json
index 5ffcb1e331..34edf97326 100644
--- a/src/locales/ja.json
+++ b/src/locales/ja.json
@@ -2412,6 +2412,8 @@
"chat.stop": "停止",
"chat.stopTurn": "このターンを停止",
"chat.computer": "ボットの画面",
+ "chat.watchScreen": "見る",
+ "chat.watchScreenHint": "ボットが画面で何をしているかを見る",
"chat.advancedOnly": "詳細モードで表示",
"chat.inspector": "インスペクター",
"chat.inspectorHint": "インスペクター — このスレッドの実行イベントと生のプロトコル",
diff --git a/src/locales/ko.json b/src/locales/ko.json
index 73a6c8d10d..b8d0f9f036 100644
--- a/src/locales/ko.json
+++ b/src/locales/ko.json
@@ -2297,6 +2297,8 @@
"chat.stop": "중지",
"chat.stopTurn": "이번 턴 중지",
"chat.computer": "봇의 화면",
+ "chat.watchScreen": "보기",
+ "chat.watchScreenHint": "봇이 화면에서 하는 일 보기",
"chat.advancedOnly": "고급 모드에서",
"chat.inspector": "인스펙터",
"chat.inspectorHint": "인스펙터 — 이 스레드의 런타임 이벤트와 원본 프로토콜",
diff --git a/src/locales/pl.json b/src/locales/pl.json
index a78ab75d1f..5ccde6cab0 100644
--- a/src/locales/pl.json
+++ b/src/locales/pl.json
@@ -2135,6 +2135,8 @@
"chat.stop": "Zatrzymaj",
"chat.stopTurn": "Zatrzymaj tę turę",
"chat.computer": "Ekran bota",
+ "chat.watchScreen": "Oglądaj",
+ "chat.watchScreenHint": "Zobacz, co bot robi na swoim ekranie",
"chat.advancedOnly": "W trybie zaawansowanym",
"chat.inspector": "Inspektor",
"chat.inspectorHint": "Inspektor — zdarzenia czasu działania i surowy protokół tego wątku",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index f3fde7a8e7..81dc0930b0 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2460,6 +2460,8 @@
"chat.stop": "Parar",
"chat.stopTurn": "Parar esta sessão",
"chat.computer": "Tela do bot",
+ "chat.watchScreen": "Assistir",
+ "chat.watchScreenHint": "Veja o que o bot está fazendo na tela",
"chat.advancedOnly": "No modo avançado",
"chat.inspector": "Inspetor",
"chat.inspectorHint": "Inspetor: eventos de execução e protocolo bruto desta conversa",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index f2e5a3ef57..e64af685c1 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -2175,6 +2175,8 @@
"chat.stop": "Стоп",
"chat.stopTurn": "Остановить этот ход",
"chat.computer": "Экран бота",
+ "chat.watchScreen": "Смотреть",
+ "chat.watchScreenHint": "Смотреть, что бот делает на своём экране",
"chat.advancedOnly": "В расширенном режиме",
"chat.inspector": "Инспектор",
"chat.inspectorHint": "Инспектор — события рантайма и необработанный протокол этого треда",
diff --git a/src/locales/tr.json b/src/locales/tr.json
index 3655a247a8..d9110c2b85 100644
--- a/src/locales/tr.json
+++ b/src/locales/tr.json
@@ -1721,6 +1721,8 @@
"chat.stop": "Durdur",
"chat.stopTurn": "Bu turu durdur",
"chat.computer": "Botun ekranı",
+ "chat.watchScreen": "İzle",
+ "chat.watchScreenHint": "Botun ekranında ne yaptığını izle",
"chat.advancedOnly": "Gelişmiş modda",
"chat.inspector": "Denetçi",
"chat.inspectorHint": "Denetçi — bu konu için çalışma zamanı olayları ve ham protokol",
diff --git a/src/locales/uk.json b/src/locales/uk.json
index a1ecd13874..85eddc5c0c 100644
--- a/src/locales/uk.json
+++ b/src/locales/uk.json
@@ -1014,6 +1014,8 @@
"chat.stop": "Стоп",
"chat.stopTurn": "Зупинити цей запит",
"chat.computer": "Екран бота",
+ "chat.watchScreen": "Дивитися",
+ "chat.watchScreenHint": "Дивитися, що бот робить на своєму екрані",
"chat.inspector": "Інспектор",
"chat.inspectorHint": "Інспектор — події рантайму і сирий протокол цієї гілки",
"chat.conversationWith": "Розмова з {name}",
diff --git a/src/locales/vi.json b/src/locales/vi.json
index e88c30bad9..fa045fbb24 100644
--- a/src/locales/vi.json
+++ b/src/locales/vi.json
@@ -1721,6 +1721,8 @@
"chat.stop": "Dừng",
"chat.stopTurn": "Dừng lượt này",
"chat.computer": "Màn hình của bot",
+ "chat.watchScreen": "Xem",
+ "chat.watchScreenHint": "Xem bot đang làm gì trên màn hình của nó",
"chat.advancedOnly": "Ở chế độ Nâng cao",
"chat.inspector": "Trình kiểm tra",
"chat.inspectorHint": "Trình kiểm tra — sự kiện runtime và giao thức thô cho luồng này",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index 8a689ad308..a776969bb4 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -2588,6 +2588,8 @@
"chat.stop": "停止",
"chat.stopTurn": "停止這個回合",
"chat.computer": "機器人的畫面",
+ "chat.watchScreen": "觀看",
+ "chat.watchScreenHint": "觀看機器人在畫面上做什麼",
"chat.advancedOnly": "在進階模式中",
"chat.inspector": "檢視器",
"chat.inspectorHint": "檢視器 — 這個對話的執行階段事件與原始協定",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 43739ba677..307283d10d 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -2436,6 +2436,8 @@
"chat.stop": "停止",
"chat.stopTurn": "停止本轮",
"chat.computer": "机器人的屏幕",
+ "chat.watchScreen": "观看",
+ "chat.watchScreenHint": "观看机器人在屏幕上做什么",
"chat.advancedOnly": "高级模式中",
"chat.inspector": "检查器",
"chat.inspectorHint": "检查器——本对话的运行时事件与原始协议",