pub struct SpanLog { /* private fields */ }Expand description
A bounded, in-order log of tool spans, built by pairing a harness’s “call started” and “call finished” records by call id.
Records arrive interleaved and out of order (agents run tools in parallel), so a span is closed by searching back for the still-open span with that id rather than assuming the most recent one.
Implementations§
Source§impl SpanLog
impl SpanLog
Sourcepub fn unbounded() -> Self
pub fn unbounded() -> Self
A log that keeps every span. For a one-shot pass over a whole transcript, never for the live tracker, where the memory and the clone per refresh would grow with the session.
Sourcepub fn open(
&mut self,
id: String,
name: String,
at: SystemTime,
sidechain: bool,
)
pub fn open( &mut self, id: String, name: String, at: SystemTime, sidechain: bool, )
Record the start of a tool call. Ignored when that id is already open, so a transcript line replayed by the harness does not double-count.
Sourcepub fn open_kind(
&mut self,
id: String,
name: String,
at: SystemTime,
sidechain: bool,
kind: SpanKind,
)
pub fn open_kind( &mut self, id: String, name: String, at: SystemTime, sidechain: bool, kind: SpanKind, )
open, for any kind of span.
Sourcepub fn end_at(&mut self, id: &str, at: SystemTime)
pub fn end_at(&mut self, id: &str, at: SystemTime)
Move the end of the newest span with this id to at, open or not. An
inference span grows as the response streams in, one content block
per line, and its end is wherever the last block landed.
Sourcepub fn open_of_kind(&self, kind: SpanKind) -> Option<&ToolSpan>
pub fn open_of_kind(&self, kind: SpanKind) -> Option<&ToolSpan>
The newest open span of this kind, if any.
Sourcepub fn discard_open(&mut self, id: &str)
pub fn discard_open(&mut self, id: &str)
Remove the newest span with this id if it is still open. For a span that turned out not to be one: an inference that never produced a reply because the user interrupted or submitted again.
Sourcepub fn close(&mut self, id: &str, at: SystemTime, error: bool)
pub fn close(&mut self, id: &str, at: SystemTime, error: bool)
Close the open call with this id. A result whose call scrolled out of the window, or that we never saw start, is dropped.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = &ToolSpan> + ExactSizeIterator
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = &ToolSpan> + ExactSizeIterator
Oldest first. Double-ended so callers can take the newest spans without collecting the whole log first, which the UI and the golden tests both do.
pub fn to_vec(&self) -> Vec<ToolSpan>
Sourcepub fn merged<'a>(
logs: impl IntoIterator<Item = &'a SpanLog>,
cap: usize,
) -> SpanLog
pub fn merged<'a>( logs: impl IntoIterator<Item = &'a SpanLog>, cap: usize, ) -> SpanLog
One log from several, ordered by start time, keeping the newest cap.
A parent’s spans and its subagents’ spans interleave in wall-clock
order, which is what a waterfall wants.