@usearazzo/runner 1.0.1-alpha.32 → 1.0.1-alpha.34
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 +29 -0
- package/README.md +10 -1
- package/dist/arazzo-runner.browser.js +1789 -403
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +18 -17
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/action/ActionResolver.cjs +13 -12
- package/src/action/ActionResolver.mjs +13 -12
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- package/src/criterion/CriterionEvaluator.cjs +13 -8
- package/src/criterion/CriterionEvaluator.mjs +13 -8
- package/src/criterion/SimpleCriterionEvaluator.cjs +5 -3
- package/src/criterion/SimpleCriterionEvaluator.mjs +6 -4
- package/src/document/APIDocument.cjs +53 -0
- package/src/document/APIDocument.mjs +53 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +66 -6
- package/src/executor/OpenAPIOperationExecutor.mjs +66 -6
- package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +1 -1
- package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +1 -1
- package/src/executor/StepExecutor.cjs +34 -15
- package/src/executor/StepExecutor.mjs +34 -15
- package/src/executor/StepRetryRunner.cjs +5 -3
- package/src/executor/StepRetryRunner.mjs +5 -3
- package/src/executor/StepTransitionInterpreter.cjs +1 -1
- package/src/executor/StepTransitionInterpreter.mjs +1 -1
- package/src/executor/WorkflowCallStack.cjs +1 -1
- package/src/executor/WorkflowCallStack.mjs +1 -1
- package/src/executor/WorkflowExecutor.cjs +277 -61
- package/src/executor/WorkflowExecutor.mjs +277 -61
- package/src/expression/RuntimeExpressionEvaluator.cjs +52 -9
- package/src/expression/RuntimeExpressionEvaluator.mjs +52 -9
- package/src/index.cjs +7 -0
- package/src/index.mjs +2 -0
- package/src/observability/ArazzoRunnerEvent.cjs +5 -0
- package/src/observability/ArazzoRunnerEvent.mjs +1 -0
- package/src/observability/DocumentRegistryEvent.cjs +5 -0
- package/src/observability/DocumentRegistryEvent.mjs +1 -0
- package/src/observability/EventChannel.cjs +96 -0
- package/src/observability/EventChannel.mjs +91 -0
- package/src/observability/OpenAPIOperationEvent.cjs +5 -0
- package/src/observability/OpenAPIOperationEvent.mjs +1 -0
- package/src/observability/Redactor.cjs +213 -0
- package/src/observability/Redactor.mjs +208 -0
- package/src/observability/WorkflowExecutionEvent.cjs +5 -0
- package/src/observability/WorkflowExecutionEvent.mjs +1 -0
- package/src/registry/DocumentRegistry.cjs +57 -11
- package/src/registry/DocumentRegistry.mjs +57 -11
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +21 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +22 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +33 -1
- package/src/registry/providers/DocumentRegistryProvider.mjs +33 -1
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +28 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +28 -5
- package/src/resolver/ArazzoValueResolver.cjs +6 -3
- package/src/resolver/ArazzoValueResolver.mjs +6 -3
- package/src/resolver/OpenAPIOperationParameterResolver.cjs +2 -2
- package/src/resolver/OpenAPIOperationParameterResolver.mjs +2 -2
- package/src/resolver/OutputResolver.cjs +10 -3
- package/src/resolver/OutputResolver.mjs +10 -3
- package/src/resolver/RequestBodyResolver.cjs +37 -17
- package/src/resolver/RequestBodyResolver.mjs +37 -17
- package/src/resolver/WorkflowParameterResolver.cjs +2 -2
- package/src/resolver/WorkflowParameterResolver.mjs +2 -2
- package/types/runner.d.ts +788 -41
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toValue } from '@speclynx/apidom-core';
|
|
2
2
|
import { isPlainObject } from 'ramda-adjunct';
|
|
3
|
+
import ShortUniqueId from 'short-unique-id';
|
|
3
4
|
import { isArrayElement, isObjectElement, isStringElement } from '@speclynx/apidom-datamodel';
|
|
4
5
|
import { isFailureActionElement, isParameterElement, isStepElement, isSuccessActionElement } from '@speclynx/apidom-ns-arazzo-1';
|
|
5
6
|
import RuntimeExpressionEvaluator from "../expression/RuntimeExpressionEvaluator.mjs";
|
|
@@ -16,6 +17,7 @@ import StepTransitionInterpreter, { actionTargets } from "./StepTransitionInterp
|
|
|
16
17
|
import ExecutionError from "../errors/ExecutionError.mjs";
|
|
17
18
|
import ResolverError from "../errors/ResolverError.mjs";
|
|
18
19
|
import { throwIfAborted } from "./abort.mjs";
|
|
20
|
+
import EventChannel from "../observability/EventChannel.mjs";
|
|
19
21
|
/**
|
|
20
22
|
* Options for the WorkflowExecutor.
|
|
21
23
|
* @public
|
|
@@ -103,6 +105,14 @@ export function settledResult(result) {
|
|
|
103
105
|
* travel together into everything it delegates to.
|
|
104
106
|
*/
|
|
105
107
|
|
|
108
|
+
/**
|
|
109
|
+
* What every event of one workflow invocation shares.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* What every step-scoped event of one step shares.
|
|
114
|
+
*/
|
|
115
|
+
|
|
106
116
|
/**
|
|
107
117
|
* Executes an Arazzo workflow: the stateful loop that turns "run one step" into
|
|
108
118
|
* "run a workflow".
|
|
@@ -148,6 +158,14 @@ class WorkflowExecutor {
|
|
|
148
158
|
static #DEFAULT_MAX_STEPS = 1000;
|
|
149
159
|
static #DEFAULT_MAX_WORKFLOW_DEPTH = 32;
|
|
150
160
|
static #DEFAULT_NOW = () => performance.now();
|
|
161
|
+
/**
|
|
162
|
+
* Generates each run's `runId`: random rather than counted, so the events
|
|
163
|
+
* of runs in different processes stay apart once collected in one place.
|
|
164
|
+
* It needs no Web Crypto, which browsers offer only on secure pages.
|
|
165
|
+
*/
|
|
166
|
+
static #RUN_IDS = new ShortUniqueId({
|
|
167
|
+
length: 12
|
|
168
|
+
});
|
|
151
169
|
static #EXECUTE_OPTION_KEYS = new Set(['inputs', 'executeOptions', 'dependencyInputs', 'runDependencies', 'signal']);
|
|
152
170
|
#document;
|
|
153
171
|
#registry;
|
|
@@ -162,6 +180,7 @@ class WorkflowExecutor {
|
|
|
162
180
|
#retryRunner;
|
|
163
181
|
#interpreter = new StepTransitionInterpreter();
|
|
164
182
|
#workflowLocatorNormalizer;
|
|
183
|
+
#events;
|
|
165
184
|
constructor(options) {
|
|
166
185
|
this.#document = options.document;
|
|
167
186
|
this.#registry = options.registry;
|
|
@@ -170,6 +189,10 @@ class WorkflowExecutor {
|
|
|
170
189
|
this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
|
|
171
190
|
this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
|
|
172
191
|
this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
|
|
192
|
+
this.#events = EventChannel.open({
|
|
193
|
+
observer: options.observer,
|
|
194
|
+
now: this.#now
|
|
195
|
+
});
|
|
173
196
|
this.#stepExecutor = options.stepExecutor;
|
|
174
197
|
this.#retryRunner = new StepRetryRunner({
|
|
175
198
|
sleep: options.sleep
|
|
@@ -193,7 +216,9 @@ class WorkflowExecutor {
|
|
|
193
216
|
signal
|
|
194
217
|
} = options;
|
|
195
218
|
const executeOptions = this.#executeOptionsByName(options.executeOptions ?? {});
|
|
219
|
+
const runId = `run-${WorkflowExecutor.#RUN_IDS.randomUUID()}`;
|
|
196
220
|
const scope = {
|
|
221
|
+
runId,
|
|
197
222
|
// the signal is put into every step's opaque bag, because that bag is
|
|
198
223
|
// how anything reaches the transport: the executor's own checks stop the
|
|
199
224
|
// run at the next boundary, and this is what cancels the request already
|
|
@@ -202,7 +227,9 @@ class WorkflowExecutor {
|
|
|
202
227
|
// leave the run walking on.
|
|
203
228
|
executeOptions: (locator, step) => ({
|
|
204
229
|
...this.#executeOptionsFor(executeOptions, locator, step),
|
|
205
|
-
signal
|
|
230
|
+
signal,
|
|
231
|
+
// set over any entry's own, like the signal: it names this run.
|
|
232
|
+
runId
|
|
206
233
|
}),
|
|
207
234
|
dependencyInputs: options.dependencyInputs ?? {},
|
|
208
235
|
runDependencies: options.runDependencies ?? true,
|
|
@@ -320,7 +347,22 @@ class WorkflowExecutor {
|
|
|
320
347
|
workflowId,
|
|
321
348
|
callStack: nested
|
|
322
349
|
});
|
|
323
|
-
const
|
|
350
|
+
const frame = {
|
|
351
|
+
runId: scope.runId,
|
|
352
|
+
workflowId,
|
|
353
|
+
path: nested.path
|
|
354
|
+
};
|
|
355
|
+
// extracted before `workflow-start`: a workflow its document does not
|
|
356
|
+
// define never starts, and the event can say where the one it runs is.
|
|
357
|
+
const extracted = this.#extractWorkflow(locator);
|
|
358
|
+
// emitted before normalization, so its events nest inside this workflow's.
|
|
359
|
+
this.#events?.emit({
|
|
360
|
+
type: 'workflow-start',
|
|
361
|
+
...frame,
|
|
362
|
+
via,
|
|
363
|
+
location: locator.document.locationOf(extracted)
|
|
364
|
+
}, startedAt);
|
|
365
|
+
const workflow = await this.#resolveWorkflow(locator, extracted, scope, frame);
|
|
324
366
|
const state = new WorkflowExecutionState({
|
|
325
367
|
inputs
|
|
326
368
|
});
|
|
@@ -329,7 +371,8 @@ class WorkflowExecutor {
|
|
|
329
371
|
document: locator.document,
|
|
330
372
|
state,
|
|
331
373
|
callStack: nested,
|
|
332
|
-
via
|
|
374
|
+
via,
|
|
375
|
+
frame
|
|
333
376
|
};
|
|
334
377
|
|
|
335
378
|
// validated before any prerequisite runs: a malformed `steps` is an
|
|
@@ -392,7 +435,16 @@ class WorkflowExecutor {
|
|
|
392
435
|
// separate from `subWorkflows` because a reference belongs to the retry
|
|
393
436
|
// that invoked it, not to the step's own target.
|
|
394
437
|
const retryReferences = [];
|
|
395
|
-
const
|
|
438
|
+
const stepFrame = {
|
|
439
|
+
...frame,
|
|
440
|
+
stepId
|
|
441
|
+
};
|
|
442
|
+
this.#events?.emit({
|
|
443
|
+
type: 'step-start',
|
|
444
|
+
...stepFrame,
|
|
445
|
+
location: invocation.document.locationOf(step)
|
|
446
|
+
}, stepStartedAt);
|
|
447
|
+
const attempt = this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(step, stepId, invocation, scope, subWorkflows), stepFrame), invocation, scope, stepId);
|
|
396
448
|
|
|
397
449
|
// the retry runner settles any `retry` actions, so `action` is the terminal
|
|
398
450
|
// action a retry chain resolved to and `attempts` is how many times the step
|
|
@@ -405,15 +457,51 @@ class WorkflowExecutor {
|
|
|
405
457
|
stepId,
|
|
406
458
|
workflowId,
|
|
407
459
|
signal: scope.signal,
|
|
408
|
-
runReference: this.#retryReference(steps,
|
|
460
|
+
runReference: this.#retryReference(steps, stepFrame, invocation, scope, retryReferences),
|
|
461
|
+
onRetry: (retry, delayMs, attempt) => {
|
|
462
|
+
const decided = {
|
|
463
|
+
...stepFrame,
|
|
464
|
+
attempt
|
|
465
|
+
};
|
|
466
|
+
this.#events?.emit({
|
|
467
|
+
type: 'action-selected',
|
|
468
|
+
...decided,
|
|
469
|
+
action: retry,
|
|
470
|
+
transition: {
|
|
471
|
+
kind: 'retry'
|
|
472
|
+
},
|
|
473
|
+
location: invocation.document.locationOf(retry)
|
|
474
|
+
});
|
|
475
|
+
if (delayMs > 0) {
|
|
476
|
+
this.#events?.emit({
|
|
477
|
+
type: 'retry-wait',
|
|
478
|
+
...decided,
|
|
479
|
+
delayMs
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
const transition = this.#interpreter.interpret(action, outcome.successful, {
|
|
485
|
+
workflowId,
|
|
486
|
+
stepId
|
|
487
|
+
});
|
|
488
|
+
this.#events?.emit({
|
|
489
|
+
type: 'action-selected',
|
|
490
|
+
...stepFrame,
|
|
491
|
+
attempt: attempts,
|
|
492
|
+
action,
|
|
493
|
+
transition,
|
|
494
|
+
location: action === undefined ? undefined : invocation.document.locationOf(action)
|
|
409
495
|
});
|
|
410
496
|
state.setStepOutputs(outcome.stepId, outcome.outputs);
|
|
497
|
+
const stepSettledAt = this.#now();
|
|
411
498
|
trace.push({
|
|
412
499
|
stepId: outcome.stepId,
|
|
500
|
+
location: invocation.document.locationOf(step),
|
|
413
501
|
successful: outcome.successful,
|
|
414
502
|
action,
|
|
415
503
|
attempts,
|
|
416
|
-
durationMs:
|
|
504
|
+
durationMs: stepSettledAt - stepStartedAt,
|
|
417
505
|
successCriteria: outcome.successCriteria,
|
|
418
506
|
actionCriteria: outcome.actionCriteria,
|
|
419
507
|
...(subWorkflows.length > 0 ? {
|
|
@@ -423,10 +511,12 @@ class WorkflowExecutor {
|
|
|
423
511
|
retryReferences
|
|
424
512
|
} : {})
|
|
425
513
|
});
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
514
|
+
this.#events?.emit({
|
|
515
|
+
type: 'step-settled',
|
|
516
|
+
...stepFrame,
|
|
517
|
+
successful: outcome.successful,
|
|
518
|
+
attempts
|
|
519
|
+
}, stepSettledAt);
|
|
430
520
|
switch (transition.kind) {
|
|
431
521
|
case 'next':
|
|
432
522
|
index += 1;
|
|
@@ -451,7 +541,7 @@ class WorkflowExecutor {
|
|
|
451
541
|
stepId,
|
|
452
542
|
callStack: nested
|
|
453
543
|
});
|
|
454
|
-
const transferredTo = await this.#runReferencedWorkflow(transition.workflowId, stepId, invocation, scope, 'goto', this.#actionInputs(action?.parameters, outcome, invocation, stepId));
|
|
544
|
+
const transferredTo = await this.#runReferencedWorkflow(transition.workflowId, stepId, invocation, scope, 'goto', await this.#actionInputs(action?.parameters, outcome, invocation, stepId));
|
|
455
545
|
runOutcome = {
|
|
456
546
|
kind: 'transferred',
|
|
457
547
|
transferredTo
|
|
@@ -472,7 +562,7 @@ class WorkflowExecutor {
|
|
|
472
562
|
break stepLoop;
|
|
473
563
|
default:
|
|
474
564
|
{
|
|
475
|
-
// exhaustiveness guard: a
|
|
565
|
+
// exhaustiveness guard: a StepTransition kind added above without a case
|
|
476
566
|
// here would otherwise fall through silently instead of failing
|
|
477
567
|
// loudly — `transition` is provably `never` once every kind above
|
|
478
568
|
// has its own case, which TypeScript checks at compile time.
|
|
@@ -515,34 +605,40 @@ class WorkflowExecutor {
|
|
|
515
605
|
* {@link WorkflowExecutor.#validateWorkflowOutputsShape} already checked
|
|
516
606
|
* the shape up front, independent of resolving it.
|
|
517
607
|
*/
|
|
518
|
-
#result(invocation, workflow, steps, outcome, dependencies, startedAt) {
|
|
608
|
+
async #result(invocation, workflow, steps, outcome, dependencies, startedAt) {
|
|
609
|
+
const settledAt = this.#now();
|
|
519
610
|
const shared = {
|
|
520
611
|
workflowId: invocation.workflowId,
|
|
521
612
|
steps,
|
|
522
|
-
durationMs:
|
|
613
|
+
durationMs: settledAt - startedAt,
|
|
523
614
|
...(dependencies.length > 0 ? {
|
|
524
615
|
dependencies
|
|
525
616
|
} : {})
|
|
526
617
|
};
|
|
527
|
-
|
|
528
|
-
return {
|
|
529
|
-
...shared,
|
|
530
|
-
outputs: {},
|
|
531
|
-
status: 'transferred',
|
|
532
|
-
// computed once, here, rather than left for a caller to chase via
|
|
533
|
-
// `settledResult` — `transferredTo` already carries its own
|
|
534
|
-
// `settledStatus`, itself computed the same way when it was built,
|
|
535
|
-
// so this is O(1) per hop rather than a walk of the whole chain.
|
|
536
|
-
settledStatus: outcome.transferredTo.settledStatus,
|
|
537
|
-
transferredTo: outcome.transferredTo
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
return {
|
|
618
|
+
const result = outcome.kind === 'transferred' ? {
|
|
541
619
|
...shared,
|
|
542
|
-
outputs:
|
|
620
|
+
outputs: {},
|
|
621
|
+
status: 'transferred',
|
|
622
|
+
// computed once, here, rather than left for a caller to chase via
|
|
623
|
+
// `settledResult` — `transferredTo` already carries its own
|
|
624
|
+
// `settledStatus`, itself computed the same way when it was built,
|
|
625
|
+
// so this is O(1) per hop rather than a walk of the whole chain.
|
|
626
|
+
settledStatus: outcome.transferredTo.settledStatus,
|
|
627
|
+
transferredTo: outcome.transferredTo
|
|
628
|
+
} : {
|
|
629
|
+
...shared,
|
|
630
|
+
outputs: await this.#resolveWorkflowOutputs(workflow, invocation),
|
|
543
631
|
status: outcome.status,
|
|
544
632
|
settledStatus: outcome.status
|
|
545
633
|
};
|
|
634
|
+
this.#events?.emit({
|
|
635
|
+
type: 'workflow-settled',
|
|
636
|
+
...invocation.frame,
|
|
637
|
+
status: result.status,
|
|
638
|
+
settledStatus: result.settledStatus,
|
|
639
|
+
outputs: result.outputs
|
|
640
|
+
}, settledAt);
|
|
641
|
+
return result;
|
|
546
642
|
}
|
|
547
643
|
|
|
548
644
|
/**
|
|
@@ -590,7 +686,7 @@ class WorkflowExecutor {
|
|
|
590
686
|
workflowId,
|
|
591
687
|
callStack
|
|
592
688
|
} = invocation;
|
|
593
|
-
return async
|
|
689
|
+
return async attempt => {
|
|
594
690
|
throwIfAborted(scope.signal, {
|
|
595
691
|
workflowId,
|
|
596
692
|
stepId,
|
|
@@ -598,7 +694,7 @@ class WorkflowExecutor {
|
|
|
598
694
|
});
|
|
599
695
|
this.#chargeBudget(scope, invocation, stepId);
|
|
600
696
|
try {
|
|
601
|
-
return await runAttempt();
|
|
697
|
+
return await runAttempt(attempt);
|
|
602
698
|
} catch (error) {
|
|
603
699
|
throwIfAborted(scope.signal, {
|
|
604
700
|
workflowId,
|
|
@@ -610,6 +706,46 @@ class WorkflowExecutor {
|
|
|
610
706
|
};
|
|
611
707
|
}
|
|
612
708
|
|
|
709
|
+
/**
|
|
710
|
+
* Wraps a step-attempt thunk with the events of an attempt: `step-attempt`
|
|
711
|
+
* as it begins, then a `criterion-evaluated` for each criterion it
|
|
712
|
+
* evaluated, success criteria first.
|
|
713
|
+
*/
|
|
714
|
+
#observedAttempt(runAttempt, stepFrame) {
|
|
715
|
+
const events = this.#events;
|
|
716
|
+
if (events === undefined) return runAttempt;
|
|
717
|
+
return async attempt => {
|
|
718
|
+
const attemptFrame = {
|
|
719
|
+
...stepFrame,
|
|
720
|
+
attempt
|
|
721
|
+
};
|
|
722
|
+
events.emit({
|
|
723
|
+
type: 'step-attempt',
|
|
724
|
+
...attemptFrame
|
|
725
|
+
});
|
|
726
|
+
const outcome = await runAttempt();
|
|
727
|
+
for (const criterion of outcome.successCriteria) {
|
|
728
|
+
events.emit({
|
|
729
|
+
type: 'criterion-evaluated',
|
|
730
|
+
...attemptFrame,
|
|
731
|
+
kind: 'success',
|
|
732
|
+
criterion,
|
|
733
|
+
location: criterion.location
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
for (const criterion of outcome.actionCriteria) {
|
|
737
|
+
events.emit({
|
|
738
|
+
type: 'criterion-evaluated',
|
|
739
|
+
...attemptFrame,
|
|
740
|
+
kind: 'action',
|
|
741
|
+
criterion,
|
|
742
|
+
location: criterion.location
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
return outcome;
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
613
749
|
/**
|
|
614
750
|
* Builds the {@link StepRetryRunContext.runReference} callback a `retry`
|
|
615
751
|
* action's `stepId` / `workflowId` reference is run through.
|
|
@@ -653,13 +789,16 @@ class WorkflowExecutor {
|
|
|
653
789
|
* reference's *completion*, not its success, and a retry that turns out
|
|
654
790
|
* futile is bounded by `retryLimit` regardless.
|
|
655
791
|
*/
|
|
656
|
-
#retryReference(steps,
|
|
792
|
+
#retryReference(steps, stepFrame, invocation, scope, retryReferences) {
|
|
657
793
|
const {
|
|
658
794
|
workflowId,
|
|
659
795
|
state,
|
|
660
796
|
callStack
|
|
661
797
|
} = invocation;
|
|
662
|
-
|
|
798
|
+
const {
|
|
799
|
+
stepId
|
|
800
|
+
} = stepFrame;
|
|
801
|
+
return async (action, outcome, attempt) => {
|
|
663
802
|
throwIfAborted(scope.signal, {
|
|
664
803
|
workflowId,
|
|
665
804
|
stepId,
|
|
@@ -680,8 +819,19 @@ class WorkflowExecutor {
|
|
|
680
819
|
const reference = toValue(action.workflowId);
|
|
681
820
|
// resolved before the budget is charged, so an authoring error in them
|
|
682
821
|
// costs no budget unit.
|
|
683
|
-
const inputs = this.#actionInputs(action.parameters, outcome, invocation, stepId);
|
|
822
|
+
const inputs = await this.#actionInputs(action.parameters, outcome, invocation, stepId);
|
|
684
823
|
this.#chargeBudget(scope, invocation, stepId);
|
|
824
|
+
const referenceFrame = {
|
|
825
|
+
...stepFrame,
|
|
826
|
+
attempt,
|
|
827
|
+
kind: 'workflow',
|
|
828
|
+
id: reference
|
|
829
|
+
};
|
|
830
|
+
this.#events?.emit({
|
|
831
|
+
type: 'retry-reference-start',
|
|
832
|
+
...referenceFrame,
|
|
833
|
+
location: invocation.document.locationOf(action)
|
|
834
|
+
});
|
|
685
835
|
const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry', inputs);
|
|
686
836
|
// the result's workflowId is the bare id the reference resolved to —
|
|
687
837
|
// the key run state is recorded under, whichever document owns it.
|
|
@@ -690,12 +840,18 @@ class WorkflowExecutor {
|
|
|
690
840
|
inputs: action.hasKey('parameters') ? inputs : state.getWorkflow(refId)?.inputs ?? {},
|
|
691
841
|
outputs: result.outputs
|
|
692
842
|
});
|
|
843
|
+
const successful = !this.#settledFailed(result);
|
|
693
844
|
retryReferences.push({
|
|
694
845
|
kind: 'workflow',
|
|
695
846
|
id: reference,
|
|
696
|
-
successful
|
|
847
|
+
successful,
|
|
697
848
|
subWorkflow: result
|
|
698
849
|
});
|
|
850
|
+
this.#events?.emit({
|
|
851
|
+
type: 'retry-reference-settled',
|
|
852
|
+
...referenceFrame,
|
|
853
|
+
successful
|
|
854
|
+
});
|
|
699
855
|
return;
|
|
700
856
|
}
|
|
701
857
|
const refStepId = toValue(action.stepId);
|
|
@@ -705,7 +861,23 @@ class WorkflowExecutor {
|
|
|
705
861
|
});
|
|
706
862
|
const refStep = steps[refIndex];
|
|
707
863
|
const refSubWorkflows = [];
|
|
708
|
-
const
|
|
864
|
+
const referenceFrame = {
|
|
865
|
+
...stepFrame,
|
|
866
|
+
attempt,
|
|
867
|
+
kind: 'step',
|
|
868
|
+
id: refStepId
|
|
869
|
+
};
|
|
870
|
+
this.#events?.emit({
|
|
871
|
+
type: 'retry-reference-start',
|
|
872
|
+
...referenceFrame,
|
|
873
|
+
location: invocation.document.locationOf(action)
|
|
874
|
+
});
|
|
875
|
+
// the referenced step's attempt is observed like any other, under its
|
|
876
|
+
// own stepId and with a count of its own.
|
|
877
|
+
const refOutcome = await this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), {
|
|
878
|
+
...stepFrame,
|
|
879
|
+
stepId: refStepId
|
|
880
|
+
}), invocation, scope, refStepId)(1);
|
|
709
881
|
state.setStepOutputs(refOutcome.stepId, refOutcome.outputs);
|
|
710
882
|
retryReferences.push({
|
|
711
883
|
kind: 'step',
|
|
@@ -715,6 +887,11 @@ class WorkflowExecutor {
|
|
|
715
887
|
subWorkflow: refSubWorkflows[0]
|
|
716
888
|
} : {})
|
|
717
889
|
});
|
|
890
|
+
this.#events?.emit({
|
|
891
|
+
type: 'retry-reference-settled',
|
|
892
|
+
...referenceFrame,
|
|
893
|
+
successful: refOutcome.successful
|
|
894
|
+
});
|
|
718
895
|
};
|
|
719
896
|
}
|
|
720
897
|
|
|
@@ -756,9 +933,23 @@ class WorkflowExecutor {
|
|
|
756
933
|
// found halfway down the list would otherwise be raised only after earlier
|
|
757
934
|
// prerequisites had already fired live requests.
|
|
758
935
|
const dependencyRefs = await this.#dependencyRefs(workflow, invocation);
|
|
936
|
+
const {
|
|
937
|
+
frame
|
|
938
|
+
} = invocation;
|
|
759
939
|
const results = [];
|
|
760
940
|
for (const dependency of dependencyRefs) {
|
|
761
941
|
const qualifiedId = this.#qualifiedId(dependency.locator);
|
|
942
|
+
const target = {
|
|
943
|
+
reference: dependency.inputsKey,
|
|
944
|
+
workflowId: dependency.locator.workflowId,
|
|
945
|
+
documentURI: dependency.locator.document.uri
|
|
946
|
+
};
|
|
947
|
+
this.#events?.emit({
|
|
948
|
+
type: 'dependency-start',
|
|
949
|
+
...frame,
|
|
950
|
+
dependency: target,
|
|
951
|
+
location: invocation.document.locationOf(dependency.entry)
|
|
952
|
+
});
|
|
762
953
|
// a dependency already completed in this run is satisfied, not repeated: a
|
|
763
954
|
// precondition holds once met, and a diamond (two dependents sharing one
|
|
764
955
|
// dependency) must not duplicate its live side effects. Every dependent
|
|
@@ -781,6 +972,13 @@ class WorkflowExecutor {
|
|
|
781
972
|
inputs,
|
|
782
973
|
outputs: result.outputs
|
|
783
974
|
});
|
|
975
|
+
this.#events?.emit({
|
|
976
|
+
type: 'dependency-settled',
|
|
977
|
+
...frame,
|
|
978
|
+
dependency: target,
|
|
979
|
+
memoized: memoized !== undefined,
|
|
980
|
+
settledStatus: result.settledStatus
|
|
981
|
+
});
|
|
784
982
|
if (this.#settledFailed(result)) return results;
|
|
785
983
|
|
|
786
984
|
// only a dependency whose chain settled non-`failed` is remembered as
|
|
@@ -822,23 +1020,25 @@ class WorkflowExecutor {
|
|
|
822
1020
|
reason: ExecutionError.MalformedDependsOn
|
|
823
1021
|
});
|
|
824
1022
|
}
|
|
825
|
-
const
|
|
1023
|
+
const entries = [...dependsOn].map((entry, index) => {
|
|
826
1024
|
if (!isStringElement(entry)) {
|
|
827
1025
|
throw new ExecutionError(`workflow "${workflowId}" has a non-string entry at dependsOn[${index}]`, {
|
|
828
1026
|
workflowId,
|
|
829
1027
|
reason: ExecutionError.MalformedDependsOn
|
|
830
1028
|
});
|
|
831
1029
|
}
|
|
832
|
-
return
|
|
1030
|
+
return entry;
|
|
833
1031
|
});
|
|
834
1032
|
const refs = [];
|
|
835
|
-
for (const
|
|
1033
|
+
for (const entry of entries) {
|
|
1034
|
+
const reference = toValue(entry);
|
|
836
1035
|
const locator = await this.#workflowLocatorNormalizer.normalize(reference, document, {
|
|
837
1036
|
workflowId
|
|
838
1037
|
});
|
|
839
1038
|
refs.push({
|
|
840
1039
|
locator,
|
|
841
|
-
inputsKey: reference
|
|
1040
|
+
inputsKey: reference,
|
|
1041
|
+
entry
|
|
842
1042
|
});
|
|
843
1043
|
}
|
|
844
1044
|
return refs;
|
|
@@ -912,7 +1112,7 @@ class WorkflowExecutor {
|
|
|
912
1112
|
// sees the same (usually absent) value on every attempt, not the
|
|
913
1113
|
// previous attempt's own result.
|
|
914
1114
|
const preContext = this.#inputContext(state, subWorkflowId, priorWorkflowEntry);
|
|
915
|
-
const inputs = this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression, document), stepScope);
|
|
1115
|
+
const inputs = await this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression, document), stepScope);
|
|
916
1116
|
const result = await this.#run(locator, inputs, scope, callStack, 'step');
|
|
917
1117
|
subWorkflows.push(result);
|
|
918
1118
|
state.setWorkflow(subWorkflowId, {
|
|
@@ -935,7 +1135,7 @@ class WorkflowExecutor {
|
|
|
935
1135
|
workflowId: subWorkflowId
|
|
936
1136
|
}
|
|
937
1137
|
};
|
|
938
|
-
const outputs = this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(context, expression, document), stepScope);
|
|
1138
|
+
const outputs = await this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(context, expression, document), stepScope);
|
|
939
1139
|
// an `end`ed sub-workflow returned to its caller with outputs, so it took
|
|
940
1140
|
// the success path like a completed one; only a chain settling `failed` is
|
|
941
1141
|
// a failure — a sub-workflow that transferred is judged by where its
|
|
@@ -950,12 +1150,12 @@ class WorkflowExecutor {
|
|
|
950
1150
|
// evaluated by the parent document's step executor — only the sub-run
|
|
951
1151
|
// itself switched documents.
|
|
952
1152
|
const stepExecutor = this.#stepExecutor.forDocument(document);
|
|
953
|
-
const successCriteria = stepExecutor.evaluateCriteria(step, context, workflowId);
|
|
1153
|
+
const successCriteria = await stepExecutor.evaluateCriteria(step, context, workflowId);
|
|
954
1154
|
const successful = !this.#settledFailed(result) && successCriteria.every(criterion => criterion.met);
|
|
955
1155
|
const {
|
|
956
1156
|
matchedActions,
|
|
957
1157
|
actionCriteria
|
|
958
|
-
} = stepExecutor.selectActions(step, successful, context, workflowId);
|
|
1158
|
+
} = await stepExecutor.selectActions(step, successful, context, workflowId);
|
|
959
1159
|
return {
|
|
960
1160
|
stepId,
|
|
961
1161
|
successful,
|
|
@@ -1113,30 +1313,46 @@ class WorkflowExecutor {
|
|
|
1113
1313
|
}
|
|
1114
1314
|
|
|
1115
1315
|
/**
|
|
1116
|
-
* Extracts
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
* missing id itself.
|
|
1316
|
+
* Extracts the workflow a locator names. A workflow its document does not
|
|
1317
|
+
* define is the executor-level `workflow-not-found` authoring error, raised
|
|
1318
|
+
* here rather than leaking the extractor's `ExtractionError`. Only the root
|
|
1319
|
+
* {@link WorkflowExecutor.execute} id reaches this check unvalidated — every
|
|
1320
|
+
* reference position goes through the locator normalizer, which already
|
|
1321
|
+
* rejects a missing workflow with the referencing context attached — so the
|
|
1322
|
+
* error's `workflowId` is the missing id itself.
|
|
1124
1323
|
*/
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
} = locator;
|
|
1130
|
-
const qualifiedId = this.#qualifiedId(locator);
|
|
1131
|
-
const cached = scope.workflows.get(qualifiedId);
|
|
1132
|
-
if (cached !== undefined) return cached;
|
|
1324
|
+
#extractWorkflow({
|
|
1325
|
+
document,
|
|
1326
|
+
workflowId
|
|
1327
|
+
}) {
|
|
1133
1328
|
if (!document.workflowIndex.has(workflowId)) {
|
|
1134
1329
|
throw new ExecutionError(`workflow "${workflowId}" not found in Arazzo document at "${document.uri}"`, {
|
|
1135
1330
|
workflowId,
|
|
1136
1331
|
reason: ExecutionError.WorkflowNotFound
|
|
1137
1332
|
});
|
|
1138
1333
|
}
|
|
1139
|
-
|
|
1334
|
+
return this.#extractor.extract(document, workflowId);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Normalizes an extracted workflow, once per run for each workflow.
|
|
1339
|
+
*/
|
|
1340
|
+
async #resolveWorkflow(locator, extracted, scope, frame) {
|
|
1341
|
+
const qualifiedId = this.#qualifiedId(locator);
|
|
1342
|
+
const cached = scope.workflows.get(qualifiedId);
|
|
1343
|
+
if (cached !== undefined) return cached;
|
|
1344
|
+
const location = locator.document.locationOf(extracted);
|
|
1345
|
+
this.#events?.emit({
|
|
1346
|
+
type: 'workflow-normalize-start',
|
|
1347
|
+
...frame,
|
|
1348
|
+
location
|
|
1349
|
+
});
|
|
1350
|
+
const workflow = await this.#normalizer.normalize(extracted, locator.document);
|
|
1351
|
+
this.#events?.emit({
|
|
1352
|
+
type: 'workflow-normalize-settled',
|
|
1353
|
+
...frame,
|
|
1354
|
+
location
|
|
1355
|
+
});
|
|
1140
1356
|
scope.workflows.set(qualifiedId, workflow);
|
|
1141
1357
|
return workflow;
|
|
1142
1358
|
}
|