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 ¶
const ( IPCTypeHello = "hello" IPCTypeReady = "ready" IPCTypeInitialize = "initialize" IPCTypeStart = "start" IPCTypeStop = "stop" IPCTypeStatus = "status" IPCTypeDone = "done" IPCTypeInferenceRequest = "inference_request" IPCTypeInferenceResponse = "inference_response" IPCTypeInferenceCancel = "inference_cancel" )
const MaxIPCFrameSize = 16 << 20
Variables ¶
var ( ErrUnexpectedMessageType = errors.New("worker protocol: expected a binary WebSocket message") ErrClosed = errors.New("worker protocol: transport is closed") )
Functions ¶
Types ¶
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.
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.