1919import com .fasterxml .jackson .annotation .JsonProperty ;
2020import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
2121import com .google .adk .JsonBaseModel ;
22- import com .google .adk .sessions .State ;
2322import com .google .errorprone .annotations .CanIgnoreReturnValue ;
24- import java .util .HashSet ;
23+ import java .util .Collections ;
24+ import java .util .HashMap ;
25+ import java .util .Map ;
2526import java .util .Objects ;
2627import java .util .Optional ;
2728import java .util .Set ;
28- import java .util .concurrent .ConcurrentHashMap ;
29- import java .util .concurrent .ConcurrentMap ;
3029import javax .annotation .Nullable ;
3130
3231/** Represents the actions attached to an event. */
3534public class EventActions extends JsonBaseModel {
3635
3736 private Optional <Boolean > skipSummarization ;
38- private ConcurrentMap <String , Object > stateDelta ;
39- private ConcurrentMap <String , Integer > artifactDelta ;
40- private Set <String > deletedArtifactIds ;
37+ private Map <String , Object > stateDelta ;
38+ private Map <String , Integer > artifactDelta ;
4139 private Optional <String > transferToAgent ;
4240 private Optional <Boolean > escalate ;
43- private ConcurrentMap <String , ConcurrentMap <String , Object >> requestedAuthConfigs ;
44- private ConcurrentMap <String , ToolConfirmation > requestedToolConfirmations ;
41+ private Map <String , Map <String , Object >> requestedAuthConfigs ;
42+ private Map <String , ToolConfirmation > requestedToolConfirmations ;
4543 private boolean endOfAgent ;
4644 private Optional <EventCompaction > compaction ;
4745
4846 /** Default constructor for Jackson. */
4947 public EventActions () {
5048 this .skipSummarization = Optional .empty ();
51- this .stateDelta = new ConcurrentHashMap <>();
52- this .artifactDelta = new ConcurrentHashMap <>();
53- this .deletedArtifactIds = new HashSet <>();
49+ this .stateDelta = Collections .synchronizedMap (new HashMap <>());
50+ this .artifactDelta = Collections .synchronizedMap (new HashMap <>());
5451 this .transferToAgent = Optional .empty ();
5552 this .escalate = Optional .empty ();
56- this .requestedAuthConfigs = new ConcurrentHashMap <>();
57- this .requestedToolConfirmations = new ConcurrentHashMap <>();
53+ this .requestedAuthConfigs = Collections . synchronizedMap ( new HashMap <>() );
54+ this .requestedToolConfirmations = Collections . synchronizedMap ( new HashMap <>() );
5855 this .endOfAgent = false ;
5956 this .compaction = Optional .empty ();
6057 }
6158
6259 private EventActions (Builder builder ) {
6360 this .skipSummarization = builder .skipSummarization ;
64- this .stateDelta = builder .stateDelta ;
65- this .artifactDelta = builder .artifactDelta ;
66- this .deletedArtifactIds = builder .deletedArtifactIds ;
61+ this .stateDelta = Collections .synchronizedMap (builder .stateDelta );
62+ this .artifactDelta = Collections .synchronizedMap (builder .artifactDelta );
6763 this .transferToAgent = builder .transferToAgent ;
6864 this .escalate = builder .escalate ;
69- this .requestedAuthConfigs = builder .requestedAuthConfigs ;
70- this .requestedToolConfirmations = builder .requestedToolConfirmations ;
65+ this .requestedAuthConfigs = Collections .synchronizedMap (builder .requestedAuthConfigs );
66+ this .requestedToolConfirmations =
67+ Collections .synchronizedMap (builder .requestedToolConfirmations );
7168 this .endOfAgent = builder .endOfAgent ;
7269 this .compaction = builder .compaction ;
7370 }
@@ -90,41 +87,32 @@ public void setSkipSummarization(boolean skipSummarization) {
9087 }
9188
9289 @ JsonProperty ("stateDelta" )
93- public ConcurrentMap <String , Object > stateDelta () {
90+ public Map <String , Object > stateDelta () {
9491 return stateDelta ;
9592 }
9693
97- @ Deprecated // Use stateDelta(), addState() and removeStateByKey() instead.
98- public void setStateDelta (ConcurrentMap <String , Object > stateDelta ) {
99- this .stateDelta = stateDelta ;
94+ public void setStateDelta (Map <String , Object > stateDelta ) {
95+ this .stateDelta = Collections .synchronizedMap (new HashMap <>(stateDelta ));
10096 }
10197
10298 /**
10399 * Removes a key from the state delta.
104100 *
105101 * @param key The key to remove.
102+ * @deprecated Use {@link #stateDelta()}.put(key, null) instead.
106103 */
104+ @ Deprecated
107105 public void removeStateByKey (String key ) {
108- stateDelta .put (key , State . REMOVED );
106+ stateDelta () .put (key , null );
109107 }
110108
111109 @ JsonProperty ("artifactDelta" )
112- public ConcurrentMap <String , Integer > artifactDelta () {
110+ public Map <String , Integer > artifactDelta () {
113111 return artifactDelta ;
114112 }
115113
116- public void setArtifactDelta (ConcurrentMap <String , Integer > artifactDelta ) {
117- this .artifactDelta = artifactDelta ;
118- }
119-
120- @ JsonProperty ("deletedArtifactIds" )
121- @ JsonInclude (JsonInclude .Include .NON_EMPTY )
122- public Set <String > deletedArtifactIds () {
123- return deletedArtifactIds ;
124- }
125-
126- public void setDeletedArtifactIds (Set <String > deletedArtifactIds ) {
127- this .deletedArtifactIds = deletedArtifactIds ;
114+ public void setArtifactDelta (Map <String , Integer > artifactDelta ) {
115+ this .artifactDelta = Collections .synchronizedMap (new HashMap <>(artifactDelta ));
128116 }
129117
130118 @ JsonProperty ("transferToAgent" )
@@ -154,23 +142,23 @@ public void setEscalate(boolean escalate) {
154142 }
155143
156144 @ JsonProperty ("requestedAuthConfigs" )
157- public ConcurrentMap <String , ConcurrentMap <String , Object >> requestedAuthConfigs () {
145+ public Map <String , Map <String , Object >> requestedAuthConfigs () {
158146 return requestedAuthConfigs ;
159147 }
160148
161- public void setRequestedAuthConfigs (
162- ConcurrentMap <String , ConcurrentMap <String , Object >> requestedAuthConfigs ) {
149+ public void setRequestedAuthConfigs (Map <String , Map <String , Object >> requestedAuthConfigs ) {
163150 this .requestedAuthConfigs = requestedAuthConfigs ;
164151 }
165152
166153 @ JsonProperty ("requestedToolConfirmations" )
167- public ConcurrentMap <String , ToolConfirmation > requestedToolConfirmations () {
154+ public Map <String , ToolConfirmation > requestedToolConfirmations () {
168155 return requestedToolConfirmations ;
169156 }
170157
171158 public void setRequestedToolConfirmations (
172- ConcurrentMap <String , ToolConfirmation > requestedToolConfirmations ) {
173- this .requestedToolConfirmations = requestedToolConfirmations ;
159+ Map <String , ToolConfirmation > requestedToolConfirmations ) {
160+ this .requestedToolConfirmations =
161+ Collections .synchronizedMap (new HashMap <>(requestedToolConfirmations ));
174162 }
175163
176164 @ JsonProperty ("endOfAgent" )
@@ -235,7 +223,6 @@ public boolean equals(Object o) {
235223 return Objects .equals (skipSummarization , that .skipSummarization )
236224 && Objects .equals (stateDelta , that .stateDelta )
237225 && Objects .equals (artifactDelta , that .artifactDelta )
238- && Objects .equals (deletedArtifactIds , that .deletedArtifactIds )
239226 && Objects .equals (transferToAgent , that .transferToAgent )
240227 && Objects .equals (escalate , that .escalate )
241228 && Objects .equals (requestedAuthConfigs , that .requestedAuthConfigs )
@@ -250,7 +237,6 @@ public int hashCode() {
250237 skipSummarization ,
251238 stateDelta ,
252239 artifactDelta ,
253- deletedArtifactIds ,
254240 transferToAgent ,
255241 escalate ,
256242 requestedAuthConfigs ,
@@ -262,38 +248,34 @@ public int hashCode() {
262248 /** Builder for {@link EventActions}. */
263249 public static class Builder {
264250 private Optional <Boolean > skipSummarization ;
265- private ConcurrentMap <String , Object > stateDelta ;
266- private ConcurrentMap <String , Integer > artifactDelta ;
267- private Set <String > deletedArtifactIds ;
251+ private Map <String , Object > stateDelta ;
252+ private Map <String , Integer > artifactDelta ;
268253 private Optional <String > transferToAgent ;
269254 private Optional <Boolean > escalate ;
270- private ConcurrentMap <String , ConcurrentMap <String , Object >> requestedAuthConfigs ;
271- private ConcurrentMap <String , ToolConfirmation > requestedToolConfirmations ;
255+ private Map <String , Map <String , Object >> requestedAuthConfigs ;
256+ private Map <String , ToolConfirmation > requestedToolConfirmations ;
272257 private boolean endOfAgent = false ;
273258 private Optional <EventCompaction > compaction ;
274259
275260 public Builder () {
276261 this .skipSummarization = Optional .empty ();
277- this .stateDelta = new ConcurrentHashMap <>();
278- this .artifactDelta = new ConcurrentHashMap <>();
279- this .deletedArtifactIds = new HashSet <>();
262+ this .stateDelta = new HashMap <>();
263+ this .artifactDelta = new HashMap <>();
280264 this .transferToAgent = Optional .empty ();
281265 this .escalate = Optional .empty ();
282- this .requestedAuthConfigs = new ConcurrentHashMap <>();
283- this .requestedToolConfirmations = new ConcurrentHashMap <>();
266+ this .requestedAuthConfigs = new HashMap <>();
267+ this .requestedToolConfirmations = new HashMap <>();
284268 this .compaction = Optional .empty ();
285269 }
286270
287271 private Builder (EventActions eventActions ) {
288272 this .skipSummarization = eventActions .skipSummarization ();
289- this .stateDelta = new ConcurrentHashMap <>(eventActions .stateDelta ());
290- this .artifactDelta = new ConcurrentHashMap <>(eventActions .artifactDelta ());
291- this .deletedArtifactIds = new HashSet <>(eventActions .deletedArtifactIds ());
273+ this .stateDelta = new HashMap <>(eventActions .stateDelta ());
274+ this .artifactDelta = new HashMap <>(eventActions .artifactDelta ());
292275 this .transferToAgent = eventActions .transferToAgent ();
293276 this .escalate = eventActions .escalate ();
294- this .requestedAuthConfigs = new ConcurrentHashMap <>(eventActions .requestedAuthConfigs ());
295- this .requestedToolConfirmations =
296- new ConcurrentHashMap <>(eventActions .requestedToolConfirmations ());
277+ this .requestedAuthConfigs = new HashMap <>(eventActions .requestedAuthConfigs ());
278+ this .requestedToolConfirmations = new HashMap <>(eventActions .requestedToolConfirmations ());
297279 this .endOfAgent = eventActions .endOfAgent ();
298280 this .compaction = eventActions .compaction ();
299281 }
@@ -307,22 +289,22 @@ public Builder skipSummarization(boolean skipSummarization) {
307289
308290 @ CanIgnoreReturnValue
309291 @ JsonProperty ("stateDelta" )
310- public Builder stateDelta (ConcurrentMap <String , Object > value ) {
292+ public Builder stateDelta (Map <String , Object > value ) {
311293 this .stateDelta = value ;
312294 return this ;
313295 }
314296
315297 @ CanIgnoreReturnValue
316298 @ JsonProperty ("artifactDelta" )
317- public Builder artifactDelta (ConcurrentMap <String , Integer > value ) {
299+ public Builder artifactDelta (Map <String , Integer > value ) {
318300 this .artifactDelta = value ;
319301 return this ;
320302 }
321303
322304 @ CanIgnoreReturnValue
323305 @ JsonProperty ("deletedArtifactIds" )
324306 public Builder deletedArtifactIds (Set <String > value ) {
325- this . deletedArtifactIds = value ;
307+ value . forEach ( v -> artifactDelta . put ( v , null )) ;
326308 return this ;
327309 }
328310
@@ -342,16 +324,15 @@ public Builder escalate(boolean escalate) {
342324
343325 @ CanIgnoreReturnValue
344326 @ JsonProperty ("requestedAuthConfigs" )
345- public Builder requestedAuthConfigs (
346- ConcurrentMap <String , ConcurrentMap <String , Object >> value ) {
327+ public Builder requestedAuthConfigs (Map <String , Map <String , Object >> value ) {
347328 this .requestedAuthConfigs = value ;
348329 return this ;
349330 }
350331
351332 @ CanIgnoreReturnValue
352333 @ JsonProperty ("requestedToolConfirmations" )
353- public Builder requestedToolConfirmations (ConcurrentMap <String , ToolConfirmation > value ) {
354- this .requestedToolConfirmations = value ;
334+ public Builder requestedToolConfirmations (Map <String , ToolConfirmation > value ) {
335+ this .requestedToolConfirmations = Collections . synchronizedMap ( new HashMap <>( value )) ;
355336 return this ;
356337 }
357338
@@ -385,7 +366,6 @@ public Builder merge(EventActions other) {
385366 other .skipSummarization ().ifPresent (this ::skipSummarization );
386367 this .stateDelta .putAll (other .stateDelta ());
387368 this .artifactDelta .putAll (other .artifactDelta ());
388- this .deletedArtifactIds .addAll (other .deletedArtifactIds ());
389369 other .transferToAgent ().ifPresent (this ::transferToAgent );
390370 other .escalate ().ifPresent (this ::escalate );
391371 this .requestedAuthConfigs .putAll (other .requestedAuthConfigs ());
0 commit comments