native_agent_server.rs

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