Skip to content

Commit af6eafc

Browse files
committed
[app-builder] add new feature variable-updater-node
1 parent 859a253 commit af6eafc

File tree

7 files changed

+167
-0
lines changed

7 files changed

+167
-0
lines changed

app-builder/plugins/aipp-plugin/src/main/resources/component/basic_node_en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
"name": "Variable Aggregation",
5555
"uniqueName": ""
5656
},
57+
{
58+
"type": "variableUpdateNodeState",
59+
"name": "Variable Update",
60+
"uniqueName": ""
61+
},
5762
{
5863
"type": "fileExtractionNodeState",
5964
"name": "File Extraction",

app-builder/plugins/aipp-plugin/src/main/resources/component/basic_node_zh.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
"name": "变量聚合",
5555
"uniqueName": ""
5656
},
57+
{
58+
"type": "variableUpdateNodeState",
59+
"name": "变量更新",
60+
"uniqueName": ""
61+
},
5762
{
5863
"type": "fileExtractionNodeState",
5964
"name": "文件提取",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>modelengine.fit.jade</groupId>
8+
<artifactId>app-builder-plugin-parent</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>modelengine.fit.jade.plugin</groupId>
13+
<artifactId>aipp-variable-updater</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>modelengine.fit.jade.waterflow</groupId>
18+
<artifactId>waterflow-runtime-service</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>modelengine.fit.jade</groupId>
22+
<artifactId>aipp-genericable</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>modelengine.fit.jober</groupId>
26+
<artifactId>jober-genericable</artifactId>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.fitframework</groupId>
34+
<artifactId>fit-build-maven-plugin</artifactId>
35+
<version>${fit.version}</version>
36+
<configuration>
37+
<category>user</category>
38+
<level>5</level>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<id>build-plugin</id>
43+
<goals>
44+
<goal>build-plugin</goal>
45+
</goals>
46+
</execution>
47+
<execution>
48+
<id>package-plugin</id>
49+
<goals>
50+
<goal>package-plugin</goal>
51+
</goals>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-antrun-plugin</artifactId>
58+
<version>${maven.antrun.version}</version>
59+
<executions>
60+
<execution>
61+
<phase>install</phase>
62+
<configuration>
63+
<target>
64+
<copy file="${project.build.directory}/${project.build.finalName}.jar"
65+
todir="../../../build/plugins"/>
66+
</target>
67+
</configuration>
68+
<goals>
69+
<goal>run</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jade.aipp.variable.updater;
8+
9+
import modelengine.fit.jober.aipp.constants.AippConst;
10+
import modelengine.fit.jober.common.ErrorCodes;
11+
import modelengine.fit.jober.common.exceptions.JobberException;
12+
import modelengine.fit.waterflow.spi.FlowableService;
13+
import modelengine.fitframework.annotation.Component;
14+
import modelengine.fitframework.annotation.Fitable;
15+
import modelengine.fitframework.util.ObjectUtils;
16+
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
/**
21+
* 变量更新算子服务。
22+
*
23+
* @author 鲁为
24+
* @since 2025-09-26
25+
*/
26+
@Component
27+
public class AippVariableUpdater implements FlowableService {
28+
public static final String UPDATE_VARIABLES = "updateVariables";
29+
public static final String INTERNAL = "_internal";
30+
public static final String OUTPUT_SCOPE = "outputScope";
31+
public static final String KEY = "key";
32+
public static final String VALUE = "value";
33+
34+
@Override
35+
@Fitable("modelengine.fit.jade.aipp.variable.updater")
36+
public List<Map<String, Object>> handleTask(List<Map<String, Object>> flowData) {
37+
Map<String, Object> businessData = this.getBusinessData(flowData);
38+
List<Map<String, Object>> updateVariables = ObjectUtils.cast(businessData.get(UPDATE_VARIABLES));
39+
Map<String, Object> internal = ObjectUtils.cast(businessData.get(INTERNAL));
40+
Map<String, Object> outputScope = ObjectUtils.cast(internal.get(OUTPUT_SCOPE));
41+
for (Map<String, Object> variable : updateVariables) {
42+
List<String> path = ObjectUtils.cast(variable.get(KEY));
43+
Object newValue = variable.get(VALUE);
44+
this.updateNestedMapByPath(outputScope, path, newValue);
45+
}
46+
return flowData;
47+
}
48+
49+
private Map<String, Object> getBusinessData(List<Map<String, Object>> flowData) {
50+
if (flowData.isEmpty() || !flowData.get(0).containsKey(AippConst.BS_DATA_KEY)) {
51+
throw new JobberException(ErrorCodes.INPUT_PARAM_IS_EMPTY, AippConst.BS_DATA_KEY);
52+
}
53+
return ObjectUtils.cast(flowData.get(0).get(AippConst.BS_DATA_KEY));
54+
}
55+
56+
private void updateNestedMapByPath(Map<String, Object> businessData, List<String> path, Object newValue) {
57+
if (businessData == null || path == null || path.isEmpty()) {
58+
return;
59+
}
60+
61+
Map<String, Object> currentMap = businessData;
62+
63+
for (int i = 0; i < path.size() - 1; i++) {
64+
String key = path.get(i);
65+
Object value = currentMap.get(key);
66+
67+
if (value instanceof Map) {
68+
currentMap = ObjectUtils.cast(value);
69+
}
70+
}
71+
72+
String finalKey = path.get(path.size() - 1);
73+
currentMap.put(finalKey, newValue);
74+
}
75+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fit:
2+
beans:
3+
packages:
4+
- 'modelengine.fit.jade.aipp.variable.updater'

app-builder/plugins/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<module>aipp-prompt-builder</module>
3131
<module>aipp-rewriter</module>
3232
<module>aipp-variable-aggregation</module>
33+
<module>aipp-variable-updater</module>
3334
<module>aipp-websocket-plugin</module>
3435
<module>app-announcement</module>
3536
<module>app-base</module>

frontend/src/pages/addFlow/components/basic-item.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const BasicItems = (props: any) => {
5555
'questionClassificationNodeCondition': <ClassificationIcon />,
5656
'httpNodeState': <HttpIcon />,
5757
'variableAggregationNodeState': <VariableAggregation />,
58+
'variableUpdateNodeState': <VariableAggregation />,
5859
'textToImageNodeState': <TextToImageIcon />,
5960
'fileExtractionNodeState': <FileExtractionIcon />,
6061
'noteNode': <ClassificationIcon />,

0 commit comments

Comments
 (0)