@outputai/core 0.4.1-dev.06c2b50.0 → 0.4.1-dev.10cf346.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
CHANGED
package/src/hooks/index.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ export interface ErrorHookPayload {
|
|
|
16
16
|
* Payload passed to the onWorkflowStart handler when a workflow run begins.
|
|
17
17
|
*/
|
|
18
18
|
export interface WorkflowStartHookPayload {
|
|
19
|
-
/**
|
|
19
|
+
/** Workflow id (stable across retries / continue-as-new). */
|
|
20
20
|
id: string;
|
|
21
|
+
/** Temporal run id for the current execution attempt. */
|
|
22
|
+
runId: string;
|
|
21
23
|
/** Name of the workflow. */
|
|
22
24
|
name: string;
|
|
23
25
|
}
|
|
@@ -26,8 +28,10 @@ export interface WorkflowStartHookPayload {
|
|
|
26
28
|
* Payload passed to the onWorkflowEnd handler when a workflow run completes successfully.
|
|
27
29
|
*/
|
|
28
30
|
export interface WorkflowEndHookPayload {
|
|
29
|
-
/**
|
|
31
|
+
/** Workflow id (stable across retries / continue-as-new). */
|
|
30
32
|
id: string;
|
|
33
|
+
/** Temporal run id for the current execution attempt. */
|
|
34
|
+
runId: string;
|
|
31
35
|
/** Name of the workflow. */
|
|
32
36
|
name: string;
|
|
33
37
|
/** Duration of the workflow run in milliseconds. */
|
|
@@ -38,8 +42,10 @@ export interface WorkflowEndHookPayload {
|
|
|
38
42
|
* Payload passed to the onWorkflowError handler when a workflow run fails.
|
|
39
43
|
*/
|
|
40
44
|
export interface WorkflowErrorHookPayload {
|
|
41
|
-
/**
|
|
45
|
+
/** Workflow id (stable across retries / continue-as-new). */
|
|
42
46
|
id: string;
|
|
47
|
+
/** Temporal run id for the current execution attempt. */
|
|
48
|
+
runId: string;
|
|
43
49
|
/** Name of the workflow. */
|
|
44
50
|
name: string;
|
|
45
51
|
/** Elapsed time before failure in milliseconds. */
|
package/src/hooks/index.js
CHANGED
|
@@ -34,16 +34,16 @@ export const onBeforeWorkerStart = handler => messageBus.on( BusEventType.WORKER
|
|
|
34
34
|
safeInvoke( handler, undefined, 'onBeforeWorkerStart' ) );
|
|
35
35
|
|
|
36
36
|
/** Listen to workflow start events, excludes catalog workflow */
|
|
37
|
-
export const onWorkflowStart = handler => messageBus.on( BusEventType.WORKFLOW_START, ( { id, name } ) =>
|
|
38
|
-
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, name }, 'onWorkflowStart' ) : null );
|
|
37
|
+
export const onWorkflowStart = handler => messageBus.on( BusEventType.WORKFLOW_START, ( { id, runId, name } ) =>
|
|
38
|
+
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, runId, name }, 'onWorkflowStart' ) : null );
|
|
39
39
|
|
|
40
40
|
/** Listen to workflow end events, excludes catalog workflow */
|
|
41
|
-
export const onWorkflowEnd = handler => messageBus.on( BusEventType.WORKFLOW_END, ( { id, name, duration } ) =>
|
|
42
|
-
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, name, duration }, 'onWorkflowEnd' ) : null );
|
|
41
|
+
export const onWorkflowEnd = handler => messageBus.on( BusEventType.WORKFLOW_END, ( { id, runId, name, duration } ) =>
|
|
42
|
+
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, runId, name, duration }, 'onWorkflowEnd' ) : null );
|
|
43
43
|
|
|
44
44
|
/** Listen to workflow error events, excludes catalog workflow */
|
|
45
|
-
export const onWorkflowError = handler => messageBus.on( BusEventType.WORKFLOW_ERROR, ( { id, name, duration, error } ) =>
|
|
46
|
-
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, name, duration, error }, 'onWorkflowError' ) : null );
|
|
45
|
+
export const onWorkflowError = handler => messageBus.on( BusEventType.WORKFLOW_ERROR, ( { id, runId, name, duration, error } ) =>
|
|
46
|
+
WORKFLOW_CATALOG !== name ? safeInvoke( handler, { id, runId, name, duration, error }, 'onWorkflowError' ) : null );
|
|
47
47
|
|
|
48
48
|
/** Generic listener for events emitted elsewhere (outside core) */
|
|
49
49
|
export const on = ( eventName, handler ) => messageBus.on( `external:${eventName}`, payload =>
|
|
@@ -63,7 +63,18 @@ export type WorkflowContext<
|
|
|
63
63
|
*
|
|
64
64
|
* @see {@link https://docs.temporal.io/workflow-execution/workflowid-runid#workflow-id}
|
|
65
65
|
*/
|
|
66
|
-
workflowId: string
|
|
66
|
+
workflowId: string,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Internal Temporal run id for the current execution attempt.
|
|
70
|
+
*
|
|
71
|
+
* A single `workflowId` can map to multiple `runId`s when a workflow is
|
|
72
|
+
* retried, reset, or continued-as-new. The current run can be pinned in
|
|
73
|
+
* downstream `/workflow/{id}/runs/{rid}/...` API calls.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://docs.temporal.io/workflow-execution/workflowid-runid#run-id}
|
|
76
|
+
*/
|
|
77
|
+
runId: string
|
|
67
78
|
}
|
|
68
79
|
};
|
|
69
80
|
|
|
@@ -39,15 +39,20 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
|
|
|
39
39
|
// this returns a plain function, for example, in unit tests
|
|
40
40
|
if ( !inWorkflowContext() ) {
|
|
41
41
|
validateWithSchema( inputSchema, input, `Workflow ${name} input` );
|
|
42
|
-
const context = Context.build( {
|
|
42
|
+
const context = Context.build( {
|
|
43
|
+
workflowId: 'test-workflow',
|
|
44
|
+
runId: 'test-run',
|
|
45
|
+
continueAsNew: async () => {},
|
|
46
|
+
isContinueAsNewSuggested: () => false
|
|
47
|
+
} );
|
|
43
48
|
const output = await fn( input, deepMerge( context, extra.context ) );
|
|
44
49
|
validateWithSchema( outputSchema, output, `Workflow ${name} output` );
|
|
45
50
|
return output;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
const { workflowId, memo, startTime } = workflowInfo();
|
|
53
|
+
const { workflowId, runId, memo, startTime } = workflowInfo();
|
|
49
54
|
|
|
50
|
-
const context = Context.build( { workflowId, continueAsNew, isContinueAsNewSuggested: () => workflowInfo().continueAsNewSuggested } );
|
|
55
|
+
const context = Context.build( { workflowId, runId, continueAsNew, isContinueAsNewSuggested: () => workflowInfo().continueAsNewSuggested } );
|
|
51
56
|
|
|
52
57
|
// Root workflows will not have the execution context yet, since it is set here.
|
|
53
58
|
const isRoot = !memo.executionContext;
|
|
@@ -57,6 +62,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
|
|
|
57
62
|
It will be used to as context for tracing (connecting events) */
|
|
58
63
|
const executionContext = memo.executionContext ?? {
|
|
59
64
|
workflowId,
|
|
65
|
+
runId,
|
|
60
66
|
workflowName: name,
|
|
61
67
|
disableTrace,
|
|
62
68
|
startTime: startTime.getTime()
|
|
@@ -7,11 +7,12 @@ export class Context {
|
|
|
7
7
|
* Builds a new context instance
|
|
8
8
|
* @param {object} options - Arguments to build a new context instance
|
|
9
9
|
* @param {string} workflowId
|
|
10
|
+
* @param {string} runId
|
|
10
11
|
* @param {function} continueAsNew
|
|
11
12
|
* @param {function} isContinueAsNewSuggested
|
|
12
13
|
* @returns {object} context
|
|
13
14
|
*/
|
|
14
|
-
static build( { workflowId, continueAsNew, isContinueAsNewSuggested } ) {
|
|
15
|
+
static build( { workflowId, runId, continueAsNew, isContinueAsNewSuggested } ) {
|
|
15
16
|
return {
|
|
16
17
|
/**
|
|
17
18
|
* Control namespace: This object adds functions to interact with Temporal flow mechanisms
|
|
@@ -24,7 +25,8 @@ export class Context {
|
|
|
24
25
|
* Info namespace: abstracts workflowInfo()
|
|
25
26
|
*/
|
|
26
27
|
info: {
|
|
27
|
-
workflowId
|
|
28
|
+
workflowId,
|
|
29
|
+
runId
|
|
28
30
|
}
|
|
29
31
|
};
|
|
30
32
|
}
|
package/src/worker/sinks.js
CHANGED
|
@@ -11,8 +11,8 @@ export const sinks = {
|
|
|
11
11
|
workflow: {
|
|
12
12
|
start: {
|
|
13
13
|
fn: ( workflowInfo, input ) => {
|
|
14
|
-
const { workflowId: id, workflowType: name, memo: { parentId, executionContext } } = workflowInfo;
|
|
15
|
-
messageBus.emit( BusEventType.WORKFLOW_START, { id, name } );
|
|
14
|
+
const { workflowId: id, runId, workflowType: name, memo: { parentId, executionContext } } = workflowInfo;
|
|
15
|
+
messageBus.emit( BusEventType.WORKFLOW_START, { id, runId, name } );
|
|
16
16
|
if ( executionContext ) { // filters out internal workflows
|
|
17
17
|
Tracing.addEventStart( { id, kind: ComponentType.WORKFLOW, name, details: input, parentId, executionContext } );
|
|
18
18
|
}
|
|
@@ -22,8 +22,8 @@ export const sinks = {
|
|
|
22
22
|
|
|
23
23
|
end: {
|
|
24
24
|
fn: ( workflowInfo, output ) => {
|
|
25
|
-
const { workflowId: id, workflowType: name, startTime, memo: { executionContext } } = workflowInfo;
|
|
26
|
-
messageBus.emit( BusEventType.WORKFLOW_END, { id, name, duration: Date.now() - startTime.getTime() } );
|
|
25
|
+
const { workflowId: id, runId, workflowType: name, startTime, memo: { executionContext } } = workflowInfo;
|
|
26
|
+
messageBus.emit( BusEventType.WORKFLOW_END, { id, runId, name, duration: Date.now() - startTime.getTime() } );
|
|
27
27
|
if ( executionContext ) { // filters out internal workflows
|
|
28
28
|
Tracing.addEventEnd( { id, details: output, executionContext } );
|
|
29
29
|
}
|
|
@@ -33,8 +33,8 @@ export const sinks = {
|
|
|
33
33
|
|
|
34
34
|
error: {
|
|
35
35
|
fn: ( workflowInfo, error ) => {
|
|
36
|
-
const { workflowId: id, workflowType: name, startTime, memo: { executionContext } } = workflowInfo;
|
|
37
|
-
messageBus.emit( BusEventType.WORKFLOW_ERROR, { id, name, error, duration: Date.now() - startTime.getTime() } );
|
|
36
|
+
const { workflowId: id, runId, workflowType: name, startTime, memo: { executionContext } } = workflowInfo;
|
|
37
|
+
messageBus.emit( BusEventType.WORKFLOW_ERROR, { id, runId, name, error, duration: Date.now() - startTime.getTime() } );
|
|
38
38
|
if ( executionContext ) { // filters out internal workflows
|
|
39
39
|
Tracing.addEventError( { id, details: error, executionContext } );
|
|
40
40
|
}
|