Skip to content

Commit d09de8d

Browse files
committed
fix(websockets): restore optional message param on control send_ methods
Control messages (keep-alive, close-stream, finalize, flush, clear, close) carry no meaningful payload — the type field is the whole message. Making the message param optional with a typed default means users can call e.g. send_keep_alive() without constructing the type themselves. Payload-carrying methods (send_text, send_media, send_settings, etc.) remain required. This restores behaviour lost in the last regen and fixes a breaking change shipped in a minor patch.
1 parent 18568bb commit d09de8d

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

.fernignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ src/deepgram/client.py
88
# - construct_type keyword args fix (generator uses positional, function requires keyword-only)
99
# - except Exception broad catch (supports custom transports, generator narrows to WebSocketException)
1010
# - _sanitize_numeric_types in agent socket client (float→int for API)
11+
# - optional message param on control send_ methods (send_keep_alive, send_close_stream, etc.)
12+
# so users don't need to instantiate the type themselves for no-payload control messages
1113
# [temporarily frozen — generator bugs in construct_type call convention and exception handling]
1214
src/deepgram/agent/v1/socket_client.py
1315
src/deepgram/listen/v1/socket_client.py

src/deepgram/agent/v1/socket_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ async def send_function_call_response(self, message: AgentV1SendFunctionCallResp
159159
"""
160160
await self._send_model(message)
161161

162-
async def send_keep_alive(self, message: AgentV1KeepAlive) -> None:
162+
async def send_keep_alive(self, message: typing.Optional[AgentV1KeepAlive] = None) -> None:
163163
"""
164164
Send a message to the websocket connection.
165165
The message will be sent as a AgentV1KeepAlive.
166166
"""
167-
await self._send_model(message)
167+
await self._send_model(message or AgentV1KeepAlive())
168168

169169
async def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
170170
"""
@@ -292,12 +292,12 @@ def send_function_call_response(self, message: AgentV1SendFunctionCallResponse)
292292
"""
293293
self._send_model(message)
294294

295-
def send_keep_alive(self, message: AgentV1KeepAlive) -> None:
295+
def send_keep_alive(self, message: typing.Optional[AgentV1KeepAlive] = None) -> None:
296296
"""
297297
Send a message to the websocket connection.
298298
The message will be sent as a AgentV1KeepAlive.
299299
"""
300-
self._send_model(message)
300+
self._send_model(message or AgentV1KeepAlive())
301301

302302
def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
303303
"""

src/deepgram/listen/v1/socket_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,26 @@ async def send_media(self, message: bytes) -> None:
8181
"""
8282
await self._send(message)
8383

84-
async def send_finalize(self, message: ListenV1Finalize) -> None:
84+
async def send_finalize(self, message: typing.Optional[ListenV1Finalize] = None) -> None:
8585
"""
8686
Send a message to the websocket connection.
8787
The message will be sent as a ListenV1Finalize.
8888
"""
89-
await self._send_model(message)
89+
await self._send_model(message or ListenV1Finalize(type="Finalize"))
9090

91-
async def send_close_stream(self, message: ListenV1CloseStream) -> None:
91+
async def send_close_stream(self, message: typing.Optional[ListenV1CloseStream] = None) -> None:
9292
"""
9393
Send a message to the websocket connection.
9494
The message will be sent as a ListenV1CloseStream.
9595
"""
96-
await self._send_model(message)
96+
await self._send_model(message or ListenV1CloseStream(type="CloseStream"))
9797

98-
async def send_keep_alive(self, message: ListenV1KeepAlive) -> None:
98+
async def send_keep_alive(self, message: typing.Optional[ListenV1KeepAlive] = None) -> None:
9999
"""
100100
Send a message to the websocket connection.
101101
The message will be sent as a ListenV1KeepAlive.
102102
"""
103-
await self._send_model(message)
103+
await self._send_model(message or ListenV1KeepAlive(type="KeepAlive"))
104104

105105
async def recv(self) -> V1SocketClientResponse:
106106
"""
@@ -186,26 +186,26 @@ def send_media(self, message: bytes) -> None:
186186
"""
187187
self._send(message)
188188

189-
def send_finalize(self, message: ListenV1Finalize) -> None:
189+
def send_finalize(self, message: typing.Optional[ListenV1Finalize] = None) -> None:
190190
"""
191191
Send a message to the websocket connection.
192192
The message will be sent as a ListenV1Finalize.
193193
"""
194-
self._send_model(message)
194+
self._send_model(message or ListenV1Finalize(type="Finalize"))
195195

196-
def send_close_stream(self, message: ListenV1CloseStream) -> None:
196+
def send_close_stream(self, message: typing.Optional[ListenV1CloseStream] = None) -> None:
197197
"""
198198
Send a message to the websocket connection.
199199
The message will be sent as a ListenV1CloseStream.
200200
"""
201-
self._send_model(message)
201+
self._send_model(message or ListenV1CloseStream(type="CloseStream"))
202202

203-
def send_keep_alive(self, message: ListenV1KeepAlive) -> None:
203+
def send_keep_alive(self, message: typing.Optional[ListenV1KeepAlive] = None) -> None:
204204
"""
205205
Send a message to the websocket connection.
206206
The message will be sent as a ListenV1KeepAlive.
207207
"""
208-
self._send_model(message)
208+
self._send_model(message or ListenV1KeepAlive(type="KeepAlive"))
209209

210210
def recv(self) -> V1SocketClientResponse:
211211
"""

src/deepgram/listen/v2/socket_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ async def send_media(self, message: bytes) -> None:
7878
"""
7979
await self._send(message)
8080

81-
async def send_close_stream(self, message: ListenV2CloseStream) -> None:
81+
async def send_close_stream(self, message: typing.Optional[ListenV2CloseStream] = None) -> None:
8282
"""
8383
Send a message to the websocket connection.
8484
The message will be sent as a ListenV2CloseStream.
8585
"""
86-
await self._send_model(message)
86+
await self._send_model(message or ListenV2CloseStream(type="CloseStream"))
8787

8888
async def recv(self) -> V2SocketClientResponse:
8989
"""
@@ -169,12 +169,12 @@ def send_media(self, message: bytes) -> None:
169169
"""
170170
self._send(message)
171171

172-
def send_close_stream(self, message: ListenV2CloseStream) -> None:
172+
def send_close_stream(self, message: typing.Optional[ListenV2CloseStream] = None) -> None:
173173
"""
174174
Send a message to the websocket connection.
175175
The message will be sent as a ListenV2CloseStream.
176176
"""
177-
self._send_model(message)
177+
self._send_model(message or ListenV2CloseStream(type="CloseStream"))
178178

179179
def recv(self) -> V2SocketClientResponse:
180180
"""

src/deepgram/speak/v1/socket_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,26 @@ async def send_text(self, message: SpeakV1Text) -> None:
8282
"""
8383
await self._send_model(message)
8484

85-
async def send_flush(self, message: SpeakV1Flush) -> None:
85+
async def send_flush(self, message: typing.Optional[SpeakV1Flush] = None) -> None:
8686
"""
8787
Send a message to the websocket connection.
8888
The message will be sent as a SpeakV1Flush.
8989
"""
90-
await self._send_model(message)
90+
await self._send_model(message or SpeakV1Flush(type="Flush"))
9191

92-
async def send_clear(self, message: SpeakV1Clear) -> None:
92+
async def send_clear(self, message: typing.Optional[SpeakV1Clear] = None) -> None:
9393
"""
9494
Send a message to the websocket connection.
9595
The message will be sent as a SpeakV1Clear.
9696
"""
97-
await self._send_model(message)
97+
await self._send_model(message or SpeakV1Clear(type="Clear"))
9898

99-
async def send_close(self, message: SpeakV1Close) -> None:
99+
async def send_close(self, message: typing.Optional[SpeakV1Close] = None) -> None:
100100
"""
101101
Send a message to the websocket connection.
102102
The message will be sent as a SpeakV1Close.
103103
"""
104-
await self._send_model(message)
104+
await self._send_model(message or SpeakV1Close(type="Close"))
105105

106106
async def recv(self) -> V1SocketClientResponse:
107107
"""
@@ -187,26 +187,26 @@ def send_text(self, message: SpeakV1Text) -> None:
187187
"""
188188
self._send_model(message)
189189

190-
def send_flush(self, message: SpeakV1Flush) -> None:
190+
def send_flush(self, message: typing.Optional[SpeakV1Flush] = None) -> None:
191191
"""
192192
Send a message to the websocket connection.
193193
The message will be sent as a SpeakV1Flush.
194194
"""
195-
self._send_model(message)
195+
self._send_model(message or SpeakV1Flush(type="Flush"))
196196

197-
def send_clear(self, message: SpeakV1Clear) -> None:
197+
def send_clear(self, message: typing.Optional[SpeakV1Clear] = None) -> None:
198198
"""
199199
Send a message to the websocket connection.
200200
The message will be sent as a SpeakV1Clear.
201201
"""
202-
self._send_model(message)
202+
self._send_model(message or SpeakV1Clear(type="Clear"))
203203

204-
def send_close(self, message: SpeakV1Close) -> None:
204+
def send_close(self, message: typing.Optional[SpeakV1Close] = None) -> None:
205205
"""
206206
Send a message to the websocket connection.
207207
The message will be sent as a SpeakV1Close.
208208
"""
209-
self._send_model(message)
209+
self._send_model(message or SpeakV1Close(type="Close"))
210210

211211
def recv(self) -> V1SocketClientResponse:
212212
"""

0 commit comments

Comments
 (0)