openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 1.16 kB
JavaScript
//!src/infra/channel-runtime-context.ts
const NOOP_DISPOSE=()=>{};function registerChannelRuntimeContext(e){return e.channelRuntime?.runtimeContexts?.register({channelId:e.channelId,accountId:e.accountId,capability:e.capability,context:e.context,abortSignal:e.abortSignal})??null}function getChannelRuntimeContext(e){return e.channelRuntime?.runtimeContexts?.get({channelId:e.channelId,accountId:e.accountId,capability:e.capability})}function watchChannelRuntimeContexts(e){return e.channelRuntime?.runtimeContexts?.watch({channelId:e.channelId,accountId:e.accountId,capability:e.capability,onEvent:e.onEvent})??null}function createTaskScopedChannelRuntime(e){const t=e.channelRuntime;if(!t)return{channelRuntime:void 0,dispose:NOOP_DISPOSE};const n=t.runtimeContexts;const r=/* @__PURE__ */ new Set;return{channelRuntime:{...t,runtimeContexts:{...n,register:e=>{const t=n.register(e);const i={dispose:()=>{if(r.delete(i))t.dispose()}};r.add(i);return i}}},dispose:()=>{for(const e of Array.from(r))e.dispose()}}}export{watchChannelRuntimeContexts as i,getChannelRuntimeContext as n,registerChannelRuntimeContext as r,createTaskScopedChannelRuntime as t};