Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/genui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 4 additions & 1 deletion packages/genui/lib/src/transport/a2ui_transport_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> get incomingText => _pipeline
.where((e) => e is TextEvent)
.cast<TextEvent>()
.map((e) => e.text.trim())
.map((e) => e.text)
.where((text) => text.isNotEmpty);

/// A stream of A2UI messages parsed from the input.
Expand Down
2 changes: 1 addition & 1 deletion packages/genui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/genui/test/transport/a2ui_transport_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ void main() {
await textFuture;
});

test('incomingText preserves chunk whitespace', () async {
final Future<dynamic> 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
Expand Down
Loading