mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 11:43:57 +08:00
127 lines
4.0 KiB
Rust
127 lines
4.0 KiB
Rust
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<IndexMap<String, Prompt>, 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<String, String> {
|
|
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<Option<String>, 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<PiPromptLibraryStatus, String> {
|
|
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<PiPromptFileSnapshot, String> {
|
|
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<PiPromptFileSnapshot, String> {
|
|
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<bool, String> {
|
|
PiPromptFileService::delete(kind, &expectedRevision).map_err(|error| error.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn list_pi_prompt_templates() -> Result<Vec<PiPromptTemplate>, 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<PiPromptTemplate, String> {
|
|
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<bool, String> {
|
|
PiPromptTemplateService::delete(&slug, &expectedRevision).map_err(|error| error.to_string())
|
|
}
|