mirror of
https://github.com/langgenius/dify.git
synced 2026-03-29 16:40:10 +08:00
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: statxc <tyleradams93226@gmail.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import type { ToolNodeType } from '../types'
|
|
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
|
import { useMemo } from 'react'
|
|
import { CollectionType } from '@/app/components/tools/types'
|
|
import {
|
|
useAllBuiltInTools,
|
|
useAllCustomTools,
|
|
useAllMCPTools,
|
|
useAllWorkflowTools,
|
|
} from '@/service/use-tools'
|
|
import { canFindTool } from '@/utils'
|
|
|
|
const useCurrentToolCollection = (
|
|
providerType: ToolNodeType['provider_type'],
|
|
providerId: string,
|
|
) => {
|
|
const { data: buildInTools } = useAllBuiltInTools()
|
|
const { data: customTools } = useAllCustomTools()
|
|
const { data: workflowTools } = useAllWorkflowTools()
|
|
const { data: mcpTools } = useAllMCPTools()
|
|
|
|
const currentTools = useMemo<ToolWithProvider[]>(() => {
|
|
switch (providerType) {
|
|
case CollectionType.builtIn:
|
|
return buildInTools || []
|
|
case CollectionType.custom:
|
|
return customTools || []
|
|
case CollectionType.workflow:
|
|
return workflowTools || []
|
|
case CollectionType.mcp:
|
|
return mcpTools || []
|
|
default:
|
|
return []
|
|
}
|
|
}, [buildInTools, customTools, mcpTools, providerType, workflowTools])
|
|
|
|
const currCollection = useMemo(() => {
|
|
return currentTools.find(item => canFindTool(item.id, providerId))
|
|
}, [currentTools, providerId])
|
|
|
|
return {
|
|
currentTools,
|
|
currCollection,
|
|
}
|
|
}
|
|
|
|
export default useCurrentToolCollection
|