@lobehub/chat 1.12.9 → 1.12.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.
Files changed (34) hide show
  1. package/.github/workflows/release.yml +3 -2
  2. package/.github/workflows/test.yml +2 -1
  3. package/CHANGELOG.md +50 -0
  4. package/package.json +57 -57
  5. package/src/app/(main)/files/[id]/Header.tsx +1 -1
  6. package/src/config/app.ts +12 -5
  7. package/src/config/db.ts +4 -0
  8. package/src/database/server/models/__tests__/chunk.test.ts +60 -1
  9. package/src/database/server/models/__tests__/file.test.ts +211 -66
  10. package/src/database/server/models/__tests__/knowledgeBase.test.ts +128 -2
  11. package/src/database/server/models/__tests__/user.test.ts +36 -1
  12. package/src/database/server/models/chunk.ts +14 -1
  13. package/src/database/server/models/file.ts +4 -2
  14. package/src/features/FileManager/FileList/FileListItem/DropdownMenu.tsx +1 -1
  15. package/src/features/FileViewer/NotSupport/index.tsx +1 -1
  16. package/src/server/routers/lambda/file.ts +9 -1
  17. package/src/services/__tests__/chat.test.ts +0 -57
  18. package/src/services/file/client.test.ts +8 -5
  19. package/src/services/file/client.ts +6 -6
  20. package/src/services/file/server.ts +3 -20
  21. package/src/services/file/type.ts +2 -2
  22. package/src/services/upload.ts +14 -0
  23. package/src/store/chat/slices/builtinTool/action.test.ts +6 -3
  24. package/src/store/chat/slices/builtinTool/action.ts +37 -14
  25. package/src/store/chat/slices/builtinTool/initialState.ts +4 -0
  26. package/src/store/file/slices/chat/action.test.ts +0 -34
  27. package/src/store/file/slices/chat/action.ts +1 -26
  28. package/src/store/file/slices/chat/initialState.ts +0 -7
  29. package/src/store/file/slices/tts/action.ts +2 -2
  30. package/src/tools/dalle/Render/Item/ImageFileItem.tsx +3 -3
  31. package/src/tools/dalle/Render/Item/index.tsx +1 -1
  32. package/src/tools/renders.ts +0 -6
  33. package/src/types/files/index.ts +0 -12
  34. package/src/utils/{downloadFile.ts → client/downloadFile.ts} +2 -1
@@ -18,7 +18,7 @@ jobs:
18
18
  --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
19
19
  ports:
20
20
  - 5432:5432
21
-
21
+
22
22
  steps:
23
23
  - uses: actions/checkout@v4
24
24
 
@@ -40,7 +40,8 @@ jobs:
40
40
  DATABASE_DRIVER: node
41
41
  NEXT_PUBLIC_SERVICE_MODE: server
42
42
  KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
43
- NEXT_PUBLIC_S3_DOMAIN: https://example.com
43
+ S3_PUBLIC_DOMAIN: https://example.com
44
+ APP_URL: https://home.com
44
45
 
45
46
  - name: Test App Coverage
46
47
  run: bun run test-app:coverage
@@ -39,7 +39,8 @@ jobs:
39
39
  DATABASE_DRIVER: node
40
40
  NEXT_PUBLIC_SERVICE_MODE: server
41
41
  KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
42
- NEXT_PUBLIC_S3_DOMAIN: https://example.com
42
+ S3_PUBLIC_DOMAIN: https://example.com
43
+ APP_URL: https://home.com
43
44
 
44
45
  - name: Upload Server coverage to Codecov
