feat(init): implement automatic data import on first launch
Add comprehensive first-launch data import system: Database layer: - Add is_empty_for_first_import() to detect empty database - Add init_default_skill_repos() to initialize 3 default skill repositories Services layer: - Implement McpService::import_from_claude/codex/gemini() to import MCP servers from existing config files - Implement PromptService::import_from_file_on_first_launch() to import prompt files (CLAUDE.md, AGENTS.md, GEMINI.md) Startup flow (lib.rs): - Check if database is empty on startup - Import existing configurations if detected: 1. Initialize default skill repositories 2. Import provider configurations from live settings 3. Import MCP servers from config files 4. Import prompt files - All imports are fault-tolerant and logged This ensures seamless migration from file-based configs to database.
This commit is contained in:
@@ -180,21 +180,68 @@ impl McpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 从 Claude 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Claude 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_claude(_state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_claude(state: &AppState) -> Result<usize, AppError> {
|
||||||
// TODO: Implement import logic using database
|
// 创建临时 MultiAppConfig 用于导入
|
||||||
// For now, return 0 as a placeholder
|
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
||||||
Ok(0)
|
|
||||||
|
// 调用原有的导入逻辑(从 mcp.rs)
|
||||||
|
let count = crate::mcp::import_from_claude(&mut temp_config)?;
|
||||||
|
|
||||||
|
// 如果有导入的服务器,保存到数据库
|
||||||
|
if count > 0 {
|
||||||
|
if let Some(servers) = &temp_config.mcp.servers {
|
||||||
|
for server in servers.values() {
|
||||||
|
state.db.save_mcp_server(server)?;
|
||||||
|
// 同步到 Claude live 配置
|
||||||
|
Self::sync_server_to_apps(state, server)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 Codex 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Codex 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_codex(_state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_codex(state: &AppState) -> Result<usize, AppError> {
|
||||||
// TODO: Implement import logic using database
|
// 创建临时 MultiAppConfig 用于导入
|
||||||
Ok(0)
|
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
||||||
|
|
||||||
|
// 调用原有的导入逻辑(从 mcp.rs)
|
||||||
|
let count = crate::mcp::import_from_codex(&mut temp_config)?;
|
||||||
|
|
||||||
|
// 如果有导入的服务器,保存到数据库
|
||||||
|
if count > 0 {
|
||||||
|
if let Some(servers) = &temp_config.mcp.servers {
|
||||||
|
for server in servers.values() {
|
||||||
|
state.db.save_mcp_server(server)?;
|
||||||
|
// 同步到 Codex live 配置
|
||||||
|
Self::sync_server_to_apps(state, server)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 Gemini 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Gemini 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_gemini(_state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_gemini(state: &AppState) -> Result<usize, AppError> {
|
||||||
// TODO: Implement import logic using database
|
// 创建临时 MultiAppConfig 用于导入
|
||||||
Ok(0)
|
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
||||||
|
|
||||||
|
// 调用原有的导入逻辑(从 mcp.rs)
|
||||||
|
let count = crate::mcp::import_from_gemini(&mut temp_config)?;
|
||||||
|
|
||||||
|
// 如果有导入的服务器,保存到数据库
|
||||||
|
if count > 0 {
|
||||||
|
if let Some(servers) = &temp_config.mcp.servers {
|
||||||
|
for server in servers.values() {
|
||||||
|
state.db.save_mcp_server(server)?;
|
||||||
|
// 同步到 Gemini live 配置
|
||||||
|
Self::sync_server_to_apps(state, server)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user