Skip to content

Commit 2635de1

Browse files
authored
[elsa] 循环节点增加默认的context入参 (#56)
1 parent 8d8e422 commit 2635de1

File tree

5 files changed

+65
-45
lines changed

5 files changed

+65
-45
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export const VIRTUAL_CONTEXT_NODE = {
5353
name: 'systemEnv',
5454
};
5555

56+
export const VIRTUAL_CONTEXT_NODE_VARIABLES = {
57+
INSTANCE_ID: 'instanceId',
58+
APP_ID: 'appId',
59+
MEMORIES: 'memories',
60+
USE_MEMORY: 'useMemory',
61+
USER_ID: 'userId',
62+
FILE_URLS: 'fileUrls',
63+
CHAT_ID: 'chatId',
64+
};
65+
5666
export const CONNECTOR = {
5767
RADIUS: 6,
5868
CONDITION_RADIUS: 4,
@@ -177,4 +187,21 @@ export const RENDER_TYPE = {
177187
RADIO: 'Radio',
178188
INPUT: 'Input',
179189
SWITCH: 'Switch',
190+
};
191+
192+
export const DEFAULT_LOOP_NODE_CONTEXT = {
193+
id: uuidv4(),
194+
name: 'context',
195+
type: DATA_TYPES.OBJECT,
196+
from: FROM_TYPE.EXPAND,
197+
value: {
198+
id: uuidv4(),
199+
name: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
200+
type: DATA_TYPES.STRING,
201+
from: FROM_TYPE.REFERENCE,
202+
referenceId: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
203+
referenceKey: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
204+
referenceNode: VIRTUAL_CONTEXT_NODE.id,
205+
value: [VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID],
206+
},
180207
};

framework/elsa/fit-elsa-react/src/components/loopNode/loopComponent.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {ChangeFlowMetaReducer} from '@/components/common/reducers/commonReducers
99
import {ChangePluginByMetaDataReducer, DeletePluginReducer, UpdateInputReducer, UpdateRadioInfoReducer} from '@/components/loopNode/reducers/reducers.js';
1010
import {defaultComponent} from '@/components/defaultComponent.js';
1111
import {v4 as uuidv4} from 'uuid';
12-
import {DATA_TYPES, FROM_TYPE} from '@/common/Consts.js';
12+
import {DATA_TYPES, DEFAULT_LOOP_NODE_CONTEXT, FROM_TYPE} from '@/common/Consts.js';
1313

1414
export const loopComponent = (jadeConfig, shape) => {
1515
const self = defaultComponent(jadeConfig);
@@ -50,6 +50,7 @@ export const loopComponent = (jadeConfig, shape) => {
5050
from: FROM_TYPE.INPUT,
5151
value: {},
5252
},
53+
DEFAULT_LOOP_NODE_CONTEXT,
5354
],
5455
outputParams: [],
5556
};

framework/elsa/fit-elsa-react/src/components/loopNode/loopNodeState.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const loopNodeState = (id, x, y, width, height, parent, drawer) => {
2121
self.flowMeta.jober.type = 'STORE_JOBER';
2222
const loopNodeEntity = {
2323
uniqueName: "",
24-
params: [{"name": "args"}, {"name": "config"}, {"name": "toolInfo"}],
24+
params: [{"name": "args"}, {"name": "config"}, {"name": "toolInfo"}, {"name": "context"}],
2525
return: {type: "array"}
2626
};
2727

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

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
DATA_TYPES,
1111
DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT,
1212
DEFAULT_LLM_KNOWLEDGE_BASES,
13-
DEFAULT_LLM_REFERENCE_OUTPUT,
13+
DEFAULT_LLM_REFERENCE_OUTPUT, DEFAULT_LOOP_NODE_CONTEXT,
1414
DEFAULT_MAX_MEMORY_ROUNDS,
1515
END_NODE_TYPE,
1616
FLOW_TYPE,
@@ -49,6 +49,8 @@ export const pageCompatibilityProcessor = (pageData, graph) => {
4949
return knowledgeRetrievalCompatibilityProcessor(shapeData, g, self);
5050
case 'questionClassificationNodeCondition':
5151
return questionClassificationCompatibilityProcessor(shapeData, g, self);
52+
case 'loopNodeState':
53+
return loopNodeCompatibilityProcessor(shapeData, g, self);
5254
default:
5355
return shapeCompatibilityProcessor(shapeData, g, self);
5456
}
@@ -185,6 +187,30 @@ export const questionClassificationCompatibilityProcessor = (shapeData, graph, p
185187
return self;
186188
};
187189

190+
/**
191+
* 循环节点兼容性处理器.
192+
*
193+
* @override
194+
*/
195+
export const loopNodeCompatibilityProcessor = (shapeData, graph, pageHandler) => {
196+
const self = shapeCompatibilityProcessor(shapeData, graph, pageHandler);
197+
198+
/**
199+
* @override
200+
*/
201+
const process = self.process;
202+
self.process = () => {
203+
process.apply(self);
204+
const jober = self.shapeData.flowMeta.jober;
205+
if (!jober.entity.params.exist(param => param.name === 'context')) {
206+
jober.entity.params.push({name: 'context'});
207+
jober.converter.entity.inputParams.push(DEFAULT_LOOP_NODE_CONTEXT);
208+
}
209+
};
210+
211+
return self;
212+
};
213+
188214

189215
/**
190216
* 开始节点兼容性处理器.
@@ -281,43 +307,9 @@ export const endNodeCompatibilityProcessor = (shapeData, graph, pageHandler) =>
281307
if (inputParam.from !== FROM_TYPE.EXPAND) {
282308
return;
283309
}
284-
285-
// const values = inputParam.value;
286-
//
287-
// // 第一个引用若不是大模型,则后续的所有大模型节点enableLog都是false.
288-
// // 若第一个引用是对大模型的引用,遍历,后续【连续】的对大模型节点的引用.
289310
const llmNodes = self.pageProcessor.getShapes(sd => sd.type === 'llmNodeState').map((n, i) => {
290311
return {index: i, data: n};
291312
});
292-
//
293-
// let indexes = []; // 记录所有需要输出日志的大模型的下标.
294-
// for (let i = 0; i < values.length; i++) {
295-
// const input = values[i];
296-
//
297-
// // 不是reference,或referenceKey不存在,退出循环.
298-
// if (input.from !== 'Reference' || !input.referenceKey) {
299-
// break;
300-
// }
301-
//
302-
// // 引用的不是大模型,退出循环.
303-
// const node = llmNodes.find(n => n.data.id === input.referenceNode);
304-
// if (!node) {
305-
// break;
306-
// }
307-
//
308-
// // 当前大模型节点的index小于indexes中的值,跳出循环.
309-
// if (indexes.length > 0 && node.index < indexes[indexes.length - 1]) {
310-
// break;
311-
// }
312-
//
313-
// const chainNodes = self.pageProcessor.getNodesBetween(node.data, self.shapeData);
314-
// if (chainNodes.contains(n => n.type === 'conditionNodeCondition' || n.type === 'manualCheckNodeState')) {
315-
// break;
316-
// }
317-
//
318-
// indexes.push(node.index);
319-
// }
320-
321313
updateLlmFlowMetas(llmNodes);
322314
};
323315

framework/elsa/fit-elsa-react/src/shapes/systemEnv.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*--------------------------------------------------------------------------------------------*/
66

77
import {rectangle} from '@fit-elsa/elsa-core';
8-
import {VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
8+
import {DATA_TYPES, VIRTUAL_CONTEXT_NODE, VIRTUAL_CONTEXT_NODE_VARIABLES} from '@/common/Consts.js';
99
import {emptyStatusManager} from '@/components/base/emptyStatusManager.js';
1010

1111
/**
@@ -25,13 +25,13 @@ export const systemEnv = (id, x, y, width, height, parent) => {
2525
self.width = 0;
2626
self.height = 0;
2727
self.virtualNodeInfoList = [
28-
{observableId: 'instanceId', value: 'instanceId', type: 'String'},
29-
{observableId: 'appId', value: 'appId', type: 'String'},
30-
{observableId: 'memories', value: 'memories', type: 'Array'},
31-
{observableId: 'useMemory', value: 'useMemory', type: 'Boolean'},
32-
{observableId: 'userId', value: 'userId', type: 'String'},
33-
{observableId: 'fileUrls', value: 'fileUrls', type: 'Array'},
34-
{observableId: 'chatId', value: 'chatId', type: 'String'},
28+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID, type: DATA_TYPES.STRING},
29+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.APP_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.APP_ID, type: DATA_TYPES.STRING},
30+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.MEMORIES, value: VIRTUAL_CONTEXT_NODE_VARIABLES.MEMORIES, type: DATA_TYPES.ARRAY},
31+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.USE_MEMORY, value: VIRTUAL_CONTEXT_NODE_VARIABLES.USE_MEMORY, type: DATA_TYPES.BOOLEAN},
32+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, type: DATA_TYPES.STRING},
33+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.FILE_URLS, value: VIRTUAL_CONTEXT_NODE_VARIABLES.FILE_URLS, type: DATA_TYPES.ARRAY},
34+
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.CHAT_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.CHAT_ID, type: DATA_TYPES.STRING},
3535
];
3636
self.statusManager = emptyStatusManager(self);
3737

0 commit comments

Comments
 (0)