From e2c073e1dabd29c7cf027702dc73b12003a42d72 Mon Sep 17 00:00:00 2001 From: Yongki Yusmanthia Date: Fri, 27 Mar 2026 06:12:56 -0700 Subject: [PATCH] refactor: Deprecate methods in BaseArtifactService that use individual session parameters PiperOrigin-RevId: 890411230 --- .../google/adk/artifacts/ArtifactService.java | 82 +++++++++++++++++++ .../adk/artifacts/BaseArtifactService.java | 58 +++---------- 2 files changed, 95 insertions(+), 45 deletions(-) create mode 100644 core/src/main/java/com/google/adk/artifacts/ArtifactService.java diff --git a/core/src/main/java/com/google/adk/artifacts/ArtifactService.java b/core/src/main/java/com/google/adk/artifacts/ArtifactService.java new file mode 100644 index 000000000..48a32bc95 --- /dev/null +++ b/core/src/main/java/com/google/adk/artifacts/ArtifactService.java @@ -0,0 +1,82 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.adk.artifacts; + +import com.google.adk.sessions.SessionKey; +import com.google.common.collect.ImmutableList; +import com.google.genai.types.Part; +import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Maybe; +import io.reactivex.rxjava3.core.Single; + +/** Standard interface for artifact services. */ +public interface ArtifactService { + + /** + * Saves an artifact and returns it with fileData if available. + * + * @param sessionKey the session key + * @param filename the filename + * @param artifact the artifact to save + * @return the saved artifact with fileData if available. + */ + Single saveAndReloadArtifact(SessionKey sessionKey, String filename, Part artifact); + + /** + * Loads the latest version of an artifact from the service. + * + * @param sessionKey the session key + * @param filename the filename + * @return the loaded artifact with fileData if available. + */ + Maybe loadArtifact(SessionKey sessionKey, String filename); + + /** + * Loads a specific version of an artifact from the service. + * + * @param sessionKey the session key + * @param filename the filename + * @param version the version + * @return the loaded artifact with fileData if available. + */ + Maybe loadArtifact(SessionKey sessionKey, String filename, int version); + + /** + * Lists all the artifact filenames within a session. + * + * @param sessionKey the session key + * @return the list artifact response containing filenames + */ + Single listArtifactKeys(SessionKey sessionKey); + + /** + * Deletes an artifact. + * + * @param sessionKey the session key + * @param filename the filename + */ + Completable deleteArtifact(SessionKey sessionKey, String filename); + + /** + * Lists all the versions (as revision IDs) of an artifact. + * + * @param sessionKey the session key + * @param filename the filename + * @return A list of integer version numbers. + */ + Single> listVersions(SessionKey sessionKey, String filename); +} diff --git a/core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java b/core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java index acf5979c2..a65e0c8bb 100644 --- a/core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java +++ b/core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java @@ -24,8 +24,13 @@ import io.reactivex.rxjava3.core.Single; import org.jspecify.annotations.Nullable; -/** Base interface for artifact services. */ -public interface BaseArtifactService { +/** + * Base interface for artifact services. + * + * @deprecated Use {@link ArtifactService} instead. + */ +@Deprecated(forRemoval = true) +public interface BaseArtifactService extends ArtifactService { /** * Saves an artifact. @@ -40,55 +45,40 @@ public interface BaseArtifactService { Single saveArtifact( String appName, String userId, String sessionId, String filename, Part artifact); - /** Saves an artifact. */ default Single saveArtifact(SessionKey sessionKey, String filename, Part artifact) { return saveArtifact( sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact); } - /** - * Saves an artifact and returns it with fileData if available. - * - *

Implementations should override this default method for efficiency, as the default performs - * two I/O operations (save then load). - * - * @param appName the app name - * @param userId the user ID - * @param sessionId the session ID - * @param filename the filename - * @param artifact the artifact to save - * @return the saved artifact with fileData if available. - */ default Single saveAndReloadArtifact( String appName, String userId, String sessionId, String filename, Part artifact) { return saveArtifact(appName, userId, sessionId, filename, artifact) .flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle()); } - /** Saves an artifact and returns it with fileData if available. */ + @Override default Single saveAndReloadArtifact( SessionKey sessionKey, String filename, Part artifact) { return saveAndReloadArtifact( sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact); } - /** Loads the latest version of an artifact from the service. */ default Maybe loadArtifact( String appName, String userId, String sessionId, String filename) { return loadArtifact(appName, userId, sessionId, filename, /* version= */ (Integer) null); } - /** Loads the latest version of an artifact from the service. */ + @Override default Maybe loadArtifact(SessionKey sessionKey, String filename) { return loadArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename); } - /** Loads a specific version of an artifact from the service. */ default Maybe loadArtifact( String appName, String userId, String sessionId, String filename, int version) { return loadArtifact(appName, userId, sessionId, filename, Integer.valueOf(version)); } + @Override default Maybe loadArtifact(SessionKey sessionKey, String filename, int version) { return loadArtifact( sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version); @@ -97,46 +87,24 @@ default Maybe loadArtifact(SessionKey sessionKey, String filename, int ver Maybe loadArtifact( String appName, String userId, String sessionId, String filename, @Nullable Integer version); - /** - * Lists all the artifact filenames within a session. - * - * @param appName the app name - * @param userId the user ID - * @param sessionId the session ID - * @return the list artifact response containing filenames - */ Single listArtifactKeys(String appName, String userId, String sessionId); + @Override default Single listArtifactKeys(SessionKey sessionKey) { return listArtifactKeys(sessionKey.appName(), sessionKey.userId(), sessionKey.id()); } - /** - * Deletes an artifact. - * - * @param appName the app name - * @param userId the user ID - * @param sessionId the session ID - * @param filename the filename - */ Completable deleteArtifact(String appName, String userId, String sessionId, String filename); + @Override default Completable deleteArtifact(SessionKey sessionKey, String filename) { return deleteArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename); } - /** - * Lists all the versions (as revision IDs) of an artifact. - * - * @param appName the app name - * @param userId the user ID - * @param sessionId the session ID - * @param filename the artifact filename - * @return A list of integer version numbers. - */ Single> listVersions( String appName, String userId, String sessionId, String filename); + @Override default Single> listVersions(SessionKey sessionKey, String filename) { return listVersions(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename); }