UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

94 lines (93 loc) • 4.19 kB
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs"; import "./utils-C8YECn2Q.mjs"; import { u as tryResolveDefaultAgentId } from "./agent-roster-t1ooUdXp.mjs"; import { f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { f as normalizeBundledLookupPath, m as parsePackagedBundledPluginPath, p as parseLegacyBundledPluginPath, t as discoverConfiguredPluginLoadPaths, u as buildBundledPluginLoadPathAliases } from "./discovery-DvJYrQFY.mjs"; import { n as findUninspectedPluginDiagnostic } from "./discovery-availability-DtlJ7XvT.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { a as resolveBundledPluginSources } from "./bundled-sources-CIS6N5EC.mjs"; import path from "node:path"; //#region 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"; } /** Find configured plugin load paths that alias bundled plugins already shipped by OpenClaw. */ 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)); } /** Remove redundant bundled plugin load path aliases while preserving unrelated custom paths. */ 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}`) }; } //#endregion export { maybeRepairBundledPluginLoadPaths as n, scanBundledPluginLoadPathMigrations as r, collectBundledPluginLoadPathWarnings as t };