use std::sync::Arc;
use ikigai_core::EndpointSpace;
use ikigai_sparql::Store;
use crate::config::BrowseSettings;
pub struct Browse {
pub space: EndpointSpace,
pub store: Arc<Store>,
}
pub fn wire(settings: &BrowseSettings) -> Browse {
let store = Arc::new(Store::open(&settings.store).unwrap_or_else(|e| {
panic!(
"ikigai-dev: browse store `{}` cannot open: {e} — refusing to run with an \
in-memory archive (explanations and annotations would be silently lost). \
ONE process holds the store at a time; if another ikigai holds this lock \
(e.g. a main-host serve instance with `serve.browse.root` lines), move \
browse ownership HERE: drop those lines and prefer-mount this server \
instead — mount = \"prefer urn:repo:=<this socket>\" and \
mount = \"prefer urn:annotation:=<this socket>\". Otherwise fix the \
path/permissions.",
settings.store.display()
)
}));
ikigai_sparql::load_vocabulary(&store).unwrap_or_else(|e| {
panic!("ikigai-dev: loading the vocabulary into the browse store: {e:?}")
});
let mut explain = ikigai_browse::ExplainConfig::new(Arc::clone(&store))
.file_provider(settings.file_model.clone())
.dir_provider(settings.dir_model.clone());
if let Some(tokens) = settings.file_max_tokens {
explain = explain.file_max_tokens(tokens);
}
if let Some(tokens) = settings.dir_max_tokens {
explain = explain.dir_max_tokens(tokens);
}
Browse {
space: ikigai_browse::space_with_explain(settings.roots.clone(), explain),
store,
}
}