Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T02:55:39.737Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

agent_servers.rs

142 lines · 4.0 KB · rust
1mod acp;
2mod custom;
3
4#[cfg(any(test, feature = "test-support"))]
5pub mod e2e_tests;
6
7use client::ProxySettings;
8use collections::{HashMap, HashSet};
9pub use custom::*;
10use fs::Fs;
11use http_client::read_no_proxy_from_env;
12use project::{AgentId, Project, agent_server_store::AgentServerStore};
13
14use acp_thread::AgentConnection;
15use agent_client_protocol::schema::v1 as acp_schema;
16use anyhow::Result;
17use gpui::{App, AppContext, Entity, Task};
18use settings::{AgentConfigOptionValue, SettingsStore};
19use std::{any::Any, rc::Rc, sync::Arc};
20
21#[cfg(any(test, feature = "test-support"))]
22pub use acp::test_support::{
23    FakeAcpAgentServer, FakeAcpConnectionHarness, connect_fake_acp_connection,
24};
25pub use acp::{
26    AcpConnection, AcpDebugMessage, AcpDebugMessageContent, AcpDebugMessageDirection,
27    GEMINI_TERMINAL_AUTH_METHOD_ID,
28};
29
30pub struct AgentServerDelegate {
31    store: Entity<AgentServerStore>,
32    new_version_available: Option<watch::Sender<Option<String>>>,
33    loading_status: Option<watch::Sender<Option<String>>>,
34}
35
36impl AgentServerDelegate {
37    pub fn new(
38        store: Entity<AgentServerStore>,
39        new_version_tx: Option<watch::Sender<Option<String>>>,
40        loading_status_tx: Option<watch::Sender<Option<String>>>,
41    ) -> Self {
42        Self {
43            store,
44            new_version_available: new_version_tx,
45            loading_status: loading_status_tx,
46        }
47    }
48
49    /// The store that owns external-agent commands for this connection.
50    #[must_use]
51    pub fn store(&self) -> &Entity<AgentServerStore> {
52        &self.store
53    }
54}
55
56pub trait AgentServer: Send {
57    fn logo(&self) -> ui::IconName;
58    fn agent_id(&self) -> AgentId;
59    fn connect(
60        &self,
61        delegate: AgentServerDelegate,
62        project: Entity<Project>,
63        cx: &mut App,
64    ) -> Task<Result<Rc<dyn AgentConnection>>>;
65
66    fn into_any(self: Rc<Self>) -> Rc<dyn Any>;
67
68    fn default_mode(&self, _cx: &App) -> Option<acp_schema::SessionModeId> {
69        None
70    }
71
72    fn set_default_mode(
73        &self,
74        _mode_id: Option<acp_schema::SessionModeId>,
75        _fs: Arc<dyn Fs>,
76        _cx: &mut App,
77    ) {
78    }
79
80    fn default_config_option(&self, _config_id: &str, _cx: &App) -> Option<AgentConfigOptionValue> {
81        None
82    }
83
84    fn set_default_config_option(
85        &self,
86        _config_id: &str,
87        _value: Option<AgentConfigOptionValue>,
88        _fs: Arc<dyn Fs>,
89        _cx: &mut App,
90    ) {
91    }
92
93    fn favorite_config_option_value_ids(
94        &self,
95        _config_id: &acp_schema::SessionConfigId,
96        _cx: &mut App,
97    ) -> HashSet<acp_schema::SessionConfigValueId> {
98        HashSet::default()
99    }
100
101    fn toggle_favorite_config_option_value(
102        &self,
103        _config_id: acp_schema::SessionConfigId,
104        _value_id: acp_schema::SessionConfigValueId,
105        _should_be_favorite: bool,
106        _fs: Arc<dyn Fs>,
107        _cx: &App,
108    ) {
109    }
110}
111
112impl dyn AgentServer {
113    pub fn downcast<T: 'static + AgentServer + Sized>(self: Rc<Self>) -> Option<Rc<T>> {
114        self.into_any().downcast().ok()
115    }
116}
117
118/// Load the default proxy environment variables to pass through to the agent
119pub fn load_proxy_env(cx: &mut App) -> HashMap<String, String> {
120    let proxy_url = cx
121        .read_global(|settings: &SettingsStore, _| settings.get::<ProxySettings>(None).proxy_url());
122    let mut env = HashMap::default();
123
124    if let Some(proxy_url) = &proxy_url {
125        let env_var = if proxy_url.scheme() == "https" {
126            "HTTPS_PROXY"
127        } else {
128            "HTTP_PROXY"
129        };
130        env.insert(env_var.to_owned(), proxy_url.to_string());
131    }
132
133    if let Some(no_proxy) = read_no_proxy_from_env() {
134        env.insert("NO_PROXY".to_owned(), no_proxy);
135    } else if proxy_url.is_some() {
136        // We sometimes need local MCP servers that we don't want to proxy
137        env.insert("NO_PROXY".to_owned(), "localhost,127.0.0.1".to_owned());
138    }
139
140    env
141}
142
Served at tenant.openagents/omega Member data and write actions are omitted.