Skip to content

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

Train fix (#5975): closing the move dialog ends the connector link

milind-soniff171b1e5bd6
diff --git a/src/components/GrokMoveDialog.test.ts b/src/components/GrokMoveDialog.test.ts
index df20e3055a..a4aca7d146 100644
--- a/src/components/GrokMoveDialog.test.ts
+++ b/src/components/GrokMoveDialog.test.ts
@@ -229,6 +229,22 @@ describe("Move from Grok Bot", () => {
vi.useRealTimers();
});
+ it("ends the link when the dialog closes", async () => {
+ vi.stubGlobal("ogb", { remoteClient: { active: false } });
+ const calls: string[] = [];
+ f.api.mockImplementation(async (path: string, init?: { method?: string }) => {
+ if (!path.startsWith("/api/setup-import/grok/connector")) return path === "/api/mcp/servers" ? { servers: [] } : {};
+ calls.push(`${init?.method} ${path}`);
+ return { available: true, connectorUrl: "https://quiet-test-words.trycloudflare.com/mcp/move/abc", arrived: [] };
+ });
+ await open();
+ expect(host.querySelector('input[aria-label="Link for Grok Bot"]')).not.toBeNull();
+ expect(calls).not.toContain("DELETE /api/setup-import/grok/connector");
+ await act(async () => root.unmount());
+ root = createRoot(host);
+ expect(calls.at(-1)).toBe("DELETE /api/setup-import/grok/connector");
+ });
+
it("says when the link stopped, keeps the Bots that had arrived, and offers a new link", async () => {
vi.useFakeTimers({ toFake: ["setInterval", "clearInterval"] });
vi.stubGlobal("ogb", { remoteClient: { active: false } });
diff --git a/src/components/GrokMoveDialog.tsx b/src/components/GrokMoveDialog.tsx
index caf337f17e..414bb004cb 100644
--- a/src/components/GrokMoveDialog.tsx
+++ b/src/components/GrokMoveDialog.tsx
@@ -182,7 +182,18 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi
/** The Bots in the preview came through the link, so a finished import ends it. */
const viaLink = useRef(false);
const arrived = useMemo(() => foundExports(arrivedFiles).bots, [arrivedFiles]);
+ /** Leaving the dialog ends the link, so nothing stays open to the internet once the person has left the move. */
+ const linkOpen = useRef(false);
+ const left = useRef(false);
+ useEffect(() => {
+ left.current = false;
+ return () => {
+ left.current = true;
+ if (linkOpen.current) void grokConnector("DELETE").catch(() => {});
+ };
+ }, []);
const takeConnector = useCallback((next: GrokConnector) => {
+ linkOpen.current = Boolean(next.connectorUrl);
setConnector({ available: next.available, stopped: next.stopped, ...(next.connectorUrl ? { connectorUrl: next.connectorUrl } : {}) });
if (!next.connectorUrl && !next.stopped) {
lastSeq.current = 0;
@@ -205,7 +216,10 @@ export function GrokMoveDialog({ onClose, inline = false }: { onClose: () => voi
const connect = async () => {
setConnecting(true);
setConnectFailed(false);
- await grokConnector("POST").then(takeConnector, () => setConnectFailed(true));
+ await grokConnector("POST").then((next) => {
+ if (!left.current) return takeConnector(next);
+ if (next.connectorUrl) void grokConnector("DELETE").catch(() => {});
+ }, () => setConnectFailed(true));
setConnecting(false);
};