Make chat reasoning a footer chip that opens a live sheet like tools

This commit is contained in:
2026-10-24 18:13:03 +01:00
parent ef575898f2
commit 5cb43b6dc8
11 changed files with 646 additions and 165 deletions
@@ -7,7 +7,7 @@ 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_disclosure.dart';
import 'chat_reasoning_chip.dart';
import 'native_disclosure.dart';
/// Builds an assistant text part; the default keeps the server's text exactly.
@@ -26,8 +26,8 @@ class ChatMessageView extends StatelessWidget {
final JsonMap row;
final ChatMessageTextBuilder? textBuilder;
/// More of an agent turn's summary chips, after its tools chip (the turn's
/// settled permission requests).
/// More of an agent turn's summary chips, after its reasoning and tools chips
/// (the turn's settled permission requests).
final List<Widget> footer;
@override
@@ -198,7 +198,9 @@ class ChatMessageView extends StatelessWidget {
return widgets;
}
/// Reasoning stays in the transcript so an open body follows live deltas.
/// 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.
Widget _agentTurn(BuildContext context, List<Widget> content, Widget bubble) {
final parts = _partsOf(row);
final reasoning = [
@@ -213,6 +215,12 @@ 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)
@@ -230,15 +238,9 @@ class ChatMessageView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (content.isNotEmpty) bubble,
if (reasoning.isNotEmpty)
ChatReasoningDisclosure(
key: const Key('chat-turn-reasoning'),
steps: reasoning,
streaming: row['streaming'] == true,
trailing: footer,
),
if (reasoning.isEmpty && footer.isNotEmpty)
if (footer.isNotEmpty)
Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: footer,
@@ -337,6 +339,21 @@ 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 [];