Files
pipelines/app/lib/features/chat/ui/transcript/chat_automated_prompt.dart
T
alan 9a6363b80e 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>
2026-12-03 15:40:34 +00:00

150 lines
4.9 KiB
Dart

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),
],
),
),
);
}
}