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