use super::keys::{memory_embedding_key_from_keys_file, needs_embedding_key};
use crate::config::{ExtraPath, MemoryConfig};
pub(crate) fn vector_enabled() -> bool {
let config = read_memory_config();
config.vector_enabled
}
pub(crate) fn read_memory_config() -> MemoryConfig {
let mut cfg = read_memory_section().unwrap_or_default();
if let Some(ref mut emb) = cfg.embedding
&& needs_embedding_key(emb.api_key.as_deref())
&& let Some(key) = memory_embedding_key_from_keys_file()
{
emb.api_key = Some(key);
}
cfg
}
pub(super) fn read_memory_section() -> Option<MemoryConfig> {
let config_path = crate::config::opencrabs_home().join("config.toml");
let content = std::fs::read_to_string(&config_path).ok()?;
let table = content.parse::<toml::Table>().ok()?;
let memory = table.get("memory")?;
toml::from_str::<MemoryConfig>(&toml::to_string(memory).ok()?).ok()
}
pub(crate) fn extra_paths_config() -> Vec<ExtraPath> {
read_memory_config().extra_paths
}
pub(crate) fn external_excludes() -> Vec<String> {
read_memory_config().exclude
}
pub(crate) fn external_allowed_in_shared() -> bool {
read_memory_config().external_allowed_in_shared
}
pub(crate) fn sweep_interval_secs() -> u64 {
read_memory_config().sweep_interval_secs
}