mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 02:50:23 +00:00
feat(openai): add gpt-5.4 support for API and Codex OAuth (#36590)
* feat(openai): add gpt-5.4 support and priority processing * feat(openai-codex): add gpt-5.4 oauth support * fix(openai): preserve provider overrides in gpt-5.4 fallback * fix(openai-codex): keep xhigh for gpt-5.4 default * fix(models): preserve configured overrides in list output * fix(models): close gpt-5.4 integration gaps * fix(openai): scope service tier to public api * fix(openai): complete prep followups for gpt-5.4 support (#36590) (thanks @dorukardahan) --------- Co-authored-by: Tyler Yust <TYTYYUST@YAHOO.COM>
This commit is contained in:
@@ -4,7 +4,7 @@ const mocks = vi.hoisted(() => {
|
||||
const printModelTable = vi.fn();
|
||||
return {
|
||||
loadConfig: vi.fn().mockReturnValue({
|
||||
agents: { defaults: { model: { primary: "openai-codex/gpt-5.3-codex" } } },
|
||||
agents: { defaults: { model: { primary: "openai-codex/gpt-5.4" } } },
|
||||
models: { providers: {} },
|
||||
}),
|
||||
ensureAuthProfileStore: vi.fn().mockReturnValue({ version: 1, profiles: {}, order: {} }),
|
||||
@@ -14,18 +14,19 @@ const mocks = vi.hoisted(() => {
|
||||
resolveConfiguredEntries: vi.fn().mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
key: "openai-codex/gpt-5.3-codex",
|
||||
ref: { provider: "openai-codex", model: "gpt-5.3-codex" },
|
||||
key: "openai-codex/gpt-5.4",
|
||||
ref: { provider: "openai-codex", model: "gpt-5.4" },
|
||||
tags: new Set(["configured"]),
|
||||
aliases: [],
|
||||
},
|
||||
],
|
||||
}),
|
||||
printModelTable,
|
||||
resolveForwardCompatModel: vi.fn().mockReturnValue({
|
||||
listProfilesForProvider: vi.fn().mockReturnValue([]),
|
||||
resolveModelWithRegistry: vi.fn().mockReturnValue({
|
||||
provider: "openai-codex",
|
||||
id: "gpt-5.3-codex",
|
||||
name: "GPT-5.3 Codex",
|
||||
id: "gpt-5.4",
|
||||
name: "GPT-5.4",
|
||||
api: "openai-codex-responses",
|
||||
baseUrl: "https://chatgpt.com/backend-api",
|
||||
input: ["text"],
|
||||
@@ -45,7 +46,7 @@ vi.mock("../../agents/auth-profiles.js", async (importOriginal) => {
|
||||
return {
|
||||
...actual,
|
||||
ensureAuthProfileStore: mocks.ensureAuthProfileStore,
|
||||
listProfilesForProvider: vi.fn().mockReturnValue([]),
|
||||
listProfilesForProvider: mocks.listProfilesForProvider,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -65,11 +66,11 @@ vi.mock("./list.table.js", () => ({
|
||||
printModelTable: mocks.printModelTable,
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/model-forward-compat.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../agents/model-forward-compat.js")>();
|
||||
vi.mock("../../agents/pi-embedded-runner/model.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../agents/pi-embedded-runner/model.js")>();
|
||||
return {
|
||||
...actual,
|
||||
resolveForwardCompatModel: mocks.resolveForwardCompatModel,
|
||||
resolveModelWithRegistry: mocks.resolveModelWithRegistry,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -88,9 +89,95 @@ describe("modelsListCommand forward-compat", () => {
|
||||
missing: boolean;
|
||||
}>;
|
||||
|
||||
const codex = rows.find((r) => r.key === "openai-codex/gpt-5.3-codex");
|
||||
const codex = rows.find((r) => r.key === "openai-codex/gpt-5.4");
|
||||
expect(codex).toBeTruthy();
|
||||
expect(codex?.missing).toBe(false);
|
||||
expect(codex?.tags).not.toContain("missing");
|
||||
});
|
||||
|
||||
it("keeps configured local openai gpt-5.4 entries visible in --local output", async () => {
|
||||
mocks.resolveConfiguredEntries.mockReturnValueOnce({
|
||||
entries: [
|
||||
{
|
||||
key: "openai/gpt-5.4",
|
||||
ref: { provider: "openai", model: "gpt-5.4" },
|
||||
tags: new Set(["configured"]),
|
||||
aliases: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
mocks.resolveModelWithRegistry.mockReturnValueOnce({
|
||||
provider: "openai",
|
||||
id: "gpt-5.4",
|
||||
name: "GPT-5.4",
|
||||
api: "openai-responses",
|
||||
baseUrl: "http://localhost:4000/v1",
|
||||
input: ["text", "image"],
|
||||
contextWindow: 1_050_000,
|
||||
maxTokens: 128_000,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
});
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
|
||||
await modelsListCommand({ json: true, local: true }, runtime as never);
|
||||
|
||||
expect(mocks.printModelTable).toHaveBeenCalled();
|
||||
const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{ key: string }>;
|
||||
expect(rows).toEqual([
|
||||
expect.objectContaining({
|
||||
key: "openai/gpt-5.4",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("marks synthetic codex gpt-5.4 rows as available when provider auth exists", async () => {
|
||||
mocks.loadModelRegistry.mockResolvedValueOnce({
|
||||
models: [],
|
||||
availableKeys: new Set(),
|
||||
registry: {},
|
||||
});
|
||||
mocks.listProfilesForProvider.mockImplementationOnce((_: unknown, provider: string) =>
|
||||
provider === "openai-codex" ? ([{ id: "profile-1" }] as Array<Record<string, unknown>>) : [],
|
||||
);
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
|
||||
await modelsListCommand({ json: true }, runtime as never);
|
||||
|
||||
expect(mocks.printModelTable).toHaveBeenCalled();
|
||||
const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{
|
||||
key: string;
|
||||
available: boolean;
|
||||
}>;
|
||||
|
||||
expect(rows).toContainEqual(
|
||||
expect.objectContaining({
|
||||
key: "openai-codex/gpt-5.4",
|
||||
available: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("exits with an error when configured-mode listing has no model registry", async () => {
|
||||
vi.clearAllMocks();
|
||||
const previousExitCode = process.exitCode;
|
||||
process.exitCode = undefined;
|
||||
mocks.loadModelRegistry.mockResolvedValueOnce({
|
||||
models: [],
|
||||
availableKeys: new Set<string>(),
|
||||
registry: undefined,
|
||||
});
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
let observedExitCode: number | undefined;
|
||||
|
||||
try {
|
||||
await modelsListCommand({ json: true }, runtime as never);
|
||||
observedExitCode = process.exitCode;
|
||||
} finally {
|
||||
process.exitCode = previousExitCode;
|
||||
}
|
||||
|
||||
expect(runtime.error).toHaveBeenCalledWith("Model registry unavailable.");
|
||||
expect(observedExitCode).toBe(1);
|
||||
expect(mocks.printModelTable).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Api, Model } from "@mariozechner/pi-ai";
|
||||
import type { ModelRegistry } from "@mariozechner/pi-coding-agent";
|
||||
import { resolveForwardCompatModel } from "../../agents/model-forward-compat.js";
|
||||
import { parseModelRef } from "../../agents/model-selection.js";
|
||||
import { resolveModelWithRegistry } from "../../agents/pi-embedded-runner/model.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { resolveConfiguredEntries } from "./list.configured.js";
|
||||
import { formatErrorWithStack } from "./list.errors.js";
|
||||
@@ -54,8 +54,7 @@ export async function modelsListCommand(
|
||||
`Model availability lookup failed; falling back to auth heuristics for discovered models: ${availabilityErrorMessage}`,
|
||||
);
|
||||
}
|
||||
|
||||
const modelByKey = new Map(models.map((model) => [modelKey(model.provider, model.id), model]));
|
||||
const discoveredKeys = new Set(models.map((model) => modelKey(model.provider, model.id)));
|
||||
|
||||
const { entries } = resolveConfiguredEntries(cfg);
|
||||
const configuredByKey = new Map(entries.map((entry) => [entry.key, entry]));
|
||||
@@ -93,26 +92,22 @@ export async function modelsListCommand(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const registry = modelRegistry;
|
||||
if (!registry) {
|
||||
runtime.error("Model registry unavailable.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (providerFilter && entry.ref.provider.toLowerCase() !== providerFilter) {
|
||||
continue;
|
||||
}
|
||||
let model = modelByKey.get(entry.key);
|
||||
if (!model && modelRegistry) {
|
||||
const forwardCompat = resolveForwardCompatModel(
|
||||
entry.ref.provider,
|
||||
entry.ref.model,
|
||||
modelRegistry,
|
||||
);
|
||||
if (forwardCompat) {
|
||||
model = forwardCompat;
|
||||
modelByKey.set(entry.key, forwardCompat);
|
||||
}
|
||||
}
|
||||
if (!model) {
|
||||
const { resolveModel } = await import("../../agents/pi-embedded-runner/model.js");
|
||||
model = resolveModel(entry.ref.provider, entry.ref.model, undefined, cfg).model;
|
||||
}
|
||||
const model = resolveModelWithRegistry({
|
||||
provider: entry.ref.provider,
|
||||
modelId: entry.ref.model,
|
||||
modelRegistry: registry,
|
||||
cfg,
|
||||
});
|
||||
if (opts.local && model && !isLocalBaseUrl(model.baseUrl)) {
|
||||
continue;
|
||||
}
|
||||
@@ -128,6 +123,9 @@ export async function modelsListCommand(
|
||||
availableKeys,
|
||||
cfg,
|
||||
authStore,
|
||||
allowProviderAvailabilityFallback: model
|
||||
? !discoveredKeys.has(modelKey(model.provider, model.id))
|
||||
: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,8 +129,18 @@ export function toModelRow(params: {
|
||||
availableKeys?: Set<string>;
|
||||
cfg?: OpenClawConfig;
|
||||
authStore?: AuthProfileStore;
|
||||
allowProviderAvailabilityFallback?: boolean;
|
||||
}): ModelRow {
|
||||
const { model, key, tags, aliases = [], availableKeys, cfg, authStore } = params;
|
||||
const {
|
||||
model,
|
||||
key,
|
||||
tags,
|
||||
aliases = [],
|
||||
availableKeys,
|
||||
cfg,
|
||||
authStore,
|
||||
allowProviderAvailabilityFallback = false,
|
||||
} = params;
|
||||
if (!model) {
|
||||
return {
|
||||
key,
|
||||
@@ -146,14 +156,15 @@ export function toModelRow(params: {
|
||||
|
||||
const input = model.input.join("+") || "text";
|
||||
const local = isLocalBaseUrl(model.baseUrl);
|
||||
const modelIsAvailable = availableKeys?.has(modelKey(model.provider, model.id)) ?? false;
|
||||
// Prefer model-level registry availability when present.
|
||||
// Fall back to provider-level auth heuristics only if registry availability isn't available.
|
||||
// Fall back to provider-level auth heuristics only if registry availability isn't available,
|
||||
// or if the caller marks this as a synthetic/forward-compat model that won't appear in getAvailable().
|
||||
const available =
|
||||
availableKeys !== undefined
|
||||
? availableKeys.has(modelKey(model.provider, model.id))
|
||||
: cfg && authStore
|
||||
? hasAuthForProvider(model.provider, cfg, authStore)
|
||||
: false;
|
||||
availableKeys !== undefined && !allowProviderAvailabilityFallback
|
||||
? modelIsAvailable
|
||||
: modelIsAvailable ||
|
||||
(cfg && authStore ? hasAuthForProvider(model.provider, cfg, authStore) : false);
|
||||
const aliasTags = aliases.length > 0 ? [`alias:${aliases.join(",")}`] : [];
|
||||
const mergedTags = new Set(tags);
|
||||
if (aliasTags.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user