Skip to main content

a2a_protocol_client/methods/
push_config.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F.
3
4//! Push notification configuration client methods.
5//!
6//! Provides `set_push_config`, `get_push_config`, `list_push_configs`, and
7//! `delete_push_config` on [`A2aClient`].
8
9use 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    /// Registers or replaces a push notification configuration for a task.
20    ///
21    /// Calls `CreateTaskPushNotificationConfig`. Returns the configuration as
22    /// stored by the server (including the server-assigned `id`).
23    ///
24    /// # Errors
25    ///
26    /// Returns [`ClientError::Protocol`] with
27    /// [`a2a_protocol_types::ErrorCode::PushNotificationNotSupported`] if the agent
28    /// does not support push notifications.
29    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    /// Retrieves a push notification configuration by task ID and config ID.
57    ///
58    /// Calls `GetTaskPushNotificationConfig`.
59    ///
60    /// # Errors
61    ///
62    /// Returns [`ClientError`] on transport or protocol errors.
63    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(&params).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    /// Lists push notification configurations for a task with pagination.
97    ///
98    /// Calls `ListTaskPushNotificationConfigs`.
99    ///
100    /// # Errors
101    ///
102    /// Returns [`ClientError`] on transport or protocol errors.
103    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(&params).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    /// Deletes a push notification configuration.
130    ///
131    /// Calls `DeleteTaskPushNotificationConfig`.
132    ///
133    /// # Errors
134    ///
135    /// Returns [`ClientError`] on transport or protocol errors.
136    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(&params).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}