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

2.7 KB
Raw Blame
import {
  PiecePropValueSchema,
  Property,
  createAction,
} from '@activepieces/pieces-framework';
import { limitField, makeClient, pageField } from '../common';
import { PredictLeadsAuth } from '../auth';
import { prepareQuery } from '../common/client';

export const findCompaniesAction = createAction({
  auth: PredictLeadsAuth,
  name: 'predict-leads_find_companies',
  displayName: 'List Companies',
  description: 'Retrieves all companies.',
  audience: 'both',
  aiMetadata: { description: 'Discovers companies in the PredictLeads database filtered by location and employee headcount range (e.g. "11-50"). Use to prospect or build a target-account list when you do not yet know specific company domains; both location and size range are required. Read-only and idempotent; supports pagination.', idempotent: true },
  props: {
    location: Property.ShortText({
      displayName: 'Location',
      required: true,
    }),
    minMaxSizes: Property.ShortText({
      displayName: 'Min Max Size',
      description:
        'A min-max size range. Examples: "11-50"". For now, only single range is supported.',
      required: true,
    }),
    page: pageField,
    limit: limitField,
  },
  async run(context) {
    const page = context.propsValue.page ?? 1;
    const limit = context.propsValue.limit ?? 1000;
    const location = context.propsValue.location;
    const min_max_sizes = context.propsValue.minMaxSizes;

    const client = makeClient(
      context.auth
    );

    try {
      const response = await client.findCompanies(
        prepareQuery({
          location,
          min_max_sizes,
          page,
          limit,
        })
      );
      return response;
    } catch (error) {
      throw new Error(JSON.stringify(error, undefined, 2));
    }
  },
});

export const findCompanyByDomainAction = createAction({
  auth: PredictLeadsAuth,
  name: 'predict-leads_find_company_by_domain',
  displayName: 'Retrieve a company',
  description: 'Retrieves a company by its domain.',
  audience: 'both',
  aiMetadata: { description: 'Looks up a single company profile in PredictLeads by its web domain (e.g. "stripe.com"). Use when you already know the domain and want that company\'s details. Read-only and idempotent.', idempotent: true },
  props: {
    domain: Property.ShortText({
      displayName: 'Domain',
      description: 'The domain of the company to find.',
      required: true,
    }),
  },
  async run(context) {
    const domain = context.propsValue.domain;

    const client = makeClient(
      context.auth
    );

    try {
      const response = await client.findCompanyByDomain(domain);
      return response;
    } catch (error) {
      throw new Error(JSON.stringify(error, undefined, 2));
    }
  },
});