Skip to content

bodhi-realtime-agent / BackgroundNotificationQueue

Class: BackgroundNotificationQueue ​

Defined in: src/core/background-notification-queue.ts:25

Queues background tool completion notifications when the LLM is actively generating audio, and flushes them one-at-a-time at turn boundaries.

Extracted from VoiceSession to isolate the queuing/delivery concern. On transports without messageTruncation (Gemini), the model silently absorbs client content while generating — notifications must be held until the model finishes its current turn. On transports with messageTruncation (OpenAI), high-priority messages can be delivered immediately (the transport handles response cancellation internally).

Constructors ​

Constructor ​

new BackgroundNotificationQueue(sendContent, log, messageTruncation?): BackgroundNotificationQueue

Defined in: src/core/background-notification-queue.ts:35

Parameters ​

sendContent ​

(turns, turnComplete) => void

log ​

(msg) => void

messageTruncation? ​

boolean = false

Returns ​

BackgroundNotificationQueue

Methods ​

clear() ​

clear(): void

Defined in: src/core/background-notification-queue.ts:135

Drop all queued notifications (used on session close).

Returns ​

void


markAudioReceived() ​

markAudioReceived(): void

Defined in: src/core/background-notification-queue.ts:106

Mark that the first audio chunk has been received this turn.

Returns ​

void


markInterrupted() ​

markInterrupted(): void

Defined in: src/core/background-notification-queue.ts:111

Mark that the current turn was interrupted by the user.

Returns ​

void


onTurnComplete() ​

onTurnComplete(): void

Defined in: src/core/background-notification-queue.ts:119

Handle turn completion: reset audio/interruption flags and flush one queued notification (unless the turn was interrupted).

Returns ​

void


resetAudio() ​

resetAudio(): void

Defined in: src/core/background-notification-queue.ts:130

Reset audio flag without flushing (used when starting a new greeting).

Returns ​

void


sendOrQueue() ​

sendOrQueue(turns, turnComplete, options?): void

Defined in: src/core/background-notification-queue.ts:53

Send a notification immediately if the model is idle, or queue it if the model is currently generating audio.

High-priority messages attempt immediate delivery when the transport supports message truncation (OpenAI). On non-truncation transports (Gemini), high-priority messages are queued at the front of the queue.

Deduplication: If a toolCallId is provided and has already been notified, the notification is silently skipped to prevent race conditions where a background task completes synchronously before audio generation begins.

Parameters ​

turns ​

Turn[]

turnComplete ​

boolean

options? ​

SendOrQueueOptions

Returns ​

void


setHeld() ​

setHeld(held): void

Defined in: src/core/background-notification-queue.ts:101

Hold or release delivery. While held, sendOrQueue queues everything (high priority at the front) and onTurnComplete flushes nothing. Releasing does not flush by itself: the next turn completion does.

Parameters ​

held ​

boolean

Returns ​

void

Built with VitePress