refactor: send raw typed payloads over chat WebSockets#24148
Draft
DanielleMaywood wants to merge 2 commits intomainfrom
Draft
refactor: send raw typed payloads over chat WebSockets#24148DanielleMaywood wants to merge 2 commits intomainfrom
DanielleMaywood wants to merge 2 commits intomainfrom
Conversation
Replace the legacy ServerSentEvent envelope with direct JSON encoding for watchChats and streamChat. These endpoints inherited the SSE envelope format from the pre-WebSocket era but never needed it — the newer WebSocket endpoints (containers, notifications, logs) already send raw typed payloads. Backend: switch from OneWayWebSocketEventSender to websocket.Accept + json.NewEncoder (matching watchAgentContainers). Move ChatWatchEvent type to codersdk so it gets codegen'd to TypeScript. Frontend: watchChat returns ChatStreamEvent[], watchChats returns ChatWatchEvent. Remove isChatListSSEEvent, isChatStreamEvent, toChatStreamEvents type guards and asString/asNumber defensive wrappers from useChatStore — the typed stream data makes them redundant.
The streamChat WebSocket now sends raw ChatStreamEvent[] payloads
instead of SSE-wrapped envelopes. Update story mocks to match by
replacing wrapSSE({event}) with JSON.stringify([event]) and deleting
the now-unused wrapSSE helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
watchChatsandstreamChatinherited theServerSentEventenvelope from the pre-WebSocket SSE era. The newer WebSocket endpoints (watchAgentContainers,watchInboxNotifications, agent logs) already send raw typed payloads — these two were the last holdouts.Backend: replace
OneWayWebSocketEventSenderwithwebsocket.Accept+json.NewEncoderfor both endpoints. MoveChatWatchEventtocodersdkso it gets codegen'd. Frontend consumers receive typed data directly instead of unwrapping anunknownenvelope.This removes
isChatListSSEEvent,isChatStreamEvent,isChatStreamEventArray,toChatStreamEvents, and theasString/asNumberwrappers innormalizeChatDetailError/normalizeRetryState— all of which existed solely because the SSE envelope erased type information.Decision log
watchChatsandstreamChatonly —watchWorkspaceandwatchAgentMetadatastill use the SSE envelope (different consumers, separate cleanup)ChatWatchEventmoved fromcoderd/pubsubtocodersdkfor codegen; pubsub aliases removed, all consumers referencecodersdkdirectlystreamChatsubscribes beforewebsocket.Acceptso failures return proper HTTP errors instead of WebSocket error framesChatEventchannel helper andHandleChatEventremain incoderd/pubsub(server-internal plumbing)