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,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,
});