graphai 0.3.1 → 0.4.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 +30 -11
- package/lib/experimental_agents/array_agents/index.d.ts +1 -3
- package/lib/experimental_agents/array_agents/index.js +15 -7
- package/lib/experimental_agents/array_agents/vanilla.d.ts +4 -0
- package/lib/experimental_agents/array_agents/vanilla.js +12 -0
- package/lib/experimental_agents/data_agents/copy_agent.d.ts +2 -0
- package/lib/experimental_agents/data_agents/copy_agent.js +2 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +43 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +22 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +15 -0
- package/lib/experimental_agents/data_agents/index.d.ts +3 -4
- package/lib/experimental_agents/data_agents/index.js +21 -9
- package/lib/experimental_agents/data_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/data_agents/packages.js +3 -1
- package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +109 -8
- package/lib/experimental_agents/data_agents/property_filter_agent.js +60 -9
- package/lib/experimental_agents/data_agents/total_agent.d.ts +13 -0
- package/lib/experimental_agents/data_agents/total_agent.js +29 -0
- package/lib/experimental_agents/data_agents/vanilla.d.ts +5 -0
- package/lib/experimental_agents/data_agents/vanilla.js +14 -0
- package/lib/experimental_agents/graph_agents/index.d.ts +1 -2
- package/lib/experimental_agents/graph_agents/index.js +15 -5
- package/lib/experimental_agents/graph_agents/map_agent.js +2 -2
- package/lib/experimental_agents/graph_agents/nested_agent.js +9 -12
- package/lib/experimental_agents/graph_agents/vanilla.d.ts +3 -0
- package/lib/experimental_agents/graph_agents/vanilla.js +10 -0
- package/lib/experimental_agents/index.d.ts +10 -3
- package/lib/experimental_agents/index.js +17 -5
- package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +42 -0
- package/lib/experimental_agents/llm_agents/groq_stream_agent.js +84 -0
- package/lib/experimental_agents/llm_agents/index.d.ts +5 -2
- package/lib/experimental_agents/llm_agents/index.js +11 -15
- package/lib/experimental_agents/llm_agents/openai_agent.d.ts +1 -0
- package/lib/experimental_agents/llm_agents/openai_agent.js +1 -0
- package/lib/experimental_agents/llm_agents/packages.d.ts +3 -1
- package/lib/experimental_agents/llm_agents/packages.js +5 -1
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +11 -0
- package/lib/experimental_agents/matrix_agents/index.d.ts +1 -2
- package/lib/experimental_agents/matrix_agents/index.js +15 -5
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +13 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +20 -1
- package/lib/experimental_agents/matrix_agents/vanilla.d.ts +3 -0
- package/lib/experimental_agents/matrix_agents/vanilla.js +10 -0
- package/lib/experimental_agents/service_agents/fetch_agent.js +1 -1
- package/lib/experimental_agents/service_agents/index.d.ts +3 -2
- package/lib/experimental_agents/service_agents/index.js +8 -5
- package/lib/experimental_agents/service_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/service_agents/packages.js +3 -1
- package/lib/experimental_agents/service_agents/wikipedia.d.ts +1 -0
- package/lib/experimental_agents/service_agents/wikipedia.js +1 -0
- package/lib/experimental_agents/sleeper_agents/index.d.ts +3 -2
- package/lib/experimental_agents/sleeper_agents/index.js +7 -4
- package/lib/experimental_agents/string_agents/index.d.ts +1 -2
- package/lib/experimental_agents/string_agents/index.js +15 -5
- package/lib/experimental_agents/string_agents/vanilla.d.ts +3 -0
- package/lib/experimental_agents/string_agents/vanilla.js +10 -0
- package/lib/experimental_agents/test_agents/index.d.ts +1 -7
- package/lib/experimental_agents/test_agents/index.js +15 -15
- package/lib/experimental_agents/test_agents/vanilla.d.ts +8 -0
- package/lib/experimental_agents/test_agents/vanilla.js +20 -0
- package/lib/experimental_agents/token_agent.d.ts +11 -1
- package/lib/experimental_agents/token_agent.js +30 -1
- package/lib/experimental_agents/vanilla.d.ts +6 -6
- package/lib/experimental_agents/vanilla.js +6 -6
- package/lib/graphai.d.ts +5 -5
- package/lib/graphai.js +6 -6
- package/lib/index.d.ts +1 -1
- package/lib/node.js +11 -10
- package/lib/task_manager.js +3 -6
- package/lib/transaction_log.d.ts +1 -1
- package/lib/transaction_log.js +2 -1
- package/lib/type.d.ts +4 -2
- package/lib/utils/test_agents.d.ts +2 -2
- package/lib/utils/test_agents.js +2 -2
- package/lib/utils/test_utils.d.ts +28 -0
- package/lib/utils/test_utils.js +26 -3
- package/package.json +10 -11
- package/lib/experimental_agents/packages.d.ts +0 -13
- package/lib/experimental_agents/packages.js +0 -35
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ An *agent function* is a TypeScript function, which implements a particular *age
|
|
|
120
120
|
There are additional optional parameters for developers of nested agents and agent filters.
|
|
121
121
|
|
|
122
122
|
- *graphData*: an optional GraphData (for nested agents)
|
|
123
|
-
- *agents*:
|
|
123
|
+
- *agents*: AgentFunctionInfoDictonary (for nested agents)
|
|
124
124
|
- *taskManager*: TaskManager (for nested agents)
|
|
125
125
|
- *log*: TransactionLog[] (for nested agents)
|
|
126
126
|
- *filterParams*: agent filter parameters (for agent filters)
|
|
@@ -317,9 +317,12 @@ flowchart LR
|
|
|
317
317
|
```
|
|
318
318
|
### Conditional Flow
|
|
319
319
|
|
|
320
|
-
|
|
320
|
+
GraphAI provides mechanisms to control the flow of data based on certain conditions. This is achieved through the *if* and *anyInput* properties.
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
#### If Property
|
|
323
|
+
|
|
324
|
+
The *if* property allows you to specify a condition that must be met for the data to flow into a particular node. The condition is defined by a data source. If the value obtained from the specified *data source* is truthy (i.e., not null, undefined, 0, false, NaN, or an empty array/string), the node will be executed; otherwise, it will be skipped.
|
|
325
|
+
For example, the following node will only be executed if the *tool_calls* property of the message from the LLM contains a value:
|
|
323
326
|
|
|
324
327
|
```typescript
|
|
325
328
|
tool_calls: {
|
|
@@ -331,11 +334,13 @@ A sample code, [weather chat](https://github.com/receptron/graphai/blob/main/sam
|
|
|
331
334
|
// This graph is nested only for the readability.
|
|
332
335
|
```
|
|
333
336
|
|
|
334
|
-
|
|
337
|
+
It is recommended to use the *if* property in conjunction with nested graphs for better code readability and organization.
|
|
338
|
+
|
|
339
|
+
#### AnyInput Property
|
|
335
340
|
|
|
336
|
-
The *anyInput* property (boolean) allows
|
|
341
|
+
The *anyInput* property (boolean) allows you to merge multiple data flow paths into a single node. When set to *true*, the agent function associated with the node will be executed as soon as data becomes available from any of the specified input data sources.
|
|
337
342
|
|
|
338
|
-
|
|
343
|
+
This property is particularly useful when you want to continue the flow regardless of which path the data comes from. In the weather chat sample application, it is used to continue the chat iteration whether a tool was requested by the LLM or not:
|
|
339
344
|
|
|
340
345
|
```typescript
|
|
341
346
|
reducer: {
|
|
@@ -346,25 +351,39 @@ The [weather chat](https://github.com/receptron/graphai/blob/main/samples/sample
|
|
|
346
351
|
},
|
|
347
352
|
```
|
|
348
353
|
|
|
354
|
+
In this example, the "reducer" node will execute as soon as data is available from either the "no_tool_calls" or "tool_calls.messagesWithSecondRes" data source.
|
|
355
|
+
|
|
356
|
+
By combining the *if* and *anyInput* properties, you can create complex conditional flows that control the execution of nodes based on the availability and values of data from various sources. This flexibility allows you to build sophisticated data-driven applications with GraphAI.
|
|
357
|
+
|
|
349
358
|
## Concurrency
|
|
350
359
|
|
|
351
|
-
|
|
360
|
+
GraphAI supports concurrent execution of tasks, allowing you to leverage parallelism and improve performance. The level of concurrency can be controlled through the *concurrency* property at the top level of the graph definition.
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
concurrency: 16 # Maximum number of concurrent tasks
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
If the *concurrency* property is not specified, the default value of 8 is used.
|
|
367
|
+
|
|
368
|
+
### Concurrency and Nested Graphs
|
|
352
369
|
|
|
353
370
|
Since the task queue is shared between the parent graph and the children graph (uness the graph is running remotely), tasks created by the child graph will be bound by the same concurrency specified by the parent graph.
|
|
354
371
|
|
|
355
372
|
Since the task executing the nested graph will be in "running" state while tasks within the child graph are runnig, the concurrency limit will be incremented by one when we start running the child graph and restored when it is completed.
|
|
356
373
|
|
|
357
|
-
|
|
374
|
+
### Task Prioritization
|
|
375
|
+
|
|
376
|
+
By default, tasks are executed in a first-in, first-out (FIFO) order with a neutral priority (0). However, you can assign custom priorities to nodes using the *priority* property. Tasks associated with nodes that have a higher priority value will be executed before those with lower priorities.
|
|
358
377
|
|
|
359
|
-
|
|
378
|
+
Negative priority values are allowed, enabling you to fine-tune the execution order based on your application's requirements.
|
|
360
379
|
|
|
361
380
|
## GraphAI class
|
|
362
381
|
|
|
363
|
-
### ```constructor(data: GraphData, callbackDictonary:
|
|
382
|
+
### ```constructor(data: GraphData, callbackDictonary: AgentFunctionInfoDictonary)```
|
|
364
383
|
Initializes a new instance of the GraphAI object with the specified graph data and a dictionary of callback functions.
|
|
365
384
|
|
|
366
385
|
- ```data: GraphData```: The graph data including nodes and optional concurrency limit.
|
|
367
|
-
- ```callbackDictonary:
|
|
386
|
+
- ```callbackDictonary: AgentFunctionInfoDictonary```: A dictionary mapping agent IDs to their respective callback functions info to be used for all nodes.
|
|
368
387
|
|
|
369
388
|
### ```async run(): Promise<ResultDataDictonary<ResultData>>```
|
|
370
389
|
Executes the graph asynchronously, starting with nodes that have no dependencies or whose dependencies have been met. The method continues to execute nodes as their dependencies are satisfied until all nodes have been executed or an error occurs.
|
|
@@ -1,9 +1,17 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var push_agent_1 = require("../../experimental_agents/array_agents/push_agent");
|
|
5
|
-
Object.defineProperty(exports, "pushAgent", { enumerable: true, get: function () { return push_agent_1.pushAgent; } });
|
|
6
|
-
var pop_agent_1 = require("../../experimental_agents/array_agents/pop_agent");
|
|
7
|
-
Object.defineProperty(exports, "popAgent", { enumerable: true, get: function () { return pop_agent_1.popAgent; } });
|
|
8
|
-
var shift_agent_1 = require("../../experimental_agents/array_agents/shift_agent");
|
|
9
|
-
Object.defineProperty(exports, "shiftAgent", { enumerable: true, get: function () { return shift_agent_1.shiftAgent; } });
|
|
17
|
+
__exportStar(require("./vanilla"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import pushAgent from "../../experimental_agents/array_agents/push_agent";
|
|
2
|
+
import popAgent from "../../experimental_agents/array_agents/pop_agent";
|
|
3
|
+
import shiftAgent from "../../experimental_agents/array_agents/shift_agent";
|
|
4
|
+
export { pushAgent, popAgent, shiftAgent };
|
|
@@ -0,0 +1,12 @@
|
|
|
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.shiftAgent = exports.popAgent = exports.pushAgent = void 0;
|
|
7
|
+
const push_agent_1 = __importDefault(require("../../experimental_agents/array_agents/push_agent"));
|
|
8
|
+
exports.pushAgent = push_agent_1.default;
|
|
9
|
+
const pop_agent_1 = __importDefault(require("../../experimental_agents/array_agents/pop_agent"));
|
|
10
|
+
exports.popAgent = pop_agent_1.default;
|
|
11
|
+
const shift_agent_1 = __importDefault(require("../../experimental_agents/array_agents/shift_agent"));
|
|
12
|
+
exports.shiftAgent = shift_agent_1.default;
|
|
@@ -5,6 +5,46 @@ declare const dataObjectMergeTemplateAgentInfo: {
|
|
|
5
5
|
agent: AgentFunction;
|
|
6
6
|
mock: AgentFunction;
|
|
7
7
|
samples: ({
|
|
8
|
+
inputs: ({
|
|
9
|
+
content1: string;
|
|
10
|
+
content2?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
content2: string;
|
|
13
|
+
content1?: undefined;
|
|
14
|
+
})[];
|
|
15
|
+
params: {};
|
|
16
|
+
result: {
|
|
17
|
+
content1: string;
|
|
18
|
+
content2: string;
|
|
19
|
+
content?: undefined;
|
|
20
|
+
a?: undefined;
|
|
21
|
+
b?: undefined;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
inputs: {
|
|
25
|
+
content1: string;
|
|
26
|
+
}[];
|
|
27
|
+
params: {};
|
|
28
|
+
result: {
|
|
29
|
+
content1: string;
|
|
30
|
+
content2?: undefined;
|
|
31
|
+
content?: undefined;
|
|
32
|
+
a?: undefined;
|
|
33
|
+
b?: undefined;
|
|
34
|
+
};
|
|
35
|
+
} | {
|
|
36
|
+
inputs: {
|
|
37
|
+
content: string;
|
|
38
|
+
}[];
|
|
39
|
+
params: {};
|
|
40
|
+
result: {
|
|
41
|
+
content: string;
|
|
42
|
+
content1?: undefined;
|
|
43
|
+
content2?: undefined;
|
|
44
|
+
a?: undefined;
|
|
45
|
+
b?: undefined;
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
8
48
|
inputs: ({
|
|
9
49
|
a: number;
|
|
10
50
|
b: number;
|
|
@@ -72,6 +112,9 @@ declare const dataObjectMergeTemplateAgentInfo: {
|
|
|
72
112
|
};
|
|
73
113
|
};
|
|
74
114
|
};
|
|
115
|
+
content1?: undefined;
|
|
116
|
+
content2?: undefined;
|
|
117
|
+
content?: undefined;
|
|
75
118
|
};
|
|
76
119
|
})[];
|
|
77
120
|
description: string;
|
|
@@ -24,6 +24,28 @@ const dataObjectMergeTemplateAgentInfo = {
|
|
|
24
24
|
agent: exports.dataObjectMergeTemplateAgent,
|
|
25
25
|
mock: exports.dataObjectMergeTemplateAgent,
|
|
26
26
|
samples: [
|
|
27
|
+
{
|
|
28
|
+
inputs: [{ content1: "hello" }, { content2: "test" }],
|
|
29
|
+
params: {},
|
|
30
|
+
result: {
|
|
31
|
+
content1: "hello",
|
|
32
|
+
content2: "test",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
inputs: [{ content1: "hello" }],
|
|
37
|
+
params: {},
|
|
38
|
+
result: {
|
|
39
|
+
content1: "hello",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
inputs: [{ content: "hello1" }, { content: "hello2" }],
|
|
44
|
+
params: {},
|
|
45
|
+
result: {
|
|
46
|
+
content: "hello2",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
27
49
|
{
|
|
28
50
|
inputs: sampleInputs,
|
|
29
51
|
params: sampleParams,
|
|
@@ -21,6 +21,21 @@ const dataSumTemplateAgentInfo = {
|
|
|
21
21
|
params: sampleParams,
|
|
22
22
|
result: sampleResult,
|
|
23
23
|
},
|
|
24
|
+
{
|
|
25
|
+
inputs: [1],
|
|
26
|
+
params: {},
|
|
27
|
+
result: 1,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
inputs: [1, 2],
|
|
31
|
+
params: {},
|
|
32
|
+
result: 3,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
inputs: [1, 2, 3],
|
|
36
|
+
params: {},
|
|
37
|
+
result: 6,
|
|
38
|
+
},
|
|
24
39
|
],
|
|
25
40
|
description: "Returns the sum of input values",
|
|
26
41
|
category: ["data"],
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { copyAgent } from "../../experimental_agents/data_agents/copy_agent";
|
|
1
|
+
export * from "./vanilla";
|
|
2
|
+
import dataObjectMergeTemplateAgent from "./data_object_merge_template_agent";
|
|
3
|
+
export { dataObjectMergeTemplateAgent };
|
|
@@ -1,11 +1,23 @@
|
|
|
1
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
2
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "dataSumTemplateAgent", { enumerable: true, get: function () { return data_sum_template_agent_1.dataSumTemplateAgent; } });
|
|
8
|
-
var property_filter_agent_1 = require("../../experimental_agents/data_agents/property_filter_agent");
|
|
9
|
-
Object.defineProperty(exports, "propertyFilterAgent", { enumerable: true, get: function () { return property_filter_agent_1.propertyFilterAgent; } });
|
|
10
|
-
var copy_agent_1 = require("../../experimental_agents/data_agents/copy_agent");
|
|
11
|
-
Object.defineProperty(exports, "copyAgent", { enumerable: true, get: function () { return copy_agent_1.copyAgent; } });
|
|
20
|
+
exports.dataObjectMergeTemplateAgent = void 0;
|
|
21
|
+
__exportStar(require("./vanilla"), exports);
|
|
22
|
+
const data_object_merge_template_agent_1 = __importDefault(require("./data_object_merge_template_agent"));
|
|
23
|
+
exports.dataObjectMergeTemplateAgent = data_object_merge_template_agent_1.default;
|
|
@@ -2,4 +2,5 @@ import totalAgent from "../../experimental_agents/data_agents/total_agent";
|
|
|
2
2
|
import dataObjectMergeTemplateAgent from "../../experimental_agents/data_agents/data_object_merge_template_agent";
|
|
3
3
|
import dataSumTemplateAgent from "../../experimental_agents/data_agents/data_sum_template_agent";
|
|
4
4
|
import propertyFilterAgent from "../../experimental_agents/data_agents/property_filter_agent";
|
|
5
|
-
|
|
5
|
+
import copyAgent from "../../experimental_agents/data_agents/copy_agent";
|
|
6
|
+
export { totalAgent, dataObjectMergeTemplateAgent, dataSumTemplateAgent, propertyFilterAgent, copyAgent };
|
|
@@ -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.propertyFilterAgent = exports.dataSumTemplateAgent = exports.dataObjectMergeTemplateAgent = exports.totalAgent = void 0;
|
|
6
|
+
exports.copyAgent = exports.propertyFilterAgent = exports.dataSumTemplateAgent = exports.dataObjectMergeTemplateAgent = exports.totalAgent = void 0;
|
|
7
7
|
const total_agent_1 = __importDefault(require("../../experimental_agents/data_agents/total_agent"));
|
|
8
8
|
exports.totalAgent = total_agent_1.default;
|
|
9
9
|
const data_object_merge_template_agent_1 = __importDefault(require("../../experimental_agents/data_agents/data_object_merge_template_agent"));
|
|
@@ -12,3 +12,5 @@ const data_sum_template_agent_1 = __importDefault(require("../../experimental_ag
|
|
|
12
12
|
exports.dataSumTemplateAgent = data_sum_template_agent_1.default;
|
|
13
13
|
const property_filter_agent_1 = __importDefault(require("../../experimental_agents/data_agents/property_filter_agent"));
|
|
14
14
|
exports.propertyFilterAgent = property_filter_agent_1.default;
|
|
15
|
+
const copy_agent_1 = __importDefault(require("../../experimental_agents/data_agents/copy_agent"));
|
|
16
|
+
exports.copyAgent = copy_agent_1.default;
|
|
@@ -2,55 +2,156 @@ import { AgentFunction } from "../../graphai";
|
|
|
2
2
|
export declare const propertyFilterAgent: AgentFunction<{
|
|
3
3
|
include?: Array<string>;
|
|
4
4
|
exclude?: Array<string>;
|
|
5
|
+
alter?: Record<string, Record<string, string>>;
|
|
6
|
+
inject?: Record<string, Record<string, any>>;
|
|
5
7
|
}>;
|
|
6
8
|
declare const propertyFilterAgentInfo: {
|
|
7
9
|
name: string;
|
|
8
10
|
agent: AgentFunction<{
|
|
9
11
|
include?: string[] | undefined;
|
|
10
12
|
exclude?: string[] | undefined;
|
|
13
|
+
alter?: Record<string, Record<string, string>> | undefined;
|
|
14
|
+
inject?: Record<string, Record<string, any>> | undefined;
|
|
11
15
|
}>;
|
|
12
16
|
mock: AgentFunction<{
|
|
13
17
|
include?: string[] | undefined;
|
|
14
18
|
exclude?: string[] | undefined;
|
|
19
|
+
alter?: Record<string, Record<string, string>> | undefined;
|
|
20
|
+
inject?: Record<string, Record<string, any>> | undefined;
|
|
15
21
|
}>;
|
|
16
22
|
samples: ({
|
|
17
|
-
inputs: {
|
|
23
|
+
inputs: (string | {
|
|
18
24
|
color: string;
|
|
19
25
|
model: string;
|
|
20
26
|
type: string;
|
|
21
27
|
maker: string;
|
|
22
28
|
range: number;
|
|
23
|
-
}[];
|
|
29
|
+
})[];
|
|
24
30
|
params: {
|
|
25
31
|
include: string[];
|
|
26
32
|
exclude?: undefined;
|
|
33
|
+
alter?: undefined;
|
|
34
|
+
inject?: undefined;
|
|
27
35
|
};
|
|
28
36
|
result: {
|
|
29
37
|
color: string;
|
|
30
38
|
model: string;
|
|
31
|
-
type?: undefined;
|
|
32
|
-
maker?: undefined;
|
|
33
|
-
range?: undefined;
|
|
34
39
|
};
|
|
35
40
|
} | {
|
|
36
|
-
inputs: {
|
|
41
|
+
inputs: (string | {
|
|
37
42
|
color: string;
|
|
38
43
|
model: string;
|
|
39
44
|
type: string;
|
|
40
45
|
maker: string;
|
|
41
46
|
range: number;
|
|
47
|
+
}[])[];
|
|
48
|
+
params: {
|
|
49
|
+
include: string[];
|
|
50
|
+
exclude?: undefined;
|
|
51
|
+
alter?: undefined;
|
|
52
|
+
inject?: undefined;
|
|
53
|
+
};
|
|
54
|
+
result: {
|
|
55
|
+
color: string;
|
|
56
|
+
model: string;
|
|
42
57
|
}[];
|
|
58
|
+
} | {
|
|
59
|
+
inputs: (string | {
|
|
60
|
+
color: string;
|
|
61
|
+
model: string;
|
|
62
|
+
type: string;
|
|
63
|
+
maker: string;
|
|
64
|
+
range: number;
|
|
65
|
+
}[])[];
|
|
43
66
|
params: {
|
|
44
67
|
exclude: string[];
|
|
45
68
|
include?: undefined;
|
|
69
|
+
alter?: undefined;
|
|
70
|
+
inject?: undefined;
|
|
46
71
|
};
|
|
47
72
|
result: {
|
|
48
73
|
type: string;
|
|
49
74
|
maker: string;
|
|
50
75
|
range: number;
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
}[];
|
|
77
|
+
} | {
|
|
78
|
+
inputs: (string | {
|
|
79
|
+
color: string;
|
|
80
|
+
model: string;
|
|
81
|
+
type: string;
|
|
82
|
+
maker: string;
|
|
83
|
+
range: number;
|
|
84
|
+
}[])[];
|
|
85
|
+
params: {
|
|
86
|
+
alter: {
|
|
87
|
+
color: {
|
|
88
|
+
red: string;
|
|
89
|
+
blue: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
include?: undefined;
|
|
93
|
+
exclude?: undefined;
|
|
94
|
+
inject?: undefined;
|
|
53
95
|
};
|
|
96
|
+
result: {
|
|
97
|
+
color: string;
|
|
98
|
+
model: string;
|
|
99
|
+
type: string;
|
|
100
|
+
maker: string;
|
|
101
|
+
range: number;
|
|
102
|
+
}[];
|
|
103
|
+
} | {
|
|
104
|
+
inputs: (string | {
|
|
105
|
+
color: string;
|
|
106
|
+
model: string;
|
|
107
|
+
type: string;
|
|
108
|
+
maker: string;
|
|
109
|
+
range: number;
|
|
110
|
+
}[])[];
|
|
111
|
+
params: {
|
|
112
|
+
inject: {
|
|
113
|
+
maker: {
|
|
114
|
+
from: number;
|
|
115
|
+
index?: undefined;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
include?: undefined;
|
|
119
|
+
exclude?: undefined;
|
|
120
|
+
alter?: undefined;
|
|
121
|
+
};
|
|
122
|
+
result: {
|
|
123
|
+
color: string;
|
|
124
|
+
model: string;
|
|
125
|
+
type: string;
|
|
126
|
+
maker: string;
|
|
127
|
+
range: number;
|
|
128
|
+
}[];
|
|
129
|
+
} | {
|
|
130
|
+
inputs: (string | {
|
|
131
|
+
color: string;
|
|
132
|
+
model: string;
|
|
133
|
+
type: string;
|
|
134
|
+
maker: string;
|
|
135
|
+
range: number;
|
|
136
|
+
}[])[];
|
|
137
|
+
params: {
|
|
138
|
+
inject: {
|
|
139
|
+
maker: {
|
|
140
|
+
index: number;
|
|
141
|
+
from: number;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
include?: undefined;
|
|
145
|
+
exclude?: undefined;
|
|
146
|
+
alter?: undefined;
|
|
147
|
+
};
|
|
148
|
+
result: {
|
|
149
|
+
color: string;
|
|
150
|
+
model: string;
|
|
151
|
+
type: string;
|
|
152
|
+
maker: string;
|
|
153
|
+
range: number;
|
|
154
|
+
}[];
|
|
54
155
|
})[];
|
|
55
156
|
description: string;
|
|
56
157
|
category: string[];
|
|
@@ -1,40 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.propertyFilterAgent = void 0;
|
|
4
|
-
const applyFilter = (input, include, exclude) => {
|
|
4
|
+
const applyFilter = (input, index, inputs, include, exclude, alter, inject) => {
|
|
5
5
|
const propIds = include ? include : Object.keys(input);
|
|
6
6
|
const excludeSet = new Set(exclude ?? []);
|
|
7
7
|
return propIds.reduce((tmp, propId) => {
|
|
8
8
|
if (!excludeSet.has(propId)) {
|
|
9
|
-
|
|
9
|
+
const injection = inject && inject[propId];
|
|
10
|
+
const mapping = alter && alter[propId];
|
|
11
|
+
if (injection && (injection.index === undefined || injection.index === index)) {
|
|
12
|
+
tmp[propId] = inputs[injection.from];
|
|
13
|
+
}
|
|
14
|
+
else if (mapping && mapping[input[propId]]) {
|
|
15
|
+
tmp[propId] = mapping[input[propId]];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
tmp[propId] = input[propId];
|
|
19
|
+
}
|
|
10
20
|
}
|
|
11
21
|
return tmp;
|
|
12
22
|
}, {});
|
|
13
23
|
};
|
|
14
24
|
const propertyFilterAgent = async ({ inputs, params }) => {
|
|
15
25
|
const [input] = inputs;
|
|
16
|
-
const { include, exclude } = params;
|
|
26
|
+
const { include, exclude, alter, inject } = params;
|
|
17
27
|
if (Array.isArray(input)) {
|
|
18
|
-
return input.map((item) => applyFilter(item, include, exclude));
|
|
28
|
+
return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject));
|
|
19
29
|
}
|
|
20
|
-
return applyFilter(input, include, exclude);
|
|
30
|
+
return applyFilter(input, 0, inputs, include, exclude, alter);
|
|
21
31
|
};
|
|
22
32
|
exports.propertyFilterAgent = propertyFilterAgent;
|
|
23
|
-
const
|
|
33
|
+
const testInputs = [
|
|
34
|
+
[
|
|
35
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla", range: 300 },
|
|
36
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
37
|
+
],
|
|
38
|
+
"Tesla Motors",
|
|
39
|
+
];
|
|
24
40
|
const propertyFilterAgentInfo = {
|
|
25
41
|
name: "propertyFilterAgent",
|
|
26
42
|
agent: exports.propertyFilterAgent,
|
|
27
43
|
mock: exports.propertyFilterAgent,
|
|
28
44
|
samples: [
|
|
29
45
|
{
|
|
30
|
-
inputs,
|
|
46
|
+
inputs: [testInputs[0][0]],
|
|
31
47
|
params: { include: ["color", "model"] },
|
|
32
48
|
result: { color: "red", model: "Model 3" },
|
|
33
49
|
},
|
|
34
50
|
{
|
|
35
|
-
inputs,
|
|
51
|
+
inputs: testInputs,
|
|
52
|
+
params: { include: ["color", "model"] },
|
|
53
|
+
result: [
|
|
54
|
+
{ color: "red", model: "Model 3" },
|
|
55
|
+
{ color: "blue", model: "Model Y" },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
inputs: testInputs,
|
|
36
60
|
params: { exclude: ["color", "model"] },
|
|
37
|
-
result:
|
|
61
|
+
result: [
|
|
62
|
+
{ type: "EV", maker: "Tesla", range: 300 },
|
|
63
|
+
{ type: "EV", maker: "Tesla", range: 400 },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
inputs: testInputs,
|
|
68
|
+
params: { alter: { color: { red: "blue", blue: "red" } } },
|
|
69
|
+
result: [
|
|
70
|
+
{ color: "blue", model: "Model 3", type: "EV", maker: "Tesla", range: 300 },
|
|
71
|
+
{ color: "red", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
inputs: testInputs,
|
|
76
|
+
params: { inject: { maker: { from: 1 } } },
|
|
77
|
+
result: [
|
|
78
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
|
|
79
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla Motors", range: 400 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
inputs: testInputs,
|
|
84
|
+
params: { inject: { maker: { index: 0, from: 1 } } },
|
|
85
|
+
result: [
|
|
86
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
|
|
87
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
88
|
+
],
|
|
38
89
|
},
|
|
39
90
|
],
|
|
40
91
|
description: "Filter properties based on property name either with 'include' or 'exclude'",
|
|
@@ -37,6 +37,19 @@ declare const totalAgentInfo: {
|
|
|
37
37
|
c: number;
|
|
38
38
|
d: number;
|
|
39
39
|
};
|
|
40
|
+
} | {
|
|
41
|
+
inputs: ({
|
|
42
|
+
a: number;
|
|
43
|
+
b?: undefined;
|
|
44
|
+
} | {
|
|
45
|
+
a: number;
|
|
46
|
+
b: number;
|
|
47
|
+
})[];
|
|
48
|
+
params: {};
|
|
49
|
+
result: {
|
|
50
|
+
a: number;
|
|
51
|
+
b: number;
|
|
52
|
+
};
|
|
40
53
|
})[];
|
|
41
54
|
description: string;
|
|
42
55
|
category: string[];
|