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

1.8 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { iloveapiAuth } from '../common/auth';
import { iloveSchemas } from '../common/schemas';
import { regionOf, rowFiles, sharedProps, webhookOf } from '../common/props';
import { runAndStoreResult } from '../common/runner';

export const mergePdfAction = createAction({
  auth: iloveapiAuth,
  name: 'merge_pdf',
  classification: 'READ',
  displayName: 'Merge PDF',
  description:
    'Combine multiple PDF files into a single document, in the order provided.',
  audience: 'both',
  outputSchema: iloveSchemas.toolResult,
  aiMetadata: {
    description:
      'Concatenate two or more PDF files into one document, preserving the order in which they are listed. Requires at least two input files. Each run generates a new merged file, so re-running does not deduplicate against earlier outputs.',
    idempotent: false,
  },
  props: {
    files: Property.Array({
      displayName: 'PDF Files',
      description:
        'List of PDF files to merge. The output preserves the listed order.',
      required: true,
      properties: {
        file: Property.File({
          displayName: 'File',
          required: true,
        }),
      },
    }),
    ...sharedProps,
  },
  async run(context) {
    const { files, output_filename, packaged_filename } = context.propsValue;

    if (!Array.isArray(files) || files.length < 2) {
      throw new Error('At least two PDF files are required for merging.');
    }

    const uploads = rowFiles({ rows: files, label: 'PDF Files' });

    return await runAndStoreResult({
      auth: context.auth.secret_text,
      region: regionOf(context.propsValue.region),
      webhook: webhookOf(context.propsValue.webhook_url),
      files: context.files,
      tool: 'merge',
      uploads,
      output_filename,
      packaged_filename,
    });
  },
});