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.4 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { browseAiApiCall } from '../common/client';
import { browseAiAuth } from '../common/auth';

export const listRobotsAction = createAction({
  name: 'list-robots',
  classification: 'SEARCH',
  auth: browseAiAuth,
  displayName: 'List Robots',
  description: 'Retrieves all robots available in your account.',
  audience: 'both',
  aiMetadata: {
    description:
      'Lists all Browse AI robots in the connected account, returning each robot and its ID. Use to discover the available robots or resolve a robot name to the ID needed by other Browse AI actions. Takes no input; read-only and idempotent.',
    idempotent: true,
  },
  props: {},
  async run(context) {
    try {
      const response = await browseAiApiCall({
        auth: { apiKey: context.auth.secret_text },
        method: HttpMethod.GET,
        resourceUri: '/robots',
      });

      return response;
    } catch (error: any) {
      if (error.response?.status === 401) {
        throw new Error('Authentication failed. Please check your API key.');
      }

      if (error.response?.status === 429) {
        throw new Error('Rate limit exceeded. Please wait before retrying.');
      }

      throw new Error(
        `Failed to fetch robots: ${error.message || 'Unknown error occurred'}`
      );
    }
  },
});