diff --git a/CHANGELOG.md b/CHANGELOG.md
index cea49337b2669..58780ca4312ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,31 @@
# Changelog
+### [Version 1.47.5](https://github.com/lobehub/lobe-chat/compare/v1.47.4...v1.47.5)
+
+Released on **2025-01-20**
+
+#### ♻ Code Refactoring
+
+- **misc**: Improve ai provider code.
+
+
+
+
+Improvements and Fixes
+
+#### Code refactoring
+
+- **misc**: Improve ai provider code, closes [#5514](https://github.com/lobehub/lobe-chat/issues/5514) ([92789cd](https://github.com/lobehub/lobe-chat/commit/92789cd))
+
+
+
+
+
+[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
+
+
+
### [Version 1.47.4](https://github.com/lobehub/lobe-chat/compare/v1.47.3...v1.47.4)
Released on **2025-01-18**
diff --git a/changelog/v1.json b/changelog/v1.json
index 3fcaf08819d74..475c0cdeadfb9 100644
--- a/changelog/v1.json
+++ b/changelog/v1.json
@@ -1,4 +1,11 @@
[
+ {
+ "children": {
+ "improvements": ["Improve ai provider code."]
+ },
+ "date": "2025-01-20",
+ "version": "1.47.5"
+ },
{
"children": {},
"date": "2025-01-18",
diff --git a/package.json b/package.json
index c40b64fa1ea8f..f0548ef90a766 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@lobehub/chat",
- "version": "1.47.4",
+ "version": "1.47.5",
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
"keywords": [
"framework",
diff --git a/src/app/(main)/settings/provider/ProviderMenu/Item.tsx b/src/app/(main)/settings/provider/ProviderMenu/Item.tsx
index 6aea3ae267e84..9907c22f742f8 100644
--- a/src/app/(main)/settings/provider/ProviderMenu/Item.tsx
+++ b/src/app/(main)/settings/provider/ProviderMenu/Item.tsx
@@ -5,7 +5,7 @@ import { createStyles } from 'antd-style';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { memo } from 'react';
-import { Flexbox } from 'react-layout-kit';
+import { Center, Flexbox } from 'react-layout-kit';
import { AiProviderListItem, AiProviderSourceEnum } from '@/types/aiProvider';
@@ -62,7 +62,16 @@ const ProviderItem = memo(({ id, name, source, enabled, logo
)}
{name}
- {enabled && }
+
+ {enabled && (
+
+
+
+ )}
+ {/* cloud slot */}
+
+ {/* cloud slot */}
+
);
});
diff --git a/src/app/(main)/settings/provider/features/ProviderConfig/EnableSwitch.tsx b/src/app/(main)/settings/provider/features/ProviderConfig/EnableSwitch.tsx
new file mode 100644
index 0000000000000..b2cdc1829f026
--- /dev/null
+++ b/src/app/(main)/settings/provider/features/ProviderConfig/EnableSwitch.tsx
@@ -0,0 +1,46 @@
+import { Skeleton } from 'antd';
+import { createStyles } from 'antd-style';
+import { FC } from 'react';
+
+import InstantSwitch from '@/components/InstantSwitch';
+import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';
+
+const useStyles = createStyles(({ css }) => ({
+ switchLoading: css`
+ width: 44px !important;
+ min-width: 44px !important;
+ height: 22px !important;
+ border-radius: 12px !important;
+ `,
+}));
+
+interface SwitchProps {
+ Component?: FC<{ id: string }>;
+ id: string;
+}
+
+const Switch = ({ id, Component }: SwitchProps) => {
+ const { styles } = useStyles();
+
+ const [toggleProviderEnabled, enabled, isLoading] = useAiInfraStore((s) => [
+ s.toggleProviderEnabled,
+ aiProviderSelectors.isProviderEnabled(id)(s),
+ aiProviderSelectors.isAiProviderConfigLoading(id)(s),
+ ]);
+
+ if (isLoading) return ;
+
+ // slot for cloud
+ if (Component) return ;
+
+ return (
+ {
+ await toggleProviderEnabled(id as any, enabled);
+ }}
+ />
+ );
+};
+
+export default Switch;
diff --git a/src/app/(main)/settings/provider/features/ProviderConfig/index.tsx b/src/app/(main)/settings/provider/features/ProviderConfig/index.tsx
index 4331b89b4abaf..174a4595b1027 100644
--- a/src/app/(main)/settings/provider/features/ProviderConfig/index.tsx
+++ b/src/app/(main)/settings/provider/features/ProviderConfig/index.tsx
@@ -12,7 +12,6 @@ import { Trans, useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';
import urlJoin from 'url-join';
-import InstantSwitch from '@/components/InstantSwitch';
import { FORM_STYLE } from '@/const/layoutTokens';
import { AES_GCM_URL, BASE_PROVIDER_DOC_URL } from '@/const/url';
import { isServerMode } from '@/const/version';
@@ -26,6 +25,7 @@ import {
import { KeyVaultsConfigKey, LLMProviderApiTokenKey, LLMProviderBaseUrlKey } from '../../const';
import Checker from './Checker';
import { SkeletonInput } from './SkeletonInput';
+import EnableSwitch from './EnableSwitch';
import UpdateProviderInfo from './UpdateProviderInfo';
const useStyles = createStyles(({ css, prefixCls, responsive, token }) => ({
@@ -131,7 +131,6 @@ const ProviderConfig = memo(
const { cx, styles, theme } = useStyles();
const [
- toggleProviderEnabled,
useFetchAiProviderItem,
updateAiProviderConfig,
enabled,
@@ -141,7 +140,6 @@ const ProviderConfig = memo(
isProviderEndpointNotEmpty,
isProviderApiKeyNotEmpty,
] = useAiInfraStore((s) => [
- s.toggleProviderEnabled,
s.useFetchAiProviderItem,
s.updateAiProviderConfig,
aiProviderSelectors.isProviderEnabled(id)(s),
@@ -285,16 +283,7 @@ const ProviderConfig = memo(
{extra}
{isCustom && }
- {isLoading ? (
-
- ) : (
- {
- await toggleProviderEnabled(id as any, enabled);
- }}
- />
- )}
+
),
title: (