Skip to content

Commit b13da71

Browse files
committed
fix: Allow variables to be assigned as the end node of the loop node
1 parent 8d4bad5 commit b13da71

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

ui/src/workflow/common/validate.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { WorkflowType } from '@/enums/application'
1+
import { WorkflowType, WorkflowMode } from '@/enums/application'
2+
23
import { t } from '@/locales'
34

45
const end_nodes: Array<string> = [
@@ -18,14 +19,39 @@ const end_nodes: Array<string> = [
1819
WorkflowType.LoopNode,
1920
WorkflowType.LoopBreakNode,
2021
]
22+
23+
const loop_end_nodes: Array<string> = [
24+
WorkflowType.AiChat,
25+
WorkflowType.Reply,
26+
WorkflowType.ToolLib,
27+
WorkflowType.ToolLibCustom,
28+
WorkflowType.ImageUnderstandNode,
29+
WorkflowType.Application,
30+
WorkflowType.SpeechToTextNode,
31+
WorkflowType.TextToSpeechNode,
32+
WorkflowType.ImageGenerateNode,
33+
WorkflowType.ImageToVideoGenerateNode,
34+
WorkflowType.TextToVideoGenerateNode,
35+
WorkflowType.ImageGenerateNode,
36+
WorkflowType.LoopBodyNode,
37+
WorkflowType.LoopNode,
38+
WorkflowType.LoopBreakNode,
39+
WorkflowType.VariableAssignNode,
40+
]
41+
const end_nodes_dict = {
42+
[WorkflowMode.Application]: end_nodes,
43+
[WorkflowMode.ApplicationLoop]: loop_end_nodes,
44+
}
2145
export class WorkFlowInstance {
2246
nodes
2347
edges
2448
workFlowNodes: Array<any>
25-
constructor(workflow: { nodes: Array<any>; edges: Array<any> }) {
49+
workflowModel: WorkflowMode
50+
constructor(workflow: { nodes: Array<any>; edges: Array<any> }, workflowModel?: WorkflowMode) {
2651
this.nodes = workflow.nodes
2752
this.edges = workflow.edges
2853
this.workFlowNodes = []
54+
this.workflowModel = workflowModel ? workflowModel : WorkflowMode.Application
2955
}
3056
/**
3157
* 校验开始节点
@@ -124,7 +150,8 @@ export class WorkFlowInstance {
124150
const node_list = edge_list
125151
.map((edge) => this.nodes.filter((node) => node.id == edge.targetNodeId))
126152
.reduce((x, y) => [...x, ...y], [])
127-
if (node_list.length == 0 && !end_nodes.includes(node.type)) {
153+
const end = end_nodes_dict[this.workflowModel]
154+
if (node_list.length == 0 && !end.includes(node.type)) {
128155
throw t('views.applicationWorkflow.validate.noNextNode')
129156
}
130157
return node_list
@@ -161,7 +188,8 @@ export class WorkFlowInstance {
161188
}
162189
} else {
163190
const edge_list = this.edges.filter((edge) => edge.sourceNodeId == node.id)
164-
if (edge_list.length == 0 && !end_nodes.includes(node.type)) {
191+
const end = end_nodes_dict[this.workflowModel]
192+
if (edge_list.length == 0 && !end.includes(node.type)) {
165193
throw `${node.properties.stepName} ${t('views.applicationWorkflow.validate.cannotEndNode')}`
166194
}
167195
}

ui/src/workflow/nodes/loop-body-node/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const props = defineProps<{ nodeModel: any }>()
1919
const containerRef = ref()
2020
2121
const validate = () => {
22-
const workflow = new WorkFlowInstance(lf.value.getGraphData())
22+
const workflow = new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop)
2323
return Promise.all(lf.value.graphModel.nodes.map((element: any) => element?.validate?.()))
2424
.then(() => {
2525
const loop_node_id = props.nodeModel.properties.loop_node_id

0 commit comments

Comments
 (0)