Keep chat activity stable in one live disclosure and distinguish unread attention
This commit is contained in:
@@ -39,6 +39,8 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
bool _disposed = false;
|
||||
int _generation = 0;
|
||||
Future<void> _persistTail = Future<void>.value();
|
||||
int _runningRevision = 0;
|
||||
final Map<String, ({int revision, bool running})> _runningFrames = {};
|
||||
StreamSubscription<JsonMap>? _frameSubscription;
|
||||
String? activeSessionId;
|
||||
|
||||
@@ -61,6 +63,7 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
|
||||
void _setRunning(String id, bool running) {
|
||||
if (_disposed) return;
|
||||
_runningFrames[id] = (revision: ++_runningRevision, running: running);
|
||||
var changed = false;
|
||||
_sessions = _sessions.map((session) {
|
||||
if ('${session['id'] ?? ''}' != id || session['running'] == running) {
|
||||
@@ -121,6 +124,7 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
void replaceRepository(ChatRepository next) {
|
||||
if (identical(next.gateway, repository.gateway)) return;
|
||||
repository = next;
|
||||
_runningFrames.clear();
|
||||
_listenFrames();
|
||||
refresh();
|
||||
}
|
||||
@@ -135,9 +139,17 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
// must not hide the list or delay the first request.
|
||||
unawaited(_ensureLocal());
|
||||
try {
|
||||
final runningRevision = _runningRevision;
|
||||
final sessions = await repository.sessions();
|
||||
if (generation != _generation) return;
|
||||
_sessions = sessions;
|
||||
_sessions = [
|
||||
for (final row in sessions)
|
||||
if ((_runningFrames['${row['id'] ?? ''}']?.revision ?? 0) >
|
||||
runningRevision)
|
||||
{...row, 'running': _runningFrames['${row['id'] ?? ''}']!.running}
|
||||
else
|
||||
row,
|
||||
];
|
||||
_seedLocal();
|
||||
_loading = false;
|
||||
_notify();
|
||||
|
||||
@@ -48,27 +48,17 @@ ChatSessionFrameEffect? chatSessionFrameEffect(JsonMap frame) {
|
||||
} else if (kind == 'step') {
|
||||
final step = event['step'];
|
||||
if (step is Map) {
|
||||
if (step['status'] == 'started' || step['status'] == 'streamed') {
|
||||
if ([
|
||||
'started',
|
||||
'streamed',
|
||||
'running',
|
||||
'streaming',
|
||||
].contains(step['status'])) {
|
||||
running = true;
|
||||
} else if (step['status'] == 'ended' && step['intermediate'] != true) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
} else if (kind == 'compaction') {
|
||||
final compaction = event['compaction'];
|
||||
if (compaction is Map) {
|
||||
if (compaction['status'] == 'running') running = true;
|
||||
if (compaction['status'] == 'completed' ||
|
||||
compaction['status'] == 'failed') {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
} else if (kind == 'shell') {
|
||||
final shell = event['shell'];
|
||||
if (shell is Map) {
|
||||
if (shell['status'] == 'running') running = true;
|
||||
if (shell['status'] == 'exited') running = false;
|
||||
}
|
||||
}
|
||||
} else if (type == 'chat_permission') {
|
||||
final permission = frame['chat_permission'];
|
||||
|
||||
@@ -82,7 +82,11 @@ class ChatSessionRowContent extends StatelessWidget {
|
||||
children: [
|
||||
if (status != null)
|
||||
_StatusLabel(status: status!, style: statusStyle),
|
||||
if (status == null && loading) _LoadingStatus(),
|
||||
if (status == null && loading)
|
||||
Semantics(
|
||||
label: 'Chat is working',
|
||||
child: const _LoadingStatus(),
|
||||
),
|
||||
for (final line in meta)
|
||||
Text(
|
||||
line,
|
||||
@@ -123,6 +127,7 @@ class ChatSessionRowContent extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _LoadingStatus extends StatelessWidget {
|
||||
const _LoadingStatus();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
|
||||
Reference in New Issue
Block a user