use async_trait::async_trait;
use mockforge_intelligence::behavioral_cloning::storage::BehavioralCloningStateProvider;
use mockforge_intelligence::behavioral_cloning::EdgeAmplifier;
use mockforge_recorder::database::RecorderDatabase;
use std::{path::PathBuf, sync::Arc};
pub use mockforge_intelligence::handlers::behavioral_cloning::*;
#[derive(Clone)]
pub struct BehavioralCloningState {
pub edge_amplifier: Arc<EdgeAmplifier>,
pub database_path: Option<PathBuf>,
}
impl BehavioralCloningState {
pub fn new() -> Self {
Self {
edge_amplifier: Arc::new(EdgeAmplifier::new()),
database_path: None,
}
}
pub fn with_database_path(path: PathBuf) -> Self {
Self {
edge_amplifier: Arc::new(EdgeAmplifier::new()),
database_path: Some(path),
}
}
async fn open_database(&self) -> Result<RecorderDatabase, String> {
let db_path = self.database_path.as_ref().cloned().unwrap_or_else(|| {
std::env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join("recordings.db")
});
RecorderDatabase::new(&db_path)
.await
.map_err(|e| format!("Failed to open recorder database: {}", e))
}
}
impl Default for BehavioralCloningState {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl BehavioralCloningStateProvider for BehavioralCloningState {
type Store = RecorderDatabase;
async fn open_store(&self) -> Result<Self::Store, String> {
self.open_database().await
}
}