Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
acp: Indicate when agent is downloading (#57710)
Bennet Bo Fenner8a432f8e0679
diff --git a/crates/agent_servers/src/agent_servers.rs b/crates/agent_servers/src/agent_servers.rsindex 64e97de2299..f95fead18e2 100644--- a/crates/agent_servers/src/agent_servers.rs+++ b/crates/agent_servers/src/agent_servers.rs@@ -30,16 +30,19 @@ pub use acp::{pub struct AgentServerDelegate {store: Entity<AgentServerStore>,new_version_available: Option<watch::Sender<Option<String>>>,+ loading_status: Option<watch::Sender<Option<String>>>,}impl AgentServerDelegate {pub fn new(store: Entity<AgentServerStore>,new_version_tx: Option<watch::Sender<Option<String>>>,+ loading_status_tx: Option<watch::Sender<Option<String>>>,) -> Self {Self {store,new_version_available: new_version_tx,+ loading_status: loading_status_tx,}}}diff --git a/crates/agent_servers/src/custom.rs b/crates/agent_servers/src/custom.rsindex 77c9595f171..358632835f1 100644--- a/crates/agent_servers/src/custom.rs+++ b/crates/agent_servers/src/custom.rs@@ -346,6 +346,9 @@ impl AgentServer for CustomAgentServer {if let Some(new_version_available_tx) = delegate.new_version_available {agent.set_new_version_available_tx(new_version_available_tx);}+ if let Some(loading_status_tx) = delegate.loading_status {+ agent.set_loading_status_tx(loading_status_tx);+ }anyhow::Ok(agent.get_command(vec![], extra_env, &mut cx.to_async()))})??.await?;diff --git a/crates/agent_servers/src/e2e_tests.rs b/crates/agent_servers/src/e2e_tests.rsindex aa9cdb2cc1b..0d26655555b 100644--- a/crates/agent_servers/src/e2e_tests.rs+++ b/crates/agent_servers/src/e2e_tests.rs@@ -436,7 +436,7 @@ pub async fn new_test_thread(cx: &mut TestAppContext,) -> Entity<AcpThread> {let store = project.read_with(cx, |project, _| project.agent_server_store().clone());- let delegate = AgentServerDelegate::new(store, None);+ let delegate = AgentServerDelegate::new(store, None, None);let connection = cx.update(|cx| server.connect(delegate, project.clone(), cx))diff --git a/crates/agent_ui/src/agent_connection_store.rs b/crates/agent_ui/src/agent_connection_store.rsindex fb4ae4b1c4b..66b1ef2c21e 100644--- a/crates/agent_ui/src/agent_connection_store.rs+++ b/crates/agent_ui/src/agent_connection_store.rs@@ -55,6 +55,7 @@ impl AgentConnectionEntry {pub enum AgentConnectionEntryEvent {NewVersionAvailable(SharedString),+ LoadingStatusChanged(Option<SharedString>),}impl EventEmitter<AgentConnectionEntryEvent> for AgentConnectionEntry {}@@ -149,7 +150,8 @@ impl AgentConnectionStore {return entry.clone();}- let (mut new_version_rx, connect_task) = self.start_connection(server, cx);+ let (mut new_version_rx, mut loading_status_rx, connect_task) =+ self.start_connection(server, cx);let connect_task = connect_task.shared();let entry = cx.new(|_cx| AgentConnectionEntry::Connecting {@@ -205,6 +207,7 @@ impl AgentConnectionStore {.detach();cx.spawn({+ let key = key.clone();let entry = entry.downgrade();async move |this, cx| {while let Ok(version) = new_version_rx.recv().await {@@ -234,6 +237,31 @@ impl AgentConnectionStore {}).detach();+ cx.spawn({+ let entry = entry.downgrade();+ async move |this, cx| {+ while let Ok(status) = loading_status_rx.recv().await {+ let status = status.map(SharedString::from);+ let key = key.clone();+ let entry = entry.clone();+ this.update(cx, move |this, cx| {+ if this.entries.get(&key) != entry.upgrade().as_ref() {+ return;+ }++ entry+ .update(cx, move |_entry, cx| {+ cx.emit(AgentConnectionEntryEvent::LoadingStatusChanged(status));+ })+ .ok();+ cx.notify();+ })+ .ok();+ }+ }+ })+ .detach();+entry}@@ -258,13 +286,19 @@ impl AgentConnectionStore {server: Rc<dyn AgentServer>,cx: &mut Context<Self>,) -> (+ Receiver<Option<String>>,Receiver<Option<String>>,Task<Result<AgentConnectedState, LoadError>>,) {let (new_version_tx, new_version_rx) = watch::channel::<Option<String>>(None);+ let (loading_status_tx, loading_status_rx) = watch::channel::<Option<String>>(None);let agent_server_store = self.project.read(cx).agent_server_store().clone();- let delegate = AgentServerDelegate::new(agent_server_store, Some(new_version_tx));+ let delegate = AgentServerDelegate::new(+ agent_server_store,+ Some(new_version_tx),+ Some(loading_status_tx),+ );let connect_task = server.connect(delegate, self.project.clone(), cx);let connect_task = cx.spawn(async move |_this, _cx| match connect_task.await {@@ -274,6 +308,6 @@ impl AgentConnectionStore {Err(err) => Err(LoadError::Other(SharedString::from(err.to_string()))),},});- (new_version_rx, connect_task)+ (new_version_rx, loading_status_rx, connect_task)}}diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rsindex 242d4b3eae9..1caa5089375 100644--- a/crates/agent_ui/src/conversation_view.rs+++ b/crates/agent_ui/src/conversation_view.rs@@ -552,6 +552,7 @@ pub struct ConversationView {notifications: Vec<WindowHandle<AgentNotification>>,notification_subscriptions: HashMap<WindowHandle<AgentNotification>, Vec<Subscription>>,auth_task: Option<Task<()>>,+ loading_status: Option<SharedString>,/// When settings change, use this to see if the theme has changed (which/// causes mermaid diagrams to re-render).last_theme_id: Option<String>,@@ -825,6 +826,7 @@ impl ConversationView {notifications: Vec::new(),notification_subscriptions: HashMap::default(),auth_task: None,+ loading_status: None,last_theme_id: Some(cx.theme().id.clone()),draft_prompt_persist_task: None,code_span_resolver,@@ -871,6 +873,8 @@ impl ConversationView {(session_id, work_dirs, title)});+ self.loading_status = None;+let state = Self::initial_state(self.agent.clone(),self.connection_store.clone(),@@ -934,6 +938,10 @@ impl ConversationView {});}}+ AgentConnectionEntryEvent::LoadingStatusChanged(status) => {+ this.loading_status = status.clone();+ cx.notify();+ }});let connect_result = connection_entry.read(cx).wait_for_connection();@@ -1426,7 +1434,10 @@ impl ConversationView {.active_view().and_then(|v| v.read(cx).thread.read(cx).title()).unwrap_or_else(|| DEFAULT_THREAD_TITLE.into()),- ServerState::Loading { .. } => "Loading…".into(),+ ServerState::Loading { .. } => self+ .loading_status+ .clone()+ .unwrap_or_else(|| "Loading…".into()),ServerState::LoadError { error, .. } => match error {LoadError::Unsupported { .. } => {format!("Upgrade {}", self.agent.agent_id()).into()@@ -3119,21 +3130,27 @@ impl Render for ConversationView {.size_full().bg(cx.theme().colors().panel_background).child(match &self.server_state {- ServerState::Loading { .. } => v_flex()- .flex_1()- .size_full()- .items_center()- .justify_center()- .child(- Label::new("Loading…").color(Color::Muted).with_animation(- "loading-agent-label",- Animation::new(Duration::from_secs(2))- .repeat()- .with_easing(pulsating_between(0.3, 0.7)),- |label, delta| label.alpha(delta),- ),- )- .into_any(),+ ServerState::Loading { .. } => {+ let label_text = self+ .loading_status+ .clone()+ .unwrap_or_else(|| "Loading…".into());+ v_flex()+ .flex_1()+ .size_full()+ .items_center()+ .justify_center()+ .child(+ Label::new(label_text).color(Color::Muted).with_animation(+ "loading-agent-label",+ Animation::new(Duration::from_secs(2))+ .repeat()+ .with_easing(pulsating_between(0.3, 0.7)),+ |label, delta| label.alpha(delta),+ ),+ )+ .into_any()+ }ServerState::LoadError { error: e, .. } => v_flex().flex_1().size_full()diff --git a/crates/agent_ui/src/mention_set.rs b/crates/agent_ui/src/mention_set.rsindex cae882e8c9f..b19a0f2ff40 100644--- a/crates/agent_ui/src/mention_set.rs+++ b/crates/agent_ui/src/mention_set.rs@@ -607,7 +607,7 @@ impl MentionSet {thread_store,));let delegate =- AgentServerDelegate::new(project.read(cx).agent_server_store().clone(), None);+ AgentServerDelegate::new(project.read(cx).agent_server_store().clone(), None, None);let connection = server.connect(delegate, project.clone(), cx);cx.spawn(async move |_, cx| {let agent = connection.await?;diff --git a/crates/project/src/agent_server_store.rs b/crates/project/src/agent_server_store.rsindex 81779906ed6..aac8903bbd9 100644--- a/crates/project/src/agent_server_store.rs+++ b/crates/project/src/agent_server_store.rs@@ -116,7 +116,7 @@ pub enum ExternalAgentSource {pub trait ExternalAgentServer {fn get_command(- &self,+ &mut self,extra_args: Vec<String>,extra_env: HashMap<String, String>,cx: &mut AsyncApp,@@ -132,6 +132,12 @@ pub trait ExternalAgentServer {fn set_new_version_available_tx(&mut self, _tx: watch::Sender<Option<String>>) {}+ fn take_loading_status_tx(&mut self) -> Option<watch::Sender<Option<String>>> {+ None+ }++ fn set_loading_status_tx(&mut self, _tx: watch::Sender<Option<String>>) {}+fn as_any(&self) -> &dyn Any;fn as_any_mut(&mut self) -> &mut dyn Any;}@@ -256,6 +262,7 @@ impl AgentServerStore {pub fn init_remote(session: &AnyProtoClient) {session.add_entity_message_handler(Self::handle_external_agents_updated);+ session.add_entity_message_handler(Self::handle_loading_status_updated);session.add_entity_message_handler(Self::handle_new_version_available);}@@ -334,12 +341,19 @@ impl AgentServerStore {// reconnect when the version changes.let mut old_versioned_agents: HashMap<AgentId,- (SharedString, watch::Sender<Option<String>>),+ (+ SharedString,+ Option<watch::Sender<Option<String>>>,+ Option<watch::Sender<Option<String>>>,+ ),> = HashMap::default();for (name, mut entry) in self.external_agents.drain() {if let Some(version) = entry.server.version().cloned() {- if let Some(tx) = entry.server.take_new_version_available_tx() {- old_versioned_agents.insert(name, (version, tx));+ let new_version_available_tx = entry.server.take_new_version_available_tx();+ let loading_status_tx = entry.server.take_loading_status_tx();+ if new_version_available_tx.is_some() || loading_status_tx.is_some() {+ old_versioned_agents+ .insert(name, (version, new_version_available_tx, loading_status_tx));}}}@@ -393,6 +407,7 @@ impl AgentServerStore {targets: agent.targets.clone(),env: env.clone(),new_version_available_tx: None,+ loading_status_tx: None,})as Box<dyn ExternalAgentServer>,ExternalAgentSource::Registry,@@ -433,7 +448,9 @@ impl AgentServerStore {// changed, notify the active connection to reconnect. Otherwise,// transfer the channel to the new entry so future updates can use it.for (name, entry) in &mut self.external_agents {- let Some((old_version, mut tx)) = old_versioned_agents.remove(name) else {+ let Some((old_version, new_version_available_tx, loading_status_tx)) =+ old_versioned_agents.remove(name)+ else {continue;};let Some(new_version) = entry.server.version() else {@@ -441,9 +458,16 @@ impl AgentServerStore {};if new_version != &old_version {- tx.send(Some(new_version.to_string())).ok();+ if let Some(mut tx) = new_version_available_tx {+ tx.send(Some(new_version.to_string())).ok();+ }} else {- entry.server.set_new_version_available_tx(tx);+ if let Some(tx) = new_version_available_tx {+ entry.server.set_new_version_available_tx(tx);+ }+ if let Some(tx) = loading_status_tx {+ entry.server.set_loading_status_tx(tx);+ }}}@@ -632,6 +656,29 @@ impl AgentServerStore {.detach_and_log_err(cx);new_version_available_tx});+ let loading_status_tx =+ downstream_client+ .clone()+ .map(|(project_id, downstream_client)| {+ let (loading_status_tx, mut loading_status_rx) = watch::channel(None);+ cx.spawn({+ let name = envelope.payload.name.clone();+ async move |_, _| {+ while let Ok(status) = loading_status_rx.recv().await {+ downstream_client.send(+ proto::ExternalAgentLoadingStatusUpdated {+ project_id,+ name: name.clone(),+ status,+ },+ )?;+ }+ anyhow::Ok(())+ }+ })+ .detach_and_log_err(cx);+ loading_status_tx+ });let mut extra_env = HashMap::default();if no_browser {extra_env.insert("NO_BROWSER".to_owned(), "1".to_owned());@@ -639,6 +686,9 @@ impl AgentServerStore {if let Some(new_version_available_tx) = new_version_available_tx {agent.set_new_version_available_tx(new_version_available_tx);}+ if let Some(loading_status_tx) = loading_status_tx {+ agent.set_loading_status_tx(loading_status_tx);+ }anyhow::Ok(agent.get_command(vec![], extra_env, &mut cx.to_async()))})?.await?;@@ -677,12 +727,16 @@ impl AgentServerStore {let mut previous_entries = std::mem::take(&mut this.external_agents);let mut new_version_available_txs = HashMap::default();+ let mut loading_status_txs = HashMap::default();let mut metadata = HashMap::default();for (name, mut entry) in previous_entries.drain() {if let Some(tx) = entry.server.take_new_version_available_tx() {new_version_available_txs.insert(name.clone(), tx);}+ if let Some(tx) = entry.server.take_loading_status_tx() {+ loading_status_txs.insert(name.clone(), tx);+ }metadata.insert(name, (entry.icon, entry.display_name, entry.source));}@@ -713,6 +767,7 @@ impl AgentServerStore {worktree_store: worktree_store.clone(),name: agent_id.clone(),new_version_available_tx: new_version_available_txs.remove(&agent_id),+ loading_status_tx: loading_status_txs.remove(&agent_id),};(agent_id,@@ -730,6 +785,22 @@ impl AgentServerStore {})}+ async fn handle_loading_status_updated(+ this: Entity<Self>,+ envelope: TypedEnvelope<proto::ExternalAgentLoadingStatusUpdated>,+ mut cx: AsyncApp,+ ) -> Result<()> {+ this.update(&mut cx, |this, _| {+ if let Some(entry) = this.external_agents.get_mut(&*envelope.payload.name)+ && let Some(mut tx) = entry.server.take_loading_status_tx()+ {+ tx.send(envelope.payload.status).ok();+ entry.server.set_loading_status_tx(tx);+ }+ });+ Ok(())+ }+async fn handle_new_version_available(this: Entity<Self>,envelope: TypedEnvelope<proto::NewExternalAgentVersionAvailable>,@@ -753,6 +824,7 @@ struct RemoteExternalAgentServer {worktree_store: Entity<WorktreeStore>,name: AgentId,new_version_available_tx: Option<watch::Sender<Option<String>>>,+ loading_status_tx: Option<watch::Sender<Option<String>>>,}impl ExternalAgentServer for RemoteExternalAgentServer {@@ -764,8 +836,16 @@ impl ExternalAgentServer for RemoteExternalAgentServer {self.new_version_available_tx = Some(tx);}+ fn take_loading_status_tx(&mut self) -> Option<watch::Sender<Option<String>>> {+ self.loading_status_tx.take()+ }++ fn set_loading_status_tx(&mut self, tx: watch::Sender<Option<String>>) {+ self.loading_status_tx = Some(tx);+ }+fn get_command(- &self,+ &mut self,extra_args: Vec<String>,extra_env: HashMap<String, String>,cx: &mut AsyncApp,@@ -980,6 +1060,7 @@ struct LocalRegistryArchiveAgent {targets: HashMap<String, RegistryTargetConfig>,env: HashMap<String, String>,new_version_available_tx: Option<watch::Sender<Option<String>>>,+ loading_status_tx: Option<watch::Sender<Option<String>>>,}impl ExternalAgentServer for LocalRegistryArchiveAgent {@@ -995,8 +1076,16 @@ impl ExternalAgentServer for LocalRegistryArchiveAgent {self.new_version_available_tx = Some(tx);}+ fn take_loading_status_tx(&mut self) -> Option<watch::Sender<Option<String>>> {+ self.loading_status_tx.take()+ }++ fn set_loading_status_tx(&mut self, tx: watch::Sender<Option<String>>) {+ self.loading_status_tx = Some(tx);+ }+fn get_command(- &self,+ &mut self,extra_args: Vec<String>,extra_env: HashMap<String, String>,cx: &mut AsyncApp,@@ -1009,6 +1098,7 @@ impl ExternalAgentServer for LocalRegistryArchiveAgent {let targets = self.targets.clone();let settings_env = self.env.clone();let version = self.version.clone();+ let loading_status_tx = self.loading_status_tx.take();cx.spawn(async move |cx| {let mut env = project_environment@@ -1063,6 +1153,12 @@ impl ExternalAgentServer for LocalRegistryArchiveAgent {versioned_archive_cache_dir(&dir, Some(version.as_ref()), archive_url);if !fs.is_dir(&version_dir).await {+ let mut loading_status_tx = loading_status_tx;+ if let Some(tx) = loading_status_tx.as_mut() {+ tx.send(Some(format!("Installing {}…", version.as_ref())))+ .ok();+ }+let sha256 = if let Some(provided_sha) = &target_config.sha256 {Some(provided_sha.clone())} else if let Some(github_archive) = github_release_archive_from_url(archive_url) {@@ -1188,7 +1284,7 @@ impl ExternalAgentServer for LocalRegistryNpxAgent {}fn get_command(- &self,+ &mut self,extra_args: Vec<String>,extra_env: HashMap<String, String>,cx: &mut AsyncApp,@@ -1292,7 +1388,7 @@ struct LocalCustomAgent {impl ExternalAgentServer for LocalCustomAgent {fn get_command(- &self,+ &mut self,extra_args: Vec<String>,extra_env: HashMap<String, String>,cx: &mut AsyncApp,diff --git a/crates/proto/proto/ai.proto b/crates/proto/proto/ai.protoindex 20c87d830a6..4309847c1be 100644--- a/crates/proto/proto/ai.proto+++ b/crates/proto/proto/ai.proto@@ -61,6 +61,7 @@ message ExternalAgentLoadingStatusUpdated {uint64 project_id = 1;string name = 2;reserved 3;+ optional string status = 4;}message NewExternalAgentVersionAvailable {