eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.99 kB
JavaScript
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";import{isNextJsProject}from"#setup/scaffold/index.js";const SCAFFOLDED_WEB_CHANNEL_LOGICAL_PATH=`channels/eve.ts`;async function inspectExistingChannelRegistrations(e){let t=join(e,`agent`),[{manifest:n},r]=await Promise.all([discoverAgent({agentRoot:t,appRoot:e}),isNextJsProject(e)]),i=new Set,a=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`}},r=await compileChannelDefinition(t,e,{binding:n,loadNamespace:createCompiledBindingNamespaceLoader({bindings:{[e.sourceId]:n},registries:[]})});if(r.kind===`channel`)for(let t of r.definitions)t.kind===`channel`&&(t.method===`POST`&&t.urlPath===EVE_SESSION_ROUTE_PATH&&i.add(e.logicalPath),t.adapterKind===`slack`&&a.add(e.logicalPath))}let o={};return[...i].some(e=>e!==SCAFFOLDED_WEB_CHANNEL_LOGICAL_PATH)&&(o.web=`POST ${EVE_SESSION_ROUTE_PATH} already registered`),a.size>0&&(o.slack=`Slack channel already registered`),{disabledChannelReasons:o,webRouteOwners:[...i],slackOwners:[...a],webAppPresent:r}}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};