@upstash/workflow 1.4.0 → 1.5.1-canary.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.
- package/README.md +9 -0
- package/astro.d.mts +19 -2
- package/astro.d.ts +19 -2
- package/astro.js +670 -159
- package/astro.mjs +1 -1
- package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
- package/cloudflare.d.mts +17 -2
- package/cloudflare.d.ts +17 -2
- package/cloudflare.js +670 -159
- package/cloudflare.mjs +1 -1
- package/docs/agents/examples.mdx +8 -0
- package/docs/agents/features.mdx +375 -0
- package/docs/agents/getting-started.mdx +139 -0
- package/docs/agents/overview.mdx +40 -0
- package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
- package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
- package/docs/agents/patterns/parallelization.mdx +77 -0
- package/docs/agents/patterns/prompt-chaining.mdx +84 -0
- package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
- package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
- package/docs/basics/best-practices/deterministic-code.mdx +132 -0
- package/docs/basics/best-practices/idempotency.mdx +38 -0
- package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
- package/docs/basics/best-practices/overview.mdx +35 -0
- package/docs/basics/best-practices/promise-any.mdx +9 -0
- package/docs/basics/best-practices/return-step-results.mdx +80 -0
- package/docs/basics/best-practices/workflow-limits.mdx +62 -0
- package/docs/basics/client/cancel.mdx +137 -0
- package/docs/basics/client/dlq/callback.mdx +21 -0
- package/docs/basics/client/dlq/delete.mdx +120 -0
- package/docs/basics/client/dlq/list.mdx +96 -0
- package/docs/basics/client/dlq/restart.mdx +164 -0
- package/docs/basics/client/dlq/resume.mdx +167 -0
- package/docs/basics/client/logs.mdx +139 -0
- package/docs/basics/client/notify.mdx +79 -0
- package/docs/basics/client/trigger.mdx +139 -0
- package/docs/basics/client/waiters.mdx +31 -0
- package/docs/basics/client.mdx +40 -0
- package/docs/basics/how.mdx +65 -0
- package/docs/basics/serve/advanced.mdx +435 -0
- package/docs/basics/serve.mdx +142 -0
- package/docs/changelog.mdx +174 -0
- package/docs/examples/allInOne.mdx +377 -0
- package/docs/examples/authWebhook.mdx +575 -0
- package/docs/examples/customRetry.mdx +309 -0
- package/docs/examples/customerOnboarding.mdx +230 -0
- package/docs/examples/dynamicWorkflow.mdx +203 -0
- package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
- package/docs/examples/imageProcessing.mdx +339 -0
- package/docs/examples/paymentRetry.mdx +438 -0
- package/docs/examples/waitForEvent.mdx +201 -0
- package/docs/features/dlq/callback.mdx +42 -0
- package/docs/features/dlq/delete.mdx +29 -0
- package/docs/features/dlq/restart.mdx +33 -0
- package/docs/features/dlq/resume.mdx +37 -0
- package/docs/features/dlq.mdx +39 -0
- package/docs/features/failure-callback.mdx +102 -0
- package/docs/features/failureFunction/advanced.mdx +36 -0
- package/docs/features/failureFunction/reliability.mdx +33 -0
- package/docs/features/flow-control/monitor.mdx +22 -0
- package/docs/features/flow-control/parallelism.mdx +45 -0
- package/docs/features/flow-control/rate-period.mdx +46 -0
- package/docs/features/flow-control.mdx +164 -0
- package/docs/features/invoke/serveMany.mdx +109 -0
- package/docs/features/invoke.mdx +39 -0
- package/docs/features/notify.mdx +127 -0
- package/docs/features/parallel-steps.mdx +41 -0
- package/docs/features/retries/prevent-retries.mdx +140 -0
- package/docs/features/retries.mdx +93 -0
- package/docs/features/wait-for-event.mdx +104 -0
- package/docs/features/wait.mdx +44 -0
- package/docs/features/webhooks.mdx +116 -0
- package/docs/getstarted.mdx +200 -0
- package/docs/howto/cancel.mdx +50 -0
- package/docs/howto/changes.mdx +33 -0
- package/docs/howto/configure.mdx +42 -0
- package/docs/howto/failures.mdx +185 -0
- package/docs/howto/get-token.mdx +18 -0
- package/docs/howto/local-development/development-server.mdx +130 -0
- package/docs/howto/local-development/local-tunnel.mdx +73 -0
- package/docs/howto/middlewares.mdx +263 -0
- package/docs/howto/migrations.mdx +335 -0
- package/docs/howto/multi-region.mdx +107 -0
- package/docs/howto/parallel-runs.mdx +52 -0
- package/docs/howto/readonly-token.mdx +19 -0
- package/docs/howto/realtime/basic.mdx +315 -0
- package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
- package/docs/howto/redact-fields.mdx +61 -0
- package/docs/howto/retry-now.mdx +41 -0
- package/docs/howto/schedule.mdx +114 -0
- package/docs/howto/security.mdx +143 -0
- package/docs/howto/singleton.mdx +137 -0
- package/docs/howto/start.mdx +69 -0
- package/docs/howto/use-webhooks.mdx +256 -0
- package/docs/integrations/aisdk.mdx +316 -0
- package/docs/integrations/anthropic.mdx +51 -0
- package/docs/integrations/datadog.mdx +69 -0
- package/docs/integrations/openai.mdx +87 -0
- package/docs/integrations/prometheus.mdx +65 -0
- package/docs/integrations/resend.mdx +82 -0
- package/docs/llms-txt.mdx +4 -0
- package/docs/openapi.yaml +2946 -0
- package/docs/pricing.mdx +22 -0
- package/docs/quickstarts/astro.mdx +185 -0
- package/docs/quickstarts/cloudflare-workers.mdx +190 -0
- package/docs/quickstarts/express.mdx +190 -0
- package/docs/quickstarts/fastapi.mdx +282 -0
- package/docs/quickstarts/flask.mdx +282 -0
- package/docs/quickstarts/hono.mdx +221 -0
- package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
- package/docs/quickstarts/nextjs-flask.mdx +147 -0
- package/docs/quickstarts/nuxt.mdx +169 -0
- package/docs/quickstarts/platforms.mdx +78 -0
- package/docs/quickstarts/solidjs.mdx +161 -0
- package/docs/quickstarts/svelte.mdx +170 -0
- package/docs/quickstarts/tanstack-start.mdx +205 -0
- package/docs/quickstarts/vercel-nextjs.mdx +233 -0
- package/docs/roadmap.mdx +8 -0
- package/docs/sdk/workflow-js.mdx +4 -0
- package/docs/sdk/workflow-py.mdx +4 -0
- package/docs/steps/api.mdx +64 -0
- package/docs/steps/call.mdx +183 -0
- package/docs/steps/cancel.mdx +25 -0
- package/docs/steps/createWebhook.mdx +40 -0
- package/docs/steps/invoke.mdx +100 -0
- package/docs/steps/notify.mdx +105 -0
- package/docs/steps/run.mdx +150 -0
- package/docs/steps/sleep.mdx +97 -0
- package/docs/steps/sleepUntil.mdx +88 -0
- package/docs/steps/waitForEvent.mdx +60 -0
- package/docs/steps/waitForWebhook.mdx +78 -0
- package/docs/steps.mdx +108 -0
- package/docs/troubleshooting/general.mdx +331 -0
- package/docs/troubleshooting/vercel.mdx +82 -0
- package/express.d.mts +19 -2
- package/express.d.ts +19 -2
- package/express.js +670 -159
- package/express.mjs +1 -1
- package/h3.d.mts +19 -2
- package/h3.d.ts +19 -2
- package/h3.js +670 -159
- package/h3.mjs +1 -1
- package/hono.d.mts +17 -2
- package/hono.d.ts +17 -2
- package/hono.js +670 -159
- package/hono.mjs +1 -1
- package/index.d.mts +50 -21
- package/index.d.ts +50 -21
- package/index.js +686 -171
- package/index.mjs +17 -13
- package/nextjs.d.mts +40 -2
- package/nextjs.d.ts +40 -2
- package/nextjs.js +670 -159
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +16 -2
- package/react-router.d.ts +16 -2
- package/react-router.js +670 -159
- package/react-router.mjs +1 -1
- package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
- package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
- package/solidjs.d.mts +10 -1
- package/solidjs.d.ts +10 -1
- package/solidjs.js +670 -159
- package/solidjs.mjs +1 -1
- package/src/platforms/astro.ts +84 -0
- package/src/platforms/cloudflare.ts +127 -0
- package/src/platforms/express.ts +147 -0
- package/src/platforms/h3.ts +105 -0
- package/src/platforms/hono.ts +103 -0
- package/src/platforms/nextjs.ts +193 -0
- package/src/platforms/react-router.ts +92 -0
- package/src/platforms/solidjs.ts +59 -0
- package/src/platforms/svelte.ts +99 -0
- package/src/platforms/tanstack.ts +96 -0
- package/src/src/client/dlq.ts +387 -0
- package/src/src/client/filter-types.ts +166 -0
- package/src/src/client/index.ts +350 -0
- package/src/src/client/types.ts +501 -0
- package/src/src/client/utils.ts +307 -0
- package/src/src/constants.ts +82 -0
- package/src/src/context/api/anthropic.ts +58 -0
- package/src/src/context/api/base.ts +52 -0
- package/src/src/context/api/index.ts +24 -0
- package/src/src/context/api/openai.ts +125 -0
- package/src/src/context/api/resend.ts +57 -0
- package/src/src/context/auto-executor.ts +707 -0
- package/src/src/context/context.ts +681 -0
- package/src/src/context/index.ts +1 -0
- package/src/src/context/provider.ts +37 -0
- package/src/src/context/steps.ts +965 -0
- package/src/src/error.ts +203 -0
- package/src/src/index.ts +13 -0
- package/src/src/middleware/default-callbacks.ts +20 -0
- package/src/src/middleware/index.ts +2 -0
- package/src/src/middleware/logging.ts +39 -0
- package/src/src/middleware/manager.ts +148 -0
- package/src/src/middleware/middleware.ts +46 -0
- package/src/src/middleware/types.ts +72 -0
- package/src/src/qstash/headers.ts +397 -0
- package/src/src/qstash/step-config.ts +268 -0
- package/src/src/qstash/submit-steps.ts +284 -0
- package/src/src/serve/authorization.ts +118 -0
- package/src/src/serve/index.ts +475 -0
- package/src/src/serve/multi-region/handlers.ts +225 -0
- package/src/src/serve/multi-region/utils.ts +88 -0
- package/src/src/serve/options.ts +241 -0
- package/src/src/serve/serve-many.ts +117 -0
- package/src/src/serve/utils.ts +11 -0
- package/src/src/types.ts +590 -0
- package/src/src/utils.ts +141 -0
- package/src/src/workflow-parser.ts +472 -0
- package/src/src/workflow-requests.ts +575 -0
- package/svelte.d.mts +17 -2
- package/svelte.d.ts +17 -2
- package/svelte.js +670 -159
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +15 -2
- package/tanstack.d.ts +15 -2
- package/tanstack.js +670 -159
- package/tanstack.mjs +1 -1
- package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
- package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upstash Workflow Changelog
|
|
3
|
+
sidebarTitle: Changelog
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<Note>
|
|
7
|
+
We have moved the roadmap and the changelog to [Github Discussions](https://github.com/orgs/upstash/discussions) starting from October 2025.Now you can follow `In Progress` features. You can see that your `Feature Requests` are recorded. You can vote for them and comment your specific use-cases to shape the feature to your needs.
|
|
8
|
+
</Note>
|
|
9
|
+
|
|
10
|
+
<Update label="June 2026">
|
|
11
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
12
|
+
- Multiple labels per workflow run are now supported. `label` on [`client.trigger`](/workflow/basics/client/trigger) and `context.invoke` accepts `string | string[]`, and log/DLQ/cancel filters accept an array to match runs that have any of the given labels (OR semantics). Workflow run logs now expose a `labels: string[]` field, and `context.labels: string[]` replaces the now-deprecated `context.label`.
|
|
13
|
+
</Update>
|
|
14
|
+
|
|
15
|
+
<Update label="March 2026">
|
|
16
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
17
|
+
- Added optional `workflowRunId` parameter to `notify` method, enabling **lookback functionality**. When provided, notifications are stored and delivered even if sent before a workflow reaches `waitForEvent`, preventing race conditions. See [notify documentation](/workflow/basics/client/notify) and [wait-for-event guide](/workflow/features/wait-for-event#race-condition-between-wait-and-notify) for details.
|
|
18
|
+
</Update>
|
|
19
|
+
|
|
20
|
+
<Update label="September 2025">
|
|
21
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
22
|
+
- `Label` feature is added. This will enable our users to label their workflow runs so that
|
|
23
|
+
- Logs can be filtered with user given label.
|
|
24
|
+
- DLQ can be filtered with user given label.
|
|
25
|
+
- `notBefore` parameter is added to `trigger` function that will allow starting a workflow run at a later date
|
|
26
|
+
given by the `notBefore` parameter.
|
|
27
|
+
- **Console:**
|
|
28
|
+
- A major Workflow redesign is landed to improve debugging and monitoring experience workflow runs logs.
|
|
29
|
+
- `Flat view` is removed. All the data is moved to single view. This is also to avoid confusing our
|
|
30
|
+
users and made over all experience simpler.
|
|
31
|
+
</Update>
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<Update label="August 2025">
|
|
35
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
36
|
+
- Added `retryDelay` option to dynamically program the retry duration. It can be configured on
|
|
37
|
+
[trigger](/workflow/basics/client/trigger#param-retry-delay), [context.call](/workflow/steps/call)
|
|
38
|
+
or `serve` (later moved to `client.trigger`, see the [migration guide](/workflow/howto/migrations#configuration-moved-from-serve-to-trigger))
|
|
39
|
+
- Added ability to detect if a given url is a workflow or not. Starting with `0.2.17` trigger made via the sdk can fail (instead of hanging),
|
|
40
|
+
if there is no workflow serve on the given url.
|
|
41
|
+
- **Console:**
|
|
42
|
+
- Local mode is added to enable our users to use the console with their local development envrionment and the locally deployed workflows.
|
|
43
|
+
See [docs](/workflow/howto/local-development#development-server-recommended) for details.
|
|
44
|
+
</Update>
|
|
45
|
+
|
|
46
|
+
<Update label="July 2025">
|
|
47
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
48
|
+
- Restart/Resume for DLQ is added to allow more options to handle failed runs. See [here](/workflow/howto/failures#manually-handling-failed-workflow-runs)
|
|
49
|
+
- Added `WorkflowNonRetryableError` to fail a workflow without causing any retries. See [here](/workflow/features/retries/prevent-retries)
|
|
50
|
+
- For additional bug fixes, see the full changelog [here](https://github.com/upstash/workflow-js/compare/v0.2.14...v0.2.16).
|
|
51
|
+
</Update>
|
|
52
|
+
|
|
53
|
+
<Update label="June 2025">
|
|
54
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
55
|
+
- Added `useFailureFunction` and `failureFunction` to `client.trigger`. See [here](https://github.com/upstash/workflow-js/pull/107).
|
|
56
|
+
- Added batch triggering support to `client.trigger`. See [here](https://github.com/upstash/workflow-js/pull/110).
|
|
57
|
+
- For additional bug fixes, see the release notes [here](https://github.com/upstash/workflow-js/releases/tag/v0.2.14).
|
|
58
|
+
- **Python SDK (`workflow-py`):**
|
|
59
|
+
- Failure function is implemented. This feature enables to act on a failure of a workflow on the code. See docs [here](/workflow/howto/failures#using-a-failurefunction-recommended)
|
|
60
|
+
- For other bug fixes, see the full changelog [here](https://github.com/upstash/workflow-py/compare/v0.1.0...v0.1.1).
|
|
61
|
+
- **Console:**
|
|
62
|
+
- A major redesign is coming next month to improve Workflow usability.
|
|
63
|
+
- **Workflow Server:**
|
|
64
|
+
- An issue causing Workflows not usable with `CloudFront` is fixed.
|
|
65
|
+
</Update>
|
|
66
|
+
|
|
67
|
+
<Update label="May 2025">
|
|
68
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
69
|
+
- Added a `workflow` parameter to `context.call`, enabling type-safe workflow calls. See [here](https://github.com/upstash/workflow-js/pull/75).
|
|
70
|
+
- Enabled passing `context.call` settings when defining an Agent. See [here](https://github.com/upstash/workflow-js/pull/90).
|
|
71
|
+
- Added `delay` support to `client.trigger`. See [here](https://github.com/upstash/workflow-js/pull/100).
|
|
72
|
+
- Introduced `period` and improved `rate` support in flow control. See [here](https://github.com/upstash/workflow-js/pull/101).
|
|
73
|
+
Previously, `period` was fixed at 1 second. For example, `rate: 3 period: 1d` throttles publishes to 3 per day.
|
|
74
|
+
- For additional bug fixes, see the release notes [here](https://github.com/upstash/workflow-js/releases/tag/v0.2.13).
|
|
75
|
+
- **Workflow Server:**
|
|
76
|
+
- Added support for custom `period` in flow control, allowing users to set a period of up to 1 week.
|
|
77
|
+
Previously, `period` was fixed at 1 second. For example, `rate: 3 period: 1d` throttles publishes to 3 per day.
|
|
78
|
+
- Implemented **Workflow Resume** and **Restart** features (SDK and Console support in progress):
|
|
79
|
+
- **Resume** allows users to retry a workflow run from the point it stopped.
|
|
80
|
+
- **Restart** allows users to retry a workflow run from the beginning.
|
|
81
|
+
- **Console:**
|
|
82
|
+
- A major redesign is coming to improve Workflow usability.
|
|
83
|
+
</Update>
|
|
84
|
+
|
|
85
|
+
<Update label="April 2025">
|
|
86
|
+
- **Python SDK (`workflow-py`):**
|
|
87
|
+
- Minor bug fixes.
|
|
88
|
+
See the full changelog [here](https://github.com/upstash/workflow-py/compare/v0.1.0...v0.1.1).
|
|
89
|
+
- **Workflow Server:**
|
|
90
|
+
- Prevented intermediate Workflow calls from failing due to request/message quota limits.
|
|
91
|
+
- Fixed handling of `RUN_STARTED` so that it correctly returns unfinished Workflow Runs as documented.
|
|
92
|
+
Previously, some Workflow Runs could be skipped if internal state was logged after `RUN_STARTED`.
|
|
93
|
+
- Applied several performance optimizations.
|
|
94
|
+
</Update>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
<Update label="March 2025">
|
|
98
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
99
|
+
- Added `onError` support to `serve` by the community. See [here](https://github.com/upstash/workflow-js/pull/79).
|
|
100
|
+
- Enabled support for all fetch-compatible models in Agents. See [more details here](https://github.com/upstash/workflow-js/pull/77).
|
|
101
|
+
- For additional bug fixes, see the full changelog [here](https://github.com/upstash/workflow-js/compare/v0.2.11...v0.2.12).
|
|
102
|
+
</Update>
|
|
103
|
+
|
|
104
|
+
<Update label="February 2025">
|
|
105
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
106
|
+
- Fixed a Unicode issue in `context.call` where binary responses from endpoints could break. See [here](https://github.com/upstash/workflow-js/pull/71).
|
|
107
|
+
- Introduced `WorkflowTool`, allowing Workflow Agents to define multi-step workflows as a tool. See [here](/workflow/agents/features#tools).
|
|
108
|
+
- Added `context.invoke` to call one workflow from another with full type-safety. See the guide [here](/workflow/features/invoke).
|
|
109
|
+
- Introduced flow control parameters to limit the rate or concurrency of workflow runs. Learn more [here](/workflow/features/flow-control).
|
|
110
|
+
- For additional bug fixes, see the full changelog [here](https://github.com/upstash/workflow-js/compare/v0.2.3...v0.2.6).
|
|
111
|
+
- **Workflow Server:**
|
|
112
|
+
- Added RateLimit and Parallelism controls to manage the frequency and concurrency of workflow runs. Learn more [here](/workflow/features/flow-control).
|
|
113
|
+
</Update>
|
|
114
|
+
|
|
115
|
+
<Update label="January 2025">
|
|
116
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
117
|
+
- Added the Agents API to workflows. You can now create AI agents to run workflows on your own infrastructure with all the benefits of workflows: reduced environment costs, fault tolerance, and scalability. Learn more about agents [here](/workflow/agents/overview).
|
|
118
|
+
- For other bug fixes, see the full changelog [here](https://github.com/upstash/workflow-js/compare/v0.2.3...v0.2.6).
|
|
119
|
+
- **Python SDK (workflow-py):**
|
|
120
|
+
- Released [`workflow-py`](https://github.com/upstash/workflow-py).
|
|
121
|
+
- **Local Development Server:**
|
|
122
|
+
- The local development server is now available for public use. This server allows you to test your workflows locally. Learn more about the local development server [here](/workflow/howto/local-development#development-server-recommended).
|
|
123
|
+
- **Console:**
|
|
124
|
+
- Separated Workflow and QStash consoles for a better user experience.
|
|
125
|
+
- Separated their DLQ messages as well.
|
|
126
|
+
- **Workflow Server:**
|
|
127
|
+
- The core team focused on RateLimit and Parallelism features. These features are ready on the server and will be announced next month after the documentation and SDKs are completed.
|
|
128
|
+
</Update>
|
|
129
|
+
|
|
130
|
+
<Update label="December 2024">
|
|
131
|
+
- **TypeScript SDK (`workflow-js`):**
|
|
132
|
+
- Introduced third-party integrations, starting with Anthropic, Resend, and OpenAI. These integrations are automatically offloaded to workflows, ensuring long-running calls do not consume user environment time. See the related documentation [here](/workflow/steps/api).
|
|
133
|
+
- Added a `timeout` parameter to `context.call`. Learn more in the [documentation](/workflow/steps/call).
|
|
134
|
+
- Improved support for workflows in Express and SvelteKit by adding the `useJSONContent` option.
|
|
135
|
+
- Resolved loop detection issues on Cloudflare and Render.
|
|
136
|
+
- Full changelog, including all fixes, is available [here](https://github.com/upstash/workflow-js/compare/v0.2.0...v0.2.3).
|
|
137
|
+
|
|
138
|
+
- **Workflow Server:**
|
|
139
|
+
- Added the `WorkflowCreatedAt` filter for Dead Letter Queue (DLQ) and Events.
|
|
140
|
+
- Prepared the local development server for public release (coming soon).
|
|
141
|
+
- Enhanced `context.SleepUntil` to support float values.
|
|
142
|
+
- Increased the event retention period from 10,000 events to up to 14 days. Learn more on the [Pricing page](https://upstash.com/pricing/workflow).
|
|
143
|
+
</Update>
|
|
144
|
+
|
|
145
|
+
<Update label="November 2024">
|
|
146
|
+
- **Python SDK (workflow-py):**
|
|
147
|
+
- Began development of the Python SDK.
|
|
148
|
+
- **TypeScript SDK (workflow-js):**
|
|
149
|
+
- Added support for string durations (e.g., `1d`, `30s`) in `context.sleep` and `context.waitForEvent`.
|
|
150
|
+
- Introduced integrations for [Astro](/workflow/quickstarts/astro) and [Express](/workflow/quickstarts/express).
|
|
151
|
+
- Added `client.trigger`, enabling workflows to start and return the workflow run ID. See the [documentation](/workflow/basics/client/trigger).
|
|
152
|
+
- Added a retry option for `context.call`. See the [documentation](/workflow/steps/call).
|
|
153
|
+
- Introduced a lazy fetch feature to support longer and larger workflows on resource-limited platforms.
|
|
154
|
+
- Added `context.cancel` to cancel the current workflow. See the [documentation](/workflow/steps/cancel).
|
|
155
|
+
- Full changelog, including fixes, is available [here](https://github.com/upstash/workflow-js/compare/v0.1.2...v0.2.0).
|
|
156
|
+
- **Workflow Server:**
|
|
157
|
+
- Added bulk cancel functionality for workflow runs. See the [REST API](/workflow/api-reference/runs/bulk-cancel-workflow-runs).
|
|
158
|
+
- Introduced content-based deduplication for workflows and retry-until-success functionality. This will allow workflows to be used in areas with unstable network connection.
|
|
159
|
+
</Update>
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
<Update label="October 2024">
|
|
163
|
+
- Optimized the console by trimming event bodies, reducing resource usage and enabling efficient querying of events with large payloads.
|
|
164
|
+
- Began development on a new architecture to deliver faster event processing on the server.
|
|
165
|
+
- Added [Wait Notify](/workflow/features/wait-for-event) feature.
|
|
166
|
+
</Update>
|
|
167
|
+
|
|
168
|
+
<Update label="September 2024">
|
|
169
|
+
- Bug fixes and internal logging improvements.
|
|
170
|
+
</Update>
|
|
171
|
+
|
|
172
|
+
<Update label="August 2024">
|
|
173
|
+
- Released [Upstash Workflow](/workflow/getstarted).
|
|
174
|
+
</Update>
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "AI Generation"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This example demonstrates advanced AI data processing using Upstash Workflow. The following example workflow downloads a large dataset, processes it in chunks using OpenAI's GPT-4 model, aggregates the results and generates a report.
|
|
8
|
+
|
|
9
|
+
## Use Case
|
|
10
|
+
|
|
11
|
+
Our workflow will:
|
|
12
|
+
|
|
13
|
+
1. Receive a request to process a dataset
|
|
14
|
+
2. Download the dataset from a remote source
|
|
15
|
+
3. Process the data in chunks using OpenAI
|
|
16
|
+
4. Aggregate results
|
|
17
|
+
5. Generate and send a final report
|
|
18
|
+
|
|
19
|
+
## Code Example
|
|
20
|
+
|
|
21
|
+
<CodeGroup>
|
|
22
|
+
|
|
23
|
+
```typescript api/workflow/route.ts
|
|
24
|
+
import { serve } from "@upstash/workflow/nextjs"
|
|
25
|
+
import {
|
|
26
|
+
downloadData,
|
|
27
|
+
aggregateResults,
|
|
28
|
+
generateReport,
|
|
29
|
+
sendReport,
|
|
30
|
+
getDatasetUrl,
|
|
31
|
+
splitIntoChunks,
|
|
32
|
+
} from "./utils"
|
|
33
|
+
|
|
34
|
+
type OpenAiResponse = {
|
|
35
|
+
choices: {
|
|
36
|
+
message: {
|
|
37
|
+
role: string,
|
|
38
|
+
content: string
|
|
39
|
+
}
|
|
40
|
+
}[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const { POST } = serve<{ datasetId: string; userId: string }>(
|
|
44
|
+
async (context) => {
|
|
45
|
+
const request = context.requestPayload
|
|
46
|
+
|
|
47
|
+
// Step 1: Download the dataset
|
|
48
|
+
const datasetUrl = await context.run("get-dataset-url", async () => {
|
|
49
|
+
return await getDatasetUrl(request.datasetId)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// HTTP request with much longer timeout (2hrs)
|
|
53
|
+
const { body: dataset } = await context.call("download-dataset", {
|
|
54
|
+
url: datasetUrl,
|
|
55
|
+
method: "GET"
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// Step 2: Process data in chunks using OpenAI
|
|
60
|
+
const chunkSize = 1000
|
|
61
|
+
const chunks = splitIntoChunks(dataset, chunkSize)
|
|
62
|
+
const processedChunks: string[] = []
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
65
|
+
const { body: processedChunk } = await context.api.openai.call(
|
|
66
|
+
`process-chunk-${i}`,
|
|
67
|
+
{
|
|
68
|
+
token: process.env.OPENAI_API_KEY,
|
|
69
|
+
operation: "chat.completions.create",
|
|
70
|
+
body: {
|
|
71
|
+
model: "gpt-4",
|
|
72
|
+
messages: [
|
|
73
|
+
{
|
|
74
|
+
role: "system",
|
|
75
|
+
content:
|
|
76
|
+
"You are an AI assistant tasked with analyzing data chunks. Provide a brief summary and key insights for the given data.",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
role: "user",
|
|
80
|
+
content: `Analyze this data chunk: ${JSON.stringify(chunks[i])}`,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
max_completion_tokens: 150,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
processedChunks.push(processedChunk.choices[0].message.content!)
|
|
89
|
+
|
|
90
|
+
// Every 10 chunks, we'll aggregate intermediate results
|
|
91
|
+
if (i % 10 === 9 || i === chunks.length - 1) {
|
|
92
|
+
await context.run(`aggregate-results${i}`, async () => {
|
|
93
|
+
await aggregateResults(processedChunks)
|
|
94
|
+
processedChunks.length = 0
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Step 3: Generate and send data report
|
|
100
|
+
const report = await context.run("generate-report", async () => {
|
|
101
|
+
return await generateReport(request.datasetId)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
await context.run("send-report", async () => {
|
|
105
|
+
await sendReport(report, request.userId)
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```python main.py
|
|
112
|
+
from fastapi import FastAPI
|
|
113
|
+
import json
|
|
114
|
+
import os
|
|
115
|
+
from typing import Dict, List, Any, TypedDict
|
|
116
|
+
from upstash_workflow.fastapi import Serve
|
|
117
|
+
from upstash_workflow import AsyncWorkflowContext, CallResponse
|
|
118
|
+
from utils import (
|
|
119
|
+
aggregate_results,
|
|
120
|
+
generate_report,
|
|
121
|
+
send_report,
|
|
122
|
+
get_dataset_url,
|
|
123
|
+
split_into_chunks,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
app = FastAPI()
|
|
128
|
+
serve = Serve(app)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class RequestPayload(TypedDict):
|
|
132
|
+
dataset_id: str
|
|
133
|
+
user_id: str
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@serve.post("/ai-generation")
|
|
137
|
+
async def ai_generation(context: AsyncWorkflowContext[RequestPayload]) -> None:
|
|
138
|
+
request = context.request_payload
|
|
139
|
+
dataset_id = request["dataset_id"]
|
|
140
|
+
user_id = request["user_id"]
|
|
141
|
+
|
|
142
|
+
# Step 1: Download the dataset
|
|
143
|
+
async def _get_dataset_url() -> str:
|
|
144
|
+
return await get_dataset_url(dataset_id)
|
|
145
|
+
|
|
146
|
+
dataset_url = await context.run("get-dataset-url", _get_dataset_url)
|
|
147
|
+
|
|
148
|
+
# HTTP request with much longer timeout (2hrs)
|
|
149
|
+
response: CallResponse[Any] = await context.call(
|
|
150
|
+
"download-dataset", url=dataset_url, method="GET"
|
|
151
|
+
)
|
|
152
|
+
dataset = response.body
|
|
153
|
+
|
|
154
|
+
# Step 2: Process data in chunks using OpenAI
|
|
155
|
+
chunk_size = 1000
|
|
156
|
+
chunks = split_into_chunks(dataset, chunk_size)
|
|
157
|
+
processed_chunks: List[str] = []
|
|
158
|
+
|
|
159
|
+
for i, chunk in enumerate(chunks):
|
|
160
|
+
openai_response: CallResponse[Dict[str, str]] = await context.call(
|
|
161
|
+
f"process-chunk-{i}",
|
|
162
|
+
url="https://api.openai.com/v1/chat/completions",
|
|
163
|
+
method="POST",
|
|
164
|
+
headers={
|
|
165
|
+
"authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}",
|
|
166
|
+
},
|
|
167
|
+
body={
|
|
168
|
+
"model": "gpt-4",
|
|
169
|
+
"messages": [
|
|
170
|
+
{
|
|
171
|
+
"role": "system",
|
|
172
|
+
"content":
|
|
173
|
+
"You are an AI assistant tasked with analyzing data chunks. Provide a brief summary and key insights for the given data.",
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"role": "user",
|
|
177
|
+
"content": f"Analyze this data chunk: {json.dumps(chunk)}",
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
"max_tokens": 150,
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
processed_chunks.append(
|
|
185
|
+
openai_response.body["choices"][0]["message"]["content"]
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# Every 10 chunks, we'll aggregate intermediate results
|
|
189
|
+
if i % 10 == 9 or i == len(chunks) - 1:
|
|
190
|
+
|
|
191
|
+
async def _aggregate_results() -> None:
|
|
192
|
+
await aggregate_results(processed_chunks)
|
|
193
|
+
processed_chunks.clear()
|
|
194
|
+
|
|
195
|
+
await context.run(f"aggregate-results{i}", _aggregate_results)
|
|
196
|
+
|
|
197
|
+
# Step 3: Generate and send data report
|
|
198
|
+
async def _generate_report() -> Any:
|
|
199
|
+
return await generate_report(dataset_id)
|
|
200
|
+
|
|
201
|
+
report = await context.run("generate-report", _generate_report)
|
|
202
|
+
|
|
203
|
+
async def _send_report() -> None:
|
|
204
|
+
await send_report(report, user_id)
|
|
205
|
+
|
|
206
|
+
await context.run("send-report", _send_report)
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
</CodeGroup>
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
## Code Breakdown
|
|
214
|
+
|
|
215
|
+
### 1. Preparing our data
|
|
216
|
+
|
|
217
|
+
We start by retrieving the dataset URL and then downloading the dataset:
|
|
218
|
+
|
|
219
|
+
<CodeGroup>
|
|
220
|
+
|
|
221
|
+
```typescript api/workflow/route.ts
|
|
222
|
+
const datasetUrl = await context.run("get-dataset-url", async () => {
|
|
223
|
+
return await getDatasetUrl(request.datasetId)
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
const { body: dataset } = await context.call("download-dataset", {
|
|
227
|
+
url: datasetUrl,
|
|
228
|
+
method: "GET"
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```python main.py
|
|
233
|
+
async def _get_dataset_url() -> str:
|
|
234
|
+
return await get_dataset_url(dataset_id)
|
|
235
|
+
|
|
236
|
+
dataset_url = await context.run("get-dataset-url", _get_dataset_url)
|
|
237
|
+
|
|
238
|
+
response: CallResponse[Any] = await context.call(
|
|
239
|
+
"download-dataset", url=dataset_url, method="GET"
|
|
240
|
+
)
|
|
241
|
+
dataset = response.body
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
</CodeGroup>
|
|
246
|
+
|
|
247
|
+
Note that we use `context.call` for the download, a way to make HTTP requests that run for much longer than your serverless execution limit would normally allow.
|
|
248
|
+
|
|
249
|
+
### 2. Processing our data
|
|
250
|
+
|
|
251
|
+
We split the dataset into chunks and process each one using OpenAI's GPT-4 model:
|
|
252
|
+
|
|
253
|
+
<CodeGroup>
|
|
254
|
+
|
|
255
|
+
```typescript api/workflow/route.ts
|
|
256
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
257
|
+
const { body: processedChunk } = await context.api.openai.call<OpenAiResponse>(
|
|
258
|
+
`process-chunk-${i}`,
|
|
259
|
+
{
|
|
260
|
+
token: process.env.OPENAI_API_KEY!,
|
|
261
|
+
operation: "chat.completions.create",
|
|
262
|
+
body: {
|
|
263
|
+
model: "gpt-4",
|
|
264
|
+
messages: [
|
|
265
|
+
{
|
|
266
|
+
role: "system",
|
|
267
|
+
content:
|
|
268
|
+
"You are an AI assistant tasked with analyzing data chunks. Provide a brief summary and key insights for the given data.",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
role: "user",
|
|
272
|
+
content: `Analyze this data chunk: ${JSON.stringify(chunks[i])}`,
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
max_completion_tokens: 150,
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```python main.py
|
|
283
|
+
for i, chunk in enumerate(chunks):
|
|
284
|
+
openai_response: CallResponse[Dict[str, str]] = await context.call(
|
|
285
|
+
f"process-chunk-{i}",
|
|
286
|
+
url="https://api.openai.com/v1/chat/completions",
|
|
287
|
+
method="POST",
|
|
288
|
+
headers={
|
|
289
|
+
"authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}",
|
|
290
|
+
},
|
|
291
|
+
body={
|
|
292
|
+
"model": "gpt-4",
|
|
293
|
+
"messages": [
|
|
294
|
+
{
|
|
295
|
+
"role": "system",
|
|
296
|
+
"content":
|
|
297
|
+
"You are an AI assistant tasked with analyzing data chunks. Provide a brief summary and key insights for the given data.",
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"role": "user",
|
|
301
|
+
"content": f"Analyze this data chunk: {json.dumps(chunk)}",
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
"max_tokens": 150,
|
|
305
|
+
},
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
</CodeGroup>
|
|
311
|
+
|
|
312
|
+
### 3. Aggregating our data
|
|
313
|
+
|
|
314
|
+
After processing our data in smaller chunks to avoid any function timeouts, we aggregate results every 10 chunks:
|
|
315
|
+
|
|
316
|
+
<CodeGroup>
|
|
317
|
+
|
|
318
|
+
```typescript api/workflow/route.ts
|
|
319
|
+
if (i % 10 === 9 || i === chunks.length - 1) {
|
|
320
|
+
await context.run(`aggregate-results${i}`, async () => {
|
|
321
|
+
await aggregateResults(processedChunks)
|
|
322
|
+
processedChunks.length = 0
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
```python main.py
|
|
329
|
+
if i % 10 == 9 or i == len(chunks) - 1:
|
|
330
|
+
|
|
331
|
+
async def _aggregate_results() -> None:
|
|
332
|
+
await aggregate_results(processed_chunks)
|
|
333
|
+
processed_chunks.clear()
|
|
334
|
+
|
|
335
|
+
await context.run(f"aggregate-results{i}", _aggregate_results)
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
</CodeGroup>
|
|
340
|
+
|
|
341
|
+
### 4. Sending a report
|
|
342
|
+
|
|
343
|
+
Finally, we generate a report based on the aggregated results and send it to the user:
|
|
344
|
+
|
|
345
|
+
<CodeGroup>
|
|
346
|
+
|
|
347
|
+
```typescript api/workflow/route.ts
|
|
348
|
+
const report = await context.run("generate-report", async () => {
|
|
349
|
+
return await generateReport(request.datasetId)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
await context.run("send-report", async () => {
|
|
353
|
+
await sendReport(report, request.userId)
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
```python main.py
|
|
359
|
+
async def _generate_report() -> Any:
|
|
360
|
+
return await generate_report(dataset_id)
|
|
361
|
+
|
|
362
|
+
report = await context.run("generate-report", _generate_report)
|
|
363
|
+
|
|
364
|
+
async def _send_report() -> None:
|
|
365
|
+
await send_report(report, user_id)
|
|
366
|
+
|
|
367
|
+
await context.run("send-report", _send_report)
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
</CodeGroup>
|
|
372
|
+
|
|
373
|
+
## Key Features
|
|
374
|
+
|
|
375
|
+
1. **Non-blocking HTTP Calls**: We use `context.call` for API requests so they don't consume the endpoint's execution time (great for optimizing serverless cost).
|
|
376
|
+
|
|
377
|
+
2. **Long-running tasks**: The dataset download can take up to 2 hours, though is realistically limited by function memory.
|