From f3210fba960efa0c3fdd23c450a2d75837982ea9 Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Thu, 28 Sep 2023 13:09:05 -0700 Subject: [PATCH] Add _isWaitingForAgentResponse Property to ChatViewModel A new property named _isWaitingForAgentResponse has been introduced to the ChatViewModel class to track the loading state when waiting for the agent's response. This boolean property is set to true when a chat message is being sent and reverts to false upon completion, whether successful or not. The notifyListeners() method is invoked to update the UI accordingly. This enhancement facilitates the display of a loading indicator, offering users visual feedback during the wait time for agent responses. --- frontend/lib/viewmodels/chat_viewmodel.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/lib/viewmodels/chat_viewmodel.dart b/frontend/lib/viewmodels/chat_viewmodel.dart index af80aba3..c33d827f 100644 --- a/frontend/lib/viewmodels/chat_viewmodel.dart +++ b/frontend/lib/viewmodels/chat_viewmodel.dart @@ -10,6 +10,10 @@ class ChatViewModel with ChangeNotifier { List _chats = []; String? _currentTaskId; + bool _isWaitingForAgentResponse = false; + + bool get isWaitingForAgentResponse => _isWaitingForAgentResponse; + bool _isContinuousMode = false; bool get isContinuousMode => _isContinuousMode; @@ -108,6 +112,9 @@ class ChatViewModel with ChangeNotifier { print("Error: Task ID is not set."); return; } + _isWaitingForAgentResponse = true; + notifyListeners(); + try { // Create the request body for executing the step StepRequestBody requestBody = StepRequestBody(input: message); @@ -163,6 +170,9 @@ class ChatViewModel with ChangeNotifier { // TODO: Bubble up errors to UI print("Error sending chat: $error"); // TODO: Handle additional error scenarios or log them as required + } finally { + _isWaitingForAgentResponse = false; + notifyListeners(); } }