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.0 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { PromptHubClient } from '../common/client';
import { listProjectsProps } from '../common/props';
import { listProjectsActionOutputSchema } from '../output-schemas';
import { prompthubAuth } from '../..';

export const listProjects = createAction({
  name: 'list_projects',
  displayName: 'List Projects',
  description: 'List PromptHub projects for a team. Returns information about each project\'s head revision and groups.',
  aiMetadata: { description: 'List the prompt projects belonging to a PromptHub team, each with its head revision and group assignments. Use this to discover available projects and their IDs before reading a head or running a prompt; optional group/model/provider filters narrow the results. Read-only and idempotent. Requires the numeric team ID.', idempotent: true },
  props: listProjectsProps,
  auth: prompthubAuth,
  outputSchema: listProjectsActionOutputSchema,
  async run({ auth, propsValue }) {
    const client = new PromptHubClient(auth.secret_text);
    const result = await client.listProjects(propsValue['teamId'], {
      group: propsValue['group'],
      model: propsValue['model'],
      provider: propsValue['provider'],
    });
    
    const data = result?.data ?? result;
    return Array.isArray(data)
      ? data.map((p: any) => ({
          id: p.id,
          name: p.name,
          description: p.description,
          head: p.head ? {
            provider: p.head.provider,
            model: p.head.model,
            prompt: p.head.prompt,
            system_message: p.head.system_message,
            formatted_request: p.head.formatted_request,
            hash: p.head.hash,
            commit_title: p.head.commit_title,
            commit_description: p.head.commit_description,
            variables: p.head.variables,
            branch: p.head.branch,
            configuration: p.head.configuration,
          } : null,
          groups: p.groups || [],
        }))
      : data;
  },
});