mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-01 12:22:09 +08:00
feat: unify Codex third-party providers into stable "custom" history bucket
Codex filters resume history by `model_provider`, so switching between provider-specific ids like `rightcode` and `aihubmix` made past sessions appear to vanish. Collapse all third-party providers into a single stable bucket so cross-switch history stays visible. - Normalize live `model_provider` to "custom" on every Codex write (reserved built-in ids like openai/ollama are preserved). - Add device-level one-shot migration that rewrites historical JSONL session files and the `state_5.sqlite` threads table from legacy provider ids into the "custom" bucket. Backs up originals under `~/.cc-switch/backups/codex-history-provider-migration-v1/` and uses the SQLite Backup API for the state DB. - Record completion in `settings.json` under `localMigrations` so the migration is strictly idempotent across launches. - Update Codex provider preset templates to emit `model_provider = "custom"` out of the box.
This commit is contained in:
@@ -176,6 +176,30 @@ impl WebDavSyncSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/// 本机自动迁移状态。
|
||||
///
|
||||
/// 这里记录的是设备级操作(例如修改本机 `~/.codex` 文件),不随数据库同步。
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LocalMigrations {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub codex_third_party_history_provider_bucket_v1:
|
||||
Option<CodexThirdPartyHistoryProviderBucketMigration>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CodexThirdPartyHistoryProviderBucketMigration {
|
||||
pub completed_at: String,
|
||||
pub target_provider_id: String,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub source_provider_ids: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub migrated_jsonl_files: usize,
|
||||
#[serde(default)]
|
||||
pub migrated_state_rows: usize,
|
||||
}
|
||||
|
||||
/// 应用设置结构
|
||||
///
|
||||
/// 存储设备级别设置,保存在本地 `~/.cc-switch/settings.json`,不随数据库同步。
|
||||
@@ -301,6 +325,10 @@ pub struct AppSettings {
|
||||
/// - Linux: "gnome-terminal" | "konsole" | "xfce4-terminal" | "alacritty" | "kitty" | "ghostty"
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub preferred_terminal: Option<String>,
|
||||
|
||||
// ===== 本机自动迁移状态 =====
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub local_migrations: Option<LocalMigrations>,
|
||||
}
|
||||
|
||||
fn default_show_in_tray() -> bool {
|
||||
@@ -351,6 +379,7 @@ impl Default for AppSettings {
|
||||
backup_interval_hours: None,
|
||||
backup_retain_count: None,
|
||||
preferred_terminal: None,
|
||||
local_migrations: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,6 +585,29 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_codex_third_party_history_provider_bucket_migrated() -> bool {
|
||||
get_settings()
|
||||
.local_migrations
|
||||
.as_ref()
|
||||
.and_then(|migrations| {
|
||||
migrations
|
||||
.codex_third_party_history_provider_bucket_v1
|
||||
.as_ref()
|
||||
})
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn mark_codex_third_party_history_provider_bucket_migrated(
|
||||
migration: CodexThirdPartyHistoryProviderBucketMigration,
|
||||
) -> Result<(), AppError> {
|
||||
mutate_settings(|settings| {
|
||||
let migrations = settings
|
||||
.local_migrations
|
||||
.get_or_insert_with(Default::default);
|
||||
migrations.codex_third_party_history_provider_bucket_v1 = Some(migration);
|
||||
})
|
||||
}
|
||||
|
||||
/// 从文件重新加载设置到内存缓存
|
||||
/// 用于导入配置等场景,确保内存缓存与文件同步
|
||||
pub fn reload_settings() -> Result<(), AppError> {
|
||||
|
||||
Reference in New Issue
Block a user