openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 5.22 kB
JavaScript
import{c as getPluginCacheRoot,l as getPluginCacheSource}from"./plugin-cache-B6QVpzXr.mjs";import{s as resolveBundledPluginsDir,t as areBundledPluginsDisabled}from"./bundled-dir-CMJ7m2eP.mjs";import{i as getPluginRegistryForContext}from"./gateway-request-scope-7deHmsb_.mjs";import{a as isPluginSourceModulePath,u as tryNativeRequireModule}from"./native-module-require-B6MgIIpV.mjs";import{i as getPluginInstance}from"./plugin-instance-scope-Bx-frH07.mjs";import{s as resolveLoaderPackageRoot}from"./sdk-alias-6-h-uxTt.mjs";import{a as loadFacadeModuleAtLocationSync,c as resolveBundledMetadataManifestRecord,i as loadBundledPluginPublicSurfaceModuleSyncCore,o as resolveBundledPublicSurfaceLocation,s as createFacadeResolutionKey,u as resolveRuntimeFacadeModuleLocation}from"./facade-loader-BQF_V8Ba.mjs";import{fileURLToPath}from"node:url";import path from"node:path";
//!src/plugin-sdk/facade-runtime.ts
const OPENCLAW_PACKAGE_ROOT=resolveLoaderPackageRoot({modulePath:fileURLToPath(import.meta.url),moduleUrl:import.meta.url})??fileURLToPath(new URL(`../..`,import.meta.url));const CURRENT_MODULE_PATH=fileURLToPath(import.meta.url);const OPENCLAW_SOURCE_EXTENSIONS_ROOT=path.resolve(OPENCLAW_PACKAGE_ROOT,`extensions`);function resolveFacadeModuleLocationUncached(e){const t=e.env??process.env;if(!areBundledPluginsDisabled(t)){const t=resolveBundledPublicSurfaceLocation(e);if(t)return t}return loadFacadeActivationCheckRuntime().resolveRegistryPluginModuleLocation(e)}function resolveFacadeModuleLocation(e){const t=resolveRuntimeFacadeModuleLocation(e);if(t!==void 0)return t;if(e.env!==void 0&&e.env!==process.env)return resolveFacadeModuleLocationUncached(e);const n=`facade-registry:${createFacadeResolutionKey({...e,bundledPluginsDir:resolveBundledPluginsDir(e.env??process.env)})}`;const r=getPluginCacheRoot(OPENCLAW_PACKAGE_ROOT).artifacts;const i=r.get(n);if(i!==void 0)return i;const a=resolveFacadeModuleLocationUncached(e);r.set(n,a);return a}function getFacadeActivationCheckRuntimeModule(){return getPluginCacheSource(CURRENT_MODULE_PATH).variants.get(`activation-runtime`)?.exports?.value}function setFacadeActivationCheckRuntimeModule(e){getPluginCacheSource(CURRENT_MODULE_PATH).variants.set(`activation-runtime`,{exports:{value:e}})}function throwFacadeActivationCheckRuntimeUnavailable(e){throw new Error(`Unable to load facade activation check runtime`,{cause:e})}function loadFacadeActivationCheckRuntime(){const e=getFacadeActivationCheckRuntimeModule();if(e)return e;try{const e=fileURLToPath(new URL(isPluginSourceModulePath(CURRENT_MODULE_PATH)?`./facade-activation-check.runtime.ts`:`./facade-activation-check.runtime.js`,import.meta.url));const t=tryNativeRequireModule(e);if(!t.ok)throw new Error(`Host facade activation runtime requires native loading: ${e}`);const n=t.moduleExport;setFacadeActivationCheckRuntimeModule(n);return n}catch(e){return throwFacadeActivationCheckRuntimeUnavailable(e)}}async function loadFacadeActivationCheckRuntimeAsync(){const e=getFacadeActivationCheckRuntimeModule()??await import(`./facade-activation-check.runtime.js`);setFacadeActivationCheckRuntimeModule(e);return e}function buildFacadeActivationCheckParams(e,t=resolveFacadeModuleLocation(e)){return{...e,location:t,sourceExtensionsRoot:OPENCLAW_SOURCE_EXTENSIONS_ROOT}}function hasBundledPluginPublicSurface(e){return resolveFacadeModuleLocation(e)!==null}function loadBundledPluginPublicSurfaceModuleSync(e){const t=resolveFacadeModuleLocation(e);const n=buildFacadeActivationCheckParams(e,t);const trackedPluginId=()=>resolveBundledMetadataManifestRecord(n)?.id??loadFacadeActivationCheckRuntime().resolveTrackedFacadePluginId(n);if(!t)return loadBundledPluginPublicSurfaceModuleSyncCore({...e,trackedPluginId});return loadFacadeModuleAtLocationSync({location:t,trackedPluginId})}function wrapActivatedSurface(e,t){const n=getPluginRegistryForContext()?.plugins.find(t=>t.id===e);return n?getPluginInstance(n)?.wrap(t)??t:t}function loadActivatedBundledPluginPublicSurfaceModuleSync(e){return wrapActivatedSurface(loadFacadeActivationCheckRuntime().resolveActivatedBundledPluginPublicSurfaceAccessOrThrow(buildFacadeActivationCheckParams(e)).pluginId,loadBundledPluginPublicSurfaceModuleSync(e))}async function loadActivatedBundledPluginPublicSurfaceModule(e){await loadFacadeActivationCheckRuntimeAsync().catch(throwFacadeActivationCheckRuntimeUnavailable);return loadActivatedBundledPluginPublicSurfaceModuleSync(e)}function tryLoadActivatedBundledPluginPublicSurfaceModuleSync(e){const t=loadFacadeActivationCheckRuntime().resolveBundledPluginPublicSurfaceAccess(buildFacadeActivationCheckParams(e));if(!t.allowed)return null;return wrapActivatedSurface(t.pluginId,loadBundledPluginPublicSurfaceModuleSync(e))}async function tryLoadActivatedBundledPluginPublicSurfaceModule(e){await loadFacadeActivationCheckRuntimeAsync();return tryLoadActivatedBundledPluginPublicSurfaceModuleSync(e)}export{tryLoadActivatedBundledPluginPublicSurfaceModule as a,loadBundledPluginPublicSurfaceModuleSync as i,loadActivatedBundledPluginPublicSurfaceModule as n,tryLoadActivatedBundledPluginPublicSurfaceModuleSync as o,loadActivatedBundledPluginPublicSurfaceModuleSync as r,hasBundledPluginPublicSurface as t};