Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Move from Grok Bot: bring each Bot's chat over on the desktop app
aivsomkar2dc34e8e0e28
diff --git a/src/components/GrokMoveDialog.test.ts b/src/components/GrokMoveDialog.test.tsindex a4aca7d146..24c7346fc8 100644--- a/src/components/GrokMoveDialog.test.ts+++ b/src/components/GrokMoveDialog.test.ts@@ -27,6 +27,7 @@ const EXPORT = JSON.stringify({ format: GROK_EXPORT_FORMAT, version: 1, bots: [{apps: [{ name: "Cursor GitHub (connect_github)" }, { name: "Linear", mcp_url: "https://mcp.linear.app/mcp" }],}] });const FILES_STAY = "Files on Grok Bot's computer don't come over. Add any your Bot needs.";+const HISTORY_COMES = "Each Bot's chat comes over too, from the Grok Bot app on this computer.";const QUIET = JSON.stringify({ format: GROK_EXPORT_FORMAT, bots: [{ name: "Quiet", instructions: "Just chat." }] });let root: Root;@@ -92,6 +93,7 @@ describe("Move from Grok Bot", () => {expect(shown()).toContain("2 apps need connecting again here");expect(shown()).toContain("A safety check keeps these skills off: Quick installer");expect(shown()).not.toContain(FILES_STAY);+ expect(shown()).not.toContain(HISTORY_COMES);plain();expect(f.api.mock.calls.map(([path]) => path).filter((path) => path.startsWith("/api/teams/import") || path.includes("/skills/"))).toEqual([]);});@@ -179,6 +181,27 @@ describe("Move from Grok Bot", () => {expect(host.querySelector('[data-grok-move="preview"]')).not.toBeNull();});+ it("on the desktop app says each Bot's chat comes over, then counts it or says why it didn't", async () => {+ vi.stubGlobal("ogb", { remoteClient: { active: false } });+ let history: unknown = { messages: 214 };+ f.api.mockImplementation(async (path: string) => (path.startsWith("/api/teams/import")+ ? { bots: [{ id: "b1", name: "Job Search", threadId: "t1" }], routines: [], connections: [] }+ : path === "/api/setup-import/grok/history" ? history : path === "/api/mcp/servers" ? { servers: [] } : {}));+ await open();+ await paste(EXPORT);+ expect(shown()).toContain(HISTORY_COMES);+ await importIt();+ expect(counts()).toMatchObject({ "Chat messages": 214 });+ expect(shown()).not.toContain("No chat came over");++ history = { reason: "noApp" };+ await act(async () => button("Move another Bot")!.click());+ await paste(EXPORT);+ await importIt();+ expect(counts()).not.toHaveProperty("Chat messages");+ expect(shown()).toContain("No chat came over: the Grok Bot app isn't on this computer.");+ });+it("on the desktop app gives a link for Grok Bot, shows the Bots that arrive through it, and ends the link once they are imported", async () => {vi.useFakeTimers({ toFake: ["setInterval", "clearInterval"] });const openExternal = vi.fn();diff --git a/src/components/GrokMoveDialog.tsx b/src/components/GrokMoveDialog.tsxindex 414bb004cb..0ce4deb9b2 100644--- a/src/components/GrokMoveDialog.tsx+++ b/src/components/GrokMoveDialog.tsx@@ -5,10 +5,11 @@ import { track } from "@/lib/analytics";import { openExternalLink } from "@/lib/app-links";import { cn } from "@/lib/cn";import { useCopyFeedback } from "@/lib/copy-text";-import { foundExports, grokConnector, grokErrorText, lookForGrokBot, MAUSBOT_GROK_TEMPLATE_URL, NOTHING_FOUND, previewGrokMove, runGrokMove, type GrokConnector, type GrokLook, type GrokPreview, type GrokReport } from "@/lib/grok-move";+import { foundExports, grokConnector, grokErrorText, lookForGrokBot, MAUSBOT_GROK_TEMPLATE_URL, NOTHING_FOUND, previewGrokMove, runGrokMove, type GrokConnector, type GrokHistory, type GrokLook, type GrokPreview, type GrokReport } from "@/lib/grok-move";import { t } from "@/lib/i18n";import { localSetupImport } from "@/lib/setup-import";import { api, useStore } from "@/state/store";+import type { LocaleKey } from "@/locales";import { GROK_EXPORT_MAX_CHARS, GROK_EXPORT_PROMPT, parseGrokExport, type GrokBot } from "../../shared/grok-import";const PRIMARY = "ui-button ui-button-primary min-h-9 px-4 text-[14px]";@@ -16,11 +17,12 @@ const SECONDARY = "ui-button min-h-9 px-4 text-[14px]";const LINE = "text-[13px] leading-relaxed text-ink-secondary";/** A Bot as one heading and a count per kind; a kind it has none of is left out. */-export function BotCounts({ heading, skills, routines, memories, notes, skillsOff }: {- heading: string; skills: number; routines: number; memories: number; notes: number; skillsOff: readonly string[];+export function BotCounts({ heading, skills, routines, memories, notes, skillsOff, history }: {+ heading: string; skills: number; routines: number; memories: number; notes: number; skillsOff: readonly string[]; history?: GrokHistory;}) {const rows = [[t("grokMove.count.skills"), skills], [t("grokMove.count.routines"), routines], [t("grokMove.count.memories"), memories], [t("grokMove.count.notes"), notes],+ [t("grokMove.count.messages"), history && "messages" in history ? history.messages : 0],] as const;return (<section data-grok-move-bot className="flex flex-col gap-1.5">@@ -34,12 +36,14 @@ export function BotCounts({ heading, skills, routines, memories, notes, skillsOf))}</dl>{skillsOff.length > 0 && <p className={LINE}>{t("grokMove.skillsOff", { names: skillsOff.join(", ") })}</p>}+ {history && "reason" in history && <p className={LINE}>{t(`grokMove.history.${history.reason}` as LocaleKey)}</p>}</section>);}-export function GrokMoveLines({ paused, files = null, apps, moved, unreadable, failed = [] }: { paused: string | null; files?: string | null; apps: number; moved: readonly string[]; unreadable: readonly string[]; failed?: readonly string[] }) {+export function GrokMoveLines({ paused, history = null, files = null, apps, moved, unreadable, failed = [] }: { paused: string | null; history?: string | null; files?: string | null; apps: number; moved: readonly string[]; unreadable: readonly string[]; failed?: readonly string[] }) {const lines = [+ history,paused,files,apps === 1 ? t("grokMove.appsOne") : apps > 1 ? t("grokMove.appsMany", { count: apps }) : null,@@ -262,7 +266,7 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voiconst start = async () => {if (!preview) return;setImporting(true);- const done = await runGrokMove(preview, dispatch);+ const done = await runGrokMove(preview, dispatch, local);track("team_imported", { members: preview.plans.length, source: "grok", mode: "add", format: "package" });if (viaLink.current && done.bots.length > 0 && done.failed.length === 0) {// Best effort: a link left behind stops working on its own within the hour.@@ -312,7 +316,8 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi<BotCounts key={plan.packageId} heading={plan.addedAs} skills={plan.skills.length} routines={plan.routines} memories={plan.memories} notes={plan.notes}skillsOff={plan.skills.filter((skill) => !skill.on).map((skill) => skill.name)} />))}- <GrokMoveLines paused={preview.plans.some((plan) => plan.routines > 0) ? t("grokMove.pausedPreview") : null} apps={preview.plans.reduce((total, plan) => total + plan.apps, 0)}+ <GrokMoveLines history={local ? t("grokMove.historyPreview") : null} paused={preview.plans.some((plan) => plan.routines > 0) ? t("grokMove.pausedPreview") : null}+ apps={preview.plans.reduce((total, plan) => total + plan.apps, 0)}moved={preview.moved} unreadable={preview.unreadable} /></>) : (diff --git a/src/lib/grok-move.test.ts b/src/lib/grok-move.test.tsindex 12572f91e4..e07b58132d 100644--- a/src/lib/grok-move.test.ts+++ b/src/lib/grok-move.test.ts@@ -1,6 +1,6 @@import { beforeEach, describe, expect, it, vi } from "vitest";-const fixture = vi.hoisted(() => ({ requests: [] as Array<[string, string | undefined, unknown]>, failImport: "", failSkill: "" }));+const fixture = vi.hoisted(() => ({ requests: [] as Array<[string, string | undefined, unknown]>, failImport: "", failSkill: "", history: {} as unknown }));vi.mock("@/state/store", () => ({api: vi.fn(async (path: string, init: { method?: string; body?: string }) => {@@ -11,6 +11,10 @@ vi.mock("@/state/store", () => ({return { bots: [{ id: `id-${body.package.name}`, name: body.package.name, threadId: "t1" }], routines: [], connections: [] };}if (fixture.failSkill && path.endsWith(`/skills/${fixture.failSkill}`)) throw new Error("no");+ if (path === "/api/setup-import/grok/history") {+ if (fixture.history instanceof Error) throw fixture.history;+ return fixture.history;+ }return {};}),}));@@ -33,6 +37,7 @@ beforeEach(() => {fixture.requests.length = 0;fixture.failImport = "";fixture.failSkill = "";+ fixture.history = {};});describe("the preview", () => {@@ -88,6 +93,35 @@ describe("the import", () => {});});+describe("each Bot's chat", () => {+ it("on the desktop app comes over for each Bot added, asked for by its name in Grok Bot, and is counted", async () => {+ fixture.history = { messages: 214 };+ const report = await runGrokMove(previewGrokMove(bots(DESK), facts()), vi.fn(), true);+ expect(fixture.requests.filter(([path]) => path === "/api/setup-import/grok/history")).toEqual([+ ["/api/setup-import/grok/history", "POST", { botId: "id-Desk", grokName: "Desk" }],+ ]);+ expect(report.bots.map((bot) => bot.history)).toEqual([{ messages: 214 }]);+ });++ it("says why it didn't come over, and a request that got no usable answer is named as failed", async () => {+ const outcome = async (answer: unknown) => {+ fixture.history = answer;+ return (await runGrokMove(previewGrokMove(bots(DESK), facts()), vi.fn(), true)).bots[0]!.history;+ };+ expect(await outcome({ reason: "ambiguous" })).toEqual({ reason: "ambiguous" });+ expect(await outcome({ reason: "noApp" })).toEqual({ reason: "noApp" });+ expect(await outcome({ reason: "somethingNew" })).toEqual({ reason: "failed" });+ expect(await outcome(new Error("offline"))).toEqual({ reason: "failed" });+ });++ it("isn't asked for where the move can't look at this computer, and a Bot that wasn't added asks nothing", async () => {+ expect((await runGrokMove(previewGrokMove(bots(DESK), facts()), vi.fn())).bots[0]).not.toHaveProperty("history");+ fixture.failImport = "Desk";+ await runGrokMove(previewGrokMove(bots(DESK), facts()), vi.fn(), true);+ expect(fixture.requests.map(([path]) => path)).not.toContain("/api/setup-import/grok/history");+ });+});+describe("files found on this computer", () => {const file = (name: string, list: unknown, modifiedAt = 1) => ({ name, modifiedAt, text: JSON.stringify({ format: GROK_EXPORT_FORMAT, bots: list }) });diff --git a/src/lib/grok-move.ts b/src/lib/grok-move.tsindex 87dfc12822..fd198e671a 100644--- a/src/lib/grok-move.ts+++ b/src/lib/grok-move.ts@@ -3,7 +3,7 @@ import { addTemplate } from "@/lib/template-add";import { api, type Action, type Bot } from "@/state/store";import type { LocaleKey } from "@/locales";import { takeImportName } from "../../shared/import-name";-import { GrokImportError, grokMovePlan, mergeGrokBots, parseGrokExport, type GrokBot, type GrokMovePlan } from "../../shared/grok-import";+import { GROK_HISTORY_REASONS, GrokImportError, grokMovePlan, mergeGrokBots, parseGrokExport, type GrokBot, type GrokHistoryReason, type GrokMovePlan } from "../../shared/grok-import";/** What the desktop app found on this computer. */export interface GrokLook {@@ -111,6 +111,16 @@ export function previewGrokMove(bots: readonly GrokBot[], facts: GrokPreviewFactreturn preview;}+/** A moved Bot's chat: how many messages came over, or why none did ("failed": the request itself didn't get an answer). */+export type GrokHistory = { messages: number } | { reason: GrokHistoryReason | "failed" };++async function bringHistory(botId: string, grokName: string): Promise<GrokHistory> {+ const answer = await api<{ messages?: unknown; reason?: unknown } | null>("/api/setup-import/grok/history",+ { method: "POST", body: JSON.stringify({ botId, grokName }), timeoutMs: 60_000 }).catch(() => null);+ if (typeof answer?.messages === "number") return { messages: answer.messages };+ return { reason: GROK_HISTORY_REASONS.find((reason) => reason === answer?.reason) ?? "failed" };+}+export interface GrokMovedBot {name: string;skills: number;@@ -120,6 +130,8 @@ export interface GrokMovedBot {notes: number;memories: number;apps: number;+ /** Absent where the move can't look at this computer: a browser, a paired device or a Cloud. */+ history?: GrokHistory;}export interface GrokReport {@@ -129,8 +141,9 @@ export interface GrokReport {failed: string[];}-/** Imports each plan through the package path, then switches on its skills. One Bot failing is named and the rest carry on. */-export async function runGrokMove(preview: GrokPreview, dispatch: (action: Action) => void): Promise<GrokReport> {+/** Imports each plan through the package path, switches on its skills and, on the desktop app (`local`), brings its chat+ * over from the Grok Bot app there. One Bot failing is named and the rest carry on. */+export async function runGrokMove(preview: GrokPreview, dispatch: (action: Action) => void, local = false): Promise<GrokReport> {const report: GrokReport = { bots: [], moved: preview.moved, unreadable: preview.unreadable, failed: [] };for (const plan of preview.plans) {try {@@ -141,7 +154,9 @@ export async function runGrokMove(preview: GrokPreview, dispatch: (action: Actioconst on = skill.on && await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.folder)}`, { method: "PATCH", body: JSON.stringify({ enabled: true }) }).then(() => true, () => false);if (!on) skillsOff.push(skill.name);}- report.bots.push({ name: bot.name, skills: plan.skills.length, skillsOff, routines: plan.routines, notes: plan.notes, memories: plan.memories, apps: plan.apps });+ const history = local ? await bringHistory(bot.id, plan.name) : undefined;+ report.bots.push({ name: bot.name, skills: plan.skills.length, skillsOff, routines: plan.routines, notes: plan.notes, memories: plan.memories, apps: plan.apps,+ ...(history ? { history } : {}) });} catch {report.failed.push(plan.name);}diff --git a/src/locales/en.json b/src/locales/en.jsonindex f60f33e1f9..71ce0df209 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -8331,6 +8331,13 @@"grokMove.count.routines": "Routines","grokMove.count.memories": "Memories","grokMove.count.notes": "Routines saved as notes",+ "grokMove.count.messages": "Chat messages",+ "grokMove.historyPreview": "Each Bot's chat comes over too, from the Grok Bot app on this computer.",+ "grokMove.history.noApp": "No chat came over: the Grok Bot app isn't on this computer.",+ "grokMove.history.noMatch": "No chat came over: the Grok Bot app on this computer has no Bot with this name.",+ "grokMove.history.ambiguous": "No chat came over: several Bots in the Grok Bot app have this name.",+ "grokMove.history.empty": "No chat came over: the Grok Bot app has none saved for this Bot.",+ "grokMove.history.failed": "Its chat couldn't be brought over.","grokMove.pausedPreview": "Routines come over paused.","grokMove.pausedReport": "Routines are paused. Turn each one off in Grok Bot, then on here.","grokMove.filesStay": "Files on Grok Bot's computer don't come over. Add any your Bot needs.",