Skip to content

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

fix(computer): leave This computer out of the place chip on a remote server's page

jimin957c56d1449a
diff --git a/src/components/ComputerPanel.simple.test.ts b/src/components/ComputerPanel.simple.test.ts
index 83ec1bdaad..4158d36fab 100644
--- a/src/components/ComputerPanel.simple.test.ts
+++ b/src/components/ComputerPanel.simple.test.ts
@@ -380,6 +380,13 @@ describe("Where the bot works", () => {
expect(grid(render(makeBot())).map((node) => text(node.props.children))).toEqual(["Auto", "Cloud desktop", "Private desktop", "Browser", "Off"]);
});
+ it("shows a bot set to This Mac as Auto on another server's page, without changing its setting", () => {
+ fixture.localComputer = { available: false, support: "unsupported", enabled: false, status: "unavailable", reasonCode: "remote-server" };
+ const pressed = grid(render(makeBot({ computer: "local" }))).filter((node) => node.props["aria-pressed"]).map((node) => text(node.props.children));
+ expect(pressed).toEqual(["Auto"]);
+ expect(fixture.dispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: "updateBot" }));
+ });
+
it("says what Auto does on My Cloud, where it starts a cloud computer by itself", () => {
fixture.config = { ...fixture.config, cloudHome: true };
expect(placeLine(render(makeBot()))).toBe("Uses the built-in browser. In a chat, it starts its cloud desktop by itself when a task needs desktop apps.");
diff --git a/src/components/ComputerPanel.tsx b/src/components/ComputerPanel.tsx
index 49c9c34b29..e74d85d7eb 100644
--- a/src/components/ComputerPanel.tsx
+++ b/src/components/ComputerPanel.tsx
@@ -41,6 +41,7 @@ import {
instanceSupportsLocalComputer,
localComputerDisabledReason,
localComputerSelectable,
+ pageOnRemoteServer,
persistedComputerSelectionMatches,
isReadyBoatState,
resolveBoatPanelAction,
@@ -1111,6 +1112,7 @@ export function ComputerPanel({
: undefined;
const cloudView = viewOf("cloud", cloudRefused);
const autoView = viewOf("auto");
+ const localHidden = pageOnRemoteServer(capabilities);
const placeOptions = ([
[null, "vm.dest.auto", "computer.dest.autoDesc", Sparkles],
["cloud", "place.cloud", "computer.dest.cloudDesc", Cloud],
@@ -1118,8 +1120,8 @@ export function ComputerPanel({
["local", "vm.dest.local", "computer.dest.localDesc", Monitor],
["browser", "vm.dest.browser", "computer.dest.browserDesc", Globe],
["off", "vm.dest.off", "computer.dest.offDesc", Power],
- ] as const).filter(([mode]) => mode === null || mode === "off" || (placeOffered(mode, state.config) && !(mode === "local" && capabilities.localComputer.reasonCode === "remote-server"))).map(([mode, labelKey, descriptionKey, Icon]) => {
- const selected = mode === null ? !profileBot.computer : profileBot.computer === mode;
+ ] as const).filter(([mode]) => mode === null || mode === "off" || (placeOffered(mode, state.config) && !(mode === "local" && localHidden))).map(([mode, labelKey, descriptionKey, Icon]) => {
+ const selected = mode === null ? !profileBot.computer || (profileBot.computer === "local" && localHidden) : profileBot.computer === mode;
const managedKind = mode === "local" ? "thisComputer" : mode === "vm" ? "localVm" : mode === "cloud" ? (profileBot.cloudBackend === "vps" ? "vps" : "box") : null;
const managedBy = managedPolicy && managedKind && !managedPolicy.computers[managedKind] ? t("policy.managedBy", { organization: managedPolicy.organizationName }) : undefined;
const view = mode === null ? autoView : mode === "cloud" ? cloudView : viewOf(mode);
diff --git a/src/components/PlaceChip.test.ts b/src/components/PlaceChip.test.ts
index da2b05920f..dd481870d2 100644
--- a/src/components/PlaceChip.test.ts
+++ b/src/components/PlaceChip.test.ts
@@ -4,7 +4,7 @@ import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
import type { Bot, InstanceInfo } from "@/state/store";
vi.stubGlobal("window", {});
-const fixture = vi.hoisted(() => ({ config: null as unknown, menuOpen: false, computerMcp: true }));
+const fixture = vi.hoisted(() => ({ config: null as unknown, menuOpen: false, computerMcp: true, localReason: undefined as string | undefined }));
// Static markup never runs the click that opens the menu; this renders it open.
vi.mock("./MenuMotion", async (importOriginal) => ({
...await importOriginal<typeof import("./MenuMotion")>(),
@@ -36,13 +36,15 @@ vi.mock("./DesktopCapabilities", async (importOriginal) => ({
capabilities: {
dictation: { available: false },
host: { packaged: true, platform: "darwin" },
- localComputer: { available: true, support: "supported", enabled: true, status: "enabled" },
+ localComputer: fixture.localReason
+ ? { available: false, support: "unsupported", enabled: false, status: "unavailable", reasonCode: fixture.localReason }
+ : { available: true, support: "supported", enabled: true, status: "enabled" },
},
ready: true,
}),
}));
-const { PlaceChip, usePlaceAvailability } = await import("./PlaceChip");
+const { PlaceChip, usePlaceAvailability, usePlaceMenuItem } = await import("./PlaceChip");
afterAll(() => vi.unstubAllGlobals());
const bot = {
@@ -112,6 +114,33 @@ describe("the menu's first row", () => {
});
});
+describe("another server's page", () => {
+ afterEach(() => { fixture.menuOpen = false; fixture.localReason = undefined; });
+ const labels = (items: { label: unknown }[]) => items.map((item) => item.label);
+
+ it("leaves This computer out of the chip menu and the phone submenu", () => {
+ fixture.localReason = "remote-server";
+ fixture.menuOpen = true;
+ const html = renderToStaticMarkup(createElement(PlaceChip, { bot: { ...bot, computer: undefined }, live: false, onPin: () => {} }));
+ const rows = html.split('role="menuitemradio"').slice(1);
+ expect(rows).toHaveLength(4);
+ expect(rows.some((row) => row.includes("This computer"))).toBe(false);
+
+ let submenu: { label: unknown }[] = [];
+ function Probe() { submenu = usePlaceMenuItem({ bot, onPin: () => {} }).submenu ?? []; return null; }
+ renderToStaticMarkup(createElement(Probe));
+ expect(labels(submenu)).not.toContain("This computer");
+ expect(submenu).toHaveLength(4);
+ });
+
+ it("still lists This computer on a desktop", () => {
+ let submenu: { label: unknown }[] = [];
+ function Probe() { submenu = usePlaceMenuItem({ bot, onPin: () => {} }).submenu ?? []; return null; }
+ renderToStaticMarkup(createElement(Probe));
+ expect(labels(submenu)).toContain("This computer");
+ });
+});
+
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.tsx
index 6fa3bd7284..9717de470a 100644
--- a/src/components/PlaceChip.tsx
+++ b/src/components/PlaceChip.tsx
@@ -4,7 +4,7 @@ import { cn } from "@/lib/cn";
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 { instanceSupportsLocalComputer, localComputerDisabledReason, localComputerSelectable, pageOnRemoteServer } from "@/lib/local-computer";
import { effectivePlace, 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";
@@ -15,7 +15,7 @@ import type { SidebarMenuItem } from "./SidebarPopoverMenu";
export type PlaceAvailability = Record<Place, boolean>;
-export function usePlaceViews(bot: Bot): Record<Place, { view: PlaceView; reachable: boolean; policy: boolean }> {
+export function usePlaceViews(bot: Bot): Record<Place, { view: PlaceView; reachable: boolean; policy: boolean; listed: boolean }> {
const { state } = useStore();
const { capabilities } = useDesktopCapabilities();
const seat = usePlaceSeat(state.config, capabilities.host.platform);
@@ -30,7 +30,8 @@ export function usePlaceViews(bot: Bot): Record<Place, { view: PlaceView; reacha
const view = placeViewFor(placeFacts({ bot, place, seat, config: state.config, instances: state.instances, local }));
const policy = (place === "cloud" ? allowed[backend] : place === "vm" ? allowed.localVm : place === "local" ? allowed.thisComputer : true)
&& placeOffered(place, state.config);
- return { view, policy, reachable: policy && !placeBlocked(view) };
+ const listed = placeOffered(place, state.config) && !(place === "local" && pageOnRemoteServer(capabilities));
+ return { view, policy, listed, reachable: policy && !placeBlocked(view) };
};
return { cloud: entry("cloud"), vm: entry("vm"), local: entry("local"), browser: entry("browser") };
}
@@ -47,7 +48,6 @@ export function usePlaceMenuItem({ bot, task, disabled = false, onPin }: {
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);
@@ -73,7 +73,7 @@ export function usePlaceMenuItem({ bot, task, disabled = false, onPin }: {
trailing: !pinned ? check : undefined,
onSelect: () => choose(null),
},
- ...PLACES.filter((place) => placeOffered(place, state.config)).map((place): SidebarMenuItem => {
+ ...PLACES.filter((place) => places[place].listed).map((place): SidebarMenuItem => {
const { view, reachable, policy } = places[place];
return {
key: `place:${place}`,
@@ -104,7 +104,6 @@ export function PlaceChip({ bot, task, live, disabled = false, onPin }: {
const [open, setOpen] = useState(false);
const motion = useMenuMotion(open);
const wrapperRef = useRef<HTMLDivElement>(null);
- const { state } = useStore();
const places = usePlaceViews(bot);
const effective = effectivePlace(bot, task);
const pinned = Boolean(task?.surface);
@@ -166,7 +165,7 @@ export function PlaceChip({ bot, task, live, disabled = false, onPin }: {
</span>
{!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) => {
+ {PLACES.filter((place) => places[place].listed).map((place) => {
const selected = task?.surface === place;
const { view, reachable, policy } = places[place];
const detail = !policy ? t("place.unavailable") : placeHasIssue(view) ? view.short : t(DESCRIPTION[place]);
diff --git a/src/lib/local-computer.ts b/src/lib/local-computer.ts
index b85d0a65da..51b1de03ee 100644
--- a/src/lib/local-computer.ts
+++ b/src/lib/local-computer.ts
@@ -11,6 +11,10 @@ export function instanceSupportsLocalComputer(
return capabilities?.localComputerMcp === true || capabilities?.computerMcp === true;
}
+export function pageOnRemoteServer(capabilities: DesktopCapabilities): boolean {
+ return capabilities.localComputer.reasonCode === "remote-server";
+}
+
export function localComputerSelectable({
capabilities,
providerSupportsLocal,
@@ -20,8 +24,7 @@ export function localComputerSelectable({
}): boolean {
if (!providerSupportsLocal) return false;
if (capabilities.localComputer.available) return true;
- // The desktop app's own computer can't serve bots running on another server; no permission fixes that.
- if (capabilities.localComputer.reasonCode === "remote-server") return false;
+ if (pageOnRemoteServer(capabilities)) return false;
return capabilities.host.platform === "darwin" || capabilities.host.platform === "win32";
}
@@ -35,7 +38,7 @@ export function localComputerDisabledReason({
}): string | null {
if (!providerSupportsLocal) return t("computer.problem.localAiCannot");
if (capabilities.localComputer.available) return null;
- if (capabilities.localComputer.reasonCode === "remote-server") return t("computer.problem.localRemoteServer");
+ if (pageOnRemoteServer(capabilities)) return t("computer.problem.localRemoteServer");
if (capabilities.host.platform === "linux") {
if (capabilities.localComputer.reasonCode === "linux-wayland-seat-safety-blocked") return t("computer.problem.localWaylandBlocked");
if (capabilities.localComputer.reasonCode === "wayland-compositor-unsupported") return t("computer.problem.localWaylandDesktop");