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