pub struct NormalizingStream {
inner: Pin<Box<dyn Stream<Item = Result<LlmStreamEvent>> + Send>>,
parser: Box<dyn ToolCallParser>,
queued: VecDeque<LlmStreamEvent>,
next_index: usize,
terminated: bool,
}Expand description
Stream adapter that runs every event through a ToolCallParser before
re-emitting the normalized result. See module docs.
Fields§
§inner: Pin<Box<dyn Stream<Item = Result<LlmStreamEvent>> + Send>>§parser: Box<dyn ToolCallParser>§queued: VecDeque<LlmStreamEvent>Events ready to emit on the next poll. A single upstream event can
expand to many downstream events (e.g. Done flushes parser state
before propagating).
next_index: usizeLowest tool-call index that is safe to use for a synthesised delta.
Bumped past every upstream index we observe so downstream
collectors can use indices as keys without collision.
terminated: booltrue once we’ve forwarded the upstream Done (or upstream ended
or errored). Subsequent polls return None.
Implementations§
Source§impl NormalizingStream
impl NormalizingStream
Sourcepub fn new(
inner: Pin<Box<dyn Stream<Item = Result<LlmStreamEvent>> + Send>>,
parser: Box<dyn ToolCallParser>,
) -> Self
pub fn new( inner: Pin<Box<dyn Stream<Item = Result<LlmStreamEvent>> + Send>>, parser: Box<dyn ToolCallParser>, ) -> Self
Wrap inner so every event is normalized through parser.
Sourcefn enqueue_parser_output(&mut self, out: ParserOutput)
fn enqueue_parser_output(&mut self, out: ParserOutput)
Translate one parser output batch into the queued event sequence.
Sourcefn handle_upstream(&mut self, event: LlmStreamEvent)
fn handle_upstream(&mut self, event: LlmStreamEvent)
Process one upstream event and queue the resulting downstream events.
Trait Implementations§
Source§impl Stream for NormalizingStream
impl Stream for NormalizingStream
Auto Trait Implementations§
impl Freeze for NormalizingStream
impl !RefUnwindSafe for NormalizingStream
impl Send for NormalizingStream
impl !Sync for NormalizingStream
impl Unpin for NormalizingStream
impl !UnwindSafe for NormalizingStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more