pub struct ToolCallBridge<I> { /* private fields */ }Expand description
Per-stream index → grammar-identity map for streamed tool calls.
I is the wire’s own index type (usize for chat-compat chunk indices,
i32 for Bedrock content-block indices); it must display so a minted id
can derive from it, and order so a drain preserves wire ordering.
Implementations§
Source§impl<I> ToolCallBridge<I>
impl<I> ToolCallBridge<I>
pub fn new() -> Self
Sourcepub fn with_minted_namespace(minted: SyntheticIds) -> Self
pub fn with_minted_namespace(minted: SyntheticIds) -> Self
A bridge minting slot identities in the given reserved namespace.
Sourcepub fn open(
&mut self,
index: I,
wire_id: Option<&str>,
name: Option<&str>,
) -> &mut ToolCallSlot
pub fn open( &mut self, index: I, wire_id: Option<&str>, name: Option<&str>, ) -> &mut ToolCallSlot
Open (or update) the slot for a wire index, establishing its identity.
On first sight the assembly key is fixed: the wire id when one is supplied, else a freshly minted identity — the single enforcement point of the mandatory-identity invariant. Later fragments update the established provider id and name from any non-empty values they carry.
Sourcepub fn get(&self, index: I) -> Option<&ToolCallSlot>
pub fn get(&self, index: I) -> Option<&ToolCallSlot>
The open slot at a wire index, if any.
Sourcepub fn get_mut(&mut self, index: I) -> Option<&mut ToolCallSlot>
pub fn get_mut(&mut self, index: I) -> Option<&mut ToolCallSlot>
The open slot at a wire index, mutably — for fragment bookkeeping
on an already-open slot without open’s insert-if-absent.
Sourcepub fn minted_ids(&mut self) -> &mut SyntheticIds
pub fn minted_ids(&mut self) -> &mut SyntheticIds
The bridge’s identity minter, for adapters that also mint whole-call identities: assemblies and whole calls must draw from ONE counter so their minted keys stay disjoint.
Sourcepub fn remove(&mut self, index: I) -> Option<ToolCallSlot>
pub fn remove(&mut self, index: I) -> Option<ToolCallSlot>
Close and take the slot at a wire index, if any.
Sourcepub fn evict_if(
&mut self,
index: I,
should_evict: impl FnOnce(&ToolCallSlot) -> bool,
) -> Option<ToolCallSlot>
pub fn evict_if( &mut self, index: I, should_evict: impl FnOnce(&ToolCallSlot) -> bool, ) -> Option<ToolCallSlot>
Evict the slot at a wire index when the predicate says the incoming fragment belongs to a different call reusing the same index (the per-profile eviction semantics — e.g. a distinct id + name pair on a wire that restarts indices per call). Returns the evicted slot so the caller can flush it to the consumer.
Sourcepub fn decorate(&mut self, decoration: ToolCallDecoration)
pub fn decorate(&mut self, decoration: ToolCallDecoration)
Apply a provider decoration to the in-flight call it names, matched by the established provider id. Decorations ride the slot onto its end event; assembly itself is untouched.
Two matching rules keep this deterministic:
- A slot whose wire never established a provider id (empty
id) never matches — a decoration for the empty string would otherwise pick an arbitrary id-less slot out ofHashMapiteration order. - Each field is first-wins: a later decoration for the same call
fills only the fields still unset, so a gemini-style
signature-then-params sequence composes instead of the second
decoration clobbering the first’s signature with
None.
Sourcepub fn drain_ordered(&mut self) -> Vec<ToolCallSlot>
pub fn drain_ordered(&mut self) -> Vec<ToolCallSlot>
Drain every open slot in wire-index order, so a multi-call turn keeps its wire ordering when flushed. The caller chooses the unparseable policy per flush site when building end events.
Sourcepub fn drain_ordered_indexed(&mut self) -> Vec<(I, ToolCallSlot)>
pub fn drain_ordered_indexed(&mut self) -> Vec<(I, ToolCallSlot)>
ToolCallBridge::drain_ordered, keeping each slot’s wire index —
for adapters that track per-slot state of their own beside the
bridge (the Responses adapter’s pending call_ids).
Trait Implementations§
Source§impl<I: Debug> Debug for ToolCallBridge<I>
impl<I: Debug> Debug for ToolCallBridge<I>
Auto Trait Implementations§
impl<I> Freeze for ToolCallBridge<I>
impl<I> RefUnwindSafe for ToolCallBridge<I>where
I: RefUnwindSafe,
impl<I> Send for ToolCallBridge<I>where
I: Send,
impl<I> Sync for ToolCallBridge<I>where
I: Sync,
impl<I> Unpin for ToolCallBridge<I>where
I: Unpin,
impl<I> UnsafeUnpin for ToolCallBridge<I>
impl<I> UnwindSafe for ToolCallBridge<I>where
I: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more