Show an animated assistant bubble before response tokens

This commit is contained in:
2026-10-25 17:38:56 +00:00
parent a58d820d43
commit 18d43cadc3
12 changed files with 676 additions and 3 deletions
@@ -65,6 +65,7 @@ class ChatThreadController extends ChangeNotifier {
String _cursor = '';
String _nativeTurnId = '';
String? _liveAssistantMessageId;
String? _awaitingResponseOperation;
JsonMap? _usage;
String? _error;
@@ -102,6 +103,7 @@ class ChatThreadController extends ChangeNotifier {
/// Usage-only snapshots refresh Info, not the expensive transcript tree.
Listenable get transcriptChanges => _transcriptChanges;
bool get running => _running;
bool get awaitingResponse => _awaitingResponseOperation != null;
String? get liveAssistantMessageId => _liveAssistantMessageId;
bool get loaded => _loaded;
bool get loading => _loading;
@@ -209,6 +211,7 @@ class ChatThreadController extends ChangeNotifier {
_running = false;
_nativeTurnId = '';
_liveAssistantMessageId = null;
_awaitingResponseOperation = null;
_authoritative = false;
_notify();
await _attach(force: true);
@@ -317,6 +320,11 @@ class ChatThreadController extends ChangeNotifier {
} else if (const ['text', 'reasoning', 'tool'].contains(body['kind'])) {
_liveAssistantMessageId = body['message_id'] as String?;
}
if (body['kind'] == 'step' &&
(body['step'] as Map?)?['status'] == 'ended' &&
(body['step'] as Map?)?['intermediate'] != true) {
_awaitingResponseOperation = null;
}
_nativeTurnId = '${next['nativeTurnId'] ?? ''}';
_notify();
}
@@ -374,6 +382,9 @@ class ChatThreadController extends ChangeNotifier {
/// the history copy replaces it in place instead of moving it.
void insertLocal(JsonMap message) {
if (_disposed) return;
if (!_running) {
_awaitingResponseOperation ??= message['operation_id'] as String?;
}
_messages = [..._messages, message];
_notify();
}
@@ -381,6 +392,9 @@ class ChatThreadController extends ChangeNotifier {
/// Removes a sent turn the server refused.
void removeLocal(String operationId) {
if (_disposed) return;
if (_awaitingResponseOperation == operationId) {
_awaitingResponseOperation = null;
}
final next = [
for (final message in _messages)
if (message['operation_id'] != operationId) message,
@@ -390,6 +404,15 @@ class ChatThreadController extends ChangeNotifier {
_notify();
}
/// An accepted queued prompt waits behind another turn, not its own reply.
void promptAccepted(String operationId, {required bool queued}) {
if (_disposed || !queued || _awaitingResponseOperation != operationId) {
return;
}
_awaitingResponseOperation = null;
_notify();
}
void _notify({bool transcript = true}) {
if (_disposed) return;
notifyListeners();