Skip to main content

unitycatalog_client/codegen/agents/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::agents::v0alpha1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct AgentServiceClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl AgentServiceClient {
14    /// Create a new client instance
15    pub fn new(client: CloudClient, mut base_url: Url) -> Self {
16        if !base_url.path().ends_with('/') {
17            base_url.set_path(&format!("{}/", base_url.path()));
18        }
19        Self { client, base_url }
20    }
21    /// Lists agents.
22    pub async fn list_agents(&self, request: &ListAgentsRequest) -> Result<ListAgentsResponse> {
23        let mut url = self.base_url.join("agents")?;
24        url.query_pairs_mut()
25            .append_pair("catalog_name", &request.catalog_name);
26        url.query_pairs_mut()
27            .append_pair("schema_name", &request.schema_name);
28        if let Some(ref value) = request.max_results {
29            url.query_pairs_mut()
30                .append_pair("max_results", &value.to_string());
31        }
32        if let Some(ref value) = request.page_token {
33            url.query_pairs_mut()
34                .append_pair("page_token", &value.to_string());
35        }
36        if let Some(ref value) = request.include_browse {
37            url.query_pairs_mut()
38                .append_pair("include_browse", &value.to_string());
39        }
40        let response = self.client.get(url).send().await?;
41        if !response.status().is_success() {
42            return Err(crate::error::parse_error_response(response).await);
43        }
44        let result = response.bytes().await?;
45        Ok(serde_json::from_slice(&result)?)
46    }
47    pub async fn create_agent(&self, request: &CreateAgentRequest) -> Result<Agent> {
48        let url = self.base_url.join("agents")?;
49        let response = self.client.post(url).json(request).send().await?;
50        if !response.status().is_success() {
51            return Err(crate::error::parse_error_response(response).await);
52        }
53        let result = response.bytes().await?;
54        Ok(serde_json::from_slice(&result)?)
55    }
56    pub async fn get_agent(&self, request: &GetAgentRequest) -> Result<Agent> {
57        let formatted_path = format!("agents/{}", request.name);
58        let mut url = self.base_url.join(&formatted_path)?;
59        if let Some(ref value) = request.include_browse {
60            url.query_pairs_mut()
61                .append_pair("include_browse", &value.to_string());
62        }
63        let response = self.client.get(url).send().await?;
64        if !response.status().is_success() {
65            return Err(crate::error::parse_error_response(response).await);
66        }
67        let result = response.bytes().await?;
68        Ok(serde_json::from_slice(&result)?)
69    }
70    pub async fn update_agent(&self, request: &UpdateAgentRequest) -> Result<Agent> {
71        let formatted_path = format!("agents/{}", request.name);
72        let url = self.base_url.join(&formatted_path)?;
73        let response = self.client.patch(url).json(request).send().await?;
74        if !response.status().is_success() {
75            return Err(crate::error::parse_error_response(response).await);
76        }
77        let result = response.bytes().await?;
78        Ok(serde_json::from_slice(&result)?)
79    }
80    pub async fn delete_agent(&self, request: &DeleteAgentRequest) -> Result<()> {
81        let formatted_path = format!("agents/{}", request.name);
82        let url = self.base_url.join(&formatted_path)?;
83        let response = self.client.delete(url).send().await?;
84        if !response.status().is_success() {
85            return Err(crate::error::parse_error_response(response).await);
86        }
87        Ok(())
88    }
89}