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

9.9 KB
Raw Blame
import { OutputSchema } from '@activepieces/pieces-framework';

const pageContentFields: OutputSchema['fields'] = [
  { key: 'markdown', label: 'Markdown' },
  { key: 'html', label: 'HTML', format: 'html' },
  { key: 'rawHtml', label: 'Raw HTML', format: 'html' },
  { key: 'links', label: 'Links' },
  { key: 'summary', label: 'Summary' },
  {
    key: 'screenshot',
    label: 'Screenshot',
    children: [
      { key: 'fileName', label: 'File Name' },
      { key: 'fileUrl', label: 'File URL', format: 'url' },
    ],
  },
];

const pageMetadataField: OutputSchema['fields'][number] = {
  key: 'metadata',
  label: 'Metadata',
  children: [
    { key: 'title', label: 'Title' },
    { key: 'language', label: 'Language' },
    { key: 'sourceURL', label: 'Source URL', format: 'url' },
    { key: 'url', label: 'Final URL', format: 'url' },
    { key: 'statusCode', label: 'Status Code', format: 'number' },
    { key: 'favicon', label: 'Favicon', format: 'image' },
    { key: 'creditsUsed', label: 'Credits Used', format: 'number' },
  ],
};

const scrapeActionsField: OutputSchema['fields'][number] = {
  key: 'actions',
  label: 'Actions',
  children: [
    {
      key: 'pdfs',
      label: 'PDF',
      listItems: [
        { key: 'fileName', label: 'File Name' },
        { key: 'fileUrl', label: 'File URL', format: 'url' },
      ],
    },
    {
      key: 'screenshots',
      label: 'Screenshots',
      listItems: [
        { key: 'fileName', label: 'File Name' },
        { key: 'fileUrl', label: 'File URL', format: 'url' },
      ],
    },
    {
      key: 'javascriptReturns',
      label: 'JavaScript Returns',
      listItems: [
        { key: 'type', label: 'Type' },
        { key: 'value', label: 'Value' },
      ],
    },
    {
      key: 'scrapes',
      label: 'Scrapes',
      labelKey: 'url',
      listItems: [
        { key: 'url', label: 'URL', format: 'url' },
        { key: 'html', label: 'HTML', format: 'html' },
      ],
    },
  ],
};

const pageWarningField: OutputSchema['fields'][number] = { key: 'warning', label: 'Warning' };

const pageResultFields: OutputSchema['fields'] = [
  ...pageContentFields,
  pageWarningField,
  pageMetadataField,
];

const scrapeResultFields: OutputSchema['fields'] = [
  ...pageContentFields,
  scrapeActionsField,
  pageWarningField,
  pageMetadataField,
];

export const scrapeActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'data', label: 'Data', children: scrapeResultFields },
  ],
};

export const scrapeUrlActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'data', label: 'Data', children: pageResultFields },
  ],
};

const jobResultFields: OutputSchema['fields'] = [
  { key: 'success', label: 'Success', format: 'boolean' },
  { key: 'status', label: 'Status' },
  { key: 'completed', label: 'Completed', format: 'number' },
  { key: 'total', label: 'Total', format: 'number' },
  { key: 'creditsUsed', label: 'Credits Used', format: 'number' },
  { key: 'expiresAt', label: 'Expires At', format: 'datetime' },
  { key: 'next', label: 'Next Page URL', format: 'url' },
  { key: 'data', label: 'Pages', listItems: pageResultFields },
];

export const crawlWebsiteActionOutputSchema: OutputSchema = {
  fields: jobResultFields,
};

export const crawlActionOutputSchema: OutputSchema = {
  fields: [
    ...jobResultFields.filter((field) => field.key !== 'data'),
    {
      key: 'data',
      label: 'Pages',
      listItems: [...pageResultFields, { key: 'screenshotError', label: 'Screenshot Error' }],
    },
  ],
};

export const getCrawlResultsActionOutputSchema: OutputSchema = {
  fields: jobResultFields,
};

export const getBatchScrapeResultsActionOutputSchema: OutputSchema = {
  fields: [
    ...jobResultFields,
    { key: 'createdAt', label: 'Created At', format: 'datetime' },
    { key: 'completedAt', label: 'Completed At', format: 'datetime' },
    { key: 'duration', label: 'Duration (ms)', format: 'number' },
  ],
};

const jobErrorFields: OutputSchema['fields'] = [
  {
    key: 'errors',
    label: 'Errors',
    labelKey: 'url',
    listItems: [
      { key: 'id', label: 'ID' },
      { key: 'url', label: 'URL', format: 'url' },
      { key: 'code', label: 'Error Code' },
      { key: 'error', label: 'Error Message' },
      { key: 'timestamp', label: 'Timestamp', format: 'datetime' },
    ],
  },
  { key: 'robotsBlocked', label: 'Robots-Blocked URLs' },
];

