@workglow/task-graph 0.2.10 → 0.2.12

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/bun.js CHANGED
@@ -1720,6 +1720,7 @@ class Task {
1720
1720
  static passthroughInputsToOutputs = false;
1721
1721
  static customizable = false;
1722
1722
  static isGraphOutput = false;
1723
+ static isPassthrough = false;
1723
1724
  static hasDynamicEntitlements = false;
1724
1725
  static entitlements() {
1725
1726
  return EMPTY_ENTITLEMENTS;
@@ -2687,7 +2688,9 @@ class DependencyBasedScheduler {
2687
2688
  // src/task-graph/TaskGraphRunner.ts
2688
2689
  function taskPrototypeHasOwnExecute(task) {
2689
2690
  const Ctor = task.constructor;
2690
- return Object.hasOwn(Ctor.prototype, "execute");
2691
+ if (Ctor.isPassthrough)
2692
+ return false;
2693
+ return Object.hasOwn(Ctor.prototype, "execute") || Object.hasOwn(Ctor.prototype, "executeStream") || task.hasChildren();
2691
2694
  }
2692
2695
  var PROPERTY_ARRAY = "PROPERTY_ARRAY";
2693
2696
  var GRAPH_RESULT_ARRAY = "GRAPH_RESULT_ARRAY";
@@ -3379,7 +3382,7 @@ class TaskGraphRunner {
3379
3382
  class GraphAsTaskRunner extends TaskRunner {
3380
3383
  async executeTaskChildren(input) {
3381
3384
  const unsubscribe = this.task.subGraph.subscribe("graph_progress", (progress, message, ...args) => {
3382
- this.task.emit("progress", progress, message, ...args);
3385
+ this.handleProgress(progress, message, ...args);
3383
3386
  });
3384
3387
  const results = await this.task.subGraph.run(input, {
3385
3388
  parentSignal: this.abortController?.signal,
@@ -5366,30 +5369,41 @@ class FallbackTaskRunner extends GraphAsTaskRunner {
5366
5369
  }
5367
5370
  const errors = [];
5368
5371
  const totalAttempts = alternatives.length;
5369
- for (let i = 0;i < alternatives.length; i++) {
5370
- if (this.abortController?.signal.aborted) {
5371
- throw new TaskAbortedError("Fallback aborted");
5372
- }
5373
- const alternative = alternatives[i];
5374
- const attemptNumber = i + 1;
5375
- await this.handleProgress(Math.round((i + 0.5) / totalAttempts * 100), `Trying data alternative ${attemptNumber}/${totalAttempts}`);
5376
- try {
5377
- this.resetSubgraph();
5378
- const mergedInput = { ...input, ...alternative };
5379
- const results = await this.task.subGraph.run(mergedInput, {
5380
- parentSignal: this.abortController?.signal,
5381
- outputCache: this.outputCache,
5382
- registry: this.registry
5383
- });
5384
- const mergedOutput = this.task.subGraph.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5385
- await this.handleProgress(100, `Data alternative ${attemptNumber}/${totalAttempts} succeeded`);
5386
- return await this.executeTaskReactive(input, mergedOutput);
5387
- } catch (error) {
5388
- if (error instanceof TaskAbortedError && !(error instanceof TaskTimeoutError)) {
5389
- throw error;
5372
+ let currentAttemptIndex = 0;
5373
+ const onSubgraphProgress = (innerProgress, message) => {
5374
+ const blended = Math.round((currentAttemptIndex + innerProgress / 100) / totalAttempts * 100);
5375
+ this.handleProgress(blended, message ?? `Data alternative ${currentAttemptIndex + 1}/${totalAttempts}`);
5376
+ };
5377
+ const unsubscribeSubgraphProgress = this.task.subGraph.subscribe("graph_progress", onSubgraphProgress);
5378
+ try {
5379
+ for (let i = 0;i < alternatives.length; i++) {
5380
+ if (this.abortController?.signal.aborted) {
5381
+ throw new TaskAbortedError("Fallback aborted");
5382
+ }
5383
+ currentAttemptIndex = i;
5384
+ const alternative = alternatives[i];
5385
+ const attemptNumber = i + 1;
5386
+ await this.handleProgress(Math.round((i + 0.5) / totalAttempts * 100), `Trying data alternative ${attemptNumber}/${totalAttempts}`);
5387
+ try {
5388
+ this.resetSubgraph();
5389
+ const mergedInput = { ...input, ...alternative };
5390
+ const results = await this.task.subGraph.run(mergedInput, {
5391
+ parentSignal: this.abortController?.signal,
5392
+ outputCache: this.outputCache,
5393
+ registry: this.registry
5394
+ });
5395
+ const mergedOutput = this.task.subGraph.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5396
+ await this.handleProgress(100, `Data alternative ${attemptNumber}/${totalAttempts} succeeded`);
5397
+ return await this.executeTaskReactive(input, mergedOutput);
5398
+ } catch (error) {
5399
+ if (error instanceof TaskAbortedError && !(error instanceof TaskTimeoutError)) {
5400
+ throw error;
5401
+ }
5402
+ errors.push({ alternative, error });
5390
5403
  }
5391
- errors.push({ alternative, error });
5392
5404
  }
5405
+ } finally {
5406
+ unsubscribeSubgraphProgress();
5393
5407
  }
5394
5408
  throw this.buildAggregateError(errors, "data");
5395
5409
  }
@@ -5730,18 +5744,14 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
5730
5744
  }
5731
5745
  const graphClone = this.cloneGraph(this.task.subGraph);
5732
5746
  this.task.emit("iteration_start", index, iterationCount);
5733
- const taskProgressUnsubs = [];
5734
- for (const t of graphClone.getTasks()) {
5735
- const fn = (p, message) => {
5736
- this.task.emit("iteration_progress", index, iterationCount, p, message);
5737
- if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5738
- this.mapPartialProgress[index] = Math.max(this.mapPartialProgress[index] ?? 0, p);
5739
- this.emitMapParentProgressFromPartials(message);
5740
- }
5741
- };
5742
- t.events.on("progress", fn);
5743
- taskProgressUnsubs.push({ task: t, fn });
5744
- }
5747
+ const onGraphProgress = (p, message) => {
5748
+ this.task.emit("iteration_progress", index, iterationCount, p, message);
5749
+ if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5750
+ this.mapPartialProgress[index] = Math.max(this.mapPartialProgress[index] ?? 0, p);
5751
+ this.emitMapParentProgressFromPartials(message);
5752
+ }
5753
+ };
5754
+ const unsubscribeGraphProgress = graphClone.subscribe("graph_progress", onGraphProgress);
5745
5755
  try {
5746
5756
  const results = await graphClone.run(input, {
5747
5757
  parentSignal: this.abortController?.signal,
@@ -5754,9 +5764,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
5754
5764
  }
5755
5765
  return graphClone.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5756
5766
  } finally {
5757
- for (const { task, fn } of taskProgressUnsubs) {
5758
- task.events.off("progress", fn);
5759
- }
5767
+ unsubscribeGraphProgress();
5760
5768
  if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5761
5769
  this.mapPartialProgress[index] = 100;
5762
5770
  this.emitMapParentProgressFromPartials();
@@ -6422,55 +6430,65 @@ class WhileTask extends GraphAsTask {
6422
6430
  let currentInput = { ...input };
6423
6431
  let currentOutput = {};
6424
6432
  const effectiveMax = arrayAnalysis ? Math.min(this.maxIterations, arrayAnalysis.iterationCount) : this.maxIterations;
6425
- while (this._currentIteration < effectiveMax) {
6426
- if (context.signal?.aborted) {
6427
- break;
6428
- }
6429
- let iterationInput;
6430
- if (arrayAnalysis) {
6431
- iterationInput = {
6432
- ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6433
- _iterationIndex: this._currentIteration
6434
- };
6435
- } else {
6436
- iterationInput = {
6437
- ...currentInput,
6438
- _iterationIndex: this._currentIteration
6439
- };
6440
- }
6441
- const results = await this.subGraph.run(iterationInput, {
6442
- parentSignal: context.signal
6443
- });
6444
- currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6445
- let shouldContinue;
6446
- try {
6447
- shouldContinue = condition(currentOutput, this._currentIteration);
6448
- } catch (err) {
6449
- if (err instanceof TaskFailedError) {
6450
- throw err;
6433
+ const onInnerGraphProgress = (innerProgress, innerMessage) => {
6434
+ const blended = Math.min(Math.round((this._currentIteration + innerProgress / 100) / effectiveMax * 100), 99);
6435
+ const message = innerMessage ? `Iteration ${this._currentIteration + 1}/${effectiveMax}: ${innerMessage}` : `Iteration ${this._currentIteration + 1}/${effectiveMax}`;
6436
+ context.updateProgress(blended, message);
6437
+ };
6438
+ const unsubscribeInnerProgress = this.subGraph.subscribe("graph_progress", onInnerGraphProgress);
6439
+ try {
6440
+ while (this._currentIteration < effectiveMax) {
6441
+ if (context.signal?.aborted) {
6442
+ break;
6451
6443
  }
6452
- const message = `${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`;
6453
- const wrappedError = new TaskFailedError(message);
6454
- if (err instanceof Error && err.stack) {
6455
- if (wrappedError.stack) {
6456
- wrappedError.stack += `
6444
+ let iterationInput;
6445
+ if (arrayAnalysis) {
6446
+ iterationInput = {
6447
+ ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6448
+ _iterationIndex: this._currentIteration
6449
+ };
6450
+ } else {
6451
+ iterationInput = {
6452
+ ...currentInput,
6453
+ _iterationIndex: this._currentIteration
6454
+ };
6455
+ }
6456
+ const results = await this.subGraph.run(iterationInput, {
6457
+ parentSignal: context.signal
6458
+ });
6459
+ currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6460
+ let shouldContinue;
6461
+ try {
6462
+ shouldContinue = condition(currentOutput, this._currentIteration);
6463
+ } catch (err) {
6464
+ if (err instanceof TaskFailedError) {
6465
+ throw err;
6466
+ }
6467
+ const message = `${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`;
6468
+ const wrappedError = new TaskFailedError(message);
6469
+ if (err instanceof Error && err.stack) {
6470
+ if (wrappedError.stack) {
6471
+ wrappedError.stack += `
6457
6472
  Caused by original error:
6458
6473
  ${err.stack}`;
6459
- } else {
6460
- wrappedError.stack = err.stack;
6474
+ } else {
6475
+ wrappedError.stack = err.stack;
6476
+ }
6461
6477
  }
6478
+ throw wrappedError;
6462
6479
  }
6463
- throw wrappedError;
6464
- }
6465
- if (!shouldContinue) {
6466
- break;
6467
- }
6468
- if (this.chainIterations) {
6469
- currentInput = { ...currentInput, ...currentOutput };
6480
+ if (!shouldContinue) {
6481
+ break;
6482
+ }
6483
+ if (this.chainIterations) {
6484
+ currentInput = { ...currentInput, ...currentOutput };
6485
+ }
6486
+ this._currentIteration++;
6487
+ const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6488
+ await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6470
6489
  }
6471
- this._currentIteration++;
6472
- const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6473
- await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6490
+ } finally {
6491
+ unsubscribeInnerProgress();
6474
6492
  }
6475
6493
  return currentOutput;
6476
6494
  }
@@ -6487,40 +6505,50 @@ ${err.stack}`;
6487
6505
  let currentInput = { ...input };
6488
6506
  let currentOutput = {};
6489
6507
  const effectiveMax = arrayAnalysis ? Math.min(this.maxIterations, arrayAnalysis.iterationCount) : this.maxIterations;
6490
- while (this._currentIteration < effectiveMax) {
6491
- if (context.signal?.aborted)
6492
- break;
6493
- let iterationInput;
6494
- if (arrayAnalysis) {
6495
- iterationInput = {
6496
- ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6497
- _iterationIndex: this._currentIteration
6498
- };
6499
- } else {
6500
- iterationInput = {
6501
- ...currentInput,
6502
- _iterationIndex: this._currentIteration
6503
- };
6504
- }
6505
- const results = await this.subGraph.run(iterationInput, {
6506
- parentSignal: context.signal
6507
- });
6508
- currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6509
- let shouldContinue;
6510
- try {
6511
- shouldContinue = condition(currentOutput, this._currentIteration);
6512
- } catch (err) {
6513
- throw new TaskFailedError(`${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`);
6514
- }
6515
- if (!shouldContinue) {
6516
- break;
6517
- }
6518
- if (this.chainIterations) {
6519
- currentInput = { ...currentInput, ...currentOutput };
6508
+ const onInnerGraphProgress = (innerProgress, innerMessage) => {
6509
+ const blended = Math.min(Math.round((this._currentIteration + innerProgress / 100) / effectiveMax * 100), 99);
6510
+ const message = innerMessage ? `Iteration ${this._currentIteration + 1}/${effectiveMax}: ${innerMessage}` : `Iteration ${this._currentIteration + 1}/${effectiveMax}`;
6511
+ context.updateProgress(blended, message);
6512
+ };
6513
+ const unsubscribeInnerProgress = this.subGraph.subscribe("graph_progress", onInnerGraphProgress);
6514
+ try {
6515
+ while (this._currentIteration < effectiveMax) {
6516
+ if (context.signal?.aborted)
6517
+ break;
6518
+ let iterationInput;
6519
+ if (arrayAnalysis) {
6520
+ iterationInput = {
6521
+ ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6522
+ _iterationIndex: this._currentIteration
6523
+ };
6524
+ } else {
6525
+ iterationInput = {
6526
+ ...currentInput,
6527
+ _iterationIndex: this._currentIteration
6528
+ };
6529
+ }
6530
+ const results = await this.subGraph.run(iterationInput, {
6531
+ parentSignal: context.signal
6532
+ });
6533
+ currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6534
+ let shouldContinue;
6535
+ try {
6536
+ shouldContinue = condition(currentOutput, this._currentIteration);
6537
+ } catch (err) {
6538
+ throw new TaskFailedError(`${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`);
6539
+ }
6540
+ if (!shouldContinue) {
6541
+ break;
6542
+ }
6543
+ if (this.chainIterations) {
6544
+ currentInput = { ...currentInput, ...currentOutput };
6545
+ }
6546
+ this._currentIteration++;
6547
+ const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6548
+ await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6520
6549
  }
6521
- this._currentIteration++;
6522
- const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6523
- await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6550
+ } finally {
6551
+ unsubscribeInnerProgress();
6524
6552
  }
6525
6553
  yield { type: "finish", data: currentOutput };
6526
6554
  }
@@ -7606,4 +7634,4 @@ export {
7606
7634
  BROWSER_GRANTS
7607
7635
  };
7608
7636
 
7609
- //# debugId=E0C406676DEAA6C764756E2164756E21
7637
+ //# debugId=AD285DF96C5D872B64756E2164756E21