Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 96 additions & 5 deletions core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Base interface for artifact services. */
public interface BaseArtifactService {

Logger logger = LoggerFactory.getLogger(BaseArtifactService.class);

/**
* Saves an artifact.
*
Expand All @@ -36,12 +40,21 @@ public interface BaseArtifactService {
* @param filename the filename
* @param artifact the artifact
* @return the revision ID (version) of the saved artifact.
* @deprecated Use {@link #saveArtifact(SessionKey, String, Part)} instead.
*/
@Deprecated
Single<Integer> saveArtifact(
String appName, String userId, String sessionId, String filename, Part artifact);

/** Saves an artifact. */
/**
* Saves an artifact.
*
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Part artifact) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return saveArtifact(
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
}
Expand All @@ -58,56 +71,118 @@ default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Par
* @param filename the filename
* @param artifact the artifact to save
* @return the saved artifact with fileData if available.
* @deprecated Use {@link #saveAndReloadArtifact(SessionKey, String, Part)} instead.
*/
@Deprecated
default Single<Part> saveAndReloadArtifact(
String appName, String userId, String sessionId, String filename, Part artifact) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
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. */
/**
* Saves an artifact and returns it with fileData if available.
*
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Single<Part> saveAndReloadArtifact(
SessionKey sessionKey, String filename, Part artifact) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return saveAndReloadArtifact(
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
}

/** Loads the latest version of an artifact from the service. */
/**
* Loads the latest version of an artifact from the service.
*
* @deprecated Use {@link #loadArtifact(SessionKey, String)} instead.
*/
@Deprecated
default Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return loadArtifact(appName, userId, sessionId, filename, /* version= */ (Integer) null);
}

/** Loads the latest version of an artifact from the service. */
/**
* Loads the latest version of an artifact from the service.
*
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return loadArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
}

/** Loads a specific version of an artifact from the service. */
/**
* Loads a specific version of an artifact from the service.
*
* @deprecated Use {@link #loadArtifact(SessionKey, String, int)} instead.
*/
@Deprecated
default Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename, int version) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return loadArtifact(appName, userId, sessionId, filename, Integer.valueOf(version));
}

/**
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int version) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return loadArtifact(
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version);
}

/**
* @deprecated Use {@link #loadArtifact(SessionKey, String, Integer)} instead.
*/
@Deprecated
Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename, @Nullable Integer version);

/**
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Maybe<Part> loadArtifact(
SessionKey sessionKey, String filename, @Nullable Integer version) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return loadArtifact(
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, 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
* @deprecated Use {@link #listArtifactKeys(SessionKey)} instead.
*/
@Deprecated
Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId);

/**
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return listArtifactKeys(sessionKey.appName(), sessionKey.userId(), sessionKey.id());
}

Expand All @@ -118,10 +193,18 @@ default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
* @param userId the user ID
* @param sessionId the session ID
* @param filename the filename
* @deprecated Use {@link #deleteArtifact(SessionKey, String)} instead.
*/
@Deprecated
Completable deleteArtifact(String appName, String userId, String sessionId, String filename);

/**
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Completable deleteArtifact(SessionKey sessionKey, String filename) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return deleteArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
}

Expand All @@ -133,11 +216,19 @@ default Completable deleteArtifact(SessionKey sessionKey, String filename) {
* @param sessionId the session ID
* @param filename the artifact filename
* @return A list of integer version numbers.
* @deprecated Use {@link #listVersions(SessionKey, String)} instead.
*/
@Deprecated
Single<ImmutableList<Integer>> listVersions(
String appName, String userId, String sessionId, String filename);

/**
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
* classes must provide their own implementation.
*/
default Single<ImmutableList<Integer>> listVersions(SessionKey sessionKey, String filename) {
logger.warn(
"This method relies on the default implementation, which will be removed in the future.");
return listVersions(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
}
}