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 new() -> TranscriptBuffer
pub fn new() -> TranscriptBuffer
Create a new transcript buffer with the default capacity.
Sourcepub 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().
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.
Trait Implementations§
Source§impl Debug for TranscriptBuffer
impl Debug for TranscriptBuffer
Source§impl Default for TranscriptBuffer
impl Default for TranscriptBuffer
Source§fn default() -> TranscriptBuffer
fn default() -> TranscriptBuffer
Auto Trait Implementations§
impl Freeze for TranscriptBuffer
impl RefUnwindSafe for TranscriptBuffer
impl Send for TranscriptBuffer
impl Sync for TranscriptBuffer
impl Unpin for TranscriptBuffer
impl UnwindSafe for TranscriptBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].