https://github.com/tanstack/workflow
🤖 Type-safe durable execution for agents and workflows. Resumable runs, append-only history, and compensable steps for TS/JS, React, Solid, Vue, and Svelte.
https://github.com/tanstack/workflow
Last synced: 18 days ago
JSON representation
🤖 Type-safe durable execution for agents and workflows. Resumable runs, append-only history, and compensable steps for TS/JS, React, Solid, Vue, and Svelte.
- Host: GitHub
- URL: https://github.com/tanstack/workflow
- Owner: TanStack
- License: mit
- Created: 2026-05-20T16:13:14.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-30T23:18:24.000Z (about 1 month ago)
- Last Synced: 2026-06-18T08:27:00.462Z (24 days ago)
- Language: TypeScript
- Size: 756 KB
- Stars: 175
- Watchers: 0
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# TanStack Workflow
Type-safe durable execution for TypeScript. Workflows are ordinary async functions that can pause, persist progress to an append-only log, and resume after approvals, webhooks, timers, or process restarts.
```bash
pnpm add @tanstack/workflow-core
```
Install `zod` or another Standard Schema-compatible library if you want runtime validation for workflow inputs, outputs, state, or signal payloads.
## Example
```ts
import {
createWorkflow,
inMemoryRunStore,
runWorkflow,
} from '@tanstack/workflow-core'
import { z } from 'zod'
const checkout = createWorkflow({
id: 'checkout',
input: z.object({ userId: z.string(), amount: z.number() }),
output: z.object({ status: z.enum(['approved', 'rejected']) }),
}).handler(async (ctx) => {
const charge = await ctx.step('charge-card', (stepCtx) =>
stripe.charges.create(
{ customer: ctx.input.userId, amount: ctx.input.amount },
{ idempotencyKey: stepCtx.id },
),
)
if (ctx.input.amount > 10_000) {
const decision = await ctx.approve({ title: 'Approve large charge?' })
if (!decision.approved) return { status: 'rejected' as const }
}
await ctx.step('send-receipt', () => sendReceipt(charge.id))
return { status: 'approved' as const }
})
const store = inMemoryRunStore()
for await (const event of runWorkflow({
workflow: checkout,
input: { userId: 'cus_123', amount: 4200 },
runStore: store,
})) {
console.log(event.type, event)
}
```
## Core Ideas
- Side effects live inside `ctx.step(id, fn)`, which records results and skips re-execution on replay.
- `ctx.waitForEvent`, `ctx.approve`, `ctx.sleep`, and `ctx.sleepUntil` pause runs until the host delivers a matching signal or approval.
- `ctx.now()` and `ctx.uuid()` record deterministic values for replay.
- Middleware can extend `ctx` with typed dependencies such as users, database handles, or tracing.
- Storage is pluggable through `RunStore`; the package ships an in-memory store for local development and tests.
## Packages
- `@tanstack/workflow-core`: engine, workflow builder, middleware, event types, request parsing helpers, version routing, and in-memory `RunStore`.
- `@tanstack/workflow-runtime`: registered workflows, durable execution store contract, timers, schedules, leases, signals, approvals, and bounded sweeps.
- `@tanstack/workflow-store-drizzle-postgres`: Drizzle/Postgres implementation of the runtime execution store.
- `@tanstack/workflow-vercel`: Vercel route handler and cron config helper for runtime sweeps.
- `@tanstack/workflow-netlify`: Netlify Scheduled Function handler and config helper for runtime sweeps.
Framework bindings and devtools are planned as follow-up packages.
## Development
```bash
pnpm install
pnpm --filter @tanstack/workflow-core test:lib
pnpm --filter @tanstack/workflow-core test:types
pnpm --filter @tanstack/workflow-core build
pnpm test
```
## Docs
- [Overview](./docs/overview.md)
- [Comparison](./docs/comparison.md)
- [Installation](./docs/installation.md)
- [Quick start](./docs/quick-start.md)
- [Guide](./docs/guide/index.md)
- [Cookbook](./docs/cookbook/index.md)
- [API reference](./docs/api/index.md)
- [Primitives](./docs/concepts/primitives.md)
- [Replay and resume](./docs/concepts/replay-and-resume.md)
- [Scheduling](./docs/concepts/scheduling.md)
## License
MIT