MCPcopy Create free account
hub / github.com/ModelEngine-Group/app-platform / graphOperator

Function graphOperator

agent-flow/src/data/GraphOperator.js:18–233  ·  view source on GitHub ↗
(graphString)

Source from the content-addressed store, hash-verified

16 * @return {{}} 画布操纵器对象.
17 */
18const graphOperator = (graphString) => {
19 const self = {};
20 const graph = JSON.parse(graphString);
21 const shapes = graph.pages[0].shapes;
22
23 /**
24 * 获取配置信息.
25 *
26 * @param keys 键值数组.
27 * @return {{}|*|null} 配置信息.
28 */
29 self.getConfig = (keys) => {
30 const config = getConfigByKeys(keys);
31 return config ? configToStruct(config) : null;
32 };
33
34 const getInputParams = (shape) => {
35 if (shape.type === 'startNodeStart') {
36 return shape.flowMeta.inputParams;
37 } else if (shape.type === 'endNodeEnd') {
38 return shape.flowMeta.callback.converter.entity.inputParams;
39 } else {
40 return shape.flowMeta.jober.converter.entity.inputParams;
41 }
42 };
43
44 const getConfigByKeys = (keys) => {
45 if (!Array.isArray(keys)) {
46 throw new Error('Expected keys to be an array');
47 }
48
49 if (keys.length === 0) {
50 return null;
51 }
52
53 const tmpKeys = [...keys];
54 const shapeId = tmpKeys.shift();
55 const shape = getShapeById(shapeId);
56 const inputParams = getInputParams(shape);
57 if (!inputParams) {
58 throw new Error('Expected inputParams exists');
59 }
60 let config = {type: DATA_TYPES.OBJECT, value: inputParams};
61 while (tmpKeys.length > 0 && config && config.value) {
62 const key = tmpKeys.shift();
63 config = config.value.find(v => v.name === key);
64 }
65 return config;
66 };
67
68 const getShapeById = (shapeId) => {
69 return shapes.find((shape) => shape.id === shapeId);
70 };
71
72 /**
73 * 修改配置.
74 *
75 * @param keys 键值数组.

Callers 1

createGraphOperatorFunction · 0.85

Calls 12

configToStructFunction · 0.90
getTypeFromUpdatesFunction · 0.85
isArrayMethod · 0.80
getConfigByKeysFunction · 0.70
updateConfigFunction · 0.70
parseMethod · 0.65
joinMethod · 0.65
findMethod · 0.65
reduceMethod · 0.65
mapMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected