openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
66 lines (65 loc) • 3.12 kB
JavaScript
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { s as redactSensitiveText } from "./redact-Mj7pppxC.mjs";
import "./utils-C8YECn2Q.mjs";
import { g as isPluginCandidateInstallOwnerAmbiguous, y as resolvePluginCandidateInstallOwner } from "./discovery-DvJYrQFY.mjs";
import { n as isPathInside } from "./path-safety-CTChYC4Z.mjs";
import { a as pluginCacheRealpathSync } from "./plugin-cache-files-e1aGp2KM.mjs";
import { i as isTrustedOfficialPluginInstallRecord, n as isThirdPartyNpmInstallRecord } from "./official-external-install-records-DHqBi8wk.mjs";
//#region src/plugins/installed-plugin-record-match.ts
function resolveCandidateInstallOwner(e) {
if (isPluginCandidateInstallOwnerAmbiguous(e.candidate)) return;
const t = resolvePluginCandidateInstallOwner(e.candidate);
return t && Object.hasOwn(e.installRecords, t) ? t : void 0;
}
function matchesInstalledPluginRecord(e) {
if (e.candidate.origin !== "global" && e.candidate.origin !== "config") return false;
const t = resolveCandidateInstallOwner(e);
const n = t ? e.installRecords[t] : void 0;
if (!n) return false;
const r = [
e.candidate.rootDir,
e.candidate.packageDir,
e.candidate.source,
e.candidate.setupSource
].filter((e) => typeof e === "string" && e.trim().length > 0).map((t) => {
const n = resolveUserPath(t, e.env);
return pluginCacheRealpathSync(n) ?? n;
});
const i = (e.installPathOnly ? [n.installPath] : [n.installPath, n.sourcePath]).filter((e) => typeof e === "string" && e.trim().length > 0).map((t) => {
const n = resolveUserPath(t, e.env);
return pluginCacheRealpathSync(n) ?? n;
});
if (r.length === 0 || i.length === 0) return false;
return i.some((e) => r.some((t) => t === e || isPathInside(e, t) || isPathInside(t, e)));
}
function resolvePluginTrust(e) {
const t = resolveCandidateInstallOwner(e);
const n = t ? e.installRecords[t] : void 0;
const r = e.candidate.origin;
let i;
if (r === "bundled") i = "bundled";
else if (isPluginCandidateInstallOwnerAmbiguous(e.candidate)) i = "owner-ambiguous";
else if (r === "workspace" || n?.source === "path" || n?.source === "npm" && (n.artifactKind !== void 0 || n.sourcePath !== void 0)) i = "origin-path";
else if (!n || !t) i = "record-missing";
else if (!matchesInstalledPluginRecord({
...e,
installPathOnly: true
})) i = "install-path-mismatch";
else if (isTrustedOfficialPluginInstallRecord({
pluginId: t,
packageName: e.candidate.packageName,
record: n
})) i = "trusted-official";
else if (n.source === "npm" && n.spec === void 0 && n.resolvedName === void 0 && n.resolvedSpec === void 0 || n.source === "clawhub" && n.clawhubUrl === void 0 && n.clawhubChannel === void 0) i = "provenance-missing";
else if (isThirdPartyNpmInstallRecord(t, e.candidate.packageName, n)) i = "third-party-npm";
else i = "provenance-invalid";
return {
reason: i,
registryPath: e.registryPath,
origin: r,
installSource: n?.source,
installSpec: n?.spec === void 0 ? void 0 : redactSensitiveText(n.spec, { mode: "tools" })
};
}
//#endregion
export { resolvePluginTrust as n, matchesInstalledPluginRecord as t };