diff --git a/packages/genui/CHANGELOG.md b/packages/genui/CHANGELOG.md index 591849fe0..c45e8e9f3 100644 --- a/packages/genui/CHANGELOG.md +++ b/packages/genui/CHANGELOG.md @@ -1,5 +1,10 @@ # `genui` Changelog +## 0.10.2 + +- Fixed `A2uiTransportAdapter.incomingText` trimming every streamed chunk, which + made words run together when chunks were concatenated. + ## 0.10.1 - Depend on `a2ui_core` 0.1.0, its first non-pre-release version. diff --git a/packages/genui/lib/src/transport/a2ui_transport_adapter.dart b/packages/genui/lib/src/transport/a2ui_transport_adapter.dart index 7eacaa883..ddc0f8bef 100644 --- a/packages/genui/lib/src/transport/a2ui_transport_adapter.dart +++ b/packages/genui/lib/src/transport/a2ui_transport_adapter.dart @@ -61,11 +61,14 @@ class A2uiTransportAdapter implements Transport { } /// A stream of sanitizer text for the chat UI. + /// + /// Chunk whitespace is preserved as emitted, so consumers can concatenate + /// chunks without words smashing together across chunk boundaries. @override Stream get incomingText => _pipeline .where((e) => e is TextEvent) .cast() - .map((e) => e.text.trim()) + .map((e) => e.text) .where((text) => text.isNotEmpty); /// A stream of A2UI messages parsed from the input. diff --git a/packages/genui/pubspec.yaml b/packages/genui/pubspec.yaml index 0cc248f82..60aa77285 100644 --- a/packages/genui/pubspec.yaml +++ b/packages/genui/pubspec.yaml @@ -4,7 +4,7 @@ name: genui description: Generates and displays generative user interfaces (GenUI) in Flutter using AI. -version: 0.10.1 +version: 0.10.2 homepage: https://github.com/flutter/genui/tree/main/packages/genui license: BSD-3-Clause issue_tracker: https://github.com/flutter/genui/issues diff --git a/packages/genui/test/transport/a2ui_transport_adapter_test.dart b/packages/genui/test/transport/a2ui_transport_adapter_test.dart index 3c6b92f08..012a60060 100644 --- a/packages/genui/test/transport/a2ui_transport_adapter_test.dart +++ b/packages/genui/test/transport/a2ui_transport_adapter_test.dart @@ -29,6 +29,16 @@ void main() { await textFuture; }); + test('incomingText preserves chunk whitespace', () async { + final Future textFuture = expectLater( + transportAdapter.incomingText, + emitsInOrder(['a variety of friendly ', 'spots']), + ); + transportAdapter.addChunk('a variety of friendly '); + transportAdapter.addChunk('spots'); + await textFuture; + }); + test('addChunk with message updates state', () async { // Using JSON block final json = '''```json