Skip to main content

ObserverHost

Struct ObserverHost 

Source
pub struct ObserverHost { /* private fields */ }
Expand description

Holds registered observers and dispatches notifications to each.

Observers run in registration order. All observers are always notified — there is no short-circuiting (use the hook system for flow control).

An empty host (no observers registered) is effectively zero-cost: each notification call iterates an empty Vec.

Implementations§

Source§

impl ObserverHost

Source

pub fn new() -> Self

Create an empty observer host.

Equivalent to ObserverHost::default but more explicit.

Source

pub fn register(&mut self, observer: Arc<dyn LoopObserver>)

Register an observer.

Observers are called in registration order at each lifecycle point. Registering the same observer twice will result in duplicate notifications.

Source

pub fn len(&self) -> usize

Number of registered observers.

Source

pub fn is_empty(&self) -> bool

Whether no observers are registered.

Source

pub fn reset_all(&self)

Reset all observers for a new session.

Calls LoopObserver::reset on every registered observer, allowing them to clear per-session accumulators.

Source

pub fn on_session_start(&self, ctx: &SessionStartContext)

Dispatch LoopObserver::on_session_start to all observers.

Iterates registered observers in registration order.

Source

pub fn on_session_end(&self, ctx: &SessionEndContext)

Dispatch LoopObserver::on_session_end to all observers.

Iterates registered observers in registration order.

Source

pub fn on_turn_start(&self, ctx: &TurnStartContext)

Dispatch LoopObserver::on_turn_start to all observers.

Iterates registered observers in registration order.

Source

pub fn on_turn_end(&self, ctx: &TurnEndContext)

Dispatch LoopObserver::on_turn_end to all observers.

Iterates registered observers in registration order.

Source

pub fn on_stream_success(&self, ctx: &StreamContext)

Dispatch LoopObserver::on_stream_success to all observers.

Iterates registered observers in registration order.

Source

pub fn on_stream_failure(&self, ctx: &StreamFailureContext)

Dispatch LoopObserver::on_stream_failure to all observers.

Iterates registered observers in registration order.

Source

pub fn on_response(&self, ctx: &ResponseContext)

Dispatch LoopObserver::on_response to all observers.

Iterates registered observers in registration order.

Source

pub fn on_tool_pre(&self, ctx: &ToolPreContext)

Dispatch LoopObserver::on_tool_pre to all observers.

Iterates registered observers in registration order.

Source

pub fn on_tool_post(&self, ctx: &ToolPostContext)

Dispatch LoopObserver::on_tool_post to all observers.

Iterates registered observers in registration order.

Source

pub fn on_compaction(&self, ctx: &CompactedContext)

Dispatch LoopObserver::on_compaction to all observers.

Iterates registered observers in registration order.

Source

pub fn on_fallback(&self, ctx: &FallbackContext)

Dispatch LoopObserver::on_fallback to all observers.

Iterates registered observers in registration order.

Source

pub fn on_model_switched(&self, ctx: &ModelSwitchedContext)

Dispatch LoopObserver::on_model_switched to all observers.

Iterates registered observers in registration order.

Source

pub fn on_loop_detected(&self, ctx: &LoopDetectedContext)

Dispatch LoopObserver::on_loop_detected to all observers.

Iterates registered observers in registration order.

Source

pub fn on_convergence_detected(&self, ctx: &ConvergenceDetectedContext)

Dispatch LoopObserver::on_convergence_detected to all observers.

Iterates registered observers in registration order.

Trait Implementations§

Source§

impl Default for ObserverHost

Source§

fn default() -> ObserverHost

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more