Skip to main content

Module envelope

Module envelope 

Source
Expand description

The Plexus wire envelope, as a client sees it.

§Why this is not plexus_core::plexus::types::PlexusStreamItem

The server-side envelope requires metadata on every non-Request variant, and the WebSocket JSON-RPC transport does deliver it. The REST bridge does not: stream_sse_response re-frames each item and emits only

event: data
data: {"content": <event JSON>}

— dropping metadata and content_type entirely (likewise event: error carries only {"message", "code"}, with no recoverable). A client type that made those fields mandatory could therefore not represent what the REST transport actually receives.

So StreamItem is deliberately the looser type: every field the REST bridge drops is Option / #[serde(default)]. It deserializes the full WebSocket envelope losslessly, and an SSE transport can construct the same type from an (event-name, data-payload) pair — which is what makes one typed client work over both transports.

(An SSE data: payload is not itself a StreamItem: the discriminant lives in the frame’s event: field, not in the JSON. Reassembling the two is the SSE transport’s job; this type is the target shape it reassembles into.)

Wire compatibility with the server envelope is a regression gate, not an assumption — see tests/client_envelope_compat.rs in plexus-macros, which round-trips every PlexusStreamItem variant produced by plexus-core through this type.

Structs§

StreamMetadata
Provenance metadata the calling layer stamps onto each item.

Enums§

StreamItem
One item of a Plexus response stream, as delivered by a Transport.