use async_trait::async_trait;
use futures::Stream;
use std::pin::Pin;
use crate::domain::{
A2AError, ListTasksParams, ListTasksResult, Message, Task, TaskArtifactUpdateEvent,
TaskPushNotificationConfig, TaskStatusUpdateEvent,
};
#[async_trait]
pub trait Transport: Send + Sync {
fn protocol(&self) -> &str;
async fn send_task_message(
&self,
task_id: &str,
message: &Message,
session_id: Option<&str>,
history_length: Option<u32>,
) -> Result<Task, A2AError>;
async fn get_task(&self, task_id: &str, history_length: Option<u32>) -> Result<Task, A2AError>;
async fn cancel_task(&self, task_id: &str) -> Result<Task, A2AError>;
async fn set_task_push_notification(
&self,
config: &TaskPushNotificationConfig,
) -> Result<TaskPushNotificationConfig, A2AError>;
async fn get_task_push_notification(
&self,
task_id: &str,
) -> Result<TaskPushNotificationConfig, A2AError>;
async fn list_tasks(&self, params: &ListTasksParams) -> Result<ListTasksResult, A2AError>;
async fn list_push_notification_configs(
&self,
task_id: &str,
) -> Result<Vec<TaskPushNotificationConfig>, A2AError>;
async fn get_push_notification_config(
&self,
task_id: &str,
config_id: &str,
) -> Result<TaskPushNotificationConfig, A2AError>;
async fn delete_push_notification_config(
&self,
task_id: &str,
config_id: &str,
) -> Result<(), A2AError>;
async fn subscribe_to_task(
&self,
task_id: &str,
history_length: Option<u32>,
last_event_id: Option<&str>,
) -> Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, A2AError>> + Send>>, A2AError>;
}
#[derive(Debug, Clone)]
pub struct StreamEvent {
pub event_id: Option<u64>,
pub item: StreamItem,
}
impl StreamEvent {
#[inline]
pub fn new(event_id: Option<u64>, item: StreamItem) -> Self {
Self { event_id, item }
}
#[inline]
pub fn untagged(item: StreamItem) -> Self {
Self {
event_id: None,
item,
}
}
}
#[derive(Debug, Clone)]
pub enum StreamItem {
Task(Task),
StatusUpdate(TaskStatusUpdateEvent),
ArtifactUpdate(TaskArtifactUpdateEvent),
}