graphai 2.0.15 → 2.0.16

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
@@ -12,6 +12,28 @@ const GraphAILogger_1 = require("./utils/GraphAILogger");
12
12
  exports.defaultConcurrency = 8;
13
13
  exports.graphDataLatestVersion = 0.5;
14
14
  class GraphAI {
15
+ version;
16
+ graphId;
17
+ graphData;
18
+ staticNodeInitData = {};
19
+ loop;
20
+ forceLoop;
21
+ logs = [];
22
+ mapIndex;
23
+ bypassAgentIds;
24
+ config = {};
25
+ agentFunctionInfoDictionary;
26
+ taskManager;
27
+ agentFilters;
28
+ retryLimit;
29
+ propFunctions;
30
+ graphLoader;
31
+ nodes;
32
+ onLogCallback = (__log, __isUpdate) => { };
33
+ callbacks = [];
34
+ verbose; // REVIEW: Do we need this?
35
+ onComplete;
36
+ repeatCount = 0;
15
37
  // This method is called when either the GraphAI obect was created,
16
38
  // or we are about to start n-th iteration (n>2).
17
39
  createNodes(graphData) {
@@ -90,12 +112,6 @@ class GraphAI {
90
112
  forceLoop: false,
91
113
  mapIndex: undefined,
92
114
  }) {
93
- this.staticNodeInitData = {};
94
- this.logs = [];
95
- this.config = {};
96
- this.onLogCallback = (__log, __isUpdate) => { };
97
- this.callbacks = [];
98
- this.repeatCount = 0;
99
115
  if (!graphData.version && !options.taskManager) {
100
116
  GraphAILogger_1.GraphAILogger.warn("------------ missing version number");
101
117
  }
package/lib/node.js CHANGED
@@ -9,10 +9,14 @@ const transaction_log_1 = require("./transaction_log");
9
9
  const result_1 = require("./utils/result");
10
10
  const GraphAILogger_1 = require("./utils/GraphAILogger");
11
11
  class Node {
12
+ nodeId;
13
+ waitlist = new Set(); // List of nodes which need data from this node.
14
+ state = type_1.NodeState.Waiting;
15
+ result = undefined;
16
+ graph;
17
+ log;
18
+ console; // console output option (before and/or after)
12
19
  constructor(nodeId, graph) {
13
- this.waitlist = new Set(); // List of nodes which need data from this node.
14
- this.state = type_1.NodeState.Waiting;
15
- this.result = undefined;
16
20
  this.nodeId = nodeId;
17
21
  this.graph = graph;
18
22
  this.log = new transaction_log_1.TransactionLog(nodeId, this.graph.mapIndex);
@@ -51,13 +55,35 @@ class Node {
51
55
  }
52
56
  exports.Node = Node;
53
57
  class ComputedNode extends Node {
58
+ graphId;
59
+ isResult;
60
+ params; // Agent-specific parameters
61
+ filterParams;
62
+ nestedGraph;
63
+ retryLimit;
64
+ retryCount = 0;
65
+ repeatUntil;
66
+ agentId;
67
+ agentFunction;
68
+ timeout; // msec
69
+ priority;
70
+ error;
71
+ transactionId; // To reject callbacks from timed-out transactions
72
+ passThrough;
73
+ anyInput; // any input makes this node ready
74
+ dataSources = []; // no longer needed. This is for transaction log.
75
+ inputs;
76
+ output;
77
+ pendings; // List of nodes this node is waiting data from.
78
+ ifSource; // conditional execution
79
+ unlessSource; // conditional execution
80
+ defaultValue;
81
+ isSkip = false;
82
+ debugInfo;
83
+ isStaticNode = false;
84
+ isComputedNode = true;
54
85
  constructor(graphId, nodeId, data, graph) {
55
86
  super(nodeId, graph);
56
- this.retryCount = 0;
57
- this.dataSources = []; // no longer needed. This is for transaction log.
58
- this.isSkip = false;
59
- this.isStaticNode = false;
60
- this.isComputedNode = true;
61
87
  this.graphId = graphId;
62
88
  this.params = data.params ?? {};
63
89
  this.console = data.console ?? {};
@@ -419,10 +445,13 @@ class ComputedNode extends Node {
419
445
  }
420
446
  exports.ComputedNode = ComputedNode;
421
447
  class StaticNode extends Node {
448
+ value;
449
+ update;
450
+ isResult;
451
+ isStaticNode = true;
452
+ isComputedNode = false;
422
453
  constructor(nodeId, data, graph) {
423
454
  super(nodeId, graph);
424
- this.isStaticNode = true;
425
- this.isComputedNode = false;
426
455
  this.value = data.value;
427
456
  this.update = data.update ? (0, utils_2.parseNodeName)(data.update) : undefined;
428
457
  this.isResult = data.isResult ?? false;
@@ -7,9 +7,10 @@ const utils_1 = require("./utils/utils");
7
7
  // NOTE: A TaskManager instance will be shared between parent graph and its children
8
8
  // when nested agents are involved.
9
9
  class TaskManager {
10
+ concurrency;
11
+ taskQueue = [];
12
+ runningNodes = new Set();
10
13
  constructor(concurrency) {
11
- this.taskQueue = [];
12
- this.runningNodes = new Set();
13
14
  this.concurrency = concurrency;
14
15
  }
15
16
  // This internal method dequeus a task from the task queue
@@ -5,6 +5,24 @@ const type_1 = require("./type");
5
5
  const utils_1 = require("./utils/utils");
6
6
  const nodeUtils_1 = require("./utils/nodeUtils");
7
7
  class TransactionLog {
8
+ nodeId;
9
+ state;
10
+ startTime;
11
+ endTime;
12
+ retryCount;
13
+ agentId;
14
+ params;
15
+ inputs;
16
+ inputsData;
17
+ namedInputs;
18
+ injectFrom;
19
+ errorMessage;
20
+ result;
21
+ resultKeys;
22
+ mapIndex;
23
+ isLoop;
24
+ repeatCount;
25
+ log;
8
26
  constructor(nodeId, mapIndex) {
9
27
  this.nodeId = nodeId;
10
28
  this.state = type_1.NodeState.Waiting;
package/lib/type.d.ts CHANGED
@@ -164,4 +164,6 @@ export type AgentFunctionInfo = {
164
164
  export type AgentFunctionInfoDictionary = Record<string, AgentFunctionInfo>;
165
165
  export type PropFunction = (result: ResultData, propId: string) => ResultData;
166
166
  export type CallbackFunction = (log: TransactionLog, isUpdate: boolean) => void;
167
+ export type LogLevel = "debug" | "info" | "log" | "warn" | "error";
168
+ export type LoggerFunction = (level: LogLevel, ...args: any[]) => void;
167
169
  export {};
@@ -1,5 +1,4 @@
1
- type LogLevel = "debug" | "info" | "log" | "warn" | "error";
2
- type LoggerFunction = (level: LogLevel, ...args: any[]) => void;
1
+ import { type LogLevel, type LoggerFunction } from "../type";
3
2
  declare function setLevelEnabled(level: LogLevel, enabled: boolean): void;
4
3
  declare function setLogger(logger: LoggerFunction): void;
5
4
  declare function debug(...args: any[]): void;
@@ -2,7 +2,7 @@ import { DataSource, AgentFunction, AgentFunctionInfo, NodeData, StaticNodeData,
2
2
  import type { GraphNodes } from "../node";
3
3
  export declare const sleep: (milliseconds: number) => Promise<unknown>;
4
4
  export declare const parseNodeName: (inputNodeId: any, isSelfNode?: boolean, nodes?: GraphNodes) => DataSource;
5
- export declare function assert(condition: boolean, message: string, isWarn?: boolean): asserts condition;
5
+ export declare function assert(condition: boolean, message: string, isWarn?: boolean, cause?: unknown): asserts condition;
6
6
  export declare const isObject: <Values = unknown>(x: unknown) => x is Record<string, Values>;
7
7
  export declare const isNull: (data: unknown) => data is null | undefined;
8
8
  export declare const strIntentionalError = "Intentional Error for Debugging";
@@ -37,9 +37,12 @@ const parseNodeName = (inputNodeId, isSelfNode = false, nodes) => {
37
37
  return { value: inputNodeId }; // non-string literal
38
38
  };
39
39
  exports.parseNodeName = parseNodeName;
40
- function assert(condition, message, isWarn = false) {
40
+ function assert(condition, message, isWarn = false, cause) {
41
41
  if (!condition) {
42
42
  if (!isWarn) {
43
+ if (cause) {
44
+ throw new Error(message, { cause });
45
+ }
43
46
  throw new Error(message);
44
47
  }
45
48
  GraphAILogger_1.GraphAILogger.warn("warn: " + message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "homepage": "https://github.com/receptron/graphai#readme",
29
29
  "devDependencies": {
30
- "typedoc": "^0.28.12",
31
- "typedoc-plugin-markdown": "^4.8.1"
30
+ "typedoc": "^0.28.13",
31
+ "typedoc-plugin-markdown": "^4.9.0"
32
32
  },
33
33
  "types": "./lib/index.d.ts",
34
34
  "directories": {