feat: add full message-level streaming + structured outputs#37
Merged
Conversation
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
79bf87d to
345b1a0
Compare
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
factory-ain3sh
left a comment
There was a problem hiding this comment.
Posted 3 review comments covering the stream overload contract, the no-op includePartialMessages option on run(), and missing coverage for default-vs-partial stream filtering.
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
factory-ain3sh
approved these changes
May 13, 2026
factory-ain3sh
left a comment
There was a problem hiding this comment.
Prior comments are addressed. I reviewed the latest changes and am good with this now.
Note: I could not run local validators in this worktree because dependency repair could not mirror main repo node_modules, but the code-review concerns are resolved.
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.
Summary
This PR makes streaming easier to consume by default and keeps chunk-level streaming available when callers opt in.
session.stream()now yields message-level events (assistant,user,tool_call,tool_result,error,result) unlessincludePartialMessages: trueis set, and each turn finishes with a finalresultevent instead of the oldturn_completesentinel.Structured output is now part of that final result for both
run(...)and streaming. The SDK accepts backendstructured_outputnotifications, falls back to parsing assistant JSON when needed, carries structured output validation errors throughstructuredOutputError, and exports the new public result/message types.API behavior
run(...)turn_completeDroidMessageType.Resultemitted by the streamsession.stream()defaultAssistantTextDelta,ToolUse,TurnCompleteAssistant,ToolCall,ToolResult,ResultincludePartialMessages: trueDroidMessageType.TurnCompleteDroidMessageType.Resultstructured_output, falls back to JSON parsing, includes validation errorsUsage
One-shot
run(...)Before, callers received a locally aggregated result after streaming completed:
After,
run(...)returns the same finalResultobject that streaming emits:Structured output and validation failures are available directly on the result:
Default message-level streaming
Before, the default stream was chunk-oriented:
After, the default stream is message-oriented:
Opt into chunk-level streaming
Use
includePartialMessages: truewhen you need deltas, completion markers, tool-call chunks, or progress updates:The stream still ends with
DroidMessageType.Result, so final metadata is handled the same way:Structured output while streaming
Structured output is attached to the final result event, not emitted as a separate public stream event:
Implementation notes
create_messagenotifications into user, assistant, and tool-call messages for the default stream.StreamStateTracker, then emits a finalResulton the non-idle to idle transition.DroidMessageType.Resultand the structured-output result fields.Validation
npm run typechecknpm run lintnpm testnpm run format:check