gemini_live/types/common.rs
1//! Shared types used by both client and server messages.
2//!
3//! These map directly to the Gemini Live API wire format — see
4//! <https://ai.google.dev/api/live> for the canonical reference.
5
6use serde::{Deserialize, Serialize};
7
8/// A conversation turn or system instruction, composed of ordered [`Part`]s.
9///
10/// When used as a turn, `role` is `"user"` or `"model"`.
11/// When used as `systemInstruction` in setup, `role` is typically omitted.
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct Content {
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub role: Option<String>,
17 pub parts: Vec<Part>,
18}
19
20/// A single piece of content within a [`Content`] turn.
21///
22/// Exactly one field is populated per part on the wire, but we model it with
23/// optional fields for forward-compatibility with future part types.
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct Part {
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub text: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub inline_data: Option<Blob>,
31}
32
33/// Base64-encoded binary data with a MIME type.
34///
35/// Used for audio (`audio/pcm;rate=16000` input, `audio/pcm;rate=24000` output)
36/// and images (`image/jpeg`, `image/png`).
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct Blob {
40 /// Base64-encoded bytes.
41 pub data: String,
42 /// MIME type, e.g. `"audio/pcm;rate=16000"` or `"image/jpeg"`.
43 pub mime_type: String,
44}
45
46/// A JSON `{}` — used where the protocol signals intent by the field's
47/// *presence* rather than its value (e.g. `activityStart`, `inputAudioTranscription`).
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49pub struct EmptyObject {}