graphai 0.1.2 → 0.2.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 +107 -78
- package/lib/experimental_agents/array_agents/packages.d.ts +4 -0
- package/lib/experimental_agents/array_agents/packages.js +12 -0
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +26 -0
- package/lib/experimental_agents/array_agents/pop_agent.js +40 -0
- package/lib/experimental_agents/array_agents/push_agent.d.ts +16 -0
- package/lib/experimental_agents/array_agents/push_agent.js +18 -0
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +26 -0
- package/lib/experimental_agents/array_agents/shift_agent.js +29 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +57 -2
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +13 -1
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +1 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +1 -0
- package/lib/experimental_agents/data_agents/packages.d.ts +4 -0
- package/lib/experimental_agents/data_agents/packages.js +12 -0
- package/lib/experimental_agents/data_agents/total_agent.d.ts +1 -0
- package/lib/experimental_agents/data_agents/total_agent.js +1 -0
- package/lib/experimental_agents/embedding_agent.d.ts +17 -3
- package/lib/experimental_agents/embedding_agent.js +13 -1
- package/lib/experimental_agents/graph_agents/index.d.ts +2 -0
- package/lib/experimental_agents/graph_agents/index.js +7 -0
- package/lib/experimental_agents/graph_agents/map_agent.d.ts +20 -0
- package/lib/experimental_agents/{map_agent.js → graph_agents/map_agent.js} +31 -10
- package/lib/experimental_agents/graph_agents/nested_agent.d.ts +22 -0
- package/lib/experimental_agents/graph_agents/nested_agent.js +70 -0
- package/lib/experimental_agents/graph_agents/packages.d.ts +3 -0
- package/lib/experimental_agents/graph_agents/packages.js +10 -0
- package/lib/experimental_agents/index.d.ts +4 -5
- package/lib/experimental_agents/index.js +4 -5
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +17 -3
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +26 -1
- package/lib/experimental_agents/matrix_agents/packages.d.ts +3 -0
- package/lib/experimental_agents/matrix_agents/packages.js +10 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +17 -3
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +13 -1
- package/lib/experimental_agents/packages.d.ts +11 -0
- package/lib/experimental_agents/packages.js +33 -0
- package/lib/experimental_agents/slashgpt_agent.d.ts +24 -0
- package/lib/experimental_agents/slashgpt_agent.js +12 -0
- package/lib/experimental_agents/sleeper_agents/packages.d.ts +3 -0
- package/lib/experimental_agents/sleeper_agents/packages.js +10 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +18 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +12 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +20 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.js +13 -1
- package/lib/experimental_agents/string_agents/packages.d.ts +3 -0
- package/lib/experimental_agents/string_agents/packages.js +10 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +1 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +1 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +1 -0
- package/lib/experimental_agents/string_agents/string_template_agent.js +1 -0
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +3 -0
- package/lib/experimental_agents/test_agents/bypass_agent.js +24 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +6 -1
- package/lib/experimental_agents/test_agents/copy2array_agent.js +32 -2
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +9 -1
- package/lib/experimental_agents/test_agents/copy_message_agent.js +19 -0
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +8 -1
- package/lib/experimental_agents/test_agents/counting_agent.js +19 -0
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +3 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +13 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +3 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +22 -0
- package/lib/experimental_agents/test_agents/packages.d.ts +7 -0
- package/lib/experimental_agents/test_agents/packages.js +18 -0
- package/lib/experimental_agents/token_agent.d.ts +20 -0
- package/lib/experimental_agents/token_agent.js +12 -0
- package/lib/graphai.d.ts +1 -1
- package/lib/graphai.js +8 -11
- package/lib/node.d.ts +1 -0
- package/lib/node.js +17 -10
- package/lib/type.d.ts +4 -3
- package/lib/utils/test_utils.js +1 -1
- package/lib/utils/utils.d.ts +3 -1
- package/lib/utils/utils.js +30 -2
- package/package.json +3 -2
- package/lib/experimental_agents/map_agent.d.ts +0 -4
- package/lib/experimental_agents/nested_agent.d.ts +0 -5
- package/lib/experimental_agents/nested_agent.js +0 -40
|
@@ -8,3 +8,27 @@ const bypassAgent = async (context) => {
|
|
|
8
8
|
return context.inputs;
|
|
9
9
|
};
|
|
10
10
|
exports.bypassAgent = bypassAgent;
|
|
11
|
+
// for test and document
|
|
12
|
+
const bypassAgentInfo = {
|
|
13
|
+
name: "bypassAgent",
|
|
14
|
+
agent: exports.bypassAgent,
|
|
15
|
+
mock: exports.bypassAgent,
|
|
16
|
+
samples: [
|
|
17
|
+
{
|
|
18
|
+
inputs: [{ a: "123" }],
|
|
19
|
+
params: {},
|
|
20
|
+
result: { a: "123" },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
inputs: [{ a: "123" }, { b: "abc" }],
|
|
24
|
+
params: {},
|
|
25
|
+
result: [{ a: "123" }, { b: "abc" }],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
description: "bypass agent",
|
|
29
|
+
category: [],
|
|
30
|
+
author: "Receptron team",
|
|
31
|
+
repository: "https://github.com/receptron/graphai",
|
|
32
|
+
license: "MIT",
|
|
33
|
+
};
|
|
34
|
+
exports.default = bypassAgentInfo;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { AgentFunction } from "../../graphai";
|
|
2
|
-
|
|
2
|
+
import { AgentFunctionInfo } from "../../type";
|
|
3
|
+
export declare const copy2ArrayAgent: AgentFunction<{
|
|
4
|
+
count: number;
|
|
5
|
+
}>;
|
|
6
|
+
declare const copy2ArrayAgentInfo: AgentFunctionInfo;
|
|
7
|
+
export default copy2ArrayAgentInfo;
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.copy2ArrayAgent = void 0;
|
|
4
|
-
const copy2ArrayAgent = async ({ inputs }) => {
|
|
5
|
-
return new Array(
|
|
4
|
+
const copy2ArrayAgent = async ({ inputs, params }) => {
|
|
5
|
+
return new Array(params.count).fill(undefined).map(() => {
|
|
6
6
|
return inputs[0];
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
exports.copy2ArrayAgent = copy2ArrayAgent;
|
|
10
|
+
// for test and document
|
|
11
|
+
const copy2ArrayAgentInfo = {
|
|
12
|
+
name: "copy2ArrayAgent",
|
|
13
|
+
agent: exports.copy2ArrayAgent,
|
|
14
|
+
mock: exports.copy2ArrayAgent,
|
|
15
|
+
samples: [
|
|
16
|
+
{
|
|
17
|
+
inputs: [{ message: "hello" }],
|
|
18
|
+
params: { count: 10 },
|
|
19
|
+
result: [
|
|
20
|
+
{ message: "hello" },
|
|
21
|
+
{ message: "hello" },
|
|
22
|
+
{ message: "hello" },
|
|
23
|
+
{ message: "hello" },
|
|
24
|
+
{ message: "hello" },
|
|
25
|
+
{ message: "hello" },
|
|
26
|
+
{ message: "hello" },
|
|
27
|
+
{ message: "hello" },
|
|
28
|
+
{ message: "hello" },
|
|
29
|
+
{ message: "hello" },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
description: "Copy2Array agent",
|
|
34
|
+
category: [],
|
|
35
|
+
author: "Receptron team",
|
|
36
|
+
repository: "https://github.com/receptron/graphai",
|
|
37
|
+
license: "MIT",
|
|
38
|
+
};
|
|
39
|
+
exports.default = copy2ArrayAgentInfo;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { AgentFunction } from "../../graphai";
|
|
2
|
-
|
|
2
|
+
import { AgentFunctionInfo } from "../../type";
|
|
3
|
+
export declare const copyMessageAgent: AgentFunction<{
|
|
4
|
+
count: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}, {
|
|
7
|
+
messages: string[];
|
|
8
|
+
}>;
|
|
9
|
+
declare const copyMessageAgentInfo: AgentFunctionInfo;
|
|
10
|
+
export default copyMessageAgentInfo;
|
|
@@ -9,3 +9,22 @@ const copyMessageAgent = async ({ params }) => {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
exports.copyMessageAgent = copyMessageAgent;
|
|
12
|
+
// for test and document
|
|
13
|
+
const copyMessageAgentInfo = {
|
|
14
|
+
name: "copyMessageAgent",
|
|
15
|
+
agent: exports.copyMessageAgent,
|
|
16
|
+
mock: exports.copyMessageAgent,
|
|
17
|
+
samples: [
|
|
18
|
+
{
|
|
19
|
+
inputs: [],
|
|
20
|
+
params: { count: 4, message: "hello" },
|
|
21
|
+
result: { messages: ["hello", "hello", "hello", "hello"] },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
description: "CopyMessage agent",
|
|
25
|
+
category: [],
|
|
26
|
+
author: "Receptron team",
|
|
27
|
+
repository: "https://github.com/receptron/graphai",
|
|
28
|
+
license: "MIT",
|
|
29
|
+
};
|
|
30
|
+
exports.default = copyMessageAgentInfo;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { AgentFunction } from "../../graphai";
|
|
2
|
-
|
|
2
|
+
import { AgentFunctionInfo } from "../../type";
|
|
3
|
+
export declare const countingAgent: AgentFunction<{
|
|
4
|
+
count: number;
|
|
5
|
+
}, {
|
|
6
|
+
list: number[];
|
|
7
|
+
}>;
|
|
8
|
+
declare const countingAgentInfo: AgentFunctionInfo;
|
|
9
|
+
export default countingAgentInfo;
|
|
@@ -9,3 +9,22 @@ const countingAgent = async ({ params }) => {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
exports.countingAgent = countingAgent;
|
|
12
|
+
// for test and document
|
|
13
|
+
const countingAgentInfo = {
|
|
14
|
+
name: "countingAgent",
|
|
15
|
+
agent: exports.countingAgent,
|
|
16
|
+
mock: exports.countingAgent,
|
|
17
|
+
samples: [
|
|
18
|
+
{
|
|
19
|
+
inputs: [],
|
|
20
|
+
params: { count: 4 },
|
|
21
|
+
result: { list: [0, 1, 2, 3] },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
description: "Counting agent",
|
|
25
|
+
category: [],
|
|
26
|
+
author: "Receptron team",
|
|
27
|
+
repository: "https://github.com/receptron/graphai",
|
|
28
|
+
license: "MIT",
|
|
29
|
+
};
|
|
30
|
+
exports.default = countingAgentInfo;
|
|
@@ -5,3 +5,16 @@ const echoAgent = async ({ params }) => {
|
|
|
5
5
|
return params;
|
|
6
6
|
};
|
|
7
7
|
exports.echoAgent = echoAgent;
|
|
8
|
+
// for test and document
|
|
9
|
+
const echoAgentInfo = {
|
|
10
|
+
name: "echoAgent",
|
|
11
|
+
agent: exports.echoAgent,
|
|
12
|
+
mock: exports.echoAgent,
|
|
13
|
+
samples: [],
|
|
14
|
+
description: "Echo agent",
|
|
15
|
+
category: [],
|
|
16
|
+
author: "Satoshi Nakajima",
|
|
17
|
+
repository: "https://github.com/receptron/graphai",
|
|
18
|
+
license: "MIT",
|
|
19
|
+
};
|
|
20
|
+
exports.default = echoAgentInfo;
|
|
@@ -8,3 +8,25 @@ const mergeNodeIdAgent = async ({ debugInfo: { nodeId }, inputs }) => {
|
|
|
8
8
|
}, { [nodeId]: "hello" });
|
|
9
9
|
};
|
|
10
10
|
exports.mergeNodeIdAgent = mergeNodeIdAgent;
|
|
11
|
+
// for test and document
|
|
12
|
+
const mergeNodeIdAgentInfo = {
|
|
13
|
+
name: "mergeNodeIdAgent",
|
|
14
|
+
agent: exports.mergeNodeIdAgent,
|
|
15
|
+
mock: exports.mergeNodeIdAgent,
|
|
16
|
+
samples: [
|
|
17
|
+
{
|
|
18
|
+
inputs: [{ message: "hello" }],
|
|
19
|
+
params: {},
|
|
20
|
+
result: {
|
|
21
|
+
message: "hello",
|
|
22
|
+
test: "hello",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
description: "merge node id agent",
|
|
27
|
+
category: [],
|
|
28
|
+
author: "Receptron team",
|
|
29
|
+
repository: "https://github.com/receptron/graphai",
|
|
30
|
+
license: "MIT",
|
|
31
|
+
};
|
|
32
|
+
exports.default = mergeNodeIdAgentInfo;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import echoAgent from "../../experimental_agents/test_agents/echo_agent";
|
|
2
|
+
import bypassAgent from "../../experimental_agents/test_agents/bypass_agent";
|
|
3
|
+
import countingAgent from "../../experimental_agents/test_agents/counting_agent";
|
|
4
|
+
import copyMessageAgent from "../../experimental_agents/test_agents/copy_message_agent";
|
|
5
|
+
import copy2ArrayAgent from "../../experimental_agents/test_agents/copy2array_agent";
|
|
6
|
+
import mergeNodeIdAgent from "../../experimental_agents/test_agents/merge_node_id_agent";
|
|
7
|
+
export { echoAgent, bypassAgent, countingAgent, copyMessageAgent, copy2ArrayAgent, mergeNodeIdAgent };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeNodeIdAgent = exports.copy2ArrayAgent = exports.copyMessageAgent = exports.countingAgent = exports.bypassAgent = exports.echoAgent = void 0;
|
|
7
|
+
const echo_agent_1 = __importDefault(require("../../experimental_agents/test_agents/echo_agent"));
|
|
8
|
+
exports.echoAgent = echo_agent_1.default;
|
|
9
|
+
const bypass_agent_1 = __importDefault(require("../../experimental_agents/test_agents/bypass_agent"));
|
|
10
|
+
exports.bypassAgent = bypass_agent_1.default;
|
|
11
|
+
const counting_agent_1 = __importDefault(require("../../experimental_agents/test_agents/counting_agent"));
|
|
12
|
+
exports.countingAgent = counting_agent_1.default;
|
|
13
|
+
const copy_message_agent_1 = __importDefault(require("../../experimental_agents/test_agents/copy_message_agent"));
|
|
14
|
+
exports.copyMessageAgent = copy_message_agent_1.default;
|
|
15
|
+
const copy2array_agent_1 = __importDefault(require("../../experimental_agents/test_agents/copy2array_agent"));
|
|
16
|
+
exports.copy2ArrayAgent = copy2array_agent_1.default;
|
|
17
|
+
const merge_node_id_agent_1 = __importDefault(require("../../experimental_agents/test_agents/merge_node_id_agent"));
|
|
18
|
+
exports.mergeNodeIdAgent = merge_node_id_agent_1.default;
|
|
@@ -4,3 +4,23 @@ export declare const tokenBoundStringsAgent: AgentFunction<{
|
|
|
4
4
|
}, {
|
|
5
5
|
content: string;
|
|
6
6
|
}, Array<string>>;
|
|
7
|
+
declare const tokenBoundStringsAgentInfo: {
|
|
8
|
+
name: string;
|
|
9
|
+
agent: AgentFunction<{
|
|
10
|
+
limit?: number | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
content: string;
|
|
13
|
+
}, string[]>;
|
|
14
|
+
mock: AgentFunction<{
|
|
15
|
+
limit?: number | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
content: string;
|
|
18
|
+
}, string[]>;
|
|
19
|
+
samples: never[];
|
|
20
|
+
description: string;
|
|
21
|
+
category: never[];
|
|
22
|
+
author: string;
|
|
23
|
+
repository: string;
|
|
24
|
+
license: string;
|
|
25
|
+
};
|
|
26
|
+
export default tokenBoundStringsAgentInfo;
|
|
@@ -31,3 +31,15 @@ const tokenBoundStringsAgent = async ({ params, inputs }) => {
|
|
|
31
31
|
return { content, tokenCount, endIndex };
|
|
32
32
|
};
|
|
33
33
|
exports.tokenBoundStringsAgent = tokenBoundStringsAgent;
|
|
34
|
+
const tokenBoundStringsAgentInfo = {
|
|
35
|
+
name: "tokenBoundStringsAgent",
|
|
36
|
+
agent: exports.tokenBoundStringsAgent,
|
|
37
|
+
mock: exports.tokenBoundStringsAgent,
|
|
38
|
+
samples: [],
|
|
39
|
+
description: "token bound Agent",
|
|
40
|
+
category: [],
|
|
41
|
+
author: "Receptron team",
|
|
42
|
+
repository: "https://github.com/receptron/graphai",
|
|
43
|
+
license: "MIT",
|
|
44
|
+
};
|
|
45
|
+
exports.default = tokenBoundStringsAgentInfo;
|
package/lib/graphai.d.ts
CHANGED
|
@@ -37,5 +37,5 @@ export declare class GraphAI {
|
|
|
37
37
|
updateLog(log: TransactionLog): void;
|
|
38
38
|
transactionLogs(): TransactionLog[];
|
|
39
39
|
injectValue(nodeId: string, value: ResultData, injectFrom?: string): void;
|
|
40
|
-
resultsOf(sources: Array<DataSource
|
|
40
|
+
resultsOf(sources: Array<DataSource>): ResultData[];
|
|
41
41
|
}
|
package/lib/graphai.js
CHANGED
|
@@ -40,8 +40,7 @@ class GraphAI {
|
|
|
40
40
|
}
|
|
41
41
|
getValueFromResults(key, results) {
|
|
42
42
|
const source = (0, utils_1.parseNodeName)(key);
|
|
43
|
-
|
|
44
|
-
return result && source.propId ? result[source.propId] : result;
|
|
43
|
+
return (0, utils_1.getDataFromSource)(results[source.nodeId], source.propIds);
|
|
45
44
|
}
|
|
46
45
|
// for static
|
|
47
46
|
initializeNodes(previousResults) {
|
|
@@ -96,10 +95,7 @@ class GraphAI {
|
|
|
96
95
|
// Public API
|
|
97
96
|
results(all) {
|
|
98
97
|
return Object.keys(this.nodes)
|
|
99
|
-
.filter((nodeId) =>
|
|
100
|
-
const node = this.nodes[nodeId];
|
|
101
|
-
return all || node.isResult;
|
|
102
|
-
})
|
|
98
|
+
.filter((nodeId) => all || this.nodes[nodeId].isResult)
|
|
103
99
|
.reduce((results, nodeId) => {
|
|
104
100
|
const node = this.nodes[nodeId];
|
|
105
101
|
if (node.result !== undefined) {
|
|
@@ -153,6 +149,10 @@ class GraphAI {
|
|
|
153
149
|
console.error("-- Already Running");
|
|
154
150
|
}
|
|
155
151
|
this.pushReadyNodesIntoQueue();
|
|
152
|
+
if (!this.isRunning()) {
|
|
153
|
+
console.warn("-- nothing to execute");
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
156
|
return new Promise((resolve, reject) => {
|
|
157
157
|
this.onComplete = () => {
|
|
158
158
|
const errors = this.errors();
|
|
@@ -227,13 +227,10 @@ class GraphAI {
|
|
|
227
227
|
console.error("InjectionTo can only specify static nodes");
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
resultsOf(sources
|
|
230
|
+
resultsOf(sources) {
|
|
231
231
|
return sources.map((source) => {
|
|
232
232
|
const { result } = this.nodes[source.nodeId];
|
|
233
|
-
|
|
234
|
-
(0, utils_1.assert)((0, utils_1.isObject)(result), `resultsOf: result is not object. nodeId ${source.nodeId}`, anyInput);
|
|
235
|
-
}
|
|
236
|
-
return result && source.propId ? result[source.propId] : result;
|
|
233
|
+
return (0, utils_1.getDataFromSource)(result, source.propIds);
|
|
237
234
|
});
|
|
238
235
|
}
|
|
239
236
|
}
|
package/lib/node.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class ComputedNode extends Node {
|
|
|
31
31
|
constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
|
|
32
32
|
isReadyNode(): boolean;
|
|
33
33
|
private retry;
|
|
34
|
+
private checkDataAvailability;
|
|
34
35
|
removePending(nodeId: string): void;
|
|
35
36
|
private isCurrentTransaction;
|
|
36
37
|
private executeTimeout;
|
package/lib/node.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaticNode = exports.ComputedNode = exports.Node = void 0;
|
|
4
|
-
const type_1 = require("./type");
|
|
5
4
|
const utils_1 = require("./utils/utils");
|
|
5
|
+
const type_1 = require("./type");
|
|
6
|
+
const utils_2 = require("./utils/utils");
|
|
6
7
|
const transaction_log_1 = require("./transaction_log");
|
|
7
8
|
class Node {
|
|
8
9
|
constructor(nodeId, graph) {
|
|
@@ -43,7 +44,7 @@ class ComputedNode extends Node {
|
|
|
43
44
|
this.timeout = data.timeout;
|
|
44
45
|
this.isResult = data.isResult ?? false;
|
|
45
46
|
this.anyInput = data.anyInput ?? false;
|
|
46
|
-
this.dataSources = (data.inputs ?? []).map(
|
|
47
|
+
this.dataSources = (data.inputs ?? []).map(utils_2.parseNodeName);
|
|
47
48
|
this.pendings = new Set(this.dataSources.map((source) => source.nodeId));
|
|
48
49
|
this.log.initForComputedNode(this);
|
|
49
50
|
}
|
|
@@ -53,7 +54,7 @@ class ComputedNode extends Node {
|
|
|
53
54
|
// We care it only when this.anyInput is true.
|
|
54
55
|
// Notice that this logic enables dynamic data-flows.
|
|
55
56
|
const counter = this.dataSources.reduce((count, source) => {
|
|
56
|
-
const [result] = this.graph.resultsOf([source]
|
|
57
|
+
const [result] = this.graph.resultsOf([source]);
|
|
57
58
|
return result === undefined ? count : count + 1;
|
|
58
59
|
}, 0);
|
|
59
60
|
if (!this.anyInput || counter > 0) {
|
|
@@ -79,14 +80,18 @@ class ComputedNode extends Node {
|
|
|
79
80
|
this.graph.onExecutionComplete(this);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
83
|
+
checkDataAvailability() {
|
|
84
|
+
(0, utils_2.assert)(this.anyInput, "checkDataAvailability should be called only for anyInput case");
|
|
85
|
+
const results = this.graph.resultsOf(this.dataSources).filter((result) => {
|
|
86
|
+
return result !== undefined;
|
|
87
|
+
});
|
|
88
|
+
return results.length > 0;
|
|
89
|
+
}
|
|
82
90
|
// This method is called when the data became available on one of nodes,
|
|
83
91
|
// which this node needs data from.
|
|
84
92
|
removePending(nodeId) {
|
|
85
93
|
if (this.anyInput) {
|
|
86
|
-
|
|
87
|
-
return result !== undefined;
|
|
88
|
-
});
|
|
89
|
-
if (results.length > 0) {
|
|
94
|
+
if (this.checkDataAvailability()) {
|
|
90
95
|
this.pendings.clear();
|
|
91
96
|
}
|
|
92
97
|
}
|
|
@@ -111,7 +116,7 @@ class ComputedNode extends Node {
|
|
|
111
116
|
// then it removes itself from the "running node" list of the graph.
|
|
112
117
|
// Notice that setting the result of this node may make other nodes ready to run.
|
|
113
118
|
async execute() {
|
|
114
|
-
const previousResults = this.graph.resultsOf(this.dataSources
|
|
119
|
+
const previousResults = this.graph.resultsOf(this.dataSources).filter((result) => {
|
|
115
120
|
// Remove undefined if anyInput flag is set.
|
|
116
121
|
return !this.anyInput || result !== undefined;
|
|
117
122
|
});
|
|
@@ -174,8 +179,10 @@ class ComputedNode extends Node {
|
|
|
174
179
|
// the agent function. It records the error in the transaction log and handles
|
|
175
180
|
// the retry if specified.
|
|
176
181
|
errorProcess(error, transactionId) {
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
if (error instanceof Error && error.message !== utils_1.strIntentionalError) {
|
|
183
|
+
console.error(this.agentId + ": error");
|
|
184
|
+
console.error(error);
|
|
185
|
+
}
|
|
179
186
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
180
187
|
console.log(`-- ${this.nodeId}: transactionId mismatch(error)`);
|
|
181
188
|
return;
|
package/lib/type.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare enum NodeState {
|
|
|
10
10
|
Injected = "injected",
|
|
11
11
|
Dispatched = "dispatched"
|
|
12
12
|
}
|
|
13
|
-
export type DefaultResultData = Record<string, any>;
|
|
13
|
+
export type DefaultResultData = Record<string, any> | string | number | Array<DefaultResultData>;
|
|
14
14
|
export type DefaultInputData = Record<string, any>;
|
|
15
15
|
export type ResultData<ResultType = DefaultResultData> = ResultType | undefined;
|
|
16
16
|
export type ResultDataDictonary<ResultType = DefaultResultData> = Record<string, ResultData<ResultType>>;
|
|
@@ -18,7 +18,7 @@ export type DefaultParamsType = Record<string, any>;
|
|
|
18
18
|
export type NodeDataParams<ParamsType = DefaultParamsType> = ParamsType;
|
|
19
19
|
export type DataSource = {
|
|
20
20
|
nodeId: string;
|
|
21
|
-
|
|
21
|
+
propIds?: string[];
|
|
22
22
|
};
|
|
23
23
|
export type StaticNodeData = {
|
|
24
24
|
value: ResultData;
|
|
@@ -54,7 +54,7 @@ export type AgentFunctionContext<ParamsType, InputDataType> = {
|
|
|
54
54
|
nodeId: string;
|
|
55
55
|
retry: number;
|
|
56
56
|
};
|
|
57
|
-
graphData?: GraphData;
|
|
57
|
+
graphData?: GraphData | string;
|
|
58
58
|
agents?: AgentFunctionDictonary;
|
|
59
59
|
log?: TransactionLog[];
|
|
60
60
|
taskManager?: TaskManager;
|
|
@@ -71,6 +71,7 @@ export type AgentFunctionInfo = {
|
|
|
71
71
|
result: any;
|
|
72
72
|
}[];
|
|
73
73
|
description: string;
|
|
74
|
+
category: string[];
|
|
74
75
|
author: string;
|
|
75
76
|
repository: string;
|
|
76
77
|
license: string;
|
package/lib/utils/test_utils.js
CHANGED
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { DataSource } from "../type";
|
|
1
|
+
import { DataSource, ResultData } from "../type";
|
|
2
2
|
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
3
3
|
export declare const parseNodeName: (inputNodeId: string) => DataSource;
|
|
4
4
|
export declare function assert(condition: boolean, message: string, isWarn?: boolean): asserts condition;
|
|
5
5
|
export declare const isObject: (x: unknown) => boolean;
|
|
6
|
+
export declare const getDataFromSource: (result: ResultData, propIds: string[] | undefined) => ResultData | undefined;
|
|
7
|
+
export declare const strIntentionalError = "Intentional Error for Debugging";
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = exports.assert = exports.parseNodeName = exports.sleep = void 0;
|
|
3
|
+
exports.strIntentionalError = exports.getDataFromSource = exports.isObject = exports.assert = exports.parseNodeName = exports.sleep = void 0;
|
|
4
4
|
const sleep = async (milliseconds) => {
|
|
5
5
|
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
6
6
|
};
|
|
@@ -10,7 +10,7 @@ const parseNodeName = (inputNodeId) => {
|
|
|
10
10
|
if (parts.length == 1) {
|
|
11
11
|
return { nodeId: parts[0] };
|
|
12
12
|
}
|
|
13
|
-
return { nodeId: parts[0],
|
|
13
|
+
return { nodeId: parts[0], propIds: parts.slice(1) };
|
|
14
14
|
};
|
|
15
15
|
exports.parseNodeName = parseNodeName;
|
|
16
16
|
function assert(condition, message, isWarn = false) {
|
|
@@ -26,3 +26,31 @@ const isObject = (x) => {
|
|
|
26
26
|
return x !== null && typeof x === "object";
|
|
27
27
|
};
|
|
28
28
|
exports.isObject = isObject;
|
|
29
|
+
const getNestedData = (result, propId) => {
|
|
30
|
+
if (Array.isArray(result)) {
|
|
31
|
+
const regex = /^\$(\d+)$/;
|
|
32
|
+
const match = propId.match(regex);
|
|
33
|
+
if (match) {
|
|
34
|
+
const index = parseInt(match[1], 10);
|
|
35
|
+
return result[index];
|
|
36
|
+
}
|
|
37
|
+
if (propId === "$last") {
|
|
38
|
+
return result[result.length - 1];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
assert((0, exports.isObject)(result), "result is not object.");
|
|
42
|
+
return result[propId];
|
|
43
|
+
};
|
|
44
|
+
const getDataFromSource = (result, propIds) => {
|
|
45
|
+
if (result && propIds && propIds.length > 0) {
|
|
46
|
+
const propId = propIds[0];
|
|
47
|
+
const ret = getNestedData(result, propId);
|
|
48
|
+
if (propIds.length > 1) {
|
|
49
|
+
return (0, exports.getDataFromSource)(ret, propIds.slice(1));
|
|
50
|
+
}
|
|
51
|
+
return ret;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
exports.getDataFromSource = getDataFromSource;
|
|
56
|
+
exports.strIntentionalError = "Intentional Error for Debugging";
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"./lib"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc && tsc-alias",
|
|
10
|
+
"build": "rm -r lib/* && tsc && tsc-alias",
|
|
11
11
|
"eslint": "eslint --fix --ext .ts ./src ./tests ./samples",
|
|
12
12
|
"format": "prettier --write '{src,tests,samples}/**/*.ts' .eslintrc.js",
|
|
13
13
|
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
14
|
+
"http_test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/http_*.ts",
|
|
14
15
|
"b": "yarn run format && yarn run eslint && yarn run build",
|
|
15
16
|
"samples": "npx ts-node -r tsconfig-paths/register samples/sample_runner.ts",
|
|
16
17
|
"sample": "npx ts-node -r tsconfig-paths/register"
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nestedAgent = void 0;
|
|
4
|
-
const graphai_1 = require("../graphai");
|
|
5
|
-
const utils_1 = require("../utils/utils");
|
|
6
|
-
const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
7
|
-
if (taskManager) {
|
|
8
|
-
const status = taskManager.getStatus(false);
|
|
9
|
-
(0, utils_1.assert)(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
|
|
10
|
-
}
|
|
11
|
-
(0, utils_1.assert)(graphData !== undefined, "nestedAgent: graphData is required");
|
|
12
|
-
const injectionTo = params.injectionTo ??
|
|
13
|
-
inputs.map((__input, index) => {
|
|
14
|
-
return `$${index}`;
|
|
15
|
-
});
|
|
16
|
-
injectionTo.forEach((nodeId) => {
|
|
17
|
-
if (graphData.nodes[nodeId] === undefined) {
|
|
18
|
-
// If the input node does not exist, automatically create a static node
|
|
19
|
-
graphData.nodes[nodeId] = { value: {} };
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const graphAI = new graphai_1.GraphAI(graphData, agents || {}, taskManager);
|
|
23
|
-
try {
|
|
24
|
-
// Inject inputs to specified source nodes
|
|
25
|
-
injectionTo.forEach((injectToNodeId, index) => {
|
|
26
|
-
graphAI.injectValue(injectToNodeId, inputs[index]);
|
|
27
|
-
});
|
|
28
|
-
const results = await graphAI.run(false);
|
|
29
|
-
log?.push(...graphAI.transactionLogs());
|
|
30
|
-
return results;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
log?.push(...graphAI.transactionLogs());
|
|
34
|
-
if (error instanceof Error) {
|
|
35
|
-
console.log("Error:", error.message);
|
|
36
|
-
}
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
exports.nestedAgent = nestedAgent;
|