1use crate::{AgentServerCommand, AgentServerSettings};
2use acp_thread::AgentConnection;
3use anyhow::Result;
4use gpui::{App, Entity, SharedString, Task};
5use project::Project;
6use std::{path::Path, rc::Rc};
7use ui::IconName;
8
9/// A generic agent server implementation for custom user-defined agents
10pub struct CustomAgentServer {
11 name: SharedString,
12 command: AgentServerCommand,
13}
14
15impl CustomAgentServer {
16 pub fn new(name: SharedString, settings: &AgentServerSettings) -> Self {
17 Self {
18 name,
19 command: settings.command.clone(),
20 }
21 }
22}
23
24impl crate::AgentServer for CustomAgentServer {
25 fn name(&self) -> SharedString {
26 self.name.clone()
27 }
28
29 fn logo(&self) -> IconName {
30 IconName::Terminal
31 }
32
33 fn empty_state_headline(&self) -> SharedString {
34 "No conversations yet".into()
35 }
36
37 fn empty_state_message(&self) -> SharedString {
38 format!("Start a conversation with {}", self.name).into()
39 }
40
41 fn connect(
42 &self,
43 root_dir: &Path,
44 _project: &Entity<Project>,
45 cx: &mut App,
46 ) -> Task<Result<Rc<dyn AgentConnection>>> {
47 let server_name = self.name();
48 let command = self.command.clone();
49 let root_dir = root_dir.to_path_buf();
50
51 cx.spawn(async move |mut cx| {
52 crate::acp::connect(server_name, command, &root_dir, &mut cx).await
53 })
54 }
55
56 fn into_any(self: Rc<Self>) -> Rc<dyn std::any::Any> {
57 self
58 }
59}