@upstash/workflow 0.2.12 → 0.2.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/hono.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-4GTHIL7S.mjs";
5
+ } from "./chunk-RMS2NQ3K.mjs";
6
6
 
7
7
  // platforms/hono.ts
8
8
  var telemetry = {
@@ -11,7 +11,7 @@ var telemetry = {
11
11
  };
12
12
  var serve = (routeFunction, options) => {
13
13
  const handler = async (context) => {
14
- const environment = context.env;
14
+ const environment = context.env ? context.env : typeof process === "undefined" ? {} : process.env;
15
15
  const request = context.req.raw;
16
16
  const { handler: serveHandler } = serveBase(routeFunction, telemetry, {
17
17
  // when hono is used without cf workers, it sends a DebugHTTPServer
package/index.d.mts 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-D1W0VOpy.mjs';
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-D1W0VOpy.mjs';
3
- import { HTTPMethods, State, FlowControl, 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, c as Step } from './types-C1WIgVLA.mjs';
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.mjs';
3
+ import { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -78,6 +78,10 @@ type BaseStepLog = {
78
78
  * headers
79
79
  */
80
80
  headers: Record<string, string[]>;
81
+ /**
82
+ * retries
83
+ */
84
+ retries: number;
81
85
  };
82
86
  type CallUrlGroup = {
83
87
  /**
@@ -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,73 @@ 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
+ });
289
371
 
290
372
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
291
373
  /**
@@ -398,8 +480,9 @@ declare class Client {
398
480
  eventId: string;
399
481
  }): Promise<Required<Waiter>[]>;
400
482
  /**
401
- * Trigger new workflow run and returns the workflow run id
483
+ * Trigger new workflow run and returns the workflow run id or an array of workflow run ids
402
484
  *
485
+ * trigger a single workflow run:
403
486
  * ```ts
404
487
  * const { workflowRunId } = await client.trigger({
405
488
  * url: "https://workflow-endpoint.com",
@@ -412,6 +495,31 @@ declare class Client {
412
495
  * console.log(workflowRunId)
413
496
  * // wfr_my-workflow
414
497
  * ```
498
+ * trigger multiple workflow runs:
499
+ * ```ts
500
+ * const result = await client.trigger([
501
+ * {
502
+ * url: "https://workflow-endpoint.com",
503
+ * body: "hello there!", // Optional body
504
+ * headers: { ... }, // Optional headers
505
+ * workflowRunId: "my-workflow", // Optional workflow run ID
506
+ * retries: 3 // Optional retries for the initial request
507
+ * },
508
+ * {
509
+ * url: "https://workflow-endpoint-2.com",
510
+ * body: "hello world!", // Optional body
511
+ * headers: { ... }, // Optional headers
512
+ * workflowRunId: "my-workflow-2", // Optional workflow run ID
513
+ * retries: 5 // Optional retries for the initial request
514
+ * },
515
+ * ]);
516
+ *
517
+ * console.log(result)
518
+ * // [
519
+ * // { workflowRunId: "wfr_my-workflow" },
520
+ * // { workflowRunId: "wfr_my-workflow-2" },
521
+ * // ]
522
+ * ```
415
523
  *
416
524
  * @param url URL of the workflow
417
525
  * @param body body to start the workflow with
@@ -423,18 +531,19 @@ declare class Client {
423
531
  * with `wfr_`.
424
532
  * @param retries retry to use in the initial request. in the rest of
425
533
  * the workflow, `retries` option of the `serve` will be used.
426
- * @returns workflow run id
427
- */
428
- trigger({ url, body, headers, workflowRunId, retries, flowControl, }: {
429
- url: string;
430
- body?: unknown;
431
- headers?: Record<string, string>;
432
- workflowRunId?: string;
433
- retries?: number;
434
- flowControl?: FlowControl;
435
- }): Promise<{
534
+ * @param flowControl Settings for controlling the number of active requests
535
+ * and number of requests per second with the same key.
536
+ * @param delay Delay for the workflow run. This is used to delay the
537
+ * execution of the workflow run. The delay is in seconds or can be passed
538
+ * as a string with a time unit (e.g. "1h", "30m", "15s").
539
+ * @returns workflow run id or an array of workflow run ids
540
+ */
541
+ trigger(params: TriggerOptions): Promise<{
436
542
  workflowRunId: string;
437
543
  }>;
544
+ trigger(params: TriggerOptions[]): Promise<{
545
+ workflowRunId: string;
546
+ }[]>;
438
547
  /**
439
548
  * Fetches logs for workflow runs.
440
549
  *
@@ -498,4 +607,4 @@ declare class WorkflowAbort extends Error {
498
607
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
499
608
  }
500
609
 
501
- export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
610
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
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-D1W0VOpy.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-D1W0VOpy.js';
3
- import { HTTPMethods, State, FlowControl, 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, 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 { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1, QstashError } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
6
6
  import '@ai-sdk/openai';
@@ -78,6 +78,10 @@ type BaseStepLog = {
78
78
  * headers
79
79
  */
80
80
  headers: Record<string, string[]>;
81
+ /**
82
+ * retries
83
+ */
84
+ retries: number;
81
85
  };
82
86
  type CallUrlGroup = {
83
87
  /**
@@ -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,73 @@ 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
+ });
289
371
 
290
372
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
291
373
  /**
@@ -398,8 +480,9 @@ declare class Client {
398
480
  eventId: string;
399
481
  }): Promise<Required<Waiter>[]>;
400
482
  /**
401
- * Trigger new workflow run and returns the workflow run id
483
+ * Trigger new workflow run and returns the workflow run id or an array of workflow run ids
402
484
  *
485
+ * trigger a single workflow run:
403
486
  * ```ts
404
487
  * const { workflowRunId } = await client.trigger({
405
488
  * url: "https://workflow-endpoint.com",
@@ -412,6 +495,31 @@ declare class Client {
412
495
  * console.log(workflowRunId)
413
496
  * // wfr_my-workflow
414
497
  * ```
498
+ * trigger multiple workflow runs:
499
+ * ```ts
500
+ * const result = await client.trigger([
501
+ * {
502
+ * url: "https://workflow-endpoint.com",
503
+ * body: "hello there!", // Optional body
504
+ * headers: { ... }, // Optional headers
505
+ * workflowRunId: "my-workflow", // Optional workflow run ID
506
+ * retries: 3 // Optional retries for the initial request
507
+ * },
508
+ * {
509
+ * url: "https://workflow-endpoint-2.com",
510
+ * body: "hello world!", // Optional body
511
+ * headers: { ... }, // Optional headers
512
+ * workflowRunId: "my-workflow-2", // Optional workflow run ID
513
+ * retries: 5 // Optional retries for the initial request
514
+ * },
515
+ * ]);
516
+ *
517
+ * console.log(result)
518
+ * // [
519
+ * // { workflowRunId: "wfr_my-workflow" },
520
+ * // { workflowRunId: "wfr_my-workflow-2" },
521
+ * // ]
522
+ * ```
415
523
  *
416
524
  * @param url URL of the workflow
417
525
  * @param body body to start the workflow with
@@ -423,18 +531,19 @@ declare class Client {
423
531
  * with `wfr_`.
424
532
  * @param retries retry to use in the initial request. in the rest of
425
533
  * the workflow, `retries` option of the `serve` will be used.
426
- * @returns workflow run id
427
- */
428
- trigger({ url, body, headers, workflowRunId, retries, flowControl, }: {
429
- url: string;
430
- body?: unknown;
431
- headers?: Record<string, string>;
432
- workflowRunId?: string;
433
- retries?: number;
434
- flowControl?: FlowControl;
435
- }): Promise<{
534
+ * @param flowControl Settings for controlling the number of active requests
535
+ * and number of requests per second with the same key.
536
+ * @param delay Delay for the workflow run. This is used to delay the
537
+ * execution of the workflow run. The delay is in seconds or can be passed
538
+ * as a string with a time unit (e.g. "1h", "30m", "15s").
539
+ * @returns workflow run id or an array of workflow run ids
540
+ */
541
+ trigger(params: TriggerOptions): Promise<{
436
542
  workflowRunId: string;
437
543
  }>;
544
+ trigger(params: TriggerOptions[]): Promise<{
545
+ workflowRunId: string;
546
+ }[]>;
438
547
  /**
439
548
  * Fetches logs for workflow runs.
440
549
  *
@@ -498,4 +607,4 @@ declare class WorkflowAbort extends Error {
498
607
  constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
499
608
  }
500
609
 
501
- export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
610
+ export { Client, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, Step, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, WorkflowAbort, WorkflowError, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };