use std::sync::Arc;
use async_trait::async_trait;
use crate::{MemoryService, SearchRequest};
pub struct MemoryServiceAdapter {
inner: Arc<dyn MemoryService>,
app_name: String,
user_id: String,
}
impl MemoryServiceAdapter {
pub fn new(
inner: Arc<dyn MemoryService>,
app_name: impl Into<String>,
user_id: impl Into<String>,
) -> Self {
Self { inner, app_name: app_name.into(), user_id: user_id.into() }
}
}
#[async_trait]
impl adk_core::Memory for MemoryServiceAdapter {
async fn search(&self, query: &str) -> adk_core::Result<Vec<adk_core::MemoryEntry>> {
let resp = self
.inner
.search(SearchRequest {
query: query.to_string(),
app_name: self.app_name.clone(),
user_id: self.user_id.clone(),
limit: None,
min_score: None,
})
.await?;
Ok(resp
.memories
.into_iter()
.map(|m| adk_core::MemoryEntry { content: m.content, author: m.author })
.collect())
}
async fn health_check(&self) -> adk_core::Result<()> {
self.inner.health_check().await
}
}