mirror of
https://github.com/langgenius/dify.git
synced 2026-04-25 01:26:57 +08:00
fix: add block enumeration and tool icon handling for enhanced workflow functionality
This commit is contained in:
parent
682b65034c
commit
6313f819cf
5
web/app/components/workflow/blocks.tsx
Normal file
5
web/app/components/workflow/blocks.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { BlockEnum } from './types'
|
||||||
|
|
||||||
|
export const ALL_AVAILABLE_BLOCKS = Object.values(BlockEnum)
|
||||||
|
export const ALL_CHAT_AVAILABLE_BLOCKS = ALL_AVAILABLE_BLOCKS.filter(key => key !== BlockEnum.End && key !== BlockEnum.Start) as BlockEnum[]
|
||||||
|
export const ALL_COMPLETION_AVAILABLE_BLOCKS = ALL_AVAILABLE_BLOCKS.filter(key => key !== BlockEnum.Answer && key !== BlockEnum.Start) as BlockEnum[]
|
||||||
@ -19,22 +19,27 @@ export const useToolIcon = (data: Node['data']) => {
|
|||||||
const buildInTools = useStore(s => s.buildInTools)
|
const buildInTools = useStore(s => s.buildInTools)
|
||||||
const customTools = useStore(s => s.customTools)
|
const customTools = useStore(s => s.customTools)
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
const workflowTools = useStore(s => s.workflowTools)
|
||||||
|
const mcpTools = useStore(s => s.mcpTools)
|
||||||
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(() => {
|
||||||
|
if (!data)
|
||||||
|
return ''
|
||||||
if (data.type === BlockEnum.Tool) {
|
if (data.type === BlockEnum.Tool) {
|
||||||
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)
|
||||||
|
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)
|
||||||
return dataSourceList?.find(toolWithProvider => toolWithProvider.plugin_id === data.plugin_id)?.icon
|
return dataSourceList?.find(toolWithProvider => toolWithProvider.plugin_id === data.plugin_id)?.icon
|
||||||
}, [data, buildInTools, customTools, workflowTools, dataSourceList])
|
}, [data, dataSourceList, buildInTools, customTools, mcpTools, workflowTools])
|
||||||
|
|
||||||
return toolIcon
|
return toolIcon
|
||||||
}
|
}
|
||||||
|
|||||||
@ -550,32 +550,6 @@ export const useNodesReadOnly = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 toolIcon = useMemo(() => {
|
|
||||||
if (!data)
|
|
||||||
return ''
|
|
||||||
if (data.type === BlockEnum.Tool) {
|
|
||||||
let targetTools = buildInTools
|
|
||||||
if (data.provider_type === CollectionType.builtIn)
|
|
||||||
targetTools = buildInTools
|
|
||||||
else if (data.provider_type === CollectionType.custom)
|
|
||||||
targetTools = customTools
|
|
||||||
else if (data.provider_type === CollectionType.mcp)
|
|
||||||
targetTools = mcpTools
|
|
||||||
else
|
|
||||||
targetTools = workflowTools
|
|
||||||
return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon
|
|
||||||
}
|
|
||||||
}, [data, buildInTools, customTools, mcpTools, workflowTools])
|
|
||||||
|
|
||||||
return toolIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useIsNodeInIteration = (iterationId: string) => {
|
export const useIsNodeInIteration = (iterationId: string) => {
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import type { StrategyDetail, StrategyPluginDetail } from '@/app/components/plugins/types'
|
import type { StrategyDetail, StrategyPluginDetail } from '@/app/components/plugins/types'
|
||||||
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/blocks'
|
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/blocks'
|
||||||
import type { NodeDefault } from '../../types'
|
import { BlockEnum, type NodeDefault } from '../../types'
|
||||||
import type { AgentNodeType } from './types'
|
import type { AgentNodeType } from './types'
|
||||||
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
import { renderI18nObject } from '@/i18n'
|
import { renderI18nObject } from '@/i18n'
|
||||||
|
import { genNodeMetaData } from '../../utils'
|
||||||
|
|
||||||
const metaData = genNodeMetaData({
|
const metaData = genNodeMetaData({
|
||||||
sort: 3,
|
sort: 3,
|
||||||
|
|||||||
@ -322,6 +322,8 @@ export type NodeDefault<T = {}> = {
|
|||||||
}
|
}
|
||||||
defaultValue: Partial<T>
|
defaultValue: Partial<T>
|
||||||
defaultRunInputData?: Record<string, any>
|
defaultRunInputData?: Record<string, any>
|
||||||
|
getAvailablePrevNodes: (isChatMode: boolean) => BlockEnum[]
|
||||||
|
getAvailableNextNodes: (isChatMode: boolean) => BlockEnum[]
|
||||||
checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string }
|
checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string }
|
||||||
getOutputVars?: (payload: T, ragVariables?: Var[]) => Var[]
|
getOutputVars?: (payload: T, ragVariables?: Var[]) => Var[]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user