45
46
  uses: codecov/codecov-action@v4
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.12.11](https://github.com/lobehub/lobe-chat/compare/v1.12.10...v1.12.11)
6
+
7
+ <sup>Released on **2024-08-23**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Remove orphan chunks if there is no related file.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Remove orphan chunks if there is no related file, closes [#3578](https://github.com/lobehub/lobe-chat/issues/3578) ([36bcaf3](https://github.com/lobehub/lobe-chat/commit/36bcaf3))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.12.10](https://github.com/lobehub/lobe-chat/compare/v1.12.9...v1.12.10)
31
+
32
+ <sup>Released on **2024-08-23**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Refactor and fix dalle.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Refactor and fix dalle, closes [#3572](https://github.com/lobehub/lobe-chat/issues/3572) ([8b39b61](https://github.com/lobehub/lobe-chat/commit/8b39b61))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.12.9](https://github.com/lobehub/lobe-chat/compare/v1.12.8...v1.12.9)
6
56
 
7
57
  <sup>Released on **2024-08-23**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.12.9",
3
+ "version": "1.12.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",
@@ -99,33 +99,33 @@
99
99
  ]
100
100
  },
101
101
  "dependencies": {
102
- "@ant-design/icons": "^5.3.7",
102
+ "@ant-design/icons": "^5.4.0",
103
103
  "@anthropic-ai/sdk": "^0.24.3",
104
104
  "@auth/core": "0.28.0",
105
- "@aws-sdk/client-bedrock-runtime": "^3.609.0",
106
- "@aws-sdk/client-s3": "^3.609.0",
107
- "@aws-sdk/s3-request-presigner": "^3.609.0",
105
+ "@aws-sdk/client-bedrock-runtime": "^3.637.0",
106
+ "@aws-sdk/client-s3": "^3.637.0",
107
+ "@aws-sdk/s3-request-presigner": "^3.637.0",
108
108
  "@azure/core-rest-pipeline": "1.16.0",
109
109
  "@azure/openai": "1.0.0-beta.12",
110
110
  "@cfworker/json-schema": "^1.12.8",
111
111
  "@clerk/localizations": "2.0.0",
112
- "@clerk/nextjs": "^5.2.14",
113
- "@clerk/themes": "^2.1.10",
112
+ "@clerk/nextjs": "^5.3.3",
113
+ "@clerk/themes": "^2.1.21",
114
114
  "@cyntler/react-doc-viewer": "^1.16.6",
115
115
  "@google/generative-ai": "^0.16.0",
116
116
  "@icons-pack/react-simple-icons": "9.6.0",
117
117
  "@khmyznikov/pwa-install": "^0.3.9",
118
- "@langchain/community": "^0.2.27",
118
+ "@langchain/community": "^0.2.31",
119
119
  "@lobehub/chat-plugin-sdk": "^1.32.4",
120
120
  "@lobehub/chat-plugins-gateway": "^1.9.0",
121
121
  "@lobehub/icons": "^1.28.0",
122
122
  "@lobehub/tts": "^1.24.3",
123
123
  "@lobehub/ui": "^1.149.2",
124
124
  "@neondatabase/serverless": "^0.9.4",
125
- "@next/third-parties": "^14.2.4",
126
- "@sentry/nextjs": "^7.118.0",
125
+ "@next/third-parties": "^14.2.6",
126
+ "@sentry/nextjs": "^7.119.0",
127
127
  "@t3-oss/env-nextjs": "^0.10.1",
128
- "@tanstack/react-query": "^5.51.11",
128
+ "@tanstack/react-query": "^5.52.1",
129
129
  "@trpc/client": "next",
130
130
  "@trpc/next": "next",
131
131
  "@trpc/react-query": "next",
@@ -133,32 +133,32 @@
133
133
  "@vercel/analytics": "^1.3.1",
134
134
  "@vercel/edge-config": "^1.2.1",
135
135
  "@vercel/speed-insights": "^1.0.12",
136
- "ahooks": "^3.8.0",
137
- "ai": "^3.2.16",
136
+ "ahooks": "^3.8.1",
137
+ "ai": "^3.3.16",
138
138
  "antd": "^5.20.2",
139
139
  "antd-style": "^3.6.2",
140
140
  "brotli-wasm": "^3.0.1",
141
- "chroma-js": "^2.4.2",
142
- "dayjs": "^1.11.11",
143
- "debug": "^4.3.5",
141
+ "chroma-js": "^2.6.0",
142
+ "dayjs": "^1.11.13",
143
+ "debug": "^4.3.6",
144
144
  "dexie": "^3.2.7",
145
145
  "diff": "^5.2.0",
146
- "drizzle-orm": "^0.32.0",
146
+ "drizzle-orm": "^0.32.2",
147
147
  "drizzle-zod": "^0.5.1",
148
148
  "fast-deep-equal": "^3.1.3",
149
149
  "file-type": "^19.4.1",
150
- "gpt-tokenizer": "^2.1.2",
151
- "i18next": "^23.11.5",
150
+ "gpt-tokenizer": "^2.2.1",
151
+ "i18next": "^23.14.0",
152
152
  "i18next-browser-languagedetector": "^7.2.1",
153
153
  "i18next-resources-to-backend": "^1.2.1",
154
154
  "idb-keyval": "^6.2.1",
155
155
  "immer": "^10.1.1",
156
156
  "ip": "^2.0.1",
157
- "jose": "^5.6.3",
157
+ "jose": "^5.7.0",
158
158
  "js-sha256": "^0.11.0",
159
- "langchain": "^0.2.16",
160
- "langfuse": "^3.14.0",
161
- "langfuse-core": "^3.14.0",
159
+ "langchain": "^0.2.17",
160
+ "langfuse": "^3.19.0",
161
+ "langfuse-core": "^3.19.0",
162
162
  "lodash-es": "^4.17.21",
163
163
  "lucide-react": "latest",
164
164
  "mammoth": "^1.8.0",
@@ -168,7 +168,7 @@
168
168
  "next-auth": "5.0.0-beta.15",
169
169
  "next-sitemap": "^4.2.3",
170
170
  "numeral": "^2.0.6",
171
- "nuqs": "^1.17.4",
171
+ "nuqs": "^1.17.8",
172
172
  "officeparser": "^4.1.1",
173
173
  "ollama": "^0.5.8",
174
174
  "openai": "~4.54.0",
@@ -176,11 +176,11 @@
176
176
  "pdf-parse": "^1.1.1",
177
177
  "pdfjs-dist": "4.4.168",
178
178
  "pg": "^8.12.0",
179
- "pino": "^9.2.0",
179
+ "pino": "^9.3.2",
180
180
  "polished": "^4.3.1",
181
- "posthog-js": "^1.144.2",
181
+ "posthog-js": "^1.157.2",
182
182
  "pwa-install-handler": "^2.6.0",
183
- "query-string": "^9.0.0",
183
+ "query-string": "^9.1.0",
184
184
  "random-words": "^2.0.1",
185
185
  "react": "^18.3.1",
186
186
  "react-dom": "^18.3.1",
@@ -190,22 +190,22 @@
190
190
  "react-layout-kit": "^1.9.0",
191
191
  "react-lazy-load": "^4.0.1",
192
192
  "react-pdf": "^9.1.0",
193
- "react-virtuoso": "^4.7.11",
193
+ "react-virtuoso": "^4.10.1",
194
194
  "react-wrap-balancer": "^1.1.1",
195
195
  "remark": "^14.0.3",
196
196
  "remark-gfm": "^3.0.1",
197
197
  "remark-html": "^15.0.2",
198
- "resolve-accept-language": "^3.1.4",
198
+ "resolve-accept-language": "^3.1.5",
199
199
  "rtl-detect": "^1.1.2",
200
- "semver": "^7.6.2",
201
- "sharp": "^0.33.4",
200
+ "semver": "^7.6.3",
201
+ "sharp": "^0.33.5",
202
202
  "superjson": "^2.2.1",
203
- "svix": "^1.24.0",
203
+ "svix": "^1.30.0",
204
204
  "swr": "^2.2.5",
205
205
  "systemjs": "^6.15.1",
206
206
  "ts-md5": "^1.3.1",
207
207
  "ua-parser-js": "^1.0.38",
208
- "unstructured-client": "^0.15.0",
208
+ "unstructured-client": "^0.15.1",
209
209
  "url-join": "^5.0.0",
210
210
  "use-merge-value": "^1.2.0",
211
211
  "utility-types": "^3.11.0",
@@ -213,74 +213,74 @@
213
213
  "ws": "^8.18.0",
214
214
  "y-protocols": "^1.0.6",
215
215
  "y-webrtc": "^10.3.0",
216
- "yaml": "^2.4.5",
216
+ "yaml": "^2.5.0",
217
217
  "yjs": "^13.6.18",
218
218
  "zod": "^3.23.8",
219
- "zustand": "^4.5.4",
219
+ "zustand": "^4.5.5",
220
220
  "zustand-utils": "^1.3.2"
221
221
  },
222
222
  "devDependencies": {
223
- "@commitlint/cli": "^19.3.0",
224
- "@ducanh2912/next-pwa": "^10.2.7",
225
- "@edge-runtime/vm": "^4.0.0",
223
+ "@commitlint/cli": "^19.4.0",
224
+ "@ducanh2912/next-pwa": "^10.2.8",
225
+ "@edge-runtime/vm": "^4.0.2",
226
226
  "@lobehub/i18n-cli": "^1.19.1",
227
- "@lobehub/lint": "^1.24.3",
228
- "@lobehub/seo-cli": "^1.4.1",
229
- "@next/bundle-analyzer": "^14.2.4",
230
- "@next/eslint-plugin-next": "^14.2.4",
227
+ "@lobehub/lint": "^1.24.4",
228
+ "@lobehub/seo-cli": "^1.4.2",
229
+ "@next/bundle-analyzer": "^14.2.6",
230
+ "@next/eslint-plugin-next": "^14.2.6",
231
231
  "@peculiar/webcrypto": "^1.5.0",
232
- "@testing-library/jest-dom": "^6.4.6",
232
+ "@testing-library/jest-dom": "^6.4.8",
233
233
  "@testing-library/react": "^16.0.0",
234
234
  "@types/chroma-js": "^2.4.4",
235
235
  "@types/debug": "^4.1.12",
236
236
  "@types/diff": "^5.2.1",
237
237
  "@types/ip": "^1.1.3",
238
238
  "@types/json-schema": "^7.0.15",
239
- "@types/lodash": "^4.17.6",
239
+ "@types/lodash": "^4.17.7",
240
240
  "@types/lodash-es": "^4.17.12",
241
- "@types/node": "^20.14.10",
241
+ "@types/node": "^20.16.1",
242
242
  "@types/numeral": "^2.0.5",
243
243
  "@types/pg": "^8.11.6",
244
- "@types/react": "^18.3.3",
244
+ "@types/react": "^18.3.4",
245
245
  "@types/react-dom": "^18.3.0",
246
246
  "@types/rtl-detect": "^1.0.3",
247
247
  "@types/semver": "^7.5.8",
248
248
  "@types/systemjs": "^6.13.5",
249
249
  "@types/ua-parser-js": "^0.7.39",
250
250
  "@types/uuid": "^10.0.0",
251
- "@types/ws": "^8.5.10",
251
+ "@types/ws": "^8.5.12",
252
252
  "@vitest/coverage-v8": "~1.2.2",
253
253
  "ajv-keywords": "^5.1.0",
254
- "commitlint": "^19.3.0",
254
+ "commitlint": "^19.4.0",
255
255
  "consola": "^3.2.3",
256
256
  "dotenv": "^16.4.5",
257
257
  "dpdm": "^3.14.0",
258
- "drizzle-kit": "^0.23.0",
258
+ "drizzle-kit": "^0.23.2",
259
259
  "eslint": "^8.57.0",
260
260
  "eslint-plugin-mdx": "^2.3.4",
261
261
  "eslint-plugin-unused-imports": "4.0.1",
262
262
  "fake-indexeddb": "^6.0.0",
263
- "glob": "^10.4.3",
263
+ "glob": "^10.4.5",
264
264
  "gray-matter": "^4.0.3",
265
265
  "happy-dom": "^14.12.3",
266
- "husky": "^9.0.11",
266
+ "husky": "^9.1.5",
267
267
  "just-diff": "^6.0.2",
268
- "lint-staged": "^15.2.7",
268
+ "lint-staged": "^15.2.9",
269
269
  "lodash": "^4.17.21",
270
270
  "markdown-table": "^3.0.3",
271
271
  "node-fetch": "^3.3.2",
272
- "node-gyp": "^10.1.0",
272
+ "node-gyp": "^10.2.0",
273
273
  "p-map": "^7.0.2",
274
- "prettier": "^3.3.2",
274
+ "prettier": "^3.3.3",
275
275
  "remark-cli": "^11.0.0",
276
276
  "remark-parse": "^10.0.2",
277
277
  "semantic-release": "^21.1.2",
278
278
  "stylelint": "^15.11.0",
279
- "tsx": "^4.16.2",
280
- "typescript": "^5.5.3",
279
+ "tsx": "^4.17.0",
280
+ "typescript": "^5.5.4",
281
281
  "unified": "^11.0.5",
282
282
  "unist-util-visit": "^5.0.0",
283
- "vite": "^5.3.3",
283
+ "vite": "^5.4.2",
284
284
  "vitest": "~1.2.2",
285
285
  "vitest-canvas-mock": "^0.3.3"
286
286
  },
@@ -9,7 +9,7 @@ import { memo } from 'react';
9
9
  import { useTranslation } from 'react-i18next';
10
10
  import { Flexbox } from 'react-layout-kit';
11
11
 
12
- import { downloadFile } from '@/utils/downloadFile';
12
+ import { downloadFile } from '@/utils/client/downloadFile';
13
13
 
14
14
  interface HeaderProps {
15
15
  filename: string;
package/src/config/app.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  import { createEnv } from '@t3-oss/env-nextjs';
3
3
  import { z } from 'zod';
4
4
 
5
+ import { isServerMode } from '@/const/version';
6
+
5
7
  declare global {
6
8
  // eslint-disable-next-line @typescript-eslint/no-namespace
7
9
  namespace NodeJS {
@@ -10,14 +12,19 @@ declare global {
10
12
  }
11
13
  }
12
14
  }
15
+ const isInVercel = process.env.VERCEL === '1';
13
16
 
14
- export const getAppConfig = () => {
15
- const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];
16
- const isInVercel = process.env.VERCEL === '1';
17
+ const vercelUrl = `https://${process.env.VERCEL_URL}`;
17
18
 
18
- const vercelUrl = `https://${process.env.VERCEL_URL}`;
19
+ const APP_URL = process.env.APP_URL ? process.env.APP_URL : isInVercel ? vercelUrl : undefined;
19
20
 
20
- const APP_URL = process.env.APP_URL ? process.env.APP_URL : isInVercel ? vercelUrl : undefined;
21
+ // only throw error in server mode and server side
22
+ if (typeof window === 'undefined' && isServerMode && !APP_URL) {
23
+ throw new Error('`APP_URL` is required in server mode');
24
+ }
25
+
26
+ export const getAppConfig = () => {
27
+ const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];
21
28
 
22
29
  return createEnv({
23
30
  client: {
package/src/config/db.ts CHANGED
@@ -11,6 +11,8 @@ export const getServerDBConfig = () => {
11
11
  DATABASE_TEST_URL: process.env.DATABASE_TEST_URL,
12
12
  DATABASE_URL: process.env.DATABASE_URL,
13
13
 
14
+ DISABLE_REMOVE_GLOBAL_FILE: process.env.DISABLE_REMOVE_GLOBAL_FILE === '1',
15
+
14
16
  KEY_VAULTS_SECRET: process.env.KEY_VAULTS_SECRET,
15
17
 
16
18
  NEXT_PUBLIC_ENABLED_SERVER_SERVICE: process.env.NEXT_PUBLIC_SERVICE_MODE === 'server',
@@ -20,6 +22,8 @@ export const getServerDBConfig = () => {
20
22
  DATABASE_TEST_URL: z.string().optional(),
21
23
  DATABASE_URL: z.string().optional(),
22
24
 
25
+ DISABLE_REMOVE_GLOBAL_FILE: z.boolean().optional(),
26
+
23
27
  KEY_VAULTS_SECRET: z.string().optional(),
24
28
  },
25
29
  });
@@ -98,7 +98,66 @@ describe('ChunkModel', () => {
98
98
  });
99
99
  });
100
100
 
101
- // Add more test cases for other methods...
101
+ describe('deleteOrphanChunks', () => {
102
+ it('should delete orphaned chunks', async () => {
103
+ // Create orphaned chunks
104
+ await serverDB
105
+ .insert(chunks)
106
+ .values([
107
+ { text: 'Orphan Chunk 1', userId },
108
+ { text: 'Orphan Chunk 2', userId },
109
+ ])
110
+ .returning();
111
+
112
+ // Create a non-orphaned chunk
113
+ const [nonOrphanChunk] = await serverDB
114
+ .insert(chunks)
115
+ .values([{ text: 'Non-Orphan Chunk', userId }])
116
+ .returning();
117
+
118
+ await serverDB.insert(fileChunks).values([{ fileId: '1', chunkId: nonOrphanChunk.id }]);
119
+
120
+ // Execute the method
121
+ await chunkModel.deleteOrphanChunks();
122
+
123
+ // Check if orphaned chunks are deleted
124
+ const remainingChunks = await serverDB.query.chunks.findMany();
125
+ expect(remainingChunks).toHaveLength(1);
126
+ expect(remainingChunks[0].id).toBe(nonOrphanChunk.id);
127
+ });
128
+
129
+ it('should not delete any chunks when there are no orphans', async () => {
130
+ // Create non-orphaned chunks
131
+ const [chunk1, chunk2] = await serverDB
132
+ .insert(chunks)
133
+ .values([
134
+ { text: 'Chunk 1', userId },
135
+ { text: 'Chunk 2', userId },
136
+ ])
137
+ .returning();
138
+
139
+ await serverDB.insert(fileChunks).values([
140
+ { fileId: '1', chunkId: chunk1.id },
141
+ { fileId: '2', chunkId: chunk2.id },
142
+ ]);
143
+
144
+ // Execute the method
145
+ await chunkModel.deleteOrphanChunks();
146
+
147
+ // Check if all chunks are still present
148
+ const remainingChunks = await serverDB.query.chunks.findMany();
149
+ expect(remainingChunks).toHaveLength(2);
150
+ });
151
+
152
+ it('should not throw an error when the database is empty', async () => {
153
+ // Ensure the database is empty
154
+ await serverDB.delete(chunks);
155
+ await serverDB.delete(fileChunks);
156
+
157
+ // Execute the method and expect it not to throw
158
+ await expect(chunkModel.deleteOrphanChunks()).resolves.not.toThrow();
159
+ });
160
+ });
102
161
 
103
162
  describe('semanticSearch', () => {
104
163
  it('should perform semantic search and return results', async () => {