Skip to content

Refactor internal steps, headers and body creation #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 4, 2025
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "app/ci/utils";

export const GET = async (request: Request) => {
expect(request.headers.get("upstash-workflow-invoke-count"), null)
expect(request.headers.get("upstash-workflow-invoke-count"), "2")
return new Response(JSON.stringify({}), { status: 200 });
}
1 change: 0 additions & 1 deletion examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"express": "^4.19.2"
},
"devDependencies": {
"@types/express": "^5.0.0",
"@types/node": "^20.5.2",
"tsx": "^4.7.3",
"typescript": "^5.1.6"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@solidjs/start": "^1.0.8",
"@sveltejs/kit": "^2.6.1",
"@types/bun": "^1.1.10",
"@types/express": "^5.0.0",
"@types/express": "^5.0.1",
"astro": "^4.16.7",
"eslint": "^9.11.1",
"eslint-plugin-unicorn": "^55.0.0",
Expand All @@ -102,9 +102,9 @@
"typescript-eslint": "^8.18.0"
},
"dependencies": {
"@ai-sdk/openai": "^1.0.15",
"@ai-sdk/openai": "^1.2.1",
"@upstash/qstash": "^2.7.22",
"ai": "^4.0.30",
"ai": "^4.1.54",
"zod": "^3.24.1"
},
"directories": {
Expand Down
18 changes: 0 additions & 18 deletions src/agents/adapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe("wrapTools", () => {

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

await mockQStashServer({
Expand Down Expand Up @@ -82,12 +81,9 @@ describe("wrapTools", () => {
headers: {
"upstash-workflow-sdk-version": "1",
"content-type": "application/json",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-workflow-init": "false",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-url": "https://requestcatcher.com/api",
Expand All @@ -104,7 +100,6 @@ describe("wrapTools", () => {

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

await mockQStashServer({
Expand Down Expand Up @@ -134,12 +129,9 @@ describe("wrapTools", () => {
headers: {
"upstash-workflow-sdk-version": "1",
"content-type": "application/json",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-workflow-init": "false",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-url": "https://requestcatcher.com/api",
Expand All @@ -156,11 +148,9 @@ describe("wrapTools", () => {

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

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

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

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

await mockQStashServer({
Expand Down Expand Up @@ -209,12 +198,9 @@ describe("wrapTools", () => {
headers: {
"content-type": "application/json",
"upstash-delay": "1000s",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-workflow-init": "false",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-sdk-version": "1",
Expand All @@ -232,7 +218,6 @@ describe("wrapTools", () => {

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

await mockQStashServer({
Expand Down Expand Up @@ -261,12 +246,9 @@ describe("wrapTools", () => {
destination: WORKFLOW_ENDPOINT,
headers: {
"content-type": "application/json",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-workflow-init": "false",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-sdk-version": "1",
Expand Down
14 changes: 4 additions & 10 deletions src/agents/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("agents", () => {
steps: [],
url: WORKFLOW_ENDPOINT,
workflowRunId,
retries: 5,
});

const agentsApi = new WorkflowAgents({ context });
Expand Down Expand Up @@ -93,13 +94,10 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${openaiToken}`,
"upstash-forward-content-type": "application/json",
Expand All @@ -110,6 +108,7 @@ describe("agents", () => {
"upstash-workflow-init": "false",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-url": "https://requestcatcher.com/api",
"upstash-callback-retries": "5",
},
},
],
Expand All @@ -120,7 +119,6 @@ describe("agents", () => {
test("should convert agent to tool", async () => {
const agentTool = agent.asTool();

// @ts-expect-error description exists but isn't accessible
expect(agentTool.description).toBe(
"An AI Agent with the following background: an agentHas access to the following tools: ai sdk tool"
);
Expand Down Expand Up @@ -160,13 +158,11 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "2",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-retries": "5",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${openaiToken}`,
"upstash-forward-content-type": "application/json",
Expand Down Expand Up @@ -225,13 +221,11 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "3",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent manager llm",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-retries": "5",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${openaiToken}`,
"upstash-forward-content-type": "application/json",
Expand Down
1 change: 0 additions & 1 deletion src/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class Agent {
*/
public asTool(): AISDKTool {
const toolDescriptions = Object.values(this.tools)
// @ts-expect-error description exists but can't be resolved
.map((tool) => tool.description)
.join("\n");
return tool({
Expand Down
9 changes: 0 additions & 9 deletions src/agents/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ describe("tasks", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${openaiToken}`,
"upstash-forward-content-type": "application/json",
Expand Down Expand Up @@ -199,13 +196,10 @@ describe("tasks", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent Manager LLM",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${customApiKey}`,
"upstash-forward-content-type": "application/json",
Expand Down Expand Up @@ -271,13 +265,10 @@ describe("tasks", () => {
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "0",
"upstash-callback-retries": "3",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
"upstash-callback-workflow-url": "https://requestcatcher.com/api",
"upstash-failure-callback-retries": "3",
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-content-type": "application/json",
"upstash-forward-upstash-agent-name": "my agent",
Expand Down
56 changes: 34 additions & 22 deletions src/context/auto-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ describe("auto-executor", () => {
headers: new Headers({}) as Headers,
steps,
url: WORKFLOW_ENDPOINT,
retries: 6,
flowControl: {
key: "key",
parallelism: 10,
},
invokeCount: 7,
});
};

Expand Down Expand Up @@ -124,13 +130,14 @@ describe("auto-executor", () => {
"content-type": "application/json",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
body: JSON.stringify({
...singleStep,
Expand Down Expand Up @@ -220,13 +227,14 @@ describe("auto-executor", () => {
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-delay": "123s",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
},
{
Expand All @@ -238,13 +246,14 @@ describe("auto-executor", () => {
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-delay": "10m",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
},
{
Expand All @@ -255,14 +264,15 @@ describe("auto-executor", () => {
"content-type": "application/json",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-not-before": "123123",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
},
{
Expand All @@ -273,14 +283,14 @@ describe("auto-executor", () => {
"content-type": "application/json",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-calltype": "step",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
},
],
Expand Down Expand Up @@ -334,13 +344,14 @@ describe("auto-executor", () => {
"content-type": "application/json",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
body: JSON.stringify(parallelSteps[2]),
},
Expand Down Expand Up @@ -390,13 +401,14 @@ describe("auto-executor", () => {
"content-type": "application/json",
"upstash-feature-set": "LazyFetch,InitialBody",
"upstash-forward-upstash-workflow-sdk-version": "1",
"upstash-forward-upstash-workflow-invoke-count": "0",
"upstash-method": "POST",
"upstash-retries": "3",
"upstash-failure-callback-retries": "3",
"upstash-workflow-runid": workflowRunId,
"upstash-workflow-init": "false",
"upstash-workflow-url": WORKFLOW_ENDPOINT,
"upstash-retries": "6",
"upstash-flow-control-key": "key",
"upstash-flow-control-value": "parallelism=10",
"upstash-forward-upstash-workflow-invoke-count": "7",
},
body: JSON.stringify(parallelSteps[3]),
},
Expand Down
Loading
Loading