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/bundle.esm.js
CHANGED
|
@@ -930,10 +930,13 @@ class StaticNode extends Node {
|
|
|
930
930
|
this.isResult = data.isResult ?? false;
|
|
931
931
|
this.console = data.console ?? {};
|
|
932
932
|
}
|
|
933
|
-
|
|
934
|
-
this.state = NodeState.Injected;
|
|
933
|
+
updateValue(value, injectFrom) {
|
|
935
934
|
this.value = value;
|
|
936
|
-
this.
|
|
935
|
+
this.log.onInjected(this, this.graph, injectFrom);
|
|
936
|
+
}
|
|
937
|
+
setResultValue(injectFrom) {
|
|
938
|
+
this.state = NodeState.Injected;
|
|
939
|
+
this.result = this.value;
|
|
937
940
|
this.log.onInjected(this, this.graph, injectFrom);
|
|
938
941
|
this.onSetResult();
|
|
939
942
|
}
|
|
@@ -1246,7 +1249,8 @@ class GraphAI {
|
|
|
1246
1249
|
_nodes[nodeId] = new ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
1247
1250
|
}
|
|
1248
1251
|
else {
|
|
1249
|
-
|
|
1252
|
+
const updateValue = this.staticNodeInitData[nodeId];
|
|
1253
|
+
_nodes[nodeId] = new StaticNode(nodeId, updateValue !== undefined ? { ...nodeData, value: updateValue } : nodeData, this);
|
|
1250
1254
|
}
|
|
1251
1255
|
return _nodes;
|
|
1252
1256
|
}, {});
|
|
@@ -1270,7 +1274,7 @@ class GraphAI {
|
|
|
1270
1274
|
return getDataFromSource(source.nodeId ? results[source.nodeId] : undefined, source, this.propFunctions);
|
|
1271
1275
|
}
|
|
1272
1276
|
// for static
|
|
1273
|
-
|
|
1277
|
+
setStaticNodeResults(enableConsoleLog = false) {
|
|
1274
1278
|
// If the result property is specified, inject it.
|
|
1275
1279
|
// If the previousResults exists (indicating we are in a loop),
|
|
1276
1280
|
// process the update property (nodeId or nodeId.propId).
|
|
@@ -1279,7 +1283,7 @@ class GraphAI {
|
|
|
1279
1283
|
if (node?.isStaticNode) {
|
|
1280
1284
|
const value = node?.value;
|
|
1281
1285
|
if (value !== undefined) {
|
|
1282
|
-
|
|
1286
|
+
node.setResultValue(nodeId);
|
|
1283
1287
|
}
|
|
1284
1288
|
if (enableConsoleLog) {
|
|
1285
1289
|
node.consoleLog();
|
|
@@ -1297,7 +1301,7 @@ class GraphAI {
|
|
|
1297
1301
|
const update = node?.update;
|
|
1298
1302
|
if (update && previousResults) {
|
|
1299
1303
|
const result = this.getValueFromResults(update, previousResults);
|
|
1300
|
-
this.
|
|
1304
|
+
this.updateStaticNodeValue(nodeId, result, update.nodeId);
|
|
1301
1305
|
}
|
|
1302
1306
|
if (enableConsoleLog) {
|
|
1303
1307
|
node.consoleLog();
|
|
@@ -1313,6 +1317,7 @@ class GraphAI {
|
|
|
1313
1317
|
graphLoader: undefined,
|
|
1314
1318
|
forceLoop: false,
|
|
1315
1319
|
}) {
|
|
1320
|
+
this.staticNodeInitData = {};
|
|
1316
1321
|
this.logs = [];
|
|
1317
1322
|
this.config = {};
|
|
1318
1323
|
this.onLogCallback = (__log, __isUpdate) => { };
|
|
@@ -1350,7 +1355,6 @@ class GraphAI {
|
|
|
1350
1355
|
},
|
|
1351
1356
|
};
|
|
1352
1357
|
this.nodes = this.createNodes(this.graphData);
|
|
1353
|
-
this.initializeStaticNodes(true);
|
|
1354
1358
|
}
|
|
1355
1359
|
getAgentFunctionInfo(agentId) {
|
|
1356
1360
|
if (agentId && this.agentFunctionInfoDictionary[agentId]) {
|
|
@@ -1427,6 +1431,7 @@ class GraphAI {
|
|
|
1427
1431
|
}
|
|
1428
1432
|
// Public API
|
|
1429
1433
|
async run(all = false) {
|
|
1434
|
+
this.setStaticNodeResults();
|
|
1430
1435
|
if (Object.values(this.nodes)
|
|
1431
1436
|
.filter((node) => node.isStaticNode)
|
|
1432
1437
|
.some((node) => node.result === undefined && node.update === undefined)) {
|
|
@@ -1498,6 +1503,7 @@ class GraphAI {
|
|
|
1498
1503
|
// We need to update static nodes, before checking the condition
|
|
1499
1504
|
const previousResults = this.results(true, true); // results from previous loop
|
|
1500
1505
|
this.updateStaticNodes(previousResults);
|
|
1506
|
+
this.setStaticNodeResults();
|
|
1501
1507
|
if (loop.count === undefined || this.repeatCount < loop.count) {
|
|
1502
1508
|
if (loop.while) {
|
|
1503
1509
|
const source = parseNodeName(loop.while);
|
|
@@ -1507,8 +1513,9 @@ class GraphAI {
|
|
|
1507
1513
|
return false; // while condition is not met
|
|
1508
1514
|
}
|
|
1509
1515
|
}
|
|
1510
|
-
this.
|
|
1516
|
+
this.nodes = this.createNodes(this.graphData);
|
|
1511
1517
|
this.updateStaticNodes(previousResults, true);
|
|
1518
|
+
this.setStaticNodeResults();
|
|
1512
1519
|
this.pushReadyNodesIntoQueue();
|
|
1513
1520
|
return true; // Indicating that we are going to continue.
|
|
1514
1521
|
}
|
|
@@ -1519,7 +1526,7 @@ class GraphAI {
|
|
|
1519
1526
|
throw new Error("This GraphAI instance is running");
|
|
1520
1527
|
}
|
|
1521
1528
|
this.nodes = this.createNodes(this.graphData);
|
|
1522
|
-
this.
|
|
1529
|
+
this.setStaticNodeResults();
|
|
1523
1530
|
}
|
|
1524
1531
|
setPreviousResults(previousResults) {
|
|
1525
1532
|
this.updateStaticNodes(previousResults);
|
|
@@ -1549,9 +1556,13 @@ class GraphAI {
|
|
|
1549
1556
|
}
|
|
1550
1557
|
// Public API
|
|
1551
1558
|
injectValue(nodeId, value, injectFrom) {
|
|
1559
|
+
this.staticNodeInitData[nodeId] = value;
|
|
1560
|
+
this.updateStaticNodeValue(nodeId, value, injectFrom);
|
|
1561
|
+
}
|
|
1562
|
+
updateStaticNodeValue(nodeId, value, injectFrom) {
|
|
1552
1563
|
const node = this.nodes[nodeId];
|
|
1553
1564
|
if (node && node.isStaticNode) {
|
|
1554
|
-
node.
|
|
1565
|
+
node.updateValue(value, injectFrom);
|
|
1555
1566
|
}
|
|
1556
1567
|
else {
|
|
1557
1568
|
throw new Error(`injectValue with Invalid nodeId, ${nodeId}`);
|