graphai 0.2.7 → 0.3.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 +130 -69
- package/lib/experimental_agents/data_agents/index.d.ts +0 -1
- package/lib/experimental_agents/data_agents/index.js +1 -3
- package/lib/experimental_agents/graph_agents/map_agent.js +1 -1
- package/lib/experimental_agents/graph_agents/nested_agent.js +7 -16
- package/lib/experimental_agents/index.d.ts +2 -8
- package/lib/experimental_agents/index.js +5 -8
- package/lib/experimental_agents/llm_agents/groq_agent.d.ts +22 -6
- package/lib/experimental_agents/llm_agents/groq_agent.js +51 -17
- package/lib/experimental_agents/llm_agents/packages.d.ts +2 -2
- package/lib/experimental_agents/llm_agents/packages.js +2 -2
- package/lib/experimental_agents/packages.d.ts +1 -0
- package/lib/experimental_agents/packages.js +1 -0
- package/lib/experimental_agents/service_agents/fetch_agent.d.ts +62 -0
- package/lib/experimental_agents/service_agents/fetch_agent.js +95 -0
- package/lib/experimental_agents/service_agents/index.d.ts +1 -1
- package/lib/experimental_agents/service_agents/index.js +3 -3
- package/lib/experimental_agents/service_agents/packages.d.ts +2 -0
- package/lib/experimental_agents/service_agents/packages.js +8 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +4 -1
- package/lib/experimental_agents/vanilla.d.ts +8 -0
- package/lib/experimental_agents/vanilla.js +26 -0
- package/lib/graphai.d.ts +1 -1
- package/lib/graphai.js +6 -5
- package/lib/node.d.ts +2 -0
- package/lib/node.js +35 -5
- package/lib/transaction_log.d.ts +1 -0
- package/lib/transaction_log.js +5 -0
- package/lib/type.d.ts +8 -4
- package/lib/type.js +1 -0
- package/lib/utils/test_utils.d.ts +3 -1
- package/lib/utils/test_utils.js +19 -1
- package/lib/utils/utils.d.ts +1 -1
- package/lib/utils/utils.js +19 -1
- package/lib/validators/common.js +1 -1
- package/lib/validators/relation_validator.js +2 -2
- package/lib/vanilla_agents.d.ts +1 -0
- package/lib/vanilla_agents.js +17 -0
- package/package.json +1 -1
- package/lib/experimental_agents/service_agents/rss_agent.d.ts +0 -13
- package/lib/experimental_agents/service_agents/rss_agent.js +0 -29
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const fetchAgent: AgentFunction<{
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
type?: string;
|
|
5
|
+
returnErrorResult?: boolean;
|
|
6
|
+
}, any, any>;
|
|
7
|
+
declare const fetchAgentInfo: {
|
|
8
|
+
name: string;
|
|
9
|
+
agent: AgentFunction<{
|
|
10
|
+
debug?: boolean | undefined;
|
|
11
|
+
type?: string | undefined;
|
|
12
|
+
returnErrorResult?: boolean | undefined;
|
|
13
|
+
}, any, any>;
|
|
14
|
+
mock: AgentFunction<{
|
|
15
|
+
debug?: boolean | undefined;
|
|
16
|
+
type?: string | undefined;
|
|
17
|
+
returnErrorResult?: boolean | undefined;
|
|
18
|
+
}, any, any>;
|
|
19
|
+
samples: ({
|
|
20
|
+
inputs: (string | {
|
|
21
|
+
foo: string;
|
|
22
|
+
"x-myHeader"?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
"x-myHeader": string;
|
|
25
|
+
foo?: undefined;
|
|
26
|
+
})[];
|
|
27
|
+
params: {
|
|
28
|
+
debug: boolean;
|
|
29
|
+
};
|
|
30
|
+
result: {
|
|
31
|
+
method: string;
|
|
32
|
+
url: string;
|
|
33
|
+
headers: {
|
|
34
|
+
"x-myHeader": string;
|
|
35
|
+
"Content-Type"?: undefined;
|
|
36
|
+
};
|
|
37
|
+
body: undefined;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
inputs: (string | {
|
|
41
|
+
foo: string;
|
|
42
|
+
} | undefined)[];
|
|
43
|
+
params: {
|
|
44
|
+
debug: boolean;
|
|
45
|
+
};
|
|
46
|
+
result: {
|
|
47
|
+
method: string;
|
|
48
|
+
url: string;
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": string;
|
|
51
|
+
"x-myHeader"?: undefined;
|
|
52
|
+
};
|
|
53
|
+
body: string;
|
|
54
|
+
};
|
|
55
|
+
})[];
|
|
56
|
+
description: string;
|
|
57
|
+
category: string[];
|
|
58
|
+
author: string;
|
|
59
|
+
repository: string;
|
|
60
|
+
license: string;
|
|
61
|
+
};
|
|
62
|
+
export default fetchAgentInfo;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchAgent = void 0;
|
|
4
|
+
const xml2js_1 = require("xml2js");
|
|
5
|
+
const fetchAgent = async ({ inputs, params }) => {
|
|
6
|
+
const [baseUrl, queryParams, baseHeaders, body] = inputs;
|
|
7
|
+
const url = new URL(baseUrl);
|
|
8
|
+
const headers = baseHeaders ? { ...baseHeaders } : {};
|
|
9
|
+
if (queryParams) {
|
|
10
|
+
const params = new URLSearchParams(queryParams);
|
|
11
|
+
url.search = params.toString();
|
|
12
|
+
}
|
|
13
|
+
if (body) {
|
|
14
|
+
headers["Content-Type"] = "application/json";
|
|
15
|
+
}
|
|
16
|
+
const fetchOptions = {
|
|
17
|
+
method: body ? "POST" : "GET",
|
|
18
|
+
headers: new Headers(headers),
|
|
19
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
20
|
+
};
|
|
21
|
+
if (params?.debug) {
|
|
22
|
+
return {
|
|
23
|
+
url: url.toString(),
|
|
24
|
+
method: fetchOptions.method,
|
|
25
|
+
headers,
|
|
26
|
+
body: fetchOptions.body,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const response = await fetch(url.toString(), fetchOptions);
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const status = response.status;
|
|
32
|
+
const error = await response.text();
|
|
33
|
+
if (params?.returnErrorResult) {
|
|
34
|
+
return { status, error };
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`HTTP error! Status: ${status} ${error} ${url.toString()}`);
|
|
37
|
+
}
|
|
38
|
+
const result = await (async () => {
|
|
39
|
+
const type = params?.type ?? "json";
|
|
40
|
+
if (type === "json") {
|
|
41
|
+
return await response.json();
|
|
42
|
+
}
|
|
43
|
+
else if (type === "xml") {
|
|
44
|
+
const xmlData = await response.text();
|
|
45
|
+
return await (0, xml2js_1.parseStringPromise)(xmlData, { explicitArray: false, mergeAttrs: true });
|
|
46
|
+
}
|
|
47
|
+
else if (type === "text") {
|
|
48
|
+
return response.text();
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Unknown Type! ${type}`);
|
|
51
|
+
})();
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
exports.fetchAgent = fetchAgent;
|
|
55
|
+
const fetchAgentInfo = {
|
|
56
|
+
name: "fetchAgent",
|
|
57
|
+
agent: exports.fetchAgent,
|
|
58
|
+
mock: exports.fetchAgent,
|
|
59
|
+
samples: [
|
|
60
|
+
{
|
|
61
|
+
inputs: ["https://www.google.com", { foo: "bar" }, { "x-myHeader": "secret" }],
|
|
62
|
+
params: {
|
|
63
|
+
debug: true,
|
|
64
|
+
},
|
|
65
|
+
result: {
|
|
66
|
+
method: "GET",
|
|
67
|
+
url: "https://www.google.com/?foo=bar",
|
|
68
|
+
headers: {
|
|
69
|
+
"x-myHeader": "secret",
|
|
70
|
+
},
|
|
71
|
+
body: undefined,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
inputs: ["https://www.google.com", undefined, undefined, { foo: "bar" }],
|
|
76
|
+
params: {
|
|
77
|
+
debug: true,
|
|
78
|
+
},
|
|
79
|
+
result: {
|
|
80
|
+
method: "POST",
|
|
81
|
+
url: "https://www.google.com/",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
},
|
|
85
|
+
body: "{\"foo\":\"bar\"}",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
description: "Retrieves JSON data from the specified URL",
|
|
90
|
+
category: ["data"],
|
|
91
|
+
author: "Receptron",
|
|
92
|
+
repository: "https://github.com/receptron/graphai",
|
|
93
|
+
license: "MIT",
|
|
94
|
+
};
|
|
95
|
+
exports.default = fetchAgentInfo;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { wikipediaAgent } from "../../experimental_agents/service_agents/wikipedia";
|
|
2
|
-
export {
|
|
2
|
+
export { fetchAgent } from "../../experimental_agents/service_agents/fetch_agent";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fetchAgent = exports.wikipediaAgent = void 0;
|
|
4
4
|
var wikipedia_1 = require("../../experimental_agents/service_agents/wikipedia");
|
|
5
5
|
Object.defineProperty(exports, "wikipediaAgent", { enumerable: true, get: function () { return wikipedia_1.wikipediaAgent; } });
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
6
|
+
var fetch_agent_1 = require("../../experimental_agents/service_agents/fetch_agent");
|
|
7
|
+
Object.defineProperty(exports, "fetchAgent", { enumerable: true, get: function () { return fetch_agent_1.fetchAgent; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
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.fetchAgent = void 0;
|
|
7
|
+
const fetch_agent_1 = __importDefault(require("../../experimental_agents/service_agents/fetch_agent"));
|
|
8
|
+
exports.fetchAgent = fetch_agent_1.default;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.echoAgent = void 0;
|
|
4
|
-
const echoAgent = async ({ params }) => {
|
|
4
|
+
const echoAgent = async ({ params, filterParams }) => {
|
|
5
|
+
if (params.filterParams) {
|
|
6
|
+
return filterParams;
|
|
7
|
+
}
|
|
5
8
|
return params;
|
|
6
9
|
};
|
|
7
10
|
exports.echoAgent = echoAgent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./string_agents";
|
|
2
|
+
export * from "./array_agents";
|
|
3
|
+
export * from "./matrix_agents";
|
|
4
|
+
export * from "./test_agents";
|
|
5
|
+
export * from "./graph_agents";
|
|
6
|
+
export * from "./function_agent";
|
|
7
|
+
export * from "./embedding_agent";
|
|
8
|
+
export * from "./data_agents";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file adds agents that runs in pure JavaScript without any external npm modules.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
// Please refrain from adding agents that require npm. Those should be added to the index.ts.
|
|
19
|
+
__exportStar(require("./string_agents"), exports);
|
|
20
|
+
__exportStar(require("./array_agents"), exports);
|
|
21
|
+
__exportStar(require("./matrix_agents"), exports);
|
|
22
|
+
__exportStar(require("./test_agents"), exports);
|
|
23
|
+
__exportStar(require("./graph_agents"), exports);
|
|
24
|
+
__exportStar(require("./function_agent"), exports);
|
|
25
|
+
__exportStar(require("./embedding_agent"), exports);
|
|
26
|
+
__exportStar(require("./data_agents"), exports);
|
package/lib/graphai.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ComputedNode, StaticNode } from "./node";
|
|
|
5
5
|
import { TaskManager } from "./task_manager";
|
|
6
6
|
type GraphNodes = Record<string, ComputedNode | StaticNode>;
|
|
7
7
|
export declare class GraphAI {
|
|
8
|
-
|
|
8
|
+
readonly version: number;
|
|
9
9
|
private readonly graphId;
|
|
10
10
|
private readonly data;
|
|
11
11
|
private readonly loop?;
|
package/lib/graphai.js
CHANGED
|
@@ -40,7 +40,7 @@ class GraphAI {
|
|
|
40
40
|
return nodes;
|
|
41
41
|
}
|
|
42
42
|
getValueFromResults(key, results) {
|
|
43
|
-
const source = (0, utils_1.parseNodeName)(key);
|
|
43
|
+
const source = (0, utils_1.parseNodeName)(key, this.version);
|
|
44
44
|
return (0, utils_1.getDataFromSource)(source.nodeId ? results[source.nodeId] : undefined, source);
|
|
45
45
|
}
|
|
46
46
|
// for static
|
|
@@ -52,15 +52,13 @@ class GraphAI {
|
|
|
52
52
|
const node = this.nodes[nodeId];
|
|
53
53
|
if (node?.isStaticNode) {
|
|
54
54
|
const value = node?.value;
|
|
55
|
-
const update = node?.update;
|
|
56
55
|
if (value) {
|
|
57
56
|
this.injectValue(nodeId, value, nodeId);
|
|
58
57
|
}
|
|
58
|
+
const update = node?.update;
|
|
59
59
|
if (update && previousResults) {
|
|
60
60
|
const result = this.getValueFromResults(update, previousResults);
|
|
61
|
-
|
|
62
|
-
this.injectValue(nodeId, result, update);
|
|
63
|
-
}
|
|
61
|
+
this.injectValue(nodeId, result, update);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
});
|
|
@@ -73,6 +71,9 @@ class GraphAI {
|
|
|
73
71
|
console.log("------------ no version");
|
|
74
72
|
}
|
|
75
73
|
this.version = data.version ?? 0.2;
|
|
74
|
+
if (this.version < 0.3) {
|
|
75
|
+
console.log("------------ upgrade to 0.3!");
|
|
76
|
+
}
|
|
76
77
|
this.retryLimit = data.retry; // optional
|
|
77
78
|
this.graphId = URL.createObjectURL(new Blob()).slice(-36);
|
|
78
79
|
this.data = data;
|
package/lib/node.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class ComputedNode extends Node {
|
|
|
16
16
|
readonly graphId: string;
|
|
17
17
|
readonly isResult: boolean;
|
|
18
18
|
readonly params: NodeDataParams;
|
|
19
|
+
private readonly dynamicParams;
|
|
19
20
|
readonly nestedGraph?: GraphData;
|
|
20
21
|
readonly retryLimit: number;
|
|
21
22
|
retryCount: number;
|
|
@@ -28,6 +29,7 @@ export declare class ComputedNode extends Node {
|
|
|
28
29
|
readonly anyInput: boolean;
|
|
29
30
|
dataSources: Array<DataSource>;
|
|
30
31
|
pendings: Set<string>;
|
|
32
|
+
private ifSource?;
|
|
31
33
|
readonly isStaticNode = false;
|
|
32
34
|
readonly isComputedNode = true;
|
|
33
35
|
constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
|
package/lib/node.js
CHANGED
|
@@ -44,8 +44,9 @@ class ComputedNode extends Node {
|
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
(0, utils_2.assert)(typeof data.agent === "function", "agent must be either string or function");
|
|
47
|
+
const agent = data.agent;
|
|
47
48
|
this.agentFunction = async ({ inputs }) => {
|
|
48
|
-
return
|
|
49
|
+
return agent(...inputs);
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
|
|
@@ -53,8 +54,21 @@ class ComputedNode extends Node {
|
|
|
53
54
|
this.isResult = data.isResult ?? false;
|
|
54
55
|
this.priority = data.priority ?? 0;
|
|
55
56
|
this.anyInput = data.anyInput ?? false;
|
|
56
|
-
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input));
|
|
57
|
+
this.dataSources = (data.inputs ?? []).map((input) => (0, utils_2.parseNodeName)(input, graph.version));
|
|
57
58
|
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
|
59
|
+
if (data.if) {
|
|
60
|
+
this.ifSource = (0, utils_2.parseNodeName)(data.if, graph.version);
|
|
61
|
+
(0, utils_2.assert)(!!this.ifSource.nodeId, `Invalid data source ${data.if}`);
|
|
62
|
+
this.pendings.add(this.ifSource.nodeId);
|
|
63
|
+
}
|
|
64
|
+
this.dynamicParams = Object.keys(this.params).reduce((tmp, key) => {
|
|
65
|
+
const dataSource = (0, utils_2.parseNodeName)(this.params[key], graph.version < 0.3 ? 0.3 : graph.version);
|
|
66
|
+
if (dataSource.nodeId) {
|
|
67
|
+
tmp[key] = dataSource;
|
|
68
|
+
this.pendings.add(dataSource.nodeId);
|
|
69
|
+
}
|
|
70
|
+
return tmp;
|
|
71
|
+
}, {});
|
|
58
72
|
this.log.initForComputedNode(this);
|
|
59
73
|
}
|
|
60
74
|
getAgentId() {
|
|
@@ -70,6 +84,15 @@ class ComputedNode extends Node {
|
|
|
70
84
|
return result === undefined ? count : count + 1;
|
|
71
85
|
}, 0);
|
|
72
86
|
if (!this.anyInput || counter > 0) {
|
|
87
|
+
if (this.ifSource) {
|
|
88
|
+
const [condition] = this.graph.resultsOf([this.ifSource]);
|
|
89
|
+
if (!condition) {
|
|
90
|
+
this.state = type_1.NodeState.Skipped;
|
|
91
|
+
this.log.onSkipped(this, this.graph);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
73
96
|
return true;
|
|
74
97
|
}
|
|
75
98
|
}
|
|
@@ -175,14 +198,20 @@ class ComputedNode extends Node {
|
|
|
175
198
|
try {
|
|
176
199
|
const callback = this.agentFunction ?? this.graph.getCallback(this.agentId);
|
|
177
200
|
const localLog = [];
|
|
201
|
+
const params = Object.keys(this.dynamicParams).reduce((tmp, key) => {
|
|
202
|
+
const [result] = this.graph.resultsOf([this.dynamicParams[key]]);
|
|
203
|
+
tmp[key] = result;
|
|
204
|
+
return tmp;
|
|
205
|
+
}, { ...this.params });
|
|
178
206
|
const context = {
|
|
179
|
-
params:
|
|
207
|
+
params: params,
|
|
180
208
|
inputs: previousResults,
|
|
181
209
|
debugInfo: {
|
|
182
210
|
nodeId: this.nodeId,
|
|
183
211
|
retry: this.retryCount,
|
|
184
212
|
verbose: this.graph.verbose,
|
|
185
213
|
},
|
|
214
|
+
filterParams: {},
|
|
186
215
|
log: localLog,
|
|
187
216
|
};
|
|
188
217
|
// NOTE: We use the existence of graph object in the agent-specific params to determine
|
|
@@ -225,8 +254,9 @@ class ComputedNode extends Node {
|
|
|
225
254
|
// the retry if specified.
|
|
226
255
|
errorProcess(error, transactionId) {
|
|
227
256
|
if (error instanceof Error && error.message !== utils_1.strIntentionalError) {
|
|
228
|
-
console.error(this.agentId
|
|
229
|
-
console.
|
|
257
|
+
console.error(`<-- ${this.nodeId}, ${this.agentId}`);
|
|
258
|
+
console.log(error);
|
|
259
|
+
console.log("-->");
|
|
230
260
|
}
|
|
231
261
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
232
262
|
console.log(`-- ${this.nodeId}: transactionId mismatch(error)`);
|
package/lib/transaction_log.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export declare class TransactionLog {
|
|
|
25
25
|
beforeExecute(node: ComputedNode, graph: GraphAI, transactionId: number, inputs: ResultData[]): void;
|
|
26
26
|
beforeAddTask(node: ComputedNode, graph: GraphAI): void;
|
|
27
27
|
onError(node: ComputedNode, graph: GraphAI, errorMessage: string): void;
|
|
28
|
+
onSkipped(node: ComputedNode, graph: GraphAI): void;
|
|
28
29
|
}
|
package/lib/transaction_log.js
CHANGED
package/lib/type.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export declare enum NodeState {
|
|
|
7
7
|
Failed = "failed",
|
|
8
8
|
TimedOut = "timed-out",
|
|
9
9
|
Completed = "completed",
|
|
10
|
-
Injected = "injected"
|
|
10
|
+
Injected = "injected",
|
|
11
|
+
Skipped = "skipped"
|
|
11
12
|
}
|
|
12
|
-
export type DefaultResultData = Record<string, any> | string | number | Array<DefaultResultData>;
|
|
13
|
+
export type DefaultResultData = Record<string, any> | string | number | boolean | Array<DefaultResultData>;
|
|
13
14
|
export type DefaultInputData = Record<string, any>;
|
|
14
15
|
export type ResultData<ResultType = DefaultResultData> = ResultType | undefined;
|
|
15
16
|
export type ResultDataDictonary<ResultType = DefaultResultData> = Record<string, ResultData<ResultType>>;
|
|
@@ -25,13 +26,15 @@ export type StaticNodeData = {
|
|
|
25
26
|
update?: string;
|
|
26
27
|
isResult?: boolean;
|
|
27
28
|
};
|
|
29
|
+
export type AgentNamelessFunction = (...param: any[]) => unknown;
|
|
28
30
|
export type ComputedNodeData = {
|
|
29
|
-
agent: string |
|
|
31
|
+
agent: string | AgentNamelessFunction;
|
|
30
32
|
inputs?: Array<any>;
|
|
31
33
|
anyInput?: boolean;
|
|
32
34
|
params?: NodeDataParams;
|
|
33
35
|
retry?: number;
|
|
34
36
|
timeout?: number;
|
|
37
|
+
if?: string;
|
|
35
38
|
graph?: GraphData;
|
|
36
39
|
isResult?: boolean;
|
|
37
40
|
priority?: number;
|
|
@@ -59,8 +62,9 @@ export type AgentFunctionContext<ParamsType = DefaultParamsType, InputDataType =
|
|
|
59
62
|
};
|
|
60
63
|
graphData?: GraphData | string;
|
|
61
64
|
agents?: AgentFunctionDictonary;
|
|
62
|
-
log?: TransactionLog[];
|
|
63
65
|
taskManager?: TaskManager;
|
|
66
|
+
filterParams: Record<string, any>;
|
|
67
|
+
log?: TransactionLog[];
|
|
64
68
|
};
|
|
65
69
|
export type AgentFunction<ParamsType = DefaultParamsType, ResultType = DefaultResultData, InputDataType = DefaultInputData> = (context: AgentFunctionContext<ParamsType, InputDataType>) => Promise<ResultData<ResultType>>;
|
|
66
70
|
export type AgentFilterFunction<ParamsType = DefaultParamsType, ResultType = DefaultResultData, InputDataType = DefaultInputData> = (context: AgentFunctionContext<ParamsType, InputDataType>, agent: AgentFunction) => Promise<ResultData<ResultType>>;
|
package/lib/type.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentFunctionInfo } from "../type";
|
|
1
|
+
import { AgentFunctionInfo, AgentFunctionContext, AgentFunction, AgentFilterInfo, ResultData } from "../type";
|
|
2
2
|
export declare const defaultTestContext: {
|
|
3
3
|
debugInfo: {
|
|
4
4
|
nodeId: string;
|
|
@@ -6,7 +6,9 @@ export declare const defaultTestContext: {
|
|
|
6
6
|
verbose: boolean;
|
|
7
7
|
};
|
|
8
8
|
params: {};
|
|
9
|
+
filterParams: {};
|
|
9
10
|
agents: {};
|
|
10
11
|
log: never[];
|
|
11
12
|
};
|
|
12
13
|
export declare const agentTestRunner: (agentInfo: AgentFunctionInfo) => Promise<void>;
|
|
14
|
+
export declare const agentFilterRunnerBuilder: (__agentFilters: AgentFilterInfo[]) => (context: AgentFunctionContext, agent: AgentFunction) => Promise<ResultData>;
|
package/lib/utils/test_utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.agentTestRunner = exports.defaultTestContext = void 0;
|
|
6
|
+
exports.agentFilterRunnerBuilder = exports.agentTestRunner = exports.defaultTestContext = void 0;
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
8
|
const node_test_1 = __importDefault(require("node:test"));
|
|
9
9
|
exports.defaultTestContext = {
|
|
@@ -13,6 +13,7 @@ exports.defaultTestContext = {
|
|
|
13
13
|
verbose: true,
|
|
14
14
|
},
|
|
15
15
|
params: {},
|
|
16
|
+
filterParams: {},
|
|
16
17
|
agents: {},
|
|
17
18
|
log: [],
|
|
18
19
|
};
|
|
@@ -37,3 +38,20 @@ const agentTestRunner = async (agentInfo) => {
|
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
exports.agentTestRunner = agentTestRunner;
|
|
41
|
+
// for agent and agent filter.
|
|
42
|
+
const agentFilterRunnerBuilder = (__agentFilters) => {
|
|
43
|
+
const agentFilters = __agentFilters;
|
|
44
|
+
const agentFilterRunner = (context, agent) => {
|
|
45
|
+
let index = 0;
|
|
46
|
+
const next = (context) => {
|
|
47
|
+
const agentFilter = agentFilters[index++];
|
|
48
|
+
if (agentFilter) {
|
|
49
|
+
return agentFilter.agent(context, next);
|
|
50
|
+
}
|
|
51
|
+
return agent(context);
|
|
52
|
+
};
|
|
53
|
+
return next(context);
|
|
54
|
+
};
|
|
55
|
+
return agentFilterRunner;
|
|
56
|
+
};
|
|
57
|
+
exports.agentFilterRunnerBuilder = agentFilterRunnerBuilder;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataSource, ResultData } from "../type";
|
|
2
2
|
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
3
|
-
export declare const parseNodeName: (inputNodeId: any) => DataSource;
|
|
3
|
+
export declare const parseNodeName: (inputNodeId: any, version: number) => 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
6
|
export declare const getDataFromSource: (result: ResultData | undefined, source: DataSource) => ResultData | undefined;
|
package/lib/utils/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ const sleep = async (milliseconds) => {
|
|
|
5
5
|
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
6
6
|
};
|
|
7
7
|
exports.sleep = sleep;
|
|
8
|
-
const
|
|
8
|
+
const parseNodeName_02 = (inputNodeId) => {
|
|
9
9
|
if (typeof inputNodeId === "string") {
|
|
10
10
|
const regex = /^"(.*)"$/;
|
|
11
11
|
const match = inputNodeId.match(regex);
|
|
@@ -20,6 +20,24 @@ const parseNodeName = (inputNodeId) => {
|
|
|
20
20
|
}
|
|
21
21
|
return { value: inputNodeId }; // non-string literal
|
|
22
22
|
};
|
|
23
|
+
const parseNodeName = (inputNodeId, version) => {
|
|
24
|
+
if (version === 0.2) {
|
|
25
|
+
return parseNodeName_02(inputNodeId);
|
|
26
|
+
}
|
|
27
|
+
if (typeof inputNodeId === "string") {
|
|
28
|
+
const regex = /^:(.*)$/;
|
|
29
|
+
const match = inputNodeId.match(regex);
|
|
30
|
+
if (!match) {
|
|
31
|
+
return { value: inputNodeId }; // string literal
|
|
32
|
+
}
|
|
33
|
+
const parts = match[1].split(".");
|
|
34
|
+
if (parts.length == 1) {
|
|
35
|
+
return { nodeId: parts[0] };
|
|
36
|
+
}
|
|
37
|
+
return { nodeId: parts[0], propIds: parts.slice(1) };
|
|
38
|
+
}
|
|
39
|
+
return { value: inputNodeId }; // non-string literal
|
|
40
|
+
};
|
|
23
41
|
exports.parseNodeName = parseNodeName;
|
|
24
42
|
function assert(condition, message, isWarn = false) {
|
|
25
43
|
if (!condition) {
|
package/lib/validators/common.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
4
|
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"];
|
|
5
|
-
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority"];
|
|
5
|
+
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority", "if"];
|
|
6
6
|
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|
|
@@ -12,7 +12,7 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
|
|
|
12
12
|
pendings[computedNodeId] = new Set();
|
|
13
13
|
if ("inputs" in nodeData && nodeData && nodeData.inputs) {
|
|
14
14
|
nodeData.inputs.forEach((inputNodeId) => {
|
|
15
|
-
const sourceNodeId = (0, utils_1.parseNodeName)(inputNodeId).nodeId;
|
|
15
|
+
const sourceNodeId = (0, utils_1.parseNodeName)(inputNodeId, data.version ?? 0.02).nodeId;
|
|
16
16
|
if (sourceNodeId) {
|
|
17
17
|
if (!nodeIds.has(sourceNodeId)) {
|
|
18
18
|
throw new Error(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${sourceNodeId}`);
|
|
@@ -29,7 +29,7 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
|
|
|
29
29
|
const nodeData = data.nodes[staticNodeId];
|
|
30
30
|
if ("value" in nodeData && nodeData.update) {
|
|
31
31
|
const update = nodeData.update;
|
|
32
|
-
const updateNodeId = (0, utils_1.parseNodeName)(update).nodeId;
|
|
32
|
+
const updateNodeId = (0, utils_1.parseNodeName)(update, data.version ?? 0.02).nodeId;
|
|
33
33
|
if (!updateNodeId) {
|
|
34
34
|
throw new Error("Update it a literal");
|
|
35
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./experimental_agents/vanilla";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./experimental_agents/vanilla"), exports);
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AgentFunction } from "../../graphai";
|
|
2
|
-
export declare const rssAgent: AgentFunction<undefined, any, string>;
|
|
3
|
-
declare const rssAgentInfo: {
|
|
4
|
-
name: string;
|
|
5
|
-
agent: AgentFunction<undefined, any, string>;
|
|
6
|
-
mock: AgentFunction<undefined, any, string>;
|
|
7
|
-
description: string;
|
|
8
|
-
category: string[];
|
|
9
|
-
author: string;
|
|
10
|
-
repository: string;
|
|
11
|
-
license: string;
|
|
12
|
-
};
|
|
13
|
-
export default rssAgentInfo;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rssAgent = void 0;
|
|
4
|
-
const xml2js_1 = require("xml2js");
|
|
5
|
-
const rssAgent = async ({ inputs }) => {
|
|
6
|
-
const url = inputs[0];
|
|
7
|
-
try {
|
|
8
|
-
const response = await fetch(url);
|
|
9
|
-
const xmlData = await response.text();
|
|
10
|
-
const jsonData = await (0, xml2js_1.parseStringPromise)(xmlData, { explicitArray: false, mergeAttrs: true });
|
|
11
|
-
return jsonData;
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
console.log(error);
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
exports.rssAgent = rssAgent;
|
|
19
|
-
const rssAgentInfo = {
|
|
20
|
-
name: "rssAgent",
|
|
21
|
-
agent: exports.rssAgent,
|
|
22
|
-
mock: exports.rssAgent,
|
|
23
|
-
description: "Retrieves XML data from RSS feed and convert it to JSON",
|
|
24
|
-
category: ["data"],
|
|
25
|
-
author: "Receptron",
|
|
26
|
-
repository: "https://github.com/receptron/graphai",
|
|
27
|
-
license: "MIT",
|
|
28
|
-
};
|
|
29
|
-
exports.default = rssAgentInfo;
|