UNPKG

eve

Version:

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

1 lines 1.65 kB
import{object,string}from"../../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/schemas.js";import"../../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/index.js";const DiscordApplicationSchema=object({id:string(),name:string(),verify_key:string()});async function discordRequest(e,t,n,r){return r(`https://discord.com/api/v10${t}`,{...n,headers:{authorization:`Bot ${e}`,"content-type":`application/json`,...n.headers}})}async function resolveDiscordApplication(e,t=fetch){let n=await discordRequest(e,`/oauth2/applications/@me`,{method:`GET`},t);if(!n.ok)throw Error(`Discord rejected the bot token (HTTP ${n.status}).`);let r=DiscordApplicationSchema.safeParse(await n.json());if(!r.success)throw Error(`Discord returned incomplete application details.`);return{id:r.data.id,name:r.data.name,publicKey:r.data.verify_key}}async function registerDiscordCommand(e,t,n,r=fetch){let i=await discordRequest(t,`/applications/${encodeURIComponent(e)}/commands`,{method:`POST`,body:JSON.stringify({name:n.name,description:n.description,type:1,options:[{name:`message`,description:`What should the agent do?`,type:3,required:!0}]})},r);if(!i.ok)throw Error(`Discord command registration failed (HTTP ${i.status}).`)}async function configureDiscordInteractionsEndpoint(e,t,n=fetch){let r=await discordRequest(e,`/applications/@me`,{method:`PATCH`,body:JSON.stringify({interactions_endpoint_url:`https://connect.vercel.com/trigger/${encodeURIComponent(t)}`})},n);if(!r.ok)throw Error(`Discord rejected the interactions endpoint (HTTP ${r.status}).`)}export{configureDiscordInteractionsEndpoint,registerDiscordCommand,resolveDiscordApplication};