Skip to content

Commit f868cf1

Browse files
authored
Refactor internal steps, headers and body creation (#87)
* fix: refactor step submissions * fix: bump ai dependencies and fix tests * fix: refactor getHeaders method * fix: tests * fix: remove comment * fix: fmt * ci: fix wrangler publish * feat: fix callback-failurecallback headers handles https://linear.app/upstash/issue/DX-1718/workflow-js-fix-fromcallback-headers * fix: tests * fix: review * fix: rm unused invokeWorkflow * fix: test * fix: express dependency we were getting type errors after @types/express v5.0.1 was released a week ago. Pinning the version of this package in the workflow-js and examples/express to 5.0.0 fixed the issue. But this wasn't a good solution in the long term. another solution was removing the dependency from examples/express and keeping it in workflow-js. We don't import anything from @types/express but we still need it in our dependencies. * fix: add debug logs
1 parent cb28b8e commit f868cf1

20 files changed

+1028
-802
lines changed

bun.lockb

-1019 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "app/ci/utils";
22

33
export const GET = async (request: Request) => {
4-
expect(request.headers.get("upstash-workflow-invoke-count"), null)
4+
expect(request.headers.get("upstash-workflow-invoke-count"), "2")
55
return new Response(JSON.stringify({}), { status: 200 });
66
}

examples/express/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"express": "^4.19.2"
1818
},
1919
"devDependencies": {
20-
"@types/express": "^5.0.0",
2120
"@types/node": "^20.5.2",
2221
"tsx": "^4.7.3",
2322
"typescript": "^5.1.6"

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"@solidjs/start": "^1.0.8",
8787
"@sveltejs/kit": "^2.6.1",
8888
"@types/bun": "^1.1.10",
89-
"@types/express": "^5.0.0",
89+
"@types/express": "^5.0.1",
9090
"astro": "^4.16.7",
9191
"eslint": "^9.11.1",
9292
"eslint-plugin-unicorn": "^55.0.0",
@@ -102,9 +102,9 @@
102102
"typescript-eslint": "^8.18.0"
103103
},
104104
"dependencies": {
105-
"@ai-sdk/openai": "^1.0.15",
105+
"@ai-sdk/openai": "^1.2.1",
106106
"@upstash/qstash": "^2.7.22",
107-
"ai": "^4.0.30",
107+
"ai": "^4.1.54",
108108
"zod": "^3.24.1"
109109
},
110110
"directories": {

src/agents/adapters.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe("wrapTools", () => {
5252

5353
expect(Object.entries(wrappedTools).length).toBe(1);
5454
const wrappedTool = wrappedTools["aiSDKTool"];
55-
// @ts-expect-error description exists but can't resolve the type
5655
expect(wrappedTool.description).toBe(aiSDKToolDescription);
5756

5857
await mockQStashServer({
@@ -82,12 +81,9 @@ describe("wrapTools", () => {
8281
headers: {
8382
"upstash-workflow-sdk-version": "1",
8483
"content-type": "application/json",
85-
"upstash-failure-callback-retries": "3",
8684
"upstash-feature-set": "LazyFetch,InitialBody",
8785
"upstash-forward-upstash-workflow-sdk-version": "1",
88-
"upstash-forward-upstash-workflow-invoke-count": "0",
8986
"upstash-method": "POST",
90-
"upstash-retries": "3",
9187
"upstash-workflow-init": "false",
9288
"upstash-workflow-runid": workflowRunId,
9389
"upstash-workflow-url": "https://requestcatcher.com/api",
@@ -104,7 +100,6 @@ describe("wrapTools", () => {
104100

105101
expect(Object.entries(wrappedTools).length).toBe(1);
106102
const wrappedTool = wrappedTools["langChainTool"];
107-
// @ts-expect-error description exists but can't resolve the type
108103
expect(wrappedTool.description).toBe(langChainToolDescription);
109104

110105
await mockQStashServer({
@@ -134,12 +129,9 @@ describe("wrapTools", () => {
134129
headers: {
135130
"upstash-workflow-sdk-version": "1",
136131
"content-type": "application/json",
137-
"upstash-failure-callback-retries": "3",
138132
"upstash-feature-set": "LazyFetch,InitialBody",
139133
"upstash-forward-upstash-workflow-sdk-version": "1",
140-
"upstash-forward-upstash-workflow-invoke-count": "0",
141134
"upstash-method": "POST",
142-
"upstash-retries": "3",
143135
"upstash-workflow-init": "false",
144136
"upstash-workflow-runid": workflowRunId,
145137
"upstash-workflow-url": "https://requestcatcher.com/api",
@@ -156,11 +148,9 @@ describe("wrapTools", () => {
156148

157149
expect(Object.entries(wrappedTools).length).toBe(2);
158150
const wrappedLangChainTool = wrappedTools["langChainTool"];
159-
// @ts-expect-error description exists but can't resolve the type
160151
expect(wrappedLangChainTool.description).toBe(langChainToolDescription);
161152

162153
const wrappedAiSDKTool = wrappedTools["aiSDKTool"];
163-
// @ts-expect-error description exists but can't resolve the type
164154
expect(wrappedAiSDKTool.description).toBe(aiSDKToolDescription);
165155
});
166156

@@ -180,7 +170,6 @@ describe("wrapTools", () => {
180170

181171
expect(Object.entries(wrappedTools).length).toBe(1);
182172
const wrappedTool = wrappedTools["nonwrappedWorkflowTool"];
183-
// @ts-expect-error description exists but can't resolve the type
184173
expect(wrappedTool.description).toBe(workflowToolDescription);
185174

186175
await mockQStashServer({
@@ -209,12 +198,9 @@ describe("wrapTools", () => {
209198
headers: {
210199
"content-type": "application/json",
211200
"upstash-delay": "1000s",
212-
"upstash-failure-callback-retries": "3",
213201
"upstash-feature-set": "LazyFetch,InitialBody",
214202
"upstash-forward-upstash-workflow-sdk-version": "1",
215-
"upstash-forward-upstash-workflow-invoke-count": "0",
216203
"upstash-method": "POST",
217-
"upstash-retries": "3",
218204
"upstash-workflow-init": "false",
219205
"upstash-workflow-runid": workflowRunId,
220206
"upstash-workflow-sdk-version": "1",
@@ -232,7 +218,6 @@ describe("wrapTools", () => {
232218

233219
expect(Object.entries(wrappedTools).length).toBe(1);
234220
const wrappedTool = wrappedTools["wrappedWorkflowTool"];
235-
// @ts-expect-error description exists but can't resolve the type
236221
expect(wrappedTool.description).toBe(workflowToolDescription);
237222

238223
await mockQStashServer({
@@ -261,12 +246,9 @@ describe("wrapTools", () => {
261246
destination: WORKFLOW_ENDPOINT,
262247
headers: {
263248
"content-type": "application/json",
264-
"upstash-failure-callback-retries": "3",
265249
"upstash-feature-set": "LazyFetch,InitialBody",
266250
"upstash-forward-upstash-workflow-sdk-version": "1",
267-
"upstash-forward-upstash-workflow-invoke-count": "0",
268251
"upstash-method": "POST",
269-
"upstash-retries": "3",
270252
"upstash-workflow-init": "false",
271253
"upstash-workflow-runid": workflowRunId,
272254
"upstash-workflow-sdk-version": "1",

src/agents/agent.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("agents", () => {
2424
steps: [],
2525
url: WORKFLOW_ENDPOINT,
2626
workflowRunId,
27+
retries: 5,
2728
});
2829

2930
const agentsApi = new WorkflowAgents({ context });
@@ -93,13 +94,10 @@ describe("agents", () => {
9394
"upstash-callback-forward-upstash-workflow-stepid": "1",
9495
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
9596
"upstash-callback-forward-upstash-workflow-steptype": "Call",
96-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
97-
"upstash-callback-retries": "3",
9897
"upstash-callback-workflow-calltype": "fromCallback",
9998
"upstash-callback-workflow-init": "false",
10099
"upstash-callback-workflow-runid": workflowRunId,
101100
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
102-
"upstash-failure-callback-retries": "3",
103101
"upstash-feature-set": "WF_NoDelete,InitialBody",
104102
"upstash-forward-authorization": `Bearer ${openaiToken}`,
105103
"upstash-forward-content-type": "application/json",
@@ -110,6 +108,7 @@ describe("agents", () => {
110108
"upstash-workflow-init": "false",
111109
"upstash-workflow-runid": workflowRunId,
112110
"upstash-workflow-url": "https://requestcatcher.com/api",
111+
"upstash-callback-retries": "5",
113112
},
114113
},
115114
],
@@ -120,7 +119,6 @@ describe("agents", () => {
120119
test("should convert agent to tool", async () => {
121120
const agentTool = agent.asTool();
122121

123-
// @ts-expect-error description exists but isn't accessible
124122
expect(agentTool.description).toBe(
125123
"An AI Agent with the following background: an agentHas access to the following tools: ai sdk tool"
126124
);
@@ -160,13 +158,11 @@ describe("agents", () => {
160158
"upstash-callback-forward-upstash-workflow-stepid": "2",
161159
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
162160
"upstash-callback-forward-upstash-workflow-steptype": "Call",
163-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
164-
"upstash-callback-retries": "3",
161+
"upstash-callback-retries": "5",
165162
"upstash-callback-workflow-calltype": "fromCallback",
166163
"upstash-callback-workflow-init": "false",
167164
"upstash-callback-workflow-runid": workflowRunId,
168165
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
169-
"upstash-failure-callback-retries": "3",
170166
"upstash-feature-set": "WF_NoDelete,InitialBody",
171167
"upstash-forward-authorization": `Bearer ${openaiToken}`,
172168
"upstash-forward-content-type": "application/json",
@@ -225,13 +221,11 @@ describe("agents", () => {
225221
"upstash-callback-forward-upstash-workflow-stepid": "3",
226222
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent manager llm",
227223
"upstash-callback-forward-upstash-workflow-steptype": "Call",
228-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
229-
"upstash-callback-retries": "3",
224+
"upstash-callback-retries": "5",
230225
"upstash-callback-workflow-calltype": "fromCallback",
231226
"upstash-callback-workflow-init": "false",
232227
"upstash-callback-workflow-runid": workflowRunId,
233228
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
234-
"upstash-failure-callback-retries": "3",
235229
"upstash-feature-set": "WF_NoDelete,InitialBody",
236230
"upstash-forward-authorization": `Bearer ${openaiToken}`,
237231
"upstash-forward-content-type": "application/json",

src/agents/agent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export class Agent {
9393
*/
9494
public asTool(): AISDKTool {
9595
const toolDescriptions = Object.values(this.tools)
96-
// @ts-expect-error description exists but can't be resolved
9796
.map((tool) => tool.description)
9897
.join("\n");
9998
return tool({

src/agents/task.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,10 @@ describe("tasks", () => {
118118
"upstash-callback-forward-upstash-workflow-stepid": "1",
119119
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
120120
"upstash-callback-forward-upstash-workflow-steptype": "Call",
121-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
122-
"upstash-callback-retries": "3",
123121
"upstash-callback-workflow-calltype": "fromCallback",
124122
"upstash-callback-workflow-init": "false",
125123
"upstash-callback-workflow-runid": workflowRunId,
126124
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
127-
"upstash-failure-callback-retries": "3",
128125
"upstash-feature-set": "WF_NoDelete,InitialBody",
129126
"upstash-forward-authorization": `Bearer ${openaiToken}`,
130127
"upstash-forward-content-type": "application/json",
@@ -199,13 +196,10 @@ describe("tasks", () => {
199196
"upstash-callback-forward-upstash-workflow-stepid": "1",
200197
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent Manager LLM",
201198
"upstash-callback-forward-upstash-workflow-steptype": "Call",
202-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
203-
"upstash-callback-retries": "3",
204199
"upstash-callback-workflow-calltype": "fromCallback",
205200
"upstash-callback-workflow-init": "false",
206201
"upstash-callback-workflow-runid": workflowRunId,
207202
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
208-
"upstash-failure-callback-retries": "3",
209203
"upstash-feature-set": "WF_NoDelete,InitialBody",
210204
"upstash-forward-authorization": `Bearer ${customApiKey}`,
211205
"upstash-forward-content-type": "application/json",
@@ -271,13 +265,10 @@ describe("tasks", () => {
271265
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
272266
"upstash-callback-forward-upstash-workflow-stepid": "1",
273267
"upstash-callback-forward-upstash-workflow-steptype": "Call",
274-
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
275-
"upstash-callback-retries": "3",
276268
"upstash-callback-workflow-calltype": "fromCallback",
277269
"upstash-callback-workflow-init": "false",
278270
"upstash-callback-workflow-runid": workflowRunId,
279271
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
280-
"upstash-failure-callback-retries": "3",
281272
"upstash-feature-set": "WF_NoDelete,InitialBody",
282273
"upstash-forward-content-type": "application/json",
283274
"upstash-forward-upstash-agent-name": "my agent",

src/context/auto-executor.test.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ describe("auto-executor", () => {
9191
headers: new Headers({}) as Headers,
9292
steps,
9393
url: WORKFLOW_ENDPOINT,
94+
retries: 6,
95+
flowControl: {
96+
key: "key",
97+
parallelism: 10,
98+
},
99+
invokeCount: 7,
94100
});
95101
};
96102

@@ -124,13 +130,14 @@ describe("auto-executor", () => {
124130
"content-type": "application/json",
125131
"upstash-feature-set": "LazyFetch,InitialBody",
126132
"upstash-forward-upstash-workflow-sdk-version": "1",
127-
"upstash-forward-upstash-workflow-invoke-count": "0",
128133
"upstash-method": "POST",
129-
"upstash-retries": "3",
130-
"upstash-failure-callback-retries": "3",
131134
"upstash-workflow-runid": workflowRunId,
132135
"upstash-workflow-init": "false",
133136
"upstash-workflow-url": WORKFLOW_ENDPOINT,
137+
"upstash-retries": "6",
138+
"upstash-flow-control-key": "key",
139+
"upstash-flow-control-value": "parallelism=10",
140+
"upstash-forward-upstash-workflow-invoke-count": "7",
134141
},
135142
body: JSON.stringify({
136143
...singleStep,
@@ -220,13 +227,14 @@ describe("auto-executor", () => {
220227
"upstash-feature-set": "LazyFetch,InitialBody",
221228
"upstash-delay": "123s",
222229
"upstash-forward-upstash-workflow-sdk-version": "1",
223-
"upstash-forward-upstash-workflow-invoke-count": "0",
224230
"upstash-method": "POST",
225-
"upstash-retries": "3",
226-
"upstash-failure-callback-retries": "3",
227231
"upstash-workflow-runid": workflowRunId,
228232
"upstash-workflow-init": "false",
229233
"upstash-workflow-url": WORKFLOW_ENDPOINT,
234+
"upstash-retries": "6",
235+
"upstash-flow-control-key": "key",
236+
"upstash-flow-control-value": "parallelism=10",
237+
"upstash-forward-upstash-workflow-invoke-count": "7",
230238
},
231239
},
232240
{
@@ -238,13 +246,14 @@ describe("auto-executor", () => {
238246
"upstash-feature-set": "LazyFetch,InitialBody",
239247
"upstash-delay": "10m",
240248
"upstash-forward-upstash-workflow-sdk-version": "1",
241-
"upstash-forward-upstash-workflow-invoke-count": "0",
242249
"upstash-method": "POST",
243-
"upstash-retries": "3",
244-
"upstash-failure-callback-retries": "3",
245250
"upstash-workflow-runid": workflowRunId,
246251
"upstash-workflow-init": "false",
247252
"upstash-workflow-url": WORKFLOW_ENDPOINT,
253+
"upstash-retries": "6",
254+
"upstash-flow-control-key": "key",
255+
"upstash-flow-control-value": "parallelism=10",
256+
"upstash-forward-upstash-workflow-invoke-count": "7",
248257
},
249258
},
250259
{
@@ -255,14 +264,15 @@ describe("auto-executor", () => {
255264
"content-type": "application/json",
256265
"upstash-feature-set": "LazyFetch,InitialBody",
257266
"upstash-forward-upstash-workflow-sdk-version": "1",
258-
"upstash-forward-upstash-workflow-invoke-count": "0",
259267
"upstash-method": "POST",
260-
"upstash-retries": "3",
261-
"upstash-failure-callback-retries": "3",
262268
"upstash-not-before": "123123",
263269
"upstash-workflow-runid": workflowRunId,
264270
"upstash-workflow-init": "false",
265271
"upstash-workflow-url": WORKFLOW_ENDPOINT,
272+
"upstash-retries": "6",
273+
"upstash-flow-control-key": "key",
274+
"upstash-flow-control-value": "parallelism=10",
275+
"upstash-forward-upstash-workflow-invoke-count": "7",
266276
},
267277
},
268278
{
@@ -273,14 +283,14 @@ describe("auto-executor", () => {
273283
"content-type": "application/json",
274284
"upstash-feature-set": "LazyFetch,InitialBody",
275285
"upstash-forward-upstash-workflow-sdk-version": "1",
276-
"upstash-forward-upstash-workflow-invoke-count": "0",
277286
"upstash-method": "POST",
278-
"upstash-retries": "3",
279-
"upstash-failure-callback-retries": "3",
280-
"upstash-workflow-calltype": "step",
281287
"upstash-workflow-runid": workflowRunId,
282288
"upstash-workflow-init": "false",
283289
"upstash-workflow-url": WORKFLOW_ENDPOINT,
290+
"upstash-retries": "6",
291+
"upstash-flow-control-key": "key",
292+
"upstash-flow-control-value": "parallelism=10",
293+
"upstash-forward-upstash-workflow-invoke-count": "7",
284294
},
285295
},
286296
],
@@ -334,13 +344,14 @@ describe("auto-executor", () => {
334344
"content-type": "application/json",
335345
"upstash-feature-set": "LazyFetch,InitialBody",
336346
"upstash-forward-upstash-workflow-sdk-version": "1",
337-
"upstash-forward-upstash-workflow-invoke-count": "0",
338347
"upstash-method": "POST",
339-
"upstash-retries": "3",
340-
"upstash-failure-callback-retries": "3",
341348
"upstash-workflow-runid": workflowRunId,
342349
"upstash-workflow-init": "false",
343350
"upstash-workflow-url": WORKFLOW_ENDPOINT,
351+
"upstash-retries": "6",
352+
"upstash-flow-control-key": "key",
353+
"upstash-flow-control-value": "parallelism=10",
354+
"upstash-forward-upstash-workflow-invoke-count": "7",
344355
},
345356
body: JSON.stringify(parallelSteps[2]),
346357
},
@@ -390,13 +401,14 @@ describe("auto-executor", () => {
390401
"content-type": "application/json",
391402
"upstash-feature-set": "LazyFetch,InitialBody",
392403
"upstash-forward-upstash-workflow-sdk-version": "1",
393-
"upstash-forward-upstash-workflow-invoke-count": "0",
394404
"upstash-method": "POST",
395-
"upstash-retries": "3",
396-
"upstash-failure-callback-retries": "3",
397405
"upstash-workflow-runid": workflowRunId,
398406
"upstash-workflow-init": "false",
399407
"upstash-workflow-url": WORKFLOW_ENDPOINT,
408+
"upstash-retries": "6",
409+
"upstash-flow-control-key": "key",
410+
"upstash-flow-control-value": "parallelism=10",
411+
"upstash-forward-upstash-workflow-invoke-count": "7",
400412
},
401413
body: JSON.stringify(parallelSteps[3]),
402414
},

0 commit comments

Comments
 (0)