Skip to content

Commit 593ec34

Browse files
authored
[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 a1ec68f commit 593ec34

File tree

9 files changed

+98
-37
lines changed

9 files changed

+98
-37
lines changed

framework/elsa/fit-elsa-react/src/common/Consts.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,10 @@ export const DEFAULT_LOOP_NODE_CONTEXT = {
208208
}],
209209
};
210210

211-
export const DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID = {
212-
id: `userId_${uuidv4()}`,
213-
name: 'userId',
214-
type: 'String',
215-
from: 'Reference',
216-
referenceNode: VIRTUAL_CONTEXT_NODE.id,
217-
referenceId: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID,
218-
referenceKey: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID,
219-
editable: false,
220-
value: [VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID],
211+
export const DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID = {
212+
id: `knowledgeConfigId_${uuidv4()}`,
213+
name: 'knowledgeConfigId',
214+
type: DATA_TYPES.STRING,
215+
from: FROM_TYPE.INPUT,
216+
value: '',
221217
};

framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/KnowledgeRetrievalWrapper.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const KnowledgeRetrievalWrapper = ({data, shapeStatus}) => {
2626
const outputParams = data && data.outputParams;
2727
const option = data.inputParams.find(item => item.name === 'option');
2828
const groupId = getConfigValue(option, ['groupId'], 'value');
29+
const knowledgeConfigId = getConfigValue(option, ['knowledgeConfigId'], 'value');
2930
const {t} = useTranslation();
3031
const dispatch = useDispatch();
3132

@@ -43,7 +44,7 @@ export const KnowledgeRetrievalWrapper = ({data, shapeStatus}) => {
4344
content={tips}
4445
maxInputLength={1000}
4546
editable={false}/>
46-
<KnowledgeForm knowledge={knowledge} groupId={groupId} disabled={shapeStatus.disabled}/>
47+
<KnowledgeForm knowledge={knowledge} groupId={groupId} knowledgeConfigId={knowledgeConfigId} disabled={shapeStatus.disabled}/>
4748
<SearchForm option={option} groupId={groupId} shapeStatus={shapeStatus}/>
4849
<OutputForm outputParams={outputParams} outputPopover={'knowledgeBaseOutputPopover'}/>
4950
</>);

framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalComponent.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import {v4 as uuidv4} from 'uuid';
88
import {KnowledgeRetrievalWrapper} from '@/components/knowledgeRetrieval/KnowledgeRetrievalWrapper.jsx';
99
import {retrievalComponent} from '@/components/retrieval/retrievalComponent.jsx';
10-
import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP, DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID, FROM_TYPE, VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
10+
import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP, DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID, FROM_TYPE} from '@/common/Consts.js';
1111
import {
12-
UpdateGroupIdReducer,
12+
UpdateGroupIdAndConfigIdReducer,
1313
UpdateInputParamReducer,
1414
UpdateKnowledgeReducer,
1515
UpdateOptionReducer,
@@ -28,7 +28,7 @@ export const knowledgeRetrievalComponent = (jadeConfig, shape) => {
2828
addReducer(builtInReducers, UpdateInputParamReducer());
2929
addReducer(builtInReducers, UpdateOptionReducer());
3030
addReducer(builtInReducers, UpdateKnowledgeReducer());
31-
addReducer(builtInReducers, UpdateGroupIdReducer());
31+
addReducer(builtInReducers, UpdateGroupIdAndConfigIdReducer());
3232

3333
/**
3434
* 必填
@@ -137,9 +137,10 @@ export const knowledgeRetrievalComponent = (jadeConfig, shape) => {
137137
type: DATA_TYPES.STRING,
138138
from: FROM_TYPE.INPUT,
139139
value: DEFAULT_KNOWLEDGE_REPO_GROUP,
140-
}],
141-
},
142-
DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID],
140+
},
141+
DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID
142+
],
143+
}],
143144
outputParams: [{
144145
id: `output_${uuidv4()}`,
145146
name: 'output',

framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalNodeState.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ export const knowledgeRetrievalNodeState = (id, x, y, width, height, parent, dra
3939
{
4040
name: 'option',
4141
},
42-
{
43-
name: 'userId',
44-
},
4542
],
4643
return: {
4744
type: 'object',

framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/reducers.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import {structToConfig, toConfigType, updateConfigValueByObject, updateInput} from '@/components/util/JadeConfigUtils.js';
88
import {v4 as uuidv4} from 'uuid';
9-
import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT, FROM_TYPE} from '@/common/Consts.js';
9+
import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT, DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID, FROM_TYPE} from '@/common/Consts.js';
1010

1111
/**
1212
* updateInputParams 事件处理器.
@@ -127,14 +127,14 @@ export const UpdateKnowledgeReducer = () => {
127127
};
128128

129129
/**
130-
* updateGroupId 事件处理器.
130+
* updateGroupIdAndConfigId 事件处理器.
131131
*
132132
* @return {{}} 处理器对象.
133133
* @constructor
134134
*/
135-
export const UpdateGroupIdReducer = () => {
135+
export const UpdateGroupIdAndConfigIdReducer = () => {
136136
const self = {};
137-
self.type = 'updateGroupId';
137+
self.type = 'updateGroupIdAndConfigId';
138138

139139
/**
140140
* 处理方法.
@@ -157,6 +157,14 @@ export const UpdateGroupIdReducer = () => {
157157
}
158158

159159
groupId.value = action.value;
160+
161+
let knowledgeConfigId = option.value.find(v => v.name === 'knowledgeConfigId');
162+
if (!knowledgeConfigId) {
163+
knowledgeConfigId = {...DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID};
164+
option.value.push(knowledgeConfigId);
165+
}
166+
knowledgeConfigId.value = action.knowledgeConfigId;
167+
160168
return newConfig;
161169
};
162170

framework/elsa/fit-elsa-react/src/components/llm/Model.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const ModelSelect = ({shapeId, model, serviceName, tag, disabled, modelOptions})
5959
onClick={handleSelectClick} // 点击下拉框时阻止事件冒泡
6060
onChange={(e) => dispatch({type: 'changeAccessInfoConfig', value: e})}
6161
options={modelOptions}
62+
dropdownMatchSelectWidth={false}
6263
/>
6364
</Form.Item>
6465
</>);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ const {Panel} = Collapse;
2222
*
2323
* @param knowledge 知识库利列表.
2424
* @param groupId 知识库group.
25+
* @param knowledgeConfigId 知识库配置的唯一标识.
2526
* @param disabled 禁用状态.
2627
* @param maximum 最大值.
2728
* @param enableGroup 是否启动groupId.
2829
* @returns {JSX.Element}
2930
*/
30-
const _KnowledgeForm = ({knowledge, groupId, disabled, maximum = null, enableGroup = true}) => {
31+
const _KnowledgeForm = ({knowledge, groupId, knowledgeConfigId, disabled, maximum = null, enableGroup = true}) => {
3132
const dispatch = useDispatch();
3233
const shape = useShapeContext();
3334
const {t} = useTranslation();
@@ -78,6 +79,7 @@ const _KnowledgeForm = ({knowledge, groupId, disabled, maximum = null, enableGro
7879
shapeId: shape.id,
7980
selectedKnowledgeBases: getSelectedKnowledgeBases(),
8081
groupId: groupId ?? DEFAULT_KNOWLEDGE_REPO_GROUP,
82+
selectedKnowledgeConfigId: knowledgeConfigId,
8183
onSelect: onSelect,
8284
},
8385
});
@@ -90,10 +92,12 @@ const _KnowledgeForm = ({knowledge, groupId, disabled, maximum = null, enableGro
9092
type: 'SELECT_KNOWLEDGE_BASE_GROUP',
9193
value: {
9294
selectedGroupId: groupId ?? DEFAULT_KNOWLEDGE_REPO_GROUP,
93-
onSelect: (repoGroupId) => {
95+
selectedKnowledgeConfigId: knowledgeConfigId,
96+
onSelect: (repoGroupId, knowledgeConfigId) => {
9497
dispatch({
95-
type: 'updateGroupId',
98+
type: 'updateGroupIdAndConfigId',
9699
value: repoGroupId,
100+
knowledgeConfigId: knowledgeConfigId,
97101
});
98102
},
99103
},
@@ -196,6 +200,7 @@ const _KnowledgeForm = ({knowledge, groupId, disabled, maximum = null, enableGro
196200
_KnowledgeForm.propTypes = {
197201
knowledge: PropTypes.array.isRequired,
198202
groupId: PropTypes.string.isRequired,
203+
knowledgeConfigId: PropTypes.string,
199204
maximum: PropTypes.number,
200205
disabled: PropTypes.bool,
201206
enableGroup: PropTypes.bool,
@@ -204,6 +209,7 @@ _KnowledgeForm.propTypes = {
204209
const areEqual = (prevProps, nextProps) => {
205210
return prevProps.knowledge === nextProps.knowledge &&
206211
prevProps.groupId === nextProps.groupId &&
212+
prevProps.knowledgeConfigId === nextProps.knowledgeConfigId &&
207213
prevProps.maximum === nextProps.maximum &&
208214
prevProps.enableGroup === nextProps.enableGroup &&
209215
prevProps.disabled === nextProps.disabled;

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

framework/elsa/fit-elsa-react/src/flow/compatibility/compatibilityProcessors.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {getDefaultReference} from '@/components/util/ReferenceUtil.js';
99
import {
1010
DATA_TYPES,
1111
DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT,
12-
DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID,
12+
DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID,
1313
DEFAULT_LLM_KNOWLEDGE_BASES,
1414
DEFAULT_LLM_REFERENCE_OUTPUT,
1515
DEFAULT_LOOP_NODE_CONTEXT,
@@ -400,19 +400,22 @@ export const knowledgeRetrievalCompatibilityProcessor = (shapeData, graph, pageH
400400
if (Array.isArray(optionValue) && !optionValue.some(v => v.name === 'groupId')) {
401401
optionValue.push(DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT);
402402
}
403+
404+
if (Array.isArray(optionValue) && !optionValue.some(v => v.name === 'knowledgeConfigId')) {
405+
optionValue.push(DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_KNOWLEDGE_CONFIG_ID);
406+
}
403407
};
404408

405409
const userIdParamProcess = () => {
406410
const inputParams = self.shapeData.flowMeta.jober.converter.entity.inputParams;
407-
const userIdParam = inputParams.find(inputParam => inputParam.name === 'userId');
408-
if (!userIdParam) {
409-
inputParams.push(DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID);
411+
const userIdInputParamIndex = inputParams.findIndex(inputParam => inputParam.name === 'userId');
412+
if (userIdInputParamIndex !== -1) {
413+
inputParams.splice(userIdInputParamIndex, 1);
410414
}
411415
const entityParams = self.shapeData.flowMeta.jober.entity.params;
412-
if (!entityParams.find(param => param.name === 'userId')) {
413-
const optionIndex = entityParams.findIndex(param => param.name === 'option');
414-
const insertIndex = optionIndex !== -1 ? optionIndex + 1 : entityParams.length;
415-
entityParams.splice(insertIndex, 0, {name: 'userId'});
416+
const userIdIndex = entityParams.findIndex(param => param.name === 'userId');
417+
if (userIdIndex !== -1) {
418+
entityParams.splice(userIdIndex, 1);
416419
}
417420
};
418421

0 commit comments

Comments
 (0)