feat: event-driven ui updates

This commit is contained in:
Dave
2025-12-25 12:39:20 +00:00
parent a97a83ef53
commit e560bd1323
4 changed files with 48 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ use crate::llm::types::{
use crate::state::SessionState;
use serde::Deserialize;
use serde_json::json;
use tauri::State;
use tauri::{AppHandle, Emitter, State};
#[derive(Deserialize)]
pub struct ProviderConfig {
@@ -26,6 +26,7 @@ pub async fn get_ollama_models(base_url: Option<String>) -> Result<Vec<String>,
#[tauri::command]
pub async fn chat(
app: AppHandle,
messages: Vec<Message>,
config: ProviderConfig,
state: State<'_, SessionState>,
@@ -77,6 +78,8 @@ pub async fn chat(
current_history.push(assistant_msg.clone());
new_messages.push(assistant_msg);
app.emit("chat:update", &current_history)
.map_err(|e| e.to_string())?;
// Execute Tools
for call in tool_calls {
@@ -93,6 +96,8 @@ pub async fn chat(
current_history.push(tool_msg.clone());
new_messages.push(tool_msg);
app.emit("chat:update", &current_history)
.map_err(|e| e.to_string())?;
}
} else {
// Final text response
@@ -104,7 +109,10 @@ pub async fn chat(
};
// We don't push to current_history needed for next loop, because we are done.
new_messages.push(assistant_msg);
new_messages.push(assistant_msg.clone());
current_history.push(assistant_msg);
app.emit("chat:update", &current_history)
.map_err(|e| e.to_string())?;
break;
}
}