openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.56 kB
JavaScript
import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import{t as normalizePluginPolicyId}from"./plugin-policy-id-Nz6ZTOOH.mjs";import{D as hasKind,E as defaultSlotIdForKey,c as normalizePluginId,u as normalizePluginsConfig,v as resolveSelectedContextEnginePluginId}from"./config-state-C1eV6UWf.mjs";import{u as tryResolveDefaultAgentId}from"./agent-roster-4XrgUgPK.mjs";import{f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{u as hasIncompletePluginDiscovery}from"./discovery-Bo4UPPd9.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{s as loadManifestMetadataSnapshot}from"./manifest-contract-eligibility-BFn2JM5T.mjs";
//!src/commands/doctor/shared/context-engine-plugin-id-selector.ts
const SLOT_PATH=`plugins.slots.contextEngine`;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}}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)}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}"`)]}}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}".`)]}export{findContextEnginePluginIdSelector as n,maybeRepairContextEnginePluginIdSelector as r,collectContextEnginePluginIdSelectorWarnings as t};