@lobehub/chat 1.36.10 → 1.36.11
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/package.json +1 -1
- package/src/{server/services → database/repositories}/dataImporter/__tests__/index.test.ts +5 -12
- package/src/{server/services → database/repositories}/dataImporter/index.ts +6 -4
- package/src/server/routers/lambda/importer.ts +3 -2
- package/vitest.config.ts +1 -1
- /package/src/{server/services → database/repositories}/dataImporter/__tests__/fixtures/messages.json +0 -0
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.36.11](https://github.com/lobehub/lobe-chat/compare/v1.36.10...v1.36.11)
|
6
|
+
|
7
|
+
<sup>Released on **2024-12-11**</sup>
|
8
|
+
|
9
|
+
#### ♻ Code Refactoring
|
10
|
+
|
11
|
+
- **misc**: Refactor data importer to repos.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Code refactoring
|
19
|
+
|
20
|
+
- **misc**: Refactor data importer to repos, closes [#4974](https://github.com/lobehub/lobe-chat/issues/4974) ([0259fec](https://github.com/lobehub/lobe-chat/commit/0259fec))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
5
30
|
### [Version 1.36.10](https://github.com/lobehub/lobe-chat/compare/v1.36.9...v1.36.10)
|
6
31
|
|
7
32
|
<sup>Released on **2024-12-10**</sup>
|
package/changelog/v1.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.36.
|
3
|
+
"version": "1.36.11",
|
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",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// @vitest-environment node
|
2
2
|
import { eq, inArray } from 'drizzle-orm';
|
3
|
-
import {
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
5
|
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
6
6
|
import {
|
@@ -13,22 +13,15 @@ import {
|
|
13
13
|
users,
|
14
14
|
} from '@/database/schemas';
|
15
15
|
import { CURRENT_CONFIG_VERSION } from '@/migrations';
|
16
|
-
import { ImportResult } from '@/services/config';
|
17
16
|
import { ImporterEntryData } from '@/types/importer';
|
18
17
|
|
19
|
-
import {
|
18
|
+
import { DataImporterRepos } from '../index';
|
20
19
|
import mockImportData from './fixtures/messages.json';
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
vi.mock('@/database/server/core/db', async () => ({
|
25
|
-
get serverDB() {
|
26
|
-
return serverDB;
|
27
|
-
},
|
28
|
-
}));
|
21
|
+
const serverDB = await getTestDBInstance();
|
29
22
|
|
30
23
|
const userId = 'test-user-id';
|
31
|
-
let importer:
|
24
|
+
let importer: DataImporterRepos;
|
32
25
|
|
33
26
|
beforeEach(async () => {
|
34
27
|
await serverDB.delete(users);
|
@@ -38,7 +31,7 @@ beforeEach(async () => {
|
|
38
31
|
await tx.insert(users).values({ id: userId });
|
39
32
|
});
|
40
33
|
|
41
|
-
importer = new
|
34
|
+
importer = new DataImporterRepos(serverDB, userId);
|
42
35
|
});
|
43
36
|
|
44
37
|
describe('DataImporter', () => {
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { eq, inArray, sql } from 'drizzle-orm';
|
2
2
|
import { and } from 'drizzle-orm/expressions';
|
3
3
|
|
4
|
-
import { serverDB } from '@/database/server';
|
5
4
|
import {
|
6
5
|
agents,
|
7
6
|
agentsToSessions,
|
@@ -12,19 +11,22 @@ import {
|
|
12
11
|
sessions,
|
13
12
|
topics,
|
14
13
|
} from '@/database/schemas';
|
14
|
+
import { LobeChatDatabase } from '@/database/type';
|
15
15
|
import { ImportResult } from '@/services/config';
|
16
16
|
import { ImporterEntryData } from '@/types/importer';
|
17
17
|
|
18
|
-
export class
|
18
|
+
export class DataImporterRepos {
|
19
19
|
private userId: string;
|
20
|
+
private db: LobeChatDatabase;
|
20
21
|
|
21
22
|
/**
|
22
23
|
* The version of the importer that this module supports
|
23
24
|
*/
|
24
25
|
supportVersion = 7;
|
25
26
|
|
26
|
-
constructor(userId: string) {
|
27
|
+
constructor(db: LobeChatDatabase, userId: string) {
|
27
28
|
this.userId = userId;
|
29
|
+
this.db = db;
|
28
30
|
}
|
29
31
|
|
30
32
|
importData = async (data: ImporterEntryData) => {
|
@@ -40,7 +42,7 @@ export class DataImporterService {
|
|
40
42
|
let topicIdMap: Record<string, string> = {};
|
41
43
|
|
42
44
|
// import sessionGroups
|
43
|
-
await
|
45
|
+
await this.db.transaction(async (trx) => {
|
44
46
|
if (data.sessionGroups && data.sessionGroups.length > 0) {
|
45
47
|
const query = await trx.query.sessionGroups.findMany({
|
46
48
|
where: and(
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { TRPCError } from '@trpc/server';
|
2
2
|
import { z } from 'zod';
|
3
3
|
|
4
|
+
import { DataImporterRepos } from '@/database/repositories/dataImporter';
|
5
|
+
import { serverDB } from '@/database/server';
|
4
6
|
import { authedProcedure, router } from '@/libs/trpc';
|
5
7
|
import { S3 } from '@/server/modules/S3';
|
6
|
-
import { DataImporterService } from '@/server/services/dataImporter';
|
7
8
|
import { ImportResults, ImporterEntryData } from '@/types/importer';
|
8
9
|
|
9
10
|
const importProcedure = authedProcedure.use(async (opts) => {
|
10
11
|
const { ctx } = opts;
|
11
|
-
const dataImporterService = new
|
12
|
+
const dataImporterService = new DataImporterRepos(serverDB, ctx.userId);
|
12
13
|
|
13
14
|
return opts.next({
|
14
15
|
ctx: { dataImporterService },
|
package/vitest.config.ts
CHANGED
/package/src/{server/services → database/repositories}/dataImporter/__tests__/fixtures/messages.json
RENAMED
File without changes
|