@lobehub/chat 0.147.10 → 0.147.12
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/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/contributing/Basic/Feature-Development.md +2 -2
- package/contributing/Basic/Feature-Development.zh-CN.md +2 -2
- package/package.json +2 -2
- package/src/app/chat/(desktop)/features/ChatInput/Footer/DragUpload.tsx +14 -2
- package/src/database/{core → client/core}/__tests__/db-upgrade.test.ts +2 -2
- package/src/database/{core → client/core}/__tests__/db.test.ts +5 -6
- package/src/database/{core → client/core}/db.ts +18 -18
- package/src/database/{core → client/core}/index.ts +1 -1
- package/src/database/{core → client/core}/migrations/migrateSettingsToUser/index.ts +1 -1
- package/src/database/{core → client/core}/model.ts +7 -7
- package/src/database/{core → client/core}/sync.ts +3 -3
- package/src/database/{models → client/models}/__DEBUG.ts +3 -3
- package/src/database/{models → client/models}/__tests__/file.test.ts +3 -4
- package/src/database/{models → client/models}/__tests__/session.test.ts +3 -3
- package/src/database/{models → client/models}/__tests__/sessionGroup.test.ts +1 -1
- package/src/database/{models → client/models}/__tests__/topic.test.ts +4 -4
- package/src/database/{models → client/models}/file.ts +1 -1
- package/src/database/{models → client/models}/message.ts +3 -3
- package/src/database/{models → client/models}/plugin.ts +1 -1
- package/src/database/{models → client/models}/session.ts +3 -3
- package/src/database/{models → client/models}/sessionGroup.ts +2 -2
- package/src/database/{models → client/models}/topic.ts +4 -4
- package/src/database/{models → client/models}/user.ts +1 -1
- package/src/database/{schemas → client/schemas}/user.ts +1 -1
- package/src/services/__tests__/file.test.ts +3 -3
- package/src/services/__tests__/message.test.ts +2 -2
- package/src/services/__tests__/plugin.test.ts +3 -3
- package/src/services/__tests__/session.test.ts +4 -4
- package/src/services/__tests__/topic.test.ts +2 -2
- package/src/services/debug.ts +1 -1
- package/src/services/file.ts +2 -2
- package/src/services/global.ts +1 -1
- package/src/services/message.ts +11 -2
- package/src/services/plugin.ts +1 -1
- package/src/services/session.ts +2 -2
- package/src/services/topic.ts +1 -1
- package/src/services/user.ts +1 -1
- package/src/store/chat/slices/message/action.ts +1 -2
- package/src/store/chat/slices/plugin/action.ts +1 -2
- package/src/types/sync.ts +1 -1
- /package/src/database/{core → client/core}/__tests__/model.test.ts +0 -0
- /package/src/database/{core → client/core}/migrations/migrateSettingsToUser/fixtures/input.json +0 -0
- /package/src/database/{core → client/core}/migrations/migrateSettingsToUser/fixtures/output.json +0 -0
- /package/src/database/{core → client/core}/migrations/migrateSettingsToUser/index.test.ts +0 -0
- /package/src/database/{core → client/core}/migrations/migrateSettingsToUser/type.ts +0 -0
- /package/src/database/{core → client/core}/schemas.ts +0 -0
- /package/src/database/{core → client/core}/types/db.ts +0 -0
- /package/src/database/{models → client/models}/__tests__/message.test.ts +0 -0
- /package/src/database/{models → client/models}/__tests__/plugin.test.ts +0 -0
- /package/src/database/{models → client/models}/__tests__/user.test.ts +0 -0
- /package/src/database/{schemas → client/schemas}/files.ts +0 -0
- /package/src/database/{schemas → client/schemas}/message.ts +0 -0
- /package/src/database/{schemas → client/schemas}/plugin.ts +0 -0
- /package/src/database/{schemas → client/schemas}/session.ts +0 -0
- /package/src/database/{schemas → client/schemas}/sessionGroup.ts +0 -0
- /package/src/database/{schemas → client/schemas}/topic.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.147.12](https://github.com/lobehub/lobe-chat/compare/v0.147.11...v0.147.12)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-04-14**</sup>
|
|
8
|
+
|
|
9
|
+
#### ♻ Code Refactoring
|
|
10
|
+
|
|
11
|
+
- **misc**: Move client db to a new folder.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Code refactoring
|
|
19
|
+
|
|
20
|
+
- **misc**: Move client db to a new folder, closes [#2037](https://github.com/lobehub/lobe-chat/issues/2037) ([ebe65bb](https://github.com/lobehub/lobe-chat/commit/ebe65bb))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.147.11](https://github.com/lobehub/lobe-chat/compare/v0.147.10...v0.147.11)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-04-14**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: Support drag or copy to upload file by model ability.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: Support drag or copy to upload file by model ability, closes [#2016](https://github.com/lobehub/lobe-chat/issues/2016) ([2abe37e](https://github.com/lobehub/lobe-chat/commit/2abe37e))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.147.10](https://github.com/lobehub/lobe-chat/compare/v0.147.9...v0.147.10)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-04-13**</sup>
|
package/README.md
CHANGED
|
@@ -260,14 +260,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
260
260
|
|
|
261
261
|
<!-- AGENT LIST -->
|
|
262
262
|
|
|
263
|
-
| Recent Submits | Description
|
|
264
|
-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
265
|
-
| [
|
|
266
|
-
| [
|
|
267
|
-
| [
|
|
268
|
-
| [
|
|
269
|
-
|
|
270
|
-
> 📊 Total agents: [<kbd>**
|
|
263
|
+
| Recent Submits | Description |
|
|
264
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
265
|
+
| [Biology Professor](https://chat-preview.lobehub.com/market?agent=bio-professor)<br/><sup>By **[luxiangze](https://github.com/luxiangze)** on **2024-04-13**</sup> | As a biology professor, you will receive questions and concepts about biology. Please explain these questions and concepts in specific and concise language, and try to use practical examples to illustrate them to help your audience better understand. Please ensure that your explanations are accurate and clear, and try to encourage creative and flexible answers. Respond in Chinese.<br/>`biology` |
|
|
266
|
+
| [Master of Fortune Telling](https://chat-preview.lobehub.com/market?agent=fortune-teller)<br/><sup>By **[kamilkenrich](https://github.com/kamilkenrich)** on **2024-04-13**</sup> | Specializes in numerology, divination, astrology, and blood type analysis<br/>`numerology` `divination` `astrology` `psychology` `blood-type` `constellation` |
|
|
267
|
+
| [Healthy Recipe Recommender](https://chat-preview.lobehub.com/market?agent=healthy-recipe-recommender)<br/><sup>By **[Greasen](https://github.com/Greasen)** on **2024-04-11**</sup> | Customized nutrition meals, scientific combinations, healthy eating, your personal nutritionist.<br/>`recipes` `fitness-meals` `nutrition-meals` |
|
|
268
|
+
| [SmartWeather Assistant](https://chat-preview.lobehub.com/market?agent=personal-weather-consultant)<br/><sup>By **[Greasen](https://github.com/Greasen)** on **2024-04-11**</sup> | SmartWeather Assistant, your personal weather advisor, fashion guide, and positive energy booster!<br/>`weather` `assistant` `fashion` |
|
|
269
|
+
|
|
270
|
+
> 📊 Total agents: [<kbd>**238**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
271
271
|
|
|
272
272
|
<!-- AGENT LIST -->
|
|
273
273
|
|
package/README.zh-CN.md
CHANGED
|
@@ -248,14 +248,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
248
248
|
|
|
249
249
|
<!-- AGENT LIST -->
|
|
250
250
|
|
|
251
|
-
| 最近新增 | 助手说明
|
|
252
|
-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
253
|
-
| [
|
|
254
|
-
| [
|
|
255
|
-
| [
|
|
256
|
-
| [
|
|
257
|
-
|
|
258
|
-
> 📊 Total agents: [<kbd>**
|
|
251
|
+
| 最近新增 | 助手说明 |
|
|
252
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
253
|
+
| [生物学教授](https://chat-preview.lobehub.com/market?agent=bio-professor)<br/><sup>By **[luxiangze](https://github.com/luxiangze)** on **2024-04-13**</sup> | 作为一位生物学教授,您将收到关于生物学的问题和概念,请用具体而简明的语言解释这些问题和概念,并尽量使用实际例子进行说明,以帮助您的听众更好地理解。请确保您的解释准确而清晰,并试图鼓励创造性和灵活性的答案。用中文回答<br/>`生物` |
|
|
254
|
+
| [命理大师](https://chat-preview.lobehub.com/market?agent=fortune-teller)<br/><sup>By **[kamilkenrich](https://github.com/kamilkenrich)** on **2024-04-13**</sup> | 擅长命理学、占卜预测、占星术和血型学分析<br/>`命理学、占卜、占星学、心理学、血型、星座` |
|
|
255
|
+
| [健康食谱推荐师](https://chat-preview.lobehub.com/market?agent=healthy-recipe-recommender)<br/><sup>By **[Greasen](https://github.com/Greasen)** on **2024-04-11**</sup> | 精准定制营养餐,科学搭配,健康饮食,你的私人营养师。<br/>`食谱、健身餐、营养餐` |
|
|
256
|
+
| [智预小助手](https://chat-preview.lobehub.com/market?agent=personal-weather-consultant)<br/><sup>By **[Greasen](https://github.com/Greasen)** on **2024-04-11**</sup> | 智预小助手,您的私人天气顾问,穿搭指南,正能量加油器!<br/>`天气` `助理、穿搭` |
|
|
257
|
+
|
|
258
|
+
> 📊 Total agents: [<kbd>**238**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
259
259
|
|
|
260
260
|
<!-- AGENT LIST -->
|
|
261
261
|
|
|
@@ -128,8 +128,8 @@ When building the LobeChat application, the Model is responsible for interacting
|
|
|
128
128
|
In `src/database/model/sessionGroup.ts`, the `SessionGroupModel` is defined as follows:
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
|
-
import { BaseModel } from '@/database/core';
|
|
132
|
-
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/schemas/sessionGroup';
|
|
131
|
+
import { BaseModel } from '@/database/client/core';
|
|
132
|
+
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/client/schemas/sessionGroup';
|
|
133
133
|
import { nanoid } from '@/utils/uuid';
|
|
134
134
|
|
|
135
135
|
class _SessionGroupModel extends BaseModel {
|
|
@@ -128,8 +128,8 @@ export class LocalDB extends Dexie {
|
|
|
128
128
|
在 `src/database/model/sessionGroup.ts` 中定义 `SessionGroupModel`:
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
|
-
import { BaseModel } from '@/database/core';
|
|
132
|
-
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/schemas/sessionGroup';
|
|
131
|
+
import { BaseModel } from '@/database/client/core';
|
|
132
|
+
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/client/schemas/sessionGroup';
|
|
133
133
|
import { nanoid } from '@/utils/uuid';
|
|
134
134
|
|
|
135
135
|
class _SessionGroupModel extends BaseModel {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.147.
|
|
3
|
+
"version": "0.147.12",
|
|
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",
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
"@next/eslint-plugin-next": "^14.1.4",
|
|
173
173
|
"@peculiar/webcrypto": "^1.4.6",
|
|
174
174
|
"@testing-library/jest-dom": "^6.4.2",
|
|
175
|
-
"@testing-library/react": "^
|
|
175
|
+
"@testing-library/react": "^15.0.0",
|
|
176
176
|
"@types/chroma-js": "^2.4.4",
|
|
177
177
|
"@types/debug": "^4.1.12",
|
|
178
178
|
"@types/diff": "^5.0.9",
|
|
@@ -7,6 +7,10 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { Center, Flexbox } from 'react-layout-kit';
|
|
8
8
|
|
|
9
9
|
import { useFileStore } from '@/store/file';
|
|
10
|
+
import { useGlobalStore } from '@/store/global';
|
|
11
|
+
import { modelProviderSelectors } from '@/store/global/selectors';
|
|
12
|
+
import { useSessionStore } from '@/store/session';
|
|
13
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
10
14
|
|
|
11
15
|
const useStyles = createStyles(({ css, token, stylish }) => {
|
|
12
16
|
return {
|
|
@@ -56,6 +60,8 @@ const useStyles = createStyles(({ css, token, stylish }) => {
|
|
|
56
60
|
};
|
|
57
61
|
});
|
|
58
62
|
|
|
63
|
+
|
|
64
|
+
|
|
59
65
|
const handleDragOver = (e: DragEvent) => {
|
|
60
66
|
e.preventDefault();
|
|
61
67
|
};
|
|
@@ -71,12 +77,16 @@ const DragUpload = memo(() => {
|
|
|
71
77
|
|
|
72
78
|
const uploadFile = useFileStore((s) => s.uploadFile);
|
|
73
79
|
|
|
80
|
+
const model = useSessionStore(agentSelectors.currentAgentModel);
|
|
81
|
+
|
|
82
|
+
const enabledFiles = useGlobalStore(modelProviderSelectors.isModelEnabledFiles(model));
|
|
83
|
+
|
|
74
84
|
const uploadImages = async (fileList: FileList | undefined) => {
|
|
75
85
|
if (!fileList || fileList.length === 0) return;
|
|
76
86
|
|
|
77
87
|
const pools = Array.from(fileList).map(async (file) => {
|
|
78
88
|
// skip none-file items
|
|
79
|
-
if (!file.type.startsWith('image')) return;
|
|
89
|
+
if (!file.type.startsWith('image') && !enabledFiles) return;
|
|
80
90
|
await uploadFile(file);
|
|
81
91
|
});
|
|
82
92
|
|
|
@@ -126,6 +136,7 @@ const DragUpload = memo(() => {
|
|
|
126
136
|
uploadImages(files);
|
|
127
137
|
};
|
|
128
138
|
|
|
139
|
+
|
|
129
140
|
useEffect(() => {
|
|
130
141
|
window.addEventListener('dragenter', handleDragEnter);
|
|
131
142
|
window.addEventListener('dragover', handleDragOver);
|
|
@@ -140,7 +151,7 @@ const DragUpload = memo(() => {
|
|
|
140
151
|
window.removeEventListener('drop', handleDrop);
|
|
141
152
|
window.removeEventListener('paste', handlePaste);
|
|
142
153
|
};
|
|
143
|
-
}, []);
|
|
154
|
+
}, [handleDrop, handlePaste]);
|
|
144
155
|
|
|
145
156
|
return (
|
|
146
157
|
isDragging && (
|
|
@@ -164,3 +175,4 @@ const DragUpload = memo(() => {
|
|
|
164
175
|
});
|
|
165
176
|
|
|
166
177
|
export default DragUpload;
|
|
178
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Dexie from 'dexie';
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { BrowserDB } from '../db';
|
|
5
5
|
import { dbSchemaV3 } from '../schemas';
|
|
6
6
|
import { LOBE_CHAT_LOCAL_DB_NAME } from '../types/db';
|
|
7
7
|
|
|
@@ -28,7 +28,7 @@ describe('LocalDB migration', () => {
|
|
|
28
28
|
dbV3.close();
|
|
29
29
|
|
|
30
30
|
// 创建新的数据库实例,包含版本4的迁移逻辑
|
|
31
|
-
const dbV4 = new
|
|
31
|
+
const dbV4 = new BrowserDB();
|
|
32
32
|
await dbV4.open();
|
|
33
33
|
|
|
34
34
|
// 验证迁移后的数据
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { LocalDB } from '../db';
|
|
3
|
+
import { DB_File } from '../../schemas/files';
|
|
4
|
+
import { BrowserDB } from '../db';
|
|
5
|
+
import { DBModel } from '../types/db';
|
|
7
6
|
|
|
8
7
|
describe('LocalDB', () => {
|
|
9
|
-
let db:
|
|
8
|
+
let db: BrowserDB;
|
|
10
9
|
|
|
11
10
|
beforeEach(() => {
|
|
12
|
-
db = new
|
|
11
|
+
db = new BrowserDB();
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
afterEach(async () => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Dexie, { Transaction } from 'dexie';
|
|
2
2
|
|
|
3
|
-
import { DB_File } from '@/database/schemas/files';
|
|
4
|
-
import { DB_Message } from '@/database/schemas/message';
|
|
5
|
-
import { DB_Plugin } from '@/database/schemas/plugin';
|
|
6
|
-
import { DB_Session } from '@/database/schemas/session';
|
|
7
|
-
import { DB_SessionGroup } from '@/database/schemas/sessionGroup';
|
|
8
|
-
import { DB_Topic } from '@/database/schemas/topic';
|
|
9
|
-
import { DB_User } from '@/database/schemas/user';
|
|
10
3
|
import { MigrationLLMSettings } from '@/migrations/FromV3ToV4';
|
|
11
4
|
import { uuid } from '@/utils/uuid';
|
|
12
5
|
|
|
6
|
+
import { DB_File } from '../schemas/files';
|
|
7
|
+
import { DB_Message } from '../schemas/message';
|
|
8
|
+
import { DB_Plugin } from '../schemas/plugin';
|
|
9
|
+
import { DB_Session } from '../schemas/session';
|
|
10
|
+
import { DB_SessionGroup } from '../schemas/sessionGroup';
|
|
11
|
+
import { DB_Topic } from '../schemas/topic';
|
|
12
|
+
import { DB_User } from '../schemas/user';
|
|
13
13
|
import { migrateSettingsToUser } from './migrations/migrateSettingsToUser';
|
|
14
14
|
import {
|
|
15
15
|
dbSchemaV1,
|
|
@@ -33,14 +33,14 @@ export interface LobeDBSchemaMap {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Define a local DB
|
|
36
|
-
export class
|
|
37
|
-
public files:
|
|
38
|
-
public sessions:
|
|
39
|
-
public messages:
|
|
40
|
-
public topics:
|
|
41
|
-
public plugins:
|
|
42
|
-
public sessionGroups:
|
|
43
|
-
public users:
|
|
36
|
+
export class BrowserDB extends Dexie {
|
|
37
|
+
public files: BrowserDBTable<'files'>;
|
|
38
|
+
public sessions: BrowserDBTable<'sessions'>;
|
|
39
|
+
public messages: BrowserDBTable<'messages'>;
|
|
40
|
+
public topics: BrowserDBTable<'topics'>;
|
|
41
|
+
public plugins: BrowserDBTable<'plugins'>;
|
|
42
|
+
public sessionGroups: BrowserDBTable<'sessionGroups'>;
|
|
43
|
+
public users: BrowserDBTable<'users'>;
|
|
44
44
|
|
|
45
45
|
constructor() {
|
|
46
46
|
super(LOBE_CHAT_LOCAL_DB_NAME);
|
|
@@ -155,7 +155,7 @@ export class LocalDB extends Dexie {
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
export const
|
|
158
|
+
export const browserDB = new BrowserDB();
|
|
159
159
|
|
|
160
160
|
// ================================================ //
|
|
161
161
|
// ================================================ //
|
|
@@ -164,10 +164,10 @@ export const LocalDBInstance = new LocalDB();
|
|
|
164
164
|
// ================================================ //
|
|
165
165
|
|
|
166
166
|
// types helper
|
|
167
|
-
export type
|
|
167
|
+
export type BrowserDBSchema = {
|
|
168
168
|
[t in keyof LobeDBSchemaMap]: {
|
|
169
169
|
model: LobeDBSchemaMap[t];
|
|
170
170
|
table: Dexie.Table<DBModel<LobeDBSchemaMap[t]>, string>;
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
|
-
type
|
|
173
|
+
type BrowserDBTable<T extends keyof LobeDBSchemaMap> = BrowserDBSchema[T]['table'];
|
|
@@ -3,16 +3,16 @@ import { ZodObject } from 'zod';
|
|
|
3
3
|
|
|
4
4
|
import { nanoid } from '@/utils/uuid';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { BrowserDB, BrowserDBSchema, browserDB } from './db';
|
|
7
7
|
import { dataSync } from './sync';
|
|
8
8
|
import { DBBaseFieldsSchema } from './types/db';
|
|
9
9
|
|
|
10
|
-
export class BaseModel<N extends keyof
|
|
11
|
-
protected readonly db:
|
|
10
|
+
export class BaseModel<N extends keyof BrowserDBSchema = any, T = BrowserDBSchema[N]['table']> {
|
|
11
|
+
protected readonly db: BrowserDB;
|
|
12
12
|
private readonly schema: ZodObject<any>;
|
|
13
|
-
private readonly _tableName: keyof
|
|
13
|
+
private readonly _tableName: keyof BrowserDBSchema;
|
|
14
14
|
|
|
15
|
-
constructor(table: N, schema: ZodObject<any>, db =
|
|
15
|
+
constructor(table: N, schema: ZodObject<any>, db = browserDB) {
|
|
16
16
|
this.db = db;
|
|
17
17
|
this.schema = schema;
|
|
18
18
|
this._tableName = table;
|
|
@@ -31,7 +31,7 @@ export class BaseModel<N extends keyof LocalDBSchema = any, T = LocalDBSchema[N]
|
|
|
31
31
|
/**
|
|
32
32
|
* create a new record
|
|
33
33
|
*/
|
|
34
|
-
protected async _addWithSync<T =
|
|
34
|
+
protected async _addWithSync<T = BrowserDBSchema[N]['model']>(
|
|
35
35
|
data: T,
|
|
36
36
|
id: string | number = nanoid(),
|
|
37
37
|
primaryKey: string = 'id',
|
|
@@ -71,7 +71,7 @@ export class BaseModel<N extends keyof LocalDBSchema = any, T = LocalDBSchema[N]
|
|
|
71
71
|
* @param options.generateId
|
|
72
72
|
* @param options.createWithNewId
|
|
73
73
|
*/
|
|
74
|
-
protected async _batchAdd<T =
|
|
74
|
+
protected async _batchAdd<T = BrowserDBSchema[N]['model']>(
|
|
75
75
|
dataArray: T[],
|
|
76
76
|
options: {
|
|
77
77
|
/**
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
StartDataSyncParams,
|
|
12
12
|
} from '@/types/sync';
|
|
13
13
|
|
|
14
|
-
import { LobeDBSchemaMap,
|
|
14
|
+
import { LobeDBSchemaMap, browserDB } from './db';
|
|
15
15
|
|
|
16
16
|
const LOG_NAME_SPACE = 'DataSync';
|
|
17
17
|
|
|
@@ -201,7 +201,7 @@ class DataSync {
|
|
|
201
201
|
onEvent: OnSyncEvent,
|
|
202
202
|
onSyncStatusChange: OnSyncStatusChange,
|
|
203
203
|
) => {
|
|
204
|
-
const table =
|
|
204
|
+
const table = browserDB[tableKey];
|
|
205
205
|
const yItemMap = this.getYMap(tableKey);
|
|
206
206
|
const updateSyncEvent = throttle(onEvent, 1000);
|
|
207
207
|
|
|
@@ -249,7 +249,7 @@ class DataSync {
|
|
|
249
249
|
};
|
|
250
250
|
|
|
251
251
|
private loadDataFromDBtoYjs = async (tableKey: keyof LobeDBSchemaMap) => {
|
|
252
|
-
const table =
|
|
252
|
+
const table = browserDB[tableKey];
|
|
253
253
|
const items = await table.toArray();
|
|
254
254
|
const yItemMap = this.getYMap(tableKey);
|
|
255
255
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is for debugging purposes only.
|
|
2
2
|
// DON'T USE IT IN PRODUCTION.
|
|
3
3
|
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
4
|
-
import { DBModel } from '@/database/core/types/db';
|
|
5
|
-
import { DB_Message } from '@/database/schemas/message';
|
|
6
|
-
import { DB_Topic } from '@/database/schemas/topic';
|
|
4
|
+
import { DBModel } from '@/database/client/core/types/db';
|
|
5
|
+
import { DB_Message } from '@/database/client/schemas/message';
|
|
6
|
+
import { DB_Topic } from '@/database/client/schemas/topic';
|
|
7
7
|
|
|
8
8
|
import { BaseModel } from '../core';
|
|
9
9
|
import { DB_Session, DB_SessionSchema } from '../schemas/session';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { LocalDB } from '../../core/db';
|
|
3
|
+
import { BrowserDB } from '../../core/db';
|
|
4
|
+
import { DB_File } from '../../schemas/files';
|
|
6
5
|
import { FileModel } from '../file';
|
|
7
6
|
|
|
8
7
|
// Assuming LocalDB is already mocked or using an in-memory database
|
|
@@ -25,7 +24,7 @@ describe('_FileModel', () => {
|
|
|
25
24
|
|
|
26
25
|
afterEach(async () => {
|
|
27
26
|
// Clean up the database after each test
|
|
28
|
-
const db = new
|
|
27
|
+
const db = new BrowserDB();
|
|
29
28
|
await db.files.clear();
|
|
30
29
|
db.close();
|
|
31
30
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
4
|
-
import { CreateMessageParams, MessageModel } from '@/database/models/message';
|
|
5
|
-
import { SessionGroupModel } from '@/database/models/sessionGroup';
|
|
6
|
-
import { TopicModel } from '@/database/models/topic';
|
|
4
|
+
import { CreateMessageParams, MessageModel } from '@/database/client/models/message';
|
|
5
|
+
import { SessionGroupModel } from '@/database/client/models/sessionGroup';
|
|
6
|
+
import { TopicModel } from '@/database/client/models/topic';
|
|
7
7
|
import { LobeAgentConfig } from '@/types/agent';
|
|
8
8
|
import {
|
|
9
9
|
LobeAgentSession,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { SessionModel } from '@/database/models/session';
|
|
3
|
+
import { SessionModel } from '@/database/client/models/session';
|
|
4
4
|
import { SessionGroups } from '@/types/session';
|
|
5
5
|
|
|
6
6
|
import { DB_SessionGroup } from '../../schemas/sessionGroup';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { DBModel } from '@/database/core/types/db';
|
|
4
|
-
import { CreateMessageParams, MessageModel } from '@/database/models/message';
|
|
5
|
-
import { DB_Message } from '@/database/schemas/message';
|
|
6
|
-
import { DB_Topic } from '@/database/schemas/topic';
|
|
3
|
+
import { DBModel } from '@/database/client/core/types/db';
|
|
4
|
+
import { CreateMessageParams, MessageModel } from '@/database/client/models/message';
|
|
5
|
+
import { DB_Message } from '@/database/client/schemas/message';
|
|
6
|
+
import { DB_Topic } from '@/database/client/schemas/topic';
|
|
7
7
|
import { nanoid } from '@/utils/uuid';
|
|
8
8
|
import * as uuidUtils from '@/utils/uuid';
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DeepPartial } from 'utility-types';
|
|
2
2
|
|
|
3
|
-
import { BaseModel } from '@/database/core';
|
|
4
|
-
import { DBModel } from '@/database/core/types/db';
|
|
5
|
-
import { DB_Message, DB_MessageSchema } from '@/database/schemas/message';
|
|
3
|
+
import { BaseModel } from '@/database/client/core';
|
|
4
|
+
import { DBModel } from '@/database/client/core/types/db';
|
|
5
|
+
import { DB_Message, DB_MessageSchema } from '@/database/client/schemas/message';
|
|
6
6
|
import { ChatMessage } from '@/types/message';
|
|
7
7
|
import { nanoid } from '@/utils/uuid';
|
|
8
8
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DeepPartial } from 'utility-types';
|
|
2
2
|
|
|
3
3
|
import { DEFAULT_AGENT_LOBE_SESSION } from '@/const/session';
|
|
4
|
-
import { BaseModel } from '@/database/core';
|
|
5
|
-
import { DBModel } from '@/database/core/types/db';
|
|
6
|
-
import { DB_Session, DB_SessionSchema } from '@/database/schemas/session';
|
|
4
|
+
import { BaseModel } from '@/database/client/core';
|
|
5
|
+
import { DBModel } from '@/database/client/core/types/db';
|
|
6
|
+
import { DB_Session, DB_SessionSchema } from '@/database/client/schemas/session';
|
|
7
7
|
import { LobeAgentConfig } from '@/types/agent';
|
|
8
8
|
import {
|
|
9
9
|
ChatSessionList,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseModel } from '@/database/core';
|
|
2
|
-
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/schemas/sessionGroup';
|
|
1
|
+
import { BaseModel } from '@/database/client/core';
|
|
2
|
+
import { DB_SessionGroup, DB_SessionGroupSchema } from '@/database/client/schemas/sessionGroup';
|
|
3
3
|
import { SessionGroups } from '@/types/session';
|
|
4
4
|
import { nanoid } from '@/utils/uuid';
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseModel } from '@/database/core';
|
|
2
|
-
import { DBModel } from '@/database/core/types/db';
|
|
3
|
-
import { MessageModel } from '@/database/models/message';
|
|
4
|
-
import { DB_Topic, DB_TopicSchema } from '@/database/schemas/topic';
|
|
1
|
+
import { BaseModel } from '@/database/client/core';
|
|
2
|
+
import { DBModel } from '@/database/client/core/types/db';
|
|
3
|
+
import { MessageModel } from '@/database/client/models/message';
|
|
4
|
+
import { DB_Topic, DB_TopicSchema } from '@/database/client/schemas/topic';
|
|
5
5
|
import { ChatTopic } from '@/types/topic';
|
|
6
6
|
import { nanoid } from '@/utils/uuid';
|
|
7
7
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { FileModel } from '@/database/models/file';
|
|
4
|
-
import { DB_File } from '@/database/schemas/files';
|
|
3
|
+
import { FileModel } from '@/database/client/models/file';
|
|
4
|
+
import { DB_File } from '@/database/client/schemas/files';
|
|
5
5
|
|
|
6
6
|
import { fileService } from '../file';
|
|
7
7
|
|
|
8
8
|
// Mocks for the FileModel
|
|
9
|
-
vi.mock('@/database/models/file', () => ({
|
|
9
|
+
vi.mock('@/database/client/models/file', () => ({
|
|
10
10
|
FileModel: {
|
|
11
11
|
create: vi.fn(),
|
|
12
12
|
delete: vi.fn(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Mock, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { CreateMessageParams, MessageModel } from '@/database/models/message';
|
|
3
|
+
import { CreateMessageParams, MessageModel } from '@/database/client/models/message';
|
|
4
4
|
import {
|
|
5
5
|
ChatMessage,
|
|
6
6
|
ChatMessageError,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { messageService } from '../message';
|
|
13
13
|
|
|
14
14
|
// Mock the MessageModel
|
|
15
|
-
vi.mock('@/database/models/message', () => {
|
|
15
|
+
vi.mock('@/database/client/models/message', () => {
|
|
16
16
|
return {
|
|
17
17
|
MessageModel: {
|
|
18
18
|
create: vi.fn(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
2
2
|
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { PluginModel } from '@/database/models/plugin';
|
|
5
|
-
import { DB_Plugin } from '@/database/schemas/plugin';
|
|
4
|
+
import { PluginModel } from '@/database/client/models/plugin';
|
|
5
|
+
import { DB_Plugin } from '@/database/client/schemas/plugin';
|
|
6
6
|
import { globalHelpers } from '@/store/global/helpers';
|
|
7
7
|
import { LobeTool } from '@/types/tool';
|
|
8
8
|
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
@@ -18,7 +18,7 @@ vi.mock('@/store/global/helpers', () => ({
|
|
|
18
18
|
getCurrentLanguage: vi.fn(),
|
|
19
19
|
},
|
|
20
20
|
}));
|
|
21
|
-
vi.mock('@/database/models/plugin', () => ({
|
|
21
|
+
vi.mock('@/database/client/models/plugin', () => ({
|
|
22
22
|
PluginModel: {
|
|
23
23
|
getList: vi.fn(),
|
|
24
24
|
create: vi.fn(),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { SessionModel } from '@/database/models/session';
|
|
4
|
-
import { SessionGroupModel } from '@/database/models/sessionGroup';
|
|
3
|
+
import { SessionModel } from '@/database/client/models/session';
|
|
4
|
+
import { SessionGroupModel } from '@/database/client/models/sessionGroup';
|
|
5
5
|
import { LobeAgentConfig } from '@/types/agent';
|
|
6
6
|
import { LobeAgentSession, LobeSessionType, SessionGroups } from '@/types/session';
|
|
7
7
|
|
|
8
8
|
import { sessionService } from '../session';
|
|
9
9
|
|
|
10
10
|
// Mock the SessionModel
|
|
11
|
-
vi.mock('@/database/models/session', () => {
|
|
11
|
+
vi.mock('@/database/client/models/session', () => {
|
|
12
12
|
return {
|
|
13
13
|
SessionModel: {
|
|
14
14
|
create: vi.fn(),
|
|
@@ -29,7 +29,7 @@ vi.mock('@/database/models/session', () => {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
// Mock the SessionGroupModel
|
|
32
|
-
vi.mock('@/database/models/sessionGroup', () => {
|
|
32
|
+
vi.mock('@/database/client/models/sessionGroup', () => {
|
|
33
33
|
return {
|
|
34
34
|
SessionGroupModel: {
|
|
35
35
|
create: vi.fn(),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Mock, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { CreateTopicParams, TopicModel } from '@/database/models/topic';
|
|
3
|
+
import { CreateTopicParams, TopicModel } from '@/database/client/models/topic';
|
|
4
4
|
import { ChatTopic } from '@/types/topic';
|
|
5
5
|
|
|
6
6
|
import { topicService } from '../topic';
|
|
7
7
|
|
|
8
8
|
// Mock the TopicModel
|
|
9
|
-
vi.mock('@/database/models/topic', () => {
|
|
9
|
+
vi.mock('@/database/client/models/topic', () => {
|
|
10
10
|
return {
|
|
11
11
|
TopicModel: {
|
|
12
12
|
create: vi.fn(),
|
package/src/services/debug.ts
CHANGED
package/src/services/file.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FileModel } from '@/database/models/file';
|
|
2
|
-
import { DB_File } from '@/database/schemas/files';
|
|
1
|
+
import { FileModel } from '@/database/client/models/file';
|
|
2
|
+
import { DB_File } from '@/database/client/schemas/files';
|
|
3
3
|
import { FilePreview } from '@/types/files';
|
|
4
4
|
import compressImage from '@/utils/compressImage';
|
|
5
5
|
|
package/src/services/global.ts
CHANGED
package/src/services/message.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DB_Message } from '@/database/schemas/message';
|
|
1
|
+
import { MessageModel } from '@/database/client/models/message';
|
|
2
|
+
import { DB_Message } from '@/database/client/schemas/message';
|
|
3
3
|
import { ChatMessage, ChatMessageError, ChatPluginPayload } from '@/types/message';
|
|
4
4
|
|
|
5
|
+
export interface CreateMessageParams
|
|
6
|
+
extends Partial<Omit<ChatMessage, 'content' | 'role'>>,
|
|
7
|
+
Pick<ChatMessage, 'content' | 'role'> {
|
|
8
|
+
fromModel?: string;
|
|
9
|
+
fromProvider?: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
traceId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
export class MessageService {
|
|
6
15
|
async create(data: CreateMessageParams) {
|
|
7
16
|
const { id } = await MessageModel.create(data);
|
package/src/services/plugin.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
pluginManifestSchema,
|
|
5
5
|
} from '@lobehub/chat-plugin-sdk';
|
|
6
6
|
|
|
7
|
-
import { PluginModel } from '@/database/models/plugin';
|
|
7
|
+
import { PluginModel } from '@/database/client/models/plugin';
|
|
8
8
|
import { globalHelpers } from '@/store/global/helpers';
|
|
9
9
|
import { OpenAIPluginManifest } from '@/types/openai/plugin';
|
|
10
10
|
import { LobeTool } from '@/types/tool';
|
package/src/services/session.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeepPartial } from 'utility-types';
|
|
2
2
|
|
|
3
|
-
import { SessionModel } from '@/database/models/session';
|
|
4
|
-
import { SessionGroupModel } from '@/database/models/sessionGroup';
|
|
3
|
+
import { SessionModel } from '@/database/client/models/session';
|
|
4
|
+
import { SessionGroupModel } from '@/database/client/models/sessionGroup';
|
|
5
5
|
import { LobeAgentConfig } from '@/types/agent';
|
|
6
6
|
import { MetaData } from '@/types/meta';
|
|
7
7
|
import {
|
package/src/services/topic.ts
CHANGED
package/src/services/user.ts
CHANGED
|
@@ -7,10 +7,9 @@ import { StateCreator } from 'zustand/vanilla';
|
|
|
7
7
|
|
|
8
8
|
import { LOADING_FLAT, isFunctionMessageAtStart, testFunctionMessageAtEnd } from '@/const/message';
|
|
9
9
|
import { TraceEventType, TraceNameMap } from '@/const/trace';
|
|
10
|
-
import { CreateMessageParams } from '@/database/models/message';
|
|
11
10
|
import { useClientDataSWR } from '@/libs/swr';
|
|
12
11
|
import { chatService } from '@/services/chat';
|
|
13
|
-
import { messageService } from '@/services/message';
|
|
12
|
+
import { CreateMessageParams, messageService } from '@/services/message';
|
|
14
13
|
import { topicService } from '@/services/topic';
|
|
15
14
|
import { traceService } from '@/services/trace';
|
|
16
15
|
import { chatHelpers } from '@/store/chat/helpers';
|
|
@@ -4,9 +4,8 @@ import { Md5 } from 'ts-md5';
|
|
|
4
4
|
import { StateCreator } from 'zustand/vanilla';
|
|
5
5
|
|
|
6
6
|
import { PLUGIN_SCHEMA_API_MD5_PREFIX, PLUGIN_SCHEMA_SEPARATOR } from '@/const/plugin';
|
|
7
|
-
import { CreateMessageParams } from '@/database/models/message';
|
|
8
7
|
import { chatService } from '@/services/chat';
|
|
9
|
-
import { messageService } from '@/services/message';
|
|
8
|
+
import { CreateMessageParams, messageService } from '@/services/message';
|
|
10
9
|
import { ChatStore } from '@/store/chat/store';
|
|
11
10
|
import { useToolStore } from '@/store/tool';
|
|
12
11
|
import { pluginSelectors } from '@/store/tool/selectors';
|
package/src/types/sync.ts
CHANGED
|
File without changes
|
/package/src/database/{core → client/core}/migrations/migrateSettingsToUser/fixtures/input.json
RENAMED
|
File without changes
|
/package/src/database/{core → client/core}/migrations/migrateSettingsToUser/fixtures/output.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|