UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

99 lines (98 loc) • 4.71 kB
import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs"; import { u as tryResolveDefaultAgentId } from "./agent-roster-t1ooUdXp.mjs"; import { f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { t as normalizePluginPolicyId } from "./plugin-policy-id-CkilMowp.mjs"; import { D as hasKind, E as defaultSlotIdForKey, c as normalizePluginId, u as normalizePluginsConfig, v as resolveSelectedContextEnginePluginId } from "./config-state-B1JlHgba.mjs"; import { r as hasIncompletePluginDiscovery } from "./discovery-availability-DtlJ7XvT.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { s as loadManifestMetadataSnapshot } from "./manifest-contract-eligibility-DoGGge-2.mjs"; //#region src/commands/doctor/shared/context-engine-plugin-id-selector.ts const SLOT_PATH = "plugins.slots.contextEngine"; /** * Before declared engine ownership, installing a context-engine plugin stored its plugin ID * as the selector. Such a selector never resolves when the plugin registers a different * engine ID, so turns silently fall back to legacy. Only the plugin's single declared, * eligible engine replaces it; ambiguous or unauthorized owners stay unchanged. */ function findContextEnginePluginIdSelector(e, t) { const n = e.plugins?.slots?.contextEngine?.trim(); if (e.plugins?.enabled === false || !n || n.toLowerCase() === "none" || n === defaultSlotIdForKey("contextEngine") || t.some((e) => e.contextEngineIds?.includes(n))) return; const r = t.find((e) => hasKind(e.kind, "context-engine") && e.contextEngineIds?.length && normalizePluginPolicyId(e.id) === normalizePluginPolicyId(n)); const i = r?.contextEngineIds ?? []; if (!r || i.length === 0) return; const [a] = i; if (i.length !== 1 || !a) return { kind: "choose", message: `- ${SLOT_PATH}: "${n}" is a plugin ID, not an engine ID. Plugin "${r.id}" declares multiple engines; set ${SLOT_PATH} to one of: ${i.join(", ")}.` }; const o = t.map(({ id: e, contextEngineIds: t }) => ({ id: e, contextEngineIds: t })); if (!isIndependentlyApproved(e, r.id) || resolveSelectedContextEnginePluginId(withSelector(e, a), o) !== r.id) return { kind: "choose", message: `- ${SLOT_PATH}: "${n}" is a plugin ID, not an engine ID. Plugin "${r.id}" declares engine "${a}", but it is not independently enabled or another eligible plugin declares the same engine. Enable plugins.entries.${r.id} or resolve the conflict, then set ${SLOT_PATH} to "${a}".` }; return { kind: "replace", selector: n, pluginId: r.id, engineId: a }; } /** * The resolver lets an explicit equal-ID selection bypass enablement and the allowlist. * Doctor did not receive that selection, so it never widens activation on its own. */ function isIndependentlyApproved(e, t) { const n = normalizePluginsConfig(e.plugins); const r = normalizePluginPolicyId(normalizePluginId(t)); return (n.entries[r]?.enabled === true || n.allow.includes(r)) && (n.allow.length === 0 || n.allow.includes(r)); } function withSelector(e, t) { return { ...e, plugins: { ...e.plugins, slots: { ...e.plugins?.slots, contextEngine: t } } }; } function loadSelectorFinding(e, t) { if (!e.plugins?.slots?.contextEngine || e.plugins.enabled === false) return; const n = tryResolveDefaultAgentId(e); const r = loadManifestMetadataSnapshot({ config: e, workspaceDir: n ? resolveAgentWorkspaceDir(e, n) : void 0, env: t ?? process.env }).manifestRegistry; return hasIncompletePluginDiscovery(r.diagnostics) ? void 0 : findContextEnginePluginIdSelector(e, r.plugins); } /** Doctor repair: replace a legacy plugin-ID context-engine selector with its declared engine. */ function maybeRepairContextEnginePluginIdSelector(e, t) { const n = loadSelectorFinding(e, t); if (!n) return { config: e, changes: [] }; if (n.kind === "choose") return { config: e, changes: [], warnings: [sanitizeForLog(n.message)] }; return { config: withSelector(e, n.engineId), changes: [sanitizeForLog(`- ${SLOT_PATH}: replaced plugin ID "${n.selector}" with its declared engine "${n.engineId}"`)] }; } /** Doctor preview: describe the selector repair without changing config. */ function collectContextEnginePluginIdSelectorWarnings(e) { const t = loadSelectorFinding(e.cfg, e.env); if (!t) return []; return [sanitizeForLog(t.kind === "choose" ? t.message : `- ${SLOT_PATH}: "${t.selector}" is plugin "${t.pluginId}"'s ID, so its engine never loads and turns fall back to legacy. Run "${e.doctorFixCommand}" to select its declared engine "${t.engineId}".`)]; } //#endregion export { findContextEnginePluginIdSelector as n, maybeRepairContextEnginePluginIdSelector as r, collectContextEnginePluginIdSelectorWarnings as t };