feat(workflow): export WorkflowChatTransport with stream reconnection support#14340
Merged
gr2m merged 4 commits intogr2m/durable-agentfrom Apr 11, 2026
Merged
feat(workflow): export WorkflowChatTransport with stream reconnection support#14340gr2m merged 4 commits intogr2m/durable-agentfrom
gr2m merged 4 commits intogr2m/durable-agentfrom
Conversation
…upport Export WorkflowChatTransport as a public API from @ai-sdk/workflow. Add initialStartIndex option for resuming streams from the tail (negative values), with x-workflow-stream-tail-index header resolution and graceful fallback. Extract getErrorMessage utility for proper error formatting in reconnection failures. Update next-workflow example to use the transport. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When a positive startIndex is used, set chunkIndex to match so that retries after disconnection resume from the correct position instead of restarting from 0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add /test page and mock /api/test-chat endpoints that simulate stream interruption. The POST route sends a partial stream (no finish event), forcing the transport to reconnect via the GET stream endpoint. The transport log panel shows the full lifecycle: POST -> streaming -> reconnect -> Chat ended. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add API reference page for WorkflowChatTransport with constructor parameters, methods, reconnection flow, server requirements, and usage examples - Add WorkflowChatTransport card to workflow reference index - Add "Resumable Streaming" section to WorkflowAgent guide with client and server endpoint examples - Add "Workflow Transport" section to the transport guide page - Add link to WorkflowChatTransport reference in Next Steps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Background
The
WorkflowChatTransportclass was implemented in@ai-sdk/workflowbut not exported, making it unavailable to consumers. This transport is needed foruseChatto enable automatic stream reconnection in workflow-based chat apps — handling network failures, page refreshes, and function timeouts by reconnecting to the workflow's stream endpoint.Reference: DurableChatTransport
Summary
WorkflowChatTransportclass and related types (WorkflowChatTransportOptions,SendMessagesOptions,ReconnectToStreamOptions) from@ai-sdk/workflowinitialStartIndexoption for resuming streams from the tail (negative values like-50fetch only the last 50 chunks, useful for page refresh recovery without replaying the full conversation)x-workflow-stream-tail-indexheader resolution to compute absolute chunk positions from negative start indices, with graceful fallback to replay-from-start when the header is missingstartIndexreconnection: setchunkIndexto match the explicit start position so retries after disconnection resume correctlystartIndexper-call override onReconnectToStreamOptionsgetErrorMessageutility for proper error formatting in reconnection failures (avoids[object Object]in error messages)examples/next-workflowmain page to useWorkflowChatTransportwithuseChatexamples/next-workflow/testpage with mock API routes that simulate stream interruption and verify reconnection recovery end-to-endDocumentation
WorkflowChatTransportreference page atdocs/reference/ai-sdk-workflow/workflow-chat-transportwith constructor parameters, methods, reconnection flow, server requirements, and examplesWorkflowChatTransportcardManual Verification
examples/next-workflowdev server (pnpm next dev)/): Sent "What is the weather in San Francisco?" — WorkflowAgent calledgetWeathertool, responded with "86°F and windy". Sent "What is 42 * 17?" — calledcalculatetool, responded "714". Both messages usedWorkflowChatTransport./test): The test page uses mock API routes where the POST endpoint sends only 2 of 6 SSE chunks (nofinishevent), simulating a function timeout. The transport detected the missingfinishchunk, automatically reconnected via GET to/api/test-chat/{runId}/stream?startIndex=2, received the remaining chunks, and displayed the complete message. The transport log panel confirmed the full lifecycle:POST response received(onChatSendMessagecallback fired)Status: streaming(partial stream consumed)Chat ended: total chunks=6(onChatEndcallback fired)Status: readyChecklist
pnpm changesetin the project root)Related Issues
Follow-up to #12165