Skip to content
Email SDK
Esc
↑↓navigate↵open⌘Jpreview

View email workflows (experimental)

See every step, delay, event branch, and email of a workflow in an interactive viewer, or print the same graph for an agent with inspectWorkflow and the CLI.

A workflow is plain TypeScript, so its shape lives in the code: which emails go out, how long it sleeps, where it waits for an event, and what happens when the event never comes. inspectWorkflow turns that code into a graph without sending anything, and describeRun turns a stored run into a timeline. The viewer below draws both for the onboarding drip from Email workflows.

onboardingv12 paths · 4 emailsCancels on unsubscribed

Steps

triggerDay 0
welcomeDay 0
before-tipDay 0
pick-tip+2d
tip+2d
activated+2d
activated-mail+2d
end+2d
nudge+5d
end+5d
receivedtimeout · 3d
100%

Details

Send email

Welcome, Ada

Step
welcome
Starts
At signup
From
Acme <hello@acme.com>
To
ada@example.com
Subject
Welcome, Ada

Preview

Definition shows every path the workflow can take. Select a node on the canvas or in the steps list to see its details: the rendered email for a send, the duration for a sleep, the timeout for an event wait. Sample run replays a real engine run of the same workflow on a fake clock: Ada signs up, gets the tip on day 2, and activates on day 3. Each keyframe is the stored run at that moment, as describeRun reports it.

Inspect a workflow in code

inspectWorkflow parses input with the workflow’s input schema, then calls run with a tracing ctx:

Call What the inspector does
ctx.send Records the step name and the rendered email: from, to, cc, bcc, reply-to, subject, text, and HTML. Sends nothing.
ctx.sleep, ctx.sleepUntil Records the delay and moves the path’s clock forward. sleepUntil measures from startedAt, which defaults to 0.
ctx.waitForEvent With a timeout, forks the path: received resolves with the sample payload from events, keyed by event name, and timeout resolves as timed out. Without one, only received exists.
ctx.step Returns the mock from steps, keyed by step name, without calling the callback. Steps without a mock return undefined and show as unknown.

The callback of ctx.step never runs, so a step can’t send, wait, or touch your database during inspection. Code between ctx calls does run, so keep it free of side effects, as replay already requires.

Exploration is deterministic and capped. maxPaths (default 32) limits how many paths are explored, and each timed wait can double the count. maxDepth (default 100) cuts a path off after that many ctx calls, rejected ones included, which stops an unbounded loop. When a cap is hit, truncated is true and a cut-off path ends in a truncated node. A path whose code throws ends in a failed node with the error. The inspector applies the engine’s own rules, so a path also fails where the engine would fail the run even though your code catches the error, such as an invalid duration or retry policy, a reused step name, or a ctx call while a step is running, and a workflow output that isn’t JSON fails the path too. An events sample that isn’t JSON is rejected up front, as sendEvent would reject it. A failure on a received branch notes any event that had no sample payload, the usual cause.

The graph is plain JSON: { workflow, version, cancelOn, nodes, edges, paths, truncated, limits }. Node ids are step names, prefixed with the branch choices that lead to them, so activated:timeout/nudge is the nudge on the timeout branch. Step names in ids are URI-encoded, and the trigger and end nodes use $trigger and $end, which no encoded step name can match. toMermaid(graph) renders a flowchart and formatWorkflowGraph(graph) a plain-text outline.

Inspect from the terminal

Agents without a browser get the same graph from the CLI. It imports the module and prints JSON, Mermaid, or text:

--input, --events, and --steps take inline JSON or @path to a file. See email-sdk workflows inspect for every option.

Mermaid

This is the onboarding graph above, from toMermaid:

Describe a stored run

describeRun(run) reads a WorkflowRun from any store and lists each journaled step in the order it ran, with its kind, status, completion time, and a short result summary. A blocked run ends with the step it waits on, and wait carries the deadline. Failed runs carry error, and canceled runs carry cancelReason.

On day 2 of the sample run, the onboarding run looks like this:

Read this page as an agent

Every docs page has a markdown twin. /docs/guides/view-email-workflows.md carries the Mermaid above and the full JSON graph below, so an agent reading the docs sees the whole workflow without running anything.

Full inspectWorkflow JSON for the onboarding drip