{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 &&{submitError}
} -Finish signing in in the Antigravity browser window, then return here.
:Finish signing in in the Antigravity browser window, then return here.
: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 && !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 ? ( -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 ? ( -
{storedLogin.data
@@ -455,14 +469,18 @@ export function AgentProviderConnection({
)}