1pub mod error;
35pub mod transport;
36
37#[cfg(feature = "asset")]
38pub mod asset;
39#[cfg(feature = "cognee")]
40pub mod cognee;
41#[cfg(feature = "search")]
42pub mod search;
43
44pub use error::{OriginError, Result};
45use transport::HttpTransport;
46
47pub mod defaults {
49 pub const ASSET_GATEWAY_URL: &str = "https://upload.xiaomao.chat";
50 pub const AI_SEARCH_URL: &str = "https://search.xiaomao.chat";
51 pub const COGNEE_URL: &str = "https://cogneeapi.xiaomao.chat";
52}
53
54pub struct OriginClientBuilder {
56 api_key: String,
57 asset_url: String,
58 search_url: String,
59 cognee_url: String,
60 cognee_token: Option<String>,
61 client: Option<reqwest::Client>,
62}
63
64impl OriginClientBuilder {
65 pub fn new(api_key: impl Into<String>) -> Self {
66 Self {
67 api_key: api_key.into(),
68 asset_url: defaults::ASSET_GATEWAY_URL.to_string(),
69 search_url: defaults::AI_SEARCH_URL.to_string(),
70 cognee_url: defaults::COGNEE_URL.to_string(),
71 cognee_token: None,
72 client: None,
73 }
74 }
75
76 pub fn asset_url(mut self, url: impl Into<String>) -> Self {
78 self.asset_url = url.into();
79 self
80 }
81
82 pub fn search_url(mut self, url: impl Into<String>) -> Self {
84 self.search_url = url.into();
85 self
86 }
87
88 pub fn cognee_url(mut self, url: impl Into<String>) -> Self {
90 self.cognee_url = url.into();
91 self
92 }
93
94 pub fn cognee_token(mut self, token: impl Into<String>) -> Self {
96 self.cognee_token = Some(token.into());
97 self
98 }
99
100 pub fn http_client(mut self, client: reqwest::Client) -> Self {
102 self.client = Some(client);
103 self
104 }
105
106 pub fn build(self) -> OriginClient {
108 let make_transport = |url: String, key: String| {
109 let transport = HttpTransport::new(url, key);
110 if let Some(ref client) = self.client {
111 transport.with_client(client.clone())
112 } else {
113 transport
114 }
115 };
116
117 let cognee_key = self.cognee_token.unwrap_or_else(|| self.api_key.clone());
118
119 OriginClient {
120 asset_transport: make_transport(self.asset_url, self.api_key.clone()),
121 search_transport: make_transport(self.search_url, self.api_key.clone()),
122 cognee_transport: make_transport(self.cognee_url, cognee_key),
123 }
124 }
125}
126
127#[derive(Debug, Clone)]
131pub struct OriginClient {
132 asset_transport: HttpTransport,
133 search_transport: HttpTransport,
134 cognee_transport: HttpTransport,
135}
136
137impl OriginClient {
138 pub fn new(api_key: impl Into<String>) -> Self {
140 OriginClientBuilder::new(api_key).build()
141 }
142
143 pub fn builder(api_key: impl Into<String>) -> OriginClientBuilder {
145 OriginClientBuilder::new(api_key)
146 }
147
148 #[cfg(feature = "asset")]
150 pub fn asset(&self) -> asset::AssetClient {
151 asset::AssetClient::new(self.asset_transport.clone())
152 }
153
154 #[cfg(feature = "search")]
156 pub fn search(&self) -> search::SearchClient {
157 search::SearchClient::new(self.search_transport.clone())
158 }
159
160 #[cfg(feature = "cognee")]
162 pub fn cognee(&self) -> cognee::CogneeClient {
163 cognee::CogneeClient::new(self.cognee_transport.clone())
164 }
165}