Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from lobehub:main #53

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

# Changelog

## [Version 1.38.0](https://github.com/lobehub/lobe-chat/compare/v1.37.2...v1.38.0)

<sup>Released on **2024-12-23**</sup>

#### ✨ Features

- **misc**: Support thread in client pglite.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### 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))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.37.2](https://github.com/lobehub/lobe-chat/compare/v1.37.1...v1.37.2)

<sup>Released on **2024-12-22**</sup>
Expand Down
7 changes: 7 additions & 0 deletions changelog/v1.json
Original file line number Diff line number Diff line change
@@ -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."]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/const/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/features/Conversation/hooks/useChatListActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'),
},
Expand Down
2 changes: 1 addition & 1 deletion src/locales/default/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
blog: '产品博客',
branching: '创建子话题',
branchingDisable:
'「子话题」功能仅服务端版本可用,如需该功能,请切换到服务端部署模式或使用 LobeChat Cloud',
'「子话题」功能在当前模式下不可用,如需该功能,请切换到 Postgres/Pglite DB 模式或使用 LobeChat Cloud',
cancel: '取消',
changelog: '更新日志',
clientDB: {
Expand Down
57 changes: 57 additions & 0 deletions src/services/thread/client.ts
Original file line number Diff line number Diff line change
@@ -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<ThreadItem[]> => {
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<ThreadItem>): Promise<any> {
return this.threadModel.update(id, data);
}

removeThread(id: string): Promise<any> {
return this.threadModel.delete(id);
}

private toDbSessionId(sessionId: string | undefined) {
return sessionId === INBOX_SESSION_ID ? null : sessionId;
}
}
5 changes: 5 additions & 0 deletions src/services/thread/index.ts
Original file line number Diff line number Diff line change
@@ -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();
23 changes: 3 additions & 20 deletions src/services/thread.ts → src/services/thread/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadItem[]> => {
return lambdaClient.thread.getThreads.query({ topicId });
};
Expand All @@ -21,34 +23,15 @@ export class ThreadService {
});
}

// createThread(params: CreateThreadParams): Promise<string> {
// return lambdaClient.thread.createThread.mutate(params);
// }

updateThread(id: string, data: Partial<ThreadItem>): Promise<any> {
return lambdaClient.thread.updateThread.mutate({ id, value: data });
}

//
removeThread(id: string): Promise<any> {
return lambdaClient.thread.removeThread.mutate({ id });
}
//
// removeThreads(sessionId: string): Promise<any> {
// return lambdaClient.thread.batchDeleteBySessionId.mutate({ id: this.toDbSessionId(sessionId) });
// }
//
// batchRemoveThreads(topics: string[]): Promise<any> {
// return lambdaClient.thread.batchDelete.mutate({ ids: topics });
// }
//
// removeAllThread(): Promise<any> {
// return lambdaClient.thread.removeAllThreads.mutate();
// }

private toDbSessionId(sessionId: string | undefined) {
return sessionId === INBOX_SESSION_ID ? null : sessionId;
}
}

export const threadService = new ThreadService();
20 changes: 20 additions & 0 deletions src/services/thread/type.ts
Original file line number Diff line number Diff line change
@@ -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<ThreadItem[]>;

createThreadWithMessage({
message,
...params
}: CreateThreadWithMessageParams): Promise<{ messageId: string; threadId: string }>;

updateThread(id: string, data: Partial<ThreadItem>): Promise<any>;
//
removeThread(id: string): Promise<any>;
}
4 changes: 2 additions & 2 deletions src/store/chat/slices/thread/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -211,7 +211,7 @@ export const chatThreadMessage: StateCreator<

useFetchThreads: (enable, topicId) =>
useClientDataSWR<ThreadItem[]>(
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,
Expand Down
Loading