Skip to main content

StreamTransformer

Trait StreamTransformer 

Source
pub trait StreamTransformer: Send {
    // Required method
    fn transform(&mut self, event: Event) -> Vec<Event>;

    // Provided methods
    fn seed(&mut self, history: &[Message]) { ... }
    fn replay(&mut self, sent: &[Event]) { ... }
}
Available on crate feature server only.
Expand description

Rewrites events on their way from an agent to the transport.

§Contract

Returning an empty Vec drops the event. Returning several events splices them in, in order. A transformer that drops the start of something must drop its continuation and terminator too. The verifier cannot identify every orphaned ID-less chunk after filtering. Normalize chunks first, or track the producer’s open streams before deciding which chunks to drop.

An emit whose output is filtered out returns Ok. At the end of a hosted run the driver checks whether the consumer received a terminal event. If the chain removed it, the driver sends a final RUN_ERROR directly to the event queue.

Required Methods§

Source

fn transform(&mut self, event: Event) -> Vec<Event>

Rewrites one event into zero or more events.

Provided Methods§

Source

fn seed(&mut self, history: &[Message])

Learns the conversation the run continues — the request’s messages — once, before the run’s first event.

Called whether or not RUN_STARTED echoes the input, which is optional and off by default. A transformer that judges an event by the id it names needs it: a resumed run may answer a tool call the interrupted run opened, and that call is in the history, not in this run’s events. The default ignores it.

Source

fn replay(&mut self, sent: &[Event])

Learns the events the run has already sent, once, after seed and before the first event of a driver that continues the run: Runner::continue_run.

sent is what a consumer holds: the output of the chain the earlier driver ran, not what its agent emitted. An event that chain dropped is not in it, and one it rewrote is there as rewritten. It may begin with the runs that came before on the same stream.

A transformer that judges an event by the id it names needs it, as it needs the history: a continuation finishes and answers calls the earlier driver opened. The default ignores it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§