realtimeclient

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package realtimeclient is a Realtime protocol client.

It exists twice over: the upstream binding needs it to put a remote model behind OpenRealtime's background reasoner, and the measurement program needs it to drive any Realtime-compatible endpoint - including this one - through the same wire the field uses. A client written against the protocol is also the only honest way to test that the protocol is what we say it is.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is one connection to a Realtime endpoint.

func Dial

func Dial(ctx context.Context, config Config) (*Client, error)

Dial connects and starts reading.

func (*Client) Close

func (client *Client) Close() error

Close ends the connection.

func (*Client) Err

func (client *Client) Err() error

Err reports why reading stopped, or nil for a clean close.

func (*Client) Events

func (client *Client) Events() <-chan Event

Events yields decoded server events until the connection closes.

func (*Client) Send

func (client *Client) Send(ctx context.Context, value any) error

Send writes one client event.

func (*Client) Wait

func (client *Client) Wait()

Wait blocks until the connection has finished reading.

type Config

type Config struct {
	// URL is the WebSocket endpoint, ws:// or wss://.
	URL string
	// Token is the bearer credential. Empty sends no Authorization header.
	Token string
	// Model is appended as a query parameter when the URL has none.
	Model string
	// Header carries additional headers, such as a provider's beta opt-in.
	Header http.Header
	// ValidateWire checks inbound server events against the pinned schema.
	// It is off by default here: a client that refuses to talk to a slightly
	// non-conformant server is less useful than one that reports the problem,
	// and the conformance suite is where strictness belongs.
	ValidateWire bool
	// ReadLimit bounds one inbound message. Zero selects 8 MiB, which is
	// generous enough for a large audio delta.
	ReadLimit int64
	// DialTimeout bounds connection establishment.
	DialTimeout time.Duration
	// WriteTimeout bounds one send on an established connection. Zero selects
	// the shipped default; a negative value removes the bound.
	//
	// Send takes a context, so a caller can always bound its own call - but
	// the callers that matter here hold a session-scoped socket and pass the
	// session's context, which ends when the conversation does. A peer that
	// stops reading then blocks the send with nothing left to end it, and
	// because Send holds the write lock, every later send blocks behind the
	// first. The upstream binding forwards a caller's audio through this, so
	// what stops is the conversation, with no error anywhere to say why.
	//
	// Thirty seconds rather than a cadence: this client carries whole Realtime
	// events to a Realtime server rather than frames to one provider, and the
	// bound only has to be past any stall a congested link produces and short
	// of forever. A caller whose traffic has a tighter cadence sets its own.
	WriteTimeout time.Duration
	// LifetimeContext optionally owns the established connection's receive
	// loop independently from the Dial call's setup context. Most callers leave
	// it nil. Measurement drivers use it when a task deadline must stop behavior
	// before closing a session-scoped inspection capability needed for terminal
	// evidence collection.
	LifetimeContext context.Context
	// EventAliases renames inbound server events onto the names this project
	// reads, which are OpenAI's current ones.
	//
	// Several endpoints implement the Realtime protocol as it stood before
	// OpenAI renamed response.audio.delta to response.output_audio.delta at
	// general availability. That is the entire difference for some of them, so
	// it is a rename table rather than a second client: a vendor whose only
	// deviation is a spelling should not cost an adapter.
	//
	// It renames the delivered event type and leaves the raw bytes untouched,
	// because the raw bytes are what the endpoint actually sent and a caller
	// decoding them should see the truth.
	EventAliases map[string]string
}

Config configures a connection.

type Event

type Event struct {
	Type string
	Raw  []byte
}

Event is one decoded server event, with its raw bytes retained so a caller can decode fields this package does not model.

func (Event) Decode

func (event Event) Decode(value any) error

Decode unmarshals the raw event into value.

func (Event) Field

func (event Event) Field(name string) string

Field returns one top-level field as a string, which is enough for the handful of routing decisions a caller usually needs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL