From 3fd66c0e12331fd34b7aac1011c2cab0b6f86ec1 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Fri, 27 Nov 2026 13:37:22 +0000 Subject: [PATCH] fix(ui): surface local and hosted sign-in actions on the primary footer button (#23112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Operators connect AI subscriptions (such as Google Antigravity, Claude, and Codex) through `AgentProviderConnection` and `OnboardingWizard`, which share `FooterNav` for the primary step button > - The remote sandbox login path (`AdapterLoginPanel`) updates the primary footer button to `Sign in to `, `Retry sign-in`, or `Connecting`, but the local and hosted sign-in path (`useLocalAiLogin` + `LocalProviderLoginInstructions`) did not wire into `FooterNav` > - As a result, the primary footer button stayed disabled and labeled `Connect` both when sign-in failed/expired and when a sign-in URL was ready, forcing users to hunt for a small muted inline link (`Start sign-in again` or `Sign in to Antigravity`) > - This pull request maps `useLocalAiLogin` state onto the shared primary footer button in both `AgentProviderConnection` and `OnboardingWizard` and hides the redundant inline retry link on failed/expired states when the footer owns it > - The benefit is that the required next action is always the prominent, enabled primary button on every connect screen ## Linked Issues or Issue Description **What happened?** On the Connect Antigravity subscription screens (and other `useLocalAiLogin` subscription flows), the bottom-right primary button remained disabled and labeled `Connect` while the required action was a small muted link inside the card (`Start sign-in again` on failed/expired sign-in, or `Sign in to Antigravity` when the OAuth URL was ready). **Expected behavior** - When sign-in fails or expires, the primary footer button should be enabled and labeled `Start sign in`, and clicking it should restart the sign-in flow. - When the sign-in URL is ready, the primary footer button should be enabled and labeled `Sign in to Antigravity` (or the active provider name), and clicking it should open the authorization URL in a new tab. - Once sign-in succeeds, the primary footer button should switch back to an enabled `Connect` button. **Steps to reproduce** 1. Open the Antigravity app connection screen (`/apps/connect?source=antigravity`) in a hosted environment with subscription mode selected. 2. Observe the sign-in prompt state: the primary bottom-right `Connect` button is disabled while `Sign in to Antigravity` is only a small underlined link inside the card. 3. Let the sign-in fail or expire and observe the error state: the primary bottom-right `Connect` button stays disabled while `Start sign-in again` is only a small underlined link. ## What Changed - `ui/src/components/AdapterLoginChrome.tsx`: - Added `resolveLocalLoginPrimaryAction` to map `useLocalAiLogin` state (`preparing`, `error`/`expired`, `submitting`, `sign_in_required` with valid HTTP(S) `authorizationUrl`, and `ready`) to a typed primary CTA descriptor. - Added optional `primaryHandlesRetry` and `onSubmittingChange` props to `LocalProviderLoginInstructions` so hosts that surface `Start sign in` and `Connecting` on `FooterNav` hide the redundant inline error retry link while standalone callers keep existing behavior. - `ui/src/components/new-agent/AgentProviderConnection.tsx`: - Wired `resolveLocalLoginPrimaryAction` into `FooterNav` (`primaryLabel`, `primaryDisabled`, `primaryIcon`, `onPrimary`) so failed/expired states render an enabled `Start sign in` button, ready authorization URLs render an enabled `Sign in to ` button that opens the URL in a new tab, and submitting/preparing states show spinner feedback. - `ui/src/components/OnboardingWizard.tsx`: - Wired `resolveLocalLoginPrimaryAction` into `connectCta` and `handleConnectStepPrimary` for the matching `LocalProviderLoginInstructions` branch so onboarding has the same primary CTA behavior. - `ui/src/components/AdapterLoginChrome.test.tsx`, `ui/src/components/new-agent/AgentProviderConnection.test.tsx`, `ui/src/pages/apps/AppsConnect.test.tsx`: - Added unit and render tests covering `resolveLocalLoginPrimaryAction`, `primaryHandlesRetry`, enabled `Sign in to Antigravity` opening the authorization URL, enabled `Start sign in` restarting failed/expired sign-in without a redundant inline link, and returning to enabled `Connect` once ready. ## Verification - Ran `pnpm --filter @paperclipai/ui typecheck` — passed. - Ran `pnpm exec vitest run ui/src/components/AdapterLoginChrome.test.tsx ui/src/components/new-agent/AgentProviderConnection.test.tsx ui/src/pages/apps/AppsConnect.test.tsx ui/src/components/ai-connections/useLocalAiLogin.test.tsx` — 4 test files, 39 tests passed. ## Risks - Low risk: UI-only change scoped to the `useLocalAiLogin` branch of `AgentProviderConnection` and `OnboardingWizard`. Standalone `LocalProviderLoginInstructions` callers default to `primaryHandlesRetry = false`, and authorization URLs are validated as `http:` or `https:` before calling `window.open`. ## Model Used - Google Gemini (Antigravity agent with tool use, file editing, and shell execution). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip --- .../e2e/conference-room-typing-intro.spec.ts | 3 +- ui/src/components/AdapterLoginChrome.test.tsx | 66 +++++++++ ui/src/components/AdapterLoginChrome.tsx | 135 ++++++++++++++++-- ui/src/components/OnboardingWizard.tsx | 119 +++++++++++---- .../AgentProviderConnection.test.tsx | 87 +++++++++++ .../new-agent/AgentProviderConnection.tsx | 41 +++++- ui/src/pages/apps/AppsConnect.test.tsx | 5 + 7 files changed, 412 insertions(+), 44 deletions(-) diff --git a/tests/e2e/conference-room-typing-intro.spec.ts b/tests/e2e/conference-room-typing-intro.spec.ts index b759d5d9a15..40f675d78b9 100644 --- a/tests/e2e/conference-room-typing-intro.spec.ts +++ b/tests/e2e/conference-room-typing-intro.spec.ts @@ -144,7 +144,8 @@ test.describe("Chat launch after onboarding wizard", () => { await runOnboardingWizard(page, companyName, { source: /Claude/, complete: async () => { const code = page.getByRole("textbox", { name: "Authorization code", exact: true }); await expect(code).toBeVisible({ timeout: 20_000 }); - await expect(page.getByRole("button", { name: "Connect", exact: true })).toBeDisabled(); + await expect(page.getByRole("button", { name: "Sign in to Claude", exact: true })).toBeEnabled(); + await expect(page.getByRole("button", { name: "Connect", exact: true })).toHaveCount(0); await code.evaluate(input => { const clipboardData = new DataTransfer(); clipboardData.setData("text/plain", "fixture-authorization-code"); diff --git a/ui/src/components/AdapterLoginChrome.test.tsx b/ui/src/components/AdapterLoginChrome.test.tsx index 2f70c6aba4d..93163e36be7 100644 --- a/ui/src/components/AdapterLoginChrome.test.tsx +++ b/ui/src/components/AdapterLoginChrome.test.tsx @@ -11,6 +11,7 @@ import { OnboardingCardField, OnboardingLoginCodeRow, onboardingCardInputClass, + resolveLocalLoginPrimaryAction, } from "./AdapterLoginChrome"; import { isBlockedFromReplay, replayLeaks } from "@/lib/analytics/replay-recording.test-utils"; @@ -356,4 +357,69 @@ describe("session replay", () => { expect(container.querySelector('input[aria-label="Antigravity redirect URL"]')).toBeNull(); expect(container.textContent).toContain("Finish signing in in the Antigravity browser window"); }); + + it("hides the inline error retry link only when primaryHandlesRetry is enabled", async () => { + const failedLogin = { + ...login, + status: "expired" as const, + error: "Google sign-in did not complete. Start sign-in again.", + }; + const standalone = await render( + , + ); + expect(standalone.textContent).toContain("Start sign-in again"); + + const footerOwned = await render( + , + ); + expect(footerOwned.textContent).toContain("Google sign-in did not complete."); + expect(Array.from(footerOwned.querySelectorAll("button")).find(b => b.textContent === "Start sign-in again")).toBeUndefined(); + }); + + it("maps local/hosted sign-in state to the expected primary footer CTA", () => { + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: true, status: null, error: null }, + })).toEqual({ kind: "preparing", label: "Preparing sign-in…", icon: "spinner", disabled: true }); + + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: false, status: "expired", error: "Google sign-in did not complete. Start sign-in again." }, + })).toEqual({ kind: "retry", label: "Start sign in", icon: "arrow", disabled: false }); + + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: false, status: "sign_in_required", authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth", error: null }, + })).toEqual({ kind: "open_sign_in", label: "Sign in to Antigravity", icon: "none", disabled: false, url: "https://accounts.google.com/o/oauth2/v2/auth" }); + + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: false, status: "sign_in_required", authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth", error: null }, + submitting: true, + })).toEqual({ kind: "connecting", label: "Connecting", icon: "spinner", disabled: true }); + + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: false, status: "sign_in_required", authorizationUrl: "javascript:alert(1)", error: null }, + })).toEqual({ kind: "waiting", label: "Connect", icon: "arrow", disabled: true }); + + expect(resolveLocalLoginPrimaryAction({ + adapterType: "antigravity_runtime", + login: { isolated: true, preparing: false, status: "ready", error: null }, + })).toBeNull(); + }); + + it("omits the inline sign-in card anchor when authorizationUrl is not http(s)", async () => { + const container = await render( + , + ); + expect(container.querySelector("a")).toBeNull(); + }); }); diff --git a/ui/src/components/AdapterLoginChrome.tsx b/ui/src/components/AdapterLoginChrome.tsx index 47a81874fdd..f72e5eb7e46 100644 --- a/ui/src/components/AdapterLoginChrome.tsx +++ b/ui/src/components/AdapterLoginChrome.tsx @@ -505,10 +505,122 @@ export function ProviderApiKeyCard({ ); } +function isHttpAuthorizationUrl(url: string | null | undefined): url is string { + if (!url) return false; + try { + const parsed = new URL(url); + return parsed.protocol === "https:" || parsed.protocol === "http:"; + } catch { + return false; + } +} + +export type LocalLoginPrimaryAction = + | { kind: "retry"; label: string; icon: "arrow"; disabled: false } + | { kind: "open_sign_in"; label: string; icon: "none"; disabled: false; url: string } + | { kind: "connecting"; label: string; icon: "spinner"; disabled: true } + | { kind: "preparing"; label: string; icon: "spinner"; disabled: true } + | { kind: "waiting"; label: string; icon: "arrow"; disabled: true } + | null; + +/** Maps local/hosted sign-in state to the step footer's primary CTA. */ +export function resolveLocalLoginPrimaryAction({ + adapterType, + login, + submitting = false, +}: { + adapterType: string; + login?: { + isolated?: boolean; + authorizationUrl?: string | null; + preparing: boolean; + status?: "ready" | "sign_in_required" | "expired" | null; + error: string | null; + }; + submitting?: boolean; +}): LocalLoginPrimaryAction { + if (!login || login.status === "ready") return null; + const browserLogin = adapterType === "claude_local" || adapterType === "codex_local" || adapterType === "antigravity_runtime"; + if (login.preparing) { + return { kind: "preparing", label: "Preparing sign-in…", icon: "spinner", disabled: true }; + } + if (Boolean(login.error) || login.status === "expired") { + return { + kind: "retry", + label: login.isolated === false ? "Check again" : "Start sign in", + icon: "arrow", + disabled: false, + }; + } + if (submitting) { + return { kind: "connecting", label: "Connecting", icon: "spinner", disabled: true }; + } + if (browserLogin && isHttpAuthorizationUrl(login.authorizationUrl)) { + return { + kind: "open_sign_in", + label: `Sign in to ${connectSourceName(adapterType)}`, + icon: "none", + disabled: false, + url: login.authorizationUrl, + }; + } + if (browserLogin && !login.authorizationUrl) { + return { kind: "preparing", label: "Preparing sign-in…", icon: "spinner", disabled: true }; + } + return { kind: "waiting", label: "Connect", icon: "arrow", disabled: true }; +} + +/** Shared controller hook that wires local/hosted sign-in state to a host's FooterNav primary CTA. */ +export function useLocalLoginPrimaryAction({ + enabled, + adapterType, + login, + onBeforeRetry, +}: { + enabled: boolean; + adapterType: string; + login: { + isolated?: boolean; + authorizationUrl?: string | null; + preparing: boolean; + status?: "ready" | "sign_in_required" | "expired" | null; + error: string | null; + retry: () => void; + }; + onBeforeRetry?: () => void; +}) { + const [submitting, setSubmitting] = useState(false); + const action = enabled + ? resolveLocalLoginPrimaryAction({ adapterType, login, submitting }) + : null; + function runPrimary(): boolean { + if (!action) return false; + if (action.kind === "retry") { + onBeforeRetry?.(); + login.retry(); + } else if (action.kind === "open_sign_in") { + window.open(action.url, "_blank", "noreferrer,noopener"); + } + return true; + } + return { + action, + runPrimary, + resetSubmitting: () => setSubmitting(false), + instructionsProps: { + primaryHandlesRetry: true, + onSubmittingChange: setSubmitting, + }, + }; +} + /** Shared instructions for local subscription setup in every authentication host. */ -export function LocalProviderLoginInstructions({ adapterType, login, hostedRedirect = false }: { +export function LocalProviderLoginInstructions({ adapterType, login, hostedRedirect = false, primaryHandlesRetry = false, onSubmittingChange }: { adapterType: string; hostedRedirect?: boolean | "optional"; + /** Omit the inline retry link when an error/expiry is already surfaced on the primary footer CTA. */ + primaryHandlesRetry?: boolean; + onSubmittingChange?: (submitting: boolean) => void; login?: { isolated?: boolean; command?: string; authorizationUrl?: string | null; code?: string | null; accountLabel?: string | null; submitCode?: (code: string) => Promise; preparing: boolean; status?: "ready" | "sign_in_required" | "expired" | null; error: string | null; retry: () => void }; }) { const [showCommand, setShowCommand] = useState(false); @@ -524,6 +636,10 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir setCodeSubmitted(false); setSubmitError(null); }, [login?.authorizationUrl, login?.preparing]); + useEffect(() => { + onSubmittingChange?.(submitting || codeSubmitted); + }, [submitting, codeSubmitted, onSubmittingChange]); + useEffect(() => () => onSubmittingChange?.(false), [onSubmittingChange]); const provider = adapterType === "antigravity_runtime" ? "Antigravity" : adapterType === "claude_local" ? "Claude Code" : adapterType === "grok_local" ? "Grok CLI" : "Codex CLI"; const isolated = login?.isolated ?? (adapterType === "codex_local" || adapterType === "grok_local"); const command = login?.command; @@ -566,17 +682,20 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir } if (login?.preparing) return

Preparing sign-in…

; const ready = login?.status === "ready"; - const awaitingBrowserSignIn = browserLogin && !ready && !login?.authorizationUrl && !login?.error; + const needsRetry = Boolean(login?.error) || login?.status === "expired"; + const safeAuthorizationUrl = isHttpAuthorizationUrl(login?.authorizationUrl) ? login.authorizationUrl : null; + const awaitingBrowserSignIn = browserLogin && !ready && !login?.authorizationUrl && !needsRetry; + const showInlineRetry = Boolean(login && !login.preparing && !ready && !awaitingBrowserSignIn && (isolated || login.error) && !(primaryHandlesRetry && needsRetry)); return
{ready ? <>

{login?.accountLabel ?? provider} is signed in. Click Connect to use this account.

{!showCommand && } : !browserLogin &&

{isolated ? `Sign in to ${provider} for this connection on the machine running Paperclip. Your existing terminal login stays separate.` : `Connect uses your local ${provider} account on the machine running Paperclip.`}

} {awaitingBrowserSignIn &&

Preparing browser sign-in…

} - {(submitting || codeSubmitted) && !ready && !login?.error &&

Finishing sign-in…

} - {browserLogin && !ready && !submitting && !codeSubmitted && !login?.error && login?.authorizationUrl && Finishing sign-in…

} + {browserLogin && !ready && !submitting && !codeSubmitted && !needsRetry && safeAuthorizationUrl && {adapterType === "claude_local" ?
@@ -609,9 +728,9 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir /> {submitError &&

{submitError}

} -
: adapterType === "antigravity_runtime" ?

Finish signing in in the Antigravity browser window, then return here.

: } +
: adapterType === "antigravity_runtime" ?

Finish signing in in the Antigravity browser window, then return here.

: } } - {!browserLogin && (!ready || showCommand) && !login?.error && <> + {!browserLogin && (!ready || showCommand) && !needsRetry && <>

Run this in a terminal on that machine and finish signing in in your browser. We’ll check automatically when you return.

{command &&
{command}
@@ -619,6 +738,6 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir
} } {login?.error &&

{login.error}

} - {login && !login.preparing && !ready && !awaitingBrowserSignIn && (isolated || login.error) && } + {showInlineRetry && } ; } diff --git a/ui/src/components/OnboardingWizard.tsx b/ui/src/components/OnboardingWizard.tsx index 9c6451ff957..dd509235fb6 100644 --- a/ui/src/components/OnboardingWizard.tsx +++ b/ui/src/components/OnboardingWizard.tsx @@ -8,7 +8,11 @@ import { agentHarnessType, agentRunner } from "@paperclipai/shared"; import { adaptersApi, type AdapterInfo } from "../api/adapters"; import { healthApi } from "@/api/health"; import { describeError } from "@/api/errors"; -import { LocalProviderLoginInstructions } from "./AdapterLoginChrome"; +import { + LocalProviderLoginInstructions, + useLocalLoginPrimaryAction, + type LocalLoginPrimaryAction, +} from "./AdapterLoginChrome"; import { useLocalAiLogin } from "./ai-connections/useLocalAiLogin"; import { aiConnectionsApi } from "@/api/ai-connections"; import { cloudInferenceApi } from "@/api/cloud-inference"; @@ -66,6 +70,46 @@ type ConnectPhase = | "unwindCard" | "unwindRoom" | "unwindRow"; + +function resolveOnboardingConnectCta(input: { + setupError: boolean; + retryLogin: boolean; + connectProgress: string | null; + adapterEnvLoading: boolean; + connectPhase: ConnectPhase; + hasSubmitLoginCode: boolean; + adapterType: string; + connectStepNeedsLogin: boolean; + connectSourceLabel: string; + connectAuthUrl: string | null; + localLoginAction: LocalLoginPrimaryAction; + connectDisabled: boolean; +}): { label: string; icon: FooterPrimaryIcon; disabled: boolean } { + if (input.setupError) return { label: "Retry", icon: "arrow", disabled: false }; + if (input.retryLogin) return { label: "Retry sign-in", icon: "arrow", disabled: false }; + if (input.connectProgress) { + return { label: input.adapterEnvLoading ? "Testing…" : input.connectProgress, icon: "spinner", disabled: true }; + } + if ((input.connectPhase === "ready" || input.connectPhase === "waiting") && input.hasSubmitLoginCode) { + return { label: "Submit code", icon: "arrow", disabled: false }; + } + if (input.connectPhase === "waiting") { + return { label: input.adapterType === "codex_local" ? "Waiting for auth…" : "Waiting for code…", icon: "spinner", disabled: true }; + } + if (input.connectPhase === "connecting") return { label: "Connecting", icon: "spinner", disabled: true }; + if (input.connectPhase !== "ready") return { label: "Next", icon: "arrow", disabled: true }; + if (input.connectStepNeedsLogin) { + return { label: `Sign in to ${input.connectSourceLabel}`, icon: "none", disabled: !input.connectAuthUrl }; + } + if (input.localLoginAction) { + return { + label: input.localLoginAction.label, + icon: input.localLoginAction.icon, + disabled: input.localLoginAction.disabled, + }; + } + return { label: "Connect", icon: "arrow", disabled: input.connectDisabled }; +} import { secretsApi } from "../api/secrets"; import { Label } from "./ui/label"; import { Input } from "./ui/input"; @@ -1613,35 +1657,46 @@ function OnboardingWizardInner({ * easing width so those changes read as one control rather than four. */ const connectSourceLabel = CONNECT_SOURCE_NAMES[adapterType] ?? adapterType; - const connectCta: { label: string; icon: FooterPrimaryIcon; disabled: boolean } = - setupError ? { label: "Retry", icon: "arrow", disabled: false } - : retryLogin ? { label: "Retry sign-in", icon: "arrow", disabled: false } : connectProgress - ? { label: adapterEnvLoading ? "Testing…" : connectProgress, icon: "spinner", disabled: true } - : (connectPhase === "ready" || connectPhase === "waiting") && submitLoginCode - ? { label: "Submit code", icon: "arrow", disabled: false } - : connectPhase === "waiting" - ? { label: adapterType === "codex_local" ? "Waiting for auth…" : "Waiting for code…", icon: "spinner", disabled: true } - : connectPhase === "connecting" - ? { label: "Connecting", icon: "spinner", disabled: true } - : connectPhase === "ready" - ? connectStepNeedsLogin - ? { - label: `Sign in to ${connectSourceLabel}`, - icon: "none", - disabled: !connectAuthUrl, - } - : { - label: "Connect", - icon: "arrow", - disabled: - !connectStepReady || connectStepLoggingIn || (credentialMode === "api" && !apiKey.trim() && !selectedApiKey && !restoredApiCredential && !managedBindingForStep()), - } - : // Nothing is chosen on arrival, and the row is what chooses. Until - // it has been answered the button has nothing to do. - { label: "Next", icon: "arrow", disabled: true }; + const localLoginPrimary = useLocalLoginPrimaryAction({ + enabled: + sourcePicked && + connectPhase === "ready" && + canUseLocalLogin && + Boolean(managedProvider) && + credentialMode === "subscription" && + !hasSavedSubscription && + !managedBindingForStep() && + connectStepHasNoSandbox && + !connectStepNeedsLogin, + adapterType, + login: localLogin, + onBeforeRetry: () => { + autoConnectStartedRef.current = false; + setError(null); + }, + }); + const localLoginAction = localLoginPrimary.action; + const connectCta = resolveOnboardingConnectCta({ + setupError, + retryLogin: Boolean(retryLogin), + connectProgress, + adapterEnvLoading, + connectPhase, + hasSubmitLoginCode: Boolean(submitLoginCode), + adapterType, + connectStepNeedsLogin, + connectSourceLabel, + connectAuthUrl, + localLoginAction, + connectDisabled: + !connectStepReady || + connectStepLoggingIn || + (credentialMode === "api" && !apiKey.trim() && !selectedApiKey && !restoredApiCredential && !managedBindingForStep()), + }); function unwindConnectStep() { localLogin.cancel(); + localLoginPrimary.resetSubmitting(); dismissedLoginResumes.current.add(loginResumeKey); if (createdCompanyId) { void queryClient.cancelQueries({ queryKey: queryKeys.agents.activeLoginSession(createdCompanyId, adapterType) }); @@ -1700,6 +1755,7 @@ function OnboardingWizardInner({ openConnectAuthorization(); return; } + if (localLoginPrimary.runPrimary()) return; // The hold owns the hire once "Connecting" is showing. That now starts at // the paste, before the credential exists, so Cmd+Enter here would hire // against a source with nothing to run on. @@ -2807,7 +2863,7 @@ function OnboardingWizardInner({ step === 4 && agentName.trim() && connectStepReady && - (retryLogin || submitLoginCode || !connectStepLoggingIn) + (retryLogin || submitLoginCode || Boolean(localLoginAction && !localLoginAction.disabled) || !connectStepLoggingIn) ) handleConnectStepPrimary(); else if (step === 5) handleLaunchToChat(); @@ -3444,7 +3500,12 @@ function OnboardingWizardInner({ /> ) : hasSavedSubscription || localLogin.status === "ready" ? null : connectStepHasNoSandbox ? ( canUseLocalLogin && managedProvider ? ( - { autoConnectStartedRef.current = false; setError(null); localLogin.retry(); } }} /> + { autoConnectStartedRef.current = false; setError(null); localLogin.retry(); } }} + /> ) : browserSignInUnavailable ?

This environment does not support browser sign-in. Go back to use an API key or choose another model.

: null ) : null} diff --git a/ui/src/components/new-agent/AgentProviderConnection.test.tsx b/ui/src/components/new-agent/AgentProviderConnection.test.tsx index 275c80607ad..683170a274f 100644 --- a/ui/src/components/new-agent/AgentProviderConnection.test.tsx +++ b/ui/src/components/new-agent/AgentProviderConnection.test.tsx @@ -116,6 +116,93 @@ describe("AgentProviderConnection hosted Google sign-in gating", () => { expect(host.textContent).toContain("Antigravity"); expect(host.textContent).toContain("Sign in to Antigravity"); expect(host.textContent).toContain("127.0.0.1"); + + const openSpy = vi.spyOn(window, "open").mockReturnValue(null); + try { + const signInCta = Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Sign in to Antigravity", + ) as HTMLButtonElement | undefined; + expect(signInCta).toBeDefined(); + expect(signInCta!.disabled).toBe(false); + flushSync(() => signInCta!.click()); + expect(openSpy).toHaveBeenCalledWith( + "https://accounts.google.com/o/oauth2/v2/auth?state=hosted-ui-state", + "_blank", + "noreferrer,noopener", + ); + } finally { + openSpy.mockRestore(); + } + }); + + it("turns the primary footer button into Start sign in when Google sign-in fails or expires and retries on click", async () => { + mocks.healthGet.mockResolvedValue({ + status: "ok", + deploymentMode: "authenticated", + deploymentExposure: "public", + localAiLoginSupported: false, + hostedGoogleAiLoginSupported: true, + }); + mocks.checkLocalLogin + .mockResolvedValueOnce({ + status: "expired", + error: "Google sign-in did not complete. Start sign-in again.", + }) + .mockResolvedValueOnce({ + status: "sign_in_required", + authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth?state=retried-state", + }); + renderConnection("antigravity_runtime", false); + + await vi.waitFor(() => { + expect(host.textContent).toContain("Google sign-in did not complete. Start sign-in again."); + }); + const startSignInCta = Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Start sign in", + ) as HTMLButtonElement | undefined; + expect(startSignInCta).toBeDefined(); + expect(startSignInCta!.disabled).toBe(false); + // Redundant inline retry link is hidden when the footer owns Start sign in. + expect(Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Start sign-in again", + )).toBeUndefined(); + + flushSync(() => startSignInCta!.click()); + await vi.waitFor(() => expect(mocks.startLocalLogin).toHaveBeenCalledTimes(2)); + expect(mocks.startLocalLogin).toHaveBeenLastCalledWith( + "company-1", + expect.objectContaining({ provider: "google", method: "subscription", restart: true }), + ); + await vi.waitFor(() => { + const signInCta = Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Sign in to Antigravity", + ) as HTMLButtonElement | undefined; + expect(signInCta).toBeDefined(); + expect(signInCta!.disabled).toBe(false); + }); + }); + + it("switches the primary footer button back to Connect once Antigravity sign-in is ready", async () => { + mocks.healthGet.mockResolvedValue({ + status: "ok", + deploymentMode: "authenticated", + deploymentExposure: "public", + localAiLoginSupported: false, + hostedGoogleAiLoginSupported: true, + }); + mocks.checkLocalLogin.mockResolvedValue({ + status: "ready", + accountLabel: "dotta@paperclip.ing", + }); + renderConnection("antigravity_runtime", false); + + await vi.waitFor(() => { + const connectCta = Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Connect", + ) as HTMLButtonElement | undefined; + expect(connectCta).toBeDefined(); + expect(connectCta!.disabled).toBe(false); + }); }); it("still exposes the Antigravity redirect paste field when local login is also supported (remote private/trusted host)", async () => { diff --git a/ui/src/components/new-agent/AgentProviderConnection.tsx b/ui/src/components/new-agent/AgentProviderConnection.tsx index 57fa836e175..5b2b487e492 100644 --- a/ui/src/components/new-agent/AgentProviderConnection.tsx +++ b/ui/src/components/new-agent/AgentProviderConnection.tsx @@ -18,6 +18,7 @@ import { LocalProviderLoginInstructions, OnboardingCardField, OnboardingLoginCard, + useLocalLoginPrimaryAction, } from "../AdapterLoginChrome"; import { ModelSourceTiles, type ModelConnectionMode } from "../onboarding/ModelSourceTiles"; import { useQueryView } from "../QueryView"; @@ -263,10 +264,18 @@ export function AgentProviderConnection({ !savedKeys.loading && !storedLogin.data && (Boolean(managedAccount) || auth.data?.status !== "present" || subscriptionId === ""); + const localLoginPrimary = useLocalLoginPrimaryAction({ + enabled: opened && !advanced && !needsLogin && method === "subscription" && canUseLocalLogin && !savedSubscription && !storedLogin.data, + adapterType, + login: localLogin, + onBeforeRetry: () => setError(null), + }); + const localLoginAction = localLoginPrimary.action; const switchMode = (next: ModelConnectionMode) => { if (advancedConnection && next === (advanced ? "advanced" : method)) return; onDraftChanged?.(); cancel(); + localLoginPrimary.resetSubmitting(); setAdvanced(next === "advanced"); setOpened(advancedConnection ? true : opened); savedManagedAccount.current = null; @@ -427,7 +436,12 @@ export function AgentProviderConnection({ }} /> ) : savedSubscription ? null : canUseLocalLogin && !storedLogin.data ? ( - { setError(null); localLogin.retry(); } }} /> + { setError(null); localLogin.retry(); } }} + /> ) : (

{storedLogin.data @@ -455,14 +469,18 @@ export function AgentProviderConnection({ )} { - if (opened && !advancedConnection) cancel(); - else onBack(); + if (opened && !advancedConnection) { + localLoginPrimary.resetSubmitting(); + cancel(); + } else onBack(); }} primaryLabel={ opened && needsLogin ? loginPhase === "waiting" ? adapterType === "codex_local" ? "Waiting for auth…" : "Waiting for code" : loginPhase === "connecting" ? "Connecting" : automaticComputer && authorizationUrl ? `Continue to ${provider}` : `Sign in to ${provider}` + : localLoginAction + ? localLoginAction.label : busy ? "Connecting" : method === "subscription" && @@ -475,14 +493,17 @@ export function AgentProviderConnection({ primaryDisabled={ managedAccount?.disabled || (Boolean(managedAccount) && method === "subscription" && !canLogin && !canUseLocalLogin) || - (needsHealth && health.isPending) || localLogin.preparing || Boolean(localLogin.error) || - (method === "subscription" && canUseLocalLogin && !savedSubscription && !storedLogin.data && localLogin.status !== "ready") || + (needsHealth && health.isPending) || (!managedAccount && adapterType !== "antigravity_runtime" && auth.isPending) || savedKeys.loading || (adapterType === "claude_local" && storedLogin.isPending) || // The saved-subscription chooser renders outside the opened section, // so reusing the visible choice must not wait for a tile click. (!opened && !(method === "subscription" && savedSubscription)) || + (localLoginAction + ? localLoginAction.disabled + : localLogin.preparing || Boolean(localLogin.error) || + (method === "subscription" && canUseLocalLogin && !savedSubscription && !storedLogin.data && localLogin.status !== "ready")) || (Boolean(needsLogin) && !awaitingLoginRequest && (!authorizationUrl || loginPhase !== "ready")) || (method === "api" && !apiKey.trim() && @@ -490,7 +511,13 @@ export function AgentProviderConnection({ !selectedKey) } loading={busy} - primaryIcon={opened && needsLogin && !awaitingLoginRequest ? loginPhase === "ready" ? "none" : "spinner" : undefined} + primaryIcon={ + opened && needsLogin && !awaitingLoginRequest + ? loginPhase === "ready" ? "none" : "spinner" + : localLoginAction + ? localLoginAction.icon + : undefined + } onPrimary={() => { if (needsLogin) { if (awaitingLoginRequest) { @@ -500,6 +527,8 @@ export function AgentProviderConnection({ if (!authorizationUrl || loginPhase !== "ready") return; window.open(authorizationUrl, "_blank", "noreferrer,noopener"); setLoginPhase("waiting"); + } else if (localLoginPrimary.runPrimary()) { + return; } else void connect(); }} /> diff --git a/ui/src/pages/apps/AppsConnect.test.tsx b/ui/src/pages/apps/AppsConnect.test.tsx index 77c237d5ca0..60746aea500 100644 --- a/ui/src/pages/apps/AppsConnect.test.tsx +++ b/ui/src/pages/apps/AppsConnect.test.tsx @@ -140,5 +140,10 @@ describe("AppsConnect Antigravity routing and branding", () => { expect(host.querySelector('img[src="/brands/apps/antigravity.svg"]')).not.toBeNull(); expect(host.textContent).toContain("Sign in to Antigravity"); expect(host.textContent).not.toContain("Connect Google"); + const primarySignIn = Array.from(host.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === "Sign in to Antigravity", + ) as HTMLButtonElement | undefined; + expect(primarySignIn).toBeDefined(); + expect(primarySignIn!.disabled).toBe(false); }); });