Skip to main content

HistoryManager

Struct HistoryManager 

Source
pub struct HistoryManager<C: ConversationStore, S: StateStore> {
    pub thread_id: ThreadId,
    pub root_thread_id: ThreadId,
    pub history: RefCell<Vec<InfinityMessage>>,
    /* private fields */
}

Fields§

§thread_id: ThreadId§root_thread_id: ThreadId§history: RefCell<Vec<InfinityMessage>>

Implementations§

Source§

impl<C: ConversationStore, S: StateStore> HistoryManager<C, S>

Source

pub async fn new_with_history( conversation_store: C, state_store: S, thread_id: ThreadId, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Source

pub fn handle_content( &self, message: InfinityMessage, message_id: String, ) -> Result<bool, Box<dyn Error + Send + Sync>>

Source

pub fn handle_completion( &self, completion: &StreamChunk, completion_id: String, display_as: Option<String>, )

Buffer a streamed assistant chunk for the current turn. The chunk is not committed to history yet — it accumulates in turn_buffer until the turn reaches a flush point (Self::flush_turn) or is discarded on failure (Self::discard_turn). This keeps partial, possibly-abandoned turns out of committed history.

Source

pub fn flush_turn(&self)

Commit the buffered current-turn content into history and pending_items. Called at a flush point: a completed turn (Final) or a turn-ending tool call. After this, the buffered messages are part of committed history and will be persisted by the next Self::sync.

Source

pub fn flush_turn_trimming_reasoning(&self)

Like Self::flush_turn, but first drops any trailing assistant reasoning (and empty text) from the buffer so the committed turn does not end on a reasoning block.

Source

pub fn discard_turn(&self)

Drop the buffered current-turn content without committing it. Called when a turn fails mid-stream (timeout, disconnect) and will be retried: the retry rebuilds the request from clean committed history, so the abandoned partial turn must not linger.

Source

pub fn turn_buffer_is_empty(&self) -> bool

Source

pub fn current_turn_view(&self) -> Vec<InfinityMessage>

Committed history followed by the in-flight buffered turn. Used for mid-turn subscriber replay so a client connecting while the model is streaming still sees the partial assistant message.

Source

pub async fn sync(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Source

pub async fn update_metadata( &self, metadata: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>

Source

pub fn get_metadata(&self) -> Option<Value>

Source

pub fn get_history(&self, supports_image_input: bool) -> Vec<Message>

Build the model-facing chat history. When supports_image_input is false, image tool-result content is replaced with a text placeholder so the history can be sent to models without image support.

Source

pub fn get_thread_stack(&self) -> Vec<ThreadId>

Returns the full thread stack: [root, ..ancestors, current_thread]. For the root thread this is just the root thread ID.

Source

pub fn conversation_store(&self) -> &C

Source

pub async fn apply_compaction( &self, ) -> Result<bool, Box<dyn Error + Send + Sync>>

Apply the latest compaction summary: reload from store, truncate in-memory history up to the compaction point, and prepend the summary.

Source

pub fn take_interrupted_tool_calls(&self) -> Vec<String>

Drain and return tool call IDs that were interrupted by new user messages. Callers use this to send best-effort cancellation notifications to RAP tool servers so they can abort in-flight operations.

Source

pub fn safe_spawn_point(&self) -> usize

Compute a safe spawn point that excludes trailing unanswered tool calls. Returns an absolute store order (accounting for prior compaction offset and ancestor prefix) suitable for use as spawn_order_override.

Source

pub async fn track_subscription( &self, tool_call_id: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Record a subscription in the current thread’s metadata. The tool_call_id is the ID of the tool call whose result had subscription: true. Ownership is implicit — a subscription is stored in the thread that created it.

Source

pub async fn remove_subscription( &self, tool_call_id: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Remove a subscription from the current thread’s active tracking.

Auto Trait Implementations§

§

impl<C, S> !Freeze for HistoryManager<C, S>

§

impl<C, S> !RefUnwindSafe for HistoryManager<C, S>

§

impl<C, S> !Sync for HistoryManager<C, S>

§

impl<C, S> Send for HistoryManager<C, S>

§

impl<C, S> Unpin for HistoryManager<C, S>
where C: Unpin, S: Unpin,

§

impl<C, S> UnsafeUnpin for HistoryManager<C, S>
where C: UnsafeUnpin, S: UnsafeUnpin,

§

impl<C, S> UnwindSafe for HistoryManager<C, S>
where C: UnwindSafe, S: UnwindSafe,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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