UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

100 lines (99 loc) • 3.72 kB
import { o as writeRuntimeJson, s as writeRuntimeStdout } from "./runtime-B-SLYP-m.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { f as DEFAULT_MODEL_ALIASES } from "./validation-core-1Fx8ByEb.mjs"; import { n as normalizeAgentModelMapForConfig } from "./model-input-DrM4DWHG.mjs"; import { r as logConfigUpdated } from "./logging-D0RirHBi.mjs"; import { c as resolveModelTarget, f as upsertCanonicalModelConfigEntry, n as ensureFlagCompatibility, o as requireKnownModelProvider, u as updateConfig } from "./shared-jZuoMzdG.mjs"; import { t as normalizeAlias } from "./alias-name-o9aqLBJk.mjs"; import { t as loadModelsConfig } from "./load-config-CTxoGQxg.mjs"; //#region src/commands/models/aliases.ts async function modelsAliasesListCommand(e, t) { ensureFlagCompatibility(e); const n = (await loadModelsConfig({ commandName: "models aliases list", runtime: t })).agents?.defaults?.models ?? {}; const r = Object.fromEntries(Object.entries(n).flatMap(([e, t]) => { const n = t?.alias?.trim(); return n ? [[n, e]] : []; })); const i = Object.entries(r).toSorted(([e], [t]) => e.localeCompare(t)); if (e.json) { writeRuntimeJson(t, { aliases: Object.fromEntries(i) }); return; } if (e.plain) { for (const [e, n] of i) writeRuntimeStdout(t, terminalText`${e} ${n}`); return; } t.log(`Aliases (${i.length}):`); if (i.length === 0) { t.log("- none"); return; } for (const [e, n] of i) t.log(terminalText`- ${e} -> ${n}`); } async function modelsAliasesAddCommand(e, t, n) { const r = normalizeAlias(e); const i = r.toLowerCase(); let a = t; let o; await updateConfig((e, n) => { const s = resolveModelTarget({ raw: t, cfg: n.runtimeConfig }); o = requireKnownModelProvider(n.runtimeConfig, s, n.providerRegistryAvailable).warning; const c = { ...e.agents?.defaults?.models }; const l = upsertCanonicalModelConfigEntry(c, s, n); a = l; for (const [e, t] of Object.entries(c)) { const n = t?.alias?.trim(); if (n && n.toLowerCase() === i && e !== l) throw new Error(`Alias ${r} already points to ${e}.`); } c[l] = { ...c[l], alias: r }; e.agents ??= {}; e.agents.defaults ??= {}; e.agents.defaults.models = c; return e; }, (e, n) => [resolveModelTarget({ raw: t, cfg: n.runtimeConfig })]); if (o) n.error?.(terminalText`${o}`); logConfigUpdated(n); n.log(terminalText`Alias ${r} -> ${a}`); } async function modelsAliasesRemoveCommand(e, t) { const n = normalizeAlias(e); const r = n.toLowerCase(); const i = await updateConfig((e) => { const t = { ...e.agents?.defaults?.models }; let i = false; for (const [e, n] of Object.entries(t)) if (n?.alias?.trim().toLowerCase() === r) { t[e] = { ...n, alias: void 0 }; i = true; } if (!i) { const e = DEFAULT_MODEL_ALIASES[r]; const i = normalizeAgentModelMapForConfig(t); if (e && i[e] && i[e]?.alias === void 0) throw new Error(`Cannot remove "${n}": it is a built-in alias for "${e}" provided automatically by OpenClaw and is not stored in your config file. To shadow it with a different target, run ${formatCliCommand(`openclaw models aliases add ${n} <model>`)}.`); throw new Error(`Alias not found: ${n}. Run ${formatCliCommand("openclaw models aliases list")} to see configured aliases.`); } e.agents ??= {}; e.agents.defaults ??= {}; e.agents.defaults.models = t; return e; }); logConfigUpdated(t); if (Object.values(i.agents?.defaults?.models ?? {}).every((e) => !e?.alias?.trim())) t.log("No aliases configured."); } //#endregion export { modelsAliasesAddCommand, modelsAliasesListCommand, modelsAliasesRemoveCommand };