use std::collections::HashMap;
use std::sync::Arc;
use crate::errors::AgentResult;
use crate::runtime::context::AuthContext;
use super::{ContentSource, MemoryContent, MemoryEntry, MemoryService, SearchOptions};
pub struct OwnedHistory {
service: Arc<dyn MemoryService>,
}
impl OwnedHistory {
pub fn new(service: Arc<dyn MemoryService>) -> Self {
Self { service }
}
pub async fn recall(
&self,
auth: &AuthContext,
query: &str,
limit: usize,
) -> AgentResult<Vec<MemoryEntry>> {
self.service
.search(auth, query, SearchOptions::history_only().with_limit(limit))
.await
}
pub async fn save_fact(
&self,
auth: &AuthContext,
text: String,
category: Option<String>,
) -> AgentResult<String> {
self.service
.add(
auth,
MemoryContent {
text,
source: ContentSource::UserFact { category },
metadata: HashMap::new(),
},
)
.await
}
}
pub struct OwnedKnowledge {
service: Arc<dyn MemoryService>,
}
impl OwnedKnowledge {
pub fn new(service: Arc<dyn MemoryService>) -> Self {
Self { service }
}
pub async fn search(
&self,
auth: &AuthContext,
query: &str,
limit: usize,
) -> AgentResult<Vec<MemoryEntry>> {
self.service
.search(
auth,
query,
SearchOptions::knowledge_only().with_limit(limit),
)
.await
}
}