Files
zed/crates/agent/src/native_agent_server.rs
T
Ben Brandt c413552859 acp: Update agent-client-protocol sdk to 0.13.1 (#58308)
Brings stable logout and additional directories support as well as
removing dep on rmcp + tokio

This also removed the unstable model selector (replaced awhile ago by
session config options) so it removes all of that code.

Native agent still uses it because we have a special model selector that
would need more work to rip out

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
2026-06-02 15:30:37 +00:00

103 lines
3.0 KiB
Rust

use std::{any::Any, rc::Rc, sync::Arc};
use agent_servers::{AgentServer, AgentServerDelegate};
use anyhow::Result;
use fs::Fs;
use gpui::{App, Entity, Task};
use project::{AgentId, Project};
use crate::{NativeAgent, NativeAgentConnection, ThreadStore, templates::Templates};
#[derive(Clone)]
pub struct NativeAgentServer {
fs: Arc<dyn Fs>,
thread_store: Entity<ThreadStore>,
}
impl NativeAgentServer {
pub fn new(fs: Arc<dyn Fs>, thread_store: Entity<ThreadStore>) -> Self {
Self { fs, thread_store }
}
}
impl AgentServer for NativeAgentServer {
fn agent_id(&self) -> AgentId {
crate::ZED_AGENT_ID.clone()
}
fn logo(&self) -> ui::IconName {
ui::IconName::ZedAgent
}
fn connect(
&self,
_delegate: AgentServerDelegate,
_project: Entity<Project>,
cx: &mut App,
) -> Task<Result<Rc<dyn acp_thread::AgentConnection>>> {
log::debug!("NativeAgentServer::connect");
let fs = self.fs.clone();
let thread_store = self.thread_store.clone();
cx.spawn(async move |cx| {
log::debug!("Creating templates for native agent");
let templates = Templates::new();
log::debug!("Creating native agent entity");
let agent = cx.update(|cx| NativeAgent::new(thread_store, templates, fs, cx));
// Create the connection wrapper
let connection = NativeAgentConnection(agent);
log::debug!("NativeAgentServer connection established successfully");
Ok(Rc::new(connection) as Rc<dyn acp_thread::AgentConnection>)
})
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use gpui::AppContext;
agent_servers::e2e_tests::common_e2e_tests!(
async |fs, cx| {
let auth = cx.update(|cx| {
prompt_store::init(cx);
let registry = language_model::LanguageModelRegistry::read_global(cx);
let auth = registry
.provider(&language_model::ANTHROPIC_PROVIDER_ID)
.unwrap()
.authenticate(cx);
cx.spawn(async move |_| auth.await)
});
auth.await.unwrap();
cx.update(|cx| {
let registry = language_model::LanguageModelRegistry::global(cx);
registry.update(cx, |registry, cx| {
registry.select_default_model(
Some(&language_model::SelectedModel {
provider: language_model::ANTHROPIC_PROVIDER_ID,
model: language_model::LanguageModelId("claude-sonnet-4-latest".into()),
}),
cx,
);
});
});
let thread_store = cx.update(|cx| cx.new(|cx| ThreadStore::new(cx)));
NativeAgentServer::new(fs.clone(), thread_store)
},
allow_option_id = "allow"
);
}