Skip to main content

TranscriptBuffer

Struct TranscriptBuffer 

Source
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

Source

pub fn new() -> Self

Create a new transcript buffer with the default capacity.

Source

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().

Source

pub fn push_input(&mut self, text: &str)

Append input (user speech) transcript text.

Source

pub fn push_output(&mut self, text: &str)

Append output (model speech) transcript text.

Source

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.

Source

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.

Source

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.

Source

pub fn all_turns(&mut self) -> &[TranscriptTurn]

All completed turns as a contiguous slice.

Requires &mut self to ensure VecDeque contiguity.

Source

pub fn retained_count(&self) -> usize

Number of retained turns (may be less than turn_count due to eviction).

Source

pub fn turn_count(&self) -> u32

Number of completed turns.

Source

pub fn format_window(&mut self, n: usize) -> String

Format the last n turns as a human-readable transcript for LLM consumption.

Source

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.

Source

pub fn set_output_transcription(&mut self, text: &str)

Set server-provided output transcription for current turn.

Source

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.

Source

pub fn has_pending(&self) -> bool

Whether there is any pending (un-finalized) transcript content.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TranscriptBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more