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