gemini.rs

 1use std::path::Path;
 2use std::rc::Rc;
 3
 4use crate::{AgentServer, AgentServerCommand};
 5use acp_thread::AgentConnection;
 6use anyhow::Result;
 7use gpui::{Entity, Task};
 8use project::Project;
 9use settings::SettingsStore;
10use ui::App;
11
12use crate::AllAgentServersSettings;
13
14#[derive(Clone)]
15pub struct Gemini;
16
17const ACP_ARG: &str = "--experimental-acp";
18
19impl AgentServer for Gemini {
20    fn name(&self) -> &'static str {
21        "Gemini"
22    }
23
24    fn empty_state_headline(&self) -> &'static str {
25        "Welcome to Gemini"
26    }
27
28    fn empty_state_message(&self) -> &'static str {
29        "Ask questions, edit files, run commands.\nBe specific for the best results."
30    }
31
32    fn logo(&self) -> ui::IconName {
33        ui::IconName::AiGemini
34    }
35
36    fn connect(
37        &self,
38        root_dir: &Path,
39        project: &Entity<Project>,
40        cx: &mut App,
41    ) -> Task<Result<Rc<dyn AgentConnection>>> {
42        let project = project.clone();
43        let root_dir = root_dir.to_path_buf();
44        let server_name = self.name();
45        cx.spawn(async move |cx| {
46            let settings = cx.read_global(|settings: &SettingsStore, _| {
47                settings.get::<AllAgentServersSettings>(None).gemini.clone()
48            })?;
49
50            let Some(command) =
51                AgentServerCommand::resolve("gemini", &[ACP_ARG], settings, &project, cx).await
52            else {
53                anyhow::bail!("Failed to find gemini binary");
54            };
55
56            crate::acp::connect(server_name, command, &root_dir, cx).await
57        })
58    }
59}
60
61#[cfg(test)]
62pub(crate) mod tests {
63    use super::*;
64    use crate::AgentServerCommand;
65    use std::path::Path;
66
67    crate::common_e2e_tests!(Gemini, allow_option_id = "proceed_once");
68
69    pub fn local_command() -> AgentServerCommand {
70        let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
71            .join("../../../gemini-cli/packages/cli")
72            .to_string_lossy()
73            .to_string();
74
75        AgentServerCommand {
76            path: "node".into(),
77            args: vec![cli_path],
78            env: None,
79        }
80    }
81}