Repository navigation
Session api use - #101
Open
MaxHeimbrock wants to merge 16 commits into
Open
Session api use#101MaxHeimbrock wants to merge 16 commits into
MaxHeimbrock wants to merge 16 commits into
Conversation
MaxHeimbrock
force-pushed
the
max/session-api-use
branch
2 times, most recently
from
November 3, 2026 15:59
b9b02ec to
1a1771d
Compare
MaxHeimbrock
added a commit
to livekit/rust-sdks
that referenced
this pull request
Dec 3, 2026
New `livekit-session` crate with `Session`. Similar to the other session APIs in https://docs.livekit.io/frontends/build/sessions/. Look at the [example](https://github.com/livekit/rust-sdks/blob/219b401e32f1aaaf0df01beb5860c4901c12cc2d/examples/session/src/main.rs) or my PR in the [Rust dev client](livekit-examples/rust-dev-client#101) for usage. Disclaimer: I mostly used Claude to write this. I am still not a Rust expert. I tried to find wholes as much as possible, look at the developer facing APIs and test it myself through the Rust dev client. Decisions I took: The platform audio is activated for the user by default, opt out via the session options (`with_platform_audio = false`). If you pass a cached token source, you will run into issues reusing the same token. This is a footgun we accept, since invalidating tokens after use is not easy to expose in the current design. Also fixed token sources are allowed, which cause the same problem. We don't plan to expose this Rust session via FFI for now. Using the actor pattern according to [AGENT.md](https://github.com/livekit/rust-sdks/blob/main/AGENTS.md?plain=1#L36). ## Public API Every enum is `#[non_exhaustive]`, and so are `SessionState` and `Message`. `SessionOptions` and `Agent` have private fields. A `Message` for `restore_messages` is built with `Message::new`. | Item | Kind | Purpose | | --- | --- | --- | | `Session` | struct, `Clone`, `Debug` | A conversation with an agent. Handles share one session; dropping the last one closes the room | | `Session::new(token_source, options)` | constructor | Credentials from a `TokenSourceFixed`, e.g. `literal` | | `Session::with_fetch_options(token_source, fetch_options, options)` | constructor | Credentials from a `TokenSourceConfigurable` with full `TokenSourceFetchOptions` | | `Session::with_agent(token_source, agent_name, options)` | constructor | Shorthand for `with_fetch_options` that dispatches `agent_name` | | `Session::start(&self) -> Result<(), SessionStartError>` | async | Fetches credentials, connects, and publishes the platform microphone; resolves at room connect, not agent connect | | `Session::end(&self)` | async | Closes the room, releasing the audio devices, or cancels a pending `start`; idempotent | | `Session::state(&self) -> watch::Receiver<SessionState>` | method | Current state (`borrow`) and changes (`changed`, `wait_for`). The agent and its tracks are read from here | | `Session::room(&self) -> Option<Arc<Room>>` | method | The room while connected or reconnecting, for what the session does not do itself, e.g. publishing a camera | | `Session::send_text(&self, text: &str) -> Result<Message, MessageSendError>` | async | Sends chat on `lk.chat` and adds it to the feed once sent | | `Session::messages(&self) -> Vec<Message>` | method | The feed, ordered by `seq` | | `Session::restore_messages(&self, messages: impl IntoIterator<Item = Message>)` | method | Replaces the feed in the given order, renumbered from zero. Takes the messages by value | | `Session::subscribe(&self) -> mpsc::UnboundedReceiver<SessionEvent>` | method | Changes to the message feed | | `SessionOptions` | struct, `Default` | Private fields, set through the builders `with_agent_connect_timeout` (20 s default), `with_room_options`, and `with_platform_audio` (`true` by default: the microphone is published and the agent's audio played) | | `SessionState { connection, agent }` | struct, `Clone`, `Default` | Snapshot published through `state()`. Not `Copy`: it holds the agent's tracks, so a kept value keeps them alive | | `SessionConnectionState` | enum, `Copy` | `Disconnected`, `Connecting`, `Connected`, `Reconnecting`; `is_connected()` | | `AgentState` | enum, `Clone` | `Disconnected`, `Connecting`, `Joined(Agent)`, `Failed(AgentFailure)`; `is_connected()`, `is_pending()`, `is_finished()`, and `identity()`, `activity()`, `audio_track()`, `avatar_video_track()` to read the agent whichever variant holds it | | `Agent` | struct, `Clone` | Snapshot of the agent in the room: `identity()`, `activity()`, `audio_track()` (its microphone, once subscribed), `avatar_video_track()` (the avatar worker's camera, once subscribed). Equality compares identity, activity and track `sid`s | | `AgentActivity` | enum, `Copy` | `Initializing`, `Idle`, `Listening`, `Thinking`, `Speaking`, `Unknown`; from the `lk.agent.state` attribute | | `AgentFailure` | enum | `Timeout { agent: Option<Agent> }` (the slow agent, if one is in the room), `Left` | | `SessionEvent` | enum | `MessageUpserted(Message)`, `MessagesRestored` | | `Message { id, seq, timestamp, origin, participant_identity, text, is_final }` | struct | One feed entry; identified by `id` + `participant_identity`. `Message::new(id, origin, participant_identity, text)` creates a final message timestamped now; builders `with_timestamp`, `with_is_final` | | `MessageOrigin` | enum, `Copy` | `AgentTranscript`, `UserTranscript`, `UserInput`, `Chat` | | `SessionStartError` | error | `AlreadyStarted`, `Cancelled`, `Token(TokenSourceError)`, `Connect(RoomError)`, `PlatformAudio(AudioError)` (no audio devices), `Microphone(RoomError)` (the microphone failed to publish; the room is closed again) | | `MessageSendError` | error | `NotConnected`, `Stream(StreamError)` | ## Commits Group 1. Crate scaffolding 1. [feat(session)](28e17ec): add the livekit-session crate manifest and module layout 2. [chore(workspace)](2bf9899): register livekit-session with cargo, knope and CODEOWNERS 3. [IMPORTANT(session)](18b7769): add the agent interop constants 4. [feat(session)](effed20): add the start and send error types Group 2. Message feed 5. [feat(session)](91e9cdb): add the Message model and the MessageStore feed 6. [test(session)](73e9c09): cover MessageStore ordering, upsert and restore 7. [IMPORTANT(session)](0f1a2a7): aggregate lk.transcription streams into transcript messages 8. [test(session)](049a6eb): cover transcript aggregation Group 3. Agent projection 9. [feat(session)](cad3aa8): add AgentState and AgentFailure 10. [feat(session)](162e58b): find the agent, its avatar worker and their tracks 11. [IMPORTANT(session)](caf3e2d): project AgentState with timeout and leave detection 12. [test(session)](4bb9627): cover agent discovery and state parsing 13. [test(session)](aa0e634): cover agent projection across reconnects, leaves and timeouts Group 4. Session runtime 14. [feat(session)](4d0e0b8): add the Dispatcher fan-out 15. [test(session)](44d44f2): cover Dispatcher pruning 16. [feat(session)](3621307): add the state shared between a session and its actor 17. [feat(session)](ba625e0): add SessionOptions, SessionState and SessionEvent 18. [feat(session)](d9419eb): add the Session handle and its constructors 19. [IMPORTANT(session)](cdac605): add the session actor and its agent-state projection 20. [IMPORTANT(session)](d9ecbe8): read chat and transcript streams in the actor 21. [IMPORTANT(session)](6b2e2e7): start and end a session 22. [feat(session)](6e8f528): expose state, room, agent tracks and the message feed 23. [test(session)](7e8998d): assert with_agent fetches with the agent name Group 5. End-to-end tests 24. [test(session)](5d951ab): add the e2e harness with a stand-in agent 25. [test(session)](f42b46d): e2e agent state follows joins, leaves and reconnects 26. [test(session)](f97c0ac): e2e agent connect timeout 27. [test(session)](321547b): e2e start publishes the platform microphone 28. [test(session)](4b35c45): e2e the feed merges chat and transcripts 29. [test(session)](4f162e0): e2e agent audio and avatar video tracks 30. [test(session)](737c264): e2e restart after a disconnect and a rejected token 31. [test(session)](d932c7c): e2e end and drop cancel a pending start 32. [test(session)](336d8f3): e2e a start cancelled during the handshake leaves nothing behind 33. [test(session)](c65e5dd): e2e memory lifecycle Group 6. Docs, example and changeset 34. [docs(session)](7da30a9): add the crate README 35. [feat(example)](686b883): add the session voice and text chat example 36. [chore(session)](5f9d744): add the changeset --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- StatusBar takes the room plus an optional detail badge and reconnect hint, and shows "Reconnecting..." during a reconnect; AgentStatusBar is gone and ConnectionButton is private again - Auth replaces AgentAuth; LocalTokenSource names its room or picks a fresh one per fetch, so the connect form builds one enum for both modes - Both settings structs carry e2ee_key: Option<String>, turned into E2eeOptions by one e2ee_options helper used by both services - Remove AgentEvent::Messages, RoomNameField, the launcher's unused minimum size and the push_id around each chat message; for_agent uses struct update syntax - Document the agent -> room widget reuse, the RoomContext rule and why TrackCmd::apply must run on the Tokio runtime - Agent dispatch on room joins is intentional: README feature line, tooltip, and agent_metadata trimmed like agent_name Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
MaxHeimbrock
force-pushed
the
max/session-api-use
branch
from
December 3, 2026 12:03
71f3abc to
0a0080c
Compare
MaxHeimbrock
marked this pull request as ready for review
December 3, 2026 12:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces an agent window to use the new Rust session api developed in livekit/rust-sdks#1593
CI is red because I still point to my local rust sdk folder.