Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(place): keep Auto checked when Auto picked the place (#4323)
Aditya Umalec0331e30eeb6
diff --git a/src/components/ComputerPanel.simple.test.ts b/src/components/ComputerPanel.simple.test.tsindex 83ec1bdaad..ce5a402a90 100644--- a/src/components/ComputerPanel.simple.test.ts+++ b/src/components/ComputerPanel.simple.test.ts@@ -545,6 +545,15 @@ describe("A chat pinned to a place", () => {expect(unpin(rendered)).toBeUndefined();}});++ it("does not call the place Auto picked a pin in Advanced either", () => {+ fixture.advanced = true;+ fresh();+ const rendered = render(pinnedOn(undefined, { surface: "browser", surfaceAuto: true }));+ expect(rendered.nodes.some((node) => node.props["data-testid"] === "place-pinned-note")).toBe(false);+ fresh();+ expect(note(render(pinnedOn(undefined, { surface: "browser" })))).toBe("This conversation is pinned to Browser. Change it from the composer.");+ });});describe("Technical controls", () => {diff --git a/src/components/ComputerPanel.tsx b/src/components/ComputerPanel.tsxindex a36cced16b..70d640c707 100644--- a/src/components/ComputerPanel.tsx+++ b/src/components/ComputerPanel.tsx@@ -9,7 +9,7 @@ import { CalendarClock, ChevronRight, Columns2, Box, Check, Cloud, Sparkles, Gloimport { api, ApiError, currentTaskBot, useStore, type Bot, type ConfigStatus } from "@/state/store";import { setAdvancedMode, useAdvancedMode } from "@/lib/interface-mode";import { ComputerFilesPane } from "./ComputerFilesPane";-import { effectivePlace, isComputerPlace, placeLabelKey, placeOffered } from "@/lib/place";+import { effectivePlace, isComputerPlace, personPin, placeLabelKey, placeOffered } from "@/lib/place";import type { CloudBackend } from "../../shared/wire";import { KeyRow } from "./keys/KeyRow"; import { openKeySettings } from "./keys/key-focus";import { cn } from "@/lib/cn";@@ -134,6 +134,7 @@ export function ComputerPanel({const { state, dispatch, flushBotPatches } = useStore();const liveTask = profileBot.tasks?.find((task) => task.threadId === profileBot.threadId);const livePlace = effectivePlace(profileBot, liveTask);+ const livePin = personPin(liveTask);const threadBot = currentTaskBot(profileBot);const connectionKey = `${profileBot.id}:${profileBot.threadId}:${livePlace}:${profileBot.cloudBackend ?? "box"}:${threadBot.modelSelection.instanceId}`;const [autoSurface, setAutoSurface] = useState<{ key: string; surface: Bot["computer"] } | null>(null);@@ -1152,8 +1153,7 @@ export function ComputerPanel({else if (mode === "browser") updateComputerSelection({ computer: mode, browser: true });else updateComputerSelection({ computer: mode });};- const heldPin = liveTask?.surface && !liveTask.surfaceAuto && profileBot.computer !== "off"- && liveTask.surface !== profileBot.computer ? liveTask.surface : undefined;+ const heldPin = livePin && profileBot.computer !== "off" && livePin !== profileBot.computer ? livePin : undefined;const tabClass = (active: boolean) => cn("flex shrink-0 items-center gap-1.5 rounded-full px-3 py-1 text-[13px] transition-colors @max-[28rem]/paneltabs:[&>svg]:hidden @max-[22rem]/paneltabs:px-2",@@ -1715,9 +1715,9 @@ export function ComputerPanel({</button>))}</div>- {liveTask?.surface && (+ {livePin && (<p className="mt-2 text-[12px] leading-5 text-ink-secondary" data-testid="place-pinned-note">- {t("place.pinnedNote", { place: t(placeLabelKey(liveTask.surface)) })}+ {t("place.pinnedNote", { place: t(placeLabelKey(livePin)) })}</p>)}<div className="mt-3 border-t border-hairline/40 pt-3 text-[12px] leading-5 text-ink-secondary" aria-live="polite" data-testid="place-line">diff --git a/src/components/PlaceChip.dom.test.ts b/src/components/PlaceChip.dom.test.tsnew file mode 100644index 0000000000..98035c47fe--- /dev/null+++ b/src/components/PlaceChip.dom.test.ts@@ -0,0 +1,62 @@+// @vitest-environment happy-dom+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, describe, expect, it, vi } from "vitest";+import type { Bot, InstanceInfo } from "@/state/store";++vi.mock("./MenuMotion", async (importOriginal) => ({+ ...await importOriginal<typeof import("./MenuMotion")>(),+ useMenuMotion: () => ({ shown: true, closing: false, className: "", exitProps: {} }),+}));+vi.mock("@/state/store", async (importOriginal) => {+ const original = await importOriginal<typeof import("@/state/store")>();+ return {+ ...original,+ useStore: () => ({+ state: {+ ...original.initialState,+ config: { ...original.initialState.config, features: { browser: true }, browserEngine: { kind: "engine" } },+ instances: [{+ instanceId: "test", driverKind: "grokAgent", displayName: "Grok", snapshot: { state: "available" },+ capabilities: { computerMcp: true, browserMcp: true },+ } as InstanceInfo],+ },+ dispatch: vi.fn(),+ }),+ };+});+vi.mock("./DesktopCapabilities", async (importOriginal) => ({+ ...await importOriginal<typeof import("./DesktopCapabilities")>(),+ useDesktopCapabilities: () => ({+ capabilities: {+ dictation: { available: false },+ host: { packaged: true, platform: "darwin" },+ localComputer: { available: true, support: "supported", enabled: true, status: "enabled" },+ },+ ready: true,+ }),+}));++const { PlaceChip } = await import("./PlaceChip");++const bot = {+ id: "bot", threadId: "thread", name: "Rio", title: "", description: "", color: "green", notifications: true,+ unread: false, busy: false, messages: [], computer: undefined, modelSelection: { instanceId: "test", model: "grok-4.6" },+} as Bot;++let root: Root | undefined;+afterEach(() => { flushSync(() => root?.unmount()); root = undefined; document.body.innerHTML = ""; });++describe("the desktop place menu", () => {+ it("pins Browser when the person clicks it, though Auto picked Browser already", () => {+ const onPin = vi.fn();+ const host = document.body.appendChild(document.createElement("div"));+ root = createRoot(host);+ flushSync(() => root!.render(createElement(PlaceChip, { bot, live: false, task: { surface: "browser", surfaceAuto: true }, onPin })));+ const row = [...host.querySelectorAll<HTMLButtonElement>('[role="menuitemradio"]')].find((el) => el.textContent?.startsWith("Browser"));+ expect(row).toBeDefined();+ flushSync(() => row!.click());+ expect(onPin).toHaveBeenCalledWith("browser");+ });+});diff --git a/src/components/PlaceChip.test.ts b/src/components/PlaceChip.test.tsindex da2b05920f..b78a2461c3 100644--- a/src/components/PlaceChip.test.ts+++ b/src/components/PlaceChip.test.ts@@ -42,7 +42,7 @@ vi.mock("./DesktopCapabilities", async (importOriginal) => ({}),}));-const { PlaceChip, usePlaceAvailability } = await import("./PlaceChip");+const { PlaceChip, usePlaceAvailability, usePlaceMenuItem } = await import("./PlaceChip");afterAll(() => vi.unstubAllGlobals());const bot = {@@ -105,6 +105,15 @@ describe("the menu's first row", () => {expect(html).toContain('aria-label="Where this conversation works: Private desktop"');});+ it("keeps Auto checked for the place Auto picked, which is no pin of the person's", () => {+ const { html, rows: menu } = rows({ bot: { ...bot, computer: undefined }, task: { surface: "browser", surfaceAuto: true } });+ expect(menu[0]).toEqual({ checked: true, text: "Auto Picks the right place for each task" });+ expect(menu.filter((row) => row.checked)).toHaveLength(1);+ expect(html).toContain('aria-label="Where this conversation works: Browser"');+ expect(html).toContain("Browser — From this bot's Works on setting");+ expect(html).not.toContain("text-accent hover:text-accent");+ });+it("keeps following the bot's setting when the bot works on a specific place", () => {const { html, rows: menu } = rows({ bot: { ...bot, computer: "local" } });expect(menu[0]).toEqual({ checked: true, text: "Follow this bot's setting Currently This computer" });@@ -112,6 +121,22 @@ describe("the menu's first row", () => {});});+describe("the phone's place menu", () => {+ it("keeps Auto checked for the place Auto picked, and still lets the person pin that place", () => {+ const onPin = vi.fn();+ let item: ReturnType<typeof usePlaceMenuItem> | undefined;+ function Probe() {+ item = usePlaceMenuItem({ bot: { ...bot, computer: undefined }, task: { surface: "browser", surfaceAuto: true }, onPin });+ return null;+ }+ renderToStaticMarkup(createElement(Probe));+ const menu = item!.submenu!;+ expect(menu.filter((row) => row.active).map((row) => row.key)).toEqual(["place:follow"]);+ menu.find((row) => row.key === "place:browser")!.onSelect();+ expect(onPin).toHaveBeenCalledWith("browser");+ });+});+describe("the places a conversation can be pinned to", () => {const availability = () => {let seen: ReturnType<typeof usePlaceAvailability> | undefined;diff --git a/src/components/PlaceChip.tsx b/src/components/PlaceChip.tsxindex 6fa3bd7284..225947d103 100644--- a/src/components/PlaceChip.tsx+++ b/src/components/PlaceChip.tsx@@ -5,7 +5,7 @@ import { useMenuMotion } from "./MenuMotion";import { MENU_HEADING, MENU_SHEET } from "./menu-recipe";import { t } from "@/lib/i18n";import { instanceSupportsLocalComputer, localComputerDisabledReason, localComputerSelectable } from "@/lib/local-computer";-import { effectivePlace, PLACES, placeLabelKey, placeOffered, type Place } from "@/lib/place";+import { effectivePlace, personPin, PLACES, placeLabelKey, placeOffered, type Place } from "@/lib/place";import { placeBlocked, placeFacts, placeHasIssue, placeViewFor, usePlaceSeat } from "@/lib/place-view";import { useStore, type Bot, type Task } from "@/state/store";import type { PlaceView } from "../../shared/place-view";@@ -43,19 +43,20 @@ export function usePlaceAvailability(bot: Bot): PlaceAvailability {/** The place chip as one + menu entry with the same choices, for a phone composer that has no room for the chip. */export function usePlaceMenuItem({ bot, task, disabled = false, onPin }: {bot: Bot;- task?: Pick<Task, "surface"> | null;+ task?: Pick<Task, "surface" | "surfaceAuto"> | null;disabled?: boolean;onPin: (surface: Place | null) => void;}): SidebarMenuItem {const { state } = useStore();const places = usePlaceViews(bot);const effective = effectivePlace(bot, task);- const pinned = Boolean(task?.surface);+ const pin = personPin(task);+ const pinned = Boolean(pin);const off = effective === "off";const botDefault = bot.computer ?? "auto";const followsAuto = botDefault === "auto";const check = <Check size={14} className="text-accent" aria-hidden="true" />;- const choose = (surface: Place | null) => { if (surface !== (task?.surface ?? null)) onPin(surface); };+ const choose = (surface: Place | null) => { if (surface !== (pin ?? null)) onPin(surface); };return {key: "place",label: t("computer.worksOn"),@@ -80,8 +81,8 @@ export function usePlaceMenuItem({ bot, task, disabled = false, onPin }: {label: t(placeLabelKey(place)),note: !policy ? t("place.unavailable") : placeHasIssue(view) ? view.short : t(DESCRIPTION[place]),icon: <PlaceIcon place={place} size={16} aria-hidden="true" />,- active: task?.surface === place,- trailing: task?.surface === place ? check : undefined,+ active: pin === place,+ trailing: pin === place ? check : undefined,disabled: !reachable,onSelect: () => choose(place),};@@ -96,7 +97,7 @@ const DESCRIPTION: Record<Place, "computer.dest.cloudDesc" | "computer.dest.vmDeexport function PlaceChip({ bot, task, live, disabled = false, onPin }: {bot: Bot;- task?: Pick<Task, "surface"> | null;+ task?: Pick<Task, "surface" | "surfaceAuto"> | null;live: boolean;disabled?: boolean;onPin: (surface: Place | null) => void;@@ -107,7 +108,8 @@ export function PlaceChip({ bot, task, live, disabled = false, onPin }: {const { state } = useStore();const places = usePlaceViews(bot);const effective = effectivePlace(bot, task);- const pinned = Boolean(task?.surface);+ const pin = personPin(task);+ const pinned = Boolean(pin);const off = effective === "off";const label = t(placeLabelKey(effective));const showLive = live && effective !== "off" && effective !== "auto";@@ -122,7 +124,7 @@ export function PlaceChip({ bot, task, live, disabled = false, onPin }: {return () => { document.removeEventListener("mousedown", outside); document.removeEventListener("keydown", escape); };}, [open]);- const choose = (surface: Place | null) => { setOpen(false); if (surface !== (task?.surface ?? null)) onPin(surface); };+ const choose = (surface: Place | null) => { setOpen(false); if (surface !== (pin ?? null)) onPin(surface); };const botDefault = bot.computer ?? "auto";const followsAuto = botDefault === "auto";@@ -167,7 +169,7 @@ export function PlaceChip({ bot, task, live, disabled = false, onPin }: {{!pinned && <Check size={14} className="mt-0.5 shrink-0 text-accent" aria-hidden="true" />}</button>{PLACES.filter((place) => placeOffered(place, state.config)).map((place) => {- const selected = task?.surface === place;+ const selected = pin === place;const { view, reachable, policy } = places[place];const detail = !policy ? t("place.unavailable") : placeHasIssue(view) ? view.short : t(DESCRIPTION[place]);return (diff --git a/src/lib/place.ts b/src/lib/place.tsindex 89753bafb7..2e3a5d1fb8 100644--- a/src/lib/place.ts+++ b/src/lib/place.ts@@ -16,6 +16,11 @@ export function effectivePlace(bot: Pick<Bot, "computer">, task?: Pick<Task, "sureturn task?.surface ?? bot.computer ?? "auto";}+/** The place the person pinned this conversation to; a place Auto picked and recorded for it is not their pin. */+export function personPin(task?: Pick<Task, "surface" | "surfaceAuto"> | null): Place | undefined {+ return task?.surfaceAuto ? undefined : task?.surface;+}+export function isComputerPlace(place: EffectivePlace): place is "cloud" | "vm" | "local" {return place === "cloud" || place === "vm" || place === "local";}