use a2a_protocol_types::{
DeletePushConfigParams, GetPushConfigParams, ListPushConfigsParams, ListPushConfigsResponse,
TaskPushNotificationConfig,
};
use crate::client::A2aClient;
use crate::error::{ClientError, ClientResult};
use crate::interceptor::{ClientRequest, ClientResponse};
impl A2aClient {
pub async fn set_push_config(
&self,
config: TaskPushNotificationConfig,
) -> ClientResult<TaskPushNotificationConfig> {
const METHOD: &str = "CreateTaskPushNotificationConfig";
let params_value = serde_json::to_value(&config).map_err(ClientError::Serialization)?;
let mut req = ClientRequest::new(METHOD, params_value);
self.interceptors.run_before(&mut req).await?;
let result = self
.transport
.send_request(METHOD, req.params, &req.extra_headers)
.await?;
let resp = ClientResponse {
method: METHOD.to_owned(),
result,
status_code: 200,
};
self.interceptors.run_after(&resp).await?;
serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
.map_err(ClientError::Serialization)
}
pub async fn get_push_config(
&self,
task_id: impl Into<String>,
id: impl Into<String>,
) -> ClientResult<TaskPushNotificationConfig> {
const METHOD: &str = "GetTaskPushNotificationConfig";
let params = GetPushConfigParams {
tenant: None,
task_id: task_id.into(),
id: id.into(),
};
let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
let mut req = ClientRequest::new(METHOD, params_value);
self.interceptors.run_before(&mut req).await?;
let result = self
.transport
.send_request(METHOD, req.params, &req.extra_headers)
.await?;
let resp = ClientResponse {
method: METHOD.to_owned(),
result,
status_code: 200,
};
self.interceptors.run_after(&resp).await?;
serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
.map_err(ClientError::Serialization)
}
pub async fn list_push_configs(
&self,
params: ListPushConfigsParams,
) -> ClientResult<ListPushConfigsResponse> {
const METHOD: &str = "ListTaskPushNotificationConfigs";
let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
let mut req = ClientRequest::new(METHOD, params_value);
self.interceptors.run_before(&mut req).await?;
let result = self
.transport
.send_request(METHOD, req.params, &req.extra_headers)
.await?;
let resp = ClientResponse {
method: METHOD.to_owned(),
result,
status_code: 200,
};
self.interceptors.run_after(&resp).await?;
serde_json::from_value::<ListPushConfigsResponse>(resp.result)
.map_err(ClientError::Serialization)
}
pub async fn delete_push_config(
&self,
task_id: impl Into<String>,
id: impl Into<String>,
) -> ClientResult<()> {
const METHOD: &str = "DeleteTaskPushNotificationConfig";
let params = DeletePushConfigParams {
tenant: None,
task_id: task_id.into(),
id: id.into(),
};
let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
let mut req = ClientRequest::new(METHOD, params_value);
self.interceptors.run_before(&mut req).await?;
let result = self
.transport
.send_request(METHOD, req.params, &req.extra_headers)
.await?;
let resp = ClientResponse {
method: METHOD.to_owned(),
result,
status_code: 200,
};
self.interceptors.run_after(&resp).await?;
Ok(())
}
}