Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: workflow loop node break conditions (#15549)

zxhlyhb541792465c7
diff --git a/web/app/components/workflow/nodes/loop/default.ts b/web/app/components/workflow/nodes/loop/default.ts
index ded8afc517f..67b1f6edde1 100644
--- a/web/app/components/workflow/nodes/loop/default.ts
+++ b/web/app/components/workflow/nodes/loop/default.ts
@@ -28,9 +28,6 @@ const nodeDefault: NodeDefault<LoopNodeType> = {
checkValid(payload: LoopNodeType, t: any) {
let errorMessages = ''
- if (!errorMessages && (!payload.break_conditions || payload.break_conditions.length === 0))
- errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.loop.breakCondition') })
-
payload.break_conditions!.forEach((condition) => {
if (!errorMessages && (!condition.variable_selector || condition.variable_selector.length === 0))
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variable`) })
diff --git a/web/app/components/workflow/nodes/loop/panel.tsx b/web/app/components/workflow/nodes/loop/panel.tsx
index e416e8d77ef..e361749f6df 100644
--- a/web/app/components/workflow/nodes/loop/panel.tsx
+++ b/web/app/components/workflow/nodes/loop/panel.tsx
@@ -55,6 +55,7 @@ const Panel: FC<NodePanelProps<LoopNodeType>> = ({
<div>
<Field
title={<div className='pl-3'>{t(`${i18nPrefix}.breakCondition`)}</div>}
+ tooltip={t(`${i18nPrefix}.breakConditionTip`)}
>
<ConditionWrap
nodeId={id}
diff --git a/web/app/components/workflow/nodes/loop/use-config.ts b/web/app/components/workflow/nodes/loop/use-config.ts
index 91eb81c46bc..6584628d8c3 100644
--- a/web/app/components/workflow/nodes/loop/use-config.ts
+++ b/web/app/components/workflow/nodes/loop/use-config.ts
@@ -17,12 +17,14 @@ import { getOperators } from './utils'
import { LogicalOperator } from './types'
import type { HandleAddCondition, HandleAddSubVariableCondition, HandleRemoveCondition, HandleToggleConditionLogicalOperator, HandleToggleSubVariableConditionLogicalOperator, HandleUpdateCondition, HandleUpdateSubVariableCondition, LoopNodeType } from './types'
import useIsVarFileAttribute from './use-is-var-file-attribute'
+import { useStore } from '@/app/components/workflow/store'
const DELIMITER = '@@@@@'
const useConfig = (id: string, payload: LoopNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const { isNodeInLoop } = useIsNodeInLoop(id)
const isChatMode = useIsChatMode()
+ const conversationVariables = useStore(s => s.conversationVariables)
const { inputs, setInputs } = useNodeCrud<LoopNodeType>(id, payload)
@@ -35,7 +37,7 @@ const useConfig = (id: string, payload: LoopNodeType) => {
const beforeNodes = getBeforeNodesInSameBranch(id)
const loopChildrenNodes = getLoopNodeChildren(id)
const canChooseVarNodes = [...beforeNodes, ...loopChildrenNodes]
- const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode)
+ const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode, undefined, [], conversationVariables)
// single run
const loopInputKey = `${id}.input_selector`
diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts
index 704364b20ae..a6dd4deb73f 100644
--- a/web/i18n/en-US/workflow.ts
+++ b/web/i18n/en-US/workflow.ts
@@ -673,6 +673,7 @@ const translation = {
loop_other: '{{count}} Loops',
currentLoop: 'Current Loop',
breakCondition: 'Loop Termination Condition',
+ breakConditionTip: 'Only variables within loops with termination conditions and conversation variables can be referenced.',
loopMaxCount: 'Maximum Loop Count',
loopMaxCountError: 'Please enter a valid maximum loop count, ranging from 1 to {{maxCount}}',
errorResponseMethod: 'Error Response Method',
diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts
index 7cf6853f87e..523a93b46d3 100644
--- a/web/i18n/zh-Hans/workflow.ts
+++ b/web/i18n/zh-Hans/workflow.ts
@@ -674,6 +674,7 @@ const translation = {
loop_other: '{{count}} 个循环',
currentLoop: '当前循环',
breakCondition: '循环终止条件',
+ breakConditionTip: '支持引用终止条件循环内的变量和会话变量。',
loopMaxCount: '最大循环次数',
loopMaxCountError: '请输入正确的 最大循环次数,范围为 1 到 {{maxCount}}',
errorResponseMethod: '错误响应方法',