graphai 0.6.19 → 0.6.20
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 +65 -23
- 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 +18 -5
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/lib/node.d.ts +2 -0
- package/lib/node.js +21 -1
- package/lib/type.d.ts +14 -9
- package/lib/type.js +1 -0
- package/lib/utils/utils.d.ts +6 -16
- package/lib/utils/utils.js +12 -1
- package/lib/validator.js +2 -1
- package/lib/validators/relation_validator.js +2 -2
- package/package.json +1 -1
package/lib/bundle.esm.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
var NodeState;
|
|
2
|
+
(function (NodeState) {
|
|
3
|
+
NodeState["Waiting"] = "waiting";
|
|
4
|
+
NodeState["Queued"] = "queued";
|
|
5
|
+
NodeState["Executing"] = "executing";
|
|
6
|
+
NodeState["ExecutingServer"] = "executing-server";
|
|
7
|
+
NodeState["Failed"] = "failed";
|
|
8
|
+
NodeState["TimedOut"] = "timed-out";
|
|
9
|
+
NodeState["Abort"] = "abort";
|
|
10
|
+
NodeState["Completed"] = "completed";
|
|
11
|
+
NodeState["Injected"] = "injected";
|
|
12
|
+
NodeState["Skipped"] = "skipped";
|
|
13
|
+
})(NodeState || (NodeState = {}));
|
|
14
|
+
|
|
1
15
|
const sleep = async (milliseconds) => {
|
|
2
16
|
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
3
17
|
};
|
|
@@ -107,6 +121,8 @@ const defaultTestContext = {
|
|
|
107
121
|
nodeId: "test",
|
|
108
122
|
retry: 0,
|
|
109
123
|
verbose: true,
|
|
124
|
+
state: NodeState.Executing,
|
|
125
|
+
subGraphs: new Map(),
|
|
110
126
|
},
|
|
111
127
|
params: {},
|
|
112
128
|
filterParams: {},
|
|
@@ -116,6 +132,12 @@ const defaultTestContext = {
|
|
|
116
132
|
const isNamedInputs = (namedInputs) => {
|
|
117
133
|
return isObject(namedInputs) && !Array.isArray(namedInputs) && Object.keys(namedInputs || {}).length > 0;
|
|
118
134
|
};
|
|
135
|
+
const isComputedNodeData = (node) => {
|
|
136
|
+
return "agent" in node;
|
|
137
|
+
};
|
|
138
|
+
const isStaticNodeData = (node) => {
|
|
139
|
+
return !("agent" in node);
|
|
140
|
+
};
|
|
119
141
|
|
|
120
142
|
// for dataSource
|
|
121
143
|
const inputs2dataSources = (inputs) => {
|
|
@@ -139,19 +161,6 @@ const dataSourceNodeIds = (sources) => {
|
|
|
139
161
|
return sources.filter((source) => source.nodeId).map((source) => source.nodeId);
|
|
140
162
|
};
|
|
141
163
|
|
|
142
|
-
var NodeState;
|
|
143
|
-
(function (NodeState) {
|
|
144
|
-
NodeState["Waiting"] = "waiting";
|
|
145
|
-
NodeState["Queued"] = "queued";
|
|
146
|
-
NodeState["Executing"] = "executing";
|
|
147
|
-
NodeState["ExecutingServer"] = "executing-server";
|
|
148
|
-
NodeState["Failed"] = "failed";
|
|
149
|
-
NodeState["TimedOut"] = "timed-out";
|
|
150
|
-
NodeState["Completed"] = "completed";
|
|
151
|
-
NodeState["Injected"] = "injected";
|
|
152
|
-
NodeState["Skipped"] = "skipped";
|
|
153
|
-
})(NodeState || (NodeState = {}));
|
|
154
|
-
|
|
155
164
|
class TransactionLog {
|
|
156
165
|
constructor(nodeId) {
|
|
157
166
|
this.nodeId = nodeId;
|
|
@@ -533,6 +542,18 @@ class ComputedNode extends Node {
|
|
|
533
542
|
this.pendings.add(source.nodeId);
|
|
534
543
|
return source;
|
|
535
544
|
}
|
|
545
|
+
resetPending() {
|
|
546
|
+
this.pendings.clear();
|
|
547
|
+
if (this.state === NodeState.Executing) {
|
|
548
|
+
this.state = NodeState.Abort;
|
|
549
|
+
if (this.debugInfo) {
|
|
550
|
+
this.debugInfo.state = NodeState.Abort;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (this.debugInfo && this.debugInfo.subGraphs) {
|
|
554
|
+
this.debugInfo.subGraphs.forEach((graph) => graph.abort());
|
|
555
|
+
}
|
|
556
|
+
}
|
|
536
557
|
isReadyNode() {
|
|
537
558
|
if (this.state !== NodeState.Waiting || this.pendings.size !== 0) {
|
|
538
559
|
return false;
|
|
@@ -696,6 +717,9 @@ class ComputedNode extends Node {
|
|
|
696
717
|
}
|
|
697
718
|
}
|
|
698
719
|
afterExecute(result, localLog) {
|
|
720
|
+
if (this.state == NodeState.Abort) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
699
723
|
this.state = NodeState.Completed;
|
|
700
724
|
this.result = this.getResult(result);
|
|
701
725
|
if (this.output) {
|
|
@@ -735,11 +759,14 @@ class ComputedNode extends Node {
|
|
|
735
759
|
}
|
|
736
760
|
}
|
|
737
761
|
getContext(previousResults, localLog, agentId, config) {
|
|
762
|
+
// Pass debugInfo by reference, and the state of this node will be received by agent/agentFilter.
|
|
763
|
+
// From graphAgent(nested, map), set the instance of graphai, and use abort on the child graphai.
|
|
764
|
+
this.debugInfo = this.getDebugInfo(agentId);
|
|
738
765
|
const context = {
|
|
739
766
|
params: this.graph.resultsOf(this.params),
|
|
740
767
|
namedInputs: previousResults,
|
|
741
768
|
inputSchema: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId)?.inputs,
|
|
742
|
-
debugInfo: this.
|
|
769
|
+
debugInfo: this.debugInfo,
|
|
743
770
|
cacheType: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId)?.cacheType,
|
|
744
771
|
filterParams: this.filterParams,
|
|
745
772
|
agentFilters: this.graph.agentFilters,
|
|
@@ -764,6 +791,8 @@ class ComputedNode extends Node {
|
|
|
764
791
|
nodeId: this.nodeId,
|
|
765
792
|
agentId,
|
|
766
793
|
retry: this.retryCount,
|
|
794
|
+
state: this.state,
|
|
795
|
+
subGraphs: new Map(),
|
|
767
796
|
verbose: this.graph.verbose,
|
|
768
797
|
version: this.graph.version,
|
|
769
798
|
isResult: this.isResult,
|
|
@@ -917,7 +946,7 @@ const relationValidator = (graphData, staticNodeIds, computedNodeIds) => {
|
|
|
917
946
|
}
|
|
918
947
|
});
|
|
919
948
|
};
|
|
920
|
-
if (
|
|
949
|
+
if (nodeData && isComputedNodeData(nodeData)) {
|
|
921
950
|
if (nodeData.inputs) {
|
|
922
951
|
const sourceNodeIds = dataSourceNodeIds(inputs2dataSources(nodeData.inputs));
|
|
923
952
|
dataSourceValidator("Inputs", sourceNodeIds);
|
|
@@ -947,7 +976,7 @@ const relationValidator = (graphData, staticNodeIds, computedNodeIds) => {
|
|
|
947
976
|
// TODO. validate update
|
|
948
977
|
staticNodeIds.forEach((staticNodeId) => {
|
|
949
978
|
const nodeData = graphData.nodes[staticNodeId];
|
|
950
|
-
if (
|
|
979
|
+
if (isStaticNodeData(nodeData) && nodeData.update) {
|
|
951
980
|
const update = nodeData.update;
|
|
952
981
|
const updateNodeId = parseNodeName(update).nodeId;
|
|
953
982
|
if (!updateNodeId) {
|
|
@@ -1003,7 +1032,7 @@ const validateGraphData = (data, agentIds) => {
|
|
|
1003
1032
|
const graphAgentIds = new Set();
|
|
1004
1033
|
Object.keys(data.nodes).forEach((nodeId) => {
|
|
1005
1034
|
const node = data.nodes[nodeId];
|
|
1006
|
-
const isStaticNode =
|
|
1035
|
+
const isStaticNode = isStaticNodeData(node);
|
|
1007
1036
|
nodeValidator(node);
|
|
1008
1037
|
const agentId = isStaticNode ? "" : node.agent;
|
|
1009
1038
|
isStaticNode && staticNodeValidator(node) && staticNodeIds.push(nodeId);
|
|
@@ -1100,7 +1129,7 @@ class GraphAI {
|
|
|
1100
1129
|
createNodes(graphData) {
|
|
1101
1130
|
const nodes = Object.keys(graphData.nodes).reduce((_nodes, nodeId) => {
|
|
1102
1131
|
const nodeData = graphData.nodes[nodeId];
|
|
1103
|
-
if (
|
|
1132
|
+
if (isComputedNodeData(nodeData)) {
|
|
1104
1133
|
_nodes[nodeId] = new ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
1105
1134
|
}
|
|
1106
1135
|
else {
|
|
@@ -1193,7 +1222,7 @@ class GraphAI {
|
|
|
1193
1222
|
this.graphLoader = options.graphLoader;
|
|
1194
1223
|
this.loop = graphData.loop;
|
|
1195
1224
|
this.verbose = graphData.verbose === true;
|
|
1196
|
-
this.onComplete = () => {
|
|
1225
|
+
this.onComplete = (__isAbort) => {
|
|
1197
1226
|
throw new Error("SOMETHING IS WRONG: onComplete is called without run()");
|
|
1198
1227
|
};
|
|
1199
1228
|
validateGraphData(graphData, [...Object.keys(agentFunctionInfoDictionary), ...this.bypassAgentIds]);
|
|
@@ -1290,10 +1319,10 @@ class GraphAI {
|
|
|
1290
1319
|
return {};
|
|
1291
1320
|
}
|
|
1292
1321
|
return new Promise((resolve, reject) => {
|
|
1293
|
-
this.onComplete = () => {
|
|
1322
|
+
this.onComplete = (isAbort = false) => {
|
|
1294
1323
|
const errors = this.errors();
|
|
1295
1324
|
const nodeIds = Object.keys(errors);
|
|
1296
|
-
if (nodeIds.length > 0) {
|
|
1325
|
+
if (nodeIds.length > 0 || isAbort) {
|
|
1297
1326
|
reject(errors[nodeIds[0]]);
|
|
1298
1327
|
}
|
|
1299
1328
|
else {
|
|
@@ -1302,6 +1331,19 @@ class GraphAI {
|
|
|
1302
1331
|
};
|
|
1303
1332
|
});
|
|
1304
1333
|
}
|
|
1334
|
+
abort() {
|
|
1335
|
+
if (this.isRunning()) {
|
|
1336
|
+
this.resetPending();
|
|
1337
|
+
}
|
|
1338
|
+
this.onComplete(this.isRunning());
|
|
1339
|
+
}
|
|
1340
|
+
resetPending() {
|
|
1341
|
+
Object.values(this.nodes).map((node) => {
|
|
1342
|
+
if (node.isComputedNode) {
|
|
1343
|
+
node.resetPending();
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1305
1347
|
// Public only for testing
|
|
1306
1348
|
isRunning() {
|
|
1307
1349
|
return this.taskManager.isRunning(this.graphId);
|
|
@@ -1312,7 +1354,7 @@ class GraphAI {
|
|
|
1312
1354
|
if (this.isRunning() || this.processLoopIfNecessary()) {
|
|
1313
1355
|
return; // continue running
|
|
1314
1356
|
}
|
|
1315
|
-
this.onComplete(); // Nothing to run. Finish it.
|
|
1357
|
+
this.onComplete(false); // Nothing to run. Finish it.
|
|
1316
1358
|
}
|
|
1317
1359
|
// Must be called only from onExecutionComplete righ after removeRunning
|
|
1318
1360
|
// Check if there is any running computed nodes.
|
|
@@ -1389,5 +1431,5 @@ class GraphAI {
|
|
|
1389
1431
|
}
|
|
1390
1432
|
}
|
|
1391
1433
|
|
|
1392
|
-
export { GraphAI, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isObject, parseNodeName, sleep, strIntentionalError };
|
|
1434
|
+
export { GraphAI, NodeState, ValidationError, agentInfoWrapper, assert, debugResultKey, defaultAgentInfo, defaultConcurrency, defaultTestContext, graphDataLatestVersion, inputs2dataSources, isComputedNodeData, isObject, isStaticNodeData, parseNodeName, sleep, strIntentionalError };
|
|
1393
1435
|
//# sourceMappingURL=bundle.esm.js.map
|