diff --git a/packages/global/core/workflow/runtime/constants.ts b/packages/global/core/workflow/runtime/constants.ts index 950c6de9b..9289e2b17 100644 --- a/packages/global/core/workflow/runtime/constants.ts +++ b/packages/global/core/workflow/runtime/constants.ts @@ -10,7 +10,7 @@ export enum SseResponseEventEnum { toolParams = 'toolParams', // tool params return toolResponse = 'toolResponse', // tool response return flowResponses = 'flowResponses', // sse response request - variables = 'variables' + updateVariables = 'updateVariables' } export enum DispatchNodeResponseKeyEnum { diff --git a/packages/global/core/workflow/template/constants.ts b/packages/global/core/workflow/template/constants.ts index be909a9d2..f16908175 100644 --- a/packages/global/core/workflow/template/constants.ts +++ b/packages/global/core/workflow/template/constants.ts @@ -19,9 +19,9 @@ import { RunPluginModule } from './system/runPlugin'; import { AiQueryExtension } from './system/queryExtension'; import type { FlowNodeTemplateType } from '../type'; -import { lafModule } from './system/laf'; -import { ifElseNode } from './system/ifElse/index'; -import { variableUpdateNode } from './system/variableUpdate'; +import { LafModule } from './system/laf'; +import { IfElseNode } from './system/ifElse/index'; +import { VariableUpdateNode } from './system/variableUpdate'; /* app flow module templates */ export const appSystemModuleTemplates: FlowNodeTemplateType[] = [ @@ -38,9 +38,9 @@ export const appSystemModuleTemplates: FlowNodeTemplateType[] = [ ContextExtractModule, HttpModule468, AiQueryExtension, - lafModule, - ifElseNode, - variableUpdateNode + LafModule, + IfElseNode, + VariableUpdateNode ]; /* plugin flow module templates */ export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [ @@ -57,9 +57,9 @@ export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [ ContextExtractModule, HttpModule468, AiQueryExtension, - lafModule, - ifElseNode, - variableUpdateNode + LafModule, + IfElseNode, + VariableUpdateNode ]; /* all module */ @@ -82,7 +82,7 @@ export const moduleTemplatesFlat: FlowNodeTemplateType[] = [ PluginOutputModule, RunPluginModule, AiQueryExtension, - lafModule, - ifElseNode, - variableUpdateNode + LafModule, + IfElseNode, + VariableUpdateNode ]; diff --git a/packages/global/core/workflow/template/system/ifElse/index.ts b/packages/global/core/workflow/template/system/ifElse/index.ts index d9a7f0a66..aedc4c32c 100644 --- a/packages/global/core/workflow/template/system/ifElse/index.ts +++ b/packages/global/core/workflow/template/system/ifElse/index.ts @@ -12,7 +12,7 @@ import { import { FlowNodeTemplateType } from '../../../type'; import { getHandleConfig } from '../../utils'; -export const ifElseNode: FlowNodeTemplateType = { +export const IfElseNode: FlowNodeTemplateType = { id: FlowNodeTypeEnum.ifElseNode, templateType: FlowNodeTemplateTypeEnum.tools, flowNodeType: FlowNodeTypeEnum.ifElseNode, diff --git a/packages/global/core/workflow/template/system/laf.ts b/packages/global/core/workflow/template/system/laf.ts index ef2206bc1..2140432bb 100644 --- a/packages/global/core/workflow/template/system/laf.ts +++ b/packages/global/core/workflow/template/system/laf.ts @@ -14,7 +14,7 @@ import { Input_Template_DynamicInput } from '../input'; import { Output_Template_AddOutput } from '../output'; import { getHandleConfig } from '../utils'; -export const lafModule: FlowNodeTemplateType = { +export const LafModule: FlowNodeTemplateType = { id: FlowNodeTypeEnum.lafModule, templateType: FlowNodeTemplateTypeEnum.externalCall, flowNodeType: FlowNodeTypeEnum.lafModule, diff --git a/packages/global/core/workflow/template/system/variableUpdate/index.tsx b/packages/global/core/workflow/template/system/variableUpdate/index.tsx index 3871bc5fb..24621358e 100644 --- a/packages/global/core/workflow/template/system/variableUpdate/index.tsx +++ b/packages/global/core/workflow/template/system/variableUpdate/index.tsx @@ -7,7 +7,7 @@ import { } from '../../../constants'; import { getHandleConfig } from '../../utils'; -export const variableUpdateNode: FlowNodeTemplateType = { +export const VariableUpdateNode: FlowNodeTemplateType = { id: FlowNodeTypeEnum.variableUpdate, templateType: FlowNodeTemplateTypeEnum.tools, flowNodeType: FlowNodeTypeEnum.variableUpdate, @@ -28,7 +28,13 @@ export const variableUpdateNode: FlowNodeTemplateType = { key: true, valueType: true }, - value: [] + value: [ + { + variable: ['', ''], + value: '', + renderType: FlowNodeInputTypeEnum.input + } + ] } ], outputs: [] diff --git a/packages/global/core/workflow/template/system/variableUpdate/type.d.ts b/packages/global/core/workflow/template/system/variableUpdate/type.d.ts index fffe90565..44e15a1ad 100644 --- a/packages/global/core/workflow/template/system/variableUpdate/type.d.ts +++ b/packages/global/core/workflow/template/system/variableUpdate/type.d.ts @@ -1,3 +1,5 @@ +import { FlowNodeInputTypeEnum } from 'core/workflow/node/constant'; + export type TUpdateListItem = { variable?: ReferenceValueProps; value?: ReferenceValueProps; diff --git a/projects/app/src/components/core/workflow/Flow/nodes/NodeVariableUpdate.tsx b/projects/app/src/components/core/workflow/Flow/nodes/NodeVariableUpdate.tsx index 7a8fef7a3..88b199766 100644 --- a/projects/app/src/components/core/workflow/Flow/nodes/NodeVariableUpdate.tsx +++ b/projects/app/src/components/core/workflow/Flow/nodes/NodeVariableUpdate.tsx @@ -30,6 +30,7 @@ import { SmallAddIcon } from '@chakra-ui/icons'; import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; import { ReferenceValueProps } from '@fastgpt/global/core/workflow/type/io'; import { ReferSelector, useReference } from './render/RenderInput/templates/Reference'; +import { getWorkflowGlobalVariables } from '@/web/core/workflow/utils'; const NodeVariableUpdate = ({ data, selected }: NodeProps) => { const { inputs = [], nodeId } = data; @@ -37,6 +38,7 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps) => const onChangeNode = useContextSelector(WorkflowContext, (v) => v.onChangeNode); const nodes = useContextSelector(WorkflowContext, (v) => v.nodes); + const nodeList = useContextSelector(WorkflowContext, (v) => v.nodeList); const updateList = useMemo( () => @@ -84,10 +86,10 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps) => const variable = updateItem.variable; const variableNodeId = variable?.[0]; const variableNode = nodes.find((node) => node.id === variableNodeId); - if (!variableNode) return 'any'; - const variableInput = variableNode.data.outputs.find( - (output) => output.id === variable?.[1] - ); + const systemVariables = getWorkflowGlobalVariables(nodeList, t); + const variableInput = !variableNode + ? systemVariables.find((item) => item.key === variable?.[1]) + : variableNode?.data.outputs.find((output) => output.id === variable?.[1]); if (!variableInput) return 'any'; return variableInput.valueType; })(); @@ -95,9 +97,7 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps) => const renderTypeData = menuList.find((item) => item.renderType === updateItem.renderType); const handleUpdate = (newValue: any) => { onUpdateList( - updateList.map((update, i) => - i === index ? { ...update, value: ['', newValue] } : update - ) + updateList.map((update, i) => (i === index ? { ...update, value: newValue } : update)) ); }; return ( @@ -123,20 +123,22 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps) => }} /> - { - onUpdateList(updateList.filter((_, i) => i !== index)); - }} - /> + {updateList.length > 1 && ( + { + onUpdateList(updateList.filter((_, i) => i !== index)); + }} + /> + )} - + {t('core.workflow.value')}