Re-derive only the live turn's transcript rows per streamed delta

ChatTranscriptRows keeps each message run's rows while the run holds the
identical message objects; applyChatEvent and the controller keep untouched
messages' identity. Shown-item filtering, task-notice groups and row-key ids
are held per row object, and the view reads message ids once per list.
Tests check the incremental path equals a full derivation across streaming,
appends, shown items, cards, turn diffs and prepended pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 18:24:02 +00:00
parent 58c72538d5
commit 9be31b8ba0
9 changed files with 698 additions and 199 deletions
@@ -234,6 +234,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
ChatShellRunsController(widget.gateway, widget.sessionId)
..addListener(_reportFinishedRuns);
late ChatRowKeys _rowKeys = ChatRowKeys();
// Keeps the rows of unchanged turns across builds; a streamed delta only
// re-derives the live turn.
ChatTranscriptRows _transcriptRows = ChatTranscriptRows();
// The last [_messageIds] and the message list it was read from.
List<JsonMap>? _idsSource;
List<String> _ids = const [];
final _sentEntrances = ChatSentEntrances();
final _rowWidgets = ChatRowWidgets();
@@ -711,6 +717,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
_controller = _attach();
_composer = _attachComposer();
_rowKeys = ChatRowKeys();
_transcriptRows = ChatTranscriptRows();
_rowWidgets.clear();
_chrome.clear();
_dismissals = ChatNoticeDismissals();
@@ -797,10 +804,21 @@ class _ChatThreadViewState extends State<ChatThreadView> {
/// The ids of the transcript's messages in view order. Cards are conversation
/// state, not messages, so a pending approval does not count as an arrival.
List<String> _messageIds() => [
for (final message in _visibleMessages())
if ('${message['id'] ?? ''}'.trim().isNotEmpty) '${message['id']}'.trim(),
];
///
/// The controller replaces its message list on every change, so the ids are
/// read once per list rather than on every call within a build.
List<String> _messageIds() {
final messages = _visibleMessages();
if (!identical(messages, _idsSource)) {
_idsSource = messages;
_ids = List.unmodifiable([
for (final message in messages)
if ('${message['id'] ?? ''}'.trim().isNotEmpty)
'${message['id']}'.trim(),
]);
}
return _ids;
}
String? _newestMessageId() {
final ids = _messageIds();
@@ -1119,7 +1137,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
groupSettledQuestions(
groupSettledPermissions(
withChatShownItems(
transcriptRows(
_transcriptRows.rows(
messages,
trailing: cards,
running: