graphai 0.1.0 → 0.1.1
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 +7 -5
- 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 +2 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +13 -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_agent.d.ts +9 -0
- package/lib/experimental_agents/matrix_agent.js +50 -0
- package/lib/experimental_agents/nested_agent.d.ts +2 -2
- package/lib/experimental_agents/nested_agent.js +14 -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 +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +24 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +4 -0
- package/lib/experimental_agents/{string_agent.js → string_agents/string_template_agent.js} +2 -5
- 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/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/echo_fork_index_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_fork_index_agent.js +7 -0
- package/lib/experimental_agents/test_agents/index.d.ts +5 -0
- package/lib/experimental_agents/test_agents/index.js +13 -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 +110 -115
- package/lib/index.d.ts +2 -0
- package/lib/log.d.ts +22 -6
- package/lib/log.js +45 -44
- package/lib/node.d.ts +31 -25
- package/lib/node.js +136 -97
- package/lib/task.d.ts +18 -0
- package/lib/task.js +63 -0
- 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/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 +3 -5
- 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/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
package/lib/type.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { TransactionLog } from "./transaction_log";
|
|
2
|
+
import type { TaskManager } from "./task_manager";
|
|
1
3
|
export declare enum NodeState {
|
|
2
4
|
Waiting = "waiting",
|
|
5
|
+
Queued = "queued",
|
|
3
6
|
Executing = "executing",
|
|
4
7
|
Failed = "failed",
|
|
5
8
|
TimedOut = "timed-out",
|
|
@@ -7,58 +10,68 @@ export declare enum NodeState {
|
|
|
7
10
|
Injected = "injected",
|
|
8
11
|
Dispatched = "dispatched"
|
|
9
12
|
}
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
12
|
-
export type
|
|
13
|
+
export type DefaultResultData = Record<string, any>;
|
|
14
|
+
export type DefaultInputData = Record<string, any>;
|
|
15
|
+
export type ResultData<ResultType = DefaultResultData> = ResultType | undefined;
|
|
16
|
+
export type ResultDataDictonary<ResultType = DefaultResultData> = Record<string, ResultData<ResultType>>;
|
|
17
|
+
export type DefaultParamsType = Record<string, any>;
|
|
18
|
+
export type NodeDataParams<ParamsType = DefaultParamsType> = ParamsType;
|
|
13
19
|
export type DataSource = {
|
|
14
20
|
nodeId: string;
|
|
15
21
|
propId?: string;
|
|
16
22
|
};
|
|
17
|
-
export type
|
|
23
|
+
export type StaticNodeData = {
|
|
24
|
+
value: ResultData;
|
|
25
|
+
update?: string;
|
|
26
|
+
isResult?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export type ComputedNodeData = {
|
|
29
|
+
agentId: string;
|
|
18
30
|
inputs?: Array<string>;
|
|
19
31
|
anyInput?: boolean;
|
|
20
32
|
params?: NodeDataParams;
|
|
21
33
|
retry?: number;
|
|
22
34
|
timeout?: number;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value?: ResultData;
|
|
26
|
-
update?: string;
|
|
35
|
+
graph?: GraphData;
|
|
36
|
+
isResult?: boolean;
|
|
27
37
|
};
|
|
38
|
+
export type NodeData = StaticNodeData | ComputedNodeData;
|
|
28
39
|
export type LoopData = {
|
|
29
40
|
count?: number;
|
|
30
41
|
while?: string;
|
|
31
42
|
};
|
|
32
43
|
export type GraphData = {
|
|
33
|
-
agentId?: string;
|
|
34
44
|
nodes: Record<string, NodeData>;
|
|
35
45
|
concurrency?: number;
|
|
36
46
|
loop?: LoopData;
|
|
37
47
|
verbose?: boolean;
|
|
38
48
|
};
|
|
39
|
-
export type
|
|
40
|
-
nodeId: string;
|
|
41
|
-
state: NodeState;
|
|
42
|
-
startTime: number;
|
|
43
|
-
endTime?: number;
|
|
44
|
-
retryCount?: number;
|
|
45
|
-
agentId?: string;
|
|
46
|
-
params?: NodeDataParams;
|
|
47
|
-
inputs?: Array<ResultData>;
|
|
48
|
-
errorMessage?: string;
|
|
49
|
-
result?: ResultData;
|
|
50
|
-
log?: TransactionLog[];
|
|
51
|
-
};
|
|
52
|
-
export type AgentFunctionContext<ParamsType, PreviousResultType> = {
|
|
53
|
-
nodeId: string;
|
|
54
|
-
forkIndex?: number;
|
|
55
|
-
retry: number;
|
|
49
|
+
export type AgentFunctionContext<ParamsType, InputDataType> = {
|
|
56
50
|
params: NodeDataParams<ParamsType>;
|
|
57
|
-
inputs: Array<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
inputs: Array<InputDataType>;
|
|
52
|
+
debugInfo: {
|
|
53
|
+
verbose: boolean;
|
|
54
|
+
nodeId: string;
|
|
55
|
+
retry: number;
|
|
56
|
+
};
|
|
57
|
+
graphData?: GraphData;
|
|
58
|
+
agents?: AgentFunctionDictonary;
|
|
59
|
+
log?: TransactionLog[];
|
|
60
|
+
taskManager?: TaskManager;
|
|
61
61
|
};
|
|
62
|
-
export type AgentFunction<ParamsType =
|
|
62
|
+
export type AgentFunction<ParamsType = DefaultParamsType, ResultType = DefaultResultData, InputDataType = DefaultInputData> = (context: AgentFunctionContext<ParamsType, InputDataType>) => Promise<ResultData<ResultType>>;
|
|
63
63
|
export type AgentFunctionDictonary = Record<string, AgentFunction<any, any, any>>;
|
|
64
|
-
export type
|
|
64
|
+
export type AgentFunctionInfo = {
|
|
65
|
+
name: string;
|
|
66
|
+
agent: AgentFunction<any, any, any>;
|
|
67
|
+
mock: AgentFunction<any, any, any>;
|
|
68
|
+
samples: {
|
|
69
|
+
inputs: any;
|
|
70
|
+
params: DefaultParamsType;
|
|
71
|
+
result: any;
|
|
72
|
+
}[];
|
|
73
|
+
description: string;
|
|
74
|
+
author: string;
|
|
75
|
+
repository: string;
|
|
76
|
+
license: string;
|
|
77
|
+
};
|
package/lib/type.js
CHANGED
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.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Asynchronous data flow execution engine to make it simple to build LLM 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,7 +11,7 @@
|
|
|
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
|
},
|
|
@@ -43,6 +40,7 @@
|
|
|
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",
|
|
@@ -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
|
-
}>;
|
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/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;
|