UNPKG

eve

Version:

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

3 lines • 1.82 kB
import{extractErrorId,formatErrorHint}from"#internal/logging.js";import{splitDiscordMessageContent}from"#public/channels/discord/api.js";import{renderInputRequestComponents}from"#public/channels/discord/hitl.js";function defaultDiscordAuth(e){let t={channel_id:e.channelId,interaction_id:e.id,user_id:e.user.id,username:e.user.username};return e.guildId!==void 0&&(t.guild_id=e.guildId),e.member?.nick!==void 0&&(t.member_nick=e.member.nick),{attributes:t,authenticator:`discord-interaction`,issuer:e.guildId?`discord:${e.guildId}`:`discord`,principalId:e.guildId?`discord:${e.guildId}:${e.user.id}`:`discord:${e.user.id}`,principalType:e.user.isBot?`service`:`user`}}function defaultOnCommand(e,t){return{auth:defaultDiscordAuth(t)}}const defaultEvents={async"turn.started"(e,t,n){await t.discord.startTyping()},async"authorization.completed"(e,t,n){e.outcome===`authorized`&&await t.discord.startTyping()},async"actions.requested"(e,t,n){await t.discord.startTyping()},async"input.requested"(e,t,n){for(let n of e.requests){let e=splitDiscordMessageContent(n.prompt)[0]??n.prompt;await t.discord.post({components:renderInputRequestComponents(n),content:e})}},async"message.completed"(e,t,n){e.finishReason!==`tool-calls`&&e.message&&await t.discord.post(e.message)},async"session.failed"(e,t){let n=formatErrorHint(e),r=extractErrorId(e.details);await t.discord.post([`This session could not recover from an error${n}.`,``,`Start a new command to continue.`,...r?[``,`Error id: ${r}`]:[]].join(` `))},async"turn.failed"(e,t,n){let r=formatErrorHint(e),i=extractErrorId(e.details);await t.discord.post([`I hit an error while handling your request${r}.`,``,`Please try again, rephrase, or reach out if it keeps failing.`,...i?[``,`Error id: ${i}`]:[]].join(` `))}};export{defaultDiscordAuth,defaultEvents,defaultOnCommand};