Skip to main content

openapp_sdk_core/resources/
lan_agent.rs

1//! `LAN agent` resource group.
2
3use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::{JsonValue, types};
8use crate::{
9    error::SdkError,
10    transport::{RequestSpec, Transport},
11};
12
13#[derive(Debug, Clone)]
14pub struct LanAgentClient {
15    transport: Arc<Transport>,
16}
17
18impl LanAgentClient {
19    pub(crate) fn new(transport: Arc<Transport>) -> Self {
20        Self { transport }
21    }
22
23    pub async fn meta(&self) -> Result<types::LanAgentMetaResponse, SdkError> {
24        self.transport
25            .request_json::<(), types::LanAgentMetaResponse>(RequestSpec {
26                method: Method::GET,
27                path: "/lan-agent/meta",
28                ..Default::default()
29            })
30            .await
31    }
32
33    pub async fn bootstrap_script(&self) -> Result<JsonValue, SdkError> {
34        self.transport
35            .request_json::<(), JsonValue>(RequestSpec {
36                method: Method::GET,
37                path: "/lan-agent/cli/bootstrap.sh",
38                ..Default::default()
39            })
40            .await
41    }
42
43    pub async fn bootstrap_token(
44        &self,
45        body: &types::LanAgentBootstrapTokenRequest,
46    ) -> Result<types::LanAgentBootstrapTokenResponse, SdkError> {
47        self.transport
48            .request_json::<
49                types::LanAgentBootstrapTokenRequest,
50                types::LanAgentBootstrapTokenResponse,
51            >(RequestSpec {
52                method: Method::POST,
53                path: "/lan-agent/cli/bootstrap-token",
54                body: Some(body),
55                ..Default::default()
56            })
57            .await
58    }
59
60    pub async fn token(&self) -> Result<types::LanAgentCliTokenResponse, SdkError> {
61        self.transport
62            .request_json::<(), types::LanAgentCliTokenResponse>(RequestSpec {
63                method: Method::POST,
64                path: "/lan-agent/cli/token",
65                ..Default::default()
66            })
67            .await
68    }
69
70    pub async fn submit_task_spec(
71        &self,
72        integration_id: &str,
73        body: &types::LanAgentTaskSpecRequest,
74    ) -> Result<types::LanAgentTaskSpecResponse, SdkError> {
75        let path = format!("/integrations/{integration_id}/lan-agent/task-spec");
76        self.transport
77            .request_json::<types::LanAgentTaskSpecRequest, types::LanAgentTaskSpecResponse>(
78                RequestSpec {
79                    method: Method::POST,
80                    path: &path,
81                    body: Some(body),
82                    ..Default::default()
83                },
84            )
85            .await
86    }
87
88    pub async fn list_tasks(&self, integration_id: &str) -> Result<Vec<JsonValue>, SdkError> {
89        let path = format!("/integrations/{integration_id}/lan-agent/tasks");
90        self.transport
91            .request_json::<(), Vec<JsonValue>>(RequestSpec {
92                method: Method::GET,
93                path: &path,
94                ..Default::default()
95            })
96            .await
97    }
98}