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