WIP on persisting chat history on daemon

This commit is contained in:
2026-02-08 22:04:33 +02:00
parent 16ab8e4207
commit e878b8120b
15 changed files with 881 additions and 28 deletions

View File

@@ -1,12 +1,11 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tokio::sync::Mutex;
use tauri::{Emitter, Manager, State, WindowEvent};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use feshared::chatmessage::{Message, MessageHistory};
use shared::ai::{ai_daemon_client::AiDaemonClient, PromptRequest};
use tauri::{Emitter, Manager, State};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use tokio::sync::Mutex;
struct AppState {
grpc_client: Mutex<AiDaemonClient<tonic::transport::Channel>>,
@@ -42,6 +41,25 @@ async fn prompt_llm(state: State<'_, AppState>, prompt: String) -> Result<String
}
}
#[tauri::command]
async fn chat_history(
state: State<'_, AppState>,
chat_id: Option<i64>,
) -> Result<MessageHistory, String> {
let history = MessageHistory {
chat_id: match chat_id {
Some(id) => id,
None => -1,
},
history: vec![Message {
id: 1,
text: String::from("asd"),
is_user: false,
}],
};
Ok(history)
}
#[tokio::main]
async fn main() {
let channel = tonic::transport::Channel::from_static("http://[::1]:50051")
@@ -56,7 +74,11 @@ async fn main() {
grpc_client: Mutex::new(client),
})
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.invoke_handler(tauri::generate_handler![toggle_popup, prompt_llm])
.invoke_handler(tauri::generate_handler![
toggle_popup,
prompt_llm,
chat_history
])
.setup(|app| {
/* Auto-hide popup when focus is lost
if let Some(window) = app.get_webview_window("popup") {