agent: Refresh UI when sending first message (#28180)

Agus Zubiaga created

Release Notes:

- Agent Beta: Fixed a delay when sending the first message in a new
thread

Change summary

crates/agent/src/assistant_panel.rs | 16 ++++++++++++++++
crates/agent/src/message_editor.rs  | 10 +++++-----
2 files changed, 21 insertions(+), 5 deletions(-)

Detailed changes

crates/agent/src/assistant_panel.rs 🔗

@@ -170,6 +170,7 @@ pub struct AssistantPanel {
     language_registry: Arc<LanguageRegistry>,
     thread_store: Entity<ThreadStore>,
     thread: Entity<ActiveThread>,
+    _thread_subscription: Subscription,
     message_editor: Entity<MessageEditor>,
     context_store: Entity<assistant_context_editor::ContextStore>,
     context_editor: Option<Entity<ContextEditor>>,
@@ -253,6 +254,12 @@ impl AssistantPanel {
             cx.new(|cx| HistoryStore::new(thread_store.clone(), context_store.clone(), cx));
 
         let active_view = ActiveView::thread(thread.clone(), window, cx);
+        let thread_subscription = cx.subscribe(&thread, |_, _, event, cx| {
+            if let ThreadEvent::MessageAdded(_) = &event {
+                // needed to leave empty state
+                cx.notify();
+            }
+        });
         let thread = cx.new(|cx| {
             ActiveThread::new(
                 thread.clone(),
@@ -273,6 +280,7 @@ impl AssistantPanel {
             language_registry,
             thread_store: thread_store.clone(),
             thread,
+            _thread_subscription: thread_subscription,
             message_editor,
             context_store,
             context_editor: None,
@@ -367,6 +375,14 @@ impl AssistantPanel {
                 cx,
             )
         });
+
+        self._thread_subscription = cx.subscribe(&thread, |_, _, event, cx| {
+            if let ThreadEvent::MessageAdded(_) = &event {
+                // needed to leave empty state
+                cx.notify();
+            }
+        });
+
         self.message_editor = cx.new(|cx| {
             MessageEditor::new(
                 self.fs.clone(),

crates/agent/src/message_editor.rs 🔗

@@ -240,14 +240,14 @@ impl MessageEditor {
                         cx.emit(ThreadEvent::ShowError(load_error));
                     }
                 })
-                .ok();
+                .log_err();
 
             thread
                 .update(cx, |thread, cx| {
                     let context = context_store.read(cx).context().clone();
                     thread.insert_user_message(user_message, context, checkpoint, cx);
                 })
-                .ok();
+                .log_err();
 
             if let Some(wait_for_summaries) = context_store
                 .update(cx, |context_store, cx| context_store.wait_for_summaries(cx))
@@ -257,7 +257,7 @@ impl MessageEditor {
                     this.waiting_for_summaries_to_send = true;
                     cx.notify();
                 })
-                .ok();
+                .log_err();
 
                 wait_for_summaries.await;
 
@@ -265,7 +265,7 @@ impl MessageEditor {
                     this.waiting_for_summaries_to_send = false;
                     cx.notify();
                 })
-                .ok();
+                .log_err();
             }
 
             // Send to model after summaries are done
@@ -273,7 +273,7 @@ impl MessageEditor {
                 .update(cx, |thread, cx| {
                     thread.send_to_model(model, request_kind, cx);
                 })
-                .ok();
+                .log_err();
         })
         .detach();
     }