graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
chatgpt-new: list models live from the route
justrach871530ab4366
diff --git a/docs/adr/0221-chatgpt-new-sign-in.md b/docs/adr/0221-chatgpt-new-sign-in.mdindex 6fa4c8d9..a94355c6 100644--- a/docs/adr/0221-chatgpt-new-sign-in.md+++ b/docs/adr/0221-chatgpt-new-sign-in.md@@ -159,8 +159,9 @@ process rather than restarting anything.Tokens are per machine: another machine signs in again and reuses theregistration. Two ChatGPT routes coexist until the switch, so the pickerlists both. Hosted use (the gateway, hosted sandboxes) is out of scope;-OpenAI requires a separate agreement for it. The live account catalog is a-follow-up, so the offline model rows can lag a rollout. HTTP requests re-send+OpenAI requires a separate agreement for it. The model list comes live from+the route's `/v1/models` (with `client_version`, like Codex's), cached for six+hours; the baked rows are only the offline fallback. HTTP requests re-sendthe whole input and caching is intermittent, so one-shot runs pay the most;live turns chain on the socket instead. While OpenAI refuses refreshes, asign-in lasts an hour and a longer task stops at the hour with a sign-indiff --git a/lean-proofs/Graff/Provider.lean b/lean-proofs/Graff/Provider.leanindex bab957c5..4706ee1f 100644--- a/lean-proofs/Graff/Provider.lean+++ b/lean-proofs/Graff/Provider.lean@@ -69,7 +69,7 @@ def specs : List Row :=, { id := "mlx", kind := .openai, auth := .bearer }, { id := "lmstudio", kind := .openai, auth := .bearer }, { id := "codex", kind := .responses, auth := .bearer, login := .codexDevice, catalog := .codex, subLogin := true }- , { id := "chatgpt-new", kind := .responses, auth := .bearer, login := .chatgptBrowser, subLogin := true }+ , { id := "chatgpt-new", kind := .responses, auth := .bearer, login := .chatgptBrowser, catalog := .openai, subLogin := true }]def ids : List String := specs.map (·.id)diff --git a/spec/kernels/providers.json b/spec/kernels/providers.jsonindex 0766b477..95fd69b9 100644--- a/spec/kernels/providers.json+++ b/spec/kernels/providers.json@@ -214,7 +214,7 @@"kind": "responses","auth": "bearer","login": "chatgpt_browser",- "catalog": "baked",+ "catalog": "openai","sub_login": true,"takes_effort": false}diff --git a/spec/ref/provider.py b/spec/ref/provider.pyindex 93595859..7e853408 100644--- a/spec/ref/provider.py+++ b/spec/ref/provider.py@@ -54,7 +54,7 @@ SPECS: list[dict] = [row("mlx", "openai", "bearer"),row("lmstudio", "openai", "bearer"),row("codex", "responses", "bearer", login="codex_device", catalog="codex", sub_login=True),- row("chatgpt-new", "responses", "bearer", login="chatgpt_browser", sub_login=True),+ row("chatgpt-new", "responses", "bearer", login="chatgpt_browser", catalog="openai", sub_login=True),]diff --git a/src/provider.zig b/src/provider.zigindex 545a1c46..ef717a7a 100644--- a/src/provider.zig+++ b/src/provider.zig@@ -134,7 +134,7 @@ pub const provider_specs = [_]ProviderSpec{// open-source apps (ADR 0221). The key is the OAuth access token saved by// `graff login chatgpt-new`, sent to the public Responses endpoint. After// codex on purpose: Codex stays the primary ChatGPT route (spec order).- .{ .id = "chatgpt-new", .display_name = "ChatGPT plan (new sign-in)", .kind = .responses, .auth = .bearer, .url = "https://api.openai.com/v1/responses", .env_key = "CHATGPT_NEW_DISABLED", .default_model = "gpt-6.1-sol", .login = .chatgpt_browser, .sub_login = true },+ .{ .id = "chatgpt-new", .display_name = "ChatGPT plan (new sign-in)", .kind = .responses, .auth = .bearer, .url = "https://api.openai.com/v1/responses", .env_key = "CHATGPT_NEW_DISABLED", .default_model = "gpt-6.1-sol", .login = .chatgpt_browser, .sub_login = true, .catalog = .openai, .models_url = "https://api.openai.com/v1/models?client_version=0.159.0" },};/// Optional workspace-local router loaded from `.graff/.config.router`.diff --git a/src/router_catalog.zig b/src/router_catalog.zigindex d3735a79..ee20805d 100644--- a/src/router_catalog.zig+++ b/src/router_catalog.zig@@ -171,7 +171,9 @@ pub fn parseModels(arena: Allocator, provider_id: []const u8, data: []const u8)var rows: std.ArrayList(pricing.ModelInfo) = .empty;for (items.array.items) |item| {if (item != .object) continue;- const raw_id = util.strFieldObj(item.object, "id") orelse util.strFieldObj(item.object, "name") orelse continue;+ const raw_id = util.strFieldObj(item.object, "id") orelse util.strFieldObj(item.object, "name") orelse util.strFieldObj(item.object, "slug") orelse continue;+ // Codex-shaped lists (the ChatGPT plan's new sign-in) key rows by slug and hide some.+ if (util.strFieldObj(item.object, "visibility")) |v| if (std.mem.eql(u8, v, "hide")) continue;// Google lists "models/gemini-3.8-flash" but answers to the bare id.const id = if (std.mem.startsWith(u8, raw_id, "models/")) raw_id["models/".len..] else raw_id;if (!validModelId(id)) continue;diff --git a/src/router_catalog_tests.zig b/src/router_catalog_tests.zigindex cd5c8bf9..85423252 100644--- a/src/router_catalog_tests.zig+++ b/src/router_catalog_tests.zig@@ -33,6 +33,23 @@ test "OpenAI catalog configuration carries its models endpoint" {}}+test "parseModels reads the ChatGPT plan's Codex-shaped list and skips hidden rows" {+ var state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer state.deinit();+ const snapshot = parseModels(state.allocator(), "chatgpt-new",+ \\{"models":[+ \\ {"slug":"gpt-6.1-sol","display_name":"GPT-6.1-Sol","visibility":"list","context_window":272000,"max_context_window":872000},+ \\ {"slug":"gpt-reserve","display_name":"Reserve","visibility":"hide","context_window":272000}+ \\]}+ ) orelse return error.TestUnexpectedResult;+ try std.testing.expectEqual(@as(usize, 1), snapshot.models.len);+ try std.testing.expectEqualStrings("chatgpt-new", snapshot.models[0].provider);+ try std.testing.expectEqualStrings("gpt-6.1-sol", snapshot.models[0].name);+ try std.testing.expectEqual(@as(u64, 272_000), snapshot.models[0].context);+ const spec = provider.specFor("chatgpt-new") orelse return error.TestUnexpectedResult;+ try std.testing.expectEqualStrings("https://api.openai.com/v1/models?client_version=0.159.0", modelsUrl(spec));+}+test "parseModels reads Vercel context_window and skips non-language types" {var state = std.heap.ArenaAllocator.init(std.testing.allocator);defer state.deinit();