use async_trait::async_trait;
use turul_a2a_types::{Artifact, Message, Task, TaskStatus};
use super::error::A2aStorageError;
use super::filter::{PushConfigListPage, TaskFilter, TaskListPage};
#[async_trait]
pub trait A2aTaskStorage: Send + Sync {
fn backend_name(&self) -> &'static str;
async fn create_task(
&self,
tenant: &str,
owner: &str,
task: Task,
) -> Result<Task, A2aStorageError>;
async fn get_task(
&self,
tenant: &str,
task_id: &str,
owner: &str,
history_length: Option<i32>,
) -> Result<Option<Task>, A2aStorageError>;
async fn update_task(
&self,
tenant: &str,
owner: &str,
task: Task,
) -> Result<(), A2aStorageError>;
async fn delete_task(
&self,
tenant: &str,
task_id: &str,
owner: &str,
) -> Result<bool, A2aStorageError>;
async fn list_tasks(&self, filter: TaskFilter) -> Result<TaskListPage, A2aStorageError>;
async fn update_task_status(
&self,
tenant: &str,
task_id: &str,
owner: &str,
new_status: TaskStatus,
) -> Result<Task, A2aStorageError>;
async fn append_message(
&self,
tenant: &str,
task_id: &str,
owner: &str,
message: Message,
) -> Result<(), A2aStorageError>;
async fn append_artifact(
&self,
tenant: &str,
task_id: &str,
owner: &str,
artifact: Artifact,
append: bool,
last_chunk: bool,
) -> Result<(), A2aStorageError>;
async fn task_count(&self) -> Result<usize, A2aStorageError>;
async fn maintenance(&self) -> Result<(), A2aStorageError>;
async fn set_cancel_requested(
&self,
tenant: &str,
task_id: &str,
owner: &str,
) -> Result<(), A2aStorageError>;
}
#[async_trait]
pub trait A2aCancellationSupervisor: Send + Sync {
fn backend_name(&self) -> &'static str;
async fn supervisor_get_cancel_requested(
&self,
tenant: &str,
task_id: &str,
) -> Result<bool, A2aStorageError>;
async fn supervisor_list_cancel_requested(
&self,
tenant: &str,
task_ids: &[String],
) -> Result<Vec<String>, A2aStorageError>;
}
#[async_trait]
pub trait A2aPushNotificationStorage: Send + Sync {
fn backend_name(&self) -> &'static str;
async fn create_config(
&self,
tenant: &str,
config: turul_a2a_proto::TaskPushNotificationConfig,
) -> Result<turul_a2a_proto::TaskPushNotificationConfig, A2aStorageError>;
async fn get_config(
&self,
tenant: &str,
task_id: &str,
config_id: &str,
) -> Result<Option<turul_a2a_proto::TaskPushNotificationConfig>, A2aStorageError>;
async fn list_configs(
&self,
tenant: &str,
task_id: &str,
page_token: Option<&str>,
page_size: Option<i32>,
) -> Result<PushConfigListPage, A2aStorageError>;
async fn list_configs_eligible_at_event(
&self,
tenant: &str,
task_id: &str,
event_sequence: u64,
page_token: Option<&str>,
page_size: Option<i32>,
) -> Result<PushConfigListPage, A2aStorageError>;
async fn delete_config(
&self,
tenant: &str,
task_id: &str,
config_id: &str,
) -> Result<(), A2aStorageError>;
}