UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines • 985 B
import{ContinuationTokenKey}from"./keys.js";import{getAdapterKind}from"#channel/adapter.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{BundleKey,ChannelKey}from"#runtime/sessions/runtime-context-keys.js";import{BoundaryHookError}from"#shared/boundary-hook-error.js";async function dispatchStreamEventHooks(e){let t=e.registry.streamEventsByType.get(e.event.type)??[],n=e.registry.streamEventsWildcard;if(t.length===0&&n.length===0)return;let r=buildHookContext(e.ctx);try{for(let n of t)await n.handler(e.event,r);for(let t of n)await t.handler(e.event,r)}catch(t){throw e.event.type===`turn.started`||e.event.type===`step.started`?new BoundaryHookError(t):t}}function buildHookContext(e){let t=e.require(BundleKey),n=e.get(ChannelKey),r=e.get(ContinuationTokenKey),i=n===void 0?void 0:getAdapterKind(n);return{...buildCallbackContext(),agent:{name:t.turnAgent.id,nodeId:t.nodeId},channel:{kind:i,continuationToken:r}}}export{dispatchStreamEventHooks};