@usearazzo/runner 1.0.1-alpha.33 → 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 +8 -0
- package/README.md +10 -1
- package/dist/arazzo-runner.browser.js +1112 -231
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +16 -15
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- 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/StepExecutor.cjs +16 -2
- package/src/executor/StepExecutor.mjs +16 -2
- 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 +269 -53
- package/src/executor/WorkflowExecutor.mjs +269 -53
- 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 +22 -3
- package/src/registry/DocumentRegistry.mjs +22 -3
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
- package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
- package/types/runner.d.ts +705 -5
|
@@ -100,7 +100,8 @@ class StepRetryRunner {
|
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Runs `attempt` until the step succeeds, a terminal failure action is reached,
|
|
103
|
-
* or its retries are exhausted.
|
|
103
|
+
* or its retries are exhausted. Each call is given its attempt number,
|
|
104
|
+
* starting at 1.
|
|
104
105
|
*/
|
|
105
106
|
async run(attempt, context) {
|
|
106
107
|
// attempts already spent on each retry action, keyed by the action element.
|
|
@@ -114,7 +115,7 @@ class StepRetryRunner {
|
|
|
114
115
|
const retriesSpent = new Map();
|
|
115
116
|
let attempts = 0;
|
|
116
117
|
for (;;) {
|
|
117
|
-
const outcome = await attempt();
|
|
118
|
+
const outcome = await attempt(attempts + 1);
|
|
118
119
|
attempts += 1;
|
|
119
120
|
if (outcome.successful) {
|
|
120
121
|
return {
|
|
@@ -148,8 +149,9 @@ class StepRetryRunner {
|
|
|
148
149
|
// sleep(0) for immediate retries, and never hand a custom sleep a
|
|
149
150
|
// zero/negative/NaN value.
|
|
150
151
|
const delayMs = this.#retryAfterMs(action);
|
|
152
|
+
context.onRetry?.(action, delayMs, attempts);
|
|
151
153
|
if (delayMs > 0) await this.#sleep(delayMs, context.signal);
|
|
152
|
-
if (runReference !== undefined) await runReference(action, outcome);
|
|
154
|
+
if (runReference !== undefined) await runReference(action, outcome, attempts);
|
|
153
155
|
fired = true;
|
|
154
156
|
break;
|
|
155
157
|
}
|
|
@@ -90,7 +90,8 @@ class StepRetryRunner {
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Runs `attempt` until the step succeeds, a terminal failure action is reached,
|
|
93
|
-
* or its retries are exhausted.
|
|
93
|
+
* or its retries are exhausted. Each call is given its attempt number,
|
|
94
|
+
* starting at 1.
|
|
94
95
|
*/
|
|
95
96
|
async run(attempt, context) {
|
|
96
97
|
// attempts already spent on each retry action, keyed by the action element.
|
|
@@ -104,7 +105,7 @@ class StepRetryRunner {
|
|
|
104
105
|
const retriesSpent = new Map();
|
|
105
106
|
let attempts = 0;
|
|
106
107
|
for (;;) {
|
|
107
|
-
const outcome = await attempt();
|
|
108
|
+
const outcome = await attempt(attempts + 1);
|
|
108
109
|
attempts += 1;
|
|
109
110
|
if (outcome.successful) {
|
|
110
111
|
return {
|
|
@@ -138,8 +139,9 @@ class StepRetryRunner {
|
|
|
138
139
|
// sleep(0) for immediate retries, and never hand a custom sleep a
|
|
139
140
|
// zero/negative/NaN value.
|
|
140
141
|
const delayMs = this.#retryAfterMs(action);
|
|
142
|
+
context.onRetry?.(action, delayMs, attempts);
|
|
141
143
|
if (delayMs > 0) await this.#sleep(delayMs, context.signal);
|
|
142
|
-
if (runReference !== undefined) await runReference(action, outcome);
|
|
144
|
+
if (runReference !== undefined) await runReference(action, outcome, attempts);
|
|
143
145
|
fired = true;
|
|
144
146
|
break;
|
|
145
147
|
}
|
|
@@ -36,7 +36,7 @@ function actionTargets(action) {
|
|
|
36
36
|
* workflow; `transfer` hands control one-way to another workflow, which the
|
|
37
37
|
* caller's run then ends on; `end` stops the run with `status: ended`; `break`
|
|
38
38
|
* stops with `status: failed` (the failure default).
|
|
39
|
-
* @
|
|
39
|
+
* @public
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -28,7 +28,7 @@ export function actionTargets(action) {
|
|
|
28
28
|
* workflow; `transfer` hands control one-way to another workflow, which the
|
|
29
29
|
* caller's run then ends on; `end` stops the run with `status: ended`; `break`
|
|
30
30
|
* stops with `status: failed` (the failure default).
|
|
31
|
-
* @
|
|
31
|
+
* @public
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -15,7 +15,7 @@ var _ExecutionError = _interopRequireDefault(require("../errors/ExecutionError.c
|
|
|
15
15
|
* reference — or a `goto`'s one-way transfer to a `workflowId` — is a call
|
|
16
16
|
* cycle. `retry` and `goto` are grouped with `step` for that classification, not
|
|
17
17
|
* `dependsOn`: each is a call the current step makes, not a stated precondition.
|
|
18
|
-
* @
|
|
18
|
+
* @public
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -8,7 +8,7 @@ import ExecutionError from "../errors/ExecutionError.mjs";
|
|
|
8
8
|
* reference — or a `goto`'s one-way transfer to a `workflowId` — is a call
|
|
9
9
|
* cycle. `retry` and `goto` are grouped with `step` for that classification, not
|
|
10
10
|
* `dependsOn`: each is a call the current step makes, not a stated precondition.
|
|
11
|
-
* @
|
|
11
|
+
* @public
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* One workflow invocation in progress. Its identity is the (documentURI,
|
|
@@ -9,6 +9,7 @@ exports.default = void 0;
|
|
|
9
9
|
exports.settledResult = settledResult;
|
|
10
10
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
11
11
|
var _ramdaAdjunct = require("ramda-adjunct");
|
|
12
|
+
var _shortUniqueId = _interopRequireDefault(require("short-unique-id"));
|
|
12
13
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
13
14
|
var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
|
|
14
15
|
var _RuntimeExpressionEvaluator = _interopRequireDefault(require("../expression/RuntimeExpressionEvaluator.cjs"));
|
|
@@ -25,6 +26,7 @@ var _StepTransitionInterpreter = _interopRequireWildcard(require("./StepTransiti
|
|
|
25
26
|
var _ExecutionError = _interopRequireDefault(require("../errors/ExecutionError.cjs"));
|
|
26
27
|
var _ResolverError = _interopRequireDefault(require("../errors/ResolverError.cjs"));
|
|
27
28
|
var _abort = require("./abort.cjs");
|
|
29
|
+
var _EventChannel = _interopRequireDefault(require("../observability/EventChannel.cjs"));
|
|
28
30
|
/**
|
|
29
31
|
* Options for the WorkflowExecutor.
|
|
30
32
|
* @public
|
|
@@ -117,6 +119,14 @@ function settledResult(result) {
|
|
|
117
119
|
* travel together into everything it delegates to.
|
|
118
120
|
*/
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* What every event of one workflow invocation shares.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* What every step-scoped event of one step shares.
|
|
128
|
+
*/
|
|
129
|
+
|
|
120
130
|
/**
|
|
121
131
|
* Executes an Arazzo workflow: the stateful loop that turns "run one step" into
|
|
122
132
|
* "run a workflow".
|
|
@@ -162,6 +172,14 @@ class WorkflowExecutor {
|
|
|
162
172
|
static #DEFAULT_MAX_STEPS = 1000;
|
|
163
173
|
static #DEFAULT_MAX_WORKFLOW_DEPTH = 32;
|
|
164
174
|
static #DEFAULT_NOW = () => performance.now();
|
|
175
|
+
/**
|
|
176
|
+
* Generates each run's `runId`: random rather than counted, so the events
|
|
177
|
+
* of runs in different processes stay apart once collected in one place.
|
|
178
|
+
* It needs no Web Crypto, which browsers offer only on secure pages.
|
|
179
|
+
*/
|
|
180
|
+
static #RUN_IDS = new _shortUniqueId.default({
|
|
181
|
+
length: 12
|
|
182
|
+
});
|
|
165
183
|
static #EXECUTE_OPTION_KEYS = new Set(['inputs', 'executeOptions', 'dependencyInputs', 'runDependencies', 'signal']);
|
|
166
184
|
#document;
|
|
167
185
|
#registry;
|
|
@@ -176,6 +194,7 @@ class WorkflowExecutor {
|
|
|
176
194
|
#retryRunner;
|
|
177
195
|
#interpreter = new _StepTransitionInterpreter.default();
|
|
178
196
|
#workflowLocatorNormalizer;
|
|
197
|
+
#events;
|
|
179
198
|
constructor(options) {
|
|
180
199
|
this.#document = options.document;
|
|
181
200
|
this.#registry = options.registry;
|
|
@@ -184,6 +203,10 @@ class WorkflowExecutor {
|
|
|
184
203
|
this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
|
|
185
204
|
this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
|
|
186
205
|
this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
|
|
206
|
+
this.#events = _EventChannel.default.open({
|
|
207
|
+
observer: options.observer,
|
|
208
|
+
now: this.#now
|
|
209
|
+
});
|
|
187
210
|
this.#stepExecutor = options.stepExecutor;
|
|
188
211
|
this.#retryRunner = new _StepRetryRunner.default({
|
|
189
212
|
sleep: options.sleep
|
|
@@ -207,7 +230,9 @@ class WorkflowExecutor {
|
|
|
207
230
|
signal
|
|
208
231
|
} = options;
|
|
209
232
|
const executeOptions = this.#executeOptionsByName(options.executeOptions ?? {});
|
|
233
|
+
const runId = `run-${WorkflowExecutor.#RUN_IDS.randomUUID()}`;
|
|
210
234
|
const scope = {
|
|
235
|
+
runId,
|
|
211
236
|
// the signal is put into every step's opaque bag, because that bag is
|
|
212
237
|
// how anything reaches the transport: the executor's own checks stop the
|
|
213
238
|
// run at the next boundary, and this is what cancels the request already
|
|
@@ -216,7 +241,9 @@ class WorkflowExecutor {
|
|
|
216
241
|
// leave the run walking on.
|
|
217
242
|
executeOptions: (locator, step) => ({
|
|
218
243
|
...this.#executeOptionsFor(executeOptions, locator, step),
|
|
219
|
-
signal
|
|
244
|
+
signal,
|
|
245
|
+
// set over any entry's own, like the signal: it names this run.
|
|
246
|
+
runId
|
|
220
247
|
}),
|
|
221
248
|
dependencyInputs: options.dependencyInputs ?? {},
|
|
222
249
|
runDependencies: options.runDependencies ?? true,
|
|
@@ -334,7 +361,22 @@ class WorkflowExecutor {
|
|
|
334
361
|
workflowId,
|
|
335
362
|
callStack: nested
|
|
336
363
|
});
|
|
337
|
-
const
|
|
364
|
+
const frame = {
|
|
365
|
+
runId: scope.runId,
|
|
366
|
+
workflowId,
|
|
367
|
+
path: nested.path
|
|
368
|
+
};
|
|
369
|
+
// extracted before `workflow-start`: a workflow its document does not
|
|
370
|
+
// define never starts, and the event can say where the one it runs is.
|
|
371
|
+
const extracted = this.#extractWorkflow(locator);
|
|
372
|
+
// emitted before normalization, so its events nest inside this workflow's.
|
|
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);
|
|
338
380
|
const state = new _WorkflowExecutionState.default({
|
|
339
381
|
inputs
|
|
340
382
|
});
|
|
@@ -343,7 +385,8 @@ class WorkflowExecutor {
|
|
|
343
385
|
document: locator.document,
|
|
344
386
|
state,
|
|
345
387
|
callStack: nested,
|
|
346
|
-
via
|
|
388
|
+
via,
|
|
389
|
+
frame
|
|
347
390
|
};
|
|
348
391
|
|
|
349
392
|
// validated before any prerequisite runs: a malformed `steps` is an
|
|
@@ -406,7 +449,16 @@ class WorkflowExecutor {
|
|
|
406
449
|
// separate from `subWorkflows` because a reference belongs to the retry
|
|
407
450
|
// that invoked it, not to the step's own target.
|
|
408
451
|
const retryReferences = [];
|
|
409
|
-
const
|
|
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);
|
|
410
462
|
|
|
411
463
|
// the retry runner settles any `retry` actions, so `action` is the terminal
|
|
412
464
|
// action a retry chain resolved to and `attempts` is how many times the step
|
|
@@ -419,15 +471,51 @@ class WorkflowExecutor {
|
|
|
419
471
|
stepId,
|
|
420
472
|
workflowId,
|
|
421
473
|
signal: scope.signal,
|
|
422
|
-
runReference: this.#retryReference(steps,
|
|
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)
|
|
423
509
|
});
|
|
424
510
|
state.setStepOutputs(outcome.stepId, outcome.outputs);
|
|
511
|
+
const stepSettledAt = this.#now();
|
|
425
512
|
trace.push({
|
|
426
513
|
stepId: outcome.stepId,
|
|
514
|
+
location: invocation.document.locationOf(step),
|
|
427
515
|
successful: outcome.successful,
|
|
428
516
|
action,
|
|
429
517
|
attempts,
|
|
430
|
-
durationMs:
|
|
518
|
+
durationMs: stepSettledAt - stepStartedAt,
|
|
431
519
|
successCriteria: outcome.successCriteria,
|
|
432
520
|
actionCriteria: outcome.actionCriteria,
|
|
433
521
|
...(subWorkflows.length > 0 ? {
|
|
@@ -437,10 +525,12 @@ class WorkflowExecutor {
|
|
|
437
525
|
retryReferences
|
|
438
526
|
} : {})
|
|
439
527
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
528
|
+
this.#events?.emit({
|
|
529
|
+
type: 'step-settled',
|
|
530
|
+
...stepFrame,
|
|
531
|
+
successful: outcome.successful,
|
|
532
|
+
attempts
|
|
533
|
+
}, stepSettledAt);
|
|
444
534
|
switch (transition.kind) {
|
|
445
535
|
case 'next':
|
|
446
536
|
index += 1;
|
|
@@ -486,7 +576,7 @@ class WorkflowExecutor {
|
|
|
486
576
|
break stepLoop;
|
|
487
577
|
default:
|
|
488
578
|
{
|
|
489
|
-
// exhaustiveness guard: a
|
|
579
|
+
// exhaustiveness guard: a StepTransition kind added above without a case
|
|
490
580
|
// here would otherwise fall through silently instead of failing
|
|
491
581
|
// loudly — `transition` is provably `never` once every kind above
|
|
492
582
|
// has its own case, which TypeScript checks at compile time.
|
|
@@ -530,33 +620,39 @@ class WorkflowExecutor {
|
|
|
530
620
|
* the shape up front, independent of resolving it.
|
|
531
621
|
*/
|
|
532
622
|
async #result(invocation, workflow, steps, outcome, dependencies, startedAt) {
|
|
623
|
+
const settledAt = this.#now();
|
|
533
624
|
const shared = {
|
|
534
625
|
workflowId: invocation.workflowId,
|
|
535
626
|
steps,
|
|
536
|
-
durationMs:
|
|
627
|
+
durationMs: settledAt - startedAt,
|
|
537
628
|
...(dependencies.length > 0 ? {
|
|
538
629
|
dependencies
|
|
539
630
|
} : {})
|
|
540
631
|
};
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
return {
|
|
632
|
+
const result = outcome.kind === 'transferred' ? {
|
|
633
|
+
...shared,
|
|
634
|
+
outputs: {},
|
|
635
|
+
status: 'transferred',
|
|
636
|
+
// computed once, here, rather than left for a caller to chase via
|
|
637
|
+
// `settledResult` — `transferredTo` already carries its own
|
|
638
|
+
// `settledStatus`, itself computed the same way when it was built,
|
|
639
|
+
// so this is O(1) per hop rather than a walk of the whole chain.
|
|
640
|
+
settledStatus: outcome.transferredTo.settledStatus,
|
|
641
|
+
transferredTo: outcome.transferredTo
|
|
642
|
+
} : {
|
|
555
643
|
...shared,
|
|
556
644
|
outputs: await this.#resolveWorkflowOutputs(workflow, invocation),
|
|
557
645
|
status: outcome.status,
|
|
558
646
|
settledStatus: outcome.status
|
|
559
647
|
};
|
|
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
|
+
return result;
|
|
560
656
|
}
|
|
561
657
|
|
|
562
658
|
/**
|
|
@@ -604,7 +700,7 @@ class WorkflowExecutor {
|
|
|
604
700
|
workflowId,
|
|
605
701
|
callStack
|
|
606
702
|
} = invocation;
|
|
607
|
-
return async
|
|
703
|
+
return async attempt => {
|
|
608
704
|
(0, _abort.throwIfAborted)(scope.signal, {
|
|
609
705
|
workflowId,
|
|
610
706
|
stepId,
|
|
@@ -612,7 +708,7 @@ class WorkflowExecutor {
|
|
|
612
708
|
});
|
|
613
709
|
this.#chargeBudget(scope, invocation, stepId);
|
|
614
710
|
try {
|
|
615
|
-
return await runAttempt();
|
|
711
|
+
return await runAttempt(attempt);
|
|
616
712
|
} catch (error) {
|
|
617
713
|
(0, _abort.throwIfAborted)(scope.signal, {
|
|
618
714
|
workflowId,
|
|
@@ -624,6 +720,46 @@ class WorkflowExecutor {
|
|
|
624
720
|
};
|
|
625
721
|
}
|
|
626
722
|
|
|
723
|
+
/**
|
|
724
|
+
* Wraps a step-attempt thunk with the events of an attempt: `step-attempt`
|
|
725
|
+
* as it begins, then a `criterion-evaluated` for each criterion it
|
|
726
|
+
* evaluated, success criteria first.
|
|
727
|
+
*/
|
|
728
|
+
#observedAttempt(runAttempt, stepFrame) {
|
|
729
|
+
const events = this.#events;
|
|
730
|
+
if (events === undefined) return runAttempt;
|
|
731
|
+
return async attempt => {
|
|
732
|
+
const attemptFrame = {
|
|
733
|
+
...stepFrame,
|
|
734
|
+
attempt
|
|
735
|
+
};
|
|
736
|
+
events.emit({
|
|
737
|
+
type: 'step-attempt',
|
|
738
|
+
...attemptFrame
|
|
739
|
+
});
|
|
740
|
+
const outcome = await runAttempt();
|
|
741
|
+
for (const criterion of outcome.successCriteria) {
|
|
742
|
+
events.emit({
|
|
743
|
+
type: 'criterion-evaluated',
|
|
744
|
+
...attemptFrame,
|
|
745
|
+
kind: 'success',
|
|
746
|
+
criterion,
|
|
747
|
+
location: criterion.location
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
for (const criterion of outcome.actionCriteria) {
|
|
751
|
+
events.emit({
|
|
752
|
+
type: 'criterion-evaluated',
|
|
753
|
+
...attemptFrame,
|
|
754
|
+
kind: 'action',
|
|
755
|
+
criterion,
|
|
756
|
+
location: criterion.location
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
return outcome;
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
|
|
627
763
|
/**
|
|
628
764
|
* Builds the {@link StepRetryRunContext.runReference} callback a `retry`
|
|
629
765
|
* action's `stepId` / `workflowId` reference is run through.
|
|
@@ -667,13 +803,16 @@ class WorkflowExecutor {
|
|
|
667
803
|
* reference's *completion*, not its success, and a retry that turns out
|
|
668
804
|
* futile is bounded by `retryLimit` regardless.
|
|
669
805
|
*/
|
|
670
|
-
#retryReference(steps,
|
|
806
|
+
#retryReference(steps, stepFrame, invocation, scope, retryReferences) {
|
|
671
807
|
const {
|
|
672
808
|
workflowId,
|
|
673
809
|
state,
|
|
674
810
|
callStack
|
|
675
811
|
} = invocation;
|
|
676
|
-
|
|
812
|
+
const {
|
|
813
|
+
stepId
|
|
814
|
+
} = stepFrame;
|
|
815
|
+
return async (action, outcome, attempt) => {
|
|
677
816
|
(0, _abort.throwIfAborted)(scope.signal, {
|
|
678
817
|
workflowId,
|
|
679
818
|
stepId,
|
|
@@ -696,6 +835,17 @@ class WorkflowExecutor {
|
|
|
696
835
|
// costs no budget unit.
|
|
697
836
|
const inputs = await this.#actionInputs(action.parameters, outcome, invocation, stepId);
|
|
698
837
|
this.#chargeBudget(scope, invocation, stepId);
|
|
838
|
+
const referenceFrame = {
|
|
839
|
+
...stepFrame,
|
|
840
|
+
attempt,
|
|
841
|
+
kind: 'workflow',
|
|
842
|
+
id: reference
|
|
843
|
+
};
|
|
844
|
+
this.#events?.emit({
|
|
845
|
+
type: 'retry-reference-start',
|
|
846
|
+
...referenceFrame,
|
|
847
|
+
location: invocation.document.locationOf(action)
|
|
848
|
+
});
|
|
699
849
|
const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry', inputs);
|
|
700
850
|
// the result's workflowId is the bare id the reference resolved to —
|
|
701
851
|
// the key run state is recorded under, whichever document owns it.
|
|
@@ -704,12 +854,18 @@ class WorkflowExecutor {
|
|
|
704
854
|
inputs: action.hasKey('parameters') ? inputs : state.getWorkflow(refId)?.inputs ?? {},
|
|
705
855
|
outputs: result.outputs
|
|
706
856
|
});
|
|
857
|
+
const successful = !this.#settledFailed(result);
|
|
707
858
|
retryReferences.push({
|
|
708
859
|
kind: 'workflow',
|
|
709
860
|
id: reference,
|
|
710
|
-
successful
|
|
861
|
+
successful,
|
|
711
862
|
subWorkflow: result
|
|
712
863
|
});
|
|
864
|
+
this.#events?.emit({
|
|
865
|
+
type: 'retry-reference-settled',
|
|
866
|
+
...referenceFrame,
|
|
867
|
+
successful
|
|
868
|
+
});
|
|
713
869
|
return;
|
|
714
870
|
}
|
|
715
871
|
const refStepId = (0, _apidomCore.toValue)(action.stepId);
|
|
@@ -719,7 +875,23 @@ class WorkflowExecutor {
|
|
|
719
875
|
});
|
|
720
876
|
const refStep = steps[refIndex];
|
|
721
877
|
const refSubWorkflows = [];
|
|
722
|
-
const
|
|
878
|
+
const referenceFrame = {
|
|
879
|
+
...stepFrame,
|
|
880
|
+
attempt,
|
|
881
|
+
kind: 'step',
|
|
882
|
+
id: refStepId
|
|
883
|
+
};
|
|
884
|
+
this.#events?.emit({
|
|
885
|
+
type: 'retry-reference-start',
|
|
886
|
+
...referenceFrame,
|
|
887
|
+
location: invocation.document.locationOf(action)
|
|
888
|
+
});
|
|
889
|
+
// the referenced step's attempt is observed like any other, under its
|
|
890
|
+
// own stepId and with a count of its own.
|
|
891
|
+
const refOutcome = await this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), {
|
|
892
|
+
...stepFrame,
|
|
893
|
+
stepId: refStepId
|
|
894
|
+
}), invocation, scope, refStepId)(1);
|
|
723
895
|
state.setStepOutputs(refOutcome.stepId, refOutcome.outputs);
|
|
724
896
|
retryReferences.push({
|
|
725
897
|
kind: 'step',
|
|
@@ -729,6 +901,11 @@ class WorkflowExecutor {
|
|
|
729
901
|
subWorkflow: refSubWorkflows[0]
|
|
730
902
|
} : {})
|
|
731
903
|
});
|
|
904
|
+
this.#events?.emit({
|
|
905
|
+
type: 'retry-reference-settled',
|
|
906
|
+
...referenceFrame,
|
|
907
|
+
successful: refOutcome.successful
|
|
908
|
+
});
|
|
732
909
|
};
|
|
733
910
|
}
|
|
734
911
|
|
|
@@ -770,9 +947,23 @@ class WorkflowExecutor {
|
|
|
770
947
|
// found halfway down the list would otherwise be raised only after earlier
|
|
771
948
|
// prerequisites had already fired live requests.
|
|
772
949
|
const dependencyRefs = await this.#dependencyRefs(workflow, invocation);
|
|
950
|
+
const {
|
|
951
|
+
frame
|
|
952
|
+
} = invocation;
|
|
773
953
|
const results = [];
|
|
774
954
|
for (const dependency of dependencyRefs) {
|
|
775
955
|
const qualifiedId = this.#qualifiedId(dependency.locator);
|
|
956
|
+
const target = {
|
|
957
|
+
reference: dependency.inputsKey,
|
|
958
|
+
workflowId: dependency.locator.workflowId,
|
|
959
|
+
documentURI: dependency.locator.document.uri
|
|
960
|
+
};
|
|
961
|
+
this.#events?.emit({
|
|
962
|
+
type: 'dependency-start',
|
|
963
|
+
...frame,
|
|
964
|
+
dependency: target,
|
|
965
|
+
location: invocation.document.locationOf(dependency.entry)
|
|
966
|
+
});
|
|
776
967
|
// a dependency already completed in this run is satisfied, not repeated: a
|
|
777
968
|
// precondition holds once met, and a diamond (two dependents sharing one
|
|
778
969
|
// dependency) must not duplicate its live side effects. Every dependent
|
|
@@ -795,6 +986,13 @@ class WorkflowExecutor {
|
|
|
795
986
|
inputs,
|
|
796
987
|
outputs: result.outputs
|
|
797
988
|
});
|
|
989
|
+
this.#events?.emit({
|
|
990
|
+
type: 'dependency-settled',
|
|
991
|
+
...frame,
|
|
992
|
+
dependency: target,
|
|
993
|
+
memoized: memoized !== undefined,
|
|
994
|
+
settledStatus: result.settledStatus
|
|
995
|
+
});
|
|
798
996
|
if (this.#settledFailed(result)) return results;
|
|
799
997
|
|
|
800
998
|
// only a dependency whose chain settled non-`failed` is remembered as
|
|
@@ -836,23 +1034,25 @@ class WorkflowExecutor {
|
|
|
836
1034
|
reason: _ExecutionError.default.MalformedDependsOn
|
|
837
1035
|
});
|
|
838
1036
|
}
|
|
839
|
-
const
|
|
1037
|
+
const entries = [...dependsOn].map((entry, index) => {
|
|
840
1038
|
if (!(0, _apidomDatamodel.isStringElement)(entry)) {
|
|
841
1039
|
throw new _ExecutionError.default(`workflow "${workflowId}" has a non-string entry at dependsOn[${index}]`, {
|
|
842
1040
|
workflowId,
|
|
843
1041
|
reason: _ExecutionError.default.MalformedDependsOn
|
|
844
1042
|
});
|
|
845
1043
|
}
|
|
846
|
-
return
|
|
1044
|
+
return entry;
|
|
847
1045
|
});
|
|
848
1046
|
const refs = [];
|
|
849
|
-
for (const
|
|
1047
|
+
for (const entry of entries) {
|
|
1048
|
+
const reference = (0, _apidomCore.toValue)(entry);
|
|
850
1049
|
const locator = await this.#workflowLocatorNormalizer.normalize(reference, document, {
|
|
851
1050
|
workflowId
|
|
852
1051
|
});
|
|
853
1052
|
refs.push({
|
|
854
1053
|
locator,
|
|
855
|
-
inputsKey: reference
|
|
1054
|
+
inputsKey: reference,
|
|
1055
|
+
entry
|
|
856
1056
|
});
|
|
857
1057
|
}
|
|
858
1058
|
return refs;
|
|
@@ -1127,30 +1327,46 @@ class WorkflowExecutor {
|
|
|
1127
1327
|
}
|
|
1128
1328
|
|
|
1129
1329
|
/**
|
|
1130
|
-
* Extracts
|
|
1131
|
-
*
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1137
|
-
* missing id itself.
|
|
1330
|
+
* Extracts the workflow a locator names. A workflow its document does not
|
|
1331
|
+
* define is the executor-level `workflow-not-found` authoring error, raised
|
|
1332
|
+
* here rather than leaking the extractor's `ExtractionError`. Only the root
|
|
1333
|
+
* {@link WorkflowExecutor.execute} id reaches this check unvalidated — every
|
|
1334
|
+
* reference position goes through the locator normalizer, which already
|
|
1335
|
+
* rejects a missing workflow with the referencing context attached — so the
|
|
1336
|
+
* error's `workflowId` is the missing id itself.
|
|
1138
1337
|
*/
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
} = locator;
|
|
1144
|
-
const qualifiedId = this.#qualifiedId(locator);
|
|
1145
|
-
const cached = scope.workflows.get(qualifiedId);
|
|
1146
|
-
if (cached !== undefined) return cached;
|
|
1338
|
+
#extractWorkflow({
|
|
1339
|
+
document,
|
|
1340
|
+
workflowId
|
|
1341
|
+
}) {
|
|
1147
1342
|
if (!document.workflowIndex.has(workflowId)) {
|
|
1148
1343
|
throw new _ExecutionError.default(`workflow "${workflowId}" not found in Arazzo document at "${document.uri}"`, {
|
|
1149
1344
|
workflowId,
|
|
1150
1345
|
reason: _ExecutionError.default.WorkflowNotFound
|
|
1151
1346
|
});
|
|
1152
1347
|
}
|
|
1153
|
-
|
|
1348
|
+
return this.#extractor.extract(document, workflowId);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* Normalizes an extracted workflow, once per run for each workflow.
|
|
1353
|
+
*/
|
|
1354
|
+
async #resolveWorkflow(locator, extracted, scope, frame) {
|
|
1355
|
+
const qualifiedId = this.#qualifiedId(locator);
|
|
1356
|
+
const cached = scope.workflows.get(qualifiedId);
|
|
1357
|
+
if (cached !== undefined) return cached;
|
|
1358
|
+
const location = locator.document.locationOf(extracted);
|
|
1359
|
+
this.#events?.emit({
|
|
1360
|
+
type: 'workflow-normalize-start',
|
|
1361
|
+
...frame,
|
|
1362
|
+
location
|
|
1363
|
+
});
|
|
1364
|
+
const workflow = await this.#normalizer.normalize(extracted, locator.document);
|
|
1365
|
+
this.#events?.emit({
|
|
1366
|
+
type: 'workflow-normalize-settled',
|
|
1367
|
+
...frame,
|
|
1368
|
+
location
|
|
1369
|
+
});
|
|
1154
1370
|
scope.workflows.set(qualifiedId, workflow);
|
|
1155
1371
|
return workflow;
|
|
1156
1372
|
}
|