1#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct OauthCallbackParams {
19 pub code: String,
20 pub state: String,
21}
22
23#[derive(Debug, Clone)]
25pub struct IntegrationsApi {
26 pub(crate) client: Client,
27}
28
29impl Client {
30 pub fn integrations(&self) -> IntegrationsApi {
32 IntegrationsApi { client: self.clone() }
33 }
34}
35
36impl IntegrationsApi {
37 pub async fn complete_o_auth(&self, provider: &models::StartOAuthProvider, body: &models::OAuthCompleteRequest) -> Result<models::AgentIntegration> {
43 self.client
44 .request_json(Request {
45 method: Method::POST,
46 path: format!("/api/v1/integrations/{}/oauth/complete", encode_path(&provider.to_string())),
47 query: NO_QUERY,
48 body: Some(body),
49 headers: Vec::new(),
50 idempotent: true,
51 })
52 .await
53 }
54
55 pub async fn create(&self, body: &models::CreateIntegrationRequest) -> Result<models::Integration> {
61 self.client
62 .request_json(Request {
63 method: Method::POST,
64 path: "/api/v1/integrations".to_string(),
65 query: NO_QUERY,
66 body: Some(body),
67 headers: Vec::new(),
68 idempotent: true,
69 })
70 .await
71 }
72
73 pub async fn delete(&self, id: &str) -> Result<models::DeleteIntegrationResponse> {
79 self.client
80 .request_json(Request {
81 method: Method::DELETE,
82 path: format!("/api/v1/integrations/{}", encode_path(id)),
83 query: NO_QUERY,
84 body: NO_BODY,
85 headers: Vec::new(),
86 idempotent: true,
87 })
88 .await
89 }
90
91 pub async fn delete_agent_integration(&self, agent_id: &str, integration_id: &str) -> Result<serde_json::Value> {
97 self.client
98 .request_json(Request {
99 method: Method::DELETE,
100 path: format!("/api/v1/agents/{}/integrations/{}", encode_path(agent_id), encode_path(integration_id)),
101 query: NO_QUERY,
102 body: NO_BODY,
103 headers: Vec::new(),
104 idempotent: true,
105 })
106 .await
107 }
108
109 pub async fn list(&self) -> Result<models::ListIntegrationsResponse> {
115 self.client
116 .request_json(Request {
117 method: Method::GET,
118 path: "/api/v1/integrations".to_string(),
119 query: NO_QUERY,
120 body: NO_BODY,
121 headers: Vec::new(),
122 idempotent: false,
123 })
124 .await
125 }
126
127 pub async fn list_agent_integrations(&self, agent_id: &str) -> Result<models::ListAgentIntegrationsResponse> {
133 self.client
134 .request_json(Request {
135 method: Method::GET,
136 path: format!("/api/v1/agents/{}/integrations", encode_path(agent_id)),
137 query: NO_QUERY,
138 body: NO_BODY,
139 headers: Vec::new(),
140 idempotent: false,
141 })
142 .await
143 }
144
145 pub async fn list_integrations_catalog(&self) -> Result<models::ListIntegrationsCatalogResponse> {
151 self.client
152 .request_json(Request {
153 method: Method::GET,
154 path: "/api/v1/integrations/catalog".to_string(),
155 query: NO_QUERY,
156 body: NO_BODY,
157 headers: Vec::new(),
158 idempotent: false,
159 })
160 .await
161 }
162
163 pub async fn oauth_callback(&self, provider: &models::StartOAuthProvider, params: &OauthCallbackParams) -> Result<serde_json::Value> {
169 self.client
170 .request_json(Request {
171 method: Method::GET,
172 path: format!("/api/v1/integrations/{}/oauth/callback", encode_path(&provider.to_string())),
173 query: Some(params),
174 body: NO_BODY,
175 headers: Vec::new(),
176 idempotent: false,
177 })
178 .await
179 }
180
181 pub async fn set_agent_integrations(&self, agent_id: &str, body: &models::SetAgentIntegrationsRequest) -> Result<models::SetAgentIntegrationsResponse> {
200 self.client
201 .request_json(Request {
202 method: Method::PUT,
203 path: format!("/api/v1/agents/{}/integrations", encode_path(agent_id)),
204 query: NO_QUERY,
205 body: Some(body),
206 headers: Vec::new(),
207 idempotent: true,
208 })
209 .await
210 }
211
212 pub async fn start_o_auth(&self, provider: &models::StartOAuthProvider, body: &models::StartOAuthRequest) -> Result<models::OAuthStartResponse> {
218 self.client
219 .request_json(Request {
220 method: Method::POST,
221 path: format!("/api/v1/integrations/{}/oauth/start", encode_path(&provider.to_string())),
222 query: NO_QUERY,
223 body: Some(body),
224 headers: Vec::new(),
225 idempotent: true,
226 })
227 .await
228 }
229
230 pub async fn test_agent_integration(&self, agent_id: &str, integration_id: &str) -> Result<models::TestAgentIntegrationResponse> {
236 self.client
237 .request_json(Request {
238 method: Method::POST,
239 path: format!("/api/v1/agents/{}/integrations/{}/test", encode_path(agent_id), encode_path(integration_id)),
240 query: NO_QUERY,
241 body: NO_BODY,
242 headers: Vec::new(),
243 idempotent: true,
244 })
245 .await
246 }
247
248 pub async fn test_integration(&self, id: &str) -> Result<models::TestIntegrationResponse> {
254 self.client
255 .request_json(Request {
256 method: Method::POST,
257 path: format!("/api/v1/integrations/{}/test", encode_path(id)),
258 query: NO_QUERY,
259 body: NO_BODY,
260 headers: Vec::new(),
261 idempotent: true,
262 })
263 .await
264 }
265
266 pub async fn update(&self, id: &str, body: &models::UpdateIntegrationRequest) -> Result<models::Integration> {
272 self.client
273 .request_json(Request {
274 method: Method::PATCH,
275 path: format!("/api/v1/integrations/{}", encode_path(id)),
276 query: NO_QUERY,
277 body: Some(body),
278 headers: Vec::new(),
279 idempotent: true,
280 })
281 .await
282 }
283
284 pub async fn update_agent_integration(&self, agent_id: &str, integration_id: &str, body: &models::UpdateAgentIntegrationRequest) -> Result<models::AgentIntegration> {
290 self.client
291 .request_json(Request {
292 method: Method::PATCH,
293 path: format!("/api/v1/agents/{}/integrations/{}", encode_path(agent_id), encode_path(integration_id)),
294 query: NO_QUERY,
295 body: Some(body),
296 headers: Vec::new(),
297 idempotent: true,
298 })
299 .await
300 }
301}