Keep chat activity stable in one live disclosure and distinguish unread attention

This commit is contained in:
2026-10-28 16:45:05 +00:00
parent e0317574de
commit 7027da4248
22 changed files with 968 additions and 301 deletions
@@ -6,10 +6,8 @@ import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../sessions/chat_adaptive.dart';
import '../../domain/chat_tool_calls.dart';
import 'chat_tool_calls_view.dart';
import 'chat_reasoning_chip.dart';
import 'chat_turn_activity_view.dart';
import 'native_disclosure.dart';
import 'chat_response_pending.dart';
/// Builds an assistant text part; the default keeps the server's text exactly.
typedef ChatMessageTextBuilder = Widget Function(BuildContext, String);
@@ -27,8 +25,7 @@ class ChatMessageView extends StatelessWidget {
final JsonMap row;
final ChatMessageTextBuilder? textBuilder;
/// More of an agent turn's summary chips, after its reasoning and tools chips
/// (the turn's settled permission requests).
/// The turn's settled permissions, independent of passive activity details.
final List<Widget> footer;
@override
@@ -199,9 +196,8 @@ class ChatMessageView extends StatelessWidget {
return widgets;
}
/// The turn's footer: its reasoning, tools and permissions chips, then its
/// model. Each chip opens a native sheet; an open reasoning sheet follows
/// live deltas.
/// Stable activity precedes the answer; permission summaries and recorded
/// model remain beneath it. Pending interaction cards are rendered separately.
Widget _agentTurn(BuildContext context, List<Widget> content, Widget bubble) {
final parts = _partsOf(row);
final reasoning = [
@@ -216,13 +212,6 @@ class ChatMessageView extends StatelessWidget {
];
final model = '${row['model'] ?? ''}'.trim();
final footer = <Widget>[
if (reasoning.isNotEmpty)
ChatReasoningChip(
key: const Key('chat-turn-reasoning'),
steps: reasoning,
streaming: row['streaming'] == true && _reasoningIsNewest(parts),
),
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
...this.footer,
if (model.isNotEmpty)
Text(
@@ -238,6 +227,20 @@ class ChatMessageView extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (row['streaming'] == true ||
reasoning.isNotEmpty ||
tools.isNotEmpty ||
(row['activityRecords'] as List? ?? const []).isNotEmpty)
ChatTurnActivityView(
key: const Key('chat-stable-turn-activity'),
parts: [
...parts,
...List<JsonMap>.from(
row['activityRecords'] as List? ?? const [],
),
],
streaming: row['streaming'] == true,
),
if (content.isNotEmpty) bubble,
if (footer.isNotEmpty)
Wrap(
@@ -266,9 +269,6 @@ class ChatMessageView extends StatelessWidget {
KeyedSubtree(key: _partKey(part, index, seen), child: widget),
);
}
if (widgets.isEmpty && row['streaming'] == true) {
widgets.add(const ChatResponsePending());
}
return widgets;
}
@@ -294,7 +294,7 @@ class ChatMessageView extends StatelessWidget {
if (!hasText) return type.isEmpty ? _unrecognised(part) : null;
return textBuilder?.call(context, text) ?? SelectableText(text);
}
// Reasoning and tool calls are drawn outside the bubble (_agentTurn).
// Reasoning and tools are retained in the turn's activity disclosure.
if (type == 'reasoning' || type == 'tool') return null;
if (type == 'file') {
if (_isFile(part)) return _attachment(context, part);
@@ -343,21 +343,6 @@ class ChatMessageView extends StatelessWidget {
SelectableText(const JsonEncoder.withIndent(' ').convert(part));
}
/// Whether the turn's newest drawn part is reasoning: while it streams, that
/// is the step still arriving. Once an answer or a tool call starts after it,
/// the reasoning chip stops spinning (a running tool spins its own chip).
bool _reasoningIsNewest(List<JsonMap> parts) {
for (final part in parts.reversed) {
final type = part['type'];
if (type == 'tool') return false;
if ((type == 'text' || type == 'reasoning') &&
'${part['text'] ?? ''}'.trim().isNotEmpty) {
return type == 'reasoning';
}
}
return false;
}
List<JsonMap> _partsOf(Map<dynamic, dynamic> source) {
final parts = source['parts'];
if (parts is! List) return const [];