Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Antigravity accounts: Cancel ends the sign-in on the server; a finished sign-in closes its panel
laijsg11c48f3febd89
diff --git a/src/components/EngineAccounts.tsx b/src/components/EngineAccounts.tsxindex ab596c78a8..40dec220d0 100644--- a/src/components/EngineAccounts.tsx+++ b/src/components/EngineAccounts.tsx@@ -217,7 +217,6 @@ function AccountRow({ group, instance, several, signingIn, onSignIn, onSignInDon: state === "signedOut" ? t("accounts.notSignedIn"): state === "unknown" ? t("accounts.unknown"): instance.snapshot.reason ?? t("onboarding.engines.needsSetup");- // An Antigravity account runs on its own runtime, so one of them can need installing while the others work.const setsUp = group === "antigravity" && state === "unavailable";const signedIn = state === "signedIn";useEffect(() => {@@ -261,10 +260,7 @@ function AccountRow({ group, instance, several, signingIn, onSignIn, onSignInDon)}</>: group === "antigravity"- ? <div data-account-sign-in={instance.instanceId}>- <AntigravitySignIn instance={instance} />- <button type="button" onClick={onSignInDone} className="mt-2 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control">{t("common.cancel")}</button>- </div>+ ? <div data-account-sign-in={instance.instanceId}><AntigravitySignIn instance={instance} onDone={onSignInDone} /></div>: <>{several && instance.authentication?.method === "device-code" && <p className="mt-2 text-[12px] leading-relaxed text-ink-secondary">{t("accounts.chatgptDeviceHint")}</p>}<DeviceSignIn instanceId={instance.instanceId} provider="codex" browserPkce={instance.authentication?.method === "browser-pkce"} autoStart onDone={onSignInDone} />@@ -354,7 +350,6 @@ export function AddAccount({ label, endpoint, extra, folder: offerFolder = false/** One card for a provider's accounts: who is signed in, one button for whoever is not, and one way to add another. */export function AccountsCard({ group, accounts, advanced, bare = false }: { group: AccountGroup; accounts: InstanceInfo[]; advanced?: ReactNode; bare?: boolean }) {const [signingIn, setSigningIn] = useState<readonly string[]>([]);- // A Google sign-in waits for its own redirect, so another account's must not end it; the other providers show one.const startSignIn = (instanceId: string) => setSigningIn((current) => group === "antigravity" ? [...current.filter((id) => id !== instanceId), instanceId] : [instanceId]);const endSignIn = (instanceId: string) => setSigningIn((current) => current.includes(instanceId) ? current.filter((id) => id !== instanceId) : current);const primary = accounts[0]!;diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsxindex 6052220bff..06892515d4 100644--- a/src/components/EngineSetup.tsx+++ b/src/components/EngineSetup.tsx@@ -285,12 +285,17 @@ function installsAntigravityCli(instance: InstanceInfo): boolean {return instance.driverKind === "antigravityAgent" && !/^agy_acp_server$/iu.test(instance.cli?.trim() ?? "");}-/** A Google sign-in for one Antigravity account, also when its last check could not tell whether it is signed in. */-export function AntigravitySignIn({ instance }: { instance: InstanceInfo }) {- return instance.install?.managed ? <ManagedEngineSetup instance={instance} signInOnly autoStart /> : <EngineSetup instance={instance} unframed />;+export function AntigravitySignIn({ instance, onDone }: { instance: InstanceInfo; onDone: () => void }) {+ return instance.install?.managed ? <ManagedEngineSetup instance={instance} signInOnly autoStart onDone={onDone} /> : <EngineSetup instance={instance} unframed />;}-function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { instance: InstanceInfo; signInOnly: boolean; autoStart?: boolean }) {+function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }: {+ instance: InstanceInfo;+ signInOnly: boolean;+ autoStart?: boolean;+ /** Signed in or cancelled; given, the panel offers Cancel. */+ onDone?: () => void;+}) {const { state, refreshInstances, refreshModels } = useStore();const signInStarted = useSignInStarted(instance.instanceId);const [busy, setBusy] = useState<"install" | "signin" | "complete" | "check" | null>(null);@@ -298,6 +303,8 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { instaconst [flow, setFlow] = useState<{ flowId: string; authorizationUrl: string; pastedCode: boolean } | null>(null);const [callbackUrl, setCallbackUrl] = useState("");const managed = instance.install!.managed!;+ const done = useRef(onDone);+ useEffect(() => { done.current = onDone; }, [onDone]);const flowId = flow?.flowId;useEffect(() => {@@ -316,6 +323,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { instaawait 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) {@@ -349,13 +357,26 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { instaelse window.open(link, "_blank", "noopener,noreferrer");};+ 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 cancel = async () => {+ cancelled.current = true;+ if (flow) await cancelFlow(flow.flowId);+ onDone?.();+ };+const signIn = () => run("signin", async () => {if (flow) return openLink(flow.authorizationUrl);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?.();return;}if (!auth.flowId || !auth.authorizationUrl) throw new Error(t("engineSetup.googleNoLink"));@@ -372,6 +393,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { instasetCallbackUrl("");await refreshInstances();await refreshModels(instance.instanceId);+ onDone?.();});const check = () => run("check", async () => {@@ -478,6 +500,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false }: { insta</>)}{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>}</div>);}diff --git a/src/components/EnginesSettings.antigravity.dom.test.ts b/src/components/EnginesSettings.antigravity.dom.test.tsindex 053e5b59c2..c7524bc2a2 100644--- a/src/components/EnginesSettings.antigravity.dom.test.ts+++ b/src/components/EnginesSettings.antigravity.dom.test.ts@@ -10,6 +10,8 @@ import { setLocale } from "@/lib/i18n";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,+ opened: [] as string[],}));vi.mock("@/state/store", async (original) => ({...await original<typeof import("@/state/store")>(),@@ -24,6 +26,7 @@ vi.mock("@/state/store", async (original) => ({const added = google("antigravity-work", "Work", { authenticated: false });return { instanceId: added.instanceId, instances: [...fixture.state.instances, added] };}+ if (path.endsWith("/auth/start") && fixture.startGate) await fixture.startGate;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 {};@@ -49,10 +52,12 @@ const other = (instanceId: string, displayName: string): InstanceInfo => ({let container: HTMLDivElement, root: Root;beforeEach(() => {vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);- vi.stubGlobal("open", () => null);+ vi.stubGlobal("open", (url: string) => { fixture.opened.push(url); return null; });setLocale("en");fixture.state = { instances: [google("antigravity", "Google Gemini (Antigravity)", { account: { email: "[email protected]" } })], bots: [], config: {} };fixture.calls = [];+ fixture.startGate = null;+ fixture.opened = [];container = document.createElement("div"); document.body.append(container); root = createRoot(container);});afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.unstubAllGlobals(); });@@ -125,6 +130,42 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {expect(row("antigravity-work").querySelector("[data-account-sign-in]")?.textContent).toContain("Open Google sign-in again");});+ it("cancels the account's Google sign-in on the server and closes its panel", async () => {+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];+ await render();+ await click(buttons(row("antigravity"), "Sign in")[0]);+ await click(buttons(row("antigravity"), "Cancel")[0]);+ expect(fixture.calls.at(-1)).toEqual({ path: "/api/instances/antigravity/auth/cancel", method: "POST", body: { flowId: "flow-antigravity" } });+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();+ expect(buttons(row("antigravity"), "Sign in")).toHaveLength(1);+ });++ it("opens no Google page for a sign-in cancelled before it started, and ends that flow", async () => {+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];+ let start!: () => void;+ fixture.startGate = new Promise((resolve) => { start = resolve; });+ await render();+ await click(buttons(row("antigravity"), "Sign in")[0]);+ await click(buttons(row("antigravity"), "Cancel")[0]);+ await act(async () => { start(); await fixture.startGate; });+ expect(fixture.opened).toEqual([]);+ expect(fixture.calls.at(-1)).toEqual({ path: "/api/instances/antigravity/auth/cancel", method: "POST", body: { flowId: "flow-antigravity" } });+ });++ it("closes the panel once the pasted redirect signs the account in, before its status is read again", async () => {+ 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 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("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();diff --git a/src/components/EnginesSettings.tsx b/src/components/EnginesSettings.tsxindex f65720a95a..4d86b1244b 100644--- a/src/components/EnginesSettings.tsx+++ b/src/components/EnginesSettings.tsx@@ -197,11 +197,7 @@ function CustomPicker({ instance, cliDefault, onClose, onSaved }: {}/** The executable behind an engine: its path, Claude's self-update, and a reset to the default. */-function EngineAdvanced({ instance, account }: {- instance: InstanceInfo;- /** Whose CLI path this is, when one card lists several accounts. */- account?: string;-}) {+function EngineAdvanced({ instance, accountName }: { instance: InstanceInfo; accountName?: string }) {const { refreshInstances } = useStoreActions();const showInstances = useShowInstances();const [open, setOpen] = useState(false);@@ -262,7 +258,7 @@ function EngineAdvanced({ instance, account }: {return (<details className="mt-4 border-t border-hairline/40 pt-3">- <summary className="cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent">{account ? `${t("engines.library.advanced")} · ${account}` : t("engines.library.advanced")}</summary>+ <summary className="cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent">{accountName ? `${t("engines.library.advanced")} · ${accountName}` : t("engines.library.advanced")}</summary><p className="mt-2 text-[12px] leading-relaxed text-ink-secondary">{t("engines.footer")}</p><div className="mt-3 flex flex-wrap items-center gap-2 text-[13px]">{instance.cli ? (@@ -535,10 +531,9 @@ function SimpleEngines({ rows, isReady, renderEngine, more, accountsOnly = false);}-/** Each Antigravity account keeps its own CLI path, so each keeps its own way to fix it. */function accountsAdvanced(group: AccountGroup, accounts: InstanceInfo[]): ReactNode {if (group === "antigravity") return accounts.map((account) => (- <EngineAdvanced key={account.instanceId} instance={account} account={accounts.length > 1 ? engineDisplayName(account) : undefined} />+ <EngineAdvanced key={account.instanceId} instance={account} accountName={accounts.length > 1 ? engineDisplayName(account) : undefined} />));return <>{group === "claude" ? <><ClaudeEndpoints /><ClaudeBedrockEndpoints /></> : <CodexEndpoints />}<EngineAdvanced instance={accounts[0]!} /></>;}