mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
bf40b0138c
- Add usage_daily_rollups table (schema v6) to aggregate proxy request logs into daily summaries, reducing query overhead for statistics - Add rollup_and_prune DAO that aggregates old detail logs (>N days) into rollup rows and deletes the originals - Update all usage stats queries to UNION detail logs with rollup data - Introduce incremental auto-vacuum for SQLite, with startup and periodic cleanup of old stream_check_logs and request log rollups - Split backup export/import into full vs sync variants: WebDAV sync now skips local-only table data (proxy_request_logs, stream_check_logs, provider_health, proxy_live_backup, usage_daily_rollups) while preserving them on import - Add enable_logging guard to skip request log writes when disabled - Apply cargo fmt formatting fixes across multiple modules
128 lines
4.8 KiB
Rust
128 lines
4.8 KiB
Rust
use std::collections::HashMap;
|
|
use tauri::State;
|
|
|
|
use crate::openclaw_config;
|
|
use crate::store::AppState;
|
|
|
|
// ============================================================================
|
|
// OpenClaw Provider Commands (migrated from provider.rs)
|
|
// ============================================================================
|
|
|
|
/// Import providers from OpenClaw live config to database.
|
|
///
|
|
/// OpenClaw uses additive mode — users may already have providers
|
|
/// configured in openclaw.json.
|
|
#[tauri::command]
|
|
pub fn import_openclaw_providers_from_live(state: State<'_, AppState>) -> Result<usize, String> {
|
|
crate::services::provider::import_openclaw_providers_from_live(state.inner())
|
|
.map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Get provider IDs in the OpenClaw live config.
|
|
#[tauri::command]
|
|
pub fn get_openclaw_live_provider_ids() -> Result<Vec<String>, String> {
|
|
openclaw_config::get_providers()
|
|
.map(|providers| providers.keys().cloned().collect())
|
|
.map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Get a single OpenClaw provider fragment from live config.
|
|
#[tauri::command]
|
|
pub fn get_openclaw_live_provider(
|
|
#[allow(non_snake_case)] providerId: String,
|
|
) -> Result<Option<serde_json::Value>, String> {
|
|
openclaw_config::get_provider(&providerId).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Scan openclaw.json for known configuration hazards.
|
|
#[tauri::command]
|
|
pub fn scan_openclaw_config_health() -> Result<Vec<openclaw_config::OpenClawHealthWarning>, String>
|
|
{
|
|
openclaw_config::scan_openclaw_config_health().map_err(|e| e.to_string())
|
|
}
|
|
|
|
// ============================================================================
|
|
// Agents Configuration Commands
|
|
// ============================================================================
|
|
|
|
/// Get OpenClaw default model config (agents.defaults.model)
|
|
#[tauri::command]
|
|
pub fn get_openclaw_default_model() -> Result<Option<openclaw_config::OpenClawDefaultModel>, String>
|
|
{
|
|
openclaw_config::get_default_model().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Set OpenClaw default model config (agents.defaults.model)
|
|
#[tauri::command]
|
|
pub fn set_openclaw_default_model(
|
|
model: openclaw_config::OpenClawDefaultModel,
|
|
) -> Result<openclaw_config::OpenClawWriteOutcome, String> {
|
|
openclaw_config::set_default_model(&model).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Get OpenClaw model catalog/allowlist (agents.defaults.models)
|
|
#[tauri::command]
|
|
pub fn get_openclaw_model_catalog(
|
|
) -> Result<Option<HashMap<String, openclaw_config::OpenClawModelCatalogEntry>>, String> {
|
|
openclaw_config::get_model_catalog().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Set OpenClaw model catalog/allowlist (agents.defaults.models)
|
|
#[tauri::command]
|
|
pub fn set_openclaw_model_catalog(
|
|
catalog: HashMap<String, openclaw_config::OpenClawModelCatalogEntry>,
|
|
) -> Result<openclaw_config::OpenClawWriteOutcome, String> {
|
|
openclaw_config::set_model_catalog(&catalog).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Get full agents.defaults config (all fields)
|
|
#[tauri::command]
|
|
pub fn get_openclaw_agents_defaults(
|
|
) -> Result<Option<openclaw_config::OpenClawAgentsDefaults>, String> {
|
|
openclaw_config::get_agents_defaults().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Set full agents.defaults config (all fields)
|
|
#[tauri::command]
|
|
pub fn set_openclaw_agents_defaults(
|
|
defaults: openclaw_config::OpenClawAgentsDefaults,
|
|
) -> Result<openclaw_config::OpenClawWriteOutcome, String> {
|
|
openclaw_config::set_agents_defaults(&defaults).map_err(|e| e.to_string())
|
|
}
|
|
|
|
// ============================================================================
|
|
// Env Configuration Commands
|
|
// ============================================================================
|
|
|
|
/// Get OpenClaw env config (env section of openclaw.json)
|
|
#[tauri::command]
|
|
pub fn get_openclaw_env() -> Result<openclaw_config::OpenClawEnvConfig, String> {
|
|
openclaw_config::get_env_config().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Set OpenClaw env config (env section of openclaw.json)
|
|
#[tauri::command]
|
|
pub fn set_openclaw_env(
|
|
env: openclaw_config::OpenClawEnvConfig,
|
|
) -> Result<openclaw_config::OpenClawWriteOutcome, String> {
|
|
openclaw_config::set_env_config(&env).map_err(|e| e.to_string())
|
|
}
|
|
|
|
// ============================================================================
|
|
// Tools Configuration Commands
|
|
// ============================================================================
|
|
|
|
/// Get OpenClaw tools config (tools section of openclaw.json)
|
|
#[tauri::command]
|
|
pub fn get_openclaw_tools() -> Result<openclaw_config::OpenClawToolsConfig, String> {
|
|
openclaw_config::get_tools_config().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Set OpenClaw tools config (tools section of openclaw.json)
|
|
#[tauri::command]
|
|
pub fn set_openclaw_tools(
|
|
tools: openclaw_config::OpenClawToolsConfig,
|
|
) -> Result<openclaw_config::OpenClawWriteOutcome, String> {
|
|
openclaw_config::set_tools_config(&tools).map_err(|e| e.to_string())
|
|
}
|