Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Settings opens on the page a Cloud's page asked This computer for
aivsomkar1d071e19c60c
diff --git a/electron/preload.cjs b/electron/preload.cjsindex 4f1c951760..54d664a861 100644--- a/electron/preload.cjs+++ b/electron/preload.cjs@@ -34,7 +34,8 @@ ipcRenderer.on("desktop-notifications:open", (_event, target) => {});// Only fixed actions are retained, never a destination supplied by a renderer.-const FIXED_SETTINGS_ACTIONS = new Set(["organization", "cloud", "cloud-settings", "cloud-add", "cloud-add-howto"]);+const FIXED_SETTINGS_ACTIONS = new Set(["organization", "cloud", "cloud-settings", "cloud-add", "cloud-add-howto",+ "overview", "phone", "ai", "bots", "desktops", "vault", "usage", "data", "people", "installations", "account", "plan", "app", "general", "appearance"]);let pendingSettingsAction = null;const appSettingsListeners = new Set();ipcRenderer.on("app:open-settings", (_event, section) => {diff --git a/electron/preload.node-test.mjs b/electron/preload.node-test.mjsindex 3cdbb5c16f..c98fd9ac07 100644--- a/electron/preload.node-test.mjs+++ b/electron/preload.node-test.mjs@@ -153,6 +153,22 @@ test("native Settings requests accept only the fixed organisation section, Cloudunsubscribe();});+test("a Settings page name from Switch to This computer reaches Settings, also before React subscribes", async () => {+ const calls = [];+ const unsubscribe = exposed.api.onOpenAppSettings(section => calls.push(section));+ try {+ emit("app:open-settings", "app");+ emit("app:open-settings", "account");+ emit("app:open-settings", "phone");+ } finally { unsubscribe(); }+ assert.deepEqual(calls, ["app", "account", "phone"]);+ emit("app:open-settings", "account");+ const later = exposed.api.onOpenAppSettings(section => calls.push(section));+ await Promise.resolve();+ assert.deepEqual(calls.slice(3), ["account"]);+ later();+});+test("a Cloud link arriving before React subscriptions is delivered exactly once after mount", async () => {emit("app:open-settings", "https://other.example");emit("app:open-settings", "cloud");diff --git a/src/App.settings-links.test.ts b/src/App.settings-links.test.tsnew file mode 100644index 0000000000..18fa06acdb--- /dev/null+++ b/src/App.settings-links.test.ts@@ -0,0 +1,63 @@+// @vitest-environment happy-dom+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot } from "react-dom/client";+import { afterEach, expect, it, vi } from "vitest";+import { initialState, type Action, type AppState } from "./state/store";++const state: AppState = { ...initialState, connected: true, hydrated: true };+let dispatched: Action[] = [];+vi.mock("./state/store", async (original) => ({+ ...await original<typeof import("./state/store")>(),+ StoreProvider: ({ children }: { children: unknown }) => children,+ useStore: () => ({ state, dispatch: (action: Action) => { dispatched.push(action); }, flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {} }),+}));+vi.mock("./lib/analytics", () => ({ initAnalytics: () => {}, track: () => {}, emailGateDone: () => true }));+const { default: App } = await import("./App");++let fromMain: ((section?: string) => void) | null = null;++function renderAt(path: string): () => void {+ vi.stubGlobal("fetch", () => new Promise(() => {}));+ window.history.replaceState(null, "", path);+ (window as { ogb?: unknown }).ogb = {+ environments: { onOpenSettings: () => () => {} },+ onOpenAppSettings: (cb: (section?: string) => void) => { fromMain = cb; return () => { fromMain = null; }; },+ };+ dispatched = [];+ const container = document.createElement("div");+ document.body.append(container);+ const root = createRoot(container);+ flushSync(() => root.render(createElement(App)));+ return () => { root.unmount(); container.remove(); };+}++const settingsOpened = () => dispatched.filter((action) => action.type === "toggleAppSettings");++afterEach(() => { delete (window as { ogb?: unknown }).ogb; fromMain = null; vi.unstubAllGlobals(); });++it("main's request for This computer's update or sign-out page opens Settings on that page", () => {+ const done = renderAt("/");+ try {+ fromMain?.("app");+ fromMain?.("account");+ fromMain?.(undefined);+ expect(settingsOpened()).toEqual([+ { type: "toggleAppSettings", open: true, section: "app" },+ { type: "toggleAppSettings", open: true, section: "account" },+ { type: "toggleAppSettings", open: true },+ ]);+ } finally { done(); }+});++it("main's request for the phone page opens the phone pairing, as the phone link does", () => {+ const done = renderAt("/");+ try {+ fromMain?.("phone");+ expect(settingsOpened()).toEqual([{ type: "toggleAppSettings", open: true, section: "phone", phonePairing: true }]);+ } finally { done(); }+ const linked = renderAt("/?desktop-settings=phone");+ try {+ expect(settingsOpened()).toEqual([{ type: "toggleAppSettings", open: true, section: "phone", phonePairing: true }]);+ } finally { linked(); }+});diff --git a/src/App.tsx b/src/App.tsxindex 64fd708794..9dbccd06dc 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -68,6 +68,7 @@ import { botCycleStep, shouldOpenKeyboardShortcuts } from "@/lib/keyboard-shortcimport { effectiveLanguage, useLanguageChoice, usePageLanguage } from "@/lib/language-preference";import { botUnreadCount, showBrowserUnread } from "@/lib/bot-unread";import { phonePairingSettingsAction, takePhonePairingRequest } from "@/lib/phone-pairing"; import { useConnectLink } from "@/lib/use-connect-link";+import { isSettingsPage } from "@/components/settings/settings-index";import { useDesktopNotificationOpens, useExternalChatLinks } from "@/hooks/use-external-chat-links";import { useUsageSnapshot } from "@/hooks/use-usage-snapshot";import { useReadShownChatOnFocus } from "@/hooks/use-read-shown-chat";@@ -288,13 +289,13 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {state.pluginsOpen;useEffect(() => {- return window.ogb?.onOpenAppSettings?.(section => dispatch((section === "cloud-add" || section === "cloud-add-howto") && window.ogb?.cloudAccount && !remoteClient+ return window.ogb?.onOpenAppSettings?.(section => dispatch(section === "phone" ? phonePairingSettingsAction() : (section === "cloud-add" || section === "cloud-add-howto") && window.ogb?.cloudAccount && !remoteClient? { type: "openCloudAdd", source: section === "cloud-add" ? "app_menu" : "app_howto" }: section === "cloud" && window.ogb?.cloudAccount && !remoteClient? CLOUD_LINK_SETTINGS: section === "cloud-settings" && (window.ogb?.cloudAccount || window.ogb?.cloudPlan) && !remoteClient? { type: "toggleAppSettings", open: true, section: "cloudAccount" }- : { type: "toggleAppSettings", open: true, ...(section === "organization" && window.ogb?.organization && !remoteClient ? { section } : {}) }));+ : { type: "toggleAppSettings", open: true, ...((section === "organization" && window.ogb?.organization && !remoteClient) || isSettingsPage(section) ? { section } : {}) }));}, [dispatch]);useEffect(() => {diff --git a/src/components/settings/settings-index.ts b/src/components/settings/settings-index.tsindex ad7cc08ace..7496e26668 100644--- a/src/components/settings/settings-index.ts+++ b/src/components/settings/settings-index.ts@@ -122,7 +122,7 @@ export const LEGACY_SETTINGS: Record<Exclude<AppSettingsSection, SettingsPageId>updates: (ctx) => (ctx.desktop ? { page: "app", anchor: "updates" } : { page: "overview" }),};-const isPage = (id: AppSettingsSection): id is SettingsPageId => SETTINGS_PAGES.some((page) => page.id === id);+export const isSettingsPage = (id: string | null | undefined): id is SettingsPageId => SETTINGS_PAGES.some((page) => page.id === id);/** True when a row or section is one Advanced mode adds (on a page Simple shows, or on an Advanced-only page). */export function needsAdvanced(target: SettingsTarget, ctx: SettingsContext): boolean {@@ -134,7 +134,7 @@ export function needsAdvanced(target: SettingsTarget, ctx: SettingsContext): boo/** Where a request for Settings lands here: its page (or Overview when that page can't exist on this place) and the* section to scroll to. A page or row only Advanced mode shows comes back with `advanced`: opening it turns Advanced on. */export function resolveSettingsTarget(requested: AppSettingsSection, ctx: SettingsContext): SettingsTarget & { missing?: SettingsPageId; advanced?: true } {- const target = isPage(requested) ? { page: requested } : LEGACY_SETTINGS[requested](ctx);+ const target = isSettingsPage(requested) ? { page: requested } : LEGACY_SETTINGS[requested](ctx);if (needsAdvanced(target, ctx)) return { ...target, advanced: true };if (pageById(target.page).when(ctx)) return target;return { page: "overview", missing: target.page };diff --git a/src/components/settings/settings-pages-preload.test.ts b/src/components/settings/settings-pages-preload.test.tsnew file mode 100644index 0000000000..1d12ffab17--- /dev/null+++ b/src/components/settings/settings-pages-preload.test.ts@@ -0,0 +1,18 @@+import { createRequire } from "node:module";+import { expect, it } from "vitest";+import { SETTINGS_PAGES } from "./settings-index";++it("every Settings page a Cloud's page can ask This computer for gets through the preload", () => {+ const require = createRequire(import.meta.url);+ const handlers = new Map<string, (event: unknown, section: unknown) => void>();+ const reached: unknown[] = [];+ const electron = require.resolve("electron");+ require.cache[electron] = { id: electron, filename: electron, loaded: true, exports: {+ ipcRenderer: { on: (channel: string, handler: (event: unknown, section: unknown) => void) => handlers.set(channel, handler), removeListener: () => {}, invoke: async () => {}, send: () => {} },+ contextBridge: { exposeInMainWorld: (_name: string, api: { onOpenAppSettings: (cb: (section: unknown) => void) => void }) => api.onOpenAppSettings((section) => reached.push(section)) },+ webUtils: { getPathForFile: () => "" },+ } } as unknown as NodeJS.Module;+ require("../../../electron/preload.cjs");+ for (const page of SETTINGS_PAGES) handlers.get("app:open-settings")?.({}, page.id);+ expect(reached).toEqual(SETTINGS_PAGES.map((page) => page.id));+});diff --git a/src/types/ogb.d.ts b/src/types/ogb.d.tsindex d59c0174d9..aec2597960 100644--- a/src/types/ogb.d.ts+++ b/src/types/ogb.d.ts@@ -398,7 +398,7 @@ const __APP_VERSION__: string;* app Settings. Every server's page in the window receives it, and the* bridge is absent in the browser. "cloud" is the* openmausbot://cloud link (Settings → OMB Cloud, opened by the link). */- onOpenAppSettings?(cb: (section?: "organization" | "cloud" | "cloud-settings" | "cloud-add" | "cloud-add-howto") => void): () => void;+ onOpenAppSettings?(cb: (section?: "organization" | "cloud" | "cloud-settings" | "cloud-add" | "cloud-add-howto" | import("../state/store").SettingsPageId) => void): () => void;/** Updates the native Dock/taskbar unread indicator. */setUnreadCount?(count: number): void;/** Opens a live desktop as a sandboxed window owned by OpenMausBot. */