openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
102 lines (101 loc) • 4.33 kB
JavaScript
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { r as isRootFileMissingFailure } from "./boundary-file-read-BfaFLDqt.mjs";
import { o as resolveRootPathSync, r as resolvePathViaExistingAncestorSync, s as safeRealpathSync } from "./boundary-path-C2gXEiXe.mjs";
import { r as isPathInside } from "./path-guards-TIjxtj6H.mjs";
import "./utils-C8YECn2Q.mjs";
import { t as discoverConfiguredPluginLoadPaths } from "./discovery-DvJYrQFY.mjs";
import { i as createPluginCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs";
import { r as resolvePackageExtensionEntries } from "./package-manifest-CC8p56hY.mjs";
import { c as readRootJsonObjectSync } from "./json-files-Cb1h8pYs.mjs";
import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs";
import { n as buildPluginCapabilitySummary, o as mergePluginDeclaredSurfaces } from "./capability-summary-Dfhfz0nD.mjs";
import fs from "node:fs";
import path from "node:path";
//#region 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 = discoverConfiguredPluginLoadPaths({
loadPaths: [r],
env: t,
deduplicate: true
});
const l = new Set(c.candidates.map((e) => safeRealpathSync(e.source) ?? e.source));
const u = s.length === 1 ? c : discoverConfiguredPluginLoadPaths({
loadPaths: s,
env: t,
deduplicate: true
});
const d = loadPluginManifestRegistryCore({
config: { plugins: { load: { paths: s } } },
env: t,
installRecords: {},
discovery: {
candidates: u.candidates.filter((e) => l.has(safeRealpathSync(e.source) ?? e.source)),
diagnostics: c.diagnostics
}
});
const f = d.diagnostics.find((e) => e.level === "error");
if (f || d.plugins.length === 0) {
const e = f ?? d.diagnostics.find((e) => e.level === "warn");
throw new Error(e?.message ?? `Plugin artifact has no valid plugin manifest: ${r}`);
}
return d.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))
};
});
}
/** Read only validated manifest surfaces belonging to the actual artifact on disk. */
function resolvePluginArtifactDeclaredSurface(e, t = process.env, n = {}) {
return inspectPluginCapabilityArtifact(e, t, n).declared;
}
//#endregion
export { resolvePluginArtifactDeclaredSurface as n, inspectPluginCapabilityArtifact as t };