UNPKG

eve

Version:

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

1 lines 1.88 kB
import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{join}from"node:path";import{compileChannelDefinition}from"#compiler/normalize-channel.js";import{createCompiledBindingNamespaceLoader}from"#compiler/load-binding-namespace.js";import{discoverAgent}from"#discover/discover-agent.js";const SCAFFOLDED_WEB_CHANNEL_LOGICAL_PATH=`channels/eve.ts`;async function inspectExistingChannelRegistrations(e){let t=join(e,`agent`),{manifest:n}=await discoverAgent({agentRoot:t,appRoot:e}),r=new Set,i=new Set;for(let e of n.channels){let n={backing:{externalDependencies:[],kind:`filesystem`,sourcePath:join(t,e.logicalPath)},logicalPath:e.logicalPath,owner:{kind:`application`}},a=await compileChannelDefinition(t,e,{binding:n,loadNamespace:createCompiledBindingNamespaceLoader({bindings:{[e.sourceId]:n},registries:[]})});if(a.kind===`channel`)for(let t of a.definitions)t.kind===`channel`&&(t.method===`POST`&&t.urlPath===EVE_SESSION_ROUTE_PATH&&r.add(e.logicalPath),t.adapterKind===`slack`&&i.add(e.logicalPath))}let a={};return[...r].some(e=>e!==SCAFFOLDED_WEB_CHANNEL_LOGICAL_PATH)&&(a.web=`POST ${EVE_SESSION_ROUTE_PATH} already registered`),i.size>0&&(a.slack=`Slack channel already registered`),{disabledChannelReasons:a,webRouteOwners:[...r],slackOwners:[...i]}}function assertCanAddSelectedChannels(e,t){if(e.includes(`web`)){let e=t.webRouteOwners.find(e=>e!==SCAFFOLDED_WEB_CHANNEL_LOGICAL_PATH);if(e!==void 0)throw Error(`Cannot scaffold Web Chat because agent/${e} already defines POST ${EVE_SESSION_ROUTE_PATH}. Web Chat scaffolds the same eve session routes.`)}if(e.includes(`slack`)){let e=t.slackOwners.find(e=>e!==`channels/slack.ts`);if(e!==void 0)throw Error(`Cannot scaffold Slack because agent/${e} already defines a Slack channel. Slack scaffolding would register the channel again.`)}}export{assertCanAddSelectedChannels,inspectExistingChannelRegistrations};