graphai 2.0.14 → 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.d.ts +1 -1
- package/lib/graphai.js +26 -7
- package/lib/node.js +43 -14
- package/lib/task_manager.js +3 -2
- package/lib/transaction_log.js +18 -0
- package/lib/type.d.ts +2 -0
- package/lib/utils/GraphAILogger.d.ts +1 -2
- package/lib/utils/data_source.js +1 -1
- package/lib/utils/utils.d.ts +1 -1
- package/lib/utils/utils.js +4 -1
- package/package.json +3 -3
package/lib/graphai.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class GraphAI {
|
|
|
32
32
|
private setStaticNodeResults;
|
|
33
33
|
private updateStaticNodes;
|
|
34
34
|
constructor(graphData: GraphData, agentFunctionInfoDictionary: AgentFunctionInfoDictionary, options?: GraphOptions);
|
|
35
|
-
getAgentFunctionInfo(agentId?: string): import("./type").AgentFunctionInfo | {
|
|
35
|
+
getAgentFunctionInfo(agentId?: string, nodeId?: string): import("./type").AgentFunctionInfo | {
|
|
36
36
|
agent: () => Promise<null>;
|
|
37
37
|
hasGraphData: boolean;
|
|
38
38
|
inputs: null;
|
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
|
}
|
|
@@ -130,7 +146,7 @@ class GraphAI {
|
|
|
130
146
|
};
|
|
131
147
|
this.nodes = this.createNodes(this.graphData);
|
|
132
148
|
}
|
|
133
|
-
getAgentFunctionInfo(agentId) {
|
|
149
|
+
getAgentFunctionInfo(agentId, nodeId) {
|
|
134
150
|
if (agentId && this.agentFunctionInfoDictionary[agentId]) {
|
|
135
151
|
return this.agentFunctionInfoDictionary[agentId];
|
|
136
152
|
}
|
|
@@ -145,6 +161,9 @@ class GraphAI {
|
|
|
145
161
|
};
|
|
146
162
|
}
|
|
147
163
|
// We are not supposed to hit this error because the validator will catch it.
|
|
164
|
+
if (nodeId) {
|
|
165
|
+
throw new Error(`No agent: ${agentId} in ${nodeId} node`);
|
|
166
|
+
}
|
|
148
167
|
throw new Error("No agent: " + agentId);
|
|
149
168
|
}
|
|
150
169
|
asString() {
|
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 ?? {};
|
|
@@ -254,7 +280,7 @@ class ComputedNode extends Node {
|
|
|
254
280
|
if (typeof agentId === "function") {
|
|
255
281
|
this.agentFunction = agentId;
|
|
256
282
|
}
|
|
257
|
-
const hasNestedGraph = Boolean(this.nestedGraph) || Boolean(agentId && this.graph.getAgentFunctionInfo(agentId).hasGraphData);
|
|
283
|
+
const hasNestedGraph = Boolean(this.nestedGraph) || Boolean(typeof agentId === "string" && this.graph.getAgentFunctionInfo(agentId, this.nodeId).hasGraphData);
|
|
258
284
|
const config = this.getConfig(hasNestedGraph, agentId);
|
|
259
285
|
const transactionId = Date.now();
|
|
260
286
|
this.prepareExecute(transactionId, previousResults, agentId);
|
|
@@ -264,7 +290,7 @@ class ComputedNode extends Node {
|
|
|
264
290
|
}, this.timeout);
|
|
265
291
|
}
|
|
266
292
|
try {
|
|
267
|
-
const agentFunction = this.agentFunction ?? this.graph.getAgentFunctionInfo(agentId).agent;
|
|
293
|
+
const agentFunction = this.agentFunction ?? this.graph.getAgentFunctionInfo(agentId, this.nodeId).agent;
|
|
268
294
|
const localLog = [];
|
|
269
295
|
const context = this.getContext(previousResults, localLog, agentId, config);
|
|
270
296
|
// NOTE: We use the existence of graph object in the agent-specific params to determine
|
|
@@ -373,9 +399,9 @@ class ComputedNode extends Node {
|
|
|
373
399
|
//params: this.graph.resultsOf(this.params),
|
|
374
400
|
params,
|
|
375
401
|
namedInputs: previousResults,
|
|
376
|
-
inputSchema: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId)?.inputs,
|
|
402
|
+
inputSchema: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId, this.nodeId)?.inputs,
|
|
377
403
|
debugInfo: this.debugInfo,
|
|
378
|
-
cacheType: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId)?.cacheType,
|
|
404
|
+
cacheType: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(agentId, this.nodeId)?.cacheType,
|
|
379
405
|
filterParams: this.filterParams,
|
|
380
406
|
config,
|
|
381
407
|
log: localLog,
|
|
@@ -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;
|
package/lib/task_manager.js
CHANGED
|
@@ -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
|
package/lib/transaction_log.js
CHANGED
|
@@ -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
|
|
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;
|
package/lib/utils/data_source.js
CHANGED
|
@@ -39,7 +39,7 @@ const innerGetDataFromSource = (result, propIds, propFunctions) => {
|
|
|
39
39
|
const propId = propIds[0];
|
|
40
40
|
const ret = getNestedData(result, propId, propFunctions);
|
|
41
41
|
if (ret === undefined) {
|
|
42
|
-
GraphAILogger_1.GraphAILogger.
|
|
42
|
+
GraphAILogger_1.GraphAILogger.debug(`prop: ${propIds.join(".")} is not hit`);
|
|
43
43
|
}
|
|
44
44
|
if (propIds.length > 1) {
|
|
45
45
|
return innerGetDataFromSource(ret, propIds.slice(1), propFunctions);
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -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";
|
package/lib/utils/utils.js
CHANGED
|
@@ -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.
|
|
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.
|
|
31
|
-
"typedoc-plugin-markdown": "^4.
|
|
30
|
+
"typedoc": "^0.28.13",
|
|
31
|
+
"typedoc-plugin-markdown": "^4.9.0"
|
|
32
32
|
},
|
|
33
33
|
"types": "./lib/index.d.ts",
|
|
34
34
|
"directories": {
|