UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) • 2.49 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; //#region src/config/legacy.roster.ts /** Keeps Doctor's allocated identities tied to their original authored list positions. */ function projectLegacyAgentRosterEntries(e) { const t = []; const n = []; const r = /* @__PURE__ */ new Set(); for (const [i, a] of e.entries()) { if (!isRecord(a)) { n.push(`Removed malformed agents.list[${i}] entry.`); continue; } const e = typeof a.id === "string" && a.id.trim() ? a.id.trim() : "agent"; const o = normalizeAgentId(e); if (o !== e) n.push(`Normalized agents.list id "${e}" → agents.entries.${o}.`); let s = o; let c = 2; while (r.has(s)) { s = `${o}-${c}`; c += 1; } const { id: l, ...u } = a; t.push({ sourceIndex: i, id: s, config: u }); r.add(s); if (s !== o) n.push(`Moved duplicate agents.list id "${o}" to agents.entries.${s}.`); } return { entries: t, diagnostics: n }; } /** Converts a valid legacy roster without applying ownership or runtime migrations. */ function parseLegacyAgentRoster(e) { if (!Array.isArray(e)) return; const t = /* @__PURE__ */ new Set(); const n = []; for (const r of e) { if (!isRecord(r)) return; const { id: e, ...i } = r; if (typeof e !== "string" || e.trim() !== e || !e) return; const a = normalizeAgentId(e); if (a !== e || t.has(a)) return; t.add(e); n.push([e, i]); } return { entries: Object.fromEntries(n), order: [...t] }; } /** Resolve the original data owner using the same occurrence identities Doctor allocates. */ function resolveLegacyAgentRosterOwner(e) { const t = isRecord(e) && isRecord(e.agents) ? e.agents : void 0; if (!t || t.ownership === "explicit") return; const n = Object.hasOwn(t, "entries") ? isRecord(t.entries) ? Object.entries(t.entries).map(([e, t]) => ({ id: e, config: t })) : [] : Array.isArray(t.list) ? projectLegacyAgentRosterEntries(t.list).entries : []; if (n.length < 2 || n.some(({ config: e }) => !isRecord(e) || Object.hasOwn(e, "default") && typeof e.default !== "boolean")) return; const r = n.filter(({ config: e }) => isRecord(e) && e.default === true); if (r.length === 0 && !Object.hasOwn(t, "entries")) return normalizeAgentId(n[0].id); return r.length === 1 ? normalizeAgentId(r[0].id) : void 0; } //#endregion export { projectLegacyAgentRosterEntries as n, resolveLegacyAgentRosterOwner as r, parseLegacyAgentRoster as t };