@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
package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/TextArea.tsx
CHANGED
|
@@ -51,7 +51,7 @@ const InputArea = memo<InputAreaProps>(({ setExpand }) => {
|
|
|
51
51
|
|
|
52
52
|
const useCmdEnterToSend = useUserStore(preferenceSelectors.useCmdEnterToSend);
|
|
53
53
|
|
|
54
|
-
const sendMessage = useSendMessage();
|
|
54
|
+
const { send: sendMessage } = useSendMessage();
|
|
55
55
|
|
|
56
56
|
useAutoFocus(ref);
|
|
57
57
|
|
|
@@ -9,13 +9,12 @@ import {
|
|
|
9
9
|
CHAT_TEXTAREA_MAX_HEIGHT,
|
|
10
10
|
HEADER_HEIGHT,
|
|
11
11
|
} from '@/const/layoutTokens';
|
|
12
|
-
import { useFileStore } from '@/store/file';
|
|
13
12
|
import { useGlobalStore } from '@/store/global';
|
|
14
13
|
import { systemStatusSelectors } from '@/store/global/selectors';
|
|
15
14
|
|
|
15
|
+
import LocalFiles from './FilePreview';
|
|
16
16
|
import Footer from './Footer';
|
|
17
17
|
import Head from './Header';
|
|
18
|
-
import LocalFiles from './LocalFiles';
|
|
19
18
|
import TextArea from './TextArea';
|
|
20
19
|
|
|
21
20
|
const DesktopChatInput = memo(() => {
|
|
@@ -25,11 +24,10 @@ const DesktopChatInput = memo(() => {
|
|
|
25
24
|
systemStatusSelectors.inputHeight(s),
|
|
26
25
|
s.updateSystemStatus,
|
|
27
26
|
]);
|
|
28
|
-
const showFileList = useFileStore((s) => s.inputFilesList.length > 0);
|
|
29
27
|
|
|
30
28
|
return (
|
|
31
29
|
<>
|
|
32
|
-
{!expand && <LocalFiles
|
|
30
|
+
{!expand && <LocalFiles />}
|
|
33
31
|
<DraggablePanel
|
|
34
32
|
fullscreen={expand}
|
|
35
33
|
headerHeight={HEADER_HEIGHT}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
2
|
+
import { Typography } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import { Trash } from 'lucide-react';
|
|
5
|
+
import { memo } from 'react';
|
|
6
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
import FileIcon from '@/components/FileIcon';
|
|
9
|
+
import { UploadFileItem } from '@/types/files';
|
|
10
|
+
|
|
11
|
+
import UploadDetail from '../../../components/UploadDetail';
|
|
12
|
+
|
|
13
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
14
|
+
container: css`
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
|
|
17
|
+
position: relative;
|
|
18
|
+
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
|
|
21
|
+
width: 250px;
|
|
22
|
+
height: 64px;
|
|
23
|
+
padding-block: 4px;
|
|
24
|
+
padding-inline: 8px 24px;
|
|
25
|
+
|
|
26
|
+
background: ${token.colorFillTertiary};
|
|
27
|
+
border: 1px solid ${token.colorBorder};
|
|
28
|
+
border-radius: 8px;
|
|
29
|
+
`,
|
|
30
|
+
deleteButton: css`
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset-block-start: 0;
|
|
33
|
+
inset-inline-end: 0;
|
|
34
|
+
|
|
35
|
+
color: #fff;
|
|
36
|
+
|
|
37
|
+
background: ${token.colorBgMask};
|
|
38
|
+
|
|
39
|
+
&:hover {
|
|
40
|
+
background: ${token.colorError};
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
interface FileItemProps extends UploadFileItem {
|
|
46
|
+
onRemove?: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const FileItem = memo<FileItemProps>(({ id, onRemove, file, status, uploadState, tasks }) => {
|
|
50
|
+
const { styles } = useStyles();
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Flexbox align={'center'} className={styles.container} gap={12} horizontal key={id}>
|
|
54
|
+
<FileIcon fileName={file.name} fileType={file.type} />
|
|
55
|
+
<Flexbox style={{ overflow: 'hidden' }}>
|
|
56
|
+
<Typography.Text ellipsis={{ tooltip: false }}>{file.name}</Typography.Text>
|
|
57
|
+
<UploadDetail size={file.size} status={status} tasks={tasks} uploadState={uploadState} />
|
|
58
|
+
</Flexbox>
|
|
59
|
+
<ActionIcon
|
|
60
|
+
className={styles.deleteButton}
|
|
61
|
+
glass
|
|
62
|
+
icon={Trash}
|
|
63
|
+
onClick={(e) => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
onRemove?.();
|
|
66
|
+
}}
|
|
67
|
+
size={'small'}
|
|
68
|
+
/>
|
|
69
|
+
</Flexbox>
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
export default FileItem;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ActionIcon, Image } from '@lobehub/ui';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { Trash } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
import { usePlatform } from '@/hooks/usePlatform';
|
|
7
|
+
|
|
8
|
+
import { MIN_IMAGE_SIZE } from './style';
|
|
9
|
+
|
|
10
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
11
|
+
deleteButton: css`
|
|
12
|
+
color: #fff;
|
|
13
|
+
background: ${token.colorBgMask};
|
|
14
|
+
|
|
15
|
+
&:hover {
|
|
16
|
+
background: ${token.colorError};
|
|
17
|
+
}
|
|
18
|
+
`,
|
|
19
|
+
editableImage: css`
|
|
20
|
+
background: ${token.colorBgContainer};
|
|
21
|
+
box-shadow: 0 0 0 1px ${token.colorFill} inset;
|
|
22
|
+
`,
|
|
23
|
+
image: css`
|
|
24
|
+
margin-block: 0 !important;
|
|
25
|
+
|
|
26
|
+
.ant-image {
|
|
27
|
+
height: 100% !important;
|
|
28
|
+
|
|
29
|
+
img {
|
|
30
|
+
height: 100% !important;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
interface FileItemProps {
|
|
37
|
+
alt?: string;
|
|
38
|
+
loading?: boolean;
|
|
39
|
+
onRemove?: () => void;
|
|
40
|
+
src?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const FileItem = memo<FileItemProps>(({ alt, onRemove, src, loading }) => {
|
|
44
|
+
const IMAGE_SIZE = MIN_IMAGE_SIZE;
|
|
45
|
+
const { styles, cx } = useStyles();
|
|
46
|
+
const { isSafari } = usePlatform();
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Image
|
|
50
|
+
actions={
|
|
51
|
+
<ActionIcon
|
|
52
|
+
className={styles.deleteButton}
|
|
53
|
+
glass
|
|
54
|
+
icon={Trash}
|
|
55
|
+
onClick={(e) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
onRemove?.();
|
|
58
|
+
}}
|
|
59
|
+
size={'small'}
|
|
60
|
+
/>
|
|
61
|
+
}
|
|
62
|
+
alt={alt || ''}
|
|
63
|
+
alwaysShowActions
|
|
64
|
+
height={isSafari ? 'auto' : '100%'}
|
|
65
|
+
isLoading={loading}
|
|
66
|
+
size={IMAGE_SIZE as any}
|
|
67
|
+
src={src}
|
|
68
|
+
style={{ height: isSafari ? 'auto' : '100%' }}
|
|
69
|
+
wrapperClassName={cx(styles.image, styles.editableImage)}
|
|
70
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export default FileItem;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CSSProperties, memo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useFileStore } from '@/store/file';
|
|
4
|
+
import { UploadFileItem } from '@/types/files';
|
|
5
|
+
|
|
6
|
+
import File from './File';
|
|
7
|
+
import Image from './Image';
|
|
8
|
+
|
|
9
|
+
interface FileItemProps extends UploadFileItem {
|
|
10
|
+
alt?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
onClick?: () => void;
|
|
14
|
+
onRemove?: () => void;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const FileItem = memo<FileItemProps>((props) => {
|
|
20
|
+
const { file, id, previewUrl, status } = props;
|
|
21
|
+
const [removeFile] = useFileStore((s) => [s.removeChatUploadFile]);
|
|
22
|
+
|
|
23
|
+
if (file.type.startsWith('image')) {
|
|
24
|
+
return (
|
|
25
|
+
<Image
|
|
26
|
+
alt={file.name}
|
|
27
|
+
loading={status === 'pending'}
|
|
28
|
+
onRemove={() => {
|
|
29
|
+
removeFile(id);
|
|
30
|
+
}}
|
|
31
|
+
src={previewUrl}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return <File onRemove={() => removeFile(id)} {...props} />;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export default FileItem;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MIN_IMAGE_SIZE = 64;
|
package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/Files/index.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ImageGallery } from '@lobehub/ui';
|
|
2
|
+
import isEqual from 'fast-deep-equal';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
|
|
6
|
+
import { filesSelectors, useFileStore } from '@/store/file';
|
|
7
|
+
|
|
8
|
+
import FileItem from './FileItem';
|
|
9
|
+
|
|
10
|
+
const Files = memo(() => {
|
|
11
|
+
const list = useFileStore(filesSelectors.chatUploadFileList, isEqual);
|
|
12
|
+
|
|
13
|
+
if (!list || list?.length === 0) return null;
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Flexbox paddingBlock={4} style={{ position: 'relative' }}>
|
|
17
|
+
<Flexbox
|
|
18
|
+
gap={4}
|
|
19
|
+
horizontal
|
|
20
|
+
padding={'4px 8px 8px'}
|
|
21
|
+
style={{ overflow: 'scroll', width: '100%' }}
|
|
22
|
+
>
|
|
23
|
+
<ImageGallery>
|
|
24
|
+
{list.map((i) => (
|
|
25
|
+
<FileItem {...i} key={i.id} loading={i.status === 'pending'} />
|
|
26
|
+
))}
|
|
27
|
+
</ImageGallery>
|
|
28
|
+
</Flexbox>
|
|
29
|
+
</Flexbox>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export default Files;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { css, cx } from 'antd-style';
|
|
2
|
+
import { FC, ReactNode, memo } from 'react';
|
|
3
|
+
import { Flexbox } from 'react-layout-kit';
|
|
4
|
+
|
|
5
|
+
const container = css`
|
|
6
|
+
height: inherit;
|
|
7
|
+
padding-block: 0;
|
|
8
|
+
padding-inline: 8px;
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
interface InnerContainerProps {
|
|
12
|
+
bottomAddons?: ReactNode;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
expand?: boolean;
|
|
15
|
+
textAreaLeftAddons?: ReactNode;
|
|
16
|
+
textAreaRightAddons?: ReactNode;
|
|
17
|
+
topAddons?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const InnerContainer: FC<InnerContainerProps> = memo(
|
|
21
|
+
({ children, expand, textAreaRightAddons, textAreaLeftAddons, bottomAddons, topAddons }) =>
|
|
22
|
+
expand ? (
|
|
23
|
+
<Flexbox className={cx(container)} gap={8}>
|
|
24
|
+
<Flexbox gap={8} horizontal justify={'flex-end'}>
|
|
25
|
+
{textAreaLeftAddons}
|
|
26
|
+
{textAreaRightAddons}
|
|
27
|
+
</Flexbox>
|
|
28
|
+
{children}
|
|
29
|
+
{topAddons}
|
|
30
|
+
{bottomAddons}
|
|
31
|
+
</Flexbox>
|
|
32
|
+
) : (
|
|
33
|
+
<Flexbox align={'flex-end'} className={cx(container)} gap={8} horizontal>
|
|
34
|
+
{textAreaLeftAddons}
|
|
35
|
+
{children}
|
|
36
|
+
{textAreaRightAddons}
|
|
37
|
+
</Flexbox>
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export default InnerContainer;
|
package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Mobile/InputArea/index.tsx
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ActionIcon, MobileSafeArea, TextArea } from '@lobehub/ui';
|
|
2
|
+
import { useSize } from 'ahooks';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import { TextAreaRef } from 'antd/es/input/TextArea';
|
|
5
|
+
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
6
|
+
import { rgba } from 'polished';
|
|
7
|
+
import { CSSProperties, ReactNode, forwardRef, useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { useTranslation } from 'react-i18next';
|
|
9
|
+
import { Flexbox } from 'react-layout-kit';
|
|
10
|
+
|
|
11
|
+
import InnerContainer from './Container';
|
|
12
|
+
|
|
13
|
+
const useStyles = createStyles(({ css, token }) => {
|
|
14
|
+
return {
|
|
15
|
+
container: css`
|
|
16
|
+
flex: none;
|
|
17
|
+
padding-block: 12px 12px;
|
|
18
|
+
background: ${token.colorFillQuaternary};
|
|
19
|
+
border-block-start: 1px solid ${rgba(token.colorBorder, 0.25)};
|
|
20
|
+
`,
|
|
21
|
+
expand: css`
|
|
22
|
+
position: absolute;
|
|
23
|
+
height: 100%;
|
|
24
|
+
`,
|
|
25
|
+
expandButton: css`
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset-inline-start: 14px;
|
|
28
|
+
`,
|
|
29
|
+
expandTextArea: css`
|
|
30
|
+
flex: 1;
|
|
31
|
+
`,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export interface MobileChatInputAreaProps {
|
|
36
|
+
bottomAddons?: ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
expand?: boolean;
|
|
39
|
+
loading?: boolean;
|
|
40
|
+
onInput?: (value: string) => void;
|
|
41
|
+
onSend?: () => void;
|
|
42
|
+
safeArea?: boolean;
|
|
43
|
+
setExpand?: (expand: boolean) => void;
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
textAreaLeftAddons?: ReactNode;
|
|
46
|
+
textAreaRightAddons?: ReactNode;
|
|
47
|
+
topAddons?: ReactNode;
|
|
48
|
+
value: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const MobileChatInputArea = forwardRef<TextAreaRef, MobileChatInputAreaProps>(
|
|
52
|
+
(
|
|
53
|
+
{
|
|
54
|
+
className,
|
|
55
|
+
style,
|
|
56
|
+
topAddons,
|
|
57
|
+
textAreaLeftAddons,
|
|
58
|
+
textAreaRightAddons,
|
|
59
|
+
bottomAddons,
|
|
60
|
+
expand = false,
|
|
61
|
+
setExpand,
|
|
62
|
+
onSend,
|
|
63
|
+
onInput,
|
|
64
|
+
loading,
|
|
65
|
+
value,
|
|
66
|
+
safeArea,
|
|
67
|
+
},
|
|
68
|
+
ref,
|
|
69
|
+
) => {
|
|
70
|
+
const { t } = useTranslation('chat');
|
|
71
|
+
const isChineseInput = useRef(false);
|
|
72
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
73
|
+
const { cx, styles } = useStyles();
|
|
74
|
+
const size = useSize(containerRef);
|
|
75
|
+
const [showFullscreen, setShowFullscreen] = useState<boolean>(false);
|
|
76
|
+
const [isFocused, setIsFocused] = useState<boolean>(false);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!size?.height) return;
|
|
80
|
+
setShowFullscreen(size.height > 72);
|
|
81
|
+
}, [size]);
|
|
82
|
+
|
|
83
|
+
const showAddons = !expand && !isFocused;
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Flexbox
|
|
87
|
+
className={cx(styles.container, expand && styles.expand, className)}
|
|
88
|
+
gap={12}
|
|
89
|
+
style={style}
|
|
90
|
+
>
|
|
91
|
+
{topAddons && <Flexbox style={showAddons ? {} : { display: 'none' }}>{topAddons}</Flexbox>}
|
|
92
|
+
<Flexbox
|
|
93
|
+
className={cx(expand && styles.expand)}
|
|
94
|
+
ref={containerRef}
|
|
95
|
+
style={{ position: 'relative' }}
|
|
96
|
+
>
|
|
97
|
+
{showFullscreen && (
|
|
98
|
+
<ActionIcon
|
|
99
|
+
active
|
|
100
|
+
className={styles.expandButton}
|
|
101
|
+
icon={expand ? ChevronDown : ChevronUp}
|
|
102
|
+
onClick={() => setExpand?.(!expand)}
|
|
103
|
+
size={{ blockSize: 24, borderRadius: '50%', fontSize: 14 }}
|
|
104
|
+
style={expand ? { top: 6 } : {}}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
<InnerContainer
|
|
108
|
+
bottomAddons={bottomAddons}
|
|
109
|
+
expand={expand}
|
|
110
|
+
textAreaLeftAddons={textAreaLeftAddons}
|
|
111
|
+
textAreaRightAddons={textAreaRightAddons}
|
|
112
|
+
topAddons={topAddons}
|
|
113
|
+
>
|
|
114
|
+
<TextArea
|
|
115
|
+
autoSize={expand ? false : { maxRows: 6, minRows: 0 }}
|
|
116
|
+
className={cx(expand && styles.expandTextArea)}
|
|
117
|
+
onBlur={(e) => {
|
|
118
|
+
onInput?.(e.target.value);
|
|
119
|
+
setIsFocused(false);
|
|
120
|
+
}}
|
|
121
|
+
onChange={(e) => {
|
|
122
|
+
onInput?.(e.target.value);
|
|
123
|
+
}}
|
|
124
|
+
onCompositionEnd={() => {
|
|
125
|
+
isChineseInput.current = false;
|
|
126
|
+
}}
|
|
127
|
+
onCompositionStart={() => {
|
|
128
|
+
isChineseInput.current = true;
|
|
129
|
+
}}
|
|
130
|
+
onFocus={() => setIsFocused(true)}
|
|
131
|
+
onPressEnter={(e) => {
|
|
132
|
+
if (!loading && !isChineseInput.current && e.shiftKey) {
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
onSend?.();
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
placeholder={t('sendPlaceholder')}
|
|
138
|
+
ref={ref}
|
|
139
|
+
style={{ height: 36, paddingBlock: 6 }}
|
|
140
|
+
type={expand ? 'pure' : 'block'}
|
|
141
|
+
value={value}
|
|
142
|
+
/>
|
|
143
|
+
</InnerContainer>
|
|
144
|
+
</Flexbox>
|
|
145
|
+
{bottomAddons && (
|
|
146
|
+
<Flexbox style={showAddons ? {} : { display: 'none' }}>{bottomAddons}</Flexbox>
|
|
147
|
+
)}
|
|
148
|
+
{safeArea && !isFocused && <MobileSafeArea position={'bottom'} />}
|
|
149
|
+
</Flexbox>
|
|
150
|
+
);
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
export default MobileChatInputArea;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ActionIcon, type ActionIconSize, Icon } from '@lobehub/ui';
|
|
2
|
+
import { Button } from 'antd';
|
|
3
|
+
import { Loader2, SendHorizontal } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
export interface MobileChatSendButtonProps {
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
onSend?: () => void;
|
|
10
|
+
onStop?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const MobileChatSendButton = memo<MobileChatSendButtonProps>(
|
|
14
|
+
({ loading, onStop, onSend, disabled }) => {
|
|
15
|
+
const size: ActionIconSize = {
|
|
16
|
+
blockSize: 36,
|
|
17
|
+
fontSize: 16,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return loading ? (
|
|
21
|
+
<ActionIcon active icon={Loader2} onClick={onStop} size={size} spin />
|
|
22
|
+
) : (
|
|
23
|
+
<Button
|
|
24
|
+
disabled={disabled}
|
|
25
|
+
icon={(<Icon icon={SendHorizontal} />) as any}
|
|
26
|
+
onClick={onSend}
|
|
27
|
+
style={{ flex: 'none' }}
|
|
28
|
+
type={'primary'}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export default MobileChatSendButton;
|
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { MobileChatInputArea, MobileChatSendButton } from '@lobehub/ui';
|
|
4
3
|
import { useTheme } from 'antd-style';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { TextAreaRef } from 'antd/es/input/TextArea';
|
|
5
|
+
import { memo, useRef, useState } from 'react';
|
|
7
6
|
|
|
8
7
|
import ActionBar from '@/features/ChatInput/ActionBar';
|
|
9
8
|
import STT from '@/features/ChatInput/STT';
|
|
10
9
|
import SaveTopic from '@/features/ChatInput/Topic';
|
|
11
|
-
import {
|
|
10
|
+
import { useSendMessage } from '@/features/ChatInput/useSend';
|
|
11
|
+
import { useChatStore } from '@/store/chat';
|
|
12
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
12
13
|
|
|
13
14
|
import Files from './Files';
|
|
15
|
+
import InputArea from './InputArea';
|
|
16
|
+
import SendButton from './Send';
|
|
14
17
|
|
|
15
18
|
const MobileChatInput = memo(() => {
|
|
16
|
-
const { t } = useTranslation('chat');
|
|
17
19
|
const theme = useTheme();
|
|
18
|
-
const
|
|
20
|
+
const ref = useRef<TextAreaRef>(null);
|
|
21
|
+
const [expand, setExpand] = useState<boolean>(false);
|
|
22
|
+
const { send: sendMessage, canSend } = useSendMessage();
|
|
23
|
+
|
|
24
|
+
const [loading, value, onInput, onStop] = useChatStore((s) => [
|
|
25
|
+
chatSelectors.isAIGenerating(s),
|
|
26
|
+
s.inputMessage,
|
|
27
|
+
s.updateInputMessage,
|
|
28
|
+
s.stopGenerateMessage,
|
|
29
|
+
]);
|
|
19
30
|
|
|
20
31
|
return (
|
|
21
|
-
<
|
|
32
|
+
<InputArea
|
|
22
33
|
expand={expand}
|
|
23
|
-
loading={loading}
|
|
24
34
|
onInput={onInput}
|
|
25
|
-
onSend={
|
|
26
|
-
|
|
35
|
+
onSend={() => {
|
|
36
|
+
setExpand(false);
|
|
37
|
+
|
|
38
|
+
sendMessage();
|
|
39
|
+
}}
|
|
27
40
|
ref={ref}
|
|
28
41
|
setExpand={setExpand}
|
|
29
42
|
style={{
|
|
@@ -34,7 +47,7 @@ const MobileChatInput = memo(() => {
|
|
|
34
47
|
}}
|
|
35
48
|
textAreaLeftAddons={<STT mobile />}
|
|
36
49
|
textAreaRightAddons={
|
|
37
|
-
<
|
|
50
|
+
<SendButton disabled={!canSend} loading={loading} onSend={sendMessage} onStop={onStop} />
|
|
38
51
|
}
|
|
39
52
|
topAddons={
|
|
40
53
|
<>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CheckCircleFilled } from '@ant-design/icons';
|
|
2
|
+
import { Icon } from '@lobehub/ui';
|
|
3
|
+
import { Progress, Typography } from 'antd';
|
|
4
|
+
import { useTheme } from 'antd-style';
|
|
5
|
+
import { Loader2Icon } from 'lucide-react';
|
|
6
|
+
import { memo } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
|
|
10
|
+
import { FileUploadState, FileUploadStatus } from '@/types/files/upload';
|
|
11
|
+
import { formatSize } from '@/utils/format';
|
|
12
|
+
|
|
13
|
+
interface UploadStateProps {
|
|
14
|
+
size: number;
|
|
15
|
+
status: FileUploadStatus;
|
|
16
|
+
uploadState?: FileUploadState;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const UploadStatus = memo<UploadStateProps>(({ status, size, uploadState }) => {
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
const { t } = useTranslation('chat');
|
|
22
|
+
|
|
23
|
+
switch (status) {
|
|
24
|
+
default:
|
|
25
|
+
case 'pending': {
|
|
26
|
+
return (
|
|
27
|
+
<Flexbox align={'center'} gap={4} horizontal>
|
|
28
|
+
<Icon icon={Loader2Icon} size={{ fontSize: 12 }} spin />
|
|
29
|
+
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
|
|
30
|
+
{t('upload.preview.status.pending')}
|
|
31
|
+
</Typography.Text>
|
|
32
|
+
</Flexbox>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
case 'uploading': {
|
|
37
|
+
return (
|
|
38
|
+
<Flexbox align={'center'} gap={4} horizontal>
|
|
39
|
+
<Progress percent={uploadState?.progress} size={14} type="circle" />
|
|
40
|
+
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
|
|
41
|
+
{formatSize(size * ((uploadState?.progress || 0) / 100), 2)} / {formatSize(size)}
|
|
42
|
+
</Typography.Text>
|
|
43
|
+
</Flexbox>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
case 'processing': {
|
|
48
|
+
return (
|
|
49
|
+
<Flexbox align={'center'} gap={4} horizontal>
|
|
50
|
+
<Progress percent={uploadState?.progress} size={14} type="circle" />
|
|
51
|
+
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
|
|
52
|
+
{formatSize(size)} · {t('upload.preview.status.processing')}
|
|
53
|
+
</Typography.Text>
|
|
54
|
+
</Flexbox>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
case 'success': {
|
|
59
|
+
return (
|
|
60
|
+
<Flexbox align={'center'} gap={4} horizontal>
|
|
61
|
+
<CheckCircleFilled style={{ color: theme.colorSuccess, fontSize: 12 }} />
|
|
62
|
+
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
|
|
63
|
+
{formatSize(size)}
|
|
64
|
+
</Typography.Text>
|
|
65
|
+
</Flexbox>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export default UploadStatus;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Typography } from 'antd';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { Flexbox } from 'react-layout-kit';
|
|
6
|
+
|
|
7
|
+
import FileParsingStatus from '@/components/FileParsingStatus';
|
|
8
|
+
import { FileParsingTask } from '@/types/asyncTask';
|
|
9
|
+
import { FileUploadState, FileUploadStatus } from '@/types/files';
|
|
10
|
+
|
|
11
|
+
import UploadStatus from './UploadStatus';
|
|
12
|
+
|
|
13
|
+
const useStyles = createStyles(({ css }) => ({
|
|
14
|
+
status: css`
|
|
15
|
+
&.ant-tag {
|
|
16
|
+
padding-inline: 0;
|
|
17
|
+
background: none;
|
|
18
|
+
}
|
|
19
|
+
`,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
interface UploadDetailProps {
|
|
23
|
+
size: number;
|
|
24
|
+
status: FileUploadStatus;
|
|
25
|
+
tasks?: FileParsingTask;
|
|
26
|
+
uploadState?: FileUploadState;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const UploadDetail = memo<UploadDetailProps>(({ uploadState, status, size, tasks }) => {
|
|
30
|
+
const { t } = useTranslation('chat');
|
|
31
|
+
const { styles } = useStyles();
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Flexbox align={'center'} gap={8} height={22} horizontal>
|
|
35
|
+
<UploadStatus size={size} status={status} uploadState={uploadState} />
|
|
36
|
+
{!!tasks && Object.keys(tasks).length === 0 ? (
|
|
37
|
+
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}>
|
|
38
|
+
{t('upload.preview.prepareTasks')}
|
|
39
|
+
</Typography.Text>
|
|
40
|
+
) : (
|
|
41
|
+
<div>
|
|
42
|
+
<FileParsingStatus {...tasks} className={styles.status} hideEmbeddingButton />
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
</Flexbox>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export default UploadDetail;
|