native_agent_server.rs

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