Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(computer): watch full screen shows only its own Take control errors and leaves Escape to dialogs over it
AdityaUmale14dcf90cbf49
diff --git a/src/components/ComputerPanel.takeover.test.ts b/src/components/ComputerPanel.takeover.test.tsindex 0f86044298..ef5d41ee1f 100644--- a/src/components/ComputerPanel.takeover.test.ts+++ b/src/components/ComputerPanel.takeover.test.ts@@ -179,6 +179,11 @@ afterEach(() => {vi.restoreAllMocks();});+/** Escape where a person presses it: on whatever has focus. */+function pressEscape() {+ (document.activeElement ?? document.body).dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));+}+describe("taking control of a Local VM", () => {it("turns the panel's own picture into the live desktop at once; no window or tab opens", async () => {await open(makeBot({ computer: "vm" }));@@ -210,7 +215,7 @@ describe("taking control of a Local VM", () => {expect(fixture.controls, "watching must not pause the bot").toEqual([]);expect(liveDesktop()).toBeNull();- window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));+ pressEscape();await settle();expect(watch(), "Escape leaves full screen").toBeNull();expect(fixture.controls).toEqual([]);@@ -225,6 +230,24 @@ describe("taking control of a Local VM", () => {expect(watch()).toBeNull();});+ it("full screen shows only errors from a Take control tried there, and leaves Escape to a dialog opened over it", async () => {+ fixture.refuse = true;+ await open(makeBot({ computer: "vm" }));+ await press("Take control");+ expect(fixture.controls.map((control) => control.action)).toEqual(["take"]);+ await press("Full screen");+ const watch = () => document.querySelector<HTMLElement>("[data-watch-full-screen]");+ expect(watch()!.querySelector("[role=alert]"), "an earlier panel error is not news in full screen").toBeNull();++ const over = document.createElement("button");+ document.body.append(over);+ over.focus();+ over.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));+ await settle();+ expect(watch(), "Escape in a dialog over full screen belongs to that dialog").not.toBeNull();+ over.remove();+ });+it("a refused Take control in full screen keeps watching and says why", async () => {fixture.refuse = true;await open(makeBot({ computer: "vm" }));@@ -248,7 +271,7 @@ describe("taking control of a Local VM", () => {expect(document.activeElement).toBe(exit);exit!.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", shiftKey: true, bubbles: true, cancelable: true }));expect(document.activeElement, "Shift+Tab from Exit must stay in full screen").toBe(take);- window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));+ pressEscape();await settle();expect(document.querySelector("[data-watch-full-screen]")).toBeNull();expect(document.activeElement).toBe(trigger);diff --git a/src/components/FullScreenButton.tsx b/src/components/FullScreenButton.tsxindex 9db4342390..2cfd96c88d 100644--- a/src/components/FullScreenButton.tsx+++ b/src/components/FullScreenButton.tsx@@ -65,14 +65,18 @@ function WatchFullScreen({ frame, name, takeDisabled, error, onClose, onTakeContconst exitRef = useRef<HTMLButtonElement>(null);const { dragProps, noDragStyle } = useCaptionChrome();const macInset = useDesktopCapabilities().capabilities.windowChrome === "mac-inset";+ // An error from before this view opened belongs to the panel; only a Take control tried here shows its outcome.+ const [tried, setTried] = useState(false);useModalDialog(dialogRef, onClose);// After the dialog has noted Full screen as the place to return to, so autoFocus can't take that place.useEffect(() => exitRef.current?.focus(), []);useEffect(() => {- // Capture, and claim the key, so the same press cannot also close something beneath the overlay.+ // Capture, and claim the key, so the same press cannot also close something beneath the overlay. A press from+ // a dialog opened over this view (such as keyboard shortcuts) is that dialog's own.const onKey = (event: KeyboardEvent) => {if (event.key !== "Escape" || event.defaultPrevented) return;+ if (!(event.target instanceof Node) || !dialogRef.current?.contains(event.target)) return;event.preventDefault();onClose();};@@ -96,7 +100,7 @@ function WatchFullScreen({ frame, name, takeDisabled, error, onClose, onTakeCont<buttontype="button"style={noDragStyle}- onClick={onTakeControl}+ onClick={() => { setTried(true); onTakeControl(); }}disabled={takeDisabled}className={cn(iconButton, "bg-accent font-medium text-accent-ink hover:brightness-110")}title={t("computer.takeControlTitle")}@@ -105,7 +109,7 @@ function WatchFullScreen({ frame, name, takeDisabled, error, onClose, onTakeCont{t("computer.takeControl")}</button></header>- {error && (+ {tried && error && (<div role="alert" className="shrink-0 border-b border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger">{error}</div>)}<div className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-inset">