Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.0 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { airOpsAuth } from '../..';
import { makeRequest } from '../common';

export const runWorkflow = createAction({
  auth: airOpsAuth,
  name: 'run_workflow',
  classification: 'WRITE',
  displayName: 'Run Workflow',
  description: 'Execute an AirOps workflow synchronously.',
  audience: 'both',
  aiMetadata: { description: 'Run a selected AirOps workflow synchronously and wait for its result, passing optional input values. Use when you need the workflow output back in the same call rather than polling; for long-running workflows prefer the async variant. Requires the target workflow (selected from the account) and triggers a new execution each time, so it is not idempotent.', idempotent: false },
  props: {
    app: Property.Dropdown({
      displayName: 'Workflow',
      description: 'Select the workflow to execute.',
      required: true,
      refreshers: [],
      auth: airOpsAuth,
      options: async ({ auth }) => {
        if (!auth) {
          return {
            disabled: true,
            placeholder: 'Connect your AirOps account first',
            options: [],
          };
        }

        try {
          const apps = await makeRequest(
            auth.secret_text,
            HttpMethod.GET,
            '/public_api/airops_apps'
          );

          return {
            disabled: false,
            options: (apps as AirOpsApp[]).map((app) => ({
              label: app.name,
              value: app.uuid,
            })),
          };
        } catch (error) {
          return {
            disabled: true,
            placeholder: 'Failed to load workflows',
            options: [],
          };
        }
      },
    }),
    inputs: Property.Json({
      displayName: 'Inputs',
      description: 'Input values for the workflow.',
      required: false,
      defaultValue: {},
    }),
    inputs_schema: Property.Json({
      displayName: 'Inputs Schema',
      description: 'Schema defining the workflow inputs (advanced).',
      required: false,
    }),
    definition: Property.Json({
      displayName: 'Definition',
      description: 'Custom workflow definition steps (advanced).',
      required: false,
    }),
  },
  async run(context) {
    const { app, inputs, inputs_schema, definition } = context.propsValue;

    const body: Record<string, unknown> = {};

    if (inputs) {
      body['inputs'] = inputs;
    }
    if (inputs_schema) {
      body['inputs_schema'] = inputs_schema;
    }
    if (definition) {
      body['definition'] = definition;
    }

    const response = await makeRequest(
      context.auth.secret_text,
      HttpMethod.POST,
      `/public_api/airops_apps/${app}/execute_definition`,
      body
    );

    return response;
  },
});

interface AirOpsApp {
  id: number;
  name: string;
  description: string;
  background_color: string;
  created_at: string;
  updated_at: string;
  active_version_id: number;
  emoji: string;
  public: boolean;
  uuid: string;
  readme: string;
}