Skip to content

API Reference parrot.integrations.liveavatar.broadcast.models

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.liveavatar.broadcast.models

View source

Broadcast data contracts (FEAT-537 — Module 2 foundation).

Implements spec §2 "Data Models" of sdd/specs/voicebot-multiroom-heygen-avatar.spec.md.

These are new contracts: one Nova VoiceBot conversation fanned out to up to ten receiving browsers through a single LiveKit room, with a server-enforced moderator and a single exclusive speaking floor.

The single most important invariant in this module is the split between:

  • :class:BroadcastDescriptor — the full server-side record. It may reference a vendor session id for audit, but it never holds a token, secret, publisher JWT, ws_url or worker address.
  • :class:BroadcastPublicState — the only projection a browser may ever receive. A model_validator fails the model at construction time if any of its own field names looks credential-bearing, so a future field that leaks breaks loudly in every test rather than silently in production (AC3).

Attribute AVATAR_STARTUP_DEADLINE_S

Type: float

Alias AuthenticatedUser

Re-exported from parrot.core.ws_auth.AuthenticatedUser.

Class BroadcastAudioFrame

One fenced block of generated PCM on its way to the selected sink.

Every frame carries the full fencing tuple so a frame produced before a handoff, an ownership change or a fallback cutover can be discarded rather than played: stale owner_epoch, floor_epoch, turn_id or output_epoch all disqualify it.

Fields:

Field Type Default Description
owner_epoch int Ownership generation the frame was produced under.
speaker_lease_id str Authenticated lease whose turn produced it.
floor_epoch int Floor generation the input turn was admitted under.
turn_id str Identifier of the producing turn.
output_epoch int Output generation the frame belongs to.
sequence int Monotonic per-turn frame sequence.
pcm bytes Raw 16-bit little-endian mono PCM at :data:OUTPUT_SAMPLE_RATE.
sample_count int Number of samples in pcm.

Method BroadcastAudioFrame.is_current

Whether this frame is still valid against the live fencing tuple.

is_current(*, owner_epoch: int, floor_epoch: int, output_epoch: int, turn_id: Optional[str] = None) -> bool

Parameter Type Default Description
owner_epoch int Current ownership generation.
floor_epoch int Current floor generation.
output_epoch int Current output generation.
turn_id Optional[str] None Current turn id, when a turn is in flight.

Returns: bool — True only when every epoch matches and the turn (if given) is the producing turn.

Class BroadcastDescriptor

Full server-side record of one broadcast.

Persisted (namespaced by tenant and broadcast id) so any worker can serve participants or request a stop, while live SDK objects stay on the process that owns the producer. Never holds audio, AWS credentials or LiveAvatar access tokens — liveavatar_session_id is an audit identifier only.

Fields:

Field Type Default Description
broadcast_id str Unique broadcast identifier.
tenant_id str Owning tenant.
agent_id str Agent this broadcast speaks for.
creator_user_id str Who created it. Creation does not confer moderator authority — the first successful admission does.
moderator_lease_id Optional[str] None Lease of the current moderator.
speaker_lease_id Optional[str] None Lease permitted to send microphone audio.
floor_epoch int 0 Monotonic floor generation.
floor_state FloorState FloorState.IDLE Current floor state.
hand_requests List[HandRequest] Ordered raised-hand queue.
voice_session_id Optional[str] None Stable conversation/session key for the shared VoiceBot memory namespace.
room_name Optional[str] None Allocated LiveKit room.
owner_worker_id Optional[str] None Worker holding the producer lease.
owner_epoch int 0 Monotonic ownership generation used for fencing.
version int 0 Monotonic public version for compare-and-set.
state BroadcastState BroadcastState.PENDING Lifecycle state.
output_epoch int 0 Monotonic output generation.
avatar_identity Optional[str] None LiveKit identity of the avatar publisher.
direct_identity Optional[str] None LiveKit identity of the distinct direct publisher.
selected_audio_track_id Optional[str] None Authoritative audio track id.
selected_video_track_id Optional[str] None Avatar video track id, when present.
max_viewers int MAX_VIEWERS Seat ceiling (1–10).
admission_sequence int 0 Next server admission sequence to hand out.
created_at datetime Creation timestamp.
updated_at datetime Last mutation timestamp.
started_at Optional[datetime] None When media initialisation began.
ended_at Optional[datetime] None When the broadcast reached a terminal state.
failure_reason Optional[BroadcastReason] None Sanitized reason code, if any.
liveavatar_session_id Optional[str] None Vendor session id for audit only, never a token.

