atrium_api/agent/
inner.rs1use super::{CloneWithProxy, Configure, SessionManager};
2use crate::types::string::Did;
3use atrium_xrpc::{Error, HttpClient, OutputDataOrBytes, XrpcClient, XrpcRequest};
4use http::{Request, Response};
5use serde::{de::DeserializeOwned, Serialize};
6use std::{fmt::Debug, ops::Deref, sync::Arc};
7
8pub struct Wrapper<M> {
9 inner: Arc<M>,
10}
11
12impl<M> Wrapper<M>
13where
14 M: SessionManager + Send + Sync,
15{
16 pub fn new(inner: M) -> Self {
17 Self { inner: Arc::new(inner) }
18 }
19}
20
21impl<M> HttpClient for Wrapper<M>
22where
23 M: SessionManager + Send + Sync,
24{
25 async fn send_http(
26 &self,
27 request: Request<Vec<u8>>,
28 ) -> Result<Response<Vec<u8>>, Box<dyn std::error::Error + Send + Sync + 'static>> {
29 self.inner.send_http(request).await
30 }
31}
32
33impl<M> XrpcClient for Wrapper<M>
34where
35 M: SessionManager + Send + Sync,
36{
37 fn base_uri(&self) -> String {
38 self.inner.base_uri()
39 }
40 async fn send_xrpc<P, I, O, E>(
41 &self,
42 request: &XrpcRequest<P, I>,
43 ) -> Result<OutputDataOrBytes<O>, Error<E>>
44 where
45 P: Serialize + Send + Sync,
46 I: Serialize + Send + Sync,
47 O: DeserializeOwned + Send + Sync,
48 E: DeserializeOwned + Send + Sync + Debug,
49 {
50 self.inner.send_xrpc(request).await
51 }
52}
53
54impl<M> SessionManager for Wrapper<M>
55where
56 M: SessionManager + Send + Sync,
57{
58 async fn did(&self) -> Option<Did> {
59 self.inner.did().await
60 }
61}
62
63impl<M> Configure for Wrapper<M>
64where
65 M: Configure,
66{
67 fn configure_endpoint(&self, endpoint: String) {
68 self.inner.configure_endpoint(endpoint);
69 }
70 fn configure_labelers_header(&self, labeler_dids: Option<Vec<(Did, bool)>>) {
71 self.inner.configure_labelers_header(labeler_dids);
72 }
73 fn configure_proxy_header(&self, did: Did, service_type: impl AsRef<str>) {
74 self.inner.configure_proxy_header(did, service_type);
75 }
76}
77
78impl<M> CloneWithProxy for Wrapper<M>
79where
80 M: CloneWithProxy,
81{
82 fn clone_with_proxy(&self, did: Did, service_type: impl AsRef<str>) -> Self {
83 Self { inner: Arc::new(self.inner.clone_with_proxy(did, service_type)) }
84 }
85}
86
87impl<M> Clone for Wrapper<M>
88where
89 M: SessionManager + Send + Sync,
90{
91 fn clone(&self) -> Self {
92 Self { inner: self.inner.clone() }
93 }
94}
95
96impl<M> Deref for Wrapper<M>
97where
98 M: SessionManager + Send + Sync,
99{
100 type Target = M;
101
102 fn deref(&self) -> &Self::Target {
103 &self.inner
104 }
105}