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';
|
import '../../../core/api_gateway.dart';
|
||||||
|
|
||||||
/// One chat's live activity as the server observes it: a turn in flight and
|
/// One chat's live activity as the server observes it: a turn in flight, how
|
||||||
/// how many background tasks (shells, background commands, subagents) still
|
/// many background tasks (shells, background commands, subagents) still run,
|
||||||
/// run. It rides on each `chat_sessions` row as `activity` and is pushed to
|
/// 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
|
/// 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.
|
/// chat's snapshots across the list and the pushes; the larger one is newer.
|
||||||
typedef ChatListActivity = ({
|
typedef ChatListActivity = ({
|
||||||
String sessionId,
|
String sessionId,
|
||||||
bool turnRunning,
|
bool turnRunning,
|
||||||
int backgroundTasks,
|
int backgroundTasks,
|
||||||
|
int awaitingOperator,
|
||||||
int seq,
|
int seq,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,11 +22,13 @@ ChatListActivity? chatListActivityOf(Object? value, {String? sessionId}) {
|
|||||||
final id = sessionId ?? (named is String ? named : '');
|
final id = sessionId ?? (named is String ? named : '');
|
||||||
if (id.isEmpty) return null;
|
if (id.isEmpty) return null;
|
||||||
final tasks = value['background_tasks'];
|
final tasks = value['background_tasks'];
|
||||||
|
final awaiting = value['awaiting_operator'];
|
||||||
final seq = value['seq'];
|
final seq = value['seq'];
|
||||||
return (
|
return (
|
||||||
sessionId: id,
|
sessionId: id,
|
||||||
turnRunning: value['turn_running'] == true,
|
turnRunning: value['turn_running'] == true,
|
||||||
backgroundTasks: tasks is num && tasks > 0 ? tasks.toInt() : 0,
|
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,
|
seq: seq is num ? seq.toInt() : 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -34,6 +37,7 @@ ChatListActivity? chatListActivityOf(Object? value, {String? sessionId}) {
|
|||||||
JsonMap chatListActivityRowFields(ChatListActivity activity) => {
|
JsonMap chatListActivityRowFields(ChatListActivity activity) => {
|
||||||
'running': activity.turnRunning,
|
'running': activity.turnRunning,
|
||||||
'background_tasks': activity.backgroundTasks,
|
'background_tasks': activity.backgroundTasks,
|
||||||
|
'awaiting_operator': activity.awaitingOperator,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Running background tasks of a list row; 0 when unknown.
|
/// Running background tasks of a list row; 0 when unknown.
|
||||||
@@ -41,3 +45,10 @@ int chatSessionBackgroundTasks(JsonMap session) {
|
|||||||
final tasks = session['background_tasks'];
|
final tasks = session['background_tasks'];
|
||||||
return tasks is int && tasks > 0 ? tasks : 0;
|
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.visible,
|
||||||
required this.running,
|
required this.running,
|
||||||
required this.backgroundTasks,
|
required this.backgroundTasks,
|
||||||
|
this.awaitingOperator = 0,
|
||||||
required this.unread,
|
required this.unread,
|
||||||
});
|
});
|
||||||
final String title;
|
final String title;
|
||||||
final Color color;
|
final Color color;
|
||||||
final bool active, visible, running, unread;
|
final bool active, visible, running, unread;
|
||||||
final int backgroundTasks;
|
final int backgroundTasks;
|
||||||
|
final int awaitingOperator;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Stack(
|
Widget build(BuildContext context) => Stack(
|
||||||
@@ -46,6 +48,7 @@ class ChatCompactAvatar extends StatelessWidget {
|
|||||||
if (chatSessionActivityBadge(
|
if (chatSessionActivityBadge(
|
||||||
running: running,
|
running: running,
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
|
awaitingOperator: awaitingOperator,
|
||||||
)
|
)
|
||||||
case final badge?)
|
case final badge?)
|
||||||
PositionedDirectional(bottom: -2, end: -3, child: badge),
|
PositionedDirectional(bottom: -2, end: -3, child: badge),
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
|||||||
final unread = controller.isUnseen(row);
|
final unread = controller.isUnseen(row);
|
||||||
final running = row['running'] == true;
|
final running = row['running'] == true;
|
||||||
final backgroundTasks = chatSessionBackgroundTasks(row);
|
final backgroundTasks = chatSessionBackgroundTasks(row);
|
||||||
|
final awaitingOperator = chatSessionAwaitingOperator(row);
|
||||||
final title = chatSessionTitle(row);
|
final title = chatSessionTitle(row);
|
||||||
final machineName =
|
final machineName =
|
||||||
ServerContext.nameFor(context, '${row['_server_id'] ?? ''}') ??
|
ServerContext.nameFor(context, '${row['_server_id'] ?? ''}') ??
|
||||||
@@ -97,6 +98,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
|||||||
active: selected,
|
active: selected,
|
||||||
visible: visible,
|
visible: visible,
|
||||||
running: running,
|
running: running,
|
||||||
|
awaitingOperator: awaitingOperator,
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
unread: unread,
|
unread: unread,
|
||||||
),
|
),
|
||||||
@@ -141,6 +143,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
|||||||
active: false,
|
active: false,
|
||||||
visible: false,
|
visible: false,
|
||||||
running: running,
|
running: running,
|
||||||
|
awaitingOperator: awaitingOperator,
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
unread: unread,
|
unread: unread,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ class ChatSessionStateLine extends StatelessWidget {
|
|||||||
required this.running,
|
required this.running,
|
||||||
required this.backgroundTasks,
|
required this.backgroundTasks,
|
||||||
required this.unread,
|
required this.unread,
|
||||||
|
this.awaitingOperator = 0,
|
||||||
});
|
});
|
||||||
final bool active, visible, running, unread;
|
final bool active, visible, running, unread;
|
||||||
final int backgroundTasks;
|
final int backgroundTasks;
|
||||||
|
final int awaitingOperator;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -32,10 +34,28 @@ class ChatSessionStateLine extends StatelessWidget {
|
|||||||
(Icons.pending_actions, '$backgroundTasks background'),
|
(Icons.pending_actions, '$backgroundTasks background'),
|
||||||
if (unread) (Icons.mark_chat_unread_outlined, 'New'),
|
if (unread) (Icons.mark_chat_unread_outlined, 'New'),
|
||||||
];
|
];
|
||||||
|
final error = Theme.of(context).colorScheme.error;
|
||||||
return Wrap(
|
return Wrap(
|
||||||
spacing: 10,
|
spacing: 10,
|
||||||
runSpacing: 4,
|
runSpacing: 4,
|
||||||
children: [
|
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)
|
for (final (icon, label) in entries)
|
||||||
Row(
|
Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -66,10 +86,12 @@ class ChatSessionSubtitle extends StatelessWidget {
|
|||||||
required this.running,
|
required this.running,
|
||||||
required this.backgroundTasks,
|
required this.backgroundTasks,
|
||||||
required this.unread,
|
required this.unread,
|
||||||
|
this.awaitingOperator = 0,
|
||||||
});
|
});
|
||||||
final String metadata;
|
final String metadata;
|
||||||
final String? machineName;
|
final String? machineName;
|
||||||
final bool closed, active, visible, running, unread;
|
final bool closed, active, visible, running, unread;
|
||||||
|
final int awaitingOperator;
|
||||||
final int backgroundTasks;
|
final int backgroundTasks;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Column(
|
Widget build(BuildContext context) => Column(
|
||||||
@@ -93,7 +115,12 @@ class ChatSessionSubtitle extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
style: TextStyle(color: chatMetadataForeground(context)),
|
style: TextStyle(color: chatMetadataForeground(context)),
|
||||||
),
|
),
|
||||||
if (active || visible || running || backgroundTasks > 0 || unread)
|
if (active ||
|
||||||
|
visible ||
|
||||||
|
running ||
|
||||||
|
backgroundTasks > 0 ||
|
||||||
|
unread ||
|
||||||
|
awaitingOperator > 0)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 4),
|
padding: const EdgeInsets.only(top: 4),
|
||||||
child: ChatSessionStateLine(
|
child: ChatSessionStateLine(
|
||||||
@@ -102,6 +129,7 @@ class ChatSessionSubtitle extends StatelessWidget {
|
|||||||
running: running,
|
running: running,
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
unread: unread,
|
unread: unread,
|
||||||
|
awaitingOperator: awaitingOperator,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -203,7 +203,8 @@ class ChatSessionsController extends ChangeNotifier {
|
|||||||
for (final row in _sessions)
|
for (final row in _sessions)
|
||||||
if ('${row['id'] ?? ''}' == id &&
|
if ('${row['id'] ?? ''}' == id &&
|
||||||
(row['running'] != fields['running'] ||
|
(row['running'] != fields['running'] ||
|
||||||
row['background_tasks'] != fields['background_tasks']))
|
row['background_tasks'] != fields['background_tasks'] ||
|
||||||
|
row['awaiting_operator'] != fields['awaiting_operator']))
|
||||||
() {
|
() {
|
||||||
changed = true;
|
changed = true;
|
||||||
return {...row, ...fields};
|
return {...row, ...fields};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../../../ui/status/app_spinner.dart';
|
import '../../../../ui/status/app_spinner.dart';
|
||||||
|
import 'chat_awaiting.dart';
|
||||||
|
|
||||||
/// The corner badge a chat's avatar wears for its live activity: the
|
/// The corner badge a chat's avatar wears for its live activity: the
|
||||||
/// platform's activity indicator while a turn runs; otherwise, while
|
/// platform's activity indicator while a turn runs; otherwise, while
|
||||||
@@ -8,7 +9,10 @@ import '../../../../ui/status/app_spinner.dart';
|
|||||||
Widget? chatSessionActivityBadge({
|
Widget? chatSessionActivityBadge({
|
||||||
required bool running,
|
required bool running,
|
||||||
required int backgroundTasks,
|
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) {
|
if (running) {
|
||||||
return Semantics(
|
return Semantics(
|
||||||
key: const Key('chat-row-working'),
|
key: const Key('chat-row-working'),
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import 'session_activity_badge.dart';
|
|||||||
import 'session_harness_icon.dart';
|
import 'session_harness_icon.dart';
|
||||||
import 'session_pane_menu.dart';
|
import 'session_pane_menu.dart';
|
||||||
import 'session_row_style.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
|
/// 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.
|
/// 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 unread = unseen && !closed;
|
||||||
final text = chatSessionSubtitle(session);
|
final text = chatSessionSubtitle(session);
|
||||||
final updatedAt = _chatSessionInstant(session['updated_at']);
|
final updatedAt = _chatSessionInstant(session['updated_at']);
|
||||||
|
final awaiting = closed ? 0 : chatSessionAwaitingOperator(session);
|
||||||
final avatar = ChatSessionAvatar(
|
final avatar = ChatSessionAvatar(
|
||||||
session: session,
|
session: session,
|
||||||
|
awaitingOperator: awaiting,
|
||||||
running: session['running'] == true && !unseen,
|
running: session['running'] == true && !unseen,
|
||||||
backgroundTasks: session['running'] == true
|
backgroundTasks: session['running'] == true
|
||||||
? 0
|
? 0
|
||||||
@@ -122,78 +125,82 @@ class ChatSessionRow extends StatelessWidget {
|
|||||||
color: marker,
|
color: marker,
|
||||||
visible: visible,
|
visible: visible,
|
||||||
active: selected,
|
active: selected,
|
||||||
child: AppListRow(
|
child: ChatAwaitingHighlight(
|
||||||
key: Key('chat-row-$id'),
|
waiting: awaiting > 0,
|
||||||
selected: selected,
|
child: AppListRow(
|
||||||
selectedFill: Colors.transparent,
|
key: Key('chat-row-$id'),
|
||||||
emphasized: unread,
|
selected: selected,
|
||||||
divider: divider,
|
selectedFill: Colors.transparent,
|
||||||
onTap: () => onOpen(session),
|
emphasized: unread,
|
||||||
onLongPress: selectionOnly ? null : onLongPress,
|
divider: divider,
|
||||||
accent: chatColorShade(context, chatSessionColor(session)),
|
onTap: () => onOpen(session),
|
||||||
showAccentBorder: false,
|
onLongPress: selectionOnly ? null : onLongPress,
|
||||||
leading: avatar,
|
accent: chatColorShade(context, chatSessionColor(session)),
|
||||||
// The star rides in the title's own text, so a narrow row ellipsises
|
showAccentBorder: false,
|
||||||
// them together.
|
leading: avatar,
|
||||||
title: Text.rich(
|
// The star rides in the title's own text, so a narrow row ellipsises
|
||||||
TextSpan(
|
// them together.
|
||||||
text: chatSessionTitle(session),
|
title: Text.rich(
|
||||||
children: [
|
TextSpan(
|
||||||
if (session['starred'] == true)
|
text: chatSessionTitle(session),
|
||||||
WidgetSpan(
|
children: [
|
||||||
alignment: PlaceholderAlignment.middle,
|
if (session['starred'] == true)
|
||||||
child: Padding(
|
WidgetSpan(
|
||||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
alignment: PlaceholderAlignment.middle,
|
||||||
child: _Star(color: accent),
|
child: Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||||
|
child: _Star(color: accent),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
timeWidget: updatedAt == null
|
||||||
timeWidget: updatedAt == null
|
? null
|
||||||
? null
|
: DefaultTextStyle.merge(
|
||||||
: DefaultTextStyle.merge(
|
style: TextStyle(
|
||||||
style: TextStyle(
|
color: unread ? accent : chatMetadataForeground(context),
|
||||||
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,
|
required this.session,
|
||||||
this.running = false,
|
this.running = false,
|
||||||
this.backgroundTasks = 0,
|
this.backgroundTasks = 0,
|
||||||
|
this.awaitingOperator = 0,
|
||||||
this.selected = false,
|
this.selected = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final JsonMap session;
|
final JsonMap session;
|
||||||
final bool running;
|
final bool running;
|
||||||
final int backgroundTasks;
|
final int backgroundTasks;
|
||||||
|
final int awaitingOperator;
|
||||||
final bool selected;
|
final bool selected;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -266,6 +275,7 @@ class ChatSessionAvatar extends StatelessWidget {
|
|||||||
badge: chatSessionActivityBadge(
|
badge: chatSessionActivityBadge(
|
||||||
running: running,
|
running: running,
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
|
awaitingOperator: awaitingOperator,
|
||||||
),
|
),
|
||||||
child: SessionHarnessIcon(session: session, color: mark),
|
child: SessionHarnessIcon(session: session, color: mark),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/domain/chat_list_activity.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/ui/sessions/chat_awaiting.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/ui/sessions/session_activity_badge.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('the list activity carries what waits on the operator', () {
|
||||||
|
final activity = chatListActivityOf({
|
||||||
|
'session_id': 's',
|
||||||
|
'turn_running': true,
|
||||||
|
'awaiting_operator': 2,
|
||||||
|
'seq': 5,
|
||||||
|
})!;
|
||||||
|
expect(activity.awaitingOperator, 2);
|
||||||
|
final row = chatListActivityRowFields(activity);
|
||||||
|
expect(chatSessionAwaitingOperator(row), 2);
|
||||||
|
expect(chatSessionAwaitingOperator(const {}), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('waiting on the operator outranks the working spinner', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Center(
|
||||||
|
child: chatSessionActivityBadge(
|
||||||
|
running: true,
|
||||||
|
backgroundTasks: 1,
|
||||||
|
awaitingOperator: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(find.byKey(const Key('chat-row-awaiting')), findsOneWidget);
|
||||||
|
expect(find.byKey(const Key('chat-row-working')), findsNothing);
|
||||||
|
expect(find.bySemanticsLabel('Waiting for your reply'), findsOneWidget);
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('a waiting row pulses; reduced motion holds it still', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
Widget host({required bool still}) => MaterialApp(
|
||||||
|
home: MediaQuery(
|
||||||
|
data: MediaQueryData(disableAnimations: still),
|
||||||
|
child: const Scaffold(
|
||||||
|
body: ChatAwaitingHighlight(
|
||||||
|
waiting: true,
|
||||||
|
child: SizedBox(height: 60, child: Text('Caplens PI')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Color tint() =>
|
||||||
|
((tester
|
||||||
|
.widget<DecoratedBox>(
|
||||||
|
find.byKey(const Key('chat-row-awaiting-highlight')),
|
||||||
|
)
|
||||||
|
.decoration
|
||||||
|
as BoxDecoration)
|
||||||
|
.color!);
|
||||||
|
await tester.pumpWidget(host(still: false));
|
||||||
|
final first = tint();
|
||||||
|
await tester.pump(const Duration(milliseconds: 550));
|
||||||
|
expect(tint(), isNot(first));
|
||||||
|
|
||||||
|
await tester.pumpWidget(host(still: true));
|
||||||
|
await tester.pump();
|
||||||
|
final held = tint();
|
||||||
|
await tester.pump(const Duration(milliseconds: 550));
|
||||||
|
expect(tint(), held);
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -221,12 +221,19 @@ void main() {
|
|||||||
'background_tasks': 2,
|
'background_tasks': 2,
|
||||||
'seq': 9,
|
'seq': 9,
|
||||||
}, sessionId: 's1'),
|
}, sessionId: 's1'),
|
||||||
(sessionId: 's1', turnRunning: true, backgroundTasks: 2, seq: 9),
|
(
|
||||||
|
sessionId: 's1',
|
||||||
|
turnRunning: true,
|
||||||
|
backgroundTasks: 2,
|
||||||
|
awaitingOperator: 0,
|
||||||
|
seq: 9,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(chatListActivityOf({'session_id': 's2'}), (
|
expect(chatListActivityOf({'session_id': 's2'}), (
|
||||||
sessionId: 's2',
|
sessionId: 's2',
|
||||||
turnRunning: false,
|
turnRunning: false,
|
||||||
backgroundTasks: 0,
|
backgroundTasks: 0,
|
||||||
|
awaitingOperator: 0,
|
||||||
seq: 0,
|
seq: 0,
|
||||||
));
|
));
|
||||||
expect(chatListActivityOf({'background_tasks': 1}), isNull);
|
expect(chatListActivityOf({'background_tasks': 1}), isNull);
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ JsonMap? _activityFor(int i) {
|
|||||||
return switch (i) {
|
return switch (i) {
|
||||||
0 => {'turn_running': true, 'background_tasks': 1, 'seq': 3},
|
0 => {'turn_running': true, 'background_tasks': 1, 'seq': 3},
|
||||||
1 => {'background_tasks': 2, 'seq': 2},
|
1 => {'background_tasks': 2, 'seq': 2},
|
||||||
|
// A turn blocked on the operator: an approval and a question unanswered.
|
||||||
|
2 => {'turn_running': true, 'awaiting_operator': 2, 'seq': 4},
|
||||||
_ => {'seq': 1},
|
_ => {'seq': 1},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,7 +397,10 @@ type ChatActivity struct {
|
|||||||
SessionID string `json:"session_id,omitempty"`
|
SessionID string `json:"session_id,omitempty"`
|
||||||
TurnRunning bool `json:"turn_running,omitempty"`
|
TurnRunning bool `json:"turn_running,omitempty"`
|
||||||
BackgroundTasks int `json:"background_tasks,omitempty"`
|
BackgroundTasks int `json:"background_tasks,omitempty"`
|
||||||
Seq int64 `json:"seq,omitempty"`
|
// AwaitingOperator counts the approvals and questions the session holds
|
||||||
|
// unanswered: the agent is blocked on the operator until they reply.
|
||||||
|
AwaitingOperator int `json:"awaiting_operator,omitempty"`
|
||||||
|
Seq int64 `json:"seq,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat export formats accepted by chat_export.
|
// Chat export formats accepted by chat_export.
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import (
|
|||||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chat list activity: every listed chat shows whether its turn is running and
|
// Chat list activity: every listed chat shows whether its turn is running,
|
||||||
// whether background tasks (shells, background commands, subagents) are still
|
// whether background tasks (shells, background commands, subagents) are still
|
||||||
// running after the turn. Room frames reach only the connections that opened
|
// running after the turn, and whether the agent is waiting on the operator (an
|
||||||
|
// unanswered approval or question). Room frames reach only the connections that opened
|
||||||
// that chat, so the hub keeps a small per-session summary and pushes each
|
// that chat, so the hub keeps a small per-session summary and pushes each
|
||||||
// change to every connection as chat_activity, and chat_sessions carries the
|
// change to every connection as chat_activity, and chat_sessions carries the
|
||||||
// current summary on each row.
|
// current summary on each row.
|
||||||
@@ -33,6 +34,7 @@ func (h *chatHub) chatActivityLocked(sessionID string) protocol.ChatActivity {
|
|||||||
}
|
}
|
||||||
activity.TurnRunning = room.running || room.observedTurn
|
activity.TurnRunning = room.running || room.observedTurn
|
||||||
activity.BackgroundTasks = h.backgroundTasksLocked(sessionID)
|
activity.BackgroundTasks = h.backgroundTasksLocked(sessionID)
|
||||||
|
activity.AwaitingOperator = len(room.pending) + len(room.forms)
|
||||||
return activity
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +58,9 @@ func (h *chatHub) noteActivityLocked(sessionID string) {
|
|||||||
h.rememberLiveLocked(sessionID)
|
h.rememberLiveLocked(sessionID)
|
||||||
next := h.chatActivityLocked(sessionID)
|
next := h.chatActivityLocked(sessionID)
|
||||||
previous := h.activity[sessionID]
|
previous := h.activity[sessionID]
|
||||||
if previous.TurnRunning == next.TurnRunning && previous.BackgroundTasks == next.BackgroundTasks {
|
if previous.TurnRunning == next.TurnRunning &&
|
||||||
|
previous.BackgroundTasks == next.BackgroundTasks &&
|
||||||
|
previous.AwaitingOperator == next.AwaitingOperator {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if h.activity == nil {
|
if h.activity == nil {
|
||||||
|
|||||||
@@ -185,3 +185,43 @@ func TestChatBackgroundTasksKeepUnattendedRoom(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An unanswered approval or question is the operator's to act on: the list
|
||||||
|
// activity counts it, and answering it clears the count.
|
||||||
|
func TestChatActivityCountsWhatAwaitsTheOperator(t *testing.T) {
|
||||||
|
h := newChatHub()
|
||||||
|
defer func() {
|
||||||
|
h.mu.Lock()
|
||||||
|
for _, room := range h.rooms {
|
||||||
|
room.cancel()
|
||||||
|
}
|
||||||
|
h.mu.Unlock()
|
||||||
|
}()
|
||||||
|
const id = "ses_wait"
|
||||||
|
awaiting := func() int {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
return h.activity[id].AwaitingOperator
|
||||||
|
}
|
||||||
|
h.mu.Lock()
|
||||||
|
h.roomLocked(id)
|
||||||
|
h.mu.Unlock()
|
||||||
|
|
||||||
|
h.pushPermission(id, protocol.ChatPermissionFrame{SessionID: id, RequestID: "perm_1"})
|
||||||
|
if got := awaiting(); got != 1 {
|
||||||
|
t.Fatalf("a pending approval: awaiting=%d", got)
|
||||||
|
}
|
||||||
|
h.mu.Lock()
|
||||||
|
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1"}})
|
||||||
|
h.mu.Unlock()
|
||||||
|
if got := awaiting(); got != 2 {
|
||||||
|
t.Fatalf("an approval and a question: awaiting=%d", got)
|
||||||
|
}
|
||||||
|
h.confirmPermission(id, "perm_1", "c", "allow")
|
||||||
|
h.mu.Lock()
|
||||||
|
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1", Resolved: true}})
|
||||||
|
h.mu.Unlock()
|
||||||
|
if got := awaiting(); got != 0 {
|
||||||
|
t.Fatalf("both answered: awaiting=%d", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ func (h *chatHub) applyLocked(frame protocol.ChatEventFrame) {
|
|||||||
room.forms = append(room.forms, *frame.Form)
|
room.forms = append(room.forms, *frame.Form)
|
||||||
}
|
}
|
||||||
h.rememberLiveLocked(frame.SessionID)
|
h.rememberLiveLocked(frame.SessionID)
|
||||||
|
h.noteActivityLocked(frame.SessionID)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ func (h *chatHub) confirmPermission(sessionID, requestID, client, decision strin
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
h.noteActivityLocked(sessionID)
|
||||||
for _, sub := range room.subs {
|
for _, sub := range room.subs {
|
||||||
targets = append(targets, sub)
|
targets = append(targets, sub)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -718,6 +718,7 @@ func (h *chatHub) pushPermission(sessionID string, frame protocol.ChatPermission
|
|||||||
if len(room.pending) > chatRoomPendingLimit {
|
if len(room.pending) > chatRoomPendingLimit {
|
||||||
room.pending = room.pending[len(room.pending)-chatRoomPendingLimit:]
|
room.pending = room.pending[len(room.pending)-chatRoomPendingLimit:]
|
||||||
}
|
}
|
||||||
|
h.noteActivityLocked(sessionID)
|
||||||
for _, sub := range room.subs {
|
for _, sub := range room.subs {
|
||||||
targets = append(targets, sub)
|
targets = append(targets, sub)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user