@usearazzo/runner 1.0.1-alpha.34 → 1.0.1-alpha.35
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/CHANGELOG.md +14 -0
- package/README.md +6 -1
- package/dist/arazzo-runner.browser.js +687 -317
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +52 -7
- package/src/errors/ExecutionError.cjs +2 -0
- package/src/errors/ExecutionError.mjs +2 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +58 -47
- package/src/executor/OpenAPIOperationExecutor.mjs +58 -47
- package/src/executor/WorkflowExecutor.cjs +302 -160
- package/src/executor/WorkflowExecutor.mjs +302 -160
- package/src/index.cjs +14 -0
- package/src/index.mjs +2 -0
- package/src/observability/EventChannel.cjs +30 -20
- package/src/observability/EventChannel.mjs +30 -23
- package/src/observability/Redactor.cjs +7 -5
- package/src/observability/Redactor.mjs +7 -5
- package/src/observability/combineObservers.cjs +18 -0
- package/src/observability/combineObservers.mjs +12 -0
- package/src/observability/instrument.cjs +159 -0
- package/src/observability/instrument.mjs +144 -0
- package/src/observability/logging/LoggingObserver.cjs +177 -0
- package/src/observability/logging/LoggingObserver.mjs +172 -0
- package/src/observability/logging/index.cjs +13 -0
- package/src/observability/logging/index.mjs +1 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.cjs +321 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.mjs +313 -0
- package/src/observability/opentelemetry/index.cjs +13 -0
- package/src/observability/opentelemetry/index.mjs +1 -0
- package/src/observability/stream/EventStream.cjs +112 -0
- package/src/observability/stream/EventStream.mjs +107 -0
- package/src/observability/stream/index.cjs +13 -0
- package/src/observability/stream/index.mjs +1 -0
- package/src/registry/DocumentRegistry.cjs +14 -9
- package/src/registry/DocumentRegistry.mjs +14 -9
- package/src/version.cjs +9 -0
- package/src/version.mjs +3 -0
- package/types/observability/logging/LoggingObserver.d.ts +82 -0
- package/types/observability/logging/index.d.ts +2 -0
- package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
- package/types/observability/opentelemetry/index.d.ts +2 -0
- package/types/observability/stream/EventStream.d.ts +68 -0
- package/types/observability/stream/index.d.ts +2 -0
- package/types/runner.d.ts +131 -34
|
@@ -22,6 +22,7 @@ var _StepExecutor = require("./StepExecutor.cjs");
|
|
|
22
22
|
var _ArazzoWorkflowLocatorNormalizer = _interopRequireDefault(require("./ArazzoWorkflowLocatorNormalizer.cjs"));
|
|
23
23
|
var _StepRetryRunner = _interopRequireDefault(require("./StepRetryRunner.cjs"));
|
|
24
24
|
var _WorkflowCallStack = _interopRequireDefault(require("./WorkflowCallStack.cjs"));
|
|
25
|
+
var _instrument = require("../observability/instrument.cjs");
|
|
25
26
|
var _StepTransitionInterpreter = _interopRequireWildcard(require("./StepTransitionInterpreter.cjs"));
|
|
26
27
|
var _ExecutionError = _interopRequireDefault(require("../errors/ExecutionError.cjs"));
|
|
27
28
|
var _ResolverError = _interopRequireDefault(require("../errors/ResolverError.cjs"));
|
|
@@ -98,6 +99,12 @@ function settledResult(result) {
|
|
|
98
99
|
* @internal
|
|
99
100
|
*/
|
|
100
101
|
|
|
102
|
+
/**
|
|
103
|
+
* How a step ran: its last attempt's outcome, the terminal action its retries
|
|
104
|
+
* resolved to, how many attempts it took, and where the run goes next.
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
|
|
101
108
|
/**
|
|
102
109
|
* One completed `dependsOn` run, remembered with the inputs it was actually
|
|
103
110
|
* given — see {@link RunScope.dependencyRuns}.
|
|
@@ -194,6 +201,7 @@ class WorkflowExecutor {
|
|
|
194
201
|
#retryRunner;
|
|
195
202
|
#interpreter = new _StepTransitionInterpreter.default();
|
|
196
203
|
#workflowLocatorNormalizer;
|
|
204
|
+
// emits only while `hasObservers`, so an unobserved block builds no events
|
|
197
205
|
#events;
|
|
198
206
|
constructor(options) {
|
|
199
207
|
this.#document = options.document;
|
|
@@ -203,7 +211,7 @@ class WorkflowExecutor {
|
|
|
203
211
|
this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
|
|
204
212
|
this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
|
|
205
213
|
this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
|
|
206
|
-
this.#events = _EventChannel.default
|
|
214
|
+
this.#events = new _EventChannel.default({
|
|
207
215
|
observer: options.observer,
|
|
208
216
|
now: this.#now
|
|
209
217
|
});
|
|
@@ -366,29 +374,81 @@ class WorkflowExecutor {
|
|
|
366
374
|
workflowId,
|
|
367
375
|
path: nested.path
|
|
368
376
|
};
|
|
369
|
-
// extracted before `workflow
|
|
377
|
+
// extracted before `workflow:start`: a workflow its document does not
|
|
370
378
|
// define never starts, and the event can say where the one it runs is.
|
|
371
379
|
const extracted = this.#extractWorkflow(locator);
|
|
372
|
-
|
|
373
|
-
this.#events?.emit({
|
|
374
|
-
type: 'workflow-start',
|
|
375
|
-
...frame,
|
|
376
|
-
via,
|
|
377
|
-
location: locator.document.locationOf(extracted)
|
|
378
|
-
}, startedAt);
|
|
379
|
-
const workflow = await this.#resolveWorkflow(locator, extracted, scope, frame);
|
|
380
|
-
const state = new _WorkflowExecutionState.default({
|
|
381
|
-
inputs
|
|
382
|
-
});
|
|
380
|
+
const location = locator.document.locationOf(extracted);
|
|
383
381
|
const invocation = {
|
|
384
382
|
workflowId,
|
|
385
383
|
document: locator.document,
|
|
386
|
-
state
|
|
384
|
+
state: new _WorkflowExecutionState.default({
|
|
385
|
+
inputs
|
|
386
|
+
}),
|
|
387
387
|
callStack: nested,
|
|
388
388
|
via,
|
|
389
389
|
frame
|
|
390
390
|
};
|
|
391
391
|
|
|
392
|
+
// traced from its `workflow:start` to its `workflow:settled`, so a span an
|
|
393
|
+
// instrumentation opens around it is active for all of its events.
|
|
394
|
+
return (0, _instrument.traced)(() => ({
|
|
395
|
+
kind: 'workflow',
|
|
396
|
+
...frame,
|
|
397
|
+
via,
|
|
398
|
+
location
|
|
399
|
+
}), async () => {
|
|
400
|
+
// a started workflow always settles, a throwing one included (an
|
|
401
|
+
// observer throwing on its start too), so an observer holding it open
|
|
402
|
+
// (a span, a stream consumer) can close it.
|
|
403
|
+
let result;
|
|
404
|
+
try {
|
|
405
|
+
// emitted before normalization, so its events nest inside this workflow's.
|
|
406
|
+
if (this.#events.hasObservers) {
|
|
407
|
+
this.#events.emit({
|
|
408
|
+
type: 'workflow:start',
|
|
409
|
+
...frame,
|
|
410
|
+
via,
|
|
411
|
+
location
|
|
412
|
+
}, startedAt);
|
|
413
|
+
}
|
|
414
|
+
result = await this.#runInvocation(locator, extracted, invocation, scope, startedAt);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
this.#settleThrown({
|
|
417
|
+
type: 'workflow:settled',
|
|
418
|
+
...frame,
|
|
419
|
+
status: 'failed',
|
|
420
|
+
settledStatus: 'failed',
|
|
421
|
+
outputs: {},
|
|
422
|
+
error
|
|
423
|
+
});
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
if (this.#events.hasObservers) {
|
|
427
|
+
this.#events.emit({
|
|
428
|
+
type: 'workflow:settled',
|
|
429
|
+
...frame,
|
|
430
|
+
status: result.status,
|
|
431
|
+
settledStatus: result.settledStatus,
|
|
432
|
+
outputs: result.outputs
|
|
433
|
+
}, startedAt + result.durationMs);
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* The part of {@link WorkflowExecutor.#run} after `workflow:start`:
|
|
441
|
+
* normalizes the workflow, checks its definition, runs its dependencies
|
|
442
|
+
* and its steps, and builds its result.
|
|
443
|
+
*/
|
|
444
|
+
async #runInvocation(locator, extracted, invocation, scope, startedAt) {
|
|
445
|
+
const {
|
|
446
|
+
workflowId,
|
|
447
|
+
callStack: nested,
|
|
448
|
+
frame
|
|
449
|
+
} = invocation;
|
|
450
|
+
const workflow = await this.#resolveWorkflow(locator, extracted, scope, frame);
|
|
451
|
+
|
|
392
452
|
// validated before any prerequisite runs: a malformed `steps` is an
|
|
393
453
|
// authoring error, and discovering it only after the dependencies have
|
|
394
454
|
// fired would mean live side effects on the way to a throw.
|
|
@@ -441,96 +501,16 @@ class WorkflowExecutor {
|
|
|
441
501
|
stepLoop: while (index < steps.length) {
|
|
442
502
|
const step = steps[index];
|
|
443
503
|
const stepId = (0, _apidomCore.toValue)(step.stepId);
|
|
444
|
-
const stepStartedAt = this.#now();
|
|
445
|
-
// the sub-workflow runs this step produces — one per attempt, so a retried
|
|
446
|
-
// sub-workflow step keeps every attempt's trace rather than only the last.
|
|
447
|
-
const subWorkflows = [];
|
|
448
|
-
// the retry reference runs this step's attempts produced, one per firing —
|
|
449
|
-
// separate from `subWorkflows` because a reference belongs to the retry
|
|
450
|
-
// that invoked it, not to the step's own target.
|
|
451
|
-
const retryReferences = [];
|
|
452
|
-
const stepFrame = {
|
|
453
|
-
...frame,
|
|
454
|
-
stepId
|
|
455
|
-
};
|
|
456
|
-
this.#events?.emit({
|
|
457
|
-
type: 'step-start',
|
|
458
|
-
...stepFrame,
|
|
459
|
-
location: invocation.document.locationOf(step)
|
|
460
|
-
}, stepStartedAt);
|
|
461
|
-
const attempt = this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(step, stepId, invocation, scope, subWorkflows), stepFrame), invocation, scope, stepId);
|
|
462
|
-
|
|
463
|
-
// the retry runner settles any `retry` actions, so `action` is the terminal
|
|
464
|
-
// action a retry chain resolved to and `attempts` is how many times the step
|
|
465
|
-
// ran.
|
|
466
504
|
const {
|
|
467
505
|
outcome,
|
|
468
506
|
action,
|
|
469
|
-
|
|
470
|
-
} = await
|
|
507
|
+
transition
|
|
508
|
+
} = await (0, _instrument.traced)(() => ({
|
|
509
|
+
kind: 'step',
|
|
510
|
+
...frame,
|
|
471
511
|
stepId,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
runReference: this.#retryReference(steps, stepFrame, invocation, scope, retryReferences),
|
|
475
|
-
onRetry: (retry, delayMs, attempt) => {
|
|
476
|
-
const decided = {
|
|
477
|
-
...stepFrame,
|
|
478
|
-
attempt
|
|
479
|
-
};
|
|
480
|
-
this.#events?.emit({
|
|
481
|
-
type: 'action-selected',
|
|
482
|
-
...decided,
|
|
483
|
-
action: retry,
|
|
484
|
-
transition: {
|
|
485
|
-
kind: 'retry'
|
|
486
|
-
},
|
|
487
|
-
location: invocation.document.locationOf(retry)
|
|
488
|
-
});
|
|
489
|
-
if (delayMs > 0) {
|
|
490
|
-
this.#events?.emit({
|
|
491
|
-
type: 'retry-wait',
|
|
492
|
-
...decided,
|
|
493
|
-
delayMs
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
const transition = this.#interpreter.interpret(action, outcome.successful, {
|
|
499
|
-
workflowId,
|
|
500
|
-
stepId
|
|
501
|
-
});
|
|
502
|
-
this.#events?.emit({
|
|
503
|
-
type: 'action-selected',
|
|
504
|
-
...stepFrame,
|
|
505
|
-
attempt: attempts,
|
|
506
|
-
action,
|
|
507
|
-
transition,
|
|
508
|
-
location: action === undefined ? undefined : invocation.document.locationOf(action)
|
|
509
|
-
});
|
|
510
|
-
state.setStepOutputs(outcome.stepId, outcome.outputs);
|
|
511
|
-
const stepSettledAt = this.#now();
|
|
512
|
-
trace.push({
|
|
513
|
-
stepId: outcome.stepId,
|
|
514
|
-
location: invocation.document.locationOf(step),
|
|
515
|
-
successful: outcome.successful,
|
|
516
|
-
action,
|
|
517
|
-
attempts,
|
|
518
|
-
durationMs: stepSettledAt - stepStartedAt,
|
|
519
|
-
successCriteria: outcome.successCriteria,
|
|
520
|
-
actionCriteria: outcome.actionCriteria,
|
|
521
|
-
...(subWorkflows.length > 0 ? {
|
|
522
|
-
subWorkflows
|
|
523
|
-
} : {}),
|
|
524
|
-
...(retryReferences.length > 0 ? {
|
|
525
|
-
retryReferences
|
|
526
|
-
} : {})
|
|
527
|
-
});
|
|
528
|
-
this.#events?.emit({
|
|
529
|
-
type: 'step-settled',
|
|
530
|
-
...stepFrame,
|
|
531
|
-
successful: outcome.successful,
|
|
532
|
-
attempts
|
|
533
|
-
}, stepSettledAt);
|
|
512
|
+
location: invocation.document.locationOf(step)
|
|
513
|
+
}), () => this.#runStep(step, stepId, steps, invocation, scope, trace));
|
|
534
514
|
switch (transition.kind) {
|
|
535
515
|
case 'next':
|
|
536
516
|
index += 1;
|
|
@@ -603,6 +583,159 @@ class WorkflowExecutor {
|
|
|
603
583
|
return this.#result(invocation, workflow, trace, runOutcome, dependencies, startedAt);
|
|
604
584
|
}
|
|
605
585
|
|
|
586
|
+
/**
|
|
587
|
+
* Emits the settled event of a workflow or step that threw. An observer
|
|
588
|
+
* throwing on it is ignored: the error that failed the operation is the one
|
|
589
|
+
* to report.
|
|
590
|
+
*/
|
|
591
|
+
#settleThrown(event) {
|
|
592
|
+
if (!this.#events.hasObservers) return;
|
|
593
|
+
try {
|
|
594
|
+
this.#events.emit(event);
|
|
595
|
+
} catch {
|
|
596
|
+
// the operation's own error is rethrown by the caller
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Runs one step of a workflow invocation, from its `step:start` to its
|
|
602
|
+
* `step:settled`, recording it in `trace` and its outputs in the state. A
|
|
603
|
+
* step that throws still settles, so an observer holding it open can close
|
|
604
|
+
* it.
|
|
605
|
+
*/
|
|
606
|
+
async #runStep(step, stepId, steps, invocation, scope, trace) {
|
|
607
|
+
const {
|
|
608
|
+
workflowId,
|
|
609
|
+
frame,
|
|
610
|
+
state
|
|
611
|
+
} = invocation;
|
|
612
|
+
const stepStartedAt = this.#now();
|
|
613
|
+
// the sub-workflow runs this step produces — one per attempt, so a retried
|
|
614
|
+
// sub-workflow step keeps every attempt's trace rather than only the last.
|
|
615
|
+
const subWorkflows = [];
|
|
616
|
+
// the retry reference runs this step's attempts produced, one per firing —
|
|
617
|
+
// separate from `subWorkflows` because a reference belongs to the retry
|
|
618
|
+
// that invoked it, not to the step's own target.
|
|
619
|
+
const retryReferences = [];
|
|
620
|
+
const stepFrame = {
|
|
621
|
+
...frame,
|
|
622
|
+
stepId
|
|
623
|
+
};
|
|
624
|
+
// the attempt reached, once past its boundary checks and before its
|
|
625
|
+
// step:attempt: an attempt announced is an attempt counted
|
|
626
|
+
let attempted = 0;
|
|
627
|
+
const countAttempt = runAttempt => attempt => {
|
|
628
|
+
attempted = attempt;
|
|
629
|
+
return runAttempt(attempt);
|
|
630
|
+
};
|
|
631
|
+
let settled;
|
|
632
|
+
try {
|
|
633
|
+
if (this.#events.hasObservers) {
|
|
634
|
+
this.#events.emit({
|
|
635
|
+
type: 'step:start',
|
|
636
|
+
...stepFrame,
|
|
637
|
+
location: invocation.document.locationOf(step)
|
|
638
|
+
}, stepStartedAt);
|
|
639
|
+
}
|
|
640
|
+
const attempt = this.#chargedAttempt(countAttempt(this.#observedAttempt(this.#stepAttempt(step, stepId, invocation, scope, subWorkflows), stepFrame)), invocation, scope, stepId);
|
|
641
|
+
|
|
642
|
+
// the retry runner settles any `retry` actions, so `action` is the terminal
|
|
643
|
+
// action a retry chain resolved to and `attempts` is how many times the step
|
|
644
|
+
// ran.
|
|
645
|
+
const {
|
|
646
|
+
outcome,
|
|
647
|
+
action,
|
|
648
|
+
attempts
|
|
649
|
+
} = await this.#retryRunner.run(attempt, {
|
|
650
|
+
stepId,
|
|
651
|
+
workflowId,
|
|
652
|
+
signal: scope.signal,
|
|
653
|
+
runReference: this.#retryReference(steps, stepFrame, invocation, scope, retryReferences),
|
|
654
|
+
onRetry: (retry, delayMs, attempt) => {
|
|
655
|
+
const decided = {
|
|
656
|
+
...stepFrame,
|
|
657
|
+
attempt
|
|
658
|
+
};
|
|
659
|
+
if (this.#events.hasObservers) {
|
|
660
|
+
this.#events.emit({
|
|
661
|
+
type: 'action:selected',
|
|
662
|
+
...decided,
|
|
663
|
+
action: retry,
|
|
664
|
+
transition: {
|
|
665
|
+
kind: 'retry'
|
|
666
|
+
},
|
|
667
|
+
location: invocation.document.locationOf(retry)
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (delayMs > 0 && this.#events.hasObservers) {
|
|
671
|
+
this.#events.emit({
|
|
672
|
+
type: 'retry:wait',
|
|
673
|
+
...decided,
|
|
674
|
+
delayMs
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
const transition = this.#interpreter.interpret(action, outcome.successful, {
|
|
680
|
+
workflowId,
|
|
681
|
+
stepId
|
|
682
|
+
});
|
|
683
|
+
if (this.#events.hasObservers) {
|
|
684
|
+
this.#events.emit({
|
|
685
|
+
type: 'action:selected',
|
|
686
|
+
...stepFrame,
|
|
687
|
+
attempt: attempts,
|
|
688
|
+
action,
|
|
689
|
+
transition,
|
|
690
|
+
location: action === undefined ? undefined : invocation.document.locationOf(action)
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
state.setStepOutputs(outcome.stepId, outcome.outputs);
|
|
694
|
+
const stepSettledAt = this.#now();
|
|
695
|
+
trace.push({
|
|
696
|
+
stepId: outcome.stepId,
|
|
697
|
+
location: invocation.document.locationOf(step),
|
|
698
|
+
successful: outcome.successful,
|
|
699
|
+
action,
|
|
700
|
+
attempts,
|
|
701
|
+
durationMs: stepSettledAt - stepStartedAt,
|
|
702
|
+
successCriteria: outcome.successCriteria,
|
|
703
|
+
actionCriteria: outcome.actionCriteria,
|
|
704
|
+
...(subWorkflows.length > 0 ? {
|
|
705
|
+
subWorkflows
|
|
706
|
+
} : {}),
|
|
707
|
+
...(retryReferences.length > 0 ? {
|
|
708
|
+
retryReferences
|
|
709
|
+
} : {})
|
|
710
|
+
});
|
|
711
|
+
settled = {
|
|
712
|
+
outcome,
|
|
713
|
+
action,
|
|
714
|
+
transition,
|
|
715
|
+
attempts,
|
|
716
|
+
settledAt: stepSettledAt
|
|
717
|
+
};
|
|
718
|
+
} catch (error) {
|
|
719
|
+
this.#settleThrown({
|
|
720
|
+
type: 'step:settled',
|
|
721
|
+
...stepFrame,
|
|
722
|
+
successful: false,
|
|
723
|
+
attempts: attempted,
|
|
724
|
+
error
|
|
725
|
+
});
|
|
726
|
+
throw error;
|
|
727
|
+
}
|
|
728
|
+
if (this.#events.hasObservers) {
|
|
729
|
+
this.#events.emit({
|
|
730
|
+
type: 'step:settled',
|
|
731
|
+
...stepFrame,
|
|
732
|
+
successful: settled.outcome.successful,
|
|
733
|
+
attempts: settled.attempts
|
|
734
|
+
}, settled.settledAt);
|
|
735
|
+
}
|
|
736
|
+
return settled;
|
|
737
|
+
}
|
|
738
|
+
|
|
606
739
|
/**
|
|
607
740
|
* Assembles the run's result from how it ended, resolving the workflow's
|
|
608
741
|
* `outputs` against the final state (unless it transferred) and stamping
|
|
@@ -645,13 +778,6 @@ class WorkflowExecutor {
|
|
|
645
778
|
status: outcome.status,
|
|
646
779
|
settledStatus: outcome.status
|
|
647
780
|
};
|
|
648
|
-
this.#events?.emit({
|
|
649
|
-
type: 'workflow-settled',
|
|
650
|
-
...invocation.frame,
|
|
651
|
-
status: result.status,
|
|
652
|
-
settledStatus: result.settledStatus,
|
|
653
|
-
outputs: result.outputs
|
|
654
|
-
}, settledAt);
|
|
655
781
|
return result;
|
|
656
782
|
}
|
|
657
783
|
|
|
@@ -721,26 +847,26 @@ class WorkflowExecutor {
|
|
|
721
847
|
}
|
|
722
848
|
|
|
723
849
|
/**
|
|
724
|
-
* Wraps a step-attempt thunk with the events of an attempt: `step
|
|
725
|
-
* as it begins, then a `criterion
|
|
850
|
+
* Wraps a step-attempt thunk with the events of an attempt: `step:attempt`
|
|
851
|
+
* as it begins, then a `criterion:evaluated` for each criterion it
|
|
726
852
|
* evaluated, success criteria first.
|
|
727
853
|
*/
|
|
728
854
|
#observedAttempt(runAttempt, stepFrame) {
|
|
729
|
-
|
|
730
|
-
if (events === undefined) return runAttempt;
|
|
855
|
+
// observers read per attempt, so hooks added mid-step apply from its next one
|
|
731
856
|
return async attempt => {
|
|
732
857
|
const attemptFrame = {
|
|
733
858
|
...stepFrame,
|
|
734
859
|
attempt
|
|
735
860
|
};
|
|
736
|
-
events.emit({
|
|
737
|
-
type: 'step
|
|
861
|
+
if (this.#events.hasObservers) this.#events.emit({
|
|
862
|
+
type: 'step:attempt',
|
|
738
863
|
...attemptFrame
|
|
739
864
|
});
|
|
740
865
|
const outcome = await runAttempt();
|
|
866
|
+
if (!this.#events.hasObservers) return outcome;
|
|
741
867
|
for (const criterion of outcome.successCriteria) {
|
|
742
|
-
events.emit({
|
|
743
|
-
type: 'criterion
|
|
868
|
+
this.#events.emit({
|
|
869
|
+
type: 'criterion:evaluated',
|
|
744
870
|
...attemptFrame,
|
|
745
871
|
kind: 'success',
|
|
746
872
|
criterion,
|
|
@@ -748,8 +874,8 @@ class WorkflowExecutor {
|
|
|
748
874
|
});
|
|
749
875
|
}
|
|
750
876
|
for (const criterion of outcome.actionCriteria) {
|
|
751
|
-
events.emit({
|
|
752
|
-
type: 'criterion
|
|
877
|
+
this.#events.emit({
|
|
878
|
+
type: 'criterion:evaluated',
|
|
753
879
|
...attemptFrame,
|
|
754
880
|
kind: 'action',
|
|
755
881
|
criterion,
|
|
@@ -841,11 +967,13 @@ class WorkflowExecutor {
|
|
|
841
967
|
kind: 'workflow',
|
|
842
968
|
id: reference
|
|
843
969
|
};
|
|
844
|
-
this.#events
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
970
|
+
if (this.#events.hasObservers) {
|
|
971
|
+
this.#events.emit({
|
|
972
|
+
type: 'retry:reference:start',
|
|
973
|
+
...referenceFrame,
|
|
974
|
+
location: invocation.document.locationOf(action)
|
|
975
|
+
});
|
|
976
|
+
}
|
|
849
977
|
const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry', inputs);
|
|
850
978
|
// the result's workflowId is the bare id the reference resolved to —
|
|
851
979
|
// the key run state is recorded under, whichever document owns it.
|
|
@@ -861,11 +989,13 @@ class WorkflowExecutor {
|
|
|
861
989
|
successful,
|
|
862
990
|
subWorkflow: result
|
|
863
991
|
});
|
|
864
|
-
this.#events
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
992
|
+
if (this.#events.hasObservers) {
|
|
993
|
+
this.#events.emit({
|
|
994
|
+
type: 'retry:reference:settled',
|
|
995
|
+
...referenceFrame,
|
|
996
|
+
successful
|
|
997
|
+
});
|
|
998
|
+
}
|
|
869
999
|
return;
|
|
870
1000
|
}
|
|
871
1001
|
const refStepId = (0, _apidomCore.toValue)(action.stepId);
|
|
@@ -881,11 +1011,13 @@ class WorkflowExecutor {
|
|
|
881
1011
|
kind: 'step',
|
|
882
1012
|
id: refStepId
|
|
883
1013
|
};
|
|
884
|
-
this.#events
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1014
|
+
if (this.#events.hasObservers) {
|
|
1015
|
+
this.#events.emit({
|
|
1016
|
+
type: 'retry:reference:start',
|
|
1017
|
+
...referenceFrame,
|
|
1018
|
+
location: invocation.document.locationOf(action)
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
889
1021
|
// the referenced step's attempt is observed like any other, under its
|
|
890
1022
|
// own stepId and with a count of its own.
|
|
891
1023
|
const refOutcome = await this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), {
|
|
@@ -901,11 +1033,13 @@ class WorkflowExecutor {
|
|
|
901
1033
|
subWorkflow: refSubWorkflows[0]
|
|
902
1034
|
} : {})
|
|
903
1035
|
});
|
|
904
|
-
this.#events
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1036
|
+
if (this.#events.hasObservers) {
|
|
1037
|
+
this.#events.emit({
|
|
1038
|
+
type: 'retry:reference:settled',
|
|
1039
|
+
...referenceFrame,
|
|
1040
|
+
successful: refOutcome.successful
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
909
1043
|
};
|
|
910
1044
|
}
|
|
911
1045
|
|
|
@@ -958,12 +1092,14 @@ class WorkflowExecutor {
|
|
|
958
1092
|
workflowId: dependency.locator.workflowId,
|
|
959
1093
|
documentURI: dependency.locator.document.uri
|
|
960
1094
|
};
|
|
961
|
-
this.#events
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1095
|
+
if (this.#events.hasObservers) {
|
|
1096
|
+
this.#events.emit({
|
|
1097
|
+
type: 'dependency:start',
|
|
1098
|
+
...frame,
|
|
1099
|
+
dependency: target,
|
|
1100
|
+
location: invocation.document.locationOf(dependency.entry)
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
967
1103
|
// a dependency already completed in this run is satisfied, not repeated: a
|
|
968
1104
|
// precondition holds once met, and a diamond (two dependents sharing one
|
|
969
1105
|
// dependency) must not duplicate its live side effects. Every dependent
|
|
@@ -986,13 +1122,15 @@ class WorkflowExecutor {
|
|
|
986
1122
|
inputs,
|
|
987
1123
|
outputs: result.outputs
|
|
988
1124
|
});
|
|
989
|
-
this.#events
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1125
|
+
if (this.#events.hasObservers) {
|
|
1126
|
+
this.#events.emit({
|
|
1127
|
+
type: 'dependency:settled',
|
|
1128
|
+
...frame,
|
|
1129
|
+
dependency: target,
|
|
1130
|
+
memoized: memoized !== undefined,
|
|
1131
|
+
settledStatus: result.settledStatus
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
996
1134
|
if (this.#settledFailed(result)) return results;
|
|
997
1135
|
|
|
998
1136
|
// only a dependency whose chain settled non-`failed` is remembered as
|
|
@@ -1356,17 +1494,21 @@ class WorkflowExecutor {
|
|
|
1356
1494
|
const cached = scope.workflows.get(qualifiedId);
|
|
1357
1495
|
if (cached !== undefined) return cached;
|
|
1358
1496
|
const location = locator.document.locationOf(extracted);
|
|
1359
|
-
this.#events
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1497
|
+
if (this.#events.hasObservers) {
|
|
1498
|
+
this.#events.emit({
|
|
1499
|
+
type: 'workflow:normalize:start',
|
|
1500
|
+
...frame,
|
|
1501
|
+
location
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1364
1504
|
const workflow = await this.#normalizer.normalize(extracted, locator.document);
|
|
1365
|
-
this.#events
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1505
|
+
if (this.#events.hasObservers) {
|
|
1506
|
+
this.#events.emit({
|
|
1507
|
+
type: 'workflow:normalize:settled',
|
|
1508
|
+
...frame,
|
|
1509
|
+
location
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1370
1512
|
scope.workflows.set(qualifiedId, workflow);
|
|
1371
1513
|
return workflow;
|
|
1372
1514
|
}
|