@outputai/core 0.10.1-dev.b7b2fbe.0 → 0.10.1-next.09ed166.0
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/package.json +1 -1
- package/src/bus.js +58 -20
- package/src/bus.spec.js +135 -77
- package/src/helpers/object.js +5 -1
- package/src/helpers/object.spec.js +5 -0
- package/src/hooks/index.d.ts +48 -45
- package/src/hooks/index.js +49 -44
- package/src/hooks/index.spec.js +74 -102
- package/src/sdk/runtime/events.d.ts +4 -6
- package/src/sdk/runtime/events.js +2 -15
- package/src/sdk/runtime/events.spec.js +14 -92
- package/src/worker/global_functions.js +2 -2
- package/src/worker/global_functions.spec.js +3 -3
- package/src/worker/index.js +3 -3
- package/src/worker/index.spec.js +6 -6
- package/src/worker/interceptors/activity.js +4 -4
- package/src/worker/interceptors/activity.spec.js +9 -9
- package/src/worker/log_hooks.js +9 -9
- package/src/worker/log_hooks.spec.js +2 -2
- package/src/worker/sinks.js +8 -8
- package/src/worker/sinks.spec.js +9 -9
package/package.json
CHANGED
package/src/bus.js
CHANGED
|
@@ -1,30 +1,68 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import {
|
|
3
|
+
import { Storage } from '#async_storage';
|
|
4
|
+
import { WORKFLOW_CATALOG } from '#consts';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
const mainEventBus = new EventEmitter();
|
|
7
|
+
const stepEventBus = new EventEmitter();
|
|
8
|
+
|
|
9
|
+
const getContext = () => {
|
|
10
|
+
const ctx = Storage.load();
|
|
11
|
+
if ( ctx ) {
|
|
12
|
+
const { outputActivityKind, activityInfo, workflowDetails } = ctx;
|
|
13
|
+
return { outputActivityKind, activityInfo, workflowDetails };
|
|
14
|
+
}
|
|
15
|
+
return {};
|
|
16
|
+
};
|
|
6
17
|
|
|
7
18
|
/**
|
|
8
|
-
*
|
|
19
|
+
* Attaches information and filter out events from the bus by proxying .emit().
|
|
20
|
+
*
|
|
21
|
+
* If createEnvelope=true, wrap payload:
|
|
22
|
+
* ```js
|
|
23
|
+
* {
|
|
24
|
+
* eventId,
|
|
25
|
+
* eventDate,
|
|
26
|
+
* outputActivityKind,
|
|
27
|
+
* activityInfo,
|
|
28
|
+
* workflowDetails,
|
|
29
|
+
* payload: <original payload>
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* if createEnvelope=false, adds eventId and eventDate to the original payload object
|
|
34
|
+
*
|
|
35
|
+
* @param {object} args
|
|
36
|
+
* @param {object} args.bus The event emitter to proxy
|
|
37
|
+
* @param {boolean} args.createEnvelope Whether to wrap event around an envelope
|
|
38
|
+
* @param {function} args.filter Filter function to drop events
|
|
9
39
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
const proxyBus = ( { bus, createEnvelope = false, filter } ) => {
|
|
41
|
+
bus.emit = new Proxy( bus.emit, {
|
|
42
|
+
apply( target, thisArg, args ) {
|
|
43
|
+
const [ eventName, payload, ...rest ] = args;
|
|
44
|
+
|
|
45
|
+
const shouldEmit = filter?.( eventName, payload ) ?? true;
|
|
46
|
+
if ( !shouldEmit ) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const eventFields = {
|
|
19
51
|
eventId: randomUUID(),
|
|
20
|
-
eventDate: Date.now()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
52
|
+
eventDate: Date.now()
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const newPayload = createEnvelope ? { ...eventFields, ...getContext(), payload } : { ...eventFields, ...payload };
|
|
56
|
+
return Reflect.apply( target, thisArg, [ eventName, newPayload, ...rest ] );
|
|
24
57
|
}
|
|
58
|
+
} );
|
|
59
|
+
};
|
|
25
60
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
61
|
+
const catalogWfFilter = ( _, payload ) => payload?.workflowDetails?.workflowType !== WORKFLOW_CATALOG;
|
|
62
|
+
|
|
63
|
+
// Main bus is not used inside steps, so it doesn't need context
|
|
64
|
+
proxyBus( { bus: mainEventBus, createEnvelope: false, filter: catalogWfFilter } );
|
|
65
|
+
// This receives SDK and user events from within steps, so add context to it
|
|
66
|
+
proxyBus( { bus: stepEventBus, createEnvelope: true } );
|
|
29
67
|
|
|
30
|
-
export
|
|
68
|
+
export { mainEventBus, stepEventBus };
|
package/src/bus.spec.js
CHANGED
|
@@ -1,135 +1,193 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const loadMock = vi.hoisted( () => vi.fn() );
|
|
4
|
+
|
|
5
|
+
vi.mock( '#async_storage', () => ( {
|
|
6
|
+
Storage: { load: loadMock }
|
|
7
|
+
} ) );
|
|
8
|
+
|
|
9
|
+
import { mainEventBus, stepEventBus } from './bus.js';
|
|
3
10
|
|
|
4
11
|
const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
12
|
+
const ACTIVITY_CONTEXT = {
|
|
13
|
+
activityInfo: { activityId: 'activity-id' },
|
|
14
|
+
workflowDetails: { workflowId: 'workflow-id' },
|
|
15
|
+
outputActivityKind: 'step'
|
|
16
|
+
};
|
|
5
17
|
|
|
6
|
-
describe( '
|
|
18
|
+
describe( 'event buses', () => {
|
|
7
19
|
beforeEach( () => {
|
|
8
|
-
|
|
20
|
+
mainEventBus.removeAllListeners();
|
|
21
|
+
stepEventBus.removeAllListeners();
|
|
22
|
+
loadMock.mockReset();
|
|
9
23
|
} );
|
|
10
24
|
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
afterEach( () => {
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
describe( 'mainEventBus', () => {
|
|
30
|
+
it( 'adds event metadata to payload fields', () => {
|
|
13
31
|
const handler = vi.fn();
|
|
14
|
-
|
|
32
|
+
const now = new Date( '2026-06-02T12:00:00.000Z' );
|
|
33
|
+
vi.useFakeTimers();
|
|
34
|
+
vi.setSystemTime( now );
|
|
35
|
+
mainEventBus.on( 'test:event', handler );
|
|
15
36
|
|
|
16
|
-
|
|
37
|
+
mainEventBus.emit( 'test:event', { foo: 'bar' } );
|
|
17
38
|
|
|
18
|
-
expect( handler ).toHaveBeenCalledWith(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
expect( handler ).toHaveBeenCalledWith( {
|
|
40
|
+
eventId: expect.stringMatching( UUID_V4_REGEX ),
|
|
41
|
+
eventDate: now.getTime(),
|
|
42
|
+
foo: 'bar'
|
|
43
|
+
} );
|
|
22
44
|
} );
|
|
23
45
|
|
|
24
|
-
it( '
|
|
46
|
+
it( 'preserves caller-supplied event metadata', () => {
|
|
25
47
|
const handler = vi.fn();
|
|
26
|
-
|
|
48
|
+
mainEventBus.on( 'test:event', handler );
|
|
27
49
|
|
|
28
|
-
|
|
29
|
-
messageBus.emit( 'test:event', { i: 2 } );
|
|
50
|
+
mainEventBus.emit( 'test:event', { eventId: 'fixed-id', eventDate: 1234 } );
|
|
30
51
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect( first ).not.toBe( second );
|
|
52
|
+
expect( handler ).toHaveBeenCalledWith( {
|
|
53
|
+
eventId: 'fixed-id',
|
|
54
|
+
eventDate: 1234
|
|
55
|
+
} );
|
|
36
56
|
} );
|
|
37
57
|
|
|
38
|
-
it( '
|
|
58
|
+
it( 'does not mutate the caller-supplied payload', () => {
|
|
39
59
|
const handler = vi.fn();
|
|
40
|
-
|
|
60
|
+
const payload = { foo: 'bar' };
|
|
61
|
+
mainEventBus.on( 'test:event', handler );
|
|
41
62
|
|
|
42
|
-
|
|
63
|
+
mainEventBus.emit( 'test:event', payload );
|
|
43
64
|
|
|
44
|
-
expect( handler ).
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
expect( handler.mock.calls[0][0] ).not.toBe( payload );
|
|
66
|
+
expect( payload ).toEqual( { foo: 'bar' } );
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
it( 'does not attach activity context', () => {
|
|
70
|
+
const handler = vi.fn();
|
|
71
|
+
loadMock.mockReturnValue( {
|
|
72
|
+
activityInfo: { activityId: 'activity-id' },
|
|
73
|
+
workflowDetails: { workflowId: 'workflow-id' },
|
|
74
|
+
outputActivityKind: 'step'
|
|
75
|
+
} );
|
|
76
|
+
mainEventBus.on( 'test:event', handler );
|
|
77
|
+
|
|
78
|
+
mainEventBus.emit( 'test:event', { foo: 'bar' } );
|
|
79
|
+
|
|
80
|
+
expect( handler ).toHaveBeenCalledWith( expect.not.objectContaining( {
|
|
81
|
+
activityInfo: expect.anything(),
|
|
82
|
+
workflowDetails: expect.anything(),
|
|
83
|
+
outputActivityKind: expect.anything()
|
|
47
84
|
} ) );
|
|
85
|
+
expect( loadMock ).not.toHaveBeenCalled();
|
|
48
86
|
} );
|
|
49
87
|
|
|
50
|
-
it( '
|
|
88
|
+
it( 'filters catalog workflow events', () => {
|
|
51
89
|
const handler = vi.fn();
|
|
52
|
-
|
|
53
|
-
vi.useFakeTimers();
|
|
54
|
-
vi.setSystemTime( now );
|
|
55
|
-
messageBus.on( 'test:event', handler );
|
|
90
|
+
mainEventBus.on( 'workflow:start', handler );
|
|
56
91
|
|
|
57
|
-
|
|
92
|
+
const emitted = mainEventBus.emit( 'workflow:start', {
|
|
93
|
+
workflowDetails: { workflowType: '$catalog' }
|
|
94
|
+
} );
|
|
58
95
|
|
|
59
|
-
expect(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
96
|
+
expect( emitted ).toBe( false );
|
|
97
|
+
expect( handler ).not.toHaveBeenCalled();
|
|
98
|
+
} );
|
|
99
|
+
} );
|
|
63
100
|
|
|
64
|
-
|
|
101
|
+
describe( 'stepEventBus', () => {
|
|
102
|
+
beforeEach( () => {
|
|
103
|
+
loadMock.mockReturnValue( ACTIVITY_CONTEXT );
|
|
65
104
|
} );
|
|
66
105
|
|
|
67
|
-
it( '
|
|
106
|
+
it( 'wraps payloads with event metadata and activity context', () => {
|
|
68
107
|
const handler = vi.fn();
|
|
69
|
-
|
|
108
|
+
const payload = { foo: 'bar' };
|
|
109
|
+
stepEventBus.on( 'test:event', handler );
|
|
70
110
|
|
|
71
|
-
|
|
111
|
+
stepEventBus.emit( 'test:event', payload );
|
|
72
112
|
|
|
73
|
-
expect( handler ).toHaveBeenCalledWith(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
113
|
+
expect( handler ).toHaveBeenCalledWith( {
|
|
114
|
+
eventId: expect.stringMatching( UUID_V4_REGEX ),
|
|
115
|
+
eventDate: expect.any( Number ),
|
|
116
|
+
...ACTIVITY_CONTEXT,
|
|
117
|
+
payload
|
|
118
|
+
} );
|
|
77
119
|
} );
|
|
78
120
|
|
|
79
|
-
it( '
|
|
121
|
+
it( 'omits activity fields outside activity context', () => {
|
|
80
122
|
const handler = vi.fn();
|
|
81
|
-
|
|
123
|
+
loadMock.mockReturnValue( undefined );
|
|
124
|
+
stepEventBus.on( 'test:event', handler );
|
|
82
125
|
|
|
83
|
-
|
|
84
|
-
messageBus.emit( 'test:event', payload );
|
|
126
|
+
stepEventBus.emit( 'test:event', { foo: 'bar' } );
|
|
85
127
|
|
|
86
|
-
expect(
|
|
87
|
-
|
|
128
|
+
expect( handler ).toHaveBeenCalledWith( {
|
|
129
|
+
eventId: expect.stringMatching( UUID_V4_REGEX ),
|
|
130
|
+
eventDate: expect.any( Number ),
|
|
131
|
+
payload: { foo: 'bar' }
|
|
132
|
+
} );
|
|
88
133
|
} );
|
|
89
|
-
} );
|
|
90
134
|
|
|
91
|
-
|
|
92
|
-
it( 'passes primitive payloads through unchanged', () => {
|
|
135
|
+
it( 'preserves arbitrary payloads unchanged inside the envelope', () => {
|
|
93
136
|
const handler = vi.fn();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
137
|
+
const array = [ 1, 2, 3 ];
|
|
138
|
+
const instance = new Date();
|
|
139
|
+
stepEventBus.on( 'test:event', handler );
|
|
140
|
+
|
|
141
|
+
stepEventBus.emit( 'test:event', 'value' );
|
|
142
|
+
stepEventBus.emit( 'test:event', array );
|
|
143
|
+
stepEventBus.emit( 'test:event', instance );
|
|
144
|
+
stepEventBus.emit( 'test:event' );
|
|
145
|
+
|
|
146
|
+
expect( handler.mock.calls[0][0].payload ).toBe( 'value' );
|
|
147
|
+
expect( handler.mock.calls[1][0].payload ).toBe( array );
|
|
148
|
+
expect( handler.mock.calls[2][0].payload ).toBe( instance );
|
|
149
|
+
expect( handler.mock.calls[3][0] ).toHaveProperty( 'payload', undefined );
|
|
103
150
|
} );
|
|
104
151
|
|
|
105
|
-
it( '
|
|
152
|
+
it( 'keeps payload metadata separate from envelope metadata', () => {
|
|
106
153
|
const handler = vi.fn();
|
|
107
|
-
|
|
154
|
+
const payload = { eventId: 'payload-id', eventDate: 1234 };
|
|
155
|
+
stepEventBus.on( 'test:event', handler );
|
|
108
156
|
|
|
109
|
-
|
|
110
|
-
messageBus.emit( 'test:event' );
|
|
157
|
+
stepEventBus.emit( 'test:event', payload );
|
|
111
158
|
|
|
112
|
-
|
|
113
|
-
expect(
|
|
159
|
+
const envelope = handler.mock.calls[0][0];
|
|
160
|
+
expect( envelope.eventId ).toMatch( UUID_V4_REGEX );
|
|
161
|
+
expect( envelope.eventId ).not.toBe( payload.eventId );
|
|
162
|
+
expect( envelope.eventDate ).not.toBe( payload.eventDate );
|
|
163
|
+
expect( envelope.payload ).toBe( payload );
|
|
114
164
|
} );
|
|
115
165
|
|
|
116
|
-
it( '
|
|
166
|
+
it( 'gives distinct emits distinct eventIds', () => {
|
|
117
167
|
const handler = vi.fn();
|
|
118
|
-
|
|
168
|
+
stepEventBus.on( 'test:event', handler );
|
|
119
169
|
|
|
120
|
-
|
|
170
|
+
stepEventBus.emit( 'test:event', { i: 1 } );
|
|
171
|
+
stepEventBus.emit( 'test:event', { i: 2 } );
|
|
121
172
|
|
|
122
|
-
|
|
173
|
+
const first = handler.mock.calls[0][0].eventId;
|
|
174
|
+
const second = handler.mock.calls[1][0].eventId;
|
|
175
|
+
expect( first ).toMatch( UUID_V4_REGEX );
|
|
176
|
+
expect( second ).toMatch( UUID_V4_REGEX );
|
|
177
|
+
expect( first ).not.toBe( second );
|
|
123
178
|
} );
|
|
124
179
|
|
|
125
|
-
it( 'forwards additional positional
|
|
180
|
+
it( 'forwards additional positional arguments unchanged', () => {
|
|
126
181
|
const handler = vi.fn();
|
|
127
|
-
|
|
182
|
+
stepEventBus.on( 'test:event', handler );
|
|
128
183
|
|
|
129
|
-
|
|
184
|
+
stepEventBus.emit( 'test:event', { foo: 'bar' }, 'extra', 99 );
|
|
130
185
|
|
|
131
186
|
expect( handler ).toHaveBeenCalledWith(
|
|
132
|
-
expect.objectContaining( {
|
|
187
|
+
expect.objectContaining( {
|
|
188
|
+
eventId: expect.stringMatching( UUID_V4_REGEX ),
|
|
189
|
+
payload: { foo: 'bar' }
|
|
190
|
+
} ),
|
|
133
191
|
'extra',
|
|
134
192
|
99
|
|
135
193
|
);
|
package/src/helpers/object.js
CHANGED
|
@@ -44,7 +44,11 @@ export const deepMergeWithResolver = ( base, ...args ) => {
|
|
|
44
44
|
const resolver = args.at( -1 );
|
|
45
45
|
|
|
46
46
|
if ( !isPlainObject( base ) ) {
|
|
47
|
-
throw new Error( 'First argument is not an object.' );
|
|
47
|
+
throw new Error( 'First argument (base object) is not an object.' );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ( typeof resolver !== 'function' ) {
|
|
51
|
+
throw new Error( 'Last argument (resolver) is not a function.' );
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
return objects.reduce( ( merged, object ) => {
|
|
@@ -224,6 +224,11 @@ describe( 'deepMergeWithResolver', () => {
|
|
|
224
224
|
expect( () => deepMergeWithResolver( 'a', {}, ( x, y ) => x + y ) ).toThrow( Error );
|
|
225
225
|
} );
|
|
226
226
|
|
|
227
|
+
it( 'throws when last argument is not a resolver function', () => {
|
|
228
|
+
expect( () => deepMergeWithResolver( { a: 1 }, { a: 2 } ) )
|
|
229
|
+
.toThrow( 'Last argument (resolver) is not a function.' );
|
|
230
|
+
} );
|
|
231
|
+
|
|
227
232
|
it( 'merges multiple objects using the resolver from left to right', () => {
|
|
228
233
|
const resolver = vi.fn( ( x, y ) => `${ x }:${ y }` );
|
|
229
234
|
|
package/src/hooks/index.d.ts
CHANGED
|
@@ -99,35 +99,19 @@ export interface Aggregations {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Common
|
|
102
|
+
* Common hook payload fields
|
|
103
103
|
*/
|
|
104
104
|
export interface HookPayloadBase {
|
|
105
105
|
/** UUID v4 stamped per emit. Stable per-emit idempotency key. */
|
|
106
106
|
eventId: string;
|
|
107
107
|
/** Timestamp of the event */
|
|
108
108
|
eventDate: number;
|
|
109
|
-
/** Information about the current workflow execution */
|
|
110
|
-
workflowDetails: WorkflowDetails;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Common hook payload fields for events associated with an activity.
|
|
115
|
-
*/
|
|
116
|
-
export interface ActivityPayloadBase extends HookPayloadBase {
|
|
117
|
-
/** Temporal's activityInfo(). */
|
|
118
|
-
activityInfo: Info;
|
|
119
|
-
/** Output component kind for the activity, e.g. step or evaluator. */
|
|
120
|
-
outputActivityKind: string;
|
|
121
109
|
}
|
|
122
110
|
|
|
123
111
|
/**
|
|
124
112
|
* Payload passed to the onError() handler when a workflow, activity or runtime error occurs.
|
|
125
113
|
*/
|
|
126
|
-
export interface ErrorHookPayload {
|
|
127
|
-
/** UUID v4 stamped per emit. Stable per-emit idempotency key. */
|
|
128
|
-
eventId: string;
|
|
129
|
-
/** Timestamp of the event */
|
|
130
|
-
eventDate: number;
|
|
114
|
+
export interface ErrorHookPayload extends HookPayloadBase {
|
|
131
115
|
/** Origin of the error: workflow execution, activity execution, or runtime. */
|
|
132
116
|
source: 'workflow' | 'activity' | 'runtime';
|
|
133
117
|
/** Information about the current workflow execution */
|
|
@@ -135,45 +119,60 @@ export interface ErrorHookPayload {
|
|
|
135
119
|
/** Temporal's activityInfo(). If source is activity */
|
|
136
120
|
activityInfo?: Info;
|
|
137
121
|
/** Output component kind for the activity, e.g. step, evaluator, or internal_step. */
|
|
138
|
-
outputActivityKind
|
|
122
|
+
outputActivityKind: string;
|
|
139
123
|
/** Attribute totals collected during the activity execution. */
|
|
140
124
|
aggregations?: Aggregations | null;
|
|
141
125
|
/** The error thrown. */
|
|
142
126
|
error: Error;
|
|
143
127
|
}
|
|
144
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Common hook payload fields for events associated with an workflow.
|
|
131
|
+
*/
|
|
132
|
+
export interface WorkflowPayloadBase extends HookPayloadBase {
|
|
133
|
+
/** Information about the current workflow execution */
|
|
134
|
+
workflowDetails: WorkflowDetails;
|
|
135
|
+
}
|
|
136
|
+
|
|
145
137
|
/**
|
|
146
138
|
* Payload passed to the onWorkflowStart() handler when a workflow run begins.
|
|
147
139
|
*/
|
|
148
|
-
export type WorkflowStartHookPayload =
|
|
140
|
+
export type WorkflowStartHookPayload = WorkflowPayloadBase;
|
|
149
141
|
|
|
150
142
|
/**
|
|
151
143
|
* Payload passed to the onWorkflowEnd() handler when a workflow run completes successfully.
|
|
152
144
|
*/
|
|
153
|
-
export type WorkflowEndHookPayload =
|
|
145
|
+
export type WorkflowEndHookPayload = WorkflowPayloadBase;
|
|
154
146
|
|
|
155
147
|
/**
|
|
156
148
|
* Payload passed to the onWorkflowError() handler when a workflow run fails.
|
|
157
149
|
*/
|
|
158
|
-
export interface WorkflowErrorHookPayload extends
|
|
150
|
+
export interface WorkflowErrorHookPayload extends WorkflowPayloadBase {
|
|
159
151
|
/** The error thrown. */
|
|
160
152
|
error: Error;
|
|
161
153
|
}
|
|
162
154
|
|
|
163
155
|
/**
|
|
164
|
-
* Common
|
|
156
|
+
* Common hook payload fields for events associated with an activity.
|
|
165
157
|
*/
|
|
166
|
-
export
|
|
158
|
+
export interface ActivityPayloadBase extends HookPayloadBase {
|
|
159
|
+
/** Information about the current workflow execution */
|
|
160
|
+
workflowDetails: WorkflowDetails;
|
|
161
|
+
/** Temporal's activityInfo(). */
|
|
162
|
+
activityInfo: Info;
|
|
163
|
+
/** Output component kind for the activity, e.g. step, evaluator, or internal_step. */
|
|
164
|
+
outputActivityKind: string;
|
|
165
|
+
}
|
|
167
166
|
|
|
168
167
|
/**
|
|
169
168
|
* Payload passed to the onActivityStart() handler when an activity starts.
|
|
170
169
|
*/
|
|
171
|
-
export type ActivityStartHookPayload =
|
|
170
|
+
export type ActivityStartHookPayload = ActivityPayloadBase;
|
|
172
171
|
|
|
173
172
|
/**
|
|
174
173
|
* Payload passed to the onActivityEnd() handler when an activity completes successfully.
|
|
175
174
|
*/
|
|
176
|
-
export interface ActivityEndHookPayload extends
|
|
175
|
+
export interface ActivityEndHookPayload extends ActivityPayloadBase {
|
|
177
176
|
/** Attribute totals collected during the activity execution. */
|
|
178
177
|
aggregations: Aggregations | null;
|
|
179
178
|
}
|
|
@@ -181,7 +180,7 @@ export interface ActivityEndHookPayload extends ActivityHookPayload {
|
|
|
181
180
|
/**
|
|
182
181
|
* Payload passed to the onActivityError() handler when an activity fails.
|
|
183
182
|
*/
|
|
184
|
-
export interface ActivityErrorHookPayload extends
|
|
183
|
+
export interface ActivityErrorHookPayload extends ActivityPayloadBase {
|
|
185
184
|
/** Attribute totals collected during the activity execution. */
|
|
186
185
|
aggregations: Aggregations | null;
|
|
187
186
|
/** The error thrown. */
|
|
@@ -233,8 +232,6 @@ export declare function onWorkflowError( handler: ( payload: WorkflowErrorHookPa
|
|
|
233
232
|
/**
|
|
234
233
|
* Register a handler to be invoked when an activity starts.
|
|
235
234
|
*
|
|
236
|
-
* Excludes internal activities.
|
|
237
|
-
*
|
|
238
235
|
* @param handler - Function called with the activity start payload.
|
|
239
236
|
*/
|
|
240
237
|
export declare function onActivityStart( handler: ( payload: ActivityStartHookPayload ) => void ): void;
|
|
@@ -242,8 +239,6 @@ export declare function onActivityStart( handler: ( payload: ActivityStartHookPa
|
|
|
242
239
|
/**
|
|
243
240
|
* Register a handler to be invoked when an activity completes successfully.
|
|
244
241
|
*
|
|
245
|
-
* Excludes internal activities.
|
|
246
|
-
*
|
|
247
242
|
* @param handler - Function called with the activity end payload.
|
|
248
243
|
*/
|
|
249
244
|
export declare function onActivityEnd( handler: ( payload: ActivityEndHookPayload ) => void ): void;
|
|
@@ -251,24 +246,32 @@ export declare function onActivityEnd( handler: ( payload: ActivityEndHookPayloa
|
|
|
251
246
|
/**
|
|
252
247
|
* Register a handler to be invoked when an activity fails.
|
|
253
248
|
*
|
|
254
|
-
* Excludes internal activities.
|
|
255
|
-
*
|
|
256
249
|
* @param handler - Function called with the activity error payload.
|
|
257
250
|
*/
|
|
258
251
|
export declare function onActivityError( handler: ( payload: ActivityErrorHookPayload ) => void ): void;
|
|
259
252
|
|
|
260
|
-
/**
|
|
261
|
-
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
/** Temporal's activityInfo(). */
|
|
265
|
-
activityInfo
|
|
266
|
-
/** Output component kind
|
|
253
|
+
/** Framework metadata, optional activity context, and the emitted payload. */
|
|
254
|
+
export type ExternalHookPayload<TPayload = unknown> = HookPayloadBase & {
|
|
255
|
+
/** Information about the current workflow execution, when emitted from an activity. */
|
|
256
|
+
workflowDetails?: WorkflowDetails;
|
|
257
|
+
/** Temporal's activityInfo(), when emitted from an activity. */
|
|
258
|
+
activityInfo?: Info;
|
|
259
|
+
/** Output component kind, when emitted from an activity. */
|
|
267
260
|
outputActivityKind?: string;
|
|
268
|
-
|
|
261
|
+
/** The emitted payload */
|
|
262
|
+
payload: TPayload | undefined;
|
|
263
|
+
};
|
|
269
264
|
|
|
270
|
-
|
|
271
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Emit a custom event from the current activity.
|
|
267
|
+
*
|
|
268
|
+
* @param eventName - The name of the event to emit.
|
|
269
|
+
* @param payload - Optional value forwarded to on() handlers.
|
|
270
|
+
*/
|
|
271
|
+
export declare function emit(
|
|
272
|
+
eventName: string,
|
|
273
|
+
payload?: unknown
|
|
274
|
+
): boolean;
|
|
272
275
|
|
|
273
276
|
/**
|
|
274
277
|
* Register a handler to be invoked when a given event happens
|
|
@@ -276,7 +279,7 @@ export type OnHookPayload<TAttributes extends Record<string, unknown> = Record<s
|
|
|
276
279
|
* @param eventName - The name of the event to subscribe
|
|
277
280
|
* @param handler - Function called with the event payload
|
|
278
281
|
*/
|
|
279
|
-
export declare function on<
|
|
282
|
+
export declare function on<TPayload = unknown>(
|
|
280
283
|
eventName: string,
|
|
281
|
-
handler: (
|
|
284
|
+
handler: ( event: ExternalHookPayload<TPayload> ) => void
|
|
282
285
|
): void;
|