UNPKG

eve

Version:

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

5 lines • 2.82 kB
import{resolvePackageDependencyPath,resolvePackageSourceFilePath}from"#internal/application/package.js";import{stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{computeApplicationChannelRouteRegistrations}from"#internal/nitro/host/application-route-registry.js";const EVE_CHANNEL_VIRTUAL_ID_PREFIX=`#nitro/virtual/eve-channel/`;function computeChannelRouteRegistrations(e){return computeApplicationChannelRouteRegistrations(e)}function registerChannelVirtualHandlers(e,t){for(let n of t.routes)addChannelVirtualHandler(e,{artifactsConfig:t.artifactsConfig,route:n})}function createChannelRouteKey(e){return`${e.method.toUpperCase()} ${e.path}`}function addChannelVirtualHandler(e,t){if(t.route.kind===`channel-preflight`){addChannelCorsPreflightHandler(e,t.route);return}let n=createChannelRouteKey(t.route),r=`${EVE_CHANNEL_VIRTUAL_ID_PREFIX}${n}`,i=stringifyEsmImportSpecifier(resolvePackageSourceFilePath(`src/internal/nitro/routes/channel-dispatch.ts`)),a=stringifyEsmImportSpecifier(resolvePackageDependencyPath(`nitro`)),o=stringifyEsmImportSpecifier(resolvePackageDependencyPath(`nitro/h3`));if(t.route.method===`WEBSOCKET`){e.options.handlers.push({handler:r,route:t.route.path}),e.options.virtual[r]=[`import { defineWebSocketHandler } from ${a};`,`import { dispatchChannelWebSocketRequest } from ${i};`,`const config = ${JSON.stringify(t.artifactsConfig)};`,`export default defineWebSocketHandler((event) => dispatchChannelWebSocketRequest(event, ${JSON.stringify(n)}, config));`].join(` `);return}e.options.handlers.push({handler:r,method:t.route.method,route:t.route.path}),e.options.virtual[r]=[...t.route.cors===void 0?[]:[`import { handleCors } from ${o};`,`const cors = ${JSON.stringify(t.route.cors)};`],`import { dispatchChannelRequest } from ${i};`,`const config = ${JSON.stringify(t.artifactsConfig)};`,t.route.cors===void 0?`export default (event) => dispatchChannelRequest(event, ${JSON.stringify(n)}, config);`:[`export default (event) => {`,` const corsResponse = handleCors(event, cors);`,` if (corsResponse !== false) return corsResponse;`,` return dispatchChannelRequest(event, ${JSON.stringify(n)}, config);`,`};`].join(` `)].join(` `)}function addChannelCorsPreflightHandler(e,t){let n=createChannelRouteKey(t),r=`${EVE_CHANNEL_VIRTUAL_ID_PREFIX}${n}`,i=stringifyEsmImportSpecifier(resolvePackageDependencyPath(`nitro/h3`));e.options.handlers.push({handler:r,method:`OPTIONS`,route:t.path}),e.options.virtual[r]=[`import { handleCors } from ${i};`,`const cors = ${JSON.stringify(t.cors)};`,`export default (event) => {`,` const corsResponse = handleCors(event, cors);`,` if (corsResponse !== false) return corsResponse;`,` return new Response(null, { status: 204 });`,`};`].join(` `)}export{computeChannelRouteRegistrations,registerChannelVirtualHandlers};