WIP push-to-talk Letta chat frontend
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 87 lines 2.2 kB view raw
1use tauri::ipc::Channel; 2 3use crate::{ 4 letta::{types::LettaCompletionMessage, LettaAgentInfo, LettaConfigKey}, 5 state::AppState, 6}; 7 8#[tauri::command] 9pub async fn list_agents(state: tauri::State<'_, AppState>) -> Result<Vec<LettaAgentInfo>, ()> { 10 match state.letta_manager.list_agents().await { 11 Ok(res) => Ok(res), 12 Err(err) => { 13 eprintln!("failed to list agents: {}", err); 14 Ok(Vec::new()) 15 } 16 } 17} 18 19#[tauri::command] 20pub async fn get_letta_base_url(state: tauri::State<'_, AppState>) -> Result<String, ()> { 21 Ok(state.letta_manager.base_url.lock().await.clone()) 22} 23 24#[tauri::command] 25pub async fn set_letta_base_url( 26 state: tauri::State<'_, AppState>, 27 url: String, 28) -> Result<String, ()> { 29 { 30 let mut base_url = state.letta_manager.base_url.lock().await; 31 *base_url = url.clone(); 32 } 33 34 state 35 .letta_manager 36 .store 37 .set(LettaConfigKey::BaseUrl.to_string(), url.clone()); 38 39 Ok(url) 40} 41 42#[tauri::command] 43pub async fn get_letta_agent_id(state: tauri::State<'_, AppState>) -> Result<String, ()> { 44 Ok(state.letta_manager.agent_id.lock().await.clone()) 45} 46 47#[tauri::command] 48pub async fn set_letta_agent_id( 49 state: tauri::State<'_, AppState>, 50 id: String, 51) -> Result<String, ()> { 52 { 53 let mut agent_id = state.letta_manager.agent_id.lock().await; 54 *agent_id = id.clone(); 55 } 56 57 state 58 .letta_manager 59 .store 60 .set(LettaConfigKey::AgentId.to_string(), id.clone()); 61 62 Ok(id) 63} 64 65#[tauri::command] 66pub async fn start_llm_completion( 67 state: tauri::State<'_, AppState>, 68 message: String, 69 on_event: Channel<LettaCompletionMessage>, 70) -> Result<(), ()> { 71 match state.letta_manager.start_completion(message).await { 72 Ok(mut rx) => { 73 while let Some(ev) = rx.recv().await { 74 on_event 75 .send(ev) 76 .expect("failed to forward event to channel"); 77 } 78 79 Ok(()) 80 } 81 Err(err) => { 82 eprintln!("failed to start completion: {}", err); 83 84 Ok(()) 85 } 86 } 87}