From 848b29ffc6b7b61b72f813e0794c9f0924ff8e6f Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Mon, 23 Dec 2024 16:36:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20feat:=20support=20thread=20in?= =?UTF-8?q?=20client=20pglite=20(#5150)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/const/version.ts | 2 + .../hooks/useChatListActionsBar.tsx | 6 +- src/locales/default/common.ts | 2 +- src/services/thread/client.ts | 57 +++++++++++++++++++ src/services/thread/index.ts | 5 ++ src/services/{thread.ts => thread/server.ts} | 23 +------- src/services/thread/type.ts | 20 +++++++ src/store/chat/slices/thread/action.ts | 4 +- 8 files changed, 93 insertions(+), 26 deletions(-) create mode 100644 src/services/thread/client.ts create mode 100644 src/services/thread/index.ts rename src/services/{thread.ts => thread/server.ts} (64%) create mode 100644 src/services/thread/type.ts diff --git a/src/const/version.ts b/src/const/version.ts index 0f3819a47490..b25c445d0b85 100644 --- a/src/const/version.ts +++ b/src/const/version.ts @@ -8,6 +8,8 @@ export const CURRENT_VERSION = pkg.version; export const isServerMode = getServerDBConfig().NEXT_PUBLIC_ENABLED_SERVER_SERVICE; export const isUsePgliteDB = process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite'; +export const isDeprecatedEdition = !isServerMode && !isUsePgliteDB; + // @ts-ignore export const isCustomBranding = BRANDING_NAME !== 'LobeChat'; // @ts-ignore diff --git a/src/features/Conversation/hooks/useChatListActionsBar.tsx b/src/features/Conversation/hooks/useChatListActionsBar.tsx index caecfc84057a..74b8e50378cc 100644 --- a/src/features/Conversation/hooks/useChatListActionsBar.tsx +++ b/src/features/Conversation/hooks/useChatListActionsBar.tsx @@ -3,7 +3,7 @@ import { Copy, Edit, ListRestart, RotateCcw, Split, Trash } from 'lucide-react'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import { isServerMode } from '@/const/version'; +import { isDeprecatedEdition } from '@/const/version'; interface ChatListActionsBar { branching: ActionIconGroupItems; @@ -23,10 +23,10 @@ export const useChatListActionsBar = ({ return useMemo( () => ({ branching: { - disable: !isServerMode, + disable: isDeprecatedEdition, icon: Split, key: 'branching', - label: isServerMode + label: !isDeprecatedEdition ? t('branching', { defaultValue: 'Create Sub Topic' }) : t('branchingDisable'), }, diff --git a/src/locales/default/common.ts b/src/locales/default/common.ts index bfcb7dbe2439..e0463b327639 100644 --- a/src/locales/default/common.ts +++ b/src/locales/default/common.ts @@ -33,7 +33,7 @@ export default { blog: '产品博客', branching: '创建子话题', branchingDisable: - '「子话题」功能仅服务端版本可用,如需该功能,请切换到服务端部署模式或使用 LobeChat Cloud', + '「子话题」功能在当前模式下不可用,如需该功能,请切换到 Postgres/Pglite DB 模式或使用 LobeChat Cloud', cancel: '取消', changelog: '更新日志', clientDB: { diff --git a/src/services/thread/client.ts b/src/services/thread/client.ts new file mode 100644 index 000000000000..e2ccdbe8435f --- /dev/null +++ b/src/services/thread/client.ts @@ -0,0 +1,57 @@ +import { INBOX_SESSION_ID } from '@/const/session'; +import { clientDB } from '@/database/client/db'; +import { MessageModel } from '@/database/server/models/message'; +import { ThreadModel } from '@/database/server/models/thread'; +import { BaseClientService } from '@/services/baseClientService'; +import { CreateMessageParams } from '@/types/message'; +import { CreateThreadParams, ThreadItem } from '@/types/topic'; + +import { IThreadService } from './type'; + +interface CreateThreadWithMessageParams extends CreateThreadParams { + message: CreateMessageParams; +} +export class ClientService extends BaseClientService implements IThreadService { + private get threadModel(): ThreadModel { + return new ThreadModel(clientDB as any, this.userId); + } + private get messageModel(): MessageModel { + return new MessageModel(clientDB as any, this.userId); + } + + getThreads = async (topicId: string): Promise => { + return this.threadModel.queryByTopicId(topicId); + }; + + createThreadWithMessage = async ( + input: CreateThreadWithMessageParams, + ): Promise<{ messageId: string; threadId: string }> => { + const thread = await this.threadModel.create({ + parentThreadId: input.parentThreadId, + sourceMessageId: input.sourceMessageId, + title: input.message.content.slice(0, 20), + topicId: input.topicId, + type: input.type, + }); + + const message = await this.messageModel.create({ + ...input.message, + sessionId: this.toDbSessionId(input.message.sessionId) as string, + threadId: thread?.id, + }); + + return { messageId: message?.id, threadId: thread?.id }; + }; + + updateThread(id: string, data: Partial): Promise { + return this.threadModel.update(id, data); + } + + removeThread(id: string): Promise { + return this.threadModel.delete(id); + } + + private toDbSessionId(sessionId: string | undefined) { + return sessionId === INBOX_SESSION_ID ? null : sessionId; + } +} diff --git a/src/services/thread/index.ts b/src/services/thread/index.ts new file mode 100644 index 000000000000..58f14219ea45 --- /dev/null +++ b/src/services/thread/index.ts @@ -0,0 +1,5 @@ +import { ClientService } from './client'; +import { ServerService } from './server'; + +export const threadService = + process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService(); diff --git a/src/services/thread.ts b/src/services/thread/server.ts similarity index 64% rename from src/services/thread.ts rename to src/services/thread/server.ts index a760c82b770d..7eea2187b8ba 100644 --- a/src/services/thread.ts +++ b/src/services/thread/server.ts @@ -3,10 +3,12 @@ import { lambdaClient } from '@/libs/trpc/client'; import { CreateMessageParams } from '@/types/message'; import { CreateThreadParams, ThreadItem } from '@/types/topic'; +import { IThreadService } from './type'; + interface CreateThreadWithMessageParams extends CreateThreadParams { message: CreateMessageParams; } -export class ThreadService { +export class ServerService implements IThreadService { getThreads = (topicId: string): Promise => { return lambdaClient.thread.getThreads.query({ topicId }); }; @@ -21,34 +23,15 @@ export class ThreadService { }); } - // createThread(params: CreateThreadParams): Promise { - // return lambdaClient.thread.createThread.mutate(params); - // } - updateThread(id: string, data: Partial): Promise { return lambdaClient.thread.updateThread.mutate({ id, value: data }); } - // removeThread(id: string): Promise { return lambdaClient.thread.removeThread.mutate({ id }); } - // - // removeThreads(sessionId: string): Promise { - // return lambdaClient.thread.batchDeleteBySessionId.mutate({ id: this.toDbSessionId(sessionId) }); - // } - // - // batchRemoveThreads(topics: string[]): Promise { - // return lambdaClient.thread.batchDelete.mutate({ ids: topics }); - // } - // - // removeAllThread(): Promise { - // return lambdaClient.thread.removeAllThreads.mutate(); - // } private toDbSessionId(sessionId: string | undefined) { return sessionId === INBOX_SESSION_ID ? null : sessionId; } } - -export const threadService = new ThreadService(); diff --git a/src/services/thread/type.ts b/src/services/thread/type.ts new file mode 100644 index 000000000000..d4ade28f3559 --- /dev/null +++ b/src/services/thread/type.ts @@ -0,0 +1,20 @@ +/* eslint-disable typescript-sort-keys/interface */ +import { CreateMessageParams } from '@/types/message'; +import { CreateThreadParams, ThreadItem } from '@/types/topic'; + +interface CreateThreadWithMessageParams extends CreateThreadParams { + message: CreateMessageParams; +} + +export interface IThreadService { + getThreads(topicId: string): Promise; + + createThreadWithMessage({ + message, + ...params + }: CreateThreadWithMessageParams): Promise<{ messageId: string; threadId: string }>; + + updateThread(id: string, data: Partial): Promise; + // + removeThread(id: string): Promise; +} diff --git a/src/store/chat/slices/thread/action.ts b/src/store/chat/slices/thread/action.ts index b9381a373bb9..31797e78653d 100644 --- a/src/store/chat/slices/thread/action.ts +++ b/src/store/chat/slices/thread/action.ts @@ -6,7 +6,7 @@ import { StateCreator } from 'zustand/vanilla'; import { chainSummaryTitle } from '@/chains/summaryTitle'; import { LOADING_FLAT, THREAD_DRAFT_ID } from '@/const/message'; -import { isServerMode } from '@/const/version'; +import { isDeprecatedEdition } from '@/const/version'; import { useClientDataSWR } from '@/libs/swr'; import { chatService } from '@/services/chat'; import { threadService } from '@/services/thread'; @@ -211,7 +211,7 @@ export const chatThreadMessage: StateCreator< useFetchThreads: (enable, topicId) => useClientDataSWR( - enable && !!topicId && isServerMode ? [SWR_USE_FETCH_THREADS, topicId] : null, + enable && !!topicId && !isDeprecatedEdition ? [SWR_USE_FETCH_THREADS, topicId] : null, async ([, topicId]: [string, string]) => threadService.getThreads(topicId), { suspense: true, From 2a3d19f8ccfb8ec4a0d9424f16459186b02ff7c3 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 23 Dec 2024 08:44:29 +0000 Subject: [PATCH 2/4] :bookmark: chore(release): v1.38.0 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [Version 1.38.0](https://github.com/lobehub/lobe-chat/compare/v1.37.2...v1.38.0) Released on **2024-12-23** #### ✨ Features - **misc**: Support thread in client pglite.
Improvements and Fixes #### What's improved * **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))
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
--- CHANGELOG.md | 25 +++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f8f5c3ae902..68026d46aada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,31 @@ # Changelog +## [Version 1.38.0](https://github.com/lobehub/lobe-chat/compare/v1.37.2...v1.38.0) + +Released on **2024-12-23** + +#### ✨ Features + +- **misc**: Support thread in client pglite. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **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)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ ### [Version 1.37.2](https://github.com/lobehub/lobe-chat/compare/v1.37.1...v1.37.2) Released on **2024-12-22** diff --git a/package.json b/package.json index ccfdaea410e4..3ecb8fbff884 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lobehub/chat", - "version": "1.37.2", + "version": "1.38.0", "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", From 8b107f4ff2e81435ced6dfc3c3d1132ec21630dd Mon Sep 17 00:00:00 2001 From: lobehubbot Date: Mon, 23 Dec 2024 08:45:26 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9D=20docs(bot):=20Auto=20sync=20a?= =?UTF-8?q?gents=20&=20plugin=20to=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/v1.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog/v1.json b/changelog/v1.json index cad6ab8f83ff..807916cd8420 100644 --- a/changelog/v1.json +++ b/changelog/v1.json @@ -1,4 +1,11 @@ [ + { + "children": { + "features": ["Support thread in client pglite."] + }, + "date": "2024-12-23", + "version": "1.38.0" + }, { "children": { "improvements": ["Move pglite to client service."] From 4f6d8fc5b3274fa17563c509adab74cebc8909ef Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:57:02 +0800 Subject: [PATCH 4/4] Update dependency @anthropic-ai/sdk to ^0.33.0 (#5123) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ecb8fbff884..26f6e1b2e3cd 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "dependencies": { "@ant-design/icons": "^5.5.1", "@ant-design/pro-components": "^2.7.18", - "@anthropic-ai/sdk": "^0.32.0", + "@anthropic-ai/sdk": "^0.33.0", "@auth/core": "^0.37.0", "@aws-sdk/client-bedrock-runtime": "^3.675.0", "@aws-sdk/client-s3": "^3.675.0",