Skip to main content

Module channel

Module channel 

Source
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:

  1. Global Registry (default) - Responses routed through registry

    • Used for MCP transport (_plexus_respond tool)
    • Works with any transport that can’t maintain channel references
  2. 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§

BidirChannel
Generic bidirectional channel for type-safe server-to-client requests.
BidirWithFallback
Bidirectional channel with fallback when transport doesn’t support bidirectional

Type Aliases§

StandardBidirChannel
Type alias for standard interactive UI patterns.