Skip to content

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

Merge remote-tracking branch 'origin/main' into new-bot-works-on-picker

Kevin4e2b49229f81
diff --cc src/components/ComputerPanel.tsx
index e8caeb4675,9db3a00bc2..2b1ccf89aa
--- a/src/components/ComputerPanel.tsx
+++ b/src/components/ComputerPanel.tsx
@@@ -19,7 -19,6 +19,7 @@@ import { listenLiveFrames } from "@/lib
import { CloudScreenPreview } from "./CloudScreenPreview";
import { isActiveTurnRefusal, isRemoteScreenshotContention } from "@/lib/remote-desktop";
import { CloudBackendPicker } from "./CloudBackendPicker";
- import { placeManagedBy, WORKS_ON_CHOICES, WorksOnGrid } from "./WorksOnGrid";
++import { placeManagedBy, worksOnChoices, WorksOnGrid, worksOnSelected } from "./WorksOnGrid";
import { useDesktopCapabilities } from "./DesktopCapabilities";
import { RoutinesSection } from "./bot-settings/RoutinesSection";
import { routineRunLabel, routineRunTone } from "@/lib/routine-display";
@@@ -1113,9 -1103,18 +1104,10 @@@ export function ComputerPanel(
: undefined;
const cloudView = viewOf("cloud", cloudRefused);
const autoView = viewOf("auto");
- const placeOptions = WORKS_ON_CHOICES.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;
+ const localHidden = pageOnRemoteServer(capabilities);
- const placeOptions = ([
- [null, "vm.dest.auto", "computer.dest.autoDesc", Sparkles],
- ["cloud", "place.cloud", "computer.dest.cloudDesc", Cloud],
- ["vm", "vm.dest.vm", "computer.dest.vmDesc", Box],
- ["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" && 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 placeOptions = worksOnChoices(state.config, capabilities).map(([mode, labelKey, descriptionKey, Icon]) => {
++ const selected = worksOnSelected(mode, profileBot.computer, capabilities);
+ const managedBy = placeManagedBy(mode, profileBot.cloudBackend, managedPolicy);
const view = mode === null ? autoView : mode === "cloud" ? cloudView : viewOf(mode);
const disabled = Boolean(managedBy) || placeBlocked(view);
const issue = !managedBy && placeHasIssue(view);
diff --cc src/components/WorksOnGrid.tsx
index a8c0de8021,0000000000..1d48d936e5
mode 100644,000000..100644
--- a/src/components/WorksOnGrid.tsx
+++ b/src/components/WorksOnGrid.tsx
@@@ -1,72 -1,0 +1,81 @@@
+import { Box, Check, Cloud, Globe, Monitor, Power, Sparkles } from "lucide-react";
+import type { LucideIcon } from "lucide-react";
+import type { Bot, ConfigStatus } from "@/state/store";
+import type { PlaceView } from "../../shared/place-view";
+import { cn } from "@/lib/cn";
+import { t } from "@/lib/i18n";
- import type { Place } from "@/lib/place";
++import { pageOnRemoteServer } from "@/lib/local-computer";
++import { placeOffered, type Place } from "@/lib/place";
+import type { LocaleKey } from "@/locales";
+
+export type WorksOnMode = Place | "off" | null;
+
- export const WORKS_ON_CHOICES = [
++const WORKS_ON_CHOICES = [
+ [null, "vm.dest.auto", "computer.dest.autoDesc", Sparkles],
+ ["cloud", "place.cloud", "computer.dest.cloudDesc", Cloud],
+ ["vm", "vm.dest.vm", "computer.dest.vmDesc", Box],
+ ["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 satisfies ReadonlyArray<readonly [WorksOnMode, LocaleKey, LocaleKey, LucideIcon]>;
+
++export function worksOnChoices(config: Parameters<typeof placeOffered>[1], capabilities: DesktopCapabilities) {
++ return WORKS_ON_CHOICES.filter(([mode]) => mode === null || mode === "off" || (placeOffered(mode, config) && !(mode === "local" && pageOnRemoteServer(capabilities))));
++}
++
++export function worksOnSelected(mode: WorksOnMode, computer: Bot["computer"], capabilities: DesktopCapabilities): boolean {
++ return mode === null ? !computer || (computer === "local" && pageOnRemoteServer(capabilities)) : computer === mode;
++}
++
+export function placeManagedBy(mode: WorksOnMode, cloudBackend: Bot["cloudBackend"], policy: ConfigStatus["managedPolicy"]): string | undefined {
+ const kind = mode === "local" ? "thisComputer" : mode === "vm" ? "localVm" : mode === "cloud" ? (cloudBackend === "vps" ? "vps" : "box") : null;
+ return policy && kind && !policy.computers[kind] ? t("policy.managedBy", { organization: policy.organizationName }) : undefined;
+}
+
+export interface WorksOnOption {
+ mode: WorksOnMode;
+ labelKey: LocaleKey;
+ descriptionKey: LocaleKey;
+ Icon: LucideIcon;
+ selected: boolean;
+ managedBy?: string;
+ disabled: boolean;
+ unavailableTitle?: string;
+ note?: string;
+ issue: boolean;
+ view: PlaceView;
+}
+
+export function WorksOnGrid({ options, onSelect }: { options: readonly WorksOnOption[]; onSelect: (mode: WorksOnMode) => void }) {
+ return (
+ <div role="group" aria-label={t("computer.destinationAria")} className="mt-3 grid auto-rows-fr grid-cols-2 gap-2">
+ {options.map(({ mode, labelKey, descriptionKey, Icon, selected, managedBy, disabled, unavailableTitle, note, issue, view }) => (
+ <button
+ key={mode ?? "auto"}
+ disabled={disabled}
+ title={unavailableTitle}
+ onClick={() => onSelect(mode)}
+ type="button"
+ aria-pressed={selected}
+ className={cn(
+ "min-w-0 rounded-lg border px-2.5 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-card",
+ selected
+ ? "border-accent/60 bg-accent/10 text-ink"
+ : "border-hairline/50 bg-panel/30 text-ink-secondary",
+ disabled
+ ? "cursor-not-allowed"
+ : "hover:border-accent/40 hover:bg-control/60",
+ )}
+ >
+ <span className="flex items-center gap-2 text-[12px] font-medium leading-4">
+ {selected ? <Check size={14} className="shrink-0 text-accent" /> : <Icon size={14} className="shrink-0 text-ink-secondary" />}
+ <span>{t(labelKey)}</span>
+ </span>
+ <span className="mt-1.5 block text-[11px] leading-4 text-ink-secondary">
+ {managedBy ?? note ?? (disabled ? view.line : issue ? view.short : t(descriptionKey))}
+ </span>
+ </button>
+ ))}
+ </div>
+ );
+}
diff --cc src/components/bot-settings/AccessSection.test.ts
index 9846d43927,6c591ad8f2..4285c7439a
--- a/src/components/bot-settings/AccessSection.test.ts
+++ b/src/components/bot-settings/AccessSection.test.ts
@@@ -43,8 -40,6 +43,9 @@@ beforeEach(() =>
fixture.mcpError = false;
fixture.servers = null;
fixture.config = null;
+ fixture.instances = [];
+ fixture.capabilities.host = { homeDir: undefined };
++ fixture.capabilities.localComputer = { available: false, reasonCode: "unsupported" };
fixture.apps = { phase: "loading", apps: [], connectedSlugs: [] };
});
afterEach(() => vi.unstubAllGlobals());
@@@ -213,66 -208,6 +214,75 @@@ describe("AccessSection Works on", () =
]);
});
+ it("offers the place itself in a bot not made yet, which has no Screen panel to open", () => {
+ const derived = makeDerived();
+ const draft = (bot: Bot) => {
+ let tree!: ReturnType<typeof AccessSection>;
+ function Capture() { tree = AccessSection({ bot, derived }); return tree; }
+ const editor = createElement(BotEditorContext.Provider, { value: { request: api, draft: true } }, createElement(Capture));
+ return { html: renderToStaticMarkup(createElement(StoreProvider, null, editor)), tree };
+ };
+ const { html } = draft(makeBot({ name: "" }));
+ expect(html).not.toContain("Open the Screen panel");
+ expect(html).not.toContain("Auto cloud preference");
+ expect(html).toContain("Works on");
+ expect(html).toContain("Cloud desktop");
+ expect(html).toMatch(/aria-pressed="true"[^>]*>.*?Auto/);
+
+ fixture.config = { box: { configured: true } } as Partial<ConfigStatus>;
+ const chosen = draft(makeBot({ computer: "cloud" }));
+ expect(chosen.html).toMatch(/<button[^>]*aria-pressed="true"[^>]*>(?:(?!<\/button>).)*?Cloud desktop/);
+ expect(chosen.html).toContain("Cloud backend");
+
+ const picker = nodes(chosen.tree).find((node) => (node.type as { name?: string }).name === "DraftWorksOn")!;
+ let rendered: ReactNode = null;
+ function Picker() { rendered = (picker.type as (props: unknown) => ReactNode)(picker.props); return rendered; }
+ renderToStaticMarkup(createElement(StoreProvider, null, createElement(Picker)));
+ const grid = nodes(rendered).find((node) => (node.type as { name?: string }).name === "WorksOnGrid")!;
+ const options = grid.props.options as Array<{ mode: string | null; disabled: boolean; view: { line: string } }>;
+ const local = options.find((option) => option.mode === "local")!;
+ expect(local.disabled).toBe(true);
+ expect(renderToStaticMarkup(grid).replaceAll("&#x27;", "'")).toContain(local.view.line);
+
+ const select = grid.props.onSelect as (mode: string | null) => void;
+ select("browser");
+ select(null);
+ expect(vi.mocked(derived.patch).mock.calls).toEqual([[{ computer: "browser", browser: true }], [{ computer: null }]]);
+ });
+
+ it("says on a selectable tile of a bot not made yet what stands in its way, with no name to borrow", () => {
+ fixture.config = { box: { configured: true } } as Partial<ConfigStatus>;
+ fixture.instances = [{ instanceId: "local", capabilities: { computerMcp: true } }];
+ fixture.capabilities.host = { homeDir: undefined, platform: "darwin" };
+ let tree!: ReturnType<typeof AccessSection>;
+ function Capture() { tree = AccessSection({ bot, derived: makeDerived() }); return tree; }
+ const bot = makeBot({ name: "", toolScope: { deny: ["mcp:computer:*"] } } as Partial<Bot>);
+ renderToStaticMarkup(createElement(StoreProvider, null, createElement(BotEditorContext.Provider, { value: { request: api, draft: true } }, createElement(Capture))));
+ const picker = nodes(tree).find((node) => (node.type as { name?: string }).name === "DraftWorksOn")!;
+ let rendered: ReactNode = null;
+ function Picker() { rendered = (picker.type as (props: unknown) => ReactNode)(picker.props); return rendered; }
+ renderToStaticMarkup(createElement(StoreProvider, null, createElement(Picker)));
+ const grid = nodes(rendered).find((node) => (node.type as { name?: string }).name === "WorksOnGrid")!;
+ const options = grid.props.options as Array<{ mode: string | null; disabled: boolean; note?: string }>;
+ const of = (mode: string) => options.find((option) => option.mode === mode)!;
+ expect(of("cloud")).toMatchObject({ disabled: false, note: "What New bot can use doesn't include a desktop." });
+ expect(of("local").disabled).toBe(false);
+ expect(of("local").note).toBeTruthy();
+ const html = renderToStaticMarkup(grid).replaceAll("&#x27;", "'").replaceAll("&amp;", "&");
+ expect(html).toContain(of("cloud").note);
+ expect(html).toContain(of("local").note);
+ });
+
+
++ it("leaves This computer out of a bot not made yet on another server's page, and shows Auto in its place", () => {
++ fixture.capabilities.localComputer = { available: false, reasonCode: "remote-server" };
++ let tree!: ReturnType<typeof AccessSection>;
++ function Capture() { tree = AccessSection({ bot: makeBot({ computer: "local" }), derived: makeDerived() }); return tree; }
++ const html = renderToStaticMarkup(createElement(StoreProvider, null, createElement(BotEditorContext.Provider, { value: { request: api, draft: true } }, createElement(Capture))));
++ expect(html).not.toContain("This computer");
++ expect(html).toMatch(/<button[^>]*aria-pressed="true"[^>]*>(?:(?!<\/button>).)*?Auto/);
++ });
++
it("hides the Boat or VPS choice on My Cloud, whose cloud computers are the plan's", () => {
expect(render(makeBot())).toContain("Cloud backend");
fixture.config = { cloudHome: true } as Partial<ConfigStatus>;
diff --cc src/components/bot-settings/AccessSection.tsx
index 8842e1d404,b5af1b1ace..64d7657741
--- a/src/components/bot-settings/AccessSection.tsx
+++ b/src/components/bot-settings/AccessSection.tsx
@@@ -7,15 -7,12 +7,14 @@@ import { useBotEditor } from "./BotEdit
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
import type { LocaleKey } from "@/locales";
- import { mcpServersForBot, mcpServersOfBot, useMcpServers } from "@/lib/mcp-servers";
+ import { mcpServersForBot, mcpServersOfBot, mcpSwitch, useMcpServers } from "@/lib/mcp-servers";
-import { placeFacts, placeViewFor, usePlaceSeat } from "@/lib/place-view";
+import { instanceSupportsLocalComputer, localComputerDisabledReason, localComputerSelectable } from "@/lib/local-computer";
- import { placeOffered } from "@/lib/place";
+import { placeBlocked, placeFacts, placeHasIssue, placeViewFor, usePlaceSeat, type PlaceSeat } from "@/lib/place-view";
import { shortPath } from "@/lib/short-path";
import { isOwnThreadFolder } from "../../../shared/thread-folder";
import { useDesktopCapabilities } from "../DesktopCapabilities";
import { CloudBackendPicker } from "../CloudBackendPicker";
- import { placeManagedBy, WORKS_ON_CHOICES, WorksOnGrid, type WorksOnMode } from "../WorksOnGrid";
++import { placeManagedBy, worksOnChoices, WorksOnGrid, worksOnSelected, type WorksOnMode } from "../WorksOnGrid";
import { Switch } from "../SettingsPrimitives";
import { PhoneAppsCard } from "./PhoneAppsCard";
import { ProposalStatus } from "./ProposalStatus";
@@@ -636,37 -631,6 +633,37 @@@ export function CloudPreference({ bot,
);
}
+function DraftWorksOn({ bot, patch, seat }: { bot: Bot; patch: ReturnType<typeof useBotSettingsDerived>["patch"]; seat: PlaceSeat }) {
+ const { state } = useStore();
+ const { capabilities } = useDesktopCapabilities();
+ const providerSupportsLocal = instanceSupportsLocalComputer(state.instances, bot);
+ const localReason = localComputerDisabledReason({ capabilities, providerSupportsLocal });
+ const named = { ...bot, name: bot.name || t("sidebar.newBotSimple") };
- const options = WORKS_ON_CHOICES.filter(([mode]) => mode === null || mode === "off" || placeOffered(mode, state.config)).map(([mode, labelKey, descriptionKey, Icon]) => {
++ const options = worksOnChoices(state.config, capabilities).map(([mode, labelKey, descriptionKey, Icon]) => {
+ const view = placeViewFor(placeFacts({
+ bot: named, place: mode ?? "auto", seat, config: state.config, instances: state.instances,
+ local: {
+ ready: localComputerSelectable({ capabilities, providerSupportsLocal }),
+ reason: localReason ?? t("computer.unavailableLocal"),
+ },
+ }));
+ const managedBy = placeManagedBy(mode, bot.cloudBackend, state.config?.managedPolicy);
+ return {
+ mode, labelKey, descriptionKey, Icon, view, managedBy,
- selected: mode === null ? !bot.computer : bot.computer === mode,
++ selected: worksOnSelected(mode, bot.computer, capabilities),
+ disabled: Boolean(managedBy) || placeBlocked(view),
+ issue: !managedBy && placeHasIssue(view),
+ note: placeHasIssue(view) ? view.line : mode === "local" ? localReason ?? undefined : undefined,
+ };
+ });
+ const choose = (mode: WorksOnMode) => patch(mode === "browser" ? { computer: mode, browser: true } : { computer: mode });
+ return <>
+ <div className="text-[15px] font-medium text-ink">{t("computer.worksOn")}</div>
+ <p className="mt-1 text-[12px] leading-5 text-ink-secondary">{t(state.config?.cloudHome ? "computer.worksOnHintCloudHome" : "computer.worksOnHint")}</p>
+ <WorksOnGrid options={options} onSelect={choose} />
+ </>;
+}
+
export type AccessPart = "worksOn" | "folder" | "apps" | "phone" | "xResearch" | "mcp" | "tools" | "browser" | "webhooks" | "always";
export function AccessSection({