1515
1616from abc import ABC
1717from abc import abstractmethod
18+ from typing import Any
1819from typing import Optional
1920
2021from google .genai import types
22+ from pydantic import BaseModel
23+ from pydantic import Field
24+
25+
26+ class ArtifactVersion (BaseModel ):
27+ """Represents the metadata of a specific version of an artifact."""
28+
29+ version : int
30+ """The version number of the artifact."""
31+ canonical_uri : str
32+ """The canonical URI of the artifact version."""
33+ custom_metadata : dict [str , Any ] = Field (default_factory = dict )
34+ """A dictionary of custom metadata associated with the artifact version."""
2135
2236
2337class BaseArtifactService (ABC ):
@@ -32,6 +46,7 @@ async def save_artifact(
3246 filename : str ,
3347 artifact : types .Part ,
3448 session_id : Optional [str ] = None ,
49+ custom_metadata : Optional [dict [str , Any ]] = None ,
3550 ) -> int :
3651 """Saves an artifact to the artifact service storage.
3752
@@ -43,8 +58,12 @@ async def save_artifact(
4358 app_name: The app name.
4459 user_id: The user ID.
4560 filename: The filename of the artifact.
46- artifact: The artifact to save.
61+ artifact: The artifact to save. If the artifact consists of `file_data`,
62+ the artifact service assumes its content has been uploaded separately,
63+ and this method will associate the `file_data` with the artifact if
64+ necessary.
4765 session_id: The session ID. If `None`, the artifact is user-scoped.
66+ custom_metadata: custom metadata to associate with the artifact.
4867
4968 Returns:
5069 The revision ID. The first version of the artifact has a revision ID of 0.
@@ -136,3 +155,54 @@ async def list_versions(
136155 Returns:
137156 A list of all available versions of the artifact.
138157 """
158+
159+ @abstractmethod
160+ async def list_artifact_versions (
161+ self ,
162+ * ,
163+ app_name : str ,
164+ user_id : str ,
165+ filename : str ,
166+ session_id : Optional [str ] = None ,
167+ ) -> list [ArtifactVersion ]:
168+ """Lists all versions and their metadata for a specific artifact.
169+
170+ Args:
171+ app_name: The name of the application.
172+ user_id: The ID of the user.
173+ filename: The name of the artifact file.
174+ session_id: The ID of the session. If `None`, lists versions of the
175+ user-scoped artifact. Otherwise, lists versions of the artifact within
176+ the specified session.
177+
178+ Returns:
179+ A list of ArtifactVersion objects, each representing a version of the
180+ artifact and its associated metadata.
181+ """
182+
183+ @abstractmethod
184+ async def get_artifact_version (
185+ self ,
186+ * ,
187+ app_name : str ,
188+ user_id : str ,
189+ filename : str ,
190+ session_id : Optional [str ] = None ,
191+ version : Optional [int ] = None ,
192+ ) -> Optional [ArtifactVersion ]:
193+ """Gets the metadata for a specific version of an artifact.
194+
195+ Args:
196+ app_name: The name of the application.
197+ user_id: The ID of the user.
198+ filename: The name of the artifact file.
199+ session_id: The ID of the session. If `None`, the artifact will be fetched
200+ from the user-scoped artifacts. Otherwise, it will be fetched from the
201+ specified session.
202+ version: The version number of the artifact to retrieve. If `None`, the
203+ latest version will be returned.
204+
205+ Returns:
206+ An ArtifactVersion object containing the metadata of the specified
207+ artifact version, or `None` if the artifact version is not found.
208+ """
0 commit comments