openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.23 kB
JavaScript
import{c as getPluginCacheRoot,l as getPluginCacheSource}from"./plugin-cache-B6QVpzXr.mjs";import{n as describeRootFileOpenFailure}from"./boundary-file-read-bB9An35K.mjs";import{p as openPluginRootFileSync}from"./plugin-cache-files-BGuripl0.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{i as isJavaScriptModulePath,t as PLUGIN_SOURCE_MODULE_EXTENSIONS}from"./native-module-require-B6MgIIpV.mjs";import{t as getCachedPluginModuleLoader}from"./plugin-module-loader-cache-Bj5H0vwC.mjs";import{createRequire}from"node:module";import fs from"node:fs";import path from"node:path";
//!src/channels/plugins/module-loader.ts
const nodeRequire=createRequire(import.meta.url);function loadModule(e){const t=path.extname(e).toLowerCase();if(!isJavaScriptModulePath(e)&&!PLUGIN_SOURCE_MODULE_EXTENSIONS.includes(t))throw new Error(`channel plugin module must be built JavaScript: ${e}`);return getCachedPluginModuleLoader({modulePath:e,importerUrl:import.meta.url,loaderFilename:import.meta.url,cacheScopeKey:`channel-plugin-module-loader`})(e)}function resolveExistingPluginModulePath(e,t){const n=getPluginCacheRoot(e).artifacts;const r=`channel-specifier:${t}`;const i=n.get(r);if(i)return i.modulePath;const a=resolvePluginModulePath(e,t);n.set(r,{modulePath:a,boundaryRoot:e});return a}function resolvePluginModulePath(e,t){const n=path.resolve(e,t.replace(/\\/g,`/`));try{return nodeRequire.resolve(n)}catch(e){if(!hasErrnoCode(e,`MODULE_NOT_FOUND`))throw e}if(!path.extname(n))for(const e of PLUGIN_SOURCE_MODULE_EXTENSIONS){const t=`${n}${e}`;if(fs.existsSync(t))return t}return n}function loadChannelPluginModule(e){const t=getPluginCacheSource(e.modulePath);const n=`channel-plugin-module:${path.resolve(e.rootDir)}`;const r=t.variants.get(n)?.exports;if(r)return r.value;const i=`plugin root`;const a=openPluginRootFileSync({filePath:e.modulePath,rootPath:e.rootDir,rejectHardlinks:false});if(!a.ok)throw new Error(describeRootFileOpenFailure({failure:a,subject:`plugin module path`,boundaryLabel:i,filePath:e.modulePath}),{cause:a.error});const o=a.path;fs.closeSync(a.fd);const s=loadModule(o);t.variants.set(n,{exports:{value:s}});return s}export{resolveExistingPluginModulePath as n,loadChannelPluginModule as t};