@lobehub/chat 1.47.9 → 1.47.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.47.11](https://github.com/lobehub/lobe-chat/compare/v1.47.10...v1.47.11)
6
+
7
+ <sup>Released on **2025-01-21**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Improve code for ai provider.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Improve code for ai provider, closes [#5532](https://github.com/lobehub/lobe-chat/issues/5532) ([ea59e24](https://github.com/lobehub/lobe-chat/commit/ea59e24))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.47.10](https://github.com/lobehub/lobe-chat/compare/v1.47.9...v1.47.10)
31
+
32
+ <sup>Released on **2025-01-21**</sup>
33
+
34
+ #### 💄 Styles
35
+
36
+ - **misc**: Support assistant blacklist.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Styles
44
+
45
+ - **misc**: Support assistant blacklist, closes [#5527](https://github.com/lobehub/lobe-chat/issues/5527) ([3534c0d](https://github.com/lobehub/lobe-chat/commit/3534c0d))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.47.9](https://github.com/lobehub/lobe-chat/compare/v1.47.8...v1.47.9)
6
56
 
7
57
  <sup>Released on **2025-01-20**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,22 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "improvements": [
5
+ "Improve code for ai provider."
6
+ ]
7
+ },
8
+ "date": "2025-01-21",
9
+ "version": "1.47.11"
10
+ },
11
+ {
12
+ "children": {
13
+ "improvements": [
14
+ "Support assistant blacklist."
15
+ ]
16
+ },
17
+ "date": "2025-01-21",
18
+ "version": "1.47.10"
19
+ },
2
20
  {
3
21
  "children": {
4
22
  "improvements": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.47.9",
3
+ "version": "1.47.11",
4
4
  "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.",
5
5
  "keywords": [
6
6
  "framework",
@@ -316,7 +316,7 @@
316
316
  "vitest": "~1.2.2",
317
317
  "vitest-canvas-mock": "^0.3.3"
318
318
  },
319
- "packageManager": "pnpm@9.15.3",
319
+ "packageManager": "pnpm@9.15.4",
320
320
  "publishConfig": {
321
321
  "access": "public",
322
322
  "registry": "https://registry.npmjs.org"
@@ -0,0 +1,24 @@
1
+ import { revalidateTag } from 'next/cache';
2
+ import { NextRequest, NextResponse } from 'next/server';
3
+
4
+ export const GET = async (request: NextRequest) => {
5
+ if (!process.env.REVALIDATE_SECRET) {
6
+ return NextResponse.json('REVALIDATE_SECRET is not set', { status: 501 });
7
+ }
8
+
9
+ const authToken = request.headers.get('Authorization');
10
+
11
+ if (!authToken || authToken !== process.env.REVALIDATE_SECRET) {
12
+ return NextResponse.json('Unauthorized', { status: 401 });
13
+ }
14
+
15
+ const tag = request.nextUrl.searchParams.get('tag');
16
+
17
+ if (!tag) {
18
+ return NextResponse.json('tag query parameter is required', { status: 400 });
19
+ }
20
+
21
+ revalidateTag(tag);
22
+
23
+ return Response.json({ now: Date.now(), revalidated: true });
24
+ };
@@ -6,10 +6,9 @@ import { memo } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
- import InstantSwitch from '@/components/InstantSwitch';
10
- import { useAiInfraStore } from '@/store/aiInfra';
11
9
  import { AiProviderListItem } from '@/types/aiProvider';
12
10
 
11
+ import EnableSwitch from './EnableSwitch';
13
12
  import { useStyles } from './style';
14
13
 
15
14
  const { Paragraph } = Typography;
@@ -21,7 +20,6 @@ const ProviderCard = memo<ProviderCardProps>(
21
20
  ({ id, description, name, enabled, source, logo, loading }) => {
22
21
  const { t } = useTranslation('providers');
23
22
  const { cx, styles, theme } = useStyles();
24
- const toggleProviderEnabled = useAiInfraStore((s) => s.toggleProviderEnabled);
25
23
 
26
24
  if (loading)
27
25
  return (
@@ -73,13 +71,7 @@ const ProviderCard = memo<ProviderCardProps>(
73
71
  <Divider style={{ margin: '4px 0' }} />
74
72
  <Flexbox horizontal justify={'space-between'} paddingBlock={'8px 0'}>
75
73
  <div />
76
- <InstantSwitch
77
- enabled={enabled}
78
- onChange={async (checked) => {
79
- await toggleProviderEnabled(id, checked);
80
- }}
81
- size={'small'}
82
- />
74
+ <EnableSwitch enabled={enabled} id={id} />
83
75
  </Flexbox>
84
76
  </Flexbox>
85
77
  </Flexbox>
@@ -0,0 +1,29 @@
1
+ import { FC } from 'react';
2
+
3
+ import InstantSwitch from '@/components/InstantSwitch';
4
+ import { useAiInfraStore } from '@/store/aiInfra';
5
+
6
+ interface SwitchProps {
7
+ Component?: FC<{ enabled: boolean, id: string; }>;
8
+ enabled: boolean;
9
+ id: string;
10
+ }
11
+
12
+ const Switch = ({ id, Component, enabled }: SwitchProps) => {
13
+ const [toggleProviderEnabled] = useAiInfraStore((s) => [s.toggleProviderEnabled]);
14
+
15
+ // slot for cloud
16
+ if (Component) return <Component enabled={enabled} id={id} />;
17
+
18
+ return (
19
+ <InstantSwitch
20
+ enabled={enabled}
21
+ onChange={async (checked) => {
22
+ await toggleProviderEnabled(id, checked);
23
+ }}
24
+ size={'small'}
25
+ />
26
+ );
27
+ };
28
+
29
+ export default Switch;
@@ -29,6 +29,10 @@ const useStyles = createStyles(({ css, responsive, token }) => ({
29
29
  ${responsive.desktop} {
30
30
  grid-template-columns: repeat(3, 1fr);
31
31
  }
32
+
33
+ ${responsive.md} {
34
+ grid-template-columns: repeat(1, 1fr);
35
+ }
32
36
  `,
33
37
  }));
34
38
 
@@ -51,7 +55,7 @@ const List = memo(() => {
51
55
  {t('list.title.enabled')}
52
56
  </Typography.Text>
53
57
  </Flexbox>
54
- <Grid>
58
+ <Grid className={styles.grid}>
55
59
  {loadingArr.map((item) => (
56
60
  <Card enabled={false} id={item} key={item} loading source={'builtin'} />
57
61
  ))}
@@ -50,7 +50,7 @@ export const Placeholder = memo(() => {
50
50
  });
51
51
 
52
52
  export const SkeletonList = memo(() => (
53
- <Flexbox gap={4} style={{ paddingTop: 6 }}>
53
+ <Flexbox flex={1} gap={4} style={{ paddingTop: 6 }}>
54
54
  {Array.from({ length: 6 }).map((_, i) => (
55
55
  <Placeholder key={i} />
56
56
  ))}
@@ -31,7 +31,7 @@ const Layout = memo(({ children, mobile }: ProviderMenuProps) => {
31
31
 
32
32
  const width = mobile ? undefined : 260;
33
33
  return (
34
- <Flexbox style={{ minWidth: width, overflow: 'scroll' }} width={width}>
34
+ <Flexbox style={{ minWidth: width, overflow: mobile ? undefined : 'scroll' }} width={width}>
35
35
  <Flexbox
36
36
  gap={8}
37
37
  horizontal
@@ -5,6 +5,7 @@ import { DEFAULT_LANG, isLocaleNotSupport } from '@/const/locale';
5
5
  import { Locales, normalizeLocale } from '@/locales/resources';
6
6
  import { EdgeConfig } from '@/server/modules/EdgeConfig';
7
7
  import { AgentStoreIndex } from '@/types/discover';
8
+ import { RevalidateTag } from '@/types/requestCache';
8
9
 
9
10
  export class AssistantStore {
10
11
  private readonly baseUrl: string;
@@ -29,10 +30,14 @@ export class AssistantStore {
29
30
  try {
30
31
  let res: Response;
31
32
 
32
- res = await fetch(this.getAgentIndexUrl(locale as any), { next: { revalidate } });
33
+ res = await fetch(this.getAgentIndexUrl(locale as any), {
34
+ next: { revalidate, tags: [RevalidateTag.AgentIndex] },
35
+ });
33
36
 
34
37
  if (res.status === 404) {
35
- res = await fetch(this.getAgentIndexUrl(DEFAULT_LANG), { next: { revalidate } });
38
+ res = await fetch(this.getAgentIndexUrl(DEFAULT_LANG), {
39
+ next: { revalidate, tags: [RevalidateTag.AgentIndex] },
40
+ });
36
41
  }
37
42
 
38
43
  if (!res.ok) {
@@ -42,14 +47,20 @@ export class AssistantStore {
42
47
 
43
48
  const data: AgentStoreIndex = await res.json();
44
49
 
45
- // Get the assistant whitelist from Edge Config
46
- const edgeConfig = new EdgeConfig();
50
+ if (EdgeConfig.isEnabled()) {
51
+ // Get the assistant whitelist from Edge Config
52
+ const edgeConfig = new EdgeConfig();
47
53
 
48
- if (!!appEnv.VERCEL_EDGE_CONFIG) {
49
- const assistantWhitelist = await edgeConfig.getAgentWhitelist();
54
+ const { whitelist, blacklist } = await edgeConfig.getAgentRestrictions();
50
55
 
51
- if (assistantWhitelist && assistantWhitelist?.length > 0) {
52
- data.agents = data.agents.filter((item) => assistantWhitelist.includes(item.identifier));
56
+ // use whitelist mode first
57
+ if (whitelist && whitelist?.length > 0) {
58
+ data.agents = data.agents.filter((item) => whitelist.includes(item.identifier));
59
+ }
60
+
61
+ // if no whitelist, use blacklist mode
62
+ else if (blacklist && blacklist?.length > 0) {
63
+ data.agents = data.agents.filter((item) => !blacklist.includes(item.identifier));
53
64
  }
54
65
  }
55
66
 
@@ -2,12 +2,16 @@ import { EdgeConfigClient, createClient } from '@vercel/edge-config';
2
2
 
3
3
  import { appEnv } from '@/config/app';
4
4
 
5
- enum EdgeConfigKeys {
5
+ const EdgeConfigKeys = {
6
6
  /**
7
7
  * Assistant whitelist
8
8
  */
9
- AssistantWhitelist = 'assistant_whitelist',
10
- }
9
+ AssistantBlacklist: 'assistant_blacklist',
10
+ /**
11
+ * Assistant whitelist
12
+ */
13
+ AssistantWhitelist: 'assistant_whitelist',
14
+ };
11
15
 
12
16
  export class EdgeConfig {
13
17
  get client(): EdgeConfigClient {
@@ -17,7 +21,23 @@ export class EdgeConfig {
17
21
  return createClient(appEnv.VERCEL_EDGE_CONFIG);
18
22
  }
19
23
 
20
- getAgentWhitelist = async (): Promise<string[] | undefined> => {
21
- return this.client.get<string[]>(EdgeConfigKeys.AssistantWhitelist);
24
+ /**
25
+ * Check if Edge Config is enabled
26
+ */
27
+ static isEnabled() {
28
+ return !!appEnv.VERCEL_EDGE_CONFIG;
29
+ }
30
+
31
+ getAgentRestrictions = async () => {
32
+ const { assistant_blacklist: blacklist, assistant_whitelist: whitelist } =
33
+ await this.client.getAll([
34
+ EdgeConfigKeys.AssistantWhitelist,
35
+ EdgeConfigKeys.AssistantBlacklist,
36
+ ]);
37
+
38
+ return { blacklist, whitelist } as {
39
+ blacklist: string[] | undefined;
40
+ whitelist: string[] | undefined;
41
+ };
22
42
  };
23
43
  }
@@ -0,0 +1,3 @@
1
+ export enum RevalidateTag {
2
+ AgentIndex = 'agent_index',
3
+ }
@@ -1,27 +0,0 @@
1
- 'use client';
2
-
3
- import { useLayoutEffect } from 'react';
4
- import urlJoin from 'url-join';
5
-
6
- import { useQuery } from '@/hooks/useQuery';
7
- import { useQueryRoute } from '@/hooks/useQueryRoute';
8
- import { SettingsTabs } from '@/store/global/initialState';
9
-
10
- /**
11
- * @description: Settings Modal (intercepting routes fallback when hard refresh)
12
- * @example: /settings/modal?tab=common => /settings/common
13
- * @refs: https://github.com/lobehub/lobe-chat/discussions/2295#discussioncomment-9290942
14
- */
15
-
16
- const SettingsModalFallback = () => {
17
- const { tab = SettingsTabs.Common } = useQuery();
18
- const router = useQueryRoute();
19
-
20
- useLayoutEffect(() => {
21
- router.replace(urlJoin('/settings', tab as SettingsTabs), { query: { tab: '' } });
22
- }, []);
23
-
24
- return null;
25
- };
26
-
27
- export default SettingsModalFallback;