feat(realtime): port JS SDK realtime features#26
Merged
AdirAmsalem merged 1 commit intomainfrom Feb 11, 2026
Merged
Conversation
ee1149b to
0fdfbe0
Compare
Port missing realtime client features from the JS SDK to the Python SDK, closing all identified gaps from the cross-SDK analysis. Also fixes all P1/P2 bugs found through external reviews and self-review. New features: - Subscribe mode (SubscribeClient, token encode/decode) - Server-assigned session_id and subscribe_token - Event buffer (deferred flush matching JS setTimeout(0)) - Generating/reconnecting connection states - Auto-reconnect with tenacity (generation counter, CancelledError handling) - set_image(None) to clear, prompt/enhance options on set_image - Prompt.enrich renamed to Prompt.enhance (backward compat in set_prompt) Bug fixes (P1): - connect() retry no longer leaks connection objects - _reconnect() resets _is_reconnecting via finally (CancelledError safe) - WS close transitions state to disconnected (triggers reconnect) - ICE restart preserves tracks, transceivers, and icecandidate handler Bug fixes (P2): - connect() classmethod cleans up manager on post-connect failure - Callback dispatch iterates list copy (safe self-removal) - cleanup() nulls _connection for cleaner post-disconnect errors - _image_to_base64 validates unrecognized strings (raises InvalidInputError) - Subscribe tokens use URL-safe base64
0fdfbe0 to
55e8b27
Compare
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.
Summary
New Features
SubscribeClientwith URL-safe token encode/decode, event buffer, on/off handlerssession_idandsubscribe_tokenproperties populated viaon_session_idcallbackcall_soon()(matches JSsetTimeout(0)) — handlers registered afterconnect()still receive events emitted during connectgeneratingandreconnectingstates, stickygeneratingthat only transitions on disconnectCancelledErrorshort-circuit, stale reconnect detectionset_imageimprovements: AcceptsNoneto clear image, optionalprompt/enhanceparameters, works for all models (not just avatar-live)enrich→enhancerename:Prompt.enhancefield;set_prompt(enrich=...)backward compat with deprecation warningFiles Changed
decart/realtime/client.py— subscribe classmethod, event buffer, session_id, set_image/set_prompt improvementsdecart/realtime/subscribe.py— NEW: SubscribeClient, token encode/decodedecart/realtime/webrtc_manager.py— auto-reconnect, generation counter, state management, P1/P2 fixesdecart/realtime/webrtc_connection.py— session_id callback, generating state, ICE restart fix, WS close fixdecart/realtime/messages.py— GenerationStartedMessagedecart/realtime/types.py— expanded ConnectionState literaldecart/types.py—Prompt.enrich→Prompt.enhancedecart/__init__.py,decart/realtime/__init__.py— subscribe exportsexamples/realtime_file.py,examples/realtime_synthetic.py— enhance renametests/test_realtime_unit.py— 24 tests (session_id, buffer, set_image null/prompt/enhance)Testing