AI SDK Internals
Vercel AI SDK internals as they matter for building production agents — three-layer API, lifecycle ordering, message reference model, prepareStep semantics. Based on ai@^6.
AI SDK Internals
Why Vercel AI SDK internals deserve their own chapter — three-layer API, version pinning, reading order
Runtime Lifecycle
The full timeline of a single agent.stream() call — 12 callback firing points across three layers, two-layer same-named callback comparison, stopWhen / timeout default chains
UI Stream Orchestration
L3 UI-stream — the two paths contrasted / createUIMessageStream's execute-driven mode / three writer methods / custom data-* event protocol / transient semantics / error capture tiering
Message Reference Model
The four message chains and their reference relationships — why mutate is permanent pollution, push is truly ephemeral, and replacing arrays hinges on element identity
prepareStep Semantics
Full signature of the per-step hook, 7 overridable fields, 4 typical patterns, and a deep analysis of the mutate-vs-push trap
Client Consumption (useChat)
The full useChat capability matrix / choosing among the four transports / UIMessage vs ModelMessage bridging / what the four statuses actually mean / callback contracts / client-side tool execution / the two-sided resume protocol / 10 common traps
End-to-End Coordination
The full round-trip of one sendMessage from click to DOM update / the full reference of 25 UIMessageChunk types / the four hops of bidirectional abort / the end-to-end resume implementation pattern / four error path classes / SSE environment-layer traps