diff --git a/framework/elsa/fit-elsa-react/src/common/Consts.js b/framework/elsa/fit-elsa-react/src/common/Consts.js index 39a0fb902..75fd09570 100644 --- a/framework/elsa/fit-elsa-react/src/common/Consts.js +++ b/framework/elsa/fit-elsa-react/src/common/Consts.js @@ -204,4 +204,16 @@ export const DEFAULT_LOOP_NODE_CONTEXT = { referenceNode: VIRTUAL_CONTEXT_NODE.id, value: [VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID], }], +}; + +export const DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID = { + id: `userId_${uuidv4()}`, + name: 'userId', + type: 'String', + from: 'Reference', + referenceNode: VIRTUAL_CONTEXT_NODE.id, + referenceId: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, + referenceKey: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, + editable: false, + value: [VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID], }; \ No newline at end of file diff --git a/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalComponent.jsx b/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalComponent.jsx index 3e8f61274..73078eb8a 100644 --- a/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalComponent.jsx +++ b/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalComponent.jsx @@ -7,7 +7,7 @@ import {v4 as uuidv4} from 'uuid'; import {KnowledgeRetrievalWrapper} from '@/components/knowledgeRetrieval/KnowledgeRetrievalWrapper.jsx'; import {retrievalComponent} from '@/components/retrieval/retrievalComponent.jsx'; -import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP, FROM_TYPE} from '@/common/Consts.js'; +import {DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP, DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID, FROM_TYPE, VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js'; import { UpdateGroupIdReducer, UpdateInputParamReducer, @@ -138,7 +138,8 @@ export const knowledgeRetrievalComponent = (jadeConfig, shape) => { from: FROM_TYPE.INPUT, value: DEFAULT_KNOWLEDGE_REPO_GROUP, }], - }], + }, + DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID], outputParams: [{ id: `output_${uuidv4()}`, name: 'output', diff --git a/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalNodeState.jsx b/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalNodeState.jsx index 77cfe6b0f..6359dee29 100644 --- a/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalNodeState.jsx +++ b/framework/elsa/fit-elsa-react/src/components/knowledgeRetrieval/knowledgeRetrievalNodeState.jsx @@ -39,6 +39,9 @@ export const knowledgeRetrievalNodeState = (id, x, y, width, height, parent, dra { name: 'option', }, + { + name: 'userId', + }, ], return: { type: 'object', diff --git a/framework/elsa/fit-elsa-react/src/flow/compatibility/compatibilityProcessors.js b/framework/elsa/fit-elsa-react/src/flow/compatibility/compatibilityProcessors.js index a0db5e2fb..85b1e1196 100644 --- a/framework/elsa/fit-elsa-react/src/flow/compatibility/compatibilityProcessors.js +++ b/framework/elsa/fit-elsa-react/src/flow/compatibility/compatibilityProcessors.js @@ -9,8 +9,10 @@ import {getDefaultReference} from '@/components/util/ReferenceUtil.js'; import { DATA_TYPES, DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT, + DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID, DEFAULT_LLM_KNOWLEDGE_BASES, - DEFAULT_LLM_REFERENCE_OUTPUT, DEFAULT_LOOP_NODE_CONTEXT, + DEFAULT_LLM_REFERENCE_OUTPUT, + DEFAULT_LOOP_NODE_CONTEXT, DEFAULT_MAX_MEMORY_ROUNDS, END_NODE_TYPE, FLOW_TYPE, @@ -390,10 +392,32 @@ export const knowledgeRetrievalCompatibilityProcessor = (shapeData, graph, pageH const process = self.process; self.process = () => { process.apply(self); - const optionValue = self.shapeData.flowMeta.jober.converter.entity.inputParams.find(inputParam => inputParam.name === 'option').value; - if (!optionValue.find(v => v.name === 'groupId')) { - optionValue.push(DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT); - } + + const optionParamProcess = () => { + const optionValue = self.shapeData.flowMeta.jober.converter.entity.inputParams + .find(inputParam => inputParam.name === 'option')?.value; + + if (Array.isArray(optionValue) && !optionValue.some(v => v.name === 'groupId')) { + optionValue.push(DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT); + } + }; + + const userIdParamProcess = () => { + const inputParams = self.shapeData.flowMeta.jober.converter.entity.inputParams; + const userIdParam = inputParams.find(inputParam => inputParam.name === 'userId'); + if (!userIdParam) { + inputParams.push(DEFAULT_KNOWLEDGE_RETRIEVAL_NODE_USER_ID); + } + const entityParams = self.shapeData.flowMeta.jober.entity.params; + if (!entityParams.find(param => param.name === 'userId')) { + const optionIndex = entityParams.findIndex(param => param.name === 'option'); + const insertIndex = optionIndex !== -1 ? optionIndex + 1 : entityParams.length; + entityParams.splice(insertIndex, 0, {name: 'userId'}); + } + }; + + optionParamProcess(); + userIdParamProcess(); }; return self;