@lobehub/chat 1.11.9 → 1.12.1
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/.github/workflows/release.yml +2 -1
- package/.github/workflows/test.yml +2 -1
- package/CHANGELOG.md +50 -0
- package/Dockerfile.database +2 -0
- package/docs/self-hosting/advanced/knowledge-base.zh-CN.mdx +65 -0
- package/locales/ar/chat.json +13 -3
- package/locales/ar/components.json +2 -0
- package/locales/bg-BG/chat.json +13 -3
- package/locales/bg-BG/components.json +2 -0
- package/locales/de-DE/chat.json +13 -3
- package/locales/de-DE/components.json +2 -0
- package/locales/en-US/chat.json +13 -3
- package/locales/en-US/components.json +2 -0
- package/locales/es-ES/chat.json +13 -3
- package/locales/es-ES/components.json +2 -0
- package/locales/fr-FR/chat.json +13 -3
- package/locales/fr-FR/components.json +2 -0
- package/locales/it-IT/chat.json +13 -3
- package/locales/it-IT/components.json +2 -0
- package/locales/ja-JP/chat.json +13 -3
- package/locales/ja-JP/components.json +2 -0
- package/locales/ko-KR/chat.json +13 -3
- package/locales/ko-KR/components.json +2 -0
- package/locales/nl-NL/chat.json +13 -3
- package/locales/nl-NL/components.json +2 -0
- package/locales/pl-PL/chat.json +13 -3
- package/locales/pl-PL/components.json +2 -0
- package/locales/pt-BR/chat.json +13 -3
- package/locales/pt-BR/components.json +2 -0
- package/locales/ru-RU/chat.json +13 -3
- package/locales/ru-RU/components.json +2 -0
- package/locales/tr-TR/chat.json +13 -3
- package/locales/tr-TR/components.json +2 -0
- package/locales/vi-VN/chat.json +13 -3
- package/locales/vi-VN/components.json +2 -0
- package/locales/zh-CN/chat.json +13 -3
- package/locales/zh-CN/components.json +2 -0
- package/locales/zh-TW/chat.json +13 -3
- package/locales/zh-TW/components.json +2 -0
- package/package.json +3 -2
- package/scripts/migrateServerDB/docker.cjs +6 -0
- package/scripts/migrateServerDB/errorHint.js +17 -0
- package/scripts/migrateServerDB/index.ts +6 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/FileItem/Content.tsx +37 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/FileItem/index.tsx +87 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/FileItem/style.ts +4 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/FileItem/utils.ts +28 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/FileList.tsx +41 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/FilePreview/index.tsx +40 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/SendMore.tsx +1 -1
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/index.tsx +7 -22
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/TextArea.tsx +1 -1
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/index.tsx +2 -4
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/FileItem/File.tsx +72 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/FileItem/Image.tsx +74 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/FileItem/index.tsx +39 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/FileItem/style.ts +1 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/index.tsx +33 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/InputArea/Container.tsx +41 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/InputArea/index.tsx +154 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Send.tsx +34 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/index.tsx +24 -11
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/components/UploadDetail/UploadStatus.tsx +71 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/components/UploadDetail/index.tsx +49 -0
- package/src/app/(main)/chat/(workspace)/@portal/FilePreview/index.tsx +26 -0
- package/src/app/(main)/chat/(workspace)/@portal/Home/Files/FileList/Item.tsx +53 -0
- package/src/app/(main)/chat/(workspace)/@portal/Home/Files/FileList/index.tsx +50 -0
- package/src/app/(main)/chat/(workspace)/@portal/Home/Files/index.tsx +21 -0
- package/src/app/(main)/chat/(workspace)/@portal/Home/index.tsx +2 -0
- package/src/app/(main)/chat/(workspace)/@portal/router.tsx +4 -0
- package/src/app/(main)/chat/(workspace)/_layout/Desktop/ChatHeader/KnowledgeTag.tsx +41 -0
- package/src/app/(main)/chat/(workspace)/_layout/Desktop/ChatHeader/Tags.tsx +7 -2
- package/src/app/(main)/chat/(workspace)/_layout/Desktop/HotKeys.tsx +1 -1
- package/src/app/(main)/files/(content)/@menu/default.tsx +27 -0
- package/src/app/(main)/files/(content)/@menu/features/FileMenu/index.tsx +97 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/EmptyStatus.tsx +53 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/Item/Content.tsx +175 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/Item/index.tsx +69 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/KnowledgeBaseList.tsx +30 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/SkeletonList.tsx +57 -0
- package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/index.tsx +54 -0
- package/src/app/(main)/files/(content)/@modal/(.)[id]/FileDetail.tsx +16 -0
- package/src/app/(main)/files/(content)/@modal/(.)[id]/FilePreview.tsx +15 -0
- package/src/app/(main)/files/(content)/@modal/(.)[id]/FullscreenModal.tsx +85 -0
- package/src/app/(main)/files/(content)/@modal/(.)[id]/page.tsx +19 -0
- package/src/app/(main)/files/(content)/@modal/default.tsx +3 -0
- package/src/app/(main)/files/(content)/NotSupportClient.tsx +152 -0
- package/src/app/(main)/files/(content)/_layout/Desktop/index.tsx +28 -0
- package/src/app/(main)/files/(content)/_layout/Mobile.tsx +47 -0
- package/src/app/(main)/files/(content)/_layout/type.ts +7 -0
- package/src/app/(main)/files/(content)/layout.tsx +18 -0
- package/src/app/(main)/files/(content)/page.tsx +14 -0
- package/src/app/(main)/files/[id]/Header.tsx +63 -0
- package/src/app/(main)/files/[id]/page.tsx +44 -0
- package/src/app/(main)/files/features/FileDetail.tsx +93 -0
- package/src/app/(main)/files/hooks/useFileCategory.ts +9 -0
- package/src/app/(main)/files/layout.tsx +12 -0
- package/src/app/(main)/files/loading.tsx +21 -0
- package/src/app/(main)/repos/[id]/@menu/Head/index.tsx +33 -0
- package/src/app/(main)/repos/[id]/@menu/Menu/index.tsx +56 -0
- package/src/app/(main)/repos/[id]/@menu/default.tsx +25 -0
- package/src/app/(main)/repos/[id]/_layout/Desktop/index.tsx +25 -0
- package/src/app/(main)/repos/[id]/_layout/Mobile.tsx +47 -0
- package/src/app/(main)/repos/[id]/_layout/type.ts +6 -0
- package/src/app/(main)/repos/[id]/hooks/useKnowledgeItem.ts +7 -0
- package/src/app/(main)/repos/[id]/layout.tsx +13 -0
- package/src/app/(main)/repos/[id]/page.tsx +18 -0
- package/src/app/(main)/repos/layout.tsx +13 -0
- package/src/app/(main)/repos/page.tsx +5 -0
- package/src/app/trpc/async/[trpc]/route.ts +28 -0
- package/src/chains/abstractChunk.ts +19 -0
- package/src/chains/answerWithContext.ts +34 -0
- package/src/chains/rewriteQuery.ts +22 -0
- package/src/components/DragUpload/index.tsx +6 -99
- package/src/components/DragUpload/useDragUpload.tsx +146 -0
- package/src/components/FeatureList/index.tsx +64 -0
- package/src/components/FileParsingStatus/index.tsx +230 -0
- package/src/components/ImageItem/index.tsx +10 -2
- package/src/components/KnowledgeIcon/index.tsx +28 -0
- package/src/config/app.ts +6 -1
- package/src/config/featureFlags/schema.ts +1 -1
- package/src/const/file.ts +1 -0
- package/src/const/url.ts +1 -0
- package/src/database/client/models/file.ts +8 -2
- package/src/database/server/migrations/0005_pgvector.sql +2 -0
- package/src/database/server/migrations/0006_add_knowledge_base.sql +307 -0
- package/src/database/server/migrations/0007_fix_embedding_table.sql +18 -0
- package/src/database/server/migrations/meta/0005_snapshot.json +2119 -0
- package/src/database/server/migrations/meta/0006_snapshot.json +3006 -0
- package/src/database/server/migrations/meta/0007_snapshot.json +3012 -0
- package/src/database/server/migrations/meta/_journal.json +21 -0
- package/src/database/server/models/__tests__/_test_template.ts +155 -0
- package/src/database/server/models/__tests__/agent.test.ts +226 -0
- package/src/database/server/models/__tests__/asyncTask.test.ts +176 -0
- package/src/database/server/models/__tests__/chunk.test.ts +336 -0
- package/src/database/server/models/__tests__/file.test.ts +317 -29
- package/src/database/server/models/__tests__/fixtures/embedding.ts +568 -0
- package/src/database/server/models/__tests__/knowledgeBase.test.ts +132 -0
- package/src/database/server/models/__tests__/message.test.ts +7 -4
- package/src/database/server/models/_template.ts +10 -1
- package/src/database/server/models/agent.ts +165 -0
- package/src/database/server/models/asyncTask.ts +96 -0
- package/src/database/server/models/chunk.ts +203 -0
- package/src/database/server/models/embedding.ts +50 -0
- package/src/database/server/models/file.ts +231 -12
- package/src/database/server/models/knowledgeBase.ts +94 -0
- package/src/database/server/models/message.ts +156 -30
- package/src/database/server/models/user.ts +12 -1
- package/src/database/server/schemas/lobechat/agent.ts +93 -0
- package/src/database/server/schemas/lobechat/discover.ts +1 -1
- package/src/database/server/schemas/lobechat/file.ts +118 -1
- package/src/database/server/schemas/lobechat/index.ts +5 -1
- package/src/database/server/schemas/lobechat/message.ts +169 -0
- package/src/database/server/schemas/lobechat/rag.ts +53 -0
- package/src/database/server/schemas/lobechat/relations.ts +68 -48
- package/src/database/server/schemas/lobechat/session.ts +77 -0
- package/src/database/server/schemas/lobechat/topic.ts +32 -0
- package/src/database/server/schemas/lobechat/user.ts +40 -25
- package/src/database/server/utils/idGenerator.ts +1 -0
- package/src/features/ChatInput/ActionBar/Clear.tsx +1 -1
- package/src/features/ChatInput/ActionBar/Knowledge/Dropdown.tsx +160 -0
- package/src/features/ChatInput/ActionBar/Knowledge/ListItem.tsx +52 -0
- package/src/features/ChatInput/ActionBar/Knowledge/index.tsx +54 -0
- package/src/features/ChatInput/ActionBar/Tools/index.tsx +1 -1
- package/src/features/ChatInput/ActionBar/Upload/ClientMode.tsx +52 -0
- package/src/features/ChatInput/ActionBar/Upload/ServerMode.tsx +104 -0
- package/src/features/ChatInput/ActionBar/Upload/index.tsx +8 -0
- package/src/features/ChatInput/ActionBar/config.ts +14 -5
- package/src/features/ChatInput/useSend.ts +16 -7
- package/src/features/Conversation/Messages/Assistant/FileChunks/Item/index.tsx +51 -0
- package/src/features/Conversation/Messages/Assistant/FileChunks/Item/style.ts +38 -0
- package/src/features/Conversation/Messages/Assistant/FileChunks/index.tsx +76 -0
- package/src/features/Conversation/Messages/Assistant/index.tsx +13 -4
- package/src/features/Conversation/Messages/Default.tsx +4 -0
- package/src/features/Conversation/Messages/User/BelowMessage.tsx +78 -0
- package/src/features/Conversation/Messages/User/FileListViewer/Item.tsx +53 -0
- package/src/features/Conversation/Messages/User/FileListViewer/index.tsx +21 -0
- package/src/{components/FileList/FileListViewer.tsx → features/Conversation/Messages/User/ImageFileListViewer.tsx} +10 -2
- package/src/features/Conversation/Messages/{User.tsx → User/index.tsx} +11 -2
- package/src/features/Conversation/Messages/index.ts +8 -3
- package/src/features/Conversation/components/ChatItem/index.tsx +33 -10
- package/src/features/Conversation/components/InboxWelcome/QuestionSuggest.tsx +1 -1
- package/src/features/Conversation/types/index.tsx +1 -0
- package/src/features/FileManager/ChunkDrawer/ChunkList/ChunkItem.tsx +61 -0
- package/src/features/FileManager/ChunkDrawer/ChunkList/index.tsx +42 -0
- package/src/features/FileManager/ChunkDrawer/Content.tsx +38 -0
- package/src/features/FileManager/ChunkDrawer/Loading/index.tsx +16 -0
- package/src/features/FileManager/ChunkDrawer/SimilaritySearchList/Item.tsx +62 -0
- package/src/features/FileManager/ChunkDrawer/SimilaritySearchList/index.tsx +31 -0
- package/src/features/FileManager/ChunkDrawer/index.tsx +48 -0
- package/src/features/FileManager/FileList/EmptyStatus.tsx +153 -0
- package/src/features/FileManager/FileList/FileListItem/ChunkTag.tsx +35 -0
- package/src/features/FileManager/FileList/FileListItem/DropdownMenu.tsx +150 -0
- package/src/features/FileManager/FileList/FileListItem/index.tsx +211 -0
- package/src/features/FileManager/FileList/FileSkeleton.tsx +25 -0
- package/src/features/FileManager/FileList/ToolBar/Config.tsx +28 -0
- package/src/features/FileManager/FileList/ToolBar/MultiSelectActions.tsx +152 -0
- package/src/features/FileManager/FileList/ToolBar/index.tsx +114 -0
- package/src/features/FileManager/FileList/index.tsx +143 -0
- package/src/features/FileManager/FileList/useCheckTaskStatus.ts +27 -0
- package/src/features/FileManager/Header/FilesSearchBar.tsx +41 -0
- package/src/features/FileManager/Header/UploadFileButton.tsx +79 -0
- package/src/features/FileManager/Header/index.tsx +39 -0
- package/src/features/FileManager/UploadDock/Item.tsx +124 -0
- package/src/features/FileManager/UploadDock/index.tsx +183 -0
- package/src/features/FileManager/index.tsx +38 -0
- package/src/features/FileSidePanel/index.tsx +79 -0
- package/src/features/FileViewer/NotSupport/index.tsx +54 -0
- package/src/features/FileViewer/PDFViewer/HighlightLayer.tsx +81 -0
- package/src/features/FileViewer/PDFViewer/index.tsx +93 -0
- package/src/features/FileViewer/PDFViewer/style.ts +20 -0
- package/src/features/FileViewer/PDFViewer/useResizeObserver.ts +33 -0
- package/src/features/FileViewer/TXTViewer/index.tsx +41 -0
- package/src/features/FileViewer/index.tsx +45 -0
- package/src/features/KnowledgeBaseModal/AddFilesToKnowledgeBase/SelectForm.tsx +115 -0
- package/src/features/KnowledgeBaseModal/AddFilesToKnowledgeBase/index.tsx +43 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/Item/Action.tsx +103 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/Item/EditCustomPlugin.tsx +55 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/Item/PluginTag.tsx +58 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/Item/index.tsx +70 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/List.tsx +49 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/Loading.tsx +13 -0
- package/src/features/KnowledgeBaseModal/AssignKnowledgeBase/index.tsx +39 -0
- package/src/features/KnowledgeBaseModal/CreateNew/CreateForm.tsx +73 -0
- package/src/features/KnowledgeBaseModal/CreateNew/index.tsx +35 -0
- package/src/features/KnowledgeBaseModal/index.ts +3 -0
- package/src/libs/langchain/loaders/pdf/index.ts +2 -2
- package/src/libs/trpc/async/asyncAuth.ts +24 -0
- package/src/libs/trpc/async/index.ts +10 -0
- package/src/libs/trpc/async/init.ts +11 -0
- package/src/libs/trpc/client/async.ts +14 -0
- package/src/libs/trpc/client/index.ts +1 -0
- package/src/libs/trpc/client/lambda.ts +9 -0
- package/src/libs/trpc/middleware/keyVaults.ts +18 -0
- package/src/libs/unstructured/__tests__/index.test.ts +0 -10
- package/src/libs/unstructured/index.ts +6 -11
- package/src/locales/default/chat.ts +47 -3
- package/src/locales/default/common.ts +1 -0
- package/src/locales/default/components.ts +2 -0
- package/src/locales/default/error.ts +6 -1
- package/src/locales/default/file.ts +92 -0
- package/src/locales/default/index.ts +4 -0
- package/src/locales/default/knowledgeBase.ts +31 -0
- package/src/locales/default/portal.ts +1 -0
- package/src/middleware.ts +3 -0
- package/src/server/asyncContext.ts +40 -0
- package/src/server/modules/ContentChunk/index.ts +135 -0
- package/src/server/modules/S3/index.ts +30 -5
- package/src/server/routers/async/caller.ts +27 -0
- package/src/server/routers/async/file.ts +247 -0
- package/src/server/routers/async/index.ts +12 -0
- package/src/server/routers/lambda/_template.ts +77 -0
- package/src/server/routers/lambda/agent.ts +159 -0
- package/src/server/routers/lambda/chunk.ts +189 -0
- package/src/server/routers/lambda/file.ts +129 -5
- package/src/server/routers/lambda/index.ts +6 -0
- package/src/server/routers/lambda/knowledgeBase.ts +79 -0
- package/src/server/routers/lambda/message.ts +6 -0
- package/src/server/routers/lambda/session.ts +0 -25
- package/src/server/routers/lambda/user.ts +5 -1
- package/src/server/services/chunk/index.ts +74 -0
- package/src/server/utils/files.ts +9 -0
- package/src/services/__tests__/chat.test.ts +18 -20
- package/src/services/__tests__/{upload.test.ts → upload_legacy.test.ts} +1 -1
- package/src/services/agent.ts +45 -0
- package/src/services/chat.ts +17 -15
- package/src/services/file/client.test.ts +1 -50
- package/src/services/file/client.ts +12 -25
- package/src/services/file/server.ts +25 -3
- package/src/services/file/type.ts +7 -4
- package/src/services/knowledgeBase.ts +34 -0
- package/src/services/message/client.test.ts +1 -1
- package/src/services/message/client.ts +29 -3
- package/src/services/message/index.ts +0 -2
- package/src/services/message/server.ts +9 -3
- package/src/services/message/type.ts +1 -13
- package/src/services/rag.ts +29 -0
- package/src/services/session/server.ts +1 -1
- package/src/services/upload.ts +89 -84
- package/src/services/upload_legacy.ts +104 -0
- package/src/services/user/client.ts +7 -2
- package/src/services/user/server.ts +6 -2
- package/src/services/user/type.ts +3 -2
- package/src/store/agent/slices/chat/action.ts +90 -18
- package/src/store/agent/slices/chat/initialState.ts +1 -0
- package/src/store/agent/slices/chat/selectors.ts +58 -0
- package/src/store/chat/slices/builtinTool/action.test.ts +2 -2
- package/src/store/chat/slices/builtinTool/action.ts +2 -2
- package/src/store/chat/slices/message/action.test.ts +2 -1
- package/src/store/chat/slices/message/action.ts +102 -26
- package/src/store/chat/slices/message/actions/rag.ts +148 -0
- package/src/store/chat/slices/message/initialState.ts +7 -0
- package/src/store/chat/slices/message/reducer.ts +6 -2
- package/src/store/chat/slices/message/selectors.ts +38 -3
- package/src/store/chat/slices/plugin/action.ts +8 -2
- package/src/store/chat/slices/portal/action.ts +8 -0
- package/src/store/chat/slices/portal/initialState.ts +3 -0
- package/src/store/chat/slices/portal/selectors.ts +8 -2
- package/src/store/file/initialState.ts +5 -1
- package/src/store/file/reducers/uploadFileList.ts +133 -0
- package/src/store/file/selectors.ts +3 -0
- package/src/store/file/slices/chat/action.test.ts +90 -90
- package/src/store/file/slices/chat/action.ts +164 -109
- package/src/store/file/slices/chat/initialState.ts +7 -2
- package/src/store/file/slices/chat/selectors.test.ts +84 -61
- package/src/store/file/slices/chat/selectors.ts +22 -32
- package/src/store/file/slices/chunk/action.ts +36 -0
- package/src/store/file/slices/chunk/index.ts +3 -0
- package/src/store/file/slices/chunk/initialState.ts +15 -0
- package/src/store/file/slices/chunk/selectors.ts +10 -0
- package/src/store/file/slices/fileManager/action.ts +187 -0
- package/src/store/file/slices/fileManager/index.ts +3 -0
- package/src/store/file/slices/fileManager/initialState.ts +18 -0
- package/src/store/file/slices/fileManager/selectors.ts +58 -0
- package/src/store/file/slices/tts/action.test.ts +1 -1
- package/src/store/file/slices/tts/action.ts +2 -2
- package/src/store/file/slices/upload/action.ts +164 -0
- package/src/store/file/store.ts +12 -1
- package/src/store/knowledgeBase/index.ts +2 -0
- package/src/store/knowledgeBase/initialState.ts +7 -0
- package/src/store/knowledgeBase/selectors.ts +1 -0
- package/src/store/knowledgeBase/slices/content/action.ts +27 -0
- package/src/store/knowledgeBase/slices/content/index.ts +1 -0
- package/src/store/knowledgeBase/slices/crud/action.ts +78 -0
- package/src/store/knowledgeBase/slices/crud/index.ts +3 -0
- package/src/store/knowledgeBase/slices/crud/initialState.ts +12 -0
- package/src/store/knowledgeBase/slices/crud/selectors.ts +7 -0
- package/src/store/knowledgeBase/store.ts +30 -0
- package/src/store/serverConfig/selectors.test.ts +1 -1
- package/src/store/user/slices/preference/selectors.ts +8 -0
- package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
- package/src/tools/dalle/Render/Item/ImageFileItem.tsx +3 -23
- package/src/types/agent/index.ts +9 -0
- package/src/types/asyncTask.ts +31 -0
- package/src/types/chunk/document.ts +9 -0
- package/src/types/chunk/index.ts +52 -0
- package/src/types/files/index.ts +35 -0
- package/src/types/files/list.ts +44 -0
- package/src/types/files/upload.ts +91 -0
- package/src/types/knowledgeBase/index.ts +45 -0
- package/src/types/message/index.ts +54 -5
- package/src/types/rag.ts +16 -0
- package/src/utils/filter.test.ts +2 -0
- package/src/utils/server/auth.ts +23 -0
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/LocalFiles.tsx +0 -46
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files.tsx +0 -19
- package/src/components/FileList/EditableFileList.tsx +0 -47
- package/src/components/FileList/index.ts +0 -2
- package/src/components/FileList/type.tsx +0 -7
- package/src/database/server/schemas/lobechat/chat.ts +0 -331
- package/src/features/ChatInput/ActionBar/FileUpload.tsx +0 -69
- package/src/features/ChatInput/useChatInput.ts +0 -45
- package/src/features/FileList/EditableFileList.tsx +0 -31
- package/src/features/FileList/FileListPreviewer.tsx +0 -17
- package/src/features/FileList/index.tsx +0 -2
- package/src/types/files.ts +0 -42
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { FilePreview } from '@/types/files';
|
|
2
|
+
import { UploadFileItem } from '@/types/files/upload';
|
|
2
3
|
|
|
3
4
|
export interface ImageFileState {
|
|
5
|
+
chatUploadFileList: UploadFileItem[];
|
|
6
|
+
/**
|
|
7
|
+
* it should be removed after dalle plugin refactor
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
4
10
|
imagesMap: Record<string, FilePreview>;
|
|
5
|
-
inputFilesList: string[];
|
|
6
11
|
uploadingIds: string[];
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
export const initialImageFileState: ImageFileState = {
|
|
15
|
+
chatUploadFileList: [],
|
|
10
16
|
imagesMap: {},
|
|
11
|
-
inputFilesList: [],
|
|
12
17
|
uploadingIds: [],
|
|
13
18
|
};
|
|
@@ -1,78 +1,101 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { FilesStoreState } from '
|
|
4
|
-
import {
|
|
3
|
+
import { FilesStoreState, initialState } from '@/store/file/initialState';
|
|
4
|
+
import { UPLOAD_STATUS_SET, UploadFileItem } from '@/types/files/upload';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
let state: FilesStoreState;
|
|
6
|
+
import { fileChatSelectors, filesSelectors } from './selectors';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
state
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
base64Url: 'base64string1',
|
|
19
|
-
url: 'blob:abc',
|
|
20
|
-
},
|
|
21
|
-
'2': {
|
|
22
|
-
id: '2',
|
|
23
|
-
name: 'b',
|
|
24
|
-
fileType: 'image/png',
|
|
25
|
-
saveMode: 'url',
|
|
26
|
-
base64Url: 'base64string2',
|
|
27
|
-
url: 'url2',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
uploadingIds: [],
|
|
31
|
-
// 假设 '3' 是不存在的 ID
|
|
32
|
-
inputFilesList: ['1', '2', '3'],
|
|
33
|
-
};
|
|
8
|
+
describe('filesSelectors', () => {
|
|
9
|
+
describe('chatUploadFileList', () => {
|
|
10
|
+
it('should return the chatUploadFileList from state', () => {
|
|
11
|
+
const state = {
|
|
12
|
+
...initialState,
|
|
13
|
+
chatUploadFileList: [{ id: '1' }] as UploadFileItem[],
|
|
14
|
+
} as FilesStoreState;
|
|
15
|
+
expect(filesSelectors.chatUploadFileList(state)).toEqual([{ id: '1' }]);
|
|
16
|
+
});
|
|
34
17
|
});
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
expect(details[1].name).toBe('b');
|
|
42
|
-
});
|
|
19
|
+
describe('isImageUploading', () => {
|
|
20
|
+
it('should return true if there are uploading ids', () => {
|
|
21
|
+
const state = { uploadingIds: ['1', '2'] } as FilesStoreState;
|
|
22
|
+
expect(filesSelectors.isImageUploading(state)).toBe(true);
|
|
23
|
+
});
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
25
|
+
it('should return false if there are no uploading ids', () => {
|
|
26
|
+
const state = { uploadingIds: [] as string[] } as FilesStoreState;
|
|
27
|
+
expect(filesSelectors.isImageUploading(state)).toBe(false);
|
|
28
|
+
});
|
|
48
29
|
});
|
|
30
|
+
});
|
|
49
31
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
describe('fileChatSelectors', () => {
|
|
33
|
+
describe('chatRawFileList', () => {
|
|
34
|
+
it('should return a list of raw files', () => {
|
|
35
|
+
const state = {
|
|
36
|
+
chatUploadFileList: [
|
|
37
|
+
{ file: { name: 'test1.jpg' } },
|
|
38
|
+
{ file: { name: 'test2.jpg' } },
|
|
39
|
+
] as UploadFileItem[],
|
|
40
|
+
} as FilesStoreState;
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
expect(fileChatSelectors.chatRawFileList(state)).toEqual([
|
|
43
|
+
{ name: 'test1.jpg' },
|
|
44
|
+
{ name: 'test2.jpg' },
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
describe('chatUploadFileList', () => {
|
|
50
|
+
it('should return the chatUploadFileList from state', () => {
|
|
51
|
+
const state = {
|
|
52
|
+
chatUploadFileList: [{ id: '1' }] as UploadFileItem[],
|
|
53
|
+
} as FilesStoreState;
|
|
54
|
+
expect(fileChatSelectors.chatUploadFileList(state)).toEqual([{ id: '1' }]);
|
|
55
|
+
});
|
|
59
56
|
});
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
describe('chatUploadFileListHasItem', () => {
|
|
59
|
+
it('should return true if chatUploadFileList has items', () => {
|
|
60
|
+
const state = { chatUploadFileList: [{ id: '1' }] as UploadFileItem[] } as FilesStoreState;
|
|
61
|
+
expect(fileChatSelectors.chatUploadFileListHasItem(state)).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should return false if chatUploadFileList is empty', () => {
|
|
65
|
+
const state = { chatUploadFileList: [] as UploadFileItem[] } as FilesStoreState;
|
|
66
|
+
expect(fileChatSelectors.chatUploadFileListHasItem(state)).toBe(false);
|
|
67
|
+
});
|
|
67
68
|
});
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
describe('isUploadingFiles', () => {
|
|
71
|
+
it('should return true if any file is in uploading status', () => {
|
|
72
|
+
const state = {
|
|
73
|
+
chatUploadFileList: [
|
|
74
|
+
{ status: Array.from(UPLOAD_STATUS_SET)[0] },
|
|
75
|
+
{ status: 'completed' },
|
|
76
|
+
] as UploadFileItem[],
|
|
77
|
+
} as FilesStoreState;
|
|
78
|
+
expect(fileChatSelectors.isUploadingFiles(state)).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should return true if any file has unfinished embedding tasks', () => {
|
|
82
|
+
const state = {
|
|
83
|
+
chatUploadFileList: [
|
|
84
|
+
{ status: 'success', tasks: { finishEmbedding: false } },
|
|
85
|
+
{ status: 'success', tasks: { finishEmbedding: true } },
|
|
86
|
+
] as UploadFileItem[],
|
|
87
|
+
} as FilesStoreState;
|
|
88
|
+
expect(fileChatSelectors.isUploadingFiles(state)).toBe(true);
|
|
89
|
+
});
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
it('should return false if no files are uploading or have unfinished tasks', () => {
|
|
92
|
+
const state: FilesStoreState = {
|
|
93
|
+
chatUploadFileList: [
|
|
94
|
+
{ status: 'success', tasks: { finishEmbedding: true } },
|
|
95
|
+
{ status: 'success' },
|
|
96
|
+
] as UploadFileItem[],
|
|
97
|
+
} as FilesStoreState;
|
|
98
|
+
expect(fileChatSelectors.isUploadingFiles(state)).toBe(false);
|
|
99
|
+
});
|
|
77
100
|
});
|
|
78
101
|
});
|
|
@@ -1,40 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const getImageDetailByList = (list: string[]) => (s: FilesStoreState) =>
|
|
4
|
-
list
|
|
5
|
-
.map((i) => s.imagesMap[i])
|
|
6
|
-
.filter(Boolean)
|
|
7
|
-
.map((i) => ({ ...i, loading: s.uploadingIds.includes(i.id) }));
|
|
8
|
-
|
|
9
|
-
const imageDetailList = (s: FilesStoreState) => getImageDetailByList(s.inputFilesList)(s);
|
|
10
|
-
|
|
11
|
-
const getImageUrlOrBase64ById =
|
|
12
|
-
(id: string) =>
|
|
13
|
-
(s: FilesStoreState): { id: string; url: string } | undefined => {
|
|
14
|
-
const preview = s.imagesMap[id];
|
|
15
|
-
|
|
16
|
-
if (!preview) return undefined;
|
|
17
|
-
|
|
18
|
-
const url = preview.saveMode === 'local' ? (preview.base64Url as string) : preview.url;
|
|
1
|
+
import { UPLOAD_STATUS_SET } from '@/types/files/upload';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
};
|
|
3
|
+
import { FilesStoreState } from '../../initialState';
|
|
22
4
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
id: string;
|
|
26
|
-
url: string;
|
|
27
|
-
}[];
|
|
5
|
+
const chatUploadFileList = (s: FilesStoreState) => s.chatUploadFileList;
|
|
6
|
+
const isImageUploading = (s: FilesStoreState) => s.uploadingIds.length > 0;
|
|
28
7
|
|
|
29
|
-
const
|
|
8
|
+
const chatRawFileList = (s: FilesStoreState) => s.chatUploadFileList.map((item) => item.file);
|
|
9
|
+
const chatUploadFileListHasItem = (s: FilesStoreState) => s.chatUploadFileList.length > 0;
|
|
30
10
|
|
|
31
|
-
const
|
|
11
|
+
const isUploadingFiles = (s: FilesStoreState) =>
|
|
12
|
+
s.chatUploadFileList.some(
|
|
13
|
+
(file) =>
|
|
14
|
+
// is file status in uploading
|
|
15
|
+
UPLOAD_STATUS_SET.has(file.status) ||
|
|
16
|
+
// or file has tasks but not finish embedding
|
|
17
|
+
(file.tasks && !file.tasks?.finishEmbedding),
|
|
18
|
+
);
|
|
32
19
|
|
|
33
20
|
export const filesSelectors = {
|
|
34
|
-
|
|
35
|
-
getImageUrlOrBase64ById,
|
|
36
|
-
getImageUrlOrBase64ByList,
|
|
37
|
-
imageDetailList,
|
|
38
|
-
imageUrlOrBase64List,
|
|
21
|
+
chatUploadFileList,
|
|
39
22
|
isImageUploading,
|
|
40
23
|
};
|
|
24
|
+
|
|
25
|
+
export const fileChatSelectors = {
|
|
26
|
+
chatRawFileList,
|
|
27
|
+
chatUploadFileList,
|
|
28
|
+
chatUploadFileListHasItem,
|
|
29
|
+
isUploadingFiles,
|
|
30
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
2
|
+
|
|
3
|
+
import { ragService } from '@/services/rag';
|
|
4
|
+
|
|
5
|
+
import { FileStore } from '../../store';
|
|
6
|
+
|
|
7
|
+
export interface FileChunkAction {
|
|
8
|
+
closeChunkDrawer: () => void;
|
|
9
|
+
highlightChunks: (ids: string[]) => void;
|
|
10
|
+
|
|
11
|
+
openChunkDrawer: (id: string) => void;
|
|
12
|
+
semanticSearch: (text: string, fileId: string) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const createFileChunkSlice: StateCreator<
|
|
16
|
+
FileStore,
|
|
17
|
+
[['zustand/devtools', never]],
|
|
18
|
+
[],
|
|
19
|
+
FileChunkAction
|
|
20
|
+
> = (set) => ({
|
|
21
|
+
closeChunkDrawer: () => {
|
|
22
|
+
set({ chunkDetailId: null, isSimilaritySearch: false, similaritySearchChunks: [] });
|
|
23
|
+
},
|
|
24
|
+
highlightChunks: (ids) => {
|
|
25
|
+
set({ highlightChunkIds: ids });
|
|
26
|
+
},
|
|
27
|
+
openChunkDrawer: (id) => {
|
|
28
|
+
set({ chunkDetailId: id });
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
semanticSearch: async (text, fileId) => {
|
|
32
|
+
set({ isSimilaritySearching: true });
|
|
33
|
+
const data = await ragService.semanticSearch(text, [fileId]);
|
|
34
|
+
set({ isSimilaritySearching: false, similaritySearchChunks: data });
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SemanticSearchChunk } from '@/types/chunk';
|
|
2
|
+
|
|
3
|
+
export interface FileChunkState {
|
|
4
|
+
chunkDetailId: string | null;
|
|
5
|
+
highlightChunkIds: string[];
|
|
6
|
+
isSimilaritySearch?: boolean;
|
|
7
|
+
isSimilaritySearching?: boolean;
|
|
8
|
+
similaritySearchChunks?: SemanticSearchChunk[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const initialFileChunkState: FileChunkState = {
|
|
12
|
+
chunkDetailId: null,
|
|
13
|
+
highlightChunkIds: [],
|
|
14
|
+
similaritySearchChunks: [],
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// import { FileStore } from '../../store';
|
|
2
|
+
import { FilesStoreState } from '@/store/file/initialState';
|
|
3
|
+
|
|
4
|
+
const showSimilaritySearchResult = (s: FilesStoreState) => s.isSimilaritySearch;
|
|
5
|
+
const enabledChunkFileId = (s: FilesStoreState) => s.chunkDetailId;
|
|
6
|
+
|
|
7
|
+
export const fileChunkSelectors = {
|
|
8
|
+
enabledChunkFileId,
|
|
9
|
+
showSimilaritySearchResult,
|
|
10
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { SWRResponse, mutate } from 'swr';
|
|
2
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
3
|
+
|
|
4
|
+
import { FILE_UPLOAD_BLACKLIST } from '@/const/file';
|
|
5
|
+
import { useClientDataSWR } from '@/libs/swr';
|
|
6
|
+
import { fileService } from '@/services/file';
|
|
7
|
+
import { ServerService } from '@/services/file/server';
|
|
8
|
+
import { ragService } from '@/services/rag';
|
|
9
|
+
import {
|
|
10
|
+
UploadFileListDispatch,
|
|
11
|
+
uploadFileListReducer,
|
|
12
|
+
} from '@/store/file/reducers/uploadFileList';
|
|
13
|
+
import { FileListItem, QueryFileListParams } from '@/types/files';
|
|
14
|
+
|
|
15
|
+
import { FileStore } from '../../store';
|
|
16
|
+
|
|
17
|
+
const serverFileService = new ServerService();
|
|
18
|
+
|
|
19
|
+
export interface FileManageAction {
|
|
20
|
+
dispatchDockFileList: (payload: UploadFileListDispatch) => void;
|
|
21
|
+
embeddingChunks: (fileIds: string[]) => Promise<void>;
|
|
22
|
+
parseFilesToChunks: (ids: string[], params?: { skipExist?: boolean }) => Promise<void>;
|
|
23
|
+
pushDockFileList: (files: File[], knowledgeBaseId?: string) => Promise<void>;
|
|
24
|
+
|
|
25
|
+
reParseFile: (id: string) => Promise<void>;
|
|
26
|
+
refreshFileList: () => Promise<void>;
|
|
27
|
+
removeAllFiles: () => Promise<void>;
|
|
28
|
+
removeFileItem: (id: string) => Promise<void>;
|
|
29
|
+
removeFiles: (ids: string[]) => Promise<void>;
|
|
30
|
+
|
|
31
|
+
toggleEmbeddingIds: (ids: string[], loading?: boolean) => void;
|
|
32
|
+
toggleParsingIds: (ids: string[], loading?: boolean) => void;
|
|
33
|
+
|
|
34
|
+
useFetchFileItem: (id?: string) => SWRResponse<FileListItem | undefined>;
|
|
35
|
+
useFetchFileManage: (params: QueryFileListParams) => SWRResponse<FileListItem[]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const FETCH_FILE_LIST_KEY = 'useFetchFileManage';
|
|
39
|
+
|
|
40
|
+
export const createFileManageSlice: StateCreator<
|
|
41
|
+
FileStore,
|
|
42
|
+
[['zustand/devtools', never]],
|
|
43
|
+
[],
|
|
44
|
+
FileManageAction
|
|
45
|
+
> = (set, get) => ({
|
|
46
|
+
dispatchDockFileList: (payload: UploadFileListDispatch) => {
|
|
47
|
+
const nextValue = uploadFileListReducer(get().dockUploadFileList, payload);
|
|
48
|
+
if (nextValue === get().dockUploadFileList) return;
|
|
49
|
+
|
|
50
|
+
set({ dockUploadFileList: nextValue }, false, `dispatchDockFileList/${payload.type}`);
|
|
51
|
+
},
|
|
52
|
+
embeddingChunks: async (fileIds: string[]) => {
|
|
53
|
+
// toggle file ids
|
|
54
|
+
get().toggleEmbeddingIds(fileIds);
|
|
55
|
+
|
|
56
|
+
// parse files
|
|
57
|
+
const pools = fileIds.map(async (id) => {
|
|
58
|
+
try {
|
|
59
|
+
await ragService.createEmbeddingChunksTask(id);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await Promise.all(pools);
|
|
66
|
+
await get().refreshFileList();
|
|
67
|
+
get().toggleEmbeddingIds(fileIds, false);
|
|
68
|
+
},
|
|
69
|
+
parseFilesToChunks: async (ids: string[], params) => {
|
|
70
|
+
// toggle file ids
|
|
71
|
+
get().toggleParsingIds(ids);
|
|
72
|
+
|
|
73
|
+
// parse files
|
|
74
|
+
const pools = ids.map(async (id) => {
|
|
75
|
+
try {
|
|
76
|
+
await ragService.createParseFileTask(id, params?.skipExist);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(e);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
await Promise.all(pools);
|
|
83
|
+
await get().refreshFileList();
|
|
84
|
+
get().toggleParsingIds(ids, false);
|
|
85
|
+
},
|
|
86
|
+
pushDockFileList: async (rawFiles, knowledgeBaseId) => {
|
|
87
|
+
const { dispatchDockFileList } = get();
|
|
88
|
+
|
|
89
|
+
// 0. skip file in blacklist
|
|
90
|
+
const files = rawFiles.filter((file) => !FILE_UPLOAD_BLACKLIST.includes(file.name));
|
|
91
|
+
|
|
92
|
+
// 1. add files
|
|
93
|
+
dispatchDockFileList({
|
|
94
|
+
atStart: true,
|
|
95
|
+
files: files.map((file) => ({ file, id: file.name, status: 'pending' })),
|
|
96
|
+
type: 'addFiles',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const pools = files.map(async (file) => {
|
|
100
|
+
await get().uploadWithProgress({
|
|
101
|
+
file,
|
|
102
|
+
knowledgeBaseId,
|
|
103
|
+
onStatusUpdate: dispatchDockFileList,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await get().refreshFileList();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await Promise.all(pools);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
reParseFile: async (id) => {
|
|
113
|
+
// toggle file ids
|
|
114
|
+
get().toggleParsingIds([id]);
|
|
115
|
+
|
|
116
|
+
await ragService.retryParseFile(id);
|
|
117
|
+
|
|
118
|
+
await get().refreshFileList();
|
|
119
|
+
|
|
120
|
+
get().toggleParsingIds([id], false);
|
|
121
|
+
},
|
|
122
|
+
refreshFileList: async () => {
|
|
123
|
+
await mutate([FETCH_FILE_LIST_KEY, get().queryListParams]);
|
|
124
|
+
},
|
|
125
|
+
removeAllFiles: async () => {
|
|
126
|
+
await fileService.removeAllFiles();
|
|
127
|
+
},
|
|
128
|
+
removeFileItem: async (id) => {
|
|
129
|
+
await fileService.removeFile(id);
|
|
130
|
+
await get().refreshFileList();
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
removeFiles: async (ids) => {
|
|
134
|
+
await fileService.removeFiles(ids);
|
|
135
|
+
await get().refreshFileList();
|
|
136
|
+
},
|
|
137
|
+
toggleEmbeddingIds: (ids, loading) => {
|
|
138
|
+
set((state) => {
|
|
139
|
+
const nextValue = new Set(state.creatingEmbeddingTaskIds);
|
|
140
|
+
|
|
141
|
+
ids.forEach((id) => {
|
|
142
|
+
if (typeof loading === 'undefined') {
|
|
143
|
+
if (nextValue.has(id)) nextValue.delete(id);
|
|
144
|
+
else nextValue.add(id);
|
|
145
|
+
} else {
|
|
146
|
+
if (loading) nextValue.add(id);
|
|
147
|
+
else nextValue.delete(id);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return { creatingEmbeddingTaskIds: Array.from(nextValue.values()) };
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
toggleParsingIds: (ids, loading) => {
|
|
155
|
+
set((state) => {
|
|
156
|
+
const nextValue = new Set(state.creatingChunkingTaskIds);
|
|
157
|
+
|
|
158
|
+
ids.forEach((id) => {
|
|
159
|
+
if (typeof loading === 'undefined') {
|
|
160
|
+
if (nextValue.has(id)) nextValue.delete(id);
|
|
161
|
+
else nextValue.add(id);
|
|
162
|
+
} else {
|
|
163
|
+
if (loading) nextValue.add(id);
|
|
164
|
+
else nextValue.delete(id);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return { creatingChunkingTaskIds: Array.from(nextValue.values()) };
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
useFetchFileItem: (id) =>
|
|
173
|
+
useClientDataSWR<FileListItem | undefined>(!id ? null : ['useFetchFileItem', id], () =>
|
|
174
|
+
serverFileService.getFileItem(id!),
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
useFetchFileManage: (params) =>
|
|
178
|
+
useClientDataSWR<FileListItem[]>(
|
|
179
|
+
[FETCH_FILE_LIST_KEY, params],
|
|
180
|
+
() => serverFileService.getFiles(params),
|
|
181
|
+
{
|
|
182
|
+
onSuccess: (data) => {
|
|
183
|
+
set({ fileList: data, queryListParams: params });
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
),
|
|
187
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FileListItem, QueryFileListParams } from '@/types/files';
|
|
2
|
+
import { UploadFileItem } from '@/types/files/upload';
|
|
3
|
+
|
|
4
|
+
export interface FileManagerState {
|
|
5
|
+
creatingChunkingTaskIds: string[];
|
|
6
|
+
creatingEmbeddingTaskIds: string[];
|
|
7
|
+
dockUploadFileList: UploadFileItem[];
|
|
8
|
+
fileDetail?: FileListItem;
|
|
9
|
+
fileList: FileListItem[];
|
|
10
|
+
queryListParams?: QueryFileListParams;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const initialFileManagerState: FileManagerState = {
|
|
14
|
+
creatingChunkingTaskIds: [],
|
|
15
|
+
creatingEmbeddingTaskIds: [],
|
|
16
|
+
dockUploadFileList: [],
|
|
17
|
+
fileList: [],
|
|
18
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// import { FileStore } from '../../store';
|
|
2
|
+
import { FilesStoreState } from '@/store/file/initialState';
|
|
3
|
+
import { FileUploadStatus } from '@/types/files/upload';
|
|
4
|
+
|
|
5
|
+
const uploadStatusArray = new Set(['uploading', 'pending', 'processing']);
|
|
6
|
+
|
|
7
|
+
const dockFileList = (s: FilesStoreState) => s.dockUploadFileList;
|
|
8
|
+
const dockRawFileList = (s: FilesStoreState) => s.dockUploadFileList.map((item) => item.file);
|
|
9
|
+
const getFileById = (id?: string | null) => (s: FilesStoreState) => {
|
|
10
|
+
if (!id) return;
|
|
11
|
+
|
|
12
|
+
return s.fileList.find((item) => item.id === id);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const isUploadingFiles = (s: FilesStoreState) =>
|
|
16
|
+
s.dockUploadFileList.some((file) => uploadStatusArray.has(file.status));
|
|
17
|
+
|
|
18
|
+
const overviewUploadingStatus = (s: FilesStoreState): FileUploadStatus => {
|
|
19
|
+
if (s.dockUploadFileList.length === 0) return 'pending';
|
|
20
|
+
if (s.dockUploadFileList.some((file) => uploadStatusArray.has(file.status))) {
|
|
21
|
+
return 'uploading';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return 'success';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const overviewUploadingProgress = (s: FilesStoreState) => {
|
|
28
|
+
const uploadFiles = s.dockUploadFileList.filter(
|
|
29
|
+
(file) => file.status === 'uploading' || file.status === 'pending',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (uploadFiles.length === 0) return 100;
|
|
33
|
+
|
|
34
|
+
const totalPercent = uploadFiles.length * 100;
|
|
35
|
+
const currentPercent = uploadFiles.reduce(
|
|
36
|
+
(acc, file) => acc + (file.uploadState?.progress || 0),
|
|
37
|
+
0,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return (currentPercent / totalPercent) * 100;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const isCreatingFileParseTask = (id: string) => (s: FilesStoreState) =>
|
|
44
|
+
s.creatingChunkingTaskIds.includes(id);
|
|
45
|
+
|
|
46
|
+
const isCreatingChunkEmbeddingTask = (id: string) => (s: FilesStoreState) =>
|
|
47
|
+
s.creatingEmbeddingTaskIds.includes(id);
|
|
48
|
+
|
|
49
|
+
export const fileManagerSelectors = {
|
|
50
|
+
dockFileList,
|
|
51
|
+
dockRawFileList,
|
|
52
|
+
getFileById,
|
|
53
|
+
isCreatingChunkEmbeddingTask,
|
|
54
|
+
isCreatingFileParseTask,
|
|
55
|
+
isUploadingFiles,
|
|
56
|
+
overviewUploadingProgress,
|
|
57
|
+
overviewUploadingStatus,
|
|
58
|
+
};
|
|
@@ -66,7 +66,7 @@ describe('TTSFileAction', () => {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
// Mock the fileService.uploadFile to resolve with uploadedFileData
|
|
69
|
-
vi.spyOn(fileService, 'createFile').mockResolvedValue(uploadedFileData);
|
|
69
|
+
vi.spyOn(fileService, 'createFile').mockResolvedValue({ id: uploadedFileData.id, url: '' });
|
|
70
70
|
|
|
71
71
|
let fileId;
|
|
72
72
|
await act(async () => {
|
|
@@ -2,7 +2,7 @@ import useSWR, { SWRResponse } from 'swr';
|
|
|
2
2
|
import { StateCreator } from 'zustand/vanilla';
|
|
3
3
|
|
|
4
4
|
import { fileService } from '@/services/file';
|
|
5
|
-
import {
|
|
5
|
+
import { legacyUploadService } from '@/services/upload_legacy';
|
|
6
6
|
import { FilePreview } from '@/types/files';
|
|
7
7
|
|
|
8
8
|
import { FileStore } from '../../store';
|
|
@@ -42,7 +42,7 @@ export const createTTSFileSlice: StateCreator<
|
|
|
42
42
|
},
|
|
43
43
|
uploadTTSFile: async (file) => {
|
|
44
44
|
try {
|
|
45
|
-
const res = await
|
|
45
|
+
const res = await legacyUploadService.uploadFile({
|
|
46
46
|
createdAt: file.lastModified,
|
|
47
47
|
data: await file.arrayBuffer(),
|
|
48
48
|
fileType: file.type,
|