#[cfg(feature = "api-server")]
use crate::{CacheManager, EmbeddingModel, ModelRegistry};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use uuid::Uuid;
#[derive(Clone)]
pub struct ApiState {
pub registry: Arc<ModelRegistry>,
pub cache_manager: Arc<CacheManager>,
pub models: Arc<RwLock<HashMap<Uuid, Arc<dyn EmbeddingModel + Send + Sync>>>>,
pub config: ApiConfig,
}
#[derive(Debug, Clone)]
pub struct ApiConfig {
pub host: String,
pub port: u16,
pub timeout_seconds: u64,
pub request_timeout_secs: u64,
pub max_batch_size: usize,
pub rate_limit: RateLimitConfig,
pub auth: AuthConfig,
pub enable_logging: bool,
pub enable_cors: bool,
}
impl Default for ApiConfig {
fn default() -> Self {
Self {
host: "0.0.0.0".to_string(),
port: 8080,
timeout_seconds: 30,
request_timeout_secs: 30,
max_batch_size: 1000,
rate_limit: RateLimitConfig::default(),
auth: AuthConfig::default(),
enable_logging: true,
enable_cors: true,
}
}
}
#[derive(Debug, Clone)]
pub struct RateLimitConfig {
pub requests_per_minute: u32,
pub enabled: bool,
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
requests_per_minute: 1000,
enabled: true,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct AuthConfig {
pub require_api_key: bool,
pub api_keys: Vec<String>,
pub enable_jwt: bool,
pub jwt_secret: Option<String>,
}