native_agent_server.rs

 1use std::{any::Any, path::Path, rc::Rc, sync::Arc};
 2
 3use agent_servers::AgentServer;
 4use anyhow::Result;
 5use fs::Fs;
 6use gpui::{App, Entity, Task};
 7use project::Project;
 8use prompt_store::PromptStore;
 9
10use crate::{HistoryStore, NativeAgent, NativeAgentConnection, templates::Templates};
11
12#[derive(Clone)]
13pub struct NativeAgentServer {
14    fs: Arc<dyn Fs>,
15    history: Entity<HistoryStore>,
16}
17
18impl NativeAgentServer {
19    pub fn new(fs: Arc<dyn Fs>, history: Entity<HistoryStore>) -> Self {
20        Self { fs, history }
21    }
22}
23
24impl AgentServer for NativeAgentServer {
25    fn name(&self) -> &'static str {
26        "Native Agent"
27    }
28
29    fn empty_state_headline(&self) -> &'static str {
30        ""
31    }
32
33    fn empty_state_message(&self) -> &'static str {
34        ""
35    }
36
37    fn logo(&self) -> ui::IconName {
38        ui::IconName::ZedAgent
39    }
40
41    fn connect(
42        &self,
43        _root_dir: &Path,
44        project: &Entity<Project>,
45        cx: &mut App,
46    ) -> Task<Result<Rc<dyn acp_thread::AgentConnection>>> {
47        log::info!(
48            "NativeAgentServer::connect called for path: {:?}",
49            _root_dir
50        );
51        let project = project.clone();
52        let fs = self.fs.clone();
53        let history = self.history.clone();
54        let prompt_store = PromptStore::global(cx);
55        cx.spawn(async move |cx| {
56            log::debug!("Creating templates for native agent");
57            let templates = Templates::new();
58            let prompt_store = prompt_store.await?;
59
60            log::debug!("Creating native agent entity");
61            let agent =
62                NativeAgent::new(project, history, templates, Some(prompt_store), fs, cx).await?;
63
64            // Create the connection wrapper
65            let connection = NativeAgentConnection(agent);
66            log::info!("NativeAgentServer connection established successfully");
67
68            Ok(Rc::new(connection) as Rc<dyn acp_thread::AgentConnection>)
69        })
70    }
71
72    fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
73        self
74    }
75}