graphai 0.1.0 → 0.1.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 +47 -35
- package/lib/experimental_agents/array_agents/index.d.ts +3 -0
- package/lib/experimental_agents/array_agents/index.js +9 -0
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/pop_agent.js +15 -0
- package/lib/experimental_agents/array_agents/push_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/push_agent.js +14 -0
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +2 -0
- package/lib/experimental_agents/{array_agents.js → array_agents/shift_agent.js} +2 -17
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +28 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +38 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +17 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +30 -0
- package/lib/experimental_agents/data_agents/index.d.ts +3 -0
- package/lib/experimental_agents/data_agents/index.js +9 -0
- package/lib/experimental_agents/data_agents/total_agent.d.ts +46 -0
- package/lib/experimental_agents/data_agents/total_agent.js +51 -0
- package/lib/experimental_agents/embedding_agent.d.ts +6 -0
- package/lib/experimental_agents/embedding_agent.js +43 -0
- package/lib/experimental_agents/index.d.ts +8 -3
- package/lib/experimental_agents/index.js +8 -3
- package/lib/experimental_agents/map_agent.d.ts +4 -0
- package/lib/experimental_agents/map_agent.js +46 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +4 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +24 -0
- package/lib/experimental_agents/matrix_agents/index.d.ts +2 -0
- package/lib/experimental_agents/matrix_agents/index.js +7 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +6 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +29 -0
- package/lib/experimental_agents/nested_agent.d.ts +1 -2
- package/lib/experimental_agents/nested_agent.js +24 -8
- package/lib/experimental_agents/slashgpt_agent.d.ts +1 -1
- package/lib/experimental_agents/slashgpt_agent.js +2 -7
- package/lib/experimental_agents/sleeper_agents/index.d.ts +2 -0
- package/lib/experimental_agents/sleeper_agents/index.js +7 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +5 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +16 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +6 -0
- package/lib/experimental_agents/{sleeper_agent.js → sleeper_agents/sleeper_agent_debug.js} +4 -13
- package/lib/experimental_agents/string_agents/index.d.ts +2 -0
- package/lib/experimental_agents/string_agents/index.js +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +39 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +64 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +27 -0
- package/lib/experimental_agents/string_agents/string_template_agent.js +33 -0
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/bypass_agent.js +10 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.js +9 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.js +11 -0
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/counting_agent.js +11 -0
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +7 -0
- package/lib/experimental_agents/test_agents/index.d.ts +6 -0
- package/lib/experimental_agents/test_agents/index.js +15 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +10 -0
- package/lib/experimental_agents/token_agent.d.ts +6 -0
- package/lib/experimental_agents/token_agent.js +33 -0
- package/lib/graphai.d.ts +23 -18
- package/lib/graphai.js +106 -115
- package/lib/index.d.ts +2 -0
- package/lib/node.d.ts +30 -25
- package/lib/node.js +131 -101
- package/lib/task_manager.d.ts +20 -0
- package/lib/task_manager.js +69 -0
- package/lib/transaction_log.d.ts +27 -0
- package/lib/transaction_log.js +56 -0
- package/lib/type.d.ts +45 -32
- package/lib/type.js +1 -0
- package/lib/utils/test_agents.d.ts +2 -0
- package/lib/utils/test_agents.js +20 -0
- package/lib/utils/test_utils.d.ts +12 -0
- package/lib/utils/test_utils.js +34 -0
- package/lib/utils/utils.d.ts +3 -1
- package/lib/utils/utils.js +17 -6
- package/lib/validator.d.ts +2 -0
- package/lib/validator.js +28 -0
- package/lib/validators/agent_validator.d.ts +1 -0
- package/lib/validators/agent_validator.js +12 -0
- package/lib/validators/common.d.ts +3 -0
- package/lib/validators/common.js +6 -0
- package/lib/validators/computed_node_validator.d.ts +2 -0
- package/lib/validators/computed_node_validator.js +13 -0
- package/lib/validators/graph_data_validator.d.ts +3 -0
- package/lib/validators/graph_data_validator.js +43 -0
- package/lib/validators/nodeValidator.d.ts +2 -0
- package/lib/validators/nodeValidator.js +13 -0
- package/lib/validators/relation_validator.d.ts +2 -0
- package/lib/validators/relation_validator.js +62 -0
- package/lib/validators/static_node_validator.d.ts +2 -0
- package/lib/validators/static_node_validator.js +13 -0
- package/package.json +10 -14
- package/lib/experimental_agents/array_agents.d.ts +0 -4
- package/lib/experimental_agents/data_agent.d.ts +0 -3
- package/lib/experimental_agents/data_agent.js +0 -25
- package/lib/experimental_agents/sleeper_agent.d.ts +0 -10
- package/lib/experimental_agents/string_agent.d.ts +0 -7
- package/lib/experimental_agents/string_agent.js +0 -15
- package/lib/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -48
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
|
@@ -0,0 +1,34 @@
|
|
|
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.agentTestRunner = exports.defaultTestContext = void 0;
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const node_test_1 = __importDefault(require("node:test"));
|
|
9
|
+
exports.defaultTestContext = {
|
|
10
|
+
debugInfo: {
|
|
11
|
+
nodeId: "test",
|
|
12
|
+
retry: 0,
|
|
13
|
+
verbose: true,
|
|
14
|
+
},
|
|
15
|
+
params: {},
|
|
16
|
+
agents: {},
|
|
17
|
+
log: [],
|
|
18
|
+
};
|
|
19
|
+
// for agent
|
|
20
|
+
const agentTestRunner = async (agentInfo) => {
|
|
21
|
+
(0, node_test_1.default)(`test ${agentInfo.name}`, async () => {
|
|
22
|
+
const { agent, samples } = agentInfo;
|
|
23
|
+
for await (const sample of samples) {
|
|
24
|
+
const { params, inputs, result } = sample;
|
|
25
|
+
const actual = await agent({
|
|
26
|
+
...exports.defaultTestContext,
|
|
27
|
+
params,
|
|
28
|
+
inputs,
|
|
29
|
+
});
|
|
30
|
+
node_assert_1.default.deepStrictEqual(result, actual);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.agentTestRunner = agentTestRunner;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { DataSource } from "../type";
|
|
2
2
|
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
3
|
-
export declare const parseNodeName: (
|
|
3
|
+
export declare const parseNodeName: (inputNodeId: string) => DataSource;
|
|
4
|
+
export declare function assert(condition: boolean, message: string, isWarn?: boolean): asserts condition;
|
|
5
|
+
export declare const isObject: (x: unknown) => boolean;
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNodeName = exports.sleep = void 0;
|
|
3
|
+
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
|
};
|
|
7
7
|
exports.sleep = sleep;
|
|
8
|
-
const parseNodeName = (
|
|
9
|
-
const parts =
|
|
8
|
+
const parseNodeName = (inputNodeId) => {
|
|
9
|
+
const parts = inputNodeId.split(".");
|
|
10
10
|
if (parts.length == 1) {
|
|
11
11
|
return { nodeId: parts[0] };
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
return { nodeId: parts[0], propId: parts[1] };
|
|
15
|
-
}
|
|
13
|
+
return { nodeId: parts[0], propId: parts[1] };
|
|
16
14
|
};
|
|
17
15
|
exports.parseNodeName = parseNodeName;
|
|
16
|
+
function assert(condition, message, isWarn = false) {
|
|
17
|
+
if (!condition) {
|
|
18
|
+
if (!isWarn) {
|
|
19
|
+
throw new Error(message);
|
|
20
|
+
}
|
|
21
|
+
console.warn("warn: " + message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.assert = assert;
|
|
25
|
+
const isObject = (x) => {
|
|
26
|
+
return x !== null && typeof x === "object";
|
|
27
|
+
};
|
|
28
|
+
exports.isObject = isObject;
|
package/lib/validator.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateGraphData = void 0;
|
|
4
|
+
const graph_data_validator_1 = require("./validators/graph_data_validator");
|
|
5
|
+
const nodeValidator_1 = require("./validators/nodeValidator");
|
|
6
|
+
const static_node_validator_1 = require("./validators/static_node_validator");
|
|
7
|
+
const computed_node_validator_1 = require("./validators/computed_node_validator");
|
|
8
|
+
const relation_validator_1 = require("./validators/relation_validator");
|
|
9
|
+
const agent_validator_1 = require("./validators/agent_validator");
|
|
10
|
+
const validateGraphData = (data, agentIds) => {
|
|
11
|
+
(0, graph_data_validator_1.graphNodesValidator)(data);
|
|
12
|
+
(0, graph_data_validator_1.graphDataValidator)(data);
|
|
13
|
+
const computedNodeIds = [];
|
|
14
|
+
const staticNodeIds = [];
|
|
15
|
+
const graphAgentIds = new Set();
|
|
16
|
+
Object.keys(data.nodes).forEach((nodeId) => {
|
|
17
|
+
const node = data.nodes[nodeId];
|
|
18
|
+
const isStaticNode = "value" in node;
|
|
19
|
+
(0, nodeValidator_1.nodeValidator)(node);
|
|
20
|
+
const agentId = isStaticNode ? "" : node.agentId;
|
|
21
|
+
isStaticNode && (0, static_node_validator_1.staticNodeValidator)(node) && staticNodeIds.push(nodeId);
|
|
22
|
+
!isStaticNode && (0, computed_node_validator_1.computedNodeValidator)(node) && computedNodeIds.push(nodeId) && graphAgentIds.add(agentId);
|
|
23
|
+
});
|
|
24
|
+
(0, agent_validator_1.agentValidator)(graphAgentIds, new Set(agentIds));
|
|
25
|
+
(0, relation_validator_1.relationValidator)(data, staticNodeIds, computedNodeIds);
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
exports.validateGraphData = validateGraphData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const agentValidator: (graphAgentIds: Set<string>, agentIds: Set<string>) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentValidator = void 0;
|
|
4
|
+
const agentValidator = (graphAgentIds, agentIds) => {
|
|
5
|
+
graphAgentIds.forEach((agentId) => {
|
|
6
|
+
if (!agentIds.has(agentId)) {
|
|
7
|
+
throw new Error("Invalid AgentId : " + agentId + " is not in callbackDictonary.");
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return true;
|
|
11
|
+
};
|
|
12
|
+
exports.agentValidator = agentValidator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
|
+
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose"];
|
|
5
|
+
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agentId", "graph", "isResult"];
|
|
6
|
+
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedNodeValidator = void 0;
|
|
4
|
+
const common_1 = require("../validators/common");
|
|
5
|
+
const computedNodeValidator = (nodeData) => {
|
|
6
|
+
Object.keys(nodeData).forEach((key) => {
|
|
7
|
+
if (!common_1.computedNodeAttributeKeys.includes(key)) {
|
|
8
|
+
throw new Error("Computed node does not allow " + key);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
exports.computedNodeValidator = computedNodeValidator;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.graphDataValidator = exports.graphNodesValidator = void 0;
|
|
4
|
+
const common_1 = require("../validators/common");
|
|
5
|
+
const graphNodesValidator = (data) => {
|
|
6
|
+
if (data.nodes === undefined) {
|
|
7
|
+
throw new Error("Invalid Graph Data: no nodes");
|
|
8
|
+
}
|
|
9
|
+
if (typeof data.nodes !== "object") {
|
|
10
|
+
throw new Error("Invalid Graph Data: invalid nodes");
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(data.nodes)) {
|
|
13
|
+
throw new Error("Invalid Graph Data: nodes must be object");
|
|
14
|
+
}
|
|
15
|
+
if (Object.keys(data.nodes).length === 0) {
|
|
16
|
+
throw new Error("Invalid Graph Data: nodes is empty");
|
|
17
|
+
}
|
|
18
|
+
Object.keys(data).forEach((key) => {
|
|
19
|
+
if (!common_1.graphDataAttributeKeys.includes(key)) {
|
|
20
|
+
throw new Error("Graph Data does not allow " + key);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.graphNodesValidator = graphNodesValidator;
|
|
25
|
+
const graphDataValidator = (data) => {
|
|
26
|
+
if (data.loop) {
|
|
27
|
+
if (data.loop.count === undefined && data.loop.while === undefined) {
|
|
28
|
+
throw new Error("Loop: Either count or while is required in loop");
|
|
29
|
+
}
|
|
30
|
+
if (data.loop.count !== undefined && data.loop.while !== undefined) {
|
|
31
|
+
throw new Error("Loop: Both count and while cannot be set");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (data.concurrency !== undefined) {
|
|
35
|
+
if (!Number.isInteger(data.concurrency)) {
|
|
36
|
+
throw new Error("Concurrency must be an integer");
|
|
37
|
+
}
|
|
38
|
+
if (data.concurrency < 1) {
|
|
39
|
+
throw new Error("Concurrency must be a positive integer");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.graphDataValidator = graphDataValidator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nodeValidator = void 0;
|
|
4
|
+
const nodeValidator = (nodeData) => {
|
|
5
|
+
if (nodeData.agentId && nodeData.value) {
|
|
6
|
+
throw new Error("Cannot set both agentId and value");
|
|
7
|
+
}
|
|
8
|
+
if (!("agentId" in nodeData) && !("value" in nodeData)) {
|
|
9
|
+
throw new Error("Either agentId or value is required");
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
exports.nodeValidator = nodeValidator;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.relationValidator = void 0;
|
|
4
|
+
const utils_1 = require("../utils/utils");
|
|
5
|
+
const relationValidator = (data, staticNodeIds, computedNodeIds) => {
|
|
6
|
+
const nodeIds = new Set(Object.keys(data.nodes));
|
|
7
|
+
const pendings = {};
|
|
8
|
+
const waitlist = {};
|
|
9
|
+
// validate input relation and set pendings and wait list
|
|
10
|
+
computedNodeIds.forEach((computedNodeId) => {
|
|
11
|
+
const nodeData = data.nodes[computedNodeId];
|
|
12
|
+
pendings[computedNodeId] = new Set();
|
|
13
|
+
if (nodeData.inputs) {
|
|
14
|
+
nodeData.inputs.forEach((inputNodeId) => {
|
|
15
|
+
const input = (0, utils_1.parseNodeName)(inputNodeId).nodeId;
|
|
16
|
+
if (!nodeIds.has(input)) {
|
|
17
|
+
throw new Error(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${input}`);
|
|
18
|
+
}
|
|
19
|
+
waitlist[input] === undefined && (waitlist[input] = new Set());
|
|
20
|
+
pendings[computedNodeId].add(input);
|
|
21
|
+
waitlist[input].add(computedNodeId);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
// TODO. validate update
|
|
26
|
+
staticNodeIds.forEach((staticNodeId) => {
|
|
27
|
+
const nodeData = data.nodes[staticNodeId];
|
|
28
|
+
const update = nodeData.update;
|
|
29
|
+
if (update) {
|
|
30
|
+
const updateNodeId = (0, utils_1.parseNodeName)(update).nodeId;
|
|
31
|
+
if (!nodeIds.has(updateNodeId)) {
|
|
32
|
+
throw new Error(`Update not match: NodeId ${staticNodeId}, update: ${update}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const cycle = (possibles) => {
|
|
37
|
+
possibles.forEach((possobleNodeId) => {
|
|
38
|
+
(waitlist[possobleNodeId] || []).forEach((waitingNodeId) => {
|
|
39
|
+
pendings[waitingNodeId].delete(possobleNodeId);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const running = [];
|
|
43
|
+
Object.keys(pendings).forEach((pendingNodeId) => {
|
|
44
|
+
if (pendings[pendingNodeId].size === 0) {
|
|
45
|
+
running.push(pendingNodeId);
|
|
46
|
+
delete pendings[pendingNodeId];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return running;
|
|
50
|
+
};
|
|
51
|
+
let runningQueue = cycle(staticNodeIds);
|
|
52
|
+
if (runningQueue.length === 0) {
|
|
53
|
+
throw new Error("No Initial Runnning Node");
|
|
54
|
+
}
|
|
55
|
+
do {
|
|
56
|
+
runningQueue = cycle(runningQueue);
|
|
57
|
+
} while (runningQueue.length > 0);
|
|
58
|
+
if (Object.keys(pendings).length > 0) {
|
|
59
|
+
throw new Error("Some nodes are not executed: " + Object.keys(pendings).join(", "));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.relationValidator = relationValidator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.staticNodeValidator = void 0;
|
|
4
|
+
const common_1 = require("../validators/common");
|
|
5
|
+
const staticNodeValidator = (nodeData) => {
|
|
6
|
+
Object.keys(nodeData).forEach((key) => {
|
|
7
|
+
if (!common_1.staticNodeAttributeKeys.includes(key)) {
|
|
8
|
+
throw new Error("Static node does not allow " + key);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
exports.staticNodeValidator = staticNodeValidator;
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Asynchronous data flow execution engine
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"graphai": "lib/graphai_cli.js"
|
|
8
|
-
},
|
|
9
6
|
"files": [
|
|
10
7
|
"./lib"
|
|
11
8
|
],
|
|
@@ -14,20 +11,20 @@
|
|
|
14
11
|
"eslint": "eslint --fix --ext .ts ./src ./tests ./samples",
|
|
15
12
|
"format": "prettier --write '{src,tests,samples}/**/*.ts' .eslintrc.js",
|
|
16
13
|
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
17
|
-
"
|
|
14
|
+
"b": "yarn run format && yarn run eslint && yarn run build",
|
|
18
15
|
"samples": "npx ts-node -r tsconfig-paths/register samples/sample_runner.ts",
|
|
19
16
|
"sample": "npx ts-node -r tsconfig-paths/register"
|
|
20
17
|
},
|
|
21
18
|
"repository": {
|
|
22
19
|
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/
|
|
20
|
+
"url": "git+https://github.com/receptron/graphai"
|
|
24
21
|
},
|
|
25
|
-
"author": "Satoshi Nakajima",
|
|
22
|
+
"author": "Satoshi Nakajima, Isamu Arimoto",
|
|
26
23
|
"license": "MIT",
|
|
27
24
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/receptron/graphai/issues"
|
|
29
26
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
27
|
+
"homepage": "https://github.com/receptron/graphai#readme",
|
|
31
28
|
"devDependencies": {
|
|
32
29
|
"@inquirer/prompts": "^5.0.0",
|
|
33
30
|
"@types/express": "^4.17.21",
|
|
@@ -43,14 +40,13 @@
|
|
|
43
40
|
"openai": "^4.12.4",
|
|
44
41
|
"prettier": "^3.0.3",
|
|
45
42
|
"slashgpt": "^0.0.8",
|
|
43
|
+
"tiktoken": "^1.0.14",
|
|
46
44
|
"ts-node": "^10.9.1",
|
|
47
45
|
"tsc-alias": "^1.8.8",
|
|
48
46
|
"tsconfig-paths": "^4.2.0",
|
|
49
47
|
"typescript": "^5.2.2",
|
|
50
|
-
"wikipedia": "^2.1.2"
|
|
51
|
-
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"yaml": "^2.3.3"
|
|
48
|
+
"wikipedia": "^2.1.2",
|
|
49
|
+
"yaml": "^2.4.1"
|
|
54
50
|
},
|
|
55
51
|
"types": "./lib/index.d.ts",
|
|
56
52
|
"directories": {
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AgentFunction } from "../graphai";
|
|
2
|
-
export declare const pushAgent: AgentFunction<Record<string, any>, Record<string, any>, Record<string, any>>;
|
|
3
|
-
export declare const popAgent: AgentFunction<Record<string, any>, Record<string, any>, Record<string, any>>;
|
|
4
|
-
export declare const shiftAgent: AgentFunction<Record<string, any>, Record<string, any>, Record<string, any>>;
|
|
@@ -1,25 +0,0 @@
|
|
|
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.dataSumTemplateAgent = exports.dataObjectMergeTemplateAgent = void 0;
|
|
7
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
-
const dataObjectMergeTemplateAgent = async ({ nodeId, params, inputs, verbose }) => {
|
|
9
|
-
if (verbose) {
|
|
10
|
-
console.log("executing", nodeId, params);
|
|
11
|
-
}
|
|
12
|
-
return inputs.reduce((tmp, input) => {
|
|
13
|
-
return (0, deepmerge_1.default)(tmp, input);
|
|
14
|
-
}, {});
|
|
15
|
-
};
|
|
16
|
-
exports.dataObjectMergeTemplateAgent = dataObjectMergeTemplateAgent;
|
|
17
|
-
const dataSumTemplateAgent = async ({ nodeId, params, inputs, verbose }) => {
|
|
18
|
-
if (verbose) {
|
|
19
|
-
console.log("executing", nodeId, params);
|
|
20
|
-
}
|
|
21
|
-
return inputs.reduce((tmp, input) => {
|
|
22
|
-
return tmp + input;
|
|
23
|
-
}, 0);
|
|
24
|
-
};
|
|
25
|
-
exports.dataSumTemplateAgent = dataSumTemplateAgent;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AgentFunction } from "../graphai";
|
|
2
|
-
export declare const sleeperAgent: AgentFunction<{
|
|
3
|
-
duration: number;
|
|
4
|
-
value?: Record<string, any>;
|
|
5
|
-
}>;
|
|
6
|
-
export declare const sleeperAgentDebug: AgentFunction<{
|
|
7
|
-
duration: number;
|
|
8
|
-
value?: Record<string, any>;
|
|
9
|
-
fail?: boolean;
|
|
10
|
-
}>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringTemplateAgent = void 0;
|
|
4
|
-
// see example
|
|
5
|
-
// tests/agents/test_string_agent.ts
|
|
6
|
-
const stringTemplateAgent = async ({ nodeId, params, inputs, verbose }) => {
|
|
7
|
-
if (verbose) {
|
|
8
|
-
console.log("executing", nodeId, params);
|
|
9
|
-
}
|
|
10
|
-
const content = inputs.reduce((template, input, index) => {
|
|
11
|
-
return template.replace("${" + index + "}", input[params.inputKey ?? "content"]);
|
|
12
|
-
}, params.template);
|
|
13
|
-
return { content };
|
|
14
|
-
};
|
|
15
|
-
exports.stringTemplateAgent = stringTemplateAgent;
|
package/lib/graphai_cli.d.ts
DELETED
package/lib/graphai_cli.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const graphai_1 = require("./graphai");
|
|
8
|
-
const experimental_agents_1 = require("./experimental_agents");
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const yaml_1 = __importDefault(require("yaml"));
|
|
12
|
-
const testAgent = async () => {
|
|
13
|
-
return {};
|
|
14
|
-
};
|
|
15
|
-
const main = async () => {
|
|
16
|
-
const file = process.argv[2];
|
|
17
|
-
if (file === undefined) {
|
|
18
|
-
console.log("no file");
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const file_path = path_1.default.resolve(process.cwd() + "/" + file);
|
|
22
|
-
if (!fs_1.default.existsSync(file_path)) {
|
|
23
|
-
console.log("no file");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const graph_data_file = fs_1.default.readFileSync(file_path, "utf8");
|
|
28
|
-
const graph_data = yaml_1.default.parse(graph_data_file);
|
|
29
|
-
const graph = new graphai_1.GraphAI(graph_data, { testAgent, slashGPTAgent: experimental_agents_1.slashGPTAgent, stringTemplateAgent: experimental_agents_1.stringTemplateAgent });
|
|
30
|
-
const results = await graph.run();
|
|
31
|
-
console.log(results);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
console.log("error", e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
main();
|
package/lib/log.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ResultData, TransactionLog, NodeDataParams } from "./type";
|
|
2
|
-
export declare const injectValueLog: (nodeId: string, value: ResultData) => TransactionLog;
|
|
3
|
-
export declare const executeLog: (nodeId: string, retryCount: number, transactionId: number, agentId: string | undefined, params: NodeDataParams, results: ResultData[]) => TransactionLog;
|
|
4
|
-
export declare const timeoutLog: (log: TransactionLog) => void;
|
|
5
|
-
export declare const callbackLog: (log: TransactionLog, result: ResultData, localLog: TransactionLog[]) => void;
|
|
6
|
-
export declare const errorLog: (log: TransactionLog, errorMessage: string) => void;
|
package/lib/log.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorLog = exports.callbackLog = exports.timeoutLog = exports.executeLog = exports.injectValueLog = void 0;
|
|
4
|
-
const type_1 = require("./type");
|
|
5
|
-
const injectValueLog = (nodeId, value) => {
|
|
6
|
-
const log = {
|
|
7
|
-
nodeId,
|
|
8
|
-
state: type_1.NodeState.Injected,
|
|
9
|
-
startTime: Date.now(),
|
|
10
|
-
endTime: Date.now(),
|
|
11
|
-
result: value,
|
|
12
|
-
};
|
|
13
|
-
return log;
|
|
14
|
-
};
|
|
15
|
-
exports.injectValueLog = injectValueLog;
|
|
16
|
-
const executeLog = (nodeId, retryCount, transactionId, agentId, params, results) => {
|
|
17
|
-
const log = {
|
|
18
|
-
nodeId,
|
|
19
|
-
retryCount: retryCount > 0 ? retryCount : undefined,
|
|
20
|
-
state: type_1.NodeState.Executing,
|
|
21
|
-
startTime: transactionId,
|
|
22
|
-
agentId,
|
|
23
|
-
params,
|
|
24
|
-
inputs: results.length > 0 ? results : undefined,
|
|
25
|
-
};
|
|
26
|
-
return log;
|
|
27
|
-
};
|
|
28
|
-
exports.executeLog = executeLog;
|
|
29
|
-
const timeoutLog = (log) => {
|
|
30
|
-
log.errorMessage = "Timeout";
|
|
31
|
-
log.state = type_1.NodeState.TimedOut;
|
|
32
|
-
log.endTime = Date.now();
|
|
33
|
-
};
|
|
34
|
-
exports.timeoutLog = timeoutLog;
|
|
35
|
-
const callbackLog = (log, result, localLog) => {
|
|
36
|
-
log.endTime = Date.now();
|
|
37
|
-
log.result = result;
|
|
38
|
-
if (localLog.length > 0) {
|
|
39
|
-
log.log = localLog;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
exports.callbackLog = callbackLog;
|
|
43
|
-
const errorLog = (log, errorMessage) => {
|
|
44
|
-
log.state = type_1.NodeState.Failed;
|
|
45
|
-
log.endTime = Date.now();
|
|
46
|
-
log.errorMessage = errorMessage;
|
|
47
|
-
};
|
|
48
|
-
exports.errorLog = errorLog;
|
package/lib/utils.d.ts
DELETED
package/lib/utils.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNodeName = void 0;
|
|
4
|
-
const parseNodeName = (name) => {
|
|
5
|
-
const parts = name.split(".");
|
|
6
|
-
if (parts.length == 1) {
|
|
7
|
-
return { sourceNodeId: parts[0] };
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return { sourceNodeId: parts[0], propId: parts[1] };
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
exports.parseNodeName = parseNodeName;
|