graphai 0.2.3 → 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.
- package/lib/experimental_agents/llm_agents/groq_agent.js +1 -5
- package/lib/graphai.js +1 -2
- package/lib/node.d.ts +2 -0
- package/lib/node.js +6 -0
- package/lib/task_manager.d.ts +8 -2
- package/lib/task_manager.js +13 -7
- package/lib/transaction_log.d.ts +1 -0
- package/lib/transaction_log.js +5 -0
- package/lib/type.d.ts +2 -2
- package/lib/type.js +0 -1
- package/lib/validators/common.js +1 -1
- package/package.json +1 -1
|
@@ -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/graphai.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphAI = void 0;
|
|
4
|
-
const type_1 = require("./type");
|
|
5
4
|
const node_1 = require("./node");
|
|
6
5
|
const utils_1 = require("./utils/utils");
|
|
7
6
|
const validator_1 = require("./validator");
|
|
@@ -144,7 +143,7 @@ class GraphAI {
|
|
|
144
143
|
}
|
|
145
144
|
// for computed
|
|
146
145
|
pushQueue(node) {
|
|
147
|
-
node.
|
|
146
|
+
node.beforeAddTask();
|
|
148
147
|
this.taskManager.addTask(node, this.graphId, (_node) => {
|
|
149
148
|
(0, utils_1.assert)(node.nodeId === _node.nodeId, "GraphAI.pushQueue node mismatch");
|
|
150
149
|
node.execute();
|
package/lib/node.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class ComputedNode extends Node {
|
|
|
21
21
|
retryCount: number;
|
|
22
22
|
readonly agentId?: string;
|
|
23
23
|
readonly timeout?: number;
|
|
24
|
+
readonly priority: number;
|
|
24
25
|
error?: Error;
|
|
25
26
|
transactionId: undefined | number;
|
|
26
27
|
readonly anyInput: boolean;
|
|
@@ -32,6 +33,7 @@ export declare class ComputedNode extends Node {
|
|
|
32
33
|
isReadyNode(): boolean;
|
|
33
34
|
private retry;
|
|
34
35
|
private checkDataAvailability;
|
|
36
|
+
beforeAddTask(): void;
|
|
35
37
|
removePending(nodeId: string): void;
|
|
36
38
|
private isCurrentTransaction;
|
|
37
39
|
private executeTimeout;
|
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));
|
|
@@ -87,6 +88,11 @@ class ComputedNode extends Node {
|
|
|
87
88
|
});
|
|
88
89
|
return results.length > 0;
|
|
89
90
|
}
|
|
91
|
+
// This method is called right before the Graph add this node to the task manager.
|
|
92
|
+
beforeAddTask() {
|
|
93
|
+
this.state = type_1.NodeState.Queued;
|
|
94
|
+
this.log.beforeAddTask(this, this.graph);
|
|
95
|
+
}
|
|
90
96
|
// This method is called when the data became available on one of nodes,
|
|
91
97
|
// which this node needs data from.
|
|
92
98
|
removePending(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/transaction_log.d.ts
CHANGED
|
@@ -23,5 +23,6 @@ export declare class TransactionLog {
|
|
|
23
23
|
onInjected(node: StaticNode, graph: GraphAI, injectFrom?: string): void;
|
|
24
24
|
onComplete(node: ComputedNode, graph: GraphAI, localLog: TransactionLog[]): void;
|
|
25
25
|
beforeExecute(node: ComputedNode, graph: GraphAI, transactionId: number, inputs: ResultData[]): void;
|
|
26
|
+
beforeAddTask(node: ComputedNode, graph: GraphAI): void;
|
|
26
27
|
onError(node: ComputedNode, graph: GraphAI, errorMessage: string): void;
|
|
27
28
|
}
|
package/lib/transaction_log.js
CHANGED
|
@@ -45,6 +45,11 @@ class TransactionLog {
|
|
|
45
45
|
graph.setLoopLog(this);
|
|
46
46
|
graph.appendLog(this);
|
|
47
47
|
}
|
|
48
|
+
beforeAddTask(node, graph) {
|
|
49
|
+
this.state = node.state;
|
|
50
|
+
graph.setLoopLog(this);
|
|
51
|
+
graph.appendLog(this);
|
|
52
|
+
}
|
|
48
53
|
onError(node, graph, errorMessage) {
|
|
49
54
|
this.state = node.state;
|
|
50
55
|
this.errorMessage = errorMessage;
|
package/lib/type.d.ts
CHANGED
|
@@ -7,8 +7,7 @@ export declare enum NodeState {
|
|
|
7
7
|
Failed = "failed",
|
|
8
8
|
TimedOut = "timed-out",
|
|
9
9
|
Completed = "completed",
|
|
10
|
-
Injected = "injected"
|
|
11
|
-
Dispatched = "dispatched"
|
|
10
|
+
Injected = "injected"
|
|
12
11
|
}
|
|
13
12
|
export type DefaultResultData = Record<string, any> | string | number | Array<DefaultResultData>;
|
|
14
13
|
export type DefaultInputData = Record<string, any>;
|
|
@@ -35,6 +34,7 @@ export type ComputedNodeData = {
|
|
|
35
34
|
timeout?: number;
|
|
36
35
|
graph?: GraphData;
|
|
37
36
|
isResult?: boolean;
|
|
37
|
+
priority?: number;
|
|
38
38
|
};
|
|
39
39
|
export type NodeData = StaticNodeData | ComputedNodeData;
|
|
40
40
|
export type LoopData = {
|
package/lib/type.js
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"];
|