custom.rs

 1use crate::{AgentServerCommand, AgentServerDelegate};
 2use acp_thread::AgentConnection;
 3use anyhow::Result;
 4use gpui::{App, SharedString, Task};
 5use std::{path::Path, rc::Rc};
 6use ui::IconName;
 7
 8/// A generic agent server implementation for custom user-defined agents
 9pub struct CustomAgentServer {
10    name: SharedString,
11    command: AgentServerCommand,
12}
13
14impl CustomAgentServer {
15    pub fn new(name: SharedString, command: AgentServerCommand) -> Self {
16        Self { name, command }
17    }
18}
19
20impl crate::AgentServer for CustomAgentServer {
21    fn telemetry_id(&self) -> &'static str {
22        "custom"
23    }
24
25    fn name(&self) -> SharedString {
26        self.name.clone()
27    }
28
29    fn logo(&self) -> IconName {
30        IconName::Terminal
31    }
32
33    fn connect(
34        &self,
35        root_dir: &Path,
36        _delegate: AgentServerDelegate,
37        cx: &mut App,
38    ) -> Task<Result<Rc<dyn AgentConnection>>> {
39        let server_name = self.name();
40        let command = self.command.clone();
41        let root_dir = root_dir.to_path_buf();
42        cx.spawn(async move |cx| crate::acp::connect(server_name, command, &root_dir, cx).await)
43    }
44
45    fn into_any(self: Rc<Self>) -> Rc<dyn std::any::Any> {
46        self
47    }
48}