gemini_adk_rs/live/
events.rs

1//! Semantic events emitted by the L1 processor.
2//!
3//! Subscribe via `LiveHandle::events()`. Zero-cost when no subscribers.
4
5use std::time::Duration;
6
7use bytes::Bytes;
8
9/// Semantic events emitted by the Live session processor.
10///
11/// The L1 equivalent of L0's [`SessionEvent`](gemini_genai_rs::prelude::SessionEvent).
12/// L0 events are wire-level; LiveEvents are semantic (extractions completed,
13/// phases transitioned, tools executed).
14///
15/// Subscribe via [`LiveHandle::events()`](super::handle::LiveHandle::events).
16/// Multiple independent subscribers supported. Zero-cost when no subscribers
17/// exist (`broadcast::send` with 0 receivers is a no-op).
18#[derive(Debug, Clone)]
19pub enum LiveEvent {
20    // -- Fast-lane events (high frequency, sync emission) --
21    /// Raw PCM audio from model. Uses `Bytes` (refcounted) — clone is
22    /// a pointer increment (~2ns), not a deep copy.
23    Audio(Bytes),
24    /// Incremental text token from model.
25    TextDelta(String),
26    /// Complete text response (all deltas concatenated).
27    TextComplete(String),
28    /// User speech transcription.
29    InputTranscript {
30        /// The transcribed text content.
31        text: String,
32        /// Whether this is the final transcription for the utterance.
33        is_final: bool,
34    },
35    /// Model speech transcription.
36    OutputTranscript {
37        /// The transcribed text content.
38        text: String,
39        /// Whether this is the final transcription for the utterance.
40        is_final: bool,
41    },
42    /// Model reasoning/thinking content.
43    Thought(String),
44    /// Voice activity detected — user started speaking.
45    VadStart,
46    /// Voice activity ended — user stopped speaking.
47    VadEnd,
48
49    // -- Control-lane events (lower frequency, async emission) --
50    /// Extraction completed. Emitted for both the top-level result
51    /// AND each flattened key (e.g., "order.items", "order.phase").
52    Extraction {
53        /// Extractor name, or `"extractor.field"` for flattened keys.
54        name: String,
55        /// The extracted JSON value.
56        value: serde_json::Value,
57    },
58    /// Extraction failed.
59    ExtractionError {
60        /// Name of the extractor that failed.
61        name: String,
62        /// Human-readable error description.
63        error: String,
64    },
65    /// A raw extraction field was considered for promotion into authoritative state.
66    StatePromotion {
67        /// Extractor name that produced the field.
68        extractor: String,
69        /// Field name inside the extractor result.
70        field: String,
71        /// State key targeted by the promotion rule.
72        state_key: String,
73        /// Whether the promotion was accepted and written.
74        accepted: bool,
75        /// Human-readable reason for the decision.
76        reason: String,
77        /// Extracted value that was considered.
78        value: serde_json::Value,
79    },
80    /// Phase machine transitioned.
81    PhaseTransition {
82        /// Phase the machine transitioned from.
83        from: String,
84        /// Phase the machine transitioned to.
85        to: String,
86        /// Human-readable reason for the transition.
87        reason: String,
88    },
89    /// Tool dispatched and result obtained.
90    ToolExecution {
91        /// Name of the tool that was called.
92        name: String,
93        /// Arguments passed to the tool.
94        args: serde_json::Value,
95        /// Result returned by the tool.
96        result: serde_json::Value,
97    },
98    /// Model completed a conversational turn.
99    TurnComplete,
100    /// Model output interrupted by user speech.
101    Interrupted,
102    /// Session connected to Gemini.
103    Connected,
104    /// Session disconnected.
105    Disconnected {
106        /// Optional reason for disconnection (server-provided or error message).
107        reason: Option<String>,
108    },
109    /// Unrecoverable error.
110    Error(String),
111    /// Server requesting session wind-down.
112    GoAway {
113        /// Time remaining before the server closes the connection.
114        time_left: Duration,
115    },
116
117    // -- Periodic events --
118    /// Aggregated session telemetry snapshot.
119    Telemetry(serde_json::Value),
120    /// Per-turn latency and token metrics.
121    TurnMetrics {
122        /// Turn number (1-indexed).
123        turn: u32,
124        /// End-to-end latency for this turn in milliseconds.
125        latency_ms: u32,
126        /// Number of prompt tokens consumed.
127        prompt_tokens: u32,
128        /// Number of response tokens generated.
129        response_tokens: u32,
130    },
131}