graphai 2.0.4 → 2.0.6
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 +32 -13
- 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 +4 -2
- package/lib/graphai.js +21 -9
- package/lib/node.d.ts +2 -1
- package/lib/node.js +7 -4
- package/lib/task_manager.d.ts +1 -0
- package/lib/task_manager.js +4 -0
- package/lib/type.d.ts +1 -0
- package/package.json +3 -3
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)) {
|
|
@@ -228,14 +230,18 @@ class GraphAI {
|
|
|
228
230
|
};
|
|
229
231
|
});
|
|
230
232
|
}
|
|
231
|
-
abort() {
|
|
233
|
+
abort(isChild = false) {
|
|
232
234
|
if (this.isRunning()) {
|
|
233
235
|
this.resetPending();
|
|
236
|
+
// Stop All Running node.
|
|
234
237
|
}
|
|
235
238
|
// For an agent like an event agent, where an external promise remains unresolved,
|
|
236
239
|
// aborting and then retrying can cause nodes or the graph to execute again.
|
|
237
240
|
// To prevent this, the transactionId is updated to ensure the retry fails.
|
|
238
241
|
Object.values(this.nodes).forEach((node) => node.isComputedNode && (node.transactionId = undefined));
|
|
242
|
+
if (!isChild) {
|
|
243
|
+
this.taskManager.reset();
|
|
244
|
+
}
|
|
239
245
|
this.onComplete(this.isRunning());
|
|
240
246
|
}
|
|
241
247
|
resetPending() {
|
|
@@ -273,6 +279,7 @@ class GraphAI {
|
|
|
273
279
|
// We need to update static nodes, before checking the condition
|
|
274
280
|
const previousResults = this.results(true, true); // results from previous loop
|
|
275
281
|
this.updateStaticNodes(previousResults);
|
|
282
|
+
this.setStaticNodeResults();
|
|
276
283
|
if (loop.count === undefined || this.repeatCount < loop.count) {
|
|
277
284
|
if (loop.while) {
|
|
278
285
|
const source = (0, utils_1.parseNodeName)(loop.while);
|
|
@@ -282,8 +289,9 @@ class GraphAI {
|
|
|
282
289
|
return false; // while condition is not met
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
|
-
this.
|
|
292
|
+
this.nodes = this.createNodes(this.graphData);
|
|
286
293
|
this.updateStaticNodes(previousResults, true);
|
|
294
|
+
this.setStaticNodeResults();
|
|
287
295
|
this.pushReadyNodesIntoQueue();
|
|
288
296
|
return true; // Indicating that we are going to continue.
|
|
289
297
|
}
|
|
@@ -294,7 +302,7 @@ class GraphAI {
|
|
|
294
302
|
throw new Error("This GraphAI instance is running");
|
|
295
303
|
}
|
|
296
304
|
this.nodes = this.createNodes(this.graphData);
|
|
297
|
-
this.
|
|
305
|
+
this.setStaticNodeResults();
|
|
298
306
|
}
|
|
299
307
|
setPreviousResults(previousResults) {
|
|
300
308
|
this.updateStaticNodes(previousResults);
|
|
@@ -324,9 +332,13 @@ class GraphAI {
|
|
|
324
332
|
}
|
|
325
333
|
// Public API
|
|
326
334
|
injectValue(nodeId, value, injectFrom) {
|
|
335
|
+
this.staticNodeInitData[nodeId] = value;
|
|
336
|
+
this.updateStaticNodeValue(nodeId, value, injectFrom);
|
|
337
|
+
}
|
|
338
|
+
updateStaticNodeValue(nodeId, value, injectFrom) {
|
|
327
339
|
const node = this.nodes[nodeId];
|
|
328
340
|
if (node && node.isStaticNode) {
|
|
329
|
-
node.
|
|
341
|
+
node.updateValue(value, injectFrom);
|
|
330
342
|
}
|
|
331
343
|
else {
|
|
332
344
|
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
|
@@ -140,7 +140,7 @@ class ComputedNode extends Node {
|
|
|
140
140
|
this.updateState(type_1.NodeState.Abort);
|
|
141
141
|
}
|
|
142
142
|
if (this.debugInfo && this.debugInfo.subGraphs) {
|
|
143
|
-
this.debugInfo.subGraphs.forEach((graph) => graph.abort());
|
|
143
|
+
this.debugInfo.subGraphs.forEach((graph) => graph.abort(true));
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
isReadyNode() {
|
|
@@ -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
|
}
|
package/lib/task_manager.d.ts
CHANGED
package/lib/task_manager.js
CHANGED
package/lib/type.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/bundle.cjs.js",
|
|
6
6
|
"module": "lib/bundle.esm.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/receptron/graphai#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typedoc": "^0.28.
|
|
33
|
-
"typedoc-plugin-markdown": "^4.6.
|
|
32
|
+
"typedoc": "^0.28.5",
|
|
33
|
+
"typedoc-plugin-markdown": "^4.6.4"
|
|
34
34
|
},
|
|
35
35
|
"types": "./lib/index.d.ts",
|
|
36
36
|
"directories": {
|