UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.68 kB
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import"./utils-Dlk0IYAa.mjs";import{a as pluginCacheRealpathSync,f as isPathInside}from"./plugin-cache-files-BGuripl0.mjs";import{c as redactSensitiveText}from"./redact-BT59pdZ_.mjs";import{F as resolvePluginCandidateInstallOwner,M as isPluginCandidateInstallOwnerAmbiguous}from"./discovery-Bo4UPPd9.mjs";import{i as isTrustedOfficialPluginInstallRecord,n as isThirdPartyNpmInstallRecord}from"./official-external-install-records-CVYKmVDj.mjs"; //!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`})}}export{resolvePluginTrust as n,matchesInstalledPluginRecord as t};