arvo-event-handler 3.0.22 → 3.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ArvoDomain.d.ts +51 -26
- package/dist/ArvoDomain.js +111 -35
- package/dist/ArvoEventHandler/index.d.ts +15 -19
- package/dist/ArvoEventHandler/index.js +21 -22
- package/dist/ArvoEventHandler/types.d.ts +32 -32
- package/dist/ArvoMachine/createMachine.d.ts +2 -0
- package/dist/ArvoMachine/types.d.ts +2 -1
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +7 -1
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +3 -4
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +12 -12
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +3 -5
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +1 -2
- package/dist/ArvoOrchestrator/factory.d.ts +1 -1
- package/dist/ArvoOrchestrator/factory.js +2 -2
- package/dist/ArvoOrchestrator/index.d.ts +3 -4
- package/dist/ArvoOrchestrator/index.js +19 -15
- package/dist/ArvoOrchestrator/types.d.ts +35 -14
- package/dist/ArvoResumable/factory.js +1 -1
- package/dist/ArvoResumable/index.d.ts +15 -19
- package/dist/ArvoResumable/index.js +18 -19
- package/dist/ArvoResumable/types.d.ts +42 -5
- package/dist/IArvoEventHandler/index.d.ts +1 -4
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ import { type ArvoContract, type ArvoEvent, type ArvoSemanticVersion, type OpenT
|
|
|
3
3
|
import type { SyncEventResource } from '../SyncEventResource';
|
|
4
4
|
import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
|
|
5
5
|
import { type ArvoOrchestrationHandlerType } from './types';
|
|
6
|
+
import type { NonEmptyArray } from '../types';
|
|
6
7
|
/**
|
|
7
8
|
* Parameters for creating system error events during orchestration failures.
|
|
8
9
|
*/
|
|
@@ -20,13 +21,11 @@ export type CreateSystemErrorEventsParams = {
|
|
|
20
21
|
/** Self contract defining error schema */
|
|
21
22
|
selfContract: VersionedArvoContract<ArvoContract, ArvoSemanticVersion>;
|
|
22
23
|
/** Optional domains for error event routing */
|
|
23
|
-
systemErrorDomain
|
|
24
|
+
systemErrorDomain: NonEmptyArray<string | null>;
|
|
24
25
|
/** Execution units for error events */
|
|
25
26
|
executionunits: number;
|
|
26
27
|
/** Source identifier */
|
|
27
28
|
source: string;
|
|
28
|
-
/** Domain for error events */
|
|
29
|
-
domain: string | null;
|
|
30
29
|
/** Type of handler reporting the error */
|
|
31
30
|
handlerType: ArvoOrchestrationHandlerType;
|
|
32
31
|
};
|
|
@@ -40,7 +39,7 @@ export type CreateSystemErrorEventsParams = {
|
|
|
40
39
|
* @param params - Error event creation parameters
|
|
41
40
|
* @returns Array of system error events for each configured domain
|
|
42
41
|
*/
|
|
43
|
-
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject: _orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source,
|
|
42
|
+
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject: _orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, handlerType, }: CreateSystemErrorEventsParams & {
|
|
44
43
|
error: Error;
|
|
45
44
|
}) => ArvoEvent[];
|
|
46
45
|
/**
|
|
@@ -66,7 +66,7 @@ var types_1 = require("./types");
|
|
|
66
66
|
*/
|
|
67
67
|
var createSystemErrorEvents = function (_a) {
|
|
68
68
|
var _b, _c, _d, _e, _f;
|
|
69
|
-
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, _orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source,
|
|
69
|
+
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, _orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, handlerType = _a.handlerType;
|
|
70
70
|
// In case of none transaction errors like errors from
|
|
71
71
|
// the machine or the event creation etc, the are workflow
|
|
72
72
|
// error and shuold be handled by the workflow. Then are
|
|
@@ -86,18 +86,18 @@ var createSystemErrorEvents = function (_a) {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
var domainSets =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
|
|
89
|
+
var domainSets = systemErrorDomain.map(function (item) {
|
|
90
|
+
return (0, ArvoDomain_1.resolveEventDomain)({
|
|
91
|
+
parentSubject: orchestrationParentSubject,
|
|
92
|
+
currentSubject: event.subject,
|
|
93
|
+
domainToResolve: item,
|
|
94
|
+
handlerSelfContract: selfContract,
|
|
95
|
+
eventContract: selfContract,
|
|
96
|
+
triggeringEvent: event,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
99
|
var result = [];
|
|
100
|
-
for (var _i = 0, _g = Array.from(domainSets); _i < _g.length; _i++) {
|
|
100
|
+
for (var _i = 0, _g = Array.from(new Set(domainSets)); _i < _g.length; _i++) {
|
|
101
101
|
var _dom = _g[_i];
|
|
102
102
|
var factoryBuilder = handlerType === 'handler' ? arvo_core_1.createArvoEventFactory : arvo_core_1.createArvoOrchestratorEventFactory;
|
|
103
103
|
result.push(factoryBuilder(selfContract).systemError({
|
|
@@ -2,7 +2,7 @@ import { type Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestrationSubjectContent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type IArvoEventHandler from '../../IArvoEventHandler';
|
|
4
4
|
import type { SyncEventResource } from '../../SyncEventResource';
|
|
5
|
-
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../../types';
|
|
5
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../../types';
|
|
6
6
|
import type { OrchestrationExecutionMemoryRecord } from '../orchestrationExecutionState';
|
|
7
7
|
import type { ArvoOrchestrationHandlerType } from '../types';
|
|
8
8
|
/**
|
|
@@ -21,11 +21,9 @@ export type OrchestrationExecutionContext<TState extends OrchestrationExecutionM
|
|
|
21
21
|
/** Maximum execution units per cycle */
|
|
22
22
|
executionunits: number;
|
|
23
23
|
/** Optional domains for system error routing */
|
|
24
|
-
systemErrorDomain
|
|
24
|
+
systemErrorDomain: NonEmptyArray<string | null>;
|
|
25
25
|
/** Self contract defining orchestrator interface */
|
|
26
26
|
selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
|
|
27
|
-
/** Domain for event routing */
|
|
28
|
-
domain: string | null;
|
|
29
27
|
/** Type of orchestration handler */
|
|
30
28
|
_handlerType: ArvoOrchestrationHandlerType;
|
|
31
29
|
/** OpenTelemetry span configuration */
|
|
@@ -78,4 +76,4 @@ export declare const returnEventsWithLogging: (param: Awaited<ReturnType<IArvoEv
|
|
|
78
76
|
* while allowing custom core logic via the execution function parameter.
|
|
79
77
|
* @returns Emitted events from successful execution or error handling
|
|
80
78
|
*/
|
|
81
|
-
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract,
|
|
79
|
+
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract, _handlerType, }: OrchestrationExecutionContext<TState>, coreExecutionFn: CoreExecutionFn<TState>) => Promise<Awaited<ReturnType<IArvoEventHandler["execute"]>>>;
|
|
@@ -84,7 +84,7 @@ exports.returnEventsWithLogging = returnEventsWithLogging;
|
|
|
84
84
|
*/
|
|
85
85
|
var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return __awaiter(void 0, [_a, coreExecutionFn_1], void 0, function (_b, coreExecutionFn) {
|
|
86
86
|
var otelConfig;
|
|
87
|
-
var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract,
|
|
87
|
+
var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, _handlerType = _b._handlerType;
|
|
88
88
|
return __generator(this, function (_c) {
|
|
89
89
|
switch (_c.label) {
|
|
90
90
|
case 0:
|
|
@@ -206,7 +206,6 @@ var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return
|
|
|
206
206
|
systemErrorDomain: systemErrorDomain,
|
|
207
207
|
executionunits: executionunits,
|
|
208
208
|
source: source,
|
|
209
|
-
domain: domain,
|
|
210
209
|
syncEventResource: syncEventResource,
|
|
211
210
|
handlerType: _handlerType,
|
|
212
211
|
}, span)];
|
|
@@ -29,4 +29,4 @@ import type { CreateArvoOrchestratorParam } from './types';
|
|
|
29
29
|
* @see {@link setupArvoMachine} for creating machine definitions
|
|
30
30
|
* @see {@link ArvoOrchestrator} for direct instantiation with custom components
|
|
31
31
|
*/
|
|
32
|
-
export declare const createArvoOrchestrator: ({ executionunits, memory, machines,
|
|
32
|
+
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, defaultEventEmissionDomains, spanOptions, requiresResourceLocking: _locking, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
|
|
@@ -44,7 +44,7 @@ var errors_1 = require("../errors");
|
|
|
44
44
|
* @see {@link ArvoOrchestrator} for direct instantiation with custom components
|
|
45
45
|
*/
|
|
46
46
|
var createArvoOrchestrator = function (_a) {
|
|
47
|
-
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines,
|
|
47
|
+
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, defaultEventEmissionDomains = _a.defaultEventEmissionDomains, spanOptions = _a.spanOptions, _locking = _a.requiresResourceLocking;
|
|
48
48
|
if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
|
|
49
49
|
throw new Error('At least one machine must be provided');
|
|
50
50
|
}
|
|
@@ -68,7 +68,7 @@ var createArvoOrchestrator = function (_a) {
|
|
|
68
68
|
registry: registry,
|
|
69
69
|
executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
|
|
70
70
|
requiresResourceLocking: requiresResourceLocking,
|
|
71
|
-
|
|
71
|
+
defaultEventEmissionDomains: defaultEventEmissionDomains,
|
|
72
72
|
spanOptions: spanOptions,
|
|
73
73
|
});
|
|
74
74
|
};
|
|
@@ -22,8 +22,8 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
|
22
22
|
readonly executionEngine: IMachineExectionEngine;
|
|
23
23
|
/** Resource manager for state synchronization and memory access */
|
|
24
24
|
readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
|
|
25
|
-
/**
|
|
26
|
-
readonly
|
|
25
|
+
/** Domains for routing events */
|
|
26
|
+
readonly defaultEventEmissionDomains: Required<NonNullable<ArvoOrchestratorParam['defaultEventEmissionDomains']>>;
|
|
27
27
|
/** OpenTelemetry span configuration for observability */
|
|
28
28
|
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
|
|
29
29
|
/** Source identifier from the first registered machine */
|
|
@@ -34,7 +34,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
|
34
34
|
get memory(): IMachineMemory<MachineMemoryRecord>;
|
|
35
35
|
/** The contract-defined domain for the handler */
|
|
36
36
|
get domain(): string | null;
|
|
37
|
-
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking,
|
|
37
|
+
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, defaultEventEmissionDomains, spanOptions, }: ArvoOrchestratorParam);
|
|
38
38
|
/**
|
|
39
39
|
* Executes state machine orchestration for an incoming event.
|
|
40
40
|
*
|
|
@@ -76,6 +76,5 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
|
76
76
|
errorMessage: string;
|
|
77
77
|
errorStack: string | null;
|
|
78
78
|
}>;
|
|
79
|
-
domain: (string | null)[] | undefined;
|
|
80
79
|
};
|
|
81
80
|
}
|
|
@@ -54,6 +54,7 @@ var createEmitableEvent_1 = require("../ArvoOrchestrationUtils/createEmitableEve
|
|
|
54
54
|
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
55
55
|
var SyncEventResource_1 = require("../SyncEventResource");
|
|
56
56
|
var errors_1 = require("../errors");
|
|
57
|
+
var ArvoDomain_1 = require("../ArvoDomain");
|
|
57
58
|
/**
|
|
58
59
|
* Orchestrates state machine execution and lifecycle management.
|
|
59
60
|
*
|
|
@@ -64,15 +65,13 @@ var errors_1 = require("../errors");
|
|
|
64
65
|
var ArvoOrchestrator = /** @class */ (function () {
|
|
65
66
|
function ArvoOrchestrator(_a) {
|
|
66
67
|
var _b;
|
|
67
|
-
var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking,
|
|
68
|
+
var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, defaultEventEmissionDomains = _a.defaultEventEmissionDomains, spanOptions = _a.spanOptions;
|
|
68
69
|
var _c, _d, _e, _f, _g, _h, _j;
|
|
69
|
-
/** Optional domains for routing system error events */
|
|
70
|
-
this.systemErrorDomain = undefined;
|
|
71
70
|
this.executionunits = executionunits;
|
|
72
71
|
this.registry = registry;
|
|
73
72
|
this.executionEngine = executionEngine;
|
|
74
73
|
this.syncEventResource = new SyncEventResource_1.SyncEventResource(memory, requiresResourceLocking);
|
|
75
|
-
this.
|
|
74
|
+
this.defaultEventEmissionDomains = __assign({ systemError: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT], services: [ArvoDomain_1.ArvoDomain.LOCAL], complete: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT] }, (defaultEventEmissionDomains !== null && defaultEventEmissionDomains !== void 0 ? defaultEventEmissionDomains : {}));
|
|
76
75
|
this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, spanOptions), { attributes: __assign(__assign((_b = {}, _b[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _b[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _b), ((_c = spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': (_j = (_h = (_g = (_f = (_e = (_d = this === null || this === void 0 ? void 0 : this.registry) === null || _d === void 0 ? void 0 : _d.machines) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.contracts) === null || _g === void 0 ? void 0 : _g.self) === null || _h === void 0 ? void 0 : _h.uri) !== null && _j !== void 0 ? _j : 'N/A' }) });
|
|
77
76
|
}
|
|
78
77
|
Object.defineProperty(ArvoOrchestrator.prototype, "source", {
|
|
@@ -143,14 +142,13 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
143
142
|
source: this.source,
|
|
144
143
|
syncEventResource: this.syncEventResource,
|
|
145
144
|
executionunits: this.executionunits,
|
|
146
|
-
systemErrorDomain: this.
|
|
145
|
+
systemErrorDomain: this.defaultEventEmissionDomains.systemError,
|
|
147
146
|
selfContract: this.registry.machines[0].contracts.self,
|
|
148
|
-
domain: this.domain,
|
|
149
147
|
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
150
|
-
var machine, inputValidation, executionResult, rawMachineEmittedEvents, emittables, newState;
|
|
151
|
-
var _c, _d, _e, _f;
|
|
148
|
+
var machine, inputValidation, executionResult, rawMachineEmittedEvents, i, emittables, newState;
|
|
149
|
+
var _c, _d, _e, _f, _g, _h;
|
|
152
150
|
var span = _b.span, otelHeaders = _b.otelHeaders, orchestrationParentSubject = _b.orchestrationParentSubject, initEventId = _b.initEventId, parsedEventSubject = _b.parsedEventSubject, state = _b.state;
|
|
153
|
-
return __generator(this, function (
|
|
151
|
+
return __generator(this, function (_j) {
|
|
154
152
|
(0, arvo_core_1.logToSpan)({
|
|
155
153
|
level: 'INFO',
|
|
156
154
|
message: "Resolving machine for event ".concat(event.type),
|
|
@@ -173,15 +171,22 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
173
171
|
executionResult = this.executionEngine.execute({ state: (_c = state === null || state === void 0 ? void 0 : state.state) !== null && _c !== void 0 ? _c : null, event: event, machine: machine }, { inheritFrom: 'CONTEXT' });
|
|
174
172
|
span.setAttribute('arvo.orchestration.status', executionResult.state.status);
|
|
175
173
|
rawMachineEmittedEvents = executionResult.events;
|
|
174
|
+
// For all the service events (non final output) make sure
|
|
175
|
+
// that the default domain is this.defaultEventEmissionDomains.services.
|
|
176
|
+
// This is because the assumption is that all the normal services
|
|
177
|
+
// the orchestrator usually talks to are in the same local
|
|
178
|
+
// domain.
|
|
179
|
+
for (i = 0; i < rawMachineEmittedEvents.length; i++) {
|
|
180
|
+
rawMachineEmittedEvents[i].domain =
|
|
181
|
+
(_d = rawMachineEmittedEvents[i].domain) !== null && _d !== void 0 ? _d : this.defaultEventEmissionDomains.services;
|
|
182
|
+
}
|
|
176
183
|
if (executionResult.finalOutput) {
|
|
177
184
|
rawMachineEmittedEvents.push({
|
|
178
185
|
type: machine.contracts.self.metadata.completeEventType,
|
|
179
186
|
id: executionResult.finalOutput.__id,
|
|
180
187
|
data: executionResult.finalOutput,
|
|
181
|
-
to: (
|
|
182
|
-
domain:
|
|
183
|
-
? [arvo_core_1.ArvoOrchestrationSubject.parse(orchestrationParentSubject).execution.domain]
|
|
184
|
-
: [null],
|
|
188
|
+
to: (_f = (_e = parsedEventSubject.meta) === null || _e === void 0 ? void 0 : _e.redirectto) !== null && _f !== void 0 ? _f : parsedEventSubject.execution.initiator,
|
|
189
|
+
domain: (_g = executionResult.finalOutput.__domain) !== null && _g !== void 0 ? _g : this.defaultEventEmissionDomains.complete,
|
|
185
190
|
executionunits: executionResult.finalOutput.__executionunits,
|
|
186
191
|
});
|
|
187
192
|
}
|
|
@@ -206,7 +211,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
206
211
|
subject: event.subject,
|
|
207
212
|
parentSubject: orchestrationParentSubject,
|
|
208
213
|
status: executionResult.state.status,
|
|
209
|
-
value: (
|
|
214
|
+
value: (_h = executionResult.state.value) !== null && _h !== void 0 ? _h : null,
|
|
210
215
|
state: executionResult.state,
|
|
211
216
|
events: {
|
|
212
217
|
consumed: event.toJSON(),
|
|
@@ -230,7 +235,6 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
230
235
|
return {
|
|
231
236
|
type: this.registry.machines[0].contracts.self.systemError.type,
|
|
232
237
|
schema: arvo_core_1.ArvoErrorSchema,
|
|
233
|
-
domain: this.systemErrorDomain,
|
|
234
238
|
};
|
|
235
239
|
},
|
|
236
240
|
enumerable: false,
|
|
@@ -5,7 +5,7 @@ import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUti
|
|
|
5
5
|
import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
|
|
6
6
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
7
7
|
import type { IMachineRegistry } from '../MachineRegistry/interface';
|
|
8
|
-
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
|
+
import type { ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../types';
|
|
9
9
|
/**
|
|
10
10
|
* Discriminated union representing the result of a try operation.
|
|
11
11
|
*/
|
|
@@ -93,20 +93,41 @@ export type ArvoOrchestratorParam = {
|
|
|
93
93
|
executionEngine: IMachineExectionEngine;
|
|
94
94
|
/** Whether to enforce resource locking for concurrent safety */
|
|
95
95
|
requiresResourceLocking: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Optional domains for system error event routing.
|
|
98
|
-
*
|
|
99
|
-
* Overrides the default fallback sequence of:
|
|
100
|
-
* `[event.domain, self.contract.domain, null]`
|
|
101
|
-
*
|
|
102
|
-
* Controls where structured `sys.*.error` events are emitted when
|
|
103
|
-
* uncaught exceptions occur. Supports symbolic constants from {@link ArvoDomain}.
|
|
104
|
-
*
|
|
105
|
-
* @default undefined - uses standard fallback broadcast domains
|
|
106
|
-
*/
|
|
107
|
-
systemErrorDomain?: (string | null)[];
|
|
108
96
|
/** OpenTelemetry span configuration for distributed tracing */
|
|
109
97
|
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Optional default domains for the events emitted
|
|
100
|
+
* by the orchestrator.
|
|
101
|
+
*/
|
|
102
|
+
defaultEventEmissionDomains?: {
|
|
103
|
+
/**
|
|
104
|
+
* Default domains for system error events emitted by this orchestrator.
|
|
105
|
+
*
|
|
106
|
+
* System errors are routed through these domains when the handler encounters
|
|
107
|
+
* unhandled exceptions or critical failures.
|
|
108
|
+
*
|
|
109
|
+
* @default [ArvoDomain.ORCHESTRATION_CONTEXT]
|
|
110
|
+
*/
|
|
111
|
+
systemError?: NonEmptyArray<string | null>;
|
|
112
|
+
/**
|
|
113
|
+
* Default domains for service events emitted by this orchestrator.
|
|
114
|
+
*
|
|
115
|
+
* The service xstate.emit function can over-ride this default.
|
|
116
|
+
*
|
|
117
|
+
* @default [ArvoDomain.LOCAL]
|
|
118
|
+
*/
|
|
119
|
+
services?: NonEmptyArray<string | null>;
|
|
120
|
+
/**
|
|
121
|
+
* Defauld domain for the final completion event emitted by this orchestrator
|
|
122
|
+
*
|
|
123
|
+
* Completion event is routed through these domains when the orchestrator successfully
|
|
124
|
+
* processes an init event. The machine 'output' transform function implementations can override
|
|
125
|
+
* this default.
|
|
126
|
+
*
|
|
127
|
+
* @default [ArvoDomain.ORCHESTRATION_CONTEXT]
|
|
128
|
+
*/
|
|
129
|
+
complete?: NonEmptyArray<string | null>;
|
|
130
|
+
};
|
|
110
131
|
};
|
|
111
132
|
/**
|
|
112
133
|
* Configuration parameters for creating an orchestrator via factory function.
|
|
@@ -114,7 +135,7 @@ export type ArvoOrchestratorParam = {
|
|
|
114
135
|
* Simplified interface for {@link createArvoOrchestrator} that automatically
|
|
115
136
|
* constructs default registry and execution engine components.
|
|
116
137
|
*/
|
|
117
|
-
export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | '
|
|
138
|
+
export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'defaultEventEmissionDomains'> & {
|
|
118
139
|
/**
|
|
119
140
|
* Optional override for resource locking requirement.
|
|
120
141
|
*
|
|
@@ -47,7 +47,7 @@ var createArvoResumable = function (param) {
|
|
|
47
47
|
handler: param.handler,
|
|
48
48
|
executionunits: (_a = param.executionunits) !== null && _a !== void 0 ? _a : 0,
|
|
49
49
|
requiresResourceLocking: (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : Object.keys(param.contracts.services).length > 1,
|
|
50
|
-
|
|
50
|
+
defaultEventEmissionDomains: param.defaultEventEmissionDomains,
|
|
51
51
|
spanOptions: param.spanOptions,
|
|
52
52
|
});
|
|
53
53
|
};
|
|
@@ -23,8 +23,8 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
23
23
|
readonly syncEventResource: SyncEventResource<ArvoResumableState<TMemory>>;
|
|
24
24
|
/** Versioned handler map for processing workflow events. */
|
|
25
25
|
readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
26
|
-
/** Optional domains for routing
|
|
27
|
-
readonly
|
|
26
|
+
/** Optional domains for routing events */
|
|
27
|
+
readonly defaultEventEmissionDomains: Required<NonNullable<ArvoResumableParam<TMemory, TSelfContract, TServiceContract>['defaultEventEmissionDomains']>>;
|
|
28
28
|
/** OpenTelemetry span configuration for observability */
|
|
29
29
|
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
|
|
30
30
|
/** Source identifier from the first registered machine */
|
|
@@ -82,21 +82,17 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
82
82
|
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
83
83
|
events: ArvoEvent[];
|
|
84
84
|
}>;
|
|
85
|
-
get systemErrorSchema(): {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
errorMessage: string;
|
|
99
|
-
errorStack: string | null;
|
|
100
|
-
}>;
|
|
101
|
-
};
|
|
85
|
+
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, import("zod").ZodObject<{
|
|
86
|
+
errorName: import("zod").ZodString;
|
|
87
|
+
errorMessage: import("zod").ZodString;
|
|
88
|
+
errorStack: import("zod").ZodNullable<import("zod").ZodString>;
|
|
89
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
90
|
+
errorName: string;
|
|
91
|
+
errorMessage: string;
|
|
92
|
+
errorStack: string | null;
|
|
93
|
+
}, {
|
|
94
|
+
errorName: string;
|
|
95
|
+
errorMessage: string;
|
|
96
|
+
errorStack: string | null;
|
|
97
|
+
}>>;
|
|
102
98
|
}
|
|
@@ -55,6 +55,7 @@ var inputValidation_1 = require("../ArvoOrchestrationUtils/inputValidation");
|
|
|
55
55
|
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
56
56
|
var index_1 = require("../SyncEventResource/index");
|
|
57
57
|
var errors_1 = require("../errors");
|
|
58
|
+
var ArvoDomain_1 = require("../ArvoDomain");
|
|
58
59
|
/**
|
|
59
60
|
* ArvoResumable complements {@link ArvoOrchestrator} by providing imperative
|
|
60
61
|
* handler functions for orchestration logic instead of declarative state machines.
|
|
@@ -68,16 +69,14 @@ var errors_1 = require("../errors");
|
|
|
68
69
|
var ArvoResumable = /** @class */ (function () {
|
|
69
70
|
function ArvoResumable(param) {
|
|
70
71
|
var _a;
|
|
71
|
-
var _b, _c, _d;
|
|
72
|
-
/** Optional domains for routing system error events */
|
|
73
|
-
this.systemErrorDomain = undefined;
|
|
72
|
+
var _b, _c, _d, _e;
|
|
74
73
|
this.executionunits = param.executionunits;
|
|
75
74
|
this.source = param.contracts.self.type;
|
|
76
75
|
this.syncEventResource = new index_1.SyncEventResource(param.memory, (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : true);
|
|
77
76
|
this.contracts = param.contracts;
|
|
78
77
|
this.handler = param.handler;
|
|
79
|
-
this.
|
|
80
|
-
this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.RESUMABLE, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((
|
|
78
|
+
this.defaultEventEmissionDomains = __assign({ systemError: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT], services: [ArvoDomain_1.ArvoDomain.LOCAL], complete: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT] }, ((_c = param.defaultEventEmissionDomains) !== null && _c !== void 0 ? _c : {}));
|
|
79
|
+
this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.RESUMABLE, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_e = (_d = param.spanOptions) === null || _d === void 0 ? void 0 : _d.attributes) !== null && _e !== void 0 ? _e : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
|
|
81
80
|
}
|
|
82
81
|
Object.defineProperty(ArvoResumable.prototype, "requiresResourceLocking", {
|
|
83
82
|
/** Whether this resumable requires resource locking for concurrent safety */
|
|
@@ -155,15 +154,14 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
155
154
|
source: this.source,
|
|
156
155
|
syncEventResource: this.syncEventResource,
|
|
157
156
|
executionunits: this.executionunits,
|
|
158
|
-
systemErrorDomain: this.
|
|
157
|
+
systemErrorDomain: this.defaultEventEmissionDomains.systemError,
|
|
159
158
|
selfContract: this.contracts.self.version('latest'),
|
|
160
|
-
domain: this.domain,
|
|
161
159
|
}, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
162
|
-
var inputValidation, contractType, eventTypeToExpectedEvent, _i, _c, _d, _, eventList, _e, eventList_1, _evt, handler, versionedSelfContract, executionResult, rawEvents, emittables, eventTrackingState, newState;
|
|
163
|
-
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
160
|
+
var inputValidation, contractType, eventTypeToExpectedEvent, _i, _c, _d, _, eventList, _e, eventList_1, _evt, handler, versionedSelfContract, executionResult, rawEvents, i, emittables, eventTrackingState, newState;
|
|
161
|
+
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
164
162
|
var span = _b.span, otelHeaders = _b.otelHeaders, orchestrationParentSubject = _b.orchestrationParentSubject, initEventId = _b.initEventId, parsedEventSubject = _b.parsedEventSubject, state = _b.state;
|
|
165
|
-
return __generator(this, function (
|
|
166
|
-
switch (
|
|
163
|
+
return __generator(this, function (_y) {
|
|
164
|
+
switch (_y.label) {
|
|
167
165
|
case 0:
|
|
168
166
|
(0, arvo_core_1.logToSpan)({
|
|
169
167
|
level: 'INFO',
|
|
@@ -230,17 +228,18 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
230
228
|
},
|
|
231
229
|
})];
|
|
232
230
|
case 1:
|
|
233
|
-
executionResult =
|
|
231
|
+
executionResult = _y.sent();
|
|
234
232
|
rawEvents = (_o = executionResult === null || executionResult === void 0 ? void 0 : executionResult.services) !== null && _o !== void 0 ? _o : [];
|
|
233
|
+
for (i = 0; i < rawEvents.length; i++) {
|
|
234
|
+
rawEvents[i].domain = (_p = rawEvents[i].domain) !== null && _p !== void 0 ? _p : this.defaultEventEmissionDomains.services;
|
|
235
|
+
}
|
|
235
236
|
if (executionResult === null || executionResult === void 0 ? void 0 : executionResult.output) {
|
|
236
237
|
rawEvents.push({
|
|
237
238
|
id: executionResult.output.__id,
|
|
238
239
|
data: executionResult.output,
|
|
239
240
|
type: this.contracts.self.metadata.completeEventType,
|
|
240
|
-
to: (
|
|
241
|
-
domain:
|
|
242
|
-
? [arvo_core_1.ArvoOrchestrationSubject.parse(orchestrationParentSubject).execution.domain]
|
|
243
|
-
: [null],
|
|
241
|
+
to: (_r = (_q = parsedEventSubject.meta) === null || _q === void 0 ? void 0 : _q.redirectto) !== null && _r !== void 0 ? _r : parsedEventSubject.execution.initiator,
|
|
242
|
+
domain: (_t = (_s = executionResult.output) === null || _s === void 0 ? void 0 : _s.__domain) !== null && _t !== void 0 ? _t : this.defaultEventEmissionDomains.complete,
|
|
244
243
|
executionunits: executionResult.output.__executionunits,
|
|
245
244
|
});
|
|
246
245
|
}
|
|
@@ -263,7 +262,7 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
263
262
|
consumed: event.toJSON(),
|
|
264
263
|
expected: emittables.length
|
|
265
264
|
? Object.fromEntries(emittables.map(function (item) { return [item.id, []]; }))
|
|
266
|
-
: ((
|
|
265
|
+
: ((_v = (_u = state === null || state === void 0 ? void 0 : state.events) === null || _u === void 0 ? void 0 : _u.expected) !== null && _v !== void 0 ? _v : null),
|
|
267
266
|
produced: emittables.map(function (item) { return item.toJSON(); }),
|
|
268
267
|
};
|
|
269
268
|
newState = {
|
|
@@ -273,7 +272,7 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
273
272
|
parentSubject: orchestrationParentSubject,
|
|
274
273
|
subject: event.subject,
|
|
275
274
|
events: eventTrackingState,
|
|
276
|
-
state$$: (
|
|
275
|
+
state$$: (_x = (_w = executionResult === null || executionResult === void 0 ? void 0 : executionResult.context) !== null && _w !== void 0 ? _w : state === null || state === void 0 ? void 0 : state.state$$) !== null && _x !== void 0 ? _x : null,
|
|
277
276
|
};
|
|
278
277
|
return [2 /*return*/, { emittables: emittables, newState: newState }];
|
|
279
278
|
}
|
|
@@ -286,7 +285,7 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
286
285
|
};
|
|
287
286
|
Object.defineProperty(ArvoResumable.prototype, "systemErrorSchema", {
|
|
288
287
|
get: function () {
|
|
289
|
-
return
|
|
288
|
+
return this.contracts.self.systemError;
|
|
290
289
|
},
|
|
291
290
|
enumerable: false,
|
|
292
291
|
configurable: true
|
|
@@ -3,7 +3,7 @@ import type { ArvoContract, ArvoEvent, ArvoOrchestratorContract, ArvoSemanticVer
|
|
|
3
3
|
import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types';
|
|
4
4
|
import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
5
5
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
6
|
-
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
6
|
+
import type { ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../types';
|
|
7
7
|
/**
|
|
8
8
|
* Extracts all possible event types (including system errors) from service contracts.
|
|
9
9
|
*/
|
|
@@ -98,6 +98,7 @@ type Handler<TState extends ArvoResumableState<Record<string, any>>, TSelfContra
|
|
|
98
98
|
}[keyof InferVersionedArvoContract<TSelfContract>['emits']] & {
|
|
99
99
|
__id?: CreateArvoEvent<Record<string, unknown>, string>['id'];
|
|
100
100
|
__executionunits?: CreateArvoEvent<Record<string, unknown>, string>['executionunits'];
|
|
101
|
+
__domain?: NonEmptyArray<string | null>;
|
|
101
102
|
};
|
|
102
103
|
/**
|
|
103
104
|
* Service call events to emit.
|
|
@@ -219,10 +220,47 @@ export type ArvoResumableParam<TMemory extends Record<string, any>, TSelfContrac
|
|
|
219
220
|
* Each contract version maps to its corresponding handler implementation.
|
|
220
221
|
*/
|
|
221
222
|
handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
222
|
-
/**
|
|
223
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Optional domains for system error event routing
|
|
225
|
+
*
|
|
226
|
+
* @default [ArvoDomain.FROM_PARENT_SUBJECT]
|
|
227
|
+
*/
|
|
228
|
+
systemErrorDomain?: NonEmptyArray<string | null>;
|
|
224
229
|
/** OpenTelemetry span configuration for distributed tracing */
|
|
225
230
|
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
231
|
+
/**
|
|
232
|
+
* Optional default domains for the events emitted
|
|
233
|
+
* by the orchestrator.
|
|
234
|
+
*/
|
|
235
|
+
defaultEventEmissionDomains?: {
|
|
236
|
+
/**
|
|
237
|
+
* Default domains for system error events emitted by this orchestrator.
|
|
238
|
+
*
|
|
239
|
+
* System errors are routed through these domains when the handler encounters
|
|
240
|
+
* unhandled exceptions or critical failures.
|
|
241
|
+
*
|
|
242
|
+
* @default [ArvoDomain.ORCHESTRATION_CONTEXT]
|
|
243
|
+
*/
|
|
244
|
+
systemError?: NonEmptyArray<string | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Default domains for service events emitted by this orchestrator.
|
|
247
|
+
*
|
|
248
|
+
* The service xstate.emit function can over-ride this default.
|
|
249
|
+
*
|
|
250
|
+
* @default [ArvoDomain.LOCAL]
|
|
251
|
+
*/
|
|
252
|
+
services?: NonEmptyArray<string | null>;
|
|
253
|
+
/**
|
|
254
|
+
* Defauld domain for the final completion event emitted by this orchestrator
|
|
255
|
+
*
|
|
256
|
+
* Completion event is routed through these domains when the orchestrator successfully
|
|
257
|
+
* processes an init event. The machine 'output' transform function implementations can override
|
|
258
|
+
* this default.
|
|
259
|
+
*
|
|
260
|
+
* @default [ArvoDomain.ORCHESTRATION_CONTEXT]
|
|
261
|
+
*/
|
|
262
|
+
complete?: NonEmptyArray<string | null>;
|
|
263
|
+
};
|
|
226
264
|
};
|
|
227
265
|
/**
|
|
228
266
|
* Configuration parameters for creating an ArvoResumable instance.
|
|
@@ -252,9 +290,8 @@ export type CreateArvoResumableParam<TMemory extends Record<string, any>, TSelfC
|
|
|
252
290
|
* @default true if multiple service contracts, false otherwise
|
|
253
291
|
*/
|
|
254
292
|
requiresResourceLocking?: boolean;
|
|
255
|
-
/** Optional domains for system error event routing */
|
|
256
|
-
systemErrorDomain?: (string | null)[];
|
|
257
293
|
/** OpenTelemetry span configuration for distributed tracing */
|
|
258
294
|
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
295
|
+
defaultEventEmissionDomains?: ArvoResumableParam<TMemory, TSelfContract, TServiceContract>['defaultEventEmissionDomains'];
|
|
259
296
|
};
|
|
260
297
|
export {};
|
|
@@ -42,9 +42,6 @@ export default interface IArvoEventHandler {
|
|
|
42
42
|
*
|
|
43
43
|
* @property type - The error event type identifier
|
|
44
44
|
* @property schema - Zod schema defining the error event data structure
|
|
45
|
-
* @property domain - Optional domains for error event routing and distribution
|
|
46
45
|
*/
|
|
47
|
-
systemErrorSchema: ArvoContractRecord
|
|
48
|
-
domain?: (string | null)[];
|
|
49
|
-
};
|
|
46
|
+
systemErrorSchema: ArvoContractRecord;
|
|
50
47
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SpanOptions } from '@opentelemetry/api';
|
|
2
2
|
import type { ArvoEvent } from 'arvo-core';
|
|
3
3
|
import type IArvoEventHandler from './IArvoEventHandler';
|
|
4
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
4
5
|
/**
|
|
5
6
|
* Makes properties optional except specified keys
|
|
6
7
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.25",
|
|
4
4
|
"description": "A complete set of orthogonal event handler and orchestration primitives for Arvo based applications, featuring declarative state machines (XState), imperative resumables for agentic workflows, contract-based routing, OpenTelemetry observability, and in-memory event broker for building composable event-driven architectures.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@opentelemetry/api": "1.9.0",
|
|
67
67
|
"@opentelemetry/core": "1.30.1",
|
|
68
|
-
"arvo-core": "3.0.
|
|
68
|
+
"arvo-core": "3.0.25",
|
|
69
69
|
"uuid": "11.1.0",
|
|
70
70
|
"xstate": "5.24.0",
|
|
71
71
|
"zod": "3.25.74",
|