22
33import json
44import typing
5+ from json .decoder import JSONDecodeError
56
7+ import websockets
68import websockets .sync .connection as websockets_sync_connection
79from ...core .events import EventEmitterMixin , EventType
8- from ...core .pydantic_utilities import parse_obj_as
10+ from ...core .unchecked_base_model import construct_type
911from .types .agent_v1agent_audio_done import AgentV1AgentAudioDone
1012from .types .agent_v1agent_started_speaking import AgentV1AgentStartedSpeaking
1113from .types .agent_v1agent_thinking import AgentV1AgentThinking
@@ -82,7 +84,7 @@ async def __aiter__(self):
8284 if isinstance (message , bytes ):
8385 yield message
8486 else :
85- yield parse_obj_as ( V1SocketClientResponse , json .loads (message )) # type: ignore
87+ yield construct_type ( type_ = V1SocketClientResponse , object_ = json .loads (message )) # type: ignore
8688
8789 async def start_listening (self ):
8890 """
@@ -101,7 +103,7 @@ async def start_listening(self):
101103 parsed = raw_message
102104 else :
103105 json_data = json .loads (raw_message )
104- parsed = parse_obj_as ( V1SocketClientResponse , json_data ) # type: ignore
106+ parsed = construct_type ( type_ = V1SocketClientResponse , object_ = json_data ) # type: ignore
105107 await self ._emit_async (EventType .MESSAGE , parsed )
106108 except Exception as exc :
107109 await self ._emit_async (EventType .ERROR , exc )
@@ -172,7 +174,7 @@ async def recv(self) -> V1SocketClientResponse:
172174 if isinstance (data , bytes ):
173175 return data # type: ignore
174176 json_data = json .loads (data )
175- return parse_obj_as ( V1SocketClientResponse , json_data ) # type: ignore
177+ return construct_type ( type_ = V1SocketClientResponse , object_ = json_data ) # type: ignore
176178
177179 async def _send (self , data : typing .Any ) -> None :
178180 """
@@ -199,7 +201,7 @@ def __iter__(self):
199201 if isinstance (message , bytes ):
200202 yield message
201203 else :
202- yield parse_obj_as ( V1SocketClientResponse , json .loads (message )) # type: ignore
204+ yield construct_type ( type_ = V1SocketClientResponse , object_ = json .loads (message )) # type: ignore
203205
204206 def start_listening (self ):
205207 """
@@ -218,7 +220,7 @@ def start_listening(self):
218220 parsed = raw_message
219221 else :
220222 json_data = json .loads (raw_message )
221- parsed = parse_obj_as ( V1SocketClientResponse , json_data ) # type: ignore
223+ parsed = construct_type ( type_ = V1SocketClientResponse , object_ = json_data ) # type: ignore
222224 self ._emit (EventType .MESSAGE , parsed )
223225 except Exception as exc :
224226 self ._emit (EventType .ERROR , exc )
@@ -289,7 +291,7 @@ def recv(self) -> V1SocketClientResponse:
289291 if isinstance (data , bytes ):
290292 return data # type: ignore
291293 json_data = json .loads (data )
292- return parse_obj_as ( V1SocketClientResponse , json_data ) # type: ignore
294+ return construct_type ( type_ = V1SocketClientResponse , object_ = json_data ) # type: ignore
293295
294296 def _send (self , data : typing .Any ) -> None :
295297 """
0 commit comments