feat(core,chat): stream partial assistant-text deltas on the SDK runtime - #383
Merged
Conversation
Adds true token-by-token streaming of assistant text through the stack, gated by an opt-in flag so batch/one-shot and existing session callers are unchanged. - core: `includePartialMessages` on ChatSessionOptions / RuntimeExecuteOptions / SDKQueryOptions, threaded from openChatSession into the SDK query(). Default off. - chat: SDKMessageTranslator handles `stream_event` `text_delta` events as ordered incremental onText(delta) calls, and suppresses the terminal whole assistant text re-emit when it already streamed as deltas. Boundary + tool semantics preserved; partials-off path byte-for-byte identical. Fixes #382 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughAdds opt-in partial assistant text streaming from chat sessions through the SDK runtime, translates ChangesPartial assistant text streaming
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying herdctl with
|
| Latest commit: |
1098aac
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://44d2a206.herdctl.pages.dev |
| Branch Preview URL: | https://feat-stream-partial-assistan.herdctl.pages.dev |
Merged
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
Fixes #382 — the SDK runtime and the
@herdctl/chattranslator surface assistant text only as wholeassistantmessages, so consumers (e.g. Paddock's chat UI) render each reply in one drop rather than streaming token-by-token. This adds true streaming of partial assistant text through the stack, behind an opt-in flag.Two independent gaps, both fixed:
1. SDK runtime never requested partials (
@herdctl/core)includePartialMessagesonChatSessionOptions→RuntimeExecuteOptions→SDKQueryOptions, threaded fromopenChatSessioninto the SDKquery()inSDKRuntime.buildSdkOptions().execute) and existing session callers that don't opt in are byte-for-byte unchanged — the SDK still yields wholeassistantmessages only.2. Translator dropped stream events (
@herdctl/chat)SDKMessageTranslator.handle()now routestype: "stream_event"messages to a newhandleStreamEvent(), which emits incrementalonText(delta)forcontent_block_delta/text_deltaevents (other events — message start/stop, tool input-json deltas, thinking deltas — are ignored).assistantmessage suppresses its text re-emit when that text already streamed as deltas (tracked per-message), so theonTextcontract stays "deltas, in order" and consumers never receive the text twice. Tool tracking (onToolStart/onToolCall) still runs on the terminal message.stream_eventmessages arrive, so state never engages).Verified against the installed
@anthropic-ai/claude-agent-sdk@0.3.205types:SDKPartialAssistantMessage = { type: "stream_event", event: BetaRawMessageStreamEvent, parent_tool_use_id, … }, where aBetaRawContentBlockDeltaEvent(type: "content_block_delta") carries aBetaTextDelta({ type: "text_delta", text }).Tests
sdk-runtime-partials.test.ts):query()receivesincludePartialMessages: truewhen opted in viaexecute()/openSession(), and it's unset by default.sdk-message-translator.test.ts):text_deltaevents produce ordered incrementalonText; the terminal assistant message does not re-emit already-streamed text; tool tracking still fires on the terminal message; non-text stream events are ignored; boundary parity across streamed turns and after tool results; attribution threading.All core (3352 pass; the lone
directory.test.ts"unwritable dir" failure is the known pre-existing root-only one) and chat (289 pass) suites green; typecheck + build clean.Consumer
Paddock consumes this to stream keeper replies token-by-token (companion ticket edspencer/paddock#315).
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes