openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
63 lines (62 loc) • 2.66 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { a as OPENAI_DEFAULT_RUNTIME_CONTEXT_TOKENS, k as resolveOpenAICodexReasoningEfforts, y as OPENAI_GPT_56_VARIANT_MODEL_IDS } from "./model-route-contract-D946w9WL.mjs";
//#region extensions/openai/codex-model-rows.ts
const OPENAI_CODEX_GPT_56_CONTEXT_WINDOW = 372e3;
function readCodexReasoningLevels(e) {
const t = asOptionalRecord(e);
const n = t?.supported_reasoning_levels ?? t?.supportedReasoningLevels;
if (!Array.isArray(n)) return;
return n.flatMap((e) => {
if (typeof e === "string" && e.trim().length > 0) return [e.trim()];
const t = asOptionalRecord(e)?.effort;
return typeof t === "string" && t.trim().length > 0 ? [t.trim()] : [];
});
}
function readCodexModelRows(e) {
const t = asOptionalRecord(e)?.models;
if (!Array.isArray(t)) throw new Error("OpenAI Codex model discovery response must be { models: [] }");
return t;
}
function shouldIncludeCodexModelRow(e, t) {
const { readLiveModelCatalogStringField: n, readLiveModelCatalogBooleanField: r } = t;
const i = normalizeLowercaseStringOrEmpty(n(e, "visibility") ?? "");
if (i && i !== "list") return false;
return (r(e, "show_in_picker") ?? r(e, "showInPicker")) !== false;
}
function resolveCodexModelInput(e, t) {
const n = asOptionalRecord(e);
const r = [n?.input_modalities, n?.inputModalities].find(Array.isArray)?.filter((e) => typeof e === "string") ?? [];
if (r.length === 0) return t?.input ?? ["text", "image"];
const i = new Set(r.map((e) => normalizeLowercaseStringOrEmpty(e)));
const a = [
"text",
"image",
"audio",
"video"
].filter((e) => i.has(e) || e === "image" && i.has("vision"));
return a.length > 0 ? a : t?.input ?? ["text", "image"];
}
function normalizeOpenAICodexCatalogModel(e) {
const t = normalizeLowercaseStringOrEmpty(e.id);
if (OPENAI_GPT_56_VARIANT_MODEL_IDS.some((e) => e === t)) {
const n = resolveOpenAICodexReasoningEfforts(t, e.compat?.supportedReasoningEfforts?.filter((e) => e !== "none"));
return {
...e,
contextWindow: OPENAI_CODEX_GPT_56_CONTEXT_WINDOW,
contextTokens: OPENAI_DEFAULT_RUNTIME_CONTEXT_TOKENS,
thinkingLevelMap: {
...e.thinkingLevelMap,
off: null
},
...e.compat ? { compat: {
...e.compat,
...n ? { supportedReasoningEfforts: n } : {}
} } : {}
};
}
return e;
}
//#endregion
export { shouldIncludeCodexModelRow as a, resolveCodexModelInput as i, readCodexModelRows as n, readCodexReasoningLevels as r, normalizeOpenAICodexCatalogModel as t };