openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.47 kB
JavaScript
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import"./utils-Dlk0IYAa.mjs";import{u as tryResolveDefaultAgentId}from"./agent-roster-4XrgUgPK.mjs";import{f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{A as parsePackagedBundledPluginPath,E as buildBundledPluginLoadPathAliases,O as normalizeBundledLookupPath,k as parseLegacyBundledPluginPath,l as findUninspectedPluginDiagnostic,t as discoverConfiguredPluginLoadPaths}from"./discovery-Bo4UPPd9.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{a as resolveBundledPluginSources}from"./bundled-sources-imFFFyl2.mjs";import path from"node:path";
//!src/commands/doctor/shared/bundled-plugin-load-paths.ts
function isOpenClawNodeModulesPackageRoot(e){const t=normalizeBundledLookupPath(e);const n=path.basename(t);const r=path.basename(path.dirname(t));return n===`openclaw`&&r===`node_modules`}function scanBundledPluginLoadPathMigrations(e,t=process.env){const n=asNullableRecord(e.plugins);const r=asNullableRecord(n?.load);const i=Array.isArray(r?.paths)?r.paths:[];if(i.length===0)return[];const a=tryResolveDefaultAgentId(e);const o=resolveBundledPluginSources({workspaceDir:a?resolveAgentWorkspaceDir(e,a):void 0,env:t});if(o.size===0)return[];const s=/* @__PURE__ */ new Map;const c=/* @__PURE__ */ new Map;for(const e of o.values()){const t={pluginId:e.pluginId,toPath:e.localPath};for(const n of buildBundledPluginLoadPathAliases(e.localPath))s.set(normalizeBundledLookupPath(n.path),t);const n=parsePackagedBundledPluginPath(e.localPath);if(n)c.set(normalizeBundledLookupPath(n.bundledLeaf),t)}const{diagnostics:l}=discoverConfiguredPluginLoadPaths({loadPaths:i.filter(e=>typeof e===`string`),env:t});const u=[];for(const e of i){if(typeof e!==`string`)continue;const n=normalizeBundledLookupPath(resolveUserPath(e,t));if(findUninspectedPluginDiagnostic(l.filter(e=>e.source!==void 0&&normalizeBundledLookupPath(e.source)===n)))continue;let r=s.get(n);if(!r){const e=parsePackagedBundledPluginPath(n)??parseLegacyBundledPluginPath(n);r=e?.packageRoot&&e.bundledLeaf&&isOpenClawNodeModulesPackageRoot(e.packageRoot)?c.get(normalizeBundledLookupPath(e.bundledLeaf)):void 0}if(!r)continue;u.push({pluginId:r.pluginId,fromPath:e,toPath:r.toPath,pathLabel:`plugins.load.paths`})}return u}function collectBundledPluginLoadPathWarnings(e){if(e.hits.length===0)return[];const t=e.hits.map(e=>`- ${e.pathLabel}: bundled plugin path "${e.fromPath}" still aliases ${e.pluginId}; OpenClaw loads the packaged bundled plugin from "${e.toPath}".`);t.push(`- Run "${e.doctorFixCommand}" to remove these redundant bundled plugin paths.`);return t.map(e=>sanitizeForLog(e))}function maybeRepairBundledPluginLoadPaths(e,t=process.env){const n=scanBundledPluginLoadPathMigrations(e,t);if(n.length===0)return{config:e,changes:[]};const r=structuredClone(e);const i=r.plugins?.load;if(!Array.isArray(i?.paths))return{config:e,changes:[]};const a=new Set(n.map(e=>normalizeBundledLookupPath(resolveUserPath(e.fromPath,t))));i.paths=Array.from(i.paths).filter(e=>typeof e!==`string`||!a.has(normalizeBundledLookupPath(resolveUserPath(e,t))));return{config:r,changes:n.map(e=>`- plugins.load.paths: removed bundled ${e.pluginId} path alias ${e.fromPath}`)}}export{maybeRepairBundledPluginLoadPaths as n,scanBundledPluginLoadPathMigrations as r,collectBundledPluginLoadPathWarnings as t};