@usearazzo/runner 1.0.1-alpha.33 → 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 +22 -0
- package/README.md +15 -1
- package/dist/arazzo-runner.browser.js +1516 -265
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +64 -18
- 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/errors/ExecutionError.cjs +2 -0
- package/src/errors/ExecutionError.mjs +2 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +77 -6
- package/src/executor/OpenAPIOperationExecutor.mjs +77 -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 +447 -89
- package/src/executor/WorkflowExecutor.mjs +447 -89
- package/src/index.cjs +21 -0
- package/src/index.mjs +4 -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 +106 -0
- package/src/observability/EventChannel.mjs +98 -0
- package/src/observability/OpenAPIOperationEvent.cjs +5 -0
- package/src/observability/OpenAPIOperationEvent.mjs +1 -0
- package/src/observability/Redactor.cjs +215 -0
- package/src/observability/Redactor.mjs +210 -0
- package/src/observability/WorkflowExecutionEvent.cjs +5 -0
- package/src/observability/WorkflowExecutionEvent.mjs +1 -0
- 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 +27 -3
- package/src/registry/DocumentRegistry.mjs +27 -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/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 +802 -5
|
@@ -16,6 +16,7 @@ import OpenAPIOperationExtractor from "../extractor/OpenAPIOperationExtractor.mj
|
|
|
16
16
|
import OpenAPIOperationNormalizer from "../normalizer/OpenAPIOperationNormalizer.mjs";
|
|
17
17
|
import OpenAPIDocumentAssembler from "../assembler/OpenAPIDocumentAssembler.mjs";
|
|
18
18
|
import ClientError from "../errors/ClientError.mjs";
|
|
19
|
+
import EventChannel from "../observability/EventChannel.mjs";
|
|
19
20
|
/**
|
|
20
21
|
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
21
22
|
* of the workflow it belongs to when the caller names one (step ids are only
|
|
@@ -157,6 +158,9 @@ class OpenAPIOperationExecutor {
|
|
|
157
158
|
#operationExtractor;
|
|
158
159
|
#operationNormalizer;
|
|
159
160
|
#documentAssembler;
|
|
161
|
+
#captureBodies;
|
|
162
|
+
// emits only while `hasObservers`, so an unobserved block builds no events
|
|
163
|
+
#events;
|
|
160
164
|
constructor(options = {}) {
|
|
161
165
|
this.#httpClient = options.httpClient ?? httpClientFetch;
|
|
162
166
|
this.#requestInterceptor = options.requestInterceptor;
|
|
@@ -164,6 +168,11 @@ class OpenAPIOperationExecutor {
|
|
|
164
168
|
this.#operationExtractor = options.operationExtractor ?? new OpenAPIOperationExtractor();
|
|
165
169
|
this.#operationNormalizer = options.operationNormalizer ?? new OpenAPIOperationNormalizer();
|
|
166
170
|
this.#documentAssembler = options.documentAssembler ?? new OpenAPIDocumentAssembler();
|
|
171
|
+
this.#events = new EventChannel({
|
|
172
|
+
observer: options.observer,
|
|
173
|
+
now: options.now
|
|
174
|
+
});
|
|
175
|
+
this.#captureBodies = options.captureBodies ?? false;
|
|
167
176
|
}
|
|
168
177
|
|
|
169
178
|
/**
|
|
@@ -184,17 +193,19 @@ class OpenAPIOperationExecutor {
|
|
|
184
193
|
// the legacy id (`{method}-{path}`) matches regardless of an explicit
|
|
185
194
|
// `operationId` in the assembled document
|
|
186
195
|
const operationId = idFromPathMethodLegacy(toValue(operation.meta.get('path')), toValue(operation.meta.get('http-method')));
|
|
187
|
-
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
188
|
-
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
189
|
-
|
|
190
196
|
// the interceptor and step are consumed here, the target always comes from
|
|
191
197
|
// the locator, and the transport is the httpClient, so none of these
|
|
192
198
|
// reach buildRequest
|
|
193
199
|
const {
|
|
194
200
|
requestInterceptor,
|
|
195
|
-
step
|
|
201
|
+
step,
|
|
202
|
+
runId
|
|
196
203
|
} = executeOptions;
|
|
197
|
-
|
|
204
|
+
// the operation as extracted from its own document, before normalizing
|
|
205
|
+
// copies it, carries where it is written; located once, and only for an
|
|
206
|
+
// observer.
|
|
207
|
+
let located;
|
|
208
|
+
const location = () => located ??= locator.document.locationOf(operation);
|
|
198
209
|
const declaredOperationId = toValue(operation.operationId);
|
|
199
210
|
const context = {
|
|
200
211
|
operation: {
|
|
@@ -217,6 +228,33 @@ class OpenAPIOperationExecutor {
|
|
|
217
228
|
}
|
|
218
229
|
})
|
|
219
230
|
};
|
|
231
|
+
if (this.#events.hasObservers) {
|
|
232
|
+
this.#events.emit({
|
|
233
|
+
type: 'openapi:operation:normalize:start',
|
|
234
|
+
...context,
|
|
235
|
+
runId,
|
|
236
|
+
location: location()
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
240
|
+
if (this.#events.hasObservers) {
|
|
241
|
+
this.#events.emit({
|
|
242
|
+
type: 'openapi:operation:normalize:settled',
|
|
243
|
+
...context,
|
|
244
|
+
runId,
|
|
245
|
+
location: location()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
249
|
+
if (this.#events.hasObservers) {
|
|
250
|
+
this.#events.emit({
|
|
251
|
+
type: 'openapi:operation:assembled',
|
|
252
|
+
...context,
|
|
253
|
+
runId,
|
|
254
|
+
location: location()
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
const rest = omit(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
220
258
|
|
|
221
259
|
// each step derives the next options rather than editing in place
|
|
222
260
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -260,6 +298,22 @@ class OpenAPIOperationExecutor {
|
|
|
260
298
|
},
|
|
261
299
|
body: request.body
|
|
262
300
|
};
|
|
301
|
+
if (this.#events.hasObservers) {
|
|
302
|
+
this.#events.emit({
|
|
303
|
+
type: 'openapi:operation:request:start',
|
|
304
|
+
...context,
|
|
305
|
+
runId,
|
|
306
|
+
location: location(),
|
|
307
|
+
request: {
|
|
308
|
+
method: request.method,
|
|
309
|
+
url: request.url,
|
|
310
|
+
headers: request.headers,
|
|
311
|
+
...(this.#captureBodies ? {
|
|
312
|
+
body: request.body
|
|
313
|
+
} : {})
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
263
317
|
let rawResponse;
|
|
264
318
|
try {
|
|
265
319
|
rawResponse = await this.#httpClient(request);
|
|
@@ -269,7 +323,24 @@ class OpenAPIOperationExecutor {
|
|
|
269
323
|
cause: error
|
|
270
324
|
});
|
|
271
325
|
}
|
|
272
|
-
|
|
326
|
+
const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
|
|
327
|
+
if (this.#events.hasObservers) {
|
|
328
|
+
this.#events.emit({
|
|
329
|
+
type: 'openapi:operation:request:settled',
|
|
330
|
+
...context,
|
|
331
|
+
runId,
|
|
332
|
+
location: location(),
|
|
333
|
+
response: {
|
|
334
|
+
status: response.status,
|
|
335
|
+
headers: response.headers,
|
|
336
|
+
size: response.size,
|
|
337
|
+
...(this.#captureBodies ? {
|
|
338
|
+
body: response.body
|
|
339
|
+
} : {})
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return response;
|
|
273
344
|
}
|
|
274
345
|
|
|
275
346
|
/**
|
|
@@ -417,18 +417,30 @@ class StepExecutor {
|
|
|
417
417
|
*/
|
|
418
418
|
async #evaluateCriterion(criterion, context) {
|
|
419
419
|
const condition = (0, _apidomCore.toValue)(criterion.condition);
|
|
420
|
+
const location = this.#document.locationOf(criterion);
|
|
421
|
+
const values = {};
|
|
422
|
+
const resolve = async expression => {
|
|
423
|
+
const value = await this.#evaluate(context, expression);
|
|
424
|
+
const wholeBody = expression === '$response.body' || expression === '$request.body';
|
|
425
|
+
values[expression] = wholeBody ? '[body]' : value;
|
|
426
|
+
return value;
|
|
427
|
+
};
|
|
420
428
|
try {
|
|
421
429
|
const {
|
|
422
430
|
met,
|
|
423
431
|
error
|
|
424
|
-
} = await this.#criterionEvaluator.evaluate(criterion,
|
|
432
|
+
} = await this.#criterionEvaluator.evaluate(criterion, resolve);
|
|
425
433
|
if (error === undefined) return {
|
|
426
434
|
condition,
|
|
427
|
-
met
|
|
435
|
+
met,
|
|
436
|
+
values,
|
|
437
|
+
location
|
|
428
438
|
};
|
|
429
439
|
return {
|
|
430
440
|
condition,
|
|
431
441
|
met,
|
|
442
|
+
values,
|
|
443
|
+
location,
|
|
432
444
|
diagnostic: {
|
|
433
445
|
code: error.reason,
|
|
434
446
|
message: error.message
|
|
@@ -442,6 +454,8 @@ class StepExecutor {
|
|
|
442
454
|
return {
|
|
443
455
|
condition,
|
|
444
456
|
met: false,
|
|
457
|
+
values,
|
|
458
|
+
location,
|
|
445
459
|
diagnostic: {
|
|
446
460
|
code: error.reason,
|
|
447
461
|
message: error.message
|
|
@@ -410,18 +410,30 @@ class StepExecutor {
|
|
|
410
410
|
*/
|
|
411
411
|
async #evaluateCriterion(criterion, context) {
|
|
412
412
|
const condition = toValue(criterion.condition);
|
|
413
|
+
const location = this.#document.locationOf(criterion);
|
|
414
|
+
const values = {};
|
|
415
|
+
const resolve = async expression => {
|
|
416
|
+
const value = await this.#evaluate(context, expression);
|
|
417
|
+
const wholeBody = expression === '$response.body' || expression === '$request.body';
|
|
418
|
+
values[expression] = wholeBody ? '[body]' : value;
|
|
419
|
+
return value;
|
|
420
|
+
};
|
|
413
421
|
try {
|
|
414
422
|
const {
|
|
415
423
|
met,
|
|
416
424
|
error
|
|
417
|
-
} = await this.#criterionEvaluator.evaluate(criterion,
|
|
425
|
+
} = await this.#criterionEvaluator.evaluate(criterion, resolve);
|
|
418
426
|
if (error === undefined) return {
|
|
419
427
|
condition,
|
|
420
|
-
met
|
|
428
|
+
met,
|
|
429
|
+
values,
|
|
430
|
+
location
|
|
421
431
|
};
|
|
422
432
|
return {
|
|
423
433
|
condition,
|
|
424
434
|
met,
|
|
435
|
+
values,
|
|
436
|
+
location,
|
|
425
437
|
diagnostic: {
|
|
426
438
|
code: error.reason,
|
|
427
439
|
message: error.message
|
|
@@ -435,6 +447,8 @@ class StepExecutor {
|
|
|
435
447
|
return {
|
|
436
448
|
condition,
|
|
437
449
|
met: false,
|
|
450
|
+
values,
|
|
451
|
+
location,
|
|
438
452
|
diagnostic: {
|
|
439
453
|
code: error.reason,
|
|
440
454
|
message: error.message
|
|
@@ -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,
|