Skip to main content

a2a_server/task_store/
store.rs

1// Copyright AGNTCY Contributors (https://github.com/agntcy)
2// SPDX-License-Identifier: Apache-2.0
3use a2a::*;
4use async_trait::async_trait;
5
6/// Version counter for optimistic concurrency control.
7pub type TaskVersion = u64;
8
9/// A task stored with version metadata.
10#[derive(Debug, Clone)]
11pub struct StoredTask {
12    pub task: Task,
13    pub version: TaskVersion,
14}
15
16/// Interface for persisting and retrieving tasks.
17#[async_trait]
18pub trait TaskStore: Send + Sync + 'static {
19    /// Create a new task. Returns the initial version.
20    async fn create(&self, task: Task) -> Result<TaskVersion, A2AError>;
21
22    /// Update an existing task. Returns the new version.
23    async fn update(&self, task: Task) -> Result<TaskVersion, A2AError>;
24
25    /// Get a task by ID.
26    async fn get(&self, task_id: &str) -> Result<Option<Task>, A2AError>;
27
28    /// List tasks matching the request criteria.
29    async fn list(&self, req: &ListTasksRequest) -> Result<ListTasksResponse, A2AError>;
30}