Struct TranscriptBuffer
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§
§impl TranscriptBuffer
impl TranscriptBuffer
pub fn new() -> TranscriptBuffer
pub fn new() -> TranscriptBuffer
Create a new transcript buffer with the default capacity.
pub fn with_capacity(max_turns: usize) -> TranscriptBuffer
pub fn with_capacity(max_turns: usize) -> TranscriptBuffer
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().
pub fn push_input(&mut self, text: &str)
pub fn push_input(&mut self, text: &str)
Append input (user speech) transcript text.
pub fn push_output(&mut self, text: &str)
pub fn push_output(&mut self, text: &str)
Append output (model speech) transcript text.
pub 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.
pub 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.
pub 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.
pub 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.
pub fn retained_count(&self) -> usize
pub fn retained_count(&self) -> usize
Number of retained turns (may be less than turn_count due to eviction).
pub fn turn_count(&self) -> u32
pub fn turn_count(&self) -> u32
Number of completed turns.
pub 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.
pub 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.
pub 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.
pub 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.
pub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Whether there is any pending (un-finalized) transcript content.
pub 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.
pub 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.