Skip to content

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

fix(engine-setup): open the paste-the-redirect step when signing in on a Cloud

AdityaUmale24402e5dc199
diff --git a/src/components/EngineSetup.antigravity.test.ts b/src/components/EngineSetup.antigravity.test.ts
new file mode 100644
index 0000000000..6773704d7b
--- /dev/null
+++ b/src/components/EngineSetup.antigravity.test.ts
@@ -0,0 +1,58 @@
+// @vitest-environment happy-dom
+import { createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+
+import { setLocale } from "@/lib/i18n";
+import { BotEditorStore, type InstanceInfo, type useStore } from "@/state/store";
+import { EngineSetup } from "./EngineSetup";
+
+const antigravity: InstanceInfo = {
+ instanceId: "antigravity", driverKind: "antigravityAgent", displayName: "Antigravity",
+ models: { default: "gemini", options: [] },
+ snapshot: { state: "available", authenticated: false, version: "1.1.1" },
+ install: { managed: { label: "Install official Antigravity", downloadBytes: 1024 } },
+};
+
+let host: HTMLDivElement;
+let root: Root;
+
+beforeEach(() => {
+ setLocale("en");
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({
+ auth: { phase: "pending", flowId: "flow-1", authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=s" },
+ }), { status: 200, headers: { "content-type": "application/json" } })));
+});
+
+afterEach(() => {
+ flushSync(() => root.unmount());
+ host.remove();
+ vi.unstubAllGlobals();
+});
+
+/** Starts the Google sign-in and returns the "Signing in from another computer?" fold. */
+async function startSignIn(cloudHome: boolean, ogb: object): Promise<HTMLDetailsElement> {
+ vi.stubGlobal("ogb", { platform: "linux", openExternal: vi.fn(async () => {}), ...ogb });
+ const store = { state: { config: cloudHome ? { cloudHome: true } : {} }, dispatch: vi.fn(), refreshInstances: vi.fn(async () => {}), refreshModels: vi.fn(async () => {}) } as unknown as ReturnType<typeof useStore>;
+ flushSync(() => root.render(createElement(BotEditorStore, { value: store, children: createElement(EngineSetup, { instance: antigravity }) })));
+ const button = [...host.querySelectorAll("button")].find((b) => b.textContent?.includes("Sign in with Google"))!;
+ button.click();
+ await vi.waitFor(() => expect(host.querySelector("details")).not.toBeNull());
+ return host.querySelector("details")!;
+}
+
+it("opens the paste-the-redirect step on a Cloud, where Google's 127.0.0.1 redirect can't reach the server", async () => {
+ expect((await startSignIn(true, { remoteClient: { active: false } })).open).toBe(true);
+});
+
+it("opens it on a desktop paired to another computer's server", async () => {
+ expect((await startSignIn(false, { remoteClient: { active: true } })).open).toBe(true);
+});
+
+it("keeps it folded on the person's own computer, where the redirect lands by itself", async () => {
+ expect((await startSignIn(false, { remoteClient: { active: false } })).open).toBe(false);
+});
diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsx
index 85db99d0b5..370fd0425d 100644
--- a/src/components/EngineSetup.tsx
+++ b/src/components/EngineSetup.tsx
@@ -33,6 +33,12 @@ export function serverTerminal(cloudHome: boolean): boolean {
return Boolean(window.ogb?.openInstallTerminal) && window.ogb?.remoteClient?.active !== true && !cloudHome;
}
+/** Google's redirect goes to 127.0.0.1 on the server, which the person's browser can't reach when the server is a Cloud or
+ * another computer: there the paste-the-redirect step is the only way to finish, so it starts open. */
+export function redirectPasteOpen(cloudHome: boolean): boolean {
+ return cloudHome || window.ogb?.remoteClient?.active === true;
+}
+
export function grokKeyInstead(instance: InstanceInfo, cloudHome: boolean): boolean {
return instance.driverKind === "grokAgent" && needsCli(instance) && !serverTerminal(cloudHome);
}
@@ -270,7 +276,7 @@ export function EngineWarningNotice({
}
function ManagedEngineSetup({ instance, signInOnly }: { instance: InstanceInfo; signInOnly: boolean }) {
- const { refreshInstances, refreshModels } = useStore();
+ const { state, refreshInstances, refreshModels } = useStore();
const [busy, setBusy] = useState<"install" | "signin" | "complete" | "check" | null>(null);
const [error, setError] = useState<string | null>(null);
const [flow, setFlow] = useState<{ flowId: string; authorizationUrl: string } | null>(null);
@@ -369,7 +375,7 @@ function ManagedEngineSetup({ instance, signInOnly }: { instance: InstanceInfo;
<button type="button" onClick={() => void check()} className="w-full rounded-lg bg-control px-3 py-2 text-[12px] font-semibold text-ink hover:bg-raised-hover">
{busy === "check" ? t("common.checking") : t("engineSetup.finishedSignIn")}
</button>
- <details className="rounded-lg border border-hairline/50 bg-app px-2.5 py-2 text-[12px] text-ink-secondary">
+ <details open={redirectPasteOpen(state.config?.cloudHome === true)} className="rounded-lg border border-hairline/50 bg-app px-2.5 py-2 text-[12px] text-ink-secondary">
<summary className="cursor-pointer select-none">{t("engineSetup.otherComputer")}</summary>
<p className="mt-2 leading-relaxed">{t("engineSetup.otherComputerHint")}</p>
<input