@upstash/workflow 1.4.0 → 1.5.0

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.
Files changed (223) hide show
  1. package/README.md +9 -0
  2. package/astro.d.mts +19 -2
  3. package/astro.d.ts +19 -2
  4. package/astro.js +670 -159
  5. package/astro.mjs +1 -1
  6. package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
  7. package/cloudflare.d.mts +17 -2
  8. package/cloudflare.d.ts +17 -2
  9. package/cloudflare.js +670 -159
  10. package/cloudflare.mjs +1 -1
  11. package/docs/agents/examples.mdx +8 -0
  12. package/docs/agents/features.mdx +374 -0
  13. package/docs/agents/getting-started.mdx +139 -0
  14. package/docs/agents/overview.mdx +40 -0
  15. package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
  16. package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
  17. package/docs/agents/patterns/parallelization.mdx +77 -0
  18. package/docs/agents/patterns/prompt-chaining.mdx +84 -0
  19. package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
  20. package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
  21. package/docs/basics/best-practices/deterministic-code.mdx +132 -0
  22. package/docs/basics/best-practices/idempotency.mdx +38 -0
  23. package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
  24. package/docs/basics/best-practices/overview.mdx +35 -0
  25. package/docs/basics/best-practices/promise-any.mdx +9 -0
  26. package/docs/basics/best-practices/return-step-results.mdx +80 -0
  27. package/docs/basics/best-practices/workflow-limits.mdx +62 -0
  28. package/docs/basics/client/cancel.mdx +137 -0
  29. package/docs/basics/client/dlq/callback.mdx +21 -0
  30. package/docs/basics/client/dlq/delete.mdx +120 -0
  31. package/docs/basics/client/dlq/list.mdx +96 -0
  32. package/docs/basics/client/dlq/restart.mdx +164 -0
  33. package/docs/basics/client/dlq/resume.mdx +167 -0
  34. package/docs/basics/client/logs.mdx +139 -0
  35. package/docs/basics/client/notify.mdx +79 -0
  36. package/docs/basics/client/trigger.mdx +139 -0
  37. package/docs/basics/client/waiters.mdx +31 -0
  38. package/docs/basics/client.mdx +40 -0
  39. package/docs/basics/how.mdx +65 -0
  40. package/docs/basics/serve/advanced.mdx +435 -0
  41. package/docs/basics/serve.mdx +142 -0
  42. package/docs/changelog.mdx +174 -0
  43. package/docs/examples/allInOne.mdx +377 -0
  44. package/docs/examples/authWebhook.mdx +567 -0
  45. package/docs/examples/customRetry.mdx +309 -0
  46. package/docs/examples/customerOnboarding.mdx +230 -0
  47. package/docs/examples/dynamicWorkflow.mdx +203 -0
  48. package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
  49. package/docs/examples/imageProcessing.mdx +339 -0
  50. package/docs/examples/paymentRetry.mdx +438 -0
  51. package/docs/examples/waitForEvent.mdx +201 -0
  52. package/docs/features/dlq/callback.mdx +42 -0
  53. package/docs/features/dlq/delete.mdx +29 -0
  54. package/docs/features/dlq/restart.mdx +33 -0
  55. package/docs/features/dlq/resume.mdx +37 -0
  56. package/docs/features/dlq.mdx +39 -0
  57. package/docs/features/failure-callback.mdx +102 -0
  58. package/docs/features/failureFunction/advanced.mdx +36 -0
  59. package/docs/features/failureFunction/reliability.mdx +33 -0
  60. package/docs/features/flow-control/monitor.mdx +22 -0
  61. package/docs/features/flow-control/parallelism.mdx +45 -0
  62. package/docs/features/flow-control/rate-period.mdx +46 -0
  63. package/docs/features/flow-control.mdx +164 -0
  64. package/docs/features/invoke/serveMany.mdx +109 -0
  65. package/docs/features/invoke.mdx +39 -0
  66. package/docs/features/notify.mdx +127 -0
  67. package/docs/features/parallel-steps.mdx +41 -0
  68. package/docs/features/retries/prevent-retries.mdx +140 -0
  69. package/docs/features/retries.mdx +93 -0
  70. package/docs/features/wait-for-event.mdx +104 -0
  71. package/docs/features/wait.mdx +44 -0
  72. package/docs/features/webhooks.mdx +116 -0
  73. package/docs/getstarted.mdx +200 -0
  74. package/docs/howto/cancel.mdx +50 -0
  75. package/docs/howto/changes.mdx +33 -0
  76. package/docs/howto/configure.mdx +42 -0
  77. package/docs/howto/failures.mdx +185 -0
  78. package/docs/howto/get-token.mdx +18 -0
  79. package/docs/howto/local-development/development-server.mdx +130 -0
  80. package/docs/howto/local-development/local-tunnel.mdx +73 -0
  81. package/docs/howto/middlewares.mdx +263 -0
  82. package/docs/howto/migrations.mdx +335 -0
  83. package/docs/howto/multi-region.mdx +107 -0
  84. package/docs/howto/parallel-runs.mdx +52 -0
  85. package/docs/howto/readonly-token.mdx +19 -0
  86. package/docs/howto/realtime/basic.mdx +315 -0
  87. package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
  88. package/docs/howto/redact-fields.mdx +61 -0
  89. package/docs/howto/retry-now.mdx +41 -0
  90. package/docs/howto/schedule.mdx +104 -0
  91. package/docs/howto/security.mdx +143 -0
  92. package/docs/howto/singleton.mdx +137 -0
  93. package/docs/howto/start.mdx +69 -0
  94. package/docs/howto/use-webhooks.mdx +256 -0
  95. package/docs/integrations/aisdk.mdx +316 -0
  96. package/docs/integrations/anthropic.mdx +51 -0
  97. package/docs/integrations/datadog.mdx +69 -0
  98. package/docs/integrations/openai.mdx +87 -0
  99. package/docs/integrations/prometheus.mdx +65 -0
  100. package/docs/integrations/resend.mdx +82 -0
  101. package/docs/llms-txt.mdx +4 -0
  102. package/docs/openapi.yaml +2944 -0
  103. package/docs/pricing.mdx +22 -0
  104. package/docs/quickstarts/astro.mdx +185 -0
  105. package/docs/quickstarts/cloudflare-workers.mdx +190 -0
  106. package/docs/quickstarts/express.mdx +190 -0
  107. package/docs/quickstarts/fastapi.mdx +282 -0
  108. package/docs/quickstarts/flask.mdx +282 -0
  109. package/docs/quickstarts/hono.mdx +221 -0
  110. package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
  111. package/docs/quickstarts/nextjs-flask.mdx +147 -0
  112. package/docs/quickstarts/nuxt.mdx +169 -0
  113. package/docs/quickstarts/platforms.mdx +78 -0
  114. package/docs/quickstarts/solidjs.mdx +161 -0
  115. package/docs/quickstarts/svelte.mdx +170 -0
  116. package/docs/quickstarts/tanstack-start.mdx +205 -0
  117. package/docs/quickstarts/vercel-nextjs.mdx +233 -0
  118. package/docs/roadmap.mdx +8 -0
  119. package/docs/sdk/workflow-js.mdx +4 -0
  120. package/docs/sdk/workflow-py.mdx +4 -0
  121. package/docs/steps/api.mdx +64 -0
  122. package/docs/steps/call.mdx +183 -0
  123. package/docs/steps/cancel.mdx +25 -0
  124. package/docs/steps/createWebhook.mdx +40 -0
  125. package/docs/steps/invoke.mdx +100 -0
  126. package/docs/steps/notify.mdx +105 -0
  127. package/docs/steps/run.mdx +150 -0
  128. package/docs/steps/sleep.mdx +97 -0
  129. package/docs/steps/sleepUntil.mdx +88 -0
  130. package/docs/steps/waitForEvent.mdx +60 -0
  131. package/docs/steps/waitForWebhook.mdx +78 -0
  132. package/docs/steps.mdx +108 -0
  133. package/docs/troubleshooting/general.mdx +331 -0
  134. package/docs/troubleshooting/vercel.mdx +82 -0
  135. package/express.d.mts +19 -2
  136. package/express.d.ts +19 -2
  137. package/express.js +670 -159
  138. package/express.mjs +1 -1
  139. package/h3.d.mts +19 -2
  140. package/h3.d.ts +19 -2
  141. package/h3.js +670 -159
  142. package/h3.mjs +1 -1
  143. package/hono.d.mts +17 -2
  144. package/hono.d.ts +17 -2
  145. package/hono.js +670 -159
  146. package/hono.mjs +1 -1
  147. package/index.d.mts +50 -21
  148. package/index.d.ts +50 -21
  149. package/index.js +686 -171
  150. package/index.mjs +17 -13
  151. package/nextjs.d.mts +40 -2
  152. package/nextjs.d.ts +40 -2
  153. package/nextjs.js +670 -159
  154. package/nextjs.mjs +1 -1
  155. package/package.json +1 -1
  156. package/react-router.d.mts +16 -2
  157. package/react-router.d.ts +16 -2
  158. package/react-router.js +670 -159
  159. package/react-router.mjs +1 -1
  160. package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
  161. package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
  162. package/solidjs.d.mts +10 -1
  163. package/solidjs.d.ts +10 -1
  164. package/solidjs.js +670 -159
  165. package/solidjs.mjs +1 -1
  166. package/src/platforms/astro.ts +84 -0
  167. package/src/platforms/cloudflare.ts +127 -0
  168. package/src/platforms/express.ts +147 -0
  169. package/src/platforms/h3.ts +105 -0
  170. package/src/platforms/hono.ts +103 -0
  171. package/src/platforms/nextjs.ts +193 -0
  172. package/src/platforms/react-router.ts +92 -0
  173. package/src/platforms/solidjs.ts +59 -0
  174. package/src/platforms/svelte.ts +99 -0
  175. package/src/platforms/tanstack.ts +96 -0
  176. package/src/src/client/dlq.ts +387 -0
  177. package/src/src/client/filter-types.ts +166 -0
  178. package/src/src/client/index.ts +350 -0
  179. package/src/src/client/types.ts +501 -0
  180. package/src/src/client/utils.ts +307 -0
  181. package/src/src/constants.ts +82 -0
  182. package/src/src/context/api/anthropic.ts +58 -0
  183. package/src/src/context/api/base.ts +52 -0
  184. package/src/src/context/api/index.ts +24 -0
  185. package/src/src/context/api/openai.ts +125 -0
  186. package/src/src/context/api/resend.ts +57 -0
  187. package/src/src/context/auto-executor.ts +707 -0
  188. package/src/src/context/context.ts +681 -0
  189. package/src/src/context/index.ts +1 -0
  190. package/src/src/context/provider.ts +37 -0
  191. package/src/src/context/steps.ts +965 -0
  192. package/src/src/error.ts +203 -0
  193. package/src/src/index.ts +13 -0
  194. package/src/src/middleware/default-callbacks.ts +20 -0
  195. package/src/src/middleware/index.ts +2 -0
  196. package/src/src/middleware/logging.ts +39 -0
  197. package/src/src/middleware/manager.ts +148 -0
  198. package/src/src/middleware/middleware.ts +46 -0
  199. package/src/src/middleware/types.ts +72 -0
  200. package/src/src/qstash/headers.ts +397 -0
  201. package/src/src/qstash/step-config.ts +268 -0
  202. package/src/src/qstash/submit-steps.ts +284 -0
  203. package/src/src/serve/authorization.ts +118 -0
  204. package/src/src/serve/index.ts +475 -0
  205. package/src/src/serve/multi-region/handlers.ts +225 -0
  206. package/src/src/serve/multi-region/utils.ts +88 -0
  207. package/src/src/serve/options.ts +241 -0
  208. package/src/src/serve/serve-many.ts +117 -0
  209. package/src/src/serve/utils.ts +11 -0
  210. package/src/src/types.ts +590 -0
  211. package/src/src/utils.ts +141 -0
  212. package/src/src/workflow-parser.ts +472 -0
  213. package/src/src/workflow-requests.ts +575 -0
  214. package/svelte.d.mts +17 -2
  215. package/svelte.d.ts +17 -2
  216. package/svelte.js +670 -159
  217. package/svelte.mjs +1 -1
  218. package/tanstack.d.mts +15 -2
  219. package/tanstack.d.ts +15 -2
  220. package/tanstack.js +670 -159
  221. package/tanstack.mjs +1 -1
  222. package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
  223. package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
