RealtimeSession
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:215
Provider-agnostic realtime voice session core. Wires a
RealtimeProviderAdapter’s tool calls to a Maelstrom instance:
update_ui submits an intent and withholds its tool result until the
resulting render settles (speak-after-render); get_ui_state answers
immediately from a structural snapshot; get_capabilities answers
immediately from the vessel capability catalog; render-settle events push
a debounced, latest-wins grounding string; and every fact the session
learns is published on RealtimeSession.events, which also feeds the
onEvent sidechannel.
Instances with createIntentScope share the application’s bounded FIFO with
typed input. Each connection owns only its pending work; disconnect retires
that work without cancelling a submitted turn. Tickets provide exact batch
outcomes, so no global idle wait or busy retry is added here. Legacy instances
are called once: busy is not-submitted, and transport uncertainty never
authorizes automatic replay.
Example
Section titled “Example”const session = new RealtimeSession({ adapter, instance: { createIntentScope: () => orchestrator.createIntentScope(), submitIntent: (intent) => orchestrator .processIntent(intent) .then((r) => ({ userMessage: r.userMessage })), waitForIdle: async () => { await orchestrator.commandProcessor.waitForIdle(); }, waitForIdleResult: () => orchestrator.commandProcessor.waitForIdle(), getStructuralSnapshot: () => orchestrator.getStructuralSnapshot(), getCapabilitySnapshot: () => orchestrator.getCapabilitySnapshot(), onSettled: (cb) => orchestrator.onSettled(cb), }, // …other options…});await session.connect();Implements
Section titled “Implements”VoiceSession
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RealtimeSession(
options):RealtimeSession
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:299
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”RealtimeSession
Properties
Section titled “Properties”memory
Section titled “memory”
readonlymemory:RealtimeSessionMemory
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:239
Recovery evidence retained independently of provider delivery. It may be shared with other sessions of the same Maelstrom session identity. Active application outcomes remain observable even after this session is disposed.
Accessors
Section titled “Accessors”events
Section titled “events”Get Signature
Section titled “Get Signature”get events():
SessionEventSource
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:355
Every fact this session publishes: connection lifecycle, transcript and
media evidence, tool calls and their results, update_ui recovery
outcomes, timings and the opening claim. Delivery is synchronous and in
publish order, with no replay, so read RealtimeSession.observations
for current values. The stream lives as long as this session; a
replacement session has its own.
Returns
Section titled “Returns”greetingState
Section titled “greetingState”Get Signature
Section titled “Get Signature”get greetingState():
GreetingState
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:400
Retained fixed-greeting presentation lifecycle for this shared session.
The value is initialized synchronously from coordinator proof and survives
session recreation when that proof is terminal. It does not mirror
provider activity, speech success, errors, transcripts, connection state,
or turn mode. Subscribe to greeting_state for later retained changes.
Returns
Section titled “Returns”lastError
Section titled “lastError”Get Signature
Section titled “Get Signature”get lastError():
unknown
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:441
The failure behind the most recent error state, if any. Cleared at the
start of the next connect() attempt, but preserved by explicit
disconnect() even after that method returns the public state to idle.
Typed provider failures are RealtimeVoiceError — switch on .code for
recovery UX. If subscription cleanup also fails, an AggregateError
retains the provider failure first, followed by cleanup failures.
Returns
Section titled “Returns”unknown
observations
Section titled “observations”Get Signature
Section titled “Get Signature”get observations():
VoiceObservationSource
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:360
Shared continuous observations. Reading or subscribing does not connect the provider.
Returns
Section titled “Returns”VoiceObservationSource
Get Signature
Section titled “Get Signature”get state():
VoiceSessionState
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:343
Returns
Section titled “Returns”VoiceSessionState
Implementation of
Section titled “Implementation of”VoiceSession.state
turnControl
Section titled “turnControl”Get Signature
Section titled “Get Signature”get turnControl():
AdapterTurnControl|undefined
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:429
Current adapter-owned manual turn control. It is exposed only after the adapter establishes manual mode and is read dynamically so adapter degradation or teardown can replace or remove the control safely.
Returns
Section titled “Returns”AdapterTurnControl | undefined
turnMode
Section titled “turnMode”Get Signature
Section titled “Get Signature”get turnMode():
TurnMode
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:410
Retained turn-boundary mode, initially automatic. Speech-native adapters
establish a clean automatic mode after connect succeeds; adapters emit
turn_mode when they establish manual control or change mode. A failed
reconnect does not synthesize a clean transition or clear this value.
Returns
Section titled “Returns”turnModeError
Section titled “turnModeError”Get Signature
Section titled “Get Signature”get turnModeError():
unknown
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:420
Diagnostic from an attempted automatic mode that degraded to manual. Clean mode events and a successful speech-native reconnect clear it; a failed reconnect preserves it. This value is for generic recovery guidance only; consumers must not render it verbatim or serialize it into telemetry.
Returns
Section titled “Returns”unknown
Methods
Section titled “Methods”connect()
Section titled “connect()”connect():
Promise<void>
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:458
Opens one provider connection. Re-entry from a live state is a no-op. A
successful connection that emitted no turn_mode establishes clean
automatic mode; a failed or stale attempt never synthesizes that fallback
and rejects with the adapter failure. An eligible configured greeting moves
to preparing synchronously before the provider handshake; retained
terminal proof leaves it settled or skipped and skips greeting work. The connection
generation owns both the greeting and connecting notifications: a
synchronous disconnect from either notification stops before audio
activation, adapter subscription, or provider connect. Audio activation
still occurs synchronously inside this call, before the first await.
Rejects once the session is disposed.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”VoiceSession.connect
disconnect()
Section titled “disconnect()”disconnect():
Promise<void>
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:656
Invalidates connection ownership and removes local subscriptions and
greeting work before awaiting provider cleanup. Whether provider cleanup
resolves or rejects, coordinator proof restores the greeting to retryable
pending or terminal settled, and the public state becomes idle.
lastError is preserved. A single cleanup or provider failure is rethrown
unchanged; multiple failures are reported together in an AggregateError.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”VoiceSession.disconnect
dispose()
Section titled “dispose()”dispose():
Promise<void>
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:684
Retires this session for good. It starts RealtimeSession.disconnect,
then detaches shared memory after outstanding application outcomes settle.
Submitted work retains truthful recovery evidence without provider delivery.
Later connect() calls reject. Repeated calls retain the first disconnect’s result, including a
rejection, without repeating provider teardown or lifecycle notifications.
Returns
Section titled “Returns”Promise<void>
getAudioStreams()
Section titled “getAudioStreams()”getAudioStreams():
AdapterAudioStreams
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:714
Live audio streams for UI metering (voice orbs, level meters). Delegates
to the provider adapter; see AdapterAudioStreams for absence semantics.
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”on(
event,handler):Unsubscribe
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:834
Parameters
Section titled “Parameters”"state"
handler
Section titled “handler”(s) => void
Returns
Section titled “Returns”Unsubscribe
Implementation of
Section titled “Implementation of”VoiceSession.on
Call Signature
Section titled “Call Signature”on(
event,handler):Unsubscribe
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:835
Parameters
Section titled “Parameters”"transcript"
handler
Section titled “handler”(t) => void
Returns
Section titled “Returns”Unsubscribe
Implementation of
Section titled “Implementation of”VoiceSession.on
Call Signature
Section titled “Call Signature”on(
event,handler):Unsubscribe
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:836
Parameters
Section titled “Parameters”"turn_mode"
handler
Section titled “handler”(event) => void
Returns
Section titled “Returns”Unsubscribe
Implementation of
Section titled “Implementation of”VoiceSession.on
Call Signature
Section titled “Call Signature”on(
event,handler):Unsubscribe
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:844
Subscribes to retained fixed-greeting lifecycle changes. The handler runs after each change, not immediately on subscription; read RealtimeSession.greetingState first for the current retained value. Disconnects and stale connection generations cannot publish late changes into a replacement generation.
Parameters
Section titled “Parameters”"greeting_state"
handler
Section titled “handler”(state) => void
Returns
Section titled “Returns”Unsubscribe
Implementation of
Section titled “Implementation of”VoiceSession.on
requestGeneratedOpening()
Section titled “requestGeneratedOpening()”requestGeneratedOpening(
instructions):Promise<boolean>
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:376
Requests generated wording once per session memory, including provider recreation.
Returns true only after adapter acceptance, never as proof of audible delivery.
Returns false when no opening was requested: unsupported, disconnected,
already attempted, or a fixed greeting is configured. A rejection still
consumes the attempt because the provider may already have received it.
No intended text becomes a transcript
or Engine history entry. Configured generatedOpening uses this same claim.
The claim is the one direct write into memory: it is a compare-and-set whose
answer gates the request, so it cannot be an event. opening.claimed is
published only after the claim is won.
Parameters
Section titled “Parameters”instructions
Section titled “instructions”string
Returns
Section titled “Returns”Promise<boolean>
skipGreeting()
Section titled “skipGreeting()”skipGreeting():
void
Defined in: packages/realtime/src/lib/realtime-session/realtime-session.ts:640
Synchronously and idempotently skip the configured fixed greeting without
disconnecting voice or changing turn mode. The coordinator proof wins
before local work is aborted, so stale async continuations cannot replay
or replace the retained skipped state.
Returns
Section titled “Returns”void