@lobehub/chat 1.47.8 → 1.47.10

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.10](https://github.com/lobehub/lobe-chat/compare/v1.47.9...v1.47.10)
6
+
7
+ <sup>Released on **2025-01-21**</sup>
8
+
9
+ #### 💄 Styles
10
+
11
+ - **misc**: Support assistant blacklist.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Styles
19
+
20
+ - **misc**: Support assistant blacklist, closes [#5527](https://github.com/lobehub/lobe-chat/issues/5527) ([3534c0d](https://github.com/lobehub/lobe-chat/commit/3534c0d))
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.9](https://github.com/lobehub/lobe-chat/compare/v1.47.8...v1.47.9)
31
+
32
+ <sup>Released on **2025-01-20**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Improve error code.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Improve error code, closes [#5525](https://github.com/lobehub/lobe-chat/issues/5525) ([4fc4fa6](https://github.com/lobehub/lobe-chat/commit/4fc4fa6))
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.8](https://github.com/lobehub/lobe-chat/compare/v1.47.7...v1.47.8)
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
+ "Support assistant blacklist."
6
+ ]
7
+ },
8
+ "date": "2025-01-21",
9
+ "version": "1.47.10"
10
+ },
11
+ {
12
+ "children": {
13
+ "improvements": [
14
+ "Improve error code."
15
+ ]
16
+ },
17
+ "date": "2025-01-20",
18
+ "version": "1.47.9"
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.8",
3
+ "version": "1.47.10",
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",
@@ -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
+ };
@@ -39,6 +39,9 @@ export const userSettings = pgTable('user_settings', {
39
39
  .primaryKey(),
40
40
 
41
41
  tts: jsonb('tts'),
42
+ /**
43
+ * @deprecated
44
+ */
42
45
  keyVaults: text('key_vaults'),
43
46
  general: jsonb('general'),
44
47
  languageModel: jsonb('language_model'),
@@ -12,6 +12,12 @@ export const genServerAiProvidersConfig = (specificConfig: Record<any, any>) =>
12
12
  (config, provider) => {
13
13
  const providerUpperCase = provider.toUpperCase();
14
14
  const providerCard = AiModels[provider] as AiFullModelCard[];
15
+
16
+ if (!providerCard)
17
+ throw new Error(
18
+ `Provider [${provider}] not found in aiModels, please make sure you have exported the provider in the \`aiModels/index.ts\``,
19
+ );
20
+
15
21
  const providerConfig = specificConfig[provider as keyof typeof specificConfig] || {};
16
22
  const providerModelList =
17
23
  process.env[providerConfig.modelListKey ?? `${providerUpperCase}_MODEL_LIST`];
@@ -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
+ }