fix: preserve whitespace-only chunks in SSE stream (#139)

* fix: preserve whitespace-only chunks in SSE stream

Fixes issue #138 where Claude models would swallow spaces between words because whitespace-only chunks (e.g., " ") were being filtered out as empty.

Changes:
- Modified sse-streamer.js to only skip truly empty strings (""), preserving strings that contain only whitespace.
- Added regression test case in tests/test-streaming-whitespace.cjs to verify whitespace preservation.

* test: add streaming whitespace regression test to main suite

---------

Co-authored-by: walczak <walczak@ial.ruhr>
This commit is contained in:
Marvin
2026-01-17 07:46:28 +01:00
committed by GitHub
parent f86a0f07c9
commit 480b4a0bc1
3 changed files with 123 additions and 3 deletions

View File

@@ -123,8 +123,8 @@ export async function* streamSSEResponse(response, originalModel) {
};
} else if (part.text !== undefined) {
// Skip empty text parts
if (!part.text || part.text.trim().length === 0) {
// Skip empty text parts (but preserve whitespace-only chunks for proper spacing)
if (part.text === '') {
continue;
}