pub mod error;
pub mod transport;
#[cfg(feature = "asset")]
pub mod asset;
#[cfg(feature = "cognee")]
pub mod cognee;
#[cfg(feature = "search")]
pub mod search;
pub use error::{OriginError, Result};
use transport::HttpTransport;
pub mod defaults {
pub const ASSET_GATEWAY_URL: &str = "https://upload.xiaomao.chat";
pub const AI_SEARCH_URL: &str = "https://search.xiaomao.chat";
pub const COGNEE_URL: &str = "https://cogneeapi.xiaomao.chat";
}
pub struct OriginClientBuilder {
api_key: String,
asset_url: String,
search_url: String,
cognee_url: String,
cognee_token: Option<String>,
client: Option<reqwest::Client>,
}
impl OriginClientBuilder {
pub fn new(api_key: impl Into<String>) -> Self {
Self {
api_key: api_key.into(),
asset_url: defaults::ASSET_GATEWAY_URL.to_string(),
search_url: defaults::AI_SEARCH_URL.to_string(),
cognee_url: defaults::COGNEE_URL.to_string(),
cognee_token: None,
client: None,
}
}
pub fn asset_url(mut self, url: impl Into<String>) -> Self {
self.asset_url = url.into();
self
}
pub fn search_url(mut self, url: impl Into<String>) -> Self {
self.search_url = url.into();
self
}
pub fn cognee_url(mut self, url: impl Into<String>) -> Self {
self.cognee_url = url.into();
self
}
pub fn cognee_token(mut self, token: impl Into<String>) -> Self {
self.cognee_token = Some(token.into());
self
}
pub fn http_client(mut self, client: reqwest::Client) -> Self {
self.client = Some(client);
self
}
pub fn build(self) -> OriginClient {
let make_transport = |url: String, key: String| {
let transport = HttpTransport::new(url, key);
if let Some(ref client) = self.client {
transport.with_client(client.clone())
} else {
transport
}
};
let cognee_key = self.cognee_token.unwrap_or_else(|| self.api_key.clone());
OriginClient {
asset_transport: make_transport(self.asset_url, self.api_key.clone()),
search_transport: make_transport(self.search_url, self.api_key.clone()),
cognee_transport: make_transport(self.cognee_url, cognee_key),
}
}
}
#[derive(Debug, Clone)]
pub struct OriginClient {
asset_transport: HttpTransport,
search_transport: HttpTransport,
cognee_transport: HttpTransport,
}
impl OriginClient {
pub fn new(api_key: impl Into<String>) -> Self {
OriginClientBuilder::new(api_key).build()
}
pub fn builder(api_key: impl Into<String>) -> OriginClientBuilder {
OriginClientBuilder::new(api_key)
}
#[cfg(feature = "asset")]
pub fn asset(&self) -> asset::AssetClient {
asset::AssetClient::new(self.asset_transport.clone())
}
#[cfg(feature = "search")]
pub fn search(&self) -> search::SearchClient {
search::SearchClient::new(self.search_transport.clone())
}
#[cfg(feature = "cognee")]
pub fn cognee(&self) -> cognee::CogneeClient {
cognee::CogneeClient::new(self.cognee_transport.clone())
}
}