openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.8 kB
JavaScript
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import{i as createPluginCache,w as withPluginCache}from"./plugin-cache-B6QVpzXr.mjs";import{r as isPathInside}from"./path-guards-DGttsOJI.mjs";import"./utils-Dlk0IYAa.mjs";import{r as isRootFileMissingFailure}from"./boundary-file-read-bB9An35K.mjs";import{a as safeRealpathSync,i as resolveRootPathSync,t as resolvePathViaExistingAncestorSync}from"./boundary-path-BeuXNL_4.mjs";import{r as resolvePackageExtensionEntries}from"./package-manifest-CMy2j7Hf.mjs";import{t as discoverConfiguredPluginLoadPaths}from"./discovery-Bo4UPPd9.mjs";import{c as readRootJsonObjectSync}from"./json-files-BBQ_0Np0.mjs";import{t as loadPluginManifestRegistryCore}from"./manifest-registry-BHN0dk30.mjs";import{n as buildPluginCapabilitySummary,o as mergePluginDeclaredSurfaces}from"./capability-summary-D1Y-zikG.mjs";import fs from"node:fs";import path from"node:path";
//!src/plugins/capability-artifact.ts
function resolvePluginArtifactManifests(e,t=process.env,n={}){const r=fs.realpathSync(resolveUserPath(e,t));const i=readRootJsonObjectSync({rootDir:r,rootRealPath:r,relativePath:`package.json`,boundaryLabel:`plugin artifact directory`,rejectHardlinks:true});if(!i.ok){if(i.reason!==`open`||!isRootFileMissingFailure(i.failure))throw new Error(`Unable to inspect the plugin artifact package manifest: ${r}`)}else{const e=resolvePackageExtensionEntries(i.value);if(e.status===`invalid`)throw new Error(e.error);if(e.status===`empty`)throw new Error(`package.json openclaw.extensions is empty`)}const a=path.resolve(resolveUserPath(n.currentArtifactDir??e,t));const o=resolvePathViaExistingAncestorSync(a);const s=[];for(const e of n.config?.plugins?.load?.paths??[]){const n=path.resolve(resolveUserPath(e,t));const i=resolvePathViaExistingAncestorSync(n);if(!isPathInside(a,n)&&!isPathInside(o,i))continue;const c=resolveRootPathSync({absolutePath:n,rootPath:a,rootCanonicalPath:o,boundaryLabel:`installed plugin artifact directory`});const l=isPathInside(a,n)?a:o;const u=isPathInside(l,n)?path.relative(l,n):path.relative(o,c.kind===`directory`?c.canonicalPath:path.join(resolvePathViaExistingAncestorSync(path.dirname(n)),path.basename(n)));const d=resolveRootPathSync({absolutePath:path.join(r,u),rootPath:r,rootCanonicalPath:r,boundaryLabel:`staged plugin artifact directory`});s.push(d.absolutePath)}s.push(r);const c={env:t,deduplicate:true,inspectingPreviousArtifact:n.inspectingPreviousArtifact};const l=discoverConfiguredPluginLoadPaths({...c,loadPaths:[r]});const u=new Set(l.candidates.map(e=>safeRealpathSync(e.source)??e.source));const d=s.length===1?l:discoverConfiguredPluginLoadPaths({...c,loadPaths:s});const f=loadPluginManifestRegistryCore({config:{plugins:{load:{paths:s}}},env:t,installRecords:{},inspectingPreviousArtifact:n.inspectingPreviousArtifact,discovery:{candidates:d.candidates.filter(e=>u.has(safeRealpathSync(e.source)??e.source)),diagnostics:l.diagnostics}});const p=f.diagnostics.find(e=>e.level===`error`);if(p||f.plugins.length===0){const e=p??f.diagnostics.find(e=>e.level===`warn`);throw new Error(e?.message??`Plugin artifact has no valid plugin manifest: ${r}`)}return f.plugins}function inspectPluginCapabilityArtifact(e,t=process.env,n={}){return withPluginCache(createPluginCache(),()=>{const r=resolvePluginArtifactManifests(e,t,n);return{manifest:r[0],manifests:r,contextEngineIdsByPlugin:Object.fromEntries(r.flatMap(e=>e.contextEngineIds?[[e.id,[...e.contextEngineIds]]]:[])),declared:mergePluginDeclaredSurfaces(r.map(e=>buildPluginCapabilitySummary({manifest:e,origin:`global`}).declared))}})}function resolvePluginArtifactDeclaredSurface(e,t=process.env,n={}){return inspectPluginCapabilityArtifact(e,t,n).declared}export{resolvePluginArtifactDeclaredSurface as n,inspectPluginCapabilityArtifact as t};