workerprotocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 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 workerprotocol implements the LiveKit agent worker WebSocket wire protocol. It deliberately exposes a small transport interface so the worker actor can be tested without a network connection.

Index

Constants

View Source
const (
	IPCTypeHello      = "hello"
	IPCTypeReady      = "ready"
	IPCTypeInitialize = "initialize"
	IPCTypeStart      = "start"
	IPCTypeStop       = "stop"
	IPCTypeStatus     = "status"
	IPCTypeDone       = "done"

	IPCTypeInferenceRequest  = "inference_request"
	IPCTypeInferenceResponse = "inference_response"
	IPCTypeInferenceCancel   = "inference_cancel"
)
View Source
const MaxIPCFrameSize = 16 << 20

Variables

View Source
var (
	ErrUnexpectedMessageType = errors.New("worker protocol: expected a binary WebSocket message")
	ErrClosed                = errors.New("worker protocol: transport is closed")
)

Functions

func AgentEndpoint

func AgentEndpoint(rawURL, workerToken string) (*url.URL, error)

AgentEndpoint converts an HTTP(S) or WebSocket LiveKit URL into the worker WebSocket endpoint and adds an optional Cloud worker token.

Types

type Dialer

type Dialer interface {
	Dial(context.Context, *url.URL, http.Header) (Transport, error)
}

Dialer opens a worker protocol transport.

type FramedConn

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

FramedConn serializes JSON messages over a stream connection with a fixed four-byte big-endian size prefix. It permits one concurrent reader and one concurrent writer.

func NewFramedConn

func NewFramedConn(conn net.Conn) *FramedConn

func (*FramedConn) Close

func (c *FramedConn) Close() error

func (*FramedConn) Read

func (c *FramedConn) Read(ctx context.Context) (IPCMessage, error)

func (*FramedConn) Write

func (c *FramedConn) Write(ctx context.Context, msg IPCMessage) error

type GorillaDialer

type GorillaDialer struct {
	HandshakeTimeout time.Duration
	WriteTimeout     time.Duration
	ReadLimit        int64
	Proxy            func(*http.Request) (*url.URL, error)
}

GorillaDialer is the production WebSocket dialer. Zero fields use safe defaults. Compression stays disabled because protobuf worker messages are small and compression adds CPU and cross-message memory state.

func (GorillaDialer) Dial

func (d GorillaDialer) Dial(ctx context.Context, endpoint *url.URL, header http.Header) (Transport, error)

type IPCMessage

type IPCMessage struct {
	Type string `json:"type"`

	Token string `json:"token,omitempty"`
	Error string `json:"error,omitempty"`
	// ErrorCode carries a stable machine-readable category for errors that
	// cross a process boundary. Error remains the human-readable diagnostic.
	ErrorCode string `json:"error_code,omitempty"`
	Reason    string `json:"reason,omitempty"`
	Status    int32  `json:"status,omitempty"`
	Success   bool   `json:"success,omitempty"`
	// RequestID, Method, and Data multiplex shared local inference over the
	// authenticated job control connection. Data is raw JSON so the framing
	// layer never performs a lossy interface{} round trip.
	RequestID string          `json:"request_id,omitempty"`
	Method    string          `json:"method,omitempty"`
	Methods   []string        `json:"methods,omitempty"`
	Data      json.RawMessage `json:"data,omitempty"`
	// DeadlineUnixNano preserves a request context deadline across both the
	// job-control and supervised-inference process hops.
	DeadlineUnixNano int64 `json:"deadline_unix_nano,omitempty"`

	Job                   []byte            `json:"job,omitempty"`
	URL                   string            `json:"url,omitempty"`
	RoomToken             string            `json:"room_token,omitempty"`
	WorkerID              string            `json:"worker_id,omitempty"`
	APIKey                string            `json:"api_key,omitempty"`
	APISecret             string            `json:"api_secret,omitempty"`
	FakeJob               bool              `json:"fake_job,omitempty"`
	ParticipantName       string            `json:"participant_name,omitempty"`
	ParticipantIdentity   string            `json:"participant_identity,omitempty"`
	ParticipantMetadata   string            `json:"participant_metadata,omitempty"`
	ParticipantAttributes map[string]string `json:"participant_attributes,omitempty"`
}

IPCMessage is the authenticated, length-delimited control protocol between the worker and its one-shot job subprocess. Job contains a protobuf-encoded livekit.Job. Secrets never appear in command-line arguments.

type Transport

type Transport interface {
	Read(context.Context) (*livekit.ServerMessage, error)
	Write(context.Context, *livekit.WorkerMessage) error
	Close() error
}

Transport permits one concurrent reader and one concurrent writer. Close is idempotent and unblocks an outstanding Read.

Jump to

Keyboard shortcuts

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