fix(ai): improve connection test diagnostics

This commit is contained in:
zipg authored and GitHub committed 2026-07-23 12:51:19 +08:00
1 parent 590e9042e8
commit 21e9578f78
9 files changed
+495 -82

No files matched your search

@@ -2195,6 +2195,24 @@ const aiTestResult = ref<"" | "success" | "error">("");
const aiTestError = ref("");
const aiTestLatency = ref<number | null>(null);
const aiTestErrorCopied = ref(false);
const aiTestErrorCategoryKeys: Record<string, string> = {
auth: "ai.testErrorAuth",
modelNotFound: "ai.testErrorModelNotFound",
rateLimit: "ai.testErrorRateLimit",
timeout: "ai.testErrorTimeout",
tokenLimit: "ai.testErrorTokenLimit",
safety: "ai.testErrorSafety",
emptyResponse: "ai.testErrorEmptyResponse",
network: "ai.testErrorNetwork",
unknown: "ai.testErrorUnknown",
};
const aiTestErrorPresentation = computed(() => {
const match = aiTestError.value.match(/^\[([^\]]+)]\s*(.*)$/s);
if (!match) return { summary: "", detail: aiTestError.value };
const key = aiTestErrorCategoryKeys[match[1]];
return key ? { summary: t(key), detail: match[2] } : { summary: "", detail: aiTestError.value };
});
const aiTestErrorDisplay = computed(() => [aiTestErrorPresentation.value.summary, aiTestErrorPresentation.value.detail].filter(Boolean).join(" "));
const aiIsCodexCli = computed(() => aiEditProvider.value === "codex-cli");
const aiIsClaudeCodeCli = computed(() => aiEditProvider.value === "claude-code-cli");
const aiIsCliProvider = computed(() => CLI_AI_PROVIDERS.has(aiEditProvider.value));
@@ -5560,7 +5578,7 @@ onUnmounted(cleanupPreviewEditor);
<Button variant="outline" @click="closeSettings">{{ t("common.close") }}</Button>
</template>
<template v-else>
<div class="flex flex-1 items-center gap-2">
<div class="flex min-w-0 flex-1 items-center gap-2">
<Button size="sm" variant="outline" :disabled="aiTesting || !!aiCliValidationError || (aiRequiresApiKey && !aiEditApiKey?.trim()) || (!aiIsCliProvider && !aiEditEndpoint?.trim()) || (!aiIsCliProvider && !aiEditModel?.trim())" @click="aiTestConn">
<Loader2 v-if="aiTesting" class="h-3 w-3 animate-spin mr-1" />
{{ t("connection.test") }}
@@ -5569,8 +5587,11 @@ onUnmounted(cleanupPreviewEditor);
<span>{{ t("connection.testSuccess") }}</span>
<span v-if="aiTestLatency != null" class="text-green-500/70">{{ aiTestLatency }}ms</span>
</span>
<span v-else-if="aiTestResult === 'error'" class="min-w-0 max-w-[360px] flex items-center gap-1.5 text-xs text-destructive">
<span class="select-text truncate" :title="aiTestError">{{ aiTestError }}</span>
<span v-else-if="aiTestResult === 'error'" class="flex min-w-0 max-w-lg items-center gap-1.5 text-xs text-destructive">
<span class="min-w-0 select-text leading-4" :title="aiTestErrorDisplay">
<span v-if="aiTestErrorPresentation.summary" class="block font-medium">{{ aiTestErrorPresentation.summary }}</span>
<span class="block truncate text-destructive/80">{{ aiTestErrorPresentation.detail }}</span>
</span>
<Button
type="button"
variant="ghost"
+9
View File
@@ -1512,6 +1512,15 @@ export default {
copyAll: "Copy All",
copied: "Copied",
copyTestResult: "Copy test result",
testErrorAuth: "Authentication or access failed. Check the API key, project permissions, and API availability.",
testErrorModelNotFound: "The model is unavailable. Check its model ID and your account access.",
testErrorRateLimit: "The rate limit or quota was exceeded. Retry later or check the account quota.",
testErrorTimeout: "The request timed out. Check the network, proxy, and endpoint.",
testErrorTokenLimit: "No visible text was generated because the output token limit was exhausted.",
testErrorSafety: "Gemini blocked the prompt or response under its safety policy.",
testErrorEmptyResponse: "The service or proxy closed the stream without returning visible text.",
testErrorNetwork: "The network connection failed. Check the endpoint and proxy.",
testErrorUnknown: "The test failed for an unclassified reason.",
replace: "Replace Editor",
append: "Append to Editor",
apply: "Apply to Editor",
+9
View File
@@ -1502,6 +1502,15 @@ export default withEnglishFallback({
copyAll: "Copiar todo",
copied: "Copiado",
copyTestResult: "Copiar resultado de prueba",
testErrorAuth: "Falló la autenticación o el acceso. Comprueba la clave de API, los permisos del proyecto y que la API esté habilitada.",
testErrorModelNotFound: "El modelo no está disponible. Comprueba su ID y el acceso de la cuenta.",
testErrorRateLimit: "Se superó el límite de solicitudes o la cuota. Inténtalo más tarde o revisa la cuota.",
testErrorTimeout: "La solicitud agotó el tiempo de espera. Comprueba la red, el proxy y el endpoint.",
testErrorTokenLimit: "No se generó texto visible porque se agotó el límite de tokens de salida.",
testErrorSafety: "La política de seguridad de Gemini bloqueó el prompt o la respuesta.",
testErrorEmptyResponse: "El servicio o el proxy cerró el flujo sin devolver texto visible.",
testErrorNetwork: "La conexión de red falló. Comprueba el endpoint y el proxy.",
testErrorUnknown: "La prueba falló por un motivo no clasificado.",
replace: "Reemplazar en el editor",
append: "Agregar al editor",
apply: "Aplicar al editor",
+9
View File
@@ -1452,6 +1452,15 @@ export default withEnglishFallback({
copyAll: "Copia Tutto",
copied: "Copiato",
copyTestResult: "Copia risultato test",
testErrorAuth: "Autenticazione o accesso non riusciti. Controlla la chiave API, i permessi del progetto e che l'API sia abilitata.",
testErrorModelNotFound: "Il modello non è disponibile. Controlla l'ID del modello e l'accesso dell'account.",
testErrorRateLimit: "È stato superato il limite di richieste o la quota. Riprova più tardi o controlla la quota.",
testErrorTimeout: "La richiesta è scaduta. Controlla rete, proxy ed endpoint.",
testErrorTokenLimit: "Non è stato generato testo visibile perché il limite dei token di output è esaurito.",
testErrorSafety: "La policy di sicurezza di Gemini ha bloccato il prompt o la risposta.",
testErrorEmptyResponse: "Il servizio o il proxy ha chiuso lo stream senza restituire testo visibile.",
testErrorNetwork: "Connessione di rete non riuscita. Controlla endpoint e proxy.",
testErrorUnknown: "Il test non è riuscito per un motivo non classificato.",
replace: "Sostituisci Editor",
append: "Accoda all'Editor",
apply: "Applica all'Editor",
+9
View File
@@ -1506,6 +1506,15 @@ export default withEnglishFallback({
copyAll: "すべてコピー",
copied: "コピーしました",
copyTestResult: "テスト結果をコピー",
testErrorAuth: "認証またはアクセスに失敗しました。API キー、プロジェクト権限、API の有効化状態を確認してください。",
testErrorModelNotFound: "モデルを利用できません。モデル ID とアカウントのアクセス権を確認してください。",
testErrorRateLimit: "レート制限またはクォータ上限に達しました。しばらく待って再試行するか、クォータを確認してください。",
testErrorTimeout: "リクエストがタイムアウトしました。ネットワーク、プロキシ、エンドポイントを確認してください。",
testErrorTokenLimit: "出力トークンを使い切ったため、表示可能なテキストが生成されませんでした。",
testErrorSafety: "Gemini の安全ポリシーにより、プロンプトまたは応答がブロックされました。",
testErrorEmptyResponse: "表示可能なテキストが返る前に、サービスまたはプロキシがストリームを終了しました。",
testErrorNetwork: "ネットワーク接続に失敗しました。エンドポイントとプロキシを確認してください。",
testErrorUnknown: "分類できない理由でテストに失敗しました。",
replace: "エディタを置換",
append: "エディタに追加",
apply: "エディタに適用",
+9
View File
@@ -1504,6 +1504,15 @@ export default withEnglishFallback({
copyAll: "Copiar Tudo",
copied: "Copiado",
copyTestResult: "Copiar resultado do teste",
testErrorAuth: "A autenticação ou o acesso falhou. Verifique a chave de API, as permissões do projeto e se a API está ativada.",
testErrorModelNotFound: "O modelo não está disponível. Verifique o ID do modelo e o acesso da conta.",
testErrorRateLimit: "O limite de solicitações ou a cota foi excedido. Tente mais tarde ou verifique a cota.",
testErrorTimeout: "A solicitação expirou. Verifique a rede, o proxy e o endpoint.",
testErrorTokenLimit: "Nenhum texto visível foi gerado porque o limite de tokens de saída se esgotou.",
testErrorSafety: "A política de segurança do Gemini bloqueou o prompt ou a resposta.",
testErrorEmptyResponse: "O serviço ou proxy fechou o fluxo sem retornar texto visível.",
testErrorNetwork: "A conexão de rede falhou. Verifique o endpoint e o proxy.",
testErrorUnknown: "O teste falhou por um motivo não classificado.",
replace: "Substituir Editor",
append: "Anexar ao Editor",
apply: "Aplicar ao Editor",
+9
View File
@@ -1512,6 +1512,15 @@ export default withEnglishFallback({
copyAll: "复制全部",
copied: "已复制",
copyTestResult: "复制测试结果",
testErrorAuth: "身份验证或访问失败,请检查 API Key、项目权限和 API 启用状态。",
testErrorModelNotFound: "模型不可用,请检查模型 ID 和当前账号的访问权限。",
testErrorRateLimit: "请求频率或配额已超限,请稍后重试或检查账号配额。",
testErrorTimeout: "请求超时,请检查网络、代理和 Endpoint。",
testErrorTokenLimit: "输出 token 已耗尽,因此没有生成可见文本。",
testErrorSafety: "Gemini 的安全策略拦截了提示词或响应。",
testErrorEmptyResponse: "服务或代理在返回可见文本前关闭了流。",
testErrorNetwork: "网络连接失败,请检查 Endpoint 和代理。",
testErrorUnknown: "测试因未分类的原因失败。",
replace: "替换编辑器",
append: "追加到编辑器",
apply: "应用到编辑器",
+9
View File
@@ -1454,6 +1454,15 @@ export default withEnglishFallback({
copyAll: "複製全部",
copied: "已複製",
copyTestResult: "複製測試結果",
testErrorAuth: "驗證或存取失敗,請檢查 API Key、專案權限和 API 啟用狀態。",
testErrorModelNotFound: "模型無法使用,請檢查模型 ID 和目前帳號的存取權限。",
testErrorRateLimit: "請求頻率或配額已超限,請稍後重試或檢查帳號配額。",
testErrorTimeout: "請求逾時,請檢查網路、代理和 Endpoint。",
testErrorTokenLimit: "輸出 token 已耗盡,因此沒有產生可見文字。",
testErrorSafety: "Gemini 的安全政策攔截了提示詞或回應。",
testErrorEmptyResponse: "服務或代理在傳回可見文字前關閉了串流。",
testErrorNetwork: "網路連線失敗,請檢查 Endpoint 和代理。",
testErrorUnknown: "測試因未分類的原因失敗。",
replace: "取代編輯器",
append: "追加到編輯器",
apply: "套用到編輯器",