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.

1.1 KB
Raw Blame
import axios, { AxiosError } from 'axios';

import config from '@core/config';

type CallSkillParams = {
  agentId: string;
};

type CallSkillBody = {
  componentId: string;
  payload?: Record<string, any> | null | '';
  version?: 'dev' | 'latest';
};

type CallSkillType = {
  params: CallSkillParams;
  body: CallSkillBody;
  endpoint: string;
};

export async function callSkill({ params, body, endpoint }: CallSkillType) {
  const RUNTIME_AGENT_URL = config.env.BASE_URL;

  const request: {
    body: string | null;
    headers: { [key: string]: string };
  } = { body: null, headers: {} };

  request.body = JSON.stringify(body?.payload || {});
  request.headers = {
    'Content-Type': 'application/json',
    'X-DEBUG-SKIP': 'true',
    ...(body.version !== 'dev' && { 'X-AGENT-VERSION': body.version }), // if version is dev, don't send it
    'X-AGENT-ID': params.agentId,
  };

  try {
    const res = await axios.post(`${RUNTIME_AGENT_URL}/api/${endpoint}`, request.body, {
      headers: request.headers,
    });
    return res.data;
  } catch (error) {
    const axiosErr = error as AxiosError;
    return axiosErr.response?.data || axiosErr.message;
  }
}