ghl-sdk 0.5.2

Unofficial async Rust SDK for the GoHighLevel (HighLevel) API 2.0 — OAuth 2.0, Private Integration Tokens, rate-limit-aware retries, paginated streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
// @generated by xtask/generate_services.py — do not edit by hand.
//! `agent-studio` — typed methods for all 11 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().agent_studio()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::agent_studio`](https://docs.rs/ghl-models/latest/ghl_models/v3/agent_studio/); every endpoint is also documented in the
//! [`agent-studio` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/agent-studio.md).
//!
//! Enable with `features = ["agent-studio"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::agent_studio as models;

/// Typed access to the `agent-studio` API v3 surface (11 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().agent_studio()`.
#[derive(Debug, Clone)]
pub struct AgentStudioService {
    pub(crate) client: Ghl,
}

impl AgentStudioService {
    pub(crate) fn new(client: Ghl) -> Self {
        Self { client }
    }
}

/// Query parameters for [`AgentStudioService::list_agents`].
#[derive(Debug, Clone, Default)]
pub struct ListAgentsParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// Optional filter to return only agents with a published production version
    pub is_published: Option<String>,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: String,
    /// `offset` query parameter.
    /// Required by the API.
    pub offset: String,
    /// `source` query parameter.
    pub source: Option<String>,
}

impl ListAgentsParams {
    /// Start from the parameters the API requires.
    pub fn new(
        location_id: impl Into<String>,
        limit: impl Into<String>,
        offset: impl Into<String>,
    ) -> Self {
        Self {
            location_id: location_id.into(),
            limit: limit.into(),
            offset: offset.into(),
            ..Default::default()
        }
    }

    /// Optional filter to return only agents with a published production version
    pub fn is_published(mut self, v: impl Into<String>) -> Self {
        self.is_published = Some(v.into());
        self
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("limit".into(), self.limit.clone()),
            ("offset".into(), self.offset.clone()),
        ];
        if let Some(v) = &self.is_published {
            q.push(("isPublished".into(), v.to_string()));
        }
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::create_agent`].
#[derive(Debug, Clone, Default)]
pub struct CreateAgentParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl CreateAgentParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::update_agent`].
#[derive(Debug, Clone, Default)]
pub struct UpdateAgentParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl UpdateAgentParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::promote_to_production`].
#[derive(Debug, Clone, Default)]
pub struct PromoteToProductionParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl PromoteToProductionParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::delete_agent`].
#[derive(Debug, Clone, Default)]
pub struct DeleteAgentParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `source` query parameter.
    pub source: Option<String>,
}

impl DeleteAgentParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::get_agent`].
#[derive(Debug, Clone, Default)]
pub struct GetAgentParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `source` query parameter.
    pub source: Option<String>,
}

impl GetAgentParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::update_agent_metadata`].
#[derive(Debug, Clone, Default)]
pub struct UpdateAgentMetadataParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl UpdateAgentMetadataParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::execute_agent`].
#[derive(Debug, Clone, Default)]
pub struct ExecuteAgentParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl ExecuteAgentParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::list_agents_deprecated`].
#[derive(Debug, Clone, Default)]
pub struct ListAgentsDeprecatedParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: String,
    /// `offset` query parameter.
    /// Required by the API.
    pub offset: String,
    /// `source` query parameter.
    pub source: Option<String>,
}

impl ListAgentsDeprecatedParams {
    /// Start from the parameters the API requires.
    pub fn new(
        location_id: impl Into<String>,
        limit: impl Into<String>,
        offset: impl Into<String>,
    ) -> Self {
        Self {
            location_id: location_id.into(),
            limit: limit.into(),
            offset: offset.into(),
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("limit".into(), self.limit.clone()),
            ("offset".into(), self.offset.clone()),
        ];
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::get_agent_deprecated`].
#[derive(Debug, Clone, Default)]
pub struct GetAgentDeprecatedParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `source` query parameter.
    pub source: Option<String>,
}

impl GetAgentDeprecatedParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AgentStudioService::execute_agent_deprecated`].
#[derive(Debug, Clone, Default)]
pub struct ExecuteAgentDeprecatedParams {
    /// `source` query parameter.
    pub source: Option<String>,
}

impl ExecuteAgentDeprecatedParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `source` query parameter.
    pub fn source(mut self, v: impl Into<String>) -> Self {
        self.source = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.source {
            q.push(("source".into(), v.to_string()));
        }
        q
    }
}

