Skip to repository content103 lines · 3.1 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T01:32:10.996Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
native_agent_server.rs
1use std::{any::Any, rc::Rc, sync::Arc};
2
3use agent_servers::{AgentServer, AgentServerDelegate};
4use anyhow::Result;
5use fs::Fs;
6use gpui::{App, Entity, Task};
7use project::{AgentId, Project};
8
9use crate::{NativeAgent, NativeAgentConnection, ThreadStore, templates::Templates};
10
11#[derive(Clone)]
12pub struct NativeAgentServer {
13 fs: Arc<dyn Fs>,
14 thread_store: Entity<ThreadStore>,
15}
16
17impl NativeAgentServer {
18 pub fn new(fs: Arc<dyn Fs>, thread_store: Entity<ThreadStore>) -> Self {
19 Self { fs, thread_store }
20 }
21}
22
23impl AgentServer for NativeAgentServer {
24 fn agent_id(&self) -> AgentId {
25 crate::OMEGA_AGENT_ID.clone()
26 }
27
28 fn logo(&self) -> ui::IconName {
29 ui::IconName::OmegaAgent
30 }
31
32 fn connect(
33 &self,
34 _delegate: AgentServerDelegate,
35 _project: Entity<Project>,
36 cx: &mut App,
37 ) -> Task<Result<Rc<dyn acp_thread::AgentConnection>>> {
38 log::debug!("NativeAgentServer::connect");
39 let fs = self.fs.clone();
40 let thread_store = self.thread_store.clone();
41 cx.spawn(async move |cx| {
42 log::debug!("Creating templates for native agent");
43 let templates = Templates::new();
44
45 log::debug!("Creating native agent entity");
46 let agent = cx.update(|cx| NativeAgent::new(thread_store, templates, fs, cx));
47
48 // Create the connection wrapper
49 let connection = NativeAgentConnection(agent);
50 log::debug!("NativeAgentServer connection established successfully");
51
52 Ok(Rc::new(connection) as Rc<dyn acp_thread::AgentConnection>)
53 })
54 }
55
56 fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
57 self
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 use gpui::AppContext;
66
67 agent_servers::e2e_tests::common_e2e_tests!(
68 async |fs, cx| {
69 let auth = cx.update(|cx| {
70 prompt_store::init(cx);
71 let registry = language_model::LanguageModelRegistry::read_global(cx);
72 let auth = registry
73 .provider(&language_model::ANTHROPIC_PROVIDER_ID)
74 .unwrap()
75 .authenticate(cx);
76
77 cx.spawn(async move |_| auth.await)
78 });
79
80 auth.await.unwrap();
81
82 cx.update(|cx| {
83 let registry = language_model::LanguageModelRegistry::global(cx);
84
85 registry.update(cx, |registry, cx| {
86 registry.select_default_model(
87 Some(&language_model::SelectedModel {
88 provider: language_model::ANTHROPIC_PROVIDER_ID,
89 model: language_model::LanguageModelId("claude-sonnet-4-latest".into()),
90 }),
91 cx,
92 );
93 });
94 });
95
96 let thread_store = cx.update(|cx| cx.new(|cx| ThreadStore::new(cx)));
97
98 NativeAgentServer::new(fs.clone(), thread_store)
99 },
100 allow_option_id = "allow"
101 );
102}
103