Skip to content

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

Antigravity accounts: a refused Cancel keeps the sign-in open; an accepted sign-in closes before the refresh

laijsg12fa23314bfc3
diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsx
index 06892515d4..a44978a9bd 100644
--- a/src/components/EngineSetup.tsx
+++ b/src/components/EngineSetup.tsx
@@ -320,10 +320,16 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
const { auth } = await api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/status?flowId=${encodeURIComponent(flowId)}`);
if (!live || auth.phase === "waiting" || auth.phase === "verifying") return;
if (auth.phase !== "succeeded") return ended(auth.phase === "expired" ? t("engineSetup.googleExpired") : auth.message ?? t("engineSetup.googleFailed"));
+ if (done.current) {
+ ended(null);
+ done.current();
+ void refreshInstances().catch(() => {});
+ void refreshModels(instance.instanceId).catch(() => {});
+ return;
+ }
await refreshInstances();
await refreshModels(instance.instanceId);
ended(null);
- if (live) done.current?.();
} catch (cause) {
// 404: this sign-in is gone on the server (finished through the pasted redirect, or its session ended).
if (cause instanceof ApiError && cause.status === 404) {
@@ -357,11 +363,30 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
else window.open(link, "_blank", "noopener,noreferrer");
};
+ const signedIn = async () => {
+ if (!done.current) {
+ await refreshInstances();
+ await refreshModels(instance.instanceId);
+ return;
+ }
+ done.current();
+ void refreshInstances().catch(() => {});
+ void refreshModels(instance.instanceId).catch(() => {});
+ };
+
const cancelled = useRef(false);
- const cancelFlow = (id: string) => api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/cancel`, { method: "POST", body: JSON.stringify({ flowId: id }) }).catch(() => {});
+ const cancelFlow = (id: string) => api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/cancel`, { method: "POST", body: JSON.stringify({ flowId: id }) });
const cancel = async () => {
cancelled.current = true;
- if (flow) await cancelFlow(flow.flowId);
+ if (flow) {
+ try {
+ await cancelFlow(flow.flowId);
+ } catch (cause) {
+ cancelled.current = false;
+ setError(cause instanceof Error ? cause.message : String(cause));
+ return;
+ }
+ }
onDone?.();
};
@@ -370,15 +395,10 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
signInStarted();
const { auth } = await api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/start`, { method: "POST" });
if (cancelled.current) {
- if (auth.flowId) await cancelFlow(auth.flowId);
- return;
- }
- if (auth.phase === "succeeded") {
- await refreshInstances();
- await refreshModels(instance.instanceId);
- onDone?.();
+ if (auth.flowId) await cancelFlow(auth.flowId).catch(() => {});
return;
}
+ if (auth.phase === "succeeded") return signedIn();
if (!auth.flowId || !auth.authorizationUrl) throw new Error(t("engineSetup.googleNoLink"));
setFlow({ flowId: auth.flowId, authorizationUrl: auth.authorizationUrl, pastedCode: auth.kind === "pasted-code" });
await openLink(auth.authorizationUrl);
@@ -391,9 +411,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
body: JSON.stringify({ flowId: flow.flowId, callbackUrl }),
});
setCallbackUrl("");
- await refreshInstances();
- await refreshModels(instance.instanceId);
- onDone?.();
+ await signedIn();
});
const check = () => run("check", async () => {
@@ -500,7 +518,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
</>
)}
{error && <p className="text-[12px] text-danger">{error}</p>}
- {onDone && <button type="button" onClick={() => void cancel()} className="rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control">{t("common.cancel")}</button>}
+ {onDone && <button type="button" disabled={busy === "complete"} onClick={() => void cancel()} className="rounded-lg disabled:opacity-50 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control">{t("common.cancel")}</button>}
</div>
);
}
diff --git a/src/components/EnginesSettings.antigravity.dom.test.ts b/src/components/EnginesSettings.antigravity.dom.test.ts
index c7524bc2a2..4c2639d99d 100644
--- a/src/components/EnginesSettings.antigravity.dom.test.ts
+++ b/src/components/EnginesSettings.antigravity.dom.test.ts
@@ -1,6 +1,4 @@
// @vitest-environment happy-dom
-// Settings → AI and the chat's AI sign-in card: every Google Gemini (Antigravity) account on one card, as Claude's and
-// ChatGPT's are.
import { act, createElement } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -11,14 +9,17 @@ const fixture = vi.hoisted(() => ({
state: { instances: [] as InstanceInfo[], bots: [] as Bot[], config: {} as Record<string, unknown> },
calls: [] as Array<{ path: string; method: string; body: unknown }>,
startGate: null as Promise<void> | null,
+ completeGate: null as Promise<void> | null,
opened: [] as string[],
+ cancelFails: false,
+ modelsFail: false,
}));
vi.mock("@/state/store", async (original) => ({
...await original<typeof import("@/state/store")>(),
useStore: () => ({
state: fixture.state,
dispatch: (action: { type: string; instances?: InstanceInfo[] }) => { if (action.type === "instances" && action.instances) fixture.state = { ...fixture.state, instances: action.instances }; },
- refreshInstances: async () => {}, refreshModels: async () => {},
+ refreshInstances: async () => {}, refreshModels: async () => { if (fixture.modelsFail) throw new Error("Could not read the models."); },
}),
api: async (path: string, init?: { method?: string; body?: string }) => {
if (init?.method) fixture.calls.push({ path, method: init.method, body: init.body ? JSON.parse(init.body) : undefined });
@@ -27,6 +28,8 @@ vi.mock("@/state/store", async (original) => ({
return { instanceId: added.instanceId, instances: [...fixture.state.instances, added] };
}
if (path.endsWith("/auth/start") && fixture.startGate) await fixture.startGate;
+ if (path.endsWith("/auth/complete") && fixture.completeGate) await fixture.completeGate;
+ if (path.endsWith("/auth/cancel") && fixture.cancelFails) throw new Error("The sign-in is finishing. Try again in a moment.");
if (path.endsWith("/auth/start")) return { auth: { phase: "waiting", flowId: `flow-${path.split("/")[3]}`, authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=fixture" } };
if (path.includes("/auth/status")) return { auth: { phase: "waiting" } };
return {};
@@ -57,7 +60,10 @@ beforeEach(() => {
fixture.state = { instances: [google("antigravity", "Google Gemini (Antigravity)", { account: { email: "[email protected]" } })], bots: [], config: {} };
fixture.calls = [];
fixture.startGate = null;
+ fixture.completeGate = null;
fixture.opened = [];
+ fixture.cancelFails = false;
+ fixture.modelsFail = false;
container = document.createElement("div"); document.body.append(container); root = createRoot(container);
});
afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.unstubAllGlobals(); });
@@ -73,6 +79,13 @@ const click = async (target: Element | undefined) => { expect(target).toBeTruthy
const row = (instanceId: string) => container.querySelector(`[data-account="${instanceId}"]`)!;
const rows = () => [...container.querySelectorAll('[data-accounts="antigravity"] [data-account]')].map((item) => item.getAttribute("data-account"));
const startCalls = () => fixture.calls.filter((call) => call.path.endsWith("/auth/start")).map((call) => call.path);
+async function pasteRedirect(instanceId: string) {
+ const input = row(instanceId).querySelector<HTMLInputElement>("[data-redirect-paste] input")!;
+ await act(async () => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, "http://127.0.0.1:1/?state=fixture&code=x");
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+}
async function openSimpleCard() {
await render("simple");
await click(container.querySelector('[data-simple-engine="antigravity"] button') ?? undefined);
@@ -156,16 +169,44 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {
fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
await render();
await click(buttons(row("antigravity"), "Sign in")[0]);
- const input = row("antigravity").querySelector<HTMLInputElement>("[data-redirect-paste] input")!;
- await act(async () => {
- Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, "http://127.0.0.1:1/?state=fixture&code=x");
- input.dispatchEvent(new Event("input", { bubbles: true }));
- });
+ await pasteRedirect("antigravity");
await click(buttons(row("antigravity"), "Send redirect")[0]);
expect(fixture.calls.at(-1)).toMatchObject({ path: "/api/instances/antigravity/auth/complete", method: "POST" });
expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
});
+ it("keeps the sign-in open and says why when the server could not cancel it", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ fixture.cancelFails = true;
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await click(buttons(row("antigravity"), "Cancel")[0]);
+ expect(row("antigravity").querySelector("[data-account-sign-in]")?.textContent).toContain("The sign-in is finishing. Try again in a moment.");
+ });
+
+ it("offers no Cancel while a pasted redirect is being sent", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ let send!: () => void;
+ fixture.completeGate = new Promise((resolve) => { send = resolve; });
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await pasteRedirect("antigravity");
+ await click(buttons(row("antigravity"), "Send redirect")[0]);
+ expect(buttons(row("antigravity"), "Cancel")[0]?.disabled).toBe(true);
+ await act(async () => { send(); await fixture.completeGate; });
+ });
+
+ it("closes the panel of a sign-in the server accepted even when the models cannot be read yet", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ fixture.modelsFail = true;
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await pasteRedirect("antigravity");
+ await click(buttons(row("antigravity"), "Send redirect")[0]);
+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
+ expect(container.textContent).not.toContain("Could not read the models.");
+ });
+
it("signs in an account whose status could not be read, rather than offering an install", async () => {
fixture.state.instances = [google("antigravity", "Google Gemini (Antigravity)", { authenticated: undefined, nativeCli: true })];
await render();