uarp-sdk 0.5.7

Async Rust client for the UARP (Snaga) Universal Agent Runtime Platform API
Documentation
// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
//!
//! Unauthenticated public-facing endpoints

#![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;

/// Query and header parameters for `listPublicTenants`.
#[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>,
}

/// Query and header parameters for `publicDomainLookup`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PublicDomainLookupParams {
    pub domain: String,
}

/// Unauthenticated public-facing endpoints
#[derive(Debug, Clone)]
pub struct PublicApi {
    pub(crate) client: Client,
}

impl Client {
    /// Unauthenticated public-facing endpoints
    pub fn public(&self) -> PublicApi {
        PublicApi { client: self.clone() }
    }
}

impl PublicApi {
    /// Create public session
    ///
    /// `POST /api/v1/public/sessions`
    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
    }

    /// Report abusive content from a public chat session
    ///
    /// Anonymous abuse report filed by a public-chat visitor. Requires no authentication of any
    /// kind — the session id in the path is the scope, and it must resolve in the public-session
    /// index. Rate limited per session (5/hour) and per IP (10/hour). The report lands in the
    /// moderation queue of the tenant that owns the agent and raises an in-product notification
    /// there.
    ///
    /// `POST /api/v1/public/sessions/{sessionId}/reports`
    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
    }

    /// Get public agent card
    ///
    /// `GET /api/v1/public/agents/{agentId}`
    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
    }

    /// Get the public featured agent for the landing-page hero
    ///
    /// `GET /api/v1/public/landing/featured-agent`
    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
    }

    /// Get public file content
    ///
    /// `GET /api/v1/public/files/{fileId}/content`
    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
    }

    /// Get public session
    ///
    /// `GET /api/v1/public/sessions/{sessionId}`
    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
    }

    /// Get public state detail
    ///
    /// `GET /api/v1/public/states/{stateId}`
    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
    }

    /// Get public tenant profile
    ///
    /// `GET /api/v1/public/tenants/{slug}`
    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
    }

    /// Tenant custom CSS stylesheet
    ///
    /// Serves tenant-configured branding CSS as `text/css`. Cached with ETag; safe for `\<link
    /// rel=stylesheet\>`.
    ///
    /// `GET /api/v1/public/tenants/{slug}/style.css`
    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
    }

    /// List public plans
    ///
    /// `GET /api/v1/public/plans`
    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
    }

    /// List public states
    ///
    /// `GET /api/v1/public/states`
    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
    }

    /// List public tenants
    ///
    /// `GET /api/v1/public/tenants`
    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
    }

    /// Stream every item returned by `listPublicTenants`, following the `cursor` cursor until the
    /// server reports no further pages.
    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,
                }
            }
        }
    }

    /// Domain lookup
    ///
    /// `GET /api/v1/public/domain-lookup`
    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
    }

    /// Anonymous analytics beacon
    ///
    /// Fire-and-forget event tracker for landing-page funnels. No auth, no PII required;
    /// rate-limited by IP.
    ///
    /// `POST /api/v1/public/track`
    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
    }

    /// Respond to public HITL
    ///
    /// `POST /api/v1/public/sessions/{sessionId}/respond`
    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
    }

    /// Send public message
    ///
    /// `POST /api/v1/public/sessions/{sessionId}/messages`
    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
    }

    /// SSE stream for public session
    ///
    /// `GET /api/v1/public/sessions/{sessionId}/events`
    ///
    /// Returns a server-sent event stream.
    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(),
        )
    }
}