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.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
make hardcoded port consistent and adjust env variable names
Forhad Hosaina098d624685f
diff --git a/packages/runtime/.env.example b/packages/runtime/.env.exampleindex 65fcdd18..79bb4ec2 100644--- a/packages/runtime/.env.example+++ b/packages/runtime/.env.example@@ -11,7 +11,7 @@ LOGTO_M2M_APP_ID=your_logto_m2m_app_idLOGTO_M2M_APP_SECRET=your_logto_m2m_app_secretLOGTO_SERVER=https://your-logto-server.comLOGTO_API_RESOURCE=https://api.smythos.com-SMYTH_API_BASE_URL=https://api.smythos.com+MIDDLEWARE_API_BASE_URL=https://api.smythos.com# AWS Lambda Configuration (for code execution)AWS_LAMBDA_REGION=us-east-1@@ -20,7 +20,7 @@ AWS_LAMBDA_SECRET_ACCESS_KEY=your_lambda_secret_key# Agent ConfigurationAGENT_DOMAIN=your-agent-domain.com-AGENT_DOMAIN_PORT=3000+AGENT_DOMAIN_PORT=5053PROD_AGENT_DOMAIN=your-prod-agent-domain.comdiff --git a/packages/runtime/src/core/config.ts b/packages/runtime/src/core/config.tsindex 6bf4a51e..526757af 100644--- a/packages/runtime/src/core/config.ts+++ b/packages/runtime/src/core/config.ts@@ -3,17 +3,19 @@ dotenv.config();const config = {env: {- ADMIN_PORT: process.env.ADMIN_PORT || 8080,-- BASE_URL: process.env.BASE_URL,- SMYTH_API_BASE_URL: process.env.SMYTH_API_SERVER,-+ // Required environment variables+ LOGTO_M2M_APP_SECRET: process.env.LOGTO_M2M_APP_SECRET,LOGTO_SERVER: process.env.LOGTO_SERVER,LOGTO_API_RESOURCE: process.env.LOGTO_API_RESOURCE,- LOGTO_M2M_APP_ID: process.env.LOGTO_M2M_APP_ID,- LOGTO_M2M_APP_SECRET: process.env.LOGTO_M2M_APP_SECRET,+ MIDDLEWARE_API_BASE_URL: process.env.MIDDLEWARE_API_BASE_URL,+ NODE_ENV: process.env?.NODE_ENV || "development",++ ADMIN_PORT: process.env.ADMIN_PORT || 5054,+ PORT: parseInt(process.env.PORT || "5053"),- NODE_ENV: process.env?.NODE_ENV,+ BASE_URL: process.env.BASE_URL || "http://localhost:5053",++ LOGTO_M2M_APP_ID: process.env.LOGTO_M2M_APP_ID,AGENT_DOMAIN: process.env?.AGENT_DOMAIN,PROD_AGENT_DOMAIN: process.env?.PROD_AGENT_DOMAIN,@@ -21,7 +23,7 @@ const config = {REQ_LIMIT_PER_MINUTE: process.env.REQ_LIMIT_PER_MINUTE || 300,- UI_SERVER: process.env.UI_SERVER,+ UI_SERVER: process.env.UI_SERVER || "http://localhost:4000",SESSION_SECRET: process.env.SESSION_SECRET,DATA_PATH: process.env.DATA_PATH,diff --git a/packages/runtime/src/core/helpers/agent.helper.ts b/packages/runtime/src/core/helpers/agent.helper.tsindex 14b462ba..8bbde22a 100644--- a/packages/runtime/src/core/helpers/agent.helper.ts+++ b/packages/runtime/src/core/helpers/agent.helper.ts@@ -107,7 +107,7 @@ export async function getAgentEmbodiments(agentID) {try {const token = (await getM2MToken("https://api.smyth.ai")) as string;const response = await axios.get(- `${config.env.SMYTH_API_BASE_URL}/_sysapi/v1/embodiments?aiAgentId=${agentID}`,+ `${config.env.MIDDLEWARE_API_BASE_URL}/_sysapi/v1/embodiments?aiAgentId=${agentID}`,{headers: {Authorization: `Bearer ${token}`,diff --git a/packages/runtime/src/core/management-router.ts b/packages/runtime/src/core/management-router.tsindex 5f8a100c..4fc27792 100644--- a/packages/runtime/src/core/management-router.ts+++ b/packages/runtime/src/core/management-router.ts@@ -3,8 +3,8 @@ import { app } from "../index.js";import { Server } from "http";import config from "./config";-const ADMIN_PORT = parseInt(process.env.ADMIN_PORT || "8080");-const PORT = parseInt(process.env.PORT || "3000");+const ADMIN_PORT = parseInt(process.env.ADMIN_PORT || "5054");+const PORT = parseInt(process.env.PORT || "5053");// eslint-disable-next-line import/no-mutable-exportsexport let server: Server;@@ -33,7 +33,7 @@ function disableAppPort() {});}-// Management app listening on port 8080+// Management app listening on port 5054const managementApp = express();export { managementApp };diff --git a/packages/runtime/src/core/router-config.ts b/packages/runtime/src/core/router-config.tsindex d31c35f0..60ca87e6 100644--- a/packages/runtime/src/core/router-config.ts+++ b/packages/runtime/src/core/router-config.ts@@ -2,8 +2,8 @@ import { Express } from "express";import { uploadHandler } from "@core/middlewares/uploadHandler.mw";-import agentRunnerOauthRouter from "@agent-runner/routes/_oauth/router";import agentRunnerAgentLoader from "@agent-runner/middlewares/agentLoader.mw";+import agentRunnerOauthRouter from "@agent-runner/routes/_oauth/router";import { processAgentRequest as agentRunnerProcessAgentRequest } from "@agent-runner/services/agent-request-handler";import debuggerAgentLoader from "@debugger/middlewares/agentLoader.mw";@@ -76,14 +76,13 @@ export function configureAgentRouters(const smartRouter = createConfiguredSmartRouter({debugger: {- agentLoader: debuggerAgentLoader,+ middlewares: [uploadHandler, debuggerAgentLoader],processAgentRequest: debuggerProcessAgentRequest,getDebugSession: debuggerGetDebugSession,createSseConnection: debuggerCreateSseConnection,},agentRunner: {- uploadHandler,- agentLoader: agentRunnerAgentLoader,+ middlewares: [uploadHandler, agentRunnerAgentLoader],processAgentRequest: agentRunnerProcessAgentRequest,},},@@ -170,7 +169,7 @@ export function createDebuggerServerConfig(): RuntimeConfig {},routing: { strategy: "separate" },server: {- port: parseInt(process.env.PORT || "5001"),+ port: parseInt(process.env.PORT || "5053"),name: "smythos-debugger-server",healthCheck: true,metrics: true,@@ -194,7 +193,7 @@ export function createAgentRunnerServerConfig(): RuntimeConfig {},routing: { strategy: "separate" },server: {- port: parseInt(process.env.PORT || "5002"),+ port: parseInt(process.env.PORT || "5053"),name: "smythos-agent-runner-server",healthCheck: true,metrics: true,@@ -218,7 +217,7 @@ export function createEmbodimentServerConfig(): RuntimeConfig {},routing: { strategy: "separate" },server: {- port: parseInt(process.env.PORT || "5003"),+ port: parseInt(process.env.PORT || "5053"),name: "smythos-embodiment-server",healthCheck: true,metrics: true,@@ -242,7 +241,7 @@ export function createCombinedServerConfig(): RuntimeConfig {},routing: { strategy: "smart" },server: {- port: parseInt(process.env.PORT || "5000"),+ port: parseInt(process.env.PORT || "5053"),name: "smythos-runtime-combined",healthCheck: true,metrics: true,diff --git a/packages/runtime/src/core/services/smythAPIReq.ts b/packages/runtime/src/core/services/smythAPIReq.tsindex aab3c47e..d7f55245 100644--- a/packages/runtime/src/core/services/smythAPIReq.ts+++ b/packages/runtime/src/core/services/smythAPIReq.ts@@ -1,20 +1,20 @@-import axios from 'axios';-import config from '../config';+import axios from "axios";+import config from "../config";//middleware sys APIexport const mwSysAPI = axios.create({- baseURL: `${config.env.SMYTH_API_BASE_URL}/_sysapi/v1`,+ baseURL: `${config.env.MIDDLEWARE_API_BASE_URL}/_sysapi/v1`,});export const mwUserAPI = axios.create({- baseURL: `${config.env.SMYTH_API_BASE_URL}/v1`,+ baseURL: `${config.env.MIDDLEWARE_API_BASE_URL}/v1`,});export function includeAuth(token: string) {- return {- headers: {- Authorization: `Bearer ${token}`,- },- };+ return {+ headers: {+ Authorization: `Bearer ${token}`,+ },+ };}/**@@ -22,20 +22,22 @@ export function includeAuth(token: string) {* @param authHeader - The Authorization header value* @returns The extracted token or null if the token is invalid*/-export const extractBearerToken = (authHeader: string | undefined): string | null => {- if (!authHeader) {- return null;- }+export const extractBearerToken = (+ authHeader: string | undefined+): string | null => {+ if (!authHeader) {+ return null;+ }- if (typeof authHeader !== 'string' || !authHeader.startsWith('Bearer ')) {- return null;- }+ if (typeof authHeader !== "string" || !authHeader.startsWith("Bearer ")) {+ return null;+ }- const token = authHeader.slice(7).trim();+ const token = authHeader.slice(7).trim();- if (!token?.length) {- return null;- }+ if (!token?.length) {+ return null;+ }- return token;+ return token;};diff --git a/packages/runtime/src/core/smart-agent-router.ts b/packages/runtime/src/core/smart-agent-router.tsindex 7be9532e..0efa239d 100644--- a/packages/runtime/src/core/smart-agent-router.ts+++ b/packages/runtime/src/core/smart-agent-router.ts@@ -1,6 +1,7 @@/*** Smart Agent Router - Intelligently routes between debugger and agent-runner* Based on request characteristics and agent properties+ **/import { Logger } from "@smythos/sre";@@ -12,7 +13,7 @@ const console = Logger("[Smart Agent Router]");export interface RouterDependencies {// Debugger dependenciesdebugger: {- agentLoader: express.RequestHandler;+ middlewares: express.RequestHandler[];processAgentRequest: (agentId: string,req: express.Request@@ -22,23 +23,21 @@ export interface RouterDependencies {};// Agent-runner dependenciesagentRunner: {- uploadHandler: express.RequestHandler;- agentLoader: express.RequestHandler;+ middlewares: express.RequestHandler[];processAgentRequest: (agent: any, req: express.Request) => Promise<any>;};}/**- * Determines which service should handle the request based on explicit headers- * This provides stable, predictable routing that doesn't depend on domain names+ * Determines which service should handle the request based on headers only+ * Simple, header-based routing for predictable behavior** ROUTING PRIORITY (highest to lowest):* 1. X-FORCE-AGENT-RUNNER: Forces agent-runner (overrides everything)* 2. Debug headers: Forces debugger (X-DEBUG-*, X-MONITOR-ID)* 3. X-FORCE-DEBUGGER: Forces debugger- * 4. Deployed versions: Always use agent-runner for production safety- * 5. X-ROUTING-MODE: Explicit mode selection (debugger|agent-runner)- * 6. Default: agent-runner (production-safe fallback)+ * 4. X-ROUTING-MODE: Explicit mode selection (debugger|agent-runner)+ * 5. Default: agent-runner (production-safe fallback)** USAGE EXAMPLES:* - Test agent-runner from localhost: Add header "X-FORCE-AGENT-RUNNER: true"@@ -47,12 +46,6 @@ export interface RouterDependencies {* - Default behavior: No headers = agent-runner (safe for production)*/function shouldUseDebugger(req: any): { useDebugger: boolean; reason: string } {- const agent = req._agent;-- if (!agent) {- return { useDebugger: false, reason: "No agent context" };- }-// 1. Check for explicit agent-runner header (highest priority)const forceAgentRunner = req.header("X-FORCE-AGENT-RUNNER") !== undefined;if (forceAgentRunner) {@@ -86,20 +79,7 @@ function shouldUseDebugger(req: any): { useDebugger: boolean; reason: string } {return { useDebugger: true, reason: "X-FORCE-DEBUGGER header present" };}- // 4. Check if it's a deployed version (production) - always use agent-runner- const isDeployedVersion =- agent.agentVersion &&- agent.agentVersion !== "development" &&- agent.agentVersion !== "latest";-- if (isDeployedVersion) {- return {- useDebugger: false,- reason: `Deployed version: ${agent.agentVersion}`,- };- }-- // 5. Default routing based on explicit mode header+ // 4. Default routing based on explicit mode headerconst routingMode = req.header("X-ROUTING-MODE");if (routingMode === "debugger") {return { useDebugger: true, reason: "X-ROUTING-MODE: debugger" };@@ -108,8 +88,7 @@ function shouldUseDebugger(req: any): { useDebugger: boolean; reason: string } {return { useDebugger: false, reason: "X-ROUTING-MODE: agent-runner" };}- // 6. Final fallback: Default to agent-runner for production safety- // This ensures that without explicit headers, we always use the production-safe route+ // 5. Final fallback: Default to agent-runner for production safetyreturn {useDebugger: false,reason: "Default production-safe routing (no explicit routing headers)",@@ -166,13 +145,25 @@ export function createSmartAgentRouter(const startTime = Date.now();try {- // Step 1: Load agent context using combined middleware approach- await runMiddleware(req, res, dependencies.agentRunner.uploadHandler);- await runMiddleware(req, res, dependencies.debugger.agentLoader);-- // Step 2: Make routing decision+ // Step 1: Make routing decision based on headersconst { useDebugger, reason } = shouldUseDebugger(req);+ // Step 2: Apply service-specific middleware (including upload handlers)+ const serviceMiddlewares = useDebugger+ ? dependencies.debugger.middlewares+ : dependencies.agentRunner.middlewares;++ console.debug(+ `Applying ${serviceMiddlewares.length} ${+ useDebugger ? "debugger" : "agent-runner"+ } middleware(s)`,+ {+ correlationId,+ middlewares: serviceMiddlewares.map((mw) => mw.name || "anonymous"),+ }+ );+ await runMiddlewares(req, res, serviceMiddlewares);+console.log(`Routing decision: ${useDebugger ? "DEBUGGER" : "AGENT-RUNNER"@@ -257,6 +248,19 @@ function runMiddleware(});}+/**+ * Helper function to run an array of middlewares sequentially+ */+async function runMiddlewares(+ req: any,+ res: express.Response,+ middlewares: express.RequestHandler[]+): Promise<void> {+ for (const middleware of middlewares) {+ await runMiddleware(req, res, middleware);+ }+}+/*** Configuration helper for different deployment scenarios*/@@ -321,12 +325,11 @@ export function createConfiguredSmartRouter(* Utility function to test routing decisions without making actual requests* Useful for debugging and testing the routing logic*/-export function testRoutingDecision(- agentContext: any,- headers: Record<string, string> = {}-): { useDebugger: boolean; reason: string } {+export function testRoutingDecision(headers: Record<string, string> = {}): {+ useDebugger: boolean;+ reason: string;+} {const mockReq = {- _agent: agentContext,header: (name: string) => headers[name],};diff --git a/packages/runtime/src/core/types/declarations/smythos.express.d.ts b/packages/runtime/src/core/types/declarations/smythos.express.d.tsindex acc7b55f..43809955 100644--- a/packages/runtime/src/core/types/declarations/smythos.express.d.ts+++ b/packages/runtime/src/core/types/declarations/smythos.express.d.ts@@ -2,7 +2,7 @@ import multer from "multer";import { Agent } from "@smythos/sre";-import Chatbot from "@embodiment/modules/chatbot/services/Chatbot.class";+import Chatbot from "@embodiment/services/Chatbot.class";declare global {namespace Express {diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.tsindex b8dba0aa..8dd66e4e 100644--- a/packages/runtime/src/index.ts+++ b/packages/runtime/src/index.ts@@ -36,7 +36,7 @@ import { routes as embodimentRoutes } from "@embodiment/routes";import { CodeSandboxService } from "./services/code-sandbox.service";const app = express();-const port = parseInt(process.env.PORT || "5000");+const port = parseInt(process.env.PORT || "5053");// Register all connectorsregisterConnectors();@@ -58,7 +58,7 @@ const sre = SmythRuntime.Instance.init({oAuthBaseUrl: `${process.env.LOGTO_SERVER}/oidc/token`,oAuthResource: process.env.LOGTO_API_RESOURCE,oAuthScope: "",- smythAPIBaseUrl: process.env.SMYTH_API_BASE_URL,+ smythAPIBaseUrl: process.env.MIDDLEWARE_API_BASE_URL,},},Vault: {@@ -87,7 +87,7 @@ const sre = SmythRuntime.Instance.init({oAuthBaseUrl: `${process.env.LOGTO_SERVER}/oidc/token`,oAuthResource: process.env.LOGTO_API_RESOURCE,oAuthScope: "",- smythAPIBaseUrl: process.env.SMYTH_API_BASE_URL,+ smythAPIBaseUrl: process.env.MIDDLEWARE_API_BASE_URL,},},Log: {@@ -219,7 +219,7 @@ const codeSandboxService = CodeSandboxService.getInstance();console.info("🎯 All Services Running:");console.info(` • Management Server: http://localhost:${- process.env.ADMIN_PORT || "8080"+ process.env.ADMIN_PORT || "5054"}`);console.info(` • Runtime Server: http://localhost:${port}`);diff --git a/packages/runtime/src/modules/agent-runner/services/logto-helper.ts b/packages/runtime/src/modules/agent-runner/services/logto-helper.tsdeleted file mode 100644index 04d107f4..00000000--- a/packages/runtime/src/modules/agent-runner/services/logto-helper.ts+++ /dev/null@@ -1,69 +0,0 @@-import axios from "axios";-import qs from "querystring";--import config from "@agent-runner/config";-//M2M test-const postData = {- grant_type: "client_credentials",- resource: "https://default.logto.app/api",- scope: "all",-};--const base64Credentials = Buffer.from(- `${config.env.LOGTO_M2M_APP_ID}:${config.env.LOGTO_M2M_APP_SECRET}`,- "utf8"-).toString("base64");--let tokenData = {- access_token: null,-};-export function getM2MToken(resource?, scope?) {- return new Promise((resolve, reject) => {- if (tokenData.access_token) {- return resolve(tokenData.access_token);- }-- const body = {- grant_type: "client_credentials",- resource: resource || config.env.LOGTO_API_RESOURCE,- scope: scope || "",- };- axios({- method: "post",- url: `${config.env.LOGTO_SERVER}/oidc/token`,- headers: {- Authorization: "Basic " + base64Credentials,- "Content-Type": "application/x-www-form-urlencoded",- },- data: qs.stringify(body),- })- .then((response) => {- tokenData.access_token = response.data.access_token;- setTimeout(() => {- tokenData.access_token = null;- }, (response.data.expires_in - 100) * 1000);- resolve(tokenData.access_token);- })- .catch((error) => {- reject({ error: error.response.data });- });- });-}--export async function getUserInfo(userId: string) {- const token = await getM2MToken("https://default.logto.app/api", "all");-- const response: any = await axios({- method: "get",- url: `${config.env.LOGTO_SERVER}/api/users/${userId}`,- headers: {- Authorization: `Bearer ${token}`,- },- }).catch((error) => ({ error }));-- if (response.error) {- return null;- }-- return response.data;-}diff --git a/packages/runtime/src/modules/agent-runner/services/smythAPIReq.ts b/packages/runtime/src/modules/agent-runner/services/smythAPIReq.tsdeleted file mode 100644index 722d275e..00000000--- a/packages/runtime/src/modules/agent-runner/services/smythAPIReq.ts+++ /dev/null@@ -1,15 +0,0 @@-import axios from "axios";--import config from "@agent-runner/config";--//middleware sys API-export const mwSysAPI = axios.create({- baseURL: `${config.env.SMYTH_API_BASE_URL}/_sysapi/v1`,-});-export function includeAuth(token: string) {- return {- headers: {- Authorization: `Bearer ${token}`,- },- };-}diff --git a/packages/runtime/src/modules/debugger/services/agent-request-handler.ts b/packages/runtime/src/modules/debugger/services/agent-request-handler.tsindex fc2bde32..4b8b96d7 100644--- a/packages/runtime/src/modules/debugger/services/agent-request-handler.ts+++ b/packages/runtime/src/modules/debugger/services/agent-request-handler.ts@@ -288,7 +288,7 @@ async function runAgentDebug(headers["X-DEBUG-RUN"] = "";//'X-DEBUG-RUN': '',- const port = process.env.PORT || 3000;+ const port = process.env.PORT || 5053;let url = `http://localhost:${port}${req.path.replace("/debug", "/api")}`;//add query paramsdiff --git a/packages/runtime/src/modules/embodiment/modules/agentChat/routes/router.ts b/packages/runtime/src/modules/embodiment/modules/agentChat/routes/router.tsindex 7ee4f149..be528ed8 100644--- a/packages/runtime/src/modules/embodiment/modules/agentChat/routes/router.ts+++ b/packages/runtime/src/modules/embodiment/modules/agentChat/routes/router.ts@@ -10,7 +10,7 @@ import { includeAuth, mwSysAPI } from "@core/services/smythAPIReq";import agentLoader from "@embodiment/middlewares/agentLoader.mw";import ChatbotLoader from "@embodiment/middlewares/ChatbotLoader.mw";-import Chatbot from "@embodiment/modules/chatbot/services/Chatbot.class";+import Chatbot from "@embodiment/services/Chatbot.class";import { buildConversationId } from "@embodiment/utils/chat.utils";// Import ChatbotResponse type for proper typingdiff --git a/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts b/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.tsindex ecfe39f0..53fc1a42 100644--- a/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts+++ b/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts@@ -423,7 +423,9 @@ async function exchangeCodeForToken(authInfo: any): Promise<any> {const isLocalAgent = domain.includes("localagent");- const baseUrl = isLocalAgent ? `http://${domain}:3000` : `https://${domain}`;+ const baseUrl = isLocalAgent+ ? `http://${domain}:${config.env.PORT}`+ : `https://${domain}`;const tokenEndpoint = `${baseUrl}/oauth/token`;const redirectUri = `${baseUrl}/chatbot/callback`;