feat: OpenAI-kompatible API mit Keys, Registry und serve-Befehl (M2.3)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
31
crates/nexus-api/src/state.rs
Normal file
31
crates/nexus-api/src/state.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
use nexus_store::Store;
|
||||
|
||||
use crate::runtime::Runtime;
|
||||
|
||||
/// Gemeinsamer Zustand aller Anfragen.
|
||||
pub struct AppState {
|
||||
store: Mutex<Store>,
|
||||
pub runtime: Runtime,
|
||||
pub http: reqwest::Client,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(store: Store, runtime: Runtime) -> Arc<Self> {
|
||||
let http = reqwest::Client::builder()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()
|
||||
.expect("HTTP-Client konnte nicht gebaut werden");
|
||||
Arc::new(Self {
|
||||
store: Mutex::new(store),
|
||||
runtime,
|
||||
http,
|
||||
})
|
||||
}
|
||||
|
||||
/// Zugriff auf die Datenbank. Nie über ein `await` hinweg halten.
|
||||
pub fn store(&self) -> MutexGuard<'_, Store> {
|
||||
self.store.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user