@@ -0,0 +1,80 @@
1
+ ---
2
+ title: "Return Results from context.run"
3
+ sidebarTitle: "Return Step Results"
4
+ ---
5
+
6
+ Always return step results if needed in subsequent steps.
7
+
8
+ <CodeGroup>
9
+
10
+ ```typescript ❌ Incorrect - TypeScript
11
+ export const { POST } = serve<string>(async (context) => {
12
+ const input = context.requestPayload
13
+
14
+ let result
15
+
16
+ await context.run("step-1", async () => {
17
+ result = await someWork(input)
18
+ })
19
+ await context.run("step-2", async () => {
20
+ await someOtherWork(result)
21
+ })
22
+ })
23
+ ```
24
+
25
+ ```typescript ✅ Correct - TypeScript
26
+ export const { POST } = serve<string>(async (context) => {
27
+ const input = context.requestPayload
28
+
29
+ const result = await context.run("step-1", async () => {
30
+ return await someWork(input)
31
+ })
32
+
33
+ await context.run("step-2", async () => {
34
+ someOtherWork(result)
35
+ })
36
+ })
37
+ ```
38
+
39
+ ```python ❌ Incorrect - Python
40
+ @serve.post("/api/example")
41
+ async def example(context: AsyncWorkflowContext[str]) -> None:
42
+ input = context.request_payload
43
+
44
+ result = None
45
+
46
+ async def _step_1() -> Dict:
47
+ nonlocal result
48
+ result = await some_work(input)
49
+
50
+ await context.run("step-1", _step_1)
51
+
52
+ async def _step_2() -> None:
53
+ await some_other_work(result)
54
+
55
+ await context.run("step-2", _step_2)
56
+
57
+ ```
58
+
59
+ ```python ✅ Correct - Python
60
+ @serve.post("/api/example")
61
+ async def example(context: AsyncWorkflowContext[str]) -> None:
62
+ input = context.request_payload
63
+
64
+ async def _step_1() -> Dict:
65
+ return await some_work(input)
66
+
67
+ result = await context.run("step-1", _step_1)
68
+
69
+ async def _step_2() -> None:
70
+ await some_other_work(result)
71
+
72
+ await context.run("step-2", _step_2)
73
+
74
+ ```
75
+
76
+ </CodeGroup>
77
+
78
+ Because your workflow endpoint is called multiple times, `result` will be uninitialized when the endpoint is called again to run `step-2`.
79
+
80
+ If you are curious about why an endpoint is called multiple times, see [how Workflow works](/workflow/basics/how).
@@ -0,0 +1,62 @@
1
+ ---
2
+ title: "Avoid Context and Step Limits"
3
+ sidebarTitle: "Workflow Limits"
4
+ ---
5
+
6
+ A single workflow run has the following hard limits:
7
+
8
+ - **Maximum step count:** 1,000 steps
9
+ - **Maximum context size:** 100 MB
10
+
11
+ These limits are hard limits and do not vary by plan. Avoid putting all of your application logic into one large workflow that could reach either limit.
12
+
13
+ The context size is the combined size of the workflow input and the results of all completed steps. Each new step result is added to that context, so the context grows as the workflow completes more steps. Workflows with many steps, large step results, or both can reach the context size limit.
14
+
15
+ Instead, separate the logic into multiple workflows and connect them with [`context.invoke`](/workflow/features/invoke). Each invoked workflow has its own context containing its input and step results. When the invoked workflow finishes, only its final output is transferred to the parent workflow as the result of a single `context.invoke` step. Its intermediate step results are not added to the parent's context.
16
+
17
+ ```typescript app/workflows/[...path]/route.ts
18
+ import type { WorkflowContext } from "@upstash/workflow"
19
+ import { createWorkflow, serveMany } from "@upstash/workflow/nextjs"
20
+
21
+ type BatchInput = { itemIds: string[] }
22
+
23
+ const processBatch = createWorkflow(
24
+ async (context: WorkflowContext<BatchInput>) => {
25
+ const validatedItems = await context.run("validate items", () => {
26
+ return context.requestPayload.itemIds.filter((itemId) => itemId.length > 0)
27
+ })
28
+
29
+ const processedItems = await context.run("process items", () => {
30
+ return validatedItems.map((itemId) => ({ itemId, processed: true }))
31
+ })
32
+
33
+ // Only this final output is transferred to the parent workflow.
34
+ return { processedCount: processedItems.length }
35
+ }
36
+ )
37
+
38
+ const parentWorkflow = createWorkflow(
39
+ async (context: WorkflowContext<BatchInput>) => {
40
+ const { body, isFailed, isCanceled } = await context.invoke(
41
+ "process batch",
42
+ {
43
+ workflow: processBatch,
44
+ body: context.requestPayload,
45
+ }
46
+ )
47
+
48
+ if (isFailed || isCanceled) {
49
+ throw new Error("The batch workflow did not complete successfully")
50
+ }
51
+
52
+ return body
53
+ }
54
+ )
55
+
56
+ export const { POST } = serveMany({
57
+ parent: parentWorkflow,
58
+ "process-batch": processBatch,
59
+ })
60
+ ```
61
+
62
+ In this example, `validatedItems` and `processedItems` are stored only in the invoked workflow's context. The parent context receives `{ processedCount }` as one step result. This keeps each workflow focused and prevents intermediate results from accumulating in a single context.
@@ -0,0 +1,137 @@
1
+ ---
2
+ title: "client.cancel"
3
+ ---
4
+
5
+ Cancel one or more workflow runs. You can pass IDs directly, use filters, or cancel all at once.
6
+
7
+ ## Arguments
8
+
9
+ The `cancel` method accepts one of the following:
10
+
11
+ ### By ID
12
+
13
+ Pass a single workflow run ID or an array of IDs directly:
14
+
15
+ ```ts
16
+ await client.cancel("<WORKFLOW_RUN_ID>");
17
+ await client.cancel(["<ID_1>", "<ID_2>"]);
18
+ ```
19
+
20
+ ### By filters
21
+
22
+ Pass an object with a `filter` field containing one or more filter criteria:
23
+
24
+ <ParamField body="filter" type="object">
25
+ <Expandable defaultOpen>
26
+ <ParamField body="workflowUrl" type="string" optional>
27
+ Cancel workflows matching this exact URL. Cannot be combined with `workflowUrlStartingWith`.
28
+ </ParamField>
29
+
30
+ <ParamField body="workflowUrlStartingWith" type="string" optional>
31
+ Cancel workflows whose URL starts with this prefix. Cannot be combined with `workflowUrl`.
32
+ </ParamField>
33
+
34
+ <ParamField body="label" type="string | string[]" optional>
35
+ Cancel workflows with this label. Pass an array to match runs that
36
+ have any of the given labels (OR semantics).
37
+ </ParamField>
38
+
39
+ <ParamField body="fromDate" type="Date | number" optional>
40
+ Cancel workflows created after this date. Accepts `Date` objects or Unix timestamps (ms).
41
+ </ParamField>
42
+
43
+ <ParamField body="toDate" type="Date | number" optional>
44
+ Cancel workflows created before this date. Accepts `Date` objects or Unix timestamps (ms).
45
+ </ParamField>
46
+
47
+ <ParamField body="callerIp" type="string" optional>
48
+ Cancel workflows triggered by this IP address.
49
+ </ParamField>
50
+
51
+ <ParamField body="flowControlKey" type="string" optional>
52
+ Cancel workflows with this flow control key.
53
+ </ParamField>
54
+ </Expandable>
55
+ </ParamField>
56
+
57
+ <ParamField body="count" type="number" optional>
58
+ Maximum number of workflow runs to cancel per call. Defaults to `100`.
59
+ </ParamField>
60
+
61
+ ### Cancel all
62
+
63
+ <ParamField body="all" type="boolean">
64
+ Set to `true` to cancel all pending and active workflow runs.
65
+ </ParamField>
66
+
67
+ ## Response
68
+
69
+ <ResponseField name="cancelled" type="number">
70
+ The number of workflow runs that were cancelled.
71
+ </ResponseField>
72
+
73
+ ## Usage
74
+
75
+ ### Cancel by ID
76
+
77
+ ```ts
78
+ // cancel a single workflow
79
+ await client.cancel("<WORKFLOW_RUN_ID>");
80
+
81
+ // cancel a set of workflow runs
82
+ await client.cancel(["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"]);
83
+ ```
84
+
85
+ ### Cancel with URL filter
86
+
87
+ Cancel all workflow runs on a specific endpoint using a URL prefix:
88
+
89
+ ```ts
90
+ await client.cancel({
91
+ filter: { workflowUrlStartingWith: "https://your-endpoint.com" }
92
+ });
93
+ ```
94
+
95
+ For an exact URL match:
96
+
97
+ ```ts
98
+ await client.cancel({
99
+ filter: { workflowUrl: "https://your-endpoint.com/api/workflow" }
100
+ });
101
+ ```
102
+
103
+ ### Cancel with filters
104
+
105
+ You can combine multiple filter parameters:
106
+
107
+ ```ts
108
+ // cancel by label
109
+ await client.cancel({ filter: { label: "my-label" } });
110
+
111
+ // cancel by label and date range
112
+ await client.cancel({
113
+ filter: {
114
+ label: "my-label",
115
+ fromDate: 1640995200000,
116
+ }
117
+ });
118
+
119
+ // cancel by URL and date range
120
+ await client.cancel({
121
+ filter: {
122
+ workflowUrl: "https://your-endpoint.com/api/workflow",
123
+ fromDate: new Date("2024-01-01"),
124
+ toDate: new Date("2024-06-01"),
125
+ }
126
+ });
127
+ ```
128
+
129
+ ### Cancel _all_ workflows
130
+
131
+ ```ts
132
+ let cancelled: number;
133
+ do {
134
+ const result = await client.cancel({ all: true });
135
+ cancelled = result.cancelled;
136
+ } while (cancelled > 0);
137
+ ```
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: "client.dlq.retryFailureFunction"
3
+ ---
4
+
5
+ If a workflow's `failureFunction` or `failureUrl` request has failed, you can retry it using the `retryFailureFunction` method:
6
+
7
+ ## Arguments
8
+
9
+ ## Response
10
+
11
+ ## Usage
12
+ ```ts
13
+ import { Client } from "@upstash/workflow";
14
+
15
+ const client = new Client({ token: "<QSTASH_TOKEN>" });
16
+
17
+ // Retry the failure callback for a specific DLQ message
18
+ const response = await client.dlq.retryFailureFunction({
19
+ dlqId: "dlq-12345" // The ID of the DLQ message to retry
20
+ });
21
+ ```
@@ -0,0 +1,120 @@
1
+ ---
2
+ title: "client.dlq.delete"
3
+ ---
4
+
5
+ The `dlq.delete` method deletes one or more workflow runs from the **Dead Letter Queue (DLQ)**.
6
+
7
+ ## Arguments
8
+
9
+ You can delete DLQ entries by ID, by an array of IDs, or by filters.
10
+
11
+ ### By DLQ ID
12
+
13
+ Pass a single DLQ ID or an array of IDs directly:
14
+
15
+ ```ts
16
+ await client.dlq.delete("dlq-123");
17
+ await client.dlq.delete(["dlq-123", "dlq-456"]);
18
+ ```
19
+
20
+ Or as an object with `dlqIds`:
21
+
22
+ ```ts
23
+ await client.dlq.delete({ dlqIds: ["dlq-123", "dlq-456"] });
24
+ ```
25
+
26
+ ### By filters
27
+
28
+ <ParamField body="filter" type="object">
29
+ <Expandable defaultOpen>
30
+ <ParamField body="workflowUrl" type="string" optional>
31
+ Filter by exact workflow URL.
32
+ </ParamField>
33
+
34
+ <ParamField body="workflowRunId" type="string" optional>
35
+ Filter by workflow run ID.
36
+ </ParamField>
37
+
38
+ <ParamField body="label" type="string | string[]" optional>
39
+ Delete workflows with this label. Pass an array to match runs that
40
+ have any of the given labels (OR semantics).
41
+ </ParamField>
42
+
43
+ <ParamField body="fromDate" type="Date | number" optional>
44
+ Delete workflows created after this date. Accepts `Date` objects or Unix timestamps (ms).
45
+ </ParamField>
46
+
47
+ <ParamField body="toDate" type="Date | number" optional>
48
+ Delete workflows created before this date. Accepts `Date` objects or Unix timestamps (ms).
49
+ </ParamField>
50
+
51
+ <ParamField body="callerIp" type="string" optional>
52
+ Filter by the IP address that triggered the workflow.
53
+ </ParamField>
54
+
55
+ <ParamField body="flowControlKey" type="string" optional>
56
+ Filter by flow control key.
57
+ </ParamField>
58
+
59
+ <ParamField body="workflowCreatedAt" type="number" optional>
60
+ Filter by workflow creation time (Unix timestamp in ms).
61
+ </ParamField>
62
+
63
+ <ParamField body="failureFunctionState" type="string" optional>
64
+ Filter by failure callback state.
65
+ </ParamField>
66
+ </Expandable>
67
+ </ParamField>
68
+
69
+ <ParamField body="count" type="number" optional>
70
+ Maximum number of messages to process per call. Defaults to `100`.
71
+ </ParamField>
72
+
73
+ <ParamField body="cursor" type="string" optional>
74
+ A pagination cursor from a previous request.
75
+ </ParamField>
76
+
77
+ ### Delete all
78
+
79
+ <ParamField body="all" type="boolean">
80
+ Set to `true` to delete all DLQ entries.
81
+ </ParamField>
82
+
83
+ ## Response
84
+
85
+ <ResponseField name="deleted" type="number">
86
+ The number of DLQ entries that were deleted.
87
+ </ResponseField>
88
+
89
+ <ResponseField name="cursor" type="string">
90
+ A pagination cursor. If not returned, all matching entries have been processed.
91
+ </ResponseField>
92
+
93
+ ## Usage
94
+
95
+ <CodeGroup>
96
+ ```ts Single
97
+ await client.dlq.delete("dlq-123");
98
+ ```
99
+ ```ts Multiple
100
+ await client.dlq.delete(["dlq-123", "dlq-456"]);
101
+ ```
102
+ ```ts By filters
103
+ // delete by label
104
+ let cursor: string | undefined;
105
+ do {
106
+ const result = await client.dlq.delete({
107
+ filter: { label: "my-label" },
108
+ cursor,
109
+ });
110
+ cursor = result.cursor;
111
+ } while (cursor);
112
+ ```
113
+ ```ts All
114
+ let cursor: string | undefined;
115
+ do {
116
+ const result = await client.dlq.delete({ all: true, cursor });
117
+ cursor = result.cursor;
118
+ } while (cursor);
119
+ ```
120
+ </CodeGroup>
@@ -0,0 +1,96 @@
1
+ ---
2
+ title: "client.dlq.list"
3
+ ---
4
+
5
+ The `dlq.list` method retrieves messages that were sent to the **Dead Letter Queue (DLQ)**.
6
+
7
+ DLQ messages represent failed workflow or QStash deliveries that could not be retried successfully.
8
+
9
+ ## Arguments
10
+
11
+ <ParamField body="cursor" type="string" optional>
12
+ A pagination cursor from a previous request.
13
+ Use this to fetch the next batch of results.
14
+ </ParamField>
15
+
16
+ <ParamField body="count" type="number" optional>
17
+ Maximum number of DLQ messages to return.
18
+ Defaults to a system-defined limit if not provided.
19
+ </ParamField>
20
+
21
+ <ParamField body="filter" type="object" optional>
22
+ Filter options for narrowing down DLQ messages.
23
+
24
+ <Expandable defaultOpen>
25
+ <ParamField body="workflowUrl" type="string" optional>
26
+ Filter by exact workflow URL.
27
+ </ParamField>
28
+
29
+ <ParamField body="workflowRunId" type="string" optional>
30
+ Filter by workflow run ID.
31
+ </ParamField>
32
+
33
+ <ParamField body="label" type="string | string[]" optional>
34
+ Filter by workflow label. Pass an array to match runs that have any
35
+ of the given labels (OR semantics).
36
+ </ParamField>
37
+
38
+ <ParamField body="fromDate" type="Date | number" optional>
39
+ Earliest date to include. Accepts `Date` objects or Unix timestamps (ms).
40
+ </ParamField>
41
+
42
+ <ParamField body="toDate" type="Date | number" optional>
43
+ Latest date to include. Accepts `Date` objects or Unix timestamps (ms).
44
+ </ParamField>
45
+
46
+ <ParamField body="callerIp" type="string" optional>
47
+ Filter by the IP address that triggered the workflow.
48
+ </ParamField>
49
+
50
+ <ParamField body="flowControlKey" type="string" optional>
51
+ Filter by flow control key.
52
+ </ParamField>
53
+
54
+ <ParamField body="workflowCreatedAt" type="number" optional>
55
+ Filter by workflow creation time (Unix timestamp in ms).
56
+ </ParamField>
57
+
58
+ <ParamField body="failureFunctionState" type="string" optional>
59
+ Filter by failure callback state.
60
+ </ParamField>
61
+ </Expandable>
62
+ </ParamField>
63
+
64
+ ## Response
65
+
66
+ <ResponseField name="messages" type="DLQMessage[]">
67
+ An array of DLQ messages that match the provided filters.
68
+ </ResponseField>
69
+
70
+ <ResponseField name="cursor" type="string">
71
+ A cursor to paginate through additional results.
72
+ If not returned, you have reached the end of the DLQ.
73
+ </ResponseField>
74
+
75
+ ## Usage
76
+
77
+ ```ts
78
+ import { Client } from "@upstash/workflow";
79
+
80
+ const client = new Client({ token: "<QSTASH_TOKEN>" });
81
+
82
+ // List all DLQ messages
83
+ const { messages, cursor } = await client.dlq.list();
84
+
85
+ // List with pagination and filtering
86
+ const result = await client.dlq.list({
87
+ cursor,
88
+ count: 10,
89
+ filter: {
90
+ fromDate: Date.now() - 86400000, // last 24 hours
91
+ toDate: Date.now(),
92
+ workflowUrl: "https://your-endpoint.com",
93
+ label: "my-workflow",
94
+ }
95
+ });
96
+ ```
@@ -0,0 +1,164 @@
1
+ ---
2
+ title: "client.dlq.restart"
3
+ ---
4
+
5
+ The `dlq.restart` method restarts one or more workflow runs from **Dead Letter Queue (DLQ)**.
6
+ This allows you to reprocess workflow runs that previously failed after exhausting retries.
7
+
8
+ ## Arguments
9
+
10
+ The first argument specifies which DLQ entries to restart. The optional second argument provides flow control and retry settings.
11
+
12
+ ### By DLQ ID
13
+
14
+ Pass a single DLQ ID or an array of IDs directly:
15
+
16
+ ```ts
17
+ await client.dlq.restart("dlq-12345");
18
+ await client.dlq.restart(["dlq-12345", "dlq-67890"]);
19
+ ```
20
+
21
+ ### By filters
22
+
23
+ Pass an object with a `filter` field:
24
+
25
+ <ParamField body="filter" type="object">
26
+ <Expandable defaultOpen>
27
+ <ParamField body="workflowUrl" type="string" optional>
28
+ Filter by exact workflow URL.
29
+ </ParamField>
30
+
31
+ <ParamField body="workflowRunId" type="string" optional>
32
+ Filter by workflow run ID.
33
+ </ParamField>
34
+
35
+ <ParamField body="label" type="string | string[]" optional>
36
+ Restart workflows with this label. Pass an array to match runs that
37
+ have any of the given labels (OR semantics).
38
+ </ParamField>
39
+
40
+ <ParamField body="fromDate" type="Date | number" optional>
41
+ Restart workflows created after this date.
42
+ </ParamField>
43
+
44
+ <ParamField body="toDate" type="Date | number" optional>
45
+ Restart workflows created before this date.
46
+ </ParamField>
47
+
48
+ <ParamField body="callerIp" type="string" optional>
49
+ Filter by the IP address that triggered the workflow.
50
+ </ParamField>
51
+
52
+ <ParamField body="flowControlKey" type="string" optional>
53
+ Filter by flow control key.
54
+ </ParamField>
55
+
56
+ <ParamField body="workflowCreatedAt" type="number" optional>
57
+ Filter by workflow creation time (Unix timestamp in ms).
58
+ </ParamField>
59
+
60
+ <ParamField body="failureFunctionState" type="string" optional>
61
+ Filter by failure callback state.
62
+ </ParamField>
63
+ </Expandable>
64
+ </ParamField>
65
+
66
+ <ParamField body="count" type="number" optional>
67
+ Maximum number of messages to process per call. Defaults to `100`.
68
+ </ParamField>
69
+
70
+ <ParamField body="cursor" type="string" optional>
71
+ A pagination cursor from a previous request.
72
+ </ParamField>
73
+
74
+ ### Restart all
75
+
76
+ <ParamField body="all" type="boolean">
77
+ Set to `true` to restart all DLQ entries.
78
+ </ParamField>
79
+
80
+ ### Options (second argument)
81
+
82
+ <ParamField body="flowControl" type="object" optional>
83
+ An optional flow control configuration to limit concurrency and execution rate of restarted workflow runs.
84
+
85
+ See [Flow Control](/workflow/features/flow-control) for details.
86
+
87
+ <Expandable title="properties">
88
+ <ParamField body="key" type="string">
89
+ A logical grouping key that identifies which requests share the same flow control limits.
90
+ </ParamField>
91
+
92
+ <ParamField body="rate" type="number">
93
+ The maximum number of allowed requests per second.
94
+ </ParamField>
95
+
96
+ <ParamField body="parallelism" type="number">
97
+ The maximum number of concurrent requests allowed.
98
+ </ParamField>
99
+
100
+ <ParamField body="period" type="string|number">
101
+ The time window used to enforce the defined rate limit. Default is `1s`.
102
+ </ParamField>
103
+ </Expandable>
104
+
105
+ </ParamField>
106
+
107
+ <ParamField body="retries" type="number" optional>
108
+ Number of retry attempts to apply to the restarted workflow invocation.
109
+ Defaults to `3` if not provided.
110
+ </ParamField>
111
+
112
+ ## Response
113
+
114
+ <ResponseField name="cursor" type="string">
115
+ A pagination cursor. If not returned, all matching entries have been processed.
116
+ </ResponseField>
117
+
118
+ <ResponseField name="workflowRuns" type="object[]">
119
+ <Expandable defaultOpen>
120
+ <ResponseField name="workflowRunId" type="string">
121
+ The ID of the new workflow run created from the restarted DLQ message.
122
+ </ResponseField>
123
+
124
+ <ResponseField name="workflowCreatedAt" type="number">
125
+ The Unix timestamp (in milliseconds) when the new workflow run was created.
126
+ </ResponseField>
127
+ </Expandable>
128
+ </ResponseField>
129
+
130
+ ## Usage
131
+
132
+ <CodeGroup>
133
+ ```ts Single
134
+ const { messages } = await client.dlq.list();
135
+
136
+ const response = await client.dlq.restart(messages[0].dlqId, {
137
+ flowControl: {
138
+ key: "my-flow-control-key",
139
+ parallelism: 10,
140
+ },
141
+ retries: 3,
142
+ });
143
+ ```
144
+ ```ts Multiple
145
+ const response = await client.dlq.restart(["dlq-12345", "dlq-67890"]);
146
+ ```
147
+ ```ts By filters
148
+ let cursor: string | undefined;
149
+ do {
150
+ const result = await client.dlq.restart({
151
+ filter: { label: "my-label" },
152
+ cursor,
153
+ });
154
+ cursor = result.cursor;
155
+ } while (cursor);
156
+ ```
157
+ ```ts All
158
+ let cursor: string | undefined;
159
+ do {
160
+ const result = await client.dlq.restart({ all: true, cursor });
161
+ cursor = result.cursor;
162
+ } while (cursor);
163
+ ```
164
+ </CodeGroup>