Chat: draw agent follow-ups and automatic continues apart from the operator
The server now names a user turn's origin (followup, auto_continue, auto_switch, scheduled) on chat messages, user frames and queued prompts, from the prompt's operation id while it holds the prompt and from its own text prefixes in history read later. Origin is a new field, so older clients keep treating these as ordinary user turns. The app draws an agent follow-up, auto-continue and account-switch prompt as a quiet outlined card on the agent's side with an icon, label and the schedule facts from the preamble; the operator's own scheduled message keeps its bubble with a small Scheduled mark. Find searches the drawn text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../conversation/chat_schedule_time.dart';
|
||||
import '../../domain/chat_prompt_origin.dart';
|
||||
import 'chat_copy_button.dart';
|
||||
import 'chat_hover_actions.dart';
|
||||
|
||||
/// The header words of an automated prompt.
|
||||
String chatAutomatedPromptLabel(ChatPromptOrigin origin) => switch (origin) {
|
||||
ChatPromptOrigin.followup => 'Follow-up from agent',
|
||||
ChatPromptOrigin.autoContinue => 'Auto-continue after limit reset',
|
||||
ChatPromptOrigin.autoSwitch => 'Continued on another account',
|
||||
_ => '',
|
||||
};
|
||||
|
||||
IconData _icon(ChatPromptOrigin origin) => switch (origin) {
|
||||
ChatPromptOrigin.followup => Icons.update,
|
||||
ChatPromptOrigin.autoContinue => Icons.autorenew,
|
||||
_ => Icons.swap_horiz,
|
||||
};
|
||||
|
||||
/// A prompt the agent or the server sent on the operator's behalf. It is not
|
||||
/// the operator's filled bubble: a quiet outlined card on the agent's side,
|
||||
/// headed by what sent it (and, for a follow-up, when the agent scheduled it
|
||||
/// or what run it waited for), with the prompt's [body] beneath. [footer]
|
||||
/// (its delivery line) and the time sit under the card with its Copy.
|
||||
class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
const ChatAutomatedPromptCard({
|
||||
super.key,
|
||||
required this.prompt,
|
||||
required this.body,
|
||||
this.footer = const [],
|
||||
this.timestamp,
|
||||
});
|
||||
|
||||
final ChatAutomatedPrompt prompt;
|
||||
final Widget body;
|
||||
final List<Widget> footer;
|
||||
final Widget? timestamp;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final label = chatAutomatedPromptLabel(prompt.origin);
|
||||
final detail = switch (prompt) {
|
||||
ChatAutomatedPrompt(:final condition?) => 'when $condition',
|
||||
ChatAutomatedPrompt(:final scheduledAt?) =>
|
||||
'scheduled ${chatScheduleTime(context, scheduledAt)}',
|
||||
_ => null,
|
||||
};
|
||||
final muted = theme.textTheme.labelMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
);
|
||||
final header = SelectionContainer.disabled(
|
||||
child: Wrap(
|
||||
key: const Key('chat-automated-prompt-header'),
|
||||
spacing: 6,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Icon(_icon(prompt.origin), size: 16, color: scheme.tertiary),
|
||||
Text(label, style: muted?.copyWith(fontWeight: FontWeight.w600)),
|
||||
if (detail != null) Text('· $detail', style: muted),
|
||||
],
|
||||
),
|
||||
);
|
||||
final card = Material(
|
||||
key: const Key('chat-automated-prompt'),
|
||||
color: scheme.surfaceContainerLow,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 8, 14, 10),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
header,
|
||||
if (prompt.body.trim().isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
DefaultTextStyle.merge(
|
||||
style: theme.textTheme.bodyMedium,
|
||||
child: body,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
final copy = prompt.body.trim().isEmpty
|
||||
? null
|
||||
: ChatHoverReveal(child: ChatCopyButton(text: prompt.body.trim()));
|
||||
return ChatHoverRegion(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
card,
|
||||
if (footer.isNotEmpty || timestamp != null || copy != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 14, top: 2),
|
||||
child: Wrap(
|
||||
key: const Key('chat-message-footer'),
|
||||
spacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [...footer, ?timestamp, ?copy],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The small "Scheduled" mark under the operator's own message they had
|
||||
/// scheduled to send later, once it is no longer waiting.
|
||||
class ChatScheduledMark extends StatelessWidget {
|
||||
const ChatScheduledMark({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
);
|
||||
return SelectionContainer.disabled(
|
||||
child: Semantics(
|
||||
container: true,
|
||||
label: 'Scheduled message',
|
||||
excludeSemantics: true,
|
||||
child: Row(
|
||||
key: const Key('chat-scheduled-mark'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.schedule_send,
|
||||
size: (style?.fontSize ?? 12) + 2,
|
||||
color: style?.color,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text('Scheduled', style: style),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../data/chat_attachment_images.dart';
|
||||
import 'chat_attachment_gallery.dart';
|
||||
import 'chat_automated_prompt.dart';
|
||||
import '../../domain/chat_prompt_origin.dart';
|
||||
import '../../domain/chat_tool_calls.dart';
|
||||
import '../../domain/chat_transcript.dart';
|
||||
import 'chat_copy_button.dart';
|
||||
@@ -31,8 +33,14 @@ class ChatMessageView extends StatelessWidget {
|
||||
this.footer = const [],
|
||||
this.images,
|
||||
this.speechScope = 'chat',
|
||||
this.scheduleShown = false,
|
||||
});
|
||||
|
||||
/// Whether [footer] already says the message is scheduled (its delivery
|
||||
/// line reads "Scheduled · sends at …"), so the operator's own scheduled
|
||||
/// message needs no second mark.
|
||||
final bool scheduleShown;
|
||||
|
||||
final JsonMap row;
|
||||
|
||||
/// Names the conversation in the reader's message ids, so leaving it can
|
||||
@@ -53,7 +61,17 @@ class ChatMessageView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = row['kind'] == 'user';
|
||||
final role = user ? 'User' : 'Assistant';
|
||||
final origin = user
|
||||
? chatPromptOrigin(_userMessage)
|
||||
: ChatPromptOrigin.operator;
|
||||
// A prompt the agent or the server sent reads as neither side's turn: a
|
||||
// quiet card on the agent's side, headed by what sent it.
|
||||
final automated = origin.automated;
|
||||
final role = automated
|
||||
? chatAutomatedPromptLabel(origin)
|
||||
: user
|
||||
? 'User'
|
||||
: 'Assistant';
|
||||
final content = user ? _userParts(context) : _agentParts(context);
|
||||
// A wide window draws an answer's Copy in the gutter left of the reading
|
||||
// column; without room it trails the time in the answer's footer.
|
||||
@@ -78,7 +96,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => Align(
|
||||
alignment: user
|
||||
alignment: user && !automated
|
||||
? AlignmentDirectional.centerEnd
|
||||
: AlignmentDirectional.centerStart,
|
||||
child: ConstrainedBox(
|
||||
@@ -90,8 +108,10 @@ class ChatMessageView extends StatelessWidget {
|
||||
? (constraints.maxWidth * 0.85).clamp(0, 560).toDouble()
|
||||
: 720 + gutter,
|
||||
),
|
||||
child: user
|
||||
? _userTurn(content, body)
|
||||
child: automated
|
||||
? _automatedTurn(origin, content)
|
||||
: user
|
||||
? _userTurn(content, body, origin)
|
||||
: _agentRow(
|
||||
context,
|
||||
content,
|
||||
@@ -115,7 +135,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
/// Attached images sit above the operator's bubble, as their own thumbnails;
|
||||
/// an images-only turn draws no empty bubble. The footer (the delivery line)
|
||||
/// sits under the bubble's trailing corner.
|
||||
Widget _userTurn(List<Widget> content, Widget body) {
|
||||
Widget _userTurn(List<Widget> content, Widget body, ChatPromptOrigin origin) {
|
||||
final thumbnails = [
|
||||
for (final part in _partsOf(_userMessage))
|
||||
if (_isFile(part) && chatPartIsThumbnail(part)) part,
|
||||
@@ -124,7 +144,8 @@ class ChatMessageView extends StatelessWidget {
|
||||
createdAt: chatMessageCreatedAt(_userMessage),
|
||||
);
|
||||
final hasTimestamp = chatMessageCreatedAt(_userMessage) != null;
|
||||
if (thumbnails.isEmpty && footer.isEmpty && !hasTimestamp) {
|
||||
final marked = origin == ChatPromptOrigin.scheduled && !scheduleShown;
|
||||
if (thumbnails.isEmpty && footer.isEmpty && !hasTimestamp && !marked) {
|
||||
return ChatUserBubble(child: body);
|
||||
}
|
||||
return Column(
|
||||
@@ -141,27 +162,53 @@ class ChatMessageView extends StatelessWidget {
|
||||
if (content.isNotEmpty || thumbnails.isEmpty)
|
||||
ChatUserBubble(child: body),
|
||||
// The delivery line and the time share one line under the bubble.
|
||||
if (footer.isNotEmpty || hasTimestamp) ...[
|
||||
if (footer.isNotEmpty || hasTimestamp || marked) ...[
|
||||
const SizedBox(height: 2),
|
||||
Wrap(
|
||||
key: const Key('chat-message-footer'),
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.end,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [...footer, if (hasTimestamp) timestamp],
|
||||
children: [
|
||||
...footer,
|
||||
if (marked) const ChatScheduledMark(),
|
||||
if (hasTimestamp) timestamp,
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// A prompt the agent or the server sent: its card, with the delivery line
|
||||
/// and time beneath.
|
||||
Widget _automatedTurn(ChatPromptOrigin origin, List<Widget> content) {
|
||||
final created = chatMessageCreatedAt(_userMessage);
|
||||
return ChatAutomatedPromptCard(
|
||||
prompt: chatAutomatedPrompt(origin, _userText(_userMessage)),
|
||||
body: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: content,
|
||||
),
|
||||
footer: footer,
|
||||
timestamp: created == null
|
||||
? null
|
||||
: ChatMessageTimestamp(createdAt: created),
|
||||
);
|
||||
}
|
||||
|
||||
/// The user turn's text parts joined as its row draws them.
|
||||
static String _userText(JsonMap message) => _partsOf(message)
|
||||
.where((part) => part['type'] == null || part['type'] == 'text')
|
||||
.map((part) => '${part['text'] ?? ''}')
|
||||
.join('\n');
|
||||
|
||||
List<Widget> _userParts(BuildContext context) {
|
||||
final message = _userMessage;
|
||||
final parts = _partsOf(message);
|
||||
final text = parts
|
||||
.where((part) => part['type'] == null || part['type'] == 'text')
|
||||
.map((part) => '${part['text'] ?? ''}')
|
||||
.join('\n');
|
||||
final automated = chatPromptOrigin(message).automated;
|
||||
final text = chatPromptDisplayText(message, _userText(message));
|
||||
final widgets = <Widget>[
|
||||
if (text.trim().isNotEmpty) ChatLinkText(text),
|
||||
for (final part in parts.where(_isFile))
|
||||
@@ -173,7 +220,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
_unrecognised(part),
|
||||
];
|
||||
final client = '${message['client'] ?? ''}'.trim();
|
||||
if (client.isNotEmpty) {
|
||||
if (client.isNotEmpty && !automated) {
|
||||
widgets.insert(0, Text(client, style: _clientStyle(context)));
|
||||
}
|
||||
return widgets;
|
||||
|
||||
Reference in New Issue
Block a user