openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
243 lines (242 loc) • 8.07 kB
JavaScript
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { n as modelTransportRoutesMatch, o as resolveUniqueCatalogModelRoute } from "./model-compat-catalog-bqzqqcXc.mjs";
import { r as isModelThinkingFormat } from "./model-config-vocabulary-ByNYIDvQ.mjs";
import { n as planManifestModelCatalogRows } from "./manifest-planner-D0jCvDhu.mjs";
import { a as resolveProviderModelRoutes } from "./provider-model-routes-CbP035Gi.mjs";
import "./types.models-BRtCm3gx.mjs";
import { t as listOpenClawPluginManifestMetadata } from "./manifest-metadata-scan-TdIXbD4q.mjs";
import { isDeepStrictEqual } from "node:util";
//#region src/commands/doctor/shared/legacy-config-migrations.runtime.models.catalog.ts
const STALE_CONTEXT_WINDOW_FIXES = {
"deepseek/deepseek-v4-flash": {
stale: 2e5,
correct: 1e6
},
"xai/grok-4.20-0309-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-0309-non-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-beta-latest-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-beta-latest-non-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-experimental-beta-0304-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-experimental-beta-0304-non-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-reasoning": {
stale: 2e6,
correct: 1e6
},
"xai/grok-4.20-non-reasoning": {
stale: 2e6,
correct: 1e6
}
};
const DEAD_MODEL_COMPAT_KEYS = ["nativeWebSearchTool", "requiresMistralToolIds"];
function* providerModelEntries(e) {
for (const [t, n] of Object.entries(asNullableRecord(e) ?? {})) {
const e = asNullableRecord(n);
if (!e || !Array.isArray(e.models)) continue;
for (const [n, r] of e.models.entries()) {
const i = asNullableRecord(r);
if (i) yield {
providerId: t,
provider: e,
modelIndex: n,
model: i
};
}
}
}
function normalizedCatalogModelKey(e, t) {
const n = normalizeProviderId(e);
const r = t.trim().toLowerCase();
const i = `${n}/`;
return `${n}::${r.startsWith(i) ? r.slice(i.length) : r}`;
}
const modelCompatCatalogRowsByProvider = /* @__PURE__ */ new Map();
let modelCompatCatalogPlugins;
function getModelCompatCatalogPlugins() {
modelCompatCatalogPlugins ??= listOpenClawPluginManifestMetadata().flatMap(({ manifest: e }) => {
const t = typeof e.id === "string" ? e.id.trim() : "";
const n = asNullableRecord(e.modelCatalog);
if (!t || !n) return [];
return [{
id: t,
providers: Array.isArray(e.providers) ? e.providers.filter((e) => typeof e === "string") : [],
modelCatalog: n
}];
});
return modelCompatCatalogPlugins;
}
function buildConfiguredProviderCatalogRows(e) {
const t = /* @__PURE__ */ new Map();
for (const n of Object.keys(e)) {
const e = normalizeProviderId(n);
let r = modelCompatCatalogRowsByProvider.get(e);
if (!r) {
r = planManifestModelCatalogRows({
registry: { plugins: getModelCompatCatalogPlugins() },
providerFilter: e
}).rows;
modelCompatCatalogRowsByProvider.set(e, r);
}
for (const e of r) {
const n = normalizedCatalogModelKey(e.provider, e.id);
const r = t.get(n) ?? [];
r.push(e);
t.set(n, r);
}
}
return t;
}
/** Resolves one catalog identity and whether its configured route remains provider-owned. */
function resolveConfiguredModelCatalogOwnership(e) {
const t = typeof e.model.id === "string" ? e.model.id : "";
if (!t) return;
const n = buildConfiguredProviderCatalogRows({ [e.providerId]: e.provider }).get(normalizedCatalogModelKey(e.providerId, t));
const r = n?.length === 1 ? n[0] : void 0;
if (!r) return;
const i = {
api: e.model.api ?? e.provider.api,
baseUrl: e.model.baseUrl ?? e.provider.baseUrl
};
const a = modelTransportRoutesMatch(r, i);
const o = resolveProviderModelRoutes({
provider: e.providerId,
modelId: t,
env: {}
});
const s = o?.kind === "routes" && o.routes.some((e) => modelTransportRoutesMatch(e, i));
return {
catalogRow: r,
ownsRoute: a || s
};
}
function* inspectModelCompatOverrides(e) {
const t = asNullableRecord(e);
if (!t) return;
const n = [...providerModelEntries(t)];
if (!n.some(({ model: e }) => asNullableRecord(e.compat))) return;
const r = buildConfiguredProviderCatalogRows(t);
for (const { providerId: e, provider: t, modelIndex: i, model: a } of n) {
const n = asNullableRecord(a.compat);
const o = typeof a.id === "string" ? a.id : "";
if (!n || !o) continue;
const s = resolveUniqueCatalogModelRoute(r.get(normalizedCatalogModelKey(e, o)), {
api: a.api ?? t.api,
baseUrl: a.baseUrl ?? t.baseUrl
});
const c = DEAD_MODEL_COMPAT_KEYS.filter((e) => Object.hasOwn(n, e));
const l = [];
const u = [];
if (s) {
const e = s.compat ?? {};
for (const [t, r] of Object.entries(n)) {
if (DEAD_MODEL_COMPAT_KEYS.includes(t)) continue;
(isDeepStrictEqual(r, e[t]) ? l : u).push(t);
}
}
yield {
compat: n,
model: a,
modelIndex: i,
providerId: e,
dead: c,
matching: l,
divergent: u
};
}
}
function hasModelCompatOverrides(e, t) {
for (const n of inspectModelCompatOverrides(e)) if (n[t].length > 0) return true;
return false;
}
const MODEL_COMPAT_CATALOG_RULES = [
{
path: ["models", "providers"],
message: "nativeWebSearchTool and requiresMistralToolIds are unused and retired; run \"openclaw doctor --fix\" to remove them.",
match: (e) => hasModelCompatOverrides(e, "dead")
},
{
path: ["models", "providers"],
message: "Catalog-known model compat values are provider-owned; run \"openclaw doctor --fix\" to remove matching config overrides.",
match: (e) => hasModelCompatOverrides(e, "matching")
},
{
path: ["models", "providers"],
message: "Catalog-known model compat differs from the provider catalog and was preserved for review. Use a distinct custom route when the endpoint really has different capabilities.",
match: (e) => hasModelCompatOverrides(e, "divergent")
}
];
function migrateModelCompatCatalogOwnership(e, t) {
const n = asNullableRecord(asNullableRecord(e.models)?.providers);
for (const { compat: e, model: r, modelIndex: i, providerId: a, dead: o, matching: s } of inspectModelCompatOverrides(n)) {
const n = [...o, ...s];
if (n.length === 0) continue;
for (const t of n) delete e[t];
if (Object.keys(e).length === 0) delete r.compat;
t.push(`Removed models.providers.${a}.models.${i}.compat catalog/dead overrides: ${n.toSorted().join(", ")}.`);
}
}
function resolveStaleContextWindowFix(e) {
const t = e.providerId.trim().toLowerCase();
const n = e.modelId.trim().toLowerCase();
const r = `${t}/`;
const i = `${t}/${n.startsWith(r) ? n.slice(r.length) : n}`;
const a = STALE_CONTEXT_WINDOW_FIXES[i];
return a && e.contextWindow === a.stale ? a : void 0;
}
function* staleModelContextWindows(e) {
for (const t of providerModelEntries(e)) {
const { providerId: e, model: n } = t;
const r = typeof n.id === "string" ? n.id : void 0;
const i = n.contextWindow;
if (!r || typeof i !== "number" || !Number.isFinite(i)) continue;
const a = resolveStaleContextWindowFix({
providerId: e,
modelId: r,
contextWindow: i
});
if (a) yield {
...t,
modelId: r,
contextWindow: i,
fix: a
};
}
}
function hasStaleContextWindowValue(e) {
return !staleModelContextWindows(e).next().done;
}
function* invalidModelThinkingFormats(e) {
for (const t of providerModelEntries(e)) {
const { model: e } = t;
const n = asNullableRecord(e.compat);
const r = n?.thinkingFormat;
if (n && typeof r === "string" && !isModelThinkingFormat(r)) yield {
...t,
compat: n,
thinkingFormat: r
};
}
}
function hasInvalidThinkingFormat(e) {
return !invalidModelThinkingFormats(e).next().done;
}
//#endregion
export { migrateModelCompatCatalogOwnership as a, staleModelContextWindows as c, invalidModelThinkingFormats as i, hasInvalidThinkingFormat as n, providerModelEntries as o, hasStaleContextWindowValue as r, resolveConfiguredModelCatalogOwnership as s, MODEL_COMPAT_CATALOG_RULES as t };