use std::path::{Path, PathBuf};
use crate::adapters::llm_research_engine::LlmResearchEngine;
use crate::adapters::sqlite_store::SqliteStore;
use crate::config::{Config, default_config_path, default_db_path};
use crate::error::{ResearchError, Result};
pub fn open_store(db_path: &Path) -> Result<SqliteStore> {
SqliteStore::open(db_path)
}
pub fn resolve_db(opt: &Option<PathBuf>) -> PathBuf {
opt.clone().unwrap_or_else(default_db_path)
}
pub fn load_config() -> Result<Config> {
Config::load(&default_config_path()).map_err(|e| ResearchError::Config(e.to_string()))
}
pub fn make_llm_engine(store: SqliteStore) -> Result<LlmResearchEngine> {
let config = load_config()?;
if let Some(llm_cfg) = config.llm {
if llm_cfg.resolve_api_key().is_none() {
tracing::warn!(
api_key_env = %llm_cfg.api_key_env,
"[llm] api_key_env not set — LLM calls will fail"
);
}
use llm_kernel::llm::ModelConfig;
let model_config = ModelConfig {
provider: llm_cfg.provider,
model: llm_cfg.model,
api_key_env: llm_cfg.api_key_env,
base_url: llm_cfg.base_url,
..ModelConfig::default()
};
return Ok(LlmResearchEngine::with_config(
Box::new(store),
model_config,
));
}
Ok(LlmResearchEngine::new(Box::new(store)))
}