diff --git a/apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py b/apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py index 4878f0c4c0c..87555baf2fa 100644 --- a/apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py +++ b/apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py @@ -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")) diff --git a/apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py b/apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py index e3390dfc2b9..fa1d6479e5c 100644 --- a/apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py +++ b/apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py @@ -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], @@ -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], @@ -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( diff --git a/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py b/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py index c11b79a7b30..f19d45b1d37 100644 --- a/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py +++ b/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py @@ -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): try: input_variable = json.loads(input_variable) except Exception: diff --git a/ui/src/components/execution-detail-card/index.vue b/ui/src/components/execution-detail-card/index.vue index 180b1c7dfb7..e68bc472e78 100644 --- a/ui/src/components/execution-detail-card/index.vue +++ b/ui/src/components/execution-detail-card/index.vue @@ -930,9 +930,11 @@
{{ - 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') }}
diff --git a/ui/src/locales/lang/en-US/workflow.ts b/ui/src/locales/lang/en-US/workflow.ts index 939706357f9..74fa49f04b4 100644 --- a/ui/src/locales/lang/en-US/workflow.ts +++ b/ui/src/locales/lang/en-US/workflow.ts @@ -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', @@ -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', diff --git a/ui/src/locales/lang/zh-CN/workflow.ts b/ui/src/locales/lang/zh-CN/workflow.ts index 79164f83bff..0f069ddeccd 100644 --- a/ui/src/locales/lang/zh-CN/workflow.ts +++ b/ui/src/locales/lang/zh-CN/workflow.ts @@ -60,6 +60,7 @@ export default { ReferencingRequired: '引用变量必填', ReferencingError: '引用变量错误', NoReferencing: '不存在的引用变量', + placeholder_key: '请输入键名', placeholder: '请选择变量', inputPlaceholder: '请输入变量', loop: '循环变量', @@ -304,7 +305,8 @@ export default { text: '按聚合策略聚合每组的变量', Strategy: '聚合策略', placeholder: '返回每组的第一个非空值', - placeholder1: '返回每组变量的集合', + placeholder1: '返回每组变量的数组(Array)', + placeholder2: '返回每组变量的字典(Dict)', group: { noneError: '名称不能为空', dupError: '名称不能重复', diff --git a/ui/src/locales/lang/zh-Hant/workflow.ts b/ui/src/locales/lang/zh-Hant/workflow.ts index 326b8c5e863..25d844d783f 100644 --- a/ui/src/locales/lang/zh-Hant/workflow.ts +++ b/ui/src/locales/lang/zh-Hant/workflow.ts @@ -60,6 +60,7 @@ export default { ReferencingRequired: '引用變量必填', ReferencingError: '引用變量錯誤', NoReferencing: '不存在的引用變量', + placeholder_key: '請輸入鍵名', placeholder: '請選擇變量', inputPlaceholder: '請輸入變量', loop: '循環變量', @@ -322,7 +323,8 @@ export default { text: '按聚合策略聚合每組的變量', Strategy: '聚合策略', placeholder: '返回每組的第一個非空值', - placeholder1: '返回每組變量的集合', + placeholder1: '返回每組變量的數組(Array)', + placeholder2: '返回每組變量的字典(Dict)', group: { noneError: '名稱不能為空', dupError: '名稱不能重複', diff --git a/ui/src/workflow/nodes/variable-aggregation-node/index.ts b/ui/src/workflow/nodes/variable-aggregation-node/index.ts index 1f2c433de60..3cddd2c9734 100644 --- a/ui/src/workflow/nodes/variable-aggregation-node/index.ts +++ b/ui/src/workflow/nodes/variable-aggregation-node/index.ts @@ -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, } diff --git a/ui/src/workflow/nodes/variable-aggregation-node/index.vue b/ui/src/workflow/nodes/variable-aggregation-node/index.vue index c40a7e4aa7b..ead21a59e20 100644 --- a/ui/src/workflow/nodes/variable-aggregation-node/index.vue +++ b/ui/src/workflow/nodes/variable-aggregation-node/index.vue @@ -34,7 +34,11 @@ /> + @@ -77,10 +81,17 @@ trigger: 'change', }" > + @@ -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) }