Skip to content

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

Launch bundle: the sign-in import dialog and the app matcher load on demand (#6931)

Milind Soni237a12bac719
diff --git a/src/components/BrowserPanel.tsx b/src/components/BrowserPanel.tsx
index 12a52a0124..11eb2ad5ad 100644
--- a/src/components/BrowserPanel.tsx
+++ b/src/components/BrowserPanel.tsx
@@ -21,7 +21,7 @@ import { passkeyWallAt } from "../../shared/passkey-wall";
import { browserScope, withBrowserScope } from "@/lib/team-browser";
import { followBounds } from "@/lib/follow-bounds";
import { useNativeViewObscured } from "@/lib/native-view-obscured";
-import { CookieImportDialog, cookieImportAvailable, siteOfAddress } from "./browser/CookieImportDialog";
+import { CookieImportDialog, cookieImportAvailable, siteOfAddress } from "./browser/cookie-import";
const BrowserDesktop = lazy(() => import("./browser/BrowserDesktop").then((module) => ({ default: module.BrowserDesktop })));
diff --git a/src/components/HandoffCard.dom.test.ts b/src/components/HandoffCard.dom.test.ts
index bb8048ec6c..bfbfedc89a 100644
--- a/src/components/HandoffCard.dom.test.ts
+++ b/src/components/HandoffCard.dom.test.ts
@@ -113,7 +113,8 @@ describe("a step the bot handed to the person", () => {
await show([row("m1", handoff({ need: "sign_in", site: "github.com", url: "https://github.com/" }))], 0, { browserEngine: { cookieImport: true } });
expect(offer).toHaveBeenCalledWith({ botId: "scout", threadId: null, site: "github.com" });
await act(async () => button("Use my sign-in from my own browser")!.click());
- await act(async () => { await new Promise((done) => setTimeout(done, 0)); });
+ // The dialog's code loads on its first open.
+ await vi.waitFor(async () => { await act(async () => { await new Promise((done) => setTimeout(done, 0)); }); expect(container.querySelector("dialog form")).not.toBeNull(); });
await act(async () => { container.querySelector<HTMLFormElement>('dialog form')!.requestSubmit(); await new Promise((done) => setTimeout(done, 0)); });
expect(importIt).toHaveBeenCalledWith({ botId: "scout", threadId: null, site: "github.com", source: "chrome", profile: "Default" });
expect(calls.find((call) => call.url.endsWith("/sign-in-cards/m1/done"))?.body).toEqual({ threadId: "t1", note: "imported the person's sign-in for github.com from their own Chrome" });
diff --git a/src/components/HandoffCard.tsx b/src/components/HandoffCard.tsx
index e50f99f9cc..d3f5a8b36f 100644
--- a/src/components/HandoffCard.tsx
+++ b/src/components/HandoffCard.tsx
@@ -11,7 +11,7 @@ import type { Bot, Message } from "@/state/store";
import { useStoreDispatch, useStoreSelector } from "@/state/store-select";
import { ASK_DARK_PRIMARY, ASK_QUIET_BUTTON, ASK_SECONDARY_BUTTON, AskCard, AskError, returnFocusToComposer } from "./AskCard";
import { ELEVATED_CARD } from "./elevated";
-import { CookieImportDialog } from "./browser/CookieImportDialog";
+import { CookieImportDialog } from "./browser/cookie-import";
import { HandoffPreview } from "./HandoffPreview";
import { HandoffSuggestion, useSignInImport, useSuggestedApp } from "./HandoffSuggestion";
diff --git a/src/components/HandoffSuggestion.tsx b/src/components/HandoffSuggestion.tsx
index 53acb90328..640ea6309f 100644
--- a/src/components/HandoffSuggestion.tsx
+++ b/src/components/HandoffSuggestion.tsx
@@ -1,7 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { Check, Copy, Loader2, RefreshCw, X } from "lucide-react";
-import { appForSite } from "../../shared/app-sites";
import type { ComputerHelpRef } from "../../shared/wire";
import { appSwitchPatch, botAppScope } from "@/lib/bot-app-access";
import { loadAppCatalog } from "@/lib/app-catalog-cache";
@@ -15,7 +14,7 @@ import { mcpSignInLink } from "@/lib/mcp-sign-in";
import { answerSignIn } from "@/lib/sign-in";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { browserScope } from "@/lib/team-browser";
-import { cookieImportAvailable } from "./browser/CookieImportDialog";
+import { cookieImportAvailable } from "./browser/cookie-import";
import { api } from "@/state/store";
import { useStoreDispatch, useStoreSelector } from "@/state/store-select";
import { ASK_DARK_PRIMARY, ASK_QUIET_BUTTON } from "./AskCard";
@@ -38,7 +37,14 @@ const readStatus = (slug: string): Promise<ConnectorStatus | undefined> =>
/** The app a waiting sign-in could use instead, once the catalogue lists it and the bot does not have it yet. */
export function useSuggestedApp(site: string, botId: string): { card: ToolkitCard; status: ConnectorStatus | undefined } | null {
- const slug = appForSite(site);
+ // The matcher reads the public-suffix list, which the launch bundle leaves out: it loads with the first request card.
+ const [matched, setMatched] = useState<{ site: string; slug: string | null } | null>(null);
+ useEffect(() => {
+ let live = true;
+ void import("../../shared/app-sites").then(({ appForSite }) => { if (live) setMatched({ site, slug: appForSite(site) }); }, () => undefined);
+ return () => { live = false; };
+ }, [site]);
+ const slug = matched?.site === site ? matched.slug : null;
const bot = useStoreSelector((state) => state.bots.find((one) => one.id === botId));
const [found, setFound] = useState<{ card: ToolkitCard; status: ConnectorStatus | undefined } | null>(null);
useEffect(() => {
diff --git a/src/components/bot-panel/browser-logins.tsx b/src/components/bot-panel/browser-logins.tsx
index 3c3907141b..883fc7bcd7 100644
--- a/src/components/bot-panel/browser-logins.tsx
+++ b/src/components/bot-panel/browser-logins.tsx
@@ -5,7 +5,7 @@ import { t } from "@/lib/i18n";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { type Bot } from "@/state/store";
import { SignedInSites } from "../SignedInSites";
-import { CookieImportDialog, cookieImportAvailable } from "../browser/CookieImportDialog";
+import { CookieImportDialog, cookieImportAvailable } from "../browser/cookie-import";
import { browserScope } from "@/lib/team-browser";
import { Card, ColRow, LinkRow, NoteRow } from "./rows";
import { sameFields, sameItems, useStoreSelector } from "@/state/store-select";
diff --git a/src/components/browser/CookieImportDialog.tsx b/src/components/browser/CookieImportDialog.tsx
index f04256ab4f..4e568e081e 100644
--- a/src/components/browser/CookieImportDialog.tsx
+++ b/src/components/browser/CookieImportDialog.tsx
@@ -6,6 +6,8 @@ import { t } from "@/lib/i18n";
import { Select } from "../Select";
import type { LocaleKey } from "@/locales";
+export { cookieImportAvailable, siteOfAddress } from "./cookie-import";
+
const button = "rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink";
const field = "w-full rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent disabled:opacity-60";
@@ -22,16 +24,6 @@ const REASONS: Record<string, LocaleKey> = {
"no-destination": "browser.cookieImport.reason.noDestination",
};
-/** The site a page address belongs to, for the form to start from; empty for anything but a web page. */
-export function siteOfAddress(address: string): string {
- try {
- const url = new URL(address);
- return url.protocol === "https:" || url.protocol === "http:" ? url.hostname.replace(/^www\./u, "") : "";
- } catch {
- return "";
- }
-}
-
/** The site an import takes, as the server reads it: the registrable domain of what was typed. */
export function importedSite(typed: string): string {
const text = typed.trim().toLowerCase();
@@ -43,11 +35,6 @@ export function importedSite(typed: string): string {
return loginSite(host);
}
-/** Whether this app can import a sign-in for a bot here: the desktop app, with the server's import ready. */
-export function cookieImportAvailable(config: { browserEngine?: { cookieImport?: true } } | null | undefined): boolean {
- return config?.browserEngine?.cookieImport === true && Boolean(window.ogb?.browserCookies);
-}
-
/**
* A site's sign-in from one of the person's own browsers into a bot's: they pick the browser, its profile and the
* site, and confirm a sentence naming all three and the bot. Security: only counts and a reason come back.
diff --git a/src/components/browser/cookie-import.tsx b/src/components/browser/cookie-import.tsx
new file mode 100644
index 0000000000..c1b1051893
--- /dev/null
+++ b/src/components/browser/cookie-import.tsx
@@ -0,0 +1,25 @@
+import { lazy, Suspense, type ComponentProps } from "react";
+
+// The dialog reads the public-suffix list (shared/logins), which the launch bundle leaves out: it loads on first open.
+const Dialog = lazy(() => import("./CookieImportDialog").then((module) => ({ default: module.CookieImportDialog })));
+
+/** The site a page address belongs to, for the form to start from; empty for anything but a web page. */
+export function siteOfAddress(address: string): string {
+ try {
+ const url = new URL(address);
+ return url.protocol === "https:" || url.protocol === "http:" ? url.hostname.replace(/^www\./u, "") : "";
+ } catch {
+ return "";
+ }
+}
+
+/** Whether this app can import a sign-in for a bot here: the desktop app, with the server's import ready. */
+export function cookieImportAvailable(config: { browserEngine?: { cookieImport?: true } } | null | undefined): boolean {
+ return config?.browserEngine?.cookieImport === true && Boolean(window.ogb?.browserCookies);
+}
+
+/** The sign-in import dialog, loaded the first time it opens. */
+export function CookieImportDialog(props: ComponentProps<typeof Dialog>) {
+ if (!props.open) return null;
+ return <Suspense fallback={null}><Dialog {...props} /></Suspense>;
+}