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:
2026-12-03 15:40:34 +00:00
parent 608b6b8edb
commit 9a6363b80e
22 changed files with 946 additions and 26 deletions
@@ -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;