pub mod catalog;
mod error;
#[cfg(any(feature = "neural", test))]
mod neural_math;
pub mod resolve;
pub mod store;
#[cfg(feature = "neural")]
mod neural;
pub use catalog::{CatalogFile, CatalogModel, ModelFormat, DEFAULT_MODEL};
pub use error::{GuardError, Result};
pub use resolve::resolve_dir;
pub use store::{sha256_hex, GuardStore, Manifest, ManifestFile};
#[cfg(feature = "neural")]
pub use neural::OnnxInjectionClassifier;
#[cfg(feature = "neural")]
pub fn load_classifier(
base_dir: &std::path::Path,
selector: &str,
) -> Option<Box<dyn harn_vm::security::InjectionClassifier>> {
let store = GuardStore::new(base_dir);
let dir = match resolve_dir(&store, selector) {
Ok(Some(dir)) => dir,
Ok(None) => return None,
Err(error) => {
eprintln!("[harn-guard] cannot resolve guard model `{selector}`: {error}");
return None;
}
};
let (model_id, format) = match store.read_manifest(selector) {
Ok(manifest) => (manifest.name, manifest.format),
Err(_) => (selector.to_owned(), ModelFormat::Onnx),
};
match neural::OnnxInjectionClassifier::load(&dir, &model_id, format) {
Ok(classifier) => Some(Box::new(classifier)),
Err(error) => {
eprintln!("[harn-guard] failed to load guard model `{model_id}`: {error}");
None
}
}
}
#[cfg(not(feature = "neural"))]
pub fn load_classifier(
_base_dir: &std::path::Path,
_selector: &str,
) -> Option<Box<dyn harn_vm::security::InjectionClassifier>> {
None
}