@workglow/task-graph 0.0.121 → 0.0.123

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.
Files changed (63) hide show
  1. package/dist/browser.js +103 -60
  2. package/dist/browser.js.map +25 -25
  3. package/dist/bun.js +103 -60
  4. package/dist/bun.js.map +25 -25
  5. package/dist/node.js +103 -60
  6. package/dist/node.js.map +25 -25
  7. package/dist/storage/TaskGraphRepository.d.ts.map +1 -1
  8. package/dist/storage/TaskGraphTabularRepository.d.ts +1 -1
  9. package/dist/storage/TaskGraphTabularRepository.d.ts.map +1 -1
  10. package/dist/storage/TaskOutputRepository.d.ts.map +1 -1
  11. package/dist/storage/TaskOutputTabularRepository.d.ts.map +1 -1
  12. package/dist/task/ConditionalTask.d.ts +1 -1
  13. package/dist/task/ConditionalTask.d.ts.map +1 -1
  14. package/dist/task/FallbackTask.d.ts +45 -45
  15. package/dist/task/FallbackTask.d.ts.map +1 -1
  16. package/dist/task/FallbackTaskRunner.d.ts +0 -8
  17. package/dist/task/FallbackTaskRunner.d.ts.map +1 -1
  18. package/dist/task/GraphAsTask.d.ts +1 -2
  19. package/dist/task/GraphAsTask.d.ts.map +1 -1
  20. package/dist/task/GraphAsTaskRunner.d.ts.map +1 -1
  21. package/dist/task/ITask.d.ts +2 -1
  22. package/dist/task/ITask.d.ts.map +1 -1
  23. package/dist/task/InputResolver.d.ts +2 -1
  24. package/dist/task/InputResolver.d.ts.map +1 -1
  25. package/dist/task/IteratorTask.d.ts +13 -13
  26. package/dist/task/IteratorTask.d.ts.map +1 -1
  27. package/dist/task/IteratorTaskRunner.d.ts +9 -1
  28. package/dist/task/IteratorTaskRunner.d.ts.map +1 -1
  29. package/dist/task/JobQueueTask.d.ts +10 -10
  30. package/dist/task/JobQueueTask.d.ts.map +1 -1
  31. package/dist/task/MapTask.d.ts +19 -19
  32. package/dist/task/MapTask.d.ts.map +1 -1
  33. package/dist/task/ReduceTask.d.ts +14 -14
  34. package/dist/task/ReduceTask.d.ts.map +1 -1
  35. package/dist/task/StreamTypes.d.ts +1 -1
  36. package/dist/task/StreamTypes.d.ts.map +1 -1
  37. package/dist/task/Task.d.ts +2 -1
  38. package/dist/task/Task.d.ts.map +1 -1
  39. package/dist/task/TaskError.d.ts.map +1 -1
  40. package/dist/task/TaskEvents.d.ts +16 -1
  41. package/dist/task/TaskEvents.d.ts.map +1 -1
  42. package/dist/task/TaskJSON.d.ts +4 -4
  43. package/dist/task/TaskJSON.d.ts.map +1 -1
  44. package/dist/task/TaskQueueRegistry.d.ts.map +1 -1
  45. package/dist/task/TaskRunner.d.ts.map +1 -1
  46. package/dist/task/TaskTypes.d.ts +1 -1
  47. package/dist/task/TaskTypes.d.ts.map +1 -1
  48. package/dist/task/WhileTask.d.ts +22 -22
  49. package/dist/task/WhileTask.d.ts.map +1 -1
  50. package/dist/task/WhileTaskRunner.d.ts.map +1 -1
  51. package/dist/task/index.d.ts +1 -1
  52. package/dist/task/iterationSchema.d.ts +1 -1
  53. package/dist/task/iterationSchema.d.ts.map +1 -1
  54. package/dist/task-graph/Dataflow.d.ts.map +1 -1
  55. package/dist/task-graph/GraphSchemaUtils.d.ts +1 -1
  56. package/dist/task-graph/GraphSchemaUtils.d.ts.map +1 -1
  57. package/dist/task-graph/TaskGraph.d.ts +2 -1
  58. package/dist/task-graph/TaskGraph.d.ts.map +1 -1
  59. package/dist/task-graph/TaskGraphRunner.d.ts +8 -2
  60. package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
  61. package/dist/task-graph/TaskGraphScheduler.d.ts.map +1 -1
  62. package/dist/task-graph/Workflow.d.ts.map +1 -1
  63. package/package.json +14 -14
