@lobehub/chat 1.12.8 → 1.12.10
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/package.json +57 -57
- package/src/app/(main)/files/[id]/Header.tsx +1 -1
- package/src/features/FileManager/FileList/FileListItem/DropdownMenu.tsx +1 -1
- package/src/features/FileViewer/NotSupport/index.tsx +1 -1
- package/src/server/routers/lambda/file.ts +4 -1
- package/src/server/utils/files.test.ts +36 -0
- package/src/server/utils/files.ts +4 -0
- package/src/services/__tests__/chat.test.ts +0 -57
- package/src/services/file/client.test.ts +8 -5
- package/src/services/file/client.ts +6 -6
- package/src/services/file/server.ts +3 -20
- package/src/services/file/type.ts +2 -2
- package/src/services/upload.ts +14 -0
- package/src/store/chat/slices/builtinTool/action.test.ts +6 -3
- package/src/store/chat/slices/builtinTool/action.ts +37 -14
- package/src/store/chat/slices/builtinTool/initialState.ts +4 -0
- package/src/store/file/slices/chat/action.test.ts +0 -34
- package/src/store/file/slices/chat/action.ts +1 -26
- package/src/store/file/slices/chat/initialState.ts +0 -7
- package/src/store/file/slices/tts/action.ts +2 -2
- package/src/tools/dalle/Render/Item/ImageFileItem.tsx +3 -3
- package/src/tools/dalle/Render/Item/index.tsx +1 -1
- package/src/tools/renders.ts +0 -6
- package/src/types/files/index.ts +0 -12
- package/src/utils/{downloadFile.ts → client/downloadFile.ts} +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 1.12.10](https://github.com/lobehub/lobe-chat/compare/v1.12.9...v1.12.10)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-08-23**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Refactor and fix dalle.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Refactor and fix dalle, closes [#3572](https://github.com/lobehub/lobe-chat/issues/3572) ([8b39b61](https://github.com/lobehub/lobe-chat/commit/8b39b61))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 1.12.9](https://github.com/lobehub/lobe-chat/compare/v1.12.8...v1.12.9)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-08-23**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: Improve s3 path-style url.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: Improve s3 path-style url, closes [#3567](https://github.com/lobehub/lobe-chat/issues/3567) ([96bb38a](https://github.com/lobehub/lobe-chat/commit/96bb38a))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 1.12.8](https://github.com/lobehub/lobe-chat/compare/v1.12.7...v1.12.8)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-08-22**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.10",
|
|
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.
|
|
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.
|
|
106
|
-
"@aws-sdk/client-s3": "^3.
|
|
107
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
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.
|
|
113
|
-
"@clerk/themes": "^2.1.
|
|
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.
|
|
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.
|
|
126
|
-
"@sentry/nextjs": "^7.
|
|
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.
|
|
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.
|
|
137
|
-
"ai": "^3.
|
|
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.
|
|
142
|
-
"dayjs": "^1.11.
|
|
143
|
-
"debug": "^4.3.
|
|
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.
|
|
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
|
|
151
|
-
"i18next": "^23.
|
|
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.
|
|
157
|
+
"jose": "^5.7.0",
|
|
158
158
|
"js-sha256": "^0.11.0",
|
|
159
|
-
"langchain": "^0.2.
|
|
160
|
-
"langfuse": "^3.
|
|
161
|
-
"langfuse-core": "^3.
|
|
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.
|
|
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
|
|
179
|
+
"pino": "^9.3.2",
|
|
180
180
|
"polished": "^4.3.1",
|
|
181
|
-
"posthog-js": "^1.
|
|
181
|
+
"posthog-js": "^1.157.2",
|
|
182
182
|
"pwa-install-handler": "^2.6.0",
|
|
183
|
-
"query-string": "^9.
|
|
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.
|
|
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.
|
|
198
|
+
"resolve-accept-language": "^3.1.5",
|
|
199
199
|
"rtl-detect": "^1.1.2",
|
|
200
|
-
"semver": "^7.6.
|
|
201
|
-
"sharp": "^0.33.
|
|
200
|
+
"semver": "^7.6.3",
|
|
201
|
+
"sharp": "^0.33.5",
|
|
202
202
|
"superjson": "^2.2.1",
|
|
203
|
-
"svix": "^1.
|
|
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.
|
|
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.
|
|
216
|
+
"yaml": "^2.5.0",
|
|
217
217
|
"yjs": "^13.6.18",
|
|
218
218
|
"zod": "^3.23.8",
|
|
219
|
-
"zustand": "^4.5.
|
|
219
|
+
"zustand": "^4.5.5",
|
|
220
220
|
"zustand-utils": "^1.3.2"
|
|
221
221
|
},
|
|
222
222
|
"devDependencies": {
|
|
223
|
-
"@commitlint/cli": "^19.
|
|
224
|
-
"@ducanh2912/next-pwa": "^10.2.
|
|
225
|
-
"@edge-runtime/vm": "^4.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.
|
|
228
|
-
"@lobehub/seo-cli": "^1.4.
|
|
229
|
-
"@next/bundle-analyzer": "^14.2.
|
|
230
|
-
"@next/eslint-plugin-next": "^14.2.
|
|
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.
|
|
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.
|
|
239
|
+
"@types/lodash": "^4.17.7",
|
|
240
240
|
"@types/lodash-es": "^4.17.12",
|
|
241
|
-
"@types/node": "^20.
|
|
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.
|
|
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.
|
|
251
|
+
"@types/ws": "^8.5.12",
|
|
252
252
|
"@vitest/coverage-v8": "~1.2.2",
|
|
253
253
|
"ajv-keywords": "^5.1.0",
|
|
254
|
-
"commitlint": "^19.
|
|
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.
|
|
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.
|
|
263
|
+
"glob": "^10.4.5",
|
|
264
264
|
"gray-matter": "^4.0.3",
|
|
265
265
|
"happy-dom": "^14.12.3",
|
|
266
|
-
"husky": "^9.
|
|
266
|
+
"husky": "^9.1.5",
|
|
267
267
|
"just-diff": "^6.0.2",
|
|
268
|
-
"lint-staged": "^15.2.
|
|
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.
|
|
272
|
+
"node-gyp": "^10.2.0",
|
|
273
273
|
"p-map": "^7.0.2",
|
|
274
|
-
"prettier": "^3.3.
|
|
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.
|
|
280
|
-
"typescript": "^5.5.
|
|
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.
|
|
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;
|
|
@@ -15,7 +15,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
15
15
|
import { useAddFilesToKnowledgeBaseModal } from '@/features/KnowledgeBaseModal';
|
|
16
16
|
import { useFileStore } from '@/store/file';
|
|
17
17
|
import { useKnowledgeBaseStore } from '@/store/knowledgeBase';
|
|
18
|
-
import { downloadFile } from '@/utils/downloadFile';
|
|
18
|
+
import { downloadFile } from '@/utils/client/downloadFile';
|
|
19
19
|
|
|
20
20
|
interface DropdownMenuProps {
|
|
21
21
|
filename: string;
|
|
@@ -5,7 +5,7 @@ import React, { ComponentType, useState } from 'react';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { Center, Flexbox } from 'react-layout-kit';
|
|
7
7
|
|
|
8
|
-
import { downloadFile } from '@/utils/downloadFile';
|
|
8
|
+
import { downloadFile } from '@/utils/client/downloadFile';
|
|
9
9
|
|
|
10
10
|
const useStyles = createStyles(({ css, token }) => ({
|
|
11
11
|
page: css`
|
|
@@ -66,7 +66,10 @@ export const fileRouter = router({
|
|
|
66
66
|
}),
|
|
67
67
|
)
|
|
68
68
|
.query(async ({ ctx, input }) => {
|
|
69
|
-
|
|
69
|
+
const item = await ctx.fileModel.findById(input.id);
|
|
70
|
+
if (!item) throw new TRPCError({ code: 'BAD_REQUEST', message: 'File not found' });
|
|
71
|
+
|
|
72
|
+
return { ...item, url: getFullFileUrl(item?.url) };
|
|
70
73
|
}),
|
|
71
74
|
|
|
72
75
|
getFileItemById: fileProcedure
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { fileEnv } from '@/config/file';
|
|
4
|
+
|
|
5
|
+
import { getFullFileUrl } from './files';
|
|
6
|
+
|
|
7
|
+
const config = {
|
|
8
|
+
S3_ENABLE_PATH_STYLE: false,
|
|
9
|
+
S3_PUBLIC_DOMAIN: 'https://example.com',
|
|
10
|
+
S3_BUCKET: 'my-bucket',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
vi.mock('@/config/file', () => ({
|
|
14
|
+
get fileEnv() {
|
|
15
|
+
return config;
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('getFullFileUrl', () => {
|
|
20
|
+
it('should return empty string for null or undefined input', () => {
|
|
21
|
+
expect(getFullFileUrl(null)).toBe('');
|
|
22
|
+
expect(getFullFileUrl(undefined)).toBe('');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return correct URL when S3_ENABLE_PATH_STYLE is false', () => {
|
|
26
|
+
const url = 'path/to/file.jpg';
|
|
27
|
+
expect(getFullFileUrl(url)).toBe('https://example.com/path/to/file.jpg');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return correct URL when S3_ENABLE_PATH_STYLE is true', () => {
|
|
31
|
+
config.S3_ENABLE_PATH_STYLE = true;
|
|
32
|
+
const url = 'path/to/file.jpg';
|
|
33
|
+
expect(getFullFileUrl(url)).toBe('https://example.com/my-bucket/path/to/file.jpg');
|
|
34
|
+
config.S3_ENABLE_PATH_STYLE = false;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -5,5 +5,9 @@ import { fileEnv } from '@/config/file';
|
|
|
5
5
|
export const getFullFileUrl = (url?: string | null) => {
|
|
6
6
|
if (!url) return '';
|
|
7
7
|
|
|
8
|
+
if (fileEnv.S3_ENABLE_PATH_STYLE) {
|
|
9
|
+
return urlJoin(fileEnv.S3_PUBLIC_DOMAIN!, fileEnv.S3_BUCKET!, url);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
return urlJoin(fileEnv.S3_PUBLIC_DOMAIN!, url);
|
|
9
13
|
};
|
|
@@ -180,48 +180,6 @@ describe('ChatService', () => {
|
|
|
180
180
|
);
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
-
it('should not include image content when default model', async () => {
|
|
184
|
-
const messages = [
|
|
185
|
-
{ content: 'Hello', role: 'user', files: ['file1'] }, // Message with files
|
|
186
|
-
{ content: 'Hi', role: 'tool', plugin: { identifier: 'plugin1', apiName: 'api1' } }, // Message with function role
|
|
187
|
-
{ content: 'Hey', role: 'assistant' }, // Regular user message
|
|
188
|
-
] as ChatMessage[];
|
|
189
|
-
|
|
190
|
-
// Mock file store state to return a specific image URL or Base64 for the given files
|
|
191
|
-
act(() => {
|
|
192
|
-
useFileStore.setState({
|
|
193
|
-
imagesMap: {
|
|
194
|
-
file1: {
|
|
195
|
-
id: 'file1',
|
|
196
|
-
name: 'abc.png',
|
|
197
|
-
saveMode: 'url',
|
|
198
|
-
fileType: 'image/png',
|
|
199
|
-
url: 'http://example.com/image.jpg',
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
206
|
-
await chatService.createAssistantMessage({
|
|
207
|
-
messages,
|
|
208
|
-
plugins: [],
|
|
209
|
-
model: 'gpt-3.5-turbo',
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
213
|
-
{
|
|
214
|
-
messages: [
|
|
215
|
-
{ content: 'Hello', role: 'user' },
|
|
216
|
-
{ content: 'Hi', name: 'plugin1____api1', role: 'tool' },
|
|
217
|
-
{ content: 'Hey', role: 'assistant' },
|
|
218
|
-
],
|
|
219
|
-
model: 'gpt-3.5-turbo',
|
|
220
|
-
},
|
|
221
|
-
undefined,
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
183
|
it('should not include image with vision models when can not find the image', async () => {
|
|
226
184
|
const messages = [
|
|
227
185
|
{ content: 'Hello', role: 'user', files: ['file2'] }, // Message with files
|
|
@@ -229,21 +187,6 @@ describe('ChatService', () => {
|
|
|
229
187
|
{ content: 'Hey', role: 'assistant' }, // Regular user message
|
|
230
188
|
] as ChatMessage[];
|
|
231
189
|
|
|
232
|
-
// Mock file store state to return a specific image URL or Base64 for the given files
|
|
233
|
-
act(() => {
|
|
234
|
-
useFileStore.setState({
|
|
235
|
-
imagesMap: {
|
|
236
|
-
file1: {
|
|
237
|
-
id: 'file1',
|
|
238
|
-
name: 'abc.png',
|
|
239
|
-
saveMode: 'url',
|
|
240
|
-
fileType: 'image/png',
|
|
241
|
-
url: 'http://example.com/image.jpg',
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
190
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
248
191
|
await chatService.createAssistantMessage({ messages, plugins: [] });
|
|
249
192
|
|
|
@@ -74,13 +74,15 @@ describe('FileService', () => {
|
|
|
74
74
|
describe('getFile', () => {
|
|
75
75
|
it('should retrieve and convert local file info to FilePreview', async () => {
|
|
76
76
|
const fileId = '1';
|
|
77
|
-
const fileData
|
|
77
|
+
const fileData = {
|
|
78
78
|
name: 'test',
|
|
79
79
|
data: new ArrayBuffer(1),
|
|
80
80
|
fileType: 'image/png',
|
|
81
81
|
saveMode: 'local',
|
|
82
82
|
size: 1,
|
|
83
|
-
|
|
83
|
+
createdAt: 1,
|
|
84
|
+
updatedAt: 2,
|
|
85
|
+
} as DB_File;
|
|
84
86
|
|
|
85
87
|
(FileModel.findById as Mock).mockResolvedValue(fileData);
|
|
86
88
|
(global.URL.createObjectURL as Mock).mockReturnValue('blob:test');
|
|
@@ -90,12 +92,13 @@ describe('FileService', () => {
|
|
|
90
92
|
|
|
91
93
|
expect(FileModel.findById).toHaveBeenCalledWith(fileId);
|
|
92
94
|
expect(result).toEqual({
|
|
95
|
+
createdAt: new Date(1),
|
|
93
96
|
id: '1',
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
size: 1,
|
|
98
|
+
type: 'image/png',
|
|
96
99
|
name: 'test',
|
|
97
|
-
saveMode: 'local',
|
|
98
100
|
url: 'blob:test',
|
|
101
|
+
updatedAt: new Date(2),
|
|
99
102
|
});
|
|
100
103
|
});
|
|
101
104
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileModel } from '@/database/client/models/file';
|
|
2
2
|
import { DB_File } from '@/database/client/schemas/files';
|
|
3
|
-
import {
|
|
3
|
+
import { FileItem } from '@/types/files';
|
|
4
4
|
|
|
5
5
|
import { IFileService } from './type';
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ export class ClientService implements IFileService {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
async getFile(id: string): Promise<
|
|
21
|
+
async getFile(id: string): Promise<FileItem> {
|
|
22
22
|
const item = await FileModel.findById(id);
|
|
23
23
|
if (!item) {
|
|
24
24
|
throw new Error('file not found');
|
|
@@ -26,14 +26,14 @@ export class ClientService implements IFileService {
|
|
|
26
26
|
|
|
27
27
|
// arrayBuffer to url
|
|
28
28
|
const url = URL.createObjectURL(new Blob([item.data!], { type: item.fileType }));
|
|
29
|
-
const base64 = Buffer.from(item.data!).toString('base64');
|
|
30
29
|
|
|
31
30
|
return {
|
|
32
|
-
|
|
33
|
-
fileType: item.fileType,
|
|
31
|
+
createdAt: new Date(item.createdAt),
|
|
34
32
|
id,
|
|
35
33
|
name: item.name,
|
|
36
|
-
|
|
34
|
+
size: item.size,
|
|
35
|
+
type: item.fileType,
|
|
36
|
+
updatedAt: new Date(item.updatedAt),
|
|
37
37
|
url,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import urlJoin from 'url-join';
|
|
2
|
-
|
|
3
|
-
import { fileEnv } from '@/config/file';
|
|
4
1
|
import { lambdaClient } from '@/libs/trpc/client';
|
|
5
2
|
import {
|
|
6
|
-
|
|
3
|
+
FileItem,
|
|
7
4
|
QueryFileListParams,
|
|
8
5
|
QueryFileListSchemaType,
|
|
9
6
|
UploadFileParams,
|
|
@@ -21,28 +18,14 @@ export class ServerService implements IFileService {
|
|
|
21
18
|
return lambdaClient.file.createFile.mutate({ ...params, knowledgeBaseId } as CreateFileParams);
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
* @deprecated
|
|
26
|
-
* @param id
|
|
27
|
-
*/
|
|
28
|
-
async getFile(id: string): Promise<FilePreview> {
|
|
29
|
-
if (!fileEnv.NEXT_PUBLIC_S3_DOMAIN) {
|
|
30
|
-
throw new Error('fileEnv.NEXT_PUBLIC_S3_DOMAIN is not set while enable server upload');
|
|
31
|
-
}
|
|
32
|
-
|
|
21
|
+
async getFile(id: string): Promise<FileItem> {
|
|
33
22
|
const item = await lambdaClient.file.findById.query({ id });
|
|
34
23
|
|
|
35
24
|
if (!item) {
|
|
36
25
|
throw new Error('file not found');
|
|
37
26
|
}
|
|
38
27
|
|
|
39
|
-
return {
|
|
40
|
-
fileType: item.fileType,
|
|
41
|
-
id: item.id,
|
|
42
|
-
name: item.name,
|
|
43
|
-
saveMode: 'url',
|
|
44
|
-
url: urlJoin(fileEnv.NEXT_PUBLIC_S3_DOMAIN!, item.url!),
|
|
45
|
-
};
|
|
28
|
+
return { ...item, type: item.fileType };
|
|
46
29
|
}
|
|
47
30
|
|
|
48
31
|
async removeFile(id: string) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileItem, UploadFileParams } from '@/types/files';
|
|
2
2
|
|
|
3
3
|
export interface IFileService {
|
|
4
4
|
createFile(
|
|
5
5
|
file: UploadFileParams,
|
|
6
6
|
knowledgeBaseId?: string,
|
|
7
7
|
): Promise<{ id: string; url: string }>;
|
|
8
|
-
getFile(id: string): Promise<
|
|
8
|
+
getFile(id: string): Promise<FileItem>;
|
|
9
9
|
removeAllFiles(): Promise<any>;
|
|
10
10
|
removeFile(id: string): Promise<any>;
|
|
11
11
|
removeFiles(ids: string[]): Promise<any>;
|
package/src/services/upload.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fileEnv } from '@/config/file';
|
|
2
2
|
import { FileModel } from '@/database/client/models/file';
|
|
3
3
|
import { edgeClient } from '@/libs/trpc/client';
|
|
4
|
+
import { API_ENDPOINTS } from '@/services/_url';
|
|
4
5
|
import { FileMetadata, UploadFileParams } from '@/types/files';
|
|
5
6
|
import { FileUploadState, FileUploadStatus } from '@/types/files/upload';
|
|
6
7
|
import { uuid } from '@/utils/uuid';
|
|
@@ -79,6 +80,19 @@ class UploadService {
|
|
|
79
80
|
};
|
|
80
81
|
};
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* get image File item with cors image URL
|
|
85
|
+
* @param url
|
|
86
|
+
* @param filename
|
|
87
|
+
* @param fileType
|
|
88
|
+
*/
|
|
89
|
+
getImageFileByUrlWithCORS = async (url: string, filename: string, fileType = 'image/png') => {
|
|
90
|
+
const res = await fetch(API_ENDPOINTS.proxy, { body: url, method: 'POST' });
|
|
91
|
+
const data = await res.arrayBuffer();
|
|
92
|
+
|
|
93
|
+
return new File([data], filename, { lastModified: Date.now(), type: fileType });
|
|
94
|
+
};
|
|
95
|
+
|
|
82
96
|
private getSignedUploadUrl = async (
|
|
83
97
|
file: File,
|
|
84
98
|
): Promise<
|
|
@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
|
|
4
4
|
import { fileService } from '@/services/file';
|
|
5
5
|
import { imageGenerationService } from '@/services/textToImage';
|
|
6
|
-
import {
|
|
6
|
+
import { uploadService } from '@/services/upload';
|
|
7
7
|
import { chatSelectors } from '@/store/chat/selectors';
|
|
8
8
|
import { ChatMessage } from '@/types/message';
|
|
9
9
|
import { DallEImageItem } from '@/types/tool/dalle';
|
|
@@ -36,7 +36,10 @@ describe('chatToolSlice', () => {
|
|
|
36
36
|
const mockId = 'image-id';
|
|
37
37
|
|
|
38
38
|
vi.spyOn(imageGenerationService, 'generateImage').mockResolvedValue(mockUrl);
|
|
39
|
-
vi.spyOn(uploadService, '
|
|
39
|
+
vi.spyOn(uploadService, 'getImageFileByUrlWithCORS').mockResolvedValue(
|
|
40
|
+
new File(['1'], 'file.png', { type: 'image/png' }),
|
|
41
|
+
);
|
|
42
|
+
vi.spyOn(uploadService, 'uploadToClientDB').mockResolvedValue({} as any);
|
|
40
43
|
vi.spyOn(fileService, 'createFile').mockResolvedValue({ id: mockId, url: '' });
|
|
41
44
|
vi.spyOn(result.current, 'toggleDallEImageLoading');
|
|
42
45
|
|
|
@@ -45,7 +48,7 @@ describe('chatToolSlice', () => {
|
|
|
45
48
|
});
|
|
46
49
|
// For each prompt, loading is toggled on and then off
|
|
47
50
|
expect(imageGenerationService.generateImage).toHaveBeenCalledTimes(prompts.length);
|
|
48
|
-
expect(uploadService.
|
|
51
|
+
expect(uploadService.uploadToClientDB).toHaveBeenCalledTimes(prompts.length);
|
|
49
52
|
|
|
50
53
|
expect(result.current.toggleDallEImageLoading).toHaveBeenCalledTimes(prompts.length * 2);
|
|
51
54
|
});
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
2
|
import pMap from 'p-map';
|
|
3
|
+
import { SWRResponse } from 'swr';
|
|
3
4
|
import { StateCreator } from 'zustand/vanilla';
|
|
4
5
|
|
|
6
|
+
import { useClientDataSWR } from '@/libs/swr';
|
|
5
7
|
import { fileService } from '@/services/file';
|
|
6
8
|
import { imageGenerationService } from '@/services/textToImage';
|
|
7
|
-
import {
|
|
9
|
+
import { uploadService } from '@/services/upload';
|
|
8
10
|
import { chatSelectors } from '@/store/chat/selectors';
|
|
9
11
|
import { ChatStore } from '@/store/chat/store';
|
|
12
|
+
import { useFileStore } from '@/store/file';
|
|
10
13
|
import { DallEImageItem } from '@/types/tool/dalle';
|
|
11
14
|
import { setNamespace } from '@/utils/storeDebug';
|
|
12
15
|
|
|
13
16
|
const n = setNamespace('tool');
|
|
14
17
|
|
|
18
|
+
const SWR_FETCH_KEY = 'FetchImageItem';
|
|
15
19
|
/**
|
|
16
20
|
* builtin tool action
|
|
17
21
|
*/
|
|
@@ -20,6 +24,7 @@ export interface ChatBuiltinToolAction {
|
|
|
20
24
|
text2image: (id: string, data: DallEImageItem[]) => Promise<void>;
|
|
21
25
|
toggleDallEImageLoading: (key: string, value: boolean) => void;
|
|
22
26
|
updateImageItem: (id: string, updater: (data: DallEImageItem[]) => void) => Promise<void>;
|
|
27
|
+
useFetchDalleImageItem: (id: string) => SWRResponse;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export const chatToolSlice: StateCreator<
|
|
@@ -60,20 +65,22 @@ export const chatToolSlice: StateCreator<
|
|
|
60
65
|
});
|
|
61
66
|
|
|
62
67
|
toggleDallEImageLoading(messageId + params.prompt, false);
|
|
68
|
+
const imageFile = await uploadService.getImageFileByUrlWithCORS(
|
|
69
|
+
url,
|
|
70
|
+
`${originPrompt || params.prompt}_${index}.png`,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const data = await useFileStore.getState().uploadWithProgress({
|
|
74
|
+
file: imageFile,
|
|
75
|
+
onStatusUpdate: () => {},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!data) return;
|
|
63
79
|
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
-
.then(async (res) => {
|
|
70
|
-
const data = await fileService.createFile(res);
|
|
71
|
-
|
|
72
|
-
updateImageItem(messageId, (draft) => {
|
|
73
|
-
draft[index].imageId = data.id;
|
|
74
|
-
draft[index].previewUrl = undefined;
|
|
75
|
-
});
|
|
76
|
-
});
|
|
80
|
+
await updateImageItem(messageId, (draft) => {
|
|
81
|
+
draft[index].imageId = data.id;
|
|
82
|
+
draft[index].previewUrl = undefined;
|
|
83
|
+
});
|
|
77
84
|
});
|
|
78
85
|
},
|
|
79
86
|
text2image: async (id, data) => {
|
|
@@ -98,4 +105,20 @@ export const chatToolSlice: StateCreator<
|
|
|
98
105
|
const nextContent = produce(data, updater);
|
|
99
106
|
await get().internal_updateMessageContent(id, JSON.stringify(nextContent));
|
|
100
107
|
},
|
|
108
|
+
useFetchDalleImageItem: (id) =>
|
|
109
|
+
useClientDataSWR([SWR_FETCH_KEY, id], async () => {
|
|
110
|
+
const item = await fileService.getFile(id);
|
|
111
|
+
|
|
112
|
+
set(
|
|
113
|
+
produce((draft) => {
|
|
114
|
+
if (draft.dalleImageMap[id]) return;
|
|
115
|
+
|
|
116
|
+
draft.dalleImageMap[id] = item;
|
|
117
|
+
}),
|
|
118
|
+
false,
|
|
119
|
+
n('useFetchFile'),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return item;
|
|
123
|
+
}),
|
|
101
124
|
});
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { FileItem } from '@/types/files';
|
|
2
|
+
|
|
1
3
|
export interface ChatToolState {
|
|
2
4
|
dalleImageLoading: Record<string, boolean>;
|
|
5
|
+
dalleImageMap: Record<string, FileItem>;
|
|
3
6
|
}
|
|
4
7
|
|
|
5
8
|
export const initialToolState: ChatToolState = {
|
|
6
9
|
dalleImageLoading: {},
|
|
10
|
+
dalleImageMap: {},
|
|
7
11
|
};
|
|
@@ -84,40 +84,6 @@ describe('useFileStore:chat', () => {
|
|
|
84
84
|
// expect(result.current.inputFilesList).toEqual([]);
|
|
85
85
|
// });
|
|
86
86
|
|
|
87
|
-
// Test for useFetchFile
|
|
88
|
-
it('useFetchFile should call useSWR and update the store', async () => {
|
|
89
|
-
const fileId = 'test-id';
|
|
90
|
-
const fileData = {
|
|
91
|
-
id: fileId,
|
|
92
|
-
name: 'test',
|
|
93
|
-
url: 'blob:test',
|
|
94
|
-
fileType: 'image/png',
|
|
95
|
-
base64Url: '',
|
|
96
|
-
saveMode: 'local',
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Mock the fileService.getFile to resolve with fileData
|
|
100
|
-
vi.spyOn(fileService, 'getFile').mockResolvedValue(fileData as any);
|
|
101
|
-
|
|
102
|
-
// Mock useSWR to call the fetcher function immediately
|
|
103
|
-
const useSWRMock = vi.mocked(useSWR);
|
|
104
|
-
useSWRMock.mockImplementation(((key: string, fetcher: any) => {
|
|
105
|
-
const data = fetcher(key);
|
|
106
|
-
return { data, error: undefined, isValidating: false, mutate: vi.fn() };
|
|
107
|
-
}) as any);
|
|
108
|
-
|
|
109
|
-
const { result } = renderHook(() => useStore().useFetchFile(fileId));
|
|
110
|
-
|
|
111
|
-
await act(async () => {
|
|
112
|
-
await result.current.data;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(fileService.getFile).toHaveBeenCalledWith(fileId);
|
|
116
|
-
|
|
117
|
-
// Since we are not rendering a component with the hook, we cannot test the state update here
|
|
118
|
-
// Instead, we would need to use a test renderer that can work with hooks, like @testing-library/react
|
|
119
|
-
});
|
|
120
|
-
|
|
121
87
|
// describe('uploadFile', () => {
|
|
122
88
|
// it('uploadFile should handle errors', async () => {
|
|
123
89
|
// const { result } = renderHook(() => useStore());
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { t } from 'i18next';
|
|
2
|
-
import { produce } from 'immer';
|
|
3
|
-
import useSWR, { SWRResponse } from 'swr';
|
|
4
2
|
import { StateCreator } from 'zustand/vanilla';
|
|
5
3
|
|
|
6
4
|
import { notification } from '@/components/AntdStaticMethods';
|
|
@@ -17,7 +15,7 @@ import {
|
|
|
17
15
|
} from '@/store/file/reducers/uploadFileList';
|
|
18
16
|
import { useUserStore } from '@/store/user';
|
|
19
17
|
import { preferenceSelectors } from '@/store/user/selectors';
|
|
20
|
-
import { FileListItem
|
|
18
|
+
import { FileListItem } from '@/types/files';
|
|
21
19
|
import { UploadFileItem } from '@/types/files/upload';
|
|
22
20
|
import { sleep } from '@/utils/sleep';
|
|
23
21
|
import { setNamespace } from '@/utils/storeDebug';
|
|
@@ -40,12 +38,6 @@ export interface FileAction {
|
|
|
40
38
|
) => Promise<void>;
|
|
41
39
|
|
|
42
40
|
uploadChatFiles: (files: File[]) => Promise<void>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* en: delete it after refactoring the Dalle plugin
|
|
46
|
-
* @deprecated
|
|
47
|
-
*/
|
|
48
|
-
useFetchFile: (id: string) => SWRResponse<FilePreview>;
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
export const createFileSlice: StateCreator<
|
|
@@ -211,21 +203,4 @@ export const createFileSlice: StateCreator<
|
|
|
211
203
|
|
|
212
204
|
await Promise.all(pools);
|
|
213
205
|
},
|
|
214
|
-
|
|
215
|
-
useFetchFile: (id) =>
|
|
216
|
-
useSWR(id, async (id) => {
|
|
217
|
-
const item = await fileService.getFile(id);
|
|
218
|
-
|
|
219
|
-
set(
|
|
220
|
-
produce((draft) => {
|
|
221
|
-
if (draft.imagesMap[id]) return;
|
|
222
|
-
|
|
223
|
-
draft.imagesMap[id] = item;
|
|
224
|
-
}),
|
|
225
|
-
false,
|
|
226
|
-
n('useFetchFile'),
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
return item;
|
|
230
|
-
}),
|
|
231
206
|
});
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { FilePreview } from '@/types/files';
|
|
2
1
|
import { UploadFileItem } from '@/types/files/upload';
|
|
3
2
|
|
|
4
3
|
export interface ImageFileState {
|
|
5
4
|
chatUploadFileList: UploadFileItem[];
|
|
6
|
-
/**
|
|
7
|
-
* it should be removed after dalle plugin refactor
|
|
8
|
-
* @deprecated
|
|
9
|
-
*/
|
|
10
|
-
imagesMap: Record<string, FilePreview>;
|
|
11
5
|
uploadingIds: string[];
|
|
12
6
|
}
|
|
13
7
|
|
|
14
8
|
export const initialImageFileState: ImageFileState = {
|
|
15
9
|
chatUploadFileList: [],
|
|
16
|
-
imagesMap: {},
|
|
17
10
|
uploadingIds: [],
|
|
18
11
|
};
|
|
@@ -3,7 +3,7 @@ import { StateCreator } from 'zustand/vanilla';
|
|
|
3
3
|
|
|
4
4
|
import { fileService } from '@/services/file';
|
|
5
5
|
import { legacyUploadService } from '@/services/upload_legacy';
|
|
6
|
-
import {
|
|
6
|
+
import { FileItem } from '@/types/files';
|
|
7
7
|
|
|
8
8
|
import { FileStore } from '../../store';
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ export interface TTSFileAction {
|
|
|
17
17
|
|
|
18
18
|
uploadTTSFile: (file: File) => Promise<string | undefined>;
|
|
19
19
|
|
|
20
|
-
useFetchTTSFile: (id: string | null) => SWRResponse<
|
|
20
|
+
useFetchTTSFile: (id: string | null) => SWRResponse<FileItem>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const createTTSFileSlice: StateCreator<
|
|
@@ -3,7 +3,7 @@ import { createStyles } from 'antd-style';
|
|
|
3
3
|
import { CSSProperties, memo } from 'react';
|
|
4
4
|
|
|
5
5
|
import { usePlatform } from '@/hooks/usePlatform';
|
|
6
|
-
import {
|
|
6
|
+
import { useChatStore } from '@/store/chat';
|
|
7
7
|
|
|
8
8
|
const MIN_IMAGE_SIZE = 64;
|
|
9
9
|
|
|
@@ -34,9 +34,9 @@ interface FileItemProps {
|
|
|
34
34
|
style?: CSSProperties;
|
|
35
35
|
}
|
|
36
36
|
const ImageFileItem = memo<FileItemProps>(({ editable, id, alwaysShowClose }) => {
|
|
37
|
-
const [
|
|
37
|
+
const [useFetchDalleImageItem] = useChatStore((s) => [s.useFetchDalleImageItem]);
|
|
38
38
|
const IMAGE_SIZE = editable ? MIN_IMAGE_SIZE : '100%';
|
|
39
|
-
const { data, isLoading } =
|
|
39
|
+
const { data, isLoading } = useFetchDalleImageItem(id);
|
|
40
40
|
const { styles, cx } = useStyles();
|
|
41
41
|
const { isSafari } = usePlatform();
|
|
42
42
|
|
|
@@ -56,7 +56,7 @@ const ImageItem = memo<DallEImageItem & { index: number; messageId: string }>(
|
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
if (imageId || previewUrl)
|
|
59
|
-
return <ImagePreview imageId={imageId} previewUrl={previewUrl}
|
|
59
|
+
return <ImagePreview imageId={imageId} previewUrl={previewUrl} prompt={prompt} />;
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
62
|
<Flexbox className={styles.container} padding={8}>
|
package/src/tools/renders.ts
CHANGED
|
@@ -5,10 +5,4 @@ import DalleRender from './dalle/Render';
|
|
|
5
5
|
|
|
6
6
|
export const BuiltinToolsRenders: Record<string, BuiltinRender> = {
|
|
7
7
|
[DalleManifest.identifier]: DalleRender as BuiltinRender,
|
|
8
|
-
/**
|
|
9
|
-
* 兼容旧版本 dalle3 的 identifier
|
|
10
|
-
* TODO: 后续数据库版本迁移时记得迁移 dalle3 对应的 identifier
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
dalle3: DalleRender as BuiltinRender,
|
|
14
8
|
};
|
package/src/types/files/index.ts
CHANGED
|
@@ -7,18 +7,6 @@ export enum FilesTabs {
|
|
|
7
7
|
Websites = 'websites',
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
export interface FilePreview {
|
|
14
|
-
base64Url?: string;
|
|
15
|
-
data?: ArrayBuffer;
|
|
16
|
-
fileType: string;
|
|
17
|
-
id: string;
|
|
18
|
-
name: string;
|
|
19
|
-
saveMode: 'local' | 'url';
|
|
20
|
-
url: string;
|
|
21
|
-
}
|
|
22
10
|
|
|
23
11
|
export interface FileItem {
|
|
24
12
|
createdAt: Date;
|
|
@@ -13,6 +13,7 @@ export const downloadFile = async (url: string, fileName: string) => {
|
|
|
13
13
|
link.remove();
|
|
14
14
|
window.URL.revokeObjectURL(blobUrl);
|
|
15
15
|
} catch (error) {
|
|
16
|
-
console.
|
|
16
|
+
console.log('Download failed:', error);
|
|
17
|
+
window.open(url);
|
|
17
18
|
}
|
|
18
19
|
};
|