feat(rust): add WebSocket (WSS) support with typed channel clients#12429
Open
iamnamananand996 wants to merge 2 commits intomainfrom
Open
feat(rust): add WebSocket (WSS) support with typed channel clients#12429iamnamananand996 wants to merge 2 commits intomainfrom
iamnamananand996 wants to merge 2 commits intomainfrom
Conversation
Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
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.
Description
Refs #12338
POC for WebSocket/WSS support in the Rust SDK generator. Adds a
tokio-tungstenite-based runtime and a code generator that readsir.websocketChannelsto emit typed per-channel Rust client structs with send/receive methods.Link to Devin run: https://app.devin.ai/sessions/9a2809fa93d24d13be0c3c338e042e91
Requested by: @iamnamananand996
Changes Made
Runtime (
websocket.rs— new as-is file)WebSocketClientstruct with asyncconnect,send_json,send_raw,closeWebSocketOptions(headers, query params, reconnection config)WebSocketStateenum andparse_websocket_message<T>helper#[cfg(feature = "websocket")], matching the SSE patternGenerator (
WebSocketChannelGenerator.ts— new)ir.websocketChannelsand emits one Rust file per channel undersrc/api/websocket/ServerMessageenum (serde-tagged), client struct,connect, per-messagesend_*,recv, andclosemethodsmod.rswith re-exportsIntegration (modified files)
AbstractRustGeneratorContext.ts—hasWebSocketChannels(), optional deps (tokio-tungstenite,urlencoding),websocketCargo featureSdkGeneratorCli.ts— wires generator into pipeline, addswebsocketmodule to API mod fileSdkGeneratorContext.ts— conditionally includeswebsocket.rsin core as-is filesErrorGenerator.ts— addsWebSocketErrorvariantAsIs.ts/mod.rs— registers and exports the new as-is fileThis is a proof-of-concept — the following items are intentionally incomplete or need scrutiny:
read_loopis stubbed: Thereadhalf of the split WebSocket stream is never stored or consumed.incoming_rxwill never yield messages. The receive path is non-functional — this needs a real implementation before shipping.No seed fixtures: The generated Rust code has not been validated to compile or run against a real IR with WebSocket channels. Recommend adding a WebSocket test case to the
exhaustiveseed fixture.String-based code generation:
WebSocketChannelGeneratorbuilds Rust via string templates. Typos or incorrect type references won't be caught until Rust compile time. Needs validation.Path expression building:
buildPathExpressionuses IR property names directly in format strings — verify these match the snake_case parameter names in the generatedconnect()method.Channel wiring confusion: Two unbounded channels are created in
connect()but only one is used. Theoutgoing_txis stored but never consumed. Thereadhalf fromws_stream.split()is also unused.Missing explicit
httpcrate dependency:websocket.rsreferenceshttp::uri::InvalidUributhttpisn't explicitly listed (may come transitively viatokio-tungstenite).Human Review Checklist
readhalf of split stream and channel wiring make sense before shippinghttpcrate is available transitively or add explicit depbuildPathExpressionoutput against generatedconnect()parameter namesUpdates since last revision
ErrorGeneratortest snapshots to include the newWebSocketErrorvariant (all tests now pass)Testing
pnpm run check)WebSocketErrorvariantNext steps before production-ready:
read_loopto consume WebSocket messages