openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
201 lines (200 loc) • 5.57 kB
JavaScript
import { r as asNullableRecord } from "../../record-coerce-CVPuDqcc.mjs";
import "../../runtime-doctor-migrations-YTlcIEpR.mjs";
import { u as isLegacyXaiBuiltinModel } from "../../model-definitions-C5KvjcKR.mjs";
import { t as isXaiProviderId } from "../../provider-id-DCdct8aI.mjs";
//#region extensions/xai/doctor-contract-api.ts
const RETIRED_REASONING_MODELS = /* @__PURE__ */ new Set([
"grok-4-1-fast",
"grok-4-1-fast-reasoning",
"grok-4-fast",
"grok-4-fast-reasoning",
"grok-4-0709"
]);
const RETIRED_NON_REASONING_MODELS = /* @__PURE__ */ new Set([
"grok-4-1-fast-non-reasoning",
"grok-4-fast-non-reasoning",
"grok-3"
]);
const RETIRED_CODE_MODELS = /* @__PURE__ */ new Set([
"grok-code-fast-1",
"grok-code-fast",
"grok-code-fast-1-0825"
]);
const PLUGIN_MODEL_MIGRATIONS = [
{
key: "webSearch",
retiredModels: RETIRED_REASONING_MODELS,
targetModel: "grok-4.3"
},
{
key: "codeExecution",
retiredModels: RETIRED_REASONING_MODELS,
targetModel: "grok-4.3"
},
{
key: "xSearch",
retiredModels: RETIRED_NON_REASONING_MODELS,
targetModel: "grok-4.3"
},
...[
"webSearch",
"codeExecution",
"xSearch"
].map((e) => ({
key: e,
retiredModels: RETIRED_CODE_MODELS,
targetModel: "grok-build-0.1"
}))
];
const XAI_MEDIA_MODEL_LIST_PATHS = [[
"tools",
"media",
"models"
]];
function isRetiredToolModel(e, t) {
const n = asNullableRecord(e)?.model;
return typeof n === "string" && t.has(n.trim().toLowerCase());
}
function hasLegacyBuiltinCatalogRows(e) {
return Array.isArray(e) && e.some((e) => isLegacyXaiBuiltinModel(e));
}
function asXaiProviderMediaEntry(e) {
const t = asNullableRecord(e);
if (!t || t.type !== void 0 && t.type !== "provider" || t.type === void 0 && t.command) return;
if (!isXaiProviderId(t.provider)) return;
return t;
}
function hasImageCapability(e) {
return Array.isArray(e.capabilities) && e.capabilities.some((e) => typeof e === "string" && e.trim().toLowerCase() === "image");
}
function isRetiredXaiImageMediaEntry(e) {
const t = asXaiProviderMediaEntry(e);
return typeof t?.model === "string" && RETIRED_REASONING_MODELS.has(t.model.trim().toLowerCase()) && hasImageCapability(t);
}
function hasRetiredXaiImageMediaEntries(e) {
return Array.isArray(e) && e.some(isRetiredXaiImageMediaEntry);
}
function isLegacyXaiSttEntry(e) {
const t = asXaiProviderMediaEntry(e);
return typeof t?.model === "string" && t.model.trim().toLowerCase() === "grok-stt";
}
function hasLegacyXaiSttEntries(e) {
return Array.isArray(e) && e.some(isLegacyXaiSttEntry);
}
const legacyConfigRules = [
...PLUGIN_MODEL_MIGRATIONS.map((e) => ({
path: [
"plugins",
"entries",
"xai",
"config",
e.key
],
message: `plugins.entries.xai.config.${e.key}.model uses a retired xAI model; run "openclaw doctor --fix" to use ${e.targetModel}.`,
match: (t) => isRetiredToolModel(t, e.retiredModels)
})),
...XAI_MEDIA_MODEL_LIST_PATHS.map((e) => ({
path: [...e],
message: `${e.join(".")} contains an xAI image entry with a retired model; run "openclaw doctor --fix" to migrate it to grok-4.3.`,
match: hasRetiredXaiImageMediaEntries
})),
...XAI_MEDIA_MODEL_LIST_PATHS.map((e) => ({
path: [...e],
message: `${e.join(".")} contains the obsolete xAI grok-stt model selector; run "openclaw doctor --fix" to remove it.`,
match: hasLegacyXaiSttEntries
})),
{
path: [
"models",
"providers",
"xai",
"models"
],
message: "models.providers.xai.models contains stale generated xAI catalog rows; run \"openclaw doctor --fix\" to remove them.",
match: hasLegacyBuiltinCatalogRows
}
];
function normalizeCompatibilityConfig({ cfg: e }) {
let t = e;
const n = [];
const r = { ...asNullableRecord(e.plugins?.entries?.xai?.config) };
for (const e of PLUGIN_MODEL_MIGRATIONS) {
const t = asNullableRecord(r[e.key]);
if (!isRetiredToolModel(t, e.retiredModels)) continue;
r[e.key] = {
...t,
model: e.targetModel
};
n.push(`Updated plugins.entries.xai.config.${e.key}.model from ${JSON.stringify(t?.model)} to ${JSON.stringify(e.targetModel)}.`);
}
if (n.length > 0) t = {
...t,
plugins: {
...e.plugins,
entries: {
...e.plugins?.entries,
xai: {
...e.plugins?.entries?.xai,
config: r
}
}
}
};
for (const r of XAI_MEDIA_MODEL_LIST_PATHS) {
const i = e.tools?.media?.models;
if (!Array.isArray(i)) continue;
let a = 0;
let o = 0;
const s = [];
for (const e of i) if (isRetiredXaiImageMediaEntry(e)) {
a += 1;
s.push({
...e,
model: "grok-4.3"
});
} else if (isLegacyXaiSttEntry(e)) {
const { model: t, ...n } = e;
o += 1;
s.push(n);
} else s.push(e);
if (a > 0 || o > 0) t = {
...t,
tools: {
...t.tools,
media: {
...t.tools?.media,
models: s
}
}
};
if (a > 0) n.push(`Migrated ${a} retired xAI image model${a === 1 ? "" : "s"} in ${r.join(".")} to grok-4.3.`);
if (o > 0) n.push(`Removed the obsolete xAI grok-stt model selector from ${o} ${r.join(".")} entr${o === 1 ? "y" : "ies"}.`);
}
const i = e.models?.providers?.xai;
if (i && Array.isArray(i.models)) {
const e = i.models.filter((e) => !isLegacyXaiBuiltinModel(e));
const r = i.models.length - e.length;
if (r > 0) {
t = {
...t,
models: {
...t.models,
providers: {
...t.models?.providers,
xai: {
...i,
models: e
}
}
}
};
n.push(`Removed ${r} stale generated xAI model catalog row(s).`);
}
}
return {
config: t,
changes: n
};
}
//#endregion
export { legacyConfigRules, normalizeCompatibilityConfig };