Expand description
Generic bidirectional channel implementation
This module provides BidirChannel, the core primitive for server-to-client
requests during streaming RPC execution. It enables interactive workflows
where the server can request input from clients mid-stream.
§Architecture
┌─────────────┐ ┌─────────────┐
│ Server │ │ Client │
│ (Activation)│ │ (TypeScript)│
└──────┬──────┘ └──────┬──────┘
│ │
│ ctx.confirm("Delete?") │
│ │
├──────────────────────────────────┤
│ PlexusStreamItem::Request │
│ {type:"request", requestId:..} │
├─────────────────────────────────►│
│ │
│ ◄── User interaction
│ │
│◄─────────────────────────────────┤
│ _plexus_respond(requestId, │
│ {type:"confirmed",value:true})│
│ │
│ returns Ok(true) │
▼ ▼§Transport Modes
The channel supports two response routing modes:
-
Global Registry (default) - Responses routed through
registry- Used for MCP transport (
_plexus_respondtool) - Works with any transport that can’t maintain channel references
- Used for MCP transport (
-
Direct Mode - Responses handled via
handle_response()method- Used for WebSocket transport
- Requires direct access to channel instance
§Thread Safety
BidirChannel is designed for concurrent use:
- Multiple requests can be pending simultaneously
- Thread-safe internal state via
Arc<Mutex<_>> - Clone-friendly for passing to async tasks
Structs§
- Bidir
Channel - Generic bidirectional channel for type-safe server-to-client requests.
- Bidir
With Fallback - Bidirectional channel with fallback when transport doesn’t support bidirectional
Type Aliases§
- Standard
Bidir Channel - Type alias for standard interactive UI patterns.