@upstash/workflow 0.2.13 → 0.2.15

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter, c as Step } from './types-C1WIgVLA.js';
2
- export { A as AsyncStepFunction, C as CallResponse, r as CallSettings, D as Duration, l as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, t as InvokableWorkflow, s as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, u as LogLevel, p as NotifyStepResponse, P as ParallelCallState, k as PublicServeOptions, m as RequiredExceptFields, j as StepFunction, h as StepTypes, i as SyncStepFunction, q as WaitEventOptions, n as WaitRequest, o as WaitStepResponse, f as WorkflowClient, e as WorkflowContext, w as WorkflowLogger, v as WorkflowLoggerOptions, g as WorkflowReceiver, d as WorkflowTool } from './types-C1WIgVLA.js';
3
- import { HTTPMethods, State, FlowControl, PublishRequest, Client as Client$1, QstashError } from '@upstash/qstash';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types-Dd-3bPoU.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, u as CallSettings, D as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, w as InvokableWorkflow, v as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, x as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, t as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, z as WorkflowLogger, y as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types-Dd-3bPoU.js';
3
+ import { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1 } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -60,6 +60,10 @@ type BaseStepLog = {
60
60
  * will be undefined for an unfinished parallel step.
61
61
  */
62
62
  out: unknown;
63
+ /**
64
+ * number of retries for the step
65
+ */
66
+ retries: number;
63
67
  /**
64
68
  * number of parallel steps
65
69
  *
@@ -184,6 +188,19 @@ type StepLogGroup = {
184
188
  steps: {
185
189
  messageId: string;
186
190
  state: "STEP_PROGRESS" | "STEP_RETRY" | "STEP_FAILED" | "STEP_CANCELED";
191
+ /**
192
+ * retries
193
+ */
194
+ retries: number;
195
+ /**
196
+ * errors which occured in the step
197
+ */
198
+ errors?: {
199
+ error: string;
200
+ headers: Record<string, string[]>;
201
+ status: number;
202
+ time: number;
203
+ }[];
187
204
  }[];
188
205
  /**
189
206
  * Log which belongs to the next step
@@ -215,6 +232,9 @@ type FailureFunctionLog = {
215
232
  * Response body of the step which caused the workflow to fail
216
233
  */
217
234
  failResponse: string;
235
+ /**
236
+ * @deprecated use dlqId field of the workflow run itself
237
+ */
218
238
  dlqId: string;
219
239
  };
220
240
  type WorkflowRunLog = {
@@ -281,11 +301,223 @@ type WorkflowRunLog = {
281
301
  */
282
302
  workflowRunCreatedAt: number;
283
303
  };
304
+ /**
305
+ * If the workflow run has failed, id of the run in DLQ
306
+ */
307
+ dlqId?: string;
284
308
  };
285
309
  type WorkflowRunLogs = {
286
310
  cursor: string;
287
311
  runs: WorkflowRunLog[];
288
312
  };
