Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(cloud home): the saved place of My Cloud follows the account's machine, and takes the Admin's name for it (#4070)
Milind Sonieb3f8176bb63
diff --git a/electron/cloud-home.node-test.mjs b/electron/cloud-home.node-test.mjsindex bbf3fccf3a..76ed07a88e 100644--- a/electron/cloud-home.node-test.mjs+++ b/electron/cloud-home.node-test.mjs@@ -6,6 +6,7 @@ import vm from "node:vm";import { createCloudAccountClient } from "./cloud-account.mjs";import { CLOUD_HOME_NAME, cloudHomeConnectUrl, cloudPlanDisk, cloudUnreachableText, isCloudHomeEntry, parseCloudCredit, parseCloudOffer, parseCloudPower, parseCloudPurchase, parseCloudSummary, parseCloudTeams, teamRoleLabel, CLOUD_TEAM_ROLES, parseCloudTrial, parsePairingGrant, parsePublicOffer, rememberedCloudHome, savedCloudHomeOrigin, withCloudHome, withoutTrial } from "./cloud-home.mjs";import environments from "./environments.cjs";+import { homeLook, withoutOldCloudHome } from "./cloud-list.mjs";const NOW = 1_800_000_000_000;const origin = "https://omb-u-1a2b3c4d5e6f.fly.dev";@@ -203,7 +204,7 @@ test("main lists the machine from verified states only, and connects without a dconst context = vm.createContext({environmentsState: { environments: [], activeId: environments.LOCAL_ID },persistEnvironments: next => { persisted.push(next); context.environmentsState = next; },- navigateMainWindow: url => navigated.push(url), withCloudHome, withActive: environments.withActive, cloudLook: { pending: () => look },+ navigateMainWindow: url => navigated.push(url), withCloudHome, withoutOldCloudHome, homeLook, withActive: environments.withActive, cloudLook: { pending: () => look },randomUUID: () => "cloud-home-id", slog: () => {}, Date: { now: () => NOW }, AbortSignal: { timeout: ms => ({ timeoutMs: ms }) },session: { defaultSession: { fetch: async (url, init) => { probes.push([url, init.credentials, init.signal.timeoutMs]); return { ok: false, json: async () => ({}) }; } } },dialog: { showMessageBox: async () => { dialogs.push(1); return { response: 1 }; } },diff --git a/electron/cloud-list.d.mts b/electron/cloud-list.d.mtsindex e328962bb8..337198e175 100644--- a/electron/cloud-list.d.mts+++ b/electron/cloud-list.d.mts@@ -69,3 +69,5 @@ export declare function cloudSetupProgress(cloud: CloudListEntry | null | undefiexport declare function swatchColor(swatch: unknown): import("./cloud-buy.mjs").CloudColor | null;export declare function listedColors(clouds: CloudListEntry[] | null | undefined): Array<{ home?: true; teamId?: string; color: import("./cloud-buy.mjs").CloudColor | null }>;export declare function ownCloudPlaces(clouds: CloudListEntry[] | null | undefined): Array<{ id: string; role: string; name: string; color: import("./cloud-buy.mjs").CloudColor | null; origin: string }>;+export declare function withoutOldCloudHome<T extends { environments: any[]; activeId: string }>(saved: T, state: unknown): T;+export declare function homeLook(state: unknown): { name: string; color: string | null } | null;diff --git a/electron/cloud-list.mjs b/electron/cloud-list.mjsindex 8af4fda7bf..486cd0fba3 100644--- a/electron/cloud-list.mjs+++ b/electron/cloud-list.mjs@@ -186,3 +186,29 @@ export function listedColors(clouds) {export function ownCloudPlaces(clouds) {return otherOwnClouds(clouds).filter(cloud => cloud.origin).map(cloud => ({ id: cloud.id, role: cloud.role, name: cloud.name, color: swatchColor(cloud.color), origin: cloud.origin }));}++/** The saved places once the session says where the account's own machine is: the place listed as home at another+ * address was My Cloud before this one. It leaves the list when the session's list has it as ended, or not at all;+ * otherwise (still one of the person's Clouds, or an Admin without the list) it stays, as a place of its own. */+export function withoutOldCloudHome(saved, state) {+ const machine = state?.status === "connected" ? state.machine : null;+ if (!machine?.origin || machine.status === "provisioning") return saved;+ const clouds = state.clouds;+ let next = saved;+ for (const entry of saved.environments) {+ if (entry.home !== true || entry.origin === machine.origin) continue;+ const listed = Array.isArray(clouds) ? clouds.find(cloud => cloud.origin === entry.origin) ?? null : null;+ if (Array.isArray(clouds) && (!listed || cloudState(listed) === "ended")) { next = environments.withoutEnvironment(next, entry.id); continue; }+ const { home: _home, ...rest } = entry;+ next = { ...next, environments: next.environments.map(candidate => (candidate.id === entry.id ? rest : candidate)) };+ }+ return next;+}++/** The name and colour the Admin lists the account's own machine's Cloud under, for its saved place; null when the+ * session lists none. */+export function homeLook(state) {+ const machine = state?.status === "connected" ? state.machine : null;+ const listed = machine?.origin && Array.isArray(state.clouds) ? state.clouds.find(cloud => ownCloud(cloud) && cloud.origin === machine.origin) : null;+ return listed?.name ? { name: listed.name, color: swatchColor(listed.color) } : null;+}diff --git a/electron/cloud-list.node-test.mjs b/electron/cloud-list.node-test.mjsindex a1661a713d..700807cc36 100644--- a/electron/cloud-list.node-test.mjs+++ b/electron/cloud-list.node-test.mjs@@ -1,7 +1,7 @@import assert from "node:assert/strict";import test from "node:test";-import { cloudMachine, cloudSetupProgress, cloudState, listedColors, MAX_CLOUDS, olderRelease, otherOwnClouds, ownCloudPlaces, parseCloudList, parseCloudRenewal, parseOrganizations, releaseVersion, signedInServers, swatchColor } from "./cloud-list.mjs";+import { cloudMachine, cloudSetupProgress, cloudState, homeLook, listedColors, MAX_CLOUDS, olderRelease, otherOwnClouds, ownCloudPlaces, parseCloudList, parseCloudRenewal, parseOrganizations, releaseVersion, withoutOldCloudHome, signedInServers, swatchColor } from "./cloud-list.mjs";import environments from "./environments.cjs";import { createHomePlaces } from "./home-places.mjs";@@ -208,3 +208,32 @@ test("the session's organizations: the Team plan this account runs them for, whefor (const bad of [null, "x", [], { ...plan, planCloudId: "../x" }, { ...plan, planCloudId: 7 }, { ...plan, canAdd: "yes" }, { ...plan, count: -1 }, { ...plan, count: 1.5 },{ ...plan, max: 0 }, { ...plan, max: "10" }]) assert.equal(parseOrganizations(bad), null, JSON.stringify(bad));});++test("once the account's machine is elsewhere, the place listed as home before leaves home: gone when the list has it ended or not at all, kept as a place of its own otherwise", () => {+ const old = "https://omb-u-old.fly.dev", now = "https://omb-u-new.fly.dev";+ const garage = { id: "g", kind: "remote", name: "Garage", origin: "https://garage.example.test" };+ const saved = { environments: [{ id: "old", kind: "remote", name: "My Cloud", origin: old, home: true }, garage], activeId: "old" };+ const at = (clouds) => ({ status: "connected", machine: { status: "ready", origin: now }, clouds });+ const ended = withoutOldCloudHome(saved, at([cloud({ id: "c-old", name: "Delete Me", origin: old, status: "ended" }), cloud({ id: "c-new", name: "Anagama", origin: now, primary: true })]));+ assert.deepEqual(ended.environments, [garage], "the ended one leaves the list");+ assert.equal(ended.activeId, environments.LOCAL_ID, "and the window comes back to this computer when it was open there");+ assert.deepEqual(withoutOldCloudHome(saved, at([cloud({ id: "c-new", origin: now, primary: true })])).environments, [garage], "one the list no longer has leaves too");+ const alive = withoutOldCloudHome(saved, at([cloud({ id: "c-old", name: "Studio", origin: old }), cloud({ id: "c-new", origin: now, primary: true })]));+ assert.deepEqual(alive.environments, [{ id: "old", kind: "remote", name: "My Cloud", origin: old }, garage], "still theirs: kept, but no longer home");+ assert.deepEqual(withoutOldCloudHome(saved, at(undefined)).environments, [{ id: "old", kind: "remote", name: "My Cloud", origin: old }, garage], "an Admin without the list: kept, but no longer home");+ assert.equal(withoutOldCloudHome(saved, { status: "connected", machine: { status: "ready", origin: old }, clouds: [] }), saved, "home where the machine is: nothing changes");+ for (const state of [{ status: "signed-out" }, { status: "connected", machine: null }, { status: "connected", machine: { status: "provisioning", origin: now } }, null]) {+ assert.equal(withoutOldCloudHome(saved, state), saved, JSON.stringify(state));+ }+ const none = { environments: [garage], activeId: environments.LOCAL_ID };+ assert.equal(withoutOldCloudHome(none, at([])), none);+});++test("the saved place of My Cloud takes the name and colour the Admin lists it under", () => {+ const now = "https://omb-u-new.fly.dev";+ const at = (clouds) => ({ status: "connected", machine: { status: "ready", origin: now }, clouds });+ assert.deepEqual(homeLook(at([cloud({ id: "c-new", name: "Anagama", color: "rose", origin: now, primary: true })])), { name: "Anagama", color: "red" });+ assert.equal(homeLook(at([cloud({ id: "c-new", name: "Anagama", origin: now, primary: true, role: "member" })])), null, "only the person's own");+ assert.equal(homeLook(at(undefined)), null);+ assert.equal(homeLook({ status: "signed-out" }), null);+});diff --git a/electron/main.mjs b/electron/main.mjsindex 94ce7d48c6..2527a4aa6a 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -108,7 +108,7 @@ import { installOneHome } from "./one-home-main.mjs"; import { installOwnHome }import { askForMicrophone, openPrivacySettings } from "./privacy-settings.mjs";import { createHomeWindow, installHomeWindowIpc } from "./home-window.mjs";import { createTeamProfileSeeds } from "./team-profile-seed.mjs";-import { createHomePlaces } from "./home-places.mjs"; import { createAddedCloudNotice, installCloudRail, railPlaces } from "./cloud-rail.mjs"; import { otherOwnClouds } from "./cloud-list.mjs"; import { installPlaceLook } from "./place-look.mjs"; import { CHROME_RAIL_PATH, createChromeRail } from "./chrome-rail.mjs";+import { createHomePlaces } from "./home-places.mjs"; import { createAddedCloudNotice, installCloudRail, railPlaces } from "./cloud-rail.mjs"; import { homeLook, otherOwnClouds, withoutOldCloudHome } from "./cloud-list.mjs"; import { installPlaceLook } from "./place-look.mjs"; import { CHROME_RAIL_PATH, createChromeRail } from "./chrome-rail.mjs";import { createWindowStateFile } from "./window-state-file.mjs";import { createEnvironmentsFile } from "./environments-file.mjs";import { createOrgLibrary } from "./org-library.mjs";@@ -1860,7 +1860,7 @@ async function connectHostedWorkspace(input, name) {/** My Cloud, and each team's Cloud the session lists (home-places.mjs), under Servers. */function rememberCloudHome(state) {try {- const next = withCloudHome(environmentsState, state?.status === "connected" ? state.machine : null, () => randomUUID(), cloudLook.pending());+ const next = withCloudHome(withoutOldCloudHome(environmentsState, state), state?.status === "connected" ? state.machine : null, () => randomUUID(), cloudLook.pending() ?? homeLook(state));if (next !== environmentsState) persistEnvironments(next);homePlaces.sync(state);} catch (error) {