#![allow(unused_imports, clippy::too_many_arguments)]
use reqwest::Method;
use serde::{Deserialize, Serialize};
use futures_core::Stream;
use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::pagination::CursorGuard;
use crate::sse::EventStream;
use crate::util::encode_path;
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ListPublicTenantsParams {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sort: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub search: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PublicDomainLookupParams {
pub domain: String,
}
#[derive(Debug, Clone)]
pub struct PublicApi {
pub(crate) client: Client,
}
impl Client {
pub fn public(&self) -> PublicApi {
PublicApi { client: self.clone() }
}
}
impl PublicApi {
pub async fn create_public_session(&self, body: &models::CreatePublicSessionRequest) -> Result<models::CreatePublicSessionResponse> {
self.client
.request_json(Request {
method: Method::POST,
path: "/api/v1/public/sessions".to_string(),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
pub async fn create_public_session_report(&self, session_id: &str, body: &models::ContentReportInput) -> Result<models::ContentReportAccepted> {
self.client
.request_json(Request {
method: Method::POST,
path: format!("/api/v1/public/sessions/{}/reports", encode_path(session_id)),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
pub async fn get_public_agent_card(&self, agent_id: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/public/agents/{}", encode_path(agent_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_featured_agent(&self) -> Result<models::GetPublicFeaturedAgentResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/public/landing/featured-agent".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_file_content(&self, file_id: &str) -> Result<bytes::Bytes> {
self.client
.request_bytes(Request {
method: Method::GET,
path: format!("/api/v1/public/files/{}/content", encode_path(file_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_session(&self, session_id: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/public/sessions/{}", encode_path(session_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_state(&self, state_id: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/public/states/{}", encode_path(state_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_tenant_profile(&self, slug: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/public/tenants/{}", encode_path(slug)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn get_public_tenant_stylesheet(&self, slug: &str) -> Result<String> {
self.client
.request_text(Request {
method: Method::GET,
path: format!("/api/v1/public/tenants/{}/style.css", encode_path(slug)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn list_public_plans(&self) -> Result<models::ListPublicPlansResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/public/plans".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn list_public_states(&self) -> Result<models::ListPublicStatesResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/public/states".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn list_public_tenants(&self, params: &ListPublicTenantsParams) -> Result<models::ListPublicTenantsResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/public/tenants".to_string(),
query: Some(params),
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub fn list_public_tenants_all<'a>(&'a self, params: &'a ListPublicTenantsParams) -> impl Stream<Item = Result<serde_json::Map<String, serde_json::Value>>> + 'a {
async_stream::try_stream! {
let mut guard = CursorGuard::new();
let mut cursor = params.cursor.clone();
loop {
let mut page_params = params.clone();
page_params.cursor = cursor.clone();
let page = self.list_public_tenants(&page_params).await?;
let items = page.items.unwrap_or_default();
let was_empty = items.is_empty();
for item in items {
yield item;
}
match guard.advance(page.cursor, page.has_more, was_empty) {
Some(next) => cursor = Some(next),
None => break,
}
}
}
}
pub async fn public_domain_lookup(&self, params: &PublicDomainLookupParams) -> Result<models::PublicDomainLookupResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/public/domain-lookup".to_string(),
query: Some(params),
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn public_track_event(&self, body: &models::PublicTrackEventRequest) -> Result<()> {
self.client
.request_empty(Request {
method: Method::POST,
path: "/api/v1/public/track".to_string(),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
pub async fn respond_to_public_hitl(&self, session_id: &str, body: &models::RespondToPublicHitlRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
self.client
.request_json(Request {
method: Method::POST,
path: format!("/api/v1/public/sessions/{}/respond", encode_path(session_id)),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
pub async fn send_public_message(&self, session_id: &str, body: &models::SendPublicMessageRequest) -> Result<models::SendPublicMessageResponse> {
self.client
.request_json(Request {
method: Method::POST,
path: format!("/api/v1/public/sessions/{}/messages", encode_path(session_id)),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
pub fn stream_public_session_events(&self, session_id: &str) -> EventStream {
self.client.request_stream(
&format!("/api/v1/public/sessions/{}/events", encode_path(session_id)),
NO_QUERY,
Vec::new(),
)
}
}