Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

2.7 KB
Raw Blame
import { Router } from 'express';
import swaggerUi from 'swagger-ui-express';

import config from '@core/config';

import { agentChatRouter } from '@embodiment/modules/agentChat/routes/router';
import { alexaRouter } from '@embodiment/modules/alexa/routes/router';
import { apiRouter } from '@embodiment/modules/API/routes/router';
import { chatRouter } from '@embodiment/modules/chat/routes/router';
import { chatBotRouter } from '@embodiment/modules/chatbot/routes/router';
import { chatGPTRouter } from '@embodiment/modules/chatGPT/routes/router';
import { formPreviewRouter } from '@embodiment/modules/formPreview/routes/router';
import { mcpRouter } from '@embodiment/modules/mcp/routes/router';
import { openaiRouter } from '@embodiment/modules/openai/routes/router';
import { postmanRouter } from '@embodiment/modules/postman/routes/router';
import { swaggerRouter } from '@embodiment/modules/swagger/routes/router';
import { voiceRouter } from '@embodiment/modules/voice/routes/router';

const mainRouter = Router();

type Route = {
  rootPath: string | (string | RegExp)[] | RegExp;
  route: Router;
  requireAuth?: boolean;
};

const defaultRoutes: Route[] = [
  {
    rootPath: ['/_openai', '/emb/openai'],
    route: openaiRouter,
  },

  {
    rootPath: ['/postman', '/emb/postman'],
    route: postmanRouter,
  },

  // #region Swagger, we need both routers
  {
    rootPath: ['/swagger', '/emb/swagger'],
    route: swaggerUi.serve,
  },
  {
    rootPath: ['/swagger', '/emb/swagger'],
    route: swaggerRouter,
  },
  // #endregion

  {
    rootPath: ['/', '/emb/api'],
    route: apiRouter,
  },
  {
    rootPath: ['/', '/emb/chatgpt'],
    route: chatGPTRouter,
  },
  {
    rootPath: ['/chatbot', 'chatBot', '/emb/chatbot'],
    route: chatBotRouter,
  },
  {
    rootPath: ['/v1/emb/chat'],
    route: chatRouter,
  },
  {
    rootPath: ['/aichat', '/emb/aichat'],
    route: agentChatRouter,
  },
  {
    rootPath: ['/alexa', '/emb/alexa'],
    route: alexaRouter,
  },
  {
    rootPath: ['/mcp', '/emb/mcp'],
    route: mcpRouter,
  },
  {
    rootPath: ['/form-preview', '/emb/form-preview'],
    route: formPreviewRouter,
  },
  {
    rootPath: ['/voice', '/emb/voice'],
    route: voiceRouter,
  },
];

const devRoutes: Route[] = [];

defaultRoutes.forEach(route => {
  if (Array.isArray(route.rootPath)) {
    route.rootPath.forEach(path => {
      mainRouter.use(path, route.route);
    });
  } else {
    mainRouter.use(route.rootPath, route.route);
  }
});

if (config.env.NODE_ENV === 'development') {
  devRoutes.forEach(route => {
    if (Array.isArray(route.rootPath)) {
      route.rootPath.forEach(path => {
        mainRouter.use(path, route.route);
      });
    } else {
      mainRouter.use(route.rootPath, route.route);
    }
  });
}

export { mainRouter as routes };