UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

9 lines • 3.4 kB
import{l as resolveGlobalSingleton}from"./string-coerce-BBqv4GXj.mjs";import{AsyncLocalStorage,AsyncResource}from"node:async_hooks"; //!src/shared/detached-async-context.ts const asyncHooks=typeof process===`undefined`?void 0:process.getBuiltinModule?.(`node:async_hooks`);const detachedAsyncContext=asyncHooks?resolveGlobalSingleton(Symbol.for(`openclaw.detachedAsyncContext`),()=>new asyncHooks.AsyncResource(`openclaw.detached-async-context`)):void 0;function runInDetachedAsyncContext(e){return detachedAsyncContext?detachedAsyncContext.runInAsyncScope(e):e()} //!src/shared/async-store.ts function enterAsyncStore(e,t){this.enterWith(e);return t()}function runWithAsyncStore(e,t,n){if(e.getStore()===t)return n();return new AsyncResource(`OpenClawAsyncStore`).runInAsyncScope(enterAsyncStore,e,t,n)} //!src/plugins/plugin-instance-error.ts const sourceAcquisitionFailures=resolveGlobalSingleton(Symbol.for(`openclaw.pluginSourceAcquisitionFailures`),()=>/* @__PURE__ */ new WeakSet);const sourcePreparationOperations=resolveGlobalSingleton(Symbol.for(`openclaw.pluginSourcePreparationOperations`),()=>/* @__PURE__ */ new WeakSet);const PluginInventoryRetiredError=resolveGlobalSingleton(Symbol.for(`openclaw.pluginInventoryRetiredError`),()=>class InventoryRetiredError extends Error{constructor(){super(`Plugin inventory has retired; begin a new plugin operation.`);this.name=`PluginInventoryRetiredError`}});const PluginSourceRecoveryUnavailableError=resolveGlobalSingleton(Symbol.for(`openclaw.pluginSourceRecoveryUnavailableError`),()=>class SourceRecoveryUnavailableError extends Error{constructor(e){super(`Captured plugin source is missing; its previous code cannot be recovered.`,{cause:e});this.name=`PluginSourceRecoveryUnavailableError`}});const PluginInstanceDrainTimeoutError=resolveGlobalSingleton(Symbol.for(`openclaw.pluginInstanceDrainTimeoutError`),()=>class DrainTimeoutError extends Error{constructor(e,t,n,r){super(e,n);this.settled=t;this.forcedRetirement=r;this.name=`PluginInstanceDrainTimeoutError`}}); //!src/plugins/plugin-instance-invocation.ts var InvocationFrame=class InvocationFrame{constructor(e,t=e.invocation){this.retentionOwner=e.retentionOwner;this.invocation=t;this.metadataScope=e.metadataScope;this.cacheScope=e.cacheScope;this.sourceCaptureStorage=e.sourceCaptureStorage}get runtimePluginId(){}get canUseInteractiveStateReadCapacity(){return false}withScopes(e){return new InvocationFrame(e)}};function createPluginExecutionFrame(e,t){return t?t.withScopes(e):new InvocationFrame(e)}const pluginExecutionContext=resolveGlobalSingleton(Symbol.for(`openclaw.pluginInstanceInvocation`),()=>{const e=new AsyncLocalStorage;return{invocation:{getStore(){return e.getStore()?.invocation},run(t,n){const r=e.getStore();return r?.invocation===t?n():runWithAsyncStore(e,createPluginExecutionFrame({...r,invocation:t},r),n)},exit(t){const n=e.getStore();return n?.invocation?runWithAsyncStore(e,n.withScopes({...n,invocation:void 0}),t):t()}},getFrame(){return e.getStore()},runFrame(t,n){return runWithAsyncStore(e,t,n)}}});const pluginInstanceInvocation=pluginExecutionContext.invocation;const getPluginExecutionFrame=pluginExecutionContext.getFrame;const runWithPluginExecutionFrame=pluginExecutionContext.runFrame;export{runInDetachedAsyncContext as a,runWithAsyncStore as i,getPluginExecutionFrame as n,PluginInstanceDrainTimeoutError as r,InvocationFrame as t};