Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Bot settings search: keep looking until the Email lookup has answered
AdityaUmale2bbba00dc123
diff --git a/src/components/BotSettingsDialog.tsx b/src/components/BotSettingsDialog.tsxindex 6471a138ef..a526dccf3a 100644--- a/src/components/BotSettingsDialog.tsx+++ b/src/components/BotSettingsDialog.tsx@@ -4,7 +4,7 @@ import { ChevronDown, Search, X } from "lucide-react";import { useStore, type Bot, type BotSettingsSection } from "@/state/store";import { cn } from "@/lib/cn";import { useCaptionChrome } from "./DesktopCapabilities";-import { BOT_SECTIONS, searchEmptyText, sectionLabel, sectionMatches } from "./bot-settings/sections";+import { BOT_SECTIONS, appSearchPhase, searchEmptyText, sectionLabel, sectionMatches } from "./bot-settings/sections";import { useBotApps } from "./bot-settings/useBotApps";import { useBotSettingsDerived } from "./bot-settings/useBotSettingsDerived";import { OverviewSection } from "./bot-settings/OverviewSection";@@ -224,7 +224,7 @@ export function BotSettingsDialog({ bot, overlay = false }: {<div className="flex min-h-0 flex-1 flex-col overflow-y-auto">{visibleSections.length === 0 && (<div className="px-4 py-4 text-[13px] leading-relaxed text-ink-secondary">- {searchEmptyText(query.trim(), searchApps.phase)}+ {searchEmptyText(query.trim(), appSearchPhase(searchApps))}</div>)}{sections.map((entry) => {diff --git a/src/components/bot-settings/sections.test.ts b/src/components/bot-settings/sections.test.tsindex c14c55f0e2..a57f44b7f1 100644--- a/src/components/bot-settings/sections.test.ts+++ b/src/components/bot-settings/sections.test.ts@@ -1,7 +1,7 @@import { afterEach, describe, expect, it } from "vitest";import { setLocale } from "@/lib/i18n";-import { BOT_SECTIONS, searchEmptyText, sectionMatches } from "./sections";+import { BOT_SECTIONS, appSearchPhase, searchEmptyText, sectionMatches } from "./sections";const section = (id: string) => {const entry = BOT_SECTIONS.find((candidate) => candidate.id === id);@@ -39,4 +39,11 @@ describe("bot settings search", () => {expect(searchEmptyText("github", "ready")).toBe("Nothing matches “github”");expect(searchEmptyText("github", "unknown")).toBe("Nothing matches “github”");});++ it("keeps looking until the Email lookup has answered too", () => {+ expect(appSearchPhase({ phase: "ready", emailSettled: false })).toBe("loading");+ expect(appSearchPhase({ phase: "unknown", emailSettled: false })).toBe("loading");+ expect(appSearchPhase({ phase: "ready", emailSettled: true })).toBe("ready");+ expect(appSearchPhase({ phase: "loading", emailSettled: true })).toBe("loading");+ });});diff --git a/src/components/bot-settings/sections.ts b/src/components/bot-settings/sections.tsindex 71d38145d5..3ac6b9dd2e 100644--- a/src/components/bot-settings/sections.ts+++ b/src/components/bot-settings/sections.ts@@ -20,7 +20,7 @@ import {import type { BotSettingsSection } from "@/state/store";import type { LocaleKey } from "@/locales";import { t } from "@/lib/i18n";-import type { BotApps } from "./useBotApps";+import type { BotApps, BotAppsState } from "./useBotApps";export const BOT_SECTIONS: Array<{id: BotSettingsSection;@@ -66,6 +66,11 @@ export function sectionMatches(entry: BotSectionEntry, query: string, appNames:.some((part) => part.toLowerCase().includes(query));}+/** App names come from the connector inventory and the Email lookup; search keeps looking until both have answered. */+export function appSearchPhase(apps: Pick<BotAppsState, "phase" | "emailSettled">): BotApps["phase"] {+ return apps.emailSettled ? apps.phase : "loading";+}+/** The note shown when no section matches. Until the bot's connected apps have loaded, an app name may still match. */export function searchEmptyText(query: string, appsPhase: BotApps["phase"]): string {return appsPhase === "loading" ? t("botSettings.searchLoading") : t("botSettings.searchNone", { query });diff --git a/src/components/bot-settings/useBotApps.dom.test.ts b/src/components/bot-settings/useBotApps.dom.test.tsnew file mode 100644index 0000000000..d2ebc3c8ac--- /dev/null+++ b/src/components/bot-settings/useBotApps.dom.test.ts@@ -0,0 +1,71 @@+// @vitest-environment happy-dom+// The settings search keeps looking until both app-name sources (connector inventory and Email) have answered.+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { setLocale } from "@/lib/i18n";+import type { Bot } from "@/state/store";++const fixture = vi.hoisted(() => ({ answerEmail: null as null | ((ok: boolean) => void) }));+vi.mock("@/lib/connected-apps", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@/lib/connected-apps")>()),+ preloadConnectedApps: () => Promise.resolve({ authoritative: true, services: { github: { connected: true } } }),+}));+vi.mock("@/state/store", async (importOriginal) => {+ const original = await importOriginal<typeof import("@/state/store")>();+ const api = (path: string) => {+ if (path === "/api/connectors/catalog") return Promise.resolve({ cards: [] });+ if (path === "/api/email") {+ return new Promise((resolve, reject) => {+ fixture.answerEmail = (ok) => (ok ? resolve({ state: "connected", accounts: [{ address: "[email protected]" }] }) : reject(new Error("down")));+ });+ }+ return Promise.reject(new Error(`unexpected ${path}`));+ };+ return { ...original, api };+});++const { useBotApps } = await import("./useBotApps");+const { appSearchPhase } = await import("./sections");++function Probe({ bot }: { bot: Bot }) {+ const apps = useBotApps(bot, true);+ return createElement("p", null, `${appSearchPhase(apps)}:${apps.apps.map((app) => app.slug).join(",")}`);+}++let host: HTMLDivElement;+let root: Root;+const settle = async () => {+ for (let i = 0; i < 3; i++) await new Promise((resolve) => setTimeout(resolve, 0));+};++beforeEach(() => {+ setLocale("en");+ fixture.answerEmail = null;+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+ flushSync(() => root.render(createElement(Probe, { bot: { id: "scout" } as Bot })));+});+afterEach(() => {+ root.unmount();+ host.remove();+});++describe("app names for the settings search", () => {+ it("stays loading while Email has not answered, even once the other apps are in", async () => {+ await settle();+ expect(host.textContent).toBe("loading:github");+ fixture.answerEmail?.(true);+ await settle();+ expect(host.textContent).toBe("ready:email,github");+ });++ it("stops loading when the Email lookup fails", async () => {+ await settle();+ fixture.answerEmail?.(false);+ await settle();+ expect(host.textContent).toBe("ready:github");+ });+});diff --git a/src/components/bot-settings/useBotApps.ts b/src/components/bot-settings/useBotApps.tsindex 883bf4c1da..3792c0e746 100644--- a/src/components/bot-settings/useBotApps.ts+++ b/src/components/bot-settings/useBotApps.ts@@ -73,11 +73,17 @@ export function botAppsFrom(return { phase: "ready", apps, connectedSlugs };}+/** The apps plus whether the Email lookup has answered (or failed); `email` alone can't tell pending from failed. */+export interface BotAppsState extends BotApps {+ emailSettled: boolean;+}+/** `load` false skips the requests until it turns true (the settings search loads apps only once someone searches). */-export function useBotApps(bot: Bot, load = true): BotApps {+export function useBotApps(bot: Bot, load = true): BotAppsState {const [inventory, setInventory] = useState<ConnectorInventory | null>(null);const [cards, setCards] = useState<ReadonlyMap<string, ToolkitCard>>(() => new Map());const [email, setEmail] = useState<EmailStatus | null>(null);+ const [emailSettled, setEmailSettled] = useState(false);useEffect(() => {if (!load) return;@@ -88,11 +94,14 @@ export function useBotApps(bot: Bot, load = true): BotApps {void loadAppCards().then((result) => {if (!cancelled) setCards(result);});- void api("/api/email").then((result: EmailStatus) => { if (!cancelled) setEmail(result); }).catch(() => {});+ void api("/api/email")+ .then((result: EmailStatus) => { if (!cancelled) setEmail(result); })+ .catch(() => {})+ .finally(() => { if (!cancelled) setEmailSettled(true); });return () => {cancelled = true;};}, [load]);- return botAppsFrom(bot, inventory, cards, email);+ return { ...botAppsFrom(bot, inventory, cards, email), emailSettled };}