Attributes:

Attribute Type Description
is_terminal bool Whether the broadcast can no longer serve participants.
selected_identity Optional[str] Publisher identity that clients must play, per the current state. In avatar the avatar participant is authoritative; in audio_only the distinct direct publisher is. Any other state has no authoritative source and browsers must stay muted.

Method BroadcastDescriptor.to_public_state

Project this descriptor down to the browser-facing state.

Viewer occupancy lives in the lease records rather than the descriptor, so the registry supplies it; it defaults to 0 for a bare descriptor. media_ready is derived from the lifecycle state unless the caller overrides it.

to_public_state(*, viewer_count: int = 0, media_ready: Optional[bool] = None) -> BroadcastPublicState

Parameter Type Default Description
viewer_count int 0 Reserved seats currently in use.
media_ready Optional[bool] None Override for the derived readiness flag.

Returns: BroadcastPublicState — class:BroadcastPublicState carrying no credentials.

Class BroadcastPublicState

Scoped public projection of a broadcast — the only shape a browser sees.

Carries no vendor token, API secret, worker credential, worker address or internal tenant data. Participants are referred to by lease id (their display ID), never by user id or email.

Every browser observes version monotonically and treats the server as the sole authority; a state older than three seconds must mute output and disable capture (spec §2).

Fields:

Field Type Default Description
broadcast_id str Public broadcast identifier.
state BroadcastState Current lifecycle state.
version int Monotonic public version; moderator controls compare-and-set against it. Lease heartbeats do not bump it.
output_epoch int Monotonic output generation; browsers reject events from an older epoch.
media_ready bool Whether room credentials and media are available.
selected_identity Optional[str] None Publisher identity currently selected for playback.
selected_audio_track_id Optional[str] None Track id of the authoritative audio source.
selected_video_track_id Optional[str] None Track id of the avatar video, when present.
viewer_count int Reserved seats in use, including moderator and speaker.
max_viewers int Seat ceiling for this broadcast.
moderator_display_id Optional[str] None Lease id of the current moderator.
speaker_display_id Optional[str] None Lease id of the participant holding the floor.
floor_state FloorState Current floor state.
floor_epoch int Monotonic floor generation; stale-epoch audio is rejected.
hand_requests List[HandRequest] Ordered raised-hand queue.
reason Optional[BroadcastReason] None Sanitized reason code for the current or terminal state.

Class BroadcastReason

Sanitized reason codes safe to return to any admitted participant.

These are the only failure/rejection strings that cross the API boundary; vendor error text, stack traces and internal addresses never do.

Class BroadcastState

Lifecycle of one broadcast.

pending → starting → avatar | audio_only → stopping → ended. The avatar → audio_only edge is one-way: fallback is sticky for the lifetime of the broadcast. A fatal Nova, LiveKit or ownership failure routes through cleanup to failed.

Attribute CONTROL_EXPIRY_S

Type: int

Attribute CONTROL_HEARTBEAT_S

Type: int

Class FloorState

State of the single exclusive speaking floor.

switching is the barrier state: the previous speaker has been cleared and the floor epoch incremented, but no new speaker is permitted yet.

Attribute HANDOFF_BARRIER_TIMEOUT_S

Type: float

Class HandRequest

One outstanding raise-hand request.

Raising a hand never captures microphone audio and never grants permission to speak. Requests are ordered by the server-assigned sequence, and repeated requests from the same lease are idempotent.

Fields:

Field Type Default Description
lease_id str Lease of the requesting participant (also its display ID).
display_name str _FALLBACK_DISPLAY_NAME Safe label from trusted profile data.
sequence int Monotonic server sequence establishing queue order.
requested_at datetime Server timestamp of the first (idempotent) request.

Attribute INPUT_SAMPLE_RATE

Type: int

Class LeaseState

State of one viewer seat reservation.

Alias LiveKitRoomTokens

Re-exported from parrot.integrations.liveavatar.models.LiveKitRoomTokens.

Attribute MAX_QUEUED_PCM_BYTES

Type: int

Attribute MAX_VIEWERS

Type: int

Attribute OUTPUT_SAMPLE_RATE

Type: int

Attribute OWNER_LEASE_TTL_S

Type: int

Attribute OWNER_RENEW_S

