use anyhow::Result;
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::session::memory::{SessionMemory, WorkingMemoryType};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct EnhancedMemorySummary {
pub base_summary: crate::session::memory::MemorySummary,
pub context_stats: ContextStats,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ContextStats {
pub total_tokens: usize,
pub message_count: usize,
pub compression_ratio: f64,
pub token_savings_percent: f64,
}
pub struct ContextBridge {
session_memory: Arc<RwLock<SessionMemory>>,
#[allow(dead_code)]
agent_id: String,
#[allow(dead_code)]
session_id: String,
}
impl ContextBridge {
pub fn new(
session_memory: Arc<RwLock<SessionMemory>>,
agent_id: String,
session_id: String,
) -> Self {
Self {
session_memory,
agent_id,
session_id,
}
}
pub async fn add_to_working_memory(
&self,
content: String,
memory_type: WorkingMemoryType,
priority: f32,
) -> Result<()> {
let mut memory = self.session_memory.write().await;
memory.add_to_working_memory(content, memory_type, priority);
Ok(())
}
pub async fn get_enhanced_memory_summary(&self) -> Result<EnhancedMemorySummary> {
let memory = self.session_memory.read().await;
let base_summary = memory.get_summary();
Ok(EnhancedMemorySummary {
base_summary,
context_stats: ContextStats {
total_tokens: 0,
message_count: 0,
compression_ratio: 1.0,
token_savings_percent: 0.0,
},
})
}
#[allow(dead_code)]
fn estimate_tokens(content: &str) -> usize {
content.len() / 4
}
}