mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
58b379252a
Rebase of the dynamic-workflow-source prototype onto main, reworked to use
the real server-side storage path instead of stashing generated code in
plaintext run metadata.
`start()` now accepts workflow source as a string, for orchestration whose
shape is only known after you deploy — a workflow-builder UI, a
customer-defined automation, an AI-generated plan over a fixed catalog of
registered steps:
await start(source, [{ userId }], { dynamic: { steps: { fetchUser } } });
The source is validated, compiled to workflow VM code, and stored with the
run through the same pipeline as the run's input: compressed, then encrypted
with the run's key. On worlds with a blob-ref layer it lands behind a ref —
inline for a small definition, object storage for a large one (see the
matching workflow-server PR). Replay hydrates it and evaluates *it* instead
of the deployment's bundle, so a run always executes the exact code it
started on.
What changed from the prototype:
- Generated code no longer rides `executionContext.dynamicWorkflow`. Only
small plaintext metadata does — version, source hash, export name, and the
alias-to-step-id map — which is what lets a run be identified as dynamic,
and its step allowlist audited, without decrypting anything. It also has
to fit the 2 KB execution-context budget, which real generated code does
not.
- The code rides `run_created` (and the queue message, for resilient start
and the turbo path, which synthesizes the run snapshot rather than reading
it) as a serialized payload, or as a ref for definitions too large to send
inline.
- `start()` verifies the created run came back carrying its code. A backend
without dynamic-source storage drops the field rather than rejecting it, so
without this the run would look fine and fail much later as an
unregistered-workflow error on a queue delivery.
- Compilation moved to its own module. The workflow id is derived from the
source *and* its step bindings, so the same definition always gets the same
durable id, and arbitrary source cannot claim a static workflow's.
Docs: new "Dynamic Workflows" page. The v5 "How it works" section is renamed
"Advanced" to fit it — the section explains the build-time execution model,
and dynamic source is the escape hatch from it. Permanent redirects cover
every `/v5/docs/how-it-works/*` slug; v4 keeps its own section at the
unversioned path, so those are deliberately untouched until v5 becomes the
default.
Tests: 35 unit tests over compilation, id derivation and validation; 4
type-level tests pinning the overload resolution; 7 e2e tests over the real
round trip (generated code executing against registered steps, stable ids,
encrypted-at-rest storage, replay across a suspension, the deferred ref
path, the step allowlist failing a run, and validation refusing to create
one). The e2e file is added to `test:e2e`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
419 lines
15 KiB
TypeScript
419 lines
15 KiB
TypeScript
import { createMDX } from 'fumadocs-mdx/next';
|
|
import type { NextConfig } from 'next';
|
|
|
|
const withMDX = createMDX();
|
|
|
|
const config: NextConfig = {
|
|
experimental: {
|
|
turbopackFileSystemCacheForDev: true,
|
|
},
|
|
|
|
typescript: {
|
|
ignoreBuildErrors: true,
|
|
},
|
|
|
|
outputFileTracingIncludes: {
|
|
'/og/\\[\\.\\.\\.slug\\]': ['./lib/og/assets/**/*'],
|
|
'/worlds/\\[id\\]/opengraph-image': ['./lib/og/assets/**/*'],
|
|
},
|
|
|
|
async redirects() {
|
|
return [
|
|
{
|
|
source: '/docs',
|
|
destination: '/docs/getting-started',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs',
|
|
destination: '/v5/docs/getting-started',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/cookbook',
|
|
destination: '/cookbook',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/cookbook/:path*',
|
|
destination: '/cookbook/:path*',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/cookbooks',
|
|
destination: '/cookbook',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/cookbooks/:path*',
|
|
destination: '/cookbook/:path*',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/err/:slug',
|
|
destination: '/docs/errors/:slug',
|
|
permanent: true,
|
|
},
|
|
// Redirect old world docs to the /worlds routes. The world pages
|
|
// (and Building a World) were removed from the versioned docs trees;
|
|
// content/worlds/{v4,v5} is the canonical source, served at /worlds/*
|
|
// (current) and /v5/worlds/* (pre-release).
|
|
{
|
|
source: '/docs/deploying/world/local-world',
|
|
destination: '/worlds/local',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/deploying/world/postgres-world',
|
|
destination: '/worlds/postgres',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/deploying/world/vercel-world',
|
|
destination: '/worlds/vercel',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/deploying/world/local-world',
|
|
destination: '/v5/worlds/local',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/deploying/world/postgres-world',
|
|
destination: '/v5/worlds/postgres',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/deploying/world/vercel-world',
|
|
destination: '/v5/worlds/vercel',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/deploying/building-a-world',
|
|
destination: '/worlds/building-a-world',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/deploying/building-a-world',
|
|
destination: '/v5/worlds/building-a-world',
|
|
permanent: true,
|
|
},
|
|
// The worlds listing and compare pages are unversioned; send the
|
|
// version-prefixed URLs (reachable via the render-time /v5 link
|
|
// rewrite on pre-release pages) to the canonical routes.
|
|
{
|
|
source: '/v5/worlds',
|
|
destination: '/worlds',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/v5/worlds/compare',
|
|
destination: '/worlds/compare',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/worlds',
|
|
destination: '/worlds',
|
|
permanent: true,
|
|
},
|
|
// Foundations "Common Patterns" page was retired in favor of dedicated
|
|
// cookbook recipes. Path-level redirect lands visitors on the cookbook
|
|
// overview where each pattern (Sequential & Parallel, Workflow
|
|
// Composition, Timeouts, etc.) has its own page. Note: anchor fragments
|
|
// from old links (#timeout-pattern, #direct-await-flattening, etc.) are
|
|
// dropped on redirect — Next.js redirects() does not match anchors.
|
|
{
|
|
source: '/docs/foundations/common-patterns',
|
|
destination: '/cookbook',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/foundations/control-flow-patterns',
|
|
destination: '/cookbook',
|
|
permanent: true,
|
|
},
|
|
// The Migration Guides section was replaced by Comparisons (#2676):
|
|
// each migrating-from-* page's content folded into the matching
|
|
// workflow-sdk-vs-* comparison page. Permanent redirects keep old
|
|
// links and indexed search results working. The /v5-prefixed
|
|
// equivalents are intentionally omitted: those URLs carried noindex,
|
|
// and the /v5 prefix collapses into the unprefixed space when v5
|
|
// becomes the default docs version.
|
|
{
|
|
source: '/docs/migration-guides',
|
|
destination: '/docs/comparisons',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-inngest',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-inngest',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-temporal',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-temporal',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-trigger-dev',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-trigger-dev',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-aws-step-functions',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-aws-step-functions',
|
|
permanent: true,
|
|
},
|
|
// Docs pages also expose text/markdown alternates at `<page>.md`.
|
|
{
|
|
source: '/docs/migration-guides.md',
|
|
destination: '/docs/comparisons.md',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-inngest.md',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-inngest.md',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-temporal.md',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-temporal.md',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-trigger-dev.md',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-trigger-dev.md',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/migration-guides/migrating-from-aws-step-functions.md',
|
|
destination: '/docs/comparisons/workflow-sdk-vs-aws-step-functions.md',
|
|
permanent: true,
|
|
},
|
|
// Anything else under the retired section lands on the index.
|
|
{
|
|
source: '/docs/migration-guides/:path*',
|
|
destination: '/docs/comparisons',
|
|
permanent: false,
|
|
},
|
|
// Cookbook: child-workflows and distributed-abort-controller moved
|
|
// from common-patterns (now "Reliability Patterns") to advanced
|
|
{
|
|
source: '/cookbook/common-patterns/child-workflows',
|
|
destination: '/cookbook/advanced/child-workflows',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/cookbook/common-patterns/distributed-abort-controller',
|
|
destination: '/cookbook/advanced/distributed-abort-controller',
|
|
permanent: true,
|
|
},
|
|
// Cookbook: stop-workflow → agent-stop-signal → agent-cancellation.
|
|
// The page now covers both Hard Cancellation (run.cancel()) and Stop
|
|
// Signal (hook + Promise.race) as named patterns, so the broader
|
|
// "Agent Cancellation" title fits both. Both prior URLs land directly
|
|
// on the current page (no redirect chains).
|
|
{
|
|
source: '/cookbook/agent-patterns/stop-workflow',
|
|
destination: '/cookbook/agent-patterns/agent-cancellation',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/cookbook/agent-patterns/agent-stop-signal',
|
|
destination: '/cookbook/agent-patterns/agent-cancellation',
|
|
permanent: true,
|
|
},
|
|
// The v5 "How it works" section was renamed to "Advanced" when Dynamic
|
|
// Workflows joined it: the section is where the build-time execution
|
|
// model is explained, and dynamic source is the escape hatch from it —
|
|
// "Advanced" describes both, "How it works" only the first.
|
|
//
|
|
// Only the /v5-prefixed paths move. v4 still serves its own
|
|
// `how-it-works` section at the unversioned /docs/how-it-works/*, so
|
|
// redirecting those would break the current default docs. Add the
|
|
// unversioned pair as part of making v5 the default.
|
|
//
|
|
// Page slugs are unchanged, so the wildcard covers every child page —
|
|
// and, because the `.md` text alternates are a path segment, their
|
|
// links too (`/v5/docs/how-it-works/encryption.md` → `.../advanced/
|
|
// encryption.md`). The section root gets its own two entries.
|
|
{
|
|
source: '/v5/docs/how-it-works',
|
|
destination: '/v5/docs/advanced',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/how-it-works.md',
|
|
destination: '/v5/docs/advanced.md',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/how-it-works/:path*',
|
|
destination: '/v5/docs/advanced/:path*',
|
|
permanent: true,
|
|
},
|
|
// setAttributes graduated from experimental_setAttributes; the API
|
|
// reference page moved with it.
|
|
{
|
|
source: '/v5/docs/api-reference/workflow/experimental-set-attributes',
|
|
destination: '/v5/docs/api-reference/workflow/set-attributes',
|
|
permanent: true,
|
|
},
|
|
// setAttributes is v5-only, so the unversioned path has no page yet.
|
|
// Land on the section index directly (no redirect chain through the
|
|
// /docs/api-reference/workflow/set-attributes fallback below). Point
|
|
// this at /docs/api-reference/workflow/set-attributes once v5 becomes
|
|
// the default version.
|
|
{
|
|
source: '/docs/api-reference/workflow/experimental-set-attributes',
|
|
destination: '/docs/api-reference/workflow',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/python',
|
|
destination: '/docs/getting-started/python',
|
|
permanent: true,
|
|
},
|
|
// API reference restructure: getWorld and the World SDK moved from the
|
|
// workflow-api section to workflow-runtime, and the observability
|
|
// utilities page became its own workflow-observability section —
|
|
// matching the `workflow/runtime` and `workflow/observability` import
|
|
// paths these APIs are actually exported from. The observability rules
|
|
// must come before the world/:path* catch-alls (first match wins).
|
|
{
|
|
source: '/docs/api-reference/workflow-api/world/observability',
|
|
destination: '/docs/api-reference/workflow-observability',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/api-reference/workflow-api/world/observability',
|
|
destination: '/v5/docs/api-reference/workflow-observability',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/api-reference/workflow-api/get-world',
|
|
destination: '/docs/api-reference/workflow-runtime/get-world',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/api-reference/workflow-api/get-world',
|
|
destination: '/v5/docs/api-reference/workflow-runtime/get-world',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/api-reference/workflow-api/world',
|
|
destination: '/docs/api-reference/workflow-runtime/world',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/api-reference/workflow-api/world',
|
|
destination: '/v5/docs/api-reference/workflow-runtime/world',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/docs/api-reference/workflow-api/world/:path*',
|
|
destination: '/docs/api-reference/workflow-runtime/world/:path*',
|
|
permanent: true,
|
|
},
|
|
{
|
|
source: '/v5/docs/api-reference/workflow-api/world/:path*',
|
|
destination: '/v5/docs/api-reference/workflow-runtime/world/:path*',
|
|
permanent: true,
|
|
},
|
|
// --- Version-switcher fallbacks ---
|
|
// The version switcher swaps the /v5 route prefix without checking
|
|
// that the page exists in the target version, so pages that exist in
|
|
// only one docs tree 404 on switch. Each rule below covers a page
|
|
// missing from one version and lands on the nearest equivalent
|
|
// (usually the section index). All are temporary redirects: they must
|
|
// be revisited when content is backported or when v5 becomes the
|
|
// default version (which swaps the trees served at /docs).
|
|
//
|
|
// Pages that exist only in v5 (v5 -> v4 switch):
|
|
{
|
|
source: '/docs/api-reference/workflow/set-attributes',
|
|
destination: '/docs/api-reference/workflow',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/api-reference/workflow-errors/precondition-failed-error',
|
|
destination: '/docs/api-reference/workflow-errors',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/api-reference/workflow-runtime/world/analytics',
|
|
destination: '/docs/api-reference/workflow-runtime/world',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source:
|
|
'/docs/changelog/(attributes-mvp|eager-processing|step-message-ownership)',
|
|
destination: '/docs/changelog',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/configuration',
|
|
destination: '/docs/deploying',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/configuration/:path*',
|
|
destination: '/docs/deploying',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/errors/abort-signal-timeout-in-workflow',
|
|
destination: '/docs/errors',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/foundations/cancellation',
|
|
destination: '/docs/foundations',
|
|
permanent: false,
|
|
},
|
|
// v4 has no how-it-works index page; foundations is the closest
|
|
// conceptual landing for the v5 cancellation internals page.
|
|
{
|
|
source: '/docs/how-it-works/cancellation',
|
|
destination: '/docs/foundations',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/getting-started/react-router',
|
|
destination: '/docs/getting-started',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/getting-started/react-router/:path*',
|
|
destination: '/docs/getting-started',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source:
|
|
'/docs/internal/(nitro-native-build|nitro-web-ui|serializable-abort-controller)',
|
|
destination: '/docs/internal',
|
|
permanent: false,
|
|
},
|
|
{
|
|
source: '/docs/observability/(attributes|tracing)',
|
|
destination: '/docs/observability',
|
|
permanent: false,
|
|
},
|
|
// Pages that exist only in v4 (v4 -> v5 switch):
|
|
{
|
|
source: '/v5/docs/api-reference/workflow-runtime/step-entrypoint',
|
|
destination: '/v5/docs/api-reference/workflow-runtime',
|
|
permanent: false,
|
|
},
|
|
// /v5/cookbook/advanced has no index page; fall back to the root.
|
|
{
|
|
source: '/v5/cookbook/advanced/distributed-abort-controller',
|
|
destination: '/v5/cookbook',
|
|
permanent: false,
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default withMDX(config);
|