From 81a4151c9a4f8a9a5c4a8d41d298d44137a7da91 Mon Sep 17 00:00:00 2001 From: sebvanleuven Date: Thu, 19 Feb 2026 16:07:51 +0000 Subject: [PATCH 1/5] 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/5] 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 ] From 5f3471d2f651bacc30e7a8c60b50f8ffd2884248 Mon Sep 17 00:00:00 2001 From: sebvanleuven Date: Thu, 19 Feb 2026 16:21:54 +0000 Subject: [PATCH 3/5] remove whiteline --- src/anam/_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/anam/_api.py b/src/anam/_api.py index 7907049..c3c05ba 100644 --- a/src/anam/_api.py +++ b/src/anam/_api.py @@ -59,7 +59,6 @@ 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 = { From d2d951418f133de61ea9db97be1d9147c13a5e96 Mon Sep 17 00:00:00 2001 From: sebvanleuven <102162250+sebvanleuven@users.noreply.github.com> Date: Thu, 19 Feb 2026 16:45:58 +0000 Subject: [PATCH 4/5] Update src/anam/types.py Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- src/anam/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anam/types.py b/src/anam/types.py index 022d4b1..cda913c 100644 --- a/src/anam/types.py +++ b/src/anam/types.py @@ -275,5 +275,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=_reorder_ice_server_urls(client_config.get("iceServers", [])), + ice_servers=_reorder_ice_server_urls(client_config.get("iceServers") or []), ) From a3baa31a765fa68b21bf9b108e8555172fb40559 Mon Sep 17 00:00:00 2001 From: sebvanleuven <102162250+sebvanleuven@users.noreply.github.com> Date: Thu, 19 Feb 2026 16:48:07 +0000 Subject: [PATCH 5/5] stable sort, maintain original order Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- src/anam/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anam/types.py b/src/anam/types.py index cda913c..47c8630 100644 --- a/src/anam/types.py +++ b/src/anam/types.py @@ -235,7 +235,7 @@ def _reorder_ice_server_urls(ice_servers: list[dict[str, Any]]) -> list[dict[str """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 0 if str(u).lower().startswith("turns:") else 1 return [ {