Show loudly in the chat list when a chat is waiting on the operator
The server's chat activity now counts each session's unanswered approvals and questions (awaiting_operator) and pushes it to every connection when it changes. A waiting chat's list row pulses in the error colour with a solid bar on its leading edge, its avatar wears a ringing bell in place of the spinner, and its state line leads with a bold "Waiting for you". Reduced motion holds the pulse and the bell still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
|
||||
/// One chat's live activity as the server observes it: a turn in flight and
|
||||
/// how many background tasks (shells, background commands, subagents) still
|
||||
/// run. It rides on each `chat_sessions` row as `activity` and is pushed to
|
||||
/// One chat's live activity as the server observes it: a turn in flight, how
|
||||
/// many background tasks (shells, background commands, subagents) still run,
|
||||
/// and how many approvals or questions wait on the operator. It rides on each `chat_sessions` row as `activity` and is pushed to
|
||||
/// every connection as `chat_activity` on each change. [seq] orders one
|
||||
/// chat's snapshots across the list and the pushes; the larger one is newer.
|
||||
typedef ChatListActivity = ({
|
||||
String sessionId,
|
||||
bool turnRunning,
|
||||
int backgroundTasks,
|
||||
int awaitingOperator,
|
||||
int seq,
|
||||
});
|
||||
|
||||
@@ -21,11 +22,13 @@ ChatListActivity? chatListActivityOf(Object? value, {String? sessionId}) {
|
||||
final id = sessionId ?? (named is String ? named : '');
|
||||
if (id.isEmpty) return null;
|
||||
final tasks = value['background_tasks'];
|
||||
final awaiting = value['awaiting_operator'];
|
||||
final seq = value['seq'];
|
||||
return (
|
||||
sessionId: id,
|
||||
turnRunning: value['turn_running'] == true,
|
||||
backgroundTasks: tasks is num && tasks > 0 ? tasks.toInt() : 0,
|
||||
awaitingOperator: awaiting is num && awaiting > 0 ? awaiting.toInt() : 0,
|
||||
seq: seq is num ? seq.toInt() : 0,
|
||||
);
|
||||
}
|
||||
@@ -34,6 +37,7 @@ ChatListActivity? chatListActivityOf(Object? value, {String? sessionId}) {
|
||||
JsonMap chatListActivityRowFields(ChatListActivity activity) => {
|
||||
'running': activity.turnRunning,
|
||||
'background_tasks': activity.backgroundTasks,
|
||||
'awaiting_operator': activity.awaitingOperator,
|
||||
};
|
||||
|
||||
/// Running background tasks of a list row; 0 when unknown.
|
||||
@@ -41,3 +45,10 @@ int chatSessionBackgroundTasks(JsonMap session) {
|
||||
final tasks = session['background_tasks'];
|
||||
return tasks is int && tasks > 0 ? tasks : 0;
|
||||
}
|
||||
|
||||
/// Approvals and questions a list row's chat holds unanswered; 0 when none or
|
||||
/// unknown. Above 0 the agent is blocked until the operator replies.
|
||||
int chatSessionAwaitingOperator(JsonMap session) {
|
||||
final awaiting = session['awaiting_operator'];
|
||||
return awaiting is int && awaiting > 0 ? awaiting : 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// How a chat that is waiting on the operator (an unanswered approval or
|
||||
/// question; the agent is blocked until they reply) stands out in the chat
|
||||
/// list: a ringing bell on the avatar, and a pulsing error-coloured row with a
|
||||
/// solid bar on its leading edge. With reduced motion both hold still.
|
||||
|
||||
/// The accessible name of a waiting chat's bell.
|
||||
String chatAwaitingLabel(int count) => count == 1
|
||||
? 'Waiting for your reply'
|
||||
: 'Waiting for your reply ($count requests)';
|
||||
|
||||
/// The bell badge a waiting chat's avatar wears in place of the spinner.
|
||||
class ChatAwaitingBadge extends StatefulWidget {
|
||||
const ChatAwaitingBadge({super.key, required this.count});
|
||||
|
||||
final int count;
|
||||
|
||||
@override
|
||||
State<ChatAwaitingBadge> createState() => _ChatAwaitingBadgeState();
|
||||
}
|
||||
|
||||
class _ChatAwaitingBadgeState extends State<ChatAwaitingBadge>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _ring = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1400),
|
||||
);
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
if (still) {
|
||||
_ring.stop();
|
||||
_ring.value = 0;
|
||||
} else if (!_ring.isAnimating) {
|
||||
_ring.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ring.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Semantics(
|
||||
key: const Key('chat-row-awaiting'),
|
||||
label: chatAwaitingLabel(widget.count),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.error,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: scheme.surface, width: 2),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: AnimatedBuilder(
|
||||
animation: _ring,
|
||||
// A bell rings in short swings, then rests for the rest of the beat.
|
||||
builder: (context, child) {
|
||||
final t = _ring.value;
|
||||
final swing = t < 0.4
|
||||
? 0.45 * (1 - t / 0.4) * (t * 10 % 2 < 1 ? 1 : -1)
|
||||
: 0.0;
|
||||
return Transform.rotate(angle: swing, child: child);
|
||||
},
|
||||
child: Icon(
|
||||
Icons.notifications_active,
|
||||
size: 18,
|
||||
color: scheme.onError,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The waiting chat's row: a pulsing error-container tint and a solid error
|
||||
/// bar on the leading edge, over the row's own content.
|
||||
class ChatAwaitingHighlight extends StatefulWidget {
|
||||
const ChatAwaitingHighlight({
|
||||
super.key,
|
||||
required this.waiting,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool waiting;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<ChatAwaitingHighlight> createState() => _ChatAwaitingHighlightState();
|
||||
}
|
||||
|
||||
class _ChatAwaitingHighlightState extends State<ChatAwaitingHighlight>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _pulse = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1100),
|
||||
);
|
||||
bool _still = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
_sync();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChatAwaitingHighlight oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_sync();
|
||||
}
|
||||
|
||||
void _sync() {
|
||||
if (widget.waiting && !_still) {
|
||||
if (!_pulse.isAnimating) _pulse.repeat(reverse: true);
|
||||
} else {
|
||||
_pulse.stop();
|
||||
_pulse.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pulse.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.waiting) return widget.child;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: RepaintBoundary(
|
||||
child: AnimatedBuilder(
|
||||
animation: _pulse,
|
||||
builder: (context, _) => DecoratedBox(
|
||||
key: const Key('chat-row-awaiting-highlight'),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.errorContainer.withValues(
|
||||
alpha: 0.35 + 0.45 * _pulse.value,
|
||||
),
|
||||
border: BorderDirectional(
|
||||
start: BorderSide(color: scheme.error, width: 5),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
widget.child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,14 @@ class ChatCompactAvatar extends StatelessWidget {
|
||||
required this.visible,
|
||||
required this.running,
|
||||
required this.backgroundTasks,
|
||||
this.awaitingOperator = 0,
|
||||
required this.unread,
|
||||
});
|
||||
final String title;
|
||||
final Color color;
|
||||
final bool active, visible, running, unread;
|
||||
final int backgroundTasks;
|
||||
final int awaitingOperator;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Stack(
|
||||
@@ -46,6 +48,7 @@ class ChatCompactAvatar extends StatelessWidget {
|
||||
if (chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
)
|
||||
case final badge?)
|
||||
PositionedDirectional(bottom: -2, end: -3, child: badge),
|
||||
|
||||
@@ -66,6 +66,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
final unread = controller.isUnseen(row);
|
||||
final running = row['running'] == true;
|
||||
final backgroundTasks = chatSessionBackgroundTasks(row);
|
||||
final awaitingOperator = chatSessionAwaitingOperator(row);
|
||||
final title = chatSessionTitle(row);
|
||||
final machineName =
|
||||
ServerContext.nameFor(context, '${row['_server_id'] ?? ''}') ??
|
||||
@@ -97,6 +98,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
active: selected,
|
||||
visible: visible,
|
||||
running: running,
|
||||
awaitingOperator: awaitingOperator,
|
||||
backgroundTasks: backgroundTasks,
|
||||
unread: unread,
|
||||
),
|
||||
@@ -141,6 +143,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
active: false,
|
||||
visible: false,
|
||||
running: running,
|
||||
awaitingOperator: awaitingOperator,
|
||||
backgroundTasks: backgroundTasks,
|
||||
unread: unread,
|
||||
),
|
||||
|
||||
@@ -16,9 +16,11 @@ class ChatSessionStateLine extends StatelessWidget {
|
||||
required this.running,
|
||||
required this.backgroundTasks,
|
||||
required this.unread,
|
||||
this.awaitingOperator = 0,
|
||||
});
|
||||
final bool active, visible, running, unread;
|
||||
final int backgroundTasks;
|
||||
final int awaitingOperator;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -32,10 +34,28 @@ class ChatSessionStateLine extends StatelessWidget {
|
||||
(Icons.pending_actions, '$backgroundTasks background'),
|
||||
if (unread) (Icons.mark_chat_unread_outlined, 'New'),
|
||||
];
|
||||
final error = Theme.of(context).colorScheme.error;
|
||||
return Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
if (awaitingOperator > 0)
|
||||
Row(
|
||||
key: const Key('chat-row-awaiting-label'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.notifications_active, size: 16, color: error),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
awaitingOperator == 1
|
||||
? 'Waiting for you'
|
||||
: 'Waiting for you ($awaitingOperator)',
|
||||
style: TextStyle(color: error, fontWeight: FontWeight.w800),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (final (icon, label) in entries)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -66,10 +86,12 @@ class ChatSessionSubtitle extends StatelessWidget {
|
||||
required this.running,
|
||||
required this.backgroundTasks,
|
||||
required this.unread,
|
||||
this.awaitingOperator = 0,
|
||||
});
|
||||
final String metadata;
|
||||
final String? machineName;
|
||||
final bool closed, active, visible, running, unread;
|
||||
final int awaitingOperator;
|
||||
final int backgroundTasks;
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
@@ -93,7 +115,12 @@ class ChatSessionSubtitle extends StatelessWidget {
|
||||
),
|
||||
style: TextStyle(color: chatMetadataForeground(context)),
|
||||
),
|
||||
if (active || visible || running || backgroundTasks > 0 || unread)
|
||||
if (active ||
|
||||
visible ||
|
||||
running ||
|
||||
backgroundTasks > 0 ||
|
||||
unread ||
|
||||
awaitingOperator > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: ChatSessionStateLine(
|
||||
@@ -102,6 +129,7 @@ class ChatSessionSubtitle extends StatelessWidget {
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
unread: unread,
|
||||
awaitingOperator: awaitingOperator,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -203,7 +203,8 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
for (final row in _sessions)
|
||||
if ('${row['id'] ?? ''}' == id &&
|
||||
(row['running'] != fields['running'] ||
|
||||
row['background_tasks'] != fields['background_tasks']))
|
||||
row['background_tasks'] != fields['background_tasks'] ||
|
||||
row['awaiting_operator'] != fields['awaiting_operator']))
|
||||
() {
|
||||
changed = true;
|
||||
return {...row, ...fields};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../ui/status/app_spinner.dart';
|
||||
import 'chat_awaiting.dart';
|
||||
|
||||
/// The corner badge a chat's avatar wears for its live activity: the
|
||||
/// platform's activity indicator while a turn runs; otherwise, while
|
||||
@@ -8,7 +9,10 @@ import '../../../../ui/status/app_spinner.dart';
|
||||
Widget? chatSessionActivityBadge({
|
||||
required bool running,
|
||||
required int backgroundTasks,
|
||||
int awaitingOperator = 0,
|
||||
}) {
|
||||
// Waiting on the operator outranks everything: the agent is blocked.
|
||||
if (awaitingOperator > 0) return ChatAwaitingBadge(count: awaitingOperator);
|
||||
if (running) {
|
||||
return Semantics(
|
||||
key: const Key('chat-row-working'),
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'session_activity_badge.dart';
|
||||
import 'session_harness_icon.dart';
|
||||
import 'session_pane_menu.dart';
|
||||
import 'session_row_style.dart';
|
||||
import 'chat_awaiting.dart';
|
||||
|
||||
/// One chat in the list, in the app's shared row on both hosts: the harness
|
||||
/// avatar, the title with its recency, one muted line, and the actions menu.
|
||||
@@ -109,8 +110,10 @@ class ChatSessionRow extends StatelessWidget {
|
||||
final unread = unseen && !closed;
|
||||
final text = chatSessionSubtitle(session);
|
||||
final updatedAt = _chatSessionInstant(session['updated_at']);
|
||||
final awaiting = closed ? 0 : chatSessionAwaitingOperator(session);
|
||||
final avatar = ChatSessionAvatar(
|
||||
session: session,
|
||||
awaitingOperator: awaiting,
|
||||
running: session['running'] == true && !unseen,
|
||||
backgroundTasks: session['running'] == true
|
||||
? 0
|
||||
@@ -122,78 +125,82 @@ class ChatSessionRow extends StatelessWidget {
|
||||
color: marker,
|
||||
visible: visible,
|
||||
active: selected,
|
||||
child: AppListRow(
|
||||
key: Key('chat-row-$id'),
|
||||
selected: selected,
|
||||
selectedFill: Colors.transparent,
|
||||
emphasized: unread,
|
||||
divider: divider,
|
||||
onTap: () => onOpen(session),
|
||||
onLongPress: selectionOnly ? null : onLongPress,
|
||||
accent: chatColorShade(context, chatSessionColor(session)),
|
||||
showAccentBorder: false,
|
||||
leading: avatar,
|
||||
// The star rides in the title's own text, so a narrow row ellipsises
|
||||
// them together.
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
text: chatSessionTitle(session),
|
||||
children: [
|
||||
if (session['starred'] == true)
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
child: _Star(color: accent),
|
||||
child: ChatAwaitingHighlight(
|
||||
waiting: awaiting > 0,
|
||||
child: AppListRow(
|
||||
key: Key('chat-row-$id'),
|
||||
selected: selected,
|
||||
selectedFill: Colors.transparent,
|
||||
emphasized: unread,
|
||||
divider: divider,
|
||||
onTap: () => onOpen(session),
|
||||
onLongPress: selectionOnly ? null : onLongPress,
|
||||
accent: chatColorShade(context, chatSessionColor(session)),
|
||||
showAccentBorder: false,
|
||||
leading: avatar,
|
||||
// The star rides in the title's own text, so a narrow row ellipsises
|
||||
// them together.
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
text: chatSessionTitle(session),
|
||||
children: [
|
||||
if (session['starred'] == true)
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
child: _Star(color: accent),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
timeWidget: updatedAt == null
|
||||
? null
|
||||
: DefaultTextStyle.merge(
|
||||
style: TextStyle(
|
||||
color: unread ? accent : chatMetadataForeground(context),
|
||||
timeWidget: updatedAt == null
|
||||
? null
|
||||
: DefaultTextStyle.merge(
|
||||
style: TextStyle(
|
||||
color: unread ? accent : chatMetadataForeground(context),
|
||||
),
|
||||
child: RelativeTimeLabel(instant: updatedAt),
|
||||
),
|
||||
// `Closed` leads the line of a closed chat, then the model and folder.
|
||||
subtitle: ChatSessionSubtitle(
|
||||
machineName:
|
||||
ServerContext.nameFor(
|
||||
context,
|
||||
'${session['_server_id'] ?? ''}',
|
||||
) ??
|
||||
session['_server_name'] as String?,
|
||||
metadata: text,
|
||||
closed: closed,
|
||||
active: selected,
|
||||
visible: visible,
|
||||
running: session['running'] == true,
|
||||
backgroundTasks: chatSessionBackgroundTasks(session),
|
||||
awaitingOperator: awaiting,
|
||||
unread: unread,
|
||||
),
|
||||
subtitleTrailing: unread
|
||||
? AppListStatusDot(
|
||||
key: const Key('chat-row-unread'),
|
||||
color: accent,
|
||||
semanticLabel: 'New',
|
||||
size: 10,
|
||||
)
|
||||
: null,
|
||||
menu: selectionOnly
|
||||
? null
|
||||
: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: onAction,
|
||||
allowOpenBeside: onOpenBeside != null,
|
||||
allowOpenBelow: onOpenBelow != null,
|
||||
allowFloat: onFloat != null,
|
||||
paneMenu: paneMenu,
|
||||
),
|
||||
child: RelativeTimeLabel(instant: updatedAt),
|
||||
),
|
||||
// `Closed` leads the line of a closed chat, then the model and folder.
|
||||
subtitle: ChatSessionSubtitle(
|
||||
machineName:
|
||||
ServerContext.nameFor(
|
||||
context,
|
||||
'${session['_server_id'] ?? ''}',
|
||||
) ??
|
||||
session['_server_name'] as String?,
|
||||
metadata: text,
|
||||
closed: closed,
|
||||
active: selected,
|
||||
visible: visible,
|
||||
running: session['running'] == true,
|
||||
backgroundTasks: chatSessionBackgroundTasks(session),
|
||||
unread: unread,
|
||||
),
|
||||
subtitleTrailing: unread
|
||||
? AppListStatusDot(
|
||||
key: const Key('chat-row-unread'),
|
||||
color: accent,
|
||||
semanticLabel: 'New',
|
||||
size: 10,
|
||||
)
|
||||
: null,
|
||||
menu: selectionOnly
|
||||
? null
|
||||
: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: onAction,
|
||||
allowOpenBeside: onOpenBeside != null,
|
||||
allowOpenBelow: onOpenBelow != null,
|
||||
allowFloat: onFloat != null,
|
||||
paneMenu: paneMenu,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -233,12 +240,14 @@ class ChatSessionAvatar extends StatelessWidget {
|
||||
required this.session,
|
||||
this.running = false,
|
||||
this.backgroundTasks = 0,
|
||||
this.awaitingOperator = 0,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
final JsonMap session;
|
||||
final bool running;
|
||||
final int backgroundTasks;
|
||||
final int awaitingOperator;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
@@ -266,6 +275,7 @@ class ChatSessionAvatar extends StatelessWidget {
|
||||
badge: chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
),
|
||||
child: SessionHarnessIcon(session: session, color: mark),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user