Skip to content

bodhi-realtime-agent / TranscriptManager

Class: TranscriptManager ​

Defined in: src/core/transcript-manager.ts:45

Manages input/output transcription buffering, deduplication, and flushing.

Extracted from VoiceSession to isolate transcript accumulation from session orchestration. Callers feed in transcription events; the manager buffers, deduplicates across tool-call boundaries, and flushes finalized text to the provided sink.

Constructors ​

Constructor ​

new TranscriptManager(sink, options?): TranscriptManager

Defined in: src/core/transcript-manager.ts:91

Parameters ​

sink ​

TranscriptSink

options? ​

TranscriptManagerOptions = {}

Returns ​

TranscriptManager

Properties ​

onBeforeFlush? ​

optional onBeforeFlush?: () => void

Defined in: src/core/transcript-manager.ts:89

Fired once at the top of flush(), before the buffers are committed; never from flushInput(). Output passed to handleOutput from here is part of the assistant message this flush commits. VoiceSession wires outputInterceptor.beforeTranscriptFlush here.

Returns ​

void


onInputFinalized? ​

optional onInputFinalized?: (text) => void

Defined in: src/core/transcript-manager.ts:78

Optional callback fired when user input is finalized (committed as a non-partial message). Triggers from both flushInput() and the input-flushing section of flush(). Used by VoiceSession to relay finalized user text to interactive subagent sessions.

Parameters ​

text ​

string

Returns ​

void


onInputReserved? ​

optional onInputReserved?: (turnId) => void

Defined in: src/core/transcript-manager.ts:83

Fired when a user message was reserved instead of committed, i.e. its authoritative transcript is still outstanding. VoiceSession uses this to arm the fallback seal timer.

Parameters ​

turnId ​

number

Returns ​

void

Methods ​

correctInput() ​

correctInput(textDelta): void

Defined in: src/core/transcript-manager.ts:206

Replace the current input buffer with the provider's own transcription (e.g. Gemini's built-in inputAudioTranscription).

The provider streams this as incremental deltas, not as a whole restated transcript per call, so the deltas are accumulated across the utterance before replacing the buffer — otherwise the buffer (and the finalized user message) would collapse to the last delta, often a word fragment. The accumulation resets at each utterance boundary along with inputBuffer. Sends a corrected partial to the client so the UI updates.

This is the lower-ranked source: once the authoritative transcript has landed for this utterance (handleInput), a late-arriving delta no longer touches the buffer, which makes precedence independent of arrival order. No-op if the delta is empty.

Parameters ​

textDelta ​

string

Returns ​

void


finalizeInterruptedInputPartial() ​

finalizeInterruptedInputPartial(): boolean

Defined in: src/core/transcript-manager.ts:297

R7b (replayed-turn transcript): promote the pending input text to a finalized user message. Used when a watchdog replay re-sends the retained utterance — inline-audio replay turns emit NO input transcription, so without this the user would see an answer to an invisible question. Prefers the authoritative batch-STT inputBuffer when present; falls back to the interrupted-turn display partial. Locks the turn (like flushInput) so a trailing transcript for the same utterance cannot duplicate the message. Returns false when nothing is pending.

Returns ​

boolean


flush() ​

flush(): void

Defined in: src/core/transcript-manager.ts:372

Flush all transcript buffers — finalize user and assistant messages.

Returns ​

void


flushInput() ​

flushInput(): void

Defined in: src/core/transcript-manager.ts:350

Flush only the input transcript buffer — finalize as a user message and send a non-partial transcript to the client. Used before tool calls so the user utterance appears in context before tool results.

Returns ​

void


handleInput() ​

handleInput(text, turnId?): void

Defined in: src/core/transcript-manager.ts:234

Accumulate incoming user speech transcription and emit a partial transcript.

turnId (when the STT provider supplies one) identifies the utterance. A change of turnId means a new user utterance arrived: if the previous one is still buffered (e.g. its barge-in was rejected so no turn finalized and flushed it), finalize it as its own message instead of concatenating the two into one user turn. A batch transcript that arrives over text a provider correction already wrote replaces it rather than appending, so the utterance does not double ("X" + "X" → "XX"). Id-less providers keep the plain delta-append behavior.

Parameters ​

text ​

string

turnId? ​

number

Returns ​

void


handleInputPartial() ​

handleInputPartial(text): void

Defined in: src/core/transcript-manager.ts:160

Handle a partial/interim transcript from a streaming STT provider. Sends to client for live display but does NOT accumulate in inputBuffer. The streaming provider manages its own partial state — each partial replaces the previous one on the client.

Parameters ​

text ​

string

Returns ​

void


handleOutput() ​

handleOutput(text): void

Defined in: src/core/transcript-manager.ts:321

Accumulate incoming model speech transcription and emit a partial transcript.

Parameters ​

text ​

string

Returns ​

void


saveOutputPrefix() ​

saveOutputPrefix(): void

Defined in: src/core/transcript-manager.ts:338

Save current output buffer as prefix and reset buffer. Called before tool execution so post-tool transcription can be deduplicated.

Returns ​

void


sealPendingInput() ​

sealPendingInput(turnId?): void

Defined in: src/core/transcript-manager.ts:143

Seal outstanding reservations with the provisional text already recorded — the fallback when the authoritative transcript fails or times out. Pass a turnId to seal one, or omit to seal all (session close).

Parameters ​

turnId? ​

number

Returns ​

void


sealReservedInput() ​

sealReservedInput(turnId, text): boolean

Defined in: src/core/transcript-manager.ts:121

Resolve the reservation for turnId with the authoritative transcript that has finally arrived, and correct the client's displayed final.

Parameters ​

turnId ​

number

text ​

string

Returns ​

boolean

false when no reservation is outstanding for that turn.


showInterruptedInputPartial() ​

showInterruptedInputPartial(textDelta): void

Defined in: src/core/transcript-manager.ts:178

Show realtime input transcription deltas immediately on an interrupted turn, as a display-only partial. Accumulates deltas for the running line but never writes inputBuffer, so the slower batch STT (handleInput) stays authoritative for the finalized user message and corrects this display. The buffer is reset on flush()/flushInput().

Parameters ​

textDelta ​

string

Returns ​

void

Built with VitePress