Skip to main content

ai_agent/
session_memory.rs

1//! Session memory - backward-compatible re-export of [services::session_memory].
2//!
3//! The actual implementation lives in `src/services/session_memory/`.
4//! This module provides:
5//! - Re-exports of all new module symbols
6//! - Backward-compatible adapters for callers that expect legacy types
7
8// Re-export everything from the new module
9pub use crate::services::session_memory::*;
10
11/// Count tool calls in assistant messages since a given index.
12/// Backward-compatible wrapper around the new module's internal function.
13pub fn count_tool_calls_since(
14    messages: &[crate::types::Message],
15    since_index: Option<usize>,
16) -> usize {
17    crate::services::session_memory::session_memory::count_tool_calls_since(
18        messages,
19        since_index,
20    )
21}
22
23/// Get the last summarized message as a message *index* into the provided
24/// message slice. Returns the length of the slice minus one when we only
25/// have a string UUID (the index is not recoverable).
26///
27/// This adapter exists because the old API returned `Option<usize>` (index)
28/// while the new API stores `Option<String>` (UUID).
29pub fn get_last_summarized_message_id_as_index(messages: &[crate::types::Message]) -> Option<usize> {
30    let uuid = get_last_summarized_message_id();
31    match uuid {
32        Some(ref id) => {
33            // Find the message index matching this UUID.
34            messages.iter().position(|m| m.uuid.as_deref() == Some(id)).or_else(|| {
35                if messages.is_empty() {
36                    None
37                } else {
38                    Some(messages.len() - 1)
39                }
40            })
41        }
42        None => None,
43    }
44}