feat(providers): seed an official preset on startup for Claude/Codex/Gemini

New and existing users now see a built-in "Claude Official" / "OpenAI
Official" / "Google Official" entry in their provider list, so switching
back to the official endpoint is one click away instead of buried in the
README.

- New providers_seed.rs holds the three seeds (id, name, settings_config,
  icon) keyed by AppType, with a single is_official_seed_id() helper that
  scans OFFICIAL_SEEDS so the id list has one source of truth.
- Database::init_default_official_providers() runs once per database
  (gated by an official_providers_seeded setting flag), appends each seed
  to the end of the sort order, and never touches is_current.
- Startup also auto-imports the live config (settings.json / auth.json /
  .env) as a "default" provider before seeding, so users with an existing
  manual config don't lose it when they click the official preset.
- Database::has_non_official_seed_provider() replaces the get_all_providers
  call in import_default_config's gating check with an id-only scan,
  dropping the N+1 endpoint sub-queries from every startup.
This commit is contained in:
Jason
2026-04-08 23:17:09 +08:00
parent df5cb6d771
commit 5dbea70eb1
5 changed files with 207 additions and 5 deletions
+35
View File
@@ -467,6 +467,41 @@ pub fn run() {
Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"),
}
// 1.5. 自动导入 live 配置 + seed 官方预设供应商(Claude / Codex / Gemini
//
// 先 import 后 seed 是有意为之:先把用户手动配置的 settings.json / auth.json / .env
// 落成 "default" provider 设为 current,再追加官方预设(is_current=false)。
// 这样用户切到官方预设时,回填机制会保护原 live 配置不丢失。
for app_type in
crate::app_config::AppType::all().filter(|t| !t.is_additive_mode())
{
match crate::services::provider::import_default_config(
&app_state,
app_type.clone(),
) {
Ok(true) => log::info!(
"✓ Imported live config for {} as default provider",
app_type.as_str()
),
Ok(false) => log::debug!(
"○ {} already has providers; live import skipped",
app_type.as_str()
),
Err(e) => log::debug!(
"○ No live config to import for {}: {e}",
app_type.as_str()
),
}
}
match app_state.db.init_default_official_providers() {
Ok(count) if count > 0 => {
log::info!("✓ Seeded {count} official provider(s)");
}
Ok(_) => {}
Err(e) => log::warn!("✗ Failed to seed official providers: {e}"),
}
// 2. OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入)
{
let has_omo = app_state