diff --git a/web/app/components/workflow/blocks.tsx b/web/app/components/workflow/blocks.tsx new file mode 100644 index 0000000000..334ddbf087 --- /dev/null +++ b/web/app/components/workflow/blocks.tsx @@ -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[] diff --git a/web/app/components/workflow/hooks/use-tool-icon.ts b/web/app/components/workflow/hooks/use-tool-icon.ts index 49c413a2e4..921e097d74 100644 --- a/web/app/components/workflow/hooks/use-tool-icon.ts +++ b/web/app/components/workflow/hooks/use-tool-icon.ts @@ -19,22 +19,27 @@ 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 dataSourceList = useStore(s => s.dataSourceList) // const a = useStore(s => s.data) 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 } if (data.type === BlockEnum.DataSource) return dataSourceList?.find(toolWithProvider => toolWithProvider.plugin_id === data.plugin_id)?.icon - }, [data, buildInTools, customTools, workflowTools, dataSourceList]) + }, [data, dataSourceList, buildInTools, customTools, mcpTools, workflowTools]) return toolIcon } diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index a0e159043d..3f65dd54c8 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -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) => { const store = useStoreApi() diff --git a/web/app/components/workflow/nodes/agent/default.ts b/web/app/components/workflow/nodes/agent/default.ts index d90ae82779..ec0df2a2ff 100644 --- a/web/app/components/workflow/nodes/agent/default.ts +++ b/web/app/components/workflow/nodes/agent/default.ts @@ -1,9 +1,10 @@ import type { StrategyDetail, StrategyPluginDetail } from '@/app/components/plugins/types' 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 { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { renderI18nObject } from '@/i18n' +import { genNodeMetaData } from '../../utils' const metaData = genNodeMetaData({ sort: 3, diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 5a471d9920..fd80e74c24 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -322,6 +322,8 @@ export type NodeDefault = { } defaultValue: Partial defaultRunInputData?: Record + getAvailablePrevNodes: (isChatMode: boolean) => BlockEnum[] + getAvailableNextNodes: (isChatMode: boolean) => BlockEnum[] checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string } getOutputVars?: (payload: T, ragVariables?: Var[]) => Var[] }