mirror of
https://github.com/langgenius/dify.git
synced 2026-01-06 06:26:00 +00:00
refactor(workflow): update RAG tool suggestions and improve filtering logic
This commit is contained in:
@@ -49,7 +49,10 @@ const ToolSelectorTrigger = ({
|
||||
!!selectedTagsLength && (
|
||||
<RiCloseCircleFill
|
||||
className='size-4 text-text-quaternary'
|
||||
onClick={() => onTagsChange([])}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onTagsChange([])
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export const useHiddenFieldNames = (type: PipelineInputVarType) => {
|
||||
break
|
||||
case PipelineInputVarType.checkbox:
|
||||
fieldNames = [
|
||||
t('appDebug.variableConfig.startedChecked'),
|
||||
t('appDebug.variableConfig.startChecked'),
|
||||
t('appDebug.variableConfig.tooltips'),
|
||||
]
|
||||
break
|
||||
|
||||
@@ -26,7 +26,6 @@ import { PluginType } from '../../plugins/types'
|
||||
import { useMarketplacePlugins } from '../../plugins/marketplace/hooks'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import RAGToolSuggestions from './rag-tool-suggestions'
|
||||
import { useRAGRecommendedPlugins } from '@/service/use-tools'
|
||||
|
||||
type AllToolsProps = {
|
||||
className?: string
|
||||
@@ -117,13 +116,7 @@ const AllTools = ({
|
||||
const wrapElemRef = useRef<HTMLDivElement>(null)
|
||||
const isSupportGroupView = [ToolTypeEnum.All, ToolTypeEnum.BuiltIn].includes(activeTab)
|
||||
|
||||
const isShowRAGRecommendations = isInRAGPipeline && activeTab === ToolTypeEnum.All && !searchText && tags.length === 0
|
||||
const { data: ragRecommendedPlugins } = useRAGRecommendedPlugins(isShowRAGRecommendations)
|
||||
const recommendedPlugins = useMemo(() => {
|
||||
if (ragRecommendedPlugins)
|
||||
return [...ragRecommendedPlugins.installed_recommended_plugins]
|
||||
return []
|
||||
}, [ragRecommendedPlugins])
|
||||
const isShowRAGRecommendations = isInRAGPipeline && activeTab === ToolTypeEnum.All && !hasFilter
|
||||
|
||||
return (
|
||||
<div className={cn('min-w-[400px] max-w-[500px]', className)}>
|
||||
@@ -154,9 +147,8 @@ const AllTools = ({
|
||||
className='max-h-[464px] overflow-y-auto'
|
||||
onScroll={pluginRef.current?.handleScroll}
|
||||
>
|
||||
{recommendedPlugins.length > 0 && (
|
||||
{isShowRAGRecommendations && (
|
||||
<RAGToolSuggestions
|
||||
tools={recommendedPlugins}
|
||||
viewType={isSupportGroupView ? activeView : ViewType.flat}
|
||||
onSelect={onSelect}
|
||||
onTagsChange={onTagsChange}
|
||||
|
||||
@@ -30,7 +30,7 @@ const List = forwardRef<ListRef, ListProps>(({
|
||||
disableMaxWidth = false,
|
||||
}, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const hasFilter = !searchText
|
||||
const noFilter = !searchText && tags.length === 0
|
||||
const hasRes = list.length > 0
|
||||
const urlWithSearchText = getMarketplaceUrl('', { q: searchText, tags: tags.join(',') })
|
||||
const nextToStickyELemRef = useRef<HTMLDivElement>(null)
|
||||
@@ -66,7 +66,7 @@ const List = forwardRef<ListRef, ListProps>(({
|
||||
window.open(urlWithSearchText, '_blank')
|
||||
}
|
||||
|
||||
if (hasFilter) {
|
||||
if (noFilter) {
|
||||
return (
|
||||
<Link
|
||||
className='system-sm-medium sticky bottom-0 z-10 flex h-8 cursor-pointer items-center rounded-b-lg border-[0.5px] border-t border-components-panel-border bg-components-panel-bg-blur px-4 py-1 text-text-accent-light-mode-only shadow-lg'
|
||||
@@ -108,7 +108,7 @@ const List = forwardRef<ListRef, ListProps>(({
|
||||
onAction={noop}
|
||||
/>
|
||||
))}
|
||||
{list.length > 0 && (
|
||||
{hasRes && (
|
||||
<div className='mb-3 mt-2 flex items-center justify-center space-x-2'>
|
||||
<div className="h-[2px] w-[90px] bg-gradient-to-l from-[rgba(16,24,40,0.08)] to-[rgba(255,255,255,0.01)]"></div>
|
||||
<Link
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
import type { Dispatch, SetStateAction } from 'react'
|
||||
import React, { useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { OnSelectBlock, ToolWithProvider } from '../types'
|
||||
import React, { useCallback, useMemo } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import type { OnSelectBlock } from '../types'
|
||||
import Tools from './tools'
|
||||
import { ToolTypeEnum } from './types'
|
||||
import type { ViewType } from './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'
|
||||
|
||||
type RAGToolSuggestionsProps = {
|
||||
tools: ToolWithProvider[]
|
||||
viewType: ViewType
|
||||
onSelect: OnSelectBlock
|
||||
onTagsChange: Dispatch<SetStateAction<string[]>>
|
||||
}
|
||||
|
||||
const RAGToolSuggestions: React.FC<RAGToolSuggestionsProps> = ({
|
||||
tools,
|
||||
viewType,
|
||||
onSelect,
|
||||
onTagsChange,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const {
|
||||
data: ragRecommendedPlugins,
|
||||
isFetching: isFetchingRAGRecommendedPlugins,
|
||||
} = useRAGRecommendedPlugins()
|
||||
|
||||
const recommendedPlugins = useMemo(() => {
|
||||
if (ragRecommendedPlugins)
|
||||
return [...ragRecommendedPlugins.installed_recommended_plugins]
|
||||
return []
|
||||
}, [ragRecommendedPlugins])
|
||||
|
||||
const loadMore = useCallback(() => {
|
||||
onTagsChange((prev) => {
|
||||
if (prev.includes('rag'))
|
||||
@@ -35,26 +48,52 @@ const RAGToolSuggestions: React.FC<RAGToolSuggestionsProps> = ({
|
||||
<div className='system-xs-medium px-3 pb-0.5 pt-1 text-text-tertiary'>
|
||||
{t('pipeline.ragToolSuggestions.title')}
|
||||
</div>
|
||||
<Tools
|
||||
className='p-0'
|
||||
tools={tools}
|
||||
onSelect={onSelect}
|
||||
canNotSelectMultiple
|
||||
toolType={ToolTypeEnum.All}
|
||||
viewType={viewType}
|
||||
hasSearchText={false}
|
||||
/>
|
||||
<div
|
||||
className='flex cursor-pointer items-center gap-x-2 py-1 pl-3 pr-2'
|
||||
onClick={loadMore}
|
||||
>
|
||||
<div className='px-1'>
|
||||
<RiMoreLine className='size-4 text-text-tertiary' />
|
||||
{isFetchingRAGRecommendedPlugins && (
|
||||
<div className='py-2'>
|
||||
<Loading type='app' />
|
||||
</div>
|
||||
<div className='system-xs-regular text-text-tertiary'>
|
||||
{t('common.operation.more')}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!isFetchingRAGRecommendedPlugins && recommendedPlugins.length === 0 && (
|
||||
<p className='system-xs-regular px-3 py-1 text-text-tertiary'>
|
||||
<Trans
|
||||
i18nKey='pipeline.ragToolSuggestions.noRecommendationPluginsInstalled'
|
||||
components={{
|
||||
CustomLink: (
|
||||
<Link
|
||||
className='text-text-accent'
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
href={getMarketplaceUrl('', { tags: 'rag' })}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
)}
|
||||
{!isFetchingRAGRecommendedPlugins && recommendedPlugins.length > 0 && (
|
||||
<>
|
||||
<Tools
|
||||
className='p-0'
|
||||
tools={recommendedPlugins}
|
||||
onSelect={onSelect}
|
||||
canNotSelectMultiple
|
||||
toolType={ToolTypeEnum.All}
|
||||
viewType={viewType}
|
||||
hasSearchText={false}
|
||||
/>
|
||||
<div
|
||||
className='flex cursor-pointer items-center gap-x-2 py-1 pl-3 pr-2'
|
||||
onClick={loadMore}
|
||||
>
|
||||
<div className='px-1'>
|
||||
<RiMoreLine className='size-4 text-text-tertiary' />
|
||||
</div>
|
||||
<div className='system-xs-regular text-text-tertiary'>
|
||||
{t('common.operation.more')}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -401,7 +401,6 @@ const translation = {
|
||||
'tooltips': 'Tooltips',
|
||||
'tooltipsPlaceholder': 'Enter helpful text shown when hovering over the label',
|
||||
'showAllSettings': 'Show All Settings',
|
||||
'checkbox': 'Checkbox',
|
||||
'startSelectedOption': 'Start selected option',
|
||||
'noDefaultSelected': 'Don\'t select',
|
||||
'hide': 'Hide',
|
||||
|
||||
@@ -33,6 +33,7 @@ const translation = {
|
||||
},
|
||||
ragToolSuggestions: {
|
||||
title: 'Suggestions for RAG',
|
||||
noRecommendationPluginsInstalled: 'No recommended plugins installed, find more in <CustomLink>Marketplace</CustomLink>',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -397,7 +397,6 @@ const translation = {
|
||||
'tooltips': '提示',
|
||||
'tooltipsPlaceholder': '输入悬停在标签上时显示的提示文本',
|
||||
'showAllSettings': '显示所有设置',
|
||||
'checkbox': '复选框',
|
||||
'startSelectedOption': '默认选中项',
|
||||
'noDefaultSelected': '不默认选中',
|
||||
'file': {
|
||||
|
||||
@@ -33,6 +33,7 @@ const translation = {
|
||||
},
|
||||
ragToolSuggestions: {
|
||||
title: 'RAG 工具推荐',
|
||||
noRecommendationPluginsInstalled: '暂无已安装的推荐插件,更多插件请在 <CustomLink>Marketplace</CustomLink> 中查找',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import { useInvalidateAllBuiltInTools } from './use-tools'
|
||||
import { useInvalidateAllBuiltInTools, useInvalidateRAGRecommendedPlugins } from './use-tools'
|
||||
import useReferenceSetting from '@/app/components/plugins/plugin-page/use-reference-setting'
|
||||
import { uninstallPlugin } from '@/service/plugins'
|
||||
import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list'
|
||||
@@ -135,12 +135,14 @@ export const useInstalledLatestVersion = (pluginIds: string[]) => {
|
||||
export const useInvalidateInstalledPluginList = () => {
|
||||
const queryClient = useQueryClient()
|
||||
const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
|
||||
const invalidateRAGRecommendedPlugins = useInvalidateRAGRecommendedPlugins()
|
||||
return () => {
|
||||
queryClient.invalidateQueries(
|
||||
{
|
||||
queryKey: useInstalledPluginListKey,
|
||||
})
|
||||
invalidateAllBuiltInTools()
|
||||
invalidateRAGRecommendedPlugins()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,10 +312,15 @@ export const useRemoveProviderCredentials = ({
|
||||
})
|
||||
}
|
||||
|
||||
export const useRAGRecommendedPlugins = (enabled: boolean) => {
|
||||
const useRAGRecommendedPluginListKey = [NAME_SPACE, 'rag-recommended-plugins']
|
||||
|
||||
export const useRAGRecommendedPlugins = () => {
|
||||
return useQuery<RAGRecommendedPlugins>({
|
||||
queryKey: [NAME_SPACE, 'rag-recommended-plugins'],
|
||||
queryKey: useRAGRecommendedPluginListKey,
|
||||
queryFn: () => get<RAGRecommendedPlugins>('/rag/pipelines/recommended-plugins'),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateRAGRecommendedPlugins = () => {
|
||||
return useInvalid(useRAGRecommendedPluginListKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user