🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: resolve server version check issue for desktop app (#11834)
Innei0bd2a59884c6
diff --git a/src/app/[variants]/(main)/settings/about/features/Version.tsx b/src/app/[variants]/(main)/settings/about/features/Version.tsxindex bdfb70b9736..2a01929c316 100644--- a/src/app/[variants]/(main)/settings/about/features/Version.tsx+++ b/src/app/[variants]/(main)/settings/about/features/Version.tsx@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';import { ProductLogo } from '@/components/Branding';import { CHANGELOG_URL, MANUAL_UPGRADE_URL, OFFICIAL_SITE } from '@/const/url';-import { CURRENT_VERSION, isDesktop } from '@/const/version';+import { CURRENT_VERSION } from '@/const/version';import { useNewVersion } from '@/features/User/UserPanel/useNewVersion';import { useGlobalStore } from '@/store/global';@@ -25,7 +25,7 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {]);const { t } = useTranslation('common');- useCheckServerVersion(isDesktop);+ useCheckServerVersion();const showServerVersion = serverVersion && serverVersion !== CURRENT_VERSION;diff --git a/src/layout/GlobalProvider/StoreInitialization.tsx b/src/layout/GlobalProvider/StoreInitialization.tsxindex 19229b81133..a2bb58e39de 100644--- a/src/layout/GlobalProvider/StoreInitialization.tsx+++ b/src/layout/GlobalProvider/StoreInitialization.tsx@@ -5,7 +5,6 @@ import { memo } from 'react';import { useTranslation } from 'react-i18next';import { createStoreUpdater } from 'zustand-utils';-import { isDesktop } from '@/const/version';import { useIsMobile } from '@/hooks/useIsMobile';import { useAgentStore } from '@/store/agent';import { useAiInfraStore } from '@/store/aiInfra';@@ -44,7 +43,7 @@ const StoreInitialization = memo(() => {useInitSystemStatus();// check server version in desktop app- useCheckServerVersion(isDesktop);+ useCheckServerVersion();// fetch server configconst useFetchServerConfig = useServerConfigStore((s) => s.useInitServerConfig);diff --git a/src/services/global.ts b/src/services/global.tsindex 7d4a0237c40..d4bb11f01e7 100644--- a/src/services/global.ts+++ b/src/services/global.ts@@ -1,8 +1,11 @@+import { isDesktop } from '@lobechat/const';import type { PartialDeep } from 'type-fest';import type { VersionResponseData } from '@/app/(backend)/api/version/route';import { BusinessGlobalService } from '@/business/client/services/BusinessGlobalService';import { lambdaClient } from '@/libs/trpc/client';+import { getElectronStoreState } from '@/store/electron';+import { electronSyncSelectors } from '@/store/electron/selectors';import { type LobeAgentConfig } from '@/types/agent';import { type GlobalRuntimeConfig } from '@/types/serverConfig';@@ -26,7 +29,26 @@ class GlobalService extends BusinessGlobalService {* @throws Error for other failures (network errors, 500s, etc.) to allow SWR retry*/getServerVersion = async (): Promise<string | null> => {- const res = await fetch(SERVER_VERSION_URL);+ const origin = (() => {+ if (isDesktop) {+ const remoteServerUrl = electronSyncSelectors.remoteServerUrl(getElectronStoreState());+ if (!remoteServerUrl) return undefined;++ try {+ return new URL(remoteServerUrl).origin;+ } catch {+ // fallback: use as-is; URL construction below will throw if invalid+ return remoteServerUrl;+ }+ }++ return undefined;+ })();++ if (!origin) return null;++ const url = new URL(SERVER_VERSION_URL, origin).toString();+ const res = await fetch(url);// Only treat 404 as "server doesn't support version API"// Other errors (500, network issues) should throw to allow retrydiff --git a/src/store/global/actions/general.ts b/src/store/global/actions/general.tsindex 73f0e0acfe7..086de7f2768 100644--- a/src/store/global/actions/general.ts+++ b/src/store/global/actions/general.ts@@ -6,6 +6,8 @@ import type { StateCreator } from 'zustand/vanilla';import { CURRENT_VERSION, isDesktop } from '@/const/version';import { useOnlyFetchOnceSWR } from '@/libs/swr';import { globalService } from '@/services/global';+import { getElectronStoreState } from '@/store/electron';+import { electronSyncSelectors } from '@/store/electron/selectors';import type { SystemStatus } from '@/store/global/initialState';import { type LocaleMode } from '@/types/locale';import { switchLang } from '@/utils/client/switchLang';@@ -23,7 +25,7 @@ export interface GlobalGeneralAction {updateResourceManagerColumnWidth: (column: 'name' | 'date' | 'size', width: number) => void;updateSystemStatus: (status: Partial<SystemStatus>, action?: any) => void;useCheckLatestVersion: (enabledCheck?: boolean) => SWRResponse<string>;- useCheckServerVersion: (enabledCheck?: boolean) => SWRResponse<string | null>;+ useCheckServerVersion: () => SWRResponse<string | null>;useInitSystemStatus: () => SWRResponse;}@@ -161,9 +163,13 @@ export const generalActionSlice: StateCreator<},),- useCheckServerVersion: (enabledCheck = true) =>+ useCheckServerVersion: () =>useOnlyFetchOnceSWR(- enabledCheck ? 'checkServerVersion' : null,+ isDesktop &&+ // only check server version for self-hosted remote server+ electronSyncSelectors.storageMode(getElectronStoreState()) !== 'cloud'+ ? 'checkServerVersion'+ : null,async () => globalService.getServerVersion(),{onSuccess: (data: string | null) => {