Skip to main content

kontext_dev_sdk/management/
agent_instances.rs

1//! Agent Sessions API (historical alias: Agent Instances).
2
3use std::sync::Arc;
4
5use kontext_dev_sdk_core::types::{
6    AgentInstanceListParams, AgentInstanceResponse, ListAgentInstancesResponse,
7};
8
9use crate::http_client::{HttpClient, HttpError, RequestOptions, RequestParams};
10
11/// TS-compatible name.
12pub type AgentSessionsResource = AgentInstancesApi;
13
14#[derive(Clone)]
15pub struct AgentInstancesApi {
16    http: Arc<HttpClient>,
17}
18
19impl AgentInstancesApi {
20    pub fn new(http: Arc<HttpClient>) -> Self {
21        Self { http }
22    }
23
24    pub async fn list(
25        &self,
26        params: Option<AgentInstanceListParams>,
27    ) -> Result<ListAgentInstancesResponse, HttpError> {
28        let options = params.map(|p| {
29            let mut request_params = RequestParams::new();
30            if let Some(limit) = p.limit {
31                request_params.insert("limit".to_string(), limit.to_string());
32            }
33            if let Some(cursor) = p.cursor {
34                request_params.insert("cursor".to_string(), cursor);
35            }
36            if let Some(application_id) = p.application_id {
37                request_params.insert("applicationId".to_string(), application_id);
38            }
39            if let Some(member_id) = p.member_id {
40                request_params.insert("memberId".to_string(), member_id);
41            }
42            if let Some(status) = p.status {
43                request_params.insert("status".to_string(), status);
44            }
45            RequestOptions {
46                params: Some(request_params),
47                headers: None,
48            }
49        });
50        self.http.get("/agent-instances", options).await
51    }
52
53    pub async fn get(&self, id: &str) -> Result<AgentInstanceResponse, HttpError> {
54        self.http.get(&format!("/agent-instances/{id}"), None).await
55    }
56
57    pub async fn revoke(&self, id: &str) -> Result<(), HttpError> {
58        self.http
59            .delete_no_content(&format!("/agent-instances/{id}"), None)
60            .await
61    }
62
63    pub async fn revoke_for_application(&self, application_id: &str) -> Result<(), HttpError> {
64        self.http
65            .delete_no_content(
66                &format!("/applications/{application_id}/agent-instances"),
67                None,
68            )
69            .await
70    }
71}