@upstash/workflow 1.5.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.
@@ -66,7 +66,7 @@ If you want to configure the calls made to the LLM APIs, you can use the `agentC
66
66
  ```ts
67
67
  const model = agents.openai('gpt-3.5-turbo', {
68
68
  callSettings: {
69
- timeout: 1000, // optional request timeout
69
+ timeout: "10s", // optional request timeout
70
70
  retries: 0, // optional retries
71
71
  flowControl: { // optional flow control
72
72
  key: "flow-control-key",
@@ -92,7 +92,7 @@ This flexibility allows you to tailor the tools to your specific needs while lev
92
92
  <CodeGroup>
93
93
 
94
94
  ```ts WorkflowTool (custom)
95
- import { WorkflowTool } from '@upstash/workflow'
95
+ import { WorkflowTool } from '@upstash/workflow-agents'
96
96
  import { z } from 'zod'
97
97
  import * as mathjs from 'mathjs'
98
98
 
@@ -116,7 +116,7 @@ const mathTool = tool({
116
116
  'A tool for evaluating mathematical expressions. ' +
117
117
  'Example expressions: ' +
118
118
  "'1.2 * (2 + 4.5)', '12.7 cm to inch', 'sin(45 deg) ^ 2'.",
119
- parameters: z.object({ expression: z.string() }),
119
+ inputSchema: z.object({ expression: z.string() }),
120
120
  execute: async ({ expression }) => mathjs.evaluate(expression),
121
121
  })
122
122
  ```
@@ -131,6 +131,7 @@ const tools = createAISDKTools(weather)
131
131
 
132
132
  ```ts LangChain (custom)
133
133
  import { DynamicStructuredTool } from "@langchain/core/tools";
134
+ import { z } from "zod";
134
135
 
135
136
  const numberGenerator = new DynamicStructuredTool({
136
137
  name: "random-number-generator",
@@ -160,14 +161,14 @@ For available toolkits, you can explore the [LangChain Toolkits](https://js.lang
160
161
  By default, the Workflow SDK will wrap the execute/invoke methods of the tools you pass with [`context.run`](/workflow/steps/run) to run them as a Workflow step. This means, you can't use steps like context.call, context.notify etc in execute/invoke right away. If you want to define steps in invoke/execute, you can use the `executeAsStep` option:
161
162
 
162
163
  ```ts {12}
163
- import { WorkflowTool } from '@upstash/workflow'
164
+ import { WorkflowTool } from '@upstash/workflow-agents'
164
165
  import { serve } from '@upstash/workflow/nextjs'
165
166
 
166
167
  export const { POST } = serve(async (context) => {
167
168
  const tool = new WorkflowTool({
168
169
  description: ...,
169
170
  schema: ...,
170
- invoke: ( ... ) => {
171
+ invoke: async ( ... ) => {
171
172
  // make HTTP call inside the tool with context.call:
172
173
  await context.call( ... )
173
174
  },
@@ -324,7 +325,7 @@ export const { POST } = serve(async (context) => {
324
325
  "'1.2 * (2 + 4.5)', '12.7 cm to inch', 'sin(45 deg) ^ 2'." +
325
326
  "only call this tool if you need to calculate a mathematical expression." +
326
327
  "when writing an expression, don't use words like 'thousand' or 'million'",
327
- parameters: z.object({ expression: z.string() }),
328
+ inputSchema: z.object({ expression: z.string() }),
328
329
  execute: async ({ expression }) => mathjs.evaluate(expression),
329
330
  }),
330
331
  },
@@ -56,7 +56,7 @@ export const { POST } = serve<{ prompt: string }>(async (context) => {
56
56
  tools: {
57
57
  communicationTool: tool({
58
58
  description: 'A tool for informing the caller about your inner thoughts',
59
- parameters: z.object({ message: z.string() }),
59
+ inputSchema: z.object({ message: z.string() }),
60
60
  execute: async ({ message }) => {
61
61
  console.log("Inner thought:", message)
62
62
  return "success"
@@ -106,7 +106,7 @@ const { workflowRunId } = await client.trigger({
106
106
  workflowRunId: "my-workflow", // optional workflow run id
107
107
  retries: 3, // optional retries
108
108
  retryDelay: "1000 * (1 + retried)", // optional delay between retries
109
- delay: "10s" // optional delay value
109
+ delay: "10s", // optional delay value
110
110
  failureUrl: "https://<YOUR_FAILURE_URL>", // optional failure url
111
111
  flowControl: { // optional flow control
112
112
  key: "USER_GIVEN_KEY",
@@ -93,9 +93,13 @@ export const { POST } = serve<UserCreatedPayload>(async (context) => {
93
93
  });
94
94
 
95
95
  async function sendProblemSolvedEmail({
96
- context: WorkflowContext<UserCreatedPayload>
97
- email: string,
98
- stats: { totalProblemsSolved: number }
96
+ context,
97
+ email,
98
+ stats,
99
+ }: {
100
+ context: WorkflowContext<UserCreatedPayload>;
101
+ email: string;
102
+ stats: { totalProblemsSolved: number };
99
103
  }) {
100
104
  if (stats.totalProblemsSolved === 0) {
101
105
  await context.run("send no answers email", async () => {
@@ -437,9 +441,13 @@ The `sendProblemSolvedEmail` method:
437
441
 
438
442
  ```typescript TypeScript
439
443
  async function sendProblemSolvedEmail({
440
- context: WorkflowContext<UserCreatedPayload>
441
- email: string,
442
- stats: { totalProblemsSolved: number }
444
+ context,
445
+ email,
446
+ stats,
447
+ }: {
448
+ context: WorkflowContext<UserCreatedPayload>;
449
+ email: string;
450
+ stats: { totalProblemsSolved: number };
443
451
  }) {
444
452
  if (stats.totalProblemsSolved === 0) {
445
453
  await context.run("send no answers email", async () => {
@@ -35,7 +35,7 @@ export const { POST } = serve<ChargeUserPayload>(async (context) => {
35
35
  // attempt to charge the user
36
36
  const result = await context.run("charge customer", async () => {
37
37
  try {
38
- return await chargeCustomer(i + 1),
38
+ return await chargeCustomer(i + 1)
39
39
  } catch (e) {
40
40
  console.error(e);
41
41
  return
@@ -19,7 +19,7 @@ You can delete entries individually, in bulk by IDs, or by using filters such as
19
19
  await client.dlq.delete(["dlq-12345", "dlq-67890"]);
20
20
 
21
21
  // delete by filters
22
- await client.dlq.delete({ label: "my-label" });
22
+ await client.dlq.delete({ filter: { label: "my-label" } });
23
23
 
24
24
  // delete all
25
25
  await client.dlq.delete({ all: true });
@@ -21,7 +21,7 @@ If you think this advanced option fits your need, you can configure it by passin
21
21
  const client = new Client({ token: "<QSTASH_TOKEN>" })
22
22
 
23
23
  const { workflowRunId } = await client.trigger({
24
- url: "https://<YOUR_WORKFLOW_URL>/workflow"
24
+ url: "https://<YOUR_WORKFLOW_URL>/workflow",
25
25
  failureUrl: "https://<YOUR_FAILURE_URL>/workflow-failure"
26
26
  })
27
27
  ```
@@ -96,7 +96,7 @@ export const { POST } = serve(async (context) => {
96
96
 
97
97
  await context.run(
98
98
  "charge customer",
99
- () => chargeCustomer(),
99
+ () => chargeCustomer("customer-id"),
100
100
  {
101
101
  flowControl: { key: "payment-provider", parallelism: 3 },
102
102
  }
@@ -38,7 +38,7 @@ This way, you can invoke a workflow simply by passing the object to `context.inv
38
38
  workflow: workflowOne,
39
39
  body: "user-1"
40
40
  }
41
- ),
41
+ );
42
42
  });
43
43
  ```
44
44
  </Step>
@@ -80,7 +80,7 @@ This way, you can invoke a workflow simply by passing the object to `context.inv
80
80
  // 👇 optionally label the invoked run; single string or array
81
81
  label: ["team-a", "high-priority"],
82
82
  }
83
- ),
83
+ );
84
84
  });
85
85
  ```
86
86
 
@@ -18,7 +18,7 @@ const {
18
18
  {
19
19
  workflow: analyzeContent,
20
20
  body: "test",
21
- header: {...}, // headers to pass to anotherWorkflow (optional)
21
+ headers: {...}, // headers to pass to anotherWorkflow (optional)
22
22
  retries, // number of retries (optional, default: 3)
23
23
  flowControl, // flow control settings (optional)
24
24
  workflowRunId // workflowRunId to set (optional)
@@ -19,7 +19,7 @@ By default, the retry count is set to **3**, and an **exponential backoff** dela
19
19
 
20
20
  ```javascript Default Backoff Algorithm
21
21
  // n = how many times this request has been retried
22
- delay = min(86400, e ** (2.5*n)) // in seconds
22
+ delay = Math.min(86400, Math.E ** (2.5*n)) // in seconds
23
23
  ```
24
24
 
25
25
  | Retry Attempt | Algorithm | Delay |
@@ -13,12 +13,12 @@ You can pass these configuration options when starting a workflow run:
13
13
  ```typescript
14
14
  import { Client } from "@upstash/workflow";
15
15
 
16
- const client = Client()
16
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
17
17
 
18
18
  const { workflowRunId } = await client.trigger({
19
19
  url: `http://localhost:3000/api/workflow`,
20
20
  retries: 3,
21
- retryDelay: "(1 + retries) * 1000",
21
+ retryDelay: "(1 + retried) * 1000",
22
22
  flowControl: {
23
23
  key: "limit-ads",
24
24
  rate: 1,
@@ -33,6 +33,7 @@ Let's create a user-specific schedule, sending a first report to each user exact
33
33
  <CodeGroup>
34
34
 
35
35
  ```typescript api/sign-up/route.ts
36
+ import { NextResponse } from "next/server";
36
37
  import { signUp } from "@/utils/auth-utils";
37
38
  import { Client } from "@upstash/qstash";
38
39
 
@@ -41,11 +42,18 @@ const client = new Client({ token: process.env.QSTASH_TOKEN! });
41
42
  export async function POST(request: Request) {
42
43
  const userData: UserData = await request.json();
43
44
 
45
+ // Simulate user registration
46
+ const user = await signUp(userData);
47
+
48
+ // Weekly cron expression whose first run is 7 days from signup
49
+ const firstSummaryDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
50
+ const cron = `${firstSummaryDate.getUTCMinutes()} ${firstSummaryDate.getUTCHours()} * * ${firstSummaryDate.getUTCDay()}`;
51
+
44
52
  // Schedule weekly account summary
45
53
  await client.schedules.create({
46
- scheduleId: `user-summary-${user.email}`,
54
+ scheduleId: `user-summary-${user.id}`,
47
55
  destination: "https://<YOUR_APP_URL>/api/send-weekly-summary",
48
- body: { userId: user.id },
56
+ body: JSON.stringify({ userId: user.id }),
49
57
  cron: cron,
50
58
  });
51
59
 
@@ -60,29 +68,31 @@ export async function POST(request: Request) {
60
68
  from fastapi import FastAPI, Request
61
69
  from fastapi.responses import JSONResponse
62
70
  from qstash import AsyncQStash
63
- from datetime import datetime, timedelta
71
+ from datetime import datetime, timedelta, timezone
72
+
73
+ from utils.auth_utils import sign_up
64
74
 
65
75
  app = FastAPI()
66
76
 
67
- client = AsyncQStash("<QSTACK_TOKEN>")
77
+ client = AsyncQStash("<QSTASH_TOKEN>")
68
78
 
69
79
 
70
80
  @app.post("/api/sign-up")
71
- async def sign_up(request: Request):
81
+ async def sign_up_route(request: Request):
72
82
  user_data = await request.json()
73
83
 
74
84
  # Simulate user registration
75
85
  user = await sign_up(user_data)
76
86
 
77
87
  # Calculate the date for the first summary (7 days from now)
78
- first_summary_date = datetime.now() + timedelta(days=7)
88
+ first_summary_date = datetime.now(timezone.utc) + timedelta(days=7)
79
89
 
80
90
  # Create cron expression for weekly summaries starting 7 days from signup
81
- cron = f"{first_summary_date.minute} {first_summary_date.hour} * * {first_summary_date.day}"
91
+ cron = f"{first_summary_date.minute} {first_summary_date.hour} * * {first_summary_date.isoweekday() % 7}"
82
92
 
83
93
  # Schedule weekly account summary
84
94
  await client.schedule.create_json(
85
- schedule_id=f"user-summary-{user.email}",
95
+ schedule_id=f"user-summary-{user.id}",
86
96
  destination="https://<YOUR_APP_URL>/api/send-weekly-summary",
87
97
  body={"userId": user.id},
88
98
  cron=cron,
package/docs/openapi.yaml CHANGED
@@ -1106,6 +1106,7 @@ paths:
1106
1106
  tags:
1107
1107
  - Logs
1108
1108
  summary: List Workflow Run Logs
1109
+ description: List and filter workflow runs with their state, completed and in-progress steps, and step details.
1109
1110
  x-mint: content |
1110
1111
  You can fetch details about workflow runs, including their state, completed and in-progress steps, and step details.
1111
1112
 
@@ -1665,6 +1666,7 @@ paths:
1665
1666
  tags:
1666
1667
  - DLQ
1667
1668
  summary: Resume Workflow from DLQ
1669
+ description: Resume a failed workflow run from the DLQ at the step where it failed, without re-running completed steps.
1668
1670
  x-mint:
1669
1671
  content: |
1670
1672
  When a workflow run fails, it's automatically moved to the DLQ (Dead Letter Queue) where it can be analyzed and resumed.
@@ -62,8 +62,8 @@ If you want requests to retry automatically, you can explicitly pass a retry con
62
62
  </Expandable>
63
63
  </ParamField>
64
64
 
65
- <ParamField body="timeout" type="number" >
66
- Maximum time (in seconds) to wait for a response.
65
+ <ParamField body="timeout" type="string" >
66
+ Maximum time to wait for a response, as a duration string such as `"10s"`.
67
67
  If retries are enabled, this timeout applies individually to each attempt.
68
68
  </ParamField>
69
69
 
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/workflow","version":"1.5.0","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*","!src/**/*.test.*","!src/**/*.test-d.*","!src/**/*.spec.*","!src/**/test-utils.*","!src/**/__tests__/**","!src/**/__snapshots__/**"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"},"./tanstack":{"import":"./tanstack.mjs","require":"./tanstack.js"},"./react-router":{"import":"./react-router.mjs","require":"./react-router.js"}},"scripts":{"build":"tsup && mkdir -p dist/src && cp -R src platforms dist/src/ && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P","prepack":"giget gh:upstash/docs/workflow docs --force-clean 1>&2"},"repository":{"type":"git","url":"git@github.com:upstash/workflow-js.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.6","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^5.1.0","giget":"3.3.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@upstash/qstash":"^2.11.3"},"directories":{"example":"examples","doc":"./docs"},"peerDependencies":{"zod":"^3.25.0 || ^4.0.0"}}
1
+ {"name":"@upstash/workflow","version":"1.5.1-canary.0","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*","!src/**/*.test.*","!src/**/*.test-d.*","!src/**/*.spec.*","!src/**/test-utils.*","!src/**/__tests__/**","!src/**/__snapshots__/**"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"},"./tanstack":{"import":"./tanstack.mjs","require":"./tanstack.js"},"./react-router":{"import":"./react-router.mjs","require":"./react-router.js"}},"scripts":{"build":"tsup && mkdir -p dist/src && cp -R src platforms dist/src/ && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P","prepack":"giget gh:upstash/docs/workflow docs --force-clean 1>&2"},"repository":{"type":"git","url":"git@github.com:upstash/workflow-js.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.6","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^5.1.0","giget":"3.3.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@upstash/qstash":"^2.12.1"},"directories":{"example":"examples","doc":"./docs"},"peerDependencies":{"zod":"^3.25.0 || ^4.0.0"}}