generalbots/botserver/src/core/config_reload.rs
Rodrigo Rodriguez (Pragmatismo) c70fbba099 refactor: Remove ooxmlsdk from default build, split document_processor, fix DriveMonitor sync
- Replace docs/sheet/slides with kb-extraction in default features (~4-6min compile time savings, ~300MB less disk)
- Add kb-extraction feature using zip+quick-xml+calamine for lightweight KB extraction
- Split document_processor.rs (829 lines) into mod.rs+types.rs+ooxml_extract.rs+rtf.rs
- Move DOCX/PPTX ZIP-based extraction to document_processor::ooxml_extract (no ooxmlsdk needed)
- Remove dead code: save_docx_preserving(), save_pptx_preserving() (zero callers)
- Fix dep: prefix for optional dependencies in feature definitions
- DriveMonitor: full S3 sync, ETag change detection, KB incremental indexing, config.csv sync
- ConfigManager: real DB reads from bot_configuration table
- 0 warnings, 0 errors on both default and full feature builds
2026-04-21 14:54:41 +00:00

59 lines
2 KiB
Rust

// Simple config reload endpoint
use axum::{extract::State, http::StatusCode, response::Json};
use serde_json::{json, Value};
use std::sync::Arc;
use crate::core::shared::state::AppState;
use crate::core::config::ConfigManager;
pub async fn reload_config(
State(state): State<Arc<AppState>>,
) -> Result<Json<Value>, StatusCode> {
let config_manager = ConfigManager::new(state.conn.clone());
// Get default bot
let conn_arc = state.conn.clone();
let (default_bot_id, _) = tokio::task::spawn_blocking(move || -> Result<(uuid::Uuid, String), String> {
let mut conn = conn_arc
.get()
.map_err(|e| format!("failed to get db connection: {e}"))?;
Ok(crate::core::bot::get_default_bot(&mut conn))
})
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
// Get LLM config
let llm_url = config_manager
.get_config(&default_bot_id, "llm-url", Some(""))
.unwrap_or_else(|_| "".to_string());
let llm_model = config_manager
.get_config(&default_bot_id, "llm-model", Some("local"))
.unwrap_or_else(|_| "local".to_string());
let llm_endpoint_path = config_manager
.get_config(&default_bot_id, "llm-endpoint-path", Some("/v1/chat/completions"))
.unwrap_or_else(|_| "/v1/chat/completions".to_string());
// Update LLM provider
if let Some(dynamic_llm) = &state.dynamic_llm_provider {
dynamic_llm
.update_from_config(&llm_url, Some(llm_model.clone()), Some(llm_endpoint_path.clone()), None)
.await;
Ok(Json(json!({
"status": "success",
"message": "LLM configuration reloaded",
"config": {
"llm_url": llm_url,
"llm_model": llm_model,
"llm_endpoint_path": llm_endpoint_path
}
})))
} else {
Ok(Json(json!({
"status": "error",
"message": "Dynamic LLM provider not available"
})))
}
}