Member Junction
    Preparing search index...

    Concrete IRealtimeSession backed by a raw ElevenLabs Agents conversation websocket.

    Owns the inbound translation (snake_case wire events → Core events) and the outbound translation (Core calls → wire frames). Created by ElevenLabsRealtime.StartSession; never instantiated directly by consumers.

    Provider-behavior notes (the contract deltas a consumer should know):

    • Transcripts are FINAL-only. The Agents websocket emits whole-utterance user_transcript / agent_response events — there are no interim deltas, so every RealtimeTranscript this session emits has IsFinal: true.
    • agent_response_correction re-finalizes a truncated turn. After a barge-in the platform sends the corrected (actually-spoken) agent text; the session emits it as a fresh FINAL assistant transcript — consumers persisting transcripts should treat a final assistant transcript arriving immediately after an interruption as the authoritative replacement for the previous one.
    • No usage events — see the driver-level note.
    • RequestSpokenUpdate is emulated with a user_message turn (ElevenLabs has no per-response-instructions channel), queued behind any in-flight response. Fidelity caveat: the instruction enters the conversation as a user turn, so the agent may occasionally reference it ("you asked me to give an update") — hosts should phrase instructions accordingly. SendContextNote is NATIVE (contextual_update) and never interrupts.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    callsFromBeforeReseed: Set<string>
    closedByConsumer: boolean
    configuredCallDurationSeconds: number
    configuredReconnectBufferSeconds: number
    configuredSessionMaxSeconds: number
    configuredTrustNativeResumption: boolean
    configuredZeroDataRetention: boolean
    conversationMemory: RealtimeConversationMemory
    pendingToolCallNames: Map<string, string>
    reconnectController: RealtimeReconnectController
    turnOpen: boolean

    Accessors

    • get CallDurationSeconds(): number

      Effective single-connection duration in seconds, resolved via ClampSessionSecondsValue so metadata (configuredCallDurationSeconds) narrows the driver's provider ceiling (DefaultCallDurationSeconds) and any state-dependent RuntimeCallDurationSeconds, never widening it.

      Returns number

    • get ConversationMemory(): RealtimeConversationMemory

      Accessor for the session's provider-neutral conversation memory ledger.

      Returns RealtimeConversationMemory

    • get DefaultTrustsNativeResumption(): boolean

      Driver default for whether native resumption handles are trusted when metadata does not override.

      Returns boolean

    • get IsClosedByConsumer(): boolean

      True once the consumer has closed the session.

      Returns boolean

    • get IsReconnecting(): boolean

      True while an in-place reconnect is currently running.

      Returns boolean

    • get ReconnectBufferSeconds(): number

      Buffer in seconds before CallDurationSeconds at which the framework initiates a reconnect.

      Returns number

    • get RequiresPostTurnResumptionHandle(): boolean

      Whether this session's provider emits a fresh resumable handle shortly after each turnComplete (e.g. Gemini / Vertex AI Live), so a planned move (goAway or soft window) during a turn waits for that post-turn handle (bounded by the deadline timer) rather than resuming from a pre-turn handle.

      Returns boolean

    • get ResumptionHandle(): string

      Latest recorded provider resumption handle, or null if none.

      Returns string

    • get RuntimeCallDurationSeconds(): number

      Dynamic state-dependent duration cap in seconds (for example, returning 120 when uncompressed video is active on Gemini Live, and undefined otherwise). Clamped with configuredCallDurationSeconds via ClampSessionSecondsValue so neither a seeded 600s catalog value nor a tighter custom metadata value (e.g., 45s) is shadowed.

      Returns number

    • get SessionMaxSeconds(): number

      Configured credential/session lifetime in seconds, when distinct from CallDurationSeconds.

      Returns number

    • get TrustsNativeResumption(): boolean

      Whether native resumption is trusted on this session (always false under ZeroDataRetention).

      Returns boolean

    Methods

    • Extracts timing and native-resumption overrides from a session configuration bag.

      Parameters

      • config: Record<string, unknown>

      Returns void

    • Arms (or re-arms) the proactive connection-duration timer for the current connection.

      Returns void

    • Cancels all reconnect and duration timers and abandons any in-flight attempt when closed by the consumer. Tool results held for the attempt are dropped: no new connection will carry them.

      Returns void

    • Surfaces an UNEXPECTED socket close as a fatal error (expected closes — the consumer called Close — are silent). ElevenLabs hard-closes at signed-URL expiry and when the agent itself ends the conversation, so this is also how credential / conversation death reaches the consumer.

      Parameters

      Returns void

    • Holds a tool result that arrives while a reconnect is moving the session, and returns true when it did. Sent then, the result would reach the connection being replaced after the attempt's seed was built, so the new connection would have the call and never its result. A driver calls this first in SendToolResult and returns when it is true. Once the move lands the result goes through SendToolResult again, after callsFromBeforeReseed is rebuilt, so a reseeded connection gets it as a late-result note; a failed reconnect or a close drops it with a warning. Outside a reconnect it returns false and changes nothing.

      Parameters

      • callID: string
      • output: string
      • OptionaltaskRevision: number

      Returns boolean

    • Clears the recorded resumption handle so subsequent reconnects fall back to history seeding.

      Returns void

    • Handles a provider-initiated connection-ending advisory (goAway / session.going_away). Reconnects immediately if idle and ready, or waits for the turn/handle boundary up to the scaled deadline.

      Parameters

      • OptionaltimeLeftMs: number

      Returns void

    • Notifies the reconnect controller when pending tool calls drain on SendToolResult. When expectsReply is true (default), a queued soft-window or ConnectionEnding move waits for the model's post-tool turn (or a fresh trusted native handle) rather than reconnecting in the gap between SendToolResult and the first model output frame.

      Parameters

      • OptionalexpectsReply: boolean

      Returns void

    • Marks a turn as ended and triggers a queued soft-window or ConnectionEnding reconnect if ready.

      Parameters

      • OptionalkeepPostToolTurnWait: boolean

      Returns void

    • Marks a turn as open so soft-window reconnects wait for the turn boundary.

      Returns void

    • Registers a handler for provider-detected interruptions (barge-in).

      True barge-in only: the handler fires ONLY when user speech interrupts ACTIVE model output — NOT on every user utterance. A user simply taking their normal turn while the model is idle is not an interruption, and drivers must not report it as one (e.g. a raw "speech started" frame must be gated on whether a model response is actually in flight).

      Turn detection / VAD is owned by the provider. The agent layer uses this hook to cancel the model's current turn and to fire the cancellationToken of any in-flight delegated agent run — a stale delegated result must never be narrated into a conversation that has moved on.

      Parameters

      • handler: () => void

        Invoked when the provider reports a true barge-in interruption.

      Returns void

    • Hook invoked when a reconnect attempt succeeds.

      Parameters

      • _usedNativeResumption: boolean

      Returns void

    • Records a provider resumption handle or conversation ID.

      Parameters

      • handle: string
      • Optionalresumable: boolean

      Returns void

    • Parameters

      • instructions: string

      Returns void

      via a user_message turn (see the class-level fidelity caveat). Collision behavior: queue. A user_message sent mid-response would barge in on the in-flight reply (the platform treats it as the user taking the floor), so the send is deferred until the active response completes.

    • Sends the conversation_initiation_client_data frame carrying the session's overrides (the per-session system prompt, and the voice when one is configured), which the managed agent's platform settings enable. The override object is built by ElevenLabsRealtime.BuildSessionOverrides and passed in already wire-shaped, so this server-bridged path and the client-direct mint cannot drift apart.

      initialContext, when provided, is held back and injected as a native contextual_update once the metadata confirms the session — ElevenLabs has no pre-turn history-seeding channel, so prior context rides the contextual-update lane.

      Parameters

      • overrides: JSONObject

        The wire-shaped conversation_config_override for this session.

      • OptionalinitialContext: string

        Optional prior context to inject once the session is confirmed.

      • OptionaltargetSocket: ElevenLabsRealtimeSocket

        Optional socket to send the initiation frame on (used during reconnect handshake).

      Returns void

    • Parameters

      • callID: string
      • output: string

      Returns Promise<void>

      client_tool_result correlated by tool_call_id. Sent IMMEDIATELY (never queued behind a reply): the platform requested the result (expects_response: true blocks the conversation on it) and handles its own continuation, so deferring it could only delay the spoken reply. The one wait is a reconnect: the result is held and sent on the new socket (holdToolResultDuringReconnect). The result string rides as given, never parsed.

    • Resolves once the server's conversation_initiation_metadata arrives (the provider's confirmation that the session — including the prompt override — is applied); rejects if the transport dies first. Awaited by ElevenLabsRealtime.StartSession so the session is never handed to a consumer before it is actually configured.

      Returns Promise<void>