assistant2: Add ability to start and stop context servers (#27080)

This PR adds the ability to start and stop context servers from within
the configuration view in the Assistant panel:


https://github.com/user-attachments/assets/93c3a7cb-d799-4286-88ba-c13cc26e959a

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-03-19 11:37:48 -04:00 committed by GitHub
parent 06ffdc6791
commit 410a942d57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 98 additions and 24 deletions

View file

@ -155,7 +155,7 @@ impl ContextServerManager {
Self::maintain_servers(this.clone(), cx).await?;
this.update(cx, |this, cx| {
let has_any_context_servers = !this.servers().is_empty();
let has_any_context_servers = !this.running_servers().is_empty();
if has_any_context_servers {
CommandPaletteFilter::update_global(cx, |filter, _cx| {
filter.show_namespace(CONTEXT_SERVERS_NAMESPACE);
@ -180,6 +180,31 @@ impl ContextServerManager {
.cloned()
}
pub fn start_server(
&self,
server: Arc<ContextServer>,
cx: &mut Context<Self>,
) -> Task<anyhow::Result<()>> {
cx.spawn(async move |this, cx| {
let id = server.id.clone();
server.start(&cx).await?;
this.update(cx, |_, cx| cx.emit(Event::ServerStarted { server_id: id }))?;
Ok(())
})
}
pub fn stop_server(
&self,
server: Arc<ContextServer>,
cx: &mut Context<Self>,
) -> anyhow::Result<()> {
server.stop()?;
cx.emit(Event::ServerStopped {
server_id: server.id(),
});
Ok(())
}
pub fn restart_server(
&mut self,
id: &Arc<str>,
@ -206,7 +231,11 @@ impl ContextServerManager {
})
}
pub fn servers(&self) -> Vec<Arc<ContextServer>> {
pub fn all_servers(&self) -> Vec<Arc<ContextServer>> {
self.servers.values().cloned().collect()
}
pub fn running_servers(&self) -> Vec<Arc<ContextServer>> {
self.servers
.values()
.filter(|server| server.client().is_some())