Skip to content

bodhi-realtime-agent / BackgroundNotificationQueue

Class: BackgroundNotificationQueue

Defined in: core/background-notification-queue.ts:27

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: core/background-notification-queue.ts:34

Parameters

sendContent

(turns, turnComplete) => void

log

(msg) => void

messageTruncation

boolean = false

Returns

BackgroundNotificationQueue

Methods

clear()

clear(): void

Defined in: core/background-notification-queue.ts:118

Drop all queued notifications (used on session close).

Returns

void


markAudioReceived()

markAudioReceived(): void

Defined in: core/background-notification-queue.ts:89

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

Returns

void


markInterrupted()

markInterrupted(): void

Defined in: core/background-notification-queue.ts:94

Mark that the current turn was interrupted by the user.

Returns

void


onTurnComplete()

onTurnComplete(): void

Defined in: core/background-notification-queue.ts:102

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

Returns

void


resetAudio()

resetAudio(): void

Defined in: core/background-notification-queue.ts:113

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

Returns

void


sendOrQueue()

sendOrQueue(turns, turnComplete, options?): void

Defined in: core/background-notification-queue.ts:52

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

Built with VitePress