eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
3 lines • 1.27 kB
JavaScript
import{extractErrorId,formatErrorHint}from"#internal/logging.js";function defaultTwilioAuth(e){let t={channel:e.channel,from:e.from};return e.to!==void 0&&(t.to=e.to),{attributes:t,authenticator:`twilio-webhook`,issuer:`twilio`,principalId:`twilio:${e.from}`,principalType:`user`}}function defaultOnText(e,t){return{auth:defaultTwilioAuth({channel:`text`,from:t.from,to:t.to})}}function defaultOnVoice(e,t){return{}}function defaultOnVoiceTranscription(e,t){return{auth:defaultTwilioAuth({channel:`voice`,from:t.from,to:t.to})}}const defaultEvents={async"message.completed"(e,t,n){e.finishReason===`tool-calls`||!e.message||await t.twilio.sendMessage(e.message)},async"turn.failed"(n,r,i){let a=formatErrorHint(n),o=extractErrorId(n.details);await r.twilio.sendMessage([`I hit an error while handling your request${a}.`,``,`Please try again, rephrase, or reach out if it keeps failing.`,...o?[``,`Error id: ${o}`]:[]].join(`
`))},async"session.failed"(n,r){let i=formatErrorHint(n),a=extractErrorId(n.details);await r.twilio.sendMessage([`This session could not recover from an error${i}.`,``,`Start a new message to continue.`,...a?[``,`Error id: ${a}`]:[]].join(`
`))}};export{defaultEvents,defaultOnText,defaultOnVoice,defaultOnVoiceTranscription,defaultTwilioAuth};