graphai 0.4.2 → 0.4.4
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 +15 -80
- package/lib/experimental_agents/array_agents/push_agent.d.ts +1 -1
- package/lib/experimental_agents/array_agents/push_agent.js +1 -1
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +1 -1
- package/lib/experimental_agents/array_agents/shift_agent.js +1 -1
- package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +45 -0
- package/lib/experimental_agents/data_agents/property_filter_agent.js +28 -4
- package/lib/experimental_agents/embedding_agent.d.ts +1 -1
- package/lib/experimental_agents/embedding_agent.js +1 -1
- package/lib/experimental_agents/graph_agents/map_agent.d.ts +1 -1
- package/lib/experimental_agents/graph_agents/map_agent.js +1 -1
- package/lib/experimental_agents/graph_agents/nested_agent.d.ts +1 -1
- package/lib/experimental_agents/graph_agents/nested_agent.js +1 -1
- package/lib/experimental_agents/graph_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/graph_agents/packages.js +3 -1
- package/lib/experimental_agents/graph_agents/vanilla.d.ts +2 -1
- package/lib/experimental_agents/graph_agents/vanilla.js +3 -1
- package/lib/experimental_agents/graph_agents/worker_agent.d.ts +39 -0
- package/lib/experimental_agents/graph_agents/worker_agent.js +111 -0
- package/lib/experimental_agents/index.d.ts +1 -2
- package/lib/experimental_agents/index.js +1 -3
- package/lib/experimental_agents/input_agents/text_input_agent.d.ts +8 -1
- package/lib/experimental_agents/input_agents/text_input_agent.js +9 -2
- package/lib/experimental_agents/llm_agents/anthropic_agent.d.ts +34 -0
- package/lib/experimental_agents/llm_agents/anthropic_agent.js +47 -0
- package/lib/experimental_agents/llm_agents/groq_agent.d.ts +5 -3
- package/lib/experimental_agents/llm_agents/groq_agent.js +6 -4
- package/lib/experimental_agents/llm_agents/index.d.ts +2 -2
- package/lib/experimental_agents/llm_agents/index.js +3 -3
- package/lib/experimental_agents/llm_agents/openai_agent.d.ts +8 -0
- package/lib/experimental_agents/llm_agents/openai_agent.js +13 -2
- package/lib/experimental_agents/llm_agents/packages.d.ts +2 -2
- package/lib/experimental_agents/llm_agents/packages.js +3 -3
- package/lib/experimental_agents/llm_agents/slashgpt_agent.d.ts +2 -0
- package/lib/experimental_agents/llm_agents/slashgpt_agent.js +2 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +1 -1
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +1 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +1 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +1 -1
- package/lib/experimental_agents/service_agents/fetch_agent.js +3 -2
- package/lib/experimental_agents/service_agents/wikipedia.js +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.js +1 -1
- package/lib/experimental_agents/string_agents/json_parser_agent.d.ts +38 -0
- package/lib/experimental_agents/string_agents/json_parser_agent.js +39 -0
- package/lib/experimental_agents/string_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/string_agents/packages.js +3 -1
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +1 -1
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +9 -7
- package/lib/experimental_agents/string_agents/string_template_agent.js +4 -1
- package/lib/experimental_agents/string_agents/vanilla.d.ts +2 -1
- package/lib/experimental_agents/string_agents/vanilla.js +3 -1
- package/lib/experimental_agents/test_agents/bypass_agent.js +1 -1
- package/lib/experimental_agents/test_agents/copy2array_agent.js +1 -1
- package/lib/experimental_agents/test_agents/copy_message_agent.js +1 -1
- package/lib/experimental_agents/test_agents/counting_agent.js +1 -1
- package/lib/experimental_agents/test_agents/echo_agent.js +13 -2
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +1 -1
- package/lib/experimental_agents/test_agents/stream_mock_agent.js +9 -2
- package/lib/experimental_agents/vanilla.d.ts +1 -2
- package/lib/experimental_agents/vanilla.js +1 -3
- package/lib/graphai.d.ts +5 -5
- package/lib/graphai.js +9 -9
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/node.d.ts +2 -1
- package/lib/node.js +37 -11
- package/lib/transaction_log.d.ts +1 -0
- package/lib/transaction_log.js +2 -0
- package/lib/type.d.ts +11 -6
- package/lib/utils/runner.d.ts +2 -0
- package/lib/utils/runner.js +20 -0
- package/lib/utils/test_agents.d.ts +2 -2
- package/lib/utils/test_utils.d.ts +1 -17
- package/lib/utils/test_utils.js +3 -21
- package/lib/utils/utils.d.ts +2 -0
- package/lib/utils/utils.js +45 -1
- package/lib/validators/agent_validator.js +2 -1
- package/lib/validators/common.d.ts +3 -0
- package/lib/validators/common.js +10 -1
- package/lib/validators/computed_node_validator.js +1 -1
- package/lib/validators/graph_data_validator.js +9 -9
- package/lib/validators/nodeValidator.js +3 -2
- package/lib/validators/relation_validator.js +6 -5
- package/lib/validators/static_node_validator.js +1 -1
- package/package.json +3 -4
- package/lib/experimental_agents/function_agent.d.ts +0 -42
- package/lib/experimental_agents/function_agent.js +0 -40
- package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +0 -42
- package/lib/experimental_agents/llm_agents/groq_stream_agent.js +0 -84
|
@@ -13,9 +13,20 @@ const echoAgentInfo = {
|
|
|
13
13
|
name: "echoAgent",
|
|
14
14
|
agent: exports.echoAgent,
|
|
15
15
|
mock: exports.echoAgent,
|
|
16
|
-
samples: [
|
|
16
|
+
samples: [
|
|
17
|
+
{
|
|
18
|
+
inputs: [],
|
|
19
|
+
params: { message: "this is test" },
|
|
20
|
+
result: { message: "this is test" },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
inputs: [],
|
|
24
|
+
params: { message: "If you add filterParams option, it will respond to filterParams", filterParams: true },
|
|
25
|
+
result: {},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
17
28
|
description: "Echo agent",
|
|
18
|
-
category: [],
|
|
29
|
+
category: ["test"],
|
|
19
30
|
author: "Satoshi Nakajima",
|
|
20
31
|
repository: "https://github.com/receptron/graphai",
|
|
21
32
|
license: "MIT",
|
|
@@ -18,11 +18,18 @@ const streamMockAgentInfo = {
|
|
|
18
18
|
name: "streamMockAgent",
|
|
19
19
|
agent: exports.streamMockAgent,
|
|
20
20
|
mock: exports.streamMockAgent,
|
|
21
|
-
samples: [
|
|
21
|
+
samples: [
|
|
22
|
+
{
|
|
23
|
+
inputs: [],
|
|
24
|
+
params: { message: "this is test" },
|
|
25
|
+
result: { message: "this is test" },
|
|
26
|
+
},
|
|
27
|
+
],
|
|
22
28
|
description: "Stream mock agent",
|
|
23
|
-
category: [],
|
|
29
|
+
category: ["test"],
|
|
24
30
|
author: "Isamu Arimoto",
|
|
25
31
|
repository: "https://github.com/receptron/graphai",
|
|
26
32
|
license: "MIT",
|
|
33
|
+
stream: true,
|
|
27
34
|
};
|
|
28
35
|
exports.default = streamMockAgentInfo;
|
|
@@ -4,6 +4,5 @@ export * from "./matrix_agents/vanilla";
|
|
|
4
4
|
export * from "./test_agents/vanilla";
|
|
5
5
|
export * from "./graph_agents/vanilla";
|
|
6
6
|
export * from "./data_agents/vanilla";
|
|
7
|
-
import functionAgent from "./function_agent";
|
|
8
7
|
import stringEmbeddingsAgent from "./embedding_agent";
|
|
9
|
-
export {
|
|
8
|
+
export { stringEmbeddingsAgent };
|
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.stringEmbeddingsAgent =
|
|
21
|
+
exports.stringEmbeddingsAgent = void 0;
|
|
22
22
|
// Please refrain from adding agents that require npm. Those should be added to the index.ts.
|
|
23
23
|
__exportStar(require("./string_agents/vanilla"), exports);
|
|
24
24
|
__exportStar(require("./array_agents/vanilla"), exports);
|
|
@@ -26,7 +26,5 @@ __exportStar(require("./matrix_agents/vanilla"), exports);
|
|
|
26
26
|
__exportStar(require("./test_agents/vanilla"), exports);
|
|
27
27
|
__exportStar(require("./graph_agents/vanilla"), exports);
|
|
28
28
|
__exportStar(require("./data_agents/vanilla"), exports);
|
|
29
|
-
const function_agent_1 = __importDefault(require("./function_agent"));
|
|
30
|
-
exports.functionAgent = function_agent_1.default;
|
|
31
29
|
const embedding_agent_1 = __importDefault(require("./embedding_agent"));
|
|
32
30
|
exports.stringEmbeddingsAgent = embedding_agent_1.default;
|
package/lib/graphai.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentFunctionInfoDictionary, AgentFilterInfo, GraphData, DataSource, ResultDataDictionary, ResultData, DefaultResultData } from "./type";
|
|
2
2
|
import { TransactionLog } from "./transaction_log";
|
|
3
3
|
import { ComputedNode, StaticNode } from "./node";
|
|
4
4
|
import { TaskManager } from "./task_manager";
|
|
@@ -9,7 +9,7 @@ export declare class GraphAI {
|
|
|
9
9
|
private readonly data;
|
|
10
10
|
private readonly loop?;
|
|
11
11
|
private readonly logs;
|
|
12
|
-
readonly agentFunctionInfoDictionary:
|
|
12
|
+
readonly agentFunctionInfoDictionary: AgentFunctionInfoDictionary;
|
|
13
13
|
readonly taskManager: TaskManager;
|
|
14
14
|
readonly agentFilters: AgentFilterInfo[];
|
|
15
15
|
readonly retryLimit?: number;
|
|
@@ -21,19 +21,19 @@ export declare class GraphAI {
|
|
|
21
21
|
private createNodes;
|
|
22
22
|
private getValueFromResults;
|
|
23
23
|
private initializeNodes;
|
|
24
|
-
constructor(data: GraphData, agentFunctionInfoDictionary:
|
|
24
|
+
constructor(data: GraphData, agentFunctionInfoDictionary: AgentFunctionInfoDictionary, options?: {
|
|
25
25
|
agentFilters?: AgentFilterInfo[] | undefined;
|
|
26
26
|
taskManager?: TaskManager | undefined;
|
|
27
27
|
});
|
|
28
28
|
getAgentFunctionInfo(agentId?: string): import("./type").AgentFunctionInfo;
|
|
29
29
|
asString(): string;
|
|
30
|
-
results<T = DefaultResultData>(all: boolean):
|
|
30
|
+
results<T = DefaultResultData>(all: boolean): ResultDataDictionary<T>;
|
|
31
31
|
errors(): Record<string, Error>;
|
|
32
32
|
private pushReadyNodesIntoQueue;
|
|
33
33
|
private pushQueueIfReady;
|
|
34
34
|
pushQueueIfReadyAndRunning(node: ComputedNode): void;
|
|
35
35
|
pushQueue(node: ComputedNode): void;
|
|
36
|
-
run<T = DefaultResultData>(all?: boolean): Promise<
|
|
36
|
+
run<T = DefaultResultData>(all?: boolean): Promise<ResultDataDictionary<T>>;
|
|
37
37
|
isRunning(): boolean;
|
|
38
38
|
onExecutionComplete(node: ComputedNode): void;
|
|
39
39
|
private processLoopIfNecessary;
|
package/lib/graphai.js
CHANGED
|
@@ -20,7 +20,7 @@ class GraphAI {
|
|
|
20
20
|
_nodes[nodeId] = new node_1.ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
-
throw new Error("Unknown node: " + nodeId);
|
|
23
|
+
throw new Error("Unknown node type (neither value nor agent): " + nodeId);
|
|
24
24
|
}
|
|
25
25
|
return _nodes;
|
|
26
26
|
}, {});
|
|
@@ -33,7 +33,7 @@ class GraphAI {
|
|
|
33
33
|
nodes[pending].waitlist.add(nodeId); // previousNode
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
|
|
36
|
+
throw new Error(`createNode: invalid input ${pending} for node, ${nodeId}`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -68,11 +68,11 @@ class GraphAI {
|
|
|
68
68
|
this.onLogCallback = (__log, __isUpdate) => { };
|
|
69
69
|
this.repeatCount = 0;
|
|
70
70
|
if (!data.version && !options.taskManager) {
|
|
71
|
-
console.
|
|
71
|
+
console.warn("------------ missing version number");
|
|
72
72
|
}
|
|
73
73
|
this.version = data.version ?? latestVersion;
|
|
74
74
|
if (this.version < latestVersion) {
|
|
75
|
-
console.
|
|
75
|
+
console.warn(`------------ upgrade to ${latestVersion}!`);
|
|
76
76
|
}
|
|
77
77
|
this.retryLimit = data.retry; // optional
|
|
78
78
|
this.graphId = URL.createObjectURL(new Blob()).slice(-36);
|
|
@@ -83,7 +83,7 @@ class GraphAI {
|
|
|
83
83
|
this.loop = data.loop;
|
|
84
84
|
this.verbose = data.verbose === true;
|
|
85
85
|
this.onComplete = () => {
|
|
86
|
-
|
|
86
|
+
throw new Error("SOMETHING IS WRONG: onComplete is called without run()");
|
|
87
87
|
};
|
|
88
88
|
(0, validator_1.validateGraphData)(data, Object.keys(agentFunctionInfoDictionary));
|
|
89
89
|
this.nodes = this.createNodes(data);
|
|
@@ -93,6 +93,7 @@ class GraphAI {
|
|
|
93
93
|
if (agentId && this.agentFunctionInfoDictionary[agentId]) {
|
|
94
94
|
return this.agentFunctionInfoDictionary[agentId];
|
|
95
95
|
}
|
|
96
|
+
// We are not supposed to hit this error because the validator will catch it.
|
|
96
97
|
throw new Error("No agent: " + agentId);
|
|
97
98
|
}
|
|
98
99
|
asString() {
|
|
@@ -154,7 +155,7 @@ class GraphAI {
|
|
|
154
155
|
// Public API
|
|
155
156
|
async run(all = false) {
|
|
156
157
|
if (this.isRunning()) {
|
|
157
|
-
|
|
158
|
+
throw new Error("This GraphUI instance is already running");
|
|
158
159
|
}
|
|
159
160
|
this.pushReadyNodesIntoQueue();
|
|
160
161
|
if (!this.isRunning()) {
|
|
@@ -201,7 +202,7 @@ class GraphAI {
|
|
|
201
202
|
const source = (0, utils_1.parseNodeName)(loop.while, this.version);
|
|
202
203
|
const value = this.getValueFromResults(source, this.results(true));
|
|
203
204
|
// NOTE: We treat an empty array as false.
|
|
204
|
-
if (
|
|
205
|
+
if (!(0, utils_1.isLogicallyTrue)(value)) {
|
|
205
206
|
return false; // while condition is not met
|
|
206
207
|
}
|
|
207
208
|
}
|
|
@@ -232,8 +233,7 @@ class GraphAI {
|
|
|
232
233
|
node.injectValue(value, injectFrom);
|
|
233
234
|
}
|
|
234
235
|
else {
|
|
235
|
-
|
|
236
|
-
console.error("InjectionTo can only specify static nodes");
|
|
236
|
+
throw new Error(`injectValue with Invalid nodeId, ${nodeId}`);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
resultsOf(sources) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { GraphAI } from "./graphai";
|
|
2
|
-
export { AgentFunction, AgentFunctionInfo,
|
|
2
|
+
export { AgentFunction, AgentFunctionInfo, AgentFunctionInfoDictionary, AgentFunctionContext, GraphData, ResultDataDictionary, ResultData, NodeState, AgentFilterFunction, AgentFilterInfo, } from "./type";
|
|
3
3
|
export type { TransactionLog } from "./transaction_log";
|
|
4
|
+
export { agentFilterRunnerBuilder } from "./utils/runner";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeState = exports.GraphAI = void 0;
|
|
3
|
+
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");
|
|
7
7
|
Object.defineProperty(exports, "NodeState", { enumerable: true, get: function () { return type_1.NodeState; } });
|
|
8
|
+
var runner_1 = require("./utils/runner");
|
|
9
|
+
Object.defineProperty(exports, "agentFilterRunnerBuilder", { enumerable: true, get: function () { return runner_1.agentFilterRunnerBuilder; } });
|
package/lib/node.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class ComputedNode extends Node {
|
|
|
18
18
|
readonly params: NodeDataParams;
|
|
19
19
|
private readonly filterParams;
|
|
20
20
|
private readonly dynamicParams;
|
|
21
|
-
readonly nestedGraph?: GraphData;
|
|
21
|
+
readonly nestedGraph?: GraphData | DataSource;
|
|
22
22
|
readonly retryLimit: number;
|
|
23
23
|
retryCount: number;
|
|
24
24
|
private readonly agentId?;
|
|
@@ -31,6 +31,7 @@ export declare class ComputedNode extends Node {
|
|
|
31
31
|
dataSources: Array<DataSource>;
|
|
32
32
|
pendings: Set<string>;
|
|
33
33
|
private ifSource?;
|
|
34
|
+
private unlessSource?;
|
|
34
35
|
private console;
|
|
35
36
|
readonly isStaticNode = false;
|
|
36
37
|
readonly isComputedNode = true;
|
package/lib/node.js
CHANGED
|
@@ -40,7 +40,6 @@ class ComputedNode extends Node {
|
|
|
40
40
|
this.params = data.params ?? {};
|
|
41
41
|
this.console = data.console ?? {};
|
|
42
42
|
this.filterParams = data.filterParams ?? {};
|
|
43
|
-
this.nestedGraph = data.graph;
|
|
44
43
|
if (typeof data.agent === "string") {
|
|
45
44
|
this.agentId = data.agent;
|
|
46
45
|
}
|
|
@@ -58,11 +57,25 @@ class ComputedNode extends Node {
|
|
|
58
57
|
this.anyInput = data.anyInput ?? false;
|
|
59
58
|
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input, graph.version));
|
|
60
59
|
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
|
60
|
+
if (typeof data.graph === "string") {
|
|
61
|
+
const source = (0, utils_2.parseNodeName)(data.graph, graph.version);
|
|
62
|
+
(0, utils_2.assert)(!!source.nodeId, `Invalid data source ${data.graph}`);
|
|
63
|
+
this.pendings.add(source.nodeId);
|
|
64
|
+
this.nestedGraph = source;
|
|
65
|
+
}
|
|
66
|
+
else if (data.graph) {
|
|
67
|
+
this.nestedGraph = data.graph;
|
|
68
|
+
}
|
|
61
69
|
if (data.if) {
|
|
62
70
|
this.ifSource = (0, utils_2.parseNodeName)(data.if, graph.version);
|
|
63
71
|
(0, utils_2.assert)(!!this.ifSource.nodeId, `Invalid data source ${data.if}`);
|
|
64
72
|
this.pendings.add(this.ifSource.nodeId);
|
|
65
73
|
}
|
|
74
|
+
if (data.unless) {
|
|
75
|
+
this.unlessSource = (0, utils_2.parseNodeName)(data.unless, graph.version);
|
|
76
|
+
(0, utils_2.assert)(!!this.unlessSource.nodeId, `Invalid data source ${data.unless}`);
|
|
77
|
+
this.pendings.add(this.unlessSource.nodeId);
|
|
78
|
+
}
|
|
66
79
|
this.dynamicParams = Object.keys(this.params).reduce((tmp, key) => {
|
|
67
80
|
const dataSource = (0, utils_2.parseNodeName)(this.params[key], graph.version < 0.3 ? 0.3 : graph.version);
|
|
68
81
|
if (dataSource.nodeId) {
|
|
@@ -89,12 +102,19 @@ class ComputedNode extends Node {
|
|
|
89
102
|
if (!this.anyInput || counter > 0) {
|
|
90
103
|
if (this.ifSource) {
|
|
91
104
|
const [condition] = this.graph.resultsOf([this.ifSource]);
|
|
92
|
-
if (!condition) {
|
|
105
|
+
if (!(0, utils_2.isLogicallyTrue)(condition)) {
|
|
106
|
+
this.state = type_1.NodeState.Skipped;
|
|
107
|
+
this.log.onSkipped(this, this.graph);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (this.unlessSource) {
|
|
112
|
+
const [condition] = this.graph.resultsOf([this.unlessSource]);
|
|
113
|
+
if ((0, utils_2.isLogicallyTrue)(condition)) {
|
|
93
114
|
this.state = type_1.NodeState.Skipped;
|
|
94
115
|
this.log.onSkipped(this, this.graph);
|
|
95
116
|
return false;
|
|
96
117
|
}
|
|
97
|
-
return true;
|
|
98
118
|
}
|
|
99
119
|
return true;
|
|
100
120
|
}
|
|
@@ -150,7 +170,7 @@ class ComputedNode extends Node {
|
|
|
150
170
|
// and attempt to retry (if specified).
|
|
151
171
|
executeTimeout(transactionId) {
|
|
152
172
|
if (this.state === type_1.NodeState.Executing && this.isCurrentTransaction(transactionId)) {
|
|
153
|
-
console.
|
|
173
|
+
console.warn(`-- timeout ${this.timeout} with ${this.nodeId}`);
|
|
154
174
|
this.retry(type_1.NodeState.TimedOut, Error("Timeout"));
|
|
155
175
|
}
|
|
156
176
|
}
|
|
@@ -227,7 +247,13 @@ class ComputedNode extends Node {
|
|
|
227
247
|
if (this.nestedGraph) {
|
|
228
248
|
this.graph.taskManager.prepareForNesting();
|
|
229
249
|
context.taskManager = this.graph.taskManager;
|
|
230
|
-
|
|
250
|
+
if ("nodes" in this.nestedGraph) {
|
|
251
|
+
context.graphData = this.nestedGraph;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const [graphData] = this.graph.resultsOf([this.nestedGraph]);
|
|
255
|
+
context.graphData = graphData; // HACK: compiler work-around
|
|
256
|
+
}
|
|
231
257
|
context.agents = this.graph.agentFunctionInfoDictionary;
|
|
232
258
|
}
|
|
233
259
|
if (this.console.before) {
|
|
@@ -243,7 +269,7 @@ class ComputedNode extends Node {
|
|
|
243
269
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
244
270
|
// This condition happens when the agent function returns
|
|
245
271
|
// after the timeout (either retried or not).
|
|
246
|
-
console.log(`-- ${this.nodeId}
|
|
272
|
+
console.log(`-- transactionId mismatch with ${this.nodeId} (probably timeout)`);
|
|
247
273
|
return;
|
|
248
274
|
}
|
|
249
275
|
this.state = type_1.NodeState.Completed;
|
|
@@ -268,19 +294,19 @@ class ComputedNode extends Node {
|
|
|
268
294
|
// the retry if specified.
|
|
269
295
|
errorProcess(error, transactionId) {
|
|
270
296
|
if (error instanceof Error && error.message !== utils_1.strIntentionalError) {
|
|
271
|
-
console.error(`<-- ${this.nodeId}, ${this.agentId}`);
|
|
272
|
-
console.
|
|
273
|
-
console.
|
|
297
|
+
console.error(`<-- NodeId: ${this.nodeId}, Agent: ${this.agentId}`);
|
|
298
|
+
console.error(error);
|
|
299
|
+
console.error("-->");
|
|
274
300
|
}
|
|
275
301
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
276
|
-
console.
|
|
302
|
+
console.warn(`-- transactionId mismatch with ${this.nodeId} (not timeout)`);
|
|
277
303
|
return;
|
|
278
304
|
}
|
|
279
305
|
if (error instanceof Error) {
|
|
280
306
|
this.retry(type_1.NodeState.Failed, error);
|
|
281
307
|
}
|
|
282
308
|
else {
|
|
283
|
-
console.error(`-- ${this.nodeId}:
|
|
309
|
+
console.error(`-- NodeId: ${this.nodeId}: Unknown error was caught`);
|
|
284
310
|
this.retry(type_1.NodeState.Failed, Error("Unknown"));
|
|
285
311
|
}
|
|
286
312
|
}
|
package/lib/transaction_log.d.ts
CHANGED
package/lib/transaction_log.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionLog = void 0;
|
|
4
4
|
const type_1 = require("./type");
|
|
5
|
+
const utils_1 = require("./utils/utils");
|
|
5
6
|
class TransactionLog {
|
|
6
7
|
constructor(nodeId) {
|
|
7
8
|
this.nodeId = nodeId;
|
|
@@ -29,6 +30,7 @@ class TransactionLog {
|
|
|
29
30
|
}
|
|
30
31
|
onComplete(node, graph, localLog) {
|
|
31
32
|
this.result = node.result;
|
|
33
|
+
this.resultKeys = (0, utils_1.debugResultKey)(this.agentId || "", node.result);
|
|
32
34
|
this.state = node.state;
|
|
33
35
|
this.endTime = Date.now();
|
|
34
36
|
graph.setLoopLog(this);
|
package/lib/type.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare enum NodeState {
|
|
|
13
13
|
export type DefaultResultData = Record<string, any> | string | number | boolean | Array<DefaultResultData>;
|
|
14
14
|
export type DefaultInputData = Record<string, any>;
|
|
15
15
|
export type ResultData<ResultType = DefaultResultData> = ResultType | undefined;
|
|
16
|
-
export type
|
|
16
|
+
export type ResultDataDictionary<ResultType = DefaultResultData> = Record<string, ResultData<ResultType>>;
|
|
17
17
|
export type DefaultParamsType = Record<string, any>;
|
|
18
18
|
export type NodeDataParams<ParamsType = DefaultParamsType> = ParamsType;
|
|
19
19
|
export type DataSource = {
|
|
@@ -26,10 +26,10 @@ export type StaticNodeData = {
|
|
|
26
26
|
update?: string;
|
|
27
27
|
isResult?: boolean;
|
|
28
28
|
};
|
|
29
|
-
export type
|
|
29
|
+
export type AgentAnonymousFunction = (...params: any[]) => unknown;
|
|
30
30
|
export type AgentFilterParams = Record<string, any>;
|
|
31
31
|
export type ComputedNodeData = {
|
|
32
|
-
agent: string |
|
|
32
|
+
agent: string | AgentAnonymousFunction;
|
|
33
33
|
inputs?: Array<any>;
|
|
34
34
|
anyInput?: boolean;
|
|
35
35
|
params?: NodeDataParams;
|
|
@@ -37,7 +37,8 @@ export type ComputedNodeData = {
|
|
|
37
37
|
retry?: number;
|
|
38
38
|
timeout?: number;
|
|
39
39
|
if?: string;
|
|
40
|
-
|
|
40
|
+
unless?: string;
|
|
41
|
+
graph?: GraphData | string;
|
|
41
42
|
isResult?: boolean;
|
|
42
43
|
priority?: number;
|
|
43
44
|
console?: Record<string, string | boolean>;
|
|
@@ -65,7 +66,7 @@ export type AgentFunctionContext<ParamsType = DefaultParamsType, InputDataType =
|
|
|
65
66
|
agentId?: string;
|
|
66
67
|
};
|
|
67
68
|
graphData?: GraphData | string;
|
|
68
|
-
agents?:
|
|
69
|
+
agents?: AgentFunctionInfoDictionary;
|
|
69
70
|
taskManager?: TaskManager;
|
|
70
71
|
filterParams: AgentFilterParams;
|
|
71
72
|
agentFilters?: AgentFilterInfo[];
|
|
@@ -88,6 +89,7 @@ export type AgentFunctionInfo = {
|
|
|
88
89
|
inputs: any;
|
|
89
90
|
params: DefaultParamsType;
|
|
90
91
|
result: any;
|
|
92
|
+
graph?: GraphData;
|
|
91
93
|
}[];
|
|
92
94
|
skipTest?: boolean;
|
|
93
95
|
description: string;
|
|
@@ -95,5 +97,8 @@ export type AgentFunctionInfo = {
|
|
|
95
97
|
author: string;
|
|
96
98
|
repository: string;
|
|
97
99
|
license: string;
|
|
100
|
+
stream?: boolean;
|
|
101
|
+
apiKeys?: string[];
|
|
102
|
+
npms?: string[];
|
|
98
103
|
};
|
|
99
|
-
export type
|
|
104
|
+
export type AgentFunctionInfoDictionary = Record<string, AgentFunctionInfo>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentFilterRunnerBuilder = void 0;
|
|
4
|
+
// for test and server.
|
|
5
|
+
const agentFilterRunnerBuilder = (__agentFilters) => {
|
|
6
|
+
const agentFilters = __agentFilters;
|
|
7
|
+
const agentFilterRunner = (context, agent) => {
|
|
8
|
+
let index = 0;
|
|
9
|
+
const next = (context) => {
|
|
10
|
+
const agentFilter = agentFilters[index++];
|
|
11
|
+
if (agentFilter) {
|
|
12
|
+
return agentFilter.agent(context, next);
|
|
13
|
+
}
|
|
14
|
+
return agent(context);
|
|
15
|
+
};
|
|
16
|
+
return next(context);
|
|
17
|
+
};
|
|
18
|
+
return agentFilterRunner;
|
|
19
|
+
};
|
|
20
|
+
exports.agentFilterRunnerBuilder = agentFilterRunnerBuilder;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const defaultTestAgents:
|
|
1
|
+
import { AgentFunctionInfoDictionary } from "../index";
|
|
2
|
+
export declare const defaultTestAgents: AgentFunctionInfoDictionary;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import { AgentFunctionInfo
|
|
2
|
-
export declare const getAgentInfo: (agent: AgentFunction<any, any, any>) => {
|
|
3
|
-
name: string;
|
|
4
|
-
samples: {
|
|
5
|
-
inputs: never[];
|
|
6
|
-
params: {};
|
|
7
|
-
result: {};
|
|
8
|
-
}[];
|
|
9
|
-
description: string;
|
|
10
|
-
category: never[];
|
|
11
|
-
author: string;
|
|
12
|
-
repository: string;
|
|
13
|
-
license: string;
|
|
14
|
-
agent: AgentFunction<any, any, any>;
|
|
15
|
-
mock: AgentFunction<any, any, any>;
|
|
16
|
-
};
|
|
1
|
+
import { AgentFunctionInfo } from "../type";
|
|
17
2
|
export declare const defaultTestContext: {
|
|
18
3
|
debugInfo: {
|
|
19
4
|
nodeId: string;
|
|
@@ -26,4 +11,3 @@ export declare const defaultTestContext: {
|
|
|
26
11
|
log: never[];
|
|
27
12
|
};
|
|
28
13
|
export declare const agentTestRunner: (agentInfo: AgentFunctionInfo) => Promise<void>;
|
|
29
|
-
export declare const agentFilterRunnerBuilder: (__agentFilters: AgentFilterInfo[]) => (context: AgentFunctionContext, agent: AgentFunction) => Promise<ResultData>;
|
package/lib/utils/test_utils.js
CHANGED
|
@@ -3,11 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const utils_1 = require("../utils/utils");
|
|
6
|
+
exports.agentTestRunner = exports.defaultTestContext = void 0;
|
|
8
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
8
|
const node_test_1 = __importDefault(require("node:test"));
|
|
10
|
-
exports.getAgentInfo = utils_1.agentInfoWrapper;
|
|
11
9
|
exports.defaultTestContext = {
|
|
12
10
|
debugInfo: {
|
|
13
11
|
nodeId: "test",
|
|
@@ -28,11 +26,12 @@ const agentTestRunner = async (agentInfo) => {
|
|
|
28
26
|
else {
|
|
29
27
|
for await (const sampleKey of samples.keys()) {
|
|
30
28
|
(0, node_test_1.default)(`test ${agentInfo.name} ${sampleKey}`, async () => {
|
|
31
|
-
const { params, inputs, result } = samples[sampleKey];
|
|
29
|
+
const { params, inputs, result, graph } = samples[sampleKey];
|
|
32
30
|
const actual = await agent({
|
|
33
31
|
...exports.defaultTestContext,
|
|
34
32
|
params,
|
|
35
33
|
inputs,
|
|
34
|
+
graphData: graph,
|
|
36
35
|
});
|
|
37
36
|
node_assert_1.default.deepStrictEqual(actual, result);
|
|
38
37
|
});
|
|
@@ -40,20 +39,3 @@ const agentTestRunner = async (agentInfo) => {
|
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
41
|
exports.agentTestRunner = agentTestRunner;
|
|
43
|
-
// for agent and agent filter.
|
|
44
|
-
const agentFilterRunnerBuilder = (__agentFilters) => {
|
|
45
|
-
const agentFilters = __agentFilters;
|
|
46
|
-
const agentFilterRunner = (context, agent) => {
|
|
47
|
-
let index = 0;
|
|
48
|
-
const next = (context) => {
|
|
49
|
-
const agentFilter = agentFilters[index++];
|
|
50
|
-
if (agentFilter) {
|
|
51
|
-
return agentFilter.agent(context, next);
|
|
52
|
-
}
|
|
53
|
-
return agent(context);
|
|
54
|
-
};
|
|
55
|
-
return next(context);
|
|
56
|
-
};
|
|
57
|
-
return agentFilterRunner;
|
|
58
|
-
};
|
|
59
|
-
exports.agentFilterRunnerBuilder = agentFilterRunnerBuilder;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -33,3 +33,5 @@ export declare const agentInfoWrapper: (agent: AgentFunction<any, any, any>) =>
|
|
|
33
33
|
agent: AgentFunction<any, any, any>;
|
|
34
34
|
mock: AgentFunction<any, any, any>;
|
|
35
35
|
};
|
|
36
|
+
export declare const debugResultKey: (agentId: string, result: any) => string[];
|
|
37
|
+
export declare const isLogicallyTrue: (value: any) => boolean;
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.agentInfoWrapper = exports.defaultAgentInfo = exports.strIntentionalError = exports.getDataFromSource = exports.isObject = exports.assert = exports.parseNodeName = exports.sleep = void 0;
|
|
3
|
+
exports.isLogicallyTrue = exports.debugResultKey = exports.agentInfoWrapper = exports.defaultAgentInfo = 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
|
};
|
|
@@ -109,3 +109,47 @@ const agentInfoWrapper = (agent) => {
|
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
111
|
exports.agentInfoWrapper = agentInfoWrapper;
|
|
112
|
+
const objectToKeyArray = (innerData) => {
|
|
113
|
+
const ret = [];
|
|
114
|
+
Object.keys(innerData).forEach((key) => {
|
|
115
|
+
ret.push([key]);
|
|
116
|
+
if (Object.keys(innerData[key]).length > 0) {
|
|
117
|
+
objectToKeyArray(innerData[key]).forEach((tmp) => {
|
|
118
|
+
ret.push([key, ...tmp]);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return ret;
|
|
123
|
+
};
|
|
124
|
+
const debugResultKey = (agentId, result) => {
|
|
125
|
+
return objectToKeyArray({ [agentId]: debugResultKeyInner(result) }).map((objectKeys) => {
|
|
126
|
+
return ":" + objectKeys.join(".");
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
exports.debugResultKey = debugResultKey;
|
|
130
|
+
const debugResultKeyInner = (result) => {
|
|
131
|
+
if (result === null || result === undefined) {
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
if (typeof result === "string") {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(result)) {
|
|
138
|
+
return Array.from(result.keys()).reduce((tmp, index) => {
|
|
139
|
+
tmp["$" + String(index)] = debugResultKeyInner(result[index]);
|
|
140
|
+
return tmp;
|
|
141
|
+
}, {});
|
|
142
|
+
}
|
|
143
|
+
return Object.keys(result).reduce((tmp, key) => {
|
|
144
|
+
tmp[key] = debugResultKeyInner(result[key]);
|
|
145
|
+
return tmp;
|
|
146
|
+
}, {});
|
|
147
|
+
};
|
|
148
|
+
const isLogicallyTrue = (value) => {
|
|
149
|
+
// Notice that empty aray is not true under GraphAI
|
|
150
|
+
if (Array.isArray(value) ? value.length === 0 : !value) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
exports.isLogicallyTrue = isLogicallyTrue;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.agentValidator = void 0;
|
|
4
|
+
const common_1 = require("../validators/common");
|
|
4
5
|
const agentValidator = (graphAgentIds, agentIds) => {
|
|
5
6
|
graphAgentIds.forEach((agentId) => {
|
|
6
7
|
if (!agentIds.has(agentId)) {
|
|
7
|
-
throw new
|
|
8
|
+
throw new common_1.ValidationError("Invalid Agent : " + agentId + " is not in AgentFunctionInfoDictionary.");
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
return true;
|
package/lib/validators/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
3
|
+
exports.ValidationError = exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
4
|
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"];
|
|
5
5
|
exports.computedNodeAttributeKeys = [
|
|
6
6
|
"inputs",
|
|
@@ -13,7 +13,16 @@ exports.computedNodeAttributeKeys = [
|
|
|
13
13
|
"isResult",
|
|
14
14
|
"priority",
|
|
15
15
|
"if",
|
|
16
|
+
"unless",
|
|
16
17
|
"filterParams",
|
|
17
18
|
"console",
|
|
18
19
|
];
|
|
19
20
|
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|
|
21
|
+
class ValidationError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(`\x1b[41m${message}\x1b[0m`); // Pass the message to the base Error class
|
|
24
|
+
// Set the prototype explicitly to ensure correct prototype chain
|
|
25
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ValidationError = ValidationError;
|
|
@@ -5,7 +5,7 @@ const common_1 = require("../validators/common");
|
|
|
5
5
|
const computedNodeValidator = (nodeData) => {
|
|
6
6
|
Object.keys(nodeData).forEach((key) => {
|
|
7
7
|
if (!common_1.computedNodeAttributeKeys.includes(key)) {
|
|
8
|
-
throw new
|
|
8
|
+
throw new common_1.ValidationError("Computed node does not allow " + key);
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
return true;
|