fix: i18n and mcp test

This commit is contained in:
wangcham
2025-10-30 15:17:06 +00:00
parent f2647316a5
commit e17b0cf5c5
5 changed files with 96 additions and 5 deletions

View File

@@ -605,13 +605,80 @@ export default function PluginConfigPage() {
.testMCPServer(form.getValues('name')) .testMCPServer(form.getValues('name'))
.then((res) => { .then((res) => {
console.log(res); console.log(res);
toast.success(t('models.testSuccess')); if (res.task_id) {
const taskId = res.task_id;
const interval = setInterval(() => {
httpClient
.getAsyncTask(taskId)
.then((taskResp) => {
console.log('Test task response:', taskResp);
if (taskResp.runtime && taskResp.runtime.done) {
clearInterval(interval);
setMcpTesting(false);
if (taskResp.runtime.exception) {
toast.error(
t('mcp.testError') +
': ' +
(taskResp.runtime.exception || t('mcp.unknownError')),
);
} else if (taskResp.runtime.result) {
try {
let result: {
status?: string;
tools_count?: number;
tools_names_lists?: string[];
error?: string;
};
const rawResult: unknown = taskResp.runtime.result;
if (typeof rawResult === 'string') {
result = JSON.parse(rawResult.replace(/'/g, '"'));
} else {
result = rawResult as typeof result;
}
if (
result.tools_names_lists &&
result.tools_names_lists.length > 0
) {
toast.success(
t('mcp.testSuccess') +
' - ' +
result.tools_names_lists.length +
' ' +
t('mcp.toolsFound'),
);
} else {
toast.error(t('mcp.testError') + ': ' + t('mcp.noToolsFound'));
}
} catch (parseError) {
console.error('Failed to parse test result:', parseError);
toast.error(t('mcp.testError') + ': ' + t('mcp.parseResultFailed'));
}
} else {
toast.error(t('mcp.testError') + ': ' + t('mcp.noResultReturned'));
}
}
})
.catch((err) => {
console.error('获取测试任务状态失败:', err);
clearInterval(interval);
setMcpTesting(false);
toast.error(t('mcp.testError') + ': ' + (err.message || t('mcp.getTaskFailed')));
});
}, 1000);
} else {
setMcpTesting(false);
toast.error(t('mcp.testError') + ': ' + t('mcp.noTaskId'));
}
}) })
.catch(() => { .catch((err) => {
toast.error(t('mcp.testError')); console.error('启动测试失败:', err);
})
.finally(() => {
setMcpTesting(false); setMcpTesting(false);
toast.error(t('mcp.testError') + ': ' + (err.message || t('mcp.unknownError')));
}); });
} }

View File

@@ -321,6 +321,12 @@ const enUS = {
connectionSuccess: 'Connection successful', connectionSuccess: 'Connection successful',
connectionFailed: 'Connection failed', connectionFailed: 'Connection failed',
toolsFound: 'tools', toolsFound: 'tools',
unknownError: 'Unknown error',
noToolsFound: 'No tools found',
parseResultFailed: 'Failed to parse test result',
noResultReturned: 'Test returned no result',
getTaskFailed: 'Failed to get task status',
noTaskId: 'No task ID obtained',
deleteSuccess: 'Deleted successfully', deleteSuccess: 'Deleted successfully',
deleteError: 'Delete failed: ', deleteError: 'Delete failed: ',
saveSuccess: 'Saved successfully', saveSuccess: 'Saved successfully',

View File

@@ -323,6 +323,12 @@ const jaJP = {
connectionSuccess: '接続に成功しました', connectionSuccess: '接続に成功しました',
connectionFailed: '接続に失敗しました', connectionFailed: '接続に失敗しました',
toolsFound: '個のツール', toolsFound: '個のツール',
unknownError: '不明なエラー',
noToolsFound: 'ツールが見つかりません',
parseResultFailed: 'テスト結果の解析に失敗しました',
noResultReturned: 'テスト結果が返されませんでした',
getTaskFailed: 'タスクステータスの取得に失敗しました',
noTaskId: 'タスクIDを取得できませんでした',
deleteSuccess: '削除に成功しました', deleteSuccess: '削除に成功しました',
deleteError: '削除に失敗しました:', deleteError: '削除に失敗しました:',
saveSuccess: '保存に成功しました', saveSuccess: '保存に成功しました',

View File

@@ -310,6 +310,12 @@ const zhHans = {
connectionSuccess: '连接成功', connectionSuccess: '连接成功',
connectionFailed: '连接失败', connectionFailed: '连接失败',
toolsFound: '个工具', toolsFound: '个工具',
unknownError: '未知错误',
noToolsFound: '未找到任何工具',
parseResultFailed: '解析测试结果失败',
noResultReturned: '测试未返回结果',
getTaskFailed: '获取任务状态失败',
noTaskId: '未获取到任务ID',
deleteSuccess: '删除成功', deleteSuccess: '删除成功',
deleteError: '删除失败:', deleteError: '删除失败:',
saveSuccess: '保存成功', saveSuccess: '保存成功',

View File

@@ -307,6 +307,12 @@ const zhHant = {
connectionSuccess: '連接成功', connectionSuccess: '連接成功',
connectionFailed: '連接失敗', connectionFailed: '連接失敗',
toolsFound: '個工具', toolsFound: '個工具',
unknownError: '未知錯誤',
noToolsFound: '未找到任何工具',
parseResultFailed: '解析測試結果失敗',
noResultReturned: '測試未返回結果',
getTaskFailed: '獲取任務狀態失敗',
noTaskId: '未獲取到任務ID',
deleteSuccess: '刪除成功', deleteSuccess: '刪除成功',
deleteError: '刪除失敗:', deleteError: '刪除失敗:',
saveSuccess: '儲存成功', saveSuccess: '儲存成功',