graphai 0.6.1 → 0.6.3
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/lib/bundle.cjs.js +1 -1
- package/lib/bundle.cjs.js.map +1 -1
- package/lib/bundle.esm.js +33 -22
- package/lib/bundle.esm.js.map +1 -1
- package/lib/bundle.umd.js +1 -1
- package/lib/bundle.umd.js.map +1 -1
- package/lib/node.d.ts +0 -1
- package/lib/node.js +11 -14
- package/lib/type.d.ts +5 -8
- package/lib/utils/prop_function.js +10 -0
- package/lib/utils/utils.d.ts +3 -3
- package/package.json +2 -2
package/lib/bundle.esm.js
CHANGED
|
@@ -247,7 +247,6 @@ class ComputedNode extends Node {
|
|
|
247
247
|
super(nodeId, graph);
|
|
248
248
|
this.retryCount = 0;
|
|
249
249
|
this.dataSources = []; // no longer needed. This is for transaction log.
|
|
250
|
-
this.isNamedInputs = false;
|
|
251
250
|
this.isStaticNode = false;
|
|
252
251
|
this.isComputedNode = true;
|
|
253
252
|
this.graphId = graphId;
|
|
@@ -261,10 +260,9 @@ class ComputedNode extends Node {
|
|
|
261
260
|
this.priority = data.priority ?? 0;
|
|
262
261
|
this.anyInput = data.anyInput ?? false;
|
|
263
262
|
this.inputs = data.inputs;
|
|
264
|
-
this.isNamedInputs = isObject(data.inputs) && !Array.isArray(data.inputs);
|
|
265
263
|
this.dataSources = data.inputs ? inputs2dataSources(data.inputs).flat(10) : [];
|
|
266
|
-
if (data.inputs &&
|
|
267
|
-
|
|
264
|
+
if (data.inputs && Array.isArray(data.inputs)) {
|
|
265
|
+
throw new Error(`array inputs have been deprecated. nodeId: ${nodeId}: see https://github.com/receptron/graphai/blob/main/docs/NamedInputs.md`);
|
|
268
266
|
}
|
|
269
267
|
this.pendings = new Set(dataSourceNodeIds(this.dataSources));
|
|
270
268
|
assert(["function", "string"].includes(typeof data.agent), "agent must be either string or function");
|
|
@@ -273,7 +271,7 @@ class ComputedNode extends Node {
|
|
|
273
271
|
}
|
|
274
272
|
else {
|
|
275
273
|
const agent = data.agent;
|
|
276
|
-
this.agentFunction =
|
|
274
|
+
this.agentFunction = async ({ namedInputs, params }) => agent(namedInputs, params);
|
|
277
275
|
}
|
|
278
276
|
if (data.graph) {
|
|
279
277
|
this.nestedGraph = typeof data.graph === "string" ? this.addPendingNode(data.graph) : data.graph;
|
|
@@ -422,18 +420,19 @@ class ComputedNode extends Node {
|
|
|
422
420
|
// if this is a nested agent or not.
|
|
423
421
|
if (this.nestedGraph) {
|
|
424
422
|
this.graph.taskManager.prepareForNesting();
|
|
425
|
-
context.taskManager = this.graph.taskManager;
|
|
423
|
+
// context.taskManager = this.graph.taskManager;
|
|
426
424
|
context.onLogCallback = this.graph.onLogCallback;
|
|
425
|
+
/*
|
|
427
426
|
if ("nodes" in this.nestedGraph) {
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
context.agents = this.graph.agentFunctionInfoDictionary;
|
|
427
|
+
context.graphData = this.nestedGraph;
|
|
428
|
+
} else {
|
|
429
|
+
context.graphData = this.graph.resultOf(this.nestedGraph) as GraphData; // HACK: compiler work-around
|
|
430
|
+
}
|
|
431
|
+
*/
|
|
432
|
+
// context.agents = this.graph.agentFunctionInfoDictionary;
|
|
434
433
|
context.forNestedGraph = {
|
|
435
|
-
graphData:
|
|
436
|
-
agents:
|
|
434
|
+
graphData: "nodes" in this.nestedGraph ? this.nestedGraph : this.graph.resultOf(this.nestedGraph), // HACK: compiler work-around
|
|
435
|
+
agents: this.graph.agentFunctionInfoDictionary,
|
|
437
436
|
graphOptions: {
|
|
438
437
|
agentFilters: this.graph.agentFilters,
|
|
439
438
|
taskManager: this.graph.taskManager,
|
|
@@ -441,6 +440,7 @@ class ComputedNode extends Node {
|
|
|
441
440
|
config: this.graph.config,
|
|
442
441
|
graphLoader: this.graph.graphLoader,
|
|
443
442
|
},
|
|
443
|
+
onLogCallback: this.graph.onLogCallback,
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
446
|
this.beforeConsoleLog(context);
|
|
@@ -501,17 +501,18 @@ class ComputedNode extends Node {
|
|
|
501
501
|
return tmp;
|
|
502
502
|
}, { ...this.params });
|
|
503
503
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
504
|
+
/*
|
|
505
|
+
private getInputs(previousResults: Record<string, ResultData | undefined>) {
|
|
506
|
+
if (Array.isArray(this.inputs)) {
|
|
507
|
+
return (this.inputs ?? []).map((key) => previousResults[String(key)]).filter((a) => !this.anyInput || a);
|
|
508
|
+
}
|
|
509
|
+
return [];
|
|
509
510
|
}
|
|
511
|
+
*/
|
|
510
512
|
getContext(previousResults, localLog) {
|
|
511
513
|
const context = {
|
|
512
514
|
params: this.getParams(),
|
|
513
|
-
|
|
514
|
-
namedInputs: this.isNamedInputs ? previousResults : {},
|
|
515
|
+
namedInputs: previousResults,
|
|
515
516
|
inputSchema: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(this.agentId)?.inputs,
|
|
516
517
|
debugInfo: this.getDebugInfo(),
|
|
517
518
|
cacheType: this.agentFunction ? undefined : this.graph.getAgentFunctionInfo(this.agentId)?.cacheType,
|
|
@@ -545,7 +546,7 @@ class ComputedNode extends Node {
|
|
|
545
546
|
}
|
|
546
547
|
beforeConsoleLog(context) {
|
|
547
548
|
if (this.console.before === true) {
|
|
548
|
-
console.log(JSON.stringify(
|
|
549
|
+
console.log(JSON.stringify(context.namedInputs, null, 2));
|
|
549
550
|
}
|
|
550
551
|
else if (this.console.before) {
|
|
551
552
|
console.log(this.console.before);
|
|
@@ -627,6 +628,16 @@ const propStringFunction = (result, propId) => {
|
|
|
627
628
|
return ret;
|
|
628
629
|
}
|
|
629
630
|
}
|
|
631
|
+
if (propId === "trim()") {
|
|
632
|
+
return result.trim();
|
|
633
|
+
}
|
|
634
|
+
if (propId === "toLowerCase()") {
|
|
635
|
+
return result.toLowerCase();
|
|
636
|
+
}
|
|
637
|
+
if (propId === "toUpperCase()") {
|
|
638
|
+
return result.toUpperCase();
|
|
639
|
+
}
|
|
640
|
+
// split()
|
|
630
641
|
}
|
|
631
642
|
return undefined;
|
|
632
643
|
};
|