Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(electron): return empty teams outside My Cloud instead of crashing IPC (#4170)
Lixin2026c2c15e9b2efb
diff --git a/electron/cloud-send.node-test.mjs b/electron/cloud-send.node-test.mjsindex 2330a91a68..d36aa90bb5 100644--- a/electron/cloud-send.node-test.mjs+++ b/electron/cloud-send.node-test.mjs@@ -8,6 +8,7 @@ import vm from "node:vm";import { BOT_PARTS, differenceSignature, itemKey, parseSendSummary, pendingRows, planSend } from "./cloud-send-parts.mjs";import { botPatch, CloudSendError, createCloudSend, parseSendState, sendNotice, unanswered } from "./cloud-send.mjs";import { installCloudSend, openOwnerSession } from "./cloud-send-main.mjs";+import { installTeamMove } from "./team-move-main.mjs";const LOCAL = "http://127.0.0.1:4100";const CLOUD = "https://omb-u-1.fly.dev";@@ -172,6 +173,21 @@ test("either page asks only for the move's line, its Try again and closing it; n}});+test("cloud-send:teams returns empty teams outside My Cloud without throwing", async () => {+ const handlers = new Map();+ installTeamMove({+ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) },+ cloudPage: (event) => event.page ?? null,+ home: () => ({ origin: CLOUD, grant: async () => ({ origin: CLOUD, code: "C" }) }),+ account: () => ({ state: () => ({ status: "connected", teams: [{ id: "team-acme", name: "Acme Corp", machine: { origin: CLOUD, status: "ready" } }] }) }),+ file: () => "/nonexistent/cloud-send.json",+ journalFile: () => "/nonexistent/team-move.json",+ });+ assert.deepEqual(await handlers.get("cloud-send:teams")({ page: "local" }), { teams: [] }, "local page gets empty teams");+ assert.deepEqual(await handlers.get("cloud-send:teams")({ page: null }), { teams: [] }, "no page context gets empty teams");+ assert.deepEqual(await handlers.get("cloud-send:teams")({ page: "cloud" }), { teams: [{ id: "team-acme", name: "Acme Corp", ready: true }] }, "My Cloud page gets actual teams");+});+function preload({ remote = false, activation = false } = {}) {let bridge; const invoked = [];vm.runInNewContext(readFileSync(new URL("./preload.cjs", import.meta.url), "utf8"), {diff --git a/electron/team-move-main.mjs b/electron/team-move-main.mjsindex d2f09f01eb..2c93c57f0d 100644--- a/electron/team-move-main.mjs+++ b/electron/team-move-main.mjs@@ -169,7 +169,12 @@ export function installTeamMove({ ipcMain, cloudPage, home, account, file, journif (cloudPage(event) !== "cloud") throw new Error(`${channel} is only available on My Cloud in this app`);return handler(...args);};- ipcMain.handle("cloud-send:teams", myCloudPage("cloud-send:teams", () => ({ teams: teams().map(({ id, name, ready }) => ({ id, name, ready })) })));+ // The page asks on every server, including a solo app and a custom base URL. Electron reports a throw from this+ // handler as "Error occurred in handler for 'cloud-send:teams'" and the desktop window dies, so anywhere but My Cloud the answer is no teams.+ ipcMain.handle("cloud-send:teams", (event) => {+ if (cloudPage(event) !== "cloud") return { teams: [] };+ return { teams: teams().map(({ id, name, ready }) => ({ id, name, ready })) };+ });ipcMain.handle("cloud-send:team-move", myCloudPage("cloud-send:team-move", (botId, teamId, name) => {const team = teamOf(String(teamId));if (!team) throw new Error("You're not in that team.");