mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-24 23:10:39 +08:00
2b1f0f0f7e
- Migrate OpenClaw commands from provider.rs to dedicated commands/openclaw.rs - Add backend types and read/write for env, tools, agents.defaults sections - Create EnvPanel (API key + custom vars KV editor) - Create ToolsPanel (profile selector + allow/deny lists) - Create AgentsDefaultsPanel (default model + runtime parameters) - Extend App.tsx menu bar with Env/Tools/Agents buttons - Remove Prompts button for OpenClaw (overlaps with Workspace AGENTS.md)
109 lines
4.1 KiB
Rust
109 lines
4.1 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())
|
|
}
|
|
|
|
// ============================================================================
|
|
// 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<(), 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<(), 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<(), 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<(), 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<(), String> {
|
|
openclaw_config::set_tools_config(&tools).map_err(|e| e.to_string())
|
|
}
|