From 81a4151c9a4f8a9a5c4a8d41d298d44137a7da91 Mon Sep 17 00:00:00 2001 From: sebvanleuven Date: Thu, 19 Feb 2026 16:07:51 +0000 Subject: [PATCH 1/2] prioritzing turns ice_servers --- src/anam/types.py | 12 +++++++++++- uv.lock | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/anam/types.py b/src/anam/types.py index 6ab936d..67eb51b 100644 --- a/src/anam/types.py +++ b/src/anam/types.py @@ -231,6 +231,16 @@ class AgentAudioInputPayload: sequence_number: int +def _reorder_ice_server_urls(ice_servers: list[dict[str, Any]]) -> list[dict[str, Any]]: + """Reorder URLs to prioritize TURNS (TURN over TLS) as aiortc only uses the first TURN URI.""" + def _turns_first(u): + return (0 if str(u).lower().startswith("turns:") else 1, u) + return [ + {**s, "urls": sorted([s["urls"]] if isinstance(s.get("urls"), str) else s.get("urls", []), key=_turns_first)} + for s in ice_servers + ] + + @dataclass class SessionInfo: """Information about an active streaming session. @@ -257,5 +267,5 @@ def from_api_response(cls, data: dict[str, Any]) -> "SessionInfo": signalling_endpoint=data["signallingEndpoint"], heartbeat_interval_seconds=client_config.get("heartbeatIntervalSeconds", 5), max_reconnection_attempts=client_config.get("maxWsReconnectionAttempts", 5), - ice_servers=client_config.get("iceServers", []), + ice_servers=_reorder_ice_server_urls(client_config.get("iceServers", [])), ) diff --git a/uv.lock b/uv.lock index 1200a81..89f9fe8 100644 --- a/uv.lock +++ b/uv.lock @@ -188,7 +188,7 @@ wheels = [ [[package]] name = "anam" -version = "0.2.0" +version = "0.3.0" source = { editable = "." } dependencies = [ { name = "aiohttp" }, From 6f159cf5cee9acc87b529fe5b227333a3286d37f Mon Sep 17 00:00:00 2001 From: sebvanleuven Date: Thu, 19 Feb 2026 16:20:41 +0000 Subject: [PATCH 2/2] lint --- src/anam/_api.py | 1 + src/anam/types.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/anam/_api.py b/src/anam/_api.py index c3c05ba..7907049 100644 --- a/src/anam/_api.py +++ b/src/anam/_api.py @@ -59,6 +59,7 @@ async def get_session_token( "Content-Type": "application/json", "Authorization": f"Bearer {self._api_key}", } + # Use custom client_label if provided, otherwise default to 'python-sdk' client_label = self._options.client_label or "python-sdk" body = { diff --git a/src/anam/types.py b/src/anam/types.py index 67eb51b..022d4b1 100644 --- a/src/anam/types.py +++ b/src/anam/types.py @@ -233,10 +233,18 @@ class AgentAudioInputPayload: def _reorder_ice_server_urls(ice_servers: list[dict[str, Any]]) -> list[dict[str, Any]]: """Reorder URLs to prioritize TURNS (TURN over TLS) as aiortc only uses the first TURN URI.""" + def _turns_first(u): return (0 if str(u).lower().startswith("turns:") else 1, u) + return [ - {**s, "urls": sorted([s["urls"]] if isinstance(s.get("urls"), str) else s.get("urls", []), key=_turns_first)} + { + **s, + "urls": sorted( + [s["urls"]] if isinstance(s.get("urls"), str) else s.get("urls", []), + key=_turns_first, + ), + } for s in ice_servers ]