Implement Continuous Mode in ChatViewModel
Added a new state variable `_isContinuousMode` to the ChatViewModel to track whether the chat is in continuous mode or not. This state is toggled via a setter and triggers UI updates through `notifyListeners()`. Enhanced the `sendChatMessage` method to automatically send a null message if continuous mode is active, triggering the next step in the chat.pull/5167/head
parent
a7c37da713
commit
5cd1abab94
frontend/lib/viewmodels
|
@ -10,6 +10,14 @@ class ChatViewModel with ChangeNotifier {
|
|||
List<Chat> _chats = [];
|
||||
String? _currentTaskId;
|
||||
|
||||
bool _isContinuousMode = false;
|
||||
|
||||
bool get isContinuousMode => _isContinuousMode;
|
||||
set isContinuousMode(bool value) {
|
||||
_isContinuousMode = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
ChatViewModel(this._chatService);
|
||||
|
||||
/// Returns the current list of chats.
|
||||
|
@ -95,7 +103,7 @@ class ChatViewModel with ChangeNotifier {
|
|||
}
|
||||
|
||||
/// Sends a chat message for a specific task.
|
||||
void sendChatMessage(String message) async {
|
||||
void sendChatMessage(String? message) async {
|
||||
if (_currentTaskId == null) {
|
||||
print("Error: Task ID is not set.");
|
||||
return;
|
||||
|
@ -136,6 +144,10 @@ class ChatViewModel with ChangeNotifier {
|
|||
// Notify UI of the new chats
|
||||
notifyListeners();
|
||||
|
||||
if (_isContinuousMode) {
|
||||
sendChatMessage(null);
|
||||
}
|
||||
|
||||
print("Chats added for task ID: $_currentTaskId");
|
||||
} catch (error) {
|
||||
// TODO: Bubble up errors to UI
|
||||
|
|
Loading…
Reference in New Issue