graphai 1.0.11 → 1.0.12
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 +71 -22
- 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.js +5 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/node.js +14 -13
- 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/prop_function.js +3 -2
- package/lib/utils/utils.js +2 -1
- package/package.json +1 -1
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) => {
|
|
@@ -300,7 +349,7 @@ const propStringFunction = (result, propId) => {
|
|
|
300
349
|
if (sliceMatch[1] !== undefined) {
|
|
301
350
|
return result.slice(Number(sliceMatch[1]));
|
|
302
351
|
}
|
|
303
|
-
|
|
352
|
+
GraphAILogger.warn("slice is not valid format: " + sliceMatch);
|
|
304
353
|
}
|
|
305
354
|
const splitMatch = propId.match(/^split\(([-_:;.,\s\n]+)\)$/);
|
|
306
355
|
if (splitMatch) {
|
|
@@ -342,7 +391,7 @@ const utilsFunctions = (input, nodes) => {
|
|
|
342
391
|
return nodes[loopCounterKey].result;
|
|
343
392
|
}
|
|
344
393
|
// If a placeholder does not match any key, replace it with an empty string.
|
|
345
|
-
|
|
394
|
+
GraphAILogger.warn("not match template utility function: ${" + input + "}");
|
|
346
395
|
return "";
|
|
347
396
|
};
|
|
348
397
|
|
|
@@ -381,7 +430,7 @@ const innerGetDataFromSource = (result, propIds, propFunctions) => {
|
|
|
381
430
|
const propId = propIds[0];
|
|
382
431
|
const ret = getNestedData(result, propId, propFunctions);
|
|
383
432
|
if (ret === undefined) {
|
|
384
|
-
|
|
433
|
+
GraphAILogger.error(`prop: ${propIds.join(".")} is not hit`);
|
|
385
434
|
}
|
|
386
435
|
if (propIds.length > 1) {
|
|
387
436
|
return innerGetDataFromSource(ret, propIds.slice(1), propFunctions);
|
|
@@ -495,14 +544,14 @@ class Node {
|
|
|
495
544
|
return;
|
|
496
545
|
}
|
|
497
546
|
else if (this.console === true || this.console.after === true) {
|
|
498
|
-
|
|
547
|
+
GraphAILogger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
|
|
499
548
|
}
|
|
500
549
|
else if (this.console.after) {
|
|
501
550
|
if (isObject(this.console.after)) {
|
|
502
|
-
|
|
551
|
+
GraphAILogger.log(JSON.stringify(resultsOf(this.console.after, { self: { result } }, this.graph.propFunctions, true), null, 2));
|
|
503
552
|
}
|
|
504
553
|
else {
|
|
505
|
-
|
|
554
|
+
GraphAILogger.log(this.console.after);
|
|
506
555
|
}
|
|
507
556
|
}
|
|
508
557
|
}
|
|
@@ -660,7 +709,7 @@ class ComputedNode extends Node {
|
|
|
660
709
|
// and attempt to retry (if specified).
|
|
661
710
|
executeTimeout(transactionId) {
|
|
662
711
|
if (this.state === NodeState.Executing && this.isCurrentTransaction(transactionId)) {
|
|
663
|
-
|
|
712
|
+
GraphAILogger.warn(`-- timeout ${this.timeout} with ${this.nodeId}`);
|
|
664
713
|
this.retry(NodeState.TimedOut, Error("Timeout"));
|
|
665
714
|
}
|
|
666
715
|
}
|
|
@@ -753,7 +802,7 @@ class ComputedNode extends Node {
|
|
|
753
802
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
754
803
|
// This condition happens when the agent function returns
|
|
755
804
|
// after the timeout (either retried or not).
|
|
756
|
-
|
|
805
|
+
GraphAILogger.log(`-- transactionId mismatch with ${this.nodeId} (probably timeout)`);
|
|
757
806
|
return;
|
|
758
807
|
}
|
|
759
808
|
// after process
|
|
@@ -791,20 +840,20 @@ class ComputedNode extends Node {
|
|
|
791
840
|
// the retry if specified.
|
|
792
841
|
errorProcess(error, transactionId, namedInputs) {
|
|
793
842
|
if (error instanceof Error && error.message !== strIntentionalError) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
843
|
+
GraphAILogger.error(`<-- NodeId: ${this.nodeId}, Agent: ${this.agentId}`);
|
|
844
|
+
GraphAILogger.error({ namedInputs });
|
|
845
|
+
GraphAILogger.error(error);
|
|
846
|
+
GraphAILogger.error("-->");
|
|
798
847
|
}
|
|
799
848
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
800
|
-
|
|
849
|
+
GraphAILogger.warn(`-- transactionId mismatch with ${this.nodeId} (not timeout)`);
|
|
801
850
|
return;
|
|
802
851
|
}
|
|
803
852
|
if (error instanceof Error) {
|
|
804
853
|
this.retry(NodeState.Failed, error);
|
|
805
854
|
}
|
|
806
855
|
else {
|
|
807
|
-
|
|
856
|
+
GraphAILogger.error(`-- NodeId: ${this.nodeId}: Unknown error was caught`);
|
|
808
857
|
this.retry(NodeState.Failed, Error("Unknown"));
|
|
809
858
|
}
|
|
810
859
|
}
|
|
@@ -852,10 +901,10 @@ class ComputedNode extends Node {
|
|
|
852
901
|
return;
|
|
853
902
|
}
|
|
854
903
|
else if (this.console === true || this.console.before === true) {
|
|
855
|
-
|
|
904
|
+
GraphAILogger.log(JSON.stringify(context.namedInputs, null, 2));
|
|
856
905
|
}
|
|
857
906
|
else if (this.console.before) {
|
|
858
|
-
|
|
907
|
+
GraphAILogger.log(this.console.before);
|
|
859
908
|
}
|
|
860
909
|
}
|
|
861
910
|
}
|
|
@@ -1254,11 +1303,11 @@ class GraphAI {
|
|
|
1254
1303
|
this.callbacks = [];
|
|
1255
1304
|
this.repeatCount = 0;
|
|
1256
1305
|
if (!graphData.version && !options.taskManager) {
|
|
1257
|
-
|
|
1306
|
+
GraphAILogger.warn("------------ missing version number");
|
|
1258
1307
|
}
|
|
1259
1308
|
this.version = graphData.version ?? graphDataLatestVersion;
|
|
1260
1309
|
if (this.version < graphDataLatestVersion) {
|
|
1261
|
-
|
|
1310
|
+
GraphAILogger.warn(`------------ upgrade to ${graphDataLatestVersion}!`);
|
|
1262
1311
|
}
|
|
1263
1312
|
this.retryLimit = graphData.retry; // optional
|
|
1264
1313
|
this.graphId = `${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 9)}`; // URL.createObjectURL(new Blob()).slice(-36);
|
|
@@ -1281,7 +1330,7 @@ class GraphAI {
|
|
|
1281
1330
|
nodes: {
|
|
1282
1331
|
...graphData.nodes,
|
|
1283
1332
|
[loopCounterKey]: { value: 0, update: `:${loopCounterKey}.add(1)` },
|
|
1284
|
-
}
|
|
1333
|
+
},
|
|
1285
1334
|
};
|
|
1286
1335
|
this.nodes = this.createNodes(this.graphData);
|
|
1287
1336
|
this.initializeStaticNodes(true);
|
|
@@ -1371,7 +1420,7 @@ class GraphAI {
|
|
|
1371
1420
|
}
|
|
1372
1421
|
this.pushReadyNodesIntoQueue();
|
|
1373
1422
|
if (!this.isRunning()) {
|
|
1374
|
-
|
|
1423
|
+
GraphAILogger.warn("-- nothing to execute");
|
|
1375
1424
|
return {};
|
|
1376
1425
|
}
|
|
1377
1426
|
return new Promise((resolve, reject) => {
|
|
@@ -1499,5 +1548,5 @@ class GraphAI {
|
|
|
1499
1548
|
}
|
|
1500
1549
|
}
|
|
1501
1550
|
|
|
1502
|
-
export { GraphAI, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
|
|
1551
|
+
export { GraphAI, GraphAILogger, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
|
|
1503
1552
|
//# sourceMappingURL=bundle.esm.js.map
|