UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) • 3.65 kB
import { o as resolveUserPath } from "./home-dir-Dc6nN6HB.mjs"; import { _ as redactSensitiveText } from "./redact-BV3wTtTv.mjs"; import "./utils-CitNzLyF.mjs"; import { n as isPathInside } from "./path-safety-DLhZlHs6.mjs"; import { l as pluginCacheRealpathSync } from "./package-manifest-DKd3Hflg.mjs"; import { F as resolvePluginCandidateInstallOwner, M as isPluginCandidateInstallOwnerAmbiguous } from "./discovery-D42cUZXk.mjs"; import { r as isTrustedOfficialPluginInstallRecord } from "./official-external-install-records-CLRWqPnV.mjs"; //#region src/plugins/installed-plugin-record-match.ts function resolveCandidateInstallOwner(params) { if (isPluginCandidateInstallOwnerAmbiguous(params.candidate)) return; const installOwner = resolvePluginCandidateInstallOwner(params.candidate); if (installOwner) return Object.hasOwn(params.installRecords, installOwner) ? installOwner : void 0; } function matchesInstalledPluginRecord(params) { if (params.candidate.origin !== "global" && params.candidate.origin !== "config") return false; const installOwner = resolveCandidateInstallOwner(params); const record = installOwner ? params.installRecords[installOwner] : void 0; if (!record) return false; const candidatePaths = [ params.candidate.rootDir, params.candidate.packageDir, params.candidate.source, params.candidate.setupSource ].filter((entry) => typeof entry === "string" && entry.trim().length > 0).map((entry) => { const resolved = resolveUserPath(entry, params.env); return pluginCacheRealpathSync(resolved) ?? resolved; }); const trackedPaths = (params.installPathOnly ? [record.installPath] : [record.installPath, record.sourcePath]).filter((entry) => typeof entry === "string" && entry.trim().length > 0).map((entry) => { const resolved = resolveUserPath(entry, params.env); return pluginCacheRealpathSync(resolved) ?? resolved; }); if (candidatePaths.length === 0 || trackedPaths.length === 0) return false; return trackedPaths.some((trackedPath) => candidatePaths.some((candidatePath) => candidatePath === trackedPath || isPathInside(trackedPath, candidatePath) || isPathInside(candidatePath, trackedPath))); } function resolvePluginTrust(params) { const installOwner = resolveCandidateInstallOwner(params); const record = installOwner ? params.installRecords[installOwner] : void 0; const origin = params.candidate.origin; let reason; if (origin === "bundled") reason = "bundled"; else if (isPluginCandidateInstallOwnerAmbiguous(params.candidate)) reason = "owner-ambiguous"; else if (origin === "workspace" || record?.source === "path" || record?.source === "npm" && (record.artifactKind !== void 0 || record.sourcePath !== void 0)) reason = "origin-path"; else if (!record || !installOwner) reason = "record-missing"; else if (!matchesInstalledPluginRecord({ ...params, installPathOnly: true })) reason = "install-path-mismatch"; else if (isTrustedOfficialPluginInstallRecord({ pluginId: installOwner, packageName: params.candidate.packageName, record })) reason = "trusted-official"; else if (record.source === "npm" && record.spec === void 0 && record.resolvedName === void 0 && record.resolvedSpec === void 0 || record.source === "clawhub" && record.clawhubUrl === void 0 && record.clawhubChannel === void 0) reason = "provenance-missing"; else reason = "provenance-invalid"; return { reason, registryPath: params.registryPath, origin, installSource: record?.source, installSpec: record?.spec === void 0 ? void 0 : redactSensitiveText(record.spec, { mode: "tools" }) }; } //#endregion export { resolvePluginTrust as n, matchesInstalledPluginRecord as t };