@lobehub/chat 1.37.1 → 1.38.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/changelog/v1.json +18 -0
  3. package/locales/en-US/common.json +2 -2
  4. package/package.json +1 -1
  5. package/src/const/version.ts +2 -0
  6. package/src/features/Conversation/hooks/useChatListActionsBar.tsx +3 -3
  7. package/src/locales/default/common.ts +1 -1
  8. package/src/services/file/{pglite.test.ts → client.test.ts} +1 -1
  9. package/src/services/file/index.ts +1 -1
  10. package/src/services/import/{pglite.test.ts → client.test.ts} +1 -1
  11. package/src/services/import/index.ts +1 -1
  12. package/src/services/message/{pglite.test.ts → client.test.ts} +1 -1
  13. package/src/services/message/index.ts +1 -1
  14. package/src/services/plugin/{pglite.test.ts → client.test.ts} +1 -1
  15. package/src/services/plugin/index.ts +1 -1
  16. package/src/services/session/{pglite.test.ts → client.test.ts} +1 -1
  17. package/src/services/session/index.ts +1 -1
  18. package/src/services/thread/client.ts +57 -0
  19. package/src/services/thread/index.ts +5 -0
  20. package/src/services/{thread.ts → thread/server.ts} +3 -20
  21. package/src/services/thread/type.ts +20 -0
  22. package/src/services/topic/index.ts +1 -1
  23. package/src/services/topic/pglite.test.ts +1 -1
  24. package/src/services/user/{pglite.test.ts → client.test.ts} +1 -1
  25. package/src/services/user/index.ts +1 -1
  26. package/src/store/chat/slices/thread/action.ts +2 -2
  27. /package/src/services/file/{pglite.ts → client.ts} +0 -0
  28. /package/src/services/import/{pglite.ts → client.ts} +0 -0
  29. /package/src/services/message/{pglite.ts → client.ts} +0 -0
  30. /package/src/services/plugin/{pglite.ts → client.ts} +0 -0
  31. /package/src/services/session/{pglite.ts → client.ts} +0 -0
  32. /package/src/services/topic/{client.test.ts → _deprecated.test.ts} +0 -0
  33. /package/src/services/topic/{pglite.ts → client.ts} +0 -0
  34. /package/src/services/user/{pglite.ts → client.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 1.38.0](https://github.com/lobehub/lobe-chat/compare/v1.37.2...v1.38.0)
6
+
7
+ <sup>Released on **2024-12-23**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support thread in client pglite.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support thread in client pglite, closes [#5150](https://github.com/lobehub/lobe-chat/issues/5150) ([848b29f](https://github.com/lobehub/lobe-chat/commit/848b29f))
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.37.2](https://github.com/lobehub/lobe-chat/compare/v1.37.1...v1.37.2)
31
+
32
+ <sup>Released on **2024-12-22**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Move pglite to client service.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Move pglite to client service, closes [#5133](https://github.com/lobehub/lobe-chat/issues/5133) ([c2ded24](https://github.com/lobehub/lobe-chat/commit/c2ded24))
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.37.1](https://github.com/lobehub/lobe-chat/compare/v1.37.0...v1.37.1)
6
56
 
7
57
  <sup>Released on **2024-12-22**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,22 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "features": [
5
+ "Support thread in client pglite."
6
+ ]
7
+ },
8
+ "date": "2024-12-23",
9
+ "version": "1.38.0"
10
+ },
11
+ {
12
+ "children": {
13
+ "improvements": [
14
+ "Move pglite to client service."
15
+ ]
16
+ },
17
+ "date": "2024-12-22",
18
+ "version": "1.37.2"
19
+ },
2
20
  {
3
21
  "children": {
4
22
  "improvements": [
@@ -59,14 +59,14 @@
59
59
  "features": {
60
60
  "knowledgeBase": {
61
61
  "desc": "Build your personal knowledge base and easily start conversations with your assistant (coming soon)",
62
- "title": "Support for knowledge base conversations, unlock your second brain"
62
+ "title": "Support for knowledge base conversations"
63
63
  },
64
64
  "localFirst": {
65
65
  "desc": "Chat data is stored entirely in the browser, keeping your data always under your control.",
66
66
  "title": "Local first, privacy first"
67
67
  },
68
68
  "pglite": {
69
- "desc": "Built on PGlite, natively supports AI Native advanced features (vector retrieval)",
69
+ "desc": "Built on PGlite, natively supports AI Native advanced features (vector search)",
70
70
  "title": "Next-generation client storage architecture"
71
71
  }
72
72
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.37.1",
3
+ "version": "1.38.0",
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",
@@ -8,6 +8,8 @@ export const CURRENT_VERSION = pkg.version;
8
8
  export const isServerMode = getServerDBConfig().NEXT_PUBLIC_ENABLED_SERVER_SERVICE;
9
9
  export const isUsePgliteDB = process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite';
10
10
 
11
+ export const isDeprecatedEdition = !isServerMode && !isUsePgliteDB;
12
+
11
13
  // @ts-ignore
12
14
  export const isCustomBranding = BRANDING_NAME !== 'LobeChat';
13
15
  // @ts-ignore
@@ -3,7 +3,7 @@ import { Copy, Edit, ListRestart, RotateCcw, Split, Trash } from 'lucide-react';
3
3
  import { useMemo } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
 
6
- import { isServerMode } from '@/const/version';
6
+ import { isDeprecatedEdition } from '@/const/version';
7
7
 
8
8
  interface ChatListActionsBar {
9
9
  branching: ActionIconGroupItems;
@@ -23,10 +23,10 @@ export const useChatListActionsBar = ({
23
23
  return useMemo(
24
24
  () => ({
25
25
  branching: {
26
- disable: !isServerMode,
26
+ disable: isDeprecatedEdition,
27
27
  icon: Split,
28
28
  key: 'branching',
29
- label: isServerMode
29
+ label: !isDeprecatedEdition
30
30
  ? t('branching', { defaultValue: 'Create Sub Topic' })
31
31
  : t('branchingDisable'),
32
32
  },
@@ -33,7 +33,7 @@ export default {
33
33
  blog: '产品博客',
34
34
  branching: '创建子话题',
35
35
  branchingDisable:
36
- '「子话题」功能仅服务端版本可用,如需该功能,请切换到服务端部署模式或使用 LobeChat Cloud',
36
+ '「子话题」功能在当前模式下不可用,如需该功能,请切换到 Postgres/Pglite DB 模式或使用 LobeChat Cloud',
37
37
  cancel: '取消',
38
38
  changelog: '更新日志',
39
39
  clientDB: {
@@ -6,7 +6,7 @@ import { files, globalFiles, users } from '@/database/schemas';
6
6
  import { clientS3Storage } from '@/services/file/ClientS3';
7
7
  import { UploadFileParams } from '@/types/files';
8
8
 
9
- import { ClientService } from './pglite';
9
+ import { ClientService } from './client';
10
10
 
11
11
  const userId = 'file-user';
12
12
 
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -15,7 +15,7 @@ import {
15
15
  import { CURRENT_CONFIG_VERSION } from '@/migrations';
16
16
  import { ImportResults, ImporterEntryData } from '@/types/importer';
17
17
 
18
- import { ClientService } from './pglite';
18
+ import { ClientService } from './client';
19
19
 
20
20
  const userId = 'test-user-id';
21
21
  const service = new ClientService(userId);
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -23,7 +23,7 @@ import {
23
23
  CreateMessageParams,
24
24
  } from '@/types/message';
25
25
 
26
- import { ClientService } from './pglite';
26
+ import { ClientService } from './client';
27
27
 
28
28
  const userId = 'message-db';
29
29
  const sessionId = '1';
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -7,7 +7,7 @@ import { installedPlugins, users } from '@/database/schemas';
7
7
  import { LobeTool } from '@/types/tool';
8
8
  import { LobeToolCustomPlugin } from '@/types/tool/plugin';
9
9
 
10
- import { ClientService } from './pglite';
10
+ import { ClientService } from './client';
11
11
  import { InstallPluginParams } from './type';
12
12
 
13
13
  // Mocking modules and functions
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -15,7 +15,7 @@ import {
15
15
  import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
16
16
  import { LobeAgentSession, LobeSessionType, SessionGroups } from '@/types/session';
17
17
 
18
- import { ClientService } from './pglite';
18
+ import { ClientService } from './client';
19
19
 
20
20
  const userId = 'message-db';
21
21
  const sessionService = new ClientService(userId);
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -0,0 +1,57 @@
1
+ import { INBOX_SESSION_ID } from '@/const/session';
2
+ import { clientDB } from '@/database/client/db';
3
+ import { MessageModel } from '@/database/server/models/message';
4
+ import { ThreadModel } from '@/database/server/models/thread';
5
+ import { BaseClientService } from '@/services/baseClientService';
6
+ import { CreateMessageParams } from '@/types/message';
7
+ import { CreateThreadParams, ThreadItem } from '@/types/topic';
8
+
9
+ import { IThreadService } from './type';
10
+
11
+ interface CreateThreadWithMessageParams extends CreateThreadParams {
12
+ message: CreateMessageParams;
13
+ }
14
+ export class ClientService extends BaseClientService implements IThreadService {
15
+ private get threadModel(): ThreadModel {
16
+ return new ThreadModel(clientDB as any, this.userId);
17
+ }
18
+ private get messageModel(): MessageModel {
19
+ return new MessageModel(clientDB as any, this.userId);
20
+ }
21
+
22
+ getThreads = async (topicId: string): Promise<ThreadItem[]> => {
23
+ return this.threadModel.queryByTopicId(topicId);
24
+ };
25
+
26
+ createThreadWithMessage = async (
27
+ input: CreateThreadWithMessageParams,
28
+ ): Promise<{ messageId: string; threadId: string }> => {
29
+ const thread = await this.threadModel.create({
30
+ parentThreadId: input.parentThreadId,
31
+ sourceMessageId: input.sourceMessageId,
32
+ title: input.message.content.slice(0, 20),
33
+ topicId: input.topicId,
34
+ type: input.type,
35
+ });
36
+
37
+ const message = await this.messageModel.create({
38
+ ...input.message,
39
+ sessionId: this.toDbSessionId(input.message.sessionId) as string,
40
+ threadId: thread?.id,
41
+ });
42
+
43
+ return { messageId: message?.id, threadId: thread?.id };
44
+ };
45
+
46
+ updateThread(id: string, data: Partial<ThreadItem>): Promise<any> {
47
+ return this.threadModel.update(id, data);
48
+ }
49
+
50
+ removeThread(id: string): Promise<any> {
51
+ return this.threadModel.delete(id);
52
+ }
53
+
54
+ private toDbSessionId(sessionId: string | undefined) {
55
+ return sessionId === INBOX_SESSION_ID ? null : sessionId;
56
+ }
57
+ }
@@ -0,0 +1,5 @@
1
+ import { ClientService } from './client';
2
+ import { ServerService } from './server';
3
+
4
+ export const threadService =
5
+ process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService();
@@ -3,10 +3,12 @@ import { lambdaClient } from '@/libs/trpc/client';
3
3
  import { CreateMessageParams } from '@/types/message';
4
4
  import { CreateThreadParams, ThreadItem } from '@/types/topic';
5
5
 
6
+ import { IThreadService } from './type';
7
+
6
8
  interface CreateThreadWithMessageParams extends CreateThreadParams {
7
9
  message: CreateMessageParams;
8
10
  }
9
- export class ThreadService {
11
+ export class ServerService implements IThreadService {
10
12
  getThreads = (topicId: string): Promise<ThreadItem[]> => {
11
13
  return lambdaClient.thread.getThreads.query({ topicId });
12
14
  };
@@ -21,34 +23,15 @@ export class ThreadService {
21
23
  });
22
24
  }
23
25
 
24
- // createThread(params: CreateThreadParams): Promise<string> {
25
- // return lambdaClient.thread.createThread.mutate(params);
26
- // }
27
-
28
26
  updateThread(id: string, data: Partial<ThreadItem>): Promise<any> {
29
27
  return lambdaClient.thread.updateThread.mutate({ id, value: data });
30
28
  }
31
29
 
32
- //
33
30
  removeThread(id: string): Promise<any> {
34
31
  return lambdaClient.thread.removeThread.mutate({ id });
35
32
  }
36
- //
37
- // removeThreads(sessionId: string): Promise<any> {
38
- // return lambdaClient.thread.batchDeleteBySessionId.mutate({ id: this.toDbSessionId(sessionId) });
39
- // }
40
- //
41
- // batchRemoveThreads(topics: string[]): Promise<any> {
42
- // return lambdaClient.thread.batchDelete.mutate({ ids: topics });
43
- // }
44
- //
45
- // removeAllThread(): Promise<any> {
46
- // return lambdaClient.thread.removeAllThreads.mutate();
47
- // }
48
33
 
49
34
  private toDbSessionId(sessionId: string | undefined) {
50
35
  return sessionId === INBOX_SESSION_ID ? null : sessionId;
51
36
  }
52
37
  }
53
-
54
- export const threadService = new ThreadService();
@@ -0,0 +1,20 @@
1
+ /* eslint-disable typescript-sort-keys/interface */
2
+ import { CreateMessageParams } from '@/types/message';
3
+ import { CreateThreadParams, ThreadItem } from '@/types/topic';
4
+
5
+ interface CreateThreadWithMessageParams extends CreateThreadParams {
6
+ message: CreateMessageParams;
7
+ }
8
+
9
+ export interface IThreadService {
10
+ getThreads(topicId: string): Promise<ThreadItem[]>;
11
+
12
+ createThreadWithMessage({
13
+ message,
14
+ ...params
15
+ }: CreateThreadWithMessageParams): Promise<{ messageId: string; threadId: string }>;
16
+
17
+ updateThread(id: string, data: Partial<ThreadItem>): Promise<any>;
18
+ //
19
+ removeThread(id: string): Promise<any>;
20
+ }
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -5,7 +5,7 @@ import { clientDB, initializeDB } from '@/database/client/db';
5
5
  import { sessions, topics, users } from '@/database/schemas';
6
6
  import { ChatTopic } from '@/types/topic';
7
7
 
8
- import { ClientService } from './pglite';
8
+ import { ClientService } from './client';
9
9
 
10
10
  // Mock data
11
11
  const userId = 'topic-user-test';
@@ -7,7 +7,7 @@ import { userSettings, users } from '@/database/schemas';
7
7
  import { UserPreference } from '@/types/user';
8
8
  import { UserSettings } from '@/types/user/settings';
9
9
 
10
- import { ClientService } from './pglite';
10
+ import { ClientService } from './client';
11
11
 
12
12
  const mockUser = {
13
13
  avatar: 'avatar.png',
@@ -1,5 +1,5 @@
1
1
  import { ClientService as DeprecatedService } from './_deprecated';
2
- import { ClientService } from './pglite';
2
+ import { ClientService } from './client';
3
3
  import { ServerService } from './server';
4
4
 
5
5
  const clientService =
@@ -6,7 +6,7 @@ import { StateCreator } from 'zustand/vanilla';
6
6
 
7
7
  import { chainSummaryTitle } from '@/chains/summaryTitle';
8
8
  import { LOADING_FLAT, THREAD_DRAFT_ID } from '@/const/message';
9
- import { isServerMode } from '@/const/version';
9
+ import { isDeprecatedEdition } from '@/const/version';
10
10
  import { useClientDataSWR } from '@/libs/swr';
11
11
  import { chatService } from '@/services/chat';
12
12
  import { threadService } from '@/services/thread';
@@ -211,7 +211,7 @@ export const chatThreadMessage: StateCreator<
211
211
 
212
212
  useFetchThreads: (enable, topicId) =>
213
213
  useClientDataSWR<ThreadItem[]>(
214
- enable && !!topicId && isServerMode ? [SWR_USE_FETCH_THREADS, topicId] : null,
214
+ enable && !!topicId && !isDeprecatedEdition ? [SWR_USE_FETCH_THREADS, topicId] : null,
215
215
  async ([, topicId]: [string, string]) => threadService.getThreads(topicId),
216
216
  {
217
217
  suspense: true,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes