UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

97 lines (96 loc) • 3.97 kB
import { l as isRecord, r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import { t as DEFAULT_AGENT_ID } from "./session-key-CqAyZeVk.mjs"; import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs"; import { t as AgentSelectionRequiredError } from "./agent-scope-config-DmXgFGKP.mjs"; import { n as projectLegacyAgentRosterEntries } from "./legacy.roster-BcYJITMZ.mjs"; import { r as resolveChannelAccountEntry } from "./account-lookup-FhQZVFfo.mjs"; import { t as resolveChannelAccountBindingRepairInput } from "./legacy-config-binding-repair-input-BUGnndOR.mjs"; import { o as resolveAgentRoute } from "./resolve-route-DBnTWpM6.mjs"; import { r as resolveReadOnlyChannelPluginsForConfig } from "./read-only-idsFCBWl.mjs"; //#region src/commands/doctor/shared/legacy-config-binding-repair.ts function pruneBindingsForMissingAgents(e, t) { const n = asNullableRecord(e); const r = asNullableRecord(n?.agents)?.list; if (!n || !Array.isArray(r) || r.length === 0 || !Array.isArray(n.bindings)) return e; const i = r; const a = n.bindings; const o = i.filter((e) => isRecord(e) && typeof e.id === "string"); if (o.length !== i.length) return e; const s = new Set(o.map((e) => normalizeAgentId(e.id))); const c = a.filter((e) => { const t = asNullableRecord(e)?.agentId; return typeof t !== "string" || t === "main" || s.has(normalizeAgentId(t)); }); const l = a.length - c.length; if (l === 0) return e; t.push(`Removed ${l} binding${l === 1 ? "" : "s"} that referenced missing agents.list ids.`); return { ...e, bindings: c.length > 0 ? c : void 0 }; } /** Preserve proven route owners before explicit ownership retires implicit account routing. */ function repairUnownedChannelAccountBindings({ config: e, sourceConfigBeforeMigrations: t }) { const n = resolveChannelAccountBindingRepairInput(e); if (!n) return { config: e, changes: [] }; const { agentIds: r, bindings: i } = n; const a = []; const o = []; const s = asNullableRecord(asNullableRecord(t)?.agents); const c = s?.list; const l = s?.ownership === void 0 && s?.entries === void 0 && Array.isArray(c) && c.length > 1 && c.every((e) => isRecord(e) && typeof e.id === "string" && e.id.trim().length > 0 && (e.default === void 0 || e.default === false)) ? projectLegacyAgentRosterEntries(c).entries[0]?.id : void 0; const u = resolveReadOnlyChannelPluginsForConfig(e, { includePersistedAuthState: false, includeSetupFallbackPlugins: true }); const d = new Map(u.plugins.map((e) => [e.id, e])); for (const t of [...u.configuredChannelIds].toSorted()) { const n = d.get(t); const i = asNullableRecord(e.channels?.[t]); if (!n || i?.enabled === false) continue; const u = asNullableRecord(i?.accounts) ?? void 0; const f = [...new Set(n.config.listAccountIds(e).map(normalizeAccountId))].toSorted(); for (const n of f) { const i = resolveChannelAccountEntry(u, n, t, normalizeAccountId); if (asNullableRecord(i)?.enabled === false) continue; let d; try { const r = resolveAgentRoute({ cfg: e, channel: t, accountId: n }); if (!l || r.matchedBy !== "default") continue; } catch (e) { if (!(e instanceof AgentSelectionRequiredError)) throw e; d = e; } const f = l; if (f && r.has(f)) a.push({ agentId: f, match: { channel: t, accountId: n } }); else if (d) o.push(!Array.isArray(c) && !isRecord(s?.entries) ? `${t}:${n} unresolved: original roster unavailable. ${d.message}` : d.message); } } return { config: a.length ? { ...e, bindings: [...i, ...a] } : e, changes: a.map(({ agentId: e, match: t }) => `Preserved ${t.channel}:${t.accountId} ownership with binding ${JSON.stringify({ agentId: e, match: t })}.`), ...o.length > 0 ? { warnings: o } : {} }; } //#endregion export { repairUnownedChannelAccountBindings as n, pruneBindingsForMissingAgents as t };