peppa/apps/web/components/SubscriptionSetup.tsx
Асель bdae019820 PEP-126: ChatGPT connection — what to do when ChatGPT asks to enable device code login
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-15 17:05:22 +05:00

106 lines
6.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ExternalLink } from "lucide-react";
import type { OwnLogin } from "@peppa/runner";
import { cancelOwnLoginAction, connectOwnSubscriptionAction, finishOwnClaudeLoginAction } from "@/app/(app)/actions";
import { Hidden } from "@/components/cards";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
const step = "flex gap-2.5";
const num = "grid size-5.5 shrink-0 place-items-center rounded-full bg-primary/15 text-xs font-semibold text-primary";
/**
* PEP-82: connecting the owner's own subscription without a terminal, in plain steps, right on
* the project page — «Подключить Claude» / «Подключить ChatGPT», then the link and the code.
*/
export function SubscriptionSetup({ projectId, back, logins }: { projectId: number; back: string; logins: OwnLogin[] }) {
if (logins.length) {
return (
<div className="mb-4 flex flex-col gap-4">
{logins.map((l) => (
<section key={l.subscriptionId} className="flex flex-col gap-3 rounded-lg border border-primary/40 bg-card px-4 py-4 text-sm" data-own-login={l.subscriptionId} aria-label={`Подключение ${l.provider === "claude" ? "Claude" : "ChatGPT"}`}>
<h2 className="m-0 text-base font-semibold">Подключаем {l.provider === "claude" ? "Claude" : "ChatGPT"} — осталось {l.provider === "claude" ? "три шага" : "два шага"}</h2>
<div className={step}>
<span className={num}>1</span>
<div className="flex flex-col items-start gap-1.5">
<span>Откройте страницу входа и войдите в свой аккаунт {l.provider === "claude" ? "Claude" : "ChatGPT"}{l.provider === "claude" ? ", затем нажмите «Authorize»" : ""}.</span>
<Button asChild size="sm" variant="default">
<a href={l.url} target="_blank" rel="noreferrer">
Открыть страницу входа <ExternalLink />
</a>
</Button>
</div>
</div>
{l.provider === "claude" ? (
<>
<div className={step}>
<span className={num}>2</span>
<span>Claude покажет длинный код — нажмите «Copy code».</span>
</div>
<div className={step}>
<span className={num}>3</span>
<form action={finishOwnClaudeLoginAction} className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
<Hidden fields={{ projectId, subscriptionId: l.subscriptionId, back }} />
<Input name="code" required autoComplete="off" placeholder="Вставьте код сюда" aria-label="Код от Claude" className="h-9 min-w-48 flex-1 font-mono" />
<Button variant="default">Готово</Button>
</form>
</div>
</>
) : (
<div className={step}>
<span className={num}>2</span>
<div className="flex flex-col items-start gap-1.5">
<span>
На той странице введите код <span className="rounded bg-muted px-2 py-0.5 font-mono text-base tracking-wider">{l.code}</span> и подтвердите вход.
</span>
<Button asChild size="sm" variant="default">
<a href={back}>Я вошёл — проверить</a>
</Button>
{/* PEP-126: ChatGPT refuses the code until this is switched on in the account — say so here. */}
<div className="mt-1 rounded-md border border-warn/50 bg-warn/10 px-3 py-2 text-sm">
<b>ChatGPT пишет «Включите вход по коду устройства», а кнопка «Продолжить» серая?</b> Это настройка вашего аккаунта ChatGPT, её нужно включить один раз:
<ol className="m-0 mt-1 flex list-decimal flex-col gap-0.5 pl-5">
<li>
Откройте{" "}
<a href="https://chatgpt.com/#settings/Security" target="_blank" rel="noreferrer">
ChatGPT → Настройки → Безопасность
</a>{" "}
(или нажмите на ссылку в красном сообщении ChatGPT).
</li>
<li>Включите вход по коду устройства для Codex.</li>
<li>Вернитесь сюда, нажмите «Отменить и начать заново» и снова «Подключить ChatGPT» — код одноразовый, старый уже не подойдёт.</li>
</ol>
</div>
</div>
</div>
)}
<form action={cancelOwnLoginAction}>
<Hidden fields={{ projectId, subscriptionId: l.subscriptionId, back }} />
<Button size="xs" variant="ghost" className="text-muted-foreground">Отменить и начать заново</Button>
</form>
</section>
))}
</div>
);
}
return (
<section className="mb-4 flex flex-col gap-3 rounded-lg border border-warn/50 bg-warn/10 px-4 py-4 text-sm" aria-label="Подключение подписки">
<h2 className="m-0 text-base font-semibold">Подключите подписку — и агенты начнут работать</h2>
<p className="m-0">
Агенты пишут код на вашей подписке Claude или ChatGPT — подойдёт обычная платная (Claude Pro или Max, ChatGPT Plus или Pro). Это одна минута: вы входите в свой аккаунт, как на любом сайте. Пароль
Пеппа не видит.
</p>
<div className="flex flex-wrap gap-2">
<form action={connectOwnSubscriptionAction}>
<Hidden fields={{ projectId, kind: "claude_login", back }} />
<Button variant="default" size="lg">Подключить Claude</Button>
</form>
<form action={connectOwnSubscriptionAction}>
<Hidden fields={{ projectId, kind: "codex_login", back }} />
<Button variant="outline" size="lg">Подключить ChatGPT</Button>
</form>
</div>
<p className="m-0 text-xs text-muted-foreground">Нет подписки? Оформите её на claude.ai или chatgpt.com и вернитесь сюда. Другие способы (готовый токен, ключ API) — в «⋯ Настройки проекта → Подписки».</p>
</section>
);
}