@outputai/core 0.10.1-dev.b7b2fbe.0 → 0.10.1-next.14a191e.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 +8 -7
- package/src/bus.js +58 -20
- package/src/bus.spec.js +135 -77
- package/src/helpers/fetch.js +1 -1
- 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 +56 -49
- package/src/hooks/index.spec.js +88 -97
- package/src/hooks/pending_hooks.js +24 -0
- package/src/hooks/pending_hooks.spec.js +62 -0
- package/src/interface/index.js +2 -1
- package/src/interface/workflow_utils.d.ts +15 -0
- package/src/interface/workflow_utils.js +19 -0
- package/src/interface/workflow_utils.spec.js +82 -1
- 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/configs.js +0 -3
- package/src/worker/global_functions.js +2 -2
- package/src/worker/global_functions.spec.js +3 -3
- package/src/worker/index.js +14 -10
- package/src/worker/index.spec.js +13 -8
- 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/src/worker/proxy.js +0 -20
- package/src/worker/proxy.spec.js +0 -51
package/src/worker/sinks.spec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { BusEventType, ComponentType } from '#consts';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const mainEventBusMock = vi.hoisted( () => ( {
|
|
5
5
|
emit: vi.fn()
|
|
6
6
|
} ) );
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ const createWorkflowDetailsMock = vi.hoisted( () => vi.fn( workflowInfo => ( {
|
|
|
15
15
|
runId: workflowInfo.runId
|
|
16
16
|
} ) ) );
|
|
17
17
|
|
|
18
|
-
vi.mock( '#bus', () => ( {
|
|
18
|
+
vi.mock( '#bus', () => ( { mainEventBus: mainEventBusMock } ) );
|
|
19
19
|
vi.mock( '#tracing', () => ( {
|
|
20
20
|
addEventStart: addEventStartMock,
|
|
21
21
|
addEventEnd: addEventEndMock,
|
|
@@ -69,7 +69,7 @@ describe( 'worker/sinks', () => {
|
|
|
69
69
|
} );
|
|
70
70
|
|
|
71
71
|
expect( createWorkflowDetailsMock ).toHaveBeenCalledWith( workflowInfo );
|
|
72
|
-
expect(
|
|
72
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_LOG, {
|
|
73
73
|
level: 'info',
|
|
74
74
|
message: 'workflow detail',
|
|
75
75
|
metadata,
|
|
@@ -83,7 +83,7 @@ describe( 'worker/sinks', () => {
|
|
|
83
83
|
|
|
84
84
|
sinks.workflow.start.fn( workflowInfo, input );
|
|
85
85
|
|
|
86
|
-
expect(
|
|
86
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_START, { workflowDetails } );
|
|
87
87
|
expect( addEventStartMock ).toHaveBeenCalledWith( {
|
|
88
88
|
id: 'run-1',
|
|
89
89
|
kind: ComponentType.WORKFLOW,
|
|
@@ -99,7 +99,7 @@ describe( 'worker/sinks', () => {
|
|
|
99
99
|
|
|
100
100
|
sinks.workflow.start.fn( { ...workflowInfo, memo: {} }, { value: 'input' } );
|
|
101
101
|
|
|
102
|
-
expect(
|
|
102
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_START, { workflowDetails } );
|
|
103
103
|
expect( addEventStartMock ).not.toHaveBeenCalled();
|
|
104
104
|
} );
|
|
105
105
|
|
|
@@ -109,7 +109,7 @@ describe( 'worker/sinks', () => {
|
|
|
109
109
|
|
|
110
110
|
sinks.workflow.end.fn( workflowInfo, output );
|
|
111
111
|
|
|
112
|
-
expect(
|
|
112
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_END, { workflowDetails } );
|
|
113
113
|
expect( addEventEndMock ).toHaveBeenCalledWith( {
|
|
114
114
|
id: 'run-1',
|
|
115
115
|
details: output,
|
|
@@ -122,7 +122,7 @@ describe( 'worker/sinks', () => {
|
|
|
122
122
|
|
|
123
123
|
sinks.workflow.end.fn( { ...workflowInfo, memo: {} }, { value: 'output' } );
|
|
124
124
|
|
|
125
|
-
expect(
|
|
125
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_END, { workflowDetails } );
|
|
126
126
|
expect( addEventEndMock ).not.toHaveBeenCalled();
|
|
127
127
|
} );
|
|
128
128
|
|
|
@@ -132,7 +132,7 @@ describe( 'worker/sinks', () => {
|
|
|
132
132
|
|
|
133
133
|
sinks.workflow.error.fn( workflowInfo, error );
|
|
134
134
|
|
|
135
|
-
expect(
|
|
135
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_ERROR, { workflowDetails, error } );
|
|
136
136
|
expect( addEventErrorMock ).toHaveBeenCalledWith( {
|
|
137
137
|
id: 'run-1',
|
|
138
138
|
details: error,
|
|
@@ -146,7 +146,7 @@ describe( 'worker/sinks', () => {
|
|
|
146
146
|
|
|
147
147
|
sinks.workflow.error.fn( { ...workflowInfo, memo: {} }, error );
|
|
148
148
|
|
|
149
|
-
expect(
|
|
149
|
+
expect( mainEventBusMock.emit ).toHaveBeenCalledWith( BusEventType.WORKFLOW_ERROR, { workflowDetails, error } );
|
|
150
150
|
expect( addEventErrorMock ).not.toHaveBeenCalled();
|
|
151
151
|
} );
|
|
152
152
|
|
package/src/worker/proxy.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { EnvHttpProxyAgent, setGlobalDispatcher } from 'undici';
|
|
2
|
-
import { createChildLogger } from '#logger';
|
|
3
|
-
|
|
4
|
-
const log = createChildLogger( 'Proxy' );
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Routes all `fetch()` calls (including those inside Temporal activities)
|
|
8
|
-
* through an HTTP/HTTPS proxy when standard proxy env vars are set.
|
|
9
|
-
* No-op when none are set.
|
|
10
|
-
*/
|
|
11
|
-
export const bootstrapFetchProxy = () => {
|
|
12
|
-
const httpProxyUrl = process.env.http_proxy ?? process.env.HTTP_PROXY;
|
|
13
|
-
const httpsProxyUrl = process.env.https_proxy ?? process.env.HTTPS_PROXY;
|
|
14
|
-
|
|
15
|
-
if ( httpProxyUrl?.length > 0 || httpsProxyUrl?.length > 0 ) {
|
|
16
|
-
log.info( 'Proxy env vars detected, setting up global fetch dispatcher EnvHttpProxyAgent', { httpProxyUrl, httpsProxyUrl } );
|
|
17
|
-
/* Ignore HTTP/2. Check: https://github.com/growthxai/output/issues/299 */
|
|
18
|
-
setGlobalDispatcher( new EnvHttpProxyAgent( { allowH2: false } ) );
|
|
19
|
-
}
|
|
20
|
-
};
|
package/src/worker/proxy.spec.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
|
|
3
|
-
const mockSetGlobalDispatcher = vi.fn();
|
|
4
|
-
const MockEnvHttpProxyAgent = vi.fn();
|
|
5
|
-
const mockLogger = { info: vi.fn(), warn: vi.fn(), error: vi.fn() };
|
|
6
|
-
|
|
7
|
-
vi.mock( 'undici', () => ( {
|
|
8
|
-
EnvHttpProxyAgent: MockEnvHttpProxyAgent,
|
|
9
|
-
setGlobalDispatcher: mockSetGlobalDispatcher
|
|
10
|
-
} ) );
|
|
11
|
-
|
|
12
|
-
vi.mock( '#logger', () => ( {
|
|
13
|
-
createChildLogger: () => mockLogger
|
|
14
|
-
} ) );
|
|
15
|
-
|
|
16
|
-
describe( 'worker/proxy', () => {
|
|
17
|
-
const proxyEnv = [ 'http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY' ];
|
|
18
|
-
|
|
19
|
-
beforeEach( () => {
|
|
20
|
-
vi.clearAllMocks();
|
|
21
|
-
for ( const key of proxyEnv ) {
|
|
22
|
-
delete process.env[key];
|
|
23
|
-
}
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
afterEach( () => {
|
|
27
|
-
vi.resetModules();
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'does nothing when no proxy env vars are set', async () => {
|
|
31
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
32
|
-
bootstrapFetchProxy();
|
|
33
|
-
|
|
34
|
-
expect( MockEnvHttpProxyAgent ).not.toHaveBeenCalled();
|
|
35
|
-
expect( mockSetGlobalDispatcher ).not.toHaveBeenCalled();
|
|
36
|
-
expect( mockLogger.info ).not.toHaveBeenCalled();
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
it( 'sets global dispatcher when proxy URL is available', async () => {
|
|
40
|
-
process.env.HTTP_PROXY = 'http://proxy:8080/';
|
|
41
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
42
|
-
bootstrapFetchProxy();
|
|
43
|
-
|
|
44
|
-
expect( MockEnvHttpProxyAgent ).toHaveBeenCalledWith( { allowH2: false } );
|
|
45
|
-
expect( mockSetGlobalDispatcher ).toHaveBeenCalledTimes( 1 );
|
|
46
|
-
expect( mockLogger.info ).toHaveBeenCalledWith(
|
|
47
|
-
'Proxy env vars detected, setting up global fetch dispatcher EnvHttpProxyAgent',
|
|
48
|
-
{ httpProxyUrl: 'http://proxy:8080/', httpsProxyUrl: undefined }
|
|
49
|
-
);
|
|
50
|
-
} );
|
|
51
|
-
} );
|