Skip to content
TypeScript

fix(server): ChatGPT-connected Codex shows reasoning for models newer than its CLI (#27931)

Theo Brownebed62e60b42a
diff --git a/apps/server/src/provider/CodexChatGptModels.test.ts b/apps/server/src/provider/CodexChatGptModels.test.ts
index 9533a3c64d0..570cea5f34d 100644
--- a/apps/server/src/provider/CodexChatGptModels.test.ts
+++ b/apps/server/src/provider/CodexChatGptModels.test.ts
@@ -19,11 +19,40 @@ it.effect(
models:
request.headers.authorization === "Bearer account-a"
? [
- { slug: "second", display_name: "Second from OpenAI", visibility: "list" },
- { slug: "hidden", display_name: "Hidden", visibility: "hidden" },
- { slug: "first", display_name: "First from OpenAI", visibility: "list" },
+ {
+ slug: "second",
+ display_name: "Second from OpenAI",
+ visibility: "list",
+ default_reasoning_level: "low",
+ supported_reasoning_levels: [
+ { effort: "low", description: "Fast" },
+ { effort: "high", description: "Deep" },
+ ],
+ },
+ {
+ slug: "hidden",
+ display_name: "Hidden",
+ visibility: "hidden",
+ default_reasoning_level: null,
+ supported_reasoning_levels: null,
+ },
+ {
+ slug: "first",
+ display_name: "First from OpenAI",
+ visibility: "list",
+ default_reasoning_level: "high",
+ supported_reasoning_levels: [{ effort: "high", description: "Deep" }],
+ },
]
- : [{ slug: "account-b-only", display_name: "B", visibility: "list" }],
+ : [
+ {
+ slug: "account-b-only",
+ display_name: "B",
+ visibility: "list",
+ default_reasoning_level: null,
+ supported_reasoning_levels: null,
+ },
+ ],
}),
),
);
@@ -49,7 +78,18 @@ it.effect(
],
);
assert.deepEqual(a[1]!.capabilities, native[0]!.capabilities);
- assert.isNull(a[0]!.capabilities);
+ assert.deepEqual(a[0]!.capabilities?.optionDescriptors, [
+ {
+ id: "reasoningEffort",
+ label: "Reasoning",
+ type: "select",
+ options: [
+ { id: "low", label: "Low", isDefault: true },
+ { id: "high", label: "High" },
+ ],
+ currentValue: "low",
+ },
+ ]);
const b = yield* chatGptModels("account-b", native).pipe(
Effect.provideService(HttpClient.HttpClient, http),
);
@@ -57,6 +97,7 @@ it.effect(
b.map((model) => model.slug),
["account-b-only"],
);
+ assert.isNull(b[0]!.capabilities);
assert.deepEqual(requests, ["Bearer account-a", "Bearer account-b"]);
}),
);
diff --git a/apps/server/src/provider/CodexChatGptModels.ts b/apps/server/src/provider/CodexChatGptModels.ts
index f3490b6cf73..ce64f0409d6 100644
--- a/apps/server/src/provider/CodexChatGptModels.ts
+++ b/apps/server/src/provider/CodexChatGptModels.ts
@@ -2,6 +2,7 @@ import type { ServerProviderModel } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import { HttpClient, HttpClientRequest } from "effect/http";
+import { mapCodexModelCapabilities } from "./CodexProvider.ts";
export class ChatGptCatalogError extends Schema.TaggedError<ChatGptCatalogError>()(
"ChatGptCatalogError",
@@ -14,6 +15,17 @@ const Catalog = Schema.Struct({
slug: Schema.NonEmptyString,
display_name: Schema.NonEmptyString,
visibility: Schema.String,
+ default_reasoning_level: Schema.optionalKey(Schema.NullOr(Schema.NonEmptyString)),
+ supported_reasoning_levels: Schema.optionalKey(
+ Schema.NullOr(
+ Schema.Array(
+ Schema.Struct({
+ effort: Schema.NonEmptyString,
+ description: Schema.optionalKey(Schema.NullOr(Schema.String)),
+ }),
+ ),
+ ),
+ ),
}),
),
});
@@ -32,15 +44,31 @@ export const chatGptModels = Effect.fn("chatGptModels")(function* (
const catalog = yield* response.json.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Catalog)));
return catalog.models
.filter((model) => model.visibility === "list")
- .map(
- (model) =>
- ({
- ...nativeModels.find((native) => native.slug === model.slug),
- capabilities:
- nativeModels.find((native) => native.slug === model.slug)?.capabilities ?? null,
- slug: model.slug,
- name: model.display_name,
- isCustom: false,
- }) satisfies ServerProviderModel,
- );
+ .map((model): ServerProviderModel => {
+ const native = nativeModels.find((candidate) => candidate.slug === model.slug);
+ // A pinned Codex CLI can predate a model the account already has; the catalog still lists its efforts.
+ const catalogCapabilities =
+ model.default_reasoning_level && model.supported_reasoning_levels
+ ? mapCodexModelCapabilities({
+ id: model.slug,
+ model: model.slug,
+ displayName: model.display_name,
+ description: "",
+ hidden: false,
+ isDefault: false,
+ defaultReasoningEffort: model.default_reasoning_level,
+ supportedReasoningEfforts: model.supported_reasoning_levels.map((level) => ({
+ reasoningEffort: level.effort,
+ description: level.description ?? "",
+ })),
+ })
+ : null;
+ return {
+ ...native,
+ capabilities: native?.capabilities ?? catalogCapabilities,
+ slug: model.slug,
+ name: model.display_name,
+ isCustom: false,
+ };
+ });
}, Effect.timeout("15 seconds"));