impl AgentStudioService {
    /// List Agents
    ///
    /// Lists all active agents for the specified location. locationId is required parameter
    /// to ensure optimal performance. Supports pagination using limit and offset.
    /// Optionally filter by isPublished=true to return only agents with a published
    /// production version.
    ///
    /// `GET /agent-studio/agent`
    ///
    /// Requires scope: `agent-studio.readonly`.
    pub async fn list_agents(
        &self,
        params: &ListAgentsParams,
    ) -> Result<models::GetPublishedAgentsResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/agent-studio/agent",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Create Agent
    ///
    /// Creates a new agent with staging version. The agent will be created with an initial
    /// staging version that can later be promoted to production.
    ///
    /// `POST /agent-studio/agent`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn create_agent(
        &self,
        params: &CreateAgentParams,
        body: &models::CreatePublicAgentDTO,
    ) -> Result<models::CreatePublicAgentResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/agent-studio/agent",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Update Agent
    ///
    /// Updates a specific agent version by versionId. Supports updating nodes, edges,
    /// variables, and configuration.
    ///
    /// `PATCH /agent-studio/agent/versions/{versionId}`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn update_agent(
        &self,
        version_id: &str,
        params: &UpdateAgentParams,
        body: &models::UpdatePublicAgentVersionDTO,
    ) -> Result<models::UpdatePublicAgentResponseDTO> {
        let path = format!(
            "/agent-studio/agent/versions/{}",
            crate::services::encode(version_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::PATCH,
                &path,
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Promote to Production
    ///
    /// Promotes a draft version to production.
    ///
    /// `POST /agent-studio/agent/versions/{versionId}/publish`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn promote_to_production(
        &self,
        version_id: &str,
        params: &PromoteToProductionParams,
        body: &models::PromoteAndPublishDTO,
    ) -> Result<models::PromoteAndPublishResponseDTO> {
        let path = format!(
            "/agent-studio/agent/versions/{}/publish",
            crate::services::encode(version_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::POST, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Delete Agent
    ///
    /// Deletes an agent and all its versions.
    ///
    /// `DELETE /agent-studio/agent/{agentId}`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn delete_agent(
        &self,
        agent_id: &str,
        params: &DeleteAgentParams,
    ) -> Result<models::DeletePublicAgentResponseDTO> {
        let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Agent
    ///
    /// Gets a specific agent by its ID for the specified location with all its versions.
    /// Returns complete agent metadata and all non-deleted versions (draft, staging,
    /// production). locationId is required parameter. The agent must have active status.
    ///
    /// `GET /agent-studio/agent/{agentId}`
    ///
    /// Requires scope: `agent-studio.readonly`.
    pub async fn get_agent(
        &self,
        agent_id: &str,
        params: &GetAgentParams,
    ) -> Result<models::GetAgentByIdResponseDTO> {
        let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Update Agent Metadata
    ///
    /// Updates agent metadata such as name, description, and status.
    ///
    /// `PATCH /agent-studio/agent/{agentId}`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn update_agent_metadata(
        &self,
        agent_id: &str,
        params: &UpdateAgentMetadataParams,
        body: &models::UpdatePublicAgentMetadataDTO,
    ) -> Result<models::UpdatePublicAgentResponseDTO> {
        let path = format!("/agent-studio/agent/{}", crate::services::encode(agent_id));
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::PATCH,
                &path,
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Execute Agent
    ///
    /// Executes the specified agent and returns a non-streaming JSON response with the
    /// complete agent output. The agent must be in active status and belong to the
    /// specified location. locationId is required in the request body. **Session
    /// Management:** - For the first message in a new session, do not include the
    /// `executionId` in the request payload. - The API will return an `executionId` along
    /// with the agent response, which uniquely identifies this conversation session. - To
    /// continue the conversation within the same session, include the `executionId` from
    /// the previous response in subsequent requests. T
    ///
    /// `POST /agent-studio/agent/{agentId}/execute`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn execute_agent(
        &self,
        agent_id: &str,
        params: &ExecuteAgentParams,
        body: &models::ExecutePublicAgentDTO,
    ) -> Result<models::ExecutePublicAgentResponseDTO> {
        let path = format!(
            "/agent-studio/agent/{}/execute",
            crate::services::encode(agent_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::POST, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// List Agents (Deprecated)
    ///
    /// **Deprecated endpoint - use GET /agent instead.** Lists all active agents that have
    /// a published production version for the specified location. locationId is required
    /// parameter. Supports pagination using limit and offset.
    ///
    /// `GET /agent-studio/public-api/agents`
    ///
    /// Requires scope: `agent-studio.readonly`.
    pub async fn list_agents_deprecated(
        &self,
        params: &ListAgentsDeprecatedParams,
    ) -> Result<models::GetPublishedAgentsResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/agent-studio/public-api/agents",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Agent (Deprecated)
    ///
    /// **Deprecated endpoint - use GET /agent/:agentId instead.** Gets a specific agent by
    /// its ID for the specified location with all its versions. locationId is required
    /// parameter. The agent must have active status.
    ///
    /// `GET /agent-studio/public-api/agents/{agentId}`
    ///
    /// Requires scope: `agent-studio.readonly`.
    pub async fn get_agent_deprecated(
        &self,
        agent_id: &str,
        params: &GetAgentDeprecatedParams,
    ) -> Result<models::GetAgentByIdResponseDTO> {
        let path = format!(
            "/agent-studio/public-api/agents/{}",
            crate::services::encode(agent_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Execute Agent (Deprecated)
    ///
    /// **Deprecated endpoint - use POST /agent/:agentId/execute instead.** Executes the
    /// specified agent and returns a non-streaming JSON response with the complete agent
    /// output. The agent must be in active status and belong to the specified location.
    /// locationId is required in the request body. **Session Management:** - For the first
    /// message in a new session, do not include the `executionId` in the request payload. -
    /// The API will return an `executionId` along with the agent response, which uniquely
    /// identifies this conversation session. - To continue the conversation within the same
    /// session, include th
    ///
    /// `POST /agent-studio/public-api/agents/{agentId}/execute`
    ///
    /// Requires scope: `agent-studio.write`.
    pub async fn execute_agent_deprecated(
        &self,
        agent_id: &str,
        params: &ExecuteAgentDeprecatedParams,
        body: &models::ExecutePublicAgentDTO,
    ) -> Result<models::ExecutePublicAgentResponseDTO> {
        let path = format!(
            "/agent-studio/public-api/agents/{}/execute",
            crate::services::encode(agent_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::POST, &path, &query, Some(body), Some("v3"))
            .await
    }
}