graphai 0.4.7 → 0.5.0
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/README.md +1 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/lib/node.d.ts +1 -0
- package/lib/node.js +36 -10
- package/lib/type.d.ts +4 -1
- package/lib/validators/relation_validator.js +27 -10
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -379,10 +379,4 @@ Since the task executing the nested graph will be in "running" state while tasks
|
|
|
379
379
|
|
|
380
380
|
By default, tasks are executed in a first-in, first-out (FIFO) order with a neutral priority (0). However, you can assign custom priorities to nodes using the *priority* property. Tasks associated with nodes that have a higher priority value will be executed before those with lower priorities.
|
|
381
381
|
|
|
382
|
-
Negative priority values are allowed, enabling you to fine-tune the execution order based on your application's requirements.
|
|
383
|
-
|
|
384
|
-
## References
|
|
385
|
-
|
|
386
|
-
- [Collaboration](./Collaboration.md)
|
|
387
|
-
- [Sample Graphs](./samples/README.md)
|
|
388
|
-
- [API Document](./APIDocument.md)
|
|
382
|
+
Negative priority values are allowed, enabling you to fine-tune the execution order based on your application's requirements.
|
package/lib/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { GraphAI } from "./graphai";
|
|
|
2
2
|
export { AgentFunction, AgentFunctionInfo, AgentFunctionInfoDictionary, AgentFunctionContext, GraphData, ResultDataDictionary, ResultData, NodeState, AgentFilterFunction, AgentFilterInfo, NodeData, StaticNodeData, ComputedNodeData, DefaultResultData, DefaultInputData, } from "./type";
|
|
3
3
|
export type { TransactionLog } from "./transaction_log";
|
|
4
4
|
export { agentFilterRunnerBuilder } from "./utils/runner";
|
|
5
|
-
export { defaultAgentInfo, agentInfoWrapper, defaultTestContext, strIntentionalError } from "./utils/utils";
|
|
5
|
+
export { defaultAgentInfo, agentInfoWrapper, defaultTestContext, strIntentionalError, assert, sleep } from "./utils/utils";
|
|
6
6
|
export { ValidationError } from "./validators/common";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.strIntentionalError = exports.defaultTestContext = exports.agentInfoWrapper = exports.defaultAgentInfo = exports.agentFilterRunnerBuilder = exports.NodeState = exports.GraphAI = void 0;
|
|
3
|
+
exports.ValidationError = exports.sleep = exports.assert = exports.strIntentionalError = exports.defaultTestContext = exports.agentInfoWrapper = exports.defaultAgentInfo = exports.agentFilterRunnerBuilder = exports.NodeState = exports.GraphAI = void 0;
|
|
4
4
|
var graphai_1 = require("./graphai");
|
|
5
5
|
Object.defineProperty(exports, "GraphAI", { enumerable: true, get: function () { return graphai_1.GraphAI; } });
|
|
6
6
|
var type_1 = require("./type");
|
|
@@ -12,5 +12,7 @@ Object.defineProperty(exports, "defaultAgentInfo", { enumerable: true, get: func
|
|
|
12
12
|
Object.defineProperty(exports, "agentInfoWrapper", { enumerable: true, get: function () { return utils_1.agentInfoWrapper; } });
|
|
13
13
|
Object.defineProperty(exports, "defaultTestContext", { enumerable: true, get: function () { return utils_1.defaultTestContext; } });
|
|
14
14
|
Object.defineProperty(exports, "strIntentionalError", { enumerable: true, get: function () { return utils_1.strIntentionalError; } });
|
|
15
|
+
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return utils_1.assert; } });
|
|
16
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
|
|
15
17
|
var common_1 = require("./validators/common");
|
|
16
18
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return common_1.ValidationError; } });
|
package/lib/node.d.ts
CHANGED
package/lib/node.js
CHANGED
|
@@ -40,23 +40,41 @@ class ComputedNode extends Node {
|
|
|
40
40
|
this.params = data.params ?? {};
|
|
41
41
|
this.console = data.console ?? {};
|
|
42
42
|
this.filterParams = data.filterParams ?? {};
|
|
43
|
+
this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
|
|
44
|
+
this.timeout = data.timeout;
|
|
45
|
+
this.isResult = data.isResult ?? false;
|
|
46
|
+
this.priority = data.priority ?? 0;
|
|
47
|
+
this.anyInput = data.anyInput ?? false;
|
|
48
|
+
if (!data.inputs) {
|
|
49
|
+
this.dataSources = [];
|
|
50
|
+
}
|
|
51
|
+
else if (Array.isArray(data.inputs)) {
|
|
52
|
+
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input, graph.version));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const inputs = data.inputs;
|
|
56
|
+
const keys = Object.keys(inputs);
|
|
57
|
+
this.inputNames = keys;
|
|
58
|
+
this.dataSources = keys.map((key) => (0, utils_2.parseNodeName)(inputs[key], graph.version));
|
|
59
|
+
}
|
|
60
|
+
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
|
43
61
|
if (typeof data.agent === "string") {
|
|
44
62
|
this.agentId = data.agent;
|
|
45
63
|
}
|
|
46
64
|
else {
|
|
47
65
|
(0, utils_2.assert)(typeof data.agent === "function", "agent must be either string or function");
|
|
48
66
|
const agent = data.agent;
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
if (this.inputNames) {
|
|
68
|
+
this.agentFunction = async ({ namedInputs }) => {
|
|
69
|
+
return agent(namedInputs);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.agentFunction = async ({ inputs }) => {
|
|
74
|
+
return agent(...inputs);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
52
77
|
}
|
|
53
|
-
this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
|
|
54
|
-
this.timeout = data.timeout;
|
|
55
|
-
this.isResult = data.isResult ?? false;
|
|
56
|
-
this.priority = data.priority ?? 0;
|
|
57
|
-
this.anyInput = data.anyInput ?? false;
|
|
58
|
-
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input, graph.version));
|
|
59
|
-
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
|
60
78
|
if (typeof data.graph === "string") {
|
|
61
79
|
const source = (0, utils_2.parseNodeName)(data.graph, graph.version);
|
|
62
80
|
(0, utils_2.assert)(!!source.nodeId, `Invalid data source ${data.graph}`);
|
|
@@ -232,6 +250,7 @@ class ComputedNode extends Node {
|
|
|
232
250
|
const context = {
|
|
233
251
|
params: params,
|
|
234
252
|
inputs: previousResults,
|
|
253
|
+
namedInputs: {},
|
|
235
254
|
debugInfo: {
|
|
236
255
|
nodeId: this.nodeId,
|
|
237
256
|
agentId: this.agentId,
|
|
@@ -242,6 +261,13 @@ class ComputedNode extends Node {
|
|
|
242
261
|
agentFilters: this.graph.agentFilters,
|
|
243
262
|
log: localLog,
|
|
244
263
|
};
|
|
264
|
+
if (this.inputNames) {
|
|
265
|
+
context.namedInputs = this.inputNames.reduce((tmp, name, index) => {
|
|
266
|
+
tmp[name] = previousResults[index];
|
|
267
|
+
return tmp;
|
|
268
|
+
}, {});
|
|
269
|
+
context.inputs = [];
|
|
270
|
+
}
|
|
245
271
|
// NOTE: We use the existence of graph object in the agent-specific params to determine
|
|
246
272
|
// if this is a nested agent or not.
|
|
247
273
|
if (this.nestedGraph) {
|
package/lib/type.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type AgentAnonymousFunction = (...params: any[]) => unknown;
|
|
|
30
30
|
export type AgentFilterParams = Record<string, any>;
|
|
31
31
|
export type ComputedNodeData = {
|
|
32
32
|
agent: string | AgentAnonymousFunction;
|
|
33
|
-
inputs?: Array<any>;
|
|
33
|
+
inputs?: Array<any> | Record<string, any>;
|
|
34
34
|
anyInput?: boolean;
|
|
35
35
|
params?: NodeDataParams;
|
|
36
36
|
filterParams?: AgentFilterParams;
|
|
@@ -64,6 +64,7 @@ export type GraphOptions = {
|
|
|
64
64
|
export type AgentFunctionContext<ParamsType = DefaultParamsType, InputDataType = DefaultInputData> = {
|
|
65
65
|
params: NodeDataParams<ParamsType>;
|
|
66
66
|
inputs: Array<InputDataType>;
|
|
67
|
+
namedInputs: Record<string, any>;
|
|
67
68
|
debugInfo: {
|
|
68
69
|
verbose: boolean;
|
|
69
70
|
nodeId: string;
|
|
@@ -90,6 +91,8 @@ export type AgentFunctionInfo = {
|
|
|
90
91
|
name: string;
|
|
91
92
|
agent: AgentFunction<any, any, any>;
|
|
92
93
|
mock: AgentFunction<any, any, any>;
|
|
94
|
+
inputs?: any;
|
|
95
|
+
output?: any;
|
|
93
96
|
samples: {
|
|
94
97
|
inputs: any;
|
|
95
98
|
params: DefaultParamsType;
|
|
@@ -12,17 +12,34 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
|
|
|
12
12
|
const nodeData = data.nodes[computedNodeId];
|
|
13
13
|
pendings[computedNodeId] = new Set();
|
|
14
14
|
if ("inputs" in nodeData && nodeData && nodeData.inputs) {
|
|
15
|
-
nodeData.inputs
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
15
|
+
if (Array.isArray(nodeData.inputs)) {
|
|
16
|
+
nodeData.inputs.forEach((inputNodeId) => {
|
|
17
|
+
const sourceNodeId = (0, utils_1.parseNodeName)(inputNodeId, data.version ?? 0.02).nodeId;
|
|
18
|
+
if (sourceNodeId) {
|
|
19
|
+
if (!nodeIds.has(sourceNodeId)) {
|
|
20
|
+
throw new common_1.ValidationError(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${sourceNodeId}`);
|
|
21
|
+
}
|
|
22
|
+
waitlist[sourceNodeId] === undefined && (waitlist[sourceNodeId] = new Set());
|
|
23
|
+
pendings[computedNodeId].add(sourceNodeId);
|
|
24
|
+
waitlist[sourceNodeId].add(computedNodeId);
|
|
20
25
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const keys = Object.keys(nodeData.inputs);
|
|
30
|
+
keys.forEach((key) => {
|
|
31
|
+
const inputNodeId = nodeData.inputs[key];
|
|
32
|
+
const sourceNodeId = (0, utils_1.parseNodeName)(inputNodeId, data.version ?? 0.3).nodeId;
|
|
33
|
+
if (sourceNodeId) {
|
|
34
|
+
if (!nodeIds.has(sourceNodeId)) {
|
|
35
|
+
throw new common_1.ValidationError(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${sourceNodeId}`);
|
|
36
|
+
}
|
|
37
|
+
waitlist[sourceNodeId] === undefined && (waitlist[sourceNodeId] = new Set());
|
|
38
|
+
pendings[computedNodeId].add(sourceNodeId);
|
|
39
|
+
waitlist[sourceNodeId].add(computedNodeId);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
26
43
|
}
|
|
27
44
|
});
|
|
28
45
|
// TODO. validate update
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -r lib/* && tsc && tsc-alias",
|
|
11
11
|
"eslint": "eslint",
|
|
12
|
+
"rollup": "npx rollup -c",
|
|
12
13
|
"doc": " npx typedoc src/index.ts --out ../../docs/apiDoc",
|
|
13
|
-
"format": "prettier --write '{src,tests,samples}/**/*.ts'",
|
|
14
|
+
"format": "prettier --write '{src,tests,samples}/**/*.ts' *.mjs",
|
|
14
15
|
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
15
16
|
"b": "yarn run format && yarn run eslint && yarn run build"
|
|
16
17
|
},
|