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.
//!
//! Agent marketplace: publish, search, rate

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

/// Query and header parameters for `getListingReviews`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetListingReviewsParams {
    #[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 `searchMarketplace`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SearchMarketplaceParams {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub q: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category: Option<models::SearchMarketplaceCategory>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sort: Option<models::SearchMarketplaceSort>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

/// Agent marketplace: publish, search, rate
#[derive(Debug, Clone)]
pub struct MarketplaceApi {
    pub(crate) client: Client,
}

impl Client {
    /// Agent marketplace: publish, search, rate
    pub fn marketplace(&self) -> MarketplaceApi {
        MarketplaceApi { client: self.clone() }
    }
}

impl MarketplaceApi {
    /// Get marketplace listing details
    ///
    /// `GET /api/v1/marketplace/listings/{listingId}`
    ///
    /// Required scopes: `marketplace:read`.
    pub async fn get_listing(&self, listing_id: &str) -> Result<models::MarketplaceListing> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: format!("/api/v1/marketplace/listings/{}", encode_path(listing_id)),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Get reviews for a listing
    ///
    /// `GET /api/v1/marketplace/listings/{listingId}/reviews`
    pub async fn get_listing_reviews(&self, listing_id: &str, params: &GetListingReviewsParams) -> Result<models::GetListingReviewsResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: format!("/api/v1/marketplace/listings/{}/reviews", encode_path(listing_id)),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Stream every item returned by `getListingReviews`, following the `cursor` cursor until the
    /// server reports no further pages.
    pub fn get_listing_reviews_all<'a>(&'a self, listing_id: &'a str, params: &'a GetListingReviewsParams) -> 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.get_listing_reviews(listing_id, &page_params).await?;
                let items = page.reviews.unwrap_or_default();
                let was_empty = items.is_empty();
                for item in items {
                    yield item;
                }
                match guard.advance(page.cursor, None, was_empty) {
                    Some(next) => cursor = Some(next),
                    None => break,
                }
            }
        }
    }

    /// List marketplace categories
    ///
    /// `GET /api/v1/marketplace/categories`
    ///
    /// Required scopes: `marketplace:read`.
    pub async fn get_marketplace_categories(&self) -> Result<serde_json::Value> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/marketplace/categories".to_string(),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Get invocation status
    ///
    /// `GET /api/v1/marketplace/invocations/{invocationId}`
    ///
    /// Required scopes: `marketplace:read`.
    pub async fn get_marketplace_invocation(&self, invocation_id: &str) -> Result<models::MarketplaceInvocation> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: format!("/api/v1/marketplace/invocations/{}", encode_path(invocation_id)),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Invoke a marketplace agent
    ///
    /// `POST /api/v1/marketplace/listings/{listingId}/invoke`
    ///
    /// Required scopes: `marketplace:invoke`.
    pub async fn invoke_listing_agent(&self, listing_id: &str, body: &models::InvokeListingAgentRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: format!("/api/v1/marketplace/listings/{}/invoke", encode_path(listing_id)),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// List user subscriptions
    ///
    /// `GET /api/v1/marketplace/subscriptions`
    ///
    /// Required scopes: `marketplace:read`.
    pub async fn list_subscriptions(&self) -> Result<models::ListSubscriptionsResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/marketplace/subscriptions".to_string(),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Publish an agent to the marketplace
    ///
    /// `POST /api/v1/marketplace/listings`
    ///
    /// Required scopes: `marketplace:write`.
    pub async fn publish_listing(&self, body: &models::PublishListingRequest) -> Result<models::MarketplaceListing> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: "/api/v1/marketplace/listings".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// Rate a marketplace listing
    ///
    /// `POST /api/v1/marketplace/listings/{listingId}/rate`
    ///
    /// Required scopes: `marketplace:write`.
    pub async fn rate_listing(&self, listing_id: &str, body: &models::RateListingRequest) -> Result<serde_json::Value> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: format!("/api/v1/marketplace/listings/{}/rate", encode_path(listing_id)),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// Search marketplace listings
    ///
    /// `GET /api/v1/marketplace/search`
    ///
    /// Required scopes: `marketplace:read`.
    pub async fn search(&self, params: &SearchMarketplaceParams) -> Result<models::SearchMarketplaceResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/marketplace/search".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Subscribe to a marketplace listing
    ///
    /// `POST /api/v1/marketplace/listings/{listingId}/subscribe`
    ///
    /// Required scopes: `marketplace:write`.
    pub async fn subscribe_to_listing(&self, listing_id: &str, body: &models::SubscribeToListingRequest) -> Result<serde_json::Map<String, serde_json::Value>> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: format!("/api/v1/marketplace/listings/{}/subscribe", encode_path(listing_id)),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// Unpublish a marketplace listing
    ///
    /// `DELETE /api/v1/marketplace/listings/{listingId}`
    ///
    /// Required scopes: `marketplace:write`.
    pub async fn unpublish_listing(&self, listing_id: &str) -> Result<serde_json::Value> {
        self.client
            .request_json(Request {
                method: Method::DELETE,
                path: format!("/api/v1/marketplace/listings/{}", encode_path(listing_id)),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// Unsubscribe from a listing
    ///
    /// `DELETE /api/v1/marketplace/listings/{listingId}/subscribe`
    ///
    /// Required scopes: `marketplace:write`.
    pub async fn unsubscribe_from_listing(&self, listing_id: &str) -> Result<models::UnsubscribeFromListingResponse> {
        self.client
            .request_json(Request {
                method: Method::DELETE,
                path: format!("/api/v1/marketplace/listings/{}/subscribe", encode_path(listing_id)),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }
}