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]) { ... }
}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§
Provided Methods§
Sourcefn seed(&mut self, history: &[Message])
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.
Sourcefn replay(&mut self, sent: &[Event])
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".