graphai 0.2.6 → 0.2.7
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 +3 -1
- package/lib/graphai.js +1 -1
- package/lib/node.d.ts +3 -1
- package/lib/node.js +14 -3
- package/lib/transaction_log.js +1 -1
- package/lib/type.d.ts +1 -1
- package/lib/validator.js +2 -2
- package/lib/validators/common.js +1 -1
- package/lib/validators/nodeValidator.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -363,9 +363,11 @@ npm run sample ./samples/home.ts
|
|
|
363
363
|
|
|
364
364
|
Step 6. Write some code and send pull requests
|
|
365
365
|
|
|
366
|
+
- Please run "yarn run format" before sending your pull request.
|
|
367
|
+
- Please do not include any build files (files under /lib) to your pull reuquest.
|
|
368
|
+
|
|
366
369
|
Key principles:
|
|
367
370
|
|
|
368
371
|
1. Keep the core (Node and GraphAI classes) small and simple.
|
|
369
372
|
2. Enhance the platform by adding 'agents' (plug ins).
|
|
370
373
|
3. Simple but effective test scripts make it easy to maintain.
|
|
371
|
-
4. Run "npm run format" before submitting pull requests.
|
package/lib/graphai.js
CHANGED
|
@@ -15,7 +15,7 @@ class GraphAI {
|
|
|
15
15
|
if ("value" in nodeData) {
|
|
16
16
|
_nodes[nodeId] = new node_1.StaticNode(nodeId, nodeData, this);
|
|
17
17
|
}
|
|
18
|
-
else if ("
|
|
18
|
+
else if ("agent" in nodeData) {
|
|
19
19
|
_nodes[nodeId] = new node_1.ComputedNode(this.graphId, nodeId, nodeData, this);
|
|
20
20
|
}
|
|
21
21
|
else {
|
package/lib/node.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export declare class ComputedNode extends Node {
|
|
|
19
19
|
readonly nestedGraph?: GraphData;
|
|
20
20
|
readonly retryLimit: number;
|
|
21
21
|
retryCount: number;
|
|
22
|
-
readonly agentId
|
|
22
|
+
private readonly agentId?;
|
|
23
|
+
private readonly agentFunction?;
|
|
23
24
|
readonly timeout?: number;
|
|
24
25
|
readonly priority: number;
|
|
25
26
|
error?: Error;
|
|
@@ -30,6 +31,7 @@ export declare class ComputedNode extends Node {
|
|
|
30
31
|
readonly isStaticNode = false;
|
|
31
32
|
readonly isComputedNode = true;
|
|
32
33
|
constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
|
|
34
|
+
getAgentId(): string;
|
|
33
35
|
isReadyNode(): boolean;
|
|
34
36
|
private retry;
|
|
35
37
|
private checkDataAvailability;
|
package/lib/node.js
CHANGED
|
@@ -39,7 +39,15 @@ class ComputedNode extends Node {
|
|
|
39
39
|
this.graphId = graphId;
|
|
40
40
|
this.params = data.params ?? {};
|
|
41
41
|
this.nestedGraph = data.graph;
|
|
42
|
-
|
|
42
|
+
if (typeof data.agent === "string") {
|
|
43
|
+
this.agentId = data.agent;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
(0, utils_2.assert)(typeof data.agent === "function", "agent must be either string or function");
|
|
47
|
+
this.agentFunction = async ({ inputs }) => {
|
|
48
|
+
return data.agent(...inputs);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
43
51
|
this.retryLimit = data.retry ?? graph.retryLimit ?? 0;
|
|
44
52
|
this.timeout = data.timeout;
|
|
45
53
|
this.isResult = data.isResult ?? false;
|
|
@@ -49,6 +57,9 @@ class ComputedNode extends Node {
|
|
|
49
57
|
this.pendings = new Set(this.dataSources.filter((source) => source.nodeId).map((source) => source.nodeId));
|
|
50
58
|
this.log.initForComputedNode(this);
|
|
51
59
|
}
|
|
60
|
+
getAgentId() {
|
|
61
|
+
return this.agentId ?? "__custom__function"; // only for display purpose in the log.
|
|
62
|
+
}
|
|
52
63
|
isReadyNode() {
|
|
53
64
|
if (this.state === type_1.NodeState.Waiting && this.pendings.size === 0) {
|
|
54
65
|
// Count the number of data actually available.
|
|
@@ -120,7 +131,7 @@ class ComputedNode extends Node {
|
|
|
120
131
|
// Check if we need to apply this filter to this node or not.
|
|
121
132
|
shouldApplyAgentFilter(agentFilter) {
|
|
122
133
|
if (agentFilter.agentIds && Array.isArray(agentFilter.agentIds) && agentFilter.agentIds.length > 0) {
|
|
123
|
-
if (agentFilter.agentIds.includes(this.agentId)) {
|
|
134
|
+
if (this.agentId && agentFilter.agentIds.includes(this.agentId)) {
|
|
124
135
|
return true;
|
|
125
136
|
}
|
|
126
137
|
}
|
|
@@ -162,7 +173,7 @@ class ComputedNode extends Node {
|
|
|
162
173
|
}, this.timeout);
|
|
163
174
|
}
|
|
164
175
|
try {
|
|
165
|
-
const callback = this.graph.getCallback(this.agentId);
|
|
176
|
+
const callback = this.agentFunction ?? this.graph.getCallback(this.agentId);
|
|
166
177
|
const localLog = [];
|
|
167
178
|
const context = {
|
|
168
179
|
params: this.params,
|
package/lib/transaction_log.js
CHANGED
package/lib/type.d.ts
CHANGED
package/lib/validator.js
CHANGED
|
@@ -17,9 +17,9 @@ const validateGraphData = (data, agentIds) => {
|
|
|
17
17
|
const node = data.nodes[nodeId];
|
|
18
18
|
const isStaticNode = "value" in node;
|
|
19
19
|
(0, nodeValidator_1.nodeValidator)(node);
|
|
20
|
-
const agentId = isStaticNode ? "" : node.
|
|
20
|
+
const agentId = isStaticNode ? "" : node.agent;
|
|
21
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);
|
|
22
|
+
!isStaticNode && (0, computed_node_validator_1.computedNodeValidator)(node) && computedNodeIds.push(nodeId) && typeof agentId === "string" && graphAgentIds.add(agentId);
|
|
23
23
|
});
|
|
24
24
|
(0, agent_validator_1.agentValidator)(graphAgentIds, new Set(agentIds));
|
|
25
25
|
(0, relation_validator_1.relationValidator)(data, staticNodeIds, computedNodeIds);
|
package/lib/validators/common.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
4
|
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"];
|
|
5
|
-
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "
|
|
5
|
+
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority"];
|
|
6
6
|
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nodeValidator = void 0;
|
|
4
4
|
const nodeValidator = (nodeData) => {
|
|
5
|
-
if (nodeData.
|
|
5
|
+
if (nodeData.agent && nodeData.value) {
|
|
6
6
|
throw new Error("Cannot set both agentId and value");
|
|
7
7
|
}
|
|
8
|
-
if (!("
|
|
8
|
+
if (!("agent" in nodeData) && !("value" in nodeData)) {
|
|
9
9
|
throw new Error("Either agentId or value is required");
|
|
10
10
|
}
|
|
11
11
|
return true;
|