Skip to content

Commit f40124b

Browse files
committed
feat: Support variable assign dict array value config
1 parent 92fd83c commit f40124b

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

apps/application/flow/step_node/variable_assign/impl/base_variable_assign_node.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# coding=utf-8
2+
import json
23
from typing import List
34

45
from application.flow.i_step_node import NodeResult
@@ -18,18 +19,25 @@ def execute(self, variable_list, stream, **kwargs) -> NodeResult:
1819
continue
1920
if 'global' == variable['fields'][0]:
2021
result = {
21-
'name': variable['fields'][1],
22+
'name': variable['name'],
2223
'input_value': self.get_reference_content(variable['fields']),
2324
}
2425
if variable['source'] == 'custom':
25-
self.workflow_manage.context[variable['fields'][1]] = variable['value']
26-
result['output_value'] = variable['value']
26+
if variable['type'] in ['dict', 'array']:
27+
if isinstance(variable['value'], dict) or isinstance(variable['value'], list):
28+
val = variable['value']
29+
else:
30+
val = json.loads(variable['value'])
31+
self.workflow_manage.context[variable['fields'][1]] = val
32+
result['output_value'] = variable['value'] = val
33+
else:
34+
self.workflow_manage.context[variable['fields'][1]] = variable['value']
35+
result['output_value'] = variable['value']
2736
else:
2837
reference = self.get_reference_content(variable['reference'])
2938
self.workflow_manage.context[variable['fields'][1]] = reference
3039
result['output_value'] = reference
3140
result_list.append(result)
32-
print(result_list)
3341

3442
return NodeResult({'variable_list': variable_list, 'result_list': result_list}, {})
3543

ui/src/components/ai-chat/ExecutionDetailDialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@
615615
{{ $t('common.param.inputParam') }}
616616
</h5>
617617
<div class="p-8-12 border-t-dashed lighter">
618-
<div v-for="(f, i) in item.variable_list" :key="i" class="mb-8">
618+
<div v-for="(f, i) in item.result_list" :key="i" class="mb-8">
619619
<span class="color-secondary">{{ f.name }}:</span> {{ f.input_value }}
620620
</div>
621621
</div>
@@ -625,7 +625,7 @@
625625
{{ $t('common.param.outputParam') }}
626626
</h5>
627627
<div class="p-8-12 border-t-dashed lighter">
628-
<div v-for="(f, i) in item.variable_list" :key="i" class="mb-8">
628+
<div v-for="(f, i) in item.result_list" :key="i" class="mb-8">
629629
<span class="color-secondary">{{ f.name }}:</span> {{ f.output_value }}
630630
</div>
631631
</div>

ui/src/workflow/nodes/variable-assign-node/index.vue

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
:placeholder="$t('views.applicationWorkflow.variable.placeholder')"
3232
v-model="item.fields"
3333
:global="true"
34+
@change="variableChange(item)"
3435
/>
3536
</el-form-item>
3637
<el-form-item>
3738
<template #label>
3839
<div class="flex-between">
3940
<div>
4041
<span
41-
>{{ $t('views.applicationWorkflow.nodes.variableAssignNode.assign')
42+
>{{ $t('views.applicationWorkflow.nodes.variableAssignNode.assign')
4243
}}<span class="danger">*</span></span
4344
>
4445
</div>
@@ -116,7 +117,15 @@ const wheel = (e: any) => {
116117
}
117118
const form = {
118119
variable_list: [
119-
{ id: randomId(), fields: [], value: null, reference: [], type: 'string', source: 'custom' }
120+
{
121+
id: randomId(),
122+
fields: [],
123+
value: null,
124+
reference: [],
125+
type: 'string',
126+
source: 'custom',
127+
name: ''
128+
}
120129
]
121130
}
122131
@@ -154,10 +163,10 @@ function addVariable() {
154163
value: null,
155164
reference: [],
156165
type: 'string',
157-
source: 'custom'
166+
source: 'custom',
167+
name: ''
158168
}
159169
list.push(obj)
160-
console.log(list)
161170
set(props.nodeModel.properties.node_data, 'variable_list', list)
162171
}
163172
@@ -167,6 +176,18 @@ function deleteVariable(index: number) {
167176
set(props.nodeModel.properties.node_data, 'variable_list', list)
168177
}
169178
179+
function variableChange(item: any) {
180+
props.nodeModel.graphModel.nodes.map((node: any) => {
181+
if (node.id === 'start-node') {
182+
node.properties.config.globalFields.forEach((field: any) => {
183+
if (field.value === item.fields[1]) {
184+
item.name = field.label
185+
}
186+
})
187+
}
188+
})
189+
}
190+
170191
onMounted(() => {
171192
if (typeof props.nodeModel.properties.node_data?.is_result === 'undefined') {
172193
if (isLastNode(props.nodeModel)) {

0 commit comments

Comments
 (0)