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.
Words that arrive once the model has started speaking are kept apart
until the turn ends: see mark_interrupted.
Sourcepub fn mark_interrupted(&mut self)
pub fn mark_interrupted(&mut self)
Record that the caller interrupted the model’s turn in progress.
The caller words that arrived after the model began speaking are the barge-in: when the turn ends they open the next turn instead of being filed, before the model’s words, under the turn they interrupted.
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)
Clear the model’s text from the turn in progress.
Sourcepub fn cut_current_model_turn(&mut self, heard_chars: usize)
pub fn cut_current_model_turn(&mut self, heard_chars: usize)
Cut the model’s text in the turn in progress to its first
heard_chars characters, ending at the last whole word. The runtime
calls this on an interruption with what the listener heard; see
playback.
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 the turn is finalized.
Trait Implementations§
Source§impl Debug for TranscriptBuffer
impl Debug for 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 UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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> ⓘ
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].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.