feat: Introduce RAG tool recommendations and refactor related components for improved plugin management (#27259)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Wu Tianwei
2025-10-28 10:22:16 +08:00
committed by GitHub
parent ff32dff163
commit 0e62a66cc2
32 changed files with 490 additions and 288 deletions

View File

@@ -45,14 +45,19 @@ import { getNodeUsedVars, isSpecialVar } from '../nodes/_base/components/variabl
import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { KnowledgeBaseNodeType } from '../nodes/knowledge-base/types'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllWorkflowTools,
} from '@/service/use-tools'
export const useChecklist = (nodes: Node[], edges: Edge[]) => {
const { t } = useTranslation()
const language = useGetLanguage()
const { nodesMap: nodesExtraData } = useNodesMetaData()
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const dataSourceList = useStore(s => s.dataSourceList)
const { data: strategyProviders } = useStrategyProviders()
const datasetsDetail = useDatasetsDetailStore(s => s.datasetsDetail)
@@ -104,7 +109,7 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
let usedVars: ValueSelector[] = []
if (node.data.type === BlockEnum.Tool)
moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools, customTools, workflowTools, language)
moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools || [], customTools || [], workflowTools || [], language)
if (node.data.type === BlockEnum.DataSource)
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
@@ -194,6 +199,9 @@ export const useChecklistBeforePublish = () => {
const { getNodesAvailableVarList } = useGetNodesAvailableVarList()
const { data: embeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
const { data: rerankModelList } = useModelList(ModelTypeEnum.rerank)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const getCheckData = useCallback((data: CommonNodeType<{}>, datasets: DataSet[]) => {
let checkData = data
@@ -221,7 +229,7 @@ export const useChecklistBeforePublish = () => {
} as CommonNodeType<KnowledgeBaseNodeType>
}
return checkData
}, [])
}, [embeddingModelList, rerankModelList])
const handleCheckBeforePublish = useCallback(async () => {
const {
@@ -230,9 +238,6 @@ export const useChecklistBeforePublish = () => {
} = store.getState()
const {
dataSourceList,
buildInTools,
customTools,
workflowTools,
} = workflowStore.getState()
const nodes = getNodes()
const filteredNodes = nodes.filter(node => node.type === CUSTOM_NODE)
@@ -275,7 +280,7 @@ export const useChecklistBeforePublish = () => {
let moreDataForCheckValid
let usedVars: ValueSelector[] = []
if (node.data.type === BlockEnum.Tool)
moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools, customTools, workflowTools, language)
moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools || [], customTools || [], workflowTools || [], language)
if (node.data.type === BlockEnum.DataSource)
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
@@ -340,7 +345,7 @@ export const useChecklistBeforePublish = () => {
}
return true
}, [store, notify, t, language, nodesExtraData, strategyProviders, updateDatasetsDetail, getCheckData, getStartNodes, workflowStore])
}, [store, notify, t, language, nodesExtraData, strategyProviders, updateDatasetsDetail, getCheckData, getStartNodes, workflowStore, buildInTools, customTools, workflowTools])
return {
handleCheckBeforePublish,

View File

@@ -11,6 +11,12 @@ import useMatchSchemaType, { getMatchedSchemaType } from '../nodes/_base/compone
import { toNodeOutputVars } from '../nodes/_base/components/variable/utils'
import type { SchemaTypeDefinition } from '@/service/use-common'
import { useCallback } from 'react'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllMCPTools,
useAllWorkflowTools,
} from '@/service/use-tools'
type Params = {
flowType: FlowType
@@ -27,17 +33,17 @@ export const useSetWorkflowVarsWithValue = ({
const invalidateSysVarValues = useInvalidateSysVarValues(flowType, flowId)
const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync()
const { schemaTypeDefinitions } = useMatchSchemaType()
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const mcpTools = useStore(s => s.mcpTools)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const { data: mcpTools } = useAllMCPTools()
const dataSourceList = useStore(s => s.dataSourceList)
const allPluginInfoList = {
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList: dataSourceList ?? [],
buildInTools: buildInTools || [],
customTools: customTools || [],
workflowTools: workflowTools || [],
mcpTools: mcpTools || [],
dataSourceList: dataSourceList || [],
}
const setInspectVarsToStore = (inspectVars: VarInInspect[], passedInAllPluginInfoList?: Record<string, ToolWithProvider[]>, passedInSchemaTypeDefinitions?: SchemaTypeDefinition[]) => {

View File

@@ -18,6 +18,12 @@ import type { FlowType } from '@/types/common'
import useFLow from '@/service/use-flow'
import { useStoreApi } from 'reactflow'
import type { SchemaTypeDefinition } from '@/service/use-common'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllMCPTools,
useAllWorkflowTools,
} from '@/service/use-tools'
type Params = {
flowId: string
@@ -51,6 +57,11 @@ export const useInspectVarsCrudCommon = ({
const { mutateAsync: doEditInspectorVar } = useEditInspectorVar(flowId)
const { handleCancelNodeSuccessStatus } = useNodesInteractionsWithoutSync()
const { handleEdgeCancelRunningStatus } = useEdgesInteractionsWithoutSync()
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const { data: mcpTools } = useAllMCPTools()
const getNodeInspectVars = useCallback((nodeId: string) => {
const { nodesWithInspectVars } = workflowStore.getState()
const node = nodesWithInspectVars.find(node => node.nodeId === nodeId)
@@ -98,10 +109,6 @@ export const useInspectVarsCrudCommon = ({
const fetchInspectVarValue = useCallback(async (selector: ValueSelector, schemaTypeDefinitions: SchemaTypeDefinition[]) => {
const {
setNodeInspectVars,
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList,
} = workflowStore.getState()
const nodeId = selector[0]
@@ -119,11 +126,11 @@ export const useInspectVarsCrudCommon = ({
const nodeArr = getNodes()
const currentNode = nodeArr.find(node => node.id === nodeId)
const allPluginInfoList = {
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList: dataSourceList ?? [],
buildInTools: buildInTools || [],
customTools: customTools || [],
workflowTools: workflowTools || [],
mcpTools: mcpTools || [],
dataSourceList: dataSourceList || [],
}
const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], allPluginInfoList, schemaTypeDefinitions)
const vars = await fetchNodeInspectVars(flowType, flowId, nodeId)
@@ -135,7 +142,7 @@ export const useInspectVarsCrudCommon = ({
}
})
setNodeInspectVars(nodeId, varsWithSchemaType)
}, [workflowStore, flowType, flowId, invalidateSysVarValues, invalidateConversationVarValues])
}, [workflowStore, flowType, flowId, invalidateSysVarValues, invalidateConversationVarValues, buildInTools, customTools, workflowTools, mcpTools])
// after last run would call this
const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => {

View File

@@ -7,6 +7,11 @@ import { CollectionType } from '@/app/components/tools/types'
import { useStore } from '@/app/components/workflow/store'
import { canFindTool } from '@/utils'
import { useGetLanguage } from '@/context/i18n'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllWorkflowTools,
} from '@/service/use-tools'
export const useNodesMetaData = () => {
const availableNodesMetaData = useHooksStore(s => s.availableNodesMetaData)
@@ -21,9 +26,9 @@ export const useNodesMetaData = () => {
export const useNodeMetaData = (node: Node) => {
const language = useGetLanguage()
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const dataSourceList = useStore(s => s.dataSourceList)
const availableNodesMetaData = useNodesMetaData()
const { data } = node
@@ -34,10 +39,10 @@ export const useNodeMetaData = (node: Node) => {
if (data.type === BlockEnum.Tool) {
if (data.provider_type === CollectionType.builtIn)
return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.author
return buildInTools?.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.author
if (data.provider_type === CollectionType.workflow)
return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
return customTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
return workflowTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
return customTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
}
return nodeMetaData?.metaData.author
}, [data, buildInTools, customTools, workflowTools, nodeMetaData, dataSourceList])
@@ -47,10 +52,10 @@ export const useNodeMetaData = (node: Node) => {
return dataSourceList?.find(dataSource => dataSource.plugin_id === data.plugin_id)?.description[language]
if (data.type === BlockEnum.Tool) {
if (data.provider_type === CollectionType.builtIn)
return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.description[language]
return buildInTools?.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.description[language]
if (data.provider_type === CollectionType.workflow)
return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]
return customTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]
return workflowTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]
return customTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]
}
return nodeMetaData?.metaData.description
}, [data, buildInTools, customTools, workflowTools, nodeMetaData, dataSourceList, language])

View File

@@ -14,12 +14,18 @@ import {
} from '../store'
import { CollectionType } from '@/app/components/tools/types'
import { canFindTool } from '@/utils'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllMCPTools,
useAllWorkflowTools,
} from '@/service/use-tools'
export const useToolIcon = (data?: Node['data']) => {
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const mcpTools = useStore(s => s.mcpTools)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const { data: mcpTools } = useAllMCPTools()
const dataSourceList = useStore(s => s.dataSourceList)
// const a = useStore(s => s.data)
const toolIcon = useMemo(() => {
@@ -27,15 +33,15 @@ export const useToolIcon = (data?: Node['data']) => {
return ''
if (data.type === BlockEnum.Tool) {
// eslint-disable-next-line sonarjs/no-dead-store
let targetTools = buildInTools
let targetTools = buildInTools || []
if (data.provider_type === CollectionType.builtIn)
targetTools = buildInTools
targetTools = buildInTools || []
else if (data.provider_type === CollectionType.custom)
targetTools = customTools
targetTools = customTools || []
else if (data.provider_type === CollectionType.mcp)
targetTools = mcpTools
targetTools = mcpTools || []
else
targetTools = workflowTools
targetTools = workflowTools || []
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
}
if (data.type === BlockEnum.DataSource)
@@ -46,24 +52,24 @@ export const useToolIcon = (data?: Node['data']) => {
}
export const useGetToolIcon = () => {
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const workflowStore = useWorkflowStore()
const getToolIcon = useCallback((data: Node['data']) => {
const {
buildInTools,
customTools,
workflowTools,
dataSourceList,
} = workflowStore.getState()
if (data.type === BlockEnum.Tool) {
// eslint-disable-next-line sonarjs/no-dead-store
let targetTools = buildInTools
let targetTools = buildInTools || []
if (data.provider_type === CollectionType.builtIn)
targetTools = buildInTools
targetTools = buildInTools || []
else if (data.provider_type === CollectionType.custom)
targetTools = customTools
targetTools = customTools || []
else
targetTools = workflowTools
targetTools = workflowTools || []
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
}

View File

@@ -8,11 +8,16 @@ import { workflowNodesAction } from '@/app/components/goto-anything/actions/work
import BlockIcon from '@/app/components/workflow/block-icon'
import { setupNodeSelectionListener } from '../utils/node-navigation'
import { BlockEnum } from '../types'
import { useStore } from '../store'
import type { Emoji } from '@/app/components/tools/types'
import { CollectionType } from '@/app/components/tools/types'
import { canFindTool } from '@/utils'
import type { LLMNodeType } from '../nodes/llm/types'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllMCPTools,
useAllWorkflowTools,
} from '@/service/use-tools'
/**
* Hook to register workflow nodes search functionality
@@ -22,23 +27,23 @@ export const useWorkflowSearch = () => {
const { handleNodeSelect } = useNodesInteractions()
// Filter and process nodes for search
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const mcpTools = useStore(s => s.mcpTools)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const { data: mcpTools } = useAllMCPTools()
// Extract tool icon logic - clean separation of concerns
const getToolIcon = useCallback((nodeData: CommonNodeType): string | Emoji | undefined => {
if (nodeData?.type !== BlockEnum.Tool) return undefined
const toolCollections: Record<string, any[]> = {
[CollectionType.builtIn]: buildInTools,
[CollectionType.custom]: customTools,
[CollectionType.mcp]: mcpTools,
[CollectionType.builtIn]: buildInTools || [],
[CollectionType.custom]: customTools || [],
[CollectionType.mcp]: mcpTools || [],
}
const targetTools = (nodeData.provider_type && toolCollections[nodeData.provider_type]) || workflowTools
return targetTools.find((tool: any) => canFindTool(tool.id, nodeData.provider_id))?.icon
return targetTools?.find((tool: any) => canFindTool(tool.id, nodeData.provider_id))?.icon
}, [buildInTools, customTools, workflowTools, mcpTools])
// Extract model info logic - clean extraction

View File

@@ -10,20 +10,25 @@ import type {
} from '@/app/components/workflow/types'
import { useIsChatMode } from './use-workflow'
import { useStoreApi } from 'reactflow'
import { useStore } from '@/app/components/workflow/store'
import type { Type } from '../nodes/llm/types'
import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type'
import {
useAllBuiltInTools,
useAllCustomTools,
useAllMCPTools,
useAllWorkflowTools,
} from '@/service/use-tools'
export const useWorkflowVariables = () => {
const { t } = useTranslation()
const workflowStore = useWorkflowStore()
const { schemaTypeDefinitions } = useMatchSchemaType()
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
const mcpTools = useStore(s => s.mcpTools)
const dataSourceList = useStore(s => s.dataSourceList)
const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools()
const { data: workflowTools } = useAllWorkflowTools()
const { data: mcpTools } = useAllMCPTools()
const getNodeAvailableVars = useCallback(({
parentNode,
beforeNodes,
@@ -43,6 +48,7 @@ export const useWorkflowVariables = () => {
conversationVariables,
environmentVariables,
ragPipelineVariables,
dataSourceList,
} = workflowStore.getState()
return toNodeAvailableVars({
parentNode,
@@ -54,15 +60,15 @@ export const useWorkflowVariables = () => {
ragVariables: ragPipelineVariables,
filterVar,
allPluginInfoList: {
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList: dataSourceList ?? [],
buildInTools: buildInTools || [],
customTools: customTools || [],
workflowTools: workflowTools || [],
mcpTools: mcpTools || [],
dataSourceList: dataSourceList || [],
},
schemaTypeDefinitions,
})
}, [t, workflowStore, schemaTypeDefinitions, buildInTools])
}, [t, workflowStore, schemaTypeDefinitions, buildInTools, customTools, workflowTools, mcpTools])
const getCurrentVariableType = useCallback(({
parentNode,
@@ -87,10 +93,6 @@ export const useWorkflowVariables = () => {
conversationVariables,
environmentVariables,
ragPipelineVariables,
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList,
} = workflowStore.getState()
return getVarType({
@@ -105,16 +107,16 @@ export const useWorkflowVariables = () => {
conversationVariables,
ragVariables: ragPipelineVariables,
allPluginInfoList: {
buildInTools,
customTools,
workflowTools,
mcpTools,
buildInTools: buildInTools || [],
customTools: customTools || [],
workflowTools: workflowTools || [],
mcpTools: mcpTools || [],
dataSourceList: dataSourceList ?? [],
},
schemaTypeDefinitions,
preferSchemaType,
})
}, [workflowStore, getVarType, schemaTypeDefinitions])
}, [workflowStore, getVarType, schemaTypeDefinitions, buildInTools, customTools, workflowTools, mcpTools])
return {
getNodeAvailableVars,

View File

@@ -32,15 +32,9 @@ import { CUSTOM_NOTE_NODE } from '../note-node/constants'
import { findUsedVarNodes, getNodeOutputVars, updateNodeVars } from '../nodes/_base/components/variable/utils'
import { useAvailableBlocks } from './use-available-blocks'
import { useStore as useAppStore } from '@/app/components/app/store'
import {
fetchAllBuiltInTools,
fetchAllCustomTools,
fetchAllMCPTools,
fetchAllWorkflowTools,
} from '@/service/tools'
import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
import { CUSTOM_LOOP_START_NODE } from '@/app/components/workflow/nodes/loop-start/constants'
import { basePath } from '@/utils/var'
import { useNodesMetaData } from '.'
export const useIsChatMode = () => {
@@ -416,51 +410,6 @@ export const useWorkflow = () => {
}
}
export const useFetchToolsData = () => {
const workflowStore = useWorkflowStore()
const handleFetchAllTools = useCallback(async (type: string) => {
if (type === 'builtin') {
const buildInTools = await fetchAllBuiltInTools()
if (basePath) {
buildInTools.forEach((item) => {
if (typeof item.icon == 'string' && !item.icon.includes(basePath))
item.icon = `${basePath}${item.icon}`
})
}
workflowStore.setState({
buildInTools: buildInTools || [],
})
}
if (type === 'custom') {
const customTools = await fetchAllCustomTools()
workflowStore.setState({
customTools: customTools || [],
})
}
if (type === 'workflow') {
const workflowTools = await fetchAllWorkflowTools()
workflowStore.setState({
workflowTools: workflowTools || [],
})
}
if (type === 'mcp') {
const mcpTools = await fetchAllMCPTools()
workflowStore.setState({
mcpTools: mcpTools || [],
})
}
}, [workflowStore])
return {
handleFetchAllTools,
}
}
export const useWorkflowReadOnly = () => {
const workflowStore = useWorkflowStore()
const workflowRunningData = useStore(s => s.workflowRunningData)