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
@@ -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;
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));
@@ -11,8 +11,14 @@ export declare class TaskManager {
11
11
  prepareForNesting(): void;
12
12
  restoreAfterNesting(): void;
13
13
  getStatus(verbose?: boolean): {
14
- runningNodes?: string[] | undefined;
15
- queuedNodes?: string[] | undefined;
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;
@@ -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
- this.taskQueue.push({ node, graphId, callback });
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
- ...(verbose
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
@@ -34,6 +34,7 @@ export type ComputedNodeData = {
34
34
  timeout?: number;
35
35
  graph?: GraphData;
36
36
  isResult?: boolean;
37
+ priority?: number;
37
38
  };
38
39
  export type NodeData = StaticNodeData | ComputedNodeData;
39
40
  export type LoopData = {
@@ -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"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [