Skip to content

bodhi-realtime-agent / GeminiLiveTransport

Class: GeminiLiveTransport

Defined in: transport/gemini-live-transport.ts:102

WebSocket transport layer for the Gemini Live API.

Wraps the @google/genai SDK's live.connect() to manage the bidirectional audio stream. Handles connection setup, message routing, tool declaration conversion (Zod → JSON Schema), and session resumption.

Implements LLMTransport for provider-agnostic usage. The constructor callback pattern is preserved for backward compatibility alongside the LLMTransport callback properties.

Implements

Constructors

Constructor

new GeminiLiveTransport(config, callbacks): GeminiLiveTransport

Defined in: transport/gemini-live-transport.ts:165

Parameters

config

GeminiTransportConfig

callbacks

GeminiTransportCallbacks

Returns

GeminiLiveTransport

Properties

audioFormat

readonly audioFormat: AudioFormatSpec

Defined in: transport/gemini-live-transport.ts:136

Implementation of

LLMTransport.audioFormat


capabilities

readonly capabilities: TransportCapabilities

Defined in: transport/gemini-live-transport.ts:125

Static capabilities — read before connecting, used for orchestrator branching.

Implementation of

LLMTransport.capabilities


onAudioOutput()?

optional onAudioOutput: (base64Data) => void

Defined in: transport/gemini-live-transport.ts:146

Parameters

base64Data

string

Returns

void

Implementation of

LLMTransport.onAudioOutput


onClose()?

optional onClose: (code?, reason?) => void

Defined in: transport/gemini-live-transport.ts:155

Parameters

code?

number

reason?

string

Returns

void

Implementation of

LLMTransport.onClose


onError()?

optional onError: (error) => void

Defined in: transport/gemini-live-transport.ts:154

Parameters

error

LLMTransportError

Returns

void

Implementation of

LLMTransport.onError


onGoAway()?

optional onGoAway: (timeLeft) => void

Defined in: transport/gemini-live-transport.ts:157

Parameters

timeLeft

string

Returns

void

Implementation of

LLMTransport.onGoAway


onGroundingMetadata()?

optional onGroundingMetadata: (metadata) => void

Defined in: transport/gemini-live-transport.ts:159

Parameters

metadata

Record<string, unknown>

Returns

void

Implementation of

LLMTransport.onGroundingMetadata


onInputTranscription()?

optional onInputTranscription: (text) => void

Defined in: transport/gemini-live-transport.ts:151

Parameters

text

string

Returns

void

Implementation of

LLMTransport.onInputTranscription


onInterrupted()?

optional onInterrupted: () => void

Defined in: transport/gemini-live-transport.ts:150

Returns

void

Implementation of

LLMTransport.onInterrupted


onModelTurnStart()?

optional onModelTurnStart: () => void

Defined in: transport/gemini-live-transport.ts:156

Fires when the model begins any response (audio, tool call, etc.). Used by VoiceSession to trigger STT provider commit.

Returns

void

Implementation of

LLMTransport.onModelTurnStart


onOutputTranscription()?

optional onOutputTranscription: (text) => void

Defined in: transport/gemini-live-transport.ts:152

Parameters

text

string

Returns

void

Implementation of

LLMTransport.onOutputTranscription


onRealtimeLLMUsage()?

optional onRealtimeLLMUsage: (usage) => void

Defined in: transport/gemini-live-transport.ts:163

Optional: fires when the provider reports token or duration usage for billing/observability.

Parameters

usage

RealtimeLLMUsageEvent

Returns

void

Implementation of

LLMTransport.onRealtimeLLMUsage


onResumptionUpdate()?

optional onResumptionUpdate: (handle, resumable) => void

Defined in: transport/gemini-live-transport.ts:158

Parameters

handle

string

resumable

boolean

Returns

void

Implementation of

LLMTransport.onResumptionUpdate


onSessionReady()?

optional onSessionReady: (sessionId) => void

Defined in: transport/gemini-live-transport.ts:153

Parameters

sessionId

string

Returns

void

Implementation of

LLMTransport.onSessionReady


onSpeechStarted()?

optional onSpeechStarted: () => void

Defined in: transport/gemini-live-transport.ts:162

Fires when the transport detects user speech via VAD. Used for TTS-level barge-in when the LLM is idle but TTS is still playing. OpenAI: wired to input_audio_buffer.speech_started. Gemini: may require custom VAD signal — needs empirical testing.

Returns

void

Implementation of

LLMTransport.onSpeechStarted


onTextDone()?

optional onTextDone: () => void

Defined in: transport/gemini-live-transport.ts:161

Fires when the model's text response is complete for this turn. Signals that all text for the current response has been delivered. Ordering contract: fires after all onTextOutput, before onTurnComplete.

Returns

void

Implementation of

LLMTransport.onTextDone


onTextOutput()?

optional onTextOutput: (text) => void

Defined in: transport/gemini-live-transport.ts:160

Fires when the model produces text output (text-mode responses). Only active when responseModality is 'text' (i.e., external TTS in use).

Parameters

text

string

Incremental text chunk (may be partial word/sentence)

Returns

void

Implementation of

LLMTransport.onTextOutput


onToolCall()?

optional onToolCall: (calls) => void

Defined in: transport/gemini-live-transport.ts:147

Parameters

calls

TransportToolCall[]

Returns

void

Implementation of

LLMTransport.onToolCall


onToolCallCancel()?

optional onToolCallCancel: (ids) => void

Defined in: transport/gemini-live-transport.ts:148

Parameters

ids

string[]

Returns

void

Implementation of

LLMTransport.onToolCallCancel


onTurnComplete()?

optional onTurnComplete: () => void

Defined in: transport/gemini-live-transport.ts:149

Returns

void

Implementation of

LLMTransport.onTurnComplete

Accessors

isConnected

Get Signature

get isConnected(): boolean

Defined in: transport/gemini-live-transport.ts:362

Returns

boolean

Implementation of

LLMTransport.isConnected

Methods

clearAudio()

clearAudio(): void

Defined in: transport/gemini-live-transport.ts:410

No-op for V1 — server VAD only.

Returns

void

Implementation of

LLMTransport.clearAudio


commitAudio()

commitAudio(): void

Defined in: transport/gemini-live-transport.ts:407

No-op for V1 — server VAD only.

Returns

void

Implementation of

LLMTransport.commitAudio


connect()

connect(transportConfig?): Promise<void>

Defined in: transport/gemini-live-transport.ts:178

Establish a WebSocket connection to the Gemini Live API. Resolves only after Gemini sends setupComplete, so callers can safely send content immediately after awaiting this method.

Also satisfies LLMTransport.connect(config) — if config is provided, it is applied before connecting.

Parameters

transportConfig?

LLMTransportConfig

Returns

Promise<void>

Implementation of

LLMTransport.connect


disconnect()

disconnect(): Promise<void>

Defined in: transport/gemini-live-transport.ts:308

Returns

Promise<void>

Implementation of

LLMTransport.disconnect


reconnect()

reconnect(stateOrHandle?): Promise<void>

Defined in: transport/gemini-live-transport.ts:280

Disconnect and reconnect, optionally with a new resumption handle or ReconnectState. Accepts either a string handle (legacy API) or ReconnectState (LLMTransport API).

Parameters

stateOrHandle?

string | ReconnectState

Returns

Promise<void>

Implementation of

LLMTransport.reconnect


sendAudio()

sendAudio(base64Data): void

Defined in: transport/gemini-live-transport.ts:322

Send base64-encoded PCM audio to Gemini as realtime input.

Parameters

base64Data

string

Returns

void

Implementation of

LLMTransport.sendAudio


sendClientContent()

sendClientContent(turns, turnComplete?): void

Defined in: transport/gemini-live-transport.ts:339

Send text-based conversation turns to Gemini (legacy API, used for context replay).

Parameters

turns

object[]

turnComplete?

boolean = true

Returns

void


sendContent()

sendContent(turns, turnComplete?): void

Defined in: transport/gemini-live-transport.ts:369

Send provider-neutral content turns to Gemini. Converts ContentTurn to Gemini format.

Parameters

turns

ContentTurn[]

turnComplete?

boolean = true

Returns

void

Implementation of

LLMTransport.sendContent


sendFile()

sendFile(base64Data, mimeType): void

Defined in: transport/gemini-live-transport.ts:379

Send a file/image to Gemini as inline data.

Parameters

base64Data

string

mimeType

string

Returns

void

Implementation of

LLMTransport.sendFile


sendToolResponse()

sendToolResponse(responses, _scheduling?): void

Defined in: transport/gemini-live-transport.ts:330

Send tool execution results back to Gemini (legacy API).

Parameters

responses

object[]

_scheduling?

"SILENT" | "WHEN_IDLE" | "INTERRUPT"

Returns

void


sendToolResult()

sendToolResult(result): void

Defined in: transport/gemini-live-transport.ts:388

Send a tool result back to Gemini (LLMTransport API).

Parameters

result

TransportToolResult

Returns

void

Implementation of

LLMTransport.sendToolResult


transferSession()

transferSession(config, state?): Promise<void>

Defined in: transport/gemini-live-transport.ts:437

Transfer session: update config → reconnect → replay conversation history.

Parameters

config

SessionUpdate

state?

ReconnectState

Returns

Promise<void>

Implementation of

LLMTransport.transferSession


triggerGeneration()

triggerGeneration(_instructions?): void

Defined in: transport/gemini-live-transport.ts:402

No-op for Gemini — generation is automatic after tool results and content injection.

Parameters

_instructions?

string

Returns

void

Implementation of

LLMTransport.triggerGeneration


updateGoogleSearch()

updateGoogleSearch(enabled): void

Defined in: transport/gemini-live-transport.ts:358

Update Google Search grounding flag (applied on next reconnect).

Parameters

enabled

boolean

Returns

void


updateSession()

updateSession(config): void

Defined in: transport/gemini-live-transport.ts:413

Update session configuration (applied on next reconnect for Gemini).

Parameters

config

SessionUpdate

Returns

void

Implementation of

LLMTransport.updateSession


updateSystemInstruction()

updateSystemInstruction(instruction): void

Defined in: transport/gemini-live-transport.ts:353

Update the system instruction (applied on next reconnect).

Parameters

instruction

string

Returns

void


updateTools()

updateTools(tools): void

Defined in: transport/gemini-live-transport.ts:348

Update the tool declarations (applied on next reconnect).

Parameters

tools

ToolDefinition[]

Returns

void

Built with VitePress