Skip to content

Open source CapCut alternative.

TypeScript

fix(cut): offer only GPT models Codex account runs [rebuild]

David Leee40c1028905
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index 9ab6d5f6..307f6079 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -117,7 +117,14 @@ import { projectBackend } from "@/cut/lib/residency";
import { beginBrowserChat, browserChatRunning, cancelBrowserChat, watchBrowserChatTurns } from "@/cut/lib/browserChatTurns";
import { putCloudThread } from "@/cut/lib/chatCloud";
import type { AgentMessage } from "@earendil-works/pi-agent-core";
-import { AI_MODELS, aiModelProvider as provider, currentChatModel } from "@/cut/lib/aiModels";
+import {
+ AI_MODELS,
+ accountRuns,
+ aiModelProvider as provider,
+ currentChatModel,
+ runnableChatModel,
+ type ChatProvider,
+} from "@/cut/lib/aiModels";
import { saveAssetToLibrary } from "@/cut/lib/library";
import { formatDuration, useGenScene } from "@/cut/lib/genScene";
import { lightboxItemFromRef, useLightbox } from "@/cut/lib/lightbox";
@@ -143,7 +150,8 @@ interface ModelsInfo {
// A CLI provider's group lists only on `installed` true — unknown (probe
// still out, or no engine) reads as absent. A provider that is installed
// but unavailable (e.g. signed out) still lists with its note.
- providers: Record<string, { available: boolean; note: string; installed?: boolean }>;
+ // A provider's `models` lists what its signed-in account runs.
+ providers: Record<string, ChatProvider>;
}
/** What an engine send carries past the messages: the editor snapshot the
@@ -1986,15 +1994,13 @@ function ChatSession({
(m) => m.status === "queued" || m.status === "folding" || m.status === "spawned",
);
- // The saved model's provider may be uninstalled — its group is hidden from
- // the picker, so fall back to the first installed provider rather than sit on
- // a selection the user can no longer see or change.
+ // The saved model's provider may be uninstalled, or its account may not run
+ // it (a ChatGPT login without GPT-6.1 Sol) — the picker hides it, so move to
+ // a model this Mac and account run rather than sit on one that fails.
useEffect(() => {
- if (!visible || !info || info.providers[provider(model)]?.installed !== false) return;
- const fallback = AI_MODELS.find(
- (m) => !m.hidden && info.providers[provider(m.id)]?.installed !== false,
- );
- if (fallback && fallback.id !== model) onModelChange(fallback.id);
+ if (!visible || !info) return;
+ const runnable = runnableChatModel(model, info.providers);
+ if (runnable && runnable !== model) onModelChange(runnable);
}, [info, model, onModelChange, visible]);
const outOfCredits = useOutOfCredits((s) => s.out);
useCreditsRecheck();
@@ -2922,7 +2928,10 @@ function ModelSelector({
const showTest =
typeof window !== "undefined" &&
localStorage.getItem("cut-ai-test") === "1";
- const models = AI_MODELS.filter((m) => !m.hidden || showTest);
+ // A model the provider's account doesn't run stays out of the list.
+ const models = AI_MODELS.filter(
+ (m) => (!m.hidden || showTest) && (!info || accountRuns(m.id, info.providers)),
+ );
const groups = [
"claude",
"codex",
diff --git a/site/src/cut/lib/aiModels.test.ts b/site/src/cut/lib/aiModels.test.ts
index 5b8774de..4687a027 100644
--- a/site/src/cut/lib/aiModels.test.ts
+++ b/site/src/cut/lib/aiModels.test.ts
@@ -3,9 +3,12 @@ import { throws } from "node:assert/strict";
import {
AI_MODELS,
RETIRED_CHAT_MODELS,
+ accountRuns,
aiModelProvider,
currentChatModel,
+ runnableChatModel,
type AiModel,
+ type ChatProviders,
} from "@/cut/lib/aiModels";
import { geminiModelRoleNames } from "@/lib/inference/gemini-models";
@@ -66,3 +69,43 @@ describe("retired chat models", () => {
expect(currentChatModel("unknown-model")).toBeUndefined();
});
});
+
+describe("models the signed-in account runs", () => {
+ // The catalog a ChatGPT login served Codex on 2026-10-14: GPT-6.1 Sol and
+ // GPT-6 Astra are in the CLI's bundled list but not yet on this account.
+ const account = ["gpt-6-luna", "gpt-reserve", "gpt-5.6-terra", "gpt-5.6-luna"];
+ const providers: ChatProviders = {
+ claude: { available: true, note: "", installed: true },
+ codex: { available: true, note: "", installed: true, models: account },
+ gemini: { available: true, note: "", installed: true },
+ };
+
+ test("a GPT pick the ChatGPT account lacks moves to the first GPT model it runs", () => {
+ expect(runnableChatModel("gpt-6.1-sol", providers)).toBe("gpt-5.6-terra");
+ expect(runnableChatModel("gpt-6-astra", providers)).toBe("gpt-5.6-terra");
+ });
+
+ test("a pick the account runs stays", () => {
+ expect(runnableChatModel("gpt-6-luna", providers)).toBe("gpt-6-luna");
+ expect(runnableChatModel("claude-opus-5-5", providers)).toBe("claude-opus-5-5");
+ });
+
+ test("the picker offers only the GPT models the account runs", () => {
+ const offered = AI_MODELS.filter((m) => accountRuns(m.id, providers)).map((m) => m.id);
+ expect(offered).not.toContain("gpt-6.1-sol");
+ expect(offered).not.toContain("gpt-6-astra");
+ expect(offered).toContain("gpt-5.6-terra");
+ expect(offered).toContain("claude-opus-5-5");
+ });
+
+ test("an engine that names no account models leaves every model runnable", () => {
+ const unlisted: ChatProviders = { ...providers, codex: { available: true, note: "", installed: true } };
+ expect(runnableChatModel("gpt-6.1-sol", unlisted)).toBe("gpt-6.1-sol");
+ });
+
+ test("a pick whose provider is not installed moves to the first installed one", () => {
+ const off = { available: false, note: "", installed: false };
+ const geminiOnly: ChatProviders = { claude: off, codex: off, gemini: providers.gemini };
+ expect(runnableChatModel("gpt-6.1-sol", geminiOnly)).toBe(geminiModelRoleNames.chat);
+ });
+});
diff --git a/site/src/cut/lib/aiModels.ts b/site/src/cut/lib/aiModels.ts
index f4435613..9372c507 100644
--- a/site/src/cut/lib/aiModels.ts
+++ b/site/src/cut/lib/aiModels.ts
@@ -51,3 +51,42 @@ export function aiModelProvider(id: string): AiModel["provider"] {
if (!model) throw new Error(`Unknown chat model: ${id}`);
return model.provider;
}
+
+/** What the engine reports for one provider. `models` lists the ids the
+ * signed-in account can run, when the provider's CLI can say: a ChatGPT
+ * login gets a per-account Codex catalog, and a model missing from it fails
+ * every turn with "not supported when using Codex with a ChatGPT account". */
+export interface ChatProvider {
+ available: boolean;
+ note: string;
+ installed?: boolean;
+ models?: string[];
+}
+
+export type ChatProviders = Partial<Record<AiModel["provider"], ChatProvider>>;
+
+/** Whether the account behind the model's provider runs it; true when the
+ * engine names no account list. */
+export function accountRuns(id: string, providers: ChatProviders): boolean {
+ const models = providers[aiModelProvider(id)]?.models;
+ if (!models) return true;
+ return models.includes(id);
+}
+
+/** The model a pick runs as: itself when its provider is installed and the
+ * account runs it, else the first model of the same provider the account
+ * runs, else the first model of any installed provider.
+ * Example: "gpt-6.1-sol" on a ChatGPT account without it → "gpt-5.6-terra". */
+export function runnableChatModel(id: string, providers: ChatProviders): string | undefined {
+ const runs = (m: AiModel) =>
+ !m.hidden && providers[m.provider]?.installed !== false && accountRuns(m.id, providers);
+ const picked = AI_MODELS.find((m) => m.id === id);
+ if (picked && providers[picked.provider]?.installed !== false && accountRuns(id, providers)) {
+ return id;
+ }
+
+ // Same provider first, so a GPT pick stays on GPT.
+ const sibling = AI_MODELS.find((m) => m.provider === picked?.provider && runs(m));
+ if (sibling) return sibling.id;
+ return AI_MODELS.find(runs)?.id;
+}
diff --git a/site/src/cut/server/ai/codexModels.test.ts b/site/src/cut/server/ai/codexModels.test.ts
new file mode 100644
index 00000000..51d53468
--- /dev/null
+++ b/site/src/cut/server/ai/codexModels.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, test } from "bun:test";
+import { codexAccountModels } from "./codexModels";
+
+describe("codexAccountModels", () => {
+ test("reads the slugs from `codex debug models`", () => {
+ const out = JSON.stringify({
+ models: [
+ { slug: "gpt-6-luna", visibility: "list" },
+ { slug: "gpt-5.6-terra", visibility: "list" },
+ ],
+ });
+ expect(codexAccountModels(out)).toEqual(["gpt-6-luna", "gpt-5.6-terra"]);
+ });
+
+ test("names no list when the output is not a catalog", () => {
+ expect(codexAccountModels("")).toBeUndefined();
+ expect(codexAccountModels("error: unrecognized subcommand 'debug'")).toBeUndefined();
+ expect(codexAccountModels(JSON.stringify({ models: "x" }))).toBeUndefined();
+ });
+});
diff --git a/site/src/cut/server/ai/codexModels.ts b/site/src/cut/server/ai/codexModels.ts
new file mode 100644
index 00000000..5422b6e4
--- /dev/null
+++ b/site/src/cut/server/ai/codexModels.ts
@@ -0,0 +1,15 @@
+import { z } from "zod";
+
+const catalogSchema = z.object({ models: z.array(z.object({ slug: z.string() })) });
+
+/** The model ids in `codex debug models` output: the catalog Codex serves
+ * the signed-in account. Undefined when the output is no catalog (an older
+ * CLI without the subcommand, or a failed refresh). */
+export function codexAccountModels(stdout: string): string[] | undefined {
+ try {
+ const parsed = catalogSchema.safeParse(JSON.parse(stdout));
+ return parsed.success ? parsed.data.models.map((m) => m.slug) : undefined;
+ } catch {
+ return undefined;
+ }
+}
diff --git a/site/src/cut/server/http/ai.ts b/site/src/cut/server/http/ai.ts
index 94e978e1..54d232d6 100644
--- a/site/src/cut/server/http/ai.ts
+++ b/site/src/cut/server/http/ai.ts
@@ -41,6 +41,7 @@ import {
import { STEP_BUDGET, stopText, turnClose, type TurnEnd } from "../../lib/turnBudget";
import { pendingAsk } from "../../lib/chatResume";
import { codexCommand } from "../tool-path";
+import { codexAccountModels } from "../ai/codexModels";
import { errorMessage } from "../util";
interface ChatBody {
@@ -510,8 +511,21 @@ function probe(cmd: string, args: string[]): Promise<{ ok: boolean; note: string
});
}
+// `codex debug models` prints each model's full instructions; 8 MB holds a catalog.
+const CODEX_CATALOG_MAX_BYTES = 8 * 1024 * 1024;
+
+/** The models Codex serves the signed-in account, read from `codex debug
+ * models`; undefined when the CLI cannot say. */
+function codexModels(cmd: string): Promise<string[] | undefined> {
+ return new Promise((resolve) => {
+ execFile(cmd, ["debug", "models"], { timeout: 8000, maxBuffer: CODEX_CATALOG_MAX_BYTES }, (err, stdout) => {
+ resolve(err ? undefined : codexAccountModels(stdout));
+ });
+ });
+}
+
// Providers rarely change mid-session; cache probes for a minute.
-type ProviderStatus = { ok: boolean; note: string; installed: boolean };
+type ProviderStatus = { ok: boolean; note: string; installed: boolean; models?: string[] };
let aiProbe: {
at: number;
value: { claude: ProviderStatus; codex: ProviderStatus };
@@ -667,26 +681,30 @@ export const aiApi = {
async models() {
let value = aiProbe && Date.now() - aiProbe.at < 60_000 ? aiProbe.value : null;
if (!value) {
- const [claude, codexLogin] = await Promise.all([
+ const codexCmd = await codexCommand();
+ const [claude, codexLogin, codexAccount] = await Promise.all([
probe("claude", ["--version"]),
- probe(await codexCommand(), ["login", "status"]),
+ probe(codexCmd, ["login", "status"]),
+ codexModels(codexCmd),
]);
// The login probe running at all means codex is installed; only its
// ENOENT failure (carried through in codexLogin) marks it missing.
+ // A ChatGPT login runs only the models its account catalog lists.
const codex: ProviderStatus = codexLogin.ok
? /logged in/i.test(codexLogin.note)
- ? { ok: true, note: codexLogin.note, installed: true }
+ ? { ok: true, note: codexLogin.note, installed: true, models: codexAccount }
: { ok: false, note: "Not signed in — run: codex login", installed: true }
: codexLogin;
value = { claude, codex };
aiProbe = { at: Date.now(), value };
}
// The model catalog lives in the page (src/cut/lib/aiModels.ts); the
- // engine only reports which provider CLIs are usable on this Mac.
+ // engine reports which provider CLIs are usable on this Mac and which
+ // models the Codex account runs.
return Response.json({
providers: {
claude: { available: value.claude.ok, note: value.claude.note, installed: value.claude.installed },
- codex: { available: value.codex.ok, note: value.codex.note, installed: value.codex.installed },
+ codex: { available: value.codex.ok, note: value.codex.note, installed: value.codex.installed, models: value.codex.models },
// Gemini chats run from the page through Donkey's hosted inference;
// the browser overlays the real availability from its sign-in probe.
gemini: { available: true, note: "runs on your Donkey account", installed: true },