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