@lobehub/lobehub 2.0.0-next.39 → 2.0.0-next.40

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,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 2.0.0-next.40](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.39...v2.0.0-next.40)
6
+
7
+ <sup>Released on **2025-11-08**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **database**: Fix deleteMessagesBySession incorrectly deleting all messages.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **database**: Fix deleteMessagesBySession incorrectly deleting all messages, closes [#10110](https://github.com/lobehub/lobe-chat/issues/10110) ([1d7f67d](https://github.com/lobehub/lobe-chat/commit/1d7f67d))
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
+
5
30
  ## [Version 2.0.0-next.39](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.38...v2.0.0-next.39)
6
31
 
7
32
  <sup>Released on **2025-11-08**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,9 @@
1
1
  [
2
+ {
3
+ "children": {},
4
+ "date": "2025-11-08",
5
+ "version": "2.0.0-next.40"
6
+ },
2
7
  {
3
8
  "children": {},
4
9
  "date": "2025-11-08",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/lobehub",
3
- "version": "2.0.0-next.39",
3
+ "version": "2.0.0-next.40",
4
4
  "description": "LobeHub - an open-source,comprehensive AI Agent 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",
@@ -1922,6 +1922,63 @@ describe('MessageModel', () => {
1922
1922
  expect(remainingMessages).toHaveLength(1);
1923
1923
  expect(remainingMessages[0].id).toBe('2');
1924
1924
  });
1925
+
1926
+ it('should delete only non-topic messages when topicId is null', async () => {
1927
+ await serverDB.insert(sessions).values([{ id: 'session1', userId }]);
1928
+ await serverDB.insert(topics).values([
1929
+ { id: 'topic1', sessionId: 'session1', userId },
1930
+ { id: 'topic2', sessionId: 'session1', userId },
1931
+ ]);
1932
+
1933
+ await serverDB.insert(messages).values([
1934
+ {
1935
+ id: '1',
1936
+ userId,
1937
+ sessionId: 'session1',
1938
+ topicId: null,
1939
+ role: 'user',
1940
+ content: 'message without topic 1',
1941
+ },
1942
+ {
1943
+ id: '2',
1944
+ userId,
1945
+ sessionId: 'session1',
1946
+ topicId: null,
1947
+ role: 'assistant',
1948
+ content: 'message without topic 2',
1949
+ },
1950
+ {
1951
+ id: '3',
1952
+ userId,
1953
+ sessionId: 'session1',
1954
+ topicId: 'topic1',
1955
+ role: 'user',
1956
+ content: 'message in topic1',
1957
+ },
1958
+ {
1959
+ id: '4',
1960
+ userId,
1961
+ sessionId: 'session1',
1962
+ topicId: 'topic2',
1963
+ role: 'assistant',
1964
+ content: 'message in topic2',
1965
+ },
1966
+ ]);
1967
+
1968
+ // Delete messages in session1 with null topicId
1969
+ await messageModel.deleteMessagesBySession('session1', null);
1970
+
1971
+ const remainingMessages = await serverDB
1972
+ .select()
1973
+ .from(messages)
1974
+ .where(eq(messages.userId, userId))
1975
+ .orderBy(messages.id);
1976
+
1977
+ // Should only keep messages with topics
1978
+ expect(remainingMessages).toHaveLength(2);
1979
+ expect(remainingMessages[0].id).toBe('3');
1980
+ expect(remainingMessages[1].id).toBe('4');
1981
+ });
1925
1982
  });
1926
1983
 
1927
1984
  describe('genId', () => {
@@ -768,19 +768,17 @@ export class MessageModel {
768
768
  sessionId?: string | null,
769
769
  topicId?: string | null,
770
770
  groupId?: string | null,
771
- ) => {
772
- const conditions = [eq(messages.userId, this.userId), this.matchSession(sessionId)];
773
-
774
- // For deletion: only filter by topicId/groupId if explicitly provided
775
- if (topicId !== undefined && topicId !== null) {
776
- conditions.push(eq(messages.topicId, topicId));
777
- }
778
- if (groupId !== undefined && groupId !== null) {
779
- conditions.push(eq(messages.groupId, groupId));
780
- }
781
-
782
- return this.db.delete(messages).where(and(...conditions));
783
- };
771
+ ) =>
772
+ this.db
773
+ .delete(messages)
774
+ .where(
775
+ and(
776
+ eq(messages.userId, this.userId),
777
+ this.matchSession(sessionId),
778
+ this.matchTopic(topicId),
779
+ this.matchGroup(groupId),
780
+ ),
781
+ );
784
782
 
785
783
  deleteAllMessages = async () => {
786
784
  return this.db.delete(messages).where(eq(messages.userId, this.userId));