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.2 KB
Raw Blame
import {
  AgentMcpTool,
  ValidateAgentMcpToolResponse,
} from '@activepieces/shared';
import { useMutation, useQuery } from '@tanstack/react-query';

import { flowsApi } from '@/features/flows/api/flows-api';
import { authenticationSession } from '@/lib/authentication-session';

import { mcpToolApi } from '../agent-tools/mcp-tool-dialog/api';

export const agentQueries = {
  useFlowsForAgent: () => {
    const projectId = authenticationSession.getProjectId();
    return useQuery({
      queryKey: ['flows', projectId],
      queryFn: async () => {
        return await flowsApi.list({
          cursor: undefined,
          limit: 1000,
          projectId: projectId!,
        });
      },
    });
  },
};

export const agentMutations = {
  useValidateMcpTool: ({
    onSuccess,
    onError,
  }: {
    onSuccess: (data: ValidateAgentMcpToolResponse) => void;
    onError: (error: Error) => void;
  }) => {
    return useMutation<
      ValidateAgentMcpToolResponse,
      Error,
      { projectId: string; tool: AgentMcpTool }
    >({
      mutationFn: ({ projectId, tool }) =>
        mcpToolApi.validateAgentMcpTool(projectId, tool),
      onSuccess,
      onError,
    });
  },
};