Skip to main content

Module encode

Module encode 

Source
Expand description

Wire encoding for the event stream.

EventStreamFormatter is the abstraction a transport implements. sse::SseFormatter is the one every AG-UI implementation supports.

use ag_ui::{Event, EventStreamFormatter, SseFormatter};

let formatter = SseFormatter::new();
let bytes = formatter.encode(&Event::text_message_end("msg-1")).unwrap();
assert_eq!(
    String::from_utf8(bytes).unwrap(),
    "data: {\"type\":\"TEXT_MESSAGE_END\",\"messageId\":\"msg-1\"}\n\n"
);

Modules§

protobuf
The AG-UI binary transport — not implemented.
sse
Server-Sent Events framing.

Constants§

PROTOBUF_MEDIA_TYPE
Media type of the AG-UI binary stream, as defined by the upstream @ag-ui/proto package.
SSE_MEDIA_TYPE
Media type of a Server-Sent Events stream.

Traits§

EventStreamFormatter
Turns events into the bytes a transport puts on the wire.

Functions§

media_type
Picks the media type to answer an Accept header with.
supported_media_types
The media types this build can emit, most preferred first.