From 2399db49449b495570326ba205628a637873dd74 Mon Sep 17 00:00:00 2001 From: Tristan Zhang Date: Thu, 9 Oct 2025 20:40:46 +0800 Subject: [PATCH] fix: adding multiple keys to the zhipu model service is not detected properly (#10583) --- .../Popups/ApiKeyListPopup/popup.tsx | 23 ++++++++++++------- .../ProviderSettings/ProviderSetting.tsx | 13 ++++++++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/components/Popups/ApiKeyListPopup/popup.tsx b/src/renderer/src/components/Popups/ApiKeyListPopup/popup.tsx index b4ca91186b..aba48b125e 100644 --- a/src/renderer/src/components/Popups/ApiKeyListPopup/popup.tsx +++ b/src/renderer/src/components/Popups/ApiKeyListPopup/popup.tsx @@ -10,6 +10,7 @@ interface ShowParams { providerId: string title?: string showHealthCheck?: boolean + providerType?: 'llm' | 'webSearch' | 'preprocess' } interface Props extends ShowParams { @@ -19,7 +20,7 @@ interface Props extends ShowParams { /** * API Key 列表弹窗容器组件 */ -const PopupContainer: React.FC = ({ providerId, title, resolve, showHealthCheck = true }) => { +const PopupContainer: React.FC = ({ providerId, title, resolve, showHealthCheck = true, providerType }) => { const [open, setOpen] = useState(true) const { t } = useTranslation() @@ -32,14 +33,20 @@ const PopupContainer: React.FC = ({ providerId, title, resolve, showHealt } const ListComponent = useMemo(() => { - if (isWebSearchProviderId(providerId)) { - return + const type = + providerType || + (isWebSearchProviderId(providerId) ? 'webSearch' : isPreprocessProviderId(providerId) ? 'preprocess' : 'llm') + + switch (type) { + case 'webSearch': + return + case 'preprocess': + return + case 'llm': + default: + return } - if (isPreprocessProviderId(providerId)) { - return - } - return - }, [providerId, showHealthCheck]) + }, [providerId, showHealthCheck, providerType]) return ( = ({ providerId }) => { const onUpdateApiVersion = () => updateProvider({ apiVersion }) const openApiKeyList = async () => { + if (localApiKey !== provider.apiKey) { + updateProvider({ apiKey: formatApiKeys(localApiKey) }) + await new Promise((resolve) => setTimeout(resolve, 0)) + } + await ApiKeyListPopup.show({ providerId: provider.id, - title: `${fancyProviderName} ${t('settings.provider.api.key.list.title')}` + title: `${fancyProviderName} ${t('settings.provider.api.key.list.title')}`, + providerType: 'llm' }) } const onCheckApi = async () => { + const formattedLocalKey = formatApiKeys(localApiKey) // 如果存在多个密钥,直接打开管理窗口 - if (provider.apiKey.includes(',')) { + if (formattedLocalKey.includes(',')) { await openApiKeyList() return } @@ -204,7 +211,7 @@ const ProviderSetting: FC = ({ providerId }) => { try { setApiKeyConnectivity((prev) => ({ ...prev, checking: true, status: HealthStatus.NOT_CHECKED })) - await checkApi({ ...provider, apiHost }, model) + await checkApi({ ...provider, apiHost, apiKey: formattedLocalKey }, model) window.toast.success({ timeout: 2000,