UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

100 lines (99 loc) • 3.65 kB
import { c as isRecord } from "./record-coerce-TIsquoVR.mjs"; import { n as normalizeAgentId } from "./agent-id-D1-Q6vR4.mjs"; import { n as LEGACY_IMPLICIT_AGENT_ID } from "./session-key-C09ow4h0.mjs"; //#region src/agents/agent-roster.ts function collectAgentEntries(cfg, withSource, limit) { const roster = readAgentRosterProperty(cfg); if (roster?.kind === "entries" && isRecord(roster.value)) { const result = []; for (const id in roster.value) { if (!Object.hasOwn(roster.value, id)) continue; const entry = roster.value[id]; if (isRecord(entry)) { const projected = { ...entry, id }; result.push(withSource ? { entry: projected, source: { kind: "entries", key: id } } : projected); if (result.length === limit) break; } } return result; } if (roster?.kind !== "list" || !Array.isArray(roster.value)) return []; const listed = []; roster.value.some((entry, index) => { if (entry !== null && typeof entry === "object") listed.push({ entry, source: { kind: "list", index } }); return listed.length === limit; }); return withSource ? listed : listed.map(({ entry }) => entry); } /** Lists valid configured agent entries from config. */ function listAgentEntriesWithSource(cfg) { return collectAgentEntries(cfg, true); } /** Lists valid configured agent entries from either supported representation. */ function listAgentEntries(cfg) { return collectAgentEntries(cfg, false); } /** Reads the explicitly owned raw roster without normalizing malformed values. */ function readAgentRosterProperty(raw) { if (!isRecord(raw)) return; const agents = raw.agents; if (!isRecord(agents)) return; const entries = agents["entries"]; if (Object.hasOwn(agents, "entries") && entries !== void 0) return { kind: "entries", value: entries }; const list = agents["list"]; if (Object.hasOwn(agents, "list") && list !== void 0) return { kind: "list", value: list }; } /** True when raw config explicitly owns either supported roster representation. */ function hasAgentRosterProperty(raw) { return readAgentRosterProperty(raw) !== void 0; } /** Lists unique configured agent ids. */ function listAgentIds(cfg) { const agents = listAgentEntries(cfg); if (agents.length === 0 && !hasAgentRosterProperty(cfg)) return [LEGACY_IMPLICIT_AGENT_ID]; return [...new Set(agents.map((entry) => normalizeAgentId(entry?.id)))]; } function tryResolveSoleAgentId(cfg) { const agents = collectAgentEntries(cfg, false, 2); if (agents.length === 0) { if (!hasAgentRosterProperty(cfg)) return LEGACY_IMPLICIT_AGENT_ID; return; } return agents.length === 1 ? normalizeAgentId(agents[0].id) : void 0; } function tryResolveRawLegacyDefaultAgentId(cfg) { if (cfg.agents?.ownership === "explicit") return; const marked = collectAgentEntries(cfg, false).filter((entry) => entry.default === true); return marked.length === 1 ? normalizeAgentId(marked[0].id) : void 0; } /** @deprecated Use tryResolveSoleAgentId; accepts raw shipped markers only for input compatibility. */ function tryResolveDefaultAgentId(cfg) { return tryResolveRawLegacyDefaultAgentId(cfg) ?? tryResolveSoleAgentId(cfg); } /** Preserves legacy data locators independently of the configured runtime owner. */ function tryResolveLegacyDataOwner(cfg) { return tryResolveDefaultAgentId(cfg); } //#endregion export { readAgentRosterProperty as a, tryResolveRawLegacyDefaultAgentId as c, listAgentIds as i, tryResolveSoleAgentId as l, listAgentEntries as n, tryResolveDefaultAgentId as o, listAgentEntriesWithSource as r, tryResolveLegacyDataOwner as s, hasAgentRosterProperty as t };