native_agent_server.rs

 1use std::{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::{NativeAgent, NativeAgentConnection, templates::Templates};
11
12#[derive(Clone)]
13pub struct NativeAgentServer {
14    fs: Arc<dyn Fs>,
15}
16
17impl NativeAgentServer {
18    pub fn new(fs: Arc<dyn Fs>) -> Self {
19        Self { fs }
20    }
21}
22
23impl AgentServer for NativeAgentServer {
24    fn name(&self) -> &'static str {
25        "Native Agent"
26    }
27
28    fn empty_state_headline(&self) -> &'static str {
29        "Native Agent"
30    }
31
32    fn empty_state_message(&self) -> &'static str {
33        "How can I help you today?"
34    }
35
36    fn logo(&self) -> ui::IconName {
37        // Using the ZedAssistant icon as it's the native built-in agent
38        ui::IconName::ZedAssistant
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 prompt_store = PromptStore::global(cx);
54        cx.spawn(async move |cx| {
55            log::debug!("Creating templates for native agent");
56            let templates = Templates::new();
57            let prompt_store = prompt_store.await?;
58
59            log::debug!("Creating native agent entity");
60            let agent = NativeAgent::new(project, templates, Some(prompt_store), fs, cx).await?;
61
62            // Create the connection wrapper
63            let connection = NativeAgentConnection(agent);
64            log::info!("NativeAgentServer connection established successfully");
65
66            Ok(Rc::new(connection) as Rc<dyn acp_thread::AgentConnection>)
67        })
68    }
69}