graphai 0.1.0 → 0.1.2
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/README.md +47 -35
- package/lib/experimental_agents/array_agents/index.d.ts +3 -0
- package/lib/experimental_agents/array_agents/index.js +9 -0
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/pop_agent.js +15 -0
- package/lib/experimental_agents/array_agents/push_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/push_agent.js +14 -0
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +2 -0
- package/lib/experimental_agents/{array_agents.js → array_agents/shift_agent.js} +2 -17
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +28 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +38 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +17 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +30 -0
- package/lib/experimental_agents/data_agents/index.d.ts +3 -0
- package/lib/experimental_agents/data_agents/index.js +9 -0
- package/lib/experimental_agents/data_agents/total_agent.d.ts +46 -0
- package/lib/experimental_agents/data_agents/total_agent.js +51 -0
- package/lib/experimental_agents/embedding_agent.d.ts +6 -0
- package/lib/experimental_agents/embedding_agent.js +43 -0
- package/lib/experimental_agents/index.d.ts +8 -3
- package/lib/experimental_agents/index.js +8 -3
- package/lib/experimental_agents/map_agent.d.ts +4 -0
- package/lib/experimental_agents/map_agent.js +46 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +4 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +24 -0
- package/lib/experimental_agents/matrix_agents/index.d.ts +2 -0
- package/lib/experimental_agents/matrix_agents/index.js +7 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +6 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +29 -0
- package/lib/experimental_agents/nested_agent.d.ts +1 -2
- package/lib/experimental_agents/nested_agent.js +24 -8
- package/lib/experimental_agents/slashgpt_agent.d.ts +1 -1
- package/lib/experimental_agents/slashgpt_agent.js +2 -7
- package/lib/experimental_agents/sleeper_agents/index.d.ts +2 -0
- package/lib/experimental_agents/sleeper_agents/index.js +7 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +5 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +16 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +6 -0
- package/lib/experimental_agents/{sleeper_agent.js → sleeper_agents/sleeper_agent_debug.js} +4 -13
- package/lib/experimental_agents/string_agents/index.d.ts +2 -0
- package/lib/experimental_agents/string_agents/index.js +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +39 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +64 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +27 -0
- package/lib/experimental_agents/string_agents/string_template_agent.js +33 -0
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/bypass_agent.js +10 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.js +9 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.js +11 -0
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/counting_agent.js +11 -0
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +7 -0
- package/lib/experimental_agents/test_agents/index.d.ts +6 -0
- package/lib/experimental_agents/test_agents/index.js +15 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +10 -0
- package/lib/experimental_agents/token_agent.d.ts +6 -0
- package/lib/experimental_agents/token_agent.js +33 -0
- package/lib/graphai.d.ts +23 -18
- package/lib/graphai.js +106 -115
- package/lib/index.d.ts +2 -0
- package/lib/node.d.ts +30 -25
- package/lib/node.js +131 -101
- package/lib/task_manager.d.ts +20 -0
- package/lib/task_manager.js +69 -0
- package/lib/transaction_log.d.ts +27 -0
- package/lib/transaction_log.js +56 -0
- package/lib/type.d.ts +45 -32
- package/lib/type.js +1 -0
- package/lib/utils/test_agents.d.ts +2 -0
- package/lib/utils/test_agents.js +20 -0
- package/lib/utils/test_utils.d.ts +12 -0
- package/lib/utils/test_utils.js +34 -0
- package/lib/utils/utils.d.ts +3 -1
- package/lib/utils/utils.js +17 -6
- package/lib/validator.d.ts +2 -0
- package/lib/validator.js +28 -0
- package/lib/validators/agent_validator.d.ts +1 -0
- package/lib/validators/agent_validator.js +12 -0
- package/lib/validators/common.d.ts +3 -0
- package/lib/validators/common.js +6 -0
- package/lib/validators/computed_node_validator.d.ts +2 -0
- package/lib/validators/computed_node_validator.js +13 -0
- package/lib/validators/graph_data_validator.d.ts +3 -0
- package/lib/validators/graph_data_validator.js +43 -0
- package/lib/validators/nodeValidator.d.ts +2 -0
- package/lib/validators/nodeValidator.js +13 -0
- package/lib/validators/relation_validator.d.ts +2 -0
- package/lib/validators/relation_validator.js +62 -0
- package/lib/validators/static_node_validator.d.ts +2 -0
- package/lib/validators/static_node_validator.js +13 -0
- package/package.json +10 -14
- package/lib/experimental_agents/array_agents.d.ts +0 -4
- package/lib/experimental_agents/data_agent.d.ts +0 -3
- package/lib/experimental_agents/data_agent.js +0 -25
- package/lib/experimental_agents/sleeper_agent.d.ts +0 -10
- package/lib/experimental_agents/string_agent.d.ts +0 -7
- package/lib/experimental_agents/string_agent.js +0 -15
- package/lib/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -48
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
package/lib/graphai.js
CHANGED
|
@@ -1,78 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphAI = void 0;
|
|
4
|
+
const type_1 = require("./type");
|
|
4
5
|
const node_1 = require("./node");
|
|
5
6
|
const utils_1 = require("./utils/utils");
|
|
7
|
+
const validator_1 = require("./validator");
|
|
8
|
+
const task_manager_1 = require("./task_manager");
|
|
6
9
|
const defaultConcurrency = 8;
|
|
7
10
|
class GraphAI {
|
|
11
|
+
// This method is called when either the GraphAI obect was created,
|
|
12
|
+
// or we are about to start n-th iteration (n>2).
|
|
8
13
|
createNodes(data) {
|
|
9
|
-
const nodeId2forkedNodeIds = {};
|
|
10
|
-
const forkedNodeId2Index = {};
|
|
11
|
-
const forkedNodeId2NodeId = {}; // for sources
|
|
12
14
|
const nodes = Object.keys(data.nodes).reduce((_nodes, nodeId) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (fork) {
|
|
17
|
-
// For fork, change the nodeId and increase the node
|
|
18
|
-
nodeId2forkedNodeIds[nodeId] = new Array(fork).fill(undefined).map((_, i) => {
|
|
19
|
-
const forkedNodeId = `${nodeId}_${i}`;
|
|
20
|
-
_nodes[forkedNodeId] = new node(forkedNodeId, i, data.nodes[nodeId], this);
|
|
21
|
-
// Data for pending and waiting
|
|
22
|
-
forkedNodeId2Index[forkedNodeId] = i;
|
|
23
|
-
forkedNodeId2NodeId[forkedNodeId] = nodeId;
|
|
24
|
-
return forkedNodeId;
|
|
25
|
-
});
|
|
15
|
+
const isStaticNode = "value" in data.nodes[nodeId];
|
|
16
|
+
if (isStaticNode) {
|
|
17
|
+
_nodes[nodeId] = new node_1.StaticNode(nodeId, data.nodes[nodeId], this);
|
|
26
18
|
}
|
|
27
19
|
else {
|
|
28
|
-
|
|
20
|
+
const nodeData = data.nodes[nodeId];
|
|
21
|
+
_nodes[nodeId] = new node_1.ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
29
22
|
}
|
|
30
23
|
return _nodes;
|
|
31
24
|
}, {});
|
|
32
|
-
// Generate the waitlist for each node
|
|
25
|
+
// Generate the waitlist for each node.
|
|
33
26
|
Object.keys(nodes).forEach((nodeId) => {
|
|
34
27
|
const node = nodes[nodeId];
|
|
35
|
-
node.
|
|
36
|
-
|
|
37
|
-
if (nodeId2forkedNodeIds[pending]) {
|
|
38
|
-
// update node.pending and pending(previous) node.wailtlist
|
|
39
|
-
if (node.fork) {
|
|
40
|
-
// 1:1 if current nodes are also forking.
|
|
41
|
-
const newPendingId = nodeId2forkedNodeIds[pending][forkedNodeId2Index[nodeId]];
|
|
42
|
-
nodes[newPendingId].waitlist.add(nodeId); // previousNode
|
|
43
|
-
node.pendings.add(newPendingId);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// 1:n if current node is not forking.
|
|
47
|
-
nodeId2forkedNodeIds[pending].forEach((newPendingId) => {
|
|
48
|
-
nodes[newPendingId].waitlist.add(nodeId); // previousNode
|
|
49
|
-
node.pendings.add(newPendingId);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
node.pendings.delete(pending);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
28
|
+
if (node.isComputedNode) {
|
|
29
|
+
node.pendings.forEach((pending) => {
|
|
55
30
|
if (nodes[pending]) {
|
|
56
31
|
nodes[pending].waitlist.add(nodeId); // previousNode
|
|
57
32
|
}
|
|
58
33
|
else {
|
|
59
34
|
console.error(`--- invalid input ${pending} for node, ${nodeId}`);
|
|
60
35
|
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
node.inputs = Array.from(node.pendings); // for fork.
|
|
64
|
-
node.sources = node.inputs.reduce((sources, input) => {
|
|
65
|
-
const refNodeId = forkedNodeId2NodeId[input] ?? input;
|
|
66
|
-
sources[input] = { nodeId: input, propId: node.sources[refNodeId].propId };
|
|
67
|
-
return sources;
|
|
68
|
-
}, {});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
69
38
|
});
|
|
70
39
|
return nodes;
|
|
71
40
|
}
|
|
72
41
|
getValueFromResults(key, results) {
|
|
73
42
|
const source = (0, utils_1.parseNodeName)(key);
|
|
74
43
|
const result = results[source.nodeId];
|
|
75
|
-
return result
|
|
44
|
+
return result && source.propId ? result[source.propId] : result;
|
|
76
45
|
}
|
|
77
46
|
// for static
|
|
78
47
|
initializeNodes(previousResults) {
|
|
@@ -85,32 +54,31 @@ class GraphAI {
|
|
|
85
54
|
const value = node?.value;
|
|
86
55
|
const update = node?.update;
|
|
87
56
|
if (value) {
|
|
88
|
-
this.injectValue(nodeId, value);
|
|
57
|
+
this.injectValue(nodeId, value, nodeId);
|
|
89
58
|
}
|
|
90
59
|
if (update && previousResults) {
|
|
91
60
|
const result = this.getValueFromResults(update, previousResults);
|
|
92
61
|
if (result) {
|
|
93
|
-
this.injectValue(nodeId, result);
|
|
62
|
+
this.injectValue(nodeId, result, update);
|
|
94
63
|
}
|
|
95
64
|
}
|
|
96
65
|
}
|
|
97
66
|
});
|
|
98
67
|
}
|
|
99
|
-
constructor(data, callbackDictonary) {
|
|
100
|
-
this.isRunning = false;
|
|
101
|
-
this.runningNodes = new Set();
|
|
102
|
-
this.nodeQueue = []; // for Computed Node
|
|
103
|
-
this.repeatCount = 0;
|
|
68
|
+
constructor(data, callbackDictonary, taskManager = undefined) {
|
|
104
69
|
this.logs = [];
|
|
70
|
+
this.onLogCallback = (__log, __isUpdate) => { };
|
|
71
|
+
this.repeatCount = 0;
|
|
72
|
+
this.graphId = URL.createObjectURL(new Blob()).slice(-36);
|
|
105
73
|
this.data = data;
|
|
106
74
|
this.callbackDictonary = callbackDictonary;
|
|
107
|
-
this.
|
|
75
|
+
this.taskManager = taskManager ?? new task_manager_1.TaskManager(data.concurrency ?? defaultConcurrency);
|
|
108
76
|
this.loop = data.loop;
|
|
109
|
-
this.agentId = data.agentId;
|
|
110
77
|
this.verbose = data.verbose === true;
|
|
111
78
|
this.onComplete = () => {
|
|
112
79
|
console.error("-- SOMETHING IS WRONG: onComplete is called without run()");
|
|
113
80
|
};
|
|
81
|
+
(0, validator_1.validateGraphData)(data, Object.keys(callbackDictonary));
|
|
114
82
|
this.nodes = this.createNodes(data);
|
|
115
83
|
this.initializeNodes();
|
|
116
84
|
}
|
|
@@ -121,14 +89,18 @@ class GraphAI {
|
|
|
121
89
|
throw new Error("No agent: " + agentId);
|
|
122
90
|
}
|
|
123
91
|
asString() {
|
|
124
|
-
return Object.
|
|
125
|
-
.map((
|
|
126
|
-
return this.nodes[nodeId].asString();
|
|
127
|
-
})
|
|
92
|
+
return Object.values(this.nodes)
|
|
93
|
+
.map((node) => node.asString())
|
|
128
94
|
.join("\n");
|
|
129
95
|
}
|
|
130
|
-
|
|
131
|
-
|
|
96
|
+
// Public API
|
|
97
|
+
results(all) {
|
|
98
|
+
return Object.keys(this.nodes)
|
|
99
|
+
.filter((nodeId) => {
|
|
100
|
+
const node = this.nodes[nodeId];
|
|
101
|
+
return all || node.isResult;
|
|
102
|
+
})
|
|
103
|
+
.reduce((results, nodeId) => {
|
|
132
104
|
const node = this.nodes[nodeId];
|
|
133
105
|
if (node.result !== undefined) {
|
|
134
106
|
results[nodeId] = node.result;
|
|
@@ -136,6 +108,7 @@ class GraphAI {
|
|
|
136
108
|
return results;
|
|
137
109
|
}, {});
|
|
138
110
|
}
|
|
111
|
+
// Public API
|
|
139
112
|
errors() {
|
|
140
113
|
return Object.keys(this.nodes).reduce((errors, nodeId) => {
|
|
141
114
|
const node = this.nodes[nodeId];
|
|
@@ -152,96 +125,114 @@ class GraphAI {
|
|
|
152
125
|
Object.keys(this.nodes).forEach((nodeId) => {
|
|
153
126
|
const node = this.nodes[nodeId];
|
|
154
127
|
if (node.isComputedNode) {
|
|
155
|
-
|
|
128
|
+
this.pushQueueIfReady(node);
|
|
156
129
|
}
|
|
157
130
|
});
|
|
158
131
|
}
|
|
159
|
-
|
|
160
|
-
if (
|
|
132
|
+
pushQueueIfReady(node) {
|
|
133
|
+
if (node.isReadyNode()) {
|
|
134
|
+
this.pushQueue(node);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
pushQueueIfReadyAndRunning(node) {
|
|
138
|
+
if (this.isRunning()) {
|
|
139
|
+
this.pushQueueIfReady(node);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// for computed
|
|
143
|
+
pushQueue(node) {
|
|
144
|
+
node.state = type_1.NodeState.Queued;
|
|
145
|
+
this.taskManager.addTask(node, this.graphId, (_node) => {
|
|
146
|
+
(0, utils_1.assert)(node.nodeId === _node.nodeId, "GraphAI.pushQueue node mismatch");
|
|
147
|
+
node.execute();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Public API
|
|
151
|
+
async run(all = false) {
|
|
152
|
+
if (this.isRunning()) {
|
|
161
153
|
console.error("-- Already Running");
|
|
162
154
|
}
|
|
163
|
-
this.isRunning = true;
|
|
164
155
|
this.pushReadyNodesIntoQueue();
|
|
165
156
|
return new Promise((resolve, reject) => {
|
|
166
157
|
this.onComplete = () => {
|
|
167
|
-
this.isRunning = false;
|
|
168
158
|
const errors = this.errors();
|
|
169
159
|
const nodeIds = Object.keys(errors);
|
|
170
160
|
if (nodeIds.length > 0) {
|
|
171
161
|
reject(errors[nodeIds[0]]);
|
|
172
162
|
}
|
|
173
163
|
else {
|
|
174
|
-
resolve(this.results());
|
|
164
|
+
resolve(this.results(all));
|
|
175
165
|
}
|
|
176
166
|
};
|
|
177
167
|
});
|
|
178
168
|
}
|
|
179
|
-
// for
|
|
180
|
-
|
|
181
|
-
this.
|
|
182
|
-
node.execute();
|
|
183
|
-
}
|
|
184
|
-
// for computed
|
|
185
|
-
pushQueue(node) {
|
|
186
|
-
if (this.runningNodes.size < this.concurrency) {
|
|
187
|
-
this.runNode(node);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
this.nodeQueue.push(node);
|
|
191
|
-
}
|
|
169
|
+
// Public only for testing
|
|
170
|
+
isRunning() {
|
|
171
|
+
return this.taskManager.isRunning(this.graphId);
|
|
192
172
|
}
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
if (this.
|
|
197
|
-
|
|
198
|
-
if (n) {
|
|
199
|
-
this.runNode(n);
|
|
200
|
-
}
|
|
173
|
+
// callback from execute
|
|
174
|
+
onExecutionComplete(node) {
|
|
175
|
+
this.taskManager.onComplete(node);
|
|
176
|
+
if (this.isRunning() || this.processLoopIfNecessary()) {
|
|
177
|
+
return; // continue running
|
|
201
178
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
this.pushReadyNodesIntoQueue();
|
|
221
|
-
return;
|
|
179
|
+
this.onComplete(); // Nothing to run. Finish it.
|
|
180
|
+
}
|
|
181
|
+
// Must be called only from onExecutionComplete righ after removeRunning
|
|
182
|
+
// Check if there is any running computed nodes.
|
|
183
|
+
// In case of no running computed note, start the another iteration if ncessary (loop)
|
|
184
|
+
processLoopIfNecessary() {
|
|
185
|
+
this.repeatCount++;
|
|
186
|
+
const loop = this.loop;
|
|
187
|
+
if (loop && (loop.count === undefined || this.repeatCount < loop.count)) {
|
|
188
|
+
const results = this.results(true); // results from previous loop
|
|
189
|
+
this.nodes = this.createNodes(this.data);
|
|
190
|
+
this.initializeNodes(results);
|
|
191
|
+
// Notice that we need to check the while condition *after* calling initializeNodes.
|
|
192
|
+
if (loop.while) {
|
|
193
|
+
const value = this.getValueFromResults(loop.while, this.results(true));
|
|
194
|
+
// NOTE: We treat an empty array as false.
|
|
195
|
+
if (Array.isArray(value) ? value.length === 0 : !value) {
|
|
196
|
+
return false; // while condition is not met
|
|
222
197
|
}
|
|
223
198
|
}
|
|
224
|
-
this.
|
|
199
|
+
this.pushReadyNodesIntoQueue();
|
|
200
|
+
return true; // Indicating that we are going to continue.
|
|
225
201
|
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
setLoopLog(log) {
|
|
205
|
+
log.isLoop = !!this.loop;
|
|
206
|
+
log.repeatCount = this.repeatCount;
|
|
226
207
|
}
|
|
227
208
|
appendLog(log) {
|
|
228
209
|
this.logs.push(log);
|
|
210
|
+
this.onLogCallback(log, false);
|
|
229
211
|
}
|
|
212
|
+
updateLog(log) {
|
|
213
|
+
this.onLogCallback(log, true);
|
|
214
|
+
}
|
|
215
|
+
// Public API
|
|
230
216
|
transactionLogs() {
|
|
231
217
|
return this.logs;
|
|
232
218
|
}
|
|
233
|
-
|
|
219
|
+
// Public API
|
|
220
|
+
injectValue(nodeId, value, injectFrom) {
|
|
234
221
|
const node = this.nodes[nodeId];
|
|
235
222
|
if (node && node.isStaticNode) {
|
|
236
|
-
node.injectValue(value);
|
|
223
|
+
node.injectValue(value, injectFrom);
|
|
237
224
|
}
|
|
238
225
|
else {
|
|
239
|
-
console.error("-- Invalid nodeId", nodeId);
|
|
226
|
+
console.error("-- Inject Error: Invalid nodeId", nodeId);
|
|
227
|
+
console.error("InjectionTo can only specify static nodes");
|
|
240
228
|
}
|
|
241
229
|
}
|
|
242
|
-
resultsOf(sources) {
|
|
230
|
+
resultsOf(sources, anyInput = false) {
|
|
243
231
|
return sources.map((source) => {
|
|
244
|
-
const result = this.nodes[source.nodeId]
|
|
232
|
+
const { result } = this.nodes[source.nodeId];
|
|
233
|
+
if (source.propId) {
|
|
234
|
+
(0, utils_1.assert)((0, utils_1.isObject)(result), `resultsOf: result is not object. nodeId ${source.nodeId}`, anyInput);
|
|
235
|
+
}
|
|
245
236
|
return result && source.propId ? result[source.propId] : result;
|
|
246
237
|
});
|
|
247
238
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/node.d.ts
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { GraphAI, GraphData } from "./graphai";
|
|
2
|
+
import { NodeDataParams, ResultData, DataSource, ComputedNodeData, StaticNodeData, NodeState } from "./type";
|
|
3
|
+
import { TransactionLog } from "./transaction_log";
|
|
4
4
|
export declare class Node {
|
|
5
|
-
nodeId: string;
|
|
6
|
-
|
|
7
|
-
anyInput: boolean;
|
|
8
|
-
inputs: Array<string>;
|
|
9
|
-
pendings: Set<string>;
|
|
10
|
-
waitlist: Set<string>;
|
|
5
|
+
readonly nodeId: string;
|
|
6
|
+
readonly waitlist: Set<string>;
|
|
11
7
|
state: NodeState;
|
|
12
|
-
|
|
13
|
-
forkIndex?: number;
|
|
14
|
-
result: ResultData;
|
|
15
|
-
transactionId: undefined | number;
|
|
8
|
+
result: ResultData | undefined;
|
|
16
9
|
protected graph: GraphAI;
|
|
17
|
-
|
|
10
|
+
protected log: TransactionLog;
|
|
11
|
+
constructor(nodeId: string, graph: GraphAI);
|
|
18
12
|
asString(): string;
|
|
19
|
-
|
|
20
|
-
protected setResult(result: ResultData, state: NodeState): void;
|
|
13
|
+
protected onSetResult(): void;
|
|
21
14
|
}
|
|
22
15
|
export declare class ComputedNode extends Node {
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
readonly graphId: string;
|
|
17
|
+
readonly isResult: boolean;
|
|
18
|
+
readonly params: NodeDataParams;
|
|
19
|
+
readonly nestedGraph?: GraphData;
|
|
20
|
+
readonly retryLimit: number;
|
|
25
21
|
retryCount: number;
|
|
26
|
-
agentId?: string;
|
|
27
|
-
timeout?: number;
|
|
22
|
+
readonly agentId?: string;
|
|
23
|
+
readonly timeout?: number;
|
|
28
24
|
error?: Error;
|
|
25
|
+
transactionId: undefined | number;
|
|
26
|
+
readonly anyInput: boolean;
|
|
27
|
+
dataSources: Array<DataSource>;
|
|
28
|
+
pendings: Set<string>;
|
|
29
29
|
readonly isStaticNode = false;
|
|
30
30
|
readonly isComputedNode = true;
|
|
31
|
-
constructor(
|
|
32
|
-
|
|
31
|
+
constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
|
|
32
|
+
isReadyNode(): boolean;
|
|
33
33
|
private retry;
|
|
34
34
|
removePending(nodeId: string): void;
|
|
35
|
+
private isCurrentTransaction;
|
|
36
|
+
private executeTimeout;
|
|
35
37
|
execute(): Promise<void>;
|
|
38
|
+
private prepareExecute;
|
|
39
|
+
private errorProcess;
|
|
36
40
|
}
|
|
37
41
|
export declare class StaticNode extends Node {
|
|
38
42
|
value?: ResultData;
|
|
39
|
-
update?: string;
|
|
43
|
+
readonly update?: string;
|
|
44
|
+
readonly isResult: boolean;
|
|
40
45
|
readonly isStaticNode = true;
|
|
41
46
|
readonly isComputedNode = false;
|
|
42
|
-
constructor(nodeId: string,
|
|
43
|
-
injectValue(value: ResultData): void;
|
|
47
|
+
constructor(nodeId: string, data: StaticNodeData, graph: GraphAI);
|
|
48
|
+
injectValue(value: ResultData, injectFrom?: string): void;
|
|
44
49
|
}
|