@outputai/core 0.16.0 → 0.16.1-next.a7e9891.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/consts.js +4 -3
- package/src/hooks/index.js +1 -1
- package/src/interface/logger.js +4 -4
- package/src/llm/utils/models_pricing_snapshot.json +1 -1
- package/src/worker/global_functions.js +11 -6
- package/src/worker/index.js +4 -4
- package/src/worker/log_hooks.js +8 -0
package/package.json
CHANGED
package/src/consts.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export const ACTIVITY_GET_TRACE_DESTINATIONS = '__internal#getTraceDestinations';
|
|
2
2
|
export const ACTIVITY_OPTIONS_FILENAME = '__activity_options.js';
|
|
3
3
|
export const ACTIVITY_SEND_HTTP_REQUEST = '__internal#sendHttpRequest';
|
|
4
|
-
export const ACTIVITY_LOGGER_SYMBOL = Symbol.for( '__activity_logger' );
|
|
5
|
-
export const METADATA_ACCESS_SYMBOL = Symbol( '__metadata' );
|
|
6
4
|
export const WORKFLOW_CATALOG = '$catalog';
|
|
7
5
|
export const WORKFLOW_OPTIONS_FILENAME = '__workflow_options.js';
|
|
8
6
|
export const WORKFLOWS_INDEX_FILENAME = '__workflows_entrypoint.js';
|
|
9
7
|
|
|
10
8
|
export const INVOKE_ACTIVITY_SYMBOL = Symbol.for( '@outputai/core:__invoke_activity' );
|
|
9
|
+
export const METADATA_ACCESS_SYMBOL = Symbol( '__metadata' );
|
|
10
|
+
export const WORKER_LOGGER_SYMBOL = Symbol.for( '@outputai/core:__worker_logger' );
|
|
11
11
|
|
|
12
12
|
export const ComponentType = {
|
|
13
13
|
EVALUATOR: 'evaluator',
|
|
@@ -33,7 +33,8 @@ export const BusEventType = {
|
|
|
33
33
|
ACTIVITY_LOG: 'activity:log',
|
|
34
34
|
ACTIVITY_START: 'activity:start',
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
WORKER_ERROR: 'worker:error',
|
|
37
|
+
WORKER_LOG: 'worker:log'
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
export const WorkflowSpecialOutput = {
|
package/src/hooks/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const onError = cb => {
|
|
|
29
29
|
callHookCb( cb, { source: 'activity', ...payload }, 'onError' ) );
|
|
30
30
|
mainEventBus.on( BusEventType.WORKFLOW_ERROR, async payload =>
|
|
31
31
|
callHookCb( cb, { source: 'workflow', ...payload }, 'onError' ) );
|
|
32
|
-
mainEventBus.on( BusEventType.
|
|
32
|
+
mainEventBus.on( BusEventType.WORKER_ERROR, async payload =>
|
|
33
33
|
callHookCb( cb, { source: 'runtime', ...payload }, 'onError' ) );
|
|
34
34
|
};
|
|
35
35
|
|
package/src/interface/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inWorkflowContext } from '@temporalio/workflow';
|
|
2
2
|
import { proxySinks } from '@temporalio/workflow';
|
|
3
|
-
import {
|
|
3
|
+
import { WORKER_LOGGER_SYMBOL } from '#consts';
|
|
4
4
|
import { isPlainObject } from '#helpers/object';
|
|
5
5
|
|
|
6
6
|
const reservedMetadataFields = new Set( [
|
|
@@ -52,9 +52,9 @@ const log = ( level, namespace, message, metadata ) => {
|
|
|
52
52
|
// When inside workflow, use sinks to send logs out
|
|
53
53
|
if ( inWorkflowContext() ) {
|
|
54
54
|
sinks.workflow.log( { level, ...sanitized } );
|
|
55
|
-
// When
|
|
56
|
-
} else if ( typeof globalThis[
|
|
57
|
-
globalThis[
|
|
55
|
+
// When on a worker (activity or host), use the global function to ship logs
|
|
56
|
+
} else if ( typeof globalThis[WORKER_LOGGER_SYMBOL] === 'function' ) {
|
|
57
|
+
globalThis[WORKER_LOGGER_SYMBOL]( { level, ...sanitized } );
|
|
58
58
|
// This fallback is used on unit tests
|
|
59
59
|
} else {
|
|
60
60
|
console[levelToConsole[level]]( sanitized.message, sanitized.metadata );
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { mainEventBus } from '#bus';
|
|
2
|
-
import {
|
|
3
|
-
import { activityInfo as activityInfoFn } from '@temporalio/activity';
|
|
2
|
+
import { WORKER_LOGGER_SYMBOL, BusEventType } from '#consts';
|
|
3
|
+
import { activityInfo as activityInfoFn, asyncLocalStorage } from '@temporalio/activity';
|
|
4
4
|
import { assignImmutableProperty } from '#helpers/object';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Sets global functions on globalThis
|
|
8
8
|
*/
|
|
9
9
|
export const bindGlobalFunctions = () => {
|
|
10
|
-
/** Defines the
|
|
11
|
-
assignImmutableProperty( globalThis,
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Defines the worker logger function, accessible from activity and worker (host) context via logger interface */
|
|
11
|
+
assignImmutableProperty( globalThis, WORKER_LOGGER_SYMBOL, ( { level, message, metadata } ) => {
|
|
12
|
+
const context = asyncLocalStorage.getStore();
|
|
13
|
+
if ( context ) { // means we are in an activity
|
|
14
|
+
mainEventBus.emit( BusEventType.ACTIVITY_LOG, { level, message, metadata, activityInfo: activityInfoFn() } );
|
|
15
|
+
} else { // means we are at the worker level, maybe a hook, but not inside the sandbox
|
|
16
|
+
mainEventBus.emit( BusEventType.WORKER_LOG, { level, message, metadata } );
|
|
17
|
+
}
|
|
18
|
+
} );
|
|
14
19
|
};
|
package/src/worker/index.js
CHANGED
|
@@ -52,6 +52,9 @@ const execute = async () => {
|
|
|
52
52
|
log.info( 'Setting up Temporal Logger...' );
|
|
53
53
|
run( setupTemporalLogger );
|
|
54
54
|
|
|
55
|
+
log.info( 'Binding globals...' );
|
|
56
|
+
run( bindGlobalFunctions );
|
|
57
|
+
|
|
55
58
|
log.info( 'Loading config...', { callerDir } );
|
|
56
59
|
await run( () => loadHooks( callerDir ) );
|
|
57
60
|
|
|
@@ -73,9 +76,6 @@ const execute = async () => {
|
|
|
73
76
|
log.info( 'Computing catalog source code hash...' );
|
|
74
77
|
const catalogHash = await run( () => hashSourceCode( callerDir ) );
|
|
75
78
|
|
|
76
|
-
log.info( 'Binding globals...' );
|
|
77
|
-
run( bindGlobalFunctions );
|
|
78
|
-
|
|
79
79
|
log.info( 'Connecting Temporal...' );
|
|
80
80
|
const proxy = grpcProxy ? { type: 'http-connect', targetHost: grpcProxy } : undefined;
|
|
81
81
|
if ( proxy ) {
|
|
@@ -139,7 +139,7 @@ execute()
|
|
|
139
139
|
const hasError = signal.aborted && !( signal.reason instanceof KillSignError );
|
|
140
140
|
if ( hasError ) {
|
|
141
141
|
log.error( 'Worker error', { error: serializeError( signal.reason ) } );
|
|
142
|
-
mainEventBus.emit( BusEventType.
|
|
142
|
+
mainEventBus.emit( BusEventType.WORKER_ERROR, { error: signal.reason } );
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
log.info( 'Flushing hook callbacks...' );
|
package/src/worker/log_hooks.js
CHANGED
|
@@ -5,6 +5,7 @@ import { serializeError } from '#helpers/error_serializer';
|
|
|
5
5
|
|
|
6
6
|
const activityLog = createChildLogger( 'Activity' );
|
|
7
7
|
const workflowLog = createChildLogger( 'Workflow' );
|
|
8
|
+
const workerLog = createChildLogger( 'Worker' );
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Intercepts internal bus events for activity and workflow lifecycle and log them
|
|
@@ -56,6 +57,13 @@ mainEventBus.on( BusEventType.ACTIVITY_LOG, ( { level, message, metadata, activi
|
|
|
56
57
|
} )
|
|
57
58
|
);
|
|
58
59
|
|
|
60
|
+
/*
|
|
61
|
+
╔═══════════════╗
|
|
62
|
+
║ Worker events ║
|
|
63
|
+
╚═══════════════╝
|
|
64
|
+
*/
|
|
65
|
+
mainEventBus.on( BusEventType.WORKER_LOG, ( { level, message, metadata } ) => workerLog[level]( message, metadata ) );
|
|
66
|
+
|
|
59
67
|
/*
|
|
60
68
|
╔═════════════════╗
|
|
61
69
|
║ Workflow events ║
|