Merge main (High contrast) into Glass; Glass snaps live switches
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../../domain/chat_tool_calls.dart';
|
||||
import '../../../domain/chat_turn_activity.dart';
|
||||
import '../chat_response_pending.dart';
|
||||
import 'boxed_quote.dart';
|
||||
|
||||
/// How many of a turn's calls a boxed block lists; earlier ones fold into
|
||||
/// one "earlier" row (every call stays in the details dialog).
|
||||
const int boxedActivityMaxCalls = 6;
|
||||
|
||||
/// A tool call's status in words, never by colour alone.
|
||||
enum BoxedToolStatus {
|
||||
done('Done', Icons.check),
|
||||
failed('Failed', Icons.close),
|
||||
running('Running', Icons.more_horiz);
|
||||
|
||||
const BoxedToolStatus(this.word, this.icon);
|
||||
|
||||
final String word;
|
||||
final IconData icon;
|
||||
|
||||
static BoxedToolStatus of(JsonMap call) => chatToolFailed(call)
|
||||
? failed
|
||||
: chatToolRunning(call)
|
||||
? running
|
||||
: done;
|
||||
}
|
||||
|
||||
/// A turn's activity under a boxed transcript (High contrast): a bordered
|
||||
/// block with one row per tool call, each led by its status as an icon and
|
||||
/// a word ("Done", "Failed", "Running") in a status colour that reads at
|
||||
/// 7:1, then the tool and what it acted on. While the turn runs a live row
|
||||
/// says what it is doing. The block is one button that opens the activity
|
||||
/// details, like the Default design's line.
|
||||
class BoxedActivityRows extends StatelessWidget {
|
||||
const BoxedActivityRows({
|
||||
super.key,
|
||||
required this.data,
|
||||
required this.status,
|
||||
required this.streaming,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final ChatTurnActivityData data;
|
||||
|
||||
/// The turn's one-line status (with its running seconds while streaming).
|
||||
final String status;
|
||||
final bool streaming;
|
||||
final VoidCallback onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final style = theme.textTheme.bodyMedium!.copyWith(color: scheme.onSurface);
|
||||
final calls = data.tools;
|
||||
final shown = calls.length > boxedActivityMaxCalls
|
||||
? calls.sublist(calls.length - boxedActivityMaxCalls)
|
||||
: calls;
|
||||
final hidden = calls.length - shown.length;
|
||||
final rule = Divider(
|
||||
height: tokens.stroke,
|
||||
thickness: tokens.stroke,
|
||||
color: scheme.outlineVariant,
|
||||
);
|
||||
final rows = <Widget>[
|
||||
if (hidden > 0)
|
||||
_row(
|
||||
context,
|
||||
null,
|
||||
Text(
|
||||
'$hidden earlier tool ${hidden == 1 ? 'use' : 'uses'}',
|
||||
style: style.copyWith(color: scheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
for (final call in shown) _call(context, call, style),
|
||||
if (calls.isEmpty && !streaming)
|
||||
_row(
|
||||
context,
|
||||
data.failed ? BoxedToolStatus.failed : BoxedToolStatus.done,
|
||||
Text(status, style: style),
|
||||
),
|
||||
if (streaming) _live(context, style),
|
||||
];
|
||||
final radius = BorderRadius.circular(tokens.radius ?? 6);
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: '$status, expand for details',
|
||||
excludeSemantics: true,
|
||||
onTap: onOpen,
|
||||
child: Material(
|
||||
key: const Key('chat-boxed-activity'),
|
||||
type: MaterialType.transparency,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: radius,
|
||||
side: BorderSide(color: scheme.outline, width: tokens.stroke),
|
||||
),
|
||||
child: InkWell(
|
||||
key: const Key('chat-turn-activity'),
|
||||
onTap: onOpen,
|
||||
borderRadius: radius,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(tokens.stroke),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (final (index, row) in rows.indexed) ...[
|
||||
if (index > 0) rule,
|
||||
row,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _call(BuildContext context, JsonMap call, TextStyle style) {
|
||||
final detail = chatToolDetail(call);
|
||||
final duration = chatToolDurationMillis(call);
|
||||
return _row(
|
||||
context,
|
||||
BoxedToolStatus.of(call),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: chatToolLabel(call),
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
if (detail != null) TextSpan(text: ' $detail'),
|
||||
if (duration != null)
|
||||
TextSpan(text: ' · ${formatChatToolDuration(duration)}'),
|
||||
],
|
||||
),
|
||||
style: style,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The running row: the pending dots, then what the turn is doing and for
|
||||
/// how long, in the accent.
|
||||
Widget _live(BuildContext context, TextStyle style) {
|
||||
final accent = Theme.of(context).colorScheme.primary;
|
||||
return _row(
|
||||
context,
|
||||
null,
|
||||
Row(
|
||||
children: [
|
||||
ExcludeSemantics(
|
||||
child: DefaultTextStyle.merge(
|
||||
style: TextStyle(color: accent),
|
||||
child: const ChatResponsePending(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
status,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: style.copyWith(color: accent),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// One row: the status word (when there is one) in a column of its own,
|
||||
/// then [body]. At least 44px tall, so the block is a big target.
|
||||
Widget _row(BuildContext context, BoxedToolStatus? status, Widget body) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final ansi = AppDesignTokens.of(context).ansi;
|
||||
final color = switch (status) {
|
||||
BoxedToolStatus.failed => ansi?.red ?? scheme.error,
|
||||
BoxedToolStatus.running => ansi?.yellow ?? scheme.tertiary,
|
||||
BoxedToolStatus.done => ansi?.green ?? scheme.primary,
|
||||
null => scheme.onSurfaceVariant,
|
||||
};
|
||||
final label = theme.textTheme.labelLarge?.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w800,
|
||||
);
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 44),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
boxedQuotePadding,
|
||||
8,
|
||||
boxedQuotePadding,
|
||||
8,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (status != null) ...[
|
||||
// One column for every row's status, as wide as the longest
|
||||
// word, so the tool names line up.
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: _statusWidth(
|
||||
label,
|
||||
MediaQuery.textScalerOf(context),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(status.icon, size: 20, color: color),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
status.word,
|
||||
key: Key('boxed-status-${status.name}'),
|
||||
style: label,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
Expanded(child: body),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final Map<(TextStyle?, TextScaler), double> _statusWidths = {};
|
||||
|
||||
/// The status column's width: the icon, its gap and the widest status word
|
||||
/// in [style] at [scaler], measured once per style and scale.
|
||||
double _statusWidth(TextStyle? style, TextScaler scaler) =>
|
||||
_statusWidths[(style, scaler)] ??= () {
|
||||
var widest = 0.0;
|
||||
for (final status in BoxedToolStatus.values) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: status.word, style: style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: scaler,
|
||||
)..layout();
|
||||
if (painter.width > widest) widest = painter.width;
|
||||
painter.dispose();
|
||||
}
|
||||
return 20 + 6 + widest.ceilToDouble();
|
||||
}();
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../sessions/chat_color_palette.dart';
|
||||
import '../chat_message_bubble.dart';
|
||||
|
||||
/// The width of the bar in the chat's colour along a boxed turn's leading
|
||||
/// edge.
|
||||
const double boxedQuoteBar = 6;
|
||||
|
||||
/// The padding inside a boxed turn, after its bar.
|
||||
const double boxedQuotePadding = 12;
|
||||
|
||||
/// Where a boxed turn's text starts, from the row's edge: the footer under
|
||||
/// it (its delivery line and time) starts here too.
|
||||
const double boxedQuoteTextInset = boxedQuoteBar + boxedQuotePadding;
|
||||
|
||||
/// The words of the label above the operator's boxed turn.
|
||||
const String boxedQuoteLabel = 'You';
|
||||
|
||||
/// The operator's turn under a boxed transcript (High contrast): a "You"
|
||||
/// label, then the words in a box framed in the ink at the design's stroke,
|
||||
/// with a thick bar in the chat's colour (the ink for a chat with none) on
|
||||
/// its leading edge. Painted in one pass: no clip layer per turn.
|
||||
class BoxedQuote extends StatelessWidget {
|
||||
const BoxedQuote({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final bar = chatColorShade(context, ChatBubbleColor.of(context));
|
||||
return Material(
|
||||
key: const Key('chat-boxed-quote'),
|
||||
type: MaterialType.transparency,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ExcludeSemantics(
|
||||
child: SelectionContainer.disabled(
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(bottom: 4),
|
||||
child: Text(
|
||||
boxedQuoteLabel,
|
||||
key: const Key('chat-boxed-quote-label'),
|
||||
style: theme.textTheme.labelLarge?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
CustomPaint(
|
||||
foregroundPainter: BoxedFramePainter(
|
||||
frame: scheme.outline,
|
||||
bar: bar ?? scheme.onSurface,
|
||||
stroke: tokens.stroke,
|
||||
radius: tokens.radius ?? 6,
|
||||
barWidth: boxedQuoteBar,
|
||||
textDirection: Directionality.of(context),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
boxedQuoteTextInset,
|
||||
10,
|
||||
boxedQuotePadding,
|
||||
10,
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A rounded frame of [stroke] in [frame], with a [barWidth] bar in [bar]
|
||||
/// along its leading edge inside the corners. Drawn with canvas clips only,
|
||||
/// so a list of them adds no layers.
|
||||
class BoxedFramePainter extends CustomPainter {
|
||||
const BoxedFramePainter({
|
||||
required this.frame,
|
||||
required this.bar,
|
||||
required this.stroke,
|
||||
required this.radius,
|
||||
required this.textDirection,
|
||||
this.barWidth = 0,
|
||||
});
|
||||
|
||||
final Color frame;
|
||||
final Color bar;
|
||||
final double stroke;
|
||||
final double radius;
|
||||
final double barWidth;
|
||||
final TextDirection textDirection;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final outer = RRect.fromRectAndRadius(
|
||||
Offset.zero & size,
|
||||
Radius.circular(radius),
|
||||
);
|
||||
if (barWidth > 0) {
|
||||
final rect = textDirection == TextDirection.ltr
|
||||
? Rect.fromLTWH(0, 0, barWidth, size.height)
|
||||
: Rect.fromLTWH(size.width - barWidth, 0, barWidth, size.height);
|
||||
canvas
|
||||
..save()
|
||||
..clipRRect(outer)
|
||||
..drawRect(rect, Paint()..color = bar)
|
||||
..restore();
|
||||
}
|
||||
canvas.drawRRect(
|
||||
outer.deflate(stroke / 2),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = stroke
|
||||
..color = frame,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(BoxedFramePainter old) =>
|
||||
old.frame != frame ||
|
||||
old.bar != bar ||
|
||||
old.stroke != stroke ||
|
||||
old.radius != radius ||
|
||||
old.barWidth != barWidth ||
|
||||
old.textDirection != textDirection;
|
||||
}
|
||||
@@ -29,10 +29,11 @@ class ChatAttachmentGallery extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => Wrap(
|
||||
key: const Key('chat-attachment-gallery'),
|
||||
alignment:
|
||||
AppDesignTokens.of(context).transcript == TranscriptStyle.manuscript
|
||||
? WrapAlignment.start
|
||||
: WrapAlignment.end,
|
||||
alignment: switch (AppDesignTokens.of(context).transcript) {
|
||||
TranscriptStyle.manuscript ||
|
||||
TranscriptStyle.boxed => WrapAlignment.start,
|
||||
_ => WrapAlignment.end,
|
||||
},
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
|
||||
@@ -105,17 +105,28 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
key: const Key('chat-automated-prompt'),
|
||||
color: glass?.card ?? scheme.surfaceContainerLow,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
// A glass design's note is a small glass card with a light top
|
||||
// edge.
|
||||
shape: glass == null
|
||||
// A boxed transcript frames it in the design's corners and
|
||||
// stroke, in the secondary ink, so it reads apart from the
|
||||
// operator's own boxes framed in the ink.
|
||||
shape: transcript == TranscriptStyle.boxed
|
||||
? RoundedRectangleBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
borderRadius: tokens.corners(BorderRadius.zero),
|
||||
side: BorderSide(
|
||||
color: scheme.outlineVariant,
|
||||
width: tokens.stroke,
|
||||
),
|
||||
)
|
||||
: GlassBorder(
|
||||
// A glass design's note is a small glass card with a
|
||||
// light top edge.
|
||||
: glass != null
|
||||
? GlassBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
highlight: glass.highlight,
|
||||
edge: glass.edge,
|
||||
)
|
||||
: RoundedRectangleBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
@@ -147,7 +158,7 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
TranscriptStyle.prompt => 8 + terminalGlyphColumn(context),
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.cells => notebookCellTextInset,
|
||||
TranscriptStyle.bubbles => 14.0,
|
||||
TranscriptStyle.bubbles || TranscriptStyle.boxed => 14.0,
|
||||
};
|
||||
return ChatHoverRegion(
|
||||
child: Column(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../sessions/chat_color_palette.dart';
|
||||
import 'boxed/boxed_quote.dart';
|
||||
import 'notebook/notebook_input_cell.dart';
|
||||
import 'paper/paper_quote.dart';
|
||||
import 'terminal/terminal_prompt_line.dart';
|
||||
@@ -52,6 +53,8 @@ class ChatUserBubble extends StatelessWidget {
|
||||
return TerminalPromptLine(child: child);
|
||||
case TranscriptStyle.manuscript:
|
||||
return PaperQuote(child: child);
|
||||
case TranscriptStyle.boxed:
|
||||
return BoxedQuote(child: child);
|
||||
case TranscriptStyle.cells:
|
||||
return NotebookInputCell(child: child);
|
||||
case TranscriptStyle.bubbles:
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'chat_link_text.dart';
|
||||
import 'chat_message_bubble.dart';
|
||||
import 'chat_turn_activity_view.dart';
|
||||
import 'native_disclosure.dart';
|
||||
import 'boxed/boxed_quote.dart';
|
||||
import 'notebook/notebook_cell_frame.dart';
|
||||
import 'notebook/notebook_gutter.dart';
|
||||
import 'notebook/notebook_tool_cell.dart';
|
||||
@@ -122,7 +123,9 @@ class ChatMessageView extends StatelessWidget {
|
||||
padding: cells
|
||||
? EdgeInsets.only(top: user ? 6 : 3, bottom: user ? 3 : 6)
|
||||
: EdgeInsets.symmetric(
|
||||
vertical: transcript == TranscriptStyle.manuscript
|
||||
vertical:
|
||||
transcript == TranscriptStyle.manuscript ||
|
||||
transcript == TranscriptStyle.boxed
|
||||
? 12
|
||||
: tokens.density.space(6),
|
||||
),
|
||||
@@ -229,11 +232,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
children: [
|
||||
if (thumbnails.isNotEmpty)
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: transcript == TranscriptStyle.manuscript
|
||||
? paperQuoteTextInset
|
||||
: 0,
|
||||
),
|
||||
padding: EdgeInsetsDirectional.only(start: _quoteInset(transcript)),
|
||||
child: ChatAttachmentGallery(
|
||||
parts: thumbnails,
|
||||
images: images ?? _inlineImages,
|
||||
@@ -252,6 +251,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
start: switch (transcript) {
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.cells => notebookCellTextInset,
|
||||
TranscriptStyle.boxed => boxedQuoteTextInset,
|
||||
_ => 0,
|
||||
},
|
||||
),
|
||||
@@ -272,6 +272,14 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// Where the text of the operator's turn starts under [transcript]: the
|
||||
/// thumbnails above it and the footer under it start there too.
|
||||
static double _quoteInset(TranscriptStyle transcript) => switch (transcript) {
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.boxed => boxedQuoteTextInset,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
/// A prompt the agent or the server sent: its card, with the delivery line
|
||||
/// and time beneath.
|
||||
Widget _automatedTurn(ChatPromptOrigin origin, List<Widget> content) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_response_pending.dart';
|
||||
import 'chat_turn_activity_details.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
import 'boxed/boxed_activity_rows.dart';
|
||||
import 'notebook/notebook_tool_cells.dart';
|
||||
import 'paper/paper_activity_note.dart';
|
||||
import 'terminal/terminal_activity_rows.dart';
|
||||
@@ -143,6 +144,13 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
failed: data.failed,
|
||||
onOpen: _open,
|
||||
);
|
||||
case TranscriptStyle.boxed:
|
||||
return BoxedActivityRows(
|
||||
data: data,
|
||||
status: label,
|
||||
streaming: widget.streaming,
|
||||
onOpen: _open,
|
||||
);
|
||||
case TranscriptStyle.cells:
|
||||
return NotebookToolCells(
|
||||
data: data,
|
||||
|
||||
Reference in New Issue
Block a user