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.

    Implements

    Index

    Constructors

    Methods

    • 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

      • Optionalcode: number
      • Optionalreason: string

      Returns void

    • Surfaces a websocket-level failure as a FATAL session error — the transport is gone, so the consumer should finalize cleanly instead of idling (driver obligation #6).

      Parameters

      • message: string

      Returns void

    • Registers a handler for session errors.

      Fatality semantics mirror the client-side BaseRealtimeClient contract:

      • Fatal: true — the session is unusable (transport/socket failure, credential/token expiry, unexpected connection loss). The consumer should finalize the session (e.g. RealtimeSessionRunner calls Stop()) instead of idling forever on a dead socket.
      • Fatal: false — a provider-reported, recoverable error frame; the session stays open and the consumer should log and continue.

      Parameters

      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

    • Parameters

      Returns Promise<void>

      binds the tool set on the server-side AGENT configuration (the driver's managed-agent ensure flow), not on the open conversation. Per the contract's idempotency rule: an identical post-start set is a silent no-op; a different set is unsupported on an open conversation — it logs a clear warning and does nothing (the NEXT session picks the new set up via the ensure flow's fingerprint check).

    • 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.

    • Parameters

      • text: string

      Returns void

      on this provider: contextual_update is ElevenLabs' purpose-built non-interrupting context channel — sent immediately regardless of an in-flight response (the platform guarantees it never triggers or disturbs generation).

    • Sends the conversation_initiation_client_data frame carrying the per-session system prompt as the agent.prompt.prompt override (which the managed agent's platform settings enable). 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

      • systemPrompt: string
      • OptionalinitialContext: string

      Returns void

    • Parameters

      • callID: string
      • output: string

      Returns Promise<void>

      client_tool_result correlated by tool_call_id. Sent IMMEDIATELY (never queued): 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 result string is parsed to ride as structured JSON when possible; free-text results pass through as-is.

    • 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>