Skip to main content

adk_artifact/
service.rs

1use adk_core::{Part, Result};
2use async_trait::async_trait;
3
4/// Request to save a binary artifact.
5#[derive(Debug, Clone)]
6pub struct SaveRequest {
7    /// Application namespace.
8    pub app_name: String,
9    /// Owning user.
10    pub user_id: String,
11    /// Session the artifact belongs to.
12    pub session_id: String,
13    /// Artifact filename (validated against path traversal).
14    pub file_name: String,
15    /// The binary content to store.
16    pub part: Part,
17    /// Explicit version to write, or `None` for auto-increment.
18    pub version: Option<i64>,
19}
20
21/// Response from a successful save operation.
22#[derive(Debug, Clone)]
23pub struct SaveResponse {
24    /// The version number that was written.
25    pub version: i64,
26}
27
28/// Request to load an artifact.
29#[derive(Debug, Clone)]
30pub struct LoadRequest {
31    /// Application namespace.
32    pub app_name: String,
33    /// Owning user.
34    pub user_id: String,
35    /// Session the artifact belongs to.
36    pub session_id: String,
37    /// Artifact filename.
38    pub file_name: String,
39    /// Specific version to load, or `None` for the latest.
40    pub version: Option<i64>,
41}
42
43/// Response from a successful load operation.
44#[derive(Debug, Clone)]
45pub struct LoadResponse {
46    /// The binary content that was stored.
47    pub part: Part,
48}
49
50/// Request to delete an artifact.
51#[derive(Debug, Clone)]
52pub struct DeleteRequest {
53    /// Application namespace.
54    pub app_name: String,
55    /// Owning user.
56    pub user_id: String,
57    /// Session the artifact belongs to.
58    pub session_id: String,
59    /// Artifact filename.
60    pub file_name: String,
61    /// Specific version to delete, or `None` to delete all versions.
62    pub version: Option<i64>,
63}
64
65/// Request to list artifacts in a session.
66#[derive(Debug, Clone)]
67pub struct ListRequest {
68    /// Application namespace.
69    pub app_name: String,
70    /// Owning user.
71    pub user_id: String,
72    /// Session to list artifacts from.
73    pub session_id: String,
74}
75
76/// Response containing artifact filenames.
77#[derive(Debug, Clone)]
78pub struct ListResponse {
79    /// Filenames of all artifacts in the session.
80    pub file_names: Vec<String>,
81}
82
83/// Request to list versions of a specific artifact.
84#[derive(Debug, Clone)]
85pub struct VersionsRequest {
86    /// Application namespace.
87    pub app_name: String,
88    /// Owning user.
89    pub user_id: String,
90    /// Session the artifact belongs to.
91    pub session_id: String,
92    /// Artifact filename.
93    pub file_name: String,
94}
95
96/// Response containing available version numbers.
97#[derive(Debug, Clone)]
98pub struct VersionsResponse {
99    /// Version numbers in ascending order.
100    pub versions: Vec<i64>,
101}
102
103/// Trait for artifact storage backends.
104///
105/// Implementations must be thread-safe (`Send + Sync`) and support
106/// versioned binary storage scoped by app, user, and session.
107#[async_trait]
108pub trait ArtifactService: Send + Sync {
109    /// Store a binary artifact, returning the version that was written.
110    async fn save(&self, req: SaveRequest) -> Result<SaveResponse>;
111    /// Retrieve a stored artifact by filename and optional version.
112    async fn load(&self, req: LoadRequest) -> Result<LoadResponse>;
113    /// Delete an artifact (specific version or all versions).
114    async fn delete(&self, req: DeleteRequest) -> Result<()>;
115    /// List all artifact filenames in a session.
116    async fn list(&self, req: ListRequest) -> Result<ListResponse>;
117    /// List all available versions of a specific artifact.
118    async fn versions(&self, req: VersionsRequest) -> Result<VersionsResponse>;
119
120    /// Verify backend connectivity.
121    ///
122    /// The default implementation succeeds, which is appropriate for
123    /// in-memory backends.
124    async fn health_check(&self) -> Result<()> {
125        Ok(())
126    }
127}