graphai 0.2.4 → 0.2.5
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.
|
@@ -3,11 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.gloqAgent = void 0;
|
|
4
4
|
const groq_sdk_1 = require("groq-sdk");
|
|
5
5
|
const utils_1 = require("../../utils/utils");
|
|
6
|
-
const groq = process.env.GROQ_API_KEY
|
|
7
|
-
? new groq_sdk_1.Groq({
|
|
8
|
-
apiKey: process.env.GROQ_API_KEY,
|
|
9
|
-
})
|
|
10
|
-
: undefined;
|
|
6
|
+
const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined;
|
|
11
7
|
const gloqAgent = async ({ params, inputs }) => {
|
|
12
8
|
(0, utils_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing.");
|
|
13
9
|
const query = params?.query ? [params.query] : [];
|
package/lib/node.d.ts
CHANGED
package/lib/node.js
CHANGED
|
@@ -43,6 +43,7 @@ class ComputedNode extends Node {
|
|
|
43
43
|
this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
|
|
44
44
|
this.timeout = data.timeout;
|
|
45
45
|
this.isResult = data.isResult ?? false;
|
|
46
|
+
this.priority = data.priority ?? 0;
|
|
46
47
|
this.anyInput = data.anyInput ?? false;
|
|
47
48
|
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input));
|
|
48
49
|
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
package/lib/task_manager.d.ts
CHANGED
|
@@ -11,8 +11,14 @@ export declare class TaskManager {
|
|
|
11
11
|
prepareForNesting(): void;
|
|
12
12
|
restoreAfterNesting(): void;
|
|
13
13
|
getStatus(verbose?: boolean): {
|
|
14
|
-
runningNodes
|
|
15
|
-
queuedNodes
|
|
14
|
+
runningNodes: string[];
|
|
15
|
+
queuedNodes: string[];
|
|
16
|
+
concurrency: number;
|
|
17
|
+
queue: number;
|
|
18
|
+
running: number;
|
|
19
|
+
} | {
|
|
20
|
+
runningNodes?: undefined;
|
|
21
|
+
queuedNodes?: undefined;
|
|
16
22
|
concurrency: number;
|
|
17
23
|
queue: number;
|
|
18
24
|
running: number;
|
package/lib/task_manager.js
CHANGED
|
@@ -27,7 +27,12 @@ class TaskManager {
|
|
|
27
27
|
// Node will call this method to put itself in the execution queue.
|
|
28
28
|
// We call the associated callback function when it is dequeued.
|
|
29
29
|
addTask(node, graphId, callback) {
|
|
30
|
-
|
|
30
|
+
// Finder tasks in the queue, which has either the same or higher priority.
|
|
31
|
+
const count = this.taskQueue.filter((task) => {
|
|
32
|
+
return task.node.priority >= node.priority;
|
|
33
|
+
}).length;
|
|
34
|
+
(0, utils_1.assert)(count <= this.taskQueue.length, "TaskManager.addTask: Something is really wrong.");
|
|
35
|
+
this.taskQueue.splice(count, 0, { node, graphId, callback });
|
|
31
36
|
this.dequeueTaskIfPossible();
|
|
32
37
|
}
|
|
33
38
|
isRunning(graphId) {
|
|
@@ -53,16 +58,17 @@ class TaskManager {
|
|
|
53
58
|
this.concurrency--;
|
|
54
59
|
}
|
|
55
60
|
getStatus(verbose = false) {
|
|
61
|
+
const nodes = verbose
|
|
62
|
+
? {
|
|
63
|
+
runningNodes: Array.from(this.runningNodes).map((node) => node.nodeId),
|
|
64
|
+
queuedNodes: this.taskQueue.map((task) => task.node.nodeId),
|
|
65
|
+
}
|
|
66
|
+
: {};
|
|
56
67
|
return {
|
|
57
68
|
concurrency: this.concurrency,
|
|
58
69
|
queue: this.taskQueue.length,
|
|
59
70
|
running: this.runningNodes.size,
|
|
60
|
-
...
|
|
61
|
-
? {
|
|
62
|
-
runningNodes: Array.from(this.runningNodes).map((node) => node.nodeId),
|
|
63
|
-
queuedNodes: this.taskQueue.map((task) => task.node.nodeId),
|
|
64
|
-
}
|
|
65
|
-
: {}),
|
|
71
|
+
...nodes,
|
|
66
72
|
};
|
|
67
73
|
}
|
|
68
74
|
}
|
package/lib/type.d.ts
CHANGED
package/lib/validators/common.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
4
|
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"];
|
|
5
|
-
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agentId", "graph", "isResult"];
|
|
5
|
+
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agentId", "graph", "isResult", "priority"];
|
|
6
6
|
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|