WIP on persisting chat history on daemon
This commit is contained in:
9
frontend/Cargo.lock
generated
9
frontend/Cargo.lock
generated
@@ -21,6 +21,7 @@ dependencies = [
|
||||
name = "ai-desktop-app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"feshared",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shared",
|
||||
@@ -37,6 +38,7 @@ name = "ai-desktop-app-ui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"feshared",
|
||||
"js-sys",
|
||||
"leptos",
|
||||
"leptos_router",
|
||||
@@ -1159,6 +1161,13 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "feshared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.6"
|
||||
|
||||
@@ -14,6 +14,7 @@ serde-wasm-bindgen = "0.6"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
leptos_router = "0.8.11"
|
||||
serde_json = "1.0.149"
|
||||
feshared = {path = "../crates/feshared"}
|
||||
|
||||
[workspace]
|
||||
members = ["src-tauri"]
|
||||
|
||||
@@ -23,6 +23,7 @@ tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
shared = { path = "../../crates/shared" }
|
||||
feshared = { path = "../../crates/feshared" }
|
||||
tonic = "0.14.2"
|
||||
tokio = "1.49.0"
|
||||
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
use crate::bridge::invoke;
|
||||
use feshared::chatmessage::{Message, MessageHistory};
|
||||
use leptos::{ev::keydown, html::Input, prelude::*};
|
||||
use wasm_bindgen::{prelude::Closure, JsCast, JsValue};
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Message {
|
||||
id: usize,
|
||||
text: String,
|
||||
is_user: bool,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Popup() -> impl IntoView {
|
||||
// Prompt signals and and action
|
||||
@@ -34,7 +28,7 @@ pub fn Popup() -> impl IntoView {
|
||||
if let Some(result) = prompt_action.value().get() {
|
||||
set_messages.update(|previous| {
|
||||
previous.push(Message {
|
||||
id: previous.len(),
|
||||
id: previous.len() as i64,
|
||||
text: result,
|
||||
is_user: false,
|
||||
});
|
||||
@@ -66,6 +60,12 @@ pub fn Popup() -> impl IntoView {
|
||||
}
|
||||
});
|
||||
|
||||
spawn_local(async move {
|
||||
let response = invoke("chat_history", JsValue::bigint_from_str("1")).await;
|
||||
let history: MessageHistory = serde_wasm_bindgen::from_value(response).unwrap();
|
||||
set_messages.set(history.history.clone());
|
||||
});
|
||||
|
||||
view! {
|
||||
<main class="window-shell rounded-container">
|
||||
<h3>"AI quick action"</h3>
|
||||
@@ -79,7 +79,7 @@ pub fn Popup() -> impl IntoView {
|
||||
if ev.key() == "Enter" {
|
||||
set_messages.update(|previous| {
|
||||
previous.push(Message {
|
||||
id: previous.len(),
|
||||
id: previous.len() as i64,
|
||||
text: prompt_text.get(),
|
||||
is_user: true,
|
||||
});
|
||||
|
||||
@@ -25,14 +25,27 @@ body {
|
||||
.response-area {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
overflow-y: scroll;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.msg {
|
||||
margin: 1px;
|
||||
border: solid 1px #808080;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
max-width: 70%;
|
||||
}
|
||||
|
||||
.msg-user {
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px) scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user