brainwires_a2a/server/
handler.rs1use std::pin::Pin;
4
5use async_trait::async_trait;
6use futures::Stream;
7
8use crate::agent_card::AgentCard;
9use crate::error::A2aError;
10use crate::params::*;
11use crate::push_notification::TaskPushNotificationConfig;
12use crate::streaming::{SendMessageResponse, StreamResponse};
13use crate::task::Task;
14
15#[async_trait]
20pub trait A2aHandler: Send + Sync + 'static {
21 fn agent_card(&self) -> &AgentCard;
23
24 async fn on_send_message(
26 &self,
27 req: SendMessageRequest,
28 ) -> Result<SendMessageResponse, A2aError>;
29
30 async fn on_send_streaming_message(
32 &self,
33 req: SendMessageRequest,
34 ) -> Result<Pin<Box<dyn Stream<Item = Result<StreamResponse, A2aError>> + Send>>, A2aError>;
35
36 async fn on_get_task(&self, req: GetTaskRequest) -> Result<Task, A2aError>;
38
39 async fn on_list_tasks(&self, req: ListTasksRequest) -> Result<ListTasksResponse, A2aError>;
41
42 async fn on_cancel_task(&self, req: CancelTaskRequest) -> Result<Task, A2aError>;
44
45 async fn on_subscribe_to_task(
47 &self,
48 req: SubscribeToTaskRequest,
49 ) -> Result<Pin<Box<dyn Stream<Item = Result<StreamResponse, A2aError>> + Send>>, A2aError>;
50
51 async fn on_create_push_config(
53 &self,
54 _config: TaskPushNotificationConfig,
55 ) -> Result<TaskPushNotificationConfig, A2aError> {
56 Err(A2aError::push_not_supported())
57 }
58
59 async fn on_get_push_config(
61 &self,
62 _req: GetTaskPushNotificationConfigRequest,
63 ) -> Result<TaskPushNotificationConfig, A2aError> {
64 Err(A2aError::push_not_supported())
65 }
66
67 async fn on_list_push_configs(
69 &self,
70 _req: ListTaskPushNotificationConfigsRequest,
71 ) -> Result<ListTaskPushNotificationConfigsResponse, A2aError> {
72 Err(A2aError::push_not_supported())
73 }
74
75 async fn on_delete_push_config(
77 &self,
78 _req: DeleteTaskPushNotificationConfigRequest,
79 ) -> Result<(), A2aError> {
80 Err(A2aError::push_not_supported())
81 }
82
83 async fn on_get_extended_agent_card(
85 &self,
86 _req: GetExtendedAgentCardRequest,
87 ) -> Result<AgentCard, A2aError> {
88 Err(A2aError::extended_card_not_configured())
89 }
90}