Skip to content

fix(streams): use empty separator in finalText() for text block concatenation#954

Open
netbrah wants to merge 1 commit intoanthropics:mainfrom
netbrah:fix/finaltext-join-separator
Open

fix(streams): use empty separator in finalText() for text block concatenation#954
netbrah wants to merge 1 commit intoanthropics:mainfrom
netbrah:fix/finaltext-join-separator

Conversation

@netbrah
Copy link
Copy Markdown

@netbrah netbrah commented Mar 19, 2026

Problem

MessageStream#finalText() and BetaMessageStream#finalText() use join(' ') 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 both MessageStream and BetaMessageStream, 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.

…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
@netbrah netbrah requested a review from a team as a code owner March 19, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant