use ed_agent::{AgentReply, ChatMessage, ChatReply, Ed, EngineInfo};
use tauri::State;
use crate::sink::TauriSink;
pub struct EdState {
ed: Ed<TauriSink>,
}
impl EdState {
pub fn new(ed: Ed<TauriSink>) -> Self {
Self { ed }
}
pub fn ed(&self) -> &Ed<TauriSink> {
&self.ed
}
}
#[tauri::command]
pub async fn chat_get_status(state: State<'_, EdState>) -> Result<EngineInfo, String> {
Ok(state.ed.info().await)
}
#[tauri::command]
pub async fn chat_get_history(state: State<'_, EdState>) -> Result<Vec<ChatMessage>, String> {
Ok(state.ed.history().await)
}
#[tauri::command]
pub async fn chat_clear_history(state: State<'_, EdState>) -> Result<usize, String> {
Ok(state.ed.clear_history().await)
}
#[tauri::command]
pub async fn chat_send_message(
state: State<'_, EdState>,
message: String,
) -> Result<ChatReply, String> {
Ok(state.ed.send(message).await)
}
#[tauri::command]
pub async fn chat_run(state: State<'_, EdState>, message: String) -> Result<AgentReply, String> {
state
.ed
.run(message)
.await
.map_err(|error| error.to_string())
}
#[tauri::command]
pub async fn chat_cancel(state: State<'_, EdState>) -> Result<(), String> {
state.ed.cancel();
Ok(())
}