1#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::agent_studio as models;
17
18#[derive(Debug, Clone)]
21pub struct AgentStudioService {
22 pub(crate) client: Ghl,
23}
24
25impl AgentStudioService {
26 pub(crate) fn new(client: Ghl) -> Self {
27 Self { client }
28 }
29}
30
31#[derive(Debug, Clone, Default)]
33pub struct ListAgentsParams {
34 pub location_id: String,
37 pub is_published: Option<String>,
39 pub limit: String,
42 pub offset: String,
45 pub source: Option<String>,
47}
48
49impl ListAgentsParams {
50 pub fn new(
52 location_id: impl Into<String>,
53 limit: impl Into<String>,
54 offset: impl Into<String>,
55 ) -> Self {
56 Self {
57 location_id: location_id.into(),
58 limit: limit.into(),
59 offset: offset.into(),
60 ..Default::default()
61 }
62 }
63
64 pub fn is_published(mut self, v: impl Into<String>) -> Self {
66 self.is_published = Some(v.into());
67 self
68 }
69
70 pub fn source(mut self, v: impl Into<String>) -> Self {
72 self.source = Some(v.into());
73 self
74 }
75
76 fn to_query(&self) -> Vec<(String, String)> {
77 let mut q: Vec<(String, String)> = vec![
78 ("locationId".into(), self.location_id.clone()),
79 ("limit".into(), self.limit.clone()),
80 ("offset".into(), self.offset.clone()),
81 ];
82 if let Some(v) = &self.is_published {
83 q.push(("isPublished".into(), v.to_string()));
84 }
85 if let Some(v) = &self.source {
86 q.push(("source".into(), v.to_string()));
87 }
88 q
89 }
90}
91
92#[derive(Debug, Clone, Default)]
94pub struct CreateAgentParams {
95 pub source: Option<String>,
97}
98
99impl CreateAgentParams {
100 pub fn new() -> Self {
102 Self {
103 ..Default::default()
104 }
105 }
106
107 pub fn source(mut self, v: impl Into<String>) -> Self {
109 self.source = Some(v.into());
110 self
111 }
112
113 fn to_query(&self) -> Vec<(String, String)> {
114 let mut q: Vec<(String, String)> = Vec::new();
115 if let Some(v) = &self.source {
116 q.push(("source".into(), v.to_string()));
117 }
118 q
119 }
120}
121
122#[derive(Debug, Clone, Default)]
124pub struct UpdateAgentParams {
125 pub source: Option<String>,
127}
128
129impl UpdateAgentParams {
130 pub fn new() -> Self {
132 Self {
133 ..Default::default()
134 }
135 }
136
137 pub fn source(mut self, v: impl Into<String>) -> Self {
139 self.source = Some(v.into());
140 self
141 }
142
143 fn to_query(&self) -> Vec<(String, String)> {
144 let mut q: Vec<(String, String)> = Vec::new();
145 if let Some(v) = &self.source {
146 q.push(("source".into(), v.to_string()));
147 }
148 q
149 }
150}
151
152#[derive(Debug, Clone, Default)]
154pub struct PromoteToProductionParams {
155 pub source: Option<String>,
157}
158
159impl PromoteToProductionParams {
160 pub fn new() -> Self {
162 Self {
163 ..Default::default()
164 }
165 }
166
167 pub fn source(mut self, v: impl Into<String>) -> Self {
169 self.source = Some(v.into());
170 self
171 }
172
173 fn to_query(&self) -> Vec<(String, String)> {
174 let mut q: Vec<(String, String)> = Vec::new();
175 if let Some(v) = &self.source {
176 q.push(("source".into(), v.to_string()));
177 }
178 q
179 }
180}
181
182#[derive(Debug, Clone, Default)]
184pub struct DeleteAgentParams {
185 pub location_id: String,
188 pub source: Option<String>,
190}
191
192impl DeleteAgentParams {
193 pub fn new(location_id: impl Into<String>) -> Self {
195 Self {
196 location_id: location_id.into(),
197 ..Default::default()
198 }
199 }
200
201 pub fn source(mut self, v: impl Into<String>) -> Self {
203 self.source = Some(v.into());
204 self
205 }
206
207 fn to_query(&self) -> Vec<(String, String)> {
208 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
209 if let Some(v) = &self.source {
210 q.push(("source".into(), v.to_string()));
211 }
212 q
213 }
214}
215
216#[derive(Debug, Clone, Default)]
218pub struct GetAgentParams {
219 pub location_id: String,
222 pub source: Option<String>,
224}
225
226impl GetAgentParams {
227 pub fn new(location_id: impl Into<String>) -> Self {
229 Self {
230 location_id: location_id.into(),
231 ..Default::default()
232 }
233 }
234
235 pub fn source(mut self, v: impl Into<String>) -> Self {
237 self.source = Some(v.into());
238 self
239 }
240
241 fn to_query(&self) -> Vec<(String, String)> {
242 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
243 if let Some(v) = &self.source {
244 q.push(("source".into(), v.to_string()));
245 }
246 q
247 }
248}
249
250#[derive(Debug, Clone, Default)]
252pub struct UpdateAgentMetadataParams {
253 pub source: Option<String>,
255}
256
257impl UpdateAgentMetadataParams {
258 pub fn new() -> Self {
260 Self {
261 ..Default::default()
262 }
263 }
264
265 pub fn source(mut self, v: impl Into<String>) -> Self {
267 self.source = Some(v.into());
268 self
269 }
270
271 fn to_query(&self) -> Vec<(String, String)> {
272 let mut q: Vec<(String, String)> = Vec::new();
273 if let Some(v) = &self.source {
274 q.push(("source".into(), v.to_string()));
275 }
276 q
277 }
278}
279
280#[derive(Debug, Clone, Default)]
282pub struct ExecuteAgentParams {
283 pub source: Option<String>,
285}
286
287impl ExecuteAgentParams {
288 pub fn new() -> Self {
290 Self {
291 ..Default::default()
292 }
293 }
294
295 pub fn source(mut self, v: impl Into<String>) -> Self {
297 self.source = Some(v.into());
298 self
299 }
300
301 fn to_query(&self) -> Vec<(String, String)> {
302 let mut q: Vec<(String, String)> = Vec::new();
303 if let Some(v) = &self.source {
304 q.push(("source".into(), v.to_string()));
305 }
306 q
307 }
308}
309
310#[derive(Debug, Clone, Default)]
312pub struct ListAgentsDeprecatedParams {
313 pub location_id: String,
316 pub limit: String,
319 pub offset: String,
322 pub source: Option<String>,
324}
325
326impl ListAgentsDeprecatedParams {
327 pub fn new(
329 location_id: impl Into<String>,
330 limit: impl Into<String>,
331 offset: impl Into<String>,
332 ) -> Self {
333 Self {
334 location_id: location_id.into(),
335 limit: limit.into(),
336 offset: offset.into(),
337 ..Default::default()
338 }
339 }
340
341 pub fn source(mut self, v: impl Into<String>) -> Self {
343 self.source = Some(v.into());
344 self
345 }
346
347 fn to_query(&self) -> Vec<(String, String)> {
348 let mut q: Vec<(String, String)> = vec![
349 ("locationId".into(), self.location_id.clone()),
350 ("limit".into(), self.limit.clone()),
351 ("offset".into(), self.offset.clone()),
352 ];
353 if let Some(v) = &self.source {
354 q.push(("source".into(), v.to_string()));
355 }
356 q
357 }
358}
359
360#[derive(Debug, Clone, Default)]
362pub struct GetAgentDeprecatedParams {
363 pub location_id: String,
366 pub source: Option<String>,
368}
369
370impl GetAgentDeprecatedParams {
371 pub fn new(location_id: impl Into<String>) -> Self {
373 Self {
374 location_id: location_id.into(),
375 ..Default::default()
376 }
377 }
378
379 pub fn source(mut self, v: impl Into<String>) -> Self {
381 self.source = Some(v.into());
382 self
383 }
384
385 fn to_query(&self) -> Vec<(String, String)> {
386 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
387 if let Some(v) = &self.source {
388 q.push(("source".into(), v.to_string()));
389 }
390 q
391 }
392}
393
394#[derive(Debug, Clone, Default)]
396pub struct ExecuteAgentDeprecatedParams {
397 pub source: Option<String>,
399}
400
401impl ExecuteAgentDeprecatedParams {
402 pub fn new() -> Self {
404 Self {
405 ..Default::default()
406 }
407 }
408
409 pub fn source(mut self, v: impl Into<String>) -> Self {
411 self.source = Some(v.into());
412 self
413 }
414
415 fn to_query(&self) -> Vec<(String, String)> {
416 let mut q: Vec<(String, String)> = Vec::new();
417 if let Some(v) = &self.source {
418 q.push(("source".into(), v.to_string()));
419 }
420 q
421 }
422}
423
424impl AgentStudioService {
425 pub async fn list_agents(
436 &self,
437 params: &ListAgentsParams,
438 ) -> Result<models::GetPublishedAgentsResponseDTO> {
439 let query = params.to_query();
440 self.client
441 .send_versioned(
442 reqwest::Method::GET,
443 "/agent-studio/agent",
444 &query,
445 None::<&()>,
446 Some("2021-04-15"),
447 )
448 .await
449 }
450
451 pub async fn create_agent(
460 &self,
461 params: &CreateAgentParams,
462 body: &models::CreatePublicAgentDTO,
463 ) -> Result<models::CreatePublicAgentResponseDTO> {
464 let query = params.to_query();
465 self.client
466 .send_versioned(
467 reqwest::Method::POST,
468 "/agent-studio/agent",
469 &query,
470 Some(body),
471 Some("2021-04-15"),
472 )
473 .await
474 }
475
476 pub async fn update_agent(
485 &self,
486 version_id: &str,
487 params: &UpdateAgentParams,
488 body: &models::UpdatePublicAgentVersionDTO,
489 ) -> Result<models::UpdatePublicAgentResponseDTO> {
490 let path = format!(
491 "/agent-studio/agent/versions/{}",
492 crate::services::encode(version_id)
493 );
494 let query = params.to_query();
495 self.client
496 .send_versioned(
497 reqwest::Method::PATCH,
498 &path,
499 &query,
500 Some(body),
501 Some("2021-04-15"),
502 )
503 .await
504 }
505
506 pub async fn promote_to_production(
514 &self,
515 version_id: &str,
516 params: &PromoteToProductionParams,
517 body: &models::PromoteAndPublishDTO,
518 ) -> Result<models::PromoteAndPublishResponseDTO> {
519 let path = format!(
520 "/agent-studio/agent/versions/{}/publish",
521 crate::services::encode(version_id)
522 );
523 let query = params.to_query();
524 self.client
525 .send_versioned(
526 reqwest::Method::POST,
527 &path,
528 &query,
529 Some(body),
530 Some("2021-04-15"),
531 )
532 .await
533 }
534
535 pub async fn delete_agent(
543 &self,
544 agent_id: &str,
545 params: &DeleteAgentParams,
546 ) -> Result<models::DeletePublicAgentResponseDTO> {
547 let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
548 let query = params.to_query();
549 self.client
550 .send_versioned(
551 reqwest::Method::DELETE,
552 &path,
553 &query,
554 None::<&()>,
555 Some("2021-04-15"),
556 )
557 .await
558 }
559
560 pub async fn get_agent(
570 &self,
571 agent_id: &str,
572 params: &GetAgentParams,
573 ) -> Result<models::GetAgentByIdResponseDTO> {
574 let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
575 let query = params.to_query();
576 self.client
577 .send_versioned(
578 reqwest::Method::GET,
579 &path,
580 &query,
581 None::<&()>,
582 Some("2021-04-15"),
583 )
584 .await
585 }
586
587 pub async fn update_agent_metadata(
595 &self,
596 agent_id: &str,
597 params: &UpdateAgentMetadataParams,
598 body: &models::UpdatePublicAgentMetadataDTO,
599 ) -> Result<models::UpdatePublicAgentResponseDTO> {
600 let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
601 let query = params.to_query();
602 self.client
603 .send_versioned(
604 reqwest::Method::PATCH,
605 &path,
606 &query,
607 Some(body),
608 Some("2021-04-15"),
609 )
610 .await
611 }
612
613 pub async fn execute_agent(
628 &self,
629 agent_id: &str,
630 params: &ExecuteAgentParams,
631 body: &models::ExecutePublicAgentDTO,
632 ) -> Result<models::ExecutePublicAgentResponseDTO> {
633 let path = format!(
634 "/agent-studio/agent/{}/execute",
635 crate::services::encode(agent_id)
636 );
637 let query = params.to_query();
638 self.client
639 .send_versioned(
640 reqwest::Method::POST,
641 &path,
642 &query,
643 Some(body),
644 Some("2021-04-15"),
645 )
646 .await
647 }
648
649 pub async fn list_agents_deprecated(
659 &self,
660 params: &ListAgentsDeprecatedParams,
661 ) -> Result<models::GetPublishedAgentsResponseDTO> {
662 let query = params.to_query();
663 self.client
664 .send_versioned(
665 reqwest::Method::GET,
666 "/agent-studio/public-api/agents",
667 &query,
668 None::<&()>,
669 Some("2021-04-15"),
670 )
671 .await
672 }
673
674 pub async fn get_agent_deprecated(
684 &self,
685 agent_id: &str,
686 params: &GetAgentDeprecatedParams,
687 ) -> Result<models::GetAgentByIdResponseDTO> {
688 let path = format!(
689 "/agent-studio/public-api/agents/{}",
690 crate::services::encode(agent_id)
691 );
692 let query = params.to_query();
693 self.client
694 .send_versioned(
695 reqwest::Method::GET,
696 &path,
697 &query,
698 None::<&()>,
699 Some("2021-04-15"),
700 )
701 .await
702 }
703
704 pub async fn execute_agent_deprecated(
719 &self,
720 agent_id: &str,
721 params: &ExecuteAgentDeprecatedParams,
722 body: &models::ExecutePublicAgentDTO,
723 ) -> Result<models::ExecutePublicAgentResponseDTO> {
724 let path = format!(
725 "/agent-studio/public-api/agents/{}/execute",
726 crate::services::encode(agent_id)
727 );
728 let query = params.to_query();
729 self.client
730 .send_versioned(
731 reqwest::Method::POST,
732 &path,
733 &query,
734 Some(body),
735 Some("2021-04-15"),
736 )
737 .await
738 }
739}