Skip to content

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

Try Cloud outside the desktop opens the Cloud website's checkout (#6554)

Milind Soni2aadcf96c95d
diff --git a/apps/docs/content/docs/security/analytics.mdx b/apps/docs/content/docs/security/analytics.mdx
index 77120f35fa..d2b3fb29e7 100644
--- a/apps/docs/content/docs/security/analytics.mdx
+++ b/apps/docs/content/docs/security/analytics.mdx
@@ -154,7 +154,7 @@ use their own Boat key, and how many bots run on cloud computers, without sendin
| `cloud_dialog_shown` | The Add a Cloud dialog opens | `source`: `app_card`, `app_howto`, `app_menu`, `app_settings`, `app_routines`, `app_whats_new_pro` (Get Pro in the What's new popup), `app_whats_new_team` (Start a Team in it or in the Teams popup, for someone with a plan of their own), `app_onboarding` (Try Cloud under MausBot's first messages); `view`: the dialog's first screen |
| `cloud_dialog_view` | The Add a Cloud dialog reaches a step | `view`: `received`, `starting`, `ready` |
| `cloud_signin` | Signing in to MausBot Cloud inside the Add a Cloud dialog takes a step | `step`: `code_sent` (a sign-in code was emailed), `signed_in`, `browser` (Continue in browser); `source`: as for `cloud_dialog_shown` |
-| `cloud_checkout_opened` | A Cloud checkout opens in the browser | `plan`: Cloud plan; `trial`: true/false; `source`: as for `cloud_dialog_shown` |
+| `cloud_checkout_opened` | A Cloud checkout opens in the browser, from the Add a Cloud dialog or, where the app has none (a browser page, or a desktop showing another computer), straight from the button that asks for it | `plan`: Cloud plan (for `via` `web`, the plan its link asks for: `pro`, or `team` for Start a Team); `trial`: true/false, from the dialog only; `source`: as for `cloud_dialog_shown`; `via`: only without the dialog: `web` (the plan's checkout on the Cloud website opened in a new tab), `cloud_page` (on a Cloud, or for Sign in, the Cloud website's own page for the account opened instead) |
| `cloud_add_another` | Buying another Cloud, for someone who has one, takes a step | `step`: `plan` (a plan chosen), `checkout_opened`, `ready`; `plan`: Cloud plan, for `plan` and `checkout_opened` |
| `rail_place_opened` | You open a place from the rail of Clouds at the window's left edge | `kind`: `computer`, `cloud`, `team`, `server` |
| `rail_add` | You use the rail's + | `step`: `opened` (its sheet opened), `cloud` (Buy a Cloud, on this computer's own sheet), `link` (Connect to a server), `address` (Enter its address instead), `organization` (a new organization added on the Team plan) |
diff --git a/docs/analytics.md b/docs/analytics.md
index 4670194822..4e9c64921f 100644
--- a/docs/analytics.md
+++ b/docs/analytics.md
@@ -150,7 +150,7 @@ use their own Boat key, and how many bots run on cloud computers, without sendin
| `cloud_dialog_shown` | The Add a Cloud dialog opens | `source`: `app_card`, `app_howto`, `app_menu`, `app_settings`, `app_routines`, `app_whats_new_pro` (Get Pro in the What's new popup), `app_whats_new_team` (Start a Team in it or in the Teams popup, for someone with a plan of their own), `app_onboarding` (Try Cloud under MausBot's first messages); `view`: the dialog's first screen |
| `cloud_dialog_view` | The Add a Cloud dialog reaches a step | `view`: `received`, `starting`, `ready` |
| `cloud_signin` | Signing in to MausBot Cloud inside the Add a Cloud dialog takes a step | `step`: `code_sent` (a sign-in code was emailed), `signed_in`, `browser` (Continue in browser); `source`: as for `cloud_dialog_shown` |
-| `cloud_checkout_opened` | A Cloud checkout opens in the browser | `plan`: Cloud plan; `trial`: true/false; `source`: as for `cloud_dialog_shown` |
+| `cloud_checkout_opened` | A Cloud checkout opens in the browser, from the Add a Cloud dialog or, where the app has none (a browser page, or a desktop showing another computer), straight from the button that asks for it | `plan`: Cloud plan (for `via` `web`, the plan its link asks for: `pro`, or `team` for Start a Team); `trial`: true/false, from the dialog only; `source`: as for `cloud_dialog_shown`; `via`: only without the dialog: `web` (the plan's checkout on the Cloud website opened in a new tab), `cloud_page` (on a Cloud, or for Sign in, the Cloud website's own page for the account opened instead) |
| `cloud_add_another` | Buying another Cloud, for someone who has one, takes a step | `step`: `plan` (a plan chosen), `checkout_opened`, `ready`; `plan`: Cloud plan, for `plan` and `checkout_opened` |
| `rail_place_opened` | You open a place from the rail of Clouds at the window's left edge | `kind`: `computer`, `cloud`, `team`, `server` |
| `rail_add` | You use the rail's + | `step`: `opened` (its sheet opened), `cloud` (Buy a Cloud, on this computer's own sheet), `link` (Connect to a server), `address` (Enter its address instead), `organization` (a new organization added on the Team plan) |
diff --git a/src/App.cloud-add-web.test.ts b/src/App.cloud-add-web.test.ts
new file mode 100644
index 0000000000..6d5444b433
--- /dev/null
+++ b/src/App.cloud-add-web.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";
+
+let state: AppState = { ...initialState, connected: true, hydrated: true };
+let dispatched: Action[] = [];
+const track = vi.fn();
+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: (...args: unknown[]) => track(...args), emailGateDone: () => true }));
+const { default: App } = await import("./App");
+
+function render(cloudAdd: AppState["cloudAdd"], ogb?: unknown): { opened: ReturnType<typeof vi.fn>; done: () => void } {
+ vi.stubGlobal("fetch", () => new Promise(() => {}));
+ const opened = vi.fn(() => null);
+ vi.stubGlobal("open", opened);
+ if (ogb) (window as { ogb?: unknown }).ogb = ogb;
+ state = { ...initialState, connected: true, hydrated: true, cloudAdd };
+ dispatched = []; track.mockClear();
+ const container = document.createElement("div");
+ document.body.append(container);
+ const root = createRoot(container);
+ flushSync(() => root.render(createElement(App)));
+ return { opened, done: () => { root.unmount(); container.remove(); } };
+}
+
+afterEach(() => { delete (window as { ogb?: unknown }).ogb; vi.unstubAllGlobals(); });
+
+it("in a browser, Try Cloud opens the Cloud website's checkout in the same tap, counts it and leaves nothing waiting", () => {
+ const { opened, done } = render({ source: "app_onboarding" });
+ try {
+ expect(opened).toHaveBeenCalledExactlyOnceWith("https://cloud.openmausbot.com/pro/buy?src=app_onboarding", "_blank", "noopener,noreferrer");
+ expect(track).toHaveBeenCalledWith("cloud_checkout_opened", { plan: "pro", source: "app_onboarding", via: "web" });
+ expect(dispatched).toContainEqual({ type: "closeCloudAdd" });
+ } finally { done(); }
+});
+
+it("on a desktop showing another computer, it goes through main to the browser", () => {
+ const openExternal = vi.fn(async () => {});
+ const { opened, done } = render({ source: "app_card" }, { remoteClient: { active: true }, cloudAccount: {}, openExternal });
+ try {
+ expect(openExternal).toHaveBeenCalledExactlyOnceWith("https://cloud.openmausbot.com/pro/buy?src=app_card");
+ expect(opened).not.toHaveBeenCalled();
+ expect(dispatched).toContainEqual({ type: "closeCloudAdd" });
+ } finally { done(); }
+});
+
+it("on the desktop's own page the Add a Cloud dialog takes it, as before", () => {
+ const openExternal = vi.fn(async () => {});
+ const { opened, done } = render({ source: "app_onboarding" }, { cloudAccount: {}, openExternal });
+ try {
+ expect(opened).not.toHaveBeenCalled();
+ expect(openExternal).not.toHaveBeenCalled();
+ expect(track).not.toHaveBeenCalledWith("cloud_checkout_opened", expect.anything());
+ expect(dispatched).not.toContainEqual({ type: "closeCloudAdd" });
+ } finally { done(); }
+});
diff --git a/src/App.tsx b/src/App.tsx
index c040d00e52..13b7445d37 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
import { ChevronLeft, Loader2, Menu } from "lucide-react";
import { CLOUD_LINK_SETTINGS, openBot, StoreProvider, useStore } from "@/state/store";
import { nextShortcutBot, shortcutBots, shownBotIds } from "@/lib/sidebar-shortcut-order";
@@ -14,6 +14,7 @@ import { GuidedTour } from "@/components/onboarding/GuidedTour";
import { LiveCallHost } from "@/components/LiveCallHost";
import { ThreadRefsProvider } from "@/components/ThreadRefs";
import { initAnalytics } from "@/lib/analytics";
+import { cloudAccountBridge, openCloudOnWeb } from "@/lib/cloud-add-web";
import { parseComputerHelp } from "@/lib/computer-control";
import { viewerClosedRelease } from "@/components/computer-takeover";
import { Sidebar } from "@/components/Sidebar";
@@ -150,7 +151,13 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {
const [paletteOpen, setPaletteOpen] = useState(false);
// Stays mounted once opened: a Cloud bought in it can arrive after the sheet is closed.
const cloudAddOpened = useRef(false);
- cloudAddOpened.current ||= Boolean(state.cloudAdd);
+ cloudAddOpened.current ||= Boolean(state.cloudAdd && cloudAccountBridge());
+ // A layout effect runs inside the tap that asked, so a browser lets it open a tab.
+ useLayoutEffect(() => {
+ if (!state.cloudAdd || cloudAccountBridge()) return;
+ openCloudOnWeb(state.cloudAdd, { cloudHome: state.config?.cloudHome === true, teamCloudPage: state.config?.team?.cloudPage });
+ dispatch({ type: "closeCloudAdd" });
+ }, [state.cloudAdd]);
const [localVmWorkspaceBotId, setLocalVmWorkspaceBotId] = useState<string | null>(null);
const menuButtonRef = useRef<HTMLButtonElement>(null);
const previousViewRef = useRef(state.activeView);
diff --git a/src/components/CloudAddDialog.tsx b/src/components/CloudAddDialog.tsx
index 6134d74935..ed7f7a20a7 100644
--- a/src/components/CloudAddDialog.tsx
+++ b/src/components/CloudAddDialog.tsx
@@ -6,6 +6,7 @@ import type { CloudColor } from "../../electron/cloud-buy.mjs";
import type { CloudAccountState, CloudCheckoutOutcome } from "../../electron/cloud-account.mjs";
import type { CloudOffer } from "../../electron/cloud-home.mjs";
import { track } from "@/lib/analytics";
+import { cloudAccountBridge } from "@/lib/cloud-add-web";
import { cn } from "@/lib/cn";
import { cloudColor, cloudNameShown, DEFAULT_CLOUD_COLOR } from "@/lib/cloud-look";
import { cloudAddView, offerPlan, sameTerms, startedSleeps, type CloudAddView, type CloudSignInPhase } from "@/lib/cloud-plan";
@@ -112,7 +113,7 @@ type Note = "copied" | "pay-failed" | "interest-sent" | "interest-failed" | null
export function CloudAddDialog({ now = Date.now }: { now?: () => number }) {
const { state, dispatch } = useStore();
const request = state.cloudAdd;
- const bridge = window.ogb?.remoteClient?.active ? undefined : window.ogb?.cloudAccount;
+ const bridge = cloudAccountBridge();
const [account, setAccount] = useState<CloudAccountState | null>(null);
const [offer, setOffer] = useState<CloudOffer | null | undefined>(undefined);
const [chosen, setChosen] = useState<string | null>(null);
diff --git a/src/lib/cloud-add-web.test.ts b/src/lib/cloud-add-web.test.ts
new file mode 100644
index 0000000000..63beccfc7f
--- /dev/null
+++ b/src/lib/cloud-add-web.test.ts
@@ -0,0 +1,53 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("@/lib/analytics", () => ({ track: vi.fn() }));
+import { track } from "@/lib/analytics";
+import { CLOUD_SOURCES } from "@/lib/cloud-plan";
+import { cloudAccountBridge, cloudWebHop, openCloudOnWeb } from "./cloud-add-web";
+
+const away = { cloudHome: false };
+
+afterEach(() => { vi.unstubAllGlobals(); vi.mocked(track).mockClear(); });
+
+describe("Add a Cloud without the desktop's own sign-in", () => {
+ it("opens the plan's checkout on the Cloud website, tagged with the button that asked", () => {
+ expect(cloudWebHop({ source: "app_onboarding" }, away)).toEqual({ url: "https://cloud.openmausbot.com/pro/buy?src=app_onboarding", via: "web", plan: "pro" });
+ expect(cloudWebHop({ source: "app_card" }, away).url).toBe("https://cloud.openmausbot.com/pro/buy?src=app_card");
+ expect(cloudWebHop({ source: "app_whats_new_pro" }, away).url).toBe("https://cloud.openmausbot.com/pro/buy?src=app_whats_new_pro");
+ expect(cloudWebHop({ source: "app_whats_new_team" }, away)).toEqual({ url: "https://cloud.openmausbot.com/pro/buy?plan=team&src=app_whats_new_team", via: "web", plan: "team" });
+ for (const source of CLOUD_SOURCES) expect(new URL(cloudWebHop({ source }, away).url).searchParams.get("src"), source).toBe(source);
+ });
+
+ it("Sign in, and anything asked on a Cloud, opens the account's own page on the Cloud website instead of a second checkout", () => {
+ expect(cloudWebHop({ source: "app_settings", signIn: true }, away)).toEqual({ url: "https://cloud.openmausbot.com/cloud?src=app_settings", via: "cloud_page" });
+ expect(cloudWebHop({ source: "app_card" }, { cloudHome: true })).toEqual({ url: "https://cloud.openmausbot.com/cloud?src=app_card", via: "cloud_page" });
+ expect(cloudWebHop({ source: "app_settings" }, { cloudHome: true, teamCloudPage: "https://omb-cloud-staging.fly.dev/cloud" }).url)
+ .toBe("https://omb-cloud-staging.fly.dev/cloud?src=app_settings");
+ expect(cloudWebHop({ source: "app_settings", signIn: true }, { cloudHome: false, teamCloudPage: "https://omb-cloud-staging.fly.dev/cloud" }).url)
+ .toBe("https://cloud.openmausbot.com/cloud?src=app_settings");
+ });
+
+ it("opens a new tab in a browser, through main on a desktop, and counts the hop", () => {
+ const open = vi.fn();
+ vi.stubGlobal("window", { open });
+ openCloudOnWeb({ source: "app_onboarding" }, away);
+ expect(open).toHaveBeenCalledExactlyOnceWith("https://cloud.openmausbot.com/pro/buy?src=app_onboarding", "_blank", "noopener,noreferrer");
+ expect(track).toHaveBeenCalledExactlyOnceWith("cloud_checkout_opened", { plan: "pro", source: "app_onboarding", via: "web" });
+ const openExternal = vi.fn(async () => {});
+ vi.stubGlobal("window", { open, ogb: { openExternal, remoteClient: { active: true } } });
+ openCloudOnWeb({ source: "app_card" }, { cloudHome: true });
+ expect(openExternal).toHaveBeenCalledExactlyOnceWith("https://cloud.openmausbot.com/cloud?src=app_card");
+ expect(open).toHaveBeenCalledTimes(1);
+ expect(track).toHaveBeenLastCalledWith("cloud_checkout_opened", { source: "app_card", via: "cloud_page" });
+ });
+
+ it("only the desktop's own page has the sign-in Add a Cloud runs on", () => {
+ const cloudAccount = { state: vi.fn() };
+ vi.stubGlobal("window", {});
+ expect(cloudAccountBridge()).toBeUndefined();
+ vi.stubGlobal("window", { ogb: { cloudAccount, remoteClient: { active: true } } });
+ expect(cloudAccountBridge()).toBeUndefined();
+ vi.stubGlobal("window", { ogb: { cloudAccount, remoteClient: { active: false } } });
+ expect(cloudAccountBridge()).toBe(cloudAccount);
+ });
+});
diff --git a/src/lib/cloud-add-web.ts b/src/lib/cloud-add-web.ts
new file mode 100644
index 0000000000..58b755d62f
--- /dev/null
+++ b/src/lib/cloud-add-web.ts
@@ -0,0 +1,31 @@
+import { track } from "@/lib/analytics";
+import { CLOUD_PLAN_URL, openExternalLink, withSource } from "@/lib/app-links";
+import type { CloudSource } from "@/lib/cloud-plan";
+import { WHATS_NEW_SOURCES } from "@/lib/whats-new";
+
+export type CloudAddRequest = { source: CloudSource; signIn?: true };
+
+/** The desktop's own MausBot Cloud sign-in, which Add a Cloud runs on: none in a browser or on a desktop showing another computer. */
+export function cloudAccountBridge() {
+ return window.ogb?.remoteClient?.active ? undefined : window.ogb?.cloudAccount;
+}
+
+export interface CloudWebHop { url: string; via: "web" | "cloud_page"; plan?: "pro" | "team" }
+
+/** Add a Cloud where there is no Add a Cloud: on a Cloud, or to sign in, the Cloud website's own page for the account
+ * (a team's, from its server, else the production one); anywhere else the plan's checkout on the Cloud website. */
+export function cloudWebHop(request: CloudAddRequest, place: { cloudHome: boolean; teamCloudPage?: string }): CloudWebHop {
+ if (place.cloudHome || request.signIn) {
+ return { url: withSource((place.cloudHome && place.teamCloudPage) || CLOUD_PLAN_URL, request.source), via: "cloud_page" };
+ }
+ const plan = request.source === WHATS_NEW_SOURCES.team ? "team" : "pro";
+ const buy = new URL("/pro/buy", CLOUD_PLAN_URL);
+ if (plan === "team") buy.searchParams.set("plan", plan);
+ return { url: withSource(buy.href, request.source), via: "web", plan };
+}
+
+export function openCloudOnWeb(request: CloudAddRequest, place: { cloudHome: boolean; teamCloudPage?: string }): void {
+ const hop = cloudWebHop(request, place);
+ void openExternalLink(hop.url).catch(() => {});
+ track("cloud_checkout_opened", { ...(hop.plan ? { plan: hop.plan } : {}), source: request.source, via: hop.via });
+}