From b1f7133a7b702b1f81cff434e4b9f28a6876d1a6 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Sun, 6 Apr 2025 10:36:10 -0300 Subject: [PATCH] agent: Refresh UI when sending first message (#28180) Release Notes: - Agent Beta: Fixed a delay when sending the first message in a new thread --- crates/agent/src/assistant_panel.rs | 16 ++++++++++++++++ crates/agent/src/message_editor.rs | 10 +++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/agent/src/assistant_panel.rs b/crates/agent/src/assistant_panel.rs index 3a1dcb855a..1f1f7bd00b 100644 --- a/crates/agent/src/assistant_panel.rs +++ b/crates/agent/src/assistant_panel.rs @@ -170,6 +170,7 @@ pub struct AssistantPanel { language_registry: Arc, thread_store: Entity, thread: Entity, + _thread_subscription: Subscription, message_editor: Entity, context_store: Entity, context_editor: Option>, @@ -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(), diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rs index 3cc00c39fb..37f4c63d63 100644 --- a/crates/agent/src/message_editor.rs +++ b/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(); }