export const getCrawlErrorsActionOutputSchema: OutputSchema = {
  fields: jobErrorFields,
};

export const getBatchScrapeErrorsActionOutputSchema: OutputSchema = {
  fields: jobErrorFields,
};

export const cancelCrawlActionOutputSchema: OutputSchema = {
  fields: [{ key: 'status', label: 'Status' }],
};

export const cancelBatchScrapeActionOutputSchema: OutputSchema = cancelCrawlActionOutputSchema;

export const batchScrapeActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'id', label: 'Job ID' },
    { key: 'url', label: 'Status URL', format: 'url' },
    { key: 'invalidURLs', label: 'Invalid URLs' },
  ],
};

export const mapWebsiteActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'links', label: 'Links' },
  ],
};

export const searchWebActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    {
      key: 'data',
      label: 'Data',
      children: [
        {
          key: 'web',
          label: 'Web Results',
          labelKey: 'title',
          listItems: [
            { key: 'url', label: 'URL', format: 'url' },
            { key: 'title', label: 'Title' },
            { key: 'description', label: 'Description' },
            { key: 'position', label: 'Position', format: 'number' },
            { key: 'markdown', label: 'Markdown' },
            {
              key: 'metadata',
              label: 'Metadata',
              children: [
                { key: 'title', label: 'Title' },
                { key: 'sourceURL', label: 'Source URL', format: 'url' },
                { key: 'url', label: 'Final URL', format: 'url' },
                { key: 'statusCode', label: 'Status Code', format: 'number' },
              ],
            },
          ],
        },
        {
          key: 'news',
          label: 'News Results',
          labelKey: 'title',
          listItems: [
            { key: 'url', label: 'URL', format: 'url' },
            { key: 'title', label: 'Title' },
            { key: 'snippet', label: 'Snippet' },
            { key: 'description', label: 'Description' },
            { key: 'date', label: 'Date' },
            { key: 'imageUrl', label: 'Image URL', format: 'image' },
            { key: 'position', label: 'Position', format: 'number' },
            { key: 'markdown', label: 'Markdown' },
            {
              key: 'metadata',
              label: 'Metadata',
              children: [
                { key: 'title', label: 'Title' },
                { key: 'sourceURL', label: 'Source URL', format: 'url' },
                { key: 'url', label: 'Final URL', format: 'url' },
                { key: 'statusCode', label: 'Status Code', format: 'number' },
              ],
            },
          ],
        },
        {
          key: 'images',
          label: 'Image Results',
          labelKey: 'title',
          listItems: [
            { key: 'title', label: 'Title' },
            { key: 'imageUrl', label: 'Image URL', format: 'image' },
            { key: 'imageWidth', label: 'Image Width', format: 'number' },
            { key: 'imageHeight', label: 'Image Height', format: 'number' },
            { key: 'url', label: 'Page URL', format: 'url' },
            { key: 'description', label: 'Description' },
            { key: 'position', label: 'Position', format: 'number' },
            { key: 'markdown', label: 'Markdown' },
            {
              key: 'metadata',
              label: 'Metadata',
              children: [
                { key: 'title', label: 'Title' },
                { key: 'sourceURL', label: 'Source URL', format: 'url' },
                { key: 'url', label: 'Final URL', format: 'url' },
                { key: 'statusCode', label: 'Status Code', format: 'number' },
              ],
            },
          ],
        },
      ],
    },
    { key: 'creditsUsed', label: 'Credits Used', format: 'number' },
    { key: 'id', label: 'Search ID' },
  ],
};

export const listActiveCrawlsActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    {
      key: 'crawls',
      label: 'Crawls',
      labelKey: 'url',
      listItems: [
        { key: 'id', label: 'Crawl ID' },
        { key: 'teamId', label: 'Team ID' },
        { key: 'url', label: 'URL', format: 'url' },
        { key: 'created_at', label: 'Created At', format: 'datetime' },
      ],
    },
  ],
};

export const extractDataActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'data', label: 'Data' },
    { key: 'status', label: 'Status' },
    { key: 'expiresAt', label: 'Expires At', format: 'datetime' },
    { key: 'tokensUsed', label: 'Tokens Used', format: 'number' },
    { key: 'creditsUsed', label: 'Credits Used', format: 'number' },
    { key: 'warnings', label: 'Warnings' },
  ],
};

export const startAgentActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'id', label: 'Agent Job ID' },
  ],
};

export const getAgentStatusActionOutputSchema: OutputSchema = {
  fields: [
    { key: 'success', label: 'Success', format: 'boolean' },
    { key: 'status', label: 'Status' },
    { key: 'data', label: 'Result' },
    { key: 'model', label: 'Model' },
    { key: 'expiresAt', label: 'Expires At', format: 'datetime' },
    { key: 'creditsUsed', label: 'Credits Used', format: 'number' },
  ],
};