graphai 2.0.11 → 2.0.13

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
@@ -174,7 +174,7 @@ const propNumberFunction = (result, propId) => {
174
174
  if (match) {
175
175
  return Number(result) + Number(match[1]);
176
176
  }
177
- const equalMatch = propId.match(/^equal\(([A-Za-z0-9!#$%&()*+,\-./:;<=>?@]+)\)/);
177
+ const equalMatch = propId.match(/^equal\(([A-Za-z0-9!#$%&()*+,\-/:;<=>?@]+)\)/);
178
178
  if (equalMatch) {
179
179
  return result === Number(equalMatch[1]);
180
180
  }
@@ -189,7 +189,20 @@ const propBooleanFunction = (result, propId) => {
189
189
  }
190
190
  return undefined;
191
191
  };
192
- const propFunctions = [propArrayFunction, propObjectFunction, propStringFunction, propNumberFunction, propBooleanFunction];
192
+ const propUndefinrdFunction = (result, propId) => {
193
+ if (result === undefined) {
194
+ const equalMatch = propId.match(/^default\(([A-Za-z0-9!#$%&()*+,\-/:;<=>?@]+)\)/);
195
+ if (equalMatch) {
196
+ if (equalMatch[1].match(/^[0-9-]+$/)) {
197
+ return Number(equalMatch[1]);
198
+ }
199
+ return equalMatch[1];
200
+ }
201
+ }
202
+ return undefined;
203
+ };
204
+ // TODO if (result === undefined) {default()}
205
+ const propFunctions = [propArrayFunction, propObjectFunction, propStringFunction, propNumberFunction, propBooleanFunction, propUndefinrdFunction];
193
206
  const utilsFunctions = (input, nodes) => {
194
207
  if (input === "@now" || input === "@now_ms") {
195
208
  return Date.now();
@@ -365,9 +378,10 @@ const dataSourceNodeIds = (sources) => {
365
378
  };
366
379
 
367
380
  class TransactionLog {
368
- constructor(nodeId) {
381
+ constructor(nodeId, mapIndex) {
369
382
  this.nodeId = nodeId;
370
383
  this.state = NodeState.Waiting;
384
+ this.mapIndex = mapIndex;
371
385
  }
372
386
  initForComputedNode(node, graph) {
373
387
  this.agentId = node.getAgentId();
@@ -459,7 +473,7 @@ const getNestedData = (result, propId, propFunctions) => {
459
473
  return undefined;
460
474
  };
461
475
  const innerGetDataFromSource = (result, propIds, propFunctions) => {
462
- if (!isNull(result) && propIds && propIds.length > 0) {
476
+ if (propIds && propIds.length > 0) {
463
477
  const propId = propIds[0];
464
478
  const ret = getNestedData(result, propId, propFunctions);
465
479
  if (ret === undefined) {
@@ -556,7 +570,7 @@ class Node {
556
570
  this.result = undefined;
557
571
  this.nodeId = nodeId;
558
572
  this.graph = graph;
559
- this.log = new TransactionLog(nodeId);
573
+ this.log = new TransactionLog(nodeId, this.graph.mapIndex);
560
574
  this.console = {};
561
575
  }
562
576
  asString() {
@@ -604,6 +618,7 @@ class ComputedNode extends Node {
604
618
  this.filterParams = data.filterParams ?? {};
605
619
  this.passThrough = data.passThrough;
606
620
  this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
621
+ this.repeatUntil = data.repeatUntil;
607
622
  this.timeout = data.timeout;
608
623
  this.isResult = data.isResult ?? false;
609
624
  this.priority = data.priority ?? 0;
@@ -839,6 +854,14 @@ class ComputedNode extends Node {
839
854
  GraphAILogger.log(`-- transactionId mismatch with ${this.nodeId} (probably timeout)`);
840
855
  return;
841
856
  }
857
+ if (this.repeatUntil?.exists) {
858
+ const dummyResult = { self: { result: this.getResult(result) } };
859
+ const repeatResult = resultsOf({ data: this.repeatUntil?.exists }, dummyResult, [], true);
860
+ if (isNull(repeatResult?.data)) {
861
+ this.retry(NodeState.Failed, Error("Repeat Until"));
862
+ return;
863
+ }
864
+ }
842
865
  // after process
843
866
  this.afterExecute(result, localLog);
844
867
  }
@@ -979,6 +1002,7 @@ const computedNodeAttributeKeys = [
979
1002
  "anyInput",
980
1003
  "params",
981
1004
  "retry",
1005
+ "repeatUntil",
982
1006
  "timeout",
983
1007
  "agent",
984
1008
  "graph",
@@ -1347,6 +1371,7 @@ class GraphAI {
1347
1371
  config: {},
1348
1372
  graphLoader: undefined,
1349
1373
  forceLoop: false,
1374
+ mapIndex: undefined,
1350
1375
  }) {
1351
1376
  this.staticNodeInitData = {};
1352
1377
  this.logs = [];
@@ -1371,6 +1396,7 @@ class GraphAI {
1371
1396
  this.config = options.config;
1372
1397
  this.graphLoader = options.graphLoader;
1373
1398
  this.forceLoop = options.forceLoop ?? false;
1399
+ this.mapIndex = options.mapIndex;
1374
1400
  this.loop = graphData.loop;
1375
1401
  this.verbose = graphData.verbose === true;
1376
1402
  this.onComplete = (__isAbort) => {
@@ -1522,6 +1548,12 @@ class GraphAI {
1522
1548
  if (this.isRunning() || this.processLoopIfNecessary()) {
1523
1549
  return; // continue running
1524
1550
  }
1551
+ if (this.verbose) {
1552
+ const notExecutedNodes = Object.values(this.nodes).filter((node) => node.isComputedNode && node.state !== "completed");
1553
+ if (notExecutedNodes.length > 0) {
1554
+ console.log("Those nodes are not running. " + notExecutedNodes.map((node) => `${node.nodeId}: ${node.state}`).join(", "));
1555
+ }
1556
+ }
1525
1557
  this.onComplete(false); // Nothing to run. Finish it.
1526
1558
  }
1527
1559
  // Must be called only from onExecutionComplete righ after removeRunning
@@ -1622,5 +1654,5 @@ class GraphAI {
1622
1654
  }
1623
1655
  }
1624
1656
 
1625
- export { GraphAI, GraphAILogger, NodeState, TaskManager, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
1657
+ export { GraphAI, GraphAILogger, NodeState, TaskManager, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isNull, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
1626
1658
  //# sourceMappingURL=bundle.esm.js.map