Member Junction
    Preparing search index...

    Class BaseRealtimeSessionAbstract

    Shared base class for server-hosted IRealtimeSession instances returned by BaseRealtimeModel.StartSession.

    Holds per-session state (connection duration timer, RealtimeConversationMemory, resumption handle, and reconnect retry loop) so BaseRealtimeModel remains stateless across concurrent sessions and so callers holding the outer IRealtimeSession reference keep the exact same session object across internal socket swaps.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

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

    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 DefaultTrustsNativeResumption(): boolean

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

      Returns boolean

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

    • 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

    • 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

    • 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

      • expectsReply: boolean = true

      Returns void

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

      Parameters

      • keepPostToolTurnWait: boolean = false

      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

    • Registers a handler for model audio output frames (the audio media plane).

      Parameters

      • handler: (chunk: ArrayBuffer) => void

        Invoked with each output audio frame as an ArrayBuffer.

      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
      • resumable: boolean = true

      Returns void

    • Registers the set of tools the model may call, translating them into the provider's native function-calling format.

      The Core-level RealtimeToolDefinition is intentionally minimal: BaseRealtimeModel lives in the lowest AI layer and cannot depend on the richer tool metadata defined in higher packages (the agent layer) — doing so would create an illegal upward/circular dependency. The agent layer is responsible for mapping its richer tool metadata down to this Core type before calling RegisterTools, and the concrete driver maps this Core type up to the provider's native function-calling schema.

      Note that some providers (e.g. Eleven Labs) bind to a pre-declared tool set on a server-side agent configuration; for those, the driver maps these definitions onto the pre-declared tool names rather than registering arbitrary schemas at session start.

      Idempotency rule: a post-start registration of a set IDENTICAL to the set supplied at connect time (via RealtimeSessionParams.Tools) MUST be a no-op. Providers that bind their tool set at connect time and cannot re-declare schemas on an open session MUST no-op (and may log) rather than degrade the conversation — e.g. by injecting schema text into the conversation as content. A genuinely DIFFERENT post-start set on such a provider is unsupported and should be surfaced as a warning, not silently mangled.

      Parameters

      Returns Promise<void>

    • Send the result of an executed tool/function call back to the model so it can continue the turn. output is the JSON-stringified tool result. Called by the agent layer after it handles an IRealtimeSession.OnToolCall.

      Parameters

      • callID: string

        The CallID from the originating RealtimeToolCall, used to correlate the result.

      • output: string

        The tool's result as a JSON-stringified string.

      • OptionaltaskRevision: number

        Optional task revision counter from the tool call. If supplied and mismatched, stale results are discarded.

      Returns Promise<void>

      A promise that resolves once the result has been sent to the provider.