agent: Gate agent registry refresh behind Disable AI setting (#50868) (cherry-pick to preview) (#50869)
zed-zippy[bot]
and
Ben Brandt
created 1 month ago
Cherry-pick of #50868 to preview
----
Make sure we don't download this file if disable_ai is enabled
Release Notes:
- N/A
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Change summary
crates/agent_ui/src/agent_panel.rs | 7 +++----
crates/project/src/agent_registry_store.rs | 22 ++++++++++++++--------
2 files changed, 17 insertions(+), 12 deletions(-)
Detailed changes
@@ -3300,13 +3300,12 @@ impl AgentPanel {
.filter(|id| {
!agent_server_store.external_agents.contains_key(*id)
})
- .map(|name| {
+ .filter_map(|name| {
let display_name = registry_store_ref
.as_ref()
.and_then(|store| store.agent(name.0.as_ref()))
- .map(|a| a.name().clone())
- .unwrap_or_else(|| name.0.clone());
- (name.clone(), display_name)
+ .map(|a| a.name().clone())?;
+ Some((name.clone(), display_name))
})
.sorted_unstable_by_key(|(_, display_name)| display_name.to_lowercase())
.collect::<Vec<_>>();
@@ -11,7 +11,7 @@ use http_client::{AsyncBody, HttpClient};
use serde::Deserialize;
use settings::Settings as _;
-use crate::agent_server_store::AllAgentServersSettings;
+use crate::DisableAiSettings;
const REGISTRY_URL: &str = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
const REFRESH_THROTTLE_DURATION: Duration = Duration::from_secs(60 * 60);
@@ -129,13 +129,11 @@ impl AgentRegistryStore {
let store = cx.new(|cx| Self::new(fs, http_client, cx));
cx.set_global(GlobalAgentRegistryStore(store.clone()));
- if AllAgentServersSettings::get_global(cx).has_registry_agents() {
- store.update(cx, |store, cx| {
- if store.agents.is_empty() {
- store.refresh(cx);
- }
- });
- }
+ store.update(cx, |store, cx| {
+ if store.agents.is_empty() {
+ store.refresh(cx);
+ }
+ });
store
}
@@ -173,6 +171,10 @@ impl AgentRegistryStore {
return;
}
+ if DisableAiSettings::get_global(cx).disable_ai {
+ return;
+ }
+
self.is_fetching = true;
self.fetch_error = None;
self.last_refresh = Some(Instant::now());
@@ -249,6 +251,10 @@ impl AgentRegistryStore {
http_client: Arc<dyn HttpClient>,
cx: &mut Context<Self>,
) {
+ if DisableAiSettings::get_global(cx).disable_ai {
+ return;
+ }
+
cx.spawn(async move |this, cx| -> Result<()> {
let cache_path = registry_cache_path();
if !fs.is_file(&cache_path).await {