@output.ai/core 0.1.16 → 0.1.17
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/index.d.ts +400 -285
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,52 +1,189 @@
|
|
|
1
|
-
// Import Zod types for dual schema support
|
|
2
1
|
import type { z } from 'zod';
|
|
3
2
|
import type { ActivityOptions } from '@temporalio/workflow';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Expose z from Zod as a convenience.
|
|
6
|
+
*/
|
|
6
7
|
export { z } from 'zod';
|
|
7
8
|
|
|
9
|
+
/*
|
|
10
|
+
╭─────────────────────────╮
|
|
11
|
+
│ C O M M O N T Y P E S │╮
|
|
12
|
+
╰─────────────────────────╯│
|
|
13
|
+
╰─────────────────────────╯
|
|
14
|
+
*/
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Type alias for any Zod schema type.
|
|
18
|
+
*/
|
|
19
|
+
export type AnyZodSchema = z.ZodType<any, any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Native Temporal configurations for activities.
|
|
10
23
|
*
|
|
11
|
-
*
|
|
12
|
-
* generic parameters (Output, Def, Input) that vary based on the specific schema type.
|
|
13
|
-
* When we want to accept ANY Zod schema (string, number, object, etc.), we must use
|
|
14
|
-
* `any` for these parameters. Using `unknown` would be too restrictive and would
|
|
15
|
-
* break Zod's type inference system.
|
|
24
|
+
* All native options are accepted except 'versioningIntent', 'taskQueue', 'allowEagerDispatch'.
|
|
16
25
|
*
|
|
17
|
-
*
|
|
18
|
-
* and Zod itself uses this pattern internally.
|
|
26
|
+
* @see {@link https://typescript.temporal.io/api/interfaces/common.ActivityOptions}
|
|
19
27
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
export type TemporalActivityOptions = Omit<ActivityOptions, 'versioningIntent' | 'taskQueue' | 'allowEagerDispatch'>;
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
╭─────────╮
|
|
32
|
+
│ S T E P │╮
|
|
33
|
+
╰─────────╯│
|
|
34
|
+
╰─────────╯
|
|
35
|
+
*/
|
|
22
36
|
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
38
|
+
* The handler function of a step.
|
|
39
|
+
*
|
|
40
|
+
* @param input - The step input; it matches the schema defined by `inputSchema`.
|
|
41
|
+
*
|
|
42
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
43
|
+
*/
|
|
44
|
+
export type StepFunction<
|
|
45
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
46
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
47
|
+
> = InputSchema extends AnyZodSchema ?
|
|
48
|
+
( input: z.infer<InputSchema> ) => Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void> :
|
|
49
|
+
() => Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A wrapper around the user defined `fn` handler function.
|
|
53
|
+
*
|
|
54
|
+
* It accepts the same input and returns the same value, calling the user function inside.
|
|
55
|
+
*
|
|
56
|
+
* It adds input and output validation based on the `inputSchema`, `outputSchema`.
|
|
57
|
+
*
|
|
58
|
+
* @param input - The Step input; it matches the schema defined by `inputSchema`.
|
|
59
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
60
|
+
*/
|
|
61
|
+
export type StepFunctionWrapper<StepFunction> =
|
|
62
|
+
Parameters<StepFunction> extends [infer Input] ?
|
|
63
|
+
( input: Input ) => ReturnType<StepFunction> :
|
|
64
|
+
() => ReturnType<StepFunction>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Creates a step.
|
|
68
|
+
*
|
|
69
|
+
* A step is a logical unit of work that can perform I/O. It is translated to a Temporal Activity.
|
|
70
|
+
*
|
|
71
|
+
* The step logic is defined in the `fn` handler function.
|
|
72
|
+
*
|
|
73
|
+
* The schema of the input that the function receives as the first argument is defined by the `inputSchema` option.
|
|
74
|
+
*
|
|
75
|
+
* The output of the `fn` handler must match the schema defined by `outputSchema`; otherwise, a validation error is raised.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```
|
|
79
|
+
* step( {
|
|
80
|
+
* name: 'process',
|
|
81
|
+
* description: 'A generic process',
|
|
82
|
+
* inputSchema: z.object( {
|
|
83
|
+
* value: z.number()
|
|
84
|
+
* } ),
|
|
85
|
+
* outputSchema: z.string(),
|
|
86
|
+
* fn: async input => {
|
|
87
|
+
* const result = await ai.call( input.value );
|
|
88
|
+
* return result as string;
|
|
89
|
+
* }
|
|
90
|
+
* } )
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Step without outputSchema
|
|
94
|
+
* ```
|
|
95
|
+
* step( {
|
|
96
|
+
* name: 'process',
|
|
97
|
+
* description: 'A generic process',
|
|
98
|
+
* inputSchema: z.object( {
|
|
99
|
+
* value: z.number()
|
|
100
|
+
* } ),
|
|
101
|
+
* fn: async input => {
|
|
102
|
+
* await ai.call( input.value );
|
|
103
|
+
* }
|
|
104
|
+
* } )
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example Step without inputSchema
|
|
108
|
+
* ```
|
|
109
|
+
* step( {
|
|
110
|
+
* name: 'process',
|
|
111
|
+
* description: 'A generic process',
|
|
112
|
+
* outputSchema: z.string(),
|
|
113
|
+
* fn: async () => {
|
|
114
|
+
* const result = await ai.call();
|
|
115
|
+
* return result as string;
|
|
116
|
+
* }
|
|
117
|
+
* } )
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example Step without inputSchema and outputSchema
|
|
121
|
+
* ```
|
|
122
|
+
* step( {
|
|
123
|
+
* name: 'process',
|
|
124
|
+
* description: 'A generic process',
|
|
125
|
+
* fn: async () => {
|
|
126
|
+
* await ai.call();
|
|
127
|
+
* }
|
|
128
|
+
* } )
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* - Never call another step from within a step.
|
|
133
|
+
* - Never call a workflow from within a step.
|
|
26
134
|
*
|
|
27
|
-
* @
|
|
135
|
+
* @typeParam InputSchema - Zod schema for the step input
|
|
136
|
+
* @typeParam OutputSchema - Zod schema for the step output
|
|
137
|
+
*
|
|
138
|
+
* @param params - Step parameters
|
|
139
|
+
* @param params.name - Human-readable step name (must start with a letter or underscore, followed by letters, numbers, or underscores)
|
|
140
|
+
* @param params.description - Description of the step
|
|
141
|
+
* @param params.inputSchema - Zod schema for the `fn` input
|
|
142
|
+
* @param params.outputSchema - Zod schema for the `fn` output
|
|
143
|
+
* @param params.fn - A handler function containing the step code
|
|
144
|
+
* @param params.options - Temporal Activity options
|
|
145
|
+
* @returns The same handler function set at `fn`
|
|
28
146
|
*/
|
|
29
|
-
export
|
|
147
|
+
export declare function step<
|
|
148
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
149
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
150
|
+
>( params: {
|
|
151
|
+
name: string;
|
|
152
|
+
description?: string;
|
|
153
|
+
inputSchema?: InputSchema;
|
|
154
|
+
outputSchema?: OutputSchema;
|
|
155
|
+
fn: StepFunction<InputSchema, OutputSchema>;
|
|
156
|
+
options?: TemporalActivityOptions;
|
|
157
|
+
} ): StepFunctionWrapper<StepFunction<InputSchema, OutputSchema>>;
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
╭─────────────────╮
|
|
161
|
+
│ W O R K F L O W │╮
|
|
162
|
+
╰─────────────────╯│
|
|
163
|
+
╰─────────────────╯
|
|
164
|
+
*/
|
|
30
165
|
|
|
31
166
|
/**
|
|
32
|
-
*
|
|
167
|
+
* Configuration for workflow invocations.
|
|
168
|
+
*
|
|
169
|
+
* Allows overriding Temporal Activity options for this workflow.
|
|
33
170
|
*/
|
|
34
|
-
export type
|
|
171
|
+
export type WorkflowInvocationConfiguration = {
|
|
35
172
|
|
|
36
173
|
/**
|
|
37
|
-
* Temporal Activity
|
|
174
|
+
* Native Temporal Activity options
|
|
38
175
|
*/
|
|
39
|
-
options?:
|
|
176
|
+
options?: TemporalActivityOptions,
|
|
40
177
|
|
|
41
178
|
/**
|
|
42
|
-
*
|
|
43
|
-
* Detached workflows called without explicitly awaiting
|
|
179
|
+
* Configures whether this workflow runs detached.
|
|
180
|
+
* Detached workflows called without explicitly awaiting the result are "fire-and-forget" and may outlive the parent.
|
|
44
181
|
*/
|
|
45
182
|
detached?: boolean
|
|
46
183
|
};
|
|
47
184
|
|
|
48
185
|
/**
|
|
49
|
-
* The second argument
|
|
186
|
+
* The second argument passed to the workflow's `fn` function.
|
|
50
187
|
*/
|
|
51
188
|
export type WorkflowContext<
|
|
52
189
|
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
@@ -58,25 +195,28 @@ export type WorkflowContext<
|
|
|
58
195
|
*/
|
|
59
196
|
control: {
|
|
60
197
|
/**
|
|
61
|
-
*
|
|
198
|
+
* Closes the current workflow execution successfully and creates a new workflow execution.
|
|
62
199
|
*
|
|
63
|
-
* The new
|
|
200
|
+
* The new workflow execution is in the same chain as the previous workflow, but it generates another trace file.
|
|
64
201
|
*
|
|
65
|
-
* It
|
|
202
|
+
* It acts as a checkpoint when the workflow gets too long or approaches certain scaling limits.
|
|
66
203
|
*
|
|
67
204
|
* It accepts input with the same schema as the parent workflow function (`inputSchema`).
|
|
68
205
|
*
|
|
69
|
-
* Calling
|
|
206
|
+
* Calling this function must be the last statement in the workflow, accompanied by a `return`:
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
70
209
|
* ```js
|
|
71
210
|
* return control.continueAsNew();
|
|
72
211
|
* ```
|
|
73
|
-
* Upon returning
|
|
212
|
+
* Upon returning, the parent workflow execution closes without any output, and the new execution takes its place.
|
|
74
213
|
*
|
|
75
|
-
* The function return type
|
|
214
|
+
* The function's return type matches `outputSchema`; although no value is returned, the execution is replaced.
|
|
76
215
|
*
|
|
77
216
|
* @see {@link https://docs.temporal.io/develop/typescript/continue-as-new}
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
217
|
+
*
|
|
218
|
+
* @param input - The input for the new run. Omit when the workflow has no input schema.
|
|
219
|
+
* @returns The workflow output type for type-checking; never returns at runtime.
|
|
80
220
|
*/
|
|
81
221
|
continueAsNew: InputSchema extends AnyZodSchema ?
|
|
82
222
|
( input: z.infer<InputSchema> ) => ( OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void ) :
|
|
@@ -88,206 +228,170 @@ export type WorkflowContext<
|
|
|
88
228
|
* Prefer returning the `continueAsNew(...)` call immediately when this becomes `true`.
|
|
89
229
|
*
|
|
90
230
|
* @see {@link https://docs.temporal.io/develop/typescript/continue-as-new#how-to-test}
|
|
91
|
-
*
|
|
231
|
+
*
|
|
232
|
+
* @returns True if a continue-as-new is suggested for the current run; otherwise false.
|
|
92
233
|
*/
|
|
93
234
|
isContinueAsNewSuggested: () => boolean
|
|
94
235
|
}
|
|
95
236
|
};
|
|
96
237
|
|
|
97
|
-
/*
|
|
98
|
-
╭─────────╮
|
|
99
|
-
│ S T E P │╮
|
|
100
|
-
╰─────────╯│
|
|
101
|
-
╰─────────╯
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/*
|
|
105
|
-
* There are 4 overloads of the "step" function:
|
|
106
|
-
* - with fn receiving input and returning output;
|
|
107
|
-
* - with fn receiving input and returning void;
|
|
108
|
-
* - with fn receiving void and returning output;
|
|
109
|
-
* - with fn receiving void and returning void;
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Creates logical unit of work defined schema for both input and output.
|
|
114
|
-
*
|
|
115
|
-
* @param {object} options - Step options
|
|
116
|
-
* @param {string} options.name - Human-readable step name (only letters, numbers and "_")
|
|
117
|
-
* @param {string} [options.description] - Description of the step
|
|
118
|
-
* @param {z.ZodType} options.inputSchema - Zod schema for the fn input
|
|
119
|
-
* @param {z.ZodType} options.outputSchema - Zod schema for the fn output
|
|
120
|
-
* @param {function} options.fn - The function logic: `(input: z.infer<InputSchema>) => Promise<z.infer<OutputSchema>>`
|
|
121
|
-
* @param {Options} [options.options] - Activity retry options
|
|
122
|
-
* @returns {function} Function with signature: `(input: z.infer<InputSchema>) => Promise<z.infer<OutputSchema>>`
|
|
123
|
-
*/
|
|
124
|
-
export async function step<
|
|
125
|
-
InputSchema extends AnyZodSchema,
|
|
126
|
-
OutputSchema extends AnyZodSchema
|
|
127
|
-
>( options: {
|
|
128
|
-
name: string;
|
|
129
|
-
description?: string;
|
|
130
|
-
inputSchema: InputSchema;
|
|
131
|
-
outputSchema: OutputSchema;
|
|
132
|
-
fn: ( input: z.infer<InputSchema> ) => Promise<z.infer<OutputSchema>>;
|
|
133
|
-
options?: Options;
|
|
134
|
-
} ): ( input: z.infer<InputSchema> ) => Promise<z.infer<OutputSchema>>;
|
|
135
|
-
|
|
136
238
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
*
|
|
142
|
-
* @
|
|
143
|
-
* @param {function} options.fn - The function logic: `(input: z.infer<InputSchema>) => Promise<void>`
|
|
144
|
-
* @param {Options} [options.options] - Activity retry options
|
|
145
|
-
* @returns {function} Function with signature: `(input: z.infer<InputSchema>) => Promise<void>`
|
|
239
|
+
* The handler function of a workflow.
|
|
240
|
+
*
|
|
241
|
+
* @param input - The workflow input; it matches the schema defined by `inputSchema`.
|
|
242
|
+
* @param context - A context object with tools and information.
|
|
243
|
+
*
|
|
244
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
146
245
|
*/
|
|
147
|
-
export
|
|
148
|
-
InputSchema extends AnyZodSchema
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} ): ( input: z.infer<InputSchema> ) => Promise<void>;
|
|
246
|
+
export type WorkflowFunction<
|
|
247
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
248
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
249
|
+
> = InputSchema extends AnyZodSchema ?
|
|
250
|
+
( input: z.infer<InputSchema>, context: WorkflowContext<InputSchema, OutputSchema> ) =>
|
|
251
|
+
Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void> :
|
|
252
|
+
( input?: undefined | null, context: WorkflowContext<InputSchema, OutputSchema> ) =>
|
|
253
|
+
Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void>;
|
|
156
254
|
|
|
157
255
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
256
|
+
* A wrapper around the user defined `fn` handler function.
|
|
257
|
+
*
|
|
258
|
+
* It accepts the same input and returns the same value, calling the user function inside.
|
|
259
|
+
*
|
|
260
|
+
* The second argument is a WorkflowInvocationConfiguration object, allowing workflows configuration overwrite.
|
|
261
|
+
*
|
|
262
|
+
* It adds input and output validation based on the `inputSchema`, `outputSchema`.
|
|
263
|
+
*
|
|
264
|
+
* @param input - The workflow input; it matches the schema defined by `inputSchema`.
|
|
265
|
+
* @param config - Additional configuration for the invocation.
|
|
266
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
167
267
|
*/
|
|
168
|
-
export
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
description?: string;
|
|
173
|
-
outputSchema: OutputSchema;
|
|
174
|
-
fn: () => Promise<z.infer<OutputSchema>>;
|
|
175
|
-
options?: Options;
|
|
176
|
-
} ): () => Promise<z.infer<OutputSchema>>;
|
|
268
|
+
export type WorkflowFunctionWrapper<WorkflowFunction> =
|
|
269
|
+
[Parameters<WorkflowFunction>[0]] extends [undefined | null] ?
|
|
270
|
+
( input?: undefined | null, config?: WorkflowInvocationConfiguration ) => ReturnType<WorkflowFunction> :
|
|
271
|
+
( input: Parameters<WorkflowFunction>[0], config?: WorkflowInvocationConfiguration ) => ReturnType<WorkflowFunction>;
|
|
177
272
|
|
|
178
273
|
/**
|
|
179
|
-
* Creates
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
274
|
+
* Creates a workflow.
|
|
275
|
+
*
|
|
276
|
+
* A workflow is an orchestration of one or more steps. It is translated to a Temporal Workflow.
|
|
277
|
+
*
|
|
278
|
+
* The workflow logic is defined in the `fn` handler function.
|
|
279
|
+
*
|
|
280
|
+
* The schema of the input that the function receives as the first argument is defined by `inputSchema`.
|
|
281
|
+
*
|
|
282
|
+
* The output of the `fn` handler must match `outputSchema`; otherwise, a validation error is raised.
|
|
283
|
+
*
|
|
284
|
+
* @remarks
|
|
285
|
+
* - Workflows should respect the same limitations as Temporal workflows.
|
|
286
|
+
* - Workflows can invoke steps or evaluators and cannot perform I/O directly.
|
|
287
|
+
* - The workflow `name` needs to be unique across all workflows in the project.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```
|
|
291
|
+
* import { step } from './my_steps.ts';
|
|
292
|
+
*
|
|
293
|
+
* workflow( {
|
|
294
|
+
* name: 'main',
|
|
295
|
+
* description: 'A generic workflow',
|
|
296
|
+
* inputSchema: z.object( {
|
|
297
|
+
* value: z.number()
|
|
298
|
+
* } ),
|
|
299
|
+
* outputSchema: z.string(),
|
|
300
|
+
* fn: async input => {
|
|
301
|
+
* const result = await step( input.value );
|
|
302
|
+
* return result as string;
|
|
303
|
+
* }
|
|
304
|
+
* } )
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* @example Workflow without outputSchema
|
|
308
|
+
* ```
|
|
309
|
+
* import { step } from './my_steps.ts';
|
|
310
|
+
*
|
|
311
|
+
* workflow( {
|
|
312
|
+
* name: 'main',
|
|
313
|
+
* description: 'A generic workflow',
|
|
314
|
+
* inputSchema: z.object( {
|
|
315
|
+
* value: z.number()
|
|
316
|
+
* } ),
|
|
317
|
+
* fn: async input => {
|
|
318
|
+
* await step( input.value );
|
|
319
|
+
* }
|
|
320
|
+
* } )
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example Workflow without inputSchema
|
|
324
|
+
* ```
|
|
325
|
+
* import { step } from './my_steps.ts';
|
|
326
|
+
*
|
|
327
|
+
* workflow( {
|
|
328
|
+
* name: 'main',
|
|
329
|
+
* description: 'A generic workflow',
|
|
330
|
+
* outputSchema: z.string(),
|
|
331
|
+
* fn: async () => {
|
|
332
|
+
* const result = await step();
|
|
333
|
+
* return result as string;
|
|
334
|
+
* }
|
|
335
|
+
* } )
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @example Workflow without inputSchema and outputSchema
|
|
339
|
+
* ```
|
|
340
|
+
* import { step } from './my_steps.ts';
|
|
341
|
+
*
|
|
342
|
+
* workflow( {
|
|
343
|
+
* name: 'main',
|
|
344
|
+
* description: 'A generic workflow',
|
|
345
|
+
* fn: async () => {
|
|
346
|
+
* await step();
|
|
347
|
+
* }
|
|
348
|
+
* } )
|
|
349
|
+
* ```
|
|
350
|
+
*
|
|
351
|
+
* @example Using continueAsNew
|
|
352
|
+
* The function `continueAsNew` (same as Temporal) can be used to create a new workflow with the same ID and pass different input.
|
|
353
|
+
*
|
|
354
|
+
* ```
|
|
355
|
+
* import { step } from './my_steps.ts';
|
|
356
|
+
*
|
|
357
|
+
* workflow( {
|
|
358
|
+
* name: 'main',
|
|
359
|
+
* description: 'A generic workflow',
|
|
360
|
+
* inputSchema: z.object( {
|
|
361
|
+
* value: z.number()
|
|
362
|
+
* } ),
|
|
363
|
+
* outputSchema: z.string(),
|
|
364
|
+
* fn: async ( input, context ) => {
|
|
365
|
+
* const result = await step( input.value );
|
|
366
|
+
* if ( context.control.isContinueAsNewSuggested() ) {
|
|
367
|
+
* return context.control.continueAsNew( input );
|
|
368
|
+
* }
|
|
369
|
+
*
|
|
370
|
+
* return result as string;
|
|
371
|
+
* }
|
|
372
|
+
* } )
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @param params - Workflow parameters
|
|
376
|
+
* @param params.name - Human-readable workflow name (must start with a letter or underscore, followed by letters, numbers, or underscores).
|
|
377
|
+
* @param params.description - Description of the workflow
|
|
378
|
+
* @param params.inputSchema - Zod schema for workflow input
|
|
379
|
+
* @param params.outputSchema - Zod schema for workflow output
|
|
380
|
+
* @param params.fn - A function containing the workflow code
|
|
381
|
+
* @param params.options - Temporal Activity options
|
|
382
|
+
* @returns The same handler function set at `fn` with a different signature
|
|
187
383
|
*/
|
|
188
|
-
export
|
|
384
|
+
export declare function workflow<
|
|
385
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
386
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
387
|
+
>( params: {
|
|
189
388
|
name: string;
|
|
190
389
|
description?: string;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
╭─────────────────╮
|
|
197
|
-
│ W O R K F L O W │╮
|
|
198
|
-
╰─────────────────╯│
|
|
199
|
-
╰─────────────────╯
|
|
200
|
-
*/
|
|
201
|
-
/*
|
|
202
|
-
* There are 4 overloads of the "workflow" function:
|
|
203
|
-
* - with fn receiving input and returning output;
|
|
204
|
-
* - with fn receiving input and returning void;
|
|
205
|
-
* - with fn receiving void and returning output;
|
|
206
|
-
* - with fn receiving void and returning void;
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Creates a workflow orchestrator with defined schema for both input and output.
|
|
211
|
-
*
|
|
212
|
-
* @param {object} options - Workflow options
|
|
213
|
-
* @param {string} options.name - Unique workflow name
|
|
214
|
-
* @param {string} [options.description] - Description of the workflow
|
|
215
|
-
* @param {z.ZodType} options.inputSchema - Zod schema for workflow input
|
|
216
|
-
* @param {z.ZodType} options.outputSchema - Zod schema for workflow output
|
|
217
|
-
* @param {function} options.fn - Workflow logic
|
|
218
|
-
* @param {Options} [options.options] - Activity retry options
|
|
219
|
-
* @returns {function} Callable workflow function
|
|
220
|
-
*/
|
|
221
|
-
export function workflow<
|
|
222
|
-
InputSchema extends AnyZodSchema,
|
|
223
|
-
OutputSchema extends AnyZodSchema
|
|
224
|
-
>( options : {
|
|
225
|
-
name: string,
|
|
226
|
-
description?: string,
|
|
227
|
-
inputSchema: InputSchema,
|
|
228
|
-
outputSchema: OutputSchema,
|
|
229
|
-
fn: ( input: z.infer<InputSchema>, context: WorkflowContext<InputSchema, OutputSchema> ) => Promise<z.infer<OutputSchema>>,
|
|
230
|
-
options?: Options
|
|
231
|
-
} ): ( input: z.infer<InputSchema>, extra?: WorkflowCallConfig ) => Promise<z.infer<OutputSchema>>;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Creates a workflow orchestrator with defined schema for input only.
|
|
235
|
-
*
|
|
236
|
-
* @param {object} options - Workflow options
|
|
237
|
-
* @param {string} options.name - Unique workflow name
|
|
238
|
-
* @param {string} [options.description] - Description of the workflow
|
|
239
|
-
* @param {z.ZodType} options.inputSchema - Zod schema for workflow input
|
|
240
|
-
* @param {function} options.fn - Workflow logic
|
|
241
|
-
* @param {Options} [options.options] - Activity retry options
|
|
242
|
-
* @returns {function} Callable workflow function
|
|
243
|
-
*/
|
|
244
|
-
export function workflow<
|
|
245
|
-
InputSchema extends AnyZodSchema
|
|
246
|
-
>( options : {
|
|
247
|
-
name: string,
|
|
248
|
-
description?: string,
|
|
249
|
-
inputSchema: InputSchema,
|
|
250
|
-
fn: ( input: z.infer<InputSchema>, context: WorkflowContext<InputSchema, undefined> ) => Promise<void>,
|
|
251
|
-
options?: Options
|
|
252
|
-
} ): ( input: z.infer<InputSchema>, extra?: WorkflowCallConfig ) => Promise<void>;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Creates a workflow orchestrator with defined schema for output only.
|
|
256
|
-
*
|
|
257
|
-
* @param {object} options - Workflow options
|
|
258
|
-
* @param {string} options.name - Unique workflow name
|
|
259
|
-
* @param {string} [options.description] - Description of the workflow
|
|
260
|
-
* @param {z.ZodType} options.outputSchema - Zod schema for workflow output
|
|
261
|
-
* @param {function} options.fn - Workflow logic
|
|
262
|
-
* @param {Options} [options.options] - Activity retry options
|
|
263
|
-
* @returns {function} Callable workflow function
|
|
264
|
-
*/
|
|
265
|
-
export function workflow<
|
|
266
|
-
OutputSchema extends AnyZodSchema
|
|
267
|
-
>( options : {
|
|
268
|
-
name: string,
|
|
269
|
-
description?: string,
|
|
270
|
-
outputSchema: OutputSchema,
|
|
271
|
-
fn: ( input?: undefined | null, context: WorkflowContext<undefined, OutputSchema> ) => Promise<z.infer<OutputSchema>>,
|
|
272
|
-
options?: Options
|
|
273
|
-
} ): ( input?: undefined | null, extra?: WorkflowCallConfig ) => Promise<z.infer<OutputSchema>>;
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Creates a workflow orchestrator without defined schemas.
|
|
277
|
-
*
|
|
278
|
-
* @param {object} options - Workflow options
|
|
279
|
-
* @param {string} options.name - Unique workflow name
|
|
280
|
-
* @param {string} [options.description] - Description of the workflow
|
|
281
|
-
* @param {function} options.fn - Workflow logic
|
|
282
|
-
* @param {Options} [options.options] - Activity retry options
|
|
283
|
-
* @returns {function} Callable workflow function
|
|
284
|
-
*/
|
|
285
|
-
export function workflow( options : {
|
|
286
|
-
name: string,
|
|
287
|
-
description?: string,
|
|
288
|
-
fn: ( input?: undefined | null, context: WorkflowContext<undefined, undefined> ) => Promise<void>,
|
|
289
|
-
options?: Options
|
|
290
|
-
} ): ( input?: undefined | null, extra?: WorkflowCallConfig ) => Promise<void>;
|
|
390
|
+
inputSchema?: InputSchema;
|
|
391
|
+
outputSchema?: OutputSchema;
|
|
392
|
+
fn: WorkflowFunction<InputSchema, OutputSchema>;
|
|
393
|
+
options?: TemporalActivityOptions;
|
|
394
|
+
} ): WorkflowFunctionWrapper<WorkflowFunction<InputSchema, OutputSchema>>;
|
|
291
395
|
|
|
292
396
|
/*
|
|
293
397
|
╭───────────────────╮
|
|
@@ -297,31 +401,32 @@ export function workflow( options : {
|
|
|
297
401
|
*/
|
|
298
402
|
|
|
299
403
|
/**
|
|
300
|
-
*
|
|
404
|
+
* Represents the result of an evaluation.
|
|
405
|
+
*
|
|
406
|
+
* Generic base class; evaluators must return an instance of an EvaluationResult subclass.
|
|
301
407
|
*/
|
|
302
|
-
class EvaluationResult {
|
|
408
|
+
export class EvaluationResult {
|
|
303
409
|
/**
|
|
304
410
|
* @constructor
|
|
305
|
-
* @param
|
|
306
|
-
* @param
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
411
|
+
* @param args
|
|
412
|
+
* @param args.value - The value of the evaluation
|
|
413
|
+
* @param args.confidence - The confidence in the evaluation
|
|
414
|
+
* @param args.reasoning - The reasoning behind the result
|
|
309
415
|
*/
|
|
310
416
|
constructor( args: { value: any; confidence: number; reasoning?: string } ); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
311
417
|
|
|
312
418
|
/**
|
|
313
|
-
* @returns
|
|
419
|
+
* @returns The evaluation result value
|
|
314
420
|
*/
|
|
315
|
-
|
|
316
421
|
get value(): any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
317
422
|
|
|
318
423
|
/**
|
|
319
|
-
* @returns
|
|
424
|
+
* @returns The evaluation result confidence
|
|
320
425
|
*/
|
|
321
426
|
get confidence(): number;
|
|
322
427
|
|
|
323
428
|
/**
|
|
324
|
-
* @returns
|
|
429
|
+
* @returns The evaluation result reasoning
|
|
325
430
|
*/
|
|
326
431
|
get reasoning(): string;
|
|
327
432
|
}
|
|
@@ -333,15 +438,15 @@ class EvaluationResult {
|
|
|
333
438
|
export class EvaluationStringResult extends EvaluationResult {
|
|
334
439
|
/**
|
|
335
440
|
* @constructor
|
|
336
|
-
* @param
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @param
|
|
441
|
+
* @param args
|
|
442
|
+
* @param args.value - The value of the evaluation
|
|
443
|
+
* @param args.confidence - The confidence on the evaluation
|
|
444
|
+
* @param args.reasoning - The reasoning behind the result
|
|
340
445
|
*/
|
|
341
446
|
constructor( args: { value: string; confidence: number; reasoning?: string } );
|
|
342
447
|
|
|
343
448
|
/**
|
|
344
|
-
* @returns
|
|
449
|
+
* @returns The evaluation result value
|
|
345
450
|
*/
|
|
346
451
|
get value(): string;
|
|
347
452
|
}
|
|
@@ -353,15 +458,15 @@ export class EvaluationStringResult extends EvaluationResult {
|
|
|
353
458
|
export class EvaluationNumberResult extends EvaluationResult {
|
|
354
459
|
/**
|
|
355
460
|
* @constructor
|
|
356
|
-
* @param
|
|
357
|
-
* @param
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
461
|
+
* @param args
|
|
462
|
+
* @param args.value - The value of the evaluation
|
|
463
|
+
* @param args.confidence - The confidence on the evaluation
|
|
464
|
+
* @param args.reasoning - The reasoning behind the result
|
|
360
465
|
*/
|
|
361
466
|
constructor( args: { value: number; confidence: number; reasoning?: string } );
|
|
362
467
|
|
|
363
468
|
/**
|
|
364
|
-
* @returns
|
|
469
|
+
* @returns The evaluation result value
|
|
365
470
|
*/
|
|
366
471
|
get value(): number;
|
|
367
472
|
}
|
|
@@ -373,71 +478,72 @@ export class EvaluationNumberResult extends EvaluationResult {
|
|
|
373
478
|
export class EvaluationBooleanResult extends EvaluationResult {
|
|
374
479
|
/**
|
|
375
480
|
* @constructor
|
|
376
|
-
* @param
|
|
377
|
-
* @param
|
|
378
|
-
* @param
|
|
379
|
-
* @param
|
|
481
|
+
* @param args
|
|
482
|
+
* @param args.value - The value of the evaluation
|
|
483
|
+
* @param args.confidence - The confidence on the evaluation
|
|
484
|
+
* @param args.reasoning - The reasoning behind the result
|
|
380
485
|
*/
|
|
381
486
|
constructor( args: { value: boolean; confidence: number; reasoning?: string } );
|
|
382
487
|
|
|
383
488
|
/**
|
|
384
|
-
* @returns
|
|
489
|
+
* @returns The evaluation result value
|
|
385
490
|
*/
|
|
386
491
|
get value(): boolean;
|
|
387
492
|
}
|
|
388
493
|
|
|
389
|
-
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* -
|
|
494
|
+
/**
|
|
495
|
+
* The handler function of an evaluator.
|
|
496
|
+
*
|
|
497
|
+
* @param input - The evaluator input; it matches the schema defined by `inputSchema`.
|
|
498
|
+
*
|
|
499
|
+
* @returns The result of the evaluation.
|
|
393
500
|
*/
|
|
501
|
+
export type EvaluatorFunction<
|
|
502
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
503
|
+
Result extends EvaluationResult
|
|
504
|
+
> = InputSchema extends AnyZodSchema ?
|
|
505
|
+
( input: z.infer<InputSchema> ) => Promise<Result> :
|
|
506
|
+
() => Promise<Result>;
|
|
394
507
|
|
|
395
508
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* @param {z.ZodType} options.inputSchema - Zod schema for the fn input
|
|
402
|
-
* @param {function} options.fn - The function logic: `(input: z.infer<InputSchema>) => Promise<z.infer<OutputSchema>>`
|
|
403
|
-
* @param {Options} [options.options] - Activity retry options
|
|
404
|
-
* @returns {function} Function with signature: `(input: z.infer<InputSchema>) => Promise<z.infer<OutputSchema>>`
|
|
509
|
+
* A wrapper around the user defined `fn` handler function.
|
|
510
|
+
*
|
|
511
|
+
* It has the same signature and returns the same value, calling the user function inside.
|
|
512
|
+
*
|
|
513
|
+
* It adds input validation based on the `inputSchema`.
|
|
405
514
|
*/
|
|
406
|
-
export
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
name: string;
|
|
411
|
-
description?: string;
|
|
412
|
-
inputSchema: InputSchema;
|
|
413
|
-
fn: ( input: z.infer<InputSchema> ) => Promise<Result>;
|
|
414
|
-
options?: Options;
|
|
415
|
-
} ): ( input: z.infer<InputSchema> ) => Promise<Result>;
|
|
515
|
+
export type EvaluatorFunctionWrapper<EvaluatorFunction> =
|
|
516
|
+
Parameters<EvaluatorFunction> extends [infer Input] ?
|
|
517
|
+
( input: Input ) => ReturnType<EvaluatorFunction> :
|
|
518
|
+
() => ReturnType<EvaluatorFunction>;
|
|
416
519
|
|
|
417
520
|
/**
|
|
418
|
-
* Creates
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* @param
|
|
423
|
-
* @param
|
|
424
|
-
* @param
|
|
425
|
-
* @param
|
|
426
|
-
* @
|
|
521
|
+
* Creates an evaluation function. It is similar to a step, but must return an EvaluationResult.
|
|
522
|
+
*
|
|
523
|
+
* It is translated to a Temporal Activity.
|
|
524
|
+
*
|
|
525
|
+
* @param params - Evaluator parameters
|
|
526
|
+
* @param params.name - Human-readable evaluator name (must start with a letter or underscore, followed by letters, numbers, or underscores)
|
|
527
|
+
* @param params.description - Description of the evaluator
|
|
528
|
+
* @param params.inputSchema - Zod schema for the `fn` input
|
|
529
|
+
* @param params.fn - A function containing the evaluator code
|
|
530
|
+
* @param params.options - Temporal Activity options
|
|
531
|
+
* @returns A wrapper function around the `fn` function
|
|
427
532
|
*/
|
|
428
|
-
export
|
|
533
|
+
export declare function evaluator<
|
|
429
534
|
InputSchema extends AnyZodSchema,
|
|
430
535
|
Result extends EvaluationResult
|
|
431
|
-
>(
|
|
536
|
+
>( params: {
|
|
432
537
|
name: string;
|
|
433
538
|
description?: string;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
539
|
+
inputSchema: InputSchema;
|
|
540
|
+
fn: EvaluatorFunction<InputSchema, Result>;
|
|
541
|
+
options?: TemporalActivityOptions;
|
|
542
|
+
} ): EvaluatorFunctionWrapper<EvaluatorFunction<InputSchema, Result>>;
|
|
437
543
|
|
|
438
544
|
/*
|
|
439
545
|
╭───────────╮
|
|
440
|
-
│ O
|
|
546
|
+
│ T O O L S │╮
|
|
441
547
|
╰───────────╯│
|
|
442
548
|
╰───────────╯
|
|
443
549
|
*/
|
|
@@ -448,23 +554,32 @@ export async function evaluator<
|
|
|
448
554
|
* Sends a request via an activity; the workflow will await a corresponding
|
|
449
555
|
* resume signal to continue and return the response payload.
|
|
450
556
|
*
|
|
451
|
-
* @param
|
|
452
|
-
* @param
|
|
453
|
-
* @param
|
|
454
|
-
* @returns
|
|
557
|
+
* @param params - Webhook request parameters
|
|
558
|
+
* @param params.url - Webhook request URL (POST)
|
|
559
|
+
* @param params.payload - Webhook request payload
|
|
560
|
+
* @returns Resolves with the response payload when resumed
|
|
455
561
|
*/
|
|
456
|
-
export function createWebhook(
|
|
562
|
+
export declare function createWebhook( params: { url: string; payload?: object } ): Promise<object>;
|
|
563
|
+
|
|
564
|
+
/*
|
|
565
|
+
╭─────────────╮
|
|
566
|
+
│ E R R O R S │╮
|
|
567
|
+
╰─────────────╯│
|
|
568
|
+
╰─────────────╯
|
|
569
|
+
*/
|
|
457
570
|
|
|
458
571
|
/**
|
|
459
572
|
* Error indicating a non-recoverable failure.
|
|
460
573
|
*
|
|
461
|
-
*
|
|
574
|
+
* Throw this error to end the workflow execution altogether without retries.
|
|
462
575
|
*/
|
|
463
576
|
export class FatalError extends Error {}
|
|
464
577
|
|
|
465
578
|
/**
|
|
466
579
|
* Error indicating invalid input or schema validation issues.
|
|
467
580
|
*
|
|
468
|
-
*
|
|
581
|
+
* This error is thrown when there are validation errors, either in the input or output, for steps, evaluators, and workflows.
|
|
582
|
+
*
|
|
583
|
+
* It will end the workflow execution without retries.
|
|
469
584
|
*/
|
|
470
585
|
export class ValidationError extends Error {}
|