@@ -36,7 +36,7 @@ export const exampleWorkflow = workflow.define({
36
36
args: {
37
37
storageId: v .id (" _storage" ),
38
38
},
39
- handler : async (step , args ) => {
39
+ handler : async (step , args ): Promise < number []> => {
40
40
const transcription = await step .runAction (
41
41
internal .index .computeTranscription ,
42
42
{ storageId: args .storageId },
@@ -48,7 +48,7 @@ export const exampleWorkflow = workflow.define({
48
48
// Run this a month after the transcription is computed.
49
49
{ runAfter: 30 * 24 * 60 * 60 * 1000 },
50
50
);
51
- console . log ( embedding ) ;
51
+ return embedding ;
52
52
},
53
53
});
54
54
```
@@ -101,6 +101,9 @@ is designed to feel like a Convex action but with a few restrictions:
101
101
restrictions over time by implementing ` Math.random() ` , ` Date.now() ` , and
102
102
` fetch ` within our workflow environment.
103
103
104
+ Note: To help avoid type cycles, always annotate the return type of the ` handler `
105
+ with the return type of the workflow.
106
+
104
107
``` ts
105
108
export const exampleWorkflow = workflow .define ({
106
109
args: { name: v .string () },
@@ -211,7 +214,7 @@ a `Promise.all()` call.
211
214
``` ts
212
215
export const exampleWorkflow = workflow .define ({
213
216
args: { name: v .string () },
214
- handler : async (step , args ) => {
217
+ handler : async (step , args ): Promise < void > => {
215
218
const [result1, result2] = await Promise .all ([
216
219
step .runAction (internal .example .myAction , args ),
217
220
step .runAction (internal .example .myAction , args ),
@@ -263,7 +266,7 @@ const workflow = new WorkflowManager(components.workflow, {
263
266
264
267
export const exampleWorkflow = workflow .define ({
265
268
args: { name: v .string () },
266
- handler : async (step , args ) => {
269
+ handler : async (step , args ): Promise < void > => {
267
270
// Uses default retry behavior & retryActionsByDefault
268
271
await step .runAction (internal .example .myAction , args );
269
272
// Retries will be attempted with the default behavior
@@ -372,17 +375,59 @@ export const kickoffWorkflow = action({
372
375
373
376
You can specify a custom name for a step by passing a ` name ` option to the step.
374
377
378
+ This allows the events emitted to your logs to be more descriptive.
379
+ By default it uses the ` file/folder:function ` name.
380
+
375
381
``` ts
376
382
export const exampleWorkflow = workflow .define ({
377
383
args: { name: v .string () },
378
- handler : async (step , args ) => {
384
+ handler : async (step , args ): Promise < void > => {
379
385
await step .runAction (internal .example .myAction , args , { name: " FOO" });
380
386
},
381
387
});
382
388
```
383
389
384
- This allows the events emitted to your logs to be more descriptive.
385
- By default it uses the ` file/folder:function ` name.
390
+ ## Tips and troubleshooting
391
+
392
+ ### Circular dependencies
393
+
394
+ Having the return value of workflows depend on other Convex functions can lead to circular dependencies due to the
395
+ ` internal.foo.bar ` way of specifying functions. The way to fix this is to explicitly type the return value of the
396
+ workflow. When in doubt, add return types to more ` handler ` functions, like this:
397
+
398
+ ``` ts
399
+ export const supportAgentWorkflow = workflow .define ({
400
+ args: { prompt: v .string (), userId: v .string (), threadId: v .string () },
401
+ + handler : async (step , { prompt , userId , threadId }): Promise <string > => {
402
+ // ...
403
+ },
404
+ });
405
+
406
+ // And regular functions too:
407
+ export const myFunction = action ({
408
+ args: { prompt: v .string () },
409
+ + handler : async (ctx , { prompt }): Promise <string > => {
410
+ // ...
411
+ },
412
+ });
413
+ ```
414
+
415
+ ### More concise workflows
416
+
417
+ To avoid the noise of ` internal.foo.* ` syntax, you can use a variable.
418
+ For instance, if you define all your steps in ` convex/steps.ts ` , you can do this:
419
+
420
+ ``` ts
421
+ const s = internal .steps ;
422
+
423
+ export const myWorkflow = workflow .define ({
424
+ args: { prompt: v .string () },
425
+ handler : async (step , args ): Promise <string > => {
426
+ + const result = await step .runAction (s .myAction , args );
427
+ return result ;
428
+ },
429
+ });
430
+ ```
386
431
387
432
## Limitations
388
433
0 commit comments