修复packycode无法测速以及更新滴滴车地址
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.15</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1.0</string>
|
||||
<string>1.2.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Claudia</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
|
@@ -724,3 +724,75 @@ pub async fn mcp_save_project_config(
|
||||
|
||||
Ok("Project MCP configuration saved".to_string())
|
||||
}
|
||||
|
||||
/// Export configuration for MCP server
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct MCPExportConfig {
|
||||
pub name: String,
|
||||
pub transport: String,
|
||||
pub command: Option<String>,
|
||||
pub args: Vec<String>,
|
||||
pub env: HashMap<String, String>,
|
||||
pub url: Option<String>,
|
||||
pub scope: String,
|
||||
}
|
||||
|
||||
/// Export result
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct MCPExportResult {
|
||||
pub servers: Vec<MCPExportConfig>,
|
||||
pub format: String, // "single" or "multiple"
|
||||
}
|
||||
|
||||
/// Exports all MCP servers configuration
|
||||
#[tauri::command]
|
||||
pub async fn mcp_export_servers(app: AppHandle) -> Result<MCPExportResult, String> {
|
||||
info!("Exporting MCP servers configuration");
|
||||
|
||||
// Get all servers
|
||||
let servers = mcp_list(app.clone()).await?;
|
||||
|
||||
if servers.is_empty() {
|
||||
return Ok(MCPExportResult {
|
||||
servers: vec![],
|
||||
format: "multiple".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// Get detailed information for each server
|
||||
let mut export_configs = Vec::new();
|
||||
|
||||
for server in &servers {
|
||||
match mcp_get(app.clone(), server.name.clone()).await {
|
||||
Ok(detailed_server) => {
|
||||
export_configs.push(MCPExportConfig {
|
||||
name: detailed_server.name,
|
||||
transport: detailed_server.transport,
|
||||
command: detailed_server.command,
|
||||
args: detailed_server.args,
|
||||
env: detailed_server.env,
|
||||
url: detailed_server.url,
|
||||
scope: detailed_server.scope,
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to get details for server {}: {}", server.name, e);
|
||||
// Still include basic information
|
||||
export_configs.push(MCPExportConfig {
|
||||
name: server.name.clone(),
|
||||
transport: server.transport.clone(),
|
||||
command: server.command.clone(),
|
||||
args: server.args.clone(),
|
||||
env: server.env.clone(),
|
||||
url: server.url.clone(),
|
||||
scope: server.scope.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(MCPExportResult {
|
||||
format: if export_configs.len() == 1 { "single" } else { "multiple" }.to_string(),
|
||||
servers: export_configs,
|
||||
})
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ use commands::claude::{
|
||||
use commands::mcp::{
|
||||
mcp_add, mcp_add_from_claude_desktop, mcp_add_json, mcp_get, mcp_get_server_status, mcp_list,
|
||||
mcp_read_project_config, mcp_remove, mcp_reset_project_choices, mcp_save_project_config,
|
||||
mcp_serve, mcp_test_connection,
|
||||
mcp_serve, mcp_test_connection, mcp_export_servers,
|
||||
};
|
||||
|
||||
use commands::usage::{
|
||||
@@ -349,6 +349,7 @@ fn main() {
|
||||
mcp_get_server_status,
|
||||
mcp_read_project_config,
|
||||
mcp_save_project_config,
|
||||
mcp_export_servers,
|
||||
|
||||
// Storage Management
|
||||
storage_list_tables,
|
||||
|
@@ -18,7 +18,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost blob: data:; style-src 'self' 'unsafe-inline' blob: data: asset: https://asset.localhost; style-src-elem 'self' 'unsafe-inline' blob: data: asset: https://asset.localhost; style-src-attr 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval' https://app.posthog.com https://*.posthog.com https://*.i.posthog.com https://*.assets.i.posthog.com; worker-src 'self' blob: asset: https://asset.localhost; font-src 'self' data: blob: asset: https://asset.localhost; connect-src 'self' ipc: http://ipc.localhost https://ipc.localhost https://app.posthog.com https://*.posthog.com https://*.i.posthog.com",
|
||||
"csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost blob: data:; style-src 'self' 'unsafe-inline' blob: data: asset: https://asset.localhost; style-src-elem 'self' 'unsafe-inline' blob: data: asset: https://asset.localhost; style-src-attr 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval' https://app.posthog.com https://*.posthog.com https://*.i.posthog.com https://*.assets.i.posthog.com; worker-src 'self' blob: asset: https://asset.localhost; font-src 'self' data: blob: asset: https://asset.localhost; connect-src 'self' ipc: http://ipc.localhost https://ipc.localhost https://app.posthog.com https://*.posthog.com https://*.i.posthog.com https://api.packycode.com https://api-hk-cn2.packycode.com https://api-us-cmin2.packycode.com https://api-us-4837.packycode.com https://api-us-cn2.packycode.com https://api-cf-pro.packycode.com https://share-api.packycode.com https://share-api-cf-pro.packycode.com https://share-api-hk-cn2.packycode.com",
|
||||
"assetProtocol": {
|
||||
"enable": true,
|
||||
"scope": [
|
||||
|
@@ -29,6 +29,7 @@ export const MCPImportExport: React.FC<MCPImportExportProps> = ({
|
||||
const [importingDesktop, setImportingDesktop] = useState(false);
|
||||
const [importingJson, setImportingJson] = useState(false);
|
||||
const [importScope, setImportScope] = useState("local");
|
||||
const [exporting, setExporting] = useState(false);
|
||||
|
||||
/**
|
||||
* Imports servers from Claude Desktop
|
||||
@@ -142,11 +143,84 @@ export const MCPImportExport: React.FC<MCPImportExportProps> = ({
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles exporting servers (placeholder)
|
||||
* Handles exporting servers
|
||||
*/
|
||||
const handleExport = () => {
|
||||
// TODO: Implement export functionality
|
||||
onError("Export functionality coming soon!");
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
setExporting(true);
|
||||
const result = await api.mcpExportServers();
|
||||
|
||||
if (result.servers.length === 0) {
|
||||
onError("No MCP servers configured to export");
|
||||
return;
|
||||
}
|
||||
|
||||
let jsonContent: string;
|
||||
let defaultFileName: string;
|
||||
|
||||
if (result.format === "single" && result.servers.length === 1) {
|
||||
// Single server format
|
||||
const server = result.servers[0];
|
||||
const exportData: any = {
|
||||
type: server.transport,
|
||||
};
|
||||
|
||||
if (server.transport === "stdio") {
|
||||
exportData.command = server.command;
|
||||
exportData.args = server.args;
|
||||
exportData.env = server.env;
|
||||
} else if (server.transport === "sse") {
|
||||
exportData.url = server.url;
|
||||
}
|
||||
|
||||
jsonContent = JSON.stringify(exportData, null, 2);
|
||||
defaultFileName = `mcp-server-${server.name}.json`;
|
||||
} else {
|
||||
// Multiple servers format
|
||||
const exportData: any = {
|
||||
mcpServers: {}
|
||||
};
|
||||
|
||||
for (const server of result.servers) {
|
||||
const serverConfig: any = {
|
||||
command: server.command || "",
|
||||
args: server.args,
|
||||
env: server.env
|
||||
};
|
||||
|
||||
if (server.transport === "sse") {
|
||||
serverConfig.url = server.url;
|
||||
}
|
||||
|
||||
exportData.mcpServers[server.name] = serverConfig;
|
||||
}
|
||||
|
||||
jsonContent = JSON.stringify(exportData, null, 2);
|
||||
defaultFileName = "mcp-servers.json";
|
||||
}
|
||||
|
||||
// Use Tauri's save dialog
|
||||
const { save } = await import('@tauri-apps/plugin-dialog');
|
||||
const filePath = await save({
|
||||
defaultPath: defaultFileName,
|
||||
filters: [{
|
||||
name: 'JSON',
|
||||
extensions: ['json']
|
||||
}]
|
||||
});
|
||||
|
||||
if (filePath) {
|
||||
// Use Tauri's file system API to write the file
|
||||
const { writeTextFile } = await import('@tauri-apps/plugin-fs');
|
||||
await writeTextFile(filePath, jsonContent);
|
||||
onError(`Successfully exported ${result.servers.length} server(s) to ${filePath}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Failed to export servers:", error);
|
||||
onError(error.toString() || "Failed to export servers");
|
||||
} finally {
|
||||
setExporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -273,12 +347,12 @@ export const MCPImportExport: React.FC<MCPImportExportProps> = ({
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Export (Coming Soon) */}
|
||||
<Card className="p-4 opacity-60">
|
||||
{/* Export Configuration */}
|
||||
<Card className="p-4 hover:bg-accent/5 transition-colors">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="p-2.5 bg-muted rounded-lg">
|
||||
<Upload className="h-5 w-5 text-muted-foreground" />
|
||||
<div className="p-2.5 bg-green-500/10 rounded-lg">
|
||||
<Upload className="h-5 w-5 text-green-500" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<h4 className="text-sm font-medium">{t('mcp.exportConfiguration')}</h4>
|
||||
@@ -289,12 +363,21 @@ export const MCPImportExport: React.FC<MCPImportExportProps> = ({
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleExport}
|
||||
disabled={true}
|
||||
variant="secondary"
|
||||
disabled={exporting}
|
||||
variant="outline"
|
||||
className="w-full gap-2"
|
||||
>
|
||||
<Upload className="h-4 w-4" />
|
||||
{t('mcp.exportComingSoon')}
|
||||
{exporting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
{t('mcp.exporting')}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Upload className="h-4 w-4" />
|
||||
{t('mcp.exportConfiguration')}
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
|
@@ -1145,7 +1145,53 @@ const CreateStationDialog: React.FC<{
|
||||
|
||||
try {
|
||||
setSubmitting(true);
|
||||
await api.relayStationCreate(formData);
|
||||
|
||||
// PackyCode 保存时自动选择最佳节点
|
||||
if (formData.adapter === 'packycode') {
|
||||
let finalApiUrl = formData.api_url;
|
||||
|
||||
if (packycodeService === 'bus') {
|
||||
// 公交车自动选择
|
||||
const busNodes = [
|
||||
{ url: "https://api.packycode.com", name: "🚌 直连1(默认公交车)" },
|
||||
{ url: "https://api-hk-cn2.packycode.com", name: "🇭🇰 直连2 (HK-CN2)" },
|
||||
{ url: "https://api-us-cmin2.packycode.com", name: "🇺🇸 直连3 (US-CMIN2)" },
|
||||
{ url: "https://api-us-4837.packycode.com", name: "🇺🇸 直连4 (US-4837)" },
|
||||
{ url: "https://api-us-cn2.packycode.com", name: "🔄 备用1 (US-CN2)" },
|
||||
{ url: "https://api-cf-pro.packycode.com", name: "☁️ 备用2 (CF-Pro)" }
|
||||
];
|
||||
|
||||
await performSpeedTest(busNodes, (bestNode) => {
|
||||
finalApiUrl = bestNode.url;
|
||||
setPackycodeNode(bestNode.url);
|
||||
});
|
||||
} else if (packycodeService === 'taxi') {
|
||||
// 滴滴车自动选择
|
||||
const taxiNodes = [
|
||||
{ url: "https://share-api.packycode.com", name: "🚗 直连1(默认滴滴车)" },
|
||||
{ url: "https://share-api-cf-pro.packycode.com", name: "☁️ 备用1 (CF-Pro)" },
|
||||
{ url: "https://share-api-hk-cn2.packycode.com", name: "🇭🇰 备用2 (HK-CN2)" }
|
||||
];
|
||||
|
||||
await performSpeedTest(taxiNodes, (bestNode) => {
|
||||
finalApiUrl = bestNode.url;
|
||||
setPackycodeTaxiNode(bestNode.url);
|
||||
});
|
||||
}
|
||||
|
||||
// 使用选择的最佳节点创建中转站
|
||||
await api.relayStationCreate({
|
||||
...formData,
|
||||
api_url: finalApiUrl,
|
||||
adapter_config: {
|
||||
service_type: packycodeService
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 非 PackyCode 适配器直接创建
|
||||
await api.relayStationCreate(formData);
|
||||
}
|
||||
|
||||
onSuccess();
|
||||
} catch (error) {
|
||||
console.error('Failed to create station:', error);
|
||||
@@ -1718,7 +1764,7 @@ const EditStationDialog: React.FC<{
|
||||
// PackyCode 特定状态
|
||||
const [packycodeService, setPackycodeService] = useState<string>(() => {
|
||||
// 从API URL判断服务类型
|
||||
if (station.adapter === 'packycode' && station.api_url.includes('share-api')) {
|
||||
if (station.adapter === 'packycode' && (station.api_url.includes('share-api') || station.api_url.includes('codex-api'))) {
|
||||
return 'taxi';
|
||||
}
|
||||
return 'bus';
|
||||
@@ -1730,6 +1776,13 @@ const EditStationDialog: React.FC<{
|
||||
}
|
||||
return 'https://api.packycode.com';
|
||||
});
|
||||
const [packycodeTaxiNode, setPackycodeTaxiNode] = useState<string>(() => {
|
||||
// 如果是PackyCode滴滴车,使用当前的API URL
|
||||
if (station.adapter === 'packycode' && (station.api_url.includes('share-api') || station.api_url.includes('codex-api'))) {
|
||||
return station.api_url;
|
||||
}
|
||||
return 'https://share-api.packycode.com';
|
||||
});
|
||||
|
||||
const [showSpeedTestModal, setShowSpeedTestModal] = useState(false);
|
||||
const [speedTestResults, setSpeedTestResults] = useState<{ url: string; name: string; responseTime: number | null; status: 'testing' | 'success' | 'failed' }[]>([]);
|
||||
@@ -1876,7 +1929,158 @@ const EditStationDialog: React.FC<{
|
||||
|
||||
try {
|
||||
setSubmitting(true);
|
||||
await api.relayStationUpdate(formData);
|
||||
|
||||
// PackyCode 保存时自动选择最佳节点
|
||||
if (formData.adapter === 'packycode') {
|
||||
let finalApiUrl = formData.api_url;
|
||||
|
||||
if (packycodeService === 'bus') {
|
||||
// 公交车自动选择
|
||||
const busNodes = [
|
||||
{ url: "https://api.packycode.com", name: "🚌 直连1(默认公交车)" },
|
||||
{ url: "https://api-hk-cn2.packycode.com", name: "🇭🇰 直连2 (HK-CN2)" },
|
||||
{ url: "https://api-us-cmin2.packycode.com", name: "🇺🇸 直连3 (US-CMIN2)" },
|
||||
{ url: "https://api-us-4837.packycode.com", name: "🇺🇸 直连4 (US-4837)" },
|
||||
{ url: "https://api-us-cn2.packycode.com", name: "🔄 备用1 (US-CN2)" },
|
||||
{ url: "https://api-cf-pro.packycode.com", name: "☁️ 备用2 (CF-Pro)" }
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
// 内联的测速逻辑
|
||||
setShowSpeedTestModal(true);
|
||||
setSpeedTestInProgress(true);
|
||||
|
||||
const initialResults = busNodes.map(node => ({
|
||||
url: node.url,
|
||||
name: node.name,
|
||||
responseTime: null,
|
||||
status: 'testing' as const
|
||||
}));
|
||||
setSpeedTestResults(initialResults);
|
||||
|
||||
let bestNode = busNodes[0];
|
||||
let minTime = Infinity;
|
||||
|
||||
const testPromises = busNodes.map(async (node, index) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await fetch(node.url, {
|
||||
method: 'HEAD',
|
||||
mode: 'no-cors'
|
||||
});
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime, status: 'success' } : result
|
||||
));
|
||||
|
||||
if (responseTime < minTime) {
|
||||
minTime = responseTime;
|
||||
bestNode = node;
|
||||
}
|
||||
|
||||
return { node, responseTime };
|
||||
} catch (error) {
|
||||
console.log(`Node ${node.url} failed:`, error);
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime: null, status: 'failed' } : result
|
||||
));
|
||||
return { node, responseTime: null };
|
||||
}
|
||||
});
|
||||
|
||||
Promise.all(testPromises).then(() => {
|
||||
setTimeout(() => {
|
||||
setSpeedTestInProgress(false);
|
||||
finalApiUrl = bestNode.url;
|
||||
setPackycodeNode(bestNode.url);
|
||||
setTimeout(() => {
|
||||
setShowSpeedTestModal(false);
|
||||
resolve();
|
||||
}, 1000);
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
} else if (packycodeService === 'taxi') {
|
||||
// 滴滴车自动选择
|
||||
const taxiNodes = [
|
||||
{ url: "https://share-api.packycode.com", name: "🚗 直连1(默认滴滴车)" },
|
||||
{ url: "https://share-api-cf-pro.packycode.com", name: "☁️ 备用1 (CF-Pro)" },
|
||||
{ url: "https://share-api-hk-cn2.packycode.com", name: "🇭🇰 备用2 (HK-CN2)" }
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
// 内联的测速逻辑
|
||||
setShowSpeedTestModal(true);
|
||||
setSpeedTestInProgress(true);
|
||||
|
||||
const initialResults = taxiNodes.map(node => ({
|
||||
url: node.url,
|
||||
name: node.name,
|
||||
responseTime: null,
|
||||
status: 'testing' as const
|
||||
}));
|
||||
setSpeedTestResults(initialResults);
|
||||
|
||||
let bestNode = taxiNodes[0];
|
||||
let minTime = Infinity;
|
||||
|
||||
const testPromises = taxiNodes.map(async (node, index) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await fetch(node.url, {
|
||||
method: 'HEAD',
|
||||
mode: 'no-cors'
|
||||
});
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime, status: 'success' } : result
|
||||
));
|
||||
|
||||
if (responseTime < minTime) {
|
||||
minTime = responseTime;
|
||||
bestNode = node;
|
||||
}
|
||||
|
||||
return { node, responseTime };
|
||||
} catch (error) {
|
||||
console.log(`Node ${node.url} failed:`, error);
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime: null, status: 'failed' } : result
|
||||
));
|
||||
return { node, responseTime: null };
|
||||
}
|
||||
});
|
||||
|
||||
Promise.all(testPromises).then(() => {
|
||||
setTimeout(() => {
|
||||
setSpeedTestInProgress(false);
|
||||
finalApiUrl = bestNode.url;
|
||||
setPackycodeTaxiNode(bestNode.url);
|
||||
setFormData(prev => ({ ...prev, api_url: bestNode.url }));
|
||||
setTimeout(() => {
|
||||
setShowSpeedTestModal(false);
|
||||
resolve();
|
||||
}, 1000);
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 使用选择的最佳节点更新中转站
|
||||
await api.relayStationUpdate({
|
||||
...formData,
|
||||
api_url: finalApiUrl,
|
||||
adapter_config: {
|
||||
service_type: packycodeService
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 非 PackyCode 适配器直接更新
|
||||
await api.relayStationUpdate(formData);
|
||||
}
|
||||
|
||||
onSuccess();
|
||||
} catch (error) {
|
||||
console.error('Failed to update station:', error);
|
||||
@@ -2168,6 +2372,118 @@ const EditStationDialog: React.FC<{
|
||||
</div>
|
||||
)}
|
||||
|
||||
{formData.adapter === 'packycode' && packycodeService === 'taxi' && (
|
||||
<div className="space-y-2">
|
||||
<Label>{t('relayStation.nodeSelection')}</Label>
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<Select
|
||||
value={packycodeTaxiNode}
|
||||
onValueChange={(value: string) => {
|
||||
setPackycodeTaxiNode(value);
|
||||
setFormData(prev => ({ ...prev, api_url: value }));
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('relayStation.selectNode')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="https://share-api.packycode.com">
|
||||
🚗 直连1(默认滴滴车)
|
||||
</SelectItem>
|
||||
<SelectItem value="https://share-api-cf-pro.packycode.com">
|
||||
☁️ 备用1 (CF-Pro)
|
||||
</SelectItem>
|
||||
<SelectItem value="https://share-api-hk-cn2.packycode.com">
|
||||
🇭🇰 备用2 (HK-CN2)
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={async () => {
|
||||
const taxiNodes = [
|
||||
{ url: "https://share-api.packycode.com", name: "🚗 直连1(默认滴滴车)" },
|
||||
{ url: "https://share-api-cf-pro.packycode.com", name: "☁️ 备用1 (CF-Pro)" },
|
||||
{ url: "https://share-api-hk-cn2.packycode.com", name: "🇭🇰 备用2 (HK-CN2)" }
|
||||
];
|
||||
|
||||
// 复制 performSpeedTest 逻辑,因为它在这个作用域中不可用
|
||||
setShowSpeedTestModal(true);
|
||||
setSpeedTestInProgress(true);
|
||||
|
||||
const initialResults = taxiNodes.map(node => ({
|
||||
url: node.url,
|
||||
name: node.name,
|
||||
responseTime: null,
|
||||
status: 'testing' as const
|
||||
}));
|
||||
setSpeedTestResults(initialResults);
|
||||
|
||||
let bestNode = taxiNodes[0];
|
||||
let minTime = Infinity;
|
||||
|
||||
const testPromises = taxiNodes.map(async (node, index) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await fetch(node.url, {
|
||||
method: 'HEAD',
|
||||
mode: 'no-cors'
|
||||
});
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime, status: 'success' } : result
|
||||
));
|
||||
|
||||
if (responseTime < minTime) {
|
||||
minTime = responseTime;
|
||||
bestNode = node;
|
||||
}
|
||||
|
||||
return { node, responseTime };
|
||||
} catch (error) {
|
||||
console.log(`Node ${node.url} failed:`, error);
|
||||
setSpeedTestResults(prev => prev.map((result, i) =>
|
||||
i === index ? { ...result, responseTime: null, status: 'failed' } : result
|
||||
));
|
||||
return { node, responseTime: null };
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all(testPromises);
|
||||
setTimeout(() => {
|
||||
setSpeedTestInProgress(false);
|
||||
setPackycodeTaxiNode(bestNode.url);
|
||||
setFormData(prev => ({ ...prev, api_url: bestNode.url }));
|
||||
setTimeout(() => {
|
||||
setShowSpeedTestModal(false);
|
||||
}, 1000);
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
console.error('Speed test failed:', error);
|
||||
setSpeedTestInProgress(false);
|
||||
setTimeout(() => {
|
||||
setShowSpeedTestModal(false);
|
||||
}, 1000);
|
||||
}
|
||||
}}
|
||||
>
|
||||
自动选择
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('relayStation.selectedNode') + ': ' + packycodeTaxiNode}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-description">{t('relayStation.description')}</Label>
|
||||
<Textarea
|
||||
|
@@ -1725,6 +1725,29 @@ export const api = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Export configuration for MCP server
|
||||
*/
|
||||
async mcpExportServers(): Promise<{
|
||||
servers: Array<{
|
||||
name: string;
|
||||
transport: string;
|
||||
command?: string;
|
||||
args: string[];
|
||||
env: Record<string, string>;
|
||||
url?: string;
|
||||
scope: string;
|
||||
}>;
|
||||
format: string;
|
||||
}> {
|
||||
try {
|
||||
return await invoke("mcp_export_servers");
|
||||
} catch (error) {
|
||||
console.error("Failed to export MCP servers:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the stored Claude binary path from settings
|
||||
* @returns Promise resolving to the path if set, null otherwise
|
||||
|
@@ -512,6 +512,7 @@
|
||||
"importFromClaudeDesktop": "Import from Claude Desktop",
|
||||
"importFromClaudeDesktopDescription": "Automatically imports all MCP servers from Claude Desktop. Installs to user scope (available across all projects).",
|
||||
"importing": "Importing...",
|
||||
"exporting": "Exporting...",
|
||||
"importFromJSON": "Import from JSON",
|
||||
"importFromJSONDescription": "Import server configuration from a JSON file",
|
||||
"chooseJSONFile": "Choose JSON File",
|
||||
|
@@ -494,6 +494,7 @@
|
||||
"importFromClaudeDesktop": "从 Claude Desktop 导入",
|
||||
"importFromClaudeDesktopDescription": "自动导入 Claude Desktop 中的所有 MCP 服务器。安装到用户范围(所有项目可用)。",
|
||||
"importing": "导入中...",
|
||||
"exporting": "导出中...",
|
||||
"importFromJSON": "从 JSON 导入",
|
||||
"importFromJSONDescription": "从 JSON 文件导入服务器配置",
|
||||
"chooseJSONFile": "选择 JSON 文件",
|
||||
|
Reference in New Issue
Block a user