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.

get env from config where it make sense

Forhad Hosain29442bb2300d
diff --git a/packages/runtime/src/core/component/Code.class.ts b/packages/runtime/src/core/component/Code.class.ts
index 4e1cae6d..b9c5e625 100644
--- a/packages/runtime/src/core/component/Code.class.ts
+++ b/packages/runtime/src/core/component/Code.class.ts
@@ -20,7 +20,7 @@ export class Code extends Component {
try {
let Output: any = {};
let _error = undefined;
- const url = (process.env.CODE_SANDBOX_URL || "http://localhost:5055") + "/run-js";
+ const url = config.env.CODE_SANDBOX_URL + "/run-js";
let codeInputs = {};
for (let fieldName in input) {
diff --git a/packages/runtime/src/core/config.ts b/packages/runtime/src/core/config.ts
index 526757af..039df130 100644
--- a/packages/runtime/src/core/config.ts
+++ b/packages/runtime/src/core/config.ts
@@ -3,6 +3,7 @@ dotenv.config();
const config = {
env: {
+ PORT: parseInt(process.env.PORT || "5053"),
// Required environment variables
LOGTO_M2M_APP_SECRET: process.env.LOGTO_M2M_APP_SECRET,
LOGTO_SERVER: process.env.LOGTO_SERVER,
@@ -11,7 +12,6 @@ const config = {
NODE_ENV: process.env?.NODE_ENV || "development",
ADMIN_PORT: process.env.ADMIN_PORT || 5054,
- PORT: parseInt(process.env.PORT || "5053"),
BASE_URL: process.env.BASE_URL || "http://localhost:5053",
@@ -22,11 +22,16 @@ const config = {
AGENT_DOMAIN_PORT: process.env?.AGENT_DOMAIN_PORT,
REQ_LIMIT_PER_MINUTE: process.env.REQ_LIMIT_PER_MINUTE || 300,
+ MAX_CONCURRENT_REQUESTS: process.env.MAX_CONCURRENT_REQUESTS || 10,
UI_SERVER: process.env.UI_SERVER || "http://localhost:4000",
SESSION_SECRET: process.env.SESSION_SECRET,
+ CODE_SANDBOX_URL: process.env.CODE_SANDBOX_URL || "http://localhost:5055",
+
DATA_PATH: process.env.DATA_PATH,
+
+ SMYTHOS_SERVER_TYPE: process.env.SMYTHOS_SERVER_TYPE || "combined",
},
};
diff --git a/packages/runtime/src/core/management-router.ts b/packages/runtime/src/core/management-router.ts
index 4fc27792..da82a3d1 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 || "5054");
-const PORT = parseInt(process.env.PORT || "5053");
+const ADMIN_PORT = config.env.ADMIN_PORT || 5054;
+const PORT = config.env.PORT || 5053;
// eslint-disable-next-line import/no-mutable-exports
export let server: Server;
diff --git a/packages/runtime/src/core/middlewares/cors.mw.ts b/packages/runtime/src/core/middlewares/cors.mw.ts
index 6105fe32..d4c4d1e5 100644
--- a/packages/runtime/src/core/middlewares/cors.mw.ts
+++ b/packages/runtime/src/core/middlewares/cors.mw.ts
@@ -1,5 +1,7 @@
import cors from "cors";
+import config from "@core/config";
+
// Minimal CORS - allow everything in development, configurable for production
const corsOptions: cors.CorsOptions = {
origin:
@@ -8,7 +10,14 @@ const corsOptions: cors.CorsOptions = {
: true,
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
- allowedHeaders: ["Content-Type", "Authorization", "X-Conversation-Id", "X-Auth-Token", "X-Parent-Cookie", "X-Monitor-Id"],
+ allowedHeaders: [
+ "Content-Type",
+ "Authorization",
+ "X-Conversation-Id",
+ "X-Auth-Token",
+ "X-Parent-Cookie",
+ "X-Monitor-Id",
+ ],
};
export default cors(corsOptions);
diff --git a/packages/runtime/src/core/middlewares/rateLimiter.mw.ts b/packages/runtime/src/core/middlewares/rateLimiter.mw.ts
index 0fcbfdf7..1727a786 100644
--- a/packages/runtime/src/core/middlewares/rateLimiter.mw.ts
+++ b/packages/runtime/src/core/middlewares/rateLimiter.mw.ts
@@ -6,12 +6,8 @@ import config from "@core/config";
const console = Logger("(Core) Middleware: RateLimiter");
// Configuration from environment variables with sensible defaults
-const REQUESTS_PER_MINUTE = parseInt(
- (config.env.REQ_LIMIT_PER_MINUTE as string) || "100"
-);
-const MAX_CONCURRENT_REQUESTS = parseInt(
- process.env.MAX_CONCURRENT_REQUESTS || "10"
-);
+const REQUESTS_PER_MINUTE = config.env.REQ_LIMIT_PER_MINUTE as number;
+const MAX_CONCURRENT_REQUESTS = config.env.MAX_CONCURRENT_REQUESTS as number;
const WINDOW_SIZE_MS = 60 * 1000; // 1 minute window
const CLEANUP_INTERVAL_MS = 5 * 60 * 1000; // Cleanup every 5 minutes
diff --git a/packages/runtime/src/core/router-config.ts b/packages/runtime/src/core/router-config.ts
index 60ca87e6..f601d889 100644
--- a/packages/runtime/src/core/router-config.ts
+++ b/packages/runtime/src/core/router-config.ts
@@ -24,6 +24,7 @@ import {
createDebuggerRouter,
} from "./shared-agent-router";
import { createConfiguredSmartRouter } from "./smart-agent-router";
+import config from "./config";
/**
* Configures and mounts agent routers based on runtime configuration
@@ -169,7 +170,7 @@ export function createDebuggerServerConfig(): RuntimeConfig {
},
routing: { strategy: "separate" },
server: {
- port: parseInt(process.env.PORT || "5053"),
+ port: config.env.PORT,
name: "smythos-debugger-server",
healthCheck: true,
metrics: true,
@@ -193,7 +194,7 @@ export function createAgentRunnerServerConfig(): RuntimeConfig {
},
routing: { strategy: "separate" },
server: {
- port: parseInt(process.env.PORT || "5053"),
+ port: config.env.PORT,
name: "smythos-agent-runner-server",
healthCheck: true,
metrics: true,
@@ -217,7 +218,7 @@ export function createEmbodimentServerConfig(): RuntimeConfig {
},
routing: { strategy: "separate" },
server: {
- port: parseInt(process.env.PORT || "5053"),
+ port: config.env.PORT,
name: "smythos-embodiment-server",
healthCheck: true,
metrics: true,
@@ -241,7 +242,7 @@ export function createCombinedServerConfig(): RuntimeConfig {
},
routing: { strategy: "smart" },
server: {
- port: parseInt(process.env.PORT || "5053"),
+ port: config.env.PORT,
name: "smythos-runtime-combined",
healthCheck: true,
metrics: true,
diff --git a/packages/runtime/src/core/runtime-config.ts b/packages/runtime/src/core/runtime-config.ts
index 617e97e5..7143eb7c 100644
--- a/packages/runtime/src/core/runtime-config.ts
+++ b/packages/runtime/src/core/runtime-config.ts
@@ -1,3 +1,4 @@
+import config from "./config";
/**
* Runtime Configuration System
* Designed for future server extraction without code changes
@@ -150,7 +151,7 @@ export const RuntimeConfigs = {
* This will be used by the extraction script
*/
export function loadRuntimeConfig(): RuntimeConfig {
- const configType = process.env.SMYTHOS_SERVER_TYPE || "combined";
+ const configType = config.env.SMYTHOS_SERVER_TYPE;
switch (configType) {
case "debugger":
diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts
index 8dd66e4e..a84f7a6e 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 || "5053");
+const port = config.env.PORT;
// Register all connectors
registerConnectors();
@@ -53,12 +53,12 @@ const sre = SmythRuntime.Instance.init({
Account: {
Connector: "SmythOSSAccount",
Settings: {
- oAuthAppID: process.env.LOGTO_M2M_APP_ID,
- oAuthAppSecret: process.env.LOGTO_M2M_APP_SECRET,
- oAuthBaseUrl: `${process.env.LOGTO_SERVER}/oidc/token`,
- oAuthResource: process.env.LOGTO_API_RESOURCE,
+ oAuthAppID: config.env.LOGTO_M2M_APP_ID,
+ oAuthAppSecret: config.env.LOGTO_M2M_APP_SECRET,
+ oAuthBaseUrl: `${config.env.LOGTO_SERVER}/oidc/token`,
+ oAuthResource: config.env.LOGTO_API_RESOURCE,
oAuthScope: "",
- smythAPIBaseUrl: process.env.MIDDLEWARE_API_BASE_URL,
+ smythAPIBaseUrl: config.env.MIDDLEWARE_API_BASE_URL + "/_sysapi",
},
},
Vault: {
@@ -82,12 +82,12 @@ const sre = SmythRuntime.Instance.init({
Settings: {
agentStageDomain: config.env.AGENT_DOMAIN || "",
agentProdDomain: config.env.PROD_AGENT_DOMAIN || "",
- oAuthAppID: process.env.LOGTO_M2M_APP_ID,
- oAuthAppSecret: process.env.LOGTO_M2M_APP_SECRET,
- oAuthBaseUrl: `${process.env.LOGTO_SERVER}/oidc/token`,
- oAuthResource: process.env.LOGTO_API_RESOURCE,
+ oAuthAppID: config.env.LOGTO_M2M_APP_ID,
+ oAuthAppSecret: config.env.LOGTO_M2M_APP_SECRET,
+ oAuthBaseUrl: `${config.env.LOGTO_SERVER}/oidc/token`,
+ oAuthResource: config.env.LOGTO_API_RESOURCE,
oAuthScope: "",
- smythAPIBaseUrl: process.env.MIDDLEWARE_API_BASE_URL,
+ smythAPIBaseUrl: config.env.MIDDLEWARE_API_BASE_URL + "/_sysapi",
},
},
Log: {
@@ -137,7 +137,7 @@ app.use(cookieParser());
app.use(
session({
name: "smythos_runtime_session",
- secret: process.env.SESSION_SECRET || "default-session-secret-for-dev",
+ secret: config.env.SESSION_SECRET || "default-session-secret-for-dev",
cookie: {
maxAge: 1 * 24 * 60 * 60 * 1000, // 1 day
sameSite: config.env.NODE_ENV === "development" ? "lax" : "none",
@@ -219,7 +219,7 @@ const codeSandboxService = CodeSandboxService.getInstance();
console.info("🎯 All Services Running:");
console.info(
` • Management Server: http://localhost:${
- process.env.ADMIN_PORT || "5054"
+ config.env.ADMIN_PORT || "5054"
}`
);
console.info(` • Runtime Server: http://localhost:${port}`);
diff --git a/packages/runtime/src/modules/debugger/services/agent-request-handler.ts b/packages/runtime/src/modules/debugger/services/agent-request-handler.ts
index 4b8b96d7..b7108ed1 100644
--- a/packages/runtime/src/modules/debugger/services/agent-request-handler.ts
+++ b/packages/runtime/src/modules/debugger/services/agent-request-handler.ts
@@ -3,6 +3,7 @@ import { Request } from "express";
import { AgentProcess, Logger } from "@smythos/sre";
+import config from "@/core/config";
import { getMockData } from "@core/helpers/agent.helper";
const console = Logger("Service: Agent Request Handler");
@@ -288,7 +289,7 @@ async function runAgentDebug(
headers["X-DEBUG-RUN"] = "";
//'X-DEBUG-RUN': '',
- const port = process.env.PORT || 5053;
+ const port = config.env.PORT;
let url = `http://localhost:${port}${req.path.replace("/debug", "/api")}`;
//add query params
diff --git a/packages/runtime/src/services/code-sandbox.service.ts b/packages/runtime/src/services/code-sandbox.service.ts
index 41651477..9d26a950 100644
--- a/packages/runtime/src/services/code-sandbox.service.ts
+++ b/packages/runtime/src/services/code-sandbox.service.ts
@@ -1,7 +1,8 @@
-import { Logger } from "@smythos/sre";
import { ChildProcess, spawn } from "child_process";
import path from "path";
+import { Logger } from "@smythos/sre";
+
const console = Logger("code-sandbox-service");
export class CodeSandboxService {