Merge branch 'main' into flutter/chat-markdown

This commit is contained in:
2026-10-21 23:34:35 +01:00
91 changed files with 12318 additions and 149 deletions
@@ -92,13 +92,34 @@ class ChatMessageView extends StatelessWidget {
List<Widget> _agentParts(BuildContext context) {
final widgets = <Widget>[];
for (final part in _partsOf(row)) {
final parts = _partsOf(row);
final seen = <String, int>{};
for (var index = 0; index < parts.length; index++) {
final part = parts[index];
final widget = _agentPart(context, part);
if (widget != null) widgets.add(widget);
if (widget == null) continue;
// Part identity, not position, so an older assistant message that folds
// into the same turn can prepend its parts without moving an open
// disclosure. The enclosing row's identity is carried by ChatRowKeys; a
// part with no server id still falls back to its position.
widgets.add(
KeyedSubtree(key: _partKey(part, index, seen), child: widget),
);
}
return widgets;
}
/// The server's part id when there is one, else this part's position. A
/// repeated identity gets an ordinal so two sibling keys never collide.
Key _partKey(JsonMap part, int index, Map<String, int> seen) {
final type = '${part['type'] ?? ''}';
final id = '${part['id'] ?? ''}'.trim();
final base = id.isEmpty ? 'index-$index' : '$type:$id';
final ordinal = (seen[base] ?? 0) + 1;
seen[base] = ordinal;
return ValueKey<String>('chat-part-$base-$ordinal');
}
/// One agent part, or null when a known part has nothing to draw. The web's
/// `partRendering` hides blank text/reasoning too, so a blank known part must
/// not fall through to the unknown-part disclosure.