use indexmap::IndexMap; use std::str::FromStr; use tauri::State; use crate::app_config::AppType; use crate::prompt::Prompt; use crate::services::pi_prompt_files::{ PiPromptFileKind, PiPromptFileService, PiPromptFileSnapshot, PiPromptTemplate, PiPromptTemplateService, }; use crate::services::prompt::{PiPromptLibraryStatus, PromptService}; use crate::store::AppState; #[tauri::command] pub async fn get_prompts( app: String, state: State<'_, AppState>, ) -> Result, String> { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::get_prompts(&state, app_type).map_err(|e| e.to_string()) } #[tauri::command] pub async fn upsert_prompt( app: String, id: String, prompt: Prompt, state: State<'_, AppState>, ) -> Result<(), String> { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::upsert_prompt(&state, app_type, &id, prompt).map_err(|e| e.to_string()) } #[tauri::command] pub async fn delete_prompt( app: String, id: String, state: State<'_, AppState>, ) -> Result<(), String> { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::delete_prompt(&state, app_type, &id).map_err(|e| e.to_string()) } #[tauri::command] pub async fn enable_prompt( app: String, id: String, state: State<'_, AppState>, ) -> Result<(), String> { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::enable_prompt(&state, app_type, &id).map_err(|e| e.to_string()) } #[tauri::command] pub async fn import_prompt_from_file( app: String, state: State<'_, AppState>, ) -> Result { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::import_from_file(&state, app_type).map_err(|e| e.to_string()) } #[tauri::command] pub async fn get_current_prompt_file_content(app: String) -> Result, String> { let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?; PromptService::get_current_file_content(app_type).map_err(|e| e.to_string()) } #[tauri::command] pub async fn get_pi_prompt_library_status( state: State<'_, AppState>, ) -> Result { PromptService::get_pi_library_status(&state).map_err(|error| error.to_string()) } #[tauri::command] pub async fn reconcile_pi_prompt_library(state: State<'_, AppState>) -> Result<(), String> { PromptService::reconcile_pi_library(&state).map_err(|error| error.to_string()) } #[tauri::command] pub async fn get_pi_prompt_file(kind: PiPromptFileKind) -> Result { PiPromptFileService::read(kind).map_err(|error| error.to_string()) } #[tauri::command] pub async fn replace_pi_prompt_file( kind: PiPromptFileKind, #[allow(non_snake_case)] expectedRevision: String, content: String, ) -> Result { PiPromptFileService::replace(kind, &expectedRevision, &content) .map_err(|error| error.to_string()) } #[tauri::command] pub async fn delete_pi_prompt_file( kind: PiPromptFileKind, #[allow(non_snake_case)] expectedRevision: String, ) -> Result { PiPromptFileService::delete(kind, &expectedRevision).map_err(|error| error.to_string()) } #[tauri::command] pub async fn list_pi_prompt_templates() -> Result, String> { PiPromptTemplateService::list().map_err(|error| error.to_string()) } #[tauri::command] pub async fn upsert_pi_prompt_template( slug: String, #[allow(non_snake_case)] expectedRevision: String, content: String, ) -> Result { PiPromptTemplateService::upsert(&slug, &expectedRevision, &content) .map_err(|error| error.to_string()) } #[tauri::command] pub async fn delete_pi_prompt_template( slug: String, #[allow(non_snake_case)] expectedRevision: String, ) -> Result { PiPromptTemplateService::delete(&slug, &expectedRevision).map_err(|error| error.to_string()) }