openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.6 kB
JavaScript
import{c as getPluginCacheRoot}from"./plugin-cache-B6QVpzXr.mjs";import{a as pluginCacheRealpathSync,r as pluginCacheExistsSync,s as readPluginCacheDirectory}from"./plugin-cache-files-BGuripl0.mjs";import{h as resolvePreferredBundledRootArtifact,m as resolvePluginRuntimeExecutionArtifact}from"./bundled-dir-CMJ7m2eP.mjs";import{i as isMissingPathError}from"./errno-DUBt6SQQ.mjs";import{fileURLToPath}from"node:url";import path from"node:path";
//!src/plugins/root-artifact-path.ts
function resolvePluginRootArtifactPath(e,t){let n;let r=false;for(const i of t){const t=path.join(e,i);if(path.dirname(i)!==`.`){const e=path.dirname(t);if(e!==n){try{r=readPluginCacheDirectory(e).length===0}catch(e){r=isMissingPathError(e)}n=e}if(r)continue}if(pluginCacheExistsSync(t))return t}return null}
//!src/plugins/doctor-contract-artifact.ts
const CONTRACT_API_EXTENSIONS=[`.js`,`.mjs`,`.cjs`,`.ts`,`.mts`,`.cts`];const CURRENT_MODULE_PATH=fileURLToPath(import.meta.url);const RUNNING_FROM_BUILT_ARTIFACT=CURRENT_MODULE_PATH.includes(`${path.sep}dist${path.sep}`)||CURRENT_MODULE_PATH.includes(`${path.sep}dist-runtime${path.sep}`);const ORDERED_EXTENSIONS=RUNNING_FROM_BUILT_ARTIFACT?CONTRACT_API_EXTENSIONS:[...CONTRACT_API_EXTENSIONS.slice(3),...CONTRACT_API_EXTENSIONS.slice(0,3)];const ARTIFACT_CANDIDATES=[`doctor-contract-api`,`contract-api`].map(e=>{const t=ORDERED_EXTENSIONS.map(t=>`${e}${t}`);return{rootPaths:t,paths:t.flatMap(e=>[e,path.join(`dist`,e)])}});function resolvePluginDoctorContractArtifact(e){const t=getPluginCacheRoot(e.rootDir).artifacts;const n=JSON.stringify([`doctor-contract`,RUNNING_FROM_BUILT_ARTIFACT,e.origin,e.sourcePreferred===true,e.packageManifest?.build?.bundledDist]);const r=t.get(n);if(r!==void 0)return r;for(const{rootPaths:r,paths:i}of ARTIFACT_CANDIDATES){const a=resolvePluginRootArtifactPath(e.rootDir,i);if(!a)continue;let o={modulePath:a,boundaryRoot:e.rootDir};if(RUNNING_FROM_BUILT_ARTIFACT&&e.origin===`bundled`&&!e.sourcePreferred){const t=e.packageManifest?.build?.bundledDist===false?resolvePluginRootArtifactPath(e.rootDir,r):r.includes(path.relative(e.rootDir,a))?a:null;if(t){const n=resolvePluginRuntimeExecutionArtifact(resolvePreferredBundledRootArtifact({rootDir:e.rootDir,source:t,packageManifest:e.packageManifest}));o={modulePath:n.source,boundaryRoot:n.rootDir}}}const s={modulePath:pluginCacheRealpathSync(o.modulePath)??o.modulePath,boundaryRoot:pluginCacheRealpathSync(o.boundaryRoot)??o.boundaryRoot};t.set(n,s);return s}t.set(n,null);return null}export{resolvePluginRootArtifactPath as n,resolvePluginDoctorContractArtifact as t};