Skip to content

Commit e2c073e

Browse files
yongkiy-googlecopybara-github
authored andcommitted
refactor: Deprecate methods in BaseArtifactService that use individual session parameters
PiperOrigin-RevId: 890411230
1 parent 4009905 commit e2c073e

2 files changed

Lines changed: 95 additions & 45 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.artifacts;
18+
19+
import com.google.adk.sessions.SessionKey;
20+
import com.google.common.collect.ImmutableList;
21+
import com.google.genai.types.Part;
22+
import io.reactivex.rxjava3.core.Completable;
23+
import io.reactivex.rxjava3.core.Maybe;
24+
import io.reactivex.rxjava3.core.Single;
25+
26+
/** Standard interface for artifact services. */
27+
public interface ArtifactService {
28+
29+
/**
30+
* Saves an artifact and returns it with fileData if available.
31+
*
32+
* @param sessionKey the session key
33+
* @param filename the filename
34+
* @param artifact the artifact to save
35+
* @return the saved artifact with fileData if available.
36+
*/
37+
Single<Part> saveAndReloadArtifact(SessionKey sessionKey, String filename, Part artifact);
38+
39+
/**
40+
* Loads the latest version of an artifact from the service.
41+
*
42+
* @param sessionKey the session key
43+
* @param filename the filename
44+
* @return the loaded artifact with fileData if available.
45+
*/
46+
Maybe<Part> loadArtifact(SessionKey sessionKey, String filename);
47+
48+
/**
49+
* Loads a specific version of an artifact from the service.
50+
*
51+
* @param sessionKey the session key
52+
* @param filename the filename
53+
* @param version the version
54+
* @return the loaded artifact with fileData if available.
55+
*/
56+
Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int version);
57+
58+
/**
59+
* Lists all the artifact filenames within a session.
60+
*
61+
* @param sessionKey the session key
62+
* @return the list artifact response containing filenames
63+
*/
64+
Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey);
65+
66+
/**
67+
* Deletes an artifact.
68+
*
69+
* @param sessionKey the session key
70+
* @param filename the filename
71+
*/
72+
Completable deleteArtifact(SessionKey sessionKey, String filename);
73+
74+
/**
75+
* Lists all the versions (as revision IDs) of an artifact.
76+
*
77+
* @param sessionKey the session key
78+
* @param filename the filename
79+
* @return A list of integer version numbers.
80+
*/
81+
Single<ImmutableList<Integer>> listVersions(SessionKey sessionKey, String filename);
82+
}

core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
import io.reactivex.rxjava3.core.Single;
2525
import org.jspecify.annotations.Nullable;
2626

27-
/** Base interface for artifact services. */
28-
public interface BaseArtifactService {
27+
/**
28+
* Base interface for artifact services.
29+
*
30+
* @deprecated Use {@link ArtifactService} instead.
31+
*/
32+
@Deprecated(forRemoval = true)
33+
public interface BaseArtifactService extends ArtifactService {
2934

3035
/**
3136
* Saves an artifact.
@@ -40,55 +45,40 @@ public interface BaseArtifactService {
4045
Single<Integer> saveArtifact(
4146
String appName, String userId, String sessionId, String filename, Part artifact);
4247

43-
/** Saves an artifact. */
4448
default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Part artifact) {
4549
return saveArtifact(
4650
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
4751
}
4852

49-
/**
50-
* Saves an artifact and returns it with fileData if available.
51-
*
52-
* <p>Implementations should override this default method for efficiency, as the default performs
53-
* two I/O operations (save then load).
54-
*
55-
* @param appName the app name
56-
* @param userId the user ID
57-
* @param sessionId the session ID
58-
* @param filename the filename
59-
* @param artifact the artifact to save
60-
* @return the saved artifact with fileData if available.
61-
*/
6253
default Single<Part> saveAndReloadArtifact(
6354
String appName, String userId, String sessionId, String filename, Part artifact) {
6455
return saveArtifact(appName, userId, sessionId, filename, artifact)
6556
.flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle());
6657
}
6758

68-
/** Saves an artifact and returns it with fileData if available. */
59+
@Override
6960
default Single<Part> saveAndReloadArtifact(
7061
SessionKey sessionKey, String filename, Part artifact) {
7162
return saveAndReloadArtifact(
7263
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
7364
}
7465

75-
/** Loads the latest version of an artifact from the service. */
7666
default Maybe<Part> loadArtifact(
7767
String appName, String userId, String sessionId, String filename) {
7868
return loadArtifact(appName, userId, sessionId, filename, /* version= */ (Integer) null);
7969
}
8070

81-
/** Loads the latest version of an artifact from the service. */
71+
@Override
8272
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename) {
8373
return loadArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
8474
}
8575

86-
/** Loads a specific version of an artifact from the service. */
8776
default Maybe<Part> loadArtifact(
8877
String appName, String userId, String sessionId, String filename, int version) {
8978
return loadArtifact(appName, userId, sessionId, filename, Integer.valueOf(version));
9079
}
9180

81+
@Override
9282
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int version) {
9383
return loadArtifact(
9484
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version);
@@ -97,46 +87,24 @@ default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int ver
9787
Maybe<Part> loadArtifact(
9888
String appName, String userId, String sessionId, String filename, @Nullable Integer version);
9989

100-
/**
101-
* Lists all the artifact filenames within a session.
102-
*
103-
* @param appName the app name
104-
* @param userId the user ID
105-
* @param sessionId the session ID
106-
* @return the list artifact response containing filenames
107-
*/
10890
Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId);
10991

92+
@Override
11093
default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
11194
return listArtifactKeys(sessionKey.appName(), sessionKey.userId(), sessionKey.id());
11295
}
11396

114-
/**
115-
* Deletes an artifact.
116-
*
117-
* @param appName the app name
118-
* @param userId the user ID
119-
* @param sessionId the session ID
120-
* @param filename the filename
121-
*/
12297
Completable deleteArtifact(String appName, String userId, String sessionId, String filename);
12398

99+
@Override
124100
default Completable deleteArtifact(SessionKey sessionKey, String filename) {
125101
return deleteArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
126102
}
127103

128-
/**
129-
* Lists all the versions (as revision IDs) of an artifact.
130-
*
131-
* @param appName the app name
132-
* @param userId the user ID
133-
* @param sessionId the session ID
134-
* @param filename the artifact filename
135-
* @return A list of integer version numbers.
136-
*/
137104
Single<ImmutableList<Integer>> listVersions(
138105
String appName, String userId, String sessionId, String filename);
139106

107+
@Override
140108
default Single<ImmutableList<Integer>> listVersions(SessionKey sessionKey, String filename) {
141109
return listVersions(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
142110
}

0 commit comments

Comments
 (0)