Skip to content

Commit a4bf5a1

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

2 files changed

Lines changed: 90 additions & 44 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: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import org.jspecify.annotations.Nullable;
2626

2727
/** Base interface for artifact services. */
28-
public interface BaseArtifactService {
28+
@Deprecated(forRemoval = true)
29+
public interface BaseArtifactService extends ArtifactService {
2930

3031
/**
3132
* Saves an artifact.
@@ -40,55 +41,40 @@ public interface BaseArtifactService {
4041
Single<Integer> saveArtifact(
4142
String appName, String userId, String sessionId, String filename, Part artifact);
4243

43-
/** Saves an artifact. */
4444
default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Part artifact) {
4545
return saveArtifact(
4646
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
4747
}
4848

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-
*/
6249
default Single<Part> saveAndReloadArtifact(
6350
String appName, String userId, String sessionId, String filename, Part artifact) {
6451
return saveArtifact(appName, userId, sessionId, filename, artifact)
6552
.flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle());
6653
}
6754

68-
/** Saves an artifact and returns it with fileData if available. */
55+
@Override
6956
default Single<Part> saveAndReloadArtifact(
7057
SessionKey sessionKey, String filename, Part artifact) {
7158
return saveAndReloadArtifact(
7259
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
7360
}
7461

75-
/** Loads the latest version of an artifact from the service. */
7662
default Maybe<Part> loadArtifact(
7763
String appName, String userId, String sessionId, String filename) {
7864
return loadArtifact(appName, userId, sessionId, filename, /* version= */ (Integer) null);
7965
}
8066

81-
/** Loads the latest version of an artifact from the service. */
67+
@Override
8268
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename) {
8369
return loadArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
8470
}
8571

86-
/** Loads a specific version of an artifact from the service. */
8772
default Maybe<Part> loadArtifact(
8873
String appName, String userId, String sessionId, String filename, int version) {
8974
return loadArtifact(appName, userId, sessionId, filename, Integer.valueOf(version));
9075
}
9176

77+
@Override
9278
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int version) {
9379
return loadArtifact(
9480
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version);
@@ -97,46 +83,24 @@ default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int ver
9783
Maybe<Part> loadArtifact(
9884
String appName, String userId, String sessionId, String filename, @Nullable Integer version);
9985

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-
*/
10886
Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId);
10987

88+
@Override
11089
default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
11190
return listArtifactKeys(sessionKey.appName(), sessionKey.userId(), sessionKey.id());
11291
}
11392

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-
*/
12293
Completable deleteArtifact(String appName, String userId, String sessionId, String filename);
12394

95+
@Override
12496
default Completable deleteArtifact(SessionKey sessionKey, String filename) {
12597
return deleteArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
12698
}
12799

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-
*/
137100
Single<ImmutableList<Integer>> listVersions(
138101
String appName, String userId, String sessionId, String filename);
139102

103+
@Override
140104
default Single<ImmutableList<Integer>> listVersions(SessionKey sessionKey, String filename) {
141105
return listVersions(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
142106
}

0 commit comments

Comments
 (0)