From 246c644316238295a5022120ef9451d40751ea59 Mon Sep 17 00:00:00 2001 From: Patsakula Nikita Date: Mon, 8 Sep 2025 23:44:40 +0300 Subject: [PATCH] agent_servers: Fix proxy configuration for Gemini (#37790) Closes #37487 Proxy settings are now taken from the Zed configuration and passed to Gemini via the "--proxy" flag. Release Notes: - acp: Gemini ACP server now uses proxy settings from Zed configuration. --- crates/agent_servers/Cargo.toml | 2 +- crates/agent_servers/src/gemini.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/agent_servers/Cargo.toml b/crates/agent_servers/Cargo.toml index 2a601dcb161b8220870f53e80890fd2bdbc91c13..bb3fe6ff9078535b500e28f4beeab957929546a5 100644 --- a/crates/agent_servers/Cargo.toml +++ b/crates/agent_servers/Cargo.toml @@ -23,7 +23,7 @@ action_log.workspace = true agent-client-protocol.workspace = true agent_settings.workspace = true anyhow.workspace = true -client = { workspace = true, optional = true } +client.workspace = true collections.workspace = true env_logger = { workspace = true, optional = true } fs.workspace = true diff --git a/crates/agent_servers/src/gemini.rs b/crates/agent_servers/src/gemini.rs index 20a18dfd332d25a828846bcbc04fd37c03c81dad..cf553273db87d7400b56956741540bd061a9c231 100644 --- a/crates/agent_servers/src/gemini.rs +++ b/crates/agent_servers/src/gemini.rs @@ -4,10 +4,12 @@ use std::{any::Any, path::Path}; use crate::{AgentServer, AgentServerDelegate}; use acp_thread::AgentConnection; use anyhow::{Context as _, Result}; +use client::ProxySettings; use collections::HashMap; -use gpui::{App, SharedString, Task}; +use gpui::{App, AppContext, SharedString, Task}; use language_models::provider::google::GoogleLanguageModelProvider; use project::agent_server_store::GEMINI_NAME; +use settings::SettingsStore; #[derive(Clone)] pub struct Gemini; @@ -35,13 +37,16 @@ impl AgentServer for Gemini { let root_dir = root_dir.map(|root_dir| root_dir.to_string_lossy().to_string()); let is_remote = delegate.project.read(cx).is_via_remote_server(); let store = delegate.store.downgrade(); + let proxy_url = cx.read_global(|settings: &SettingsStore, _| { + settings.get::(None).proxy.clone() + }); cx.spawn(async move |cx| { let mut extra_env = HashMap::default(); if let Some(api_key) = cx.update(GoogleLanguageModelProvider::api_key)?.await.ok() { extra_env.insert("GEMINI_API_KEY".into(), api_key.key); } - let (command, root_dir, login) = store + let (mut command, root_dir, login) = store .update(cx, |store, cx| { let agent = store .get_external_agent(&GEMINI_NAME.into()) @@ -55,6 +60,15 @@ impl AgentServer for Gemini { )) })?? .await?; + + // Add proxy flag if proxy settings are configured in Zed and not in the args + if let Some(proxy_url_value) = &proxy_url + && !command.args.iter().any(|arg| arg.contains("--proxy")) + { + command.args.push("--proxy".into()); + command.args.push(proxy_url_value.clone()); + } + let connection = crate::acp::connect(name, command, root_dir.as_ref(), is_remote, cx).await?; Ok((connection, login))