Skip to content

Commit a76e8f0

Browse files
authored
[elsa] 知识检索节点添加userId入参 (#97)
* [elsa] 知识检索节点添加userId入参 * [elsa] 检视意见修改,增加对inputParam中option的空判断
1 parent 753b62c commit a76e8f0

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,16 @@ export const DEFAULT_LOOP_NODE_CONTEXT = {
204204
referenceNode: VIRTUAL_CONTEXT_NODE.id,
205205
value: [VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID],
206206
}],
207+
};
208+
209+
export const DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID = {
210+
id: `userId_${uuidv4()}`,
211+
name: 'userId',
212+
type: 'String',
213+
from: 'Reference',
214+
referenceNode: VIRTUAL_CONTEXT_NODE.id,
215+
referenceId: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID,
216+
referenceKey: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID,
217+
editable: false,
218+
value: [VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID],
207219
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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, FROM_TYPE} from '@/common/Consts.js';
10+
import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP, DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID, FROM_TYPE, VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
1111
import {
1212
UpdateGroupIdReducer,
1313
UpdateInputParamReducer,
@@ -138,7 +138,8 @@ export const knowledgeRetrievalComponent = (jadeConfig, shape) => {
138138
from: FROM_TYPE.INPUT,
139139
value: DEFAULT_KNOWLEDGE_REPO_GROUP,
140140
}],
141-
}],
141+
},
142+
DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID],
142143
outputParams: [{
143144
id: `output_${uuidv4()}`,
144145
name: 'output',

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

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

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ 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,
1213
DEFAULT_LLM_KNOWLEDGE_BASES,
13-
DEFAULT_LLM_REFERENCE_OUTPUT, DEFAULT_LOOP_NODE_CONTEXT,
14+
DEFAULT_LLM_REFERENCE_OUTPUT,
15+
DEFAULT_LOOP_NODE_CONTEXT,
1416
DEFAULT_MAX_MEMORY_ROUNDS,
1517
END_NODE_TYPE,
1618
FLOW_TYPE,
@@ -390,10 +392,32 @@ export const knowledgeRetrievalCompatibilityProcessor = (shapeData, graph, pageH
390392
const process = self.process;
391393
self.process = () => {
392394
process.apply(self);
393-
const optionValue = self.shapeData.flowMeta.jober.converter.entity.inputParams.find(inputParam => inputParam.name === 'option').value;
394-
if (!optionValue.find(v => v.name === 'groupId')) {
395-
optionValue.push(DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT);
396-
}
395+
396+
const optionParamProcess = () => {
397+
const optionValue = self.shapeData.flowMeta.jober.converter.entity.inputParams
398+
.find(inputParam => inputParam.name === 'option')?.value;
399+
400+
if (Array.isArray(optionValue) && !optionValue.some(v => v.name === 'groupId')) {
401+
optionValue.push(DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT);
402+
}
403+
};
404+
405+
const userIdParamProcess = () => {
406+
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);
410+
}
411+
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+
}
417+
};
418+
419+
optionParamProcess();
420+
userIdParamProcess();
397421
};
398422

399423
return self;

0 commit comments

Comments
 (0)