mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 21:23:22 +08:00
refactor: replace useStore hooks with useAll*Tools hooks for better data fetching in workflow components
This commit is contained in:
parent
f3b63e5126
commit
dc21ab5f59
@ -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 { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
import type { KnowledgeBaseNodeType } from '../nodes/knowledge-base/types'
|
import type { KnowledgeBaseNodeType } from '../nodes/knowledge-base/types'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
export const useChecklist = (nodes: Node[], edges: Edge[]) => {
|
export const useChecklist = (nodes: Node[], edges: Edge[]) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const language = useGetLanguage()
|
const language = useGetLanguage()
|
||||||
const { nodesMap: nodesExtraData } = useNodesMetaData()
|
const { nodesMap: nodesExtraData } = useNodesMetaData()
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
const { data: strategyProviders } = useStrategyProviders()
|
const { data: strategyProviders } = useStrategyProviders()
|
||||||
const datasetsDetail = useDatasetsDetailStore(s => s.datasetsDetail)
|
const datasetsDetail = useDatasetsDetailStore(s => s.datasetsDetail)
|
||||||
@ -104,7 +109,7 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
|
|||||||
let usedVars: ValueSelector[] = []
|
let usedVars: ValueSelector[] = []
|
||||||
|
|
||||||
if (node.data.type === BlockEnum.Tool)
|
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)
|
if (node.data.type === BlockEnum.DataSource)
|
||||||
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
|
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
|
||||||
@ -194,6 +199,9 @@ export const useChecklistBeforePublish = () => {
|
|||||||
const { getNodesAvailableVarList } = useGetNodesAvailableVarList()
|
const { getNodesAvailableVarList } = useGetNodesAvailableVarList()
|
||||||
const { data: embeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
|
const { data: embeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
|
||||||
const { data: rerankModelList } = useModelList(ModelTypeEnum.rerank)
|
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[]) => {
|
const getCheckData = useCallback((data: CommonNodeType<{}>, datasets: DataSet[]) => {
|
||||||
let checkData = data
|
let checkData = data
|
||||||
@ -230,9 +238,6 @@ export const useChecklistBeforePublish = () => {
|
|||||||
} = store.getState()
|
} = store.getState()
|
||||||
const {
|
const {
|
||||||
dataSourceList,
|
dataSourceList,
|
||||||
buildInTools,
|
|
||||||
customTools,
|
|
||||||
workflowTools,
|
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const nodes = getNodes()
|
const nodes = getNodes()
|
||||||
const filteredNodes = nodes.filter(node => node.type === CUSTOM_NODE)
|
const filteredNodes = nodes.filter(node => node.type === CUSTOM_NODE)
|
||||||
@ -275,7 +280,7 @@ export const useChecklistBeforePublish = () => {
|
|||||||
let moreDataForCheckValid
|
let moreDataForCheckValid
|
||||||
let usedVars: ValueSelector[] = []
|
let usedVars: ValueSelector[] = []
|
||||||
if (node.data.type === BlockEnum.Tool)
|
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)
|
if (node.data.type === BlockEnum.DataSource)
|
||||||
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
|
moreDataForCheckValid = getDataSourceCheckParams(node.data as DataSourceNodeType, dataSourceList || [], language)
|
||||||
@ -340,7 +345,7 @@ export const useChecklistBeforePublish = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
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 {
|
return {
|
||||||
handleCheckBeforePublish,
|
handleCheckBeforePublish,
|
||||||
|
|||||||
@ -11,6 +11,12 @@ import useMatchSchemaType, { getMatchedSchemaType } from '../nodes/_base/compone
|
|||||||
import { toNodeOutputVars } from '../nodes/_base/components/variable/utils'
|
import { toNodeOutputVars } from '../nodes/_base/components/variable/utils'
|
||||||
import type { SchemaTypeDefinition } from '@/service/use-common'
|
import type { SchemaTypeDefinition } from '@/service/use-common'
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
flowType: FlowType
|
flowType: FlowType
|
||||||
@ -27,17 +33,17 @@ export const useSetWorkflowVarsWithValue = ({
|
|||||||
const invalidateSysVarValues = useInvalidateSysVarValues(flowType, flowId)
|
const invalidateSysVarValues = useInvalidateSysVarValues(flowType, flowId)
|
||||||
const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync()
|
const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync()
|
||||||
const { schemaTypeDefinitions } = useMatchSchemaType()
|
const { schemaTypeDefinitions } = useMatchSchemaType()
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
const allPluginInfoList = {
|
const allPluginInfoList = {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const setInspectVarsToStore = (inspectVars: VarInInspect[], passedInAllPluginInfoList?: Record<string, ToolWithProvider[]>, passedInSchemaTypeDefinitions?: SchemaTypeDefinition[]) => {
|
const setInspectVarsToStore = (inspectVars: VarInInspect[], passedInAllPluginInfoList?: Record<string, ToolWithProvider[]>, passedInSchemaTypeDefinitions?: SchemaTypeDefinition[]) => {
|
||||||
|
|||||||
@ -18,6 +18,12 @@ import type { FlowType } from '@/types/common'
|
|||||||
import useFLow from '@/service/use-flow'
|
import useFLow from '@/service/use-flow'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
import type { SchemaTypeDefinition } from '@/service/use-common'
|
import type { SchemaTypeDefinition } from '@/service/use-common'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
flowId: string
|
flowId: string
|
||||||
@ -51,6 +57,11 @@ export const useInspectVarsCrudCommon = ({
|
|||||||
const { mutateAsync: doEditInspectorVar } = useEditInspectorVar(flowId)
|
const { mutateAsync: doEditInspectorVar } = useEditInspectorVar(flowId)
|
||||||
const { handleCancelNodeSuccessStatus } = useNodesInteractionsWithoutSync()
|
const { handleCancelNodeSuccessStatus } = useNodesInteractionsWithoutSync()
|
||||||
const { handleEdgeCancelRunningStatus } = useEdgesInteractionsWithoutSync()
|
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 getNodeInspectVars = useCallback((nodeId: string) => {
|
||||||
const { nodesWithInspectVars } = workflowStore.getState()
|
const { nodesWithInspectVars } = workflowStore.getState()
|
||||||
const node = nodesWithInspectVars.find(node => node.nodeId === nodeId)
|
const node = nodesWithInspectVars.find(node => node.nodeId === nodeId)
|
||||||
@ -98,10 +109,6 @@ export const useInspectVarsCrudCommon = ({
|
|||||||
const fetchInspectVarValue = useCallback(async (selector: ValueSelector, schemaTypeDefinitions: SchemaTypeDefinition[]) => {
|
const fetchInspectVarValue = useCallback(async (selector: ValueSelector, schemaTypeDefinitions: SchemaTypeDefinition[]) => {
|
||||||
const {
|
const {
|
||||||
setNodeInspectVars,
|
setNodeInspectVars,
|
||||||
buildInTools,
|
|
||||||
customTools,
|
|
||||||
workflowTools,
|
|
||||||
mcpTools,
|
|
||||||
dataSourceList,
|
dataSourceList,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const nodeId = selector[0]
|
const nodeId = selector[0]
|
||||||
@ -119,11 +126,11 @@ export const useInspectVarsCrudCommon = ({
|
|||||||
const nodeArr = getNodes()
|
const nodeArr = getNodes()
|
||||||
const currentNode = nodeArr.find(node => node.id === nodeId)
|
const currentNode = nodeArr.find(node => node.id === nodeId)
|
||||||
const allPluginInfoList = {
|
const allPluginInfoList = {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
}
|
}
|
||||||
const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], allPluginInfoList, schemaTypeDefinitions)
|
const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], allPluginInfoList, schemaTypeDefinitions)
|
||||||
const vars = await fetchNodeInspectVars(flowType, flowId, nodeId)
|
const vars = await fetchNodeInspectVars(flowType, flowId, nodeId)
|
||||||
@ -135,7 +142,7 @@ export const useInspectVarsCrudCommon = ({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
setNodeInspectVars(nodeId, varsWithSchemaType)
|
setNodeInspectVars(nodeId, varsWithSchemaType)
|
||||||
}, [workflowStore, flowType, flowId, invalidateSysVarValues, invalidateConversationVarValues])
|
}, [workflowStore, flowType, flowId, invalidateSysVarValues, invalidateConversationVarValues, buildInTools, customTools, workflowTools, mcpTools])
|
||||||
|
|
||||||
// after last run would call this
|
// after last run would call this
|
||||||
const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => {
|
const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => {
|
||||||
|
|||||||
@ -7,6 +7,11 @@ import { CollectionType } from '@/app/components/tools/types'
|
|||||||
import { useStore } from '@/app/components/workflow/store'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
import { useGetLanguage } from '@/context/i18n'
|
import { useGetLanguage } from '@/context/i18n'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
export const useNodesMetaData = () => {
|
export const useNodesMetaData = () => {
|
||||||
const availableNodesMetaData = useHooksStore(s => s.availableNodesMetaData)
|
const availableNodesMetaData = useHooksStore(s => s.availableNodesMetaData)
|
||||||
@ -21,9 +26,9 @@ export const useNodesMetaData = () => {
|
|||||||
|
|
||||||
export const useNodeMetaData = (node: Node) => {
|
export const useNodeMetaData = (node: Node) => {
|
||||||
const language = useGetLanguage()
|
const language = useGetLanguage()
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
const availableNodesMetaData = useNodesMetaData()
|
const availableNodesMetaData = useNodesMetaData()
|
||||||
const { data } = node
|
const { data } = node
|
||||||
@ -34,10 +39,10 @@ export const useNodeMetaData = (node: Node) => {
|
|||||||
|
|
||||||
if (data.type === BlockEnum.Tool) {
|
if (data.type === BlockEnum.Tool) {
|
||||||
if (data.provider_type === CollectionType.builtIn)
|
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)
|
if (data.provider_type === CollectionType.workflow)
|
||||||
return workflowTools.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 customTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
|
||||||
}
|
}
|
||||||
return nodeMetaData?.metaData.author
|
return nodeMetaData?.metaData.author
|
||||||
}, [data, buildInTools, customTools, workflowTools, nodeMetaData, dataSourceList])
|
}, [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]
|
return dataSourceList?.find(dataSource => dataSource.plugin_id === data.plugin_id)?.description[language]
|
||||||
if (data.type === BlockEnum.Tool) {
|
if (data.type === BlockEnum.Tool) {
|
||||||
if (data.provider_type === CollectionType.builtIn)
|
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)
|
if (data.provider_type === CollectionType.workflow)
|
||||||
return workflowTools.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 customTools?.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]
|
||||||
}
|
}
|
||||||
return nodeMetaData?.metaData.description
|
return nodeMetaData?.metaData.description
|
||||||
}, [data, buildInTools, customTools, workflowTools, nodeMetaData, dataSourceList, language])
|
}, [data, buildInTools, customTools, workflowTools, nodeMetaData, dataSourceList, language])
|
||||||
|
|||||||
@ -14,12 +14,18 @@ import {
|
|||||||
} from '../store'
|
} from '../store'
|
||||||
import { CollectionType } from '@/app/components/tools/types'
|
import { CollectionType } from '@/app/components/tools/types'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
export const useToolIcon = (data?: Node['data']) => {
|
export const useToolIcon = (data?: Node['data']) => {
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
// const a = useStore(s => s.data)
|
// const a = useStore(s => s.data)
|
||||||
const toolIcon = useMemo(() => {
|
const toolIcon = useMemo(() => {
|
||||||
@ -27,15 +33,15 @@ export const useToolIcon = (data?: Node['data']) => {
|
|||||||
return ''
|
return ''
|
||||||
if (data.type === BlockEnum.Tool) {
|
if (data.type === BlockEnum.Tool) {
|
||||||
// eslint-disable-next-line sonarjs/no-dead-store
|
// eslint-disable-next-line sonarjs/no-dead-store
|
||||||
let targetTools = buildInTools
|
let targetTools = buildInTools || []
|
||||||
if (data.provider_type === CollectionType.builtIn)
|
if (data.provider_type === CollectionType.builtIn)
|
||||||
targetTools = buildInTools
|
targetTools = buildInTools || []
|
||||||
else if (data.provider_type === CollectionType.custom)
|
else if (data.provider_type === CollectionType.custom)
|
||||||
targetTools = customTools
|
targetTools = customTools || []
|
||||||
else if (data.provider_type === CollectionType.mcp)
|
else if (data.provider_type === CollectionType.mcp)
|
||||||
targetTools = mcpTools
|
targetTools = mcpTools || []
|
||||||
else
|
else
|
||||||
targetTools = workflowTools
|
targetTools = workflowTools || []
|
||||||
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
|
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
|
||||||
}
|
}
|
||||||
if (data.type === BlockEnum.DataSource)
|
if (data.type === BlockEnum.DataSource)
|
||||||
@ -46,24 +52,24 @@ export const useToolIcon = (data?: Node['data']) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useGetToolIcon = () => {
|
export const useGetToolIcon = () => {
|
||||||
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
|
const { data: customTools } = useAllCustomTools()
|
||||||
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const getToolIcon = useCallback((data: Node['data']) => {
|
const getToolIcon = useCallback((data: Node['data']) => {
|
||||||
const {
|
const {
|
||||||
buildInTools,
|
|
||||||
customTools,
|
|
||||||
workflowTools,
|
|
||||||
dataSourceList,
|
dataSourceList,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
|
|
||||||
if (data.type === BlockEnum.Tool) {
|
if (data.type === BlockEnum.Tool) {
|
||||||
// eslint-disable-next-line sonarjs/no-dead-store
|
// eslint-disable-next-line sonarjs/no-dead-store
|
||||||
let targetTools = buildInTools
|
let targetTools = buildInTools || []
|
||||||
if (data.provider_type === CollectionType.builtIn)
|
if (data.provider_type === CollectionType.builtIn)
|
||||||
targetTools = buildInTools
|
targetTools = buildInTools || []
|
||||||
else if (data.provider_type === CollectionType.custom)
|
else if (data.provider_type === CollectionType.custom)
|
||||||
targetTools = customTools
|
targetTools = customTools || []
|
||||||
else
|
else
|
||||||
targetTools = workflowTools
|
targetTools = workflowTools || []
|
||||||
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
|
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,11 @@ import type { Emoji } from '@/app/components/tools/types'
|
|||||||
import { CollectionType } from '@/app/components/tools/types'
|
import { CollectionType } from '@/app/components/tools/types'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
import type { LLMNodeType } from '../nodes/llm/types'
|
import type { LLMNodeType } from '../nodes/llm/types'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to register workflow nodes search functionality
|
* Hook to register workflow nodes search functionality
|
||||||
@ -22,9 +27,9 @@ export const useWorkflowSearch = () => {
|
|||||||
const { handleNodeSelect } = useNodesInteractions()
|
const { handleNodeSelect } = useNodesInteractions()
|
||||||
|
|
||||||
// Filter and process nodes for search
|
// Filter and process nodes for search
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const mcpTools = useStore(s => s.mcpTools)
|
||||||
|
|
||||||
// Extract tool icon logic - clean separation of concerns
|
// Extract tool icon logic - clean separation of concerns
|
||||||
@ -32,13 +37,13 @@ export const useWorkflowSearch = () => {
|
|||||||
if (nodeData?.type !== BlockEnum.Tool) return undefined
|
if (nodeData?.type !== BlockEnum.Tool) return undefined
|
||||||
|
|
||||||
const toolCollections: Record<string, any[]> = {
|
const toolCollections: Record<string, any[]> = {
|
||||||
[CollectionType.builtIn]: buildInTools,
|
[CollectionType.builtIn]: buildInTools || [],
|
||||||
[CollectionType.custom]: customTools,
|
[CollectionType.custom]: customTools || [],
|
||||||
[CollectionType.mcp]: mcpTools,
|
[CollectionType.mcp]: mcpTools || [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetTools = (nodeData.provider_type && toolCollections[nodeData.provider_type]) || workflowTools
|
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])
|
}, [buildInTools, customTools, workflowTools, mcpTools])
|
||||||
|
|
||||||
// Extract model info logic - clean extraction
|
// Extract model info logic - clean extraction
|
||||||
|
|||||||
@ -10,20 +10,25 @@ import type {
|
|||||||
} from '@/app/components/workflow/types'
|
} from '@/app/components/workflow/types'
|
||||||
import { useIsChatMode } from './use-workflow'
|
import { useIsChatMode } from './use-workflow'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
|
||||||
import type { Type } from '../nodes/llm/types'
|
import type { Type } from '../nodes/llm/types'
|
||||||
import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type'
|
import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
export const useWorkflowVariables = () => {
|
export const useWorkflowVariables = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const { schemaTypeDefinitions } = useMatchSchemaType()
|
const { schemaTypeDefinitions } = useMatchSchemaType()
|
||||||
|
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
|
||||||
const getNodeAvailableVars = useCallback(({
|
const getNodeAvailableVars = useCallback(({
|
||||||
parentNode,
|
parentNode,
|
||||||
beforeNodes,
|
beforeNodes,
|
||||||
@ -43,6 +48,7 @@ export const useWorkflowVariables = () => {
|
|||||||
conversationVariables,
|
conversationVariables,
|
||||||
environmentVariables,
|
environmentVariables,
|
||||||
ragPipelineVariables,
|
ragPipelineVariables,
|
||||||
|
dataSourceList,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
return toNodeAvailableVars({
|
return toNodeAvailableVars({
|
||||||
parentNode,
|
parentNode,
|
||||||
@ -54,15 +60,15 @@ export const useWorkflowVariables = () => {
|
|||||||
ragVariables: ragPipelineVariables,
|
ragVariables: ragPipelineVariables,
|
||||||
filterVar,
|
filterVar,
|
||||||
allPluginInfoList: {
|
allPluginInfoList: {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
},
|
},
|
||||||
schemaTypeDefinitions,
|
schemaTypeDefinitions,
|
||||||
})
|
})
|
||||||
}, [t, workflowStore, schemaTypeDefinitions, buildInTools])
|
}, [t, workflowStore, schemaTypeDefinitions, buildInTools, customTools, workflowTools, mcpTools])
|
||||||
|
|
||||||
const getCurrentVariableType = useCallback(({
|
const getCurrentVariableType = useCallback(({
|
||||||
parentNode,
|
parentNode,
|
||||||
|
|||||||
@ -32,15 +32,9 @@ import { CUSTOM_NOTE_NODE } from '../note-node/constants'
|
|||||||
import { findUsedVarNodes, getNodeOutputVars, updateNodeVars } from '../nodes/_base/components/variable/utils'
|
import { findUsedVarNodes, getNodeOutputVars, updateNodeVars } from '../nodes/_base/components/variable/utils'
|
||||||
import { useAvailableBlocks } from './use-available-blocks'
|
import { useAvailableBlocks } from './use-available-blocks'
|
||||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
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_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 { CUSTOM_LOOP_START_NODE } from '@/app/components/workflow/nodes/loop-start/constants'
|
||||||
import { basePath } from '@/utils/var'
|
|
||||||
import { useNodesMetaData } from '.'
|
import { useNodesMetaData } from '.'
|
||||||
|
|
||||||
export const useIsChatMode = () => {
|
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 = () => {
|
export const useWorkflowReadOnly = () => {
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const workflowRunningData = useStore(s => s.workflowRunningData)
|
const workflowRunningData = useStore(s => s.workflowRunningData)
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import {
|
|||||||
} from './types'
|
} from './types'
|
||||||
import {
|
import {
|
||||||
useEdgesInteractions,
|
useEdgesInteractions,
|
||||||
useFetchToolsData,
|
|
||||||
useNodesInteractions,
|
useNodesInteractions,
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
useNodesSyncDraft,
|
useNodesSyncDraft,
|
||||||
@ -92,6 +91,12 @@ import useMatchSchemaType from './nodes/_base/components/variable/use-match-sche
|
|||||||
import type { VarInInspect } from '@/types/workflow'
|
import type { VarInInspect } from '@/types/workflow'
|
||||||
import { fetchAllInspectVars } from '@/service/workflow'
|
import { fetchAllInspectVars } from '@/service/workflow'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
const Confirm = dynamic(() => import('@/app/components/base/confirm'), {
|
const Confirm = dynamic(() => import('@/app/components/base/confirm'), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@ -242,13 +247,6 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const { handleFetchAllTools } = useFetchToolsData()
|
|
||||||
useEffect(() => {
|
|
||||||
handleFetchAllTools('builtin')
|
|
||||||
handleFetchAllTools('custom')
|
|
||||||
handleFetchAllTools('workflow')
|
|
||||||
handleFetchAllTools('mcp')
|
|
||||||
}, [handleFetchAllTools])
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleNodeDragStart,
|
handleNodeDragStart,
|
||||||
@ -299,10 +297,10 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
|
|
||||||
const { schemaTypeDefinitions } = useMatchSchemaType()
|
const { schemaTypeDefinitions } = useMatchSchemaType()
|
||||||
const { fetchInspectVars } = useSetWorkflowVarsWithValue()
|
const { fetchInspectVars } = useSetWorkflowVarsWithValue()
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
// buildInTools, customTools, workflowTools, mcpTools, dataSourceList
|
// buildInTools, customTools, workflowTools, mcpTools, dataSourceList
|
||||||
const configsMap = useHooksStore(s => s.configsMap)
|
const configsMap = useHooksStore(s => s.configsMap)
|
||||||
@ -323,10 +321,10 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
passInVars: true,
|
passInVars: true,
|
||||||
vars,
|
vars,
|
||||||
passedInAllPluginInfoList: {
|
passedInAllPluginInfoList: {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList ?? [],
|
||||||
},
|
},
|
||||||
passedInSchemaTypeDefinitions: schemaTypeDefinitions,
|
passedInSchemaTypeDefinitions: schemaTypeDefinitions,
|
||||||
|
|||||||
@ -75,6 +75,7 @@ import { DataSourceClassification } from '@/app/components/workflow/nodes/data-s
|
|||||||
import { useModalContext } from '@/context/modal-context'
|
import { useModalContext } from '@/context/modal-context'
|
||||||
import DataSourceBeforeRunForm from '@/app/components/workflow/nodes/data-source/before-run-form'
|
import DataSourceBeforeRunForm from '@/app/components/workflow/nodes/data-source/before-run-form'
|
||||||
import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars-crud'
|
import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars-crud'
|
||||||
|
import { useAllBuiltInTools } from '@/service/use-tools'
|
||||||
|
|
||||||
const getCustomRunForm = (params: CustomRunFormProps): React.JSX.Element => {
|
const getCustomRunForm = (params: CustomRunFormProps): React.JSX.Element => {
|
||||||
const nodeType = params.payload.type
|
const nodeType = params.payload.type
|
||||||
@ -259,9 +260,9 @@ const BasePanel: FC<BasePanelProps> = ({
|
|||||||
return {}
|
return {}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const currCollection = useMemo(() => {
|
const currCollection = useMemo(() => {
|
||||||
return buildInTools.find(item => canFindTool(item.id, data.provider_id))
|
return buildInTools?.find(item => canFindTool(item.id, data.provider_id))
|
||||||
}, [buildInTools, data.provider_id])
|
}, [buildInTools, data.provider_id])
|
||||||
const showPluginAuth = useMemo(() => {
|
const showPluginAuth = useMemo(() => {
|
||||||
return data.type === BlockEnum.Tool && currCollection?.allow_delete
|
return data.type === BlockEnum.Tool && currCollection?.allow_delete
|
||||||
|
|||||||
@ -53,6 +53,13 @@ import { useInvalidLastRun } from '@/service/use-workflow'
|
|||||||
import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud'
|
import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud'
|
||||||
import type { FlowType } from '@/types/common'
|
import type { FlowType } from '@/types/common'
|
||||||
import useMatchSchemaType from '../components/variable/use-match-schema-type'
|
import useMatchSchemaType from '../components/variable/use-match-schema-type'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
// eslint-disable-next-line ts/no-unsafe-function-type
|
// eslint-disable-next-line ts/no-unsafe-function-type
|
||||||
const checkValidFns: Record<BlockEnum, Function> = {
|
const checkValidFns: Record<BlockEnum, Function> = {
|
||||||
[BlockEnum.LLM]: checkLLMValid,
|
[BlockEnum.LLM]: checkLLMValid,
|
||||||
@ -133,21 +140,23 @@ const useOneStepRun = <T>({
|
|||||||
const availableNodesIncludeParent = getBeforeNodesInSameBranchIncludeParent(id)
|
const availableNodesIncludeParent = getBeforeNodesInSameBranchIncludeParent(id)
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const { schemaTypeDefinitions } = useMatchSchemaType()
|
const { schemaTypeDefinitions } = useMatchSchemaType()
|
||||||
|
|
||||||
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
|
const { data: customTools } = useAllCustomTools()
|
||||||
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
|
|
||||||
const getVar = (valueSelector: ValueSelector): Var | undefined => {
|
const getVar = (valueSelector: ValueSelector): Var | undefined => {
|
||||||
const isSystem = valueSelector[0] === 'sys'
|
const isSystem = valueSelector[0] === 'sys'
|
||||||
const {
|
const {
|
||||||
buildInTools,
|
|
||||||
customTools,
|
|
||||||
workflowTools,
|
|
||||||
mcpTools,
|
|
||||||
dataSourceList,
|
dataSourceList,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const allPluginInfoList = {
|
const allPluginInfoList = {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const allOutputVars = toNodeOutputVars(availableNodes, isChatMode, undefined, undefined, conversationVariables, [], allPluginInfoList, schemaTypeDefinitions)
|
const allOutputVars = toNodeOutputVars(availableNodes, isChatMode, undefined, undefined, conversationVariables, [], allPluginInfoList, schemaTypeDefinitions)
|
||||||
|
|||||||
@ -42,6 +42,12 @@ import BoolValue from '@/app/components/workflow/panel/chat-variable-panel/compo
|
|||||||
import { getVarType } from '@/app/components/workflow/nodes/_base/components/variable/utils'
|
import { getVarType } from '@/app/components/workflow/nodes/_base/components/variable/utils'
|
||||||
import { useIsChatMode } from '@/app/components/workflow/hooks/use-workflow'
|
import { useIsChatMode } from '@/app/components/workflow/hooks/use-workflow'
|
||||||
import useMatchSchemaType from '../../../_base/components/variable/use-match-schema-type'
|
import useMatchSchemaType from '../../../_base/components/variable/use-match-schema-type'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName'
|
const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName'
|
||||||
|
|
||||||
type ConditionItemProps = {
|
type ConditionItemProps = {
|
||||||
@ -91,15 +97,12 @@ const ConditionItem = ({
|
|||||||
const [isHovered, setIsHovered] = useState(false)
|
const [isHovered, setIsHovered] = useState(false)
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
|
const { data: customTools } = useAllCustomTools()
|
||||||
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
|
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const {
|
|
||||||
setControlPromptEditorRerenderKey,
|
|
||||||
buildInTools,
|
|
||||||
customTools,
|
|
||||||
mcpTools,
|
|
||||||
workflowTools,
|
|
||||||
dataSourceList,
|
|
||||||
} = workflowStore.getState()
|
|
||||||
|
|
||||||
const doUpdateCondition = useCallback((newCondition: Condition) => {
|
const doUpdateCondition = useCallback((newCondition: Condition) => {
|
||||||
if (isSubVariableKey)
|
if (isSubVariableKey)
|
||||||
@ -213,6 +216,8 @@ const ConditionItem = ({
|
|||||||
const handleVarChange = useCallback((valueSelector: ValueSelector, _varItem: Var) => {
|
const handleVarChange = useCallback((valueSelector: ValueSelector, _varItem: Var) => {
|
||||||
const {
|
const {
|
||||||
conversationVariables,
|
conversationVariables,
|
||||||
|
setControlPromptEditorRerenderKey,
|
||||||
|
dataSourceList,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
const resolvedVarType = getVarType({
|
const resolvedVarType = getVarType({
|
||||||
valueSelector,
|
valueSelector,
|
||||||
@ -220,11 +225,11 @@ const ConditionItem = ({
|
|||||||
availableNodes,
|
availableNodes,
|
||||||
isChatMode,
|
isChatMode,
|
||||||
allPluginInfoList: {
|
allPluginInfoList: {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
},
|
},
|
||||||
schemaTypeDefinitions,
|
schemaTypeDefinitions,
|
||||||
})
|
})
|
||||||
@ -241,12 +246,12 @@ const ConditionItem = ({
|
|||||||
})
|
})
|
||||||
doUpdateCondition(newCondition)
|
doUpdateCondition(newCondition)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}, [condition, doUpdateCondition, availableNodes, isChatMode, setControlPromptEditorRerenderKey, schemaTypeDefinitions])
|
}, [condition, doUpdateCondition, availableNodes, isChatMode, schemaTypeDefinitions, buildInTools, customTools, mcpTools, workflowTools])
|
||||||
|
|
||||||
const showBooleanInput = useMemo(() => {
|
const showBooleanInput = useMemo(() => {
|
||||||
if(condition.varType === VarType.boolean)
|
if(condition.varType === VarType.boolean)
|
||||||
return true
|
return true
|
||||||
// eslint-disable-next-line sonarjs/prefer-single-boolean-return
|
|
||||||
if(condition.varType === VarType.arrayBoolean && [ComparisonOperator.contains, ComparisonOperator.notContains].includes(condition.comparison_operator!))
|
if(condition.varType === VarType.arrayBoolean && [ComparisonOperator.contains, ComparisonOperator.notContains].includes(condition.comparison_operator!))
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -15,6 +15,12 @@ import type { Item } from '@/app/components/base/select'
|
|||||||
import useInspectVarsCrud from '../../hooks/use-inspect-vars-crud'
|
import useInspectVarsCrud from '../../hooks/use-inspect-vars-crud'
|
||||||
import { isEqual } from 'lodash-es'
|
import { isEqual } from 'lodash-es'
|
||||||
import { useStore } from '../../store'
|
import { useStore } from '../../store'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: IterationNodeType) => {
|
const useConfig = (id: string, payload: IterationNodeType) => {
|
||||||
const {
|
const {
|
||||||
@ -40,17 +46,17 @@ const useConfig = (id: string, payload: IterationNodeType) => {
|
|||||||
// output
|
// output
|
||||||
const { getIterationNodeChildren } = useWorkflow()
|
const { getIterationNodeChildren } = useWorkflow()
|
||||||
const iterationChildrenNodes = getIterationNodeChildren(id)
|
const iterationChildrenNodes = getIterationNodeChildren(id)
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
const allPluginInfoList = {
|
const allPluginInfoList = {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
}
|
}
|
||||||
const childrenNodeVars = toNodeOutputVars(iterationChildrenNodes, isChatMode, undefined, [], [], [], allPluginInfoList)
|
const childrenNodeVars = toNodeOutputVars(iterationChildrenNodes, isChatMode, undefined, [], [], [], allPluginInfoList)
|
||||||
|
|
||||||
|
|||||||
@ -15,9 +15,24 @@ import useNodeCrud from '../_base/hooks/use-node-crud'
|
|||||||
import { toNodeOutputVars } from '../_base/components/variable/utils'
|
import { toNodeOutputVars } from '../_base/components/variable/utils'
|
||||||
import { getOperators } from './utils'
|
import { getOperators } from './utils'
|
||||||
import { LogicalOperator } from './types'
|
import { LogicalOperator } from './types'
|
||||||
import type { HandleAddCondition, HandleAddSubVariableCondition, HandleRemoveCondition, HandleToggleConditionLogicalOperator, HandleToggleSubVariableConditionLogicalOperator, HandleUpdateCondition, HandleUpdateSubVariableCondition, LoopNodeType } from './types'
|
import type {
|
||||||
|
HandleAddCondition,
|
||||||
|
HandleAddSubVariableCondition,
|
||||||
|
HandleRemoveCondition,
|
||||||
|
HandleToggleConditionLogicalOperator,
|
||||||
|
HandleToggleSubVariableConditionLogicalOperator,
|
||||||
|
HandleUpdateCondition,
|
||||||
|
HandleUpdateSubVariableCondition,
|
||||||
|
LoopNodeType,
|
||||||
|
} from './types'
|
||||||
import useIsVarFileAttribute from './use-is-var-file-attribute'
|
import useIsVarFileAttribute from './use-is-var-file-attribute'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: LoopNodeType) => {
|
const useConfig = (id: string, payload: LoopNodeType) => {
|
||||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||||
@ -38,17 +53,17 @@ const useConfig = (id: string, payload: LoopNodeType) => {
|
|||||||
// output
|
// output
|
||||||
const { getLoopNodeChildren } = useWorkflow()
|
const { getLoopNodeChildren } = useWorkflow()
|
||||||
const loopChildrenNodes = [{ id, data: payload } as any, ...getLoopNodeChildren(id)]
|
const loopChildrenNodes = [{ id, data: payload } as any, ...getLoopNodeChildren(id)]
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
const dataSourceList = useStore(s => s.dataSourceList)
|
const dataSourceList = useStore(s => s.dataSourceList)
|
||||||
const allPluginInfoList = {
|
const allPluginInfoList = {
|
||||||
buildInTools,
|
buildInTools: buildInTools || [],
|
||||||
customTools,
|
customTools: customTools || [],
|
||||||
workflowTools,
|
workflowTools: workflowTools || [],
|
||||||
mcpTools,
|
mcpTools: mcpTools || [],
|
||||||
dataSourceList: dataSourceList ?? [],
|
dataSourceList: dataSourceList || [],
|
||||||
}
|
}
|
||||||
const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode, undefined, [], conversationVariables, [], allPluginInfoList)
|
const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode, undefined, [], conversationVariables, [], allPluginInfoList)
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import BlockSelector from '../../../../block-selector'
|
import BlockSelector from '../../../../block-selector'
|
||||||
import type { Param, ParamType } from '../../types'
|
import type { Param, ParamType } from '../../types'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
|
||||||
import type {
|
import type {
|
||||||
DataSourceDefaultValue,
|
DataSourceDefaultValue,
|
||||||
ToolDefaultValue,
|
ToolDefaultValue,
|
||||||
@ -18,6 +17,11 @@ import { CollectionType } from '@/app/components/tools/types'
|
|||||||
import type { BlockEnum } from '@/app/components/workflow/types'
|
import type { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.parameterExtractor'
|
const i18nPrefix = 'workflow.nodes.parameterExtractor'
|
||||||
|
|
||||||
@ -42,9 +46,9 @@ const ImportFromTool: FC<Props> = ({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
|
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
|
|
||||||
const handleSelectTool = useCallback((_type: BlockEnum, toolInfo?: ToolDefaultValue | DataSourceDefaultValue) => {
|
const handleSelectTool = useCallback((_type: BlockEnum, toolInfo?: ToolDefaultValue | DataSourceDefaultValue) => {
|
||||||
if (!toolInfo || 'datasource_name' in toolInfo)
|
if (!toolInfo || 'datasource_name' in toolInfo)
|
||||||
@ -54,11 +58,11 @@ const ImportFromTool: FC<Props> = ({
|
|||||||
const currentTools = (() => {
|
const currentTools = (() => {
|
||||||
switch (provider_type) {
|
switch (provider_type) {
|
||||||
case CollectionType.builtIn:
|
case CollectionType.builtIn:
|
||||||
return buildInTools
|
return buildInTools || []
|
||||||
case CollectionType.custom:
|
case CollectionType.custom:
|
||||||
return customTools
|
return customTools || []
|
||||||
case CollectionType.workflow:
|
case CollectionType.workflow:
|
||||||
return workflowTools
|
return workflowTools || []
|
||||||
default:
|
default:
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
import { useStore, useWorkflowStore } from '../../store'
|
import { useWorkflowStore } from '../../store'
|
||||||
import type { ToolNodeType, ToolVarInputs } from './types'
|
import type { ToolNodeType, ToolVarInputs } from './types'
|
||||||
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
@ -15,15 +15,20 @@ import {
|
|||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import type { InputVar } from '@/app/components/workflow/types'
|
import type { InputVar } from '@/app/components/workflow/types'
|
||||||
import {
|
import {
|
||||||
useFetchToolsData,
|
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
|
import {
|
||||||
|
useAllBuiltInTools,
|
||||||
|
useAllCustomTools,
|
||||||
|
useAllMCPTools,
|
||||||
|
useAllWorkflowTools,
|
||||||
|
useInvalidToolsByType,
|
||||||
|
} from '@/service/use-tools'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: ToolNodeType) => {
|
const useConfig = (id: string, payload: ToolNodeType) => {
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||||
const { handleFetchAllTools } = useFetchToolsData()
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
@ -43,21 +48,21 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||||||
tool_parameters,
|
tool_parameters,
|
||||||
} = inputs
|
} = inputs
|
||||||
const isBuiltIn = provider_type === CollectionType.builtIn
|
const isBuiltIn = provider_type === CollectionType.builtIn
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
const { data: buildInTools } = useAllBuiltInTools()
|
||||||
const customTools = useStore(s => s.customTools)
|
const { data: customTools } = useAllCustomTools()
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const mcpTools = useStore(s => s.mcpTools)
|
const { data: mcpTools } = useAllMCPTools()
|
||||||
|
|
||||||
const currentTools = useMemo(() => {
|
const currentTools = useMemo(() => {
|
||||||
switch (provider_type) {
|
switch (provider_type) {
|
||||||
case CollectionType.builtIn:
|
case CollectionType.builtIn:
|
||||||
return buildInTools
|
return buildInTools || []
|
||||||
case CollectionType.custom:
|
case CollectionType.custom:
|
||||||
return customTools
|
return customTools || []
|
||||||
case CollectionType.workflow:
|
case CollectionType.workflow:
|
||||||
return workflowTools
|
return workflowTools || []
|
||||||
case CollectionType.mcp:
|
case CollectionType.mcp:
|
||||||
return mcpTools
|
return mcpTools || []
|
||||||
default:
|
default:
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@ -75,6 +80,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||||||
{ setTrue: showSetAuthModal, setFalse: hideSetAuthModal },
|
{ setTrue: showSetAuthModal, setFalse: hideSetAuthModal },
|
||||||
] = useBoolean(false)
|
] = useBoolean(false)
|
||||||
|
|
||||||
|
const invalidToolsByType = useInvalidToolsByType(provider_type)
|
||||||
const handleSaveAuth = useCallback(
|
const handleSaveAuth = useCallback(
|
||||||
async (value: any) => {
|
async (value: any) => {
|
||||||
await updateBuiltInToolCredential(currCollection?.name as string, value)
|
await updateBuiltInToolCredential(currCollection?.name as string, value)
|
||||||
@ -83,14 +89,14 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('common.api.actionSuccess'),
|
message: t('common.api.actionSuccess'),
|
||||||
})
|
})
|
||||||
handleFetchAllTools(provider_type)
|
invalidToolsByType()
|
||||||
hideSetAuthModal()
|
hideSetAuthModal()
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
currCollection?.name,
|
currCollection?.name,
|
||||||
hideSetAuthModal,
|
hideSetAuthModal,
|
||||||
t,
|
t,
|
||||||
handleFetchAllTools,
|
invalidToolsByType,
|
||||||
provider_type,
|
provider_type,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -241,17 +247,15 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||||||
name: outputKey,
|
name: outputKey,
|
||||||
type:
|
type:
|
||||||
output.type === 'array'
|
output.type === 'array'
|
||||||
? `Array[${
|
? `Array[${output.items?.type
|
||||||
output.items?.type
|
? output.items.type.slice(0, 1).toLocaleUpperCase()
|
||||||
? output.items.type.slice(0, 1).toLocaleUpperCase()
|
+ output.items.type.slice(1)
|
||||||
+ output.items.type.slice(1)
|
: 'Unknown'
|
||||||
: 'Unknown'
|
|
||||||
}]`
|
}]`
|
||||||
: `${
|
: `${output.type
|
||||||
output.type
|
? output.type.slice(0, 1).toLocaleUpperCase()
|
||||||
? output.type.slice(0, 1).toLocaleUpperCase()
|
+ output.type.slice(1)
|
||||||
+ output.type.slice(1)
|
: 'Unknown'
|
||||||
: 'Unknown'
|
|
||||||
}`,
|
}`,
|
||||||
description: output.description,
|
description: output.description,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,30 +1,11 @@
|
|||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
import type {
|
|
||||||
ToolWithProvider,
|
|
||||||
} from '@/app/components/workflow/types'
|
|
||||||
|
|
||||||
export type ToolSliceShape = {
|
export type ToolSliceShape = {
|
||||||
buildInTools: ToolWithProvider[]
|
|
||||||
setBuildInTools: (tools: ToolWithProvider[]) => void
|
|
||||||
customTools: ToolWithProvider[]
|
|
||||||
setCustomTools: (tools: ToolWithProvider[]) => void
|
|
||||||
workflowTools: ToolWithProvider[]
|
|
||||||
setWorkflowTools: (tools: ToolWithProvider[]) => void
|
|
||||||
mcpTools: ToolWithProvider[]
|
|
||||||
setMcpTools: (tools: ToolWithProvider[]) => void
|
|
||||||
toolPublished: boolean
|
toolPublished: boolean
|
||||||
setToolPublished: (toolPublished: boolean) => void
|
setToolPublished: (toolPublished: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createToolSlice: StateCreator<ToolSliceShape> = set => ({
|
export const createToolSlice: StateCreator<ToolSliceShape> = set => ({
|
||||||
buildInTools: [],
|
|
||||||
setBuildInTools: buildInTools => set(() => ({ buildInTools })),
|
|
||||||
customTools: [],
|
|
||||||
setCustomTools: customTools => set(() => ({ customTools })),
|
|
||||||
workflowTools: [],
|
|
||||||
setWorkflowTools: workflowTools => set(() => ({ workflowTools })),
|
|
||||||
mcpTools: [],
|
|
||||||
setMcpTools: mcpTools => set(() => ({ mcpTools })),
|
|
||||||
toolPublished: false,
|
toolPublished: false,
|
||||||
setToolPublished: toolPublished => set(() => ({ toolPublished })),
|
setToolPublished: toolPublished => set(() => ({ toolPublished })),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -4,9 +4,11 @@ import type {
|
|||||||
MCPServerDetail,
|
MCPServerDetail,
|
||||||
Tool,
|
Tool,
|
||||||
} from '@/app/components/tools/types'
|
} from '@/app/components/tools/types'
|
||||||
|
import { CollectionType } from '@/app/components/tools/types'
|
||||||
import type { RAGRecommendedPlugins, ToolWithProvider } from '@/app/components/workflow/types'
|
import type { RAGRecommendedPlugins, ToolWithProvider } from '@/app/components/workflow/types'
|
||||||
import type { AppIconType } from '@/types/app'
|
import type { AppIconType } from '@/types/app'
|
||||||
import { useInvalid } from './use-base'
|
import { useInvalid } from './use-base'
|
||||||
|
import type { QueryKey } from '@tanstack/react-query'
|
||||||
import {
|
import {
|
||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
@ -76,6 +78,16 @@ export const useInvalidateAllMCPTools = () => {
|
|||||||
return useInvalid(useAllMCPToolsKey)
|
return useInvalid(useAllMCPToolsKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useInvalidToolsKeyMap: Record<string, QueryKey> = {
|
||||||
|
[CollectionType.builtIn]: useAllBuiltInToolsKey,
|
||||||
|
[CollectionType.custom]: useAllCustomToolsKey,
|
||||||
|
[CollectionType.workflow]: useAllWorkflowToolsKey,
|
||||||
|
[CollectionType.mcp]: useAllMCPToolsKey,
|
||||||
|
}
|
||||||
|
export const useInvalidToolsByType = (type: CollectionType) => {
|
||||||
|
return useInvalid(useInvalidToolsKeyMap[type])
|
||||||
|
}
|
||||||
|
|
||||||
export const useCreateMCP = () => {
|
export const useCreateMCP = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: [NAME_SPACE, 'create-mcp'],
|
mutationKey: [NAME_SPACE, 'create-mcp'],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user