Type: int

Attribute PENDING_TTL_S

Type: int

Class ParticipantPrincipal

Scoped authenticated principal every broadcast operation is checked against.

The existing :class:~parrot.core.ws_auth.AuthenticatedUser carries only user_id/username/email/roles — it has no tenant or agent scope. This model adds that scope, which the HTTP/WS resolver supplies from trusted server state (never from a client-supplied field).

A valid principal is necessary but not sufficient for any moderated operation: moderator and speaker authority derive from admission and grants, not from roles.

Fields:

Field Type Default Description
user_id str Stable authenticated user identifier.
tenant_id str Tenant the operation is scoped to.
agent_id str Agent the broadcast belongs to.
display_name str _FALLBACK_DISPLAY_NAME Safe, bounded label shown to other participants.
roles List[str] Roles carried by the authenticated session.

Method ParticipantPrincipal.from_authenticated_user

Build a scoped principal from an authenticated WebSocket/HTTP user.

The tenant and agent scope are supplied by the caller from trusted server-side resolution — deliberately not read off the token payload.

from_authenticated_user(user: AuthenticatedUser, *, tenant_id: str, agent_id: str) -> 'ParticipantPrincipal'

Parameter Type Default Description
user AuthenticatedUser The authenticated user from parrot.core.ws_auth.
tenant_id str Server-resolved tenant scope.
agent_id str Server-resolved agent scope.

Returns: 'ParticipantPrincipal' — A scoped :class:ParticipantPrincipal.

Attribute TERMINAL_RETENTION_S

Type: int

Attribute VIEWER_CREDENTIAL_TTL_S

Type: int

Class ViewerJoinResponse

Admission response returned only to the principal that owns the lease.

Carries the subscribe-only client_token and nothing else from :class:~parrot.integrations.liveavatar.models.LiveKitRoomTokens — the publish-capable agent_token never leaves the server.

Fields:

Field Type Default Description
public_state BroadcastPublicState The current public projection.
lease_id str The admitted lease.
livekit_url str Room WebSocket URL.
room str Room name.
client_token str Subscribe-only JWT, unique to this browser.
expires_at datetime Admission-credential expiry.

Method ViewerJoinResponse.from_tokens

Project room tokens down to the browser-safe subset.

This is the only sanctioned path from :class:LiveKitRoomTokens to a client response; it structurally drops agent_token.

from_tokens(tokens: LiveKitRoomTokens, *, public_state: BroadcastPublicState, lease_id: str, expires_at: datetime) -> 'ViewerJoinResponse'

Parameter Type Default Description
tokens LiveKitRoomTokens Freshly minted room tokens for this viewer's identity.
public_state BroadcastPublicState Current public projection.
lease_id str The admitted lease id.
expires_at datetime Admission-credential expiry.

Returns: 'ViewerJoinResponse' — A browser-safe :class:ViewerJoinResponse.

Class ViewerLease

One reserved receiving seat, held from admission until confirmed release.

A lease reserves one of :data:MAX_VIEWERS slots even before the browser connects any media, so pending admissions cannot over-admit the room. Slots are released on confirmed disconnect or removal, never on an HTTP heartbeat timeout alone.

Fields:

Field Type Default Description
lease_id str Unique lease identifier; also this participant's display ID.
principal ParticipantPrincipal The scoped principal that owns this lease.
livekit_identity str Unique LiveKit identity, independent of user_id (identity reuse would evict the previous participant).
state LeaseState LeaseState.PENDING Reservation state.
credential_expires_at Optional[datetime] None When the issued admission credential stops being usable to join. Not a revocation of an existing connection.
admission_deadline Optional[datetime] None When an unconfirmed pending seat may be reclaimed.
confirmed bool False Whether the participant's presence has been confirmed against LiveKit rather than merely asserted by the client.
admission_sequence int Server admission order; the earliest sequence wins moderator election.
last_control_heartbeat Optional[datetime] None Last authenticated control-socket heartbeat.
speaker_socket_id Optional[str] None Identifier of the single bound microphone socket, if this lease currently holds the floor.

Function public_payload

Serialise a public state for the wire in JSON-safe form.

public_payload(state: BroadcastPublicState) -> dict[str, Any]

Parameter Type Default Description
state BroadcastPublicState The projection to serialise.

Returns: dict[str, Any] — A JSON-serialisable dict (enums as values, datetimes as ISO strings).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally