fix(streams): use empty separator in finalText() for text block concatenation#954
Open
netbrah wants to merge 1 commit intoanthropics:mainfrom
Open
fix(streams): use empty separator in finalText() for text block concatenation#954netbrah wants to merge 1 commit intoanthropics:mainfrom
netbrah wants to merge 1 commit intoanthropics:mainfrom
Conversation
…tenation
Both MessageStream and BetaMessageStream used `join(' ')` to combine
multiple text blocks in `#getFinalText()`, inserting an unexpected space
between adjacent text blocks. This caused double spaces when the model
returned text blocks with trailing/leading spaces (e.g. "Hello " + " world"
became "Hello world").
Changed to `join('')` which matches:
- The JSDoc: "concatenated together if there are more than one text blocks"
- The Python SDK behavior: `"".join(text_blocks)`
Added a test verifying multi-text-block concatenation produces the
expected result without extra spaces.
Made-with: Cursor
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.
Problem
MessageStream#finalText()andBetaMessageStream#finalText()usejoin(' ')to combine multiple text blocks, inserting an unexpected space character between adjacent blocks. This causes double spaces when the model returns text blocks with trailing/leading whitespace (e.g."Hello " + " world"becomes"Hello world").Fix
Changed to
join('')in bothMessageStreamandBetaMessageStream, which matches the JSDoc ("concatenated together if there are more than one text blocks") and the Python SDK ("".join(text_blocks)).Added a test that streams two text blocks and verifies
finalText()concatenates them without inserting extra whitespace.