pub struct TranscriptBuffer { /* private fields */ }Expand description
Accumulates input/output transcripts and segments them by turn boundaries.
Uses a ring buffer (VecDeque) that evicts the oldest turns when
max_turns is reached. This prevents unbounded memory growth in
long-running voice sessions.
Thread safety: wrap in Arc<parking_lot::Mutex<TranscriptBuffer>> when
sharing between fast lane (push) and control lane (end_turn / window).
Implementations§
Source§impl TranscriptBuffer
impl TranscriptBuffer
Sourcepub fn with_capacity(max_turns: usize) -> Self
pub fn with_capacity(max_turns: usize) -> Self
Create a buffer with a custom maximum turn capacity.
When the buffer reaches max_turns completed turns, the oldest
turn is evicted on each new end_turn().
Sourcepub fn push_input(&mut self, text: &str)
pub fn push_input(&mut self, text: &str)
Append input (user speech) transcript text.
Sourcepub fn push_output(&mut self, text: &str)
pub fn push_output(&mut self, text: &str)
Append output (model speech) transcript text.
Sourcepub fn push_tool_call(&mut self, name: String, args: &Value, result: &Value)
pub fn push_tool_call(&mut self, name: String, args: &Value, result: &Value)
Record a tool call summary for the current turn.
Args and result are truncated to 200 characters of their JSON representation.
Sourcepub fn end_turn(&mut self) -> Option<TranscriptTurn>
pub fn end_turn(&mut self) -> Option<TranscriptTurn>
Finalize the current turn and return it.
Resets the current accumulators for the next turn. Only creates a turn if there is any transcript content.
Sourcepub fn window(&mut self, n: usize) -> &[TranscriptTurn]
pub fn window(&mut self, n: usize) -> &[TranscriptTurn]
Get the last n completed turns as a contiguous slice.
Requires &mut self to ensure VecDeque contiguity.
Sourcepub fn all_turns(&mut self) -> &[TranscriptTurn]
pub fn all_turns(&mut self) -> &[TranscriptTurn]
All completed turns as a contiguous slice.
Requires &mut self to ensure VecDeque contiguity.
Sourcepub fn retained_count(&self) -> usize
pub fn retained_count(&self) -> usize
Number of retained turns (may be less than turn_count due to eviction).
Sourcepub fn turn_count(&self) -> u32
pub fn turn_count(&self) -> u32
Number of completed turns.
Sourcepub fn format_window(&mut self, n: usize) -> String
pub fn format_window(&mut self, n: usize) -> String
Format the last n turns as a human-readable transcript for LLM consumption.
Sourcepub fn set_input_transcription(&mut self, text: &str)
pub fn set_input_transcription(&mut self, text: &str)
Set server-provided input transcription for current turn. Overwrites client-accumulated input if server transcription is available.
Sourcepub fn set_output_transcription(&mut self, text: &str)
pub fn set_output_transcription(&mut self, text: &str)
Set server-provided output transcription for current turn.
Sourcepub fn truncate_current_model_turn(&mut self)
pub fn truncate_current_model_turn(&mut self)
Truncate the current model turn in progress. Called on interruption. Only what was already delivered to the client is retained.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Whether there is any pending (un-finalized) transcript content.
Sourcepub fn snapshot_window(&mut self, n: usize) -> TranscriptWindow
pub fn snapshot_window(&mut self, n: usize) -> TranscriptWindow
Create a TranscriptWindow snapshot of the last n completed turns.
This is a cheap clone operation designed for passing to phase callbacks.
Sourcepub fn snapshot_window_with_current(&mut self, n: usize) -> TranscriptWindow
pub fn snapshot_window_with_current(&mut self, n: usize) -> TranscriptWindow
Snapshot including the current in-progress turn (not yet finalized).
Used by GenerationComplete extractors to see the model’s full output
before interruption truncation clears current_model.