@lobehub/chat 1.36.30 → 1.36.32
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 +50 -0
- package/changelog/v1.json +18 -0
- package/docs/self-hosting/environment-variables/model-provider.mdx +7 -0
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +7 -0
- package/docs/self-hosting/server-database/dokploy.zh-CN.mdx +12 -12
- package/package.json +1 -1
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/Content.tsx +3 -9
- package/src/app/(main)/chat/(workspace)/@conversation/features/ThreadHydration.tsx +2 -4
- package/src/app/(main)/chat/@session/features/SessionListContent/DefaultMode.tsx +2 -5
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/InstallPlugin.tsx +10 -15
- package/src/database/repositories/dataImporter/__tests__/index.test.ts +11 -18
- package/src/database/repositories/dataImporter/index.ts +31 -46
- package/src/database/server/models/__tests__/_test_template.ts +1 -1
- package/src/database/server/models/__tests__/agent.test.ts +1 -1
- package/src/database/server/models/__tests__/asyncTask.test.ts +1 -1
- package/src/database/server/models/__tests__/chunk.test.ts +1 -1
- package/src/database/server/models/__tests__/file.test.ts +1 -1
- package/src/database/server/models/__tests__/knowledgeBase.test.ts +1 -2
- package/src/database/server/models/__tests__/message.test.ts +35 -72
- package/src/database/server/models/__tests__/nextauth.test.ts +1 -1
- package/src/database/server/models/__tests__/session.test.ts +1 -1
- package/src/database/server/models/__tests__/sessionGroup.test.ts +1 -2
- package/src/database/server/models/__tests__/topic.test.ts +1 -1
- package/src/database/server/models/__tests__/user.test.ts +1 -1
- package/src/database/server/models/_template.ts +2 -2
- package/src/database/server/models/agent.ts +17 -25
- package/src/database/server/models/asyncTask.ts +2 -2
- package/src/database/server/models/chunk.ts +14 -14
- package/src/database/server/models/embedding.ts +1 -1
- package/src/database/server/models/file.ts +8 -10
- package/src/database/server/models/knowledgeBase.ts +4 -6
- package/src/database/server/models/message.ts +54 -65
- package/src/database/server/models/plugin.ts +6 -2
- package/src/database/server/models/ragEval/dataset.ts +2 -2
- package/src/database/server/models/ragEval/datasetRecord.ts +3 -8
- package/src/database/server/models/ragEval/evaluation.ts +3 -2
- package/src/database/server/models/ragEval/evaluationRecord.ts +2 -2
- package/src/database/server/models/session.ts +40 -35
- package/src/database/server/models/sessionGroup.ts +4 -4
- package/src/database/server/models/thread.ts +2 -2
- package/src/database/server/models/topic.ts +48 -53
- package/src/database/server/models/user.ts +12 -12
- package/src/features/AgentSetting/AgentPlugin/index.tsx +1 -1
- package/src/features/ChatInput/ActionBar/Tools/Dropdown.tsx +4 -4
- package/src/features/Portal/Thread/Chat/ChatList.tsx +1 -2
- package/src/hooks/useCheckPluginsIsInstalled.ts +10 -0
- package/src/hooks/useFetchInstalledPlugins.ts +10 -0
- package/src/hooks/useFetchMessages.ts +15 -0
- package/src/hooks/useFetchSessions.ts +13 -0
- package/src/hooks/useFetchThreads.ts +11 -0
- package/src/hooks/useFetchTopics.ts +6 -6
- package/src/layout/GlobalProvider/StoreInitialization.tsx +3 -1
- package/src/libs/agent-runtime/utils/streams/azureOpenai.test.ts +0 -1
- package/src/libs/next-auth/adapter/index.ts +1 -1
- package/src/server/routers/lambda/chunk.ts +2 -2
- package/src/services/user/client.ts +2 -2
- package/src/store/agent/slices/chat/action.test.ts +21 -10
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChat.test.ts +10 -0
- package/src/store/chat/slices/builtinTool/action.ts +0 -1
- package/src/store/chat/slices/message/action.test.ts +3 -1
- package/src/store/chat/slices/message/action.ts +7 -3
- package/src/store/chat/slices/thread/action.ts +3 -3
- package/src/store/chat/slices/topic/action.test.ts +1 -1
- package/src/store/chat/slices/topic/action.ts +3 -3
- package/src/store/global/selectors.ts +6 -0
- package/src/store/session/slices/session/action.ts +6 -3
- package/src/store/session/slices/sessionGroup/action.test.ts +8 -6
- package/src/store/tool/slices/plugin/action.ts +5 -3
- package/src/store/tool/slices/store/action.ts +4 -3
- package/src/store/user/slices/common/action.test.ts +3 -1
- package/vercel.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,56 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.36.32](https://github.com/lobehub/lobe-chat/compare/v1.36.31...v1.36.32)
|
6
|
+
|
7
|
+
<sup>Released on **2024-12-17**</sup>
|
8
|
+
|
9
|
+
#### ♻ Code Refactoring
|
10
|
+
|
11
|
+
- **misc**: Refactor the drizzle code style.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Code refactoring
|
19
|
+
|
20
|
+
- **misc**: Refactor the drizzle code style, closes [#5058](https://github.com/lobehub/lobe-chat/issues/5058) ([4057ad3](https://github.com/lobehub/lobe-chat/commit/4057ad3))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
### [Version 1.36.31](https://github.com/lobehub/lobe-chat/compare/v1.36.30...v1.36.31)
|
31
|
+
|
32
|
+
<sup>Released on **2024-12-17**</sup>
|
33
|
+
|
34
|
+
#### ♻ Code Refactoring
|
35
|
+
|
36
|
+
- **misc**: Refactor the data fetch with clientDB init check.
|
37
|
+
|
38
|
+
<br/>
|
39
|
+
|
40
|
+
<details>
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
42
|
+
|
43
|
+
#### Code refactoring
|
44
|
+
|
45
|
+
- **misc**: Refactor the data fetch with clientDB init check, closes [#5049](https://github.com/lobehub/lobe-chat/issues/5049) ([e6d2e09](https://github.com/lobehub/lobe-chat/commit/e6d2e09))
|
46
|
+
|
47
|
+
</details>
|
48
|
+
|
49
|
+
<div align="right">
|
50
|
+
|
51
|
+
[](#readme-top)
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
5
55
|
### [Version 1.36.30](https://github.com/lobehub/lobe-chat/compare/v1.36.29...v1.36.30)
|
6
56
|
|
7
57
|
<sup>Released on **2024-12-16**</sup>
|
package/changelog/v1.json
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
[
|
2
|
+
{
|
3
|
+
"children": {
|
4
|
+
"improvements": [
|
5
|
+
"Refactor the drizzle code style."
|
6
|
+
]
|
7
|
+
},
|
8
|
+
"date": "2024-12-17",
|
9
|
+
"version": "1.36.32"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"children": {
|
13
|
+
"improvements": [
|
14
|
+
"Refactor the data fetch with clientDB init check."
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"date": "2024-12-17",
|
18
|
+
"version": "1.36.31"
|
19
|
+
},
|
2
20
|
{
|
3
21
|
"children": {
|
4
22
|
"improvements": [
|
@@ -288,6 +288,13 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
|
|
288
288
|
- Default: `https://api.Perplexity.ai`
|
289
289
|
- Example: `https://my-Perplexity-proxy.com`
|
290
290
|
|
291
|
+
### `PERPLEXITY_MODEL_LIST`
|
292
|
+
|
293
|
+
- Type: Optional
|
294
|
+
- Description: Used to control the model list, use `+` to add a model, use `-` to hide a model, use `model_name=display_name` to customize the display name of a model, separated by commas. Definition syntax rules see
|
295
|
+
- Default: `-`
|
296
|
+
- Example: `-all,+llama-3.1-sonar-small-128k-online,+llama-3.1-sonar-small-128k-chat`
|
297
|
+
|
291
298
|
## Minimax AI
|
292
299
|
|
293
300
|
### `MINIMAX_API_KEY`
|
@@ -279,6 +279,13 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量,
|
|
279
279
|
- 默认值:-
|
280
280
|
- 示例:`pplx-xxxxxx...xxxxxx`
|
281
281
|
|
282
|
+
### `PERPLEXITY_MODEL_LIST`
|
283
|
+
|
284
|
+
- 类型:可选
|
285
|
+
- 描述:用于指定自定义 Perplexity 语言模型。模型定义语法规则见 [模型列表][model-list]
|
286
|
+
- 默认值:-
|
287
|
+
- 示例: `-all,+llama-3.1-sonar-small-128k-online,+llama-3.1-sonar-small-128k-chat`
|
288
|
+
|
282
289
|
### `PERPLEXITY_PROXY_URL`
|
283
290
|
|
284
291
|
- 类型:可选
|
@@ -1,15 +1,15 @@
|
|
1
|
-
---
|
2
|
-
title: 在 Dokploy 上部署 LobeChat 的服务端数据库版本
|
3
|
-
description: 本文详细介绍如何在 Dokploy 中部署服务端数据库版 LobeChat,包括数据库配置、身份验证服务配置的设置步骤。
|
4
|
-
tags:
|
5
|
-
- 服务端数据库
|
6
|
-
- Postgres
|
7
|
-
- Clerk
|
8
|
-
- Dokploy部署
|
9
|
-
- 数据库配置
|
10
|
-
- 身份验证服务
|
11
|
-
- 环境变量配置
|
12
|
-
---
|
1
|
+
---
|
2
|
+
title: 在 Dokploy 上部署 LobeChat 的服务端数据库版本
|
3
|
+
description: 本文详细介绍如何在 Dokploy 中部署服务端数据库版 LobeChat,包括数据库配置、身份验证服务配置的设置步骤。
|
4
|
+
tags:
|
5
|
+
- 服务端数据库
|
6
|
+
- Postgres
|
7
|
+
- Clerk
|
8
|
+
- Dokploy部署
|
9
|
+
- 数据库配置
|
10
|
+
- 身份验证服务
|
11
|
+
- 环境变量配置
|
12
|
+
---
|
13
13
|
|
14
14
|
# 在 Dokploy 上部署服务端数据库版
|
15
15
|
本文将详细介绍如何在 Dokploy 中部署服务端数据库版 LobeChat。
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.36.
|
3
|
+
"version": "1.36.32",
|
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",
|
@@ -3,9 +3,9 @@
|
|
3
3
|
import React, { memo, useCallback } from 'react';
|
4
4
|
|
5
5
|
import { SkeletonList, VirtualizedList } from '@/features/Conversation';
|
6
|
+
import { useFetchMessages } from '@/hooks/useFetchMessages';
|
6
7
|
import { useChatStore } from '@/store/chat';
|
7
8
|
import { chatSelectors } from '@/store/chat/selectors';
|
8
|
-
import { useSessionStore } from '@/store/session';
|
9
9
|
|
10
10
|
import MainChatItem from './ChatItem';
|
11
11
|
import Welcome from './WelcomeChatItem';
|
@@ -15,15 +15,9 @@ interface ListProps {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
const Content = memo<ListProps>(({ mobile }) => {
|
18
|
-
const [
|
19
|
-
s.activeTopicId,
|
20
|
-
s.useFetchMessages,
|
21
|
-
chatSelectors.isCurrentChatLoaded(s),
|
22
|
-
]);
|
23
|
-
|
24
|
-
const [sessionId] = useSessionStore((s) => [s.activeId]);
|
25
|
-
useFetchMessages(sessionId, activeTopicId);
|
18
|
+
const [isCurrentChatLoaded] = useChatStore((s) => [chatSelectors.isCurrentChatLoaded(s)]);
|
26
19
|
|
20
|
+
useFetchMessages();
|
27
21
|
const data = useChatStore(chatSelectors.mainDisplayChatIDs);
|
28
22
|
|
29
23
|
const itemContent = useCallback(
|
@@ -4,6 +4,7 @@ import { useQueryState } from 'nuqs';
|
|
4
4
|
import { memo, useEffect, useLayoutEffect } from 'react';
|
5
5
|
import { createStoreUpdater } from 'zustand-utils';
|
6
6
|
|
7
|
+
import { useFetchThreads } from '@/hooks/useFetchThreads';
|
7
8
|
import { useChatStore } from '@/store/chat';
|
8
9
|
|
9
10
|
// sync outside state to useChatStore
|
@@ -34,10 +35,7 @@ const ThreadHydration = memo(() => {
|
|
34
35
|
}
|
35
36
|
}, [portalThread]);
|
36
37
|
|
37
|
-
const
|
38
|
-
s.activeTopicId,
|
39
|
-
s.useFetchThreads,
|
40
|
-
]);
|
38
|
+
const activeTopicId = useChatStore((s) => s.activeTopicId);
|
41
39
|
|
42
40
|
useFetchThreads(activeTopicId);
|
43
41
|
|
@@ -3,12 +3,11 @@ import isEqual from 'fast-deep-equal';
|
|
3
3
|
import { memo, useMemo, useState } from 'react';
|
4
4
|
import { useTranslation } from 'react-i18next';
|
5
5
|
|
6
|
+
import { useFetchSessions } from '@/hooks/useFetchSessions';
|
6
7
|
import { useGlobalStore } from '@/store/global';
|
7
8
|
import { systemStatusSelectors } from '@/store/global/selectors';
|
8
9
|
import { useSessionStore } from '@/store/session';
|
9
10
|
import { sessionSelectors } from '@/store/session/selectors';
|
10
|
-
import { useUserStore } from '@/store/user';
|
11
|
-
import { authSelectors } from '@/store/user/selectors';
|
12
11
|
import { SessionDefaultGroup } from '@/types/session';
|
13
12
|
|
14
13
|
import Actions from '../SessionListContent/CollapseGroup/Actions';
|
@@ -25,9 +24,7 @@ const DefaultMode = memo(() => {
|
|
25
24
|
const [renameGroupModalOpen, setRenameGroupModalOpen] = useState(false);
|
26
25
|
const [configGroupModalOpen, setConfigGroupModalOpen] = useState(false);
|
27
26
|
|
28
|
-
|
29
|
-
const [useFetchSessions] = useSessionStore((s) => [s.useFetchSessions]);
|
30
|
-
useFetchSessions(isLogin);
|
27
|
+
useFetchSessions();
|
31
28
|
|
32
29
|
const defaultSessions = useSessionStore(sessionSelectors.defaultSessions, isEqual);
|
33
30
|
const customSessionGroups = useSessionStore(sessionSelectors.customSessionGroups, isEqual);
|
@@ -5,6 +5,7 @@ import { createStyles } from 'antd-style';
|
|
5
5
|
import { memo, useState } from 'react';
|
6
6
|
import { useTranslation } from 'react-i18next';
|
7
7
|
|
8
|
+
import { useFetchInstalledPlugins } from '@/hooks/useFetchInstalledPlugins';
|
8
9
|
import { useToolStore } from '@/store/tool';
|
9
10
|
import { pluginSelectors, pluginStoreSelectors } from '@/store/tool/selectors';
|
10
11
|
|
@@ -21,21 +22,15 @@ const InstallPlugin = memo<{ identifier: string }>(({ identifier }) => {
|
|
21
22
|
const { t } = useTranslation(['discover', 'plugin']);
|
22
23
|
const [loading, setLoading] = useState(false);
|
23
24
|
const { modal } = App.useApp();
|
24
|
-
const [
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
s.useFetchInstalledPlugins,
|
34
|
-
pluginSelectors.isPluginInstalled(identifier)(s),
|
35
|
-
pluginStoreSelectors.isPluginInstallLoading(identifier)(s),
|
36
|
-
s.installPlugin,
|
37
|
-
s.uninstallPlugin,
|
38
|
-
]);
|
25
|
+
const [useFetchPluginStore, installed, installing, installPlugin, unInstallPlugin] = useToolStore(
|
26
|
+
(s) => [
|
27
|
+
s.useFetchPluginStore,
|
28
|
+
pluginSelectors.isPluginInstalled(identifier)(s),
|
29
|
+
pluginStoreSelectors.isPluginInstallLoading(identifier)(s),
|
30
|
+
s.installPlugin,
|
31
|
+
s.uninstallPlugin,
|
32
|
+
],
|
33
|
+
);
|
39
34
|
|
40
35
|
const { isLoading } = useFetchPluginStore();
|
41
36
|
const { isLoading: installedPluginLoading } = useFetchInstalledPlugins();
|
@@ -1,8 +1,7 @@
|
|
1
1
|
// @vitest-environment node
|
2
|
-
import { eq, inArray } from 'drizzle-orm';
|
2
|
+
import { eq, inArray } from 'drizzle-orm/expressions';
|
3
3
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
|
-
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
6
5
|
import {
|
7
6
|
agents,
|
8
7
|
agentsToSessions,
|
@@ -12,6 +11,7 @@ import {
|
|
12
11
|
topics,
|
13
12
|
users,
|
14
13
|
} from '@/database/schemas';
|
14
|
+
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
15
15
|
import { CURRENT_CONFIG_VERSION } from '@/migrations';
|
16
16
|
import { ImporterEntryData } from '@/types/importer';
|
17
17
|
|
@@ -60,8 +60,7 @@ describe('DataImporter', () => {
|
|
60
60
|
it('should skip existing session groups and return correct result', async () => {
|
61
61
|
await serverDB
|
62
62
|
.insert(sessionGroups)
|
63
|
-
.values({ clientId: 'group1', name: 'Existing Group', userId })
|
64
|
-
.execute();
|
63
|
+
.values({ clientId: 'group1', name: 'Existing Group', userId });
|
65
64
|
|
66
65
|
const data: ImporterEntryData = {
|
67
66
|
version: CURRENT_CONFIG_VERSION,
|
@@ -141,7 +140,7 @@ describe('DataImporter', () => {
|
|
141
140
|
});
|
142
141
|
|
143
142
|
it('should skip existing sessions and return correct result', async () => {
|
144
|
-
await serverDB.insert(sessions).values({ clientId: 'session1', userId })
|
143
|
+
await serverDB.insert(sessions).values({ clientId: 'session1', userId });
|
145
144
|
|
146
145
|
const data: ImporterEntryData = {
|
147
146
|
version: CURRENT_CONFIG_VERSION,
|
@@ -477,10 +476,7 @@ describe('DataImporter', () => {
|
|
477
476
|
});
|
478
477
|
|
479
478
|
it('should skip existing topics and return correct result', async () => {
|
480
|
-
await serverDB
|
481
|
-
.insert(topics)
|
482
|
-
.values({ clientId: 'topic1', title: 'Existing Topic', userId })
|
483
|
-
.execute();
|
479
|
+
await serverDB.insert(topics).values({ clientId: 'topic1', title: 'Existing Topic', userId });
|
484
480
|
|
485
481
|
const data: ImporterEntryData = {
|
486
482
|
version: CURRENT_CONFIG_VERSION,
|
@@ -616,15 +612,12 @@ describe('DataImporter', () => {
|
|
616
612
|
});
|
617
613
|
|
618
614
|
it('should skip existing messages and return correct result', async () => {
|
619
|
-
await serverDB
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
userId,
|
626
|
-
})
|
627
|
-
.execute();
|
615
|
+
await serverDB.insert(messages).values({
|
616
|
+
clientId: 'msg1',
|
617
|
+
content: 'Existing Message',
|
618
|
+
role: 'user',
|
619
|
+
userId,
|
620
|
+
});
|
628
621
|
|
629
622
|
const data: ImporterEntryData = {
|
630
623
|
version: CURRENT_CONFIG_VERSION,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import { and } from 'drizzle-orm/expressions';
|
1
|
+
import { sql } from 'drizzle-orm';
|
2
|
+
import { and, eq, inArray } from 'drizzle-orm/expressions';
|
3
3
|
|
4
4
|
import {
|
5
5
|
agents,
|
@@ -71,8 +71,7 @@ export class DataImporterRepos {
|
|
71
71
|
set: { updatedAt: new Date() },
|
72
72
|
target: [sessionGroups.clientId, sessionGroups.userId],
|
73
73
|
})
|
74
|
-
.returning({ clientId: sessionGroups.clientId, id: sessionGroups.id })
|
75
|
-
.execute();
|
74
|
+
.returning({ clientId: sessionGroups.clientId, id: sessionGroups.id });
|
76
75
|
|
77
76
|
sessionGroupResult.added = mapArray.length - query.length;
|
78
77
|
|
@@ -109,8 +108,7 @@ export class DataImporterRepos {
|
|
109
108
|
set: { updatedAt: new Date() },
|
110
109
|
target: [sessions.clientId, sessions.userId],
|
111
110
|
})
|
112
|
-
.returning({ clientId: sessions.clientId, id: sessions.id })
|
113
|
-
.execute();
|
111
|
+
.returning({ clientId: sessions.clientId, id: sessions.id });
|
114
112
|
|
115
113
|
// get the session client-server id map
|
116
114
|
sessionIdMap = Object.fromEntries(mapArray.map(({ clientId, id }) => [clientId, id]));
|
@@ -133,18 +131,14 @@ export class DataImporterRepos {
|
|
133
131
|
userId: this.userId,
|
134
132
|
})),
|
135
133
|
)
|
136
|
-
.returning({ id: agents.id })
|
137
|
-
.execute();
|
134
|
+
.returning({ id: agents.id });
|
138
135
|
|
139
|
-
await trx
|
140
|
-
.
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
})),
|
146
|
-
)
|
147
|
-
.execute();
|
136
|
+
await trx.insert(agentsToSessions).values(
|
137
|
+
shouldInsertSessionAgents.map(({ id }, index) => ({
|
138
|
+
agentId: agentMapArray[index].id,
|
139
|
+
sessionId: sessionIdMap[id],
|
140
|
+
})),
|
141
|
+
);
|
148
142
|
}
|
149
143
|
}
|
150
144
|
|
@@ -178,8 +172,7 @@ export class DataImporterRepos {
|
|
178
172
|
set: { updatedAt: new Date() },
|
179
173
|
target: [topics.clientId, topics.userId],
|
180
174
|
})
|
181
|
-
.returning({ clientId: topics.clientId, id: topics.id })
|
182
|
-
.execute();
|
175
|
+
.returning({ clientId: topics.clientId, id: topics.id });
|
183
176
|
|
184
177
|
topicIdMap = Object.fromEntries(mapArray.map(({ clientId, id }) => [clientId, id]));
|
185
178
|
|
@@ -230,7 +223,7 @@ export class DataImporterRepos {
|
|
230
223
|
|
231
224
|
for (let i = 0; i < inertValues.length; i += BATCH_SIZE) {
|
232
225
|
const batch = inertValues.slice(i, i + BATCH_SIZE);
|
233
|
-
await trx.insert(messages).values(batch)
|
226
|
+
await trx.insert(messages).values(batch);
|
234
227
|
}
|
235
228
|
|
236
229
|
console.timeEnd('insert messages');
|
@@ -265,7 +258,7 @@ export class DataImporterRepos {
|
|
265
258
|
.filter(Boolean);
|
266
259
|
|
267
260
|
if (parentIdUpdates.length > 0) {
|
268
|
-
|
261
|
+
await trx
|
269
262
|
.update(messages)
|
270
263
|
.set({
|
271
264
|
parentId: sql`CASE ${sql.join(parentIdUpdates)} END`,
|
@@ -281,42 +274,34 @@ export class DataImporterRepos {
|
|
281
274
|
// const SQL = updateQuery.toSQL();
|
282
275
|
// console.log('sql:', SQL.sql);
|
283
276
|
// console.log('params:', SQL.params);
|
284
|
-
|
285
|
-
await updateQuery.execute();
|
286
277
|
}
|
287
278
|
console.timeEnd('execute updates parentId');
|
288
279
|
|
289
280
|
// 4. insert message plugins
|
290
281
|
const pluginInserts = shouldInsertMessages.filter((msg) => msg.plugin);
|
291
282
|
if (pluginInserts.length > 0) {
|
292
|
-
await trx
|
293
|
-
.
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
})),
|
304
|
-
)
|
305
|
-
.execute();
|
283
|
+
await trx.insert(messagePlugins).values(
|
284
|
+
pluginInserts.map((msg) => ({
|
285
|
+
apiName: msg.plugin?.apiName,
|
286
|
+
arguments: msg.plugin?.arguments,
|
287
|
+
id: messageIdMap[msg.id],
|
288
|
+
identifier: msg.plugin?.identifier,
|
289
|
+
state: msg.pluginState,
|
290
|
+
toolCallId: msg.tool_call_id,
|
291
|
+
type: msg.plugin?.type,
|
292
|
+
})),
|
293
|
+
);
|
306
294
|
}
|
307
295
|
|
308
296
|
// 5. insert message translate
|
309
297
|
const translateInserts = shouldInsertMessages.filter((msg) => msg.extra?.translate);
|
310
298
|
if (translateInserts.length > 0) {
|
311
|
-
await trx
|
312
|
-
.
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
})),
|
318
|
-
)
|
319
|
-
.execute();
|
299
|
+
await trx.insert(messageTranslates).values(
|
300
|
+
translateInserts.map((msg) => ({
|
301
|
+
id: messageIdMap[msg.id],
|
302
|
+
...msg.extra?.translate,
|
303
|
+
})),
|
304
|
+
);
|
320
305
|
}
|
321
306
|
|
322
307
|
// TODO: 未来需要处理 TTS 和图片的插入 (目前存在 file 的部分,不方便处理)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// @vitest-environment node
|
2
|
-
import { eq, inArray } from 'drizzle-orm';
|
2
|
+
import { eq, inArray } from 'drizzle-orm/expressions';
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
5
|
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
@@ -1,6 +1,5 @@
|
|
1
1
|
// @vitest-environment node
|
2
|
-
import { eq } from 'drizzle-orm';
|
3
|
-
import { and, desc } from 'drizzle-orm/expressions';
|
2
|
+
import { and, eq } from 'drizzle-orm/expressions';
|
4
3
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
5
4
|
|
6
5
|
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|