313
+ type TriggerOptions = {
314
+ /**
315
+ * URL of the workflow to trigger
316
+ */
317
+ url: string;
318
+ /**
319
+ * Body to send to the workflow
320
+ */
321
+ body?: unknown;
322
+ /**
323
+ * Headers to send to the workflow
324
+ */
325
+ headers?: Record<string, string>;
326
+ /**
327
+ * Workflow run id to use for the workflow run.
328
+ * If not provided, a random workflow run id will be generated.
329
+ */
330
+ workflowRunId?: string;
331
+ /**
332
+ * Number of retries to perform if the request fails.
333
+ *
334
+ * @default 3
335
+ */
336
+ retries?: number;
337
+ /**
338
+ * Flow control to use for the workflow run.
339
+ * If not provided, no flow control will be used.
340
+ */
341
+ flowControl?: FlowControl;
342
+ /**
343
+ * Delay to apply before triggering the workflow.
344
+ */
345
+ delay?: PublishRequest["delay"];
346
+ } & ({
347
+ /**
348
+ * URL to call if the first request to the workflow endpoint fails
349
+ */
350
+ failureUrl?: never;
351
+ /**
352
+ * Whether the workflow endpoint has a failure function
353
+ * defined to be invoked if the first request fails.
354
+ *
355
+ * If true, the failureUrl will be ignored.
356
+ */
357
+ useFailureFunction?: true;
358
+ } | {
359
+ /**
360
+ * URL to call if the first request to the workflow endpoint fails
361
+ */
362
+ failureUrl?: string;
363
+ /**
364
+ * Whether the workflow endpoint has a failure function
365
+ * defined to be invoked if the first request fails.
366
+ *
367
+ * If true, the failureUrl will be ignored.
368
+ */
369
+ useFailureFunction?: never;
370
+ });
371
+ type DLQResumeRestartOptions<TDLQId extends string | string[] = string | string[]> = {
372
+ dlqId: TDLQId;
373
+ } & Pick<TriggerOptions, "flowControl" | "retries">;
374
+ type DLQResumeRestartResponse = {
375
+ /**
376
+ * id of the workflow run created to resume or restart the DLQ message
377
+ */
378
+ workflowRunId: string;
379
+ /**
380
+ * Time when the new workflow run was created
381
+ */
382
+ workflowCreatedAt: string;
383
+ };
384
+
385
+ type QStashDLQFilterOptions = NonNullable<Required<Parameters<Client$1["dlq"]["listMessages"]>[0]>>["filter"];
386
+ type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus">;
387
+ type DLQMessage = {
388
+ messageId: string;
389
+ url: string;
390
+ method: string;
391
+ header: Record<string, string[]>;
392
+ body: string;
393
+ maxRetries: number;
394
+ notBefore: number;
395
+ createdAt: number;
396
+ callerIP: string;
397
+ workflowRunId: string;
398
+ workflowCreatedAt: number;
399
+ workflowUrl: string;
400
+ responseStatus: number;
401
+ responseHeader: Record<string, string[]>;
402
+ responseBody: string;
403
+ dlqId: string;
404
+ };
405
+ type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId">;
406
+ declare class DLQ {
407
+ private client;
408
+ constructor(client: Client$1);
409
+ /**
410
+ * list the items in the DLQ
411
+ *
412
+ * @param cursor - Optional cursor for pagination.
413
+ * @param count - Optional number of items to return.
414
+ * @param filter - Optional filter options to apply to the DLQ items.
415
+ * The available filter options are:
416
+ * - `fromDate`: Filter items which entered the DLQ after this date.
417
+ * - `toDate`: Filter items which entered the DLQ before this date.
418
+ * - `url`: Filter items by the URL they were sent to.
419
+ * - `responseStatus`: Filter items by the response status code.
420
+ * @returns
421
+ */
422
+ list(parameters?: {
423
+ cursor?: string;
424
+ count?: number;
425
+ filter?: DLQFilterOptions;
426
+ }): Promise<{
427
+ messages: PublicDLQMessage[];
428
+ cursor?: string;
429
+ }>;
430
+ /**
431
+ * Resumes the workflow run for the given DLQ message(s).
432
+ *
433
+ * Resuming means that the new workflow run will start executing from where
434
+ * the original workflow run failed, using the same input and context.
435
+ *
436
+ * If you want to restart the workflow run from the beginning, use
437
+ * `restart` method instead.
438
+ *
439
+ * Example with a single DLQ ID:
440
+ * ```ts
441
+ * const response = await client.dlq.resume({
442
+ * dlqId: "dlq-12345",
443
+ * flowControl: {
444
+ * key: "my-flow-control-key",
445
+ * value: "my-flow-control-value",
446
+ * },
447
+ * retries: 3,
448
+ * });
449
+ *
450
+ * console.log(response.workflowRunId); // ID of the new workflow run
451
+ * ```
452
+ *
453
+ * Example with multiple DLQ IDs:
454
+ * ```ts
455
+ * const response = await client.dlq.resume({
456
+ * dlqId: ["dlq-12345", "dlq-67890"],
457
+ * // other parameters...
458
+ * });
459
+ * console.log(response[0].workflowRunId); // ID of the first workflow run
460
+ * console.log(response[1].workflowRunId); // ID of the second workflow run
461
+ * ```
462
+ *
463
+ * if the dlqId is not found, throws an error.
464
+ *
465
+ * @param dlqId - The ID(s) of the DLQ message(s) to resume.
466
+ * @param flowControl - Optional flow control parameters. If not passed, flow
467
+ * control of the failing workflow will be used
468
+ * @param retries - Optional number of retries to perform if the request fails.
469
+ * If not passed, retries settings of the failing workflow will be used.
470
+ * @returns run id and creation time of the new workflow run(s).
471
+ */
472
+ resume(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
473
+ resume(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
474
+ /**
475
+ * Restarts the workflow run for the given DLQ message(s).
476
+ *
477
+ * Restarting means that the new workflow run will start executing from the
478
+ * beginning with the same initial payload and configuration.
479
+ *
480
+ * If you want to resume the workflow run from where it failed, use
481
+ * `resume` method instead.
482
+ *
483
+ * Example with a single DLQ ID:
484
+ * ```ts
485
+ * const response = await client.dlq.restart({
486
+ * dlqId: "dlq-12345",
487
+ * flowControl: {
488
+ * key: "my-flow-control-key",
489
+ * value: "my-flow-control-value",
490
+ * },
491
+ * retries: 3,
492
+ * });
493
+ *
494
+ * console.log(response.workflowRunId); // ID of the new workflow run
495
+ * ```
496
+ *
497
+ * Example with multiple DLQ IDs:
498
+ * ```ts
499
+ * const response = await client.dlq.restart({
500
+ * dlqId: ["dlq-12345", "dlq-67890"],
501
+ * // other parameters...
502
+ * });
503
+ * console.log(response[0].workflowRunId); // ID of the first workflow run
504
+ * console.log(response[1].workflowRunId); // ID of the second workflow run
505
+ * ```
506
+ *
507
+ * if the dlqId is not found, throws an error.
508
+ *
509
+ * @param dlqId - The ID(s) of the DLQ message(s) to restart.
510
+ * @param flowControl - Optional flow control parameters. If not passed, flow
511
+ * control of the failing workflow will be used
512
+ * @param retries - Optional number of retries to perform if the request fails.
513
+ * If not passed, retries settings of the failing workflow will be used.
514
+ * @returns run id and creation time of the new workflow run(s).
515
+ */
516
+ restart(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
517
+ restart(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
518
+ private static handleDLQOptions;
519
+ private static getDlqIdQueryParameter;
520
+ }
289
521
 
290
522
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
291
523
  /**
@@ -398,8 +630,9 @@ declare class Client {
398
630
  eventId: string;
399
631
  }): Promise<Required<Waiter>[]>;
400
632
  /**
401
- * Trigger new workflow run and returns the workflow run id
633
+ * Trigger new workflow run and returns the workflow run id or an array of workflow run ids
402
634
  *
635
+ * trigger a single workflow run:
403
636
  * ```ts
404
637
  * const { workflowRunId } = await client.trigger({
405
638
  * url: "https://workflow-endpoint.com",
@@ -412,6 +645,31 @@ declare class Client {
412
645
  * console.log(workflowRunId)
413
646
  * // wfr_my-workflow
414
647
  * ```
648
+ * trigger multiple workflow runs:
649
+ * ```ts
650
+ * const result = await client.trigger([
651
+ * {
652
+ * url: "https://workflow-endpoint.com",
653
+ * body: "hello there!", // Optional body
654
+ * headers: { ... }, // Optional headers
655
+ * workflowRunId: "my-workflow", // Optional workflow run ID
656
+ * retries: 3 // Optional retries for the initial request
657
+ * },
658
+ * {
659
+ * url: "https://workflow-endpoint-2.com",
660
+ * body: "hello world!", // Optional body
661
+ * headers: { ... }, // Optional headers
662
+ * workflowRunId: "my-workflow-2", // Optional workflow run ID
663
+ * retries: 5 // Optional retries for the initial request
664
+ * },
665
+ * ]);
666
+ *
667
+ * console.log(result)
668
+ * // [
669
+ * // { workflowRunId: "wfr_my-workflow" },
670
+ * // { workflowRunId: "wfr_my-workflow-2" },
671
+ * // ]
672
+ * ```
415
673
  *
416
674
  * @param url URL of the workflow
417
675
  * @param body body to start the workflow with
@@ -428,19 +686,14 @@ declare class Client {
428
686
  * @param delay Delay for the workflow run. This is used to delay the
429
687
  * execution of the workflow run. The delay is in seconds or can be passed
430
688
  * as a string with a time unit (e.g. "1h", "30m", "15s").
431
- * @returns workflow run id
432
- */
433
- trigger({ url, body, headers, workflowRunId, retries, flowControl, delay, }: {
434
- url: string;
435
- body?: unknown;
436
- headers?: Record<string, string>;
437
- workflowRunId?: string;
438
- retries?: number;
439
- flowControl?: FlowControl;
440
- delay?: PublishRequest["delay"];
441
- }): Promise<{
689
+ * @returns workflow run id or an array of workflow run ids
690
+ */
691
+ trigger(params: TriggerOptions): Promise<{
442
692
  workflowRunId: string;
443
693
  }>;
694
+ trigger(params: TriggerOptions[]): Promise<{
695
+ workflowRunId: string;
696
+ }[]>;
444
697
  /**
445
698
  * Fetches logs for workflow runs.
446
699
  *
@@ -476,32 +729,7 @@ declare class Client {
476
729
  workflowUrl?: WorkflowRunLog["workflowUrl"];
477
730
  workflowCreatedAt?: WorkflowRunLog["workflowRunCreatedAt"];
478
731
  }): Promise<WorkflowRunLogs>;
732
+ get dlq(): DLQ;
479
733
  }
480
734
 
481
- /**
482
- * Error raised during Workflow execution
483
- */
484
- declare class WorkflowError extends QstashError {
485
- constructor(message: string);
486
- }
487
- /**
488
- * Raised when the workflow executes a function successfully
489
- * and aborts to end the execution
490
- */
491
- declare class WorkflowAbort extends Error {
492
- stepInfo?: Step;
493
- stepName: string;
494
- /**
495
- * whether workflow is to be canceled on abort
496
- */
497
- cancelWorkflow: boolean;
498
- /**
499
- *
500
- * @param stepName name of the aborting step
501
- * @param stepInfo step information
502
- * @param cancelWorkflow
503
- */
504
- constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
505
- }
506
-
507
- export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
735
+ export { Client, type DLQResumeRestartOptions, type DLQResumeRestartResponse, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };