@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,53 @@
|
|
|
1
|
+
import { Typography } from 'antd';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
import FileIcon from '@/components/FileIcon';
|
|
7
|
+
import { ChatFileItem } from '@/types/message';
|
|
8
|
+
import { formatSize } from '@/utils/format';
|
|
9
|
+
|
|
10
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
11
|
+
container: css`
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
|
|
16
|
+
max-width: 420px;
|
|
17
|
+
padding-block: 8px;
|
|
18
|
+
padding-inline: 12px;
|
|
19
|
+
|
|
20
|
+
background: ${token.colorFillTertiary};
|
|
21
|
+
border-radius: 8px;
|
|
22
|
+
|
|
23
|
+
&:hover {
|
|
24
|
+
background: ${token.colorFillSecondary};
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const ArtifactItem = memo<ChatFileItem>(({ name, fileType, size }) => {
|
|
30
|
+
const { styles } = useStyles();
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Flexbox
|
|
34
|
+
align={'center'}
|
|
35
|
+
className={styles.container}
|
|
36
|
+
gap={8}
|
|
37
|
+
horizontal
|
|
38
|
+
// onClick={() => {
|
|
39
|
+
// if (!isToolHasUI || !identifier) return;
|
|
40
|
+
//
|
|
41
|
+
// openToolUI(messageId, identifier);
|
|
42
|
+
// }}
|
|
43
|
+
>
|
|
44
|
+
<FileIcon fileName={name} fileType={fileType} />
|
|
45
|
+
<Flexbox>
|
|
46
|
+
<Typography.Text ellipsis={{ tooltip: true }}>{name}</Typography.Text>
|
|
47
|
+
<Typography.Text type={'secondary'}>{formatSize(size)}</Typography.Text>
|
|
48
|
+
</Flexbox>
|
|
49
|
+
</Flexbox>
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default ArtifactItem;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Avatar, Icon } from '@lobehub/ui';
|
|
2
|
+
import { Typography } from 'antd';
|
|
3
|
+
import { useTheme } from 'antd-style';
|
|
4
|
+
import isEqual from 'fast-deep-equal';
|
|
5
|
+
import { InboxIcon } from 'lucide-react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { Center, Flexbox } from 'react-layout-kit';
|
|
8
|
+
import Balancer from 'react-wrap-balancer';
|
|
9
|
+
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
11
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
12
|
+
|
|
13
|
+
import SkeletonLoading from '../../../components/SkeletonLoading';
|
|
14
|
+
import FileItem from './Item';
|
|
15
|
+
|
|
16
|
+
const FileList = () => {
|
|
17
|
+
const { t } = useTranslation('portal');
|
|
18
|
+
const files = useChatStore(chatSelectors.currentUserFiles, isEqual);
|
|
19
|
+
const theme = useTheme();
|
|
20
|
+
const isCurrentChatLoaded = useChatStore(chatSelectors.isCurrentChatLoaded);
|
|
21
|
+
|
|
22
|
+
return !isCurrentChatLoaded ? (
|
|
23
|
+
<Flexbox gap={12} paddingInline={12}>
|
|
24
|
+
<SkeletonLoading />
|
|
25
|
+
</Flexbox>
|
|
26
|
+
) : files.length === 0 ? (
|
|
27
|
+
<Center
|
|
28
|
+
gap={8}
|
|
29
|
+
paddingBlock={24}
|
|
30
|
+
style={{ border: `1px dashed ${theme.colorSplit}`, borderRadius: 8, marginInline: 12 }}
|
|
31
|
+
>
|
|
32
|
+
<Avatar
|
|
33
|
+
avatar={<Icon icon={InboxIcon} size={'large'} />}
|
|
34
|
+
background={theme.colorFillTertiary}
|
|
35
|
+
size={48}
|
|
36
|
+
/>
|
|
37
|
+
<Balancer>
|
|
38
|
+
<Typography.Text type={'secondary'}>{t('emptyArtifactList')}</Typography.Text>
|
|
39
|
+
</Balancer>
|
|
40
|
+
</Center>
|
|
41
|
+
) : (
|
|
42
|
+
<Flexbox gap={12} paddingInline={12}>
|
|
43
|
+
{files.map((m) => (
|
|
44
|
+
<FileItem {...m} key={m.id} />
|
|
45
|
+
))}
|
|
46
|
+
</Flexbox>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default FileList;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Typography } from 'antd';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
import FileList from './FileList';
|
|
7
|
+
|
|
8
|
+
export const Files = memo(() => {
|
|
9
|
+
const { t } = useTranslation('portal');
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Flexbox gap={8}>
|
|
13
|
+
<Typography.Title level={5} style={{ marginInline: 12 }}>
|
|
14
|
+
{t('files')}
|
|
15
|
+
</Typography.Title>
|
|
16
|
+
<FileList />
|
|
17
|
+
</Flexbox>
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default Files;
|
|
@@ -6,13 +6,17 @@ import { useChatStore } from '@/store/chat';
|
|
|
6
6
|
import { chatPortalSelectors } from '@/store/chat/selectors';
|
|
7
7
|
|
|
8
8
|
import Artifacts from './Artifacts';
|
|
9
|
+
import FilePreview from './FilePreview';
|
|
9
10
|
import Home from './Home';
|
|
10
11
|
|
|
11
12
|
const PortalView = memo(() => {
|
|
12
13
|
const showArtifactUI = useChatStore(chatPortalSelectors.showArtifactUI);
|
|
14
|
+
const showFilePreview = useChatStore(chatPortalSelectors.showFilePreview);
|
|
13
15
|
|
|
14
16
|
if (showArtifactUI) return <Artifacts />;
|
|
15
17
|
|
|
18
|
+
if (showFilePreview) return <FilePreview />;
|
|
19
|
+
|
|
16
20
|
return <Home />;
|
|
17
21
|
});
|
|
18
22
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Icon, Tag } from '@lobehub/ui';
|
|
4
|
+
import type { MenuProps } from 'antd';
|
|
5
|
+
import { Dropdown } from 'antd';
|
|
6
|
+
import { LibraryBig } from 'lucide-react';
|
|
7
|
+
import { memo } from 'react';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
|
|
10
|
+
import KnowledgeIcon from '@/components/KnowledgeIcon';
|
|
11
|
+
import { KnowledgeItem } from '@/types/knowledgeBase';
|
|
12
|
+
|
|
13
|
+
export interface PluginTagProps {
|
|
14
|
+
data: KnowledgeItem[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const PluginTag = memo<PluginTagProps>(({ data }) => {
|
|
18
|
+
if (data.length === 0) return null;
|
|
19
|
+
|
|
20
|
+
const items: MenuProps['items'] = data.map((item) => ({
|
|
21
|
+
icon: <KnowledgeIcon fileType={item.fileType} name={item.name} type={item.type} />,
|
|
22
|
+
key: item.id,
|
|
23
|
+
label: <Flexbox style={{ paddingInlineStart: 8 }}>{item.name}</Flexbox>,
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
const count = data.length;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Dropdown menu={{ items }}>
|
|
30
|
+
<div>
|
|
31
|
+
<Tag>
|
|
32
|
+
{<Icon icon={LibraryBig} />}
|
|
33
|
+
{data[0].name}
|
|
34
|
+
{count > 1 && <div>({data.length - 1}+)</div>}
|
|
35
|
+
</Tag>
|
|
36
|
+
</div>
|
|
37
|
+
</Dropdown>
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default PluginTag;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import isEqual from 'fast-deep-equal';
|
|
1
2
|
import { memo } from 'react';
|
|
2
3
|
import { Flexbox } from 'react-layout-kit';
|
|
3
4
|
|
|
@@ -9,12 +10,15 @@ import { useUserStore } from '@/store/user';
|
|
|
9
10
|
import { modelProviderSelectors } from '@/store/user/selectors';
|
|
10
11
|
|
|
11
12
|
import PluginTag from '../../../features/PluginTag';
|
|
13
|
+
import KnowledgeTag from './KnowledgeTag';
|
|
12
14
|
|
|
13
15
|
const TitleTags = memo(() => {
|
|
14
|
-
const [model,
|
|
16
|
+
const [model, hasKnowledge] = useAgentStore((s) => [
|
|
15
17
|
agentSelectors.currentAgentModel(s),
|
|
16
|
-
agentSelectors.
|
|
18
|
+
agentSelectors.hasKnowledge(s),
|
|
17
19
|
]);
|
|
20
|
+
const plugins = useAgentStore(agentSelectors.currentAgentPlugins, isEqual);
|
|
21
|
+
const enabledKnowledge = useAgentStore(agentSelectors.currentEnabledKnowledge, isEqual);
|
|
18
22
|
|
|
19
23
|
const showPlugin = useUserStore(modelProviderSelectors.isModelEnabledFunctionCall(model));
|
|
20
24
|
|
|
@@ -24,6 +28,7 @@ const TitleTags = memo(() => {
|
|
|
24
28
|
<ModelTag model={model} />
|
|
25
29
|
</ModelSwitchPanel>
|
|
26
30
|
{showPlugin && plugins?.length > 0 && <PluginTag plugins={plugins} />}
|
|
31
|
+
{hasKnowledge && <KnowledgeTag data={enabledKnowledge} />}
|
|
27
32
|
</Flexbox>
|
|
28
33
|
);
|
|
29
34
|
});
|
|
@@ -18,7 +18,7 @@ const HotKeys = () => {
|
|
|
18
18
|
]);
|
|
19
19
|
const lastMessage = useChatStore(chatSelectors.latestMessage, isEqual);
|
|
20
20
|
|
|
21
|
-
const [clearImageList] = useFileStore((s) => [s.
|
|
21
|
+
const [clearImageList] = useFileStore((s) => [s.clearChatUploadFileList]);
|
|
22
22
|
const clearHotkeys = [META_KEY, ALT_KEY, CLEAN_MESSAGE_KEY].join('+');
|
|
23
23
|
|
|
24
24
|
const resetConversation = useCallback(() => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
import PanelTitle from '@/components/PanelTitle';
|
|
7
|
+
|
|
8
|
+
import FileMenu from './features/FileMenu';
|
|
9
|
+
import KnowledgeBase from './features/KnowledgeBase';
|
|
10
|
+
|
|
11
|
+
const Menu = () => {
|
|
12
|
+
const { t } = useTranslation('file');
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Flexbox gap={16} height={'100%'}>
|
|
16
|
+
<Flexbox paddingInline={8}>
|
|
17
|
+
<PanelTitle desc={t('desc')} title={t('title')} />
|
|
18
|
+
<FileMenu />
|
|
19
|
+
</Flexbox>
|
|
20
|
+
<KnowledgeBase />
|
|
21
|
+
</Flexbox>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Menu.displayName = 'Menu';
|
|
26
|
+
|
|
27
|
+
export default Menu;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Icon } from '@lobehub/ui';
|
|
4
|
+
import { FileText, Globe, ImageIcon, LayoutGrid, Mic2, SquarePlay } from 'lucide-react';
|
|
5
|
+
import Link from 'next/link';
|
|
6
|
+
import { memo, useMemo } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
|
|
10
|
+
import { useFileCategory } from '@/app/(main)/files/hooks/useFileCategory';
|
|
11
|
+
import Menu from '@/components/Menu';
|
|
12
|
+
import type { MenuProps } from '@/components/Menu';
|
|
13
|
+
import { FilesTabs } from '@/types/files';
|
|
14
|
+
|
|
15
|
+
const FileMenu = memo(() => {
|
|
16
|
+
const { t } = useTranslation('file');
|
|
17
|
+
const [activeKey, setActiveKey] = useFileCategory();
|
|
18
|
+
|
|
19
|
+
const items: MenuProps['items'] = useMemo(
|
|
20
|
+
() =>
|
|
21
|
+
[
|
|
22
|
+
{
|
|
23
|
+
icon: <Icon icon={LayoutGrid} />,
|
|
24
|
+
key: FilesTabs.All,
|
|
25
|
+
label: (
|
|
26
|
+
<Link href={'/files'} onClick={(e) => e.preventDefault()}>
|
|
27
|
+
{t('tab.all')}
|
|
28
|
+
</Link>
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
icon: <Icon icon={FileText} />,
|
|
33
|
+
key: FilesTabs.Documents,
|
|
34
|
+
label: (
|
|
35
|
+
<Link href={'/files?category=documents'} onClick={(e) => e.preventDefault()}>
|
|
36
|
+
{t('tab.documents')}
|
|
37
|
+
</Link>
|
|
38
|
+
),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
icon: <Icon icon={ImageIcon} />,
|
|
42
|
+
key: FilesTabs.Images,
|
|
43
|
+
label: (
|
|
44
|
+
<Link href={'/files?category=images'} onClick={(e) => e.preventDefault()}>
|
|
45
|
+
{t('tab.images')}
|
|
46
|
+
</Link>
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
icon: <Icon icon={Mic2} />,
|
|
51
|
+
key: FilesTabs.Audios,
|
|
52
|
+
label: (
|
|
53
|
+
<Link href={'/files?category=audios'} onClick={(e) => e.preventDefault()}>
|
|
54
|
+
{t('tab.audios')}
|
|
55
|
+
</Link>
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
icon: <Icon icon={SquarePlay} />,
|
|
60
|
+
key: FilesTabs.Videos,
|
|
61
|
+
label: (
|
|
62
|
+
<Link href={'/files?category=videos'} onClick={(e) => e.preventDefault()}>
|
|
63
|
+
{t('tab.videos')}
|
|
64
|
+
</Link>
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
icon: <Icon icon={Globe} />,
|
|
69
|
+
key: FilesTabs.Websites,
|
|
70
|
+
label: (
|
|
71
|
+
<Link href={'/files?category=websites'} onClick={(e) => e.preventDefault()}>
|
|
72
|
+
{t('tab.websites')}
|
|
73
|
+
</Link>
|
|
74
|
+
),
|
|
75
|
+
},
|
|
76
|
+
]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.slice(0, 5) as MenuProps['items'],
|
|
79
|
+
[t],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Flexbox>
|
|
84
|
+
<Menu
|
|
85
|
+
items={items}
|
|
86
|
+
onClick={({ key }) => {
|
|
87
|
+
setActiveKey(key);
|
|
88
|
+
}}
|
|
89
|
+
selectable
|
|
90
|
+
selectedKeys={[activeKey]}
|
|
91
|
+
variant={'compact'}
|
|
92
|
+
/>
|
|
93
|
+
</Flexbox>
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export default FileMenu;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createStyles } from 'antd-style';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Trans } from 'react-i18next';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
7
|
+
container: css`
|
|
8
|
+
font-size: 12px;
|
|
9
|
+
color: ${token.colorTextTertiary};
|
|
10
|
+
`,
|
|
11
|
+
|
|
12
|
+
paragraph: css`
|
|
13
|
+
justify-content: center;
|
|
14
|
+
width: 100%;
|
|
15
|
+
|
|
16
|
+
kbd {
|
|
17
|
+
margin-inline: 2px;
|
|
18
|
+
padding-inline: 6px;
|
|
19
|
+
background: ${token.colorFillTertiary};
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
}
|
|
22
|
+
`,
|
|
23
|
+
}));
|
|
24
|
+
const EmptyStatus = () => {
|
|
25
|
+
const { styles } = useStyles();
|
|
26
|
+
return (
|
|
27
|
+
<Flexbox
|
|
28
|
+
align={'flex-end'}
|
|
29
|
+
className={styles.container}
|
|
30
|
+
gap={12}
|
|
31
|
+
paddingInline={20}
|
|
32
|
+
width={'100%'}
|
|
33
|
+
>
|
|
34
|
+
<svg
|
|
35
|
+
fill="currentColor"
|
|
36
|
+
fillRule="evenodd"
|
|
37
|
+
style={{ flex: 'none', height: 'fit-content', lineHeight: 1 }}
|
|
38
|
+
viewBox="0 0 126 64"
|
|
39
|
+
width={130}
|
|
40
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
41
|
+
>
|
|
42
|
+
<path d="M.5 63a.5.5 0 001 0h-1zM122 1l-2.887 5h5.774L122 1zM1.5 62.042a.5.5 0 10-1 0h1zm-1-1.917a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.916a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 101 0h-1zm1-1.916a.5.5 0 10-1 0h1zm-1-1.917a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.916a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 101 0h-1zm1.063-1.938a.5.5 0 10-.991-.13l.991.13zm-.418-2.274a.5.5 0 00.924.383l-.924-.383zm1.904-1.312a.5.5 0 10-.793-.609l.793.61zm.776-2.178a.5.5 0 00.61.793l-.61-.793zm2.304-.187a.5.5 0 00-.383-.924l.383.924zm1.761-1.497a.5.5 0 00.13.991l-.13-.991zm2.12.928a.5.5 0 100-1v1zm2.019-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 000-1v1zm2.018-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 100-1v1zm2.019-1a.5.5 0 100 1v-1zm2.019 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.018 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 100-1v1zm2.02-1a.5.5 0 100 1v-1zm2.018 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 100-1v1zm2.02-1a.5.5 0 100 1v-1zm2.018 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 100-1v1zm2.018-1a.5.5 0 100 1v-1zm2.02 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 100-1v1zm2.018-1a.5.5 0 100 1v-1zm2.02 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 000-1v1zm2.018-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 100-1v1zm2.019-1a.5.5 0 100 1v-1zm2.019 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 100 1v-1zm2.019 1a.5.5 0 100-1v1zm2.02-1a.5.5 0 100 1v-1zm2.018 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 000-1v1zm2.02-1a.5.5 0 100 1v-1zm2.018 1a.5.5 0 100-1v1zm2.02-1a.5.5 0 100 1v-1zm2.019 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.02 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.019 1a.5.5 0 000-1v1zm2.019-1a.5.5 0 000 1v-1zm2.12.928a.501.501 0 00-.13-.991l.13.991zm1.761-1.497a.501.501 0 00.383.924l-.383-.924zm2.304-.187a.5.5 0 00-.609-.793l.609.793zm.776-2.178a.5.5 0 10.793.609l-.793-.61zm1.904-1.312a.5.5 0 10-.924-.383l.924.383zm-.418-2.274a.5.5 0 10.991.13l-.991-.13zm1.063-1.938a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.916a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 001 0h-1zm1-1.916a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.916a.5.5 0 001 0h-1zm1-1.917a.5.5 0 00-1 0h1zm-1-1.917a.5.5 0 001 0h-1zM1.5 63v-.958h-1V63h1zm0-2.875v-1.917h-1v1.917h1zm0-3.833v-1.917h-1v1.917h1zm0-3.834v-1.916h-1v1.916h1zm0-3.833v-1.917h-1v1.917h1zm0-3.833v-1.917h-1v1.917h1zm0-3.834V40h-1v.958h1zm0-.958c0-.333.022-.66.063-.98l-.991-.13A8.574 8.574 0 00.5 40h1zm.569-2.87c.253-.61.584-1.18.98-1.696l-.793-.609a8.49 8.49 0 00-1.11 1.921l.923.383zm2.365-3.08a7.487 7.487 0 011.695-.981l-.383-.924a8.495 8.495 0 00-1.92 1.111l.608.793zm3.586-1.487c.32-.041.648-.063.98-.063v-1c-.376 0-.746.024-1.11.072l.13.991zM9 32.5h1.01v-1H9v1zm3.029 0h2.02v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.02v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.02v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.02v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.02v1zm4.038 0h2.019v-1h-2.019v1zm4.038 0h2.02v-1h-2.02v1zm4.039 0h2.019v-1h-2.019v1zm4.038 0H114v-1h-1.01v1zm1.01 0c.376 0 .746-.024 1.11-.072l-.13-.991c-.32.041-.648.063-.98.063v1zm3.254-.645a8.506 8.506 0 001.921-1.111l-.609-.793a7.519 7.519 0 01-1.695.98l.383.924zm3.49-2.68a8.516 8.516 0 001.111-1.921l-.924-.383a7.527 7.527 0 01-.98 1.695l.793.609zm1.684-4.066c.048-.363.072-.733.072-1.109h-1c0 .332-.022.66-.063.98l.991.13zM122.5 24v-.958h-1V24h1zm0-2.875v-1.917h-1v1.917h1zm0-3.833v-1.917h-1v1.917h1zm0-3.834v-1.916h-1v1.916h1zm0-3.833V7.708h-1v1.917h1zm0-3.833V3.875h-1v1.917h1z"></path>
|
|
43
|
+
</svg>
|
|
44
|
+
<Flexbox align={'center'} className={styles.paragraph} horizontal>
|
|
45
|
+
<Trans i18nKey={'knowledgeBase.list.empty'} ns={'file'}>
|
|
46
|
+
点击 <kbd>+</kbd> 开始创建知识库
|
|
47
|
+
</Trans>
|
|
48
|
+
</Flexbox>
|
|
49
|
+
</Flexbox>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default EmptyStatus;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ActionIcon, EditableText, Icon } from '@lobehub/ui';
|
|
2
|
+
import { App, Dropdown, type MenuProps, Typography } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import { LucideLoader2, MoreVertical, PencilLine, Trash } from 'lucide-react';
|
|
5
|
+
import { memo, useMemo } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { Center, Flexbox } from 'react-layout-kit';
|
|
8
|
+
|
|
9
|
+
import BubblesLoading from '@/components/BubblesLoading';
|
|
10
|
+
import RepoIcon from '@/components/RepoIcon';
|
|
11
|
+
import { LOADING_FLAT } from '@/const/message';
|
|
12
|
+
import { useKnowledgeBaseStore } from '@/store/knowledgeBase';
|
|
13
|
+
|
|
14
|
+
export const knowledgeItemClass = 'knowledge-base-item';
|
|
15
|
+
|
|
16
|
+
const useStyles = createStyles(({ css }) => ({
|
|
17
|
+
content: css`
|
|
18
|
+
position: relative;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
flex: 1;
|
|
21
|
+
`,
|
|
22
|
+
icon: css`
|
|
23
|
+
min-width: 24px;
|
|
24
|
+
border-radius: 4px;
|
|
25
|
+
`,
|
|
26
|
+
title: css`
|
|
27
|
+
flex: 1;
|
|
28
|
+
height: 28px;
|
|
29
|
+
line-height: 28px;
|
|
30
|
+
text-align: start;
|
|
31
|
+
`,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const { Paragraph } = Typography;
|
|
35
|
+
|
|
36
|
+
interface KnowledgeBaseItemProps {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
showMore: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Content = memo<KnowledgeBaseItemProps>(({ id, name, showMore }) => {
|
|
43
|
+
const { t } = useTranslation(['file', 'common']);
|
|
44
|
+
|
|
45
|
+
const [editing, updateKnowledgeBase, removeKnowledgeBase, isLoading] = useKnowledgeBaseStore(
|
|
46
|
+
(s) => [
|
|
47
|
+
s.knowledgeBaseRenamingId === id,
|
|
48
|
+
s.updateKnowledgeBase,
|
|
49
|
+
s.removeKnowledgeBase,
|
|
50
|
+
s.knowledgeBaseLoadingIds.includes(id),
|
|
51
|
+
],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const { styles } = useStyles();
|
|
55
|
+
|
|
56
|
+
const toggleEditing = (visible?: boolean) => {
|
|
57
|
+
useKnowledgeBaseStore.setState(
|
|
58
|
+
{ knowledgeBaseRenamingId: visible ? id : null },
|
|
59
|
+
false,
|
|
60
|
+
'toggleEditing',
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const { modal } = App.useApp();
|
|
65
|
+
|
|
66
|
+
const items = useMemo<MenuProps['items']>(
|
|
67
|
+
() => [
|
|
68
|
+
{
|
|
69
|
+
icon: <Icon icon={PencilLine} />,
|
|
70
|
+
key: 'rename',
|
|
71
|
+
label: t('rename', { ns: 'common' }),
|
|
72
|
+
onClick: () => {
|
|
73
|
+
toggleEditing(true);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'divider',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
danger: true,
|
|
81
|
+
icon: <Icon icon={Trash} />,
|
|
82
|
+
key: 'delete',
|
|
83
|
+
label: t('delete', { ns: 'common' }),
|
|
84
|
+
onClick: () => {
|
|
85
|
+
if (!id) return;
|
|
86
|
+
|
|
87
|
+
modal.confirm({
|
|
88
|
+
centered: true,
|
|
89
|
+
okButtonProps: { danger: true },
|
|
90
|
+
onOk: async () => {
|
|
91
|
+
await removeKnowledgeBase(id);
|
|
92
|
+
},
|
|
93
|
+
title: t('knowledgeBase.list.confirmRemoveKnowledgeBase'),
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
[],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Flexbox
|
|
103
|
+
align={'center'}
|
|
104
|
+
gap={8}
|
|
105
|
+
horizontal
|
|
106
|
+
justify={'space-between'}
|
|
107
|
+
onDoubleClick={(e) => {
|
|
108
|
+
if (!id) return;
|
|
109
|
+
if (e.altKey) toggleEditing(true);
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
<Center className={isLoading ? '' : styles.icon} height={24} width={24}>
|
|
113
|
+
{isLoading ? <Icon icon={LucideLoader2} spin /> : <RepoIcon />}
|
|
114
|
+
</Center>
|
|
115
|
+
{!editing ? (
|
|
116
|
+
name === LOADING_FLAT ? (
|
|
117
|
+
<Flexbox flex={1} height={28} justify={'center'}>
|
|
118
|
+
<BubblesLoading />
|
|
119
|
+
</Flexbox>
|
|
120
|
+
) : (
|
|
121
|
+
<Paragraph
|
|
122
|
+
className={styles.title}
|
|
123
|
+
ellipsis={{ rows: 1, tooltip: { placement: 'left', title: name } }}
|
|
124
|
+
style={{ margin: 0, opacity: isLoading ? 0.6 : undefined }}
|
|
125
|
+
>
|
|
126
|
+
{name}
|
|
127
|
+
</Paragraph>
|
|
128
|
+
)
|
|
129
|
+
) : (
|
|
130
|
+
<EditableText
|
|
131
|
+
editing={editing}
|
|
132
|
+
onChangeEnd={(v) => {
|
|
133
|
+
if (name !== v) {
|
|
134
|
+
updateKnowledgeBase(id, { name: v });
|
|
135
|
+
}
|
|
136
|
+
toggleEditing(false);
|
|
137
|
+
}}
|
|
138
|
+
onClick={(e) => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
}}
|
|
141
|
+
onEditingChange={toggleEditing}
|
|
142
|
+
showEditIcon={false}
|
|
143
|
+
size={'small'}
|
|
144
|
+
style={{ height: 28 }}
|
|
145
|
+
type={'pure'}
|
|
146
|
+
value={name}
|
|
147
|
+
/>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{showMore && !editing && (
|
|
151
|
+
<div
|
|
152
|
+
onClick={(e) => {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
<Dropdown
|
|
158
|
+
arrow={false}
|
|
159
|
+
menu={{
|
|
160
|
+
items: items,
|
|
161
|
+
onClick: ({ domEvent }) => {
|
|
162
|
+
domEvent.stopPropagation();
|
|
163
|
+
},
|
|
164
|
+
}}
|
|
165
|
+
trigger={['click']}
|
|
166
|
+
>
|
|
167
|
+
<ActionIcon className={knowledgeItemClass} icon={MoreVertical} size={'small'} />
|
|
168
|
+
</Dropdown>
|
|
169
|
+
</div>
|
|
170
|
+
)}
|
|
171
|
+
</Flexbox>
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
export default Content;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createStyles } from 'antd-style';
|
|
2
|
+
import Link from 'next/link';
|
|
3
|
+
import { memo, useState } from 'react';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
import Content, { knowledgeItemClass } from './Content';
|
|
7
|
+
|
|
8
|
+
const useStyles = createStyles(({ css, token, isDarkMode }) => ({
|
|
9
|
+
active: css`
|
|
10
|
+
background: ${isDarkMode ? token.colorFillSecondary : token.colorFillTertiary};
|
|
11
|
+
transition: background 200ms ${token.motionEaseOut};
|
|
12
|
+
|
|
13
|
+
&:hover {
|
|
14
|
+
background: ${token.colorFill};
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
container: css`
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
|
|
20
|
+
margin-inline: 8px;
|
|
21
|
+
padding-block: 4px;
|
|
22
|
+
padding-inline: 8px;
|
|
23
|
+
|
|
24
|
+
border-radius: ${token.borderRadius}px;
|
|
25
|
+
|
|
26
|
+
&.${knowledgeItemClass} {
|
|
27
|
+
width: calc(100% - 16px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
background: ${token.colorFillSecondary};
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
split: css`
|
|
35
|
+
border-block-end: 1px solid ${token.colorSplit};
|
|
36
|
+
`,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export interface KnowledgeBaseItemProps {
|
|
40
|
+
active?: boolean;
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const KnowledgeBaseItem = memo<KnowledgeBaseItemProps>(({ name, active, id }) => {
|
|
46
|
+
const { styles, cx } = useStyles();
|
|
47
|
+
const [isHover, setHovering] = useState(false);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Link href={`/repos/${id}`}>
|
|
51
|
+
<Flexbox
|
|
52
|
+
align={'center'}
|
|
53
|
+
className={cx(styles.container, knowledgeItemClass, active && styles.active)}
|
|
54
|
+
distribution={'space-between'}
|
|
55
|
+
horizontal
|
|
56
|
+
onMouseEnter={() => {
|
|
57
|
+
setHovering(true);
|
|
58
|
+
}}
|
|
59
|
+
onMouseLeave={() => {
|
|
60
|
+
setHovering(false);
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<Content id={id} name={name} showMore={isHover} />
|
|
64
|
+
</Flexbox>
|
|
65
|
+
</Link>
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export default KnowledgeBaseItem;
|