@lobehub/lobehub 2.0.0-next.40 → 2.0.0-next.41
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 +25 -0
- package/changelog/v1.json +9 -0
- package/locales/ar/chat.json +1 -0
- package/locales/bg-BG/chat.json +1 -0
- package/locales/de-DE/chat.json +1 -0
- package/locales/en-US/chat.json +1 -0
- package/locales/es-ES/chat.json +1 -0
- package/locales/fa-IR/chat.json +1 -0
- package/locales/fr-FR/chat.json +1 -0
- package/locales/it-IT/chat.json +1 -0
- package/locales/ja-JP/chat.json +1 -0
- package/locales/ko-KR/chat.json +1 -0
- package/locales/nl-NL/chat.json +1 -0
- package/locales/pl-PL/chat.json +1 -0
- package/locales/pt-BR/chat.json +1 -0
- package/locales/ru-RU/chat.json +1 -0
- package/locales/tr-TR/chat.json +1 -0
- package/locales/vi-VN/chat.json +1 -0
- package/locales/zh-CN/chat.json +1 -0
- package/locales/zh-TW/chat.json +1 -0
- package/package.json +1 -1
- package/packages/database/src/models/__tests__/messages/message.create.test.ts +492 -0
- package/packages/database/src/models/__tests__/messages/message.delete.test.ts +481 -0
- package/packages/database/src/models/__tests__/messages/message.query.test.ts +970 -0
- package/packages/database/src/models/__tests__/messages/message.stats.test.ts +584 -0
- package/packages/database/src/models/__tests__/messages/message.update.test.ts +716 -0
- package/packages/database/src/models/message.ts +2 -50
- package/src/server/services/message/index.ts +14 -4
- package/packages/database/src/models/__tests__/message.test.ts +0 -2632
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
UIChatMessage,
|
|
15
15
|
UpdateMessageParams,
|
|
16
16
|
UpdateMessageRAGParams,
|
|
17
|
-
UpdateMessageResult,
|
|
18
17
|
} from '@lobechat/types';
|
|
19
18
|
import type { HeatmapsProps } from '@lobehub/charts';
|
|
20
19
|
import dayjs from 'dayjs';
|
|
@@ -550,13 +549,7 @@ export class MessageModel {
|
|
|
550
549
|
update = async (
|
|
551
550
|
id: string,
|
|
552
551
|
{ imageList, ...message }: Partial<UpdateMessageParams>,
|
|
553
|
-
|
|
554
|
-
groupAssistantMessages?: boolean;
|
|
555
|
-
postProcessUrl?: (path: string | null, file: { fileType: string }) => Promise<string>;
|
|
556
|
-
sessionId?: string | null;
|
|
557
|
-
topicId?: string | null;
|
|
558
|
-
},
|
|
559
|
-
): Promise<UpdateMessageResult> => {
|
|
552
|
+
): Promise<{ success: boolean }> => {
|
|
560
553
|
try {
|
|
561
554
|
await this.db.transaction(async (trx) => {
|
|
562
555
|
// 1. insert message files
|
|
@@ -574,22 +567,6 @@ export class MessageModel {
|
|
|
574
567
|
.where(and(eq(messages.id, id), eq(messages.userId, this.userId)));
|
|
575
568
|
});
|
|
576
569
|
|
|
577
|
-
// if sessionId or topicId provided, return the updated message list
|
|
578
|
-
if (options?.sessionId !== undefined || options?.topicId !== undefined) {
|
|
579
|
-
const messageList = await this.query(
|
|
580
|
-
{
|
|
581
|
-
sessionId: options.sessionId,
|
|
582
|
-
topicId: options.topicId,
|
|
583
|
-
},
|
|
584
|
-
{
|
|
585
|
-
groupAssistantMessages: options.groupAssistantMessages ?? false,
|
|
586
|
-
postProcessUrl: options.postProcessUrl,
|
|
587
|
-
},
|
|
588
|
-
);
|
|
589
|
-
|
|
590
|
-
return { messages: messageList, success: true };
|
|
591
|
-
}
|
|
592
|
-
|
|
593
570
|
return { success: true };
|
|
594
571
|
} catch (error) {
|
|
595
572
|
console.error('Update message error:', error);
|
|
@@ -610,16 +587,7 @@ export class MessageModel {
|
|
|
610
587
|
.where(and(eq(messages.userId, this.userId), eq(messages.id, id)));
|
|
611
588
|
};
|
|
612
589
|
|
|
613
|
-
updatePluginState = async (
|
|
614
|
-
id: string,
|
|
615
|
-
state: Record<string, any>,
|
|
616
|
-
options?: {
|
|
617
|
-
groupAssistantMessages?: boolean;
|
|
618
|
-
postProcessUrl?: (path: string | null, file: { fileType: string }) => Promise<string>;
|
|
619
|
-
sessionId?: string | null;
|
|
620
|
-
topicId?: string | null;
|
|
621
|
-
},
|
|
622
|
-
): Promise<UpdateMessageResult> => {
|
|
590
|
+
updatePluginState = async (id: string, state: Record<string, any>): Promise<void> => {
|
|
623
591
|
const item = await this.db.query.messagePlugins.findFirst({
|
|
624
592
|
where: eq(messagePlugins.id, id),
|
|
625
593
|
});
|
|
@@ -629,22 +597,6 @@ export class MessageModel {
|
|
|
629
597
|
.update(messagePlugins)
|
|
630
598
|
.set({ state: merge(item.state || {}, state) })
|
|
631
599
|
.where(eq(messagePlugins.id, id));
|
|
632
|
-
|
|
633
|
-
// Return updated messages if sessionId or topicId is provided
|
|
634
|
-
if (options?.sessionId !== undefined || options?.topicId !== undefined) {
|
|
635
|
-
const messageList = await this.query(
|
|
636
|
-
{
|
|
637
|
-
sessionId: options.sessionId,
|
|
638
|
-
topicId: options.topicId,
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
groupAssistantMessages: options.groupAssistantMessages ?? false,
|
|
642
|
-
postProcessUrl: options.postProcessUrl,
|
|
643
|
-
},
|
|
644
|
-
);
|
|
645
|
-
return { messages: messageList, success: true };
|
|
646
|
-
}
|
|
647
|
-
return { success: true };
|
|
648
600
|
};
|
|
649
601
|
|
|
650
602
|
updateMessagePlugin = async (id: string, value: Partial<MessagePluginItem>) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LobeChatDatabase } from '@lobechat/database';
|
|
2
|
-
import { CreateMessageParams, UpdateMessageParams } from '@lobechat/types';
|
|
2
|
+
import { CreateMessageParams, UIChatMessage, UpdateMessageParams } from '@lobechat/types';
|
|
3
3
|
|
|
4
4
|
import { MessageModel } from '@/database/models/message';
|
|
5
5
|
|
|
@@ -51,7 +51,9 @@ export class MessageService {
|
|
|
51
51
|
/**
|
|
52
52
|
* Query messages and return response with success status (used after mutations)
|
|
53
53
|
*/
|
|
54
|
-
private async queryWithSuccess(
|
|
54
|
+
private async queryWithSuccess(
|
|
55
|
+
options?: QueryOptions,
|
|
56
|
+
): Promise<{ messages?: UIChatMessage[], success: boolean; }> {
|
|
55
57
|
if (!options || (options.sessionId === undefined && options.topicId === undefined)) {
|
|
56
58
|
return { success: true };
|
|
57
59
|
}
|
|
@@ -139,7 +141,11 @@ export class MessageService {
|
|
|
139
141
|
* Update plugin state and return message list
|
|
140
142
|
* Pattern: update + conditional query
|
|
141
143
|
*/
|
|
142
|
-
async updatePluginState(
|
|
144
|
+
async updatePluginState(
|
|
145
|
+
id: string,
|
|
146
|
+
value: any,
|
|
147
|
+
options: QueryOptions,
|
|
148
|
+
): Promise<{ messages?: UIChatMessage[], success: boolean; }> {
|
|
143
149
|
await this.messageModel.updatePluginState(id, value);
|
|
144
150
|
return this.queryWithSuccess(options);
|
|
145
151
|
}
|
|
@@ -148,7 +154,11 @@ export class MessageService {
|
|
|
148
154
|
* Update message and return message list
|
|
149
155
|
* Pattern: update + conditional query
|
|
150
156
|
*/
|
|
151
|
-
async updateMessage(
|
|
157
|
+
async updateMessage(
|
|
158
|
+
id: string,
|
|
159
|
+
value: UpdateMessageParams,
|
|
160
|
+
options: QueryOptions,
|
|
161
|
+
): Promise<{ messages?: UIChatMessage[], success: boolean; }> {
|
|
152
162
|
await this.messageModel.update(id, value as any);
|
|
153
163
|
return this.queryWithSuccess(options);
|
|
154
164
|
}
|