Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class VariableListSerializer(serializers.Serializer):
v_id = serializers.CharField(required=True, label=_("Variable id"))
key = serializers.CharField(required=False, label=_("Key"), allow_null=True, allow_blank=True, )
variable = serializers.ListField(required=True, label=_("Variable"))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def save_context(self, details, workflow_manage):
self.context['exception_message'] = details.get('err_message')

def get_first_non_null(self, variable_list):

for variable in variable_list:
v = self.workflow_manage.get_reference_field(
variable.get('variable')[0],
Expand All @@ -40,12 +39,16 @@ def get_first_non_null(self, variable_list):
return v
return None

def set_variable_to_json(self, variable_list):

def set_variable_to_array(self, variable_list):
return [self.workflow_manage.get_reference_field(
variable.get('variable')[0],
variable.get('variable')[1:]) for variable in variable_list]

def set_variable_to_dict(self, variable_list):
return {(variable.get('key') or variable.get('variable')[-1]): self.workflow_manage.get_reference_field(
variable.get('variable')[0],
variable.get('variable')[1:]) for variable in variable_list}

def reset_variable(self, variable):
value = self.workflow_manage.get_reference_field(
variable.get('variable')[0],
Expand All @@ -65,9 +68,14 @@ def reset_group_list(self, group_list):

def execute(self, strategy, group_list, **kwargs) -> NodeResult:
strategy_map = {'first_non_null': self.get_first_non_null,
'variable_to_json': self.set_variable_to_json,
'variable_to_array': self.set_variable_to_array,
'variable_to_dict': self.set_variable_to_dict,
}

# 向下兼容
if strategy == 'variable_to_json':
strategy = 'variable_to_array'

result = {item.get('field'): strategy_map[strategy](item.get('variable_list')) for item in group_list}

return NodeResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def save_context(self, details, workflow_manage):
self.context['exception_message'] = details.get('err_message')

def execute(self, input_variable, variable_list, **kwargs) -> NodeResult:
if type(input_variable).__name__ == "str":
if isinstance(input_variable, str):
Copy link
Contributor Author

@wangliang181230 wangliang181230 Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前提交的代码,顺便优化一下语法

try:
input_variable = json.loads(input_variable)
except Exception:
Expand Down
8 changes: 5 additions & 3 deletions ui/src/components/execution-detail-card/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,11 @@
</h5>
<div class="p-8-12 border-t-dashed lighter pre-wrap">
{{
data.strategy === 'variable_to_json'
? t('workflow.nodes.variableAggregationNode.placeholder1')
: t('workflow.nodes.variableAggregationNode.placeholder')
data.strategy === 'first_non_null'
? t('workflow.nodes.variableAggregationNode.placeholder')
: data.strategy === 'variable_to_dict'
? t('workflow.nodes.variableAggregationNode.placeholder2')
: t('workflow.nodes.variableAggregationNode.placeholder1')
}}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/locales/lang/en-US/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
ReferencingRequired: 'Referenced variable is required',
ReferencingError: 'Invalid referenced variable',
NoReferencing: 'Referenced variable does not exist',
placeholder_key: 'Enter key',
placeholder: 'Please select a variable',
inputPlaceholder: 'Please enter variable',
loop: 'Loop Variable',
Expand Down Expand Up @@ -323,7 +324,8 @@ You are a master of problem optimization, adept at accurately inferring user int
text: 'Aggregate variables of each group according to the aggregation strategy',
Strategy: 'Aggregation Strategy',
placeholder: 'Return the first non-null value of each group',
placeholder1: 'Return the set of variables for each group',
placeholder1: 'Return the array of variables for each group',
placeholder2: 'Return the dict of variables for each group',
group: {
noneError: 'Name cannot be empty',
dupError: 'Name cannot be duplicated',
Expand Down
4 changes: 3 additions & 1 deletion ui/src/locales/lang/zh-CN/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
ReferencingRequired: '引用变量必填',
ReferencingError: '引用变量错误',
NoReferencing: '不存在的引用变量',
placeholder_key: '请输入键名',
placeholder: '请选择变量',
inputPlaceholder: '请输入变量',
loop: '循环变量',
Expand Down Expand Up @@ -304,7 +305,8 @@ export default {
text: '按聚合策略聚合每组的变量',
Strategy: '聚合策略',
placeholder: '返回每组的第一个非空值',
placeholder1: '返回每组变量的集合',
placeholder1: '返回每组变量的数组(Array)',
placeholder2: '返回每组变量的字典(Dict)',
group: {
noneError: '名称不能为空',
dupError: '名称不能重复',
Expand Down
4 changes: 3 additions & 1 deletion ui/src/locales/lang/zh-Hant/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
ReferencingRequired: '引用變量必填',
ReferencingError: '引用變量錯誤',
NoReferencing: '不存在的引用變量',
placeholder_key: '請輸入鍵名',
placeholder: '請選擇變量',
inputPlaceholder: '請輸入變量',
loop: '循環變量',
Expand Down Expand Up @@ -322,7 +323,8 @@ export default {
text: '按聚合策略聚合每組的變量',
Strategy: '聚合策略',
placeholder: '返回每組的第一個非空值',
placeholder1: '返回每組變量的集合',
placeholder1: '返回每組變量的數組(Array)',
placeholder2: '返回每組變量的字典(Dict)',
group: {
noneError: '名稱不能為空',
dupError: '名稱不能重複',
Expand Down
8 changes: 7 additions & 1 deletion ui/src/workflow/nodes/variable-aggregation-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ class VariableAggregationNode extends AppNode {
}
}

class VariableAggregationNodeModel extends AppNodeModel {
get_width() {
return 450
}
}

export default {
type: 'variable-aggregation-node',
model: AppNodeModel,
model: VariableAggregationNodeModel,
view: VariableAggregationNode,
}
20 changes: 17 additions & 3 deletions ui/src/workflow/nodes/variable-aggregation-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
/>
<el-option
:label="t('workflow.nodes.variableAggregationNode.placeholder1')"
value="variable_to_json"
value="variable_to_array"
/>
<el-option
:label="t('workflow.nodes.variableAggregationNode.placeholder2')"
value="variable_to_dict"
/>
</el-select>
</el-form-item>
Expand Down Expand Up @@ -77,10 +81,17 @@
trigger: 'change',
}"
>
<el-input
v-if="form_data.strategy === 'variable_to_dict'"
v-model="item.key"
:placeholder="$t('workflow.variable.placeholder_key')"
style="width: 100px; margin-right: 8px"
maxlength="256"
/>
<NodeCascader
ref="nodeCascaderRef"
:nodeModel="nodeModel"
style="width: 200px"
:style="{ width: form_data.strategy === 'variable_to_dict' ? '200px' : '308px'}"
:placeholder="$t('workflow.variable.placeholder')"
v-model="item.variable"
/>
Expand Down Expand Up @@ -149,7 +160,10 @@ const form = {
const form_data = computed({
get: () => {
if (props.nodeModel.properties.node_data) {
return props.nodeModel.properties.node_data
// 向下兼容
if (props.nodeModel.properties.node_data.strategy === 'variable_to_json') {
props.nodeModel.properties.node_data.strategy = 'variable_to_array'
}
} else {
set(props.nodeModel.properties, 'node_data', form)
}
Expand Down
Loading