//! Classroom generation and interaction commands //! //! Tauri commands for the OpenMAIC-style interactive classroom: //! - Generate classroom (4-stage pipeline with progress events) //! - Multi-agent chat //! - Export (HTML/Markdown/JSON) use std::sync::Arc; use tokio::sync::Mutex; use tauri::Manager; use zclaw_kernel::generation::Classroom; pub mod chat; pub mod export; pub mod generate; pub mod persist; // --------------------------------------------------------------------------- // Shared state types // --------------------------------------------------------------------------- /// In-memory classroom store: classroom_id → Classroom pub type ClassroomStore = Arc>>; /// Active generation tasks: topic → progress pub type GenerationTasks = Arc>>; // Re-export chat state type // Re-export chat state type — used by lib.rs to construct managed state #[allow(unused_imports)] pub use chat::ChatStore; pub use persist::ClassroomPersistence; // --------------------------------------------------------------------------- // State constructors // --------------------------------------------------------------------------- pub fn create_classroom_state() -> ClassroomStore { Arc::new(Mutex::new(std::collections::HashMap::new())) } pub fn create_generation_tasks() -> GenerationTasks { Arc::new(Mutex::new(std::collections::HashMap::new())) } /// Create and initialize the classroom persistence layer, loading saved data. pub async fn init_persistence( app_handle: &tauri::AppHandle, store: &ClassroomStore, chat_store: &ChatStore, ) -> Result { let app_dir = app_handle .path() .app_data_dir() .map_err(|e| format!("Failed to get app data dir: {}", e))?; let db_path = app_dir.join("classroom").join("classrooms.db"); std::fs::create_dir_all(db_path.parent().unwrap()) .map_err(|e| format!("Failed to create classroom dir: {}", e))?; let persistence: ClassroomPersistence = ClassroomPersistence::open(db_path).await?; let loaded = persistence.load_all(store, chat_store).await?; tracing::info!("[ClassroomPersistence] Loaded {} classrooms from SQLite", loaded); Ok(persistence) }