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.

fix: (expermential): fix openapi spec to call agent locally

Ahmed Essam24ebca0dfa3a
diff --git a/packages/runtime/src/core/config.ts b/packages/runtime/src/core/config.ts
index 2c1ee249..7c970b97 100644
--- a/packages/runtime/src/core/config.ts
+++ b/packages/runtime/src/core/config.ts
@@ -34,6 +34,7 @@ const config = {
ADMIN_PORT: process.env.RUNTIME_ADMIN_PORT || process.env.ADMIN_PORT || 5054,
BASE_URL: process.env.RUNTIME_URL || `http://localhost:${process.env.RUNTIME_PORT}`,
+ LOCAL_BASE_URL: `http://localhost:${process.env.RUNTIME_PORT}`,
LOGTO_M2M_APP_ID: process.env.LOGTO_M2M_APP_ID,
diff --git a/packages/runtime/src/modules/embodiment/helpers/openapi-adapter.helper.ts b/packages/runtime/src/modules/embodiment/helpers/openapi-adapter.helper.ts
index ba602e52..c88827df 100644
--- a/packages/runtime/src/modules/embodiment/helpers/openapi-adapter.helper.ts
+++ b/packages/runtime/src/modules/embodiment/helpers/openapi-adapter.helper.ts
@@ -134,14 +134,29 @@ async function getOpenAPIJSONById(
* @returns Promise<any> - The OpenAPI specification or error
*/
export async function getOpenAPIJSONForAI(domain: string, version: string, addDefaultFileParsingAgent = false): Promise<any> {
+ let _domain = domain;
try {
const agentId = await getAgentIdByDomain(domain);
if (!agentId) {
return { error: 'Agent not found' };
}
- return getOpenAPIJSONById(agentId, domain, version, true, addDefaultFileParsingAgent);
+ //* in case of local agent domain, we use the local base URL since it is possible that the app would be running
+ //* on a different port than the assigned default port (e.g if the app is running inside a Docker container part of a compose that have
+ //* Trafeik, so if this app tried to reach the domain specified, it will not resolve to the correct port)
+ if (isUsingLocalAgentDomain(_domain)) {
+ _domain = new URL(config.env.LOCAL_BASE_URL).hostname;
+ }
+
+ return getOpenAPIJSONById(agentId, _domain, version, true, addDefaultFileParsingAgent);
} catch (error) {
return { error: error.message || 'OpenAPI generation failed' };
}
}
+
+function isUsingLocalAgentDomain(domain: string): boolean {
+ if (domain.includes('localhost')) {
+ return true;
+ }
+ return false;
+}