diff --git a/frontend/src/i18n/locales/en/accounts.json b/frontend/src/i18n/locales/en/accounts.json index 5a914be25..96b7f0c0c 100644 --- a/frontend/src/i18n/locales/en/accounts.json +++ b/frontend/src/i18n/locales/en/accounts.json @@ -116,7 +116,6 @@ "failed": "Connection test failed", "modelRequired": "Select a model to test", "browserUnsupported": "The current browser does not support connection testing", - "missingCompletion": "The connection test did not return a completion event", "invalidResponse": "Could not parse the test response", "disconnected": "Connection lost during the test" }, diff --git a/frontend/src/i18n/locales/zh-Hans/accounts.json b/frontend/src/i18n/locales/zh-Hans/accounts.json index 316e40ef5..2279ffad5 100644 --- a/frontend/src/i18n/locales/zh-Hans/accounts.json +++ b/frontend/src/i18n/locales/zh-Hans/accounts.json @@ -116,7 +116,6 @@ "failed": "测试连接失败", "modelRequired": "未选择模型", "browserUnsupported": "当前浏览器不支持连接测试", - "missingCompletion": "测试连接未返回完成事件", "invalidResponse": "测试响应解析失败", "disconnected": "测试连接已断开" }, diff --git a/frontend/src/i18n/locales/zh-Hant/accounts.json b/frontend/src/i18n/locales/zh-Hant/accounts.json index 05494e446..7cb03e84b 100644 --- a/frontend/src/i18n/locales/zh-Hant/accounts.json +++ b/frontend/src/i18n/locales/zh-Hant/accounts.json @@ -116,7 +116,6 @@ "failed": "測試連接失敗", "modelRequired": "未選擇模型", "browserUnsupported": "當前瀏覽器不支持連接測試", - "missingCompletion": "測試連接未返回完成事件", "invalidResponse": "測試響應解析失敗", "disconnected": "測試連接已斷開" }, diff --git a/frontend/src/views/accounts/composables/useAccountConnectionTest.ts b/frontend/src/views/accounts/composables/useAccountConnectionTest.ts index 5391423f2..7c1829495 100644 --- a/frontend/src/views/accounts/composables/useAccountConnectionTest.ts +++ b/frontend/src/views/accounts/composables/useAccountConnectionTest.ts @@ -3,19 +3,13 @@ import { CheckCircle2, Clock3, Wifi, XCircle } from '@lucide/vue' import { useEventSource } from '@vueuse/core' import { clamp } from 'es-toolkit' -import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue' +import { computed, ref, shallowRef, watch } from 'vue' import { getAccountModels, refreshAccountModels } from '@/api' import { API_BASE_URL } from '@/api/constants' -import { useIdSet } from '@/composables/useIdSet' import { useRequestState } from '@/composables/useRequestState' import { t } from '@/i18n' import { notification as ZNotification } from '@/utils/notification' -import { errorMessage, withMinimumDuration } from '@/utils/operation' - -interface ConnectionTestRun { - accountId: string - resolve: () => void -} +import { errorMessage } from '@/utils/operation' type ConnectionTestStatus = 'idle' | 'running' | 'success' | 'error' type ConnectionTestLogTone = 'normal' | 'info' | 'success' | 'danger' @@ -180,7 +174,6 @@ export function useAccountConnectionTest(options: { reload: () => Promise(null) - const testingConnections = useIdSet() const modelsRequest = useRequestState() const modelsRequestMode = shallowRef<'load' | 'refresh'>('load') const loadingConnectionTestModels = computed(() => modelsRequest.loading.value && modelsRequestMode.value === 'load') @@ -204,7 +197,7 @@ export function useAccountConnectionTest(options: { reload: () => Promise connectionTestEventSource.value ? testingAccount.value?.id : undefined) const connectionTestStatusView = computed(() => { if (connectionTestStatus.value === 'running') { @@ -244,7 +237,7 @@ export function useAccountConnectionTest(options: { reload: () => Promise Promise Promise Promise Promise - new Promise((resolve) => { - connectionTestRun = { - accountId: account.id, - resolve, - } - const params = new URLSearchParams({ - accountId: account.id, - modelId: connectionTestSelectedModel.value, - }) - connectionTestStreamUrl.value - = `${API_BASE_URL}/api/admin/accounts/connection-test?${params}` - openConnectionTestEventSource() - if (!connectionTestEventSource.value) - failConnectionTest(t('accounts.connectionTest.errors.browserUnsupported')) - }), - ) - if (connectionTestStatus.value === 'running') { - recordConnectionTestFailure('failure', t('accounts.connectionTest.failed'), t('accounts.connectionTest.errors.missingCompletion')) - } + openConnectionTestEventSource() + if (!connectionTestEventSource.value) + failConnectionTest(t('accounts.connectionTest.errors.browserUnsupported')) } catch (error: unknown) { - recordConnectionTestFailure('failure', t('accounts.connectionTest.failed'), errorMessage(error, t('accounts.connectionTest.errors.failed'))) - } - finally { - clearConnectionTestRun() + failConnectionTest(errorMessage(error, t('accounts.connectionTest.errors.failed'))) } } watch(connectionTestStreamMessage, (message) => { - if (!message?.raw || !connectionTestRun) + if (!message?.raw || !connectionTestEventSource.value) return try { const event = parseConnectionTestEvent(message.raw) @@ -548,12 +499,12 @@ export function useAccountConnectionTest(options: { reload: () => Promise { - if (error && connectionTestRun) + if (error && connectionTestEventSource.value) failConnectionTest(t('accounts.connectionTest.errors.disconnected')) - }) + }, { flush: 'sync' }) watch([ showConnectionTestModal, @@ -561,14 +512,10 @@ export function useAccountConnectionTest(options: { reload: () => Promise { modelsRequest.invalidate({ resetLoading: open }) if (!open) { - abortConnectionTest() + closeConnectionTestEventSource() } }, { flush: 'sync' }) - onBeforeUnmount(() => { - abortConnectionTest() - }) - return { showConnectionTestModal, testingAccount, @@ -579,7 +526,7 @@ export function useAccountConnectionTest(options: { reload: () => Promise