Skip to content
Python

Settings ▸ Models: sign-in pane for the subscription provider

Devika Verma91b4ad07021d
diff --git a/surfaces/gui/e2e/fixtures.ts b/surfaces/gui/e2e/fixtures.ts
index 80c9c634..e9ac104b 100644
--- a/surfaces/gui/e2e/fixtures.ts
+++ b/surfaces/gui/e2e/fixtures.ts
@@ -350,6 +350,9 @@ const PROVIDERS = [
// ollama: keyless local provider — "configured" without proving anything runs; the
// onboarding gallery shows "No key needed" and its form is endpoint + Detect (§39).
{ name: "ollama", title: "Ollama (local models)", needs_key: false, fields: [{ key: "base_url", label: "Endpoint", secret: false, required: false, help: "", placeholder: "http://127.0.0.1:11434", default: "http://127.0.0.1:11434" }], configured: true, values: {}, suggested_models: ["qwen3-coder:30b"], key_set_at: null, last_used_at: null },
+ // openai-codex: the subscription OAuth provider — no key form; the gallery card and
+ // form render sign-in state instead (auth: "oauth"). Starts signed out.
+ { name: "openai-codex", title: "ChatGPT (OpenAI subscription)", needs_key: false, auth: "oauth", signed_in: false, account: null, authorizing: false, last_error: null, blurb: "Sign in with your ChatGPT plan and run OpenAI models through your subscription — no API key. Tokens stay on this machine.", fields: [], configured: false, values: {}, suggested_models: ["gpt-5.2-codex"], key_set_at: null, last_used_at: null },
];
/** Install the API + WebSocket mocks on a page. Returns handles for assertions/seed data. */
@@ -1856,6 +1859,36 @@ export async function mockApi(page: import("@playwright/test").Page) {
prov.key_set_at = null;
return json({ ok: true, provider: name });
}
+ // Subscription OAuth sign-in (openai-codex): the flow "completes" instantly —
+ // signin flips the row to signed in; status mirrors it; signout clears it.
+ if (p.endsWith("/v1/providers/openai-codex/signin") && m === "POST") {
+ const prov = providers.find((x) => x.name === "openai-codex");
+ if (prov) {
+ prov.signed_in = true;
+ prov.configured = true;
+ prov.account = "[email protected]";
+ }
+ return json({ ok: true, started: true });
+ }
+ if (p.endsWith("/v1/providers/openai-codex/status")) {
+ const prov = providers.find((x) => x.name === "openai-codex");
+ return json({
+ signed_in: !!prov?.signed_in,
+ account: prov?.account || null,
+ authorizing: false,
+ last_error: null,
+ authorize_url: null,
+ });
+ }
+ if (p.endsWith("/v1/providers/openai-codex/signout") && m === "POST") {
+ const prov = providers.find((x) => x.name === "openai-codex");
+ if (prov) {
+ prov.signed_in = false;
+ prov.configured = false;
+ prov.account = null;
+ }
+ return json({ ok: true, had_tokens: true });
+ }
if (p.endsWith("/v1/providers")) return json(providers);
if (p.endsWith("/v1/channels/recent"))
return json({
diff --git a/surfaces/gui/e2e/provider-keys.spec.ts b/surfaces/gui/e2e/provider-keys.spec.ts
index 55dbda9a..3b8c528e 100644
--- a/surfaces/gui/e2e/provider-keys.spec.ts
+++ b/surfaces/gui/e2e/provider-keys.spec.ts
@@ -71,3 +71,25 @@ test("non-secret fields blur-save on a configured provider (ollama endpoint)", a
await page.getByTestId("set-provider-ollama").click();
await expect(page.getByTestId("set-field-base_url")).toHaveValue("http://127.0.0.1:9999");
});
+
+test("the subscription provider signs in from the browser flow, no key form", async ({
+ page,
+}) => {
+ await openModels(page);
+ const card = page.getByTestId("set-provider-openai-codex");
+ await expect(card).toContainText("Sign in with your plan");
+ await card.click();
+
+ // No key fields — the pane is the sign-in button (plus the blurb).
+ await expect(page.getByTestId("set-field-api_key")).toHaveCount(0);
+ await page.getByTestId("set-oauth-signin").click();
+
+ // The mock completes the flow on the first poll; the pane flips to signed in.
+ await expect(page.getByTestId("set-oauth-account")).toContainText("[email protected]");
+
+ // Sign out returns the pane (and the gallery card) to the signed-out state.
+ await page.getByTestId("set-oauth-signout").click();
+ await expect(page.getByTestId("set-oauth-signin")).toBeVisible();
+ await page.getByTestId("set-back").click();
+ await expect(card).toContainText("Sign in with your plan");
+});
diff --git a/surfaces/gui/src/api.ts b/surfaces/gui/src/api.ts
index be3f4f39..aad13ff1 100644
--- a/surfaces/gui/src/api.ts
+++ b/surfaces/gui/src/api.ts
@@ -1765,6 +1765,36 @@ export interface ProviderInfo {
blurb?: string; // one-line note under the title ("Uses X's OpenAI-compatible API…")
key_set_at?: string | null; // ISO date the key was last (re)saved — absent for env-only config
last_used_at?: number | null; // epoch secs the provider last served a completion
+ // OAuth providers (auth === "oauth"): browser sign-in instead of a key form.
+ auth?: string | null;
+ signed_in?: boolean;
+ account?: string | null; // signed-in account label (email or id)
+ authorizing?: boolean;
+ last_error?: string | null;
+}
+
+// -- ChatGPT-subscription provider sign-in (OAuth; tokens never reach the GUI) ------
+export interface CodexAuthStatus {
+ signed_in: boolean;
+ account?: string | null;
+ authorizing: boolean;
+ last_error?: string | null;
+ authorize_url?: string | null;
+}
+
+export async function codexSignin(): Promise<{ ok: boolean }> {
+ const res = await fetch(`${httpBase()}/v1/providers/openai-codex/signin`, { method: "POST" });
+ return res.json();
+}
+
+export async function codexAuthStatus(): Promise<CodexAuthStatus> {
+ const res = await fetch(`${httpBase()}/v1/providers/openai-codex/status`);
+ return res.json();
+}
+
+export async function codexSignout(): Promise<{ ok: boolean }> {
+ const res = await fetch(`${httpBase()}/v1/providers/openai-codex/signout`, { method: "POST" });
+ return res.json();
}
export async function getProviders(): Promise<ProviderInfo[]> {
diff --git a/surfaces/gui/src/providers/ProviderSetup.tsx b/surfaces/gui/src/providers/ProviderSetup.tsx
index 909db470..afe73741 100644
--- a/surfaces/gui/src/providers/ProviderSetup.tsx
+++ b/surfaces/gui/src/providers/ProviderSetup.tsx
@@ -1,5 +1,8 @@
import { useEffect, useRef, useState, type ReactNode } from "react";
import {
+ codexAuthStatus,
+ codexSignin,
+ codexSignout,
getProviders,
removeProvider,
setProvider,
@@ -217,6 +220,15 @@ export function useProviderSetup(opts?: { onSaved?: () => void }): ProviderSetup
};
const statusFor = (p: ProviderInfo, o?: { lastUsed?: boolean }) => {
+ if (p.auth === "oauth") {
+ if (p.signed_in)
+ return (
+ <span className="block text-[12px] text-ok font-medium truncate">
+ ✓ Signed in{p.account ? <span className="text-muted font-normal"> · {p.account}</span> : ""}
+ </span>
+ );
+ return <span className="block text-[12px] text-faint truncate">Sign in with your plan</span>;
+ }
if (p.configured && p.needs_key) {
const used = o?.lastUsed ? relTime(p.last_used_at) : null;
return (
@@ -274,6 +286,101 @@ export function useProviderSetup(opts?: { onSaved?: () => void }): ProviderSetup
}
/** The gallery: one card per provider, each wearing its own state. */
+/** OAuth provider pane (auth === "oauth"): browser sign-in instead of a key form.
+ * Signin runs server-side in the background; this polls the status route until the
+ * flow flips to signed-in or reports an error. Tokens never reach the GUI. */
+function OAuthSignIn({ info, tp, onChanged }: { info: ProviderInfo; tp: string; onChanged: () => Promise<void> }) {
+ const [busy, setBusy] = useState(!!info.authorizing);
+ const [error, setError] = useState<string | null>(info.last_error || null);
+ const [reopenUrl, setReopenUrl] = useState<string | null>(null);
+ const alive = useRef(true);
+ useEffect(() => {
+ alive.current = true; // StrictMode double-mount: the cleanup below must not stick
+ return () => { alive.current = false; };
+ }, []);
+
+ const poll = async () => {
+ for (let i = 0; i < 150 && alive.current; i++) {
+ await new Promise((r) => setTimeout(r, 2000));
+ const s = await codexAuthStatus().catch(() => null);
+ if (!s) continue;
+ if (s.authorize_url) setReopenUrl(s.authorize_url);
+ if (s.signed_in || (!s.authorizing && s.last_error)) {
+ if (alive.current) {
+ setBusy(false);
+ setError(s.last_error || null);
+ }
+ await onChanged();
+ return;
+ }
+ }
+ if (alive.current) setBusy(false);
+ };
+
+ const start = async () => {
+ setBusy(true);
+ setError(null);
+ await codexSignin().catch(() => setError("Couldn't start the sign-in."));
+ void poll();
+ };
+
+ if (info.signed_in)
+ return (
+ <div className="mt-4">
+ <div className="flex items-center gap-2.5 rounded-xl border border-okLine bg-okSoft px-3 py-2.5">
+ <span className="text-[13px] text-ink min-w-0 flex-1 truncate" data-testid={`${tp}-oauth-account`}>
+ ✓ Signed in{info.account ? ` as ${info.account}` : ""}
+ </span>
+ <button
+ className="shrink-0 rounded-lg border border-line bg-panel px-3 py-1.5 text-[13px] text-ink hover:border-lineStrong"
+ data-testid={`${tp}-oauth-signout`}
+ onClick={async () => {
+ await codexSignout().catch(() => {});
+ await onChanged();
+ }}
+ >
+ Sign out
+ </button>
+ </div>
+ <p className="text-[12px] text-faint mt-2">
+ Usage draws on the plan's rolling window, not per-token billing. Sign-in stays on this computer.
+ </p>
+ </div>
+ );
+
+ return (
+ <div className="mt-4">
+ <button
+ className="rounded-lg border border-accent bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-105 disabled:opacity-40"
+ onClick={() => void start()}
+ disabled={busy}
+ data-testid={`${tp}-oauth-signin`}
+ >
+ {busy ? "Waiting for the browser…" : "Sign in with ChatGPT"}
+ </button>
+ {busy && (
+ <p className="text-[12px] text-faint mt-2">
+ Finish signing in in the browser window.
+ {reopenUrl && (
+ <>
+ {" "}
+ <button
+ className="text-muted underline decoration-line underline-offset-2 hover:text-ink"
+ onClick={() => openExternal(reopenUrl)}
+ >
+ Reopen the sign-in page
+ </button>
+ </>
+ )}
+ </p>
+ )}
+ <div className="mt-2 min-h-[19px] text-[13px]">
+ {error && <span className="text-warnInk">{error}</span>}
+ </div>
+ </div>
+ );
+}
+
export function ProviderCards({
ps,
tp,
@@ -405,6 +512,8 @@ export function ProviderForm({
</div>
{info?.blurb && <p className="text-[12px] text-faint mt-1">{info.blurb}</p>}
+ {info?.auth === "oauth" && <OAuthSignIn info={info} tp={tp} onChanged={ps.refreshProviders} />}
+
{fieldsAll
.filter(
(f) =>
@@ -499,7 +608,7 @@ export function ProviderForm({
— takes about a minute.
</p>
)}
- {info && !info.needs_key && (
+ {info && !info.needs_key && info.auth !== "oauth" && (
<p className="text-[12px] text-faint mt-2">
No API key needed — Ollama runs models on this computer.{" "}
<button
@@ -559,7 +668,7 @@ export function ProviderForm({
<div className="mt-3 min-h-[19px] text-[13px]">
{ps.verify.state === "error" && <span className="text-warnInk">{ps.verify.msg}</span>}
</div>
- {footer}
+ {info?.auth === "oauth" ? null : footer}
</div>
);
}