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 ///
30 /// An implementation must honour `req.page_size` and set
31 /// `next_page_token` when more tasks remain. `DefaultRequestHandler`
32 /// clamps `page_size` to
33 /// [`MAX_PAGE_SIZE`](crate::pagination::MAX_PAGE_SIZE) before calling
34 /// this, and truncates the response to that bound if more comes back --
35 /// so a store that ignores `page_size` will have its extra tasks
36 /// dropped, and the caller loses them, because the handler cannot
37 /// synthesise a continuation token for a paging scheme it does not own.
38 async fn list(&self, req: &ListTasksRequest) -> Result<ListTasksResponse, A2AError>;
39}