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