@lobehub/chat 1.36.10 → 1.36.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/changelog/v1.json +18 -0
- package/package.json +1 -1
- package/src/database/migrations/0006_add_knowledge_base.sql +1 -1
- package/src/database/migrations/0007_fix_embedding_table.sql +4 -0
- 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/database/server/models/topic.ts +1 -1
- package/src/server/routers/lambda/importer.ts +3 -2
- package/src/services/import/client.ts +1 -1
- package/src/types/importer.ts +10 -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,56 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.36.12](https://github.com/lobehub/lobe-chat/compare/v1.36.11...v1.36.12)
|
6
|
+
|
7
|
+
<sup>Released on **2024-12-11**</sup>
|
8
|
+
|
9
|
+
#### ♻ Code Refactoring
|
10
|
+
|
11
|
+
- **misc**: Update sql and types.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Code refactoring
|
19
|
+
|
20
|
+
- **misc**: Update sql and types, closes [#4979](https://github.com/lobehub/lobe-chat/issues/4979) ([8243f01](https://github.com/lobehub/lobe-chat/commit/8243f01))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
### [Version 1.36.11](https://github.com/lobehub/lobe-chat/compare/v1.36.10...v1.36.11)
|
31
|
+
|
32
|
+
<sup>Released on **2024-12-11**</sup>
|
33
|
+
|
34
|
+
#### ♻ Code Refactoring
|
35
|
+
|
36
|
+
- **misc**: Refactor data importer to repos.
|
37
|
+
|
38
|
+
<br/>
|
39
|
+
|
40
|
+
<details>
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
42
|
+
|
43
|
+
#### Code refactoring
|
44
|
+
|
45
|
+
- **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))
|
46
|
+
|
47
|
+
</details>
|
48
|
+
|
49
|
+
<div align="right">
|
50
|
+
|
51
|
+
[](#readme-top)
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
5
55
|
### [Version 1.36.10](https://github.com/lobehub/lobe-chat/compare/v1.36.9...v1.36.10)
|
6
56
|
|
7
57
|
<sup>Released on **2024-12-10**</sup>
|
package/changelog/v1.json
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
[
|
2
|
+
{
|
3
|
+
"children": {
|
4
|
+
"improvements": [
|
5
|
+
"Update sql and types."
|
6
|
+
]
|
7
|
+
},
|
8
|
+
"date": "2024-12-11",
|
9
|
+
"version": "1.36.12"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"children": {
|
13
|
+
"improvements": [
|
14
|
+
"Refactor data importer to repos."
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"date": "2024-12-11",
|
18
|
+
"version": "1.36.11"
|
19
|
+
},
|
2
20
|
{
|
3
21
|
"children": {
|
4
22
|
"improvements": [
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.36.
|
3
|
+
"version": "1.36.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",
|
@@ -121,7 +121,7 @@ CREATE TABLE IF NOT EXISTS "unstructured_chunks" (
|
|
121
121
|
"file_id" varchar
|
122
122
|
);
|
123
123
|
--> statement-breakpoint
|
124
|
-
ALTER TABLE "files_to_messages" RENAME TO "messages_files"
|
124
|
+
ALTER TABLE "files_to_messages" RENAME TO "messages_files";--> statement-breakpoint
|
125
125
|
DROP TABLE "files_to_agents";--> statement-breakpoint
|
126
126
|
ALTER TABLE "files" ADD COLUMN "file_hash" varchar(64);--> statement-breakpoint
|
127
127
|
ALTER TABLE "files" ADD COLUMN "chunk_task_id" uuid;--> statement-breakpoint
|
@@ -3,16 +3,20 @@ CREATE TEMP TABLE embeddings_temp AS
|
|
3
3
|
SELECT DISTINCT ON (chunk_id) *
|
4
4
|
FROM embeddings
|
5
5
|
ORDER BY chunk_id, random();
|
6
|
+
--> statement-breakpoint
|
6
7
|
|
7
8
|
-- step 2: delete all rows from the original table
|
8
9
|
DELETE FROM embeddings;
|
10
|
+
--> statement-breakpoint
|
9
11
|
|
10
12
|
-- step 3: insert the rows we want to keep back into the original table
|
11
13
|
INSERT INTO embeddings
|
12
14
|
SELECT * FROM embeddings_temp;
|
15
|
+
--> statement-breakpoint
|
13
16
|
|
14
17
|
-- step 4: drop the temporary table
|
15
18
|
DROP TABLE embeddings_temp;
|
19
|
+
--> statement-breakpoint
|
16
20
|
|
17
21
|
-- step 5: now it's safe to add the unique constraint
|
18
22
|
ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_chunk_id_unique" UNIQUE("chunk_id");
|
@@ -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(
|
@@ -2,9 +2,9 @@ import { Column, count, inArray, sql } from 'drizzle-orm';
|
|
2
2
|
import { and, desc, eq, exists, isNull, like, or } from 'drizzle-orm/expressions';
|
3
3
|
|
4
4
|
import { LobeChatDatabase } from '@/database/type';
|
5
|
+
import { idGenerator } from '@/database/utils/idGenerator';
|
5
6
|
|
6
7
|
import { NewMessage, TopicItem, messages, topics } from '../../schemas';
|
7
|
-
import { idGenerator } from '@/database/utils/idGenerator';
|
8
8
|
|
9
9
|
export interface CreateTopicParams {
|
10
10
|
favorite?: boolean;
|
@@ -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 },
|
@@ -32,7 +32,7 @@ export class ClientService {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
if (sessionGroups.length > 0) {
|
35
|
-
const res = await SessionGroupModel.batchCreate(sessionGroups);
|
35
|
+
const res = await SessionGroupModel.batchCreate(sessionGroups as any);
|
36
36
|
sessionGroupResult = this.mapImportResult(res);
|
37
37
|
}
|
38
38
|
|
package/src/types/importer.ts
CHANGED
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
MessageRoleType,
|
9
9
|
} from '@/types/message';
|
10
10
|
import { MetaData } from '@/types/meta';
|
11
|
-
import { SessionGroupId
|
11
|
+
import { SessionGroupId } from '@/types/session';
|
12
12
|
import { ChatTopic } from '@/types/topic';
|
13
13
|
|
14
14
|
interface ImportSession {
|
@@ -64,9 +64,17 @@ interface ImportMessage {
|
|
64
64
|
updatedAt: number;
|
65
65
|
}
|
66
66
|
|
67
|
+
interface ImportSessionGroup {
|
68
|
+
createdAt: number;
|
69
|
+
id: string;
|
70
|
+
name: string;
|
71
|
+
sort?: number | null;
|
72
|
+
updatedAt: number;
|
73
|
+
}
|
74
|
+
|
67
75
|
export interface ImporterEntryData {
|
68
76
|
messages?: ImportMessage[];
|
69
|
-
sessionGroups?:
|
77
|
+
sessionGroups?: ImportSessionGroup[];
|
70
78
|
sessions?: ImportSession[];
|
71
79
|
topics?: ChatTopic[];
|
72
80
|
version: number;
|
package/vitest.config.ts
CHANGED
/package/src/{server/services → database/repositories}/dataImporter/__tests__/fixtures/messages.json
RENAMED
File without changes
|