Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.1 KB
Raw Blame
import { useCallback } from 'react';

import { useConnectorManageableChecker } from '@/hooks/useConnectorManagePolicy';

import { openConnectorEditModal } from './imperative';

interface ConfigurableConnector {
  agentId?: string | null;
  id: string;
  mcpConnectionType: string | null;
  userId?: string | null;
}

/**
 * The tool picker's "Configure" action for each connector row, one hook call
 * for the whole list. The drawer reads the stored credentials
 * (`connector.getForEdit`), so a viewer who may not manage them gets no action,
 * the rule Settings' Configure follows; while the policy loads nobody does yet.
 * A market-hosted (cloud) connector has no connection settings at all.
 */
export const useConnectorConfigure = () => {
  const checkManageable = useConnectorManageableChecker();

  return useCallback(
    (connector: ConfigurableConnector) =>
      connector.mcpConnectionType === 'cloud' || !checkManageable(connector).canManageCredentials
        ? undefined
        : { onConfigure: () => openConnectorEditModal(connector.id) },
    [checkManageable],
  );
};