a2a_protocol_client/methods/
push_config.rs1use a2a_protocol_types::{
10 DeletePushConfigParams, GetPushConfigParams, ListPushConfigsParams, ListPushConfigsResponse,
11 TaskPushNotificationConfig,
12};
13
14use crate::client::A2aClient;
15use crate::error::{ClientError, ClientResult};
16use crate::interceptor::{ClientRequest, ClientResponse};
17
18impl A2aClient {
19 pub async fn set_push_config(
30 &self,
31 config: TaskPushNotificationConfig,
32 ) -> ClientResult<TaskPushNotificationConfig> {
33 const METHOD: &str = "CreateTaskPushNotificationConfig";
34
35 let params_value = serde_json::to_value(&config).map_err(ClientError::Serialization)?;
36
37 let mut req = ClientRequest::new(METHOD, params_value);
38 self.interceptors.run_before(&mut req).await?;
39
40 let result = self
41 .transport
42 .send_request(METHOD, req.params, &req.extra_headers)
43 .await?;
44
45 let resp = ClientResponse {
46 method: METHOD.to_owned(),
47 result,
48 status_code: 200,
49 };
50 self.interceptors.run_after(&resp).await?;
51
52 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
53 .map_err(ClientError::Serialization)
54 }
55
56 pub async fn get_push_config(
64 &self,
65 task_id: impl Into<String>,
66 id: impl Into<String>,
67 ) -> ClientResult<TaskPushNotificationConfig> {
68 const METHOD: &str = "GetTaskPushNotificationConfig";
69
70 let params = GetPushConfigParams {
71 tenant: None,
72 task_id: task_id.into(),
73 id: id.into(),
74 };
75 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
76
77 let mut req = ClientRequest::new(METHOD, params_value);
78 self.interceptors.run_before(&mut req).await?;
79
80 let result = self
81 .transport
82 .send_request(METHOD, req.params, &req.extra_headers)
83 .await?;
84
85 let resp = ClientResponse {
86 method: METHOD.to_owned(),
87 result,
88 status_code: 200,
89 };
90 self.interceptors.run_after(&resp).await?;
91
92 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
93 .map_err(ClientError::Serialization)
94 }
95
96 pub async fn list_push_configs(
104 &self,
105 params: ListPushConfigsParams,
106 ) -> ClientResult<ListPushConfigsResponse> {
107 const METHOD: &str = "ListTaskPushNotificationConfigs";
108
109 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
110 let mut req = ClientRequest::new(METHOD, params_value);
111 self.interceptors.run_before(&mut req).await?;
112
113 let result = self
114 .transport
115 .send_request(METHOD, req.params, &req.extra_headers)
116 .await?;
117
118 let resp = ClientResponse {
119 method: METHOD.to_owned(),
120 result,
121 status_code: 200,
122 };
123 self.interceptors.run_after(&resp).await?;
124
125 serde_json::from_value::<ListPushConfigsResponse>(resp.result)
126 .map_err(ClientError::Serialization)
127 }
128
129 pub async fn delete_push_config(
137 &self,
138 task_id: impl Into<String>,
139 id: impl Into<String>,
140 ) -> ClientResult<()> {
141 const METHOD: &str = "DeleteTaskPushNotificationConfig";
142
143 let params = DeletePushConfigParams {
144 tenant: None,
145 task_id: task_id.into(),
146 id: id.into(),
147 };
148 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
149
150 let mut req = ClientRequest::new(METHOD, params_value);
151 self.interceptors.run_before(&mut req).await?;
152
153 let result = self
154 .transport
155 .send_request(METHOD, req.params, &req.extra_headers)
156 .await?;
157
158 let resp = ClientResponse {
159 method: METHOD.to_owned(),
160 result,
161 status_code: 200,
162 };
163 self.interceptors.run_after(&resp).await?;
164
165 Ok(())
166 }
167}