@lobehub/chat 1.11.9 → 1.12.0
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 +25 -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/meta/0005_snapshot.json +2119 -0
- package/src/database/server/migrations/meta/0006_snapshot.json +3006 -0
- package/src/database/server/migrations/meta/_journal.json +14 -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 +47 -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 +51 -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
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const DRAGGING_ROOT_ID = 'dragging-root';
|
|
5
|
+
export const getContainer = () => document.querySelector(`#${DRAGGING_ROOT_ID}`);
|
|
6
|
+
|
|
7
|
+
const handleDragOver = (e: DragEvent) => {
|
|
8
|
+
if (!e.dataTransfer?.items || e.dataTransfer.items.length === 0) return;
|
|
9
|
+
|
|
10
|
+
const isFile = e.dataTransfer.types.includes('Files');
|
|
11
|
+
if (isFile) {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const processEntry = async (entry: FileSystemEntry): Promise<File[]> => {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
if (entry.isFile) {
|
|
19
|
+
(entry as FileSystemFileEntry).file((file) => {
|
|
20
|
+
resolve([file]);
|
|
21
|
+
});
|
|
22
|
+
} else if (entry.isDirectory) {
|
|
23
|
+
const dirReader = (entry as FileSystemDirectoryEntry).createReader();
|
|
24
|
+
dirReader.readEntries(async (entries) => {
|
|
25
|
+
const filesPromises = entries.map((element) => processEntry(element));
|
|
26
|
+
const fileArrays = await Promise.all(filesPromises);
|
|
27
|
+
resolve(fileArrays.flat());
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
resolve([]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const getFileListFromDataTransferItems = async (items: DataTransferItem[]) => {
|
|
36
|
+
// get filesList
|
|
37
|
+
const filePromises: Promise<File[]>[] = [];
|
|
38
|
+
for (const item of items) {
|
|
39
|
+
if (item.kind === 'file') {
|
|
40
|
+
const entry = item.webkitGetAsEntry();
|
|
41
|
+
if (entry) {
|
|
42
|
+
filePromises.push(processEntry(entry));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const fileArrays = await Promise.all(filePromises);
|
|
48
|
+
return fileArrays.flat();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const useDragUpload = (onUploadFiles: (files: File[]) => Promise<void>) => {
|
|
52
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
53
|
+
// When a file is dragged to a different area, the 'dragleave' event may be triggered,
|
|
54
|
+
// causing isDragging to be mistakenly set to false.
|
|
55
|
+
// to fix this issue, use a counter to ensure the status change only when drag event left the browser window .
|
|
56
|
+
const dragCounter = useRef(0);
|
|
57
|
+
|
|
58
|
+
const handleDragEnter = (e: DragEvent) => {
|
|
59
|
+
if (!e.dataTransfer?.items || e.dataTransfer.items.length === 0) return;
|
|
60
|
+
|
|
61
|
+
const isFile = e.dataTransfer.types.includes('Files');
|
|
62
|
+
if (isFile) {
|
|
63
|
+
dragCounter.current += 1;
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
setIsDragging(true);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const handleDragLeave = (e: DragEvent) => {
|
|
70
|
+
if (!e.dataTransfer?.items || e.dataTransfer.items.length === 0) return;
|
|
71
|
+
|
|
72
|
+
const isFile = e.dataTransfer.types.includes('Files');
|
|
73
|
+
if (isFile) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
|
|
76
|
+
// reset counter
|
|
77
|
+
dragCounter.current -= 1;
|
|
78
|
+
|
|
79
|
+
if (dragCounter.current === 0) {
|
|
80
|
+
setIsDragging(false);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleDrop = async (e: DragEvent) => {
|
|
86
|
+
if (!e.dataTransfer?.items || e.dataTransfer.items.length === 0) return;
|
|
87
|
+
|
|
88
|
+
const isFile = e.dataTransfer.types.includes('Files');
|
|
89
|
+
if (!isFile) return;
|
|
90
|
+
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
|
|
93
|
+
// reset counter
|
|
94
|
+
dragCounter.current = 0;
|
|
95
|
+
|
|
96
|
+
setIsDragging(false);
|
|
97
|
+
const items = Array.from(e.dataTransfer?.items);
|
|
98
|
+
|
|
99
|
+
const files = await getFileListFromDataTransferItems(items);
|
|
100
|
+
|
|
101
|
+
if (files.length === 0) return;
|
|
102
|
+
|
|
103
|
+
// upload files
|
|
104
|
+
onUploadFiles(files);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handlePaste = async (event: ClipboardEvent) => {
|
|
108
|
+
// get files from clipboard
|
|
109
|
+
if (!event.clipboardData) return;
|
|
110
|
+
const items = Array.from(event.clipboardData?.items);
|
|
111
|
+
|
|
112
|
+
const files = await getFileListFromDataTransferItems(items);
|
|
113
|
+
if (files.length === 0) return;
|
|
114
|
+
|
|
115
|
+
onUploadFiles(files);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (getContainer()) return;
|
|
120
|
+
const root = document.createElement('div');
|
|
121
|
+
root.id = DRAGGING_ROOT_ID;
|
|
122
|
+
document.body.append(root);
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
root.remove();
|
|
126
|
+
};
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
window.addEventListener('dragenter', handleDragEnter);
|
|
131
|
+
window.addEventListener('dragover', handleDragOver);
|
|
132
|
+
window.addEventListener('dragleave', handleDragLeave);
|
|
133
|
+
window.addEventListener('drop', handleDrop);
|
|
134
|
+
window.addEventListener('paste', handlePaste);
|
|
135
|
+
|
|
136
|
+
return () => {
|
|
137
|
+
window.removeEventListener('dragenter', handleDragEnter);
|
|
138
|
+
window.removeEventListener('dragover', handleDragOver);
|
|
139
|
+
window.removeEventListener('dragleave', handleDragLeave);
|
|
140
|
+
window.removeEventListener('drop', handleDrop);
|
|
141
|
+
window.removeEventListener('paste', handlePaste);
|
|
142
|
+
};
|
|
143
|
+
}, [handleDragEnter, handleDragOver, handleDragLeave, handleDrop, handlePaste]);
|
|
144
|
+
|
|
145
|
+
return isDragging;
|
|
146
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { LucideIcon } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { Center, Flexbox } from 'react-layout-kit';
|
|
6
|
+
|
|
7
|
+
const useStyles = createStyles(({ css, token, isDarkMode, responsive }) => ({
|
|
8
|
+
desc: css`
|
|
9
|
+
width: 280px;
|
|
10
|
+
margin-block-end: 0;
|
|
11
|
+
color: ${token.colorTextSecondary};
|
|
12
|
+
|
|
13
|
+
${responsive.mobile} {
|
|
14
|
+
line-height: ${token.lineHeight};
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
icon: css`
|
|
18
|
+
color: ${isDarkMode ? token.blue : token.geekblue};
|
|
19
|
+
`,
|
|
20
|
+
iconCtn: css`
|
|
21
|
+
width: 72px;
|
|
22
|
+
height: 72px;
|
|
23
|
+
background: ${isDarkMode ? token.blue1 : token.geekblue1};
|
|
24
|
+
border-radius: 50%;
|
|
25
|
+
`,
|
|
26
|
+
title: css`
|
|
27
|
+
margin-block-end: 0;
|
|
28
|
+
font-size: ${token.fontSizeLG}px;
|
|
29
|
+
font-weight: bold;
|
|
30
|
+
`,
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
export interface FeatureItem {
|
|
34
|
+
avatar: LucideIcon;
|
|
35
|
+
desc: string;
|
|
36
|
+
title: string;
|
|
37
|
+
}
|
|
38
|
+
interface FeatureListProps {
|
|
39
|
+
data: FeatureItem[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FeatureList = memo<FeatureListProps>(({ data }) => {
|
|
43
|
+
const { styles } = useStyles();
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Flexbox gap={32}>
|
|
47
|
+
{data.map((item) => {
|
|
48
|
+
return (
|
|
49
|
+
<Flexbox align={'flex-start'} gap={24} horizontal key={item.title}>
|
|
50
|
+
<Center className={styles.iconCtn}>
|
|
51
|
+
<Icon className={styles.icon} icon={item.avatar} size={{ fontSize: 36 }} />
|
|
52
|
+
</Center>
|
|
53
|
+
<Flexbox gap={8}>
|
|
54
|
+
<p className={styles.title}>{item.title}</p>
|
|
55
|
+
<p className={styles.desc}>{item.desc}</p>
|
|
56
|
+
</Flexbox>
|
|
57
|
+
</Flexbox>
|
|
58
|
+
);
|
|
59
|
+
})}
|
|
60
|
+
</Flexbox>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export default FeatureList;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Icon, Tooltip } from '@lobehub/ui';
|
|
2
|
+
import { Badge, Button, Tag } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import { BoltIcon, Loader2Icon, RotateCwIcon } from 'lucide-react';
|
|
5
|
+
import { darken, lighten } from 'polished';
|
|
6
|
+
import { memo } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
|
|
10
|
+
import { AsyncTaskStatus, FileParsingTask } from '@/types/asyncTask';
|
|
11
|
+
|
|
12
|
+
const useStyles = createStyles(({ css, token, isDarkMode }) => ({
|
|
13
|
+
errorReason: css`
|
|
14
|
+
padding: 4px;
|
|
15
|
+
|
|
16
|
+
font-family: monospace;
|
|
17
|
+
font-size: 12px;
|
|
18
|
+
|
|
19
|
+
background: ${isDarkMode ? darken(0.1, token.colorText) : lighten(0.1, token.colorText)};
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
`,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
interface FileParsingStatusProps extends FileParsingTask {
|
|
25
|
+
className?: string;
|
|
26
|
+
hideEmbeddingButton?: boolean;
|
|
27
|
+
onClick?: (status: AsyncTaskStatus) => void;
|
|
28
|
+
onEmbeddingClick?: () => void;
|
|
29
|
+
onErrorClick?: (task: 'chunking' | 'embedding') => void;
|
|
30
|
+
preparingEmbedding?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const FileParsingStatus = memo<FileParsingStatusProps>(
|
|
34
|
+
({
|
|
35
|
+
chunkingStatus,
|
|
36
|
+
onEmbeddingClick,
|
|
37
|
+
chunkingError,
|
|
38
|
+
finishEmbedding,
|
|
39
|
+
chunkCount,
|
|
40
|
+
embeddingStatus,
|
|
41
|
+
embeddingError,
|
|
42
|
+
onClick,
|
|
43
|
+
preparingEmbedding,
|
|
44
|
+
onErrorClick,
|
|
45
|
+
className,
|
|
46
|
+
hideEmbeddingButton,
|
|
47
|
+
}) => {
|
|
48
|
+
const { t } = useTranslation(['components', 'common']);
|
|
49
|
+
const { styles, cx } = useStyles();
|
|
50
|
+
|
|
51
|
+
switch (chunkingStatus) {
|
|
52
|
+
case AsyncTaskStatus.Processing: {
|
|
53
|
+
return (
|
|
54
|
+
<Tooltip
|
|
55
|
+
overlayStyle={{ pointerEvents: 'none' }}
|
|
56
|
+
title={t('FileParsingStatus.chunks.status.processingTip')}
|
|
57
|
+
>
|
|
58
|
+
<Tag
|
|
59
|
+
bordered={false}
|
|
60
|
+
className={className}
|
|
61
|
+
color={'processing'}
|
|
62
|
+
icon={<Badge status={'processing'} />}
|
|
63
|
+
style={{ display: 'flex', gap: 4 }}
|
|
64
|
+
>
|
|
65
|
+
{t('FileParsingStatus.chunks.status.processing')}
|
|
66
|
+
</Tag>
|
|
67
|
+
</Tooltip>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
case AsyncTaskStatus.Error: {
|
|
72
|
+
return (
|
|
73
|
+
<Tooltip
|
|
74
|
+
overlayStyle={{ maxWidth: 340, pointerEvents: 'none' }}
|
|
75
|
+
// style={{}}
|
|
76
|
+
title={
|
|
77
|
+
<Flexbox gap={4}>
|
|
78
|
+
{t('FileParsingStatus.chunks.status.errorResult')}
|
|
79
|
+
{chunkingError && (
|
|
80
|
+
<Flexbox className={styles.errorReason}>
|
|
81
|
+
[{chunkingError.name}]:{' '}
|
|
82
|
+
{chunkingError.body && typeof chunkingError.body !== 'string'
|
|
83
|
+
? chunkingError.body.detail
|
|
84
|
+
: chunkingError.body}
|
|
85
|
+
</Flexbox>
|
|
86
|
+
)}
|
|
87
|
+
</Flexbox>
|
|
88
|
+
}
|
|
89
|
+
>
|
|
90
|
+
<Tag bordered={false} className={className} color={'error'}>
|
|
91
|
+
{t('FileParsingStatus.chunks.status.error')}{' '}
|
|
92
|
+
<Icon
|
|
93
|
+
icon={RotateCwIcon}
|
|
94
|
+
onClick={() => {
|
|
95
|
+
onErrorClick?.('chunking');
|
|
96
|
+
}}
|
|
97
|
+
style={{ cursor: 'pointer' }}
|
|
98
|
+
title={t('retry', { ns: 'common' })}
|
|
99
|
+
/>
|
|
100
|
+
</Tag>
|
|
101
|
+
</Tooltip>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
case AsyncTaskStatus.Success: {
|
|
106
|
+
const isEmbeddingProcessing = embeddingStatus === AsyncTaskStatus.Processing;
|
|
107
|
+
|
|
108
|
+
switch (embeddingStatus) {
|
|
109
|
+
case AsyncTaskStatus.Processing: {
|
|
110
|
+
return (
|
|
111
|
+
<Flexbox horizontal>
|
|
112
|
+
<Tooltip
|
|
113
|
+
overlayStyle={{ pointerEvents: 'none' }}
|
|
114
|
+
title={t('FileParsingStatus.chunks.embeddingStatus.processing')}
|
|
115
|
+
>
|
|
116
|
+
<Tag
|
|
117
|
+
bordered={false}
|
|
118
|
+
className={cx('chunk-tag', className)}
|
|
119
|
+
color={'processing'}
|
|
120
|
+
icon={
|
|
121
|
+
preparingEmbedding ? (
|
|
122
|
+
<Icon icon={Loader2Icon} spin />
|
|
123
|
+
) : (
|
|
124
|
+
<Icon icon={BoltIcon} spin={isEmbeddingProcessing} />
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
style={{ cursor: 'pointer' }}
|
|
128
|
+
>
|
|
129
|
+
{chunkCount}
|
|
130
|
+
</Tag>
|
|
131
|
+
</Tooltip>
|
|
132
|
+
</Flexbox>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
case AsyncTaskStatus.Error: {
|
|
137
|
+
return (
|
|
138
|
+
<Tooltip
|
|
139
|
+
overlayStyle={{ maxWidth: 340, pointerEvents: 'none' }}
|
|
140
|
+
title={
|
|
141
|
+
<Flexbox gap={4}>
|
|
142
|
+
{t('FileParsingStatus.chunks.embeddingStatus.errorResult')}
|
|
143
|
+
{embeddingError && (
|
|
144
|
+
<Flexbox className={styles.errorReason}>
|
|
145
|
+
[{embeddingError.name}]:{' '}
|
|
146
|
+
{embeddingError.body && typeof embeddingError.body !== 'string'
|
|
147
|
+
? embeddingError.body.detail
|
|
148
|
+
: embeddingError.body}
|
|
149
|
+
</Flexbox>
|
|
150
|
+
)}
|
|
151
|
+
</Flexbox>
|
|
152
|
+
}
|
|
153
|
+
>
|
|
154
|
+
<Tag bordered={false} className={className} color={'error'}>
|
|
155
|
+
{t('FileParsingStatus.chunks.embeddingStatus.error')}{' '}
|
|
156
|
+
<Icon
|
|
157
|
+
icon={RotateCwIcon}
|
|
158
|
+
onClick={() => {
|
|
159
|
+
onErrorClick?.('embedding');
|
|
160
|
+
}}
|
|
161
|
+
style={{ cursor: 'pointer' }}
|
|
162
|
+
title={t('retry', { ns: 'common' })}
|
|
163
|
+
/>
|
|
164
|
+
</Tag>
|
|
165
|
+
</Tooltip>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Flexbox horizontal>
|
|
172
|
+
<Tooltip
|
|
173
|
+
overlayStyle={{ pointerEvents: 'none' }}
|
|
174
|
+
title={
|
|
175
|
+
finishEmbedding
|
|
176
|
+
? t('FileParsingStatus.chunks.embeddingStatus.success')
|
|
177
|
+
: t('FileParsingStatus.chunks.embeddingStatus.empty')
|
|
178
|
+
}
|
|
179
|
+
>
|
|
180
|
+
<Tag
|
|
181
|
+
bordered={false}
|
|
182
|
+
className={cx('chunk-tag', className)}
|
|
183
|
+
color={finishEmbedding ? 'purple' : undefined}
|
|
184
|
+
icon={
|
|
185
|
+
preparingEmbedding ? (
|
|
186
|
+
<Icon icon={Loader2Icon} spin />
|
|
187
|
+
) : (
|
|
188
|
+
<Icon icon={BoltIcon} spin={isEmbeddingProcessing} />
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
onClick={() => {
|
|
192
|
+
onClick?.(AsyncTaskStatus.Success);
|
|
193
|
+
}}
|
|
194
|
+
style={{ cursor: 'pointer' }}
|
|
195
|
+
>
|
|
196
|
+
{chunkCount}
|
|
197
|
+
{
|
|
198
|
+
// if want to hide button
|
|
199
|
+
hideEmbeddingButton ||
|
|
200
|
+
// or if finished the embedding
|
|
201
|
+
finishEmbedding ||
|
|
202
|
+
// or if preparing the embedding
|
|
203
|
+
preparingEmbedding ? null : (
|
|
204
|
+
<Button
|
|
205
|
+
onClick={(e) => {
|
|
206
|
+
e.stopPropagation();
|
|
207
|
+
onEmbeddingClick?.();
|
|
208
|
+
}}
|
|
209
|
+
style={{
|
|
210
|
+
fontSize: 12,
|
|
211
|
+
height: 'auto',
|
|
212
|
+
paddingBlock: 0,
|
|
213
|
+
paddingInline: '8px 0',
|
|
214
|
+
}}
|
|
215
|
+
type={'link'}
|
|
216
|
+
>
|
|
217
|
+
{t('FileParsingStatus.chunks.embeddings')}
|
|
218
|
+
</Button>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
</Tag>
|
|
222
|
+
</Tooltip>
|
|
223
|
+
</Flexbox>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
export default FileParsingStatus;
|
|
@@ -22,6 +22,14 @@ const useStyles = createStyles(({ css, token }) => ({
|
|
|
22
22
|
`,
|
|
23
23
|
image: css`
|
|
24
24
|
margin-block: 0 !important;
|
|
25
|
+
|
|
26
|
+
.ant-image {
|
|
27
|
+
height: 100% !important;
|
|
28
|
+
|
|
29
|
+
img {
|
|
30
|
+
height: 100% !important;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
`,
|
|
26
34
|
}));
|
|
27
35
|
|
|
@@ -37,7 +45,7 @@ interface FileItemProps {
|
|
|
37
45
|
url?: string;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
|
-
const
|
|
48
|
+
const FileItem = memo<FileItemProps>(
|
|
41
49
|
({ editable, alt, onRemove, url, loading, alwaysShowClose }) => {
|
|
42
50
|
const IMAGE_SIZE = editable ? MIN_IMAGE_SIZE : '100%';
|
|
43
51
|
const { styles, cx } = useStyles();
|
|
@@ -72,4 +80,4 @@ const ImageItem = memo<FileItemProps>(
|
|
|
72
80
|
},
|
|
73
81
|
);
|
|
74
82
|
|
|
75
|
-
export default
|
|
83
|
+
export default FileItem;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { Center } from 'react-layout-kit';
|
|
3
|
+
|
|
4
|
+
import FileIcon from '@/components/FileIcon';
|
|
5
|
+
import RepoIcon from '@/components/RepoIcon';
|
|
6
|
+
import { KnowledgeType } from '@/types/knowledgeBase';
|
|
7
|
+
|
|
8
|
+
interface KnowledgeIconProps {
|
|
9
|
+
fileType?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
size?: number | { file?: number; repo?: number };
|
|
12
|
+
type: KnowledgeType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const KnowledgeIcon = memo<KnowledgeIconProps>(({ type, size, fileType, name }) => {
|
|
16
|
+
const repoSize = (typeof size === 'object' ? size.repo : size) || 24;
|
|
17
|
+
const fileSize = (typeof size === 'object' ? size.file : size) || 24;
|
|
18
|
+
|
|
19
|
+
return type === KnowledgeType.KnowledgeBase ? (
|
|
20
|
+
<Center height={repoSize} width={repoSize}>
|
|
21
|
+
<RepoIcon size={repoSize / 1.2} />
|
|
22
|
+
</Center>
|
|
23
|
+
) : (
|
|
24
|
+
<FileIcon fileName={name} fileType={fileType!} size={fileSize} />
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export default KnowledgeIcon;
|
package/src/config/app.ts
CHANGED
|
@@ -13,6 +13,11 @@ declare global {
|
|
|
13
13
|
|
|
14
14
|
export const getAppConfig = () => {
|
|
15
15
|
const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];
|
|
16
|
+
const isInVercel = process.env.VERCEL === '1';
|
|
17
|
+
|
|
18
|
+
const vercelUrl = `https://${process.env.VERCEL_URL}`;
|
|
19
|
+
|
|
20
|
+
const APP_URL = process.env.APP_URL ? process.env.APP_URL : isInVercel ? vercelUrl : undefined;
|
|
16
21
|
|
|
17
22
|
return createEnv({
|
|
18
23
|
client: {
|
|
@@ -52,7 +57,7 @@ export const getAppConfig = () => {
|
|
|
52
57
|
: 'https://chat-plugins.lobehub.com',
|
|
53
58
|
|
|
54
59
|
PLUGIN_SETTINGS: process.env.PLUGIN_SETTINGS,
|
|
55
|
-
APP_URL
|
|
60
|
+
APP_URL,
|
|
56
61
|
},
|
|
57
62
|
});
|
|
58
63
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const FILE_UPLOAD_BLACKLIST = ['.DS_Store'];
|
package/src/const/url.ts
CHANGED
|
@@ -25,6 +25,7 @@ export const DOCUMENTS = urlJoin(OFFICIAL_SITE, '/docs');
|
|
|
25
25
|
export const USAGE_DOCUMENTS = urlJoin(DOCUMENTS, '/usage');
|
|
26
26
|
export const SELF_HOSTING_DOCUMENTS = urlJoin(DOCUMENTS, '/self-hosting');
|
|
27
27
|
export const WEBRTC_SYNC_DOCUMENTS = urlJoin(SELF_HOSTING_DOCUMENTS, '/advanced/webrtc');
|
|
28
|
+
export const DATABASE_SELF_HOSTING_URL = urlJoin(SELF_HOSTING_DOCUMENTS, '/server-database');
|
|
28
29
|
|
|
29
30
|
// use this for the link
|
|
30
31
|
export const DOCUMENTS_REFER_URL = `${DOCUMENTS}?utm_source=${UTM_SOURCE}`;
|
|
@@ -15,8 +15,14 @@ class _FileModel extends BaseModel<'files'> {
|
|
|
15
15
|
return this._addWithSync(file, `file-${id}`);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async findById(id: string): Promise<DBModel<DB_File
|
|
19
|
-
|
|
18
|
+
async findById(id: string): Promise<DBModel<DB_File> | undefined> {
|
|
19
|
+
const item = await this.table.get(id);
|
|
20
|
+
if (!item) return;
|
|
21
|
+
|
|
22
|
+
// arrayBuffer to url
|
|
23
|
+
const base64 = Buffer.from(item.data!).toString('base64');
|
|
24
|
+
|
|
25
|
+
return { ...item, url: `data:${item.fileType};base64,${base64}` };
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
async delete(id: string) {
|