mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-31 19:22:15 +08:00
feat(omo): unify common config enabled via provider meta for OpenCode
This commit is contained in:
@@ -323,7 +323,7 @@ fn scan_cli_version(tool: &str) -> (Option<String>, Option<String>) {
|
||||
let mut search_paths: Vec<std::path::PathBuf> = vec![
|
||||
home.join(".local/bin"), // Native install (official recommended)
|
||||
home.join(".npm-global/bin"),
|
||||
home.join("n/bin"), // n version manager
|
||||
home.join("n/bin"), // n version manager
|
||||
home.join(".volta/bin"), // Volta package manager
|
||||
];
|
||||
|
||||
|
||||
@@ -465,7 +465,7 @@ pub fn is_common_config_enabled(meta: Option<&ProviderMeta>, app_type: &AppType)
|
||||
AppType::Claude => by_app.claude,
|
||||
AppType::Codex => by_app.codex,
|
||||
AppType::Gemini => by_app.gemini,
|
||||
AppType::OpenCode => None, // OpenCode doesn't support common config
|
||||
AppType::OpenCode => by_app.opencode,
|
||||
})
|
||||
.or(m.common_config_enabled)
|
||||
})
|
||||
|
||||
@@ -200,6 +200,8 @@ pub struct CommonConfigEnabledByApp {
|
||||
pub codex: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gemini: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub opencode: Option<bool>,
|
||||
}
|
||||
|
||||
/// 供应商元数据
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::config::write_json_file;
|
||||
use crate::database::OmoGlobalConfig;
|
||||
use crate::error::AppError;
|
||||
use crate::opencode_config::get_opencode_dir;
|
||||
use crate::provider::{CommonConfigEnabledByApp, ProviderMeta};
|
||||
use crate::store::AppState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
@@ -142,6 +143,29 @@ impl OmoService {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_common_config_enabled(provider: &crate::provider::Provider) -> bool {
|
||||
// Unified path: use provider meta (same mechanism as other apps).
|
||||
if let Some(meta) = provider.meta.as_ref() {
|
||||
if let Some(enabled) = meta
|
||||
.common_config_enabled_by_app
|
||||
.as_ref()
|
||||
.and_then(|by_app| by_app.opencode)
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
if let Some(enabled) = meta.common_config_enabled {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
||||
// Backward compatibility: legacy OMO providers stored this flag in settings_config.
|
||||
provider
|
||||
.settings_config
|
||||
.get("useCommonConfig")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
pub fn delete_config_file() -> Result<(), AppError> {
|
||||
let config_path = Self::config_path();
|
||||
if config_path.exists() {
|
||||
@@ -160,11 +184,7 @@ impl OmoService {
|
||||
let agents = p.settings_config.get("agents").cloned();
|
||||
let categories = p.settings_config.get("categories").cloned();
|
||||
let other_fields = p.settings_config.get("otherFields").cloned();
|
||||
let use_common_config = p
|
||||
.settings_config
|
||||
.get("useCommonConfig")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(true);
|
||||
let use_common_config = Self::resolve_common_config_enabled(p);
|
||||
(agents, categories, other_fields, use_common_config)
|
||||
});
|
||||
|
||||
@@ -237,7 +257,6 @@ impl OmoService {
|
||||
if let Some(categories) = obj.get("categories") {
|
||||
settings.insert("categories".to_string(), categories.clone());
|
||||
}
|
||||
settings.insert("useCommonConfig".to_string(), Value::Bool(true));
|
||||
|
||||
let other = Self::extract_other_fields(&obj);
|
||||
if !other.is_empty() {
|
||||
@@ -263,7 +282,13 @@ impl OmoService {
|
||||
created_at: Some(chrono::Utc::now().timestamp_millis()),
|
||||
sort_index: None,
|
||||
notes: None,
|
||||
meta: None,
|
||||
meta: Some(ProviderMeta {
|
||||
common_config_enabled_by_app: Some(CommonConfigEnabledByApp {
|
||||
opencode: Some(true),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
icon: None,
|
||||
icon_color: None,
|
||||
in_failover_queue: false,
|
||||
|
||||
Reference in New Issue
Block a user