package/dist/node.js CHANGED
@@ -82,7 +82,8 @@ var init_TaskTypes = __esm(() => {
82
82
  });
83
83
 
84
84
  // src/task-graph/Dataflow.ts
85
- import { areSemanticallyCompatible, EventEmitter } from "@workglow/util";
85
+ import { areSemanticallyCompatible } from "@workglow/util/schema";
86
+ import { EventEmitter } from "@workglow/util";
86
87
 
87
88
  class Dataflow {
88
89
  sourceTaskId;
@@ -913,7 +914,6 @@ function getStructuredOutputSchemas(schema) {
913
914
  function hasStructuredOutput(schema) {
914
915
  return getStructuredOutputSchemas(schema).size > 0;
915
916
  }
916
- var init_StreamTypes = () => {};
917
917
 
918
918
  // src/task/TaskRunner.ts
919
919
  import {
@@ -1292,22 +1292,21 @@ class TaskRunner {
1292
1292
  }
1293
1293
  async handleProgress(progress, message, ...args) {
1294
1294
  this.task.progress = progress;
1295
- await this.updateProgress(this.task, progress, message, ...args);
1296
1295
  this.task.emit("progress", progress, message, ...args);
1296
+ await this.updateProgress(this.task, progress, message, ...args);
1297
1297
  }
1298
1298
  }
1299
1299
  var init_TaskRunner = __esm(() => {
1300
1300
  init_TaskOutputRepository();
1301
1301
  init_Conversions();
1302
1302
  init_InputResolver();
1303
- init_StreamTypes();
1304
1303
  init_TaskError();
1305
1304
  init_TaskTypes();
1306
1305
  });
1307
1306
 
1308
1307
  // src/task/Task.ts
1308
+ import { compileSchema } from "@workglow/util/schema";
1309
1309
  import {
1310
- compileSchema,
1311
1310
  deepEqual,
1312
1311
  EventEmitter as EventEmitter3,
1313
1312
  uuid4 as uuid42
@@ -1600,7 +1599,7 @@ class Task {
1600
1599
  return this.events.waitOn(name);
1601
1600
  }
1602
1601
  emit(name, ...args) {
1603
- this._events?.emit(name, ...args);
1602
+ this.events.emit(name, ...args);
1604
1603
  }
1605
1604
  emitSchemaChange(inputSchema, outputSchema) {
1606
1605
  const finalInputSchema = inputSchema ?? this.inputSchema();
@@ -1742,13 +1741,15 @@ class Task {
1742
1741
  const extras = config.extras;
1743
1742
  if (!extras || Object.keys(extras).length === 0)
1744
1743
  delete config.extras;
1745
- const json = this.stripSymbols({
1744
+ const base = {
1746
1745
  id: this.id,
1747
1746
  type: this.type,
1748
- defaults: this.defaults,
1749
- config
1750
- });
1751
- return json;
1747
+ defaults: this.defaults
1748
+ };
1749
+ if (Object.keys(config).length > 0) {
1750
+ base.config = config;
1751
+ }
1752
+ return this.stripSymbols(base);
1752
1753
  }
1753
1754
  toDependencyJSON(options) {
1754
1755
  const json = this.toJSON(options);
@@ -1861,13 +1862,11 @@ function getNestedValue(obj, path) {
1861
1862
  }
1862
1863
  return current;
1863
1864
  }
1864
- var init_ConditionUtils = () => {};
1865
1865
 
1866
1866
  // src/task/ConditionalTask.ts
1867
1867
  import { getLogger } from "@workglow/util";
1868
1868
  var conditionalTaskConfigSchema, ConditionalTask;
1869
1869
  var init_ConditionalTask = __esm(() => {
1870
- init_ConditionUtils();
1871
1870
  init_Task();
1872
1871
  init_TaskTypes();
1873
1872
  conditionalTaskConfigSchema = {
@@ -2221,7 +2220,6 @@ class DependencyBasedScheduler {
2221
2220
  }
2222
2221
  }
2223
2222
  var init_TaskGraphScheduler = __esm(() => {
2224
- init_StreamTypes();
2225
2223
  init_TaskTypes();
2226
2224
  });
2227
2225
 
@@ -2235,6 +2233,10 @@ import {
2235
2233
  SpanStatusCode as SpanStatusCode2,
2236
2234
  uuid4 as uuid43
2237
2235
  } from "@workglow/util";
2236
+ function taskPrototypeHasOwnExecute(task) {
2237
+ const Ctor = task.constructor;
2238
+ return Object.hasOwn(Ctor.prototype, "execute");
2239
+ }
2238
2240
 
2239
2241
  class TaskGraphRunner {
2240
2242
  processScheduler;
@@ -2821,23 +2823,25 @@ class TaskGraphRunner {
2821
2823
  this.graph.emit("disabled");
2822
2824
  }
2823
2825
  async handleProgress(task, progress, message, ...args) {
2824
- const total = this.graph.getTasks().length;
2825
- if (total > 1) {
2826
- const completed = this.graph.getTasks().reduce((acc, t) => acc + t.progress, 0);
2827
- progress = Math.round(completed / total);
2826
+ const contributors = this.graph.getTasks().filter(taskPrototypeHasOwnExecute);
2827
+ if (contributors.length > 1) {
2828
+ const sum = contributors.reduce((acc, t) => acc + t.progress, 0);
2829
+ progress = Math.round(sum / contributors.length);
2830
+ } else if (contributors.length === 1) {
2831
+ const [only] = contributors;
2832
+ progress = only.progress;
2828
2833
  }
2829
2834
  this.pushStatusFromNodeToEdges(this.graph, task);
2835
+ this.graph.emit("graph_progress", progress, message, args);
2830
2836
  if (task.runOutputData && Object.keys(task.runOutputData).length > 0) {
2831
2837
  await this.pushOutputFromNodeToEdges(task, task.runOutputData);
2832
2838
  }
2833
- this.graph.emit("graph_progress", progress, message, args);
2834
2839
  }
2835
2840
  }
2836
2841
  var PROPERTY_ARRAY = "PROPERTY_ARRAY", GRAPH_RESULT_ARRAY = "GRAPH_RESULT_ARRAY";
2837
2842
  var init_TaskGraphRunner = __esm(() => {
2838
2843
  init_TaskOutputRepository();
2839
2844
  init_ConditionalTask();
2840
- init_StreamTypes();
2841
2845
  init_TaskError();
2842
2846
  init_TaskTypes();
2843
2847
  init_Dataflow();
@@ -2901,7 +2905,7 @@ __export(exports_GraphAsTask, {
2901
2905
  graphAsTaskConfigSchema: () => graphAsTaskConfigSchema,
2902
2906
  GraphAsTask: () => GraphAsTask
2903
2907
  });
2904
- import { compileSchema as compileSchema2 } from "@workglow/util";
2908
+ import { compileSchema as compileSchema2 } from "@workglow/util/schema";
2905
2909
  var graphAsTaskConfigSchema, GraphAsTask;
2906
2910
  var init_GraphAsTask = __esm(() => {
2907
2911
  init_GraphSchemaUtils();
@@ -3202,7 +3206,8 @@ var init_TaskGraphEvents = __esm(() => {
3202
3206
  });
3203
3207
 
3204
3208
  // src/task-graph/TaskGraph.ts
3205
- import { DirectedAcyclicGraph, EventEmitter as EventEmitter4, uuid4 as uuid44 } from "@workglow/util";
3209
+ import { DirectedAcyclicGraph } from "@workglow/util/graph";
3210
+ import { EventEmitter as EventEmitter4, uuid4 as uuid44 } from "@workglow/util";
3206
3211
 
3207
3212
  class TaskGraph {
3208
3213
  outputCache;
@@ -3515,7 +3520,6 @@ init_Dataflow();
3515
3520
 
3516
3521
  // src/task-graph/Workflow.ts
3517
3522
  init_GraphAsTask();
3518
- init_StreamTypes();
3519
3523
  init_TaskError();
3520
3524
  init_Conversions();
3521
3525
  init_Dataflow();
@@ -4614,7 +4618,6 @@ function resetMethodNameCache() {
4614
4618
  }
4615
4619
  // src/task/index.ts
4616
4620
  init_ConditionalTask();
4617
- init_ConditionUtils();
4618
4621
 
4619
4622
  // src/task/FallbackTask.ts
4620
4623
  init_GraphAsTask();
@@ -4838,6 +4841,9 @@ init_GraphAsTaskRunner();
4838
4841
  import { uuid4 as uuid46 } from "@workglow/util";
4839
4842
 
4840
4843
  class IteratorTaskRunner extends GraphAsTaskRunner {
4844
+ aggregatingParentMapProgress = false;
4845
+ mapPartialProgress = [];
4846
+ mapPartialIterationCount = 0;
4841
4847
  async executeTask(input) {
4842
4848
  const analysis = this.task.analyzeIterationInput(input);
4843
4849
  if (analysis.iterationCount === 0) {
@@ -4859,30 +4865,43 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
4859
4865
  const concurrency = Math.max(1, Math.min(requestedConcurrency, iterationCount));
4860
4866
  const orderedResults = preserveOrder ? new Array(iterationCount) : [];
4861
4867
  const completionOrderResults = [];
4862
- let completedCount = 0;
4863
- for (let batchStart = 0;batchStart < iterationCount; batchStart += batchSize) {
4864
- if (this.abortController?.signal.aborted) {
4865
- break;
4866
- }
4867
- const batchEnd = Math.min(batchStart + batchSize, iterationCount);
4868
- const batchIndices = Array.from({ length: batchEnd - batchStart }, (_, i) => batchStart + i);
4869
- const batchResults = await this.executeBatch(batchIndices, analysis, iterationCount, concurrency, async () => {
4870
- completedCount++;
4871
- const progress = Math.round(completedCount / iterationCount * 100);
4872
- await this.handleProgress(progress, `Completed ${completedCount}/${iterationCount} iterations`);
4873
- });
4874
- for (const { index, result } of batchResults) {
4875
- if (result === undefined)
4876
- continue;
4877
- if (preserveOrder) {
4878
- orderedResults[index] = result;
4879
- } else {
4880
- completionOrderResults.push(result);
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
+ }
4881
4887
  }
4882
4888
  }
4889
+ const collected = preserveOrder ? orderedResults.filter((result) => result !== undefined) : completionOrderResults;
4890
+ return this.task.collectResults(collected);
4891
+ } finally {
4892
+ this.aggregatingParentMapProgress = false;
4883
4893
  }
4884
- const collected = preserveOrder ? orderedResults.filter((result) => result !== undefined) : completionOrderResults;
4885
- return this.task.collectResults(collected);
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} — ${childMessage}` : `${base} iterations`;
4904
+ this.handleProgress(overall, msg);
4886
4905
  }
4887
4906
  async executeReduceIterations(analysis) {
4888
4907
  const iterationCount = analysis.iterationCount;
@@ -4894,7 +4913,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
4894
4913
  const iterationInput = this.task.buildIterationRunInput(analysis, index, iterationCount, {
4895
4914
  accumulator
4896
4915
  });
4897
- const iterationResult = await this.executeSubgraphIteration(iterationInput);
4916
+ const iterationResult = await this.executeSubgraphIteration(iterationInput, index, iterationCount);
4898
4917
  accumulator = this.task.mergeIterationIntoAccumulator(accumulator, iterationResult, index);
4899
4918
  const progress = Math.round((index + 1) / iterationCount * 100);
4900
4919
  await this.handleProgress(progress, `Completed ${index + 1}/${iterationCount} iterations`);
@@ -4917,7 +4936,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
4917
4936
  }
4918
4937
  const index = indices[position];
4919
4938
  const iterationInput = this.task.buildIterationRunInput(analysis, index, iterationCount);
4920
- const result = await this.executeSubgraphIteration(iterationInput);
4939
+ const result = await this.executeSubgraphIteration(iterationInput, index, iterationCount);
4921
4940
  results.push({ index, result });
4922
4941
  await onItemComplete?.();
4923
4942
  }
@@ -4944,20 +4963,44 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
4944
4963
  }
4945
4964
  return clone;
4946
4965
  }
4947
- async executeSubgraphIteration(input) {
4966
+ async executeSubgraphIteration(input, index, iterationCount) {
4948
4967
  if (this.abortController?.signal.aborted) {
4949
4968
  return;
4950
4969
  }
4951
4970
  const graphClone = this.cloneGraph(this.task.subGraph);
4952
- const results = await graphClone.run(input, {
4953
- parentSignal: this.abortController?.signal,
4954
- outputCache: this.outputCache,
4955
- registry: this.registry
4956
- });
4957
- if (results.length === 0) {
4958
- return;
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);
4959
5003
  }
4960
- return graphClone.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
4961
5004
  }
4962
5005
  }
4963
5006
 
@@ -5455,7 +5498,6 @@ class IteratorTask extends GraphAsTask {
5455
5498
  }
5456
5499
 
5457
5500
  // src/task/WhileTask.ts
5458
- init_ConditionUtils();
5459
5501
  init_GraphAsTask();
5460
5502
  init_TaskError();
5461
5503
 
@@ -6463,7 +6505,6 @@ queueMicrotask(() => {
6463
6505
  });
6464
6506
 
6465
6507
  // src/task/index.ts
6466
- init_StreamTypes();
6467
6508
  init_Task();
6468
6509
  init_TaskError();
6469
6510
 
@@ -6668,7 +6709,8 @@ init_TaskOutputRepository();
6668
6709
 
6669
6710
  // src/storage/TaskOutputTabularRepository.ts
6670
6711
  init_TaskOutputRepository();
6671
- import { compress, decompress, makeFingerprint } from "@workglow/util";
6712
+ import { compress, decompress } from "@workglow/util/compress";
6713
+ import { makeFingerprint } from "@workglow/util";
6672
6714
  var TaskOutputSchema = {
6673
6715
  type: "object",
6674
6716
  properties: {
@@ -6752,6 +6794,7 @@ class TaskOutputTabularRepository extends TaskOutputRepository {
6752
6794
  export {
6753
6795
  wrapSchemaInArray,
6754
6796
  whileTaskConfigSchema,
6797
+ taskPrototypeHasOwnExecute,
6755
6798
  setTaskQueueRegistry,
6756
6799
  setGlobalTaskConstructors,
6757
6800
  serialGraph,
@@ -6873,4 +6916,4 @@ export {
6873
6916
  ConditionalTask
6874
6917
  };
6875
6918
 
6876
- //# debugId=65F073C748987DA264756E2164756E21
6919
+ //# debugId=411C07B0A5E826F264756E2164756E21