mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-18 19:20:07 +08:00
Compare commits
79 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b69a052009 | |||
| 1c739b7841 | |||
| dca1d822da | |||
| 65f50a0a29 | |||
| 3aa3f00251 | |||
| 7749e325a2 | |||
| 3b500be525 | |||
| 1dc1f86560 | |||
| 7574d049ff | |||
| d4487755bf | |||
| 3264d71a4d | |||
| b20e121013 | |||
| e98acf94fc | |||
| 304d14b1ab | |||
| 09a87c97b8 | |||
| d31531f88b | |||
| ae21754d50 | |||
| 7c1f13e4f3 | |||
| fd25c9949f | |||
| 6443dc897d | |||
| 7aa381cbb7 | |||
| 1de3f1b7f8 | |||
| edc71efe4c | |||
| 3faf22f1c9 | |||
| 0cb8b30f15 | |||
| be1c2ac76e | |||
| e7451bda22 | |||
| 5a3420932b | |||
| a2688603fb | |||
| 23a407544a | |||
| 2b34dc4ec9 | |||
| 529051f0e8 | |||
| 5d1eed563d | |||
| 6e7547ef6e | |||
| f02efbd2b7 | |||
| a39b1d8698 | |||
| 86255fe106 | |||
| 4acd48adc9 | |||
| d4cd8105d1 | |||
| 2b1ae2aa71 | |||
| cf57fbed7b | |||
| eefb764f72 | |||
| 4ed3e3bf84 | |||
| 99471f6706 | |||
| 4210b1547c | |||
| cfee4d6fcc | |||
| 24dc628130 | |||
| bf74620051 | |||
| e8d4397b3a | |||
| 2b0bc73276 | |||
| 939a2e4f2b | |||
| 1a89267986 | |||
| 127fa5bf9d | |||
| 0d4be40c25 | |||
| 00720ecf30 | |||
| de7f93d513 | |||
| e7545f8cdf | |||
| 838a99b5d2 | |||
| 325c6a5f21 | |||
| 8824462e4c | |||
| 0c1d94e57b | |||
| 636a1e2c60 | |||
| a56a578e91 | |||
| c582be265b | |||
| 8f218057f3 | |||
| 81a6c08673 | |||
| 988ea326d9 | |||
| f1b0fa2985 | |||
| 3f470de608 | |||
| 03af3600b0 | |||
| 482b8a1cab | |||
| ddb0b68b4c | |||
| 524fa94339 | |||
| 162c92144c | |||
| b075ee9fbb | |||
| 17cf701bad | |||
| 977185e2d5 | |||
| 764ba81ea6 | |||
| d802b7bf61 |
+1041
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ const KEEP_LIST = [
|
|||||||
'zhipu', 'chatglm', 'glm', 'minimax', 'mistral', 'cohere',
|
'zhipu', 'chatglm', 'glm', 'minimax', 'mistral', 'cohere',
|
||||||
'perplexity', 'huggingface', 'midjourney', 'stability',
|
'perplexity', 'huggingface', 'midjourney', 'stability',
|
||||||
'xai', 'grok', 'yi', 'zeroone', 'ollama',
|
'xai', 'grok', 'yi', 'zeroone', 'ollama',
|
||||||
|
'packycode',
|
||||||
|
|
||||||
// Cloud/Tools
|
// Cloud/Tools
|
||||||
'aws', 'googlecloud', 'huawei', 'cloudflare',
|
'aws', 'googlecloud', 'huawei', 'cloudflare',
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const KNOWN_METADATA = {
|
|||||||
microsoft: { name: 'microsoft', displayName: 'Microsoft', category: 'ai-provider', keywords: ['copilot', 'azure'], defaultColor: '#00A4EF' },
|
microsoft: { name: 'microsoft', displayName: 'Microsoft', category: 'ai-provider', keywords: ['copilot', 'azure'], defaultColor: '#00A4EF' },
|
||||||
cohere: { name: 'cohere', displayName: 'Cohere', category: 'ai-provider', keywords: ['cohere'], defaultColor: '#39594D' },
|
cohere: { name: 'cohere', displayName: 'Cohere', category: 'ai-provider', keywords: ['cohere'], defaultColor: '#39594D' },
|
||||||
perplexity: { name: 'perplexity', displayName: 'Perplexity', category: 'ai-provider', keywords: ['perplexity'], defaultColor: '#20808D' },
|
perplexity: { name: 'perplexity', displayName: 'Perplexity', category: 'ai-provider', keywords: ['perplexity'], defaultColor: '#20808D' },
|
||||||
|
packycode: { name: 'packycode', displayName: 'PackyCode', category: 'ai-provider', keywords: ['packycode', 'packy', 'packyapi'], defaultColor: 'currentColor' },
|
||||||
mistral: { name: 'mistral', displayName: 'Mistral', category: 'ai-provider', keywords: ['mistral'], defaultColor: '#FF7000' },
|
mistral: { name: 'mistral', displayName: 'Mistral', category: 'ai-provider', keywords: ['mistral'], defaultColor: '#FF7000' },
|
||||||
huggingface: { name: 'huggingface', displayName: 'Hugging Face', category: 'ai-provider', keywords: ['huggingface', 'hf'], defaultColor: '#FFD21E' },
|
huggingface: { name: 'huggingface', displayName: 'Hugging Face', category: 'ai-provider', keywords: ['huggingface', 'hf'], defaultColor: '#FFD21E' },
|
||||||
aws: { name: 'aws', displayName: 'AWS', category: 'cloud', keywords: ['amazon', 'cloud'], defaultColor: '#FF9900' },
|
aws: { name: 'aws', displayName: 'AWS', category: 'cloud', keywords: ['amazon', 'cloud'], defaultColor: '#FF9900' },
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
use crate::deeplink::{
|
||||||
|
import_mcp_from_deeplink, import_prompt_from_deeplink, import_provider_from_deeplink,
|
||||||
|
import_skill_from_deeplink, parse_deeplink_url, DeepLinkImportRequest,
|
||||||
|
};
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
@@ -15,18 +18,18 @@ pub fn parse_deeplink(url: String) -> Result<DeepLinkImportRequest, String> {
|
|||||||
pub fn merge_deeplink_config(
|
pub fn merge_deeplink_config(
|
||||||
request: DeepLinkImportRequest,
|
request: DeepLinkImportRequest,
|
||||||
) -> Result<DeepLinkImportRequest, String> {
|
) -> Result<DeepLinkImportRequest, String> {
|
||||||
log::info!("Merging config for deep link request: {}", request.name);
|
log::info!("Merging config for deep link request: {:?}", request.name);
|
||||||
crate::deeplink::parse_and_merge_config(&request).map_err(|e| e.to_string())
|
crate::deeplink::parse_and_merge_config(&request).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import a provider from a deep link request (after user confirmation)
|
/// Import a provider from a deep link request (legacy, kept for compatibility)
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn import_from_deeplink(
|
pub fn import_from_deeplink(
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
request: DeepLinkImportRequest,
|
request: DeepLinkImportRequest,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Importing provider from deep link: {} for app {}",
|
"Importing provider from deep link: {:?} for app {:?}",
|
||||||
request.name,
|
request.name,
|
||||||
request.app
|
request.app
|
||||||
);
|
);
|
||||||
@@ -37,3 +40,50 @@ pub fn import_from_deeplink(
|
|||||||
|
|
||||||
Ok(provider_id)
|
Ok(provider_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Import resource from a deep link request (unified handler)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn import_from_deeplink_unified(
|
||||||
|
state: State<'_, AppState>,
|
||||||
|
request: DeepLinkImportRequest,
|
||||||
|
) -> Result<serde_json::Value, String> {
|
||||||
|
log::info!("Importing {} resource from deep link", request.resource);
|
||||||
|
|
||||||
|
match request.resource.as_str() {
|
||||||
|
"provider" => {
|
||||||
|
let provider_id =
|
||||||
|
import_provider_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
||||||
|
Ok(serde_json::json!({
|
||||||
|
"type": "provider",
|
||||||
|
"id": provider_id
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
"prompt" => {
|
||||||
|
let prompt_id =
|
||||||
|
import_prompt_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
||||||
|
Ok(serde_json::json!({
|
||||||
|
"type": "prompt",
|
||||||
|
"id": prompt_id
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
"mcp" => {
|
||||||
|
let result = import_mcp_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
||||||
|
// Add type field to the result
|
||||||
|
Ok(serde_json::json!({
|
||||||
|
"type": "mcp",
|
||||||
|
"importedCount": result.imported_count,
|
||||||
|
"importedIds": result.imported_ids,
|
||||||
|
"failed": result.failed
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
"skill" => {
|
||||||
|
let skill_key =
|
||||||
|
import_skill_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
||||||
|
Ok(serde_json::json!({
|
||||||
|
"type": "skill",
|
||||||
|
"key": skill_key
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
_ => Err(format!("Unsupported resource type: {}", request.resource)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,6 +63,22 @@ impl Database {
|
|||||||
Ok(db)
|
Ok(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 创建内存数据库(用于测试)
|
||||||
|
pub fn memory() -> Result<Self, AppError> {
|
||||||
|
let conn = Connection::open_in_memory().map_err(|e| AppError::Database(e.to_string()))?;
|
||||||
|
|
||||||
|
// 启用外键约束
|
||||||
|
conn.execute("PRAGMA foreign_keys = ON;", [])
|
||||||
|
.map_err(|e| AppError::Database(e.to_string()))?;
|
||||||
|
|
||||||
|
let db = Self {
|
||||||
|
conn: Mutex::new(conn),
|
||||||
|
};
|
||||||
|
db.create_tables()?;
|
||||||
|
|
||||||
|
Ok(db)
|
||||||
|
}
|
||||||
|
|
||||||
fn create_tables(&self) -> Result<(), AppError> {
|
fn create_tables(&self) -> Result<(), AppError> {
|
||||||
let conn = lock_conn!(self.conn);
|
let conn = lock_conn!(self.conn);
|
||||||
Self::create_tables_on_conn(&conn)
|
Self::create_tables_on_conn(&conn)
|
||||||
@@ -373,8 +389,8 @@ impl Database {
|
|||||||
// 导出 schema
|
// 导出 schema
|
||||||
let mut stmt = conn
|
let mut stmt = conn
|
||||||
.prepare(
|
.prepare(
|
||||||
"SELECT type, name, tbl_name, sql
|
"SELECT type, name, tbl_name, sql
|
||||||
FROM sqlite_master
|
FROM sqlite_master
|
||||||
WHERE sql NOT NULL AND type IN ('table','index','trigger','view')
|
WHERE sql NOT NULL AND type IN ('table','index','trigger','view')
|
||||||
ORDER BY type='table' DESC, name",
|
ORDER BY type='table' DESC, name",
|
||||||
)
|
)
|
||||||
@@ -500,7 +516,7 @@ impl Database {
|
|||||||
|
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT OR REPLACE INTO providers (
|
"INSERT OR REPLACE INTO providers (
|
||||||
id, app_type, name, settings_config, website_url, category,
|
id, app_type, name, settings_config, website_url, category,
|
||||||
created_at, sort_index, notes, icon, icon_color, meta, is_current
|
created_at, sort_index, notes, icon, icon_color, meta, is_current
|
||||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
||||||
params![
|
params![
|
||||||
@@ -793,7 +809,7 @@ impl Database {
|
|||||||
|
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT OR REPLACE INTO providers (
|
"INSERT OR REPLACE INTO providers (
|
||||||
id, app_type, name, settings_config, website_url, category,
|
id, app_type, name, settings_config, website_url, category,
|
||||||
created_at, sort_index, notes, icon, icon_color, meta, is_current
|
created_at, sort_index, notes, icon, icon_color, meta, is_current
|
||||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
||||||
params![
|
params![
|
||||||
|
|||||||
+938
-113
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,7 @@ pub use app_config::{AppType, McpApps, McpServer, MultiAppConfig};
|
|||||||
pub use codex_config::{get_codex_auth_path, get_codex_config_path, write_codex_live_atomic};
|
pub use codex_config::{get_codex_auth_path, get_codex_config_path, write_codex_live_atomic};
|
||||||
pub use commands::*;
|
pub use commands::*;
|
||||||
pub use config::{get_claude_mcp_path, get_claude_settings_path, read_json_file};
|
pub use config::{get_claude_mcp_path, get_claude_settings_path, read_json_file};
|
||||||
|
pub use database::Database;
|
||||||
pub use deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
pub use deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
||||||
pub use error::AppError;
|
pub use error::AppError;
|
||||||
pub use mcp::{
|
pub use mcp::{
|
||||||
@@ -314,7 +315,7 @@ fn handle_deeplink_url(
|
|||||||
match crate::deeplink::parse_deeplink_url(url_str) {
|
match crate::deeplink::parse_deeplink_url(url_str) {
|
||||||
Ok(request) => {
|
Ok(request) => {
|
||||||
log::info!(
|
log::info!(
|
||||||
"✓ Successfully parsed deep link: resource={}, app={}, name={}",
|
"✓ Successfully parsed deep link: resource={}, app={:?}, name={:?}",
|
||||||
request.resource,
|
request.resource,
|
||||||
request.app,
|
request.app,
|
||||||
request.name
|
request.name
|
||||||
@@ -840,6 +841,7 @@ pub fn run() {
|
|||||||
commands::parse_deeplink,
|
commands::parse_deeplink,
|
||||||
commands::merge_deeplink_config,
|
commands::merge_deeplink_config,
|
||||||
commands::import_from_deeplink,
|
commands::import_from_deeplink,
|
||||||
|
commands::import_from_deeplink_unified,
|
||||||
update_tray_menu,
|
update_tray_menu,
|
||||||
// Environment variable management
|
// Environment variable management
|
||||||
commands::check_env_conflicts,
|
commands::check_env_conflicts,
|
||||||
@@ -889,7 +891,7 @@ pub fn run() {
|
|||||||
match crate::deeplink::parse_deeplink_url(&url_str) {
|
match crate::deeplink::parse_deeplink_url(&url_str) {
|
||||||
Ok(request) => {
|
Ok(request) => {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={}",
|
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={:?}",
|
||||||
request.resource,
|
request.resource,
|
||||||
request.app
|
request.app
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,46 +1,36 @@
|
|||||||
use std::sync::RwLock;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cc_switch_lib::{
|
use cc_switch_lib::{import_provider_from_deeplink, parse_deeplink_url, AppState, Database};
|
||||||
import_provider_from_deeplink, parse_deeplink_url, AppState, AppType, MultiAppConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[path = "support.rs"]
|
#[path = "support.rs"]
|
||||||
mod support;
|
mod support;
|
||||||
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deeplink_import_claude_provider_persists_to_config() {
|
fn deeplink_import_claude_provider_persists_to_db() {
|
||||||
let _guard = test_mutex().lock().expect("acquire test mutex");
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
||||||
reset_test_fs();
|
reset_test_fs();
|
||||||
let home = ensure_test_home();
|
let _home = ensure_test_home();
|
||||||
|
|
||||||
let url = "ccswitch://v1/import?resource=provider&app=claude&name=DeepLink%20Claude&homepage=https%3A%2F%2Fexample.com&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-claude-key&model=claude-sonnet-4";
|
let url = "ccswitch://v1/import?resource=provider&app=claude&name=DeepLink%20Claude&homepage=https%3A%2F%2Fexample.com&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-claude-key&model=claude-sonnet-4&icon=claude";
|
||||||
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
||||||
|
|
||||||
let mut config = MultiAppConfig::default();
|
let db = Arc::new(Database::memory().expect("create memory db"));
|
||||||
config.ensure_app(&AppType::Claude);
|
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState { db: db.clone() };
|
||||||
config: RwLock::new(config),
|
|
||||||
};
|
|
||||||
|
|
||||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||||
.expect("import provider from deeplink");
|
.expect("import provider from deeplink");
|
||||||
|
|
||||||
// 验证内存状态
|
// Verify DB state
|
||||||
let guard = state.config.read().expect("read config");
|
let providers = db.get_all_providers("claude").expect("get providers");
|
||||||
let manager = guard
|
let provider = providers
|
||||||
.get_manager(&AppType::Claude)
|
|
||||||
.expect("claude manager should exist");
|
|
||||||
let provider = manager
|
|
||||||
.providers
|
|
||||||
.get(&provider_id)
|
.get(&provider_id)
|
||||||
.expect("provider created via deeplink");
|
.expect("provider created via deeplink");
|
||||||
assert_eq!(provider.name, request.name);
|
|
||||||
assert_eq!(
|
assert_eq!(provider.name, request.name.clone().unwrap());
|
||||||
provider.website_url.as_deref(),
|
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
||||||
Some(request.homepage.as_str())
|
assert_eq!(provider.icon.as_deref(), Some("claude"));
|
||||||
);
|
|
||||||
let auth_token = provider
|
let auth_token = provider
|
||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
||||||
@@ -49,50 +39,34 @@ fn deeplink_import_claude_provider_persists_to_config() {
|
|||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/env/ANTHROPIC_BASE_URL")
|
.pointer("/env/ANTHROPIC_BASE_URL")
|
||||||
.and_then(|v| v.as_str());
|
.and_then(|v| v.as_str());
|
||||||
assert_eq!(auth_token, Some(request.api_key.as_str()));
|
assert_eq!(auth_token, request.api_key.as_deref());
|
||||||
assert_eq!(base_url, Some(request.endpoint.as_str()));
|
assert_eq!(base_url, request.endpoint.as_deref());
|
||||||
drop(guard);
|
|
||||||
|
|
||||||
// 验证配置已持久化
|
|
||||||
let config_path = home.join(".cc-switch").join("config.json");
|
|
||||||
assert!(
|
|
||||||
config_path.exists(),
|
|
||||||
"importing provider from deeplink should persist config.json"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
||||||
let _guard = test_mutex().lock().expect("acquire test mutex");
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
||||||
reset_test_fs();
|
reset_test_fs();
|
||||||
let home = ensure_test_home();
|
let _home = ensure_test_home();
|
||||||
|
|
||||||
let url = "ccswitch://v1/import?resource=provider&app=codex&name=DeepLink%20Codex&homepage=https%3A%2F%2Fopenai.example&endpoint=https%3A%2F%2Fapi.openai.example%2Fv1&apiKey=sk-test-codex-key&model=gpt-4o";
|
let url = "ccswitch://v1/import?resource=provider&app=codex&name=DeepLink%20Codex&homepage=https%3A%2F%2Fopenai.example&endpoint=https%3A%2F%2Fapi.openai.example%2Fv1&apiKey=sk-test-codex-key&model=gpt-4o&icon=openai";
|
||||||
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
||||||
|
|
||||||
let mut config = MultiAppConfig::default();
|
let db = Arc::new(Database::memory().expect("create memory db"));
|
||||||
config.ensure_app(&AppType::Codex);
|
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState { db: db.clone() };
|
||||||
config: RwLock::new(config),
|
|
||||||
};
|
|
||||||
|
|
||||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||||
.expect("import provider from deeplink");
|
.expect("import provider from deeplink");
|
||||||
|
|
||||||
let guard = state.config.read().expect("read config");
|
let providers = db.get_all_providers("codex").expect("get providers");
|
||||||
let manager = guard
|
let provider = providers
|
||||||
.get_manager(&AppType::Codex)
|
|
||||||
.expect("codex manager should exist");
|
|
||||||
let provider = manager
|
|
||||||
.providers
|
|
||||||
.get(&provider_id)
|
.get(&provider_id)
|
||||||
.expect("provider created via deeplink");
|
.expect("provider created via deeplink");
|
||||||
assert_eq!(provider.name, request.name);
|
|
||||||
assert_eq!(
|
assert_eq!(provider.name, request.name.clone().unwrap());
|
||||||
provider.website_url.as_deref(),
|
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
||||||
Some(request.homepage.as_str())
|
assert_eq!(provider.icon.as_deref(), Some("openai"));
|
||||||
);
|
|
||||||
let auth_value = provider
|
let auth_value = provider
|
||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/auth/OPENAI_API_KEY")
|
.pointer("/auth/OPENAI_API_KEY")
|
||||||
@@ -102,20 +76,13 @@ fn deeplink_import_codex_provider_builds_auth_and_config() {
|
|||||||
.get("config")
|
.get("config")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
assert_eq!(auth_value, Some(request.api_key.as_str()));
|
assert_eq!(auth_value, request.api_key.as_deref());
|
||||||
assert!(
|
assert!(
|
||||||
config_text.contains(request.endpoint.as_str()),
|
config_text.contains(request.endpoint.as_deref().unwrap()),
|
||||||
"config.toml content should contain endpoint"
|
"config.toml content should contain endpoint"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
config_text.contains("model = \"gpt-4o\""),
|
config_text.contains("model = \"gpt-4o\""),
|
||||||
"config.toml content should contain model setting"
|
"config.toml content should contain model setting"
|
||||||
);
|
);
|
||||||
drop(guard);
|
|
||||||
|
|
||||||
let config_path = home.join(".cc-switch").join("config.json");
|
|
||||||
assert!(
|
|
||||||
config_path.exists(),
|
|
||||||
"importing provider from deeplink should persist config.json"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { AppId } from "@/lib/api";
|
import type { AppId } from "@/lib/api";
|
||||||
import { ClaudeIcon, CodexIcon, GeminiIcon } from "./BrandIcons";
|
import { ProviderIcon } from "@/components/ProviderIcon";
|
||||||
|
|
||||||
interface AppSwitcherProps {
|
interface AppSwitcherProps {
|
||||||
activeApp: AppId;
|
activeApp: AppId;
|
||||||
@@ -11,6 +11,17 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
if (app === activeApp) return;
|
if (app === activeApp) return;
|
||||||
onSwitch(app);
|
onSwitch(app);
|
||||||
};
|
};
|
||||||
|
const iconSize = 20;
|
||||||
|
const appIconName: Record<AppId, string> = {
|
||||||
|
claude: "claude",
|
||||||
|
codex: "openai",
|
||||||
|
gemini: "gemini",
|
||||||
|
};
|
||||||
|
const appDisplayName: Record<AppId, string> = {
|
||||||
|
claude: "Claude",
|
||||||
|
codex: "Codex",
|
||||||
|
gemini: "Gemini",
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1 gap-1">
|
<div className="inline-flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1 gap-1">
|
||||||
@@ -23,15 +34,17 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<ClaudeIcon
|
<ProviderIcon
|
||||||
size={16}
|
icon={appIconName.claude}
|
||||||
|
name={appDisplayName.claude}
|
||||||
|
size={iconSize}
|
||||||
className={
|
className={
|
||||||
activeApp === "claude"
|
activeApp === "claude"
|
||||||
? "text-foreground"
|
? "text-foreground"
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>Claude</span>
|
<span>{appDisplayName.claude}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -43,15 +56,17 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<CodexIcon
|
<ProviderIcon
|
||||||
size={16}
|
icon={appIconName.codex}
|
||||||
|
name={appDisplayName.codex}
|
||||||
|
size={iconSize}
|
||||||
className={
|
className={
|
||||||
activeApp === "codex"
|
activeApp === "codex"
|
||||||
? "text-foreground"
|
? "text-foreground"
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>Codex</span>
|
<span>{appDisplayName.codex}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -63,15 +78,17 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<GeminiIcon
|
<ProviderIcon
|
||||||
size={16}
|
icon={appIconName.gemini}
|
||||||
|
name={appDisplayName.gemini}
|
||||||
|
size={iconSize}
|
||||||
className={
|
className={
|
||||||
activeApp === "gemini"
|
activeApp === "gemini"
|
||||||
? "text-foreground"
|
? "text-foreground"
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>Gemini</span>
|
<span>{appDisplayName.gemini}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { PromptConfirmation } from "./deeplink/PromptConfirmation";
|
||||||
|
import { McpConfirmation } from "./deeplink/McpConfirmation";
|
||||||
|
import { SkillConfirmation } from "./deeplink/SkillConfirmation";
|
||||||
|
import { ProviderIcon } from "./ProviderIcon";
|
||||||
|
|
||||||
interface DeeplinkError {
|
interface DeeplinkError {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -26,6 +30,24 @@ export function DeepLinkImportDialog() {
|
|||||||
const [isImporting, setIsImporting] = useState(false);
|
const [isImporting, setIsImporting] = useState(false);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
// 容错判断:MCP 导入结果可能缺少 type 字段
|
||||||
|
const isMcpImportResult = (
|
||||||
|
value: unknown,
|
||||||
|
): value is {
|
||||||
|
importedCount: number;
|
||||||
|
importedIds: string[];
|
||||||
|
failed: Array<{ id: string; error: string }>;
|
||||||
|
type?: "mcp";
|
||||||
|
} => {
|
||||||
|
if (!value || typeof value !== "object") return false;
|
||||||
|
const v = value as Record<string, unknown>;
|
||||||
|
return (
|
||||||
|
typeof v.importedCount === "number" &&
|
||||||
|
Array.isArray(v.importedIds) &&
|
||||||
|
Array.isArray(v.failed)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Listen for deep link import events
|
// Listen for deep link import events
|
||||||
const unlistenImport = listen<DeepLinkImportRequest>(
|
const unlistenImport = listen<DeepLinkImportRequest>(
|
||||||
@@ -78,22 +100,89 @@ export function DeepLinkImportDialog() {
|
|||||||
setIsImporting(true);
|
setIsImporting(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deeplinkApi.importFromDeeplink(request);
|
const result = await deeplinkApi.importFromDeeplink(request);
|
||||||
|
const refreshMcp = async (summary: {
|
||||||
|
importedCount: number;
|
||||||
|
importedIds: string[];
|
||||||
|
failed: Array<{ id: string; error: string }>;
|
||||||
|
}) => {
|
||||||
|
// 强制刷新 MCP 相关缓存,确保管理页重新从数据库加载
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ["mcp", "all"],
|
||||||
|
refetchType: "all",
|
||||||
|
});
|
||||||
|
await queryClient.refetchQueries({
|
||||||
|
queryKey: ["mcp", "all"],
|
||||||
|
type: "all",
|
||||||
|
});
|
||||||
|
|
||||||
// Invalidate provider queries to refresh the list
|
if (summary.failed.length > 0) {
|
||||||
await queryClient.invalidateQueries({
|
toast.warning(`部分导入成功`, {
|
||||||
queryKey: ["providers", request.app],
|
description: `成功: ${summary.importedCount}, 失败: ${summary.failed.length}`,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
toast.success("MCP Servers 导入成功", {
|
||||||
|
description: `成功导入 ${summary.importedCount} 个服务器`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
toast.success(t("deeplink.importSuccess"), {
|
// Handle different result types
|
||||||
description: t("deeplink.importSuccessDescription", {
|
if ("type" in result) {
|
||||||
name: request.name,
|
if (result.type === "provider") {
|
||||||
}),
|
await queryClient.invalidateQueries({
|
||||||
});
|
queryKey: ["providers", request.app],
|
||||||
|
});
|
||||||
|
toast.success(t("deeplink.importSuccess"), {
|
||||||
|
description: t("deeplink.importSuccessDescription", {
|
||||||
|
name: request.name,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} else if (result.type === "prompt") {
|
||||||
|
// Prompts don't use React Query, trigger a custom event for refresh
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent("prompt-imported", {
|
||||||
|
detail: { app: request.app },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
toast.success("提示词导入成功", {
|
||||||
|
description: `已导入提示词: ${request.name}`,
|
||||||
|
});
|
||||||
|
} else if (result.type === "mcp") {
|
||||||
|
await refreshMcp(result);
|
||||||
|
} else if (result.type === "skill") {
|
||||||
|
// Refresh Skills with aggressive strategy
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["skills"],
|
||||||
|
refetchType: "all",
|
||||||
|
});
|
||||||
|
await queryClient.refetchQueries({
|
||||||
|
queryKey: ["skills"],
|
||||||
|
type: "all",
|
||||||
|
});
|
||||||
|
toast.success("Skill 仓库添加成功", {
|
||||||
|
description: `已添加仓库: ${request.repo}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (isMcpImportResult(result)) {
|
||||||
|
// 兜底处理:旧版本后端可能未返回 type 字段
|
||||||
|
await refreshMcp(result);
|
||||||
|
} else {
|
||||||
|
// Legacy return type (string ID) - assume provider
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ["providers", request.app],
|
||||||
|
});
|
||||||
|
toast.success(t("deeplink.importSuccess"), {
|
||||||
|
description: t("deeplink.importSuccessDescription", {
|
||||||
|
name: request.name,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close dialog after all refreshes complete
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to import provider from deep link:", error);
|
console.error("Failed to import from deep link:", error);
|
||||||
toast.error(t("deeplink.importError"), {
|
toast.error(t("deeplink.importError"), {
|
||||||
description: error instanceof Error ? error.message : String(error),
|
description: error instanceof Error ? error.message : String(error),
|
||||||
});
|
});
|
||||||
@@ -189,6 +278,34 @@ export function DeepLinkImportDialog() {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getTitle = () => {
|
||||||
|
if (!request) return t("deeplink.confirmImport");
|
||||||
|
switch (request.resource) {
|
||||||
|
case "prompt":
|
||||||
|
return "导入提示词";
|
||||||
|
case "mcp":
|
||||||
|
return "导入 MCP Servers";
|
||||||
|
case "skill":
|
||||||
|
return "添加 Skill 仓库";
|
||||||
|
default:
|
||||||
|
return t("deeplink.confirmImport");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDescription = () => {
|
||||||
|
if (!request) return t("deeplink.confirmImportDescription");
|
||||||
|
switch (request.resource) {
|
||||||
|
case "prompt":
|
||||||
|
return "请确认是否导入此系统提示词";
|
||||||
|
case "mcp":
|
||||||
|
return "请确认是否导入这些 MCP Servers";
|
||||||
|
case "skill":
|
||||||
|
return "请确认是否添加此 Skill 仓库";
|
||||||
|
default:
|
||||||
|
return t("deeplink.confirmImportDescription");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen && !!request} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen && !!request} onOpenChange={setIsOpen}>
|
||||||
<DialogContent className="sm:max-w-[500px]" zIndex="top">
|
<DialogContent className="sm:max-w-[500px]" zIndex="top">
|
||||||
@@ -196,200 +313,197 @@ export function DeepLinkImportDialog() {
|
|||||||
<>
|
<>
|
||||||
{/* 标题显式左对齐,避免默认居中样式影响 */}
|
{/* 标题显式左对齐,避免默认居中样式影响 */}
|
||||||
<DialogHeader className="text-left sm:text-left">
|
<DialogHeader className="text-left sm:text-left">
|
||||||
<DialogTitle>{t("deeplink.confirmImport")}</DialogTitle>
|
<DialogTitle>{getTitle()}</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>{getDescription()}</DialogDescription>
|
||||||
{t("deeplink.confirmImportDescription")}
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
{/* 主体内容整体右移,略大于标题内边距,让内容看起来不贴边 */}
|
{/* 主体内容整体右移,略大于标题内边距,让内容看起来不贴边 */}
|
||||||
<div className="space-y-4 px-8 py-4 max-h-[60vh] overflow-y-auto [scrollbar-width:thin] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:block [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-gray-200 dark:[&::-webkit-scrollbar-thumb]:bg-gray-700">
|
<div className="space-y-4 px-8 py-4 max-h-[60vh] overflow-y-auto [scrollbar-width:thin] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:block [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-gray-200 dark:[&::-webkit-scrollbar-thumb]:bg-gray-700">
|
||||||
{/* App Type */}
|
{request.resource === "prompt" && (
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
<PromptConfirmation request={request} />
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
)}
|
||||||
{t("deeplink.app")}
|
{request.resource === "mcp" && (
|
||||||
</div>
|
<McpConfirmation request={request} />
|
||||||
<div className="col-span-2 text-sm font-medium capitalize">
|
)}
|
||||||
{request.app}
|
{request.resource === "skill" && (
|
||||||
</div>
|
<SkillConfirmation request={request} />
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Provider Name */}
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.providerName")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-medium">
|
|
||||||
{request.name}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Homepage */}
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.homepage")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm break-all text-blue-600 dark:text-blue-400">
|
|
||||||
{request.homepage}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* API Endpoint */}
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.endpoint")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm break-all">
|
|
||||||
{request.endpoint}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* API Key (masked) */}
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.apiKey")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono text-muted-foreground">
|
|
||||||
{maskedApiKey}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Model Fields - 根据应用类型显示不同的模型字段 */}
|
|
||||||
{request.app === "claude" ? (
|
|
||||||
<>
|
|
||||||
{/* Claude 四种模型字段 */}
|
|
||||||
{request.haikuModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.haikuModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.haikuModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.sonnetModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.sonnetModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.sonnetModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.opusModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.opusModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.opusModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.model && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.multiModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.model}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{/* Codex 和 Gemini 使用通用 model 字段 */}
|
|
||||||
{request.model && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.model")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.model}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Notes (if present) */}
|
{/* Legacy Provider View */}
|
||||||
{request.notes && (
|
{(request.resource === "provider" || !request.resource) && (
|
||||||
<div className="grid grid-cols-3 items-start gap-4">
|
<>
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
{/* Provider Icon - enlarge and center near the top */}
|
||||||
{t("deeplink.notes")}
|
{request.icon && (
|
||||||
</div>
|
<div className="flex justify-center pt-2 pb-1">
|
||||||
<div className="col-span-2 text-sm text-muted-foreground">
|
<ProviderIcon
|
||||||
{request.notes}
|
icon={request.icon}
|
||||||
</div>
|
name={request.name || request.icon}
|
||||||
</div>
|
size={80}
|
||||||
)}
|
className="drop-shadow-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Config File Details (v3.8+) */}
|
{/* App Type */}
|
||||||
{hasConfigFile && (
|
|
||||||
<div className="space-y-3 pt-2 border-t border-border-default">
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
{t("deeplink.configSource")}
|
{t("deeplink.app")}
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2 text-sm">
|
<div className="col-span-2 text-sm font-medium capitalize">
|
||||||
<span className="inline-flex items-center px-2 py-0.5 rounded-md bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 text-xs font-medium">
|
{request.app}
|
||||||
{configSource === "base64"
|
|
||||||
? t("deeplink.configEmbedded")
|
|
||||||
: t("deeplink.configRemote")}
|
|
||||||
</span>
|
|
||||||
{request.configFormat && (
|
|
||||||
<span className="ml-2 text-xs text-muted-foreground uppercase">
|
|
||||||
{request.configFormat}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Parsed Config Details */}
|
{/* Provider Name */}
|
||||||
{parsedConfig && (
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<div className="rounded-lg bg-muted/50 p-3 space-y-2">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
<div className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
{t("deeplink.providerName")}
|
||||||
{t("deeplink.configDetails")}
|
</div>
|
||||||
</div>
|
<div className="col-span-2 text-sm font-medium">
|
||||||
|
{request.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Claude config */}
|
{/* Homepage */}
|
||||||
{parsedConfig.type === "claude" && parsedConfig.env && (
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<div className="space-y-1.5">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
{Object.entries(parsedConfig.env).map(
|
{t("deeplink.homepage")}
|
||||||
([key, value]) => (
|
</div>
|
||||||
<div
|
<div className="col-span-2 text-sm break-all text-blue-600 dark:text-blue-400">
|
||||||
key={key}
|
{request.homepage}
|
||||||
className="grid grid-cols-2 gap-2 text-xs"
|
</div>
|
||||||
>
|
</div>
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
|
||||||
{key}
|
{/* API Endpoint */}
|
||||||
</span>
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<span className="font-mono truncate">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
{maskValue(key, String(value))}
|
{t("deeplink.endpoint")}
|
||||||
</span>
|
</div>
|
||||||
</div>
|
<div className="col-span-2 text-sm break-all">
|
||||||
),
|
{request.endpoint}
|
||||||
)}
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* API Key (masked) */}
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.apiKey")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono text-muted-foreground">
|
||||||
|
{maskedApiKey}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Model Fields - 根据应用类型显示不同的模型字段 */}
|
||||||
|
{request.app === "claude" ? (
|
||||||
|
<>
|
||||||
|
{/* Claude 四种模型字段 */}
|
||||||
|
{request.haikuModel && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.haikuModel")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono">
|
||||||
|
{request.haikuModel}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{request.sonnetModel && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.sonnetModel")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono">
|
||||||
|
{request.sonnetModel}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{request.opusModel && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.opusModel")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono">
|
||||||
|
{request.opusModel}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{request.model && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.multiModel")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono">
|
||||||
|
{request.model}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{/* Codex 和 Gemini 使用通用 model 字段 */}
|
||||||
|
{request.model && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.model")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono">
|
||||||
|
{request.model}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Codex config */}
|
{/* Notes (if present) */}
|
||||||
{parsedConfig.type === "codex" && (
|
{request.notes && (
|
||||||
<div className="space-y-2">
|
<div className="grid grid-cols-3 items-start gap-4">
|
||||||
{parsedConfig.auth &&
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
Object.keys(parsedConfig.auth).length > 0 && (
|
{t("deeplink.notes")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm text-muted-foreground">
|
||||||
|
{request.notes}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Config File Details (v3.8+) */}
|
||||||
|
{hasConfigFile && (
|
||||||
|
<div className="space-y-3 pt-2 border-t border-border-default">
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.configSource")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm">
|
||||||
|
<span className="inline-flex items-center px-2 py-0.5 rounded-md bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 text-xs font-medium">
|
||||||
|
{configSource === "base64"
|
||||||
|
? t("deeplink.configEmbedded")
|
||||||
|
: t("deeplink.configRemote")}
|
||||||
|
</span>
|
||||||
|
{request.configFormat && (
|
||||||
|
<span className="ml-2 text-xs text-muted-foreground uppercase">
|
||||||
|
{request.configFormat}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Parsed Config Details */}
|
||||||
|
{parsedConfig && (
|
||||||
|
<div className="rounded-lg bg-muted/50 p-3 space-y-2">
|
||||||
|
<div className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
||||||
|
{t("deeplink.configDetails")}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Claude config */}
|
||||||
|
{parsedConfig.type === "claude" &&
|
||||||
|
parsedConfig.env && (
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<div className="text-xs text-muted-foreground">
|
{Object.entries(parsedConfig.env).map(
|
||||||
Auth:
|
|
||||||
</div>
|
|
||||||
{Object.entries(parsedConfig.auth).map(
|
|
||||||
([key, value]) => (
|
([key, value]) => (
|
||||||
<div
|
<div
|
||||||
key={key}
|
key={key}
|
||||||
className="grid grid-cols-2 gap-2 text-xs pl-2"
|
className="grid grid-cols-2 gap-2 text-xs"
|
||||||
>
|
>
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
<span className="font-mono text-muted-foreground truncate">
|
||||||
{key}
|
{key}
|
||||||
@@ -402,61 +516,92 @@ export function DeepLinkImportDialog() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{parsedConfig.tomlConfig && (
|
|
||||||
<div className="space-y-1">
|
{/* Codex config */}
|
||||||
<div className="text-xs text-muted-foreground">
|
{parsedConfig.type === "codex" && (
|
||||||
TOML Config:
|
<div className="space-y-2">
|
||||||
</div>
|
{parsedConfig.auth &&
|
||||||
<pre className="text-xs font-mono bg-background p-2 rounded overflow-x-auto max-h-24 whitespace-pre-wrap">
|
Object.keys(parsedConfig.auth).length > 0 && (
|
||||||
{parsedConfig.tomlConfig.substring(0, 300)}
|
<div className="space-y-1.5">
|
||||||
{parsedConfig.tomlConfig.length > 300 && "..."}
|
<div className="text-xs text-muted-foreground">
|
||||||
</pre>
|
Auth:
|
||||||
|
</div>
|
||||||
|
{Object.entries(parsedConfig.auth).map(
|
||||||
|
([key, value]) => (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className="grid grid-cols-2 gap-2 text-xs pl-2"
|
||||||
|
>
|
||||||
|
<span className="font-mono text-muted-foreground truncate">
|
||||||
|
{key}
|
||||||
|
</span>
|
||||||
|
<span className="font-mono truncate">
|
||||||
|
{maskValue(key, String(value))}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{parsedConfig.tomlConfig && (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<div className="text-xs text-muted-foreground">
|
||||||
|
TOML Config:
|
||||||
|
</div>
|
||||||
|
<pre className="text-xs font-mono bg-background p-2 rounded overflow-x-auto max-h-24 whitespace-pre-wrap">
|
||||||
|
{parsedConfig.tomlConfig.substring(0, 300)}
|
||||||
|
{parsedConfig.tomlConfig.length > 300 &&
|
||||||
|
"..."}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Gemini config */}
|
{/* Gemini config */}
|
||||||
{parsedConfig.type === "gemini" && parsedConfig.env && (
|
{parsedConfig.type === "gemini" &&
|
||||||
<div className="space-y-1.5">
|
parsedConfig.env && (
|
||||||
{Object.entries(parsedConfig.env).map(
|
<div className="space-y-1.5">
|
||||||
([key, value]) => (
|
{Object.entries(parsedConfig.env).map(
|
||||||
<div
|
([key, value]) => (
|
||||||
key={key}
|
<div
|
||||||
className="grid grid-cols-2 gap-2 text-xs"
|
key={key}
|
||||||
>
|
className="grid grid-cols-2 gap-2 text-xs"
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
>
|
||||||
{key}
|
<span className="font-mono text-muted-foreground truncate">
|
||||||
</span>
|
{key}
|
||||||
<span className="font-mono truncate">
|
</span>
|
||||||
{maskValue(key, String(value))}
|
<span className="font-mono truncate">
|
||||||
</span>
|
{maskValue(key, String(value))}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
),
|
)}
|
||||||
)}
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Config URL (if remote) */}
|
||||||
|
{request.configUrl && (
|
||||||
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
|
{t("deeplink.configUrl")}
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2 text-sm font-mono text-muted-foreground break-all">
|
||||||
|
{request.configUrl}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Config URL (if remote) */}
|
{/* Warning */}
|
||||||
{request.configUrl && (
|
<div className="rounded-lg bg-yellow-50 dark:bg-yellow-900/20 p-3 text-sm text-yellow-800 dark:text-yellow-200">
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
{t("deeplink.warning")}
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
</div>
|
||||||
{t("deeplink.configUrl")}
|
</>
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono text-muted-foreground break-all">
|
|
||||||
{request.configUrl}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Warning */}
|
|
||||||
<div className="rounded-lg bg-yellow-50 dark:bg-yellow-900/20 p-3 text-sm text-yellow-800 dark:text-yellow-200">
|
|
||||||
{t("deeplink.warning")}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
|||||||
return {
|
return {
|
||||||
width: sizeValue,
|
width: sizeValue,
|
||||||
height: sizeValue,
|
height: sizeValue,
|
||||||
|
// 内嵌 SVG 使用 1em 作为尺寸基准,这里同步 fontSize 让图标实际跟随 size 放大
|
||||||
|
fontSize: sizeValue,
|
||||||
|
lineHeight: 1,
|
||||||
};
|
};
|
||||||
}, [size]);
|
}, [size]);
|
||||||
|
|
||||||
@@ -57,6 +60,8 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
|||||||
.join("")
|
.join("")
|
||||||
.toUpperCase()
|
.toUpperCase()
|
||||||
.slice(0, 2);
|
.slice(0, 2);
|
||||||
|
const fallbackFontSize =
|
||||||
|
typeof size === "number" ? `${Math.max(size * 0.5, 12)}px` : "0.5em";
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -68,7 +73,7 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
fontSize: `${typeof size === "number" ? size * 0.4 : 14}px`,
|
fontSize: fallbackFontSize,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{initials}
|
{initials}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
||||||
|
import { decodeBase64Utf8 } from "../../lib/utils/base64";
|
||||||
|
|
||||||
|
export function McpConfirmation({
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
request: DeepLinkImportRequest;
|
||||||
|
}) {
|
||||||
|
const mcpServers = useMemo(() => {
|
||||||
|
if (!request.config) return null;
|
||||||
|
try {
|
||||||
|
const decoded = decodeBase64Utf8(request.config);
|
||||||
|
const parsed = JSON.parse(decoded);
|
||||||
|
return parsed.mcpServers || {};
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse MCP config:", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, [request.config]);
|
||||||
|
|
||||||
|
const targetApps = request.apps?.split(",") || [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-lg font-semibold">批量导入 MCP Servers</h3>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
目标应用
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 flex gap-2 flex-wrap">
|
||||||
|
{targetApps.map((app) => (
|
||||||
|
<span
|
||||||
|
key={app}
|
||||||
|
className="px-2 py-1 bg-primary/10 text-primary text-xs rounded capitalize"
|
||||||
|
>
|
||||||
|
{app.trim()}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
MCP Servers ({Object.keys(mcpServers || {}).length} 个)
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 space-y-2 max-h-64 overflow-auto border rounded p-2 bg-muted/30">
|
||||||
|
{mcpServers &&
|
||||||
|
Object.entries(mcpServers).map(([id, spec]: [string, any]) => (
|
||||||
|
<div key={id} className="p-2 bg-background rounded border">
|
||||||
|
<div className="font-semibold text-sm">{id}</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-1 font-mono truncate">
|
||||||
|
{spec.command
|
||||||
|
? `Command: ${spec.command} `
|
||||||
|
: `URL: ${spec.url} `}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{request.enabled && (
|
||||||
|
<div className="text-yellow-600 dark:text-yellow-500 text-sm flex items-center gap-2">
|
||||||
|
<span>⚠️</span>
|
||||||
|
<span>导入后将立即写入所有指定应用的配置文件</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
||||||
|
import { decodeBase64Utf8 } from "../../lib/utils/base64";
|
||||||
|
|
||||||
|
export function PromptConfirmation({
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
request: DeepLinkImportRequest;
|
||||||
|
}) {
|
||||||
|
const decodedContent = useMemo(() => {
|
||||||
|
if (!request.content) return "";
|
||||||
|
return decodeBase64Utf8(request.content);
|
||||||
|
}, [request.content]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-lg font-semibold">导入系统提示词</h3>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
应用
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm capitalize">{request.app}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
名称
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm">{request.name}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{request.description && (
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
描述
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm">{request.description}</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
内容预览
|
||||||
|
</label>
|
||||||
|
<pre className="mt-1 max-h-48 overflow-auto bg-muted/50 p-2 rounded text-xs whitespace-pre-wrap border">
|
||||||
|
{decodedContent.substring(0, 500)}
|
||||||
|
{decodedContent.length > 500 && "..."}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{request.enabled && (
|
||||||
|
<div className="text-yellow-600 dark:text-yellow-500 text-sm flex items-center gap-2">
|
||||||
|
<span>⚠️</span>
|
||||||
|
<span>导入后将立即启用此提示词,其他提示词将被禁用</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
||||||
|
|
||||||
|
export function SkillConfirmation({
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
request: DeepLinkImportRequest;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-lg font-semibold">添加 Claude Skill 仓库</h3>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
GitHub 仓库
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm font-mono bg-muted/50 p-2 rounded border">
|
||||||
|
{request.repo}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
目标目录
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm font-mono bg-muted/50 p-2 rounded border">
|
||||||
|
{request.directory}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
分支
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm">{request.branch || "main"}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{request.skillsPath && (
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-muted-foreground">
|
||||||
|
Skills 路径
|
||||||
|
</label>
|
||||||
|
<div className="mt-1 text-sm">{request.skillsPath}</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-blue-600 dark:text-blue-400 text-sm bg-blue-50 dark:bg-blue-950/30 p-3 rounded border border-blue-200 dark:border-blue-800">
|
||||||
|
<p>ℹ️ 此操作将添加 Skill 仓库到列表。</p>
|
||||||
|
<p className="mt-1">
|
||||||
|
添加后,您可以在 Skills 管理界面中选择安装具体的 Skill。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -43,6 +43,22 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
if (open) reload();
|
if (open) reload();
|
||||||
}, [open, reload]);
|
}, [open, reload]);
|
||||||
|
|
||||||
|
// Listen for prompt import events from deep link
|
||||||
|
useEffect(() => {
|
||||||
|
const handlePromptImported = (event: Event) => {
|
||||||
|
const customEvent = event as CustomEvent;
|
||||||
|
// Reload if the import is for this app
|
||||||
|
if (customEvent.detail?.app === appId) {
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("prompt-imported", handlePromptImported);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("prompt-imported", handlePromptImported);
|
||||||
|
};
|
||||||
|
}, [appId, reload]);
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
setEditingId(null);
|
setEditingId(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
|
|||||||
@@ -141,12 +141,12 @@ export function ProviderCard({
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* 供应商图标 */}
|
{/* 供应商图标 */}
|
||||||
<div className="h-9 w-9 rounded-lg bg-white/5 flex items-center justify-center border border-gray-200 dark:border-white/10 group-hover:scale-105 transition-transform duration-300">
|
<div className="h-8 w-8 rounded-lg bg-white/5 flex items-center justify-center border border-gray-200 dark:border-white/10 group-hover:scale-105 transition-transform duration-300">
|
||||||
<ProviderIcon
|
<ProviderIcon
|
||||||
icon={provider.icon}
|
icon={provider.icon}
|
||||||
name={provider.name}
|
name={provider.name}
|
||||||
color={provider.iconColor}
|
color={provider.iconColor}
|
||||||
size={26}
|
size={20}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 overflow-y-auto">
|
<div className="flex-1 overflow-y-auto">
|
||||||
<div className="space-y-6 mx-auto max-w-[56rem] px-6 py-6 w-full">
|
<div className="space-y-2 mx-auto max-w-[56rem] px-6 py-6 w-full">
|
||||||
<IconPicker
|
<IconPicker
|
||||||
value={currentIcon}
|
value={currentIcon}
|
||||||
onValueChange={handleIconSelect}
|
onValueChange={handleIconSelect}
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ import {
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
import { RefreshCw, Search } from "lucide-react";
|
import { RefreshCw, Search } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { SkillCard } from "./SkillCard";
|
import { SkillCard } from "./SkillCard";
|
||||||
@@ -32,6 +39,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [repoManagerOpen, setRepoManagerOpen] = useState(false);
|
const [repoManagerOpen, setRepoManagerOpen] = useState(false);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [filterStatus, setFilterStatus] = useState<
|
||||||
|
"all" | "installed" | "uninstalled"
|
||||||
|
>("all");
|
||||||
|
|
||||||
const loadSkills = async (afterLoad?: (data: Skill[]) => void) => {
|
const loadSkills = async (afterLoad?: (data: Skill[]) => void) => {
|
||||||
try {
|
try {
|
||||||
@@ -172,10 +182,16 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
|
|
||||||
// 过滤技能列表
|
// 过滤技能列表
|
||||||
const filteredSkills = useMemo(() => {
|
const filteredSkills = useMemo(() => {
|
||||||
if (!searchQuery.trim()) return skills;
|
const byStatus = skills.filter((skill) => {
|
||||||
|
if (filterStatus === "installed") return skill.installed;
|
||||||
|
if (filterStatus === "uninstalled") return !skill.installed;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!searchQuery.trim()) return byStatus;
|
||||||
|
|
||||||
const query = searchQuery.toLowerCase();
|
const query = searchQuery.toLowerCase();
|
||||||
return skills.filter((skill) => {
|
return byStatus.filter((skill) => {
|
||||||
const name = skill.name?.toLowerCase() || "";
|
const name = skill.name?.toLowerCase() || "";
|
||||||
const description = skill.description?.toLowerCase() || "";
|
const description = skill.description?.toLowerCase() || "";
|
||||||
const directory = skill.directory?.toLowerCase() || "";
|
const directory = skill.directory?.toLowerCase() || "";
|
||||||
@@ -186,7 +202,7 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
directory.includes(query)
|
directory.includes(query)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}, [skills, searchQuery]);
|
}, [skills, searchQuery, filterStatus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full min-h-0 bg-background/50">
|
<div className="flex flex-col h-full min-h-0 bg-background/50">
|
||||||
@@ -218,17 +234,54 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* 搜索框 */}
|
{/* 搜索框 */}
|
||||||
<div className="mb-6">
|
<div className="mb-6 flex flex-col gap-3 md:flex-row md:items-center">
|
||||||
<div className="relative">
|
<div className="relative flex-1 min-w-0">
|
||||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder={t("skills.searchPlaceholder")}
|
placeholder={t("skills.searchPlaceholder")}
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
className="pl-9"
|
className="pl-9 pr-3"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="w-full md:w-48">
|
||||||
|
<Select
|
||||||
|
value={filterStatus}
|
||||||
|
onValueChange={(val) =>
|
||||||
|
setFilterStatus(
|
||||||
|
val as "all" | "installed" | "uninstalled",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="bg-card border shadow-sm text-foreground">
|
||||||
|
<SelectValue
|
||||||
|
placeholder={t("skills.filter.placeholder")}
|
||||||
|
className="text-left"
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent className="bg-card text-foreground shadow-lg">
|
||||||
|
<SelectItem
|
||||||
|
value="all"
|
||||||
|
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
||||||
|
>
|
||||||
|
{t("skills.filter.all")}
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem
|
||||||
|
value="installed"
|
||||||
|
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
||||||
|
>
|
||||||
|
{t("skills.filter.installed")}
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem
|
||||||
|
value="uninstalled"
|
||||||
|
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
||||||
|
>
|
||||||
|
{t("skills.filter.uninstalled")}
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
{searchQuery && (
|
{searchQuery && (
|
||||||
<p className="mt-2 text-sm text-muted-foreground">
|
<p className="mt-2 text-sm text-muted-foreground">
|
||||||
{t("skills.count", { count: filteredSkills.length })}
|
{t("skills.count", { count: filteredSkills.length })}
|
||||||
|
|||||||
@@ -738,6 +738,12 @@
|
|||||||
},
|
},
|
||||||
"search": "Search Skills",
|
"search": "Search Skills",
|
||||||
"searchPlaceholder": "Search skill name or description...",
|
"searchPlaceholder": "Search skill name or description...",
|
||||||
|
"filter": {
|
||||||
|
"placeholder": "Filter by status",
|
||||||
|
"all": "All",
|
||||||
|
"installed": "Installed",
|
||||||
|
"uninstalled": "Not installed"
|
||||||
|
},
|
||||||
"noResults": "No matching skills found"
|
"noResults": "No matching skills found"
|
||||||
},
|
},
|
||||||
"deeplink": {
|
"deeplink": {
|
||||||
@@ -748,6 +754,7 @@
|
|||||||
"homepage": "Homepage",
|
"homepage": "Homepage",
|
||||||
"endpoint": "API Endpoint",
|
"endpoint": "API Endpoint",
|
||||||
"apiKey": "API Key",
|
"apiKey": "API Key",
|
||||||
|
"icon": "Icon",
|
||||||
"model": "Model",
|
"model": "Model",
|
||||||
"haikuModel": "Haiku Model",
|
"haikuModel": "Haiku Model",
|
||||||
"sonnetModel": "Sonnet Model",
|
"sonnetModel": "Sonnet Model",
|
||||||
|
|||||||
@@ -738,6 +738,12 @@
|
|||||||
},
|
},
|
||||||
"search": "搜索技能",
|
"search": "搜索技能",
|
||||||
"searchPlaceholder": "搜索技能名称或描述...",
|
"searchPlaceholder": "搜索技能名称或描述...",
|
||||||
|
"filter": {
|
||||||
|
"placeholder": "状态筛选",
|
||||||
|
"all": "全部",
|
||||||
|
"installed": "已安装",
|
||||||
|
"uninstalled": "未安装"
|
||||||
|
},
|
||||||
"noResults": "未找到匹配的技能"
|
"noResults": "未找到匹配的技能"
|
||||||
},
|
},
|
||||||
"deeplink": {
|
"deeplink": {
|
||||||
@@ -748,6 +754,7 @@
|
|||||||
"homepage": "官网地址",
|
"homepage": "官网地址",
|
||||||
"endpoint": "API 端点",
|
"endpoint": "API 端点",
|
||||||
"apiKey": "API 密钥",
|
"apiKey": "API 密钥",
|
||||||
|
"icon": "图标",
|
||||||
"model": "模型",
|
"model": "模型",
|
||||||
"haikuModel": "Haiku 模型",
|
"haikuModel": "Haiku 模型",
|
||||||
"sonnetModel": "Sonnet 模型",
|
"sonnetModel": "Sonnet 模型",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -219,6 +219,13 @@ export const iconMetadata: Record<string, IconMetadata> = {
|
|||||||
keywords: ["gpt", "chatgpt"],
|
keywords: ["gpt", "chatgpt"],
|
||||||
defaultColor: "#00A67E",
|
defaultColor: "#00A67E",
|
||||||
},
|
},
|
||||||
|
packycode: {
|
||||||
|
name: "packycode",
|
||||||
|
displayName: "PackyCode",
|
||||||
|
category: "ai-provider",
|
||||||
|
keywords: ["packycode", "packy", "packyapi"],
|
||||||
|
defaultColor: "currentColor",
|
||||||
|
},
|
||||||
palm: {
|
palm: {
|
||||||
name: "palm",
|
name: "palm",
|
||||||
displayName: "palm",
|
displayName: "palm",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.3 KiB |
+56
-15
@@ -1,25 +1,66 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
|
export type ResourceType = "provider" | "prompt" | "mcp" | "skill";
|
||||||
|
|
||||||
export interface DeepLinkImportRequest {
|
export interface DeepLinkImportRequest {
|
||||||
version: string;
|
version: string;
|
||||||
resource: string;
|
resource: ResourceType;
|
||||||
app: "claude" | "codex" | "gemini";
|
|
||||||
name: string;
|
// Common fields
|
||||||
homepage: string;
|
app?: "claude" | "codex" | "gemini";
|
||||||
endpoint: string;
|
name?: string;
|
||||||
apiKey: string;
|
enabled?: boolean;
|
||||||
|
|
||||||
|
// Provider fields
|
||||||
|
homepage?: string;
|
||||||
|
endpoint?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
icon?: string;
|
||||||
model?: string;
|
model?: string;
|
||||||
notes?: string;
|
notes?: string;
|
||||||
// Claude 专用模型字段 (v3.7.1+)
|
|
||||||
haikuModel?: string;
|
haikuModel?: string;
|
||||||
sonnetModel?: string;
|
sonnetModel?: string;
|
||||||
opusModel?: string;
|
opusModel?: string;
|
||||||
// 配置文件导入字段 (v3.8+)
|
|
||||||
config?: string; // Base64 编码的配置内容
|
// Prompt fields
|
||||||
configFormat?: string; // json/toml
|
content?: string;
|
||||||
configUrl?: string; // 远程配置 URL
|
description?: string;
|
||||||
|
|
||||||
|
// MCP fields
|
||||||
|
apps?: string; // "claude,codex,gemini"
|
||||||
|
|
||||||
|
// Skill fields
|
||||||
|
repo?: string;
|
||||||
|
directory?: string;
|
||||||
|
branch?: string;
|
||||||
|
skillsPath?: string;
|
||||||
|
|
||||||
|
// Config file fields
|
||||||
|
config?: string;
|
||||||
|
configFormat?: string;
|
||||||
|
configUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface McpImportResult {
|
||||||
|
importedCount: number;
|
||||||
|
importedIds: string[];
|
||||||
|
failed: Array<{
|
||||||
|
id: string;
|
||||||
|
error: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ImportResult =
|
||||||
|
| { type: "provider"; id: string }
|
||||||
|
| { type: "prompt"; id: string }
|
||||||
|
| {
|
||||||
|
type: "mcp";
|
||||||
|
importedCount: number;
|
||||||
|
importedIds: string[];
|
||||||
|
failed: Array<{ id: string; error: string }>;
|
||||||
|
}
|
||||||
|
| { type: "skill"; key: string };
|
||||||
|
|
||||||
export const deeplinkApi = {
|
export const deeplinkApi = {
|
||||||
/**
|
/**
|
||||||
* Parse a deep link URL
|
* Parse a deep link URL
|
||||||
@@ -43,13 +84,13 @@ export const deeplinkApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import a provider from a deep link request
|
* Import a resource from a deep link request (unified handler)
|
||||||
* @param request The deep link import request
|
* @param request The deep link import request
|
||||||
* @returns The ID of the imported provider
|
* @returns Import result based on resource type
|
||||||
*/
|
*/
|
||||||
importFromDeeplink: async (
|
importFromDeeplink: async (
|
||||||
request: DeepLinkImportRequest,
|
request: DeepLinkImportRequest,
|
||||||
): Promise<string> => {
|
): Promise<ImportResult> => {
|
||||||
return invoke("import_from_deeplink", { request });
|
return invoke("import_from_deeplink_unified", { request });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Decode Base64 encoded UTF-8 string
|
||||||
|
*
|
||||||
|
* This function handles various Base64 edge cases that can occur when
|
||||||
|
* Base64 strings are passed through URLs:
|
||||||
|
* - Spaces (URL parsing may convert '+' to space)
|
||||||
|
* - Missing padding ('=' characters)
|
||||||
|
* - Different Base64 variants
|
||||||
|
*
|
||||||
|
* @param str - Base64 encoded string
|
||||||
|
* @returns Decoded UTF-8 string
|
||||||
|
*/
|
||||||
|
export function decodeBase64Utf8(str: string): string {
|
||||||
|
try {
|
||||||
|
// Clean up the input: replace spaces with + (URL parsing may convert + to space)
|
||||||
|
let cleaned = str.trim().replace(/ /g, "+");
|
||||||
|
|
||||||
|
// Try to decode with standard Base64 first
|
||||||
|
try {
|
||||||
|
const binString = atob(cleaned);
|
||||||
|
const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0)!);
|
||||||
|
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
||||||
|
} catch (e1) {
|
||||||
|
// If standard fails, try adding padding
|
||||||
|
const remainder = cleaned.length % 4;
|
||||||
|
if (remainder !== 0) {
|
||||||
|
cleaned += "=".repeat(4 - remainder);
|
||||||
|
}
|
||||||
|
const binString = atob(cleaned);
|
||||||
|
const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0)!);
|
||||||
|
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Base64 decode error:", e, "Input:", str);
|
||||||
|
// Last resort fallback using deprecated but sometimes working method
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(escape(atob(str.replace(/ /g, "+"))));
|
||||||
|
} catch {
|
||||||
|
// If all else fails, return original string
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user