Skip to content

fix: join text blocks with empty string in finalText#950

Open
frankgoldfish wants to merge 1 commit intoanthropics:mainfrom
frankgoldfish:fix/message-stream-join-separator
Open

fix: join text blocks with empty string in finalText#950
frankgoldfish wants to merge 1 commit intoanthropics:mainfrom
frankgoldfish:fix/message-stream-join-separator

Conversation

@frankgoldfish
Copy link
Copy Markdown

Summary

  • Fixes #getFinalText() in src/lib/MessageStream.ts to join multiple text blocks with an empty string instead of a space

Bug

#getFinalText() was calling textBlocks.join(' '), which inserts an unexpected space character between text content blocks:

// Before (buggy)
return textBlocks.join(' ');   // "Hello world" with an extra space

When a response contains two adjacent text blocks ("Hello" and " world"), the result would be "Hello world" (double space) instead of "Hello world".

Fix

// After (correct)
return textBlocks.join('');

This matches the Python SDK which uses "".join(text_blocks) (empty separator), and the docstring which says the blocks are concatenated (not space-joined).

Test plan

  • Existing base64/MessageStream tests still pass
  • Consistent with Python SDK behaviour ("".join(text_blocks))
  • Matches the JSDoc description: "concatenated together if there are more than one text blocks"

🤖 Generated with Claude Code

textBlocks.join(' ') was inserting an unexpected space character between
multiple text content blocks. This is inconsistent with the Python SDK which
uses ''.join(text_blocks). When the API returns multiple text blocks they
should be concatenated without any separator.
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