eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.11 kB
JavaScript
import{createLogger}from"#internal/logging.js";import{toChannelLocalContinuationToken}from"#shared/continuation-token.js";const log=createLogger(`channel.adapter`);function defaultDeliverResult(e){if(e.message!==void 0)return{inputResponses:e.inputResponses,message:e.message,context:e.context,outputSchema:e.outputSchema};if(e.inputResponses!==void 0&&e.inputResponses.length>0)return{inputResponses:e.inputResponses,context:e.context,outputSchema:e.outputSchema};if(e.context!==void 0&&e.context.length>0)return{context:e.context,outputSchema:e.outputSchema};if(e.outputSchema!==void 0)return{outputSchema:e.outputSchema}}function getAdapterKind(e){return e.kind}async function callAdapterEventHandler(e,n,r){let i=e[n.type];if(i!==void 0)try{await i(`data`in n?n.data:void 0,r)}catch(t){log.error(`adapter event handler threw — event swallowed`,{adapterKind:getAdapterKind(e),eventType:n.type,error:t})}return n.type===`session.waiting`?{...n,data:{...n.data,continuationToken:toChannelLocalContinuationToken(r.session.continuationToken)}}:n}export{callAdapterEventHandler,defaultDeliverResult,getAdapterKind};