-
Notifications
You must be signed in to change notification settings - Fork 19
feat: enable real-time streaming of generator tool preliminary results #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+571
−43
Conversation
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
louisgv
reviewed
Dec 26, 2025
This change enables generator tool yields to be streamed to consumers AS they happen during execution, instead of being batched after completion. Changes: - Add ToolEventBroadcaster for push-based multi-consumer event streaming - Wire onPreliminaryResult callback in executeToolRound to broadcast events - Update getToolStream() and getFullResponsesStream() to consume broadcast - Fix Zod v4 toJSONSchema target to 'draft-7' (openapi-3.0 was invalid) - Add comprehensive unit tests for ToolEventBroadcaster - Fix test files to use draft-7 target
- Add buffer cleanup after all consumers complete (memory leak fix) - Use lazy initialization for broadcaster (race condition fix) - Add try-catch in onPreliminaryResult callback (error handling) - Add tests for completion between consumer iterations
e15dc75 to
de38fe8
Compare
…push Addresses review feedback from louisgv. The push() method doesn't throw, so the try-catch was unnecessary. Using optional chaining (?.) instead of non-null assertion (!) is safer and more idiomatic TypeScript.
de38fe8 to
7236091
Compare
louisgv
reviewed
Jan 6, 2026
louisgv
reviewed
Jan 6, 2026
louisgv
previously approved these changes
Jan 6, 2026
Contributor
louisgv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise lgtm!
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 enables real-time streaming of generator tool preliminary results - yields are streamed AS they happen during execution, instead of being batched after tool execution completes.
Key changes:
ReusableReadableStreampatterngetToolStream()andgetFullResponsesStream()now yield preliminary results as generator tools emit themtoJSONSchematarget from invalid'openapi-3.0'to'draft-7'(Zod v4 compatibility)How it works
yieldis immediately pushed toToolEventBroadcastercreateConsumer()receive events in real-time as they're pushedExample Usage
Define a generator tool with progress events
Consume real-time events with
getToolStream()Consume with
getFullResponsesStream()Files changed
src/lib/tool-event-broadcaster.tssrc/lib/model-result.tssrc/lib/tool-executor.tssrc/index.tstests/unit/tool-event-broadcaster.test.tstests/e2e/call-model-tools.test.tsTest plan