fix: filter empty messages without altering text#975
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the incomingText stream in A2uiTransportAdapter to map the raw text without trimming, but filters out strings that are empty after trimming. The reviewer correctly points out that using text.trim().isNotEmpty will discard chunks consisting entirely of whitespace (such as spaces or newlines), which are common in streaming LLM responses and necessary to prevent words from running together. The reviewer suggests using text.isNotEmpty instead to preserve these whitespaces.
| .map((e) => e.text) | ||
| .where((text) => text.trim().isNotEmpty); |
There was a problem hiding this comment.
Using text.trim().isNotEmpty will discard chunks that consist entirely of whitespace, such as a single space (" ") or a newline ("\n"). In streaming LLM responses, it is extremely common for whitespace or newlines to be emitted as separate chunks. Discarding them will cause words to run together (e.g., producing "Helloworld" instead of "Hello world").
To preserve all valid whitespaces while filtering out truly empty strings, you should use text.isNotEmpty instead of text.trim().isNotEmpty.
| .map((e) => e.text) | |
| .where((text) => text.trim().isNotEmpty); | |
| .map((e) => e.text) | |
| .where((text) => text.isNotEmpty); |
Description
Modify
A2uiTransportAdapterto preserve whitespaces in AI text responses while still discarding empty text parts.Trimming all messages causes inconsistent concatenation issues.
Fixes #906
BEFORE:

AFTER:

Pre-launch Checklist
///).