langfuse_client_base/apis/
sessions_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum SessionsGetError {
20 Status400(serde_json::Value),
21 Status401(serde_json::Value),
22 Status403(serde_json::Value),
23 Status404(serde_json::Value),
24 Status405(serde_json::Value),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum SessionsListError {
32 Status400(serde_json::Value),
33 Status401(serde_json::Value),
34 Status403(serde_json::Value),
35 Status404(serde_json::Value),
36 Status405(serde_json::Value),
37 UnknownValue(serde_json::Value),
38}
39
40pub async fn sessions_get(
42 configuration: &configuration::Configuration,
43 session_id: &str,
44) -> Result<models::SessionWithTraces, Error<SessionsGetError>> {
45 let p_path_session_id = session_id;
47
48 let uri_str = format!(
49 "{}/api/public/sessions/{sessionId}",
50 configuration.base_path,
51 sessionId = crate::apis::urlencode(p_path_session_id)
52 );
53 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55 if let Some(ref user_agent) = configuration.user_agent {
56 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57 }
58 if let Some(ref auth_conf) = configuration.basic_auth {
59 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
60 };
61
62 let req = req_builder.build()?;
63 let resp = configuration.client.execute(req).await?;
64
65 let status = resp.status();
66 let content_type = resp
67 .headers()
68 .get("content-type")
69 .and_then(|v| v.to_str().ok())
70 .unwrap_or("application/octet-stream");
71 let content_type = super::ContentType::from(content_type);
72
73 if !status.is_client_error() && !status.is_server_error() {
74 let content = resp.text().await?;
75 match content_type {
76 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
77 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SessionWithTraces`"))),
78 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SessionWithTraces`")))),
79 }
80 } else {
81 let content = resp.text().await?;
82 let entity: Option<SessionsGetError> = serde_json::from_str(&content).ok();
83 Err(Error::ResponseError(ResponseContent {
84 status,
85 content,
86 entity,
87 }))
88 }
89}
90
91pub async fn sessions_list(
93 configuration: &configuration::Configuration,
94 page: Option<i32>,
95 limit: Option<i32>,
96 from_timestamp: Option<String>,
97 to_timestamp: Option<String>,
98 environment: Option<Vec<String>>,
99) -> Result<models::PaginatedSessions, Error<SessionsListError>> {
100 let p_query_page = page;
102 let p_query_limit = limit;
103 let p_query_from_timestamp = from_timestamp;
104 let p_query_to_timestamp = to_timestamp;
105 let p_query_environment = environment;
106
107 let uri_str = format!("{}/api/public/sessions", configuration.base_path);
108 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110 if let Some(ref param_value) = p_query_page {
111 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
112 }
113 if let Some(ref param_value) = p_query_limit {
114 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
115 }
116 if let Some(ref param_value) = p_query_from_timestamp {
117 req_builder = req_builder.query(&[("fromTimestamp", ¶m_value.to_string())]);
118 }
119 if let Some(ref param_value) = p_query_to_timestamp {
120 req_builder = req_builder.query(&[("toTimestamp", ¶m_value.to_string())]);
121 }
122 if let Some(ref param_value) = p_query_environment {
123 req_builder = match "multi" {
124 "multi" => req_builder.query(
125 ¶m_value
126 .into_iter()
127 .map(|p| ("environment".to_owned(), p.to_string()))
128 .collect::<Vec<(std::string::String, std::string::String)>>(),
129 ),
130 _ => req_builder.query(&[(
131 "environment",
132 ¶m_value
133 .into_iter()
134 .map(|p| p.to_string())
135 .collect::<Vec<String>>()
136 .join(",")
137 .to_string(),
138 )]),
139 };
140 }
141 if let Some(ref user_agent) = configuration.user_agent {
142 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143 }
144 if let Some(ref auth_conf) = configuration.basic_auth {
145 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
146 };
147
148 let req = req_builder.build()?;
149 let resp = configuration.client.execute(req).await?;
150
151 let status = resp.status();
152 let content_type = resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let content_type = super::ContentType::from(content_type);
158
159 if !status.is_client_error() && !status.is_server_error() {
160 let content = resp.text().await?;
161 match content_type {
162 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedSessions`"))),
164 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PaginatedSessions`")))),
165 }
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<SessionsListError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent {
170 status,
171 content,
172 entity,
173 }))
174 }
175}