Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
import { createElement, isValidElement, type ReactElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Bot } from "@/state/store";
const fixture = vi.hoisted(() => ({ advanced: true, draft: false, mode: "per-bot" as string | undefined }));
vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => fixture.advanced }));
vi.mock("./BotEditorContext", () => ({ useBotEditor: () => ({ draft: fixture.draft }) }));
vi.mock("@/state/store-select", () => ({
useStoreSelector: (select: (state: unknown) => unknown) => select({ config: { localVm: fixture.mode ? { mode: fixture.mode } : undefined } }),
}));
import { KeepDesktopRunning } from "./KeepDesktopRunning";
const bot = (extra: Partial<Bot> = {}) => ({ id: "b1", name: "Scout", computer: "vm", ...extra } as unknown as Bot);
const html = (target: Bot) => renderToStaticMarkup(createElement(KeepDesktopRunning, { bot: target, patch: () => {} }));
beforeEach(() => {
fixture.advanced = true;
fixture.draft = false;
fixture.mode = "per-bot";
});
describe("keeping a bot's own desktop running", () => {
it("shows only in Advanced, for a saved bot on its own Local VM", () => {
expect(html(bot())).toContain("Keep this bot's desktop always running");
fixture.advanced = false;
expect(html(bot())).toBe("");
fixture.advanced = true;
fixture.mode = "shared";
expect(html(bot())).toBe("");
fixture.mode = "per-bot";
expect(html(bot({ computer: "local" }))).toBe("");
fixture.draft = true;
expect(html(bot())).toBe("");
});
it("is off unless chosen, and saves the bot's choice", () => {
expect(html(bot())).toContain('aria-checked="false"');
expect(html(bot({ localVm: { keepDesktopRunning: true } }))).toContain('aria-checked="true"');
const patch = vi.fn();
const element = KeepDesktopRunning({ bot: bot(), patch }) as ReactElement<{ children: ReactElement[] }>;
const toggle = element.props.children.find((child) => isValidElement(child) && (child.props as { onClick?: unknown }).onClick) as ReactElement<{ onClick: () => void }>;
toggle.props.onClick();
expect(patch).toHaveBeenCalledWith({ localVm: { keepDesktopRunning: true } });
});
});