graphai 1.0.11 → 1.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.cjs.js +1 -1
- package/lib/bundle.cjs.js.map +1 -1
- package/lib/bundle.esm.js +81 -25
- 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 +1 -0
- package/lib/graphai.js +14 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/node.js +14 -13
- package/lib/type.d.ts +1 -0
- package/lib/utils/GraphAILogger.d.ts +19 -0
- package/lib/utils/GraphAILogger.js +51 -0
- package/lib/utils/data_source.js +2 -1
- package/lib/utils/nodeUtils.js +1 -0
- package/lib/utils/prop_function.js +3 -2
- package/lib/utils/utils.js +2 -1
- package/package.json +2 -2
package/lib/bundle.esm.js
CHANGED
|
@@ -12,6 +12,55 @@ var NodeState;
|
|
|
12
12
|
NodeState["Skipped"] = "skipped";
|
|
13
13
|
})(NodeState || (NodeState = {}));
|
|
14
14
|
|
|
15
|
+
const enabledLevels = {
|
|
16
|
+
debug: true,
|
|
17
|
+
info: true,
|
|
18
|
+
log: true,
|
|
19
|
+
warn: true,
|
|
20
|
+
error: true,
|
|
21
|
+
};
|
|
22
|
+
let customLogger = null;
|
|
23
|
+
function setLevelEnabled(level, enabled) {
|
|
24
|
+
enabledLevels[level] = enabled;
|
|
25
|
+
}
|
|
26
|
+
function setLogger(logger) {
|
|
27
|
+
customLogger = logger;
|
|
28
|
+
}
|
|
29
|
+
function output(level, ...args) {
|
|
30
|
+
if (!enabledLevels[level])
|
|
31
|
+
return;
|
|
32
|
+
if (customLogger) {
|
|
33
|
+
customLogger(level, ...args);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
(console[level] || console.log)(...args);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function debug(...args) {
|
|
40
|
+
output("debug", ...args);
|
|
41
|
+
}
|
|
42
|
+
function info(...args) {
|
|
43
|
+
output("info", ...args);
|
|
44
|
+
}
|
|
45
|
+
function log(...args) {
|
|
46
|
+
output("log", ...args);
|
|
47
|
+
}
|
|
48
|
+
function warn(...args) {
|
|
49
|
+
output("warn", ...args);
|
|
50
|
+
}
|
|
51
|
+
function error(...args) {
|
|
52
|
+
output("error", ...args);
|
|
53
|
+
}
|
|
54
|
+
const GraphAILogger = {
|
|
55
|
+
setLevelEnabled,
|
|
56
|
+
setLogger,
|
|
57
|
+
debug,
|
|
58
|
+
info,
|
|
59
|
+
log,
|
|
60
|
+
warn,
|
|
61
|
+
error,
|
|
62
|
+
};
|
|
63
|
+
|
|
15
64
|
const sleep = async (milliseconds) => {
|
|
16
65
|
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
17
66
|
};
|
|
@@ -42,7 +91,7 @@ function assert(condition, message, isWarn = false) {
|
|
|
42
91
|
if (!isWarn) {
|
|
43
92
|
throw new Error(message);
|
|
44
93
|
}
|
|
45
|
-
|
|
94
|
+
GraphAILogger.warn("warn: " + message);
|
|
46
95
|
}
|
|
47
96
|
}
|
|
48
97
|
const isObject = (x) => {
|
|
@@ -158,6 +207,7 @@ const inputs2dataSources = (inputs) => {
|
|
|
158
207
|
}
|
|
159
208
|
return parseNodeName(inputs);
|
|
160
209
|
};
|
|
210
|
+
// TODO: Maybe it's a remnant of old array inputs. Check and delete.
|
|
161
211
|
const dataSourceNodeIds = (sources) => {
|
|
162
212
|
if (!Array.isArray(sources)) {
|
|
163
213
|
throw new Error("sources must be array!! maybe inputs is invalid");
|
|
@@ -300,7 +350,7 @@ const propStringFunction = (result, propId) => {
|
|
|
300
350
|
if (sliceMatch[1] !== undefined) {
|
|
301
351
|
return result.slice(Number(sliceMatch[1]));
|
|
302
352
|
}
|
|
303
|
-
|
|
353
|
+
GraphAILogger.warn("slice is not valid format: " + sliceMatch);
|
|
304
354
|
}
|
|
305
355
|
const splitMatch = propId.match(/^split\(([-_:;.,\s\n]+)\)$/);
|
|
306
356
|
if (splitMatch) {
|
|
@@ -342,7 +392,7 @@ const utilsFunctions = (input, nodes) => {
|
|
|
342
392
|
return nodes[loopCounterKey].result;
|
|
343
393
|
}
|
|
344
394
|
// If a placeholder does not match any key, replace it with an empty string.
|
|
345
|
-
|
|
395
|
+
GraphAILogger.warn("not match template utility function: ${" + input + "}");
|
|
346
396
|
return "";
|
|
347
397
|
};
|
|
348
398
|
|
|
@@ -381,7 +431,7 @@ const innerGetDataFromSource = (result, propIds, propFunctions) => {
|
|
|
381
431
|
const propId = propIds[0];
|
|
382
432
|
const ret = getNestedData(result, propId, propFunctions);
|
|
383
433
|
if (ret === undefined) {
|
|
384
|
-
|
|
434
|
+
GraphAILogger.error(`prop: ${propIds.join(".")} is not hit`);
|
|
385
435
|
}
|
|
386
436
|
if (propIds.length > 1) {
|
|
387
437
|
return innerGetDataFromSource(ret, propIds.slice(1), propFunctions);
|
|
@@ -495,14 +545,14 @@ class Node {
|
|
|
495
545
|
return;
|
|
496
546
|
}
|
|
497
547
|
else if (this.console === true || this.console.after === true) {
|
|
498
|
-
|
|
548
|
+
GraphAILogger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
|
|
499
549
|
}
|
|
500
550
|
else if (this.console.after) {
|
|
501
551
|
if (isObject(this.console.after)) {
|
|
502
|
-
|
|
552
|
+
GraphAILogger.log(JSON.stringify(resultsOf(this.console.after, { self: { result } }, this.graph.propFunctions, true), null, 2));
|
|
503
553
|
}
|
|
504
554
|
else {
|
|
505
|
-
|
|
555
|
+
GraphAILogger.log(this.console.after);
|
|
506
556
|
}
|
|
507
557
|
}
|
|
508
558
|
}
|
|
@@ -660,7 +710,7 @@ class ComputedNode extends Node {
|
|
|
660
710
|
// and attempt to retry (if specified).
|
|
661
711
|
executeTimeout(transactionId) {
|
|
662
712
|
if (this.state === NodeState.Executing && this.isCurrentTransaction(transactionId)) {
|
|
663
|
-
|
|
713
|
+
GraphAILogger.warn(`-- timeout ${this.timeout} with ${this.nodeId}`);
|
|
664
714
|
this.retry(NodeState.TimedOut, Error("Timeout"));
|
|
665
715
|
}
|
|
666
716
|
}
|
|
@@ -753,7 +803,7 @@ class ComputedNode extends Node {
|
|
|
753
803
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
754
804
|
// This condition happens when the agent function returns
|
|
755
805
|
// after the timeout (either retried or not).
|
|
756
|
-
|
|
806
|
+
GraphAILogger.log(`-- transactionId mismatch with ${this.nodeId} (probably timeout)`);
|
|
757
807
|
return;
|
|
758
808
|
}
|
|
759
809
|
// after process
|
|
@@ -791,20 +841,20 @@ class ComputedNode extends Node {
|
|
|
791
841
|
// the retry if specified.
|
|
792
842
|
errorProcess(error, transactionId, namedInputs) {
|
|
793
843
|
if (error instanceof Error && error.message !== strIntentionalError) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
844
|
+
GraphAILogger.error(`<-- NodeId: ${this.nodeId}, Agent: ${this.agentId}`);
|
|
845
|
+
GraphAILogger.error({ namedInputs });
|
|
846
|
+
GraphAILogger.error(error);
|
|
847
|
+
GraphAILogger.error("-->");
|
|
798
848
|
}
|
|
799
849
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
800
|
-
|
|
850
|
+
GraphAILogger.warn(`-- transactionId mismatch with ${this.nodeId} (not timeout)`);
|
|
801
851
|
return;
|
|
802
852
|
}
|
|
803
853
|
if (error instanceof Error) {
|
|
804
854
|
this.retry(NodeState.Failed, error);
|
|
805
855
|
}
|
|
806
856
|
else {
|
|
807
|
-
|
|
857
|
+
GraphAILogger.error(`-- NodeId: ${this.nodeId}: Unknown error was caught`);
|
|
808
858
|
this.retry(NodeState.Failed, Error("Unknown"));
|
|
809
859
|
}
|
|
810
860
|
}
|
|
@@ -852,10 +902,10 @@ class ComputedNode extends Node {
|
|
|
852
902
|
return;
|
|
853
903
|
}
|
|
854
904
|
else if (this.console === true || this.console.before === true) {
|
|
855
|
-
|
|
905
|
+
GraphAILogger.log(JSON.stringify(context.namedInputs, null, 2));
|
|
856
906
|
}
|
|
857
907
|
else if (this.console.before) {
|
|
858
|
-
|
|
908
|
+
GraphAILogger.log(this.console.before);
|
|
859
909
|
}
|
|
860
910
|
}
|
|
861
911
|
}
|
|
@@ -1247,6 +1297,7 @@ class GraphAI {
|
|
|
1247
1297
|
bypassAgentIds: [],
|
|
1248
1298
|
config: {},
|
|
1249
1299
|
graphLoader: undefined,
|
|
1300
|
+
forceLoop: false,
|
|
1250
1301
|
}) {
|
|
1251
1302
|
this.logs = [];
|
|
1252
1303
|
this.config = {};
|
|
@@ -1254,11 +1305,11 @@ class GraphAI {
|
|
|
1254
1305
|
this.callbacks = [];
|
|
1255
1306
|
this.repeatCount = 0;
|
|
1256
1307
|
if (!graphData.version && !options.taskManager) {
|
|
1257
|
-
|
|
1308
|
+
GraphAILogger.warn("------------ missing version number");
|
|
1258
1309
|
}
|
|
1259
1310
|
this.version = graphData.version ?? graphDataLatestVersion;
|
|
1260
1311
|
if (this.version < graphDataLatestVersion) {
|
|
1261
|
-
|
|
1312
|
+
GraphAILogger.warn(`------------ upgrade to ${graphDataLatestVersion}!`);
|
|
1262
1313
|
}
|
|
1263
1314
|
this.retryLimit = graphData.retry; // optional
|
|
1264
1315
|
this.graphId = `${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 9)}`; // URL.createObjectURL(new Blob()).slice(-36);
|
|
@@ -1269,6 +1320,7 @@ class GraphAI {
|
|
|
1269
1320
|
this.bypassAgentIds = options.bypassAgentIds ?? [];
|
|
1270
1321
|
this.config = options.config;
|
|
1271
1322
|
this.graphLoader = options.graphLoader;
|
|
1323
|
+
this.forceLoop = options.forceLoop ?? false;
|
|
1272
1324
|
this.loop = graphData.loop;
|
|
1273
1325
|
this.verbose = graphData.verbose === true;
|
|
1274
1326
|
this.onComplete = (__isAbort) => {
|
|
@@ -1281,7 +1333,7 @@ class GraphAI {
|
|
|
1281
1333
|
nodes: {
|
|
1282
1334
|
...graphData.nodes,
|
|
1283
1335
|
[loopCounterKey]: { value: 0, update: `:${loopCounterKey}.add(1)` },
|
|
1284
|
-
}
|
|
1336
|
+
},
|
|
1285
1337
|
};
|
|
1286
1338
|
this.nodes = this.createNodes(this.graphData);
|
|
1287
1339
|
this.initializeStaticNodes(true);
|
|
@@ -1371,15 +1423,15 @@ class GraphAI {
|
|
|
1371
1423
|
}
|
|
1372
1424
|
this.pushReadyNodesIntoQueue();
|
|
1373
1425
|
if (!this.isRunning()) {
|
|
1374
|
-
|
|
1426
|
+
GraphAILogger.warn("-- nothing to execute");
|
|
1375
1427
|
return {};
|
|
1376
1428
|
}
|
|
1377
1429
|
return new Promise((resolve, reject) => {
|
|
1378
1430
|
this.onComplete = (isAbort = false) => {
|
|
1379
1431
|
const errors = this.errors();
|
|
1380
|
-
const
|
|
1381
|
-
if (
|
|
1382
|
-
reject(errors[
|
|
1432
|
+
const errorNodeIds = Object.keys(errors);
|
|
1433
|
+
if (errorNodeIds.length > 0 || isAbort) {
|
|
1434
|
+
reject(errors[errorNodeIds[0]]);
|
|
1383
1435
|
}
|
|
1384
1436
|
else {
|
|
1385
1437
|
resolve(this.results(all));
|
|
@@ -1420,6 +1472,10 @@ class GraphAI {
|
|
|
1420
1472
|
// Check if there is any running computed nodes.
|
|
1421
1473
|
// In case of no running computed note, start the another iteration if ncessary (loop)
|
|
1422
1474
|
processLoopIfNecessary() {
|
|
1475
|
+
//
|
|
1476
|
+
if (!this.forceLoop && Object.keys(this.errors()).length > 0) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1423
1479
|
this.repeatCount++;
|
|
1424
1480
|
const loop = this.loop;
|
|
1425
1481
|
if (!loop) {
|
|
@@ -1499,5 +1555,5 @@ class GraphAI {
|
|
|
1499
1555
|
}
|
|
1500
1556
|
}
|
|
1501
1557
|
|
|
1502
|
-
export { GraphAI, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
|
|
1558
|
+
export { GraphAI, GraphAILogger, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
|
|
1503
1559
|
//# sourceMappingURL=bundle.esm.js.map
|