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>
impl<C: ConversationStore, S: StateStore> HistoryManager<C, S>
pub async fn new_with_history( conversation_store: C, state_store: S, thread_id: ThreadId, ) -> Result<Self, Box<dyn Error + Send + Sync>>
pub fn handle_content( &self, message: InfinityMessage, message_id: String, ) -> Result<bool, Box<dyn Error + Send + Sync>>
Sourcepub fn handle_completion(
&self,
completion: &StreamChunk,
completion_id: String,
display_as: Option<String>,
)
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.
Sourcepub fn flush_turn(&self)
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.
Sourcepub fn flush_turn_trimming_reasoning(&self)
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.
Sourcepub fn discard_turn(&self)
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.
pub fn turn_buffer_is_empty(&self) -> bool
Sourcepub fn current_turn_view(&self) -> Vec<InfinityMessage>
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.
pub async fn sync(&self) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn update_metadata( &self, metadata: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn get_metadata(&self) -> Option<Value>
Sourcepub fn get_history(&self, supports_image_input: bool) -> Vec<Message>
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.
Sourcepub fn get_thread_stack(&self) -> Vec<ThreadId>
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.
pub fn conversation_store(&self) -> &C
Sourcepub async fn apply_compaction(
&self,
) -> Result<bool, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn take_interrupted_tool_calls(&self) -> Vec<String>
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.
Sourcepub fn safe_spawn_point(&self) -> usize
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.
Sourcepub async fn track_subscription(
&self,
tool_call_id: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.