Skip to content

Commit 380bab6

Browse files
RonnyChan96surpercodehang
authored andcommitted
[elsa] Fix bugs of 0.1.x. (#123)
* [elsa] 大模型节点模型下拉框宽度根据下拉选项内容长度自适应 (#115) (cherry picked from commit f98986e) * [elsa] 知识检索节点去除userId入参,在option中增加knowledgeConfigId参数 (#119) (cherry picked from commit 9db5b06) * [elsa] add selectedKnowledgeConfigId in SELECT_KNOWLEDGE_BASE event * [elsa] Modify the update method in GraphOperator.js to automatically add a value if it does not exist during an update operation.
1 parent 00e4936 commit 380bab6

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

framework/elsa/fit-elsa-react/src/components/retrieval/KnowledgeForm.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const _KnowledgeForm = ({knowledge, groupId, knowledgeConfigId, disabled, maximu
7979
shapeId: shape.id,
8080
selectedKnowledgeBases: getSelectedKnowledgeBases(),
8181
groupId: groupId ?? DEFAULT_KNOWLEDGE_REPO_GROUP,
82+
selectedKnowledgeConfigId: knowledgeConfigId,
8283
onSelect: onSelect,
8384
},
8485
});

framework/elsa/fit-elsa-react/src/data/GraphOperator.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
66

7+
import {v4 as uuidv4} from 'uuid';
78
import {configToStruct, toConfig} from '@/components/util/JadeConfigUtils.js';
89
import {DATA_TYPES, FROM_TYPE} from '@/common/Consts.js';
910
import {ShapeDataValidationProcessor} from '@/data/ShapeDataValidationProcessor.js';
@@ -75,10 +76,49 @@ const graphOperator = (graphString) => {
7576
* @param updates 待修改的值.
7677
*/
7778
self.update = (keys, updates) => {
78-
const config = getConfigByKeys(keys);
79-
updateConfig(config, updates);
79+
if (!keys || keys.length === 0) {
80+
throw new Error('Keys cannot be empty');
81+
}
82+
// 获取除最后一层外的所有路径
83+
const parentKeys = keys.slice(0, -1);
84+
const lastKey = keys[keys.length - 1];
85+
// 检查父路径是否存在
86+
const parentConfig = getConfigByKeys(parentKeys);
87+
if (!parentConfig || !parentConfig.value) {
88+
throw new Error(`Parent path does not exist: ${parentKeys.join('.')}`);
89+
}
90+
// 检查最后一层是否存在
91+
let targetConfig = parentConfig.value.find(v => v.name === lastKey);
92+
// 如果最后一层不存在,则创建
93+
if (!targetConfig) {
94+
targetConfig = {
95+
id: uuidv4(),
96+
name: lastKey,
97+
from: FROM_TYPE.INPUT,
98+
type: getTypeFromUpdates(updates),
99+
value: updates
100+
};
101+
parentConfig.value.push(targetConfig);
102+
}
103+
updateConfig(targetConfig, updates);
80104
};
81105

106+
// 根据updates的类型返回对应的DATA_TYPES
107+
const getTypeFromUpdates = (updates) => {
108+
if (Array.isArray(updates)) {
109+
return DATA_TYPES.ARRAY;
110+
} else if (updates && typeof updates === 'object') {
111+
return DATA_TYPES.OBJECT;
112+
} else if (typeof updates === 'string') {
113+
return DATA_TYPES.STRING;
114+
} else if (typeof updates === 'number') {
115+
return DATA_TYPES.NUMBER;
116+
} else if (typeof updates === 'boolean') {
117+
return DATA_TYPES.BOOLEAN;
118+
}
119+
return DATA_TYPES.STRING; // 或者其他默认类型
120+
}
121+
82122
const updateConfig = (config, updates) => {
83123
if (Array.isArray(updates)) {
84124
config.value = updates.map(update => {
@@ -97,6 +137,14 @@ const graphOperator = (graphString) => {
97137
const update = updates[k];
98138
const correspondingConfig = config.value?.find(v => v.name === k);
99139
if (!correspondingConfig) {
140+
config.value = config.value || []; // 确保 config.value 是数组
141+
config.value.push({
142+
id: uuidv4(),
143+
name: k,
144+
from: FROM_TYPE.INPUT,
145+
type: getTypeFromUpdates(update),
146+
value: update,
147+
});
100148
return;
101149
}
102150

0 commit comments

Comments
 (0)