livekit

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: 17 Imported by: 0

Documentation

Overview

Package livekit binds a voice.AgentSession to the current job's LiveKit room, recording, observability, report, and primary-session lifecycle.

Start is the one-step production path corresponding to AgentSession.start in the TypeScript and Python SDKs. The lower-level voice, roomio, recorderio, and telemetry packages remain available when an application needs explicit ownership of individual components.

Index

Constants

View Source
const (
	DefaultEventCapacity   = 256
	DefaultMaxReportEvents = 4096
	DefaultMaxReportBytes  = 8 << 20
	DefaultCloseTimeout    = 30 * time.Second
	DefaultFinalizeTimeout = 15 * time.Minute
)

Variables

View Source
var (
	ErrJobContextRequired        = errors.New("voice/livekit: a job context is required")
	ErrAudioRecordingUnavailable = errors.New("voice/livekit: audio recording requires both audio input and output")
	ErrReportEventLimit          = errors.New("voice/livekit: session report event retention limit reached")
)

Functions

This section is empty.

Types

type ReportStats

type ReportStats struct {
	RetainedEvents uint64
	RetainedBytes  uint64
	DroppedEvents  uint64
	CaptureError   error
}

ReportStats makes bounded-retention loss explicit. RetainedBytes counts the immutable canonical event bytes stored at the time of the snapshot.

type Runtime

type Runtime[UserData any] struct {
	// contains filtered or unexported fields
}

Runtime owns the components started by Start and implements agents.JobSessionLifecycle. Primary runtimes are closed and finalized by the job runner; a secondary runtime must be closed by its caller.

func Start

func Start[UserData any](ctx context.Context, session *voice.AgentSession[UserData], agent *voice.Agent[UserData], options StartOptions[UserData]) (_ *Runtime[UserData], resultErr error)

Start connects the current job if needed, atomically claims the primary session role, installs bounded event capture and media IO, configures lazy Cloud telemetry when applicable, and starts the AgentSession. Every partial start is rolled back in reverse ownership order.

func (*Runtime[UserData]) Close

func (r *Runtime[UserData]) Close(ctx context.Context) error

Close performs both lifecycle stages. The job runner calls the two explicit methods itself to preserve room-disconnect ordering.

func (*Runtime[UserData]) CloseSession

func (r *Runtime[UserData]) CloseSession(ctx context.Context) error

CloseSession implements agents.JobSessionLifecycle. Cleanup continues under an internal deadline if the caller stops waiting.

func (*Runtime[UserData]) FinalizeSession

func (r *Runtime[UserData]) FinalizeSession(ctx context.Context) error

FinalizeSession creates the immutable report, persists console reports, uploads Cloud observability data when configured, and drains telemetry.

func (*Runtime[UserData]) Logger

func (r *Runtime[UserData]) Logger() *slog.Logger

func (*Runtime[UserData]) Primary

func (r *Runtime[UserData]) Primary() bool

func (*Runtime[UserData]) RecorderIO

func (r *Runtime[UserData]) RecorderIO() *recorderio.RecorderIO

func (*Runtime[UserData]) RecordingOptions

func (r *Runtime[UserData]) RecordingOptions() voice.RecordingOptions

func (*Runtime[UserData]) Report

func (r *Runtime[UserData]) Report() *voice.SessionReport

func (*Runtime[UserData]) ReportStats

func (r *Runtime[UserData]) ReportStats() ReportStats

func (*Runtime[UserData]) RoomIO

func (r *Runtime[UserData]) RoomIO() *roomio.RoomIO

type StartOptions

type StartOptions[UserData any] struct {
	Job            *agents.JobContext[UserData]
	ConnectOptions agents.ConnectOptions

	RoomInput  *roomio.RoomInputOptions
	RoomOutput *roomio.RoomOutputOptions
	RoomIO     *roomio.RoomIO

	// Recording inherits livekit.Job.enable_recording when zero-valued. A
	// concrete sparse update explicitly selects its granular policy.
	Recording       agents.Override[voice.RecordingOptionsUpdate]
	Recorder        *recorderio.RecorderIO
	RecorderOptions recorderio.RecorderOptions

	EventCapacity   int
	MaxReportEvents int
	MaxReportBytes  int
	CloseTimeout    time.Duration
	FinalizeTimeout time.Duration

	Logger     *slog.Logger
	HTTPClient *http.Client
	Metadata   map[string]any
	UploadGate *telemetry.UploadGate
	// ObservabilityURL overrides Cloud endpoint discovery. It must be an
	// origin URL; LIVEKIT_OBSERVABILITY_URL is used when this field is empty.
	ObservabilityURL      string
	RecordingEndpoint     string
	LogEndpoint           string
	DisableCloudTelemetry bool

	// OnReport runs after the immutable report is assembled and before local
	// persistence or Cloud upload. It must honor ctx.
	OnReport func(context.Context, *voice.SessionReport) error
	// OnError receives asynchronous RoomIO and report-capture errors. Panics are
	// isolated. The Runtime also exposes the first capture error in ReportStats.
	OnError func(error)
}

StartOptions controls the high-level LiveKit binding. Zero values select the production defaults. After compatibility validation succeeds, supplying RoomIO or Recorder transfers ownership to the Start transaction: the returned Runtime closes them on success and partial-start rollback closes them on failure. Callers that need borrowed ownership should compose the lower-level roomio/recorderio packages directly.

Jump to

Keyboard shortcuts

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