graphai 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundle.cjs.js +1 -1
- package/lib/bundle.cjs.js.map +1 -1
- package/lib/bundle.esm.js +22 -11
- package/lib/bundle.esm.js.map +1 -1
- package/lib/bundle.umd.js +1 -1
- package/lib/bundle.umd.js.map +1 -1
- package/lib/graphai.d.ts +3 -1
- package/lib/graphai.js +16 -8
- package/lib/node.d.ts +2 -1
- package/lib/node.js +6 -3
- package/package.json +1 -1
package/lib/graphai.js
CHANGED
|
@@ -21,7 +21,8 @@ class GraphAI {
|
|
|
21
21
|
_nodes[nodeId] = new node_1.ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
|
|
24
|
+
const updateValue = this.staticNodeInitData[nodeId];
|
|
25
|
+
_nodes[nodeId] = new node_1.StaticNode(nodeId, updateValue !== undefined ? { ...nodeData, value: updateValue } : nodeData, this);
|
|
25
26
|
}
|
|
26
27
|
return _nodes;
|
|
27
28
|
}, {});
|
|
@@ -45,7 +46,7 @@ class GraphAI {
|
|
|
45
46
|
return (0, data_source_1.getDataFromSource)(source.nodeId ? results[source.nodeId] : undefined, source, this.propFunctions);
|
|
46
47
|
}
|
|
47
48
|
// for static
|
|
48
|
-
|
|
49
|
+
setStaticNodeResults(enableConsoleLog = false) {
|
|
49
50
|
// If the result property is specified, inject it.
|
|
50
51
|
// If the previousResults exists (indicating we are in a loop),
|
|
51
52
|
// process the update property (nodeId or nodeId.propId).
|
|
@@ -54,7 +55,7 @@ class GraphAI {
|
|
|
54
55
|
if (node?.isStaticNode) {
|
|
55
56
|
const value = node?.value;
|
|
56
57
|
if (value !== undefined) {
|
|
57
|
-
|
|
58
|
+
node.setResultValue(nodeId);
|
|
58
59
|
}
|
|
59
60
|
if (enableConsoleLog) {
|
|
60
61
|
node.consoleLog();
|
|
@@ -72,7 +73,7 @@ class GraphAI {
|
|
|
72
73
|
const update = node?.update;
|
|
73
74
|
if (update && previousResults) {
|
|
74
75
|
const result = this.getValueFromResults(update, previousResults);
|
|
75
|
-
this.
|
|
76
|
+
this.updateStaticNodeValue(nodeId, result, update.nodeId);
|
|
76
77
|
}
|
|
77
78
|
if (enableConsoleLog) {
|
|
78
79
|
node.consoleLog();
|
|
@@ -88,6 +89,7 @@ class GraphAI {
|
|
|
88
89
|
graphLoader: undefined,
|
|
89
90
|
forceLoop: false,
|
|
90
91
|
}) {
|
|
92
|
+
this.staticNodeInitData = {};
|
|
91
93
|
this.logs = [];
|
|
92
94
|
this.config = {};
|
|
93
95
|
this.onLogCallback = (__log, __isUpdate) => { };
|
|
@@ -125,7 +127,6 @@ class GraphAI {
|
|
|
125
127
|
},
|
|
126
128
|
};
|
|
127
129
|
this.nodes = this.createNodes(this.graphData);
|
|
128
|
-
this.initializeStaticNodes(true);
|
|
129
130
|
}
|
|
130
131
|
getAgentFunctionInfo(agentId) {
|
|
131
132
|
if (agentId && this.agentFunctionInfoDictionary[agentId]) {
|
|
@@ -202,6 +203,7 @@ class GraphAI {
|
|
|
202
203
|
}
|
|
203
204
|
// Public API
|
|
204
205
|
async run(all = false) {
|
|
206
|
+
this.setStaticNodeResults();
|
|
205
207
|
if (Object.values(this.nodes)
|
|
206
208
|
.filter((node) => node.isStaticNode)
|
|
207
209
|
.some((node) => node.result === undefined && node.update === undefined)) {
|
|
@@ -273,6 +275,7 @@ class GraphAI {
|
|
|
273
275
|
// We need to update static nodes, before checking the condition
|
|
274
276
|
const previousResults = this.results(true, true); // results from previous loop
|
|
275
277
|
this.updateStaticNodes(previousResults);
|
|
278
|
+
this.setStaticNodeResults();
|
|
276
279
|
if (loop.count === undefined || this.repeatCount < loop.count) {
|
|
277
280
|
if (loop.while) {
|
|
278
281
|
const source = (0, utils_1.parseNodeName)(loop.while);
|
|
@@ -282,8 +285,9 @@ class GraphAI {
|
|
|
282
285
|
return false; // while condition is not met
|
|
283
286
|
}
|
|
284
287
|
}
|
|
285
|
-
this.
|
|
288
|
+
this.nodes = this.createNodes(this.graphData);
|
|
286
289
|
this.updateStaticNodes(previousResults, true);
|
|
290
|
+
this.setStaticNodeResults();
|
|
287
291
|
this.pushReadyNodesIntoQueue();
|
|
288
292
|
return true; // Indicating that we are going to continue.
|
|
289
293
|
}
|
|
@@ -294,7 +298,7 @@ class GraphAI {
|
|
|
294
298
|
throw new Error("This GraphAI instance is running");
|
|
295
299
|
}
|
|
296
300
|
this.nodes = this.createNodes(this.graphData);
|
|
297
|
-
this.
|
|
301
|
+
this.setStaticNodeResults();
|
|
298
302
|
}
|
|
299
303
|
setPreviousResults(previousResults) {
|
|
300
304
|
this.updateStaticNodes(previousResults);
|
|
@@ -324,9 +328,13 @@ class GraphAI {
|
|
|
324
328
|
}
|
|
325
329
|
// Public API
|
|
326
330
|
injectValue(nodeId, value, injectFrom) {
|
|
331
|
+
this.staticNodeInitData[nodeId] = value;
|
|
332
|
+
this.updateStaticNodeValue(nodeId, value, injectFrom);
|
|
333
|
+
}
|
|
334
|
+
updateStaticNodeValue(nodeId, value, injectFrom) {
|
|
327
335
|
const node = this.nodes[nodeId];
|
|
328
336
|
if (node && node.isStaticNode) {
|
|
329
|
-
node.
|
|
337
|
+
node.updateValue(value, injectFrom);
|
|
330
338
|
}
|
|
331
339
|
else {
|
|
332
340
|
throw new Error(`injectValue with Invalid nodeId, ${nodeId}`);
|
package/lib/node.d.ts
CHANGED
|
@@ -72,7 +72,8 @@ export declare class StaticNode extends Node {
|
|
|
72
72
|
readonly isStaticNode = true;
|
|
73
73
|
readonly isComputedNode = false;
|
|
74
74
|
constructor(nodeId: string, data: StaticNodeData, graph: GraphAI);
|
|
75
|
-
|
|
75
|
+
updateValue(value: ResultData, injectFrom?: string): void;
|
|
76
|
+
setResultValue(injectFrom?: string): void;
|
|
76
77
|
consoleLog(): void;
|
|
77
78
|
}
|
|
78
79
|
export type GraphNodes = Record<string, ComputedNode | StaticNode>;
|
package/lib/node.js
CHANGED
|
@@ -418,10 +418,13 @@ class StaticNode extends Node {
|
|
|
418
418
|
this.isResult = data.isResult ?? false;
|
|
419
419
|
this.console = data.console ?? {};
|
|
420
420
|
}
|
|
421
|
-
|
|
422
|
-
this.state = type_1.NodeState.Injected;
|
|
421
|
+
updateValue(value, injectFrom) {
|
|
423
422
|
this.value = value;
|
|
424
|
-
this.
|
|
423
|
+
this.log.onInjected(this, this.graph, injectFrom);
|
|
424
|
+
}
|
|
425
|
+
setResultValue(injectFrom) {
|
|
426
|
+
this.state = type_1.NodeState.Injected;
|
|
427
|
+
this.result = this.value;
|
|
425
428
|
this.log.onInjected(this, this.graph, injectFrom);
|
|
426
429
|
this.onSetResult();
|
|
427
430
|
}
|