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
adjust constants and remove agent.helper from embodiment
Forhad Hosain18375fa4e1c7
diff --git a/packages/runtime/src/core/constants.ts b/packages/runtime/src/core/constants.tsindex 073f4279..5c2fccf3 100644--- a/packages/runtime/src/core/constants.ts+++ b/packages/runtime/src/core/constants.ts@@ -1,5 +1,5 @@export const DEFAULT_AGENT_MODEL_SETTINGS_KEY = "chatGptModel"; // the key in the agent settings object that contains the model name-export const DEFAULT_AGENT_MODEL = "gpt-4o-mini"; // the default model to use if no model is specified in the agent settings+export const DEFAULT_AGENT_MODEL = "gpt-5-mini"; // the default model to use if no model is specified in the agent settingsexport const PROD_VERSION_VALUES = ["prod", "production", "stable"];export const TEST_VERSION_VALUES = [@@ -10,33 +10,6 @@ export const TEST_VERSION_VALUES = ["staging",];-export enum EMBODIMENT_TYPES {- ChatBot = "chatBot",- ChatGPT = "chatGPT",- FormPreview = "form",-}--export const MODELS_FOR_LEGACY_USERS = [- "gpt-4o-mini",- "gpt-4.1-nano",- "gpt-4.1-mini",- "gpt-4.1",- "gpt-4.5-preview",- "gpt-4o",- "o4-mini",- "o3",- "o3-mini",- "o1",- "o1-mini",- "o1-preview",- "gpt-4-turbo-latest",- "gpt-4-turbo",- "gpt-4-latest",- "gpt-4",- "gpt-3.5-turbo-latest",- "gpt-3.5-turbo",-];-export const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5 MBexport const MAX_FILE_COUNT = 5;diff --git a/packages/runtime/src/modules/agent-runner/constants.ts b/packages/runtime/src/modules/agent-runner/constants.tsindex 4dde3303..273f2f99 100644--- a/packages/runtime/src/modules/agent-runner/constants.ts+++ b/packages/runtime/src/modules/agent-runner/constants.ts@@ -1,78 +1 @@-import os from 'os';--// supported request methods-export const REQUEST_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];--export const REQUEST_CONTENT_TYPES = {- none: 'none',- urlEncodedFormData: 'application/x-www-form-urlencoded',- multipartFormData: 'multipart/form-data',- json: 'application/json',- text: 'text/plain',- xml: 'application/xml',- binary: 'binary',-};--export enum EMBODIMENT_TYPES {- ChatBot = 'chatBot',- ChatGPT = 'chatGPT',-}--export const ERR_MSG_INVALID_IMAGE_SOURCE =- 'Please provide a valid Image Source. Supported image sources are: HTTP(S) URL, Base64 string, Data URL, Output Image from other component(s).';-export const ERR_MSG_INVALID_BINARY =- 'Please provide a valid data that is either a Blob, SmythFileObject (Binary Output from any Component), ArrayBuffer, Buffer, Base64 string, Data URL, or HTTP(s) URL';-export const ERR_MSG_MAX_DEPTH = 'The maximum depth has been exceeded for the provided array or object.';-export const ERR_MSG_MAX_ARRAY_SIZE = 'The maximum array size has been exceeded for the provided array.';-export const ERR_MSG_MAX_OBJECT_SIZE = 'The maximum object size has been exceeded for the provided object.';--export const MAX_DEPTH = 10;-export const MAX_OBJECT_SIZE = 1000;-export const MAX_ARRAY_SIZE = 1000;--export const MAX_FILE_SIZE = 20 * 1024 * 1024; // 10MB--export const MAX_FILE_COUNT = 10;--// Default maximum number of tokens allowed for LLM-export const DEFAULT_MAX_TOKENS_FOR_LLM = 2048;--// life cycle tag for daily purge of s3 objects-export const S3_DAILY_PURGE_LIFECYCLE_TAG = 'ExpirationPolicy=DeleteDaily';-export const S3_WEEKLY_PURGE_LIFECYCLE_TAG = 'ExpirationPolicy=DeleteWeekly';-export const S3_MONTHLY_PURGE_LIFECYCLE_TAG = 'ExpirationPolicy=DeleteMonthly';--export const TOOL_USE_DEFAULT_MODEL = 'gpt-3.5-turbo';--export const COMP_NAMES = {- apiCall: 'APICall',- code: 'Code',- llmPrompt: 'PromptGenerator',- visionLLM: 'VisionLLM',-};--export const JSON_RESPONSE_INSTRUCTION =- '\nAll responses should be in valid JSON format, compacted without newlines, indentations, or additional JSON syntax markers.';--export const DEFAULT_FILE_PARSING_ENDPOINT = '/api/process_attachment_fallback';--export const MODELS_FOR_LEGACY_USERS = [- 'gpt-4o-mini',- 'gpt-4.1-nano',- 'gpt-4.1-mini',- 'gpt-4.1',- 'gpt-4.5-preview',- 'gpt-4o',- 'o4-mini',- 'o3',- 'o3-mini',- 'o1',- 'o1-mini',- 'o1-preview',- 'gpt-4-turbo-latest',- 'gpt-4-turbo',- 'gpt-4-latest',- 'gpt-4',- 'gpt-3.5-turbo-latest',- 'gpt-3.5-turbo',-];+export const DEFAULT_FILE_PARSING_ENDPOINT = "/api/process_attachment_fallback";diff --git a/packages/runtime/src/modules/embodiment/constants.ts b/packages/runtime/src/modules/embodiment/constants.tsnew file mode 100644index 00000000..3462fdb0--- /dev/null+++ b/packages/runtime/src/modules/embodiment/constants.ts@@ -0,0 +1,5 @@+export enum EMBODIMENT_TYPES {+ ChatBot = "chatBot",+ ChatGPT = "chatGPT",+ FormPreview = "form",+}diff --git a/packages/runtime/src/modules/embodiment/helpers/agent.helper.ts b/packages/runtime/src/modules/embodiment/helpers/agent.helper.tsdeleted file mode 100644index be8dee02..00000000--- a/packages/runtime/src/modules/embodiment/helpers/agent.helper.ts+++ /dev/null@@ -1,329 +0,0 @@-import { AccessCandidate, ConnectorService } from "@smythos/sre";-import axios from "axios";--import config from "@core/config";-import { PROD_VERSION_VALUES, TEST_VERSION_VALUES } from "@core/constants";-import { includeAuth, mwSysAPI } from "@core/services/smythAPIReq";-import { getM2MToken } from "@embodiment/helpers/logto.helper";--export function extractAgentVerionsAndPath(url) {- const regex = /^\/v(\d+(\.\d+)?)?(\/api\/.+)/;- const match = url.match(regex);-- if (match) {- return {- path: match[3],- version: match[1] || "",- };- } else {- return {- path: url,- version: "",- };- }-}--export function getAgentIdAndVersion(model: string) {- const [agentId, version] = model.split("@");- let agentVersion = version?.trim() || undefined;- if (TEST_VERSION_VALUES.includes(agentVersion)) {- agentVersion = "";- }- if (PROD_VERSION_VALUES.includes(agentVersion)) {- agentVersion = "latest";- }-- return { agentId, agentVersion };-}--export async function getAgentEmbodiments(agentID) {- try {- const token = (await getM2MToken("https://api.smyth.ai")) as string;- const url = `${config.env.SMYTH_API_BASE_URL}/_sysapi/v1/embodiments?aiAgentId=${agentID}`;- console.log("calling URL", url);-- const response = await axios.get(- `${config.env.SMYTH_API_BASE_URL}/_sysapi/v1/embodiments?aiAgentId=${agentID}`,- {- headers: {- Authorization: `Bearer ${token}`,- },- }- );- // }- // const response = await smythAPIReq.get(`/embodiments?aiAgentId=${agentID}`, includeAuth(token));-- return response.data.embodiments;- } catch (error: any) {- console.error(error.response?.data, error.message);- console.log(- `Error getting embodiments for agentId=${agentID}: ${error?.message}`- );- throw new Error(- `Error getting embodiments for agentId=${agentID}: ${error?.message}`- );-- ///throw error;- }-}--export async function getAgentDomainById(agentId: string) {- const token = (await getM2MToken("https://api.smyth.ai")) as string;- const agentDataConnector = ConnectorService.getAgentDataConnector();-- const Authorization = `Bearer ${token}`;-- //TODO : OPTIMIZE THIS : use aiAgentId param instead of getting all domains then filtering- const result: any = await mwSysAPI- .get("/domains?verified=true", { headers: { Authorization } })- .catch((error) => ({ error }));-- if (result.error) {- throw new Error("Error getting domain info");- }-- const domain = result.data.domains.find(- (domainEntry: any) => domainEntry?.aiAgent?.id === agentId- )?.name;-- if (!domain) {- const deployed = await agentDataConnector.isDeployed(agentId);- if (deployed) {- return `${agentId}.${config.env.PROD_AGENT_DOMAIN}`;- } else {- return `${agentId}.${config.env.AGENT_DOMAIN}`;- }- }- return domain;-}--export async function readAgentOAuthConfig(agentData) {- console.log("readAgentOAuthConfig", agentData?.id);- //const authInfo = agentData?.auth;- const authInfo = await getAgentAuthData(agentData.id);- const method = authInfo?.method;- const provider = authInfo?.provider[authInfo?.method];- if (!provider) {- return {};- }- const authOIDCConfigURL = provider.OIDCConfigURL;- const clientID = provider.clientID;- const clientSecret = provider.clientSecret;- const openid: any = await axios- .get(authOIDCConfigURL)- .catch((error) => ({ error }));-- const tokenURL = openid?.data?.token_endpoint;- const authorizationURL = openid?.data?.authorization_endpoint;-- return {- authorizationURL,- tokenURL,- clientID,- clientSecret,- method,- provider,- };-}--export async function getAgentIdByDomain(domain = "") {- let agentId;- //first check if this is the internal wildcard agents domain- const isStageWildcardDomain = domain.includes(config.env.AGENT_DOMAIN);- const isProdWildcardDomain = domain.includes(config.env.PROD_AGENT_DOMAIN);- if (isStageWildcardDomain || isProdWildcardDomain) {- //console.log('Internal agent domain detected', domain);- agentId = domain.split(".")[0];- //sanity check- if (- `${agentId}.${config.env.AGENT_DOMAIN}` !== domain &&- `${agentId}.${config.env.PROD_AGENT_DOMAIN}` !== domain- ) {- throw new Error(`Invalid agent domain: ${domain}`);- }-- //if this is a stage domain, no more check, return the agentId- if (isStageWildcardDomain) return agentId;- }-- const token = (await getM2MToken("https://api.smyth.ai")) as string;- const Authorization = `Bearer ${token}`;- //FIXME : filter domains by agentId and by domain Id once it's supported in the middleware- const result: any = await mwSysAPI- .get("/domains?verified=true", { headers: { Authorization } })- .catch((error) => ({ error }));-- if (result.error) {- throw new Error("Error getting domain info");- }-- //we have an agentId from the wildcard domain, if this domain is already associated with- if (agentId) {- const hasDomain = result.data.domains.find(- (domainEntry: any) => domainEntry?.aiAgent?.id === agentId- );- if (hasDomain) {- throw new Error("Wrong domain");- }- } else {- agentId = result.data.domains.find(- (domainEntry: any) => domainEntry.name === domain- )?.aiAgent?.id;- }-- //if a custom domain is found, use it, otherwise use the agentId from the wildcard domain-- return agentId;-}--function migrateAgentData(data) {- if (!data.version) {- console.log(- `Agent [${data.name}] has an old schema. Migrating to latest version...`- );- // version 0 ===> migrate from receptors/connectors to inputs/outputs- const newData = JSON.parse(JSON.stringify(data));- for (let component of newData.components) {- component.outputs = component.connectors;- component.inputs = component.receptors;- component.outputProps = component.connectorProps;- component.inputProps = component.receptorProps;- delete component.connectors;- delete component.receptors;- delete component.connectorProps;- delete component.receptorProps;- }- return newData;- }-- if (data.version === "1.0.0") {- //migrate .description to .behavior- if (data.description && !data.behavior) {- data.behavior = data.description;- //delete newConfig.description;- }- }-- return data;-}--//TODO : cache versioned agent data. when an agent has a version, the data does not change, we can keep it in cache to avoid calling the api every time-export async function getAgentDataById(agentID, version) {- console.log("getAgentDataById", agentID, version);- try {- const token = (await getM2MToken("https://api.smyth.ai")) as string;-- let agentObj;-- //FIXME : once we have the agent name in deployment api response, we can skip this call- const response = await mwSysAPI.get(- `/ai-agent/${agentID}?include=team.subscription`,- includeAuth(token)- );- agentObj = response.data.agent;- const authData = agentObj.data.auth; //use most up to date auth data-- const tasksResponse = await mwSysAPI.get(- `/quota/team/${agentObj.teamId}/tasks/subscription`,- includeAuth(token)- );- agentObj.taskData = tasksResponse.data;-- agentObj.data.debugSessionEnabled =- agentObj?.data?.debugSessionEnabled && agentObj?.isLocked; //disable debug session if agent is not locked (locked agent means that it's open in the Agent builder)-- if (version) {- const deploymentsList = await mwSysAPI.get(- `/ai-agent/${agentID}/deployments`,- includeAuth(token)- );- const deployment =- version == "latest"- ? deploymentsList?.data?.deployments[0]- : deploymentsList?.data?.deployments?.find(- (deployment) => deployment.version === version- );- if (deployment) {- const deployResponse = await mwSysAPI.get(- `/ai-agent/deployments/${deployment.id}`,- includeAuth(token)- );- agentObj.data = deployResponse?.data?.deployment?.aiAgentData;- agentObj.data.debugSessionEnabled = false; //never enable debug session when using a deployed version- agentObj.data.agentVersion = deployment.version;- } else {- //if (version !== 'latest') {- throw new Error(`Requested Deploy Version not found: ${version}`);- //} // if version == 'latest' but no deployment is found we just fallback to the agent live data- }- }-- //TODO: Also include team and subscription info-- //agentObj.data.auth = authData;- if (!agentObj?.data?.auth?.method || agentObj?.data?.auth?.method == "none")- agentObj.data.auth = authData;-- agentObj.data = migrateAgentData(agentObj.data);-- return agentObj;- } catch (error: any) {- console.error(error.response?.data, error.message);- console.log(- `Error getting agent data for agentId=${agentID}: ${error?.message}`- );- throw new Error(- `Error getting agent data for agentId=${agentID}: ${error?.message}`- );- }-}--// #region Agent Auth Data-// Constants for agent auth data-const AGENT_AUTH = {- SETTINGS_KEY: "agent-auth-data",- CACHE: {- KEY_PREFIX: "agent:auth_data",- TTL: 60 * 60 * 24 * 7, // 7 days in seconds- },-} as const;--/**- * Fetches agent authentication data from the account connector- * @param agentId - The ID of the agent- * @returns Promise containing the agent settings- */-async function fetchAgentAuthData(agentId: string) {- const accountConnector = ConnectorService.getAccountConnector();- return await accountConnector- .user(AccessCandidate.agent(agentId))- .getAgentSetting(AGENT_AUTH.SETTINGS_KEY);-}--/**- * Gets agent authentication data with caching support- * @param agentId - The ID of the agent- * @returns Promise containing the agent auth settings- */-// TODO: To get data from cache, we need to reset the cache from UI backend when auth data is updated-export async function getAgentAuthData(agentId: string) {- // const cacheConnector = ConnectorService.getCacheConnector();- // const cacheKey = `${AGENT_AUTH.CACHE.KEY_PREFIX}:${agentId}`;-- // const cachedSettings = await cacheConnector.user(AccessCandidate.agent(agentId))?.get(cacheKey);- // if (cachedSettings) {- // return JSON.parse(cachedSettings);- // }-- const freshSettings = await fetchAgentAuthData(agentId);-- // void cacheConnector- // .user(AccessCandidate.agent(agentId))- // .set(cacheKey, JSON.stringify(freshSettings), AGENT_AUTH.CACHE.TTL)- // .catch((error) => {- // console.warn('Error setting agent auth data in cache', error?.message || error);- // });-- return JSON.parse(freshSettings || "{}");-}-// #endregion Agent Auth Datadiff --git a/packages/runtime/src/modules/embodiment/helpers/chatgpt.helper.ts b/packages/runtime/src/modules/embodiment/helpers/chatgpt.helper.tsindex 2139eb73..df3e7a26 100644--- a/packages/runtime/src/modules/embodiment/helpers/chatgpt.helper.ts+++ b/packages/runtime/src/modules/embodiment/helpers/chatgpt.helper.ts@@ -1,14 +1,16 @@import fs from "fs";import path from "path";-import { ChatGPTManifest } from "@/modules/embodiment/types/chatgpt.types";-import { EMBODIMENT_TYPES } from "@core/constants";+import { JSONContentHelper, TemplateStringHelper } from "@smythos/sre";+import {getAgentDataById,getAgentEmbodiments,getAgentIdByDomain,-} from "@embodiment/helpers/agent.helper";-import { JSONContentHelper, TemplateStringHelper } from "@smythos/sre";+} from "@core/helpers/agent.helper";++import { ChatGPTManifest } from "@/modules/embodiment/types/chatgpt.types";+import { EMBODIMENT_TYPES } from "@embodiment/constants";let chatGPTDataPath = "./data/chatGPT";diff --git a/packages/runtime/src/modules/embodiment/middlewares/agentLoader.mw.ts b/packages/runtime/src/modules/embodiment/middlewares/agentLoader.mw.tsindex ba908792..f34f69e6 100644--- a/packages/runtime/src/modules/embodiment/middlewares/agentLoader.mw.ts+++ b/packages/runtime/src/modules/embodiment/middlewares/agentLoader.mw.ts@@ -7,13 +7,12 @@ import {} from "@smythos/sre";import config from "@core/config";-import { addDefaultComponentsAndConnections } from "@core/helpers/agent.helper";-import {extractAgentVerionsAndPath,getAgentDomainById,getAgentIdAndVersion,-} from "@embodiment/helpers/agent.helper";+} from "@core/helpers/agent.helper";+import { addDefaultComponentsAndConnections } from "@core/helpers/agent.helper";const console = Logger("[Embodiment] Middleware: Agent Loader");diff --git a/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts b/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.tsindex 4ed31c6a..ecfe39f0 100644--- a/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts+++ b/packages/runtime/src/modules/embodiment/modules/chatbot/routes/router.ts@@ -1,11 +1,13 @@-import config from "@core/config";-import { EMBODIMENT_TYPES } from "@core/constants";-import { uploadHandler } from "@core/middlewares/uploadHandler.mw";-import { AccessCandidate, Agent, BinaryInput } from "@smythos/sre";import axios from "axios";import express from "express";-import { readAgentOAuthConfig } from "@embodiment/helpers/agent.helper";+import { AccessCandidate, Agent, BinaryInput } from "@smythos/sre";++import config from "@core/config";+import { readAgentOAuthConfig } from "@core/helpers/agent.helper";+import { uploadHandler } from "@core/middlewares/uploadHandler.mw";++import { EMBODIMENT_TYPES } from "@embodiment/constants";import { getChatGPTManifest } from "@embodiment/helpers/chatgpt.helper";import agentLoader from "@embodiment/middlewares/agentLoader.mw";import ChatbotLoader from "@embodiment/middlewares/ChatbotLoader.mw";diff --git a/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts b/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.tsindex db7a715e..c8553dfd 100644--- a/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts+++ b/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts@@ -2,9 +2,9 @@ import { Agent, AgentLogger, Conversation } from "@smythos/sre";import { Request } from "express";import config from "@core/config";-import { EMBODIMENT_TYPES } from "@core/constants";import { delay } from "@core/utils/date-time.utils";+import { EMBODIMENT_TYPES } from "@embodiment/constants";import { getOpenAPIJSONForAI } from "@embodiment/helpers/openapi-adapter.helper";import { ChatConversationsEnv } from "@embodiment/utils/chat.utils";diff --git a/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts b/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.tsindex 40bcaec7..2141a0c8 100644--- a/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts+++ b/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts@@ -1,5 +1,7 @@-import ApiError from "@core/utils/apiError";-import { getAgentIdAndVersion } from "@embodiment/helpers/agent.helper";+import crypto from "crypto";+import { OpenAI } from "openai";+import { Readable } from "stream";+import {AccessCandidate,Agent,@@ -7,9 +9,9 @@ import {Conversation,Logger,} from "@smythos/sre";-import crypto from "crypto";-import { OpenAI } from "openai";-import { Readable } from "stream";++import ApiError from "@core/utils/apiError";+import { getAgentIdAndVersion } from "@core/helpers/agent.helper";const console = Logger("[Embodiment] Service: OpenAI Chat");diff --git a/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts b/packages/runtime/src/modules/embodiment/services/Chatbot.class.tsindex d537cbd8..b525abbc 100644--- a/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts+++ b/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts@@ -3,7 +3,8 @@ import { Request } from "express";import { Agent, AgentLogger, Conversation } from "@smythos/sre";import config from "@core/config";-import { EMBODIMENT_TYPES } from "@core/constants";++import { EMBODIMENT_TYPES } from "@embodiment/constants";import { getOpenAPIJSONForAI } from "../helpers/openapi-adapter.helper";import { FsChatbotContextStore } from "./FsChatbotContextStore.class";