openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.52 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
//#region src/commands/doctor/shared/model-replacement.ts
function parseDoctorModelReplacements(e) {
const t = e.map((e) => {
let t;
try {
t = asOptionalRecord(JSON.parse(e));
} catch {
throw new Error("--replace-model requires a JSON object.");
}
const n = typeof t?.from === "string" ? t.from.trim() : "";
const r = typeof t?.to === "string" ? t.to.trim() : "";
const i = t?.accessProgram;
if (!/^openai\/gpt-daybreak-(blue|red)-latest$/.test(n) || !/^openai\/[^/@\s]+$/.test(r) || /^openai\/gpt-daybreak-(blue|red)-latest$/.test(r) || i !== "standard" && i !== "daybreak_blue" && i !== "daybreak_red" || Object.keys(t ?? {}).some((e) => ![
"from",
"to",
"accessProgram"
].includes(e))) throw new Error("--replace-model requires {\"from\":\"openai/gpt-daybreak-blue-latest\" (or red),\"to\":\"openai/<specific-model>\",\"accessProgram\":\"standard\" (or daybreak_blue/daybreak_red)}, without account suffixes.");
return {
from: n,
to: r,
accessProgram: i
};
});
const n = /* @__PURE__ */ new Set();
const r = /* @__PURE__ */ new Map();
for (const e of t) {
if (n.has(e.from)) throw new Error("Duplicate --replace-model source: " + e.from);
if (r.has(e.to) && r.get(e.to) !== e.accessProgram) throw new Error("Conflicting Access programs for --replace-model target: " + e.to);
n.add(e.from);
r.set(e.to, e.accessProgram);
}
return t;
}
//#endregion
export { parseDoctorModelReplacements };