graphai 0.5.11 → 0.5.13

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 {
@@ -209,6 +218,7 @@ class ComputedNode extends Node {
209
218
  if (this.nestedGraph) {
210
219
  this.graph.taskManager.prepareForNesting();
211
220
  context.taskManager = this.graph.taskManager;
221
+ context.onLogCallback = this.graph.onLogCallback;
212
222
  if ("nodes" in this.nestedGraph) {
213
223
  context.graphData = this.nestedGraph;
214
224
  }
@@ -324,14 +334,6 @@ class ComputedNode extends Node {
324
334
  console.log(this.console.before);
325
335
  }
326
336
  }
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
337
  }
336
338
  exports.ComputedNode = ComputedNode;
337
339
  class StaticNode extends Node {
@@ -342,6 +344,7 @@ class StaticNode extends Node {
342
344
  this.value = data.value;
343
345
  this.update = data.update ? (0, utils_2.parseNodeName)(data.update) : undefined;
344
346
  this.isResult = data.isResult ?? false;
347
+ this.console = data.console ?? {};
345
348
  }
346
349
  injectValue(value, injectFrom) {
347
350
  this.state = type_1.NodeState.Injected;
@@ -349,5 +352,8 @@ class StaticNode extends Node {
349
352
  this.log.onInjected(this, this.graph, injectFrom);
350
353
  this.onSetResult();
351
354
  }
355
+ consoleLog() {
356
+ this.afterConsoleLog(this.result);
357
+ }
352
358
  }
353
359
  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>;
@@ -82,6 +83,7 @@ export type AgentFunctionContext<ParamsType = DefaultParamsType, InputDataType =
82
83
  graphData?: GraphData;
83
84
  agents?: AgentFunctionInfoDictionary;
84
85
  taskManager?: TaskManager;
86
+ onLogCallback?: (log: TransactionLog, isUpdate: boolean) => void;
85
87
  filterParams: AgentFilterParams;
86
88
  agentFilters?: AgentFilterInfo[];
87
89
  log?: TransactionLog[];
@@ -92,15 +92,20 @@ const getNestedData = (result, propId) => {
92
92
  }
93
93
  }
94
94
  }
95
- else if (Number.isFinite(result)) {
95
+ else if (result !== undefined && Number.isFinite(result)) {
96
96
  if (propId === "toString()") {
97
97
  return String(result);
98
98
  }
99
+ const regex = /^add\((-?\d+)\)$/;
100
+ const match = propId.match(regex);
101
+ if (match) {
102
+ return Number(result) + Number(match[1]);
103
+ }
99
104
  }
100
105
  return undefined;
101
106
  };
102
107
  const innerGetDataFromSource = (result, propIds) => {
103
- if (result && propIds && propIds.length > 0) {
108
+ if (!(0, exports.isNull)(result) && propIds && propIds.length > 0) {
104
109
  const propId = propIds[0];
105
110
  const ret = getNestedData(result, propId);
106
111
  if (ret === undefined) {
@@ -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.13",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [