@output.ai/core 0.1.12 → 0.1.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@output.ai/core",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "The core module of the output framework",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.d.ts CHANGED
@@ -24,13 +24,25 @@ type AnyZodSchema = z.ZodType<any, any, any>;
24
24
  * Activity options accepted by step/evaluator/workflow definitions.
25
25
  * Exposes supported Temporal ActivityOptions.
26
26
  *
27
- * @typedef {object} Options
28
27
  * @description Exposes supported Temporal ActivityOptions
29
28
  */
30
29
  export type Options = Omit<ActivityOptions, 'versioningIntent' | 'taskQueue' | 'allowEagerDispatch'>;
31
30
 
31
+ /**
32
+ * The last argument when calling workflows is used to configure it
33
+ */
32
34
  export type WorkflowCallConfig = {
33
- options?: Options
35
+
36
+ /**
37
+ * Temporal Activity Options
38
+ */
39
+ options?: Options,
40
+
41
+ /**
42
+ * Whether this workflow will run detached or not.
43
+ * Detached workflows called without explicitly awaiting for the result will be "fire-an-forget", outliving the parent.
44
+ */
45
+ detached?: boolean
34
46
  };
35
47
 
36
48
  /*
@@ -1,5 +1,5 @@
1
1
  // THIS RUNS IN THE TEMPORAL'S SANDBOX ENVIRONMENT
2
- import { defineSignal, setHandler, proxyActivities, workflowInfo, proxySinks } from '@temporalio/workflow';
2
+ import { defineSignal, setHandler, proxyActivities, workflowInfo, proxySinks, uuid4 } from '@temporalio/workflow';
3
3
  import { ACTIVITY_SEND_WEBHOOK } from '#consts';
4
4
  import { FatalError } from '#errors';
5
5
  import { validateCreateWebhook } from './validations/static.js';
@@ -20,7 +20,7 @@ export async function createWebhook( { url, payload } ) {
20
20
  const sinks = await proxySinks();
21
21
  const resumeSignal = defineSignal( 'resume' );
22
22
 
23
- const traceId = `${workflowId}-${url}-${Date.now()}`;
23
+ const traceId = `${workflowId}-${url}-${uuid4}`;
24
24
  sinks.trace.addEventStart( { id: traceId, name: 'resume', kind: 'webhook' } );
25
25
  return new Promise( resolve =>
26
26
  setHandler( resumeSignal, responsePayload => {
@@ -1,5 +1,5 @@
1
1
  // THIS RUNS IN THE TEMPORAL'S SANDBOX ENVIRONMENT
2
- import { proxyActivities, inWorkflowContext, executeChild, workflowInfo } from '@temporalio/workflow';
2
+ import { proxyActivities, inWorkflowContext, executeChild, workflowInfo, uuid4, ParentClosePolicy } from '@temporalio/workflow';
3
3
  import { validateWorkflow } from './validations/static.js';
4
4
  import { validateWithSchema } from './validations/runtime.js';
5
5
  import { SHARED_STEP_PREFIX, ACTIVITY_GET_TRACE_DESTINATIONS } from '#consts';
@@ -59,18 +59,28 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
59
59
  invokeSharedStep: async ( stepName, input, options ) => steps[`${SHARED_STEP_PREFIX}#${stepName}`]( input, options ),
60
60
  invokeEvaluator: async ( evaluatorName, input, options ) => steps[`${workflowPath}#${evaluatorName}`]( input, options ),
61
61
 
62
- startWorkflow: async ( childName, input, extra = {} ) => {
63
- return executeChild( childName, {
62
+ /**
63
+ * Start a child workflow
64
+ *
65
+ * @param {string} childName
66
+ * @param {unknown} input
67
+ * @param {object} extra
68
+ * @param {boolean} extra.detached
69
+ * @param {import('@temporalio/workflow').ActivityOptions} extra.options
70
+ * @returns
71
+ */
72
+ startWorkflow: async ( childName, input, extra = {} ) =>
73
+ executeChild( childName, {
64
74
  args: input ? [ input ] : [],
65
- workflowId: `${workflowId}-${childName}-${Date.now()}`,
75
+ workflowId: `${workflowId}-${childName}-${uuid4()}`,
76
+ parentClosePolicy: ParentClosePolicy[extra?.detached ? 'ABANDON' : 'TERMINATE'],
66
77
  memo: {
67
78
  executionContext,
68
79
  parentId: workflowId,
69
80
  // new configuration for activities of the child workflow, this will be omitted so it will use what that workflow have defined
70
81
  ...( extra?.options && { activityOptions: mergeActivityOptions( activityOptions, extra.options ) } )
71
82
  }
72
- } );
73
- }
83
+ } )
74
84
  }, input );
75
85
 
76
86
  validateWithSchema( outputSchema, output, `Workflow ${name} output` );