Chat: fold activity-only rows between messages into one summary line
Tool-only turns, thinking-only turns and background-task notices that sit between two content rows become one collapsible activity_group row, e.g. "Ran 7 commands · used 9 tools · 8 background tasks finished · 1 failed", the failure count in the error colour and never ellipsized. Expanding it shows the folded rows as they render on their own. A run's task notices fold into one chip at the newest notice; a notice whose id recurs later is counted only at its latest position. Grouping is a pure domain step (groupChatActivity) applied last in the thread view's row pipeline; group rows list every member id so ChatRowKeys keeps their identity, unchanged runs return the identical group object, and the transcript anchor accepts a group's agent-turn ids. The scroll fixture gains ?bgwork=1 for the shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../ui/adaptive/platform.dart';
|
||||
import '../../domain/chat_activity_groups.dart';
|
||||
import 'chat_turn_activity_view.dart';
|
||||
|
||||
/// A run of activity-only rows (tool turns, background-task notices) as one
|
||||
/// summary line, e.g. `Ran 7 commands · used 9 tools · 1 failed`, the failure
|
||||
/// in the error colour. Activating it shows the folded rows beneath, each as
|
||||
/// it renders on its own.
|
||||
class ChatActivityGroupView extends StatefulWidget {
|
||||
const ChatActivityGroupView({
|
||||
super.key,
|
||||
required this.row,
|
||||
required this.memberBuilder,
|
||||
});
|
||||
|
||||
/// A [chatActivityGroupKind] row (see [groupChatActivity]).
|
||||
final JsonMap row;
|
||||
|
||||
/// Builds one folded row the way the transcript builds it on its own.
|
||||
final Widget Function(JsonMap member) memberBuilder;
|
||||
|
||||
@override
|
||||
State<ChatActivityGroupView> createState() => _ChatActivityGroupViewState();
|
||||
}
|
||||
|
||||
class _ChatActivityGroupViewState extends State<ChatActivityGroupView> {
|
||||
bool _expanded = false;
|
||||
|
||||
void _toggle() => setState(() => _expanded = !_expanded);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final color = scheme.onSurfaceVariant;
|
||||
final segments = chatActivityGroupSegments(widget.row);
|
||||
final label = chatActivityGroupLabel(widget.row);
|
||||
final counts = [
|
||||
for (final segment in segments)
|
||||
if (!segment.failed) segment,
|
||||
];
|
||||
final failures = [
|
||||
for (final segment in segments)
|
||||
if (segment.failed) segment,
|
||||
];
|
||||
// Desktop hover hugs the label; phones keep the full-width touch row, as
|
||||
// a turn's own activity line does.
|
||||
final compact = prefersCompactHitTargets(context);
|
||||
final summary = ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 32),
|
||||
child: Row(
|
||||
mainAxisSize: compact ? MainAxisSize.min : MainAxisSize.max,
|
||||
children: [
|
||||
// The counts shrink first on a narrow window; the failure count
|
||||
// stays whole, in the error colour.
|
||||
Flexible(
|
||||
child: Text(
|
||||
[for (final segment in counts) segment.text].join(' · '),
|
||||
key: const Key('chat-activity-group-label'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: color),
|
||||
),
|
||||
),
|
||||
for (final segment in failures)
|
||||
Text(
|
||||
' · ${segment.text}',
|
||||
key: const Key('chat-activity-group-failed'),
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: scheme.error),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
_expanded ? Icons.expand_more : Icons.chevron_right,
|
||||
color: color,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final button = TextButton(
|
||||
key: const Key('chat-activity-group'),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 48),
|
||||
padding: const EdgeInsets.all(chatAgentContentInset),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
onPressed: _toggle,
|
||||
child: summary,
|
||||
);
|
||||
final members = chatActivityGroupRows(widget.row);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Semantics(
|
||||
button: true,
|
||||
expanded: _expanded,
|
||||
label:
|
||||
'$label, ${_expanded ? 'hide' : 'show'} '
|
||||
'${members.length == 1 ? 'the activity' : 'all ${members.length} activity rows'}',
|
||||
excludeSemantics: true,
|
||||
onTap: _toggle,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
widthFactor: 1,
|
||||
child: button,
|
||||
),
|
||||
),
|
||||
if (_expanded)
|
||||
for (var index = 0; index < members.length; index++)
|
||||
KeyedSubtree(
|
||||
key: ValueKey<String>(
|
||||
'chat-activity-member-${members[index]['key'] ?? index}',
|
||||
),
|
||||
child: widget.memberBuilder(members[index]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user