@workglow/task-graph 0.0.99 → 0.0.100
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/dist/browser.js +49 -35
- package/dist/browser.js.map +7 -7
- package/dist/bun.js +49 -35
- package/dist/bun.js.map +7 -7
- package/dist/node.js +49 -35
- package/dist/node.js.map +7 -7
- package/dist/task/GraphAsTask.d.ts.map +1 -1
- package/dist/task/ITask.d.ts +11 -0
- package/dist/task/ITask.d.ts.map +1 -1
- package/dist/task/TaskRunner.d.ts +20 -3
- package/dist/task/TaskRunner.d.ts.map +1 -1
- package/dist/task-graph/Dataflow.d.ts +11 -10
- package/dist/task-graph/Dataflow.d.ts.map +1 -1
- package/dist/task-graph/TaskGraph.d.ts +7 -0
- package/dist/task-graph/TaskGraph.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphRunner.d.ts +22 -1
- package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/bun.js
CHANGED
|
@@ -48,10 +48,8 @@ class Dataflow {
|
|
|
48
48
|
if (!this.stream)
|
|
49
49
|
return;
|
|
50
50
|
const reader = this.stream.getReader();
|
|
51
|
-
const accumulatedPorts = new Map;
|
|
52
51
|
let lastSnapshotData = undefined;
|
|
53
52
|
let finishData = undefined;
|
|
54
|
-
let hasTextDelta = false;
|
|
55
53
|
let streamError;
|
|
56
54
|
try {
|
|
57
55
|
while (true) {
|
|
@@ -59,16 +57,6 @@ class Dataflow {
|
|
|
59
57
|
if (done)
|
|
60
58
|
break;
|
|
61
59
|
switch (event.type) {
|
|
62
|
-
case "text-delta": {
|
|
63
|
-
if (this.sourceTaskPortId !== DATAFLOW_ALL_PORTS && event.port !== this.sourceTaskPortId) {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
hasTextDelta = true;
|
|
67
|
-
accumulatedPorts.set(event.port, (accumulatedPorts.get(event.port) ?? "") + event.textDelta);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case "object-delta":
|
|
71
|
-
break;
|
|
72
60
|
case "snapshot":
|
|
73
61
|
lastSnapshotData = event.data;
|
|
74
62
|
break;
|
|
@@ -91,19 +79,8 @@ class Dataflow {
|
|
|
91
79
|
}
|
|
92
80
|
if (lastSnapshotData !== undefined) {
|
|
93
81
|
this.setPortData(lastSnapshotData);
|
|
94
|
-
} else if (finishData
|
|
82
|
+
} else if (finishData !== undefined) {
|
|
95
83
|
this.setPortData(finishData);
|
|
96
|
-
} else if (hasTextDelta) {
|
|
97
|
-
if (this.sourceTaskPortId === DATAFLOW_ALL_PORTS) {
|
|
98
|
-
const obj = {};
|
|
99
|
-
for (const [port, text] of accumulatedPorts) {
|
|
100
|
-
obj[port] = text;
|
|
101
|
-
}
|
|
102
|
-
this.value = obj;
|
|
103
|
-
} else {
|
|
104
|
-
const text = accumulatedPorts.values().next().value ?? "";
|
|
105
|
-
this.value = text;
|
|
106
|
-
}
|
|
107
84
|
}
|
|
108
85
|
}
|
|
109
86
|
reset() {
|
|
@@ -549,6 +526,7 @@ class TaskRunner {
|
|
|
549
526
|
outputCache;
|
|
550
527
|
registry = globalServiceRegistry;
|
|
551
528
|
inputStreams;
|
|
529
|
+
shouldAccumulate = true;
|
|
552
530
|
constructor(task) {
|
|
553
531
|
this.task = task;
|
|
554
532
|
this.own = this.own.bind(this);
|
|
@@ -657,7 +635,7 @@ class TaskRunner {
|
|
|
657
635
|
throw new TaskError(`Task ${this.task.type} declares append streaming but no output port has x-stream: "append"`);
|
|
658
636
|
}
|
|
659
637
|
}
|
|
660
|
-
const accumulated = new Map;
|
|
638
|
+
const accumulated = this.shouldAccumulate ? new Map : undefined;
|
|
661
639
|
let chunkCount = 0;
|
|
662
640
|
let finalOutput;
|
|
663
641
|
this.task.emit("stream_start");
|
|
@@ -677,33 +655,40 @@ class TaskRunner {
|
|
|
677
655
|
if (event.type === "snapshot") {
|
|
678
656
|
this.task.runOutputData = event.data;
|
|
679
657
|
}
|
|
680
|
-
this.task.emit("stream_chunk", event);
|
|
681
658
|
switch (event.type) {
|
|
682
659
|
case "text-delta": {
|
|
683
|
-
|
|
660
|
+
if (accumulated) {
|
|
661
|
+
accumulated.set(event.port, (accumulated.get(event.port) ?? "") + event.textDelta);
|
|
662
|
+
}
|
|
663
|
+
this.task.emit("stream_chunk", event);
|
|
684
664
|
const progress = Math.min(99, Math.round(100 * (1 - Math.exp(-0.05 * chunkCount))));
|
|
685
665
|
await this.handleProgress(progress);
|
|
686
666
|
break;
|
|
687
667
|
}
|
|
688
668
|
case "object-delta": {
|
|
669
|
+
this.task.emit("stream_chunk", event);
|
|
689
670
|
const progress = Math.min(99, Math.round(100 * (1 - Math.exp(-0.05 * chunkCount))));
|
|
690
671
|
await this.handleProgress(progress);
|
|
691
672
|
break;
|
|
692
673
|
}
|
|
693
674
|
case "snapshot": {
|
|
675
|
+
this.task.emit("stream_chunk", event);
|
|
694
676
|
const progress = Math.min(99, Math.round(100 * (1 - Math.exp(-0.05 * chunkCount))));
|
|
695
677
|
await this.handleProgress(progress);
|
|
696
678
|
break;
|
|
697
679
|
}
|
|
698
680
|
case "finish": {
|
|
699
|
-
if (
|
|
681
|
+
if (accumulated) {
|
|
700
682
|
const merged = { ...event.data || {} };
|
|
701
683
|
for (const [port, text] of accumulated) {
|
|
702
|
-
|
|
684
|
+
if (text.length > 0)
|
|
685
|
+
merged[port] = text;
|
|
703
686
|
}
|
|
704
687
|
finalOutput = merged;
|
|
705
|
-
|
|
688
|
+
this.task.emit("stream_chunk", { type: "finish", data: merged });
|
|
689
|
+
} else {
|
|
706
690
|
finalOutput = event.data;
|
|
691
|
+
this.task.emit("stream_chunk", event);
|
|
707
692
|
}
|
|
708
693
|
break;
|
|
709
694
|
}
|
|
@@ -742,6 +727,7 @@ class TaskRunner {
|
|
|
742
727
|
} else if (cache instanceof TaskOutputRepository) {
|
|
743
728
|
this.outputCache = cache;
|
|
744
729
|
}
|
|
730
|
+
this.shouldAccumulate = config.shouldAccumulate !== false;
|
|
745
731
|
if (config.updateProgress) {
|
|
746
732
|
this.updateProgress = config.updateProgress;
|
|
747
733
|
}
|
|
@@ -1553,6 +1539,7 @@ class TaskGraphRunner {
|
|
|
1553
1539
|
reactiveRunning = false;
|
|
1554
1540
|
graph;
|
|
1555
1541
|
outputCache;
|
|
1542
|
+
accumulateLeafOutputs = true;
|
|
1556
1543
|
registry = globalServiceRegistry2;
|
|
1557
1544
|
abortController;
|
|
1558
1545
|
inProgressTasks = new Map;
|
|
@@ -1772,6 +1759,29 @@ class TaskGraphRunner {
|
|
|
1772
1759
|
}
|
|
1773
1760
|
}
|
|
1774
1761
|
}
|
|
1762
|
+
taskNeedsAccumulation(task) {
|
|
1763
|
+
if (this.outputCache)
|
|
1764
|
+
return true;
|
|
1765
|
+
const outEdges = this.graph.getTargetDataflows(task.config.id);
|
|
1766
|
+
if (outEdges.length === 0)
|
|
1767
|
+
return this.accumulateLeafOutputs;
|
|
1768
|
+
const outSchema = task.outputSchema();
|
|
1769
|
+
for (const df of outEdges) {
|
|
1770
|
+
if (df.sourceTaskPortId === DATAFLOW_ALL_PORTS) {
|
|
1771
|
+
if (getStreamingPorts(outSchema).length > 0)
|
|
1772
|
+
return true;
|
|
1773
|
+
continue;
|
|
1774
|
+
}
|
|
1775
|
+
const targetTask = this.graph.getTask(df.targetTaskId);
|
|
1776
|
+
if (!targetTask)
|
|
1777
|
+
continue;
|
|
1778
|
+
const inSchema = targetTask.inputSchema();
|
|
1779
|
+
if (edgeNeedsAccumulation(outSchema, df.sourceTaskPortId, inSchema, df.targetTaskPortId)) {
|
|
1780
|
+
return true;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
return false;
|
|
1784
|
+
}
|
|
1775
1785
|
async runTask(task, input) {
|
|
1776
1786
|
const isStreamable = isTaskStreamable(task);
|
|
1777
1787
|
if (isStreamable) {
|
|
@@ -1794,7 +1804,7 @@ class TaskGraphRunner {
|
|
|
1794
1804
|
return this.runStreamingTask(task, input);
|
|
1795
1805
|
}
|
|
1796
1806
|
const results = await task.runner.run(input, {
|
|
1797
|
-
outputCache: this.outputCache,
|
|
1807
|
+
outputCache: this.outputCache ?? false,
|
|
1798
1808
|
updateProgress: async (task2, progress, message, ...args) => await this.handleProgress(task2, progress, message, ...args),
|
|
1799
1809
|
registry: this.registry
|
|
1800
1810
|
});
|
|
@@ -1814,6 +1824,7 @@ class TaskGraphRunner {
|
|
|
1814
1824
|
}
|
|
1815
1825
|
async runStreamingTask(task, input) {
|
|
1816
1826
|
const streamMode = getOutputStreamMode(task.outputSchema());
|
|
1827
|
+
const shouldAccumulate = this.taskNeedsAccumulation(task);
|
|
1817
1828
|
let streamingNotified = false;
|
|
1818
1829
|
const onStatus = (status) => {
|
|
1819
1830
|
if (status === TaskStatus.STREAMING && !streamingNotified) {
|
|
@@ -1838,7 +1849,8 @@ class TaskGraphRunner {
|
|
|
1838
1849
|
task.on("stream_end", onStreamEnd);
|
|
1839
1850
|
try {
|
|
1840
1851
|
const results = await task.runner.run(input, {
|
|
1841
|
-
outputCache: this.outputCache,
|
|
1852
|
+
outputCache: this.outputCache ?? false,
|
|
1853
|
+
shouldAccumulate,
|
|
1842
1854
|
updateProgress: async (task2, progress, message, ...args) => await this.handleProgress(task2, progress, message, ...args),
|
|
1843
1855
|
registry: this.registry
|
|
1844
1856
|
});
|
|
@@ -1946,6 +1958,7 @@ class TaskGraphRunner {
|
|
|
1946
1958
|
} else {
|
|
1947
1959
|
this.registry = new ServiceRegistry2(globalServiceRegistry2.container.createChildContainer());
|
|
1948
1960
|
}
|
|
1961
|
+
this.accumulateLeafOutputs = config?.accumulateLeafOutputs !== false;
|
|
1949
1962
|
if (config?.outputCache !== undefined) {
|
|
1950
1963
|
if (typeof config.outputCache === "boolean") {
|
|
1951
1964
|
if (config.outputCache === true) {
|
|
@@ -2277,7 +2290,7 @@ class GraphAsTask extends Task {
|
|
|
2277
2290
|
}
|
|
2278
2291
|
}
|
|
2279
2292
|
});
|
|
2280
|
-
const runPromise = this.subGraph.run(input, { parentSignal: context.signal }).then((results2) => {
|
|
2293
|
+
const runPromise = this.subGraph.run(input, { parentSignal: context.signal, accumulateLeafOutputs: false }).then((results2) => {
|
|
2281
2294
|
subgraphDone = true;
|
|
2282
2295
|
resolveWaiting?.();
|
|
2283
2296
|
return results2;
|
|
@@ -3084,7 +3097,8 @@ class TaskGraph {
|
|
|
3084
3097
|
run(input = {}, config = {}) {
|
|
3085
3098
|
return this.runner.runGraph(input, {
|
|
3086
3099
|
outputCache: config?.outputCache || this.outputCache,
|
|
3087
|
-
parentSignal: config?.parentSignal || undefined
|
|
3100
|
+
parentSignal: config?.parentSignal || undefined,
|
|
3101
|
+
accumulateLeafOutputs: config?.accumulateLeafOutputs
|
|
3088
3102
|
});
|
|
3089
3103
|
}
|
|
3090
3104
|
runReactive(input = {}) {
|
|
@@ -5188,4 +5202,4 @@ export {
|
|
|
5188
5202
|
ConditionalTask
|
|
5189
5203
|
};
|
|
5190
5204
|
|
|
5191
|
-
//# debugId=
|
|
5205
|
+
//# debugId=8204DBBC6072784764756E2164756E21
|