Add reusable Rust SDK relay helpers#134
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds raw WebSocket event subscription, stable event normalization types and functions, identity comparison helpers, DM participant caching, idempotent channel/agent creation helpers, and expands the public API. Includes documentation and parity tests. ChangesRust SDK event normalization and client enhancements
Sequence Diagram(s)sequenceDiagram
participant Client
participant WsClient
participant RawBroadcast as Raw Events
participant Normalizer
participant TypedBroadcast as Typed Events
Client->>WsClient: subscribe_raw_events()
WsClient-->>Client: RawEventReceiver
Note over WsClient: incoming text frame
WsClient->>RawBroadcast: broadcast raw JSON Value
Client->>Normalizer: normalize_inbound_event(raw_json)
Normalizer->>Normalizer: extract sender, target, kind, priority
Normalizer-->>Client: NormalizedInboundEvent
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/sdk-rust/src/lib.rs (1)
1-66: ⚡ Quick winConsider adding examples for new features in top-level documentation.
The doc comment examples demonstrate the Quick Start and basic WebSocket event handling, but don't showcase the newly added features (raw event subscription, event normalization, registration helpers, or
ensure_joined_channel). Users browsing the crate documentation would benefit from seeing these patterns here.📚 Suggested documentation additions
Consider adding a third example section after the WebSocket Events example:
//! ## Raw Events and Normalization //! //! ```rust,no_run //! use relaycast::{normalize_inbound_event, WsClient, WsClientOptions}; //! //! #[tokio::main] //! async fn main() -> Result<(), Box<dyn std::error::Error>> { //! let mut ws = WsClient::new(WsClientOptions::new("at_live_agent_token")); //! let mut raw_events = ws.subscribe_raw_events(); //! ws.connect().await?; //! //! while let Ok(raw) = raw_events.recv().await { //! if let Some(event) = normalize_inbound_event(&raw) { //! println!("{} -> {}: {}", event.from, event.target, event.text); //! } //! } //! //! Ok(()) //! } //! ```🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sdk-rust/src/lib.rs` around lines 1 - 66, Add a new documentation example showing the newly added features: create a short third example titled "Raw Events and Normalization" that demonstrates using WsClient and WsClientOptions to connect, calling subscribe_raw_events (or the actual raw subscription method), receiving raw events, and passing them to normalize_inbound_event to produce normalized events; also show a brief snippet using the registration helpers (e.g., RegisterAgent/registration helper function) and calling ensure_joined_channel to guarantee the agent is in a channel before sending messages so users can see the end-to-end flow. Reference the symbols WsClient, WsClientOptions, subscribe_raw_events, normalize_inbound_event, ensure_joined_channel, and the registration helper functions/classes so the example maps directly to the new APIs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/sdk-rust/src/ws.rs`:
- Around line 347-354: The log truncation currently uses a byte-slice
&text[..text.len().min(200)] which can panic on multi-byte UTF-8 boundaries; add
a safe truncation helper (e.g., fn truncate_str(s: &str, max_chars: usize) ->
&str { ... }) near reconnect_delay_ms and replace occurrences of
&text[..text.len().min(200)] in the WebSocket message handler (the warn! calls
that log dropped messages in ws.rs) with truncate_str(&text, 200) so you
truncate by character boundaries instead of bytes.
---
Nitpick comments:
In `@packages/sdk-rust/src/lib.rs`:
- Around line 1-66: Add a new documentation example showing the newly added
features: create a short third example titled "Raw Events and Normalization"
that demonstrates using WsClient and WsClientOptions to connect, calling
subscribe_raw_events (or the actual raw subscription method), receiving raw
events, and passing them to normalize_inbound_event to produce normalized
events; also show a brief snippet using the registration helpers (e.g.,
RegisterAgent/registration helper function) and calling ensure_joined_channel to
guarantee the agent is in a channel before sending messages so users can see the
end-to-end flow. Reference the symbols WsClient, WsClientOptions,
subscribe_raw_events, normalize_inbound_event, ensure_joined_channel, and the
registration helper functions/classes so the example maps directly to the new
APIs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4e50dd88-dc2d-424e-869e-2875ec2f279a
📒 Files selected for processing (10)
packages/sdk-rust/CHANGELOG.mdpackages/sdk-rust/README.mdpackages/sdk-rust/src/agent.rspackages/sdk-rust/src/dm_participants.rspackages/sdk-rust/src/events.rspackages/sdk-rust/src/identity.rspackages/sdk-rust/src/lib.rspackages/sdk-rust/src/registration.rspackages/sdk-rust/src/ws.rspackages/sdk-rust/tests/parity.rs
|
Preview deployed!
This preview shares the staging database and will be cleaned up when the PR is merged or closed. Run E2E testsnpm run e2e -- https://pr134-api.relaycast.dev --ciOpen observer dashboard |
|
Addressed review bot feedback in a667080:
Local validation: |
Summary
Tests