Files
pipelines/app/lib/features/chat/ui/transcript/chat_injected_rows.dart
T
alan a3a59adb30 Quieter transcript metadata: day dividers, time-only rows, muted meta rows
- Date once per calendar day: a muted centred divider above each day's
  first timed row (chatDayDividers); rows show only their time ("10:16"),
  with the full date and time kept in the tooltip and semantics. The user's
  time shares the delivery line; a harness notice's time trails its line.
- Activity line and turn chips are secondary: bodyMedium, regular weight,
  onSurfaceVariant (error colour kept for failures), a small chevron_right
  that turns down while its details are open (replaces expand_less).
- Copy / Read aloud: 18 px muted icons; on pointer devices shown only while
  the reply is hovered or an action is focused (also without the gutter);
  touch keeps them visible with a full tap target. The time leads the
  footer so hidden actions leave no gap.
- Settled questions: the question on one line, the operator's answer in
  full on its own line beneath it.
- Meta rows (activity, chips, notices, compaction line) start at the reply
  text's leading edge; turn chips sit in their own column under the answer.
- Scroll fixture: ?timestamps=1 spreads messages over two days.

Row keys are unchanged; the divider joins a row without replacing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 11:10:51 +00:00

216 lines
6.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_transcript_days.dart';
import 'chat_message_bubble.dart';
import 'chat_message_timestamp.dart';
import 'chat_message_view.dart';
import 'chat_turn_activity_view.dart';
/// Content the harness delivered into the session, drawn on the agent's side:
/// an `agent_report` row (a delegated agent's report) and a `system_notice`
/// row (a one-line harness notice such as a background task finishing). Neither
/// is the operator's turn, so neither uses the operator's bubble.
/// The text and sender a row's message recorded.
({String text, String sender}) _content(JsonMap row) {
final message = row['message'];
final parts = message is Map ? message['parts'] : null;
final buffer = StringBuffer();
var sender = '';
if (parts is List) {
for (final part in parts) {
if (part is! Map || part['type'] != 'text') continue;
final text = '${part['text'] ?? ''}';
if (text.trim().isEmpty) continue;
if (buffer.isNotEmpty) buffer.write('\n\n');
buffer.write(text);
final name = '${part['name'] ?? ''}'.trim();
if (sender.isEmpty && name.isNotEmpty) sender = name;
}
}
return (text: buffer.toString().trim(), sender: sender);
}
/// The report's first line, with markdown markers removed, as its summary.
String chatAgentReportSummary(String text) {
for (final raw in text.split('\n')) {
final line = raw
.trim()
.replaceFirst(RegExp(r'^(#{1,6}\s+|[-*+]\s+|>\s*)'), '')
.replaceAll('**', '')
.trim();
if (line.isNotEmpty) return line;
}
return '';
}
/// A delegated agent's report: collapsed to its first line, expanded to the
/// whole report rendered as markdown.
class ChatAgentReportCard extends StatefulWidget {
const ChatAgentReportCard({super.key, required this.row, this.textBuilder});
final JsonMap row;
final ChatMessageTextBuilder? textBuilder;
@override
State<ChatAgentReportCard> createState() => _ChatAgentReportCardState();
}
class _ChatAgentReportCardState extends State<ChatAgentReportCard> {
bool _expanded = false;
void _toggle() => setState(() => _expanded = !_expanded);
@override
Widget build(BuildContext context) {
final content = _content(widget.row);
final title = content.sender.isEmpty
? 'Agent report'
: 'Agent report · ${content.sender}';
final summary = chatAgentReportSummary(content.text);
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
final header = Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 12, top: 2),
child: Icon(Icons.assignment, color: secondary),
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: Theme.of(context).textTheme.titleSmall),
if (summary.isNotEmpty)
Text(
summary,
maxLines: _expanded ? null : 1,
overflow: _expanded ? null : TextOverflow.ellipsis,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: secondary),
),
],
),
),
Icon(
_expanded ? Icons.expand_less : Icons.expand_more,
color: secondary,
),
],
);
final toggle = Semantics(
container: true,
button: true,
expanded: _expanded,
label: title,
value: summary,
onTap: _toggle,
child: ExcludeSemantics(
child: InkWell(
onTap: _toggle,
child: Padding(padding: const EdgeInsets.all(12), child: header),
),
),
);
final body = _expanded
? Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 12),
child: DefaultTextStyle.merge(
style: chatMessageTextStyle(context),
child:
widget.textBuilder?.call(context, content.text) ??
SelectableText(content.text),
),
)
: null;
final column = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [toggle, ?body],
);
return Semantics(
container: true,
explicitChildNodes: true,
label: 'Agent report',
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 720),
child: Card.outlined(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
child: column,
),
),
),
),
);
}
}
/// A one-line harness notice in the agent's column, in the secondary style.
class ChatSystemNoticeLine extends StatelessWidget {
const ChatSystemNoticeLine({super.key, required this.row});
final JsonMap row;
@override
Widget build(BuildContext context) {
final text = _content(row).text;
if (text.isEmpty) return const SizedBox.shrink();
final color = Theme.of(context).colorScheme.onSurfaceVariant;
final style = Theme.of(context).textTheme.bodySmall?.copyWith(color: color);
final time = chatRowCreatedAt(row);
// The icon starts at the reply text's edge, like the turn's activity line.
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
chatAgentContentInset,
6,
chatAgentContentInset,
6,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Semantics(
container: true,
label: 'System notice',
value: text,
child: ExcludeSemantics(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Icon(
Icons.info_outline,
size: style?.fontSize == null
? 16
: style!.fontSize! * 1.2,
color: color,
),
),
Expanded(child: Text(text, style: style)),
],
),
),
),
),
// Its time trails on the same line, as an answer's does.
if (time != null)
Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: ChatMessageTimestamp(createdAt: time),
),
],
),
);
}
}