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
40#[deprecated]
42#[bon::builder]
43pub async fn sessions_get(
44 configuration: &configuration::Configuration,
45 session_id: &str,
46) -> Result<models::SessionWithTraces, Error<SessionsGetError>> {
47 let p_path_session_id = session_id;
49
50 let uri_str = format!(
51 "{}/api/public/sessions/{sessionId}",
52 configuration.base_path,
53 sessionId = crate::apis::urlencode(p_path_session_id)
54 );
55 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
56
57 if let Some(ref user_agent) = configuration.user_agent {
58 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
59 }
60 if let Some(ref auth_conf) = configuration.basic_auth {
61 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
62 };
63
64 let req = req_builder.build()?;
65 let resp = configuration.client.execute(req).await?;
66
67 let status = resp.status();
68 let content_type = resp
69 .headers()
70 .get("content-type")
71 .and_then(|v| v.to_str().ok())
72 .unwrap_or("application/octet-stream");
73 let content_type = super::ContentType::from(content_type);
74
75 if !status.is_client_error() && !status.is_server_error() {
76 let content = resp.text().await?;
77 match content_type {
78 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SessionWithTraces`"))),
80 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`")))),
81 }
82 } else {
83 let content = resp.text().await?;
84 let entity: Option<SessionsGetError> = serde_json::from_str(&content).ok();
85 Err(Error::ResponseError(ResponseContent {
86 status,
87 content,
88 entity,
89 }))
90 }
91}
92
93#[deprecated]
95#[bon::builder]
96pub async fn sessions_list(
97 configuration: &configuration::Configuration,
98 page: Option<i32>,
99 limit: Option<i32>,
100 from_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
101 to_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
102 environment: Option<Vec<String>>,
103) -> Result<models::PaginatedSessions, Error<SessionsListError>> {
104 let p_query_page = page;
106 let p_query_limit = limit;
107 let p_query_from_timestamp = from_timestamp;
108 let p_query_to_timestamp = to_timestamp;
109 let p_query_environment = environment;
110
111 let uri_str = format!("{}/api/public/sessions", configuration.base_path);
112 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
113
114 if let Some(ref param_value) = p_query_page {
115 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
116 }
117 if let Some(ref param_value) = p_query_limit {
118 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
119 }
120 if let Some(ref param_value) = p_query_from_timestamp {
121 req_builder = req_builder.query(&[("fromTimestamp", ¶m_value.to_string())]);
122 }
123 if let Some(ref param_value) = p_query_to_timestamp {
124 req_builder = req_builder.query(&[("toTimestamp", ¶m_value.to_string())]);
125 }
126 if let Some(ref param_value) = p_query_environment {
127 req_builder = match "multi" {
128 "multi" => req_builder.query(
129 ¶m_value
130 .into_iter()
131 .map(|p| ("environment".to_owned(), p.to_string()))
132 .collect::<Vec<(std::string::String, std::string::String)>>(),
133 ),
134 _ => req_builder.query(&[(
135 "environment",
136 ¶m_value
137 .into_iter()
138 .map(|p| p.to_string())
139 .collect::<Vec<String>>()
140 .join(",")
141 .to_string(),
142 )]),
143 };
144 }
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref auth_conf) = configuration.basic_auth {
149 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedSessions`"))),
168 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`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<SessionsListError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent {
174 status,
175 content,
176 entity,
177 }))
178 }
179}