feat(app): chat reasoning is a chip beside the tool chip, opening its own sheet

This commit is contained in:
2026-10-23 16:22:31 +01:00
parent 7539a7a552
commit f2aa559d0e
5 changed files with 202 additions and 174 deletions
@@ -188,8 +188,8 @@ class ChatMessageView extends StatelessWidget {
return widgets;
}
/// The agent turn as the web lays it out: its reasoning as a quiet line
/// above the answer, the answer in the bubble, and one tool chip below.
/// The agent turn: the answer in the bubble, then one row with its reasoning
/// and tool-call chips, each opening its own sheet.
Widget _agentTurn(BuildContext context, List<Widget> content, Widget bubble) {
final parts = _partsOf(row);
final reasoning = [
@@ -206,16 +206,16 @@ class ChatMessageView extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (reasoning.isNotEmpty)
NativeDisclosure(
key: const Key('chat-reasoning'),
label: reasoning.length == 1
? 'Reasoning'
: 'Reasoning · ${reasoning.length} steps',
childBuilder: (context) => SelectableText(reasoning.join('\n\n')),
),
if (content.isNotEmpty) bubble,
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
// Reasoning and tool calls share one quiet row below the answer.
if (reasoning.isNotEmpty || tools.isNotEmpty)
Wrap(
spacing: 8,
children: [
if (reasoning.isNotEmpty) ChatReasoningChip(steps: reasoning),
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
],
),
],
);
}
@@ -41,6 +41,73 @@ class ChatToolCallsChip extends StatelessWidget {
size: 14,
color: color,
);
return _TurnChip(
chipKey: const Key('chat-tool-chip'),
leading: leading,
label: label,
color: color,
semanticsLabel: calls.length == 1
? '1 tool call, expand for details'
: '${calls.length} tool calls, expand for details',
sheet: _ToolCallsSheet(calls: calls),
);
}
}
/// A turn's reasoning as a chip beside its tool chip, the same way: `Reasoning`
/// or `Reasoning · N steps`, opening a sheet with the steps.
class ChatReasoningChip extends StatelessWidget {
const ChatReasoningChip({super.key, required this.steps});
final List<String> steps;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final color = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final label = steps.length == 1
? 'Reasoning'
: 'Reasoning · ${steps.length} steps';
return _TurnChip(
chipKey: const Key('chat-reasoning-chip'),
leading: Icon(
cupertino ? CupertinoIcons.lightbulb : Icons.lightbulb_outline,
size: 14,
color: color,
),
label: label,
color: color,
semanticsLabel: '$label, expand for details',
sheet: _ReasoningSheet(label: label, steps: steps),
);
}
}
/// The quiet chip shell both turn summaries share, and its native sheet.
class _TurnChip extends StatelessWidget {
const _TurnChip({
required this.chipKey,
required this.leading,
required this.label,
required this.color,
required this.semanticsLabel,
required this.sheet,
});
final Key chipKey;
final Widget leading;
final String label;
final Color color;
final String semanticsLabel;
final Widget sheet;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -59,22 +126,20 @@ class ChatToolCallsChip extends StatelessWidget {
// The child's own action is excluded with its label, so the node
// carries the activation for assistive technology.
onTap: () => _open(context, cupertino),
label: calls.length == 1
? '1 tool call, expand for details'
: '${calls.length} tool calls, expand for details',
label: semanticsLabel,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 2),
child: cupertino
? CupertinoButton(
key: const Key('chat-tool-chip'),
key: chipKey,
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
minimumSize: Size.zero,
onPressed: () => _open(context, cupertino),
child: content,
)
: InkWell(
key: const Key('chat-tool-chip'),
key: chipKey,
borderRadius: BorderRadius.circular(8),
onTap: () => _open(context, cupertino),
child: Padding(
@@ -90,7 +155,6 @@ class ChatToolCallsChip extends StatelessWidget {
}
Future<void> _open(BuildContext context, bool cupertino) {
final sheet = _ToolCallsSheet(calls: calls);
if (cupertino) {
return showCupertinoModalPopup<void>(
context: context,
@@ -107,6 +171,49 @@ class ChatToolCallsChip extends StatelessWidget {
}
}
class _ReasoningSheet extends StatelessWidget {
const _ReasoningSheet({required this.label, required this.steps});
final String label;
final List<String> steps;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final style = cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyMedium;
return DefaultTextStyle.merge(
style: style,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
),
child: ListView(
key: const Key('chat-reasoning-sheet'),
shrinkWrap: true,
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
label,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
for (final (index, step) in steps.indexed)
Padding(
padding: EdgeInsets.only(top: index == 0 ? 0 : 12),
child: SelectableText(step),
),
],
),
),
);
}
}
class _ToolCallsSheet extends StatelessWidget {
const _ToolCallsSheet({required this.calls});