From 4312c864075de1e67949f7caab594cb8ae372679 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Thu, 12 Mar 2026 12:17:07 +0100 Subject: [PATCH] Remove agent server argument when requesting connection --- crates/agent_ui/src/agent_connection_store.rs | 26 ++++++++--- crates/agent_ui/src/agent_panel.rs | 10 ++--- crates/agent_ui/src/connection_view.rs | 45 +++++++++++-------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/crates/agent_ui/src/agent_connection_store.rs b/crates/agent_ui/src/agent_connection_store.rs index 936b9b7a2de984f20f59c8f050ecb3bff1386595..2d0e4d2e6ef635dbdcc62e8f8922dcf3db94ace4 100644 --- a/crates/agent_ui/src/agent_connection_store.rs +++ b/crates/agent_ui/src/agent_connection_store.rs @@ -1,6 +1,7 @@ use std::rc::Rc; use acp_thread::{AgentConnection, LoadError}; +use agent::ThreadStore; use agent_servers::{AgentServer, AgentServerDelegate}; use anyhow::Result; use collections::HashMap; @@ -53,16 +54,22 @@ impl EventEmitter for AgentConnectionEntry {} pub struct AgentConnectionStore { project: Entity, + thread_store: Entity, entries: HashMap>, _subscriptions: Vec, } impl AgentConnectionStore { - pub fn new(project: Entity, cx: &mut Context) -> Self { + pub fn new( + project: Entity, + thread_store: Entity, + cx: &mut Context, + ) -> Self { let agent_server_store = project.read(cx).agent_server_store().clone(); let subscription = cx.subscribe(&agent_server_store, Self::handle_agent_servers_updated); Self { project, + thread_store, entries: HashMap::default(), _subscriptions: vec![subscription], } @@ -74,11 +81,15 @@ impl AgentConnectionStore { pub fn request_connection( &mut self, - key: ExternalAgent, - server: Rc, + agent: ExternalAgent, cx: &mut Context, ) -> Entity { - self.entries.get(&key).cloned().unwrap_or_else(|| { + self.entries.get(&agent).cloned().unwrap_or_else(|| { + let server = agent.server( + self.project.read(cx).fs().clone(), + self.thread_store.clone(), + ); + let (mut new_version_rx, connect_task) = self.start_connection(server.clone(), cx); let connect_task = connect_task.shared(); @@ -86,10 +97,10 @@ impl AgentConnectionStore { connect_task: connect_task.clone(), }); - self.entries.insert(key.clone(), entry.clone()); + self.entries.insert(agent.clone(), entry.clone()); cx.spawn({ - let key = key.clone(); + let key = agent.clone(); let entry = entry.clone(); async move |this, cx| match connect_task.await { Ok(connected_state) => { @@ -123,7 +134,8 @@ impl AgentConnectionStore { version.clone().into(), )); }); - this.update(cx, |this, _cx| this.entries.remove(&key)).ok(); + this.update(cx, |this, _cx| this.entries.remove(&agent)) + .ok(); } } } diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 741e995c8f1b2e44677ec7c7de7bef22a3421f3c..ccd891da11a74e0086b4323cba8af09a5868b5c2 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -1188,7 +1188,8 @@ impl AgentPanel { language_registry, text_thread_store, prompt_store, - connection_store: cx.new(|cx| AgentConnectionStore::new(project.clone(), cx)), + connection_store: cx + .new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)), configuration: None, configuration_subscription: None, focus_handle: cx.focus_handle(), @@ -1337,12 +1338,11 @@ impl AgentPanel { ) { let agent = ExternalAgent::NativeAgent; - let server = agent.server(self.fs.clone(), self.thread_store.clone()); let session_id = action.from_session_id.clone(); - let entry = self.connection_store.update(cx, |store, cx| { - store.request_connection(agent.clone(), server, cx) - }); + let entry = self + .connection_store + .update(cx, |store, cx| store.request_connection(agent.clone(), cx)); let connect_task = entry.read(cx).wait_for_connection(); cx.spawn_in(window, async move |this, cx| { diff --git a/crates/agent_ui/src/connection_view.rs b/crates/agent_ui/src/connection_view.rs index 8aeacbd61ad404f94c39efbd14a846a3b52150d9..ae4a3d8aef9ae37673816360f9fdc56ffbb5e19a 100644 --- a/crates/agent_ui/src/connection_view.rs +++ b/crates/agent_ui/src/connection_view.rs @@ -654,9 +654,8 @@ impl ConnectionView { .or_else(|| worktree_roots.first().cloned()) .unwrap_or_else(|| paths::home_dir().as_path().into()); - let connection_entry = connection_store.update(cx, |store, cx| { - store.request_connection(connection_key, agent.clone(), cx) - }); + let connection_entry = + connection_store.update(cx, |store, cx| store.request_connection(connection_key, cx)); let connection_entry_subscription = cx.subscribe(&connection_entry, |this, _entry, event, cx| match event { @@ -2910,8 +2909,9 @@ pub(crate) mod tests { let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone()); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let thread_view = cx.update(|window, cx| { cx.new(|cx| { @@ -3022,8 +3022,9 @@ pub(crate) mod tests { let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone()); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let thread_view = cx.update(|window, cx| { cx.new(|cx| { @@ -3079,8 +3080,9 @@ pub(crate) mod tests { let captured_cwd = connection.captured_cwd.clone(); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let _thread_view = cx.update(|window, cx| { cx.new(|cx| { @@ -3134,8 +3136,9 @@ pub(crate) mod tests { let captured_cwd = connection.captured_cwd.clone(); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let _thread_view = cx.update(|window, cx| { cx.new(|cx| { @@ -3189,8 +3192,9 @@ pub(crate) mod tests { let captured_cwd = connection.captured_cwd.clone(); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let _thread_view = cx.update(|window, cx| { cx.new(|cx| { @@ -3505,8 +3509,9 @@ pub(crate) mod tests { // Set up thread view in workspace 1 let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project1.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project1.clone(), thread_store.clone(), cx)) + }); let agent = StubAgentServer::default_response(); let thread_view = cx.update(|window, cx| { @@ -3726,8 +3731,9 @@ pub(crate) mod tests { let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone()); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let agent_key = ExternalAgent::Custom { name: "Test".into(), @@ -4470,8 +4476,9 @@ pub(crate) mod tests { let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone()); let thread_store = cx.update(|_window, cx| cx.new(|cx| ThreadStore::new(cx))); - let connection_store = - cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); + let connection_store = cx.update(|_window, cx| { + cx.new(|cx| AgentConnectionStore::new(project.clone(), thread_store.clone(), cx)) + }); let connection = Rc::new(StubAgentConnection::new()); let thread_view = cx.update(|window, cx| {