mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(gateway): share codex model visibility
This commit is contained in:
@@ -58,6 +58,12 @@ describe("resolveVisibleModelCatalog", () => {
|
|||||||
name: "GPT 5.5",
|
name: "GPT 5.5",
|
||||||
api: "openai-responses",
|
api: "openai-responses",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provider: "openai",
|
||||||
|
id: "gpt-5.4-codex",
|
||||||
|
name: "GPT 5.4 Codex",
|
||||||
|
api: "openai-responses",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = await resolveVisibleModelCatalog({
|
const result = await resolveVisibleModelCatalog({
|
||||||
@@ -71,8 +77,16 @@ describe("resolveVisibleModelCatalog", () => {
|
|||||||
expect(authChecker).toHaveBeenNthCalledWith(1, "openai", "openai-responses");
|
expect(authChecker).toHaveBeenNthCalledWith(1, "openai", "openai-responses");
|
||||||
expect(authChecker).toHaveBeenNthCalledWith(2, "openai", "openai-responses");
|
expect(authChecker).toHaveBeenNthCalledWith(2, "openai", "openai-responses");
|
||||||
expect(authChecker).toHaveBeenNthCalledWith(3, "openai", "openai-chatgpt-responses");
|
expect(authChecker).toHaveBeenNthCalledWith(3, "openai", "openai-chatgpt-responses");
|
||||||
expect(authChecker).toHaveBeenCalledTimes(3);
|
expect(authChecker).toHaveBeenNthCalledWith(4, "openai", "openai-responses");
|
||||||
|
expect(authChecker).toHaveBeenNthCalledWith(5, "openai", "openai-chatgpt-responses");
|
||||||
|
expect(authChecker).toHaveBeenCalledTimes(5);
|
||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
provider: "openai",
|
||||||
|
id: "gpt-5.4-codex",
|
||||||
|
name: "GPT 5.4 Codex",
|
||||||
|
api: "openai-responses",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provider: "openai",
|
provider: "openai",
|
||||||
id: "gpt-5.5",
|
id: "gpt-5.5",
|
||||||
|
|||||||
@@ -14,13 +14,17 @@ import {
|
|||||||
} from "./model-visibility-policy.js";
|
} from "./model-visibility-policy.js";
|
||||||
|
|
||||||
type ModelCatalogVisibilityView = "default" | "configured" | "all";
|
type ModelCatalogVisibilityView = "default" | "configured" | "all";
|
||||||
export type ProviderAuthChecker = (provider: string, modelApi?: string) => boolean | Promise<boolean>;
|
export type ProviderAuthChecker = (
|
||||||
|
provider: string,
|
||||||
|
modelApi?: string,
|
||||||
|
) => boolean | Promise<boolean>;
|
||||||
const OPENAI_PROVIDER_ID = "openai";
|
const OPENAI_PROVIDER_ID = "openai";
|
||||||
const OPENAI_CODEX_RESPONSES_API = "openai-chatgpt-responses";
|
const OPENAI_CODEX_RESPONSES_API = "openai-chatgpt-responses";
|
||||||
const OPENAI_CODEX_ROUTABLE_MODEL_IDS = new Set([
|
const OPENAI_CODEX_ROUTABLE_MODEL_IDS = new Set([
|
||||||
"gpt-5.5",
|
"gpt-5.5",
|
||||||
"gpt-5.5-pro",
|
"gpt-5.5-pro",
|
||||||
"gpt-5.4",
|
"gpt-5.4",
|
||||||
|
"gpt-5.4-codex",
|
||||||
"gpt-5.4-pro",
|
"gpt-5.4-pro",
|
||||||
"gpt-5.4-mini",
|
"gpt-5.4-mini",
|
||||||
]);
|
]);
|
||||||
@@ -29,7 +33,7 @@ function isPromiseLike(value: boolean | Promise<boolean>): value is Promise<bool
|
|||||||
return typeof value === "object" && value !== null && typeof value.then === "function";
|
return typeof value === "object" && value !== null && typeof value.then === "function";
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCodexRoutableOpenAIPlatformCatalogEntry(entry: ModelCatalogEntry): boolean {
|
export function isCodexRoutableOpenAIPlatformCatalogEntry(entry: ModelCatalogEntry): boolean {
|
||||||
// OpenAI platform entries for current Codex-routable ids can use the ChatGPT
|
// OpenAI platform entries for current Codex-routable ids can use the ChatGPT
|
||||||
// Responses auth path even when their catalog API is not already that API.
|
// Responses auth path even when their catalog API is not already that API.
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ import {
|
|||||||
loadModelCatalogForBrowse,
|
loadModelCatalogForBrowse,
|
||||||
type ModelCatalogBrowseView,
|
type ModelCatalogBrowseView,
|
||||||
} from "../../agents/model-catalog-browse.js";
|
} from "../../agents/model-catalog-browse.js";
|
||||||
import { resolveVisibleModelCatalog } from "../../agents/model-catalog-visibility.js";
|
import {
|
||||||
|
isCodexRoutableOpenAIPlatformCatalogEntry,
|
||||||
|
resolveVisibleModelCatalog,
|
||||||
|
} from "../../agents/model-catalog-visibility.js";
|
||||||
import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js";
|
import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js";
|
||||||
import { resolveDefaultAgentWorkspaceDir } from "../../agents/workspace.js";
|
import { resolveDefaultAgentWorkspaceDir } from "../../agents/workspace.js";
|
||||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||||
@@ -37,16 +40,7 @@ type ModelsListProviderAuthChecker = (
|
|||||||
|
|
||||||
let loggedSlowModelsListCatalog = false;
|
let loggedSlowModelsListCatalog = false;
|
||||||
const OAUTH_REFRESH_MARGIN_MS = 5 * 60 * 1000;
|
const OAUTH_REFRESH_MARGIN_MS = 5 * 60 * 1000;
|
||||||
const OPENAI_PROVIDER_ID = "openai";
|
|
||||||
const OPENAI_CODEX_RESPONSES_API = "openai-chatgpt-responses";
|
const OPENAI_CODEX_RESPONSES_API = "openai-chatgpt-responses";
|
||||||
const OPENAI_CODEX_ROUTABLE_MODEL_IDS = new Set([
|
|
||||||
"gpt-5.5",
|
|
||||||
"gpt-5.5-pro",
|
|
||||||
"gpt-5.4",
|
|
||||||
"gpt-5.4-codex",
|
|
||||||
"gpt-5.4-pro",
|
|
||||||
"gpt-5.4-mini",
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Unknown views are rejected by protocol validation first; this helper keeps the
|
// Unknown views are rejected by protocol validation first; this helper keeps the
|
||||||
// handler default explicit for older clients that omit the field.
|
// handler default explicit for older clients that omit the field.
|
||||||
@@ -211,15 +205,6 @@ function createModelsListProviderAuthChecker(params: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCodexRoutableOpenAIPlatformCatalogEntry(entry: ModelCatalogEntry): boolean {
|
|
||||||
return (
|
|
||||||
normalizeProviderId(entry.provider) === OPENAI_PROVIDER_ID &&
|
|
||||||
entry.api !== undefined &&
|
|
||||||
entry.api !== OPENAI_CODEX_RESPONSES_API &&
|
|
||||||
OPENAI_CODEX_ROUTABLE_MODEL_IDS.has(entry.id.trim().toLowerCase())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveModelsListEntryAvailability(
|
async function resolveModelsListEntryAvailability(
|
||||||
providerAuthChecker: ModelsListProviderAuthChecker,
|
providerAuthChecker: ModelsListProviderAuthChecker,
|
||||||
entry: ModelCatalogEntry,
|
entry: ModelCatalogEntry,
|
||||||
|
|||||||
Reference in New Issue
Block a user