feat(app): register the live Chat destination with read-only history

This commit is contained in:
2026-10-21 22:57:08 +01:00
parent 76fb2cdd87
commit 86a9b4a664
19 changed files with 2365 additions and 48 deletions
@@ -34,25 +34,36 @@ JsonMap mergeChatHistory(JsonMap previous, JsonMap page, {bool older = false}) {
/// Consecutive assistant messages form one answer turn. All part fields (also
/// future/unknown protocol types) are preserved in original order.
///
/// `key` is the turn's first assistant message id, which is only a display
/// anchor: paging an older assistant message into the turn changes it, so widget
/// identity uses `messageIds`. That list carries every message the folded turn
/// currently holds so the view can keep the same row element while the turn
/// grows at either end.
List<JsonMap> transcriptRows(List<JsonMap> messages) {
final rows = <JsonMap>[];
String? key;
final ids = <String>[];
final parts = <JsonMap>[];
void flush() {
if (key != null && parts.isNotEmpty) {
rows.add({
'kind': 'assistant',
'key': key,
'messageIds': List<String>.of(ids),
'parts': List<JsonMap>.of(parts),
});
}
key = null;
ids.clear();
parts.clear();
}
for (final message in messages) {
if (message['role'] == 'assistant') {
key ??= '${message['id'] ?? ''}';
final id = '${message['id'] ?? ''}'.trim();
key ??= id;
if (id.isNotEmpty) ids.add(id);
for (final part in (message['parts'] as List? ?? const [])) {
if (part is Map) parts.add(Map<String, dynamic>.from(part));
}