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: a second move brings the chat into Bots already moved
aivsomkare1f8795f8969
diff --git a/src/components/GrokMoveDialog.test.ts b/src/components/GrokMoveDialog.test.tsindex 24c7346fc8..79e7b9eda3 100644--- a/src/components/GrokMoveDialog.test.ts+++ b/src/components/GrokMoveDialog.test.ts@@ -137,7 +137,7 @@ describe("Move from Grok Bot", () => {await paste(QUIET);const plan = (await import("@/lib/grok-move")).previewGrokMove;const { plans } = plan(JSON.parse(QUIET).bots.map((bot: object) => ({ ...bot, title: "", description: "", memories: [], userFacts: [], skills: [], routines: [], apps: [] })), { bots: [], servers: new Set(), timeZone: "UTC" });- f.state = { config: {}, bots: [{ name: "Quiet", installedPackage: { id: plans[0]!.packageId, name: "Quiet" } }] };+ f.state = { config: {}, bots: [{ id: "here-Quiet", name: "Quiet", installedPackage: { id: plans[0]!.packageId, name: "Quiet" } }] };await act(async () => root.unmount());root = createRoot(host);await open();diff --git a/src/components/GrokMoveDialog.tsx b/src/components/GrokMoveDialog.tsxindex 0ce4deb9b2..3fd1316ddd 100644--- a/src/components/GrokMoveDialog.tsx+++ b/src/components/GrokMoveDialog.tsx@@ -307,8 +307,12 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi{report ? (<>{report.bots.map((bot) => <BotCounts key={bot.name} heading={t("grokMove.isHere", { name: bot.name })} {...bot} />)}+ {report.moved.flatMap(({ name, history }) => !history ? [] : [+ <p key={name} className={LINE}>{"messages" in history ? t("grokMove.movedChat", { name, count: history.messages })+ : t("grokMove.movedNoChat", { name, why: t(`grokMove.history.${history.reason}` as LocaleKey) })}</p>,+ ])}<GrokMoveLines paused={report.bots.some((bot) => bot.routines > 0) ? t("grokMove.pausedReport") : null} files={t("grokMove.filesStay")} apps={report.bots.reduce((total, bot) => total + bot.apps, 0)}- moved={report.moved} unreadable={report.unreadable} failed={report.failed} />+ moved={report.moved.flatMap(({ name, history }) => history ? [] : [name])} unreadable={report.unreadable} failed={report.failed} /></>) : preview ? (<>@@ -318,7 +322,8 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi))}<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} />+ moved={local ? [] : preview.moved.map(({ name }) => name)} unreadable={preview.unreadable} />+ {local && preview.moved.length > 0 && <p className={LINE}>{t("grokMove.alreadyHereChats", { names: preview.moved.map(({ name }) => name).join(", ") })}</p>}</>) : (<BringBack local={local} look={look} found={found} reply={reply} error={error} onReply={setReply}@@ -339,7 +344,7 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi) : preview ? (<><button type="button" disabled={importing} onClick={() => setPreview(null)} className={SECONDARY}>{t("grokMove.back")}</button>- <button type="button" data-grok-move-import disabled={importing || !preview.plans.length} onClick={() => void start()} className={cn(PRIMARY, "inline-flex items-center gap-2")}>+ <button type="button" data-grok-move-import disabled={importing || !(preview.plans.length || (local && preview.moved.length))} onClick={() => void start()} className={cn(PRIMARY, "inline-flex items-center gap-2")}>{importing && <Loader2 size={15} className="animate-spin" />}{importing ? t("grokMove.importing") : t("grokMove.import")}</button>diff --git a/src/lib/grok-move.test.ts b/src/lib/grok-move.test.tsindex e07b58132d..52a2fdc831 100644--- a/src/lib/grok-move.test.ts+++ b/src/lib/grok-move.test.ts@@ -59,10 +59,19 @@ describe("the preview", () => {it("names a Bot already moved instead of copying it; a taken name only renumbers", () => {const first = previewGrokMove(bots(DESK), facts()).plans[0]!;- const again = previewGrokMove(bots(DESK), facts({ bots: [{ name: "Desk", installedPackage: { id: first.packageId, name: "Desk" } as never }] }));+ const again = previewGrokMove(bots(DESK), facts({ bots: [{ id: "here-Desk", name: "Desk", installedPackage: { id: first.packageId, name: "Desk" } as never }] }));expect(again.plans).toEqual([]);- expect(again.moved).toEqual(["Desk"]);- expect(previewGrokMove(bots(DESK), facts({ bots: [{ name: "Desk" }] })).plans[0]!.addedAs).toBe("Desk 2");+ expect(again.moved).toEqual([{ name: "Desk", botId: "here-Desk" }]);+ expect(previewGrokMove(bots(DESK), facts({ bots: [{ id: "other", name: "Desk" }] })).plans[0]!.addedAs).toBe("Desk 2");+ });++ it("a Bot moved before gets its chat on a second move, into the bot already here, and nothing else is imported", async () => {+ const first = previewGrokMove(bots(DESK), facts()).plans[0]!;+ fixture.history = { messages: 214 };+ const report = await runGrokMove(previewGrokMove(bots(DESK), facts({ bots: [{ id: "here-Desk", name: "Desk", installedPackage: { id: first.packageId, name: "Desk" } as never }] })), vi.fn(), true);+ expect(fixture.requests).toEqual([["/api/setup-import/grok/history", "POST", { botId: "here-Desk", grokName: "Desk" }]]);+ expect(report.moved).toEqual([{ name: "Desk", history: { messages: 214 } }]);+ expect(report.bots).toEqual([]);});});diff --git a/src/lib/grok-move.ts b/src/lib/grok-move.tsindex fd198e671a..06c423bcfa 100644--- a/src/lib/grok-move.ts+++ b/src/lib/grok-move.ts@@ -79,27 +79,29 @@ export function foundExports(files: GrokLook["files"]): FoundExports {export interface GrokPreview {/** `addedAs`: the Bot's name here, numbered when it is taken. */plans: Array<GrokMovePlan & { addedAs: string }>;- moved: string[];+ /** Bots moved before: `botId` is the bot here, so the move can still bring its chat. */+ moved: Array<{ name: string; botId: string }>;unreadable: string[];}export interface GrokPreviewFacts {- bots: readonly Pick<Bot, "name" | "installedPackage">[];+ bots: readonly Pick<Bot, "id" | "name" | "installedPackage">[];servers: ReadonlySet<string>;timeZone: string;}/** The whole plan, nothing written. A Bot already moved or that can't be read is named, and costs the others nothing. */export function previewGrokMove(bots: readonly GrokBot[], facts: GrokPreviewFacts): GrokPreview {- const installed = new Set(facts.bots.flatMap((bot) => bot.installedPackage?.id ?? []));+ const installed = new Map(facts.bots.flatMap((bot) => bot.installedPackage ? [[bot.installedPackage.id, bot.id] as const] : []));const names = new Set(facts.bots.map((bot) => bot.name.trim().toLowerCase()));const servers = new Set(facts.servers);const preview: GrokPreview = { plans: [], moved: [], unreadable: [] };for (const bot of bots) {try {const plan = grokMovePlan(bot, { timeZone: facts.timeZone, takenServers: servers });- if (installed.has(plan.packageId)) {- preview.moved.push(plan.name);+ const here = installed.get(plan.packageId);+ if (here) {+ preview.moved.push({ name: plan.name, botId: here });continue;}for (const connection of plan.document.package.connections ?? []) servers.add(connection.key);@@ -136,7 +138,8 @@ export interface GrokMovedBot {export interface GrokReport {bots: GrokMovedBot[];- moved: string[];+ /** Bots moved before; `history` is their chat, brought now on the desktop app. */+ moved: Array<{ name: string; history?: GrokHistory }>;unreadable: string[];failed: string[];}@@ -144,7 +147,11 @@ export interface 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: [] };+ const report: GrokReport = { bots: [], moved: [], unreadable: preview.unreadable, failed: [] };+ for (const { name, botId } of preview.moved) {+ const history = local ? await bringHistory(botId, name) : undefined;+ report.moved.push({ name, ...(history ? { history } : {}) });+ }for (const plan of preview.plans) {try {const bot = (await addTemplate(plan.document, dispatch)).first;diff --git a/src/locales/en.json b/src/locales/en.jsonindex a8a531119b..30c5120ce3 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -8338,6 +8338,9 @@"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.alreadyHereChats": "Already here: {names}. Import brings over their chats.",+ "grokMove.movedChat": "{name} was already here. Its chat came over: {count} messages, in “Chat from Grok Bot”.",+ "grokMove.movedNoChat": "{name} was already here. {why}","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.",