diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index 00a192cf7a046b5991475aae131a74561bea92fe..632bdf6f898272d039bf33edab9b7ded83511240 100644 --- a/crates/acp_thread/src/acp_thread.rs +++ b/crates/acp_thread/src/acp_thread.rs @@ -111,14 +111,7 @@ pub enum AssistantMessageChunk { impl AssistantMessageChunk { pub fn from_str(chunk: &str, language_registry: &Arc, cx: &mut App) -> Self { Self::Message { - block: ContentBlock::new( - acp::ContentBlock::Text(acp::TextContent { - text: chunk.to_owned().into(), - annotations: None, - }), - language_registry, - cx, - ), + block: ContentBlock::new(chunk.into(), language_registry, cx), } } @@ -562,7 +555,7 @@ pub struct AcpThread { action_log: Entity, shared_buffers: HashMap, BufferSnapshot>, send_task: Option>, - connection: Arc, + connection: Rc, child_status: Option>>, session_id: acp::SessionId, } @@ -606,7 +599,7 @@ impl Error for LoadError {} impl AcpThread { pub fn new( - connection: Arc, + connection: Rc, // todo! remove me title: SharedString, // todo! remove this? @@ -1294,7 +1287,7 @@ impl acp_old::Client for OldAcpClientDelegate { .await; let outcome = match response { - Ok(option_id) => outcomes[option_id.0.parse::().unwrap_or(0)].clone(), + Ok(option_id) => outcomes[option_id.0.parse::().unwrap_or(0)], Err(oneshot::Canceled) => acp_old::ToolCallConfirmationOutcome::Cancel, }; @@ -1831,7 +1824,7 @@ mod tests { }; AcpThread::new( - Arc::new(connection), + Rc::new(connection), "Test".into(), None, project, diff --git a/crates/acp_thread/src/connection.rs b/crates/acp_thread/src/connection.rs index ad10dc53553758d4854e72948c77af73cdbba07a..5106686714b21e9c0f0aa75082ef0ae52fd9e556 100644 --- a/crates/acp_thread/src/connection.rs +++ b/crates/acp_thread/src/connection.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, error::Error, fmt, path::Path, rc::Rc, sync::Arc}; +use std::{cell::RefCell, error::Error, fmt, path::Path, rc::Rc}; use agent_client_protocol as acp; use agentic_coding_protocol::{self as acp_old, AgentRequest}; @@ -14,7 +14,7 @@ pub trait AgentConnection { &self, project: Entity, cwd: &Path, - connection: Arc, + connection: Rc, cx: &mut AsyncApp, ) -> Task>>; @@ -46,7 +46,7 @@ impl AgentConnection for OldAcpAgentConnection { &self, project: Entity, _cwd: &Path, - connection: Arc, + connection: Rc, cx: &mut AsyncApp, ) -> Task>> { let task = self.connection.request_any( diff --git a/crates/agent_servers/src/agent_servers.rs b/crates/agent_servers/src/agent_servers.rs index 8a63d6835bce990d658c1c59468ba416879f7729..1e33e59c671e0408ab8c16a1257af3a754699db6 100644 --- a/crates/agent_servers/src/agent_servers.rs +++ b/crates/agent_servers/src/agent_servers.rs @@ -23,6 +23,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::{ path::{Path, PathBuf}, + rc::Rc, sync::Arc, }; use util::ResultExt as _; @@ -42,7 +43,7 @@ pub trait AgentServer: Send { root_dir: &Path, project: &Entity, cx: &mut App, - ) -> Task>>; + ) -> Task>>; } impl std::fmt::Debug for AgentServerCommand { diff --git a/crates/agent_servers/src/claude.rs b/crates/agent_servers/src/claude.rs index a506036fbec1fd4c8f4cdeb29cd66f86d806a00a..7221b9f2a2c4082272356b3ddec0c479778d11f1 100644 --- a/crates/agent_servers/src/claude.rs +++ b/crates/agent_servers/src/claude.rs @@ -9,7 +9,6 @@ use std::fmt::Display; use std::path::Path; use std::pin::pin; use std::rc::Rc; -use std::sync::Arc; use uuid::Uuid; use agent_client_protocol as acp; @@ -56,7 +55,7 @@ impl AgentServer for ClaudeCode { root_dir: &Path, project: &Entity, cx: &mut App, - ) -> Task>> { + ) -> Task>> { let project = project.clone(); let root_dir = root_dir.to_path_buf(); cx.spawn(async move |cx| { @@ -179,7 +178,7 @@ impl AgentServer for ClaudeCode { _mcp_server: Some(permission_mcp_server), }; - Ok(Arc::new(connection) as _) + Ok(Rc::new(connection) as _) }) } } @@ -202,7 +201,7 @@ impl AgentConnection for ClaudeAgentConnection { &self, project: Entity, _cwd: &Path, - connection: Arc, + connection: Rc, cx: &mut AsyncApp, ) -> Task>> { let session_id = self.session_id.clone(); diff --git a/crates/agent_servers/src/codex.rs b/crates/agent_servers/src/codex.rs index f86c4450beaabb2d91c831413536cf1bb9ca0bcd..e66828491467ebef6ceedf249e84a318be4ce536 100644 --- a/crates/agent_servers/src/codex.rs +++ b/crates/agent_servers/src/codex.rs @@ -1,6 +1,5 @@ use project::Project; -use std::path::Path; -use std::sync::Arc; +use std::{path::Path, rc::Rc}; use anyhow::Result; use gpui::{App, Entity, Task}; @@ -33,7 +32,7 @@ impl AgentServer for Codex { _root_dir: &Path, _project: &Entity, _cx: &mut App, - ) -> Task>> { + ) -> Task>> { // re-implement using ACP todo!() } diff --git a/crates/agent_servers/src/mcp_server.rs b/crates/agent_servers/src/mcp_server.rs index e26ef21458a04b5a18492dd694fef2d91cca5b85..66b58be1ab94b6f276fef84eeefa9b4c4cacb157 100644 --- a/crates/agent_servers/src/mcp_server.rs +++ b/crates/agent_servers/src/mcp_server.rs @@ -197,9 +197,12 @@ impl ZedMcpServer { ) -> Task>> { cx.spawn(async move |cx| { // todo! get session id somehow - let threads_map = threads_map.borrow(); - let Some((_, thread)) = threads_map.iter().next() else { - anyhow::bail!("Server not available"); + let thread = { + let threads_map = threads_map.borrow(); + let Some((_, thread)) = threads_map.iter().next() else { + anyhow::bail!("Server not available"); + }; + thread.clone() }; let content = thread @@ -219,9 +222,12 @@ impl ZedMcpServer { ) -> Task> { cx.spawn(async move |cx| { // todo! get session id somehow - let threads_map = threads_map.borrow(); - let Some((_, thread)) = threads_map.iter().next() else { - anyhow::bail!("Server not available"); + let thread = { + let threads_map = threads_map.borrow(); + let Some((_, thread)) = threads_map.iter().next() else { + anyhow::bail!("Server not available"); + }; + thread.clone() }; let content = thread @@ -252,9 +258,12 @@ impl ZedMcpServer { ) -> Task> { cx.spawn(async move |cx| { // todo! get session id somehow - let threads_map = threads_map.borrow(); - let Some((_, thread)) = threads_map.iter().next() else { - anyhow::bail!("Server not available"); + let thread = { + let threads_map = threads_map.borrow(); + let Some((_, thread)) = threads_map.iter().next() else { + anyhow::bail!("Server not available"); + }; + thread.clone() }; let claude_tool = ClaudeTool::infer(¶ms.tool_name, params.input.clone()); diff --git a/crates/agent_servers/src/stdio_agent_server.rs b/crates/agent_servers/src/stdio_agent_server.rs index a0d1e3f856fb2ee092029466d3414cab8a8e5e9f..c2f5503591a4210b5aa5b2b1c9755180e6ae3f43 100644 --- a/crates/agent_servers/src/stdio_agent_server.rs +++ b/crates/agent_servers/src/stdio_agent_server.rs @@ -4,7 +4,7 @@ use agentic_coding_protocol as acp_old; use anyhow::{Result, anyhow}; use gpui::{App, AsyncApp, Entity, Task, WeakEntity, prelude::*}; use project::Project; -use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc}; +use std::{cell::RefCell, path::Path, rc::Rc}; use util::ResultExt; pub trait StdioAgentServer: Send + Clone { @@ -47,7 +47,7 @@ impl AgentServer for T { root_dir: &Path, project: &Entity, cx: &mut App, - ) -> Task>> { + ) -> Task>> { let root_dir = root_dir.to_path_buf(); let project = project.clone(); let this = self.clone(); @@ -107,7 +107,7 @@ impl AgentServer for T { result }); - let connection: Arc = Arc::new(OldAcpAgentConnection { + let connection: Rc = Rc::new(OldAcpAgentConnection { connection, child_status, thread: thread_rc,