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: wait for this lookup's inventory too, not one kept from an earlier search
AdityaUmale63e45438e25f
diff --git a/src/components/bot-settings/sections.test.ts b/src/components/bot-settings/sections.test.tsindex 67abaffd2f..42a16e6336 100644--- a/src/components/bot-settings/sections.test.ts+++ b/src/components/bot-settings/sections.test.ts@@ -41,10 +41,11 @@ describe("bot settings search", () => {});it("keeps looking until the Email lookup has answered too", () => {- expect(appSearchPhase({ phase: "ready", cardsSettled: true, emailSettled: false })).toBe("loading");- expect(appSearchPhase({ phase: "unknown", cardsSettled: true, emailSettled: false })).toBe("loading");- expect(appSearchPhase({ phase: "ready", cardsSettled: false, emailSettled: true })).toBe("loading");- expect(appSearchPhase({ phase: "ready", cardsSettled: true, emailSettled: true })).toBe("ready");- expect(appSearchPhase({ phase: "loading", cardsSettled: true, emailSettled: true })).toBe("loading");+ expect(appSearchPhase({ inventorySettled: true, phase: "ready", cardsSettled: true, emailSettled: false })).toBe("loading");+ expect(appSearchPhase({ inventorySettled: true, phase: "unknown", cardsSettled: true, emailSettled: false })).toBe("loading");+ expect(appSearchPhase({ inventorySettled: true, phase: "ready", cardsSettled: false, emailSettled: true })).toBe("loading");+ expect(appSearchPhase({ inventorySettled: true, phase: "ready", cardsSettled: true, emailSettled: true })).toBe("ready");+ expect(appSearchPhase({ inventorySettled: true, phase: "loading", cardsSettled: true, emailSettled: true })).toBe("loading");+ expect(appSearchPhase({ inventorySettled: false, phase: "ready", cardsSettled: true, emailSettled: true })).toBe("loading");});});diff --git a/src/components/bot-settings/sections.ts b/src/components/bot-settings/sections.tsindex 034f7893b1..025165baf0 100644--- a/src/components/bot-settings/sections.ts+++ b/src/components/bot-settings/sections.ts@@ -67,8 +67,8 @@ export function sectionMatches(entry: BotSectionEntry, query: string, appNames:}/** App names come from the connector inventory, the app catalog and the Email lookup; search keeps looking until all have answered. */-export function appSearchPhase(apps: Pick<BotAppsState, "phase" | "cardsSettled" | "emailSettled">): BotApps["phase"] {- return apps.cardsSettled && apps.emailSettled ? apps.phase : "loading";+export function appSearchPhase(apps: Pick<BotAppsState, "phase" | "inventorySettled" | "cardsSettled" | "emailSettled">): BotApps["phase"] {+ return apps.inventorySettled && apps.cardsSettled && 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. */diff --git a/src/components/bot-settings/useBotApps.dom.test.ts b/src/components/bot-settings/useBotApps.dom.test.tsindex 98f8bc1f1b..26bff2b66d 100644--- a/src/components/bot-settings/useBotApps.dom.test.ts+++ b/src/components/bot-settings/useBotApps.dom.test.ts@@ -9,12 +9,20 @@ import type { Bot } from "@/state/store";const fixture = vi.hoisted(() => ({holdCatalog: false,+ holdInventory: false,+ answerInventory: null as null | (() => void),answerCatalog: null as null | ((ok: boolean) => void),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 } } }),+ preloadConnectedApps: () => {+ const inventory = { authoritative: true, services: { github: { connected: true } } };+ if (!fixture.holdInventory) return Promise.resolve(inventory);+ return new Promise((resolve) => {+ fixture.answerInventory = () => resolve(inventory);+ });+ },}));vi.mock("@/state/store", async (importOriginal) => {const original = await importOriginal<typeof import("@/state/store")>();@@ -66,6 +74,8 @@ afterEach(() => {host = null;root = null;fixture.holdCatalog = false;+ fixture.holdInventory = false;+ fixture.answerInventory = null;fixture.answerCatalog = null;fixture.answerEmail = null;});@@ -115,4 +125,22 @@ describe("app names for the settings search", () => {await settle();expect(view.textContent).toBe("ready:email,github");});++ it("is loading while a new lookup's inventory is pending, even with an earlier inventory in hand", async () => {+ const view = render();+ await settle();+ fixture.answerEmail?.(false);+ await settle();+ expect(view.textContent).toBe("ready:github");+ fixture.holdInventory = true;+ render(false);+ render(true);+ await settle();+ fixture.answerEmail?.(false);+ await settle();+ expect(view.textContent).toBe("loading:github");+ fixture.answerInventory?.();+ await settle();+ expect(view.textContent).toBe("ready:github");+ });});diff --git a/src/components/bot-settings/useBotApps.ts b/src/components/bot-settings/useBotApps.tsindex 32d2c0d5da..12ac669c54 100644--- a/src/components/bot-settings/useBotApps.ts+++ b/src/components/bot-settings/useBotApps.ts@@ -73,8 +73,10 @@ export function botAppsFrom(return { phase: "ready", apps, connectedSlugs };}-/** The apps plus whether the app catalog and Email lookups have answered (or failed); the values alone can't tell pending from failed. */+/** The apps plus whether this lookup's inventory, app catalog and Email requests have answered (or failed); the values alone+ * can't tell pending from failed, and an inventory kept from an earlier lookup is not this lookup's answer. */export interface BotAppsState extends BotApps {+ inventorySettled: boolean;cardsSettled: boolean;emailSettled: boolean;}@@ -84,16 +86,20 @@ 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 [inventorySettled, setInventorySettled] = useState(false);const [cardsSettled, setCardsSettled] = useState(false);const [emailSettled, setEmailSettled] = useState(false);useEffect(() => {if (!load) return;let cancelled = false;+ setInventorySettled(false);setCardsSettled(false);setEmailSettled(false);void preloadConnectedApps().then((result) => {- if (!cancelled) setInventory(result);+ if (cancelled) return;+ setInventory(result);+ setInventorySettled(true);});void loadAppCards().then((result) => {if (cancelled) return;@@ -109,5 +115,5 @@ export function useBotApps(bot: Bot, load = true): BotAppsState {};}, [load]);- return { ...botAppsFrom(bot, inventory, cards, email), cardsSettled, emailSettled };+ return { ...botAppsFrom(bot, inventory, cards, email), inventorySettled, cardsSettled, emailSettled };}