Skip to main content

gproxy_protocol/wire/gemini/live/
server.rs

1use super::LiveContent;
2use super::LiveInt64;
3use crate::Rest;
4use crate::gemini::FunctionCall;
5use crate::gemini::count_tokens::ModalityTokenCount;
6use crate::gemini::generation::ServiceTier;
7use serde::{Deserialize, Serialize};
8
9// The Developer API grounding and URL-context definitions are the same as
10// GenerateContent. SDK retrieval_queries/source_flagging_uris are Vertex-only.
11pub type LiveGroundingMetadata = crate::gemini::generate_content::GroundingMetadata;
12pub type LiveUrlContextMetadata = crate::gemini::generate_content::UrlContextMetadata;
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
15#[serde(rename_all = "camelCase")]
16#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
17#[derive(gproxy_protocol_macros::DeclaredFields)]
18pub struct BidiGenerateContentServerContent {
19    #[serde(alias = "model_turn")]
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub model_turn: Option<LiveContent>,
22    #[serde(alias = "generation_complete")]
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub generation_complete: Option<bool>,
25    #[serde(alias = "turn_complete")]
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub turn_complete: Option<bool>,
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub interrupted: Option<bool>,
30    #[serde(alias = "grounding_metadata")]
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub grounding_metadata: Option<LiveGroundingMetadata>,
33    #[serde(alias = "input_transcription")]
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub input_transcription: Option<BidiGenerateContentTranscription>,
36    #[serde(alias = "output_transcription")]
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub output_transcription: Option<BidiGenerateContentTranscription>,
39    #[serde(alias = "interim_input_transcription")]
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub interim_input_transcription: Option<BidiGenerateContentTranscription>,
42    #[serde(alias = "url_context_metadata")]
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub url_context_metadata: Option<LiveUrlContextMetadata>,
45    #[serde(alias = "waiting_for_input")]
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub waiting_for_input: Option<bool>,
48    #[serde(alias = "turn_complete_reason")]
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    pub turn_complete_reason: Option<TurnCompleteReason>,
51    #[serde(alias = "interaction_status")]
52    #[serde(default, skip_serializing_if = "Option::is_none")]
53    pub interaction_status: Option<InteractionStatus>,
54    #[serde(alias = "speech_state")]
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub speech_state: Option<SpeechState>,
57    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
58    pub rest: Rest,
59}
60
61#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
62#[serde(rename_all = "camelCase")]
63#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
64#[derive(gproxy_protocol_macros::DeclaredFields)]
65pub struct BidiGenerateContentToolCall {
66    #[serde(alias = "function_calls")]
67    #[serde(default, skip_serializing_if = "Option::is_none")]
68    pub function_calls: Option<Vec<FunctionCall>>,
69    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
70    pub rest: Rest,
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
74#[serde(rename_all = "camelCase")]
75#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
76#[derive(gproxy_protocol_macros::DeclaredFields)]
77pub struct BidiGenerateContentToolCallCancellation {
78    #[serde(default, skip_serializing_if = "Option::is_none")]
79    pub ids: Option<Vec<String>>,
80    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
81    pub rest: Rest,
82}
83
84#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
85#[serde(rename_all = "camelCase")]
86#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
87#[derive(gproxy_protocol_macros::DeclaredFields)]
88pub struct GoAway {
89    #[serde(alias = "time_left")]
90    #[serde(default, skip_serializing_if = "Option::is_none")]
91    pub time_left: Option<String>,
92    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
93    pub rest: Rest,
94}
95
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
97#[serde(rename_all = "camelCase")]
98#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
99#[derive(gproxy_protocol_macros::DeclaredFields)]
100pub struct SessionResumptionUpdate {
101    #[serde(alias = "new_handle")]
102    #[serde(default, skip_serializing_if = "Option::is_none")]
103    pub new_handle: Option<String>,
104    #[serde(default, skip_serializing_if = "Option::is_none")]
105    pub resumable: Option<bool>,
106    #[serde(alias = "last_consumed_client_message_index")]
107    #[serde(default, skip_serializing_if = "Option::is_none")]
108    pub last_consumed_client_message_index: Option<LiveInt64>,
109    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
110    pub rest: Rest,
111}
112
113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
114#[serde(rename_all = "camelCase")]
115#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
116#[derive(gproxy_protocol_macros::DeclaredFields)]
117pub struct BidiGenerateContentTranscription {
118    #[serde(default, skip_serializing_if = "Option::is_none")]
119    pub text: Option<String>,
120    #[serde(default, skip_serializing_if = "Option::is_none")]
121    pub finished: Option<bool>,
122    #[serde(alias = "language_code")]
123    #[serde(default, skip_serializing_if = "Option::is_none")]
124    pub language_code: Option<String>,
125    #[serde(alias = "speaker_label")]
126    #[serde(default, skip_serializing_if = "Option::is_none")]
127    pub speaker_label: Option<String>,
128    #[serde(default, skip_serializing_if = "Option::is_none")]
129    pub words: Option<Vec<WordInfo>>,
130    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
131    pub rest: Rest,
132}
133
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
135#[serde(rename_all = "camelCase")]
136#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
137#[derive(gproxy_protocol_macros::DeclaredFields)]
138pub struct WordInfo {
139    #[serde(default, skip_serializing_if = "Option::is_none")]
140    pub word: Option<String>,
141    #[serde(alias = "start_offset")]
142    #[serde(default, skip_serializing_if = "Option::is_none")]
143    pub start_offset: Option<String>,
144    #[serde(alias = "end_offset")]
145    #[serde(default, skip_serializing_if = "Option::is_none")]
146    pub end_offset: Option<String>,
147    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
148    pub rest: Rest,
149}
150
151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
152#[serde(rename_all = "camelCase")]
153#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
154#[derive(gproxy_protocol_macros::DeclaredFields)]
155pub struct LiveUsageMetadata {
156    #[serde(alias = "prompt_token_count")]
157    #[serde(default, skip_serializing_if = "Option::is_none")]
158    pub prompt_token_count: Option<i64>,
159    #[serde(alias = "cached_content_token_count")]
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub cached_content_token_count: Option<i64>,
162    #[serde(alias = "response_token_count")]
163    #[serde(default, skip_serializing_if = "Option::is_none")]
164    pub response_token_count: Option<i64>,
165    #[serde(alias = "tool_use_prompt_token_count")]
166    #[serde(default, skip_serializing_if = "Option::is_none")]
167    pub tool_use_prompt_token_count: Option<i64>,
168    #[serde(alias = "thoughts_token_count")]
169    #[serde(default, skip_serializing_if = "Option::is_none")]
170    pub thoughts_token_count: Option<i64>,
171    #[serde(alias = "total_token_count")]
172    #[serde(default, skip_serializing_if = "Option::is_none")]
173    pub total_token_count: Option<i64>,
174    #[serde(alias = "prompt_tokens_details")]
175    #[serde(default, skip_serializing_if = "Option::is_none")]
176    pub prompt_tokens_details: Option<Vec<ModalityTokenCount>>,
177    #[serde(alias = "cache_tokens_details")]
178    #[serde(default, skip_serializing_if = "Option::is_none")]
179    pub cache_tokens_details: Option<Vec<ModalityTokenCount>>,
180    #[serde(alias = "response_tokens_details")]
181    #[serde(default, skip_serializing_if = "Option::is_none")]
182    pub response_tokens_details: Option<Vec<ModalityTokenCount>>,
183    #[serde(alias = "tool_use_prompt_tokens_details")]
184    #[serde(default, skip_serializing_if = "Option::is_none")]
185    pub tool_use_prompt_tokens_details: Option<Vec<ModalityTokenCount>>,
186    #[serde(alias = "service_tier")]
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub service_tier: Option<ServiceTier>,
189    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
190    pub rest: Rest,
191}
192
193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
194#[serde(rename_all = "camelCase")]
195#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
196#[derive(gproxy_protocol_macros::DeclaredFields)]
197pub struct VoiceActivityDetectionSignal {
198    #[serde(alias = "vad_signal_type")]
199    #[serde(default, skip_serializing_if = "Option::is_none")]
200    pub vad_signal_type: Option<VadSignalType>,
201    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
202    pub rest: Rest,
203}
204
205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
206#[serde(rename_all = "camelCase")]
207#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
208#[derive(gproxy_protocol_macros::DeclaredFields)]
209pub struct VoiceActivity {
210    #[serde(rename = "type")]
211    #[serde(default, skip_serializing_if = "Option::is_none")]
212    pub type_: Option<VoiceActivityType>,
213    #[serde(alias = "audio_offset")]
214    #[serde(default, skip_serializing_if = "Option::is_none")]
215    pub audio_offset: Option<String>,
216    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
217    pub rest: Rest,
218}
219
220#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
221#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
222#[derive(gproxy_protocol_macros::DeclaredFields)]
223pub enum TurnCompleteReason {
224    #[serde(rename = "TURN_COMPLETE_REASON_UNSPECIFIED")]
225    TurnCompleteReasonUnspecified,
226    #[serde(rename = "MALFORMED_FUNCTION_CALL")]
227    MalformedFunctionCall,
228    #[serde(rename = "RESPONSE_REJECTED")]
229    ResponseRejected,
230    #[serde(rename = "NEED_MORE_INPUT")]
231    NeedMoreInput,
232    #[serde(rename = "PROHIBITED_INPUT_CONTENT")]
233    ProhibitedInputContent,
234    #[serde(rename = "IMAGE_PROHIBITED_INPUT_CONTENT")]
235    ImageProhibitedInputContent,
236    #[serde(rename = "INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED")]
237    InputTextContainProminentPersonProhibited,
238    #[serde(rename = "INPUT_IMAGE_CELEBRITY")]
239    InputImageCelebrity,
240    #[serde(rename = "INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED")]
241    InputImagePhotoRealisticChildProhibited,
242    #[serde(rename = "INPUT_TEXT_NCII_PROHIBITED")]
243    InputTextNciiProhibited,
244    #[serde(rename = "INPUT_OTHER")]
245    InputOther,
246    #[serde(rename = "INPUT_IP_PROHIBITED")]
247    InputIpProhibited,
248    #[serde(rename = "BLOCKLIST")]
249    Blocklist,
250    #[serde(rename = "UNSAFE_PROMPT_FOR_IMAGE_GENERATION")]
251    UnsafePromptForImageGeneration,
252    #[serde(rename = "GENERATED_IMAGE_SAFETY")]
253    GeneratedImageSafety,
254    #[serde(rename = "GENERATED_CONTENT_SAFETY")]
255    GeneratedContentSafety,
256    #[serde(rename = "GENERATED_AUDIO_SAFETY")]
257    GeneratedAudioSafety,
258    #[serde(rename = "GENERATED_VIDEO_SAFETY")]
259    GeneratedVideoSafety,
260    #[serde(rename = "GENERATED_CONTENT_PROHIBITED")]
261    GeneratedContentProhibited,
262    #[serde(rename = "GENERATED_CONTENT_BLOCKLIST")]
263    GeneratedContentBlocklist,
264    #[serde(rename = "GENERATED_IMAGE_PROHIBITED")]
265    GeneratedImageProhibited,
266    #[serde(rename = "GENERATED_IMAGE_CELEBRITY")]
267    GeneratedImageCelebrity,
268    #[serde(rename = "GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER")]
269    GeneratedImageProminentPeopleDetectedByRewriter,
270    #[serde(rename = "GENERATED_IMAGE_IDENTIFIABLE_PEOPLE")]
271    GeneratedImageIdentifiablePeople,
272    #[serde(rename = "GENERATED_IMAGE_MINORS")]
273    GeneratedImageMinors,
274    #[serde(rename = "OUTPUT_IMAGE_IP_PROHIBITED")]
275    OutputImageIpProhibited,
276    #[serde(rename = "GENERATED_OTHER")]
277    GeneratedOther,
278    #[serde(rename = "MAX_REGENERATION_REACHED")]
279    MaxRegenerationReached,
280}
281
282#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
283#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
284#[derive(gproxy_protocol_macros::DeclaredFields)]
285pub enum InteractionStatus {
286    #[serde(rename = "INTERACTION_STATUS_UNSPECIFIED")]
287    InteractionStatusUnspecified,
288    #[serde(rename = "IN_PROGRESS")]
289    InProgress,
290    #[serde(rename = "REQUIRES_ACTION")]
291    RequiresAction,
292    #[serde(rename = "IDLE")]
293    Idle,
294}
295
296#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
297#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
298#[derive(gproxy_protocol_macros::DeclaredFields)]
299pub enum VadSignalType {
300    #[serde(rename = "VAD_SIGNAL_TYPE_UNSPECIFIED")]
301    VadSignalTypeUnspecified,
302    #[serde(rename = "VAD_SIGNAL_TYPE_SOS")]
303    VadSignalTypeSos,
304    #[serde(rename = "VAD_SIGNAL_TYPE_EOS")]
305    VadSignalTypeEos,
306}
307
308#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
309#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
310#[derive(gproxy_protocol_macros::DeclaredFields)]
311pub enum VoiceActivityType {
312    #[serde(rename = "TYPE_UNSPECIFIED")]
313    TypeUnspecified,
314    #[serde(rename = "ACTIVITY_START")]
315    ActivityStart,
316    #[serde(rename = "ACTIVITY_END")]
317    ActivityEnd,
318}
319
320/// ai.google.dev/api/live exposes deprecated speechState but provides no value
321/// table; current public proto/SDK omit its declaration. Preserve the named enum
322/// representation without inventing constants. ProtoJSON enums can be names/ints.
323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
324#[serde(untagged)]
325#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
326#[derive(gproxy_protocol_macros::DeclaredFields)]
327pub enum SpeechState {
328    Name(String),
329    Number(i32),
330}