Polish the onboarding model connection cards (#23255)

## Thinking Path

> - Paperclip helps people manage AI agents.
> - Onboarding connects the first agent to a model provider.
> - Both subscription flows ask the user to complete an authorization
step.
> - Moving that action into the provider card keeps the footer stable.
> - The updated cards also keep their spacing through loading and mode
changes.

## Linked Issues or Issue Description

**Subsystem affected**

First-agent onboarding.

**Current behavior**

The sign-in action changes the footer label during connection. Switching
credential modes shifts the layout.

**Proposed behavior**

Show the provider sign-in action beside its code. Keep Next disabled
while connecting. Advance after verification.

## What Changed

- Align the Claude and OpenAI code controls, instructions and provider
marks.
- Reserve the loaded card height and animate the API controls together.
- Update the standalone walkthrough with simulated provider approvals.

## Verification

- Browser walkthroughs covered both simulated approvals and automatic
advance to Review before integration with master.
- Measured equal loading and ready heights, API field spacing, and
mode-switch positions in the local preview.

- On revision `7c07c13c5f`, UI typecheck passed, 31 focused tests
passed, and the Chromium Claude paste-to-chat journey passed.

## Risks

Local and hosted login use different retry paths. Check both during
review.

## Model Used

OpenAI Codex, GPT-6, with repository and browser tools.

## Checklist

- [x] Included project context, issue description, verification scope
and risks.
- [x] Described the model and tools used.
- [x] Checked the roadmap for overlapping onboarding work.
- [ ] Verify final revision in CI and resolve review feedback.
- [x] I have searched GitHub for duplicate or related PRs and linked
them above

Related prior work includes #19557 and #13499.

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
TonioandPaperclip authored and GitHub committed 2026-11-30 05:42:22 +00:00
1 parent 629281b1e8
commit e55b475f30
9 files changed
+147 -43

No files matched your search

@@ -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: "Sign in to Claude", exact: true })).toBeEnabled();
await expect(page.getByRole("link", { name: "Sign in", exact: true })).toBeVisible();
await expect(page.getByRole("button", { name: "Next", exact: true })).toBeDisabled();
await expect(page.getByRole("button", { name: "Connect", exact: true })).toHaveCount(0);
await code.evaluate(input => {
const clipboardData = new DataTransfer();
+2 -2
View File
@@ -195,8 +195,8 @@ test.describe("Onboarding wizard", () => {
await source.waitFor({ timeout: 30_000 });
await source.click();
const cardInstruction = page.getByText("then come back and enter authorization code");
const authorizationLink = page.getByRole("link", { name: /^Sign in to / });
const cardInstruction = page.getByText("Return to this window and enter the authorization code.");
const authorizationLink = page.getByRole("link", { name: "Sign in", exact: true });
await expect(cardInstruction).toBeVisible({ timeout: 30_000 });
await expect(authorizationLink).toBeVisible({ timeout: 15_000 });
+4 -6
View File
@@ -388,7 +388,7 @@ test.describe("Onboarding wizard", () => {
// Nothing before the row is answered: the card is the answer to the tile,
// and the button has nothing to do until there is a source to do it with.
const cardInstruction = page.getByText("then come back and enter authorization code");
const cardInstruction = page.getByText("Return to this window and enter the authorization code.");
await expect(cardInstruction).toHaveCount(0);
await expect(page.getByRole("button", { name: "Next", exact: true })).toBeDisabled();
@@ -399,9 +399,7 @@ test.describe("Onboarding wizard", () => {
await source.click();
await expect(cardInstruction).toBeVisible({ timeout: 30_000 });
// One destination, two ways to it: the card's own link for anyone
// finishing in another browser, and the step's button for the flow.
const cardLink = page.getByRole("link", { name: /^Sign in to / });
const cardLink = page.getByRole("link", { name: "Sign in", exact: true });
await expect(cardLink).toBeVisible({ timeout: 15_000 });
await expect(cardLink).toHaveAttribute("href", /claude\.ai\/oauth\/authorize/);
await expect.poll(() => persistedAgentStatus).toBe(200);
@@ -409,8 +407,8 @@ test.describe("Onboarding wizard", () => {
expect(persisted.ok()).toBe(true);
expect(await persisted.json()).toMatchObject({ id: persistedAgentId, name: "Ada", defaultEnvironmentId: null });
await expect(
page.getByRole("button", { name: /^Sign in to / }),
).toBeEnabled({ timeout: 15_000 });
page.getByRole("button", { name: "Next", exact: true }),
).toBeDisabled({ timeout: 15_000 });
// No "Use saved login" here: the hire step applies a stored login itself.
await expect(page.getByRole("button", { name: "Use saved login" })).toHaveCount(0);
expect(hireCalled).toBe(false);
+60 -5
View File
@@ -1,4 +1,4 @@
import { useEffect, useId, useRef, useState, type ClipboardEvent, type ReactNode } from "react";
import { createContext, useContext, useEffect, useId, useRef, useState, type ClipboardEvent, type ReactNode } from "react";
import { AnimatePresence, motion } from "motion/react";
import { Copy, Check, Loader2 } from "lucide-react";
@@ -72,6 +72,7 @@ export function connectSourceName(adapterType: string): string {
*/
export function OnboardingLoginCard({
instruction,
revealTogether = false,
loading = false,
children,
}: {
@@ -81,6 +82,7 @@ export function OnboardingLoginCard({
* be mono to read as a name rather than as prose.
*/
instruction: ReactNode;
revealTogether?: boolean;
/**
* Show a spinner instead of the contents, at the same height.
*
@@ -93,6 +95,25 @@ export function OnboardingLoginCard({
loading?: boolean;
children: ReactNode;
}) {
if (revealTogether) {
return (
<div className="relative rounded-xl bg-muted/40 p-4">
<div
inert={loading}
className={cn("flex flex-col gap-4", loading ? "invisible" : "onboarding-subscription-reveal")}
>
<div className="pl-2 text-xs text-muted-foreground">{instruction}</div>
{children}
</div>
{loading && (
<div role="status" aria-label="Preparing the sign-in" className="absolute inset-0 grid place-items-center">
<Loader2 className="size-4 animate-spin text-muted-foreground" />
</div>
)}
</div>
);
}
if (loading) {
return (
<div
@@ -105,6 +126,7 @@ export function OnboardingLoginCard({
);
}
return (
<div className="flex min-h-(--sz-108px) flex-col gap-4 rounded-xl bg-muted/40 p-4">
{/* The row is the instruction alone. It shared this line with a Cancel
@@ -339,6 +361,10 @@ export const onboardingCardInputClass =
"placeholder:font-sans placeholder:text-sm placeholder:text-muted-foreground " +
"outline-none focus-visible:ring-ring/50 focus-visible:ring-(length:--rad-3)";
function focusWithoutScrolling(input: HTMLInputElement | null) {
input?.focus({ preventScroll: true });
}
/**
* The card's single-line field, whatever the card is asking for.
*
@@ -366,6 +392,7 @@ export function OnboardingCardField({
disabled,
label = "Authorization code",
description,
describedBy,
placeholder = "Paste authorization code here",
masked = false,
autoFocus = false,
@@ -378,6 +405,7 @@ export function OnboardingCardField({
disabled?: boolean;
label?: string;
description?: string;
describedBy?: string;
placeholder?: string;
/**
* Dots instead of the value. The key card asks for it because a provider key
@@ -400,10 +428,9 @@ export function OnboardingCardField({
const descriptionId = useId();
const input = (
<input
// eslint-disable-next-line jsx-a11y/no-autofocus -- see the prop's note
autoFocus={autoFocus}
ref={autoFocus ? focusWithoutScrolling : undefined}
aria-label={label}
aria-describedby={description ? descriptionId : undefined}
aria-describedby={description ? descriptionId : describedBy}
type={masked ? "password" : "text"}
autoComplete="off"
spellCheck={false}
@@ -431,6 +458,8 @@ export function OnboardingCardField({
);
}
export const OnboardingSignInMark = createContext<ReactNode>(null);
/** Shared authentication presentation. Hosts retain their existing session lifecycle. */
export function ProviderSubscriptionCard({
providerName,
@@ -453,6 +482,31 @@ export function ProviderSubscriptionCard({
loading?: boolean;
children: ReactNode;
}) {
const mark = useContext(OnboardingSignInMark);
if (mark && !failure && (mode === "submitted_code" || mode === "displayed_code")) {
return (
<OnboardingLoginCard revealTogether loading={loading} instruction={
<span className="grid gap-1">
<span>1. Sign into your {providerName} account{mode === "submitted_code" && " and copy the authorization code"}.</span>
<span>2. {mode === "submitted_code" ? "Return to this window and enter the authorization code." : "Enter the code below in the sign-in window."}</span>
</span>
}>
<div className="flex flex-wrap items-center gap-3">
<Button asChild className="gap-1 rounded-full py-0 pl-3 pr-6">
<a href={authorizationUrl} target="_blank" rel="noopener noreferrer" onClick={event => {
if (onOpenAuthorization) {
event.preventDefault();
onOpenAuthorization();
}
}}>
<span className="size-(--sz-30px) shrink-0">{mark}</span>Sign in
</a>
</Button>
<div className="min-h-(--sz-44px) min-w-0 flex-1 basis-44">{children}</div>
</div>
</OnboardingLoginCard>
);
}
return (
<OnboardingLoginCard
loading={loading}
@@ -623,6 +677,7 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir
onSubmittingChange?: (submitting: boolean) => void;
login?: { isolated?: boolean; command?: string; authorizationUrl?: string | null; code?: string | null; accountLabel?: string | null; submitCode?: (code: string) => Promise<void>; preparing: boolean; status?: "ready" | "sign_in_required" | "expired" | null; error: string | null; retry: () => void };
}) {
const onboardingSignIn = useContext(OnboardingSignInMark);
const [showCommand, setShowCommand] = useState(false);
const [browserCode, setBrowserCode] = useState("");
const [submitting, setSubmitting] = useState(false);
@@ -706,7 +761,7 @@ export function LocalProviderLoginInstructions({ adapterType, login, hostedRedir
onSubmit={() => void submitBrowserCode()}
disabled={submitting}
/>
<Button type="button" disabled={!browserCode.trim() || submitting} onClick={() => void submitBrowserCode()}>Submit code</Button>
{!onboardingSignIn && <Button type="button" disabled={!browserCode.trim() || submitting} onClick={() => void submitBrowserCode()}>Submit code</Button>}
</div> : hostedGoogleRedirect ? <div className="flex flex-col gap-2">
<p className="px-2 text-xs text-muted-foreground">
{optionalHostedGoogleRedirect
+41 -22
View File
@@ -1,3 +1,4 @@
import { OnboardingSignInMark } from "./AdapterLoginChrome";
import type { AiConnectionLoginIntent } from "@paperclipai/shared";
import { cancelAdapterLoginSession, cancelPendingAdapterLogin, matchesAdapterLoginTarget } from "./useAdapterLoginCancellation";
import { useQueryView } from "@/components/QueryView";
@@ -72,6 +73,7 @@ type ConnectPhase =
| "unwindRow";
function resolveOnboardingConnectCta(input: {
passiveSubscriptionFooter: boolean;
setupError: boolean;
retryLogin: boolean;
connectProgress: string | null;
@@ -87,6 +89,7 @@ function resolveOnboardingConnectCta(input: {
}): { 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.passiveSubscriptionFooter) return { label: "Next", icon: "arrow", disabled: true };
if (input.connectProgress) {
return { label: input.adapterEnvLoading ? "Testing…" : input.connectProgress, icon: "spinner", disabled: true };
}
@@ -267,7 +270,7 @@ const MODEL_SOURCE_BRAND_MARKS: Record<string, string> = {
*/
function OpenAiBlossom({ className }: { className?: string }) {
return (
<svg viewBox="0 0 716 716" className={className} fill="none" aria-hidden>
<svg viewBox="114 114 488 488" className={className} fill="none" aria-hidden>
<path
fill="currentColor"
d="M508.749 317.399C516.777 287.314 508.991 253.884 485.389 230.282C461.788 206.681 428.36 198.895 398.273 206.923C376.231 184.928 343.39 174.956 311.148 183.596C278.906 192.234 255.45 217.292 247.36 247.361C217.291 255.451 192.233 278.91 183.595 311.149C174.957 343.391 184.927 376.232 206.924 398.274C198.896 428.359 206.683 461.789 230.284 485.391C253.885 508.992 287.313 516.779 317.401 508.75C339.442 530.745 372.286 540.717 404.525 532.079C436.767 523.441 460.223 498.384 468.313 468.315C498.383 460.224 523.44 436.766 532.078 404.526C540.716 372.285 530.747 339.443 508.749 317.402V317.399ZM470.899 244.776C486.892 260.77 493.488 282.601 490.687 303.412L415.577 260.046C412.411 258.218 408.509 258.218 405.345 260.046L317.401 310.82V277.526C317.401 275.191 318.652 273.005 320.676 271.837L387.644 233.174C414.178 218.353 448.346 222.223 470.901 244.776H470.899ZM357.837 311.144L398.275 334.491V381.185L357.837 404.532L317.398 381.185V334.491L357.837 311.144ZM264.776 269.693C265.207 239.305 285.644 211.649 316.453 203.393C338.3 197.54 360.505 202.744 377.127 215.573L302.014 258.937C298.848 260.764 296.898 264.144 296.898 267.798V369.346L268.065 352.699C266.043 351.531 264.776 349.353 264.776 347.017V269.691V269.693ZM203.391 316.454C209.244 294.608 224.854 277.978 244.276 269.999V356.73C244.276 360.384 246.226 363.763 249.392 365.591L337.337 416.365L308.503 433.013C306.481 434.181 303.961 434.188 301.939 433.02L234.971 394.357C208.868 378.789 195.138 347.261 203.391 316.454ZM244.775 470.9C228.781 454.906 222.186 433.075 224.986 412.264L300.096 455.63C303.263 457.457 307.164 457.457 310.328 455.63L398.273 404.856V438.149C398.273 440.485 397.022 442.671 394.997 443.839L328.029 482.502C301.495 497.322 267.327 493.452 244.772 470.9H244.775ZM450.897 445.982C450.466 476.371 430.029 504.027 399.22 512.283C377.373 518.136 355.168 512.932 338.547 500.102L413.659 456.738C416.826 454.911 418.775 451.532 418.775 447.877V346.329L447.609 362.977C449.631 364.145 450.897 366.323 450.897 368.659V445.985V445.982ZM512.282 399.221C506.429 421.068 490.819 437.697 471.397 445.676V358.946C471.397 355.292 469.448 351.912 466.281 350.085L378.336 299.311L407.17 282.663C409.192 281.495 411.712 281.487 413.734 282.655L480.702 321.318C506.805 336.887 520.536 368.415 512.282 399.221Z"
@@ -1573,12 +1576,12 @@ function OnboardingWizardInner({
!connectStepReady || connectStepNeedsLogin || connectCredentialStored ||
credentialMode !== "subscription" ||
(adapterType !== "claude_local" && adapterType !== "codex_local") ||
(!hasSavedSubscription && localLogin.status !== "ready") ||
(!hasSavedSubscription && localLogin.status !== "ready" && authSignalStatus !== "present") ||
loading || autoConnectStartedRef.current) return;
autoConnectStartedRef.current = true;
void handleGiveHeartbeat();
}, [effectiveOnboardingOpen, step, connectPhase, connectStepReady, connectStepNeedsLogin,
connectCredentialStored, credentialMode, adapterType, hasSavedSubscription, localLogin.status, loading]);
connectCredentialStored, credentialMode, adapterType, hasSavedSubscription, localLogin.status, authSignalStatus, loading]);
/**
* The beats, each waiting for the animation before it.
@@ -1656,7 +1659,12 @@ function OnboardingWizardInner({
* rather than offering — see `FooterNav`, where the label cross-fades over an
* easing width so those changes read as one control rather than four.
*/
const showApiAccountNote = credentialMode === "api" && !selectedApiKey && !hasGatewaySelection && !connectionModels &&
(adapterType === "claude_local" || adapterType === "codex_local");
const showAdvancedSetup = sourceSelected && connectCardMounted && !connectProgress && credentialMode === "api" && createdCompanyId && (adapterType === "codex_local" || adapterType === "claude_local");
const connectSourceLabel = CONNECT_SOURCE_NAMES[adapterType] ?? adapterType;
const subscriptionSignIn = credentialMode === "subscription" &&
(adapterType === "claude_local" || adapterType === "codex_local");
const localLoginPrimary = useLocalLoginPrimaryAction({
enabled:
sourcePicked &&
@@ -1677,6 +1685,7 @@ function OnboardingWizardInner({
});
const localLoginAction = localLoginPrimary.action;
const connectCta = resolveOnboardingConnectCta({
passiveSubscriptionFooter: subscriptionSignIn && localLoginAction?.kind !== "retry" && !error && !visibleAdapterEnvError,
setupError,
retryLogin: Boolean(retryLogin),
connectProgress,
@@ -1694,6 +1703,7 @@ function OnboardingWizardInner({
(credentialMode === "api" && !apiKey.trim() && !selectedApiKey && !restoredApiCredential && !managedBindingForStep()),
});
function unwindConnectStep() {
localLogin.cancel();
localLoginPrimary.resetSubmitting();
@@ -2861,6 +2871,7 @@ function OnboardingWizardInner({
// would start a second server session.
else if (
step === 4 &&
!connectCta.disabled &&
agentName.trim() &&
connectStepReady &&
(retryLogin || submitLoginCode || Boolean(localLoginAction && !localLoginAction.disabled) || !connectStepLoggingIn)
@@ -2981,6 +2992,7 @@ function OnboardingWizardInner({
isAgentArcStep || step === 1
? "w-(--sz-560px) max-w-full px-8 py-10 sm:px-10 sm:py-11"
: "w-full max-w-md px-8 py-12",
step === 4 && "pb-8 sm:pb-9",
)}
>
{/* Full-length progress bar (brand .wsteps/.wstep) — segment N
@@ -3343,6 +3355,7 @@ function OnboardingWizardInner({
not, and they outlive the space by a beat. See
`connectCardMounted`.
*/}
<OnboardingSignInMark.Provider value={subscriptionSignIn ? <ModelSourceMark type={adapterType} Fallback={Loader2} /> : null}>
{!connectCardMounted ? null : connectProgress ? (
<p role="status" className="flex items-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
@@ -3350,9 +3363,13 @@ function OnboardingWizardInner({
</p>
) : credentialMode === "api" ? (
<OnboardingLoginCard
instruction={hasGatewaySelection || connectionModels ? "Choose a model for your saved connection" : savedKeys.options.length ? "Choose a saved API key or enter a new one" : `Provide your ${
revealTogether={showApiAccountNote}
instruction={<span className="grid gap-1">
<span>{hasGatewaySelection || connectionModels ? "Choose a model for your saved connection" : savedKeys.options.length ? "Choose a saved API key or enter a new one" : `Provide your ${
CONNECT_SOURCE_NAMES[adapterType] ?? adapterType
} API key to connect`}
} API key to connect.`}</span>
{showApiAccountNote && <span id="onboarding-api-account-note">This will be your default {connectSourceLabel} account.</span>}
</span>}
>
{!hasGatewaySelection && <SavedProviderKeySelect {...savedKeys} disabled={loading || adapterEnvLoading} value={selectedApiKey?.id ?? ""} onChange={(id) => {
setGatewayConnection(undefined);
@@ -3362,7 +3379,8 @@ function OnboardingWizardInner({
}} />}
{!selectedApiKey && !hasGatewaySelection && !connectionModels && <OnboardingCardField
label="API key"
description={managedProvider ? `This will be your default ${CONNECT_SOURCE_NAMES[adapterType] ?? managedProvider} account.` : undefined}
describedBy={showApiAccountNote ? "onboarding-api-account-note" : undefined}
description={!showApiAccountNote && managedProvider ? `This will be your default ${CONNECT_SOURCE_NAMES[adapterType] ?? managedProvider} account.` : undefined}
placeholder="Enter API key here"
masked
// The card is the answer to the tile just pressed, so
@@ -3508,24 +3526,24 @@ function OnboardingWizardInner({
/>
) : browserSignInUnavailable ? <p role="status" className="text-xs text-muted-foreground">This environment does not support browser sign-in. Go back to use an API key or choose another model.</p> : null
) : null}
</OnboardingSignInMark.Provider>
{showAdvancedSetup && (
<details className="mt-2 space-y-3">
<summary className="cursor-pointer text-sm text-muted-foreground">Advanced</summary>
<OnboardingGatewaySetup
companyId={createdCompanyId} agentId={setupAgentId ?? undefined} environmentId={resolvedLoginEnvironmentId ?? undefined}
adapterType={adapterType} disabled={loading || adapterEnvLoading}
className="-ml-3"
onComplete={binding => {
setGatewayConnection({ companyId: createdCompanyId, adapterType, binding });
setApiKey("");
setModel("");
setError(null);
}} />
</details>
)}
</motion.div>
{sourceSelected && connectCardLive && connectCardMounted && !connectProgress && credentialMode === "api" && createdCompanyId && (adapterType === "codex_local" || adapterType === "claude_local") && (
<details className="space-y-3">
<summary className="cursor-pointer text-sm text-muted-foreground">Advanced</summary>
<OnboardingGatewaySetup
companyId={createdCompanyId} agentId={setupAgentId ?? undefined} environmentId={resolvedLoginEnvironmentId ?? undefined}
adapterType={adapterType} disabled={loading || adapterEnvLoading}
className="-ml-3"
onComplete={binding => {
setGatewayConnection({ companyId: createdCompanyId, adapterType, binding });
setApiKey("");
setModel("");
setError(null);
}} />
</details>
)}
{/* Conditional adapter fields */}
{/* Progress is shown above; failed checks remain actionable here. */}
@@ -3704,6 +3722,7 @@ function OnboardingWizardInner({
`canGoBackFromOnboardingStep` returns false for it. */}
{(isAgentArcStep || step === 1) && (
<FooterNav
compact={step === 4 && Boolean(showAdvancedSetup) && connectCardSpace}
onBack={
// On the connect step Back unwinds the sign-in first, and
// only means "the previous step" once nothing is running.
+3 -1
View File
@@ -22,6 +22,7 @@ export type FooterPrimaryIcon = "arrow" | "spinner" | "none";
* `CTA_WIDTH` and `CTA_LABEL_*` for why the two halves are timed apart.
*/
export function FooterNav({
compact = false,
onBack,
primaryLabel,
primaryDisabled,
@@ -30,6 +31,7 @@ export function FooterNav({
primaryIcon,
onPrimary,
}: {
compact?: boolean;
onBack?: () => void;
primaryLabel: string;
primaryDisabled?: boolean;
@@ -49,7 +51,7 @@ export function FooterNav({
const icon: FooterPrimaryIcon = primaryIcon ?? (loading ? "spinner" : "arrow");
return (
<div className="flex items-center justify-between pt-9">
<div className={`flex items-center justify-between motion-safe:transition-[padding-top] motion-safe:duration-200 ${compact ? "pt-4.5" : "pt-9"}`}>
{onBack ? (
// Same size as the primary, not a tier down. Back is ghost until you
// point at it, and a shorter pill made the hover surface read as a
@@ -84,7 +84,7 @@ export function SavedProviderKeySelect({
kind?: "api" | "subscription";
}) {
return (
<div className="space-y-2">
<div className="space-y-2 empty:hidden">
{options.length > 0 && (
<label className="block space-y-2 text-sm">
<span>{kind === "api" ? "API key" : "Subscription"}</span>
+6
View File
@@ -1363,6 +1363,12 @@ html:has(.paperclip-app-shell[data-keyboard-open="true"] [data-classic-task-shel
them live by writing the tokens on :root. Keep timing here, in tokens — the
components only add class names.
──────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
.onboarding-subscription-reveal {
animation: tc-fade-rise var(--onboarding-motion-card-enter) ease-out;
}
}
@keyframes tc-fade-rise {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: none; }
+28 -5
View File
@@ -6,6 +6,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { CompanyProvider } from "./context/CompanyContext";
import { DialogProvider, useDialog } from "./context/DialogContext";
import { OnboardingWizard } from "./components/OnboardingWizard";
import { onboardingDraftStorage } from "./lib/onboarding-state";
import "./index.css";
/**
@@ -26,8 +27,9 @@ import "./index.css";
const COMPANY = { id: "company-preview", name: "Initech", issuePrefix: "INI" };
const SESSION_ID = "preview-session";
const AUTH_URL = "https://claude.ai/oauth/authorize?code=true&client=paperclip";
const OPENAI_URL = "https://auth.openai.com/codex/device";
const AUTH_URL = new URL("#preview-claude", window.location.href).href;
const OPENAI_URL = new URL("#preview-openai", window.location.href).href;
const DEVICE_APPROVAL_KEY = "paperclip-preview-device-approval";
/** How long the fake server takes to produce a prompt. */
const PROMPT_LATENCY_MS = 1200;
@@ -61,6 +63,11 @@ function respond(pathname: string, method: string): Response {
if (has("/instance/settings")) return json({ defaultEnvironmentId: "env-sandbox" });
// No credential anywhere, which is what makes the step offer a sign-in.
if (pathname.endsWith("/ai-connections")) return json({ currentUserId: "preview-user", canManageConnections: true, connections: [] });
if (pathname.endsWith("/agents")) return json(method === "POST" ? { id: "agent-preview", pauseReason: "setup" } : []);
if (pathname.endsWith("/secrets") || pathname.endsWith("/me/user-secrets")) return json([]);
if (has("/ai-connections/login/")) return json({ connectionId: "preview-connection", grantId: "preview-grant" });
if (has("/agents/agent-preview")) return json({ id: "agent-preview", name: "CEO", runtimeConfig: {}, adapterConfig: {} });
if (has("/auth-signal")) return json({ status: "absent" });
if (has("/claude-oauth-token-status")) return json({}, 404);
if (pathname.endsWith("/models")) return json([]);
@@ -108,6 +115,7 @@ function respond(pathname: string, method: string): Response {
].map(([type, label, panelMode, timeoutPolicy]) => ({
type,
label,
defaultRunner: "legacy",
source: "builtin",
modelsCount: 0,
loaded: true,
@@ -124,10 +132,11 @@ function respond(pathname: string, method: string): Response {
);
// The browser-code login: a session, then a prompt once the latency passes.
if (pathname.endsWith("login-sessions/active")) return json({}, 404);
if (has("/setup-token-login-sessions")) {
if (has("/prompt")) {
const ready = Date.now() - sessionStartedAt > PROMPT_LATENCY_MS;
return ready ? json({ authorizationUrl: AUTH_URL, transportAdvisory: null }) : json({}, 404);
return json({ authorizationUrl: ready ? AUTH_URL : null, transportAdvisory: null });
}
if (has("/completion")) return json({ storedSessionId: "stored-preview" });
if (has("/code")) {
@@ -162,7 +171,7 @@ function respond(pathname: string, method: string): Response {
const ready = Date.now() - sessionStartedAt > PROMPT_LATENCY_MS;
return json({
sessionId: SESSION_ID,
status: "pending",
status: Number(localStorage.getItem(DEVICE_APPROVAL_KEY)) >= sessionStartedAt ? "authenticated" : "pending",
prompt: ready ? { url: OPENAI_URL, code: "Q2RJ-E1YIF" } : null,
});
}
@@ -206,7 +215,21 @@ function OpenOnConnectStep() {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
createRoot(document.getElementById("root")!).render(
// The preview starts after the naming step and keeps its draft off the app's storage.
let previewDraft: string | null = JSON.stringify({ createdCompanyId: COMPANY.id, agentName: "CEO", step: 4 });
onboardingDraftStorage.read = () => previewDraft;
onboardingDraftStorage.write = value => { previewDraft = value; };
onboardingDraftStorage.clear = () => { previewDraft = null; };
const root = createRoot(document.getElementById("root")!);
if (location.hash === "#preview-claude") {
root.render(<main className="p-8">Return to the preview and enter the sample code <code>preview-code</code>.</main>);
} else if (location.hash === "#preview-openai") {
root.render(<main className="p-8"><button onClick={() => {
localStorage.setItem(DEVICE_APPROVAL_KEY, String(Date.now()));
window.close();
}}>Approve preview code Q2RJ-E1YIF</button></main>);
} else root.render(
<StrictMode>
<MemoryRouter>
<QueryClientProvider client={queryClient}>