@workglow/task-graph 0.0.120 → 0.0.122
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 +99 -58
- package/dist/browser.js.map +8 -8
- package/dist/bun.js +99 -58
- package/dist/bun.js.map +8 -8
- package/dist/node.js +99 -58
- package/dist/node.js.map +8 -8
- package/dist/storage/TaskGraphRepository.d.ts.map +1 -1
- package/dist/storage/TaskGraphTabularRepository.d.ts.map +1 -1
- package/dist/storage/TaskOutputRepository.d.ts.map +1 -1
- package/dist/storage/TaskOutputTabularRepository.d.ts.map +1 -1
- package/dist/task/ConditionalTask.d.ts.map +1 -1
- package/dist/task/FallbackTask.d.ts +44 -44
- package/dist/task/FallbackTask.d.ts.map +1 -1
- package/dist/task/FallbackTaskRunner.d.ts +0 -8
- package/dist/task/FallbackTaskRunner.d.ts.map +1 -1
- package/dist/task/GraphAsTask.d.ts +1 -1
- package/dist/task/GraphAsTask.d.ts.map +1 -1
- package/dist/task/GraphAsTaskRunner.d.ts.map +1 -1
- package/dist/task/IteratorTask.d.ts +12 -12
- package/dist/task/IteratorTask.d.ts.map +1 -1
- package/dist/task/IteratorTaskRunner.d.ts +9 -1
- package/dist/task/IteratorTaskRunner.d.ts.map +1 -1
- package/dist/task/JobQueueTask.d.ts +9 -9
- package/dist/task/JobQueueTask.d.ts.map +1 -1
- package/dist/task/MapTask.d.ts +18 -18
- package/dist/task/MapTask.d.ts.map +1 -1
- package/dist/task/ReduceTask.d.ts +13 -13
- package/dist/task/ReduceTask.d.ts.map +1 -1
- package/dist/task/Task.d.ts +2 -1
- package/dist/task/Task.d.ts.map +1 -1
- package/dist/task/TaskError.d.ts.map +1 -1
- package/dist/task/TaskEvents.d.ts +14 -0
- package/dist/task/TaskEvents.d.ts.map +1 -1
- package/dist/task/TaskJSON.d.ts +4 -4
- package/dist/task/TaskJSON.d.ts.map +1 -1
- package/dist/task/TaskQueueRegistry.d.ts.map +1 -1
- package/dist/task/TaskRunner.d.ts.map +1 -1
- package/dist/task/WhileTask.d.ts +21 -21
- package/dist/task/WhileTask.d.ts.map +1 -1
- package/dist/task/WhileTaskRunner.d.ts.map +1 -1
- package/dist/task/index.d.ts +1 -1
- package/dist/task-graph/Dataflow.d.ts.map +1 -1
- package/dist/task-graph/TaskGraph.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphRunner.d.ts +8 -2
- package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphScheduler.d.ts.map +1 -1
- package/dist/task-graph/Workflow.d.ts.map +1 -1
- package/package.json +19 -14
package/dist/bun.js
CHANGED
|
@@ -83,7 +83,8 @@ var init_TaskTypes = __esm(() => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
// src/task-graph/Dataflow.ts
|
|
86
|
-
import { areSemanticallyCompatible
|
|
86
|
+
import { areSemanticallyCompatible } from "@workglow/schema";
|
|
87
|
+
import { EventEmitter } from "@workglow/util";
|
|
87
88
|
|
|
88
89
|
class Dataflow {
|
|
89
90
|
sourceTaskId;
|
|
@@ -914,7 +915,6 @@ function getStructuredOutputSchemas(schema) {
|
|
|
914
915
|
function hasStructuredOutput(schema) {
|
|
915
916
|
return getStructuredOutputSchemas(schema).size > 0;
|
|
916
917
|
}
|
|
917
|
-
var init_StreamTypes = () => {};
|
|
918
918
|
|
|
919
919
|
// src/task/TaskRunner.ts
|
|
920
920
|
import {
|
|
@@ -1293,22 +1293,21 @@ class TaskRunner {
|
|
|
1293
1293
|
}
|
|
1294
1294
|
async handleProgress(progress, message, ...args) {
|
|
1295
1295
|
this.task.progress = progress;
|
|
1296
|
-
await this.updateProgress(this.task, progress, message, ...args);
|
|
1297
1296
|
this.task.emit("progress", progress, message, ...args);
|
|
1297
|
+
await this.updateProgress(this.task, progress, message, ...args);
|
|
1298
1298
|
}
|
|
1299
1299
|
}
|
|
1300
1300
|
var init_TaskRunner = __esm(() => {
|
|
1301
1301
|
init_TaskOutputRepository();
|
|
1302
1302
|
init_Conversions();
|
|
1303
1303
|
init_InputResolver();
|
|
1304
|
-
init_StreamTypes();
|
|
1305
1304
|
init_TaskError();
|
|
1306
1305
|
init_TaskTypes();
|
|
1307
1306
|
});
|
|
1308
1307
|
|
|
1309
1308
|
// src/task/Task.ts
|
|
1309
|
+
import { compileSchema } from "@workglow/schema";
|
|
1310
1310
|
import {
|
|
1311
|
-
compileSchema,
|
|
1312
1311
|
deepEqual,
|
|
1313
1312
|
EventEmitter as EventEmitter3,
|
|
1314
1313
|
uuid4 as uuid42
|
|
@@ -1601,7 +1600,7 @@ class Task {
|
|
|
1601
1600
|
return this.events.waitOn(name);
|
|
1602
1601
|
}
|
|
1603
1602
|
emit(name, ...args) {
|
|
1604
|
-
this.
|
|
1603
|
+
this.events.emit(name, ...args);
|
|
1605
1604
|
}
|
|
1606
1605
|
emitSchemaChange(inputSchema, outputSchema) {
|
|
1607
1606
|
const finalInputSchema = inputSchema ?? this.inputSchema();
|
|
@@ -1743,13 +1742,15 @@ class Task {
|
|
|
1743
1742
|
const extras = config.extras;
|
|
1744
1743
|
if (!extras || Object.keys(extras).length === 0)
|
|
1745
1744
|
delete config.extras;
|
|
1746
|
-
const
|
|
1745
|
+
const base = {
|
|
1747
1746
|
id: this.id,
|
|
1748
1747
|
type: this.type,
|
|
1749
|
-
defaults: this.defaults
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1748
|
+
defaults: this.defaults
|
|
1749
|
+
};
|
|
1750
|
+
if (Object.keys(config).length > 0) {
|
|
1751
|
+
base.config = config;
|
|
1752
|
+
}
|
|
1753
|
+
return this.stripSymbols(base);
|
|
1753
1754
|
}
|
|
1754
1755
|
toDependencyJSON(options) {
|
|
1755
1756
|
const json = this.toJSON(options);
|
|
@@ -1862,13 +1863,11 @@ function getNestedValue(obj, path) {
|
|
|
1862
1863
|
}
|
|
1863
1864
|
return current;
|
|
1864
1865
|
}
|
|
1865
|
-
var init_ConditionUtils = () => {};
|
|
1866
1866
|
|
|
1867
1867
|
// src/task/ConditionalTask.ts
|
|
1868
1868
|
import { getLogger } from "@workglow/util";
|
|
1869
1869
|
var conditionalTaskConfigSchema, ConditionalTask;
|
|
1870
1870
|
var init_ConditionalTask = __esm(() => {
|
|
1871
|
-
init_ConditionUtils();
|
|
1872
1871
|
init_Task();
|
|
1873
1872
|
init_TaskTypes();
|
|
1874
1873
|
conditionalTaskConfigSchema = {
|
|
@@ -2222,7 +2221,6 @@ class DependencyBasedScheduler {
|
|
|
2222
2221
|
}
|
|
2223
2222
|
}
|
|
2224
2223
|
var init_TaskGraphScheduler = __esm(() => {
|
|
2225
|
-
init_StreamTypes();
|
|
2226
2224
|
init_TaskTypes();
|
|
2227
2225
|
});
|
|
2228
2226
|
|
|
@@ -2236,6 +2234,10 @@ import {
|
|
|
2236
2234
|
SpanStatusCode as SpanStatusCode2,
|
|
2237
2235
|
uuid4 as uuid43
|
|
2238
2236
|
} from "@workglow/util";
|
|
2237
|
+
function taskPrototypeHasOwnExecute(task) {
|
|
2238
|
+
const Ctor = task.constructor;
|
|
2239
|
+
return Object.hasOwn(Ctor.prototype, "execute");
|
|
2240
|
+
}
|
|
2239
2241
|
|
|
2240
2242
|
class TaskGraphRunner {
|
|
2241
2243
|
processScheduler;
|
|
@@ -2822,23 +2824,25 @@ class TaskGraphRunner {
|
|
|
2822
2824
|
this.graph.emit("disabled");
|
|
2823
2825
|
}
|
|
2824
2826
|
async handleProgress(task, progress, message, ...args) {
|
|
2825
|
-
const
|
|
2826
|
-
if (
|
|
2827
|
-
const
|
|
2828
|
-
progress = Math.round(
|
|
2827
|
+
const contributors = this.graph.getTasks().filter(taskPrototypeHasOwnExecute);
|
|
2828
|
+
if (contributors.length > 1) {
|
|
2829
|
+
const sum = contributors.reduce((acc, t) => acc + t.progress, 0);
|
|
2830
|
+
progress = Math.round(sum / contributors.length);
|
|
2831
|
+
} else if (contributors.length === 1) {
|
|
2832
|
+
const [only] = contributors;
|
|
2833
|
+
progress = only.progress;
|
|
2829
2834
|
}
|
|
2830
2835
|
this.pushStatusFromNodeToEdges(this.graph, task);
|
|
2836
|
+
this.graph.emit("graph_progress", progress, message, args);
|
|
2831
2837
|
if (task.runOutputData && Object.keys(task.runOutputData).length > 0) {
|
|
2832
2838
|
await this.pushOutputFromNodeToEdges(task, task.runOutputData);
|
|
2833
2839
|
}
|
|
2834
|
-
this.graph.emit("graph_progress", progress, message, args);
|
|
2835
2840
|
}
|
|
2836
2841
|
}
|
|
2837
2842
|
var PROPERTY_ARRAY = "PROPERTY_ARRAY", GRAPH_RESULT_ARRAY = "GRAPH_RESULT_ARRAY";
|
|
2838
2843
|
var init_TaskGraphRunner = __esm(() => {
|
|
2839
2844
|
init_TaskOutputRepository();
|
|
2840
2845
|
init_ConditionalTask();
|
|
2841
|
-
init_StreamTypes();
|
|
2842
2846
|
init_TaskError();
|
|
2843
2847
|
init_TaskTypes();
|
|
2844
2848
|
init_Dataflow();
|
|
@@ -2902,7 +2906,7 @@ __export(exports_GraphAsTask, {
|
|
|
2902
2906
|
graphAsTaskConfigSchema: () => graphAsTaskConfigSchema,
|
|
2903
2907
|
GraphAsTask: () => GraphAsTask
|
|
2904
2908
|
});
|
|
2905
|
-
import { compileSchema as compileSchema2 } from "@workglow/
|
|
2909
|
+
import { compileSchema as compileSchema2 } from "@workglow/schema";
|
|
2906
2910
|
var graphAsTaskConfigSchema, GraphAsTask;
|
|
2907
2911
|
var init_GraphAsTask = __esm(() => {
|
|
2908
2912
|
init_GraphSchemaUtils();
|
|
@@ -3516,7 +3520,6 @@ init_Dataflow();
|
|
|
3516
3520
|
|
|
3517
3521
|
// src/task-graph/Workflow.ts
|
|
3518
3522
|
init_GraphAsTask();
|
|
3519
|
-
init_StreamTypes();
|
|
3520
3523
|
init_TaskError();
|
|
3521
3524
|
init_Conversions();
|
|
3522
3525
|
init_Dataflow();
|
|
@@ -4615,7 +4618,6 @@ function resetMethodNameCache() {
|
|
|
4615
4618
|
}
|
|
4616
4619
|
// src/task/index.ts
|
|
4617
4620
|
init_ConditionalTask();
|
|
4618
|
-
init_ConditionUtils();
|
|
4619
4621
|
|
|
4620
4622
|
// src/task/FallbackTask.ts
|
|
4621
4623
|
init_GraphAsTask();
|
|
@@ -4839,6 +4841,9 @@ init_GraphAsTaskRunner();
|
|
|
4839
4841
|
import { uuid4 as uuid46 } from "@workglow/util";
|
|
4840
4842
|
|
|
4841
4843
|
class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
4844
|
+
aggregatingParentMapProgress = false;
|
|
4845
|
+
mapPartialProgress = [];
|
|
4846
|
+
mapPartialIterationCount = 0;
|
|
4842
4847
|
async executeTask(input) {
|
|
4843
4848
|
const analysis = this.task.analyzeIterationInput(input);
|
|
4844
4849
|
if (analysis.iterationCount === 0) {
|
|
@@ -4860,30 +4865,43 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4860
4865
|
const concurrency = Math.max(1, Math.min(requestedConcurrency, iterationCount));
|
|
4861
4866
|
const orderedResults = preserveOrder ? new Array(iterationCount) : [];
|
|
4862
4867
|
const completionOrderResults = [];
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
const
|
|
4873
|
-
await this.
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4868
|
+
this.aggregatingParentMapProgress = true;
|
|
4869
|
+
this.mapPartialIterationCount = iterationCount;
|
|
4870
|
+
this.mapPartialProgress = new Array(iterationCount).fill(0);
|
|
4871
|
+
try {
|
|
4872
|
+
for (let batchStart = 0;batchStart < iterationCount; batchStart += batchSize) {
|
|
4873
|
+
if (this.abortController?.signal.aborted) {
|
|
4874
|
+
break;
|
|
4875
|
+
}
|
|
4876
|
+
const batchEnd = Math.min(batchStart + batchSize, iterationCount);
|
|
4877
|
+
const batchIndices = Array.from({ length: batchEnd - batchStart }, (_, i) => batchStart + i);
|
|
4878
|
+
const batchResults = await this.executeBatch(batchIndices, analysis, iterationCount, concurrency, undefined);
|
|
4879
|
+
for (const { index, result } of batchResults) {
|
|
4880
|
+
if (result === undefined)
|
|
4881
|
+
continue;
|
|
4882
|
+
if (preserveOrder) {
|
|
4883
|
+
orderedResults[index] = result;
|
|
4884
|
+
} else {
|
|
4885
|
+
completionOrderResults.push(result);
|
|
4886
|
+
}
|
|
4882
4887
|
}
|
|
4883
4888
|
}
|
|
4889
|
+
const collected = preserveOrder ? orderedResults.filter((result) => result !== undefined) : completionOrderResults;
|
|
4890
|
+
return this.task.collectResults(collected);
|
|
4891
|
+
} finally {
|
|
4892
|
+
this.aggregatingParentMapProgress = false;
|
|
4884
4893
|
}
|
|
4885
|
-
|
|
4886
|
-
|
|
4894
|
+
}
|
|
4895
|
+
emitMapParentProgressFromPartials(childMessage) {
|
|
4896
|
+
const n = this.mapPartialIterationCount;
|
|
4897
|
+
if (n <= 0)
|
|
4898
|
+
return;
|
|
4899
|
+
const sum = this.mapPartialProgress.reduce((a, b) => a + b, 0);
|
|
4900
|
+
const overall = Math.round(sum / n);
|
|
4901
|
+
const done = this.mapPartialProgress.filter((v) => v >= 100).length;
|
|
4902
|
+
const base = `Map ${done}/${n}`;
|
|
4903
|
+
const msg = childMessage ? `${base} \u2014 ${childMessage}` : `${base} iterations`;
|
|
4904
|
+
this.handleProgress(overall, msg);
|
|
4887
4905
|
}
|
|
4888
4906
|
async executeReduceIterations(analysis) {
|
|
4889
4907
|
const iterationCount = analysis.iterationCount;
|
|
@@ -4895,7 +4913,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4895
4913
|
const iterationInput = this.task.buildIterationRunInput(analysis, index, iterationCount, {
|
|
4896
4914
|
accumulator
|
|
4897
4915
|
});
|
|
4898
|
-
const iterationResult = await this.executeSubgraphIteration(iterationInput);
|
|
4916
|
+
const iterationResult = await this.executeSubgraphIteration(iterationInput, index, iterationCount);
|
|
4899
4917
|
accumulator = this.task.mergeIterationIntoAccumulator(accumulator, iterationResult, index);
|
|
4900
4918
|
const progress = Math.round((index + 1) / iterationCount * 100);
|
|
4901
4919
|
await this.handleProgress(progress, `Completed ${index + 1}/${iterationCount} iterations`);
|
|
@@ -4918,7 +4936,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4918
4936
|
}
|
|
4919
4937
|
const index = indices[position];
|
|
4920
4938
|
const iterationInput = this.task.buildIterationRunInput(analysis, index, iterationCount);
|
|
4921
|
-
const result = await this.executeSubgraphIteration(iterationInput);
|
|
4939
|
+
const result = await this.executeSubgraphIteration(iterationInput, index, iterationCount);
|
|
4922
4940
|
results.push({ index, result });
|
|
4923
4941
|
await onItemComplete?.();
|
|
4924
4942
|
}
|
|
@@ -4945,20 +4963,44 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4945
4963
|
}
|
|
4946
4964
|
return clone;
|
|
4947
4965
|
}
|
|
4948
|
-
async executeSubgraphIteration(input) {
|
|
4966
|
+
async executeSubgraphIteration(input, index, iterationCount) {
|
|
4949
4967
|
if (this.abortController?.signal.aborted) {
|
|
4950
4968
|
return;
|
|
4951
4969
|
}
|
|
4952
4970
|
const graphClone = this.cloneGraph(this.task.subGraph);
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4971
|
+
this.task.emit("iteration_start", index, iterationCount);
|
|
4972
|
+
const taskProgressUnsubs = [];
|
|
4973
|
+
for (const t of graphClone.getTasks()) {
|
|
4974
|
+
const fn = (p, message) => {
|
|
4975
|
+
this.task.emit("iteration_progress", index, iterationCount, p, message);
|
|
4976
|
+
if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
|
|
4977
|
+
this.mapPartialProgress[index] = Math.max(this.mapPartialProgress[index] ?? 0, p);
|
|
4978
|
+
this.emitMapParentProgressFromPartials(message);
|
|
4979
|
+
}
|
|
4980
|
+
};
|
|
4981
|
+
t.events.on("progress", fn);
|
|
4982
|
+
taskProgressUnsubs.push({ task: t, fn });
|
|
4983
|
+
}
|
|
4984
|
+
try {
|
|
4985
|
+
const results = await graphClone.run(input, {
|
|
4986
|
+
parentSignal: this.abortController?.signal,
|
|
4987
|
+
outputCache: this.outputCache,
|
|
4988
|
+
registry: this.registry
|
|
4989
|
+
});
|
|
4990
|
+
if (results.length === 0) {
|
|
4991
|
+
return;
|
|
4992
|
+
}
|
|
4993
|
+
return graphClone.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
|
|
4994
|
+
} finally {
|
|
4995
|
+
for (const { task, fn } of taskProgressUnsubs) {
|
|
4996
|
+
task.events.off("progress", fn);
|
|
4997
|
+
}
|
|
4998
|
+
if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
|
|
4999
|
+
this.mapPartialProgress[index] = 100;
|
|
5000
|
+
this.emitMapParentProgressFromPartials();
|
|
5001
|
+
}
|
|
5002
|
+
this.task.emit("iteration_complete", index, iterationCount);
|
|
4960
5003
|
}
|
|
4961
|
-
return graphClone.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
|
|
4962
5004
|
}
|
|
4963
5005
|
}
|
|
4964
5006
|
|
|
@@ -5456,7 +5498,6 @@ class IteratorTask extends GraphAsTask {
|
|
|
5456
5498
|
}
|
|
5457
5499
|
|
|
5458
5500
|
// src/task/WhileTask.ts
|
|
5459
|
-
init_ConditionUtils();
|
|
5460
5501
|
init_GraphAsTask();
|
|
5461
5502
|
init_TaskError();
|
|
5462
5503
|
|
|
@@ -6464,7 +6505,6 @@ queueMicrotask(() => {
|
|
|
6464
6505
|
});
|
|
6465
6506
|
|
|
6466
6507
|
// src/task/index.ts
|
|
6467
|
-
init_StreamTypes();
|
|
6468
6508
|
init_Task();
|
|
6469
6509
|
init_TaskError();
|
|
6470
6510
|
|
|
@@ -6753,6 +6793,7 @@ class TaskOutputTabularRepository extends TaskOutputRepository {
|
|
|
6753
6793
|
export {
|
|
6754
6794
|
wrapSchemaInArray,
|
|
6755
6795
|
whileTaskConfigSchema,
|
|
6796
|
+
taskPrototypeHasOwnExecute,
|
|
6756
6797
|
setTaskQueueRegistry,
|
|
6757
6798
|
setGlobalTaskConstructors,
|
|
6758
6799
|
serialGraph,
|
|
@@ -6874,4 +6915,4 @@ export {
|
|
|
6874
6915
|
ConditionalTask
|
|
6875
6916
|
};
|
|
6876
6917
|
|
|
6877
|
-
//# debugId=
|
|
6918
|
+
//# debugId=C2FCEDD1A34FF93E64756E2164756E21
|