AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat: Add support for temporary chat message
hunteraraujo9021d8392d85
diff --git a/frontend/lib/viewmodels/chat_viewmodel.dart b/frontend/lib/viewmodels/chat_viewmodel.dartindex bd42964e20..294a3b77c5 100644--- a/frontend/lib/viewmodels/chat_viewmodel.dart+++ b/frontend/lib/viewmodels/chat_viewmodel.dart@@ -95,7 +95,9 @@ class ChatViewModel with ChangeNotifier {}// Assign the chats list- _chats = chats;+ if (chats.length > 0) {+ _chats = chats;+ }// Notify listeners to rebuild UInotifyListeners();@@ -154,6 +156,9 @@ class ChatViewModel with ChangeNotifier {_chats.add(agentChat);+ // Remove the temporary message+ removeTemporaryMessage();+// Notify UI of the new chatsnotifyListeners();@@ -170,6 +175,8 @@ class ChatViewModel with ChangeNotifier {print("Chats added for task ID: $_currentTaskId");} catch (e) {+ // Remove the temporary message in case of an error+ removeTemporaryMessage();// TODO: We are bubbling up the full response. Revisit this.rethrow;// TODO: Handle additional error scenarios or log them as required@@ -179,6 +186,25 @@ class ChatViewModel with ChangeNotifier {}}+ void addTemporaryMessage(String message) {+ Chat tempMessage = Chat(+ // You can generate a unique ID or use a placeholder+ id: "TEMP_ID",+ taskId: "TEMP_ID",+ message: message,+ timestamp: DateTime.now(),+ messageType: MessageType.user,+ artifacts: []);++ _chats.add(tempMessage);+ notifyListeners();+ }++ void removeTemporaryMessage() {+ _chats.removeWhere((chat) => chat.id == "TEMP_ID");+ notifyListeners();+ }+/// Downloads an artifact associated with a specific chat.////// [taskId] is the ID of the task.diff --git a/frontend/lib/views/chat/chat_view.dart b/frontend/lib/views/chat/chat_view.dartindex 9e28f6843e..9dac1c1c52 100644--- a/frontend/lib/views/chat/chat_view.dart+++ b/frontend/lib/views/chat/chat_view.dart@@ -113,6 +113,7 @@ class _ChatViewState extends State<ChatView> {padding: const EdgeInsets.all(8.0),child: ChatInputField(onSendPressed: (message) async {+ widget.viewModel.addTemporaryMessage(message);try {if (widget.viewModel.currentTaskId != null) {widget.viewModel.sendChatMessage(