docs(cookbook): rewrite core recipes, dedupe, and reorder sidebar#1850
Merged
Conversation
- publishing-libraries.mdx: the second processPayment snippet uses
getWorkflowRunId() defined in the prior block. Each block is type-checked
independently, so add @skip-typecheck (matches the existing pattern in
this file).
- ai-sdk.mdx: the "snapshot tailIndex first" pitfall is a fragment
referencing probe / turnHook / run / text from the surrounding multi-turn
pattern. Add @skip-typecheck.
- chat-sdk.mdx: the [platform] webhook route used Next.js 15 typegen
(RouteContext<"/api/webhooks/[platform]">), which isn't part of the
docs-typecheck environment. Switch to the manually-typed
{ params }: { params: Promise<{ platform: string }> } form — still fully
supported by Next.js 15+ and doesn't depend on .next/types.
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass over the cookbook focused on correctness, concrete examples, and tighter information architecture.
Rewrites
When to use/How it works/Adapting to your use casesections and drops abstract/variation noise.prepareStepflag-checking andstate === "call"tricks never fire). Replaced withPromise.race(stream, hook)+ explicitemit*steps that write custom data parts (data-approval-needed,data-approval-resolved,data-stopped) to the durable stream.agent-patterns/agent-cancellation.mdx, formerlystop-workflow.mdx) — renamed from "Stop Workflow" → "Agent Stop Signal" → "Agent Cancellation" and broadened to cover two named patterns as equal-weight peers: Hard Cancellation viagetRun(runId).cancel()for forced termination, and Stop Signal via a hook +Promise.racefor a graceful exit with cleanup and final stream notification (data-stoppedpart). The page opens with a## Choosing an approachcomparison hub (bullets + 7-row trade-off table covering mechanism, speed, cleanup behavior, stream notification, return-value semantics, code complexity, and recommended use case) before the per-pattern deep dives. A<Callout type="warn">scoped to the Stop Signal section documents that the underlying model stream isn't cancelled — tokens generated after the signal still bill — and cross-links to Distributed Abort Controller for hard cross-process cancellation. Removed the misleading "Cost control" use case from "When to use this".integrations/ai-sdk.mdx) — refocused from aDurableAgentshowcase to lower-levelstreamText(); main example is a multi-turn session pattern (one workflow run per conversation, hook created once, durable stream sliced per turn via manual pumping). Added deep links to ai-sdk.dev for each primitive and a dedicated Pitfalls section (snapshottailIndexbefore resuming the hook; don't callwritable.close()in a workflow function; release — don't cancel — the source reader).integrations/sandbox.mdx) — rewrote around the real@vercel/sandboxSDK surface (previous page had multiple API errors:template→runtime,sandbox.id→sandbox.sandboxId,destroy()doesn't exist). Flagship pattern is now one workflow run = one persistent sandbox session that outlives the 5-hour hard cap via proactive snapshot + recreate. Links out to Open Agents as the canonical adopter.integrations/chat-sdk.mdx) — full rewrite. Previous page was titled "Chat SDK" but documented AI SDK'suseChatprimitive and was effectively a duplicate of the AI SDK page. New page targets chat-sdk.dev (unified Slack / Teams / Discord / Telegram / GitHub / Linear / WhatsApp / Google Chat bot SDK) and shows how Workflow makes its sessions durable via one-workflow-run-per-thread + hook-driven inbound message routing. Uses a Mermaidflowchart TD(ASCII diagrams alias visibly at the site's rendered line-height).advanced/publishing-libraries.mdx) — swapped the ASCII file tree for Fumadocs<Files>/<Folder>/<File>components (font-independent SVG). Corrected the isomorphic-packages callout:"use workflow"/"use step"directives are safe in library source — they're string expression statements and no-op when the SWC plugin doesn't process them. Added Mux AI and World ID adopter examples with canonical blog links.New cookbook recipes (foundations → cookbook migration)
The
foundations/common-patterns.mdxpage mixed three independent topics (timeouts, sequential/parallel execution, workflow composition) and lived in the foundations section despite being recipe-shaped content. Split into three dedicated cookbook pages undercommon-patterns/, each with the standard cookbook frame (When to use this/How it works/Adapting to your use case/Key APIs):common-patterns/timeouts.mdx— soft timeouts viaPromise.race(operation, sleep(deadline))with discriminated result tagging. Examples for slow steps and webhook deadlines.<Callout type="warn">documenting thatPromise.racedoesn't cancel the losing branch (matters for side-effecting or expensive operations) — same caveat as the Agent Cancellation page, cross-linked to Distributed Abort Controller for hard cross-process cancellation.common-patterns/sequential-and-parallel.mdx— sequential pipelines,Promise.all/Promise.allSettledfor parallel fan-out, andPromise.racefor first-wins between webhooks and timers. Includes the full Birthday Card Generator demo as the integrated example.common-patterns/workflow-composition.mdx— composing workflows from other workflows. Covers both direct await (the parent flattens the child's events into its own log) and background execution viastart()(the child runs as an independent run with its ownrunId). Comparison table contrasting the two and adeploymentId: "latest"note for cross-deployment composition.The original
foundations/common-patterns.mdxis deleted; a permanent redirect from/docs/foundations/common-patterns→/cookbooklands callers on the cookbook overview where the three split pages are linked.Deletions (redundant or flawed)
foundations/streamingandai/defining-toolsin the main docs.hook.create()inside awhile(true)throwsHookConflictError; counter example's read path doesn't return a value to the caller). Framing ("workflow run = entity with methods") doesn't hold up —start()mints its ownrunIdso you still need an external entity → runId map.foundations/serialization. The one unique detail (class registry symbol name) was folded into the foundations page.publishing-libraries.mdx; overlap was already large (peer-dep snippet + runtime-detection snippet) and both targeted npm library authors.foundations/common-patterns.mdx— replaced by the three dedicated cookbook recipes above.Sidebar restructure
Overview → Agent Patterns → Common Patterns → Integrations → Advanced(wasOverview → Common → Agent → Integrations → Advanced). Agent Patterns leads since it drives most new-visitor traffic.Child WorkflowsandDistributed Abort Controllerfromcommon-patterns/toadvanced/— they're composition / cancellation concerns, not common reliability recipes.Common Patternsfrom the foundations sidebar after the migration above;foundations/index.mdxandfoundations/starting-workflows.mdxupdated to point at the cookbook for follow-ups instead of the deleted foundations page.git mvso rename history survivesgit log --follow.Redirects
Permanent redirects added in
next.config.tsso no inbound links 404 — covers search indexes, bookmarks, and external references in theworkflow-initskill and CI smoke tests:/cookbook/agent-patterns/stop-workflow→/cookbook/agent-patterns/agent-cancellation/cookbook/agent-patterns/agent-stop-signal→/cookbook/agent-patterns/agent-cancellation/cookbook/common-patterns/child-workflows→/cookbook/advanced/child-workflows/cookbook/common-patterns/distributed-abort-controller→/cookbook/advanced/distributed-abort-controller/docs/foundations/common-patterns→/cookbook/docs/foundations/control-flow-patterns→/cookbook(existing redirect updated to point at the cookbook overview)Both prior URLs for the renamed agent cancellation page redirect directly to the current location — no chain hops.
Made with Cursor