import type { Dispatch, SetStateAction } from 'react' import React, { useCallback, useMemo } from 'react' import { Trans, useTranslation } from 'react-i18next' import type { OnSelectBlock } from '@/app/components/workflow/types' import type { ViewType } from '@/app/components/workflow/block-selector/view-type-select' import { RiMoreLine } from '@remixicon/react' import Loading from '@/app/components/base/loading' import Link from 'next/link' import { getMarketplaceUrl } from '@/utils/var' import { useRAGRecommendedPlugins } from '@/service/use-tools' import List from './list' import { getFormattedPlugin } from '@/app/components/plugins/marketplace/utils' type RAGToolRecommendationsProps = { viewType: ViewType onSelect: OnSelectBlock onTagsChange: Dispatch> } const RAGToolRecommendations = ({ viewType, onSelect, onTagsChange, }: RAGToolRecommendationsProps) => { const { t } = useTranslation() const { data: ragRecommendedPlugins, isLoading: isLoadingRAGRecommendedPlugins, isFetching: isFetchingRAGRecommendedPlugins, } = useRAGRecommendedPlugins() const recommendedPlugins = useMemo(() => { if (ragRecommendedPlugins) return ragRecommendedPlugins.installed_recommended_plugins return [] }, [ragRecommendedPlugins]) const unInstalledPlugins = useMemo(() => { if (ragRecommendedPlugins) return (ragRecommendedPlugins.uninstalled_recommended_plugins).map(getFormattedPlugin) return [] }, [ragRecommendedPlugins]) const loadMore = useCallback(() => { onTagsChange((prev) => { if (prev.includes('rag')) return prev return [...prev, 'rag'] }) }, [onTagsChange]) return (
{t('pipeline.ragToolSuggestions.title')}
{/* For first time loading, show loading */} {isLoadingRAGRecommendedPlugins && (
)} {!isFetchingRAGRecommendedPlugins && recommendedPlugins.length === 0 && unInstalledPlugins.length === 0 && (

), }} />

)} {(recommendedPlugins.length > 0 || unInstalledPlugins.length > 0) && ( <>
{t('common.operation.more')}
)}
) } export default React.memo(RAGToolRecommendations)