Skip to content

Commit 55fb099

Browse files
author
Peter Steinberger
committed
fix(openai): preserve GPT-5.6 thinking metadata
1 parent b54ff85 commit 55fb099

15 files changed

Lines changed: 162 additions & 34 deletions

‎extensions/openai/openai-chatgpt-provider.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,45 @@ describe("OpenAI provider Codex transport hooks", () => {
110110
contextWindow: 372_000,
111111
contextTokens: 372_000,
112112
maxTokens: 128_000,
113-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
113+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
114114
});
115115
},
116116
);
117117

118+
it.each([
119+
{ name: "fills a missing map", thinkingLevelMap: undefined, expectedOff: null },
120+
{ name: "preserves explicit overrides", thinkingLevelMap: { off: "low" }, expectedOff: "low" },
121+
])("$name on registry-backed GPT-5.6 models", ({ thinkingLevelMap, expectedOff }) => {
122+
const provider = buildOpenAIProvider();
123+
const model = provider.resolveDynamicModel?.({
124+
provider: "openai",
125+
modelId: "gpt-5.6-luna",
126+
authProfileMode: "oauth",
127+
modelRegistry: {
128+
find: () => ({
129+
id: "gpt-5.6-luna",
130+
name: "GPT-5.6 Luna",
131+
provider: "openai",
132+
api: "openai-responses",
133+
baseUrl: "https://api.openai.com/v1",
134+
reasoning: true,
135+
input: ["text"],
136+
cost: { input: 1, output: 6, cacheRead: 0.1, cacheWrite: 1.25 },
137+
contextWindow: 372_000,
138+
maxTokens: 128_000,
139+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
140+
}),
141+
},
142+
} as never);
143+
144+
expect(model).toMatchObject({
145+
api: "openai-chatgpt-responses",
146+
baseUrl: "https://chatgpt.com/backend-api/codex",
147+
input: ["text", "image"],
148+
thinkingLevelMap: { off: expectedOff, xhigh: "xhigh", max: "max" },
149+
});
150+
});
151+
118152
it("keeps default Codex-backed OpenAI catalog models on the Codex Responses transport", () => {
119153
const provider = buildOpenAIProvider();
120154

‎extensions/openai/openai-chatgpt-provider.ts‎

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ const OPENAI_CODEX_BASE_URL = OPENAI_CODEX_RESPONSES_BASE_URL;
5151
const OPENAI_CODEX_LOGIN_ASSISTANT_PRIORITY = -30;
5252
const OPENAI_CODEX_DEVICE_PAIRING_ASSISTANT_PRIORITY = -10;
5353
const OPENAI_CODEX_GPT_56_MODEL_IDS = ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"] as const;
54+
const OPENAI_CODEX_GPT_56_THINKING_LEVEL_MAP = {
55+
off: null,
56+
xhigh: "xhigh",
57+
max: "max",
58+
} as const;
5459
const OPENAI_CODEX_GPT_55_MODEL_ID = "gpt-5.5";
5560
const OPENAI_CODEX_GPT_55_PRO_MODEL_ID = "gpt-5.5-pro";
5661
const OPENAI_CODEX_GPT_54_MODEL_ID = "gpt-5.4";
@@ -234,27 +239,34 @@ function resolveCodexForwardCompatModel(ctx: ProviderResolveDynamicModelContext)
234239
const model = ctx.modelRegistry.find(PROVIDER_ID, trimmedModelId) as
235240
| ProviderRuntimeModel
236241
| undefined;
237-
return (
238-
withDefaultCodexContextMetadata({
239-
model: withCodexTransport(model, synthBaseUrl),
240-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
241-
contextTokens: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
242-
}) ??
243-
normalizeModelCompat({
244-
id: trimmedModelId,
245-
name: trimmedModelId,
246-
api: "openai-chatgpt-responses",
247-
provider: PROVIDER_ID,
248-
baseUrl: synthBaseUrl,
249-
reasoning: true,
250-
input: ["text", "image"],
251-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
252-
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
253-
contextTokens: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
254-
maxTokens: OPENAI_CODEX_GPT_54_MAX_TOKENS,
255-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
256-
} as ProviderRuntimeModel)
257-
);
242+
const registeredModel = withDefaultCodexContextMetadata({
243+
model: withCodexTransport(model, synthBaseUrl),
244+
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
245+
contextTokens: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
246+
});
247+
if (registeredModel) {
248+
return normalizeModelCompat({
249+
...registeredModel,
250+
thinkingLevelMap: {
251+
...OPENAI_CODEX_GPT_56_THINKING_LEVEL_MAP,
252+
...registeredModel.thinkingLevelMap,
253+
},
254+
} as ProviderRuntimeModel);
255+
}
256+
return normalizeModelCompat({
257+
id: trimmedModelId,
258+
name: trimmedModelId,
259+
api: "openai-chatgpt-responses",
260+
provider: PROVIDER_ID,
261+
baseUrl: synthBaseUrl,
262+
reasoning: true,
263+
input: ["text", "image"],
264+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
265+
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
266+
contextTokens: OPENAI_CODEX_GPT_56_CONTEXT_TOKENS,
267+
maxTokens: OPENAI_CODEX_GPT_54_MAX_TOKENS,
268+
thinkingLevelMap: OPENAI_CODEX_GPT_56_THINKING_LEVEL_MAP,
269+
} as ProviderRuntimeModel);
258270
}
259271

260272
if (lower === OPENAI_CODEX_GPT_55_MODEL_ID) {

‎extensions/openai/openai-provider.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ describe("buildOpenAIProvider", () => {
207207
"gpt-5.6-terra",
208208
"gpt-5.6-luna",
209209
]);
210+
expect(gpt56Models?.map((model) => model.thinkingLevelMap?.off)).toEqual([null, null, null]);
210211
expect(OPENAI_DEFAULT_MODEL).toBe("openai/gpt-5.5");
211212
});
212213

@@ -451,7 +452,7 @@ describe("buildOpenAIProvider", () => {
451452
compat: {
452453
supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
453454
},
454-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
455+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
455456
});
456457
expect(openai?.models.find((model) => model.id === "gpt-5.3-codex-spark")).toMatchObject({
457458
name: "GPT-5.3 Codex Spark",
@@ -1031,17 +1032,17 @@ describe("buildOpenAIProvider", () => {
10311032
{
10321033
id: "gpt-5.6-sol",
10331034
cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 6.25 },
1034-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
1035+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
10351036
},
10361037
{
10371038
id: "gpt-5.6-terra",
10381039
cost: { input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 3.125 },
1039-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
1040+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
10401041
},
10411042
{
10421043
id: "gpt-5.6-luna",
10431044
cost: { input: 1, output: 6, cacheRead: 0.1, cacheWrite: 1.25 },
1044-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
1045+
thinkingLevelMap: { off: null, xhigh: "xhigh", max: "max" },
10451046
},
10461047
])("resolves $id locally with preview metadata", ({ id, cost, thinkingLevelMap }) => {
10471048
const provider = buildOpenAIProvider();

‎extensions/openai/openai-provider.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ const OPENAI_CHAT_LATEST_TEMPLATE_MODEL_IDS = [
120120
OPENAI_GPT_54_MODEL_ID,
121121
] as const;
122122
const OPENAI_GPT_56_TEMPLATE_MODEL_IDS = [OPENAI_GPT_55_MODEL_ID] as const;
123+
const OPENAI_GPT_56_THINKING_LEVEL_MAP = {
124+
off: null,
125+
xhigh: "xhigh",
126+
max: "max",
127+
} as const;
123128
const OPENAI_MODERN_MODEL_IDS = [
124129
OPENAI_CHAT_LATEST_MODEL_ID,
125130
OPENAI_GPT_56_SOL_MODEL_ID,
@@ -352,6 +357,7 @@ function buildOpenAICodexModelFromLiveRow(row: unknown): ModelDefinitionConfig |
352357
: fallback?.compat;
353358
const thinkingLevelMap = {
354359
...fallback?.thinkingLevelMap,
360+
...(normalizeLowercaseStringOrEmpty(modelId).startsWith("gpt-5.6") ? { off: null } : {}),
355361
...(reasoningLevels.includes("xhigh") ? { xhigh: "xhigh" as const } : {}),
356362
...(reasoningLevels.includes("max") ? { max: "max" as const } : {}),
357363
};
@@ -608,7 +614,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
608614
contextWindow: OPENAI_GPT_56_CONTEXT_TOKENS,
609615
contextTokens: OPENAI_GPT_56_CONTEXT_TOKENS,
610616
maxTokens: OPENAI_GPT_54_MAX_TOKENS,
611-
thinkingLevelMap: { xhigh: "xhigh", max: "max" },
617+
thinkingLevelMap: OPENAI_GPT_56_THINKING_LEVEL_MAP,
612618
};
613619
} else if (lower === OPENAI_GPT_55_MODEL_ID) {
614620
templateIds = [OPENAI_GPT_55_MODEL_ID, OPENAI_GPT_54_MODEL_ID];

‎extensions/openai/openclaw.plugin.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"contextWindow": 372000,
111111
"maxTokens": 128000,
112112
"cost": { "input": 5, "output": 30, "cacheRead": 0.5, "cacheWrite": 6.25 },
113-
"thinkingLevelMap": { "xhigh": "xhigh", "max": "max" },
113+
"thinkingLevelMap": { "off": null, "xhigh": "xhigh", "max": "max" },
114114
"compat": {
115115
"supportsReasoningEffort": true,
116116
"supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]
@@ -124,7 +124,7 @@
124124
"contextWindow": 372000,
125125
"maxTokens": 128000,
126126
"cost": { "input": 2.5, "output": 15, "cacheRead": 0.25, "cacheWrite": 3.125 },
127-
"thinkingLevelMap": { "xhigh": "xhigh", "max": "max" },
127+
"thinkingLevelMap": { "off": null, "xhigh": "xhigh", "max": "max" },
128128
"compat": {
129129
"supportsReasoningEffort": true,
130130
"supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]
@@ -138,7 +138,7 @@
138138
"contextWindow": 372000,
139139
"maxTokens": 128000,
140140
"cost": { "input": 1, "output": 6, "cacheRead": 0.1, "cacheWrite": 1.25 },
141-
"thinkingLevelMap": { "xhigh": "xhigh", "max": "max" },
141+
"thinkingLevelMap": { "off": null, "xhigh": "xhigh", "max": "max" },
142142
"compat": {
143143
"supportsReasoningEffort": true,
144144
"supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]

‎packages/model-catalog-core/src/model-catalog-normalize.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ describe("model catalog normalization", () => {
2828
contextWindow: 256000,
2929
contextTokens: 200000,
3030
maxTokens: 128000,
31+
thinkingLevelMap: {
32+
off: null,
33+
minimal: " low ",
34+
max: "max",
35+
adaptive: "high",
36+
},
3137
cost: {
3238
input: 1.25,
3339
output: 10,
@@ -132,6 +138,7 @@ describe("model catalog normalization", () => {
132138
contextWindow: 256000,
133139
contextTokens: 200000,
134140
maxTokens: 128000,
141+
thinkingLevelMap: { off: null, minimal: "low", max: "max" },
135142
cost: {
136143
input: 1.25,
137144
output: 10,

‎packages/model-catalog-core/src/model-catalog-normalize.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "./model-catalog-refs.js";
77
import {
88
MODEL_CATALOG_APIS,
9+
MODEL_CATALOG_THINKING_LEVELS,
910
isModelCatalogThinkingFormat,
1011
type ModelCatalog,
1112
type ModelCatalogAlias,
@@ -22,6 +23,7 @@ import {
2223
type ModelCatalogSource,
2324
type ModelCatalogStatus,
2425
type ModelCatalogSuppression,
26+
type ModelCatalogThinkingLevelMap,
2527
type ModelCatalogTieredCost,
2628
type ModelCatalogVercelGatewayRouting,
2729
type NormalizedModelCatalogRow,
@@ -71,6 +73,27 @@ function normalizeOptionalTrimmedStringList(value: unknown): string[] | undefine
7173
return normalized.length > 0 ? normalized : undefined;
7274
}
7375

76+
function normalizeModelCatalogThinkingLevelMap(
77+
value: unknown,
78+
): ModelCatalogThinkingLevelMap | undefined {
79+
if (!isRecord(value)) {
80+
return undefined;
81+
}
82+
const normalized: ModelCatalogThinkingLevelMap = {};
83+
for (const level of MODEL_CATALOG_THINKING_LEVELS) {
84+
const mapped = value[level];
85+
if (mapped === null) {
86+
normalized[level] = null;
87+
continue;
88+
}
89+
const normalizedValue = normalizeOptionalString(mapped);
90+
if (normalizedValue !== undefined) {
91+
normalized[level] = normalizedValue;
92+
}
93+
}
94+
return Object.keys(normalized).length > 0 ? normalized : undefined;
95+
}
96+
7497
function normalizeSafeRecordKey(value: unknown): string {
7598
const key = normalizeOptionalString(value) ?? "";
7699
return key && !isBlockedObjectKey(key) ? key : "";
@@ -484,6 +507,7 @@ function normalizeModelCatalogModel(value: unknown): ModelCatalogModel | undefin
484507
const contextWindow = normalizePositiveNumber(value.contextWindow);
485508
const contextTokens = normalizePositiveInteger(value.contextTokens);
486509
const maxTokens = normalizePositiveNumber(value.maxTokens);
510+
const thinkingLevelMap = normalizeModelCatalogThinkingLevelMap(value.thinkingLevelMap);
487511
const cost = normalizeModelCatalogCost(value.cost);
488512
const compat = normalizeModelCatalogCompat(value.compat);
489513
const mediaInput = normalizeModelCatalogMediaInput(value.mediaInput);
@@ -503,6 +527,7 @@ function normalizeModelCatalogModel(value: unknown): ModelCatalogModel | undefin
503527
...(contextWindow !== undefined ? { contextWindow } : {}),
504528
...(contextTokens !== undefined ? { contextTokens } : {}),
505529
...(maxTokens !== undefined ? { maxTokens } : {}),
530+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
506531
...(cost ? { cost } : {}),
507532
...(compat ? { compat } : {}),
508533
...(mediaInput ? { mediaInput } : {}),
@@ -695,6 +720,7 @@ export function normalizeModelCatalogProviderRows(params: {
695720
const contextWindow = normalizePositiveNumber(model.contextWindow);
696721
const contextTokens = normalizePositiveInteger(model.contextTokens);
697722
const maxTokens = normalizePositiveNumber(model.maxTokens);
723+
const thinkingLevelMap = normalizeModelCatalogThinkingLevelMap(model.thinkingLevelMap);
698724
const cost = normalizeModelCatalogCost(model.cost);
699725
const compat = normalizeModelCatalogCompat(model.compat);
700726
const mediaInput = normalizeModelCatalogMediaInput(model.mediaInput);
@@ -718,6 +744,7 @@ export function normalizeModelCatalogProviderRows(params: {
718744
...(contextWindow !== undefined ? { contextWindow } : {}),
719745
...(contextTokens !== undefined ? { contextTokens } : {}),
720746
...(maxTokens !== undefined ? { maxTokens } : {}),
747+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
721748
...(cost ? { cost } : {}),
722749
...(compat ? { compat } : {}),
723750
...(mediaInput ? { mediaInput } : {}),

‎packages/model-catalog-core/src/model-catalog-types.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ export type ModelCatalogMediaInputConfig = {
135135

136136
/** Supported input modality for a model. */
137137
export type ModelCatalogInput = "text" | "image" | "document";
138+
/** Model-level thinking settings carried by provider catalog metadata. */
139+
export const MODEL_CATALOG_THINKING_LEVELS = [
140+
"off",
141+
"minimal",
142+
"low",
143+
"medium",
144+
"high",
145+
"xhigh",
146+
"max",
147+
] as const;
148+
export type ModelCatalogThinkingLevel = (typeof MODEL_CATALOG_THINKING_LEVELS)[number];
149+
export type ModelCatalogThinkingLevelMap = Partial<
150+
Record<ModelCatalogThinkingLevel, string | null>
151+
>;
138152
/** Discovery lifecycle for a provider catalog. */
139153
export type ModelCatalogDiscovery = "static" | "refreshable" | "runtime";
140154
/** Availability state for a model. */
@@ -213,6 +227,7 @@ export type ModelCatalogModel = {
213227
contextWindow?: number;
214228
contextTokens?: number;
215229
maxTokens?: number;
230+
thinkingLevelMap?: ModelCatalogThinkingLevelMap;
216231
cost?: ModelCatalogCost;
217232
compat?: ModelCatalogCompatConfig;
218233
mediaInput?: ModelCatalogMediaInputConfig;
@@ -275,6 +290,7 @@ export type NormalizedModelCatalogRow = {
275290
contextWindow?: number;
276291
contextTokens?: number;
277292
maxTokens?: number;
293+
thinkingLevelMap?: ModelCatalogThinkingLevelMap;
278294
cost?: ModelCatalogCost;
279295
compat?: ModelCatalogCompatConfig;
280296
mediaInput?: ModelCatalogMediaInputConfig;

‎src/agents/embedded-agent-runner/model.static-catalog.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function createMistralManifestPlugin(overrides?: {
9999
reasoning: true,
100100
contextWindow: 262144,
101101
maxTokens: 8192,
102+
thinkingLevelMap: { off: null, minimal: "low", max: "max" },
102103
cost: { input: 1.5, output: 7.5, cacheRead: 0, cacheWrite: 0 },
103104
mediaInput: {
104105
image: { maxSidePx: 2048, preferredSidePx: 1536, tokenMode: "provider" },
@@ -174,6 +175,7 @@ describe("resolveBundledStaticCatalogModel", () => {
174175
name: "Mistral Medium 3.5",
175176
provider: "mistral",
176177
reasoning: true,
178+
thinkingLevelMap: { off: null, minimal: "low", max: "max" },
177179
});
178180
});
179181

‎src/agents/embedded-agent-runner/model.static-catalog.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function modelFromStaticCatalogRow(row: NormalizedModelCatalogRow): ProviderRunt
9393
contextWindow: row.contextWindow ?? DEFAULT_CONTEXT_TOKENS,
9494
contextTokens: row.contextTokens,
9595
maxTokens: row.maxTokens ?? DEFAULT_CONTEXT_TOKENS,
96+
thinkingLevelMap: row.thinkingLevelMap ? { ...row.thinkingLevelMap } : undefined,
9697
headers: row.headers,
9798
compat: row.compat,
9899
mediaInput: row.mediaInput,

0 commit comments

Comments
 (0)