graphai 0.5.11 → 0.5.12

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/graphai.js CHANGED
@@ -45,7 +45,7 @@ class GraphAI {
45
45
  return (0, utils_1.getDataFromSource)(source.nodeId ? results[source.nodeId] : undefined, source);
46
46
  }
47
47
  // for static
48
- initializeStaticNodes() {
48
+ initializeStaticNodes(enableConsoleLog = false) {
49
49
  // If the result property is specified, inject it.
50
50
  // If the previousResults exists (indicating we are in a loop),
51
51
  // process the update property (nodeId or nodeId.propId).
@@ -56,10 +56,13 @@ class GraphAI {
56
56
  if (value !== undefined) {
57
57
  this.injectValue(nodeId, value, nodeId);
58
58
  }
59
+ if (enableConsoleLog) {
60
+ node.consoleLog();
61
+ }
59
62
  }
60
63
  });
61
64
  }
62
- updateStaticNodes(previousResults) {
65
+ updateStaticNodes(previousResults, enableConsoleLog = false) {
63
66
  // If the result property is specified, inject it.
64
67
  // If the previousResults exists (indicating we are in a loop),
65
68
  // process the update property (nodeId or nodeId.propId).
@@ -71,6 +74,9 @@ class GraphAI {
71
74
  const result = this.getValueFromResults(update, previousResults);
72
75
  this.injectValue(nodeId, result, update.nodeId);
73
76
  }
77
+ if (enableConsoleLog) {
78
+ node.consoleLog();
79
+ }
74
80
  }
75
81
  });
76
82
  }
@@ -106,7 +112,7 @@ class GraphAI {
106
112
  };
107
113
  (0, validator_1.validateGraphData)(data, [...Object.keys(agentFunctionInfoDictionary), ...this.bypassAgentIds]);
108
114
  this.nodes = this.createNodes(data);
109
- this.initializeStaticNodes();
115
+ this.initializeStaticNodes(true);
110
116
  }
111
117
  getAgentFunctionInfo(agentId) {
112
118
  if (agentId && this.agentFunctionInfoDictionary[agentId]) {
@@ -237,7 +243,7 @@ class GraphAI {
237
243
  }
238
244
  this.nodes = this.createNodes(this.data);
239
245
  this.initializeStaticNodes();
240
- this.updateStaticNodes(previousResults);
246
+ this.updateStaticNodes(previousResults, true);
241
247
  this.pushReadyNodesIntoQueue();
242
248
  return true; // Indicating that we are going to continue.
243
249
  }
package/lib/node.d.ts CHANGED
@@ -8,9 +8,11 @@ export declare class Node {
8
8
  result: ResultData | undefined;
9
9
  protected graph: GraphAI;
10
10
  protected log: TransactionLog;
11
+ protected console: Record<string, string | boolean>;
11
12
  constructor(nodeId: string, graph: GraphAI);
12
13
  asString(): string;
13
14
  protected onSetResult(): void;
15
+ protected afterConsoleLog(result: ResultData): void;
14
16
  }
15
17
  export declare class ComputedNode extends Node {
16
18
  readonly graphId: string;
@@ -35,7 +37,6 @@ export declare class ComputedNode extends Node {
35
37
  pendings: Set<string>;
36
38
  private ifSource?;
37
39
  private unlessSource?;
38
- private console;
39
40
  readonly isStaticNode = false;
40
41
  readonly isComputedNode = true;
41
42
  constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
@@ -59,7 +60,6 @@ export declare class ComputedNode extends Node {
59
60
  private getResult;
60
61
  private getDebugInfo;
61
62
  private beforeConsoleLog;
62
- private afterConsoleLog;
63
63
  }
64
64
  export declare class StaticNode extends Node {
65
65
  value?: ResultData;
@@ -69,5 +69,6 @@ export declare class StaticNode extends Node {
69
69
  readonly isComputedNode = false;
70
70
  constructor(nodeId: string, data: StaticNodeData, graph: GraphAI);
71
71
  injectValue(value: ResultData, injectFrom?: string): void;
72
+ consoleLog(): void;
72
73
  }
73
74
  export type GraphNodes = Record<string, ComputedNode | StaticNode>;
package/lib/node.js CHANGED
@@ -14,6 +14,7 @@ class Node {
14
14
  this.nodeId = nodeId;
15
15
  this.graph = graph;
16
16
  this.log = new transaction_log_1.TransactionLog(nodeId);
17
+ this.console = {};
17
18
  }
18
19
  asString() {
19
20
  return `${this.nodeId}: ${this.state} ${[...this.waitlist]}`;
@@ -29,6 +30,14 @@ class Node {
29
30
  }
30
31
  });
31
32
  }
33
+ afterConsoleLog(result) {
34
+ if (this.console.after === true) {
35
+ console.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
36
+ }
37
+ else if (this.console.after) {
38
+ console.log(this.console.after);
39
+ }
40
+ }
32
41
  }
33
42
  exports.Node = Node;
34
43
  class ComputedNode extends Node {
@@ -324,14 +333,6 @@ class ComputedNode extends Node {
324
333
  console.log(this.console.before);
325
334
  }
326
335
  }
327
- afterConsoleLog(result) {
328
- if (this.console.after === true) {
329
- console.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
330
- }
331
- else if (this.console.after) {
332
- console.log(this.console.after);
333
- }
334
- }
335
336
  }
336
337
  exports.ComputedNode = ComputedNode;
337
338
  class StaticNode extends Node {
@@ -342,6 +343,7 @@ class StaticNode extends Node {
342
343
  this.value = data.value;
343
344
  this.update = data.update ? (0, utils_2.parseNodeName)(data.update) : undefined;
344
345
  this.isResult = data.isResult ?? false;
346
+ this.console = data.console ?? {};
345
347
  }
346
348
  injectValue(value, injectFrom) {
347
349
  this.state = type_1.NodeState.Injected;
@@ -349,5 +351,8 @@ class StaticNode extends Node {
349
351
  this.log.onInjected(this, this.graph, injectFrom);
350
352
  this.onSetResult();
351
353
  }
354
+ consoleLog() {
355
+ this.afterConsoleLog(this.result);
356
+ }
352
357
  }
353
358
  exports.StaticNode = StaticNode;
package/lib/type.d.ts CHANGED
@@ -27,6 +27,7 @@ export type StaticNodeData = {
27
27
  value: ResultData;
28
28
  update?: string;
29
29
  isResult?: boolean;
30
+ console?: Record<string, string | boolean>;
30
31
  };
31
32
  export type AgentAnonymousFunction = (...params: any[]) => unknown;
32
33
  export type AgentFilterParams = Record<string, any>;
@@ -18,7 +18,7 @@ exports.computedNodeAttributeKeys = [
18
18
  "console",
19
19
  "passThrough",
20
20
  ];
21
- exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
21
+ exports.staticNodeAttributeKeys = ["value", "update", "isResult", "console"];
22
22
  class ValidationError extends Error {
23
23
  constructor(message) {
24
24
  super(`\x1b[41m${message}\x1b[0m`); // Pass the message to the base Error class
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [