1mod agent;
29mod config;
30mod error;
31mod ffi;
32mod result;
33
34pub use agent::GopherAgent;
35pub use config::{Config, ConfigBuilder};
36pub use error::{Error, Result};
37pub use result::{AgentResult, AgentResultStatus};
38
39#[cfg(feature = "auth")]
41pub use ffi::auth::{GopherAuthClient, TokenPayload, ValidationResult};
42
43use std::sync::atomic::{AtomicBool, Ordering};
44use std::sync::Once;
45
46static INIT: Once = Once::new();
47static INITIALIZED: AtomicBool = AtomicBool::new(false);
48
49pub fn init() -> Result<()> {
52 let mut init_result = Ok(());
53
54 INIT.call_once(|| {
55 if !ffi::is_available() {
56 init_result = Err(Error::Library(
57 "Failed to load gopher-orch native library".into(),
58 ));
59 return;
60 }
61 INITIALIZED.store(true, Ordering::SeqCst);
62 });
63
64 init_result
65}
66
67pub fn is_initialized() -> bool {
69 INITIALIZED.load(Ordering::SeqCst)
70}
71
72pub fn shutdown() {
74 INITIALIZED.store(false, Ordering::SeqCst);
75}
76
77#[cfg(test)]
78mod tests {
79 use super::*;
80
81 #[test]
82 fn test_init() {
83 let _ = init();
85 }
86
87 #[test]
88 fn test_config_builder() {
89 let config = ConfigBuilder::new()
90 .with_provider("TestProvider")
91 .with_model("test-model")
92 .with_api_key("test-key")
93 .build();
94
95 assert_eq!(config.provider(), "TestProvider");
96 assert_eq!(config.model(), "test-model");
97 assert!(config.has_api_key());
98 }
99}