Skip to content

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

Ask which bots move on whichever page is open

Milind Soni28211ac8ffeb
diff --git a/electron/cloud-send-main.mjs b/electron/cloud-send-main.mjs
index de090bb93c..8c6a3b2f57 100644
--- a/electron/cloud-send-main.mjs
+++ b/electron/cloud-send-main.mjs
@@ -95,9 +95,7 @@ export function installCloudSend({ ipcMain, cloudPage, server, local, home, cook
/** The notice either page gets, with the one-time move's line when there is one. */
const notice = (snapshot) => {
const line = moving(), team = pageOf() === "cloud" ? teamMove()?.view() ?? null : null, bots = pageOf() === "local" ? botMove()?.view() ?? null : null;
- // Being asked which bots go is this computer's page's own.
- const shown = line?.phase === "choose" && pageOf() !== "local" ? null : line;
- return { ...sendNotice(snapshot), ...(shown ? { move: shown } : {}), ...(team ? { teamMove: team } : {}), ...(bots ? { botMove: bots } : {}) };
+ return { ...sendNotice(snapshot), ...(line ? { move: line } : {}), ...(team ? { teamMove: team } : {}), ...(bots ? { botMove: bots } : {}) };
};
const deliver = (snapshot) => {
if (pageOf()) window().webContents.send("cloud-send:notice-changed", notice(snapshot));
diff --git a/electron/cloud-send.d.mts b/electron/cloud-send.d.mts
index 45e37f0590..7c6d98698c 100644
--- a/electron/cloud-send.d.mts
+++ b/electron/cloud-send.d.mts
@@ -121,6 +121,8 @@ export interface CloudSendPageBridge {
openTeam?(teamId: string): Promise<void>;
/** On this computer's page: whether its bots can move to My Cloud now, and which are on their way. */
botMoveState?(): Promise<BotMoveState>;
+ /** The bots of this computer's a person can choose to move, asked on either page. */
+ botChoices?(): Promise<{ bots: Array<{ id: string; name: string }> }>;
/** Moves these bots to My Cloud; the others stay here and go on working. */
moveBots?(ids: string[]): Promise<BotMoveState>;
/** Moves everything to My Cloud: this computer's one-time move. */
diff --git a/electron/cloud-send.node-test.mjs b/electron/cloud-send.node-test.mjs
index a017c3fa52..86a313a3f4 100644
--- a/electron/cloud-send.node-test.mjs
+++ b/electron/cloud-send.node-test.mjs
@@ -203,7 +203,7 @@ function preload({ remote = false, activation = false } = {}) {
}
test("the bridge: either page gets only the move's line and the switch that keeps this computer's bots here; its Try again, moving a bot into a team, and turning that switch go only from the person's click on My Cloud's page", async () => {
- const keys = ["notice", "dismiss", "moveRetry", "teams", "moveToTeam", "moveToTeamCoded", "teamRetry", "openTeam", "teamBring", "teamBringMove", "teamBringStatus", "botMoveState", "moveBots", "moveEverything", "botMoveRetry", "openMyCloud", "keepHere", "setKeepHere", "onNotice"];
+ const keys = ["notice", "dismiss", "moveRetry", "teams", "moveToTeam", "moveToTeamCoded", "teamRetry", "openTeam", "teamBring", "teamBringMove", "teamBringStatus", "botMoveState", "botChoices", "moveBots", "moveEverything", "botMoveRetry", "openMyCloud", "keepHere", "setKeepHere", "onNotice"];
const local = preload();
assert.equal(local.bridge.cloudSend, undefined);
assert.equal(local.bridge.cloudLogins, undefined);
@@ -218,6 +218,8 @@ test("the bridge: either page gets only the move's line and the switch that keep
await assert.rejects(page.bridge.cloudSendPage.teamRetry(), /Try again/);
await assert.rejects(page.bridge.cloudSendPage.teamBringMove("scout"), /Choose Move/);
await assert.rejects(page.bridge.cloudSendPage.setKeepHere(true), /Turn the switch/);
+ await assert.rejects(page.bridge.cloudSendPage.moveBots(["scout"]), /Choose which bots/);
+ await assert.rejects(page.bridge.cloudSendPage.moveEverything(), /Choose which bots/);
await page.bridge.cloudSendPage.keepHere();
assert.deepEqual(page.invoked.filter(([channel]) => channel.startsWith("cloud-send") || channel === "one-home:keep-set"), []);
assert.deepEqual(page.invoked, [["one-home:keep"]], "reading the switch needs no click");
diff --git a/electron/one-home-main.mjs b/electron/one-home-main.mjs
index cab71e9502..c575fbc856 100644
--- a/electron/one-home-main.mjs
+++ b/electron/one-home-main.mjs
@@ -313,8 +313,10 @@ export function installOneHome({ localRequest: anyServer, clean = null, account,
return { available: cloudTakesBots() && (!moving || moving.phase === "back"), moving: botMove.moving() };
};
sendDeps.ipcMain.handle("cloud-send:bot-move-state", localPage("cloud-send:bot-move-state", botMoveState));
- // The bots come from this computer's own server, never from the page; the page only names which of them.
- sendDeps.ipcMain.handle("cloud-send:move-bots", localPage("cloud-send:move-bots", async (ids) => {
+ // Asked on whichever page is open: a person just back from buying My Cloud is looking at My Cloud. The bots come from this
+ // computer's own server, never from the page; the page only names which of them.
+ sendDeps.ipcMain.handle("cloud-send:bot-choices", onPage("cloud-send:bot-choices", async () => ({ bots: (await botsHere()).map((bot) => ({ id: bot.id, name: bot.name })) })));
+ sendDeps.ipcMain.handle("cloud-send:move-bots", onPage("cloud-send:move-bots", async (ids) => {
if (!botMoveState().available) throw new Error(t("native.cloud.keepNoCloud"));
const asked = new Set(Array.isArray(ids) ? ids.map(String) : []);
const bots = (await botsHere()).filter((bot) => asked.has(bot.id)).map((bot) => ({ id: bot.id, name: bot.name }));
@@ -324,7 +326,7 @@ export function installOneHome({ localRequest: anyServer, clean = null, account,
botMove.start(bots, oneHomeCloud(account()?.state())?.account ?? null);
return botMoveState();
}));
- sendDeps.ipcMain.handle("cloud-send:move-everything", localPage("cloud-send:move-everything", () => {
+ sendDeps.ipcMain.handle("cloud-send:move-everything", onPage("cloud-send:move-everything", () => {
choice.write({ v: 1, answered: true });
void botMove.drop().catch((error) => log(`bot move: ${error?.message ?? error}`));
void home.keep(false).catch((error) => log(`one home: ${error?.message ?? error}`));
diff --git a/electron/one-home-main.node-test.mjs b/electron/one-home-main.node-test.mjs
index a22697ff29..295274e228 100644
--- a/electron/one-home-main.node-test.mjs
+++ b/electron/one-home-main.node-test.mjs
@@ -157,7 +157,7 @@ test("the team bring handlers receive the same dynamic translator as one home",
} finally { main.close(); }
});
-test("a first move waits for the person's choice, asked on this computer's page only; with one bot there is nothing to choose", async () => {
+test("a first move waits for the person's choice, asked on whichever page is open; with one bot there is nothing to choose", async () => {
const CLOUD = "https://omb-t-1.fly.dev";
const folder = mkdtempSync(join(tmpdir(), "omb-move-choice-"));
const launch = (bots) => {
@@ -181,10 +181,11 @@ test("a first move waits for the person's choice, asked on this computer's page
assert.equal(asked.kept(), null, "nothing starts by itself");
assert.deepEqual(asked.ask("cloud-send:notice", "local").move, { phase: "choose" });
asked.show(`${CLOUD}/`);
- assert.equal(asked.ask("cloud-send:notice", "cloud").move, undefined, "My Cloud's page is not asked");
- asked.show("http://127.0.0.1:4100/");
- assert.throws(() => asked.ask("cloud-send:move-everything", "cloud"), /only available on this computer's page/u);
- asked.ask("cloud-send:move-everything", "local");
+ assert.deepEqual(asked.ask("cloud-send:notice", "cloud").move, { phase: "choose" }, "someone back from buying My Cloud is looking at it, and is asked there");
+ assert.deepEqual((await asked.ask("cloud-send:bot-choices", "cloud")).bots.map((bot) => bot.id), ["b0", "b1", "b2"], "this computer's bots, whichever page asks");
+ assert.throws(() => asked.ask("cloud-send:bot-move-state", "cloud"), /only available on this computer's page/u);
+ assert.throws(() => asked.ask("cloud-send:move-everything", null), /only available/u);
+ asked.ask("cloud-send:move-everything", "cloud");
await asked.main.kick();
assert.equal(asked.kept()?.phase, "copy", "Move everything starts the one-time move");
diff --git a/electron/preload.cjs b/electron/preload.cjs
index 78bee5a11f..100c0c0460 100644
--- a/electron/preload.cjs
+++ b/electron/preload.cjs
@@ -527,10 +527,13 @@ const bridge = {
teamBringMove: botId => navigator.userActivation?.isActive === true
? ipcRenderer.invoke("cloud-send:team-bring-move", String(botId)) : Promise.reject(new Error("Choose Move to move the bot.")),
teamBringStatus: () => ipcRenderer.invoke("cloud-send:team-bring-status"),
- // This computer's page: which of its bots move to My Cloud. Main refuses every other page.
+ // Which of this computer's bots move to My Cloud: asked on either page, and only from the person's click on My Cloud's.
botMoveState: () => ipcRenderer.invoke("cloud-send:bot-move-state"),
- moveBots: ids => ipcRenderer.invoke("cloud-send:move-bots", Array.isArray(ids) ? ids.map(String) : []),
- moveEverything: () => ipcRenderer.invoke("cloud-send:move-everything"),
+ botChoices: () => ipcRenderer.invoke("cloud-send:bot-choices"),
+ moveBots: ids => isLocalPage || navigator.userActivation?.isActive === true
+ ? ipcRenderer.invoke("cloud-send:move-bots", Array.isArray(ids) ? ids.map(String) : []) : Promise.reject(new Error("Choose which bots move.")),
+ moveEverything: () => isLocalPage || navigator.userActivation?.isActive === true
+ ? ipcRenderer.invoke("cloud-send:move-everything") : Promise.reject(new Error("Choose which bots move.")),
botMoveRetry: () => ipcRenderer.invoke("cloud-send:bot-move-retry"),
openMyCloud: () => ipcRenderer.invoke("cloud-send:open-my-cloud"),
// Settings → MausBot Cloud, Advanced: "Keep this computer's bots on this computer".
diff --git a/src/components/CloudSendStrip.tsx b/src/components/CloudSendStrip.tsx
index 6408025645..eca307a51d 100644
--- a/src/components/CloudSendStrip.tsx
+++ b/src/components/CloudSendStrip.tsx
@@ -43,9 +43,9 @@ export function CloudSendStrip({ cloudHome }: { cloudHome: boolean }) {
const [notice, setNotice] = useCloudSendNotice(bridge);
const [notNow, setNotNow] = useState(false);
if (!bridge || !notice) return null;
- if (cloudHome) return notice.teamMove ? <TeamMoveLine move={notice.teamMove} onChange={(next) => setNotice({ ...notice, teamMove: next ?? undefined })} /> : null;
return <>
{notice.move?.phase === "choose" && !notNow && <MoveChooser onClose={() => setNotNow(true)} />}
- {notice.botMove && <BotMoveLine move={notice.botMove} onChange={(next) => setNotice({ ...notice, botMove: next ?? undefined })} />}
+ {cloudHome && notice.teamMove && <TeamMoveLine move={notice.teamMove} onChange={(next) => setNotice({ ...notice, teamMove: next ?? undefined })} />}
+ {!cloudHome && notice.botMove && <BotMoveLine move={notice.botMove} onChange={(next) => setNotice({ ...notice, botMove: next ?? undefined })} />}
</>;
}
diff --git a/src/components/MoveToMyCloud.dom.test.ts b/src/components/MoveToMyCloud.dom.test.ts
index fd587d98bd..9bde6d3d43 100644
--- a/src/components/MoveToMyCloud.dom.test.ts
+++ b/src/components/MoveToMyCloud.dom.test.ts
@@ -3,20 +3,18 @@ import { act, createElement } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
-const fixture = vi.hoisted(() => ({ bots: [] as Array<Record<string, unknown>> }));
-vi.mock("@/state/store", () => ({ useStore: () => ({ state: { bots: fixture.bots }, dispatch: () => {} }) }));
-vi.mock("./Avatar", () => ({ BotAvatar: () => null }));
+const fixture = vi.hoisted(() => ({ bots: [] as Array<{ id: string; name: string }> }));
import { BotMoveLine, MoveChooser, MovedToMyCloudRow, useMoveToMyCloud } from "./MoveToMyCloud";
let container: HTMLDivElement, root: Root;
-const page = { moveBots: vi.fn(async () => ({ available: true, moving: [] })), moveEverything: vi.fn(async () => ({ available: true, moving: [] })), botMoveState: vi.fn(async () => ({ available: true, moving: ["moving-one"] })),
+const page = { botChoices: vi.fn(async () => ({ bots: fixture.bots })), moveBots: vi.fn(async () => ({ available: true, moving: [] })), moveEverything: vi.fn(async () => ({ available: true, moving: [] })), botMoveState: vi.fn(async () => ({ available: true, moving: ["moving-one"] })),
openMyCloud: vi.fn(async () => {}), botMoveRetry: vi.fn(async () => null), dismiss: vi.fn(async () => ({})) };
const onClose = vi.fn();
const named = (count: number) => Array.from({ length: count }, (_, i) => ({ id: `b${i}`, name: i % 2 ? `Sales ${i}` : `Ops ${i}` }));
const q = (selector: string) => document.body.querySelector<HTMLElement>(selector);
const all = (selector: string) => [...document.body.querySelectorAll<HTMLElement>(selector)];
const click = async (element: HTMLElement | null) => { expect(element).toBeTruthy(); await act(async () => element!.click()); };
-const render = async (bots: Array<Record<string, unknown>>) => { fixture.bots = bots; await act(async () => root.render(createElement(MoveChooser, { onClose }))); };
+const render = async (bots: Array<{ id: string; name: string }>) => { fixture.bots = bots; await act(async () => root.render(createElement(MoveChooser, { onClose }))); await act(async () => {}); };
async function type(value: string) {
const field = q("[data-move-search]") as HTMLInputElement;
await act(async () => {
@@ -52,8 +50,9 @@ it("moves only the bots ticked, and says how many", async () => {
expect(page.moveBots).toHaveBeenCalledWith(["b1", "b3"]);
});
-it("never offers the helper every place has, an archived bot, or one that moved", async () => {
- await render([{ id: "a", name: "Ada" }, { id: "d", name: "Maus", defaultBot: { v: 1 } }, { id: "h", name: "Old", hidden: true }, { id: "m", name: "Gone", movedTo: { state: "moved", team: { id: "my-cloud" } } }]);
+it("offers the bots main lists, whichever page asks: a page's own bots are never what is moved", async () => {
+ await render([{ id: "a", name: "Ada" }]);
+ expect(page.botChoices).toHaveBeenCalled();
expect(all("[data-move-bot]").map((row) => row.dataset.moveBot)).toEqual(["a"]);
});
diff --git a/src/components/MoveToMyCloud.tsx b/src/components/MoveToMyCloud.tsx
index b464fabe18..81b9aba7d7 100644
--- a/src/components/MoveToMyCloud.tsx
+++ b/src/components/MoveToMyCloud.tsx
@@ -5,10 +5,9 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { createPortal } from "react-dom";
import { ArrowRightLeft, Check, Cloud, Loader2, X } from "lucide-react";
import type { BotMoveState, BotMoveView } from "../../electron/cloud-send.mjs";
-import { botMoveLine, chooserBots, filterBots, ipcErrorText, CHOOSER_PAGE, MY_CLOUD_TEAM } from "@/lib/cloud-send";
+import { botMoveLine, filterBots, ipcErrorText, CHOOSER_PAGE, MY_CLOUD_TEAM } from "@/lib/cloud-send";
import { t } from "@/lib/i18n";
-import { useStore, type Bot } from "@/state/store";
-import { BotAvatar } from "./Avatar";
+import type { Bot } from "@/state/store";
import { ConfirmDialog } from "./ConfirmDialog";
import { NotNowButton, PRIMARY_BUTTON } from "./NoticeCard";
@@ -18,15 +17,19 @@ const bridge = () => (!window.ogb?.remoteClient?.active ? window.ogb?.cloudSendP
/** Which bots go to My Cloud: any of them, found by name, or everything with one press. */
export function MoveChooser({ onClose }: { onClose: () => void }) {
- const { state } = useStore();
- const bots = useMemo(() => chooserBots(state.bots), [state.bots]);
+ const [bots, setBots] = useState<ReadonlyArray<{ id: string; name: string }> | null>(null);
+ useEffect(() => {
+ let alive = true;
+ void bridge()?.botChoices?.().then((answer) => { if (alive) setBots(answer.bots); }, () => { if (alive) setBots([]); });
+ return () => { alive = false; };
+ }, []);
const [query, setQuery] = useState("");
const [chosen, setChosen] = useState<ReadonlySet<string>>(new Set());
const [shown, setShown] = useState(CHOOSER_PAGE);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const root = useRef<HTMLDivElement>(null);
- const found = useMemo(() => filterBots(bots, query), [bots, query]);
+ const found = useMemo(() => filterBots(bots ?? [], query), [bots, query]);
const allFound = found.length > 0 && found.every((bot) => chosen.has(bot.id));
useEffect(() => {
root.current?.querySelector<HTMLElement>("input")?.focus();
@@ -70,13 +73,12 @@ export function MoveChooser({ onClose }: { onClose: () => void }) {
const on = chosen.has(bot.id);
return <li key={bot.id}>
<button type="button" role="checkbox" aria-checked={on} data-move-bot={bot.id} onClick={() => toggle(bot.id)} className="flex w-full items-center gap-2.5 px-3 py-2 text-start text-[14px] hover:bg-raised">
- <BotAvatar bot={bot} size={22} animated={false} />
<span className="min-w-0 flex-1 truncate" dir="auto">{bot.name}</span>
{on && <Check size={15} aria-hidden="true" />}
</button>
</li>;
})}
- {!found.length && <li className="px-3 py-3 text-[13px] text-ink-tertiary">{t("cloudSend.choose.none")}</li>}
+ {bots !== null && !found.length && <li className="px-3 py-3 text-[13px] text-ink-tertiary">{t("cloudSend.choose.none")}</li>}
{found.length > shown && <li><button type="button" data-move-more="" className="w-full px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised" onClick={() => setShown((count) => count + CHOOSER_PAGE)}>
{t("cloudSend.choose.more", { count: found.length - shown })}
</button></li>}
diff --git a/src/lib/cloud-send.test.ts b/src/lib/cloud-send.test.ts
index adb91d346b..8de5747e89 100644
--- a/src/lib/cloud-send.test.ts
+++ b/src/lib/cloud-send.test.ts
@@ -3,17 +3,13 @@ import { setLocale } from "@/lib/i18n";
import { readFileSync } from "node:fs";
import en from "@/locales/en.json";
import ptBr from "@/locales/pt-br.json";
-import { botMoveLine, chooserBots, filterBots, ipcErrorText, moveLine, moveQuietUntil } from "./cloud-send";
+import { botMoveLine, filterBots, ipcErrorText, moveLine, moveQuietUntil } from "./cloud-send";
beforeEach(() => { setLocale("en"); });
afterEach(() => { setLocale("en"); });
describe("choosing which bots move", () => {
- const bot = (id: string, name: string, extra: { hidden?: boolean; defaultBot?: unknown; movedTo?: unknown } = {}) => ({ id, name, ...extra });
-
- it("offers every bot but the helper every place has, an archived one, or one that moved", () => {
- expect(chooserBots([bot("a", "Ada"), bot("d", "Maus", { defaultBot: { v: 1 } }), bot("h", "Old", { hidden: true }), bot("m", "Gone", { movedTo: { state: "moved" } })]).map((entry) => entry.id)).toEqual(["a"]);
- });
+ const bot = (id: string, name: string) => ({ id, name });
it("finds bots by every word of what is typed, in any case, and finds thousands at once", () => {
const bots = Array.from({ length: 50_000 }, (_, i) => bot(`b${i}`, `Sales Bot ${i}`));
diff --git a/src/lib/cloud-send.ts b/src/lib/cloud-send.ts
index 23d1c30ab5..b9a6c84a68 100644
--- a/src/lib/cloud-send.ts
+++ b/src/lib/cloud-send.ts
@@ -15,6 +15,7 @@ const BRIDGE_REFUSALS: Readonly<Record<string, LocaleKey>> = {
"Turn the switch to keep this computer's bots here.": "cloudAccount.keepHere.unclicked",
"Choose Try again to move.": "cloudSend.move.unclicked",
"Choose Move to move the bot.": "teamMove.unclicked",
+ "Choose which bots move.": "cloudSend.choose.unclicked",
};
/** The words main threw, without Electron's "Error invoking remote method" wrapper; null when there are none. */
@@ -163,8 +164,6 @@ function ownMoveLine(move: OneHomeView, place: string, page: "local" | "cloud"):
/** The "team" a bot that moved from this computer to My Cloud is held for (electron/bot-move-main.mjs). */
export const MY_CLOUD_TEAM = "my-cloud";
-/** The bots the person can choose to move: as the sidebar has them, but the helper every place has and any that moved. */
-export const chooserBots = <T extends { hidden?: boolean; defaultBot?: unknown; movedTo?: unknown }>(bots: readonly T[]): T[] => bots.filter((bot) => !bot.hidden && !bot.defaultBot && !bot.movedTo);
/** How many of the choice the list shows at a time, however many bots there are. */
export const CHOOSER_PAGE = 200;
/** The bots whose names hold every word of `query`. */
diff --git a/src/locales/en.json b/src/locales/en.json
index 12e0be5b26..e5eb77da11 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -1377,6 +1377,7 @@
"cloudSend.choose.more": "Show {count} more",
"cloudSend.choose.rooms": "A room moves when all of its bots do.",
"cloudSend.choose.failed": "Couldn't start the move. Try again.",
+ "cloudSend.choose.unclicked": "Choose which bots move.",
"cloudSend.botMove.menu": "Move to My Cloud",
"cloudSend.botMove.confirmTitle": "Move {bot} to My Cloud?",
"cloudSend.botMove.confirmBody": "{bot}'s chats, skills, memory and routines go with it, and it works on My Cloud from then on. Your other bots stay on this computer.",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 5ae1a39f01..8b8aa45a5e 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -7184,6 +7184,7 @@
"cloudSend.choose.more": "Mostrar mais {count}",
"cloudSend.choose.rooms": "Uma sala vai quando todos os bots dela vão.",
"cloudSend.choose.failed": "Não foi possível iniciar a mudança. Tente de novo.",
+ "cloudSend.choose.unclicked": "Escolha quais bots vão.",
"cloudSend.botMove.menu": "Levar para o Cloud",
"cloudSend.botMove.confirmTitle": "Levar {bot} para o Cloud?",
"cloudSend.botMove.confirmBody": "As conversas, skills, memória e rotinas de {bot} vão junto, e a partir daí ele trabalha no Cloud. Seus outros bots ficam neste computador.",