graphai 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +1 -1
- package/lib/experimental_agents/array_agents/push_agent.d.ts +17 -3
- package/lib/experimental_agents/array_agents/push_agent.js +15 -1
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +1 -1
- package/lib/experimental_agents/data_agents/copy_agent.d.ts +1 -1
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +1 -1
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +1 -1
- package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +43 -13
- package/lib/experimental_agents/data_agents/property_filter_agent.js +31 -12
- package/lib/experimental_agents/data_agents/total_agent.d.ts +1 -1
- package/lib/experimental_agents/embedding_agent.d.ts +1 -1
- package/lib/experimental_agents/function_agent.d.ts +1 -1
- package/lib/experimental_agents/graph_agents/map_agent.d.ts +4 -4
- package/lib/experimental_agents/graph_agents/map_agent.js +5 -5
- package/lib/experimental_agents/graph_agents/nested_agent.d.ts +4 -4
- package/lib/experimental_agents/graph_agents/nested_agent.js +4 -4
- package/lib/experimental_agents/index.d.ts +1 -0
- package/lib/experimental_agents/index.js +1 -0
- package/lib/experimental_agents/input_agents/index.d.ts +2 -0
- package/lib/experimental_agents/input_agents/index.js +8 -0
- package/lib/experimental_agents/input_agents/packages.d.ts +2 -0
- package/lib/experimental_agents/input_agents/packages.js +8 -0
- package/lib/experimental_agents/input_agents/text_input_agent.d.ts +26 -0
- package/lib/experimental_agents/input_agents/text_input_agent.js +23 -0
- package/lib/experimental_agents/llm_agents/groq_agent.d.ts +13 -10
- package/lib/experimental_agents/llm_agents/groq_agent.js +32 -5
- package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +1 -1
- package/lib/experimental_agents/llm_agents/openai_agent.d.ts +5 -1
- package/lib/experimental_agents/llm_agents/openai_agent.js +2 -0
- package/lib/experimental_agents/llm_agents/slashgpt_agent.d.ts +1 -1
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +1 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +1 -1
- package/lib/experimental_agents/service_agents/fetch_agent.d.ts +1 -1
- package/lib/experimental_agents/service_agents/wikipedia.d.ts +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +1 -1
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +1 -1
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +2 -33
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +51 -9
- package/lib/experimental_agents/string_agents/string_template_agent.js +36 -9
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +1 -1
- package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +1 -1
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +1 -2
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +1 -2
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +1 -2
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +1 -2
- package/lib/experimental_agents/test_agents/stream_mock_agent.d.ts +1 -2
- package/lib/experimental_agents/token_agent.d.ts +1 -1
- package/lib/experimental_agents/vanilla.d.ts +3 -2
- package/lib/experimental_agents/vanilla.js +8 -2
- package/lib/graphai.d.ts +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +1 -1
- package/lib/node.d.ts +2 -1
- package/lib/node.js +7 -0
- package/lib/type.d.ts +1 -0
- package/lib/utils/test_agents.d.ts +1 -1
- package/lib/utils/test_utils.d.ts +11 -24
- package/lib/utils/test_utils.js +3 -24
- package/lib/utils/utils.d.ts +29 -1
- package/lib/utils/utils.js +24 -1
- package/lib/validators/common.js +14 -1
- package/package.json +6 -2
|
@@ -22,9 +22,9 @@ const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.en
|
|
|
22
22
|
//
|
|
23
23
|
// https://console.groq.com/docs/quickstart
|
|
24
24
|
//
|
|
25
|
-
const groqAgent = async ({ params, inputs }) => {
|
|
25
|
+
const groqAgent = async ({ params, inputs, filterParams }) => {
|
|
26
26
|
(0, utils_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing.");
|
|
27
|
-
const { verbose, query, system, tools, tool_choice, max_tokens, temperature } = params;
|
|
27
|
+
const { verbose, query, system, tools, tool_choice, max_tokens, temperature, isStreaming } = params;
|
|
28
28
|
const [input_query, previous_messages] = inputs;
|
|
29
29
|
// Notice that we ignore params.system if previous_message exists.
|
|
30
30
|
const messages = previous_messages && Array.isArray(previous_messages) ? previous_messages : system ? [{ role: "system", content: system }] : [];
|
|
@@ -38,11 +38,18 @@ const groqAgent = async ({ params, inputs }) => {
|
|
|
38
38
|
if (verbose) {
|
|
39
39
|
console.log(messages);
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const streamOption = {
|
|
42
42
|
messages,
|
|
43
43
|
model: params.model,
|
|
44
44
|
temperature: temperature ?? 0.7,
|
|
45
|
+
stream: true,
|
|
45
46
|
};
|
|
47
|
+
const nonStreamOption = {
|
|
48
|
+
messages,
|
|
49
|
+
model: params.model,
|
|
50
|
+
temperature: temperature ?? 0.7,
|
|
51
|
+
};
|
|
52
|
+
const options = isStreaming ? streamOption : nonStreamOption;
|
|
46
53
|
if (max_tokens) {
|
|
47
54
|
options.max_tokens = max_tokens;
|
|
48
55
|
}
|
|
@@ -50,8 +57,28 @@ const groqAgent = async ({ params, inputs }) => {
|
|
|
50
57
|
options.tools = tools;
|
|
51
58
|
options.tool_choice = tool_choice ?? "auto";
|
|
52
59
|
}
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
if (!options.stream) {
|
|
61
|
+
const result = await groq.chat.completions.create(options);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
// streaming
|
|
65
|
+
const stream = await groq.chat.completions.create(options);
|
|
66
|
+
let lastMessage = null;
|
|
67
|
+
const contents = [];
|
|
68
|
+
for await (const message of stream) {
|
|
69
|
+
const token = message.choices[0].delta.content;
|
|
70
|
+
if (token) {
|
|
71
|
+
if (filterParams && filterParams.streamTokenCallback) {
|
|
72
|
+
filterParams.streamTokenCallback(token);
|
|
73
|
+
}
|
|
74
|
+
contents.push(token);
|
|
75
|
+
}
|
|
76
|
+
lastMessage = message;
|
|
77
|
+
}
|
|
78
|
+
if (lastMessage) {
|
|
79
|
+
lastMessage.choices[0]["message"] = [{ role: "assistant", content: contents.join("") }];
|
|
80
|
+
}
|
|
81
|
+
return lastMessage;
|
|
55
82
|
};
|
|
56
83
|
exports.groqAgent = groqAgent;
|
|
57
84
|
const groqAgentInfo = {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
1
|
+
import { AgentFunction } from "../../index";
|
|
2
2
|
export declare const openAIAgent: AgentFunction<{
|
|
3
3
|
model?: string;
|
|
4
4
|
query?: string;
|
|
5
5
|
system?: string;
|
|
6
|
+
tools?: any;
|
|
7
|
+
tool_choice?: any;
|
|
6
8
|
verbose?: boolean;
|
|
7
9
|
temperature?: number;
|
|
8
10
|
}, Record<string, any> | string, string | Array<any>>;
|
|
@@ -19,6 +21,8 @@ declare const openaiAgentInfo: {
|
|
|
19
21
|
model?: string | undefined;
|
|
20
22
|
query?: string | undefined;
|
|
21
23
|
system?: string | undefined;
|
|
24
|
+
tools?: any;
|
|
25
|
+
tool_choice?: any;
|
|
22
26
|
verbose?: boolean | undefined;
|
|
23
27
|
temperature?: number | undefined;
|
|
24
28
|
}, string | Record<string, any>, string | any[]>;
|
|
@@ -25,6 +25,8 @@ const openAIAgent = async ({ filterParams, params, inputs }) => {
|
|
|
25
25
|
const chatStream = await openai.beta.chat.completions.stream({
|
|
26
26
|
model: params.model || "gpt-3.5-turbo",
|
|
27
27
|
messages,
|
|
28
|
+
tools: params.tools,
|
|
29
|
+
tool_choice: params.tool_choice,
|
|
28
30
|
temperature: temperature ?? 0.7,
|
|
29
31
|
stream: true,
|
|
30
32
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
1
|
+
import { AgentFunction } from "../../index";
|
|
2
2
|
export declare const dotProductAgent: AgentFunction<Record<never, never>, Array<number>, Array<Array<number>> | Array<number>>;
|
|
3
3
|
declare const dotProductAgentInfo: {
|
|
4
4
|
name: string;
|
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
1
|
+
import { AgentFunction, AgentFunctionInfo } from "../../index";
|
|
2
2
|
export declare const stringSplitterAgent: AgentFunction<{
|
|
3
3
|
chunkSize?: number;
|
|
4
4
|
overlap?: number;
|
|
5
5
|
}, {
|
|
6
6
|
contents: Array<string>;
|
|
7
7
|
}, string>;
|
|
8
|
-
declare const stringSplitterAgentInfo:
|
|
9
|
-
name: string;
|
|
10
|
-
agent: AgentFunction<{
|
|
11
|
-
chunkSize?: number | undefined;
|
|
12
|
-
overlap?: number | undefined;
|
|
13
|
-
}, {
|
|
14
|
-
contents: Array<string>;
|
|
15
|
-
}, string>;
|
|
16
|
-
mock: AgentFunction<{
|
|
17
|
-
chunkSize?: number | undefined;
|
|
18
|
-
overlap?: number | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
contents: Array<string>;
|
|
21
|
-
}, string>;
|
|
22
|
-
samples: {
|
|
23
|
-
inputs: string[];
|
|
24
|
-
params: {
|
|
25
|
-
chunkSize: number;
|
|
26
|
-
};
|
|
27
|
-
result: {
|
|
28
|
-
contents: string[];
|
|
29
|
-
count: number;
|
|
30
|
-
chunkSize: number;
|
|
31
|
-
overlap: number;
|
|
32
|
-
};
|
|
33
|
-
}[];
|
|
34
|
-
description: string;
|
|
35
|
-
category: never[];
|
|
36
|
-
author: string;
|
|
37
|
-
repository: string;
|
|
38
|
-
license: string;
|
|
39
|
-
};
|
|
8
|
+
declare const stringSplitterAgentInfo: AgentFunctionInfo;
|
|
40
9
|
export default stringSplitterAgentInfo;
|
|
@@ -1,22 +1,64 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
1
|
+
import { AgentFunction } from "../../index";
|
|
2
2
|
export declare const stringTemplateAgent: AgentFunction<{
|
|
3
|
-
template:
|
|
4
|
-
},
|
|
3
|
+
template: any;
|
|
4
|
+
}, any, string>;
|
|
5
5
|
declare const stringTemplateAgentInfo: {
|
|
6
6
|
name: string;
|
|
7
7
|
agent: AgentFunction<{
|
|
8
|
-
template:
|
|
9
|
-
},
|
|
8
|
+
template: any;
|
|
9
|
+
}, any, string>;
|
|
10
10
|
mock: AgentFunction<{
|
|
11
|
-
template:
|
|
12
|
-
},
|
|
13
|
-
samples: {
|
|
11
|
+
template: any;
|
|
12
|
+
}, any, string>;
|
|
13
|
+
samples: ({
|
|
14
14
|
inputs: string[];
|
|
15
15
|
params: {
|
|
16
16
|
template: string;
|
|
17
17
|
};
|
|
18
18
|
result: string;
|
|
19
|
-
}
|
|
19
|
+
} | {
|
|
20
|
+
inputs: string[];
|
|
21
|
+
params: {
|
|
22
|
+
template: string[];
|
|
23
|
+
};
|
|
24
|
+
result: string[];
|
|
25
|
+
} | {
|
|
26
|
+
inputs: string[];
|
|
27
|
+
params: {
|
|
28
|
+
template: {
|
|
29
|
+
apple: string;
|
|
30
|
+
lemon: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
result: {
|
|
34
|
+
apple: string;
|
|
35
|
+
lemon: string;
|
|
36
|
+
};
|
|
37
|
+
} | {
|
|
38
|
+
inputs: string[];
|
|
39
|
+
params: {
|
|
40
|
+
template: {
|
|
41
|
+
apple: string;
|
|
42
|
+
lemon: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
result: {
|
|
46
|
+
apple: string;
|
|
47
|
+
lemon: string;
|
|
48
|
+
}[];
|
|
49
|
+
} | {
|
|
50
|
+
inputs: string[];
|
|
51
|
+
params: {
|
|
52
|
+
template: {
|
|
53
|
+
apple: string;
|
|
54
|
+
lemon: string[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
result: {
|
|
58
|
+
apple: string;
|
|
59
|
+
lemon: string[];
|
|
60
|
+
};
|
|
61
|
+
})[];
|
|
20
62
|
description: string;
|
|
21
63
|
category: never[];
|
|
22
64
|
author: string;
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringTemplateAgent = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const processTemplate = (template, match, input) => {
|
|
5
|
+
if (typeof template === "string") {
|
|
6
|
+
return template.replace(match, input);
|
|
7
|
+
}
|
|
8
|
+
else if (Array.isArray(template)) {
|
|
9
|
+
return template.map((item) => processTemplate(item, match, input));
|
|
10
|
+
}
|
|
11
|
+
return Object.keys(template).reduce((tmp, key) => {
|
|
12
|
+
tmp[key] = processTemplate(template[key], match, input);
|
|
13
|
+
return tmp;
|
|
14
|
+
}, {});
|
|
15
|
+
};
|
|
6
16
|
const stringTemplateAgent = async ({ params, inputs }) => {
|
|
7
|
-
|
|
8
|
-
return template
|
|
17
|
+
return inputs.reduce((template, input, index) => {
|
|
18
|
+
return processTemplate(template, "${" + index + "}", input);
|
|
9
19
|
}, params.template);
|
|
10
|
-
return content;
|
|
11
20
|
};
|
|
12
21
|
exports.stringTemplateAgent = stringTemplateAgent;
|
|
13
22
|
const sampleInput = ["hello", "test"];
|
|
14
|
-
const sampleParams = { template: "${0}: ${1}" };
|
|
15
|
-
const sampleResult = "hello: test";
|
|
16
23
|
// for test and document
|
|
17
24
|
const stringTemplateAgentInfo = {
|
|
18
25
|
name: "stringTemplateAgent",
|
|
@@ -21,8 +28,28 @@ const stringTemplateAgentInfo = {
|
|
|
21
28
|
samples: [
|
|
22
29
|
{
|
|
23
30
|
inputs: sampleInput,
|
|
24
|
-
params:
|
|
25
|
-
result:
|
|
31
|
+
params: { template: "${0}: ${1}" },
|
|
32
|
+
result: "hello: test",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
inputs: sampleInput,
|
|
36
|
+
params: { template: ["${0}: ${1}", "${1}: ${0}"] },
|
|
37
|
+
result: ["hello: test", "test: hello"],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
inputs: sampleInput,
|
|
41
|
+
params: { template: { apple: "${0}", lemon: "${1}" } },
|
|
42
|
+
result: { apple: "hello", lemon: "test" },
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
inputs: sampleInput,
|
|
46
|
+
params: { template: [{ apple: "${0}", lemon: "${1}" }] },
|
|
47
|
+
result: [{ apple: "hello", lemon: "test" }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
inputs: sampleInput,
|
|
51
|
+
params: { template: { apple: "${0}", lemon: ["${1}"] } },
|
|
52
|
+
result: { apple: "hello", lemon: ["test"] },
|
|
26
53
|
},
|
|
27
54
|
],
|
|
28
55
|
description: "Template agent",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
2
|
-
import { AgentFunctionInfo } from "../../type";
|
|
1
|
+
import { AgentFunction, AgentFunctionInfo } from "../../index";
|
|
3
2
|
export declare const echoAgent: AgentFunction;
|
|
4
3
|
declare const echoAgentInfo: AgentFunctionInfo;
|
|
5
4
|
export default echoAgentInfo;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
2
|
-
import { AgentFunctionInfo } from "../../type";
|
|
1
|
+
import { AgentFunction, AgentFunctionInfo } from "../../index";
|
|
3
2
|
export declare const mergeNodeIdAgent: AgentFunction;
|
|
4
3
|
declare const mergeNodeIdAgentInfo: AgentFunctionInfo;
|
|
5
4
|
export default mergeNodeIdAgentInfo;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AgentFunction } from "../../
|
|
2
|
-
import { AgentFunctionInfo } from "../../type";
|
|
1
|
+
import { AgentFunction, AgentFunctionInfo } from "../../index";
|
|
3
2
|
export declare const streamMockAgent: AgentFunction;
|
|
4
3
|
declare const streamMockAgentInfo: AgentFunctionInfo;
|
|
5
4
|
export default streamMockAgentInfo;
|
|
@@ -4,5 +4,6 @@ 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
|
-
|
|
8
|
-
|
|
7
|
+
import functionAgent from "./function_agent";
|
|
8
|
+
import stringEmbeddingsAgent from "./embedding_agent";
|
|
9
|
+
export { functionAgent, stringEmbeddingsAgent };
|
|
@@ -14,7 +14,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
14
14
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
17
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.stringEmbeddingsAgent = exports.functionAgent = void 0;
|
|
18
22
|
// Please refrain from adding agents that require npm. Those should be added to the index.ts.
|
|
19
23
|
__exportStar(require("./string_agents/vanilla"), exports);
|
|
20
24
|
__exportStar(require("./array_agents/vanilla"), exports);
|
|
@@ -22,5 +26,7 @@ __exportStar(require("./matrix_agents/vanilla"), exports);
|
|
|
22
26
|
__exportStar(require("./test_agents/vanilla"), exports);
|
|
23
27
|
__exportStar(require("./graph_agents/vanilla"), exports);
|
|
24
28
|
__exportStar(require("./data_agents/vanilla"), exports);
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const function_agent_1 = __importDefault(require("./function_agent"));
|
|
30
|
+
exports.functionAgent = function_agent_1.default;
|
|
31
|
+
const embedding_agent_1 = __importDefault(require("./embedding_agent"));
|
|
32
|
+
exports.stringEmbeddingsAgent = embedding_agent_1.default;
|
package/lib/graphai.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { AgentFunction, GraphData, AgentFunctionInfoDictonary } from "./type";
|
|
2
1
|
import { AgentFunctionInfoDictonary, AgentFilterInfo, GraphData, DataSource, ResultDataDictonary, ResultData, DefaultResultData } from "./type";
|
|
3
2
|
import { TransactionLog } from "./transaction_log";
|
|
4
3
|
import { ComputedNode, StaticNode } from "./node";
|
|
@@ -45,3 +44,4 @@ export declare class GraphAI {
|
|
|
45
44
|
injectValue(nodeId: string, value: ResultData, injectFrom?: string): void;
|
|
46
45
|
resultsOf(sources: Array<DataSource>): ResultData[];
|
|
47
46
|
}
|
|
47
|
+
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export { AgentFunction, AgentFunctionInfoDictonary, GraphData, ResultDataDictonary, ResultData, NodeState } from "./type";
|
|
1
|
+
export { GraphAI } from "./graphai";
|
|
2
|
+
export { AgentFunction, AgentFunctionInfo, AgentFunctionInfoDictonary, GraphData, ResultDataDictonary, ResultData, NodeState, AgentFilterFunction, } from "./type";
|
|
4
3
|
export type { TransactionLog } from "./transaction_log";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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; } });
|
package/lib/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphAI, GraphData } from "./
|
|
1
|
+
import type { GraphAI, GraphData } from "./index";
|
|
2
2
|
import { NodeDataParams, ResultData, DataSource, ComputedNodeData, StaticNodeData, NodeState } from "./type";
|
|
3
3
|
import { TransactionLog } from "./transaction_log";
|
|
4
4
|
export declare class Node {
|
|
@@ -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 console;
|
|
34
35
|
readonly isStaticNode = false;
|
|
35
36
|
readonly isComputedNode = true;
|
|
36
37
|
constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
|
package/lib/node.js
CHANGED
|
@@ -38,6 +38,7 @@ class ComputedNode extends Node {
|
|
|
38
38
|
this.isComputedNode = true;
|
|
39
39
|
this.graphId = graphId;
|
|
40
40
|
this.params = data.params ?? {};
|
|
41
|
+
this.console = data.console ?? {};
|
|
41
42
|
this.filterParams = data.filterParams ?? {};
|
|
42
43
|
this.nestedGraph = data.graph;
|
|
43
44
|
if (typeof data.agent === "string") {
|
|
@@ -229,7 +230,13 @@ class ComputedNode extends Node {
|
|
|
229
230
|
context.graphData = this.nestedGraph;
|
|
230
231
|
context.agents = this.graph.agentFunctionInfoDictionary;
|
|
231
232
|
}
|
|
233
|
+
if (this.console.before) {
|
|
234
|
+
console.log(this.console.before === true ? JSON.stringify(context.inputs, null, 2) : this.console.before);
|
|
235
|
+
}
|
|
232
236
|
const result = await this.agentFilterHandler(context, agentFunction);
|
|
237
|
+
if (this.console.after) {
|
|
238
|
+
console.log(this.console.after === true ? (typeof result === "string" ? result : JSON.stringify(result, null, 2)) : this.console.after);
|
|
239
|
+
}
|
|
233
240
|
if (this.nestedGraph) {
|
|
234
241
|
this.graph.taskManager.restoreAfterNesting();
|
|
235
242
|
}
|
package/lib/type.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AgentFunctionInfoDictonary } from "../
|
|
1
|
+
import { AgentFunctionInfoDictonary } from "../index";
|
|
2
2
|
export declare const defaultTestAgents: AgentFunctionInfoDictonary;
|
|
@@ -1,28 +1,4 @@
|
|
|
1
1
|
import { AgentFunctionInfo, AgentFunctionContext, AgentFunction, AgentFilterInfo, ResultData } from "../type";
|
|
2
|
-
export declare const defaultTestContext: {
|
|
3
|
-
debugInfo: {
|
|
4
|
-
nodeId: string;
|
|
5
|
-
retry: number;
|
|
6
|
-
verbose: boolean;
|
|
7
|
-
};
|
|
8
|
-
params: {};
|
|
9
|
-
filterParams: {};
|
|
10
|
-
agents: {};
|
|
11
|
-
log: never[];
|
|
12
|
-
};
|
|
13
|
-
export declare const defaultAgentInfo: {
|
|
14
|
-
name: string;
|
|
15
|
-
samples: {
|
|
16
|
-
inputs: never[];
|
|
17
|
-
params: {};
|
|
18
|
-
result: {};
|
|
19
|
-
}[];
|
|
20
|
-
description: string;
|
|
21
|
-
category: never[];
|
|
22
|
-
author: string;
|
|
23
|
-
repository: string;
|
|
24
|
-
license: string;
|
|
25
|
-
};
|
|
26
2
|
export declare const getAgentInfo: (agent: AgentFunction<any, any, any>) => {
|
|
27
3
|
name: string;
|
|
28
4
|
samples: {
|
|
@@ -38,5 +14,16 @@ export declare const getAgentInfo: (agent: AgentFunction<any, any, any>) => {
|
|
|
38
14
|
agent: AgentFunction<any, any, any>;
|
|
39
15
|
mock: AgentFunction<any, any, any>;
|
|
40
16
|
};
|
|
17
|
+
export declare const defaultTestContext: {
|
|
18
|
+
debugInfo: {
|
|
19
|
+
nodeId: string;
|
|
20
|
+
retry: number;
|
|
21
|
+
verbose: boolean;
|
|
22
|
+
};
|
|
23
|
+
params: {};
|
|
24
|
+
filterParams: {};
|
|
25
|
+
agents: {};
|
|
26
|
+
log: never[];
|
|
27
|
+
};
|
|
41
28
|
export declare const agentTestRunner: (agentInfo: AgentFunctionInfo) => Promise<void>;
|
|
42
29
|
export declare const agentFilterRunnerBuilder: (__agentFilters: AgentFilterInfo[]) => (context: AgentFunctionContext, agent: AgentFunction) => Promise<ResultData>;
|
package/lib/utils/test_utils.js
CHANGED
|
@@ -3,9 +3,11 @@ 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.agentFilterRunnerBuilder = exports.agentTestRunner = exports.
|
|
6
|
+
exports.agentFilterRunnerBuilder = exports.agentTestRunner = exports.defaultTestContext = exports.getAgentInfo = void 0;
|
|
7
|
+
const utils_1 = require("../utils/utils");
|
|
7
8
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
9
|
const node_test_1 = __importDefault(require("node:test"));
|
|
10
|
+
exports.getAgentInfo = utils_1.agentInfoWrapper;
|
|
9
11
|
exports.defaultTestContext = {
|
|
10
12
|
debugInfo: {
|
|
11
13
|
nodeId: "test",
|
|
@@ -17,29 +19,6 @@ exports.defaultTestContext = {
|
|
|
17
19
|
agents: {},
|
|
18
20
|
log: [],
|
|
19
21
|
};
|
|
20
|
-
exports.defaultAgentInfo = {
|
|
21
|
-
name: "defaultAgentInfo",
|
|
22
|
-
samples: [
|
|
23
|
-
{
|
|
24
|
-
inputs: [],
|
|
25
|
-
params: {},
|
|
26
|
-
result: {},
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
description: "",
|
|
30
|
-
category: [],
|
|
31
|
-
author: "",
|
|
32
|
-
repository: "",
|
|
33
|
-
license: "",
|
|
34
|
-
};
|
|
35
|
-
const getAgentInfo = (agent) => {
|
|
36
|
-
return {
|
|
37
|
-
agent,
|
|
38
|
-
mock: agent,
|
|
39
|
-
...exports.defaultAgentInfo,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
exports.getAgentInfo = getAgentInfo;
|
|
43
22
|
// for agent
|
|
44
23
|
const agentTestRunner = async (agentInfo) => {
|
|
45
24
|
const { agent, samples, skipTest } = agentInfo;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
import { DataSource, ResultData } from "../type";
|
|
1
|
+
import { DataSource, ResultData, AgentFunction } from "../type";
|
|
2
2
|
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
3
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;
|
|
7
7
|
export declare const strIntentionalError = "Intentional Error for Debugging";
|
|
8
|
+
export declare const defaultAgentInfo: {
|
|
9
|
+
name: string;
|
|
10
|
+
samples: {
|
|
11
|
+
inputs: never[];
|
|
12
|
+
params: {};
|
|
13
|
+
result: {};
|
|
14
|
+
}[];
|
|
15
|
+
description: string;
|
|
16
|
+
category: never[];
|
|
17
|
+
author: string;
|
|
18
|
+
repository: string;
|
|
19
|
+
license: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const agentInfoWrapper: (agent: AgentFunction<any, any, any>) => {
|
|
22
|
+
name: string;
|
|
23
|
+
samples: {
|
|
24
|
+
inputs: never[];
|
|
25
|
+
params: {};
|
|
26
|
+
result: {};
|
|
27
|
+
}[];
|
|
28
|
+
description: string;
|
|
29
|
+
category: never[];
|
|
30
|
+
author: string;
|
|
31
|
+
repository: string;
|
|
32
|
+
license: string;
|
|
33
|
+
agent: AgentFunction<any, any, any>;
|
|
34
|
+
mock: AgentFunction<any, any, any>;
|
|
35
|
+
};
|