mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-25 19:32:39 +08:00
Compare commits
79 Commits
fix/openco
...
refactor/s
| 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
deplink.html
1041
deplink.html
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ const KEEP_LIST = [
|
||||
'zhipu', 'chatglm', 'glm', 'minimax', 'mistral', 'cohere',
|
||||
'perplexity', 'huggingface', 'midjourney', 'stability',
|
||||
'xai', 'grok', 'yi', 'zeroone', 'ollama',
|
||||
'packycode',
|
||||
|
||||
// Cloud/Tools
|
||||
'aws', 'googlecloud', 'huawei', 'cloudflare',
|
||||
|
||||
@@ -24,6 +24,7 @@ const KNOWN_METADATA = {
|
||||
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' },
|
||||
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' },
|
||||
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' },
|
||||
|
||||
@@ -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 tauri::State;
|
||||
|
||||
@@ -15,18 +18,18 @@ pub fn parse_deeplink(url: String) -> Result<DeepLinkImportRequest, String> {
|
||||
pub fn merge_deeplink_config(
|
||||
request: DeepLinkImportRequest,
|
||||
) -> 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())
|
||||
}
|
||||
|
||||
/// 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]
|
||||
pub fn import_from_deeplink(
|
||||
state: State<AppState>,
|
||||
request: DeepLinkImportRequest,
|
||||
) -> Result<String, String> {
|
||||
log::info!(
|
||||
"Importing provider from deep link: {} for app {}",
|
||||
"Importing provider from deep link: {:?} for app {:?}",
|
||||
request.name,
|
||||
request.app
|
||||
);
|
||||
@@ -37,3 +40,50 @@ pub fn import_from_deeplink(
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
/// 创建内存数据库(用于测试)
|
||||
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> {
|
||||
let conn = lock_conn!(self.conn);
|
||||
Self::create_tables_on_conn(&conn)
|
||||
@@ -373,8 +389,8 @@ impl Database {
|
||||
// 导出 schema
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT type, name, tbl_name, sql
|
||||
FROM sqlite_master
|
||||
"SELECT type, name, tbl_name, sql
|
||||
FROM sqlite_master
|
||||
WHERE sql NOT NULL AND type IN ('table','index','trigger','view')
|
||||
ORDER BY type='table' DESC, name",
|
||||
)
|
||||
@@ -500,7 +516,7 @@ impl Database {
|
||||
|
||||
tx.execute(
|
||||
"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
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
||||
params![
|
||||
@@ -793,7 +809,7 @@ impl Database {
|
||||
|
||||
tx.execute(
|
||||
"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
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)",
|
||||
params![
|
||||
|
||||
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 commands::*;
|
||||
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 error::AppError;
|
||||
pub use mcp::{
|
||||
@@ -314,7 +315,7 @@ fn handle_deeplink_url(
|
||||
match crate::deeplink::parse_deeplink_url(url_str) {
|
||||
Ok(request) => {
|
||||
log::info!(
|
||||
"✓ Successfully parsed deep link: resource={}, app={}, name={}",
|
||||
"✓ Successfully parsed deep link: resource={}, app={:?}, name={:?}",
|
||||
request.resource,
|
||||
request.app,
|
||||
request.name
|
||||
@@ -840,6 +841,7 @@ pub fn run() {
|
||||
commands::parse_deeplink,
|
||||
commands::merge_deeplink_config,
|
||||
commands::import_from_deeplink,
|
||||
commands::import_from_deeplink_unified,
|
||||
update_tray_menu,
|
||||
// Environment variable management
|
||||
commands::check_env_conflicts,
|
||||
@@ -889,7 +891,7 @@ pub fn run() {
|
||||
match crate::deeplink::parse_deeplink_url(&url_str) {
|
||||
Ok(request) => {
|
||||
log::info!(
|
||||
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={}",
|
||||
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={:?}",
|
||||
request.resource,
|
||||
request.app
|
||||
);
|
||||
|
||||
@@ -1,46 +1,36 @@
|
||||
use std::sync::RwLock;
|
||||
use std::sync::Arc;
|
||||
|
||||
use cc_switch_lib::{
|
||||
import_provider_from_deeplink, parse_deeplink_url, AppState, AppType, MultiAppConfig,
|
||||
};
|
||||
use cc_switch_lib::{import_provider_from_deeplink, parse_deeplink_url, AppState, Database};
|
||||
|
||||
#[path = "support.rs"]
|
||||
mod support;
|
||||
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
||||
|
||||
#[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");
|
||||
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 mut config = MultiAppConfig::default();
|
||||
config.ensure_app(&AppType::Claude);
|
||||
let db = Arc::new(Database::memory().expect("create memory db"));
|
||||
|
||||
let state = AppState {
|
||||
config: RwLock::new(config),
|
||||
};
|
||||
let state = AppState { db: db.clone() };
|
||||
|
||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||
.expect("import provider from deeplink");
|
||||
|
||||
// 验证内存状态
|
||||
let guard = state.config.read().expect("read config");
|
||||
let manager = guard
|
||||
.get_manager(&AppType::Claude)
|
||||
.expect("claude manager should exist");
|
||||
let provider = manager
|
||||
.providers
|
||||
// Verify DB state
|
||||
let providers = db.get_all_providers("claude").expect("get providers");
|
||||
let provider = providers
|
||||
.get(&provider_id)
|
||||
.expect("provider created via deeplink");
|
||||
assert_eq!(provider.name, request.name);
|
||||
assert_eq!(
|
||||
provider.website_url.as_deref(),
|
||||
Some(request.homepage.as_str())
|
||||
);
|
||||
|
||||
assert_eq!(provider.name, request.name.clone().unwrap());
|
||||
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
||||
assert_eq!(provider.icon.as_deref(), Some("claude"));
|
||||
let auth_token = provider
|
||||
.settings_config
|
||||
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
||||
@@ -49,50 +39,34 @@ fn deeplink_import_claude_provider_persists_to_config() {
|
||||
.settings_config
|
||||
.pointer("/env/ANTHROPIC_BASE_URL")
|
||||
.and_then(|v| v.as_str());
|
||||
assert_eq!(auth_token, Some(request.api_key.as_str()));
|
||||
assert_eq!(base_url, Some(request.endpoint.as_str()));
|
||||
drop(guard);
|
||||
|
||||
// 验证配置已持久化
|
||||
let config_path = home.join(".cc-switch").join("config.json");
|
||||
assert!(
|
||||
config_path.exists(),
|
||||
"importing provider from deeplink should persist config.json"
|
||||
);
|
||||
assert_eq!(auth_token, request.api_key.as_deref());
|
||||
assert_eq!(base_url, request.endpoint.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
||||
let _guard = test_mutex().lock().expect("acquire test mutex");
|
||||
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 mut config = MultiAppConfig::default();
|
||||
config.ensure_app(&AppType::Codex);
|
||||
let db = Arc::new(Database::memory().expect("create memory db"));
|
||||
|
||||
let state = AppState {
|
||||
config: RwLock::new(config),
|
||||
};
|
||||
let state = AppState { db: db.clone() };
|
||||
|
||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||
.expect("import provider from deeplink");
|
||||
|
||||
let guard = state.config.read().expect("read config");
|
||||
let manager = guard
|
||||
.get_manager(&AppType::Codex)
|
||||
.expect("codex manager should exist");
|
||||
let provider = manager
|
||||
.providers
|
||||
let providers = db.get_all_providers("codex").expect("get providers");
|
||||
let provider = providers
|
||||
.get(&provider_id)
|
||||
.expect("provider created via deeplink");
|
||||
assert_eq!(provider.name, request.name);
|
||||
assert_eq!(
|
||||
provider.website_url.as_deref(),
|
||||
Some(request.homepage.as_str())
|
||||
);
|
||||
|
||||
assert_eq!(provider.name, request.name.clone().unwrap());
|
||||
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
||||
assert_eq!(provider.icon.as_deref(), Some("openai"));
|
||||
let auth_value = provider
|
||||
.settings_config
|
||||
.pointer("/auth/OPENAI_API_KEY")
|
||||
@@ -102,20 +76,13 @@ fn deeplink_import_codex_provider_builds_auth_and_config() {
|
||||
.get("config")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or_default();
|
||||
assert_eq!(auth_value, Some(request.api_key.as_str()));
|
||||
assert_eq!(auth_value, request.api_key.as_deref());
|
||||
assert!(
|
||||
config_text.contains(request.endpoint.as_str()),
|
||||
config_text.contains(request.endpoint.as_deref().unwrap()),
|
||||
"config.toml content should contain endpoint"
|
||||
);
|
||||
assert!(
|
||||
config_text.contains("model = \"gpt-4o\""),
|
||||
"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 { ClaudeIcon, CodexIcon, GeminiIcon } from "./BrandIcons";
|
||||
import { ProviderIcon } from "@/components/ProviderIcon";
|
||||
|
||||
interface AppSwitcherProps {
|
||||
activeApp: AppId;
|
||||
@@ -11,6 +11,17 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
||||
if (app === activeApp) return;
|
||||
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 (
|
||||
<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"
|
||||
}`}
|
||||
>
|
||||
<ClaudeIcon
|
||||
size={16}
|
||||
<ProviderIcon
|
||||
icon={appIconName.claude}
|
||||
name={appDisplayName.claude}
|
||||
size={iconSize}
|
||||
className={
|
||||
activeApp === "claude"
|
||||
? "text-foreground"
|
||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||
}
|
||||
/>
|
||||
<span>Claude</span>
|
||||
<span>{appDisplayName.claude}</span>
|
||||
</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"
|
||||
}`}
|
||||
>
|
||||
<CodexIcon
|
||||
size={16}
|
||||
<ProviderIcon
|
||||
icon={appIconName.codex}
|
||||
name={appDisplayName.codex}
|
||||
size={iconSize}
|
||||
className={
|
||||
activeApp === "codex"
|
||||
? "text-foreground"
|
||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||
}
|
||||
/>
|
||||
<span>Codex</span>
|
||||
<span>{appDisplayName.codex}</span>
|
||||
</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"
|
||||
}`}
|
||||
>
|
||||
<GeminiIcon
|
||||
size={16}
|
||||
<ProviderIcon
|
||||
icon={appIconName.gemini}
|
||||
name={appDisplayName.gemini}
|
||||
size={iconSize}
|
||||
className={
|
||||
activeApp === "gemini"
|
||||
? "text-foreground"
|
||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
||||
}
|
||||
/>
|
||||
<span>Gemini</span>
|
||||
<span>{appDisplayName.gemini}</span>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -13,6 +13,10 @@ import { Button } from "@/components/ui/button";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
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 {
|
||||
url: string;
|
||||
@@ -26,6 +30,24 @@ export function DeepLinkImportDialog() {
|
||||
const [isImporting, setIsImporting] = 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(() => {
|
||||
// Listen for deep link import events
|
||||
const unlistenImport = listen<DeepLinkImportRequest>(
|
||||
@@ -78,22 +100,89 @@ export function DeepLinkImportDialog() {
|
||||
setIsImporting(true);
|
||||
|
||||
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
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ["providers", request.app],
|
||||
});
|
||||
if (summary.failed.length > 0) {
|
||||
toast.warning(`部分导入成功`, {
|
||||
description: `成功: ${summary.importedCount}, 失败: ${summary.failed.length}`,
|
||||
});
|
||||
} else {
|
||||
toast.success("MCP Servers 导入成功", {
|
||||
description: `成功导入 ${summary.importedCount} 个服务器`,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
toast.success(t("deeplink.importSuccess"), {
|
||||
description: t("deeplink.importSuccessDescription", {
|
||||
name: request.name,
|
||||
}),
|
||||
});
|
||||
// Handle different result types
|
||||
if ("type" in result) {
|
||||
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);
|
||||
} 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"), {
|
||||
description: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
@@ -189,6 +278,34 @@ export function DeepLinkImportDialog() {
|
||||
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 (
|
||||
<Dialog open={isOpen && !!request} onOpenChange={setIsOpen}>
|
||||
<DialogContent className="sm:max-w-[500px]" zIndex="top">
|
||||
@@ -196,200 +313,197 @@ export function DeepLinkImportDialog() {
|
||||
<>
|
||||
{/* 标题显式左对齐,避免默认居中样式影响 */}
|
||||
<DialogHeader className="text-left sm:text-left">
|
||||
<DialogTitle>{t("deeplink.confirmImport")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t("deeplink.confirmImportDescription")}
|
||||
</DialogDescription>
|
||||
<DialogTitle>{getTitle()}</DialogTitle>
|
||||
<DialogDescription>{getDescription()}</DialogDescription>
|
||||
</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">
|
||||
{/* App Type */}
|
||||
<div className="grid grid-cols-3 items-center gap-4">
|
||||
<div className="font-medium text-sm text-muted-foreground">
|
||||
{t("deeplink.app")}
|
||||
</div>
|
||||
<div className="col-span-2 text-sm font-medium capitalize">
|
||||
{request.app}
|
||||
</div>
|
||||
</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>
|
||||
)}
|
||||
</>
|
||||
{request.resource === "prompt" && (
|
||||
<PromptConfirmation request={request} />
|
||||
)}
|
||||
{request.resource === "mcp" && (
|
||||
<McpConfirmation request={request} />
|
||||
)}
|
||||
{request.resource === "skill" && (
|
||||
<SkillConfirmation request={request} />
|
||||
)}
|
||||
|
||||
{/* Notes (if present) */}
|
||||
{request.notes && (
|
||||
<div className="grid grid-cols-3 items-start gap-4">
|
||||
<div className="font-medium text-sm text-muted-foreground">
|
||||
{t("deeplink.notes")}
|
||||
</div>
|
||||
<div className="col-span-2 text-sm text-muted-foreground">
|
||||
{request.notes}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{/* Legacy Provider View */}
|
||||
{(request.resource === "provider" || !request.resource) && (
|
||||
<>
|
||||
{/* Provider Icon - enlarge and center near the top */}
|
||||
{request.icon && (
|
||||
<div className="flex justify-center pt-2 pb-1">
|
||||
<ProviderIcon
|
||||
icon={request.icon}
|
||||
name={request.name || request.icon}
|
||||
size={80}
|
||||
className="drop-shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Config File Details (v3.8+) */}
|
||||
{hasConfigFile && (
|
||||
<div className="space-y-3 pt-2 border-t border-border-default">
|
||||
{/* App Type */}
|
||||
<div className="grid grid-cols-3 items-center gap-4">
|
||||
<div className="font-medium text-sm text-muted-foreground">
|
||||
{t("deeplink.configSource")}
|
||||
{t("deeplink.app")}
|
||||
</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 className="col-span-2 text-sm font-medium capitalize">
|
||||
{request.app}
|
||||
</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>
|
||||
{/* 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>
|
||||
|
||||
{/* Claude config */}
|
||||
{parsedConfig.type === "claude" && parsedConfig.env && (
|
||||
<div className="space-y-1.5">
|
||||
{Object.entries(parsedConfig.env).map(
|
||||
([key, value]) => (
|
||||
<div
|
||||
key={key}
|
||||
className="grid grid-cols-2 gap-2 text-xs"
|
||||
>
|
||||
<span className="font-mono text-muted-foreground truncate">
|
||||
{key}
|
||||
</span>
|
||||
<span className="font-mono truncate">
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
</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>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Codex config */}
|
||||
{parsedConfig.type === "codex" && (
|
||||
<div className="space-y-2">
|
||||
{parsedConfig.auth &&
|
||||
Object.keys(parsedConfig.auth).length > 0 && (
|
||||
{/* Notes (if present) */}
|
||||
{request.notes && (
|
||||
<div className="grid grid-cols-3 items-start gap-4">
|
||||
<div className="font-medium text-sm text-muted-foreground">
|
||||
{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="text-xs text-muted-foreground">
|
||||
Auth:
|
||||
</div>
|
||||
{Object.entries(parsedConfig.auth).map(
|
||||
{Object.entries(parsedConfig.env).map(
|
||||
([key, value]) => (
|
||||
<div
|
||||
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">
|
||||
{key}
|
||||
@@ -402,61 +516,92 @@ export function DeepLinkImportDialog() {
|
||||
)}
|
||||
</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>
|
||||
|
||||
{/* Codex config */}
|
||||
{parsedConfig.type === "codex" && (
|
||||
<div className="space-y-2">
|
||||
{parsedConfig.auth &&
|
||||
Object.keys(parsedConfig.auth).length > 0 && (
|
||||
<div className="space-y-1.5">
|
||||
<div className="text-xs text-muted-foreground">
|
||||
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>
|
||||
)}
|
||||
|
||||
{/* Gemini config */}
|
||||
{parsedConfig.type === "gemini" && parsedConfig.env && (
|
||||
<div className="space-y-1.5">
|
||||
{Object.entries(parsedConfig.env).map(
|
||||
([key, value]) => (
|
||||
<div
|
||||
key={key}
|
||||
className="grid grid-cols-2 gap-2 text-xs"
|
||||
>
|
||||
<span className="font-mono text-muted-foreground truncate">
|
||||
{key}
|
||||
</span>
|
||||
<span className="font-mono truncate">
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
{/* Gemini config */}
|
||||
{parsedConfig.type === "gemini" &&
|
||||
parsedConfig.env && (
|
||||
<div className="space-y-1.5">
|
||||
{Object.entries(parsedConfig.env).map(
|
||||
([key, value]) => (
|
||||
<div
|
||||
key={key}
|
||||
className="grid grid-cols-2 gap-2 text-xs"
|
||||
>
|
||||
<span className="font-mono text-muted-foreground truncate">
|
||||
{key}
|
||||
</span>
|
||||
<span className="font-mono truncate">
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
</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>
|
||||
)}
|
||||
|
||||
{/* 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>
|
||||
{/* 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>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 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>
|
||||
|
||||
<DialogFooter>
|
||||
|
||||
@@ -32,6 +32,9 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
||||
return {
|
||||
width: sizeValue,
|
||||
height: sizeValue,
|
||||
// 内嵌 SVG 使用 1em 作为尺寸基准,这里同步 fontSize 让图标实际跟随 size 放大
|
||||
fontSize: sizeValue,
|
||||
lineHeight: 1,
|
||||
};
|
||||
}, [size]);
|
||||
|
||||
@@ -57,6 +60,8 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
||||
.join("")
|
||||
.toUpperCase()
|
||||
.slice(0, 2);
|
||||
const fallbackFontSize =
|
||||
typeof size === "number" ? `${Math.max(size * 0.5, 12)}px` : "0.5em";
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
@@ -68,7 +73,7 @@ export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
fontSize: `${typeof size === "number" ? size * 0.4 : 14}px`,
|
||||
fontSize: fallbackFontSize,
|
||||
}}
|
||||
>
|
||||
{initials}
|
||||
|
||||
71
src/components/deeplink/McpConfirmation.tsx
Normal file
71
src/components/deeplink/McpConfirmation.tsx
Normal file
@@ -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>
|
||||
);
|
||||
}
|
||||
60
src/components/deeplink/PromptConfirmation.tsx
Normal file
60
src/components/deeplink/PromptConfirmation.tsx
Normal file
@@ -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>
|
||||
);
|
||||
}
|
||||
56
src/components/deeplink/SkillConfirmation.tsx
Normal file
56
src/components/deeplink/SkillConfirmation.tsx
Normal file
@@ -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();
|
||||
}, [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 = () => {
|
||||
setEditingId(null);
|
||||
setIsFormOpen(true);
|
||||
|
||||
@@ -141,12 +141,12 @@ export function ProviderCard({
|
||||
</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
|
||||
icon={provider.icon}
|
||||
name={provider.name}
|
||||
color={provider.iconColor}
|
||||
size={26}
|
||||
size={20}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
||||
</div>
|
||||
</div>
|
||||
<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
|
||||
value={currentIcon}
|
||||
onValueChange={handleIconSelect}
|
||||
|
||||
@@ -8,6 +8,13 @@ import {
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { RefreshCw, Search } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { SkillCard } from "./SkillCard";
|
||||
@@ -32,6 +39,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [repoManagerOpen, setRepoManagerOpen] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [filterStatus, setFilterStatus] = useState<
|
||||
"all" | "installed" | "uninstalled"
|
||||
>("all");
|
||||
|
||||
const loadSkills = async (afterLoad?: (data: Skill[]) => void) => {
|
||||
try {
|
||||
@@ -172,10 +182,16 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
|
||||
// 过滤技能列表
|
||||
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();
|
||||
return skills.filter((skill) => {
|
||||
return byStatus.filter((skill) => {
|
||||
const name = skill.name?.toLowerCase() || "";
|
||||
const description = skill.description?.toLowerCase() || "";
|
||||
const directory = skill.directory?.toLowerCase() || "";
|
||||
@@ -186,7 +202,7 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
directory.includes(query)
|
||||
);
|
||||
});
|
||||
}, [skills, searchQuery]);
|
||||
}, [skills, searchQuery, filterStatus]);
|
||||
|
||||
return (
|
||||
<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="relative">
|
||||
<div className="mb-6 flex flex-col gap-3 md:flex-row md:items-center">
|
||||
<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" />
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={t("skills.searchPlaceholder")}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9"
|
||||
className="pl-9 pr-3"
|
||||
/>
|
||||
</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 && (
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{t("skills.count", { count: filteredSkills.length })}
|
||||
|
||||
@@ -738,6 +738,12 @@
|
||||
},
|
||||
"search": "Search Skills",
|
||||
"searchPlaceholder": "Search skill name or description...",
|
||||
"filter": {
|
||||
"placeholder": "Filter by status",
|
||||
"all": "All",
|
||||
"installed": "Installed",
|
||||
"uninstalled": "Not installed"
|
||||
},
|
||||
"noResults": "No matching skills found"
|
||||
},
|
||||
"deeplink": {
|
||||
@@ -748,6 +754,7 @@
|
||||
"homepage": "Homepage",
|
||||
"endpoint": "API Endpoint",
|
||||
"apiKey": "API Key",
|
||||
"icon": "Icon",
|
||||
"model": "Model",
|
||||
"haikuModel": "Haiku Model",
|
||||
"sonnetModel": "Sonnet Model",
|
||||
|
||||
@@ -738,6 +738,12 @@
|
||||
},
|
||||
"search": "搜索技能",
|
||||
"searchPlaceholder": "搜索技能名称或描述...",
|
||||
"filter": {
|
||||
"placeholder": "状态筛选",
|
||||
"all": "全部",
|
||||
"installed": "已安装",
|
||||
"uninstalled": "未安装"
|
||||
},
|
||||
"noResults": "未找到匹配的技能"
|
||||
},
|
||||
"deeplink": {
|
||||
@@ -748,6 +754,7 @@
|
||||
"homepage": "官网地址",
|
||||
"endpoint": "API 端点",
|
||||
"apiKey": "API 密钥",
|
||||
"icon": "图标",
|
||||
"model": "模型",
|
||||
"haikuModel": "Haiku 模型",
|
||||
"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"],
|
||||
defaultColor: "#00A67E",
|
||||
},
|
||||
packycode: {
|
||||
name: "packycode",
|
||||
displayName: "PackyCode",
|
||||
category: "ai-provider",
|
||||
keywords: ["packycode", "packy", "packyapi"],
|
||||
defaultColor: "currentColor",
|
||||
},
|
||||
palm: {
|
||||
name: "palm",
|
||||
displayName: "palm",
|
||||
|
||||
1
src/icons/extracted/packycode.svg
Normal file
1
src/icons/extracted/packycode.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.3 KiB |
@@ -1,25 +1,66 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export type ResourceType = "provider" | "prompt" | "mcp" | "skill";
|
||||
|
||||
export interface DeepLinkImportRequest {
|
||||
version: string;
|
||||
resource: string;
|
||||
app: "claude" | "codex" | "gemini";
|
||||
name: string;
|
||||
homepage: string;
|
||||
endpoint: string;
|
||||
apiKey: string;
|
||||
resource: ResourceType;
|
||||
|
||||
// Common fields
|
||||
app?: "claude" | "codex" | "gemini";
|
||||
name?: string;
|
||||
enabled?: boolean;
|
||||
|
||||
// Provider fields
|
||||
homepage?: string;
|
||||
endpoint?: string;
|
||||
apiKey?: string;
|
||||
icon?: string;
|
||||
model?: string;
|
||||
notes?: string;
|
||||
// Claude 专用模型字段 (v3.7.1+)
|
||||
haikuModel?: string;
|
||||
sonnetModel?: string;
|
||||
opusModel?: string;
|
||||
// 配置文件导入字段 (v3.8+)
|
||||
config?: string; // Base64 编码的配置内容
|
||||
configFormat?: string; // json/toml
|
||||
configUrl?: string; // 远程配置 URL
|
||||
|
||||
// Prompt fields
|
||||
content?: string;
|
||||
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 = {
|
||||
/**
|
||||
* 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
|
||||
* @returns The ID of the imported provider
|
||||
* @returns Import result based on resource type
|
||||
*/
|
||||
importFromDeeplink: async (
|
||||
request: DeepLinkImportRequest,
|
||||
): Promise<string> => {
|
||||
return invoke("import_from_deeplink", { request });
|
||||
): Promise<ImportResult> => {
|
||||
return invoke("import_from_deeplink_unified", { request });
|
||||
},
|
||||
};
|
||||
|
||||
43
src/lib/utils/base64.ts
Normal file
43
src/lib/utils/base64.ts
Normal file
@@ -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