diff --git a/src-tauri/src/commands/llm.rs b/src-tauri/src/commands/llm.rs index e83183a..2689d21 100644 --- a/src-tauri/src/commands/llm.rs +++ b/src-tauri/src/commands/llm.rs @@ -421,3 +421,37 @@ pub async fn extract_content_tags_cmd( .map_err(|e| e.to_string())? .map_err(|e| e.to_string()) } + +/// Auto-generate a 4-8 word title for a transcript. Mirrors the +/// `extract_content_tags_cmd` shape: `is_loaded` short-circuit, then +/// `spawn_blocking` for the synchronous llama-cpp generation, with +/// the same `PowerAssertion` guard used by the other LLM paths. +/// +/// Two callers expected: +/// 1. Frontend `addToHistory` — fires this fire-and-forget after a +/// successful save, gated on the same `aiTier !== "off"` / +/// `formatMode !== "Raw"` conditions that drive auto-cleanup. +/// 2. HistoryPage per-row + bulk on-demand button — explicit user +/// trigger for retroactively titling old transcripts. +/// +/// Returns the post-sanitised title; an `Err` from +/// `LlmEngine::generate_title` (empty transcript, model output that +/// sanitises to nothing) is propagated as a string so the frontend +/// can surface it in the bulk progress UI. +#[tauri::command] +pub async fn generate_title_cmd( + state: State<'_, AppState>, + transcript: String, +) -> Result { + if !state.llm_engine.is_loaded() { + return Err("LLM not loaded. Download an AI model in Settings.".to_string()); + } + let engine = state.llm_engine.clone(); + tokio::task::spawn_blocking(move || { + let _power_guard = PowerAssertion::begin("kon LLM title generation"); + engine.generate_title(&transcript) + }) + .await + .map_err(|e| e.to_string())? + .map_err(|e| e.to_string()) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0bf9b65..b7c8b31 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -419,6 +419,8 @@ pub fn run() { commands::fs::write_text_file_cmd, // LLM content tags (Phase 9) commands::llm::extract_content_tags_cmd, + // Auto-title generation (also via per-row + bulk in History) + commands::llm::generate_title_cmd, // Paste (auto-insert at cursor) commands::paste::paste_text, commands::paste::paste_text_replacing,