Feat: IfElse node support variable reference (#5025)

* if else node support reference (#5016)

* if else node support reference

* optimize input render

* ui

* fix

---------

Co-authored-by: Archer <545436317@qq.com>

* fix: chat

* perf: download invoice

* optimize ifelse node ui (#5024)

* perf: ifelse node

* optimize type (#5027)

---------

Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
Archer
2025-06-13 17:15:24 +08:00
committed by GitHub
parent 8acb16f9f2
commit 0914eacb5e
29 changed files with 393 additions and 276 deletions

View File

@@ -1,7 +1,10 @@
import type { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import { type DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type';
import {
type RuntimeNodeItemType,
type DispatchNodeResultType
} from '@fastgpt/global/core/workflow/runtime/type';
import {
IfElseResultEnum,
VariableConditionEnum
@@ -14,6 +17,7 @@ import {
import { type ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/type';
import { getElseIFLabel, getHandleId } from '@fastgpt/global/core/workflow/utils';
import { getReferenceVariableValue } from '@fastgpt/global/core/workflow/runtime/utils';
import { type ReferenceItemValueType } from '@fastgpt/global/core/workflow/type/io';
type Props = ModuleDispatchProps<{
[NodeInputKeyEnum.condition]: IfElseConditionType;
@@ -49,7 +53,7 @@ function isInclude(value: any, target: any) {
}
}
function checkCondition(condition: VariableConditionEnum, inputValue: any, value: string) {
function checkCondition(condition: VariableConditionEnum, inputValue: any, value: any) {
const operations: Record<VariableConditionEnum, () => boolean> = {
[VariableConditionEnum.isEmpty]: () => isEmpty(inputValue),
[VariableConditionEnum.isNotEmpty]: () => !isEmpty(inputValue),
@@ -100,19 +104,29 @@ function checkCondition(condition: VariableConditionEnum, inputValue: any, value
function getResult(
condition: IfElseConditionType,
list: ConditionListItemType[],
variables: any,
runtimeNodes: any[]
variables: Record<string, any>,
runtimeNodes: RuntimeNodeItemType[]
) {
const listResult = list.map((item) => {
const { variable, condition: variableCondition, value } = item;
const { variable, condition: variableCondition, value, valueType } = item;
if (!variableCondition) return;
const inputValue = getReferenceVariableValue({
const conditionLeftValue = getReferenceVariableValue({
value: variable,
variables,
nodes: runtimeNodes
});
return checkCondition(variableCondition as VariableConditionEnum, inputValue, value || '');
const conditionRightValue =
valueType === 'reference'
? getReferenceVariableValue({
value: value as ReferenceItemValueType,
variables,
nodes: runtimeNodes
})
: value;
return checkCondition(variableCondition, conditionLeftValue, conditionRightValue);
});
return condition === 'AND' ? listResult.every(Boolean) : listResult.some(Boolean);