Skip to content

fix: add History message type support and prevent Content-Length header in WebSocket upgrade#396

Open
naomi-deepgram wants to merge 1 commit intomainfrom
fix/header
Open

fix: add History message type support and prevent Content-Length header in WebSocket upgrade#396
naomi-deepgram wants to merge 1 commit intomainfrom
fix/header

Conversation

@naomi-deepgram
Copy link
Copy Markdown

Summary

  • History message type: The Voice Agent API returns a "type": "History" server message that was not handled by the SDK — it would silently fall through to the Unhandled event. This PR adds full support so subscribers can receive and act on History events.
  • Content-Length header: On .NET 5+, WebSocket upgrade requests now use SocketsHttpHandler via HttpMessageInvoker, which does not add a Content-Length: 0 header to the upgrade request. This header violates the WebSocket protocol and causes failures with strict proxies such as Azure API Management (APIM).

Changes

History message type ("type": "History")

  • Deepgram/Models/Agent/v2/WebSocket/HistoryResponse.cs — New model with Role, Content, and FunctionCalls fields; includes a HistoryFunctionCall record
  • Deepgram/Models/Agent/v2/WebSocket/AgentType.cs — Added History to the AgentType enum and History = "History" to AgentClientTypes
  • Deepgram/Clients/Agent/v2/Websocket/Client.cs — Added _historyReceived event, Subscribe(EventHandler<HistoryResponse>), and case AgentType.History: in ProcessTextMessage
  • Deepgram/Clients/Interfaces/v2/IAgentWebSocketClient.cs — Added Subscribe(EventHandler<HistoryResponse>) to the interface

Content-Length fix

  • Deepgram/Abstractions/v2/AbstractWebSocketClient.cs — On NET5_0_OR_GREATER, ConnectAsync is called with an HttpMessageInvoker wrapping SocketsHttpHandler instead of the default handler, preventing Content-Length: 0 from being included in the WebSocket upgrade request

Test plan

  • 7 new unit tests added to AgentClientTests.cs covering HistoryResponse serialisation, HistoryFunctionCall field mapping, null-field omission, enum presence, and the AgentClientTypes constant
  • Full test suite passes (170/170)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant