fix(chat): place per-message reasoning left of the tools count

This commit is contained in:
2026-10-24 11:47:07 +01:00
parent 8547a1527f
commit b355679507
5 changed files with 189 additions and 37 deletions
@@ -203,6 +203,18 @@ class ChatMessageView extends StatelessWidget {
if (isChatToolPart(part)) part,
];
final model = '${row['model'] ?? ''}'.trim();
final footer = <Widget>[
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
if (model.isNotEmpty)
Text(
model,
key: const Key('chat-reply-model'),
style: TextStyle(
fontSize: 12,
color: _secondaryColor(context, _isCupertino(context)),
),
),
];
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -213,24 +225,13 @@ class ChatMessageView extends StatelessWidget {
key: const Key('chat-turn-reasoning'),
steps: reasoning,
streaming: row['streaming'] == true,
trailing: footer,
),
if (tools.isNotEmpty || model.isNotEmpty)
if (reasoning.isEmpty && footer.isNotEmpty)
Wrap(
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
// Which model answered, quietly, after the chips.
if (model.isNotEmpty)
Text(
model,
key: const Key('chat-reply-model'),
style: TextStyle(
fontSize: 12,
color: _secondaryColor(context, _isCupertino(context)),
),
),
],
children: footer,
),
],
);
@@ -2,52 +2,100 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../sessions/chat_adaptive.dart';
import 'native_disclosure.dart';
/// Only reasoning actually supplied by the backend. Keeping its body in the
/// transcript (rather than a modal snapshot) lets an open disclosure rebuild
/// with every delta, even while answer text is also arriving.
class ChatReasoningDisclosure extends StatelessWidget {
class ChatReasoningDisclosure extends StatefulWidget {
const ChatReasoningDisclosure({
super.key,
required this.steps,
required this.streaming,
this.trailing = const [],
});
final List<String> steps;
final bool streaming;
final List<Widget> trailing;
@override
State<ChatReasoningDisclosure> createState() =>
_ChatReasoningDisclosureState();
}
class _ChatReasoningDisclosureState extends State<ChatReasoningDisclosure> {
late bool _expanded = widget.streaming;
void _toggle() => setState(() => _expanded = !_expanded);
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final label = steps.length == 1
final label = widget.steps.length == 1
? 'Reasoning'
: 'Reasoning · ${steps.length} steps';
final disclosure = NativeDisclosure(
key: const Key('chat-reasoning-disclosure'),
: 'Reasoning · ${widget.steps.length} steps';
final control = Semantics(
key: const Key('chat-reasoning-toggle'),
button: true,
expanded: _expanded,
label: label,
initiallyExpanded: streaming,
childBuilder: (_) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (final (index, step) in steps.indexed)
Padding(
padding: EdgeInsets.only(top: index == 0 ? 0 : 12, bottom: 8),
child: SelectableText(step),
onTap: _toggle,
excludeSemantics: true,
child: cupertino
? CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
minimumSize: Size.zero,
onPressed: _toggle,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: Text(label)),
Icon(
_expanded
? CupertinoIcons.chevron_up
: CupertinoIcons.chevron_down,
size: 14,
),
],
),
)
: TextButton(
onPressed: _toggle,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: Text(label)),
Icon(
_expanded ? Icons.expand_less : Icons.expand_more,
size: 14,
),
],
),
),
],
),
);
// Material's native ExpansionTile needs a surface; Cupertino must not
// acquire a Material dependency just to show its own disclosure button.
return DefaultTextStyle.merge(
style: cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyMedium,
child: cupertino
? disclosure
: Material(color: Colors.transparent, child: disclosure),
child: Column(
key: const Key('chat-reasoning-disclosure'),
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [control, ...widget.trailing],
),
if (_expanded)
for (final (index, step) in widget.steps.indexed)
Padding(
padding: EdgeInsets.only(top: index == 0 ? 0 : 12, bottom: 8),
child: SelectableText(step),
),
],
),
);
}
}