All skills
upstash avatar

/upstash-workflow-js

@36daab8
by upstashupstash/skills27 stars
7

Work with the @upstash/workflow TypeScript/JavaScript SDK for durable, long-running workflows in serverless functions, multi-step processes that survive timeouts, retries, and restarts (built on QStash). Use when defining a workflow endpoint with serve(), running steps with context.run, sleeping for minutes to days without holding a function open, calling external APIs with context.call, waiting for an external event or webhook, invoking other workflows, configuring retries, failure callbacks, and a DLQ, controlling concurrency, rate, and parallelism, triggering, cancelling, or inspecting runs with the Workflow client, building AI agents and orchestrators, human-in-the-loop approvals, realtime updates, local development with the QStash dev server, adding middleware, or migrating workflows safely. Also use when the user asks for durable execution, step functions, saga or orchestration patterns, background jobs with checkpoints, or long-running tasks on Vercel, Next.js, Cloudflare Workers, or other serverless platforms.

Use this Skill: https://skilld.dev/gh/upstash/skills/upstash-workflow-js

This session only. Nothing lands on disk.

basicsserve.md

≈605 tokens on demand. Your agent reads this file only when SKILL.md points to it.

This documentation explains how to use serve() to expose workflows as HTTP endpoints.

Core Concept

serve() turns an async route function into a workflow endpoint. When a request arrives, a workflow run is created, and the route function defines the execution logic using context.run().

Full Example With Inline Comments

import { serve } from "@upstash/workflow/nextjs";
import { z } from "zod";
import { Client, Receiver } from "@upstash/qstash";
import { loggingMiddleware } from "@upstash/workflow";

type InitialPayload = { foo: string; bar: number };

const payloadSchema = z.object({ foo: z.string(), bar: z.number() });

export const { POST } = serve<InitialPayload>(
  async (context) => {
    const payload = context.requestPayload;
    await context.run("step-1", async () => `hello ${payload.foo}`);
  },
  {
    // Runs when the workflow fails after all retries
    failureFunction: async ({ context, failStatus, failResponse, failHeaders, failStack }) =>
      console.error(failResponse),

    // Hooks for step lifecycle, run lifecycle, and debug events
    middlewares: [loggingMiddleware],

    // Manually parse the initial request payload before workflow execution
    initialPayloadParser: (raw) => JSON.parse(raw),

    // Automatically validate + parse the request payload using Zod
    schema: payloadSchema,

    // Override the full URL used to schedule subsequent workflow steps
    url: "https://myapp.com/api/workflow",

    // Override only the base portion of the inferred URL (keeps the route path)
    baseUrl: "https://proxy-url.com",

    // Provide a custom QStash client
    qstashClient: new Client({ token: process.env.QSTASH_TOKEN! }),

    // Provide a custom QStash Receiver for verifying that requests come from QStash
    receiver: new Receiver({
      currentSigningKey: process.env.QSTASH_CURRENT_SIGNING_KEY!,
      nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY!,
    }),

    // Override environment variables available inside workflow execution
    env: {
      QSTASH_URL: "https://qstash.upstash.io",
      QSTASH_TOKEN: process.env.QSTASH_TOKEN!,
    },

    // Output detailed execution logs to stdout
    verbose: true,

    // Disable anonymous telemetry for this workflow endpoint
    disableTelemetry: true,
  }
);

Common Pitfalls

  • Incorrect URL inference behind proxies or local tunnels—set url or baseUrl.

Source: SKILL.md on GitHub

1 warning17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill is a comprehensive documentation and implementation guide for the Upstash Workflow SDK. It covers durable serverless workflows, agent orchestration, and reliability features. All identified external resources and tool downloads are official components of the Upstash platform or well-known development services. No security issues or malicious patterns were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: MEDIUM · 1 issue

Signed by skilld at 36daab8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last month
metadata
{
  "author": "Upstash",
  "homepage": "https://upstash.com"
}

README badge

README badge for upstash/skills/upstash-workflow-js