Skip to content

Commit 5c35c52

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: add session resumption.
PiperOrigin-RevId: 745227055
1 parent a3ea4ed commit 5c35c52

File tree

4 files changed

+334
-0
lines changed

4 files changed

+334
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2025 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+
* https://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+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/**
29+
* Configuration of session resumption mechanism.
30+
*
31+
* <p>Included in `BidiGenerateContentSetup.session_resumption`. If included server will send
32+
* SessionResumptionUpdate messages.
33+
*/
34+
@AutoValue
35+
@JsonDeserialize(builder = LiveClientSessionResumptionConfig.Builder.class)
36+
public abstract class LiveClientSessionResumptionConfig extends JsonSerializable {
37+
/**
38+
* Session resumption handle of previous session (session to restore).
39+
*
40+
* <p>If not present new session will be started.
41+
*/
42+
@JsonProperty("handle")
43+
public abstract Optional<String> handle();
44+
45+
/**
46+
* If set the server will to send `last_consumed_client_message_index` in the
47+
* `session_resumption_update` messages to allow for transparent reconnections.
48+
*/
49+
@JsonProperty("transparent")
50+
public abstract Optional<Boolean> transparent();
51+
52+
/** Instantiates a builder for LiveClientSessionResumptionConfig. */
53+
public static Builder builder() {
54+
return new AutoValue_LiveClientSessionResumptionConfig.Builder();
55+
}
56+
57+
/** Creates a builder with the same values as this instance. */
58+
public abstract Builder toBuilder();
59+
60+
/** Builder for LiveClientSessionResumptionConfig. */
61+
@AutoValue.Builder
62+
public abstract static class Builder {
63+
/**
64+
* For internal usage. Please use `LiveClientSessionResumptionConfig.builder()` for
65+
* instantiation.
66+
*/
67+
@JsonCreator
68+
private static Builder create() {
69+
return new AutoValue_LiveClientSessionResumptionConfig.Builder();
70+
}
71+
72+
@JsonProperty("handle")
73+
public abstract Builder handle(String handle);
74+
75+
@JsonProperty("transparent")
76+
public abstract Builder transparent(boolean transparent);
77+
78+
public abstract LiveClientSessionResumptionConfig build();
79+
}
80+
81+
/** Deserializes a JSON string to a LiveClientSessionResumptionConfig object. */
82+
public static LiveClientSessionResumptionConfig fromJson(String jsonString) {
83+
return JsonSerializable.fromJsonString(jsonString, LiveClientSessionResumptionConfig.class);
84+
}
85+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2025 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+
* https://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+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/** Server will not be able to service client soon. */
29+
@AutoValue
30+
@JsonDeserialize(builder = LiveServerGoAway.Builder.class)
31+
public abstract class LiveServerGoAway extends JsonSerializable {
32+
/**
33+
* The remaining time before the connection will be terminated as ABORTED. The minimal time
34+
* returned here is specified differently together with the rate limits for a given model.
35+
*/
36+
@JsonProperty("timeLeft")
37+
public abstract Optional<String> timeLeft();
38+
39+
/** Instantiates a builder for LiveServerGoAway. */
40+
public static Builder builder() {
41+
return new AutoValue_LiveServerGoAway.Builder();
42+
}
43+
44+
/** Creates a builder with the same values as this instance. */
45+
public abstract Builder toBuilder();
46+
47+
/** Builder for LiveServerGoAway. */
48+
@AutoValue.Builder
49+
public abstract static class Builder {
50+
/** For internal usage. Please use `LiveServerGoAway.builder()` for instantiation. */
51+
@JsonCreator
52+
private static Builder create() {
53+
return new AutoValue_LiveServerGoAway.Builder();
54+
}
55+
56+
@JsonProperty("timeLeft")
57+
public abstract Builder timeLeft(String timeLeft);
58+
59+
public abstract LiveServerGoAway build();
60+
}
61+
62+
/** Deserializes a JSON string to a LiveServerGoAway object. */
63+
public static LiveServerGoAway fromJson(String jsonString) {
64+
return JsonSerializable.fromJsonString(jsonString, LiveServerGoAway.class);
65+
}
66+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2025 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+
* https://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+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/**
29+
* Update of the session resumption state.
30+
*
31+
* <p>Only sent if `session_resumption` was set in the connection config.
32+
*/
33+
@AutoValue
34+
@JsonDeserialize(builder = LiveServerSessionResumptionUpdate.Builder.class)
35+
public abstract class LiveServerSessionResumptionUpdate extends JsonSerializable {
36+
/** New handle that represents state that can be resumed. Empty if `resumable`=false. */
37+
@JsonProperty("newHandle")
38+
public abstract Optional<String> newHandle();
39+
40+
/**
41+
* True if session can be resumed at this point. It might be not possible to resume session at
42+
* some points. In that case we send update empty new_handle and resumable=false. Example of such
43+
* case could be model executing function calls or just generating. Resuming session (using
44+
* previous session token) in such state will result in some data loss.
45+
*/
46+
@JsonProperty("resumable")
47+
public abstract Optional<Boolean> resumable();
48+
49+
/**
50+
* Index of last message sent by client that is included in state represented by this
51+
* SessionResumptionToken. Only sent when `SessionResumptionConfig.transparent` is set.
52+
*
53+
* <p>Presence of this index allows users to transparently reconnect and avoid issue of losing
54+
* some part of realtime audio input/video. If client wishes to temporarily disconnect (for
55+
* example as result of receiving GoAway) they can do it without losing state by buffering
56+
* messages sent since last `SessionResmumptionTokenUpdate`. This field will enable them to limit
57+
* buffering (avoid keeping all requests in RAM).
58+
*
59+
* <p>Note: This should not be used for when resuming a session at some time later -- in those
60+
* cases partial audio and video frames arelikely not needed.
61+
*/
62+
@JsonProperty("lastConsumedClientMessageIndex")
63+
public abstract Optional<Long> lastConsumedClientMessageIndex();
64+
65+
/** Instantiates a builder for LiveServerSessionResumptionUpdate. */
66+
public static Builder builder() {
67+
return new AutoValue_LiveServerSessionResumptionUpdate.Builder();
68+
}
69+
70+
/** Creates a builder with the same values as this instance. */
71+
public abstract Builder toBuilder();
72+
73+
/** Builder for LiveServerSessionResumptionUpdate. */
74+
@AutoValue.Builder
75+
public abstract static class Builder {
76+
/**
77+
* For internal usage. Please use `LiveServerSessionResumptionUpdate.builder()` for
78+
* instantiation.
79+
*/
80+
@JsonCreator
81+
private static Builder create() {
82+
return new AutoValue_LiveServerSessionResumptionUpdate.Builder();
83+
}
84+
85+
@JsonProperty("newHandle")
86+
public abstract Builder newHandle(String newHandle);
87+
88+
@JsonProperty("resumable")
89+
public abstract Builder resumable(boolean resumable);
90+
91+
@JsonProperty("lastConsumedClientMessageIndex")
92+
public abstract Builder lastConsumedClientMessageIndex(Long lastConsumedClientMessageIndex);
93+
94+
public abstract LiveServerSessionResumptionUpdate build();
95+
}
96+
97+
/** Deserializes a JSON string to a LiveServerSessionResumptionUpdate object. */
98+
public static LiveServerSessionResumptionUpdate fromJson(String jsonString) {
99+
return JsonSerializable.fromJsonString(jsonString, LiveServerSessionResumptionUpdate.class);
100+
}
101+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2025 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+
* https://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+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/**
29+
* Configuration of session resumption mechanism.
30+
*
31+
* <p>Included in `LiveConnectConfig.session_resumption`. If included server will send
32+
* `LiveServerSessionResumptionUpdate` messages.
33+
*/
34+
@AutoValue
35+
@JsonDeserialize(builder = SessionResumptionConfig.Builder.class)
36+
public abstract class SessionResumptionConfig extends JsonSerializable {
37+
/**
38+
* Session resumption handle of previous session (session to restore).
39+
*
40+
* <p>If not present new session will be started.
41+
*/
42+
@JsonProperty("handle")
43+
public abstract Optional<String> handle();
44+
45+
/**
46+
* If set the server will send `last_consumed_client_message_index` in the
47+
* `session_resumption_update` messages to allow for transparent reconnections.
48+
*/
49+
@JsonProperty("transparent")
50+
public abstract Optional<Boolean> transparent();
51+
52+
/** Instantiates a builder for SessionResumptionConfig. */
53+
public static Builder builder() {
54+
return new AutoValue_SessionResumptionConfig.Builder();
55+
}
56+
57+
/** Creates a builder with the same values as this instance. */
58+
public abstract Builder toBuilder();
59+
60+
/** Builder for SessionResumptionConfig. */
61+
@AutoValue.Builder
62+
public abstract static class Builder {
63+
/** For internal usage. Please use `SessionResumptionConfig.builder()` for instantiation. */
64+
@JsonCreator
65+
private static Builder create() {
66+
return new AutoValue_SessionResumptionConfig.Builder();
67+
}
68+
69+
@JsonProperty("handle")
70+
public abstract Builder handle(String handle);
71+
72+
@JsonProperty("transparent")
73+
public abstract Builder transparent(boolean transparent);
74+
75+
public abstract SessionResumptionConfig build();
76+
}
77+
78+
/** Deserializes a JSON string to a SessionResumptionConfig object. */
79+
public static SessionResumptionConfig fromJson(String jsonString) {
80+
return JsonSerializable.fromJsonString(jsonString, SessionResumptionConfig.class);
81+
}
82+
}

0 commit comments

Comments
 (0)