@lobehub/chat 1.11.8 → 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 +50 -0
- package/Dockerfile.database +2 -0
- package/docs/self-hosting/advanced/knowledge-base.zh-CN.mdx +65 -0
- package/locales/ar/chat.json +46 -3
- package/locales/ar/common.json +1 -0
- package/locales/ar/components.json +2 -0
- package/locales/ar/error.json +1 -0
- package/locales/ar/file.json +91 -0
- package/locales/ar/knowledgeBase.json +31 -0
- package/locales/ar/portal.json +1 -0
- package/locales/bg-BG/chat.json +46 -3
- package/locales/bg-BG/common.json +1 -0
- package/locales/bg-BG/components.json +2 -0
- package/locales/bg-BG/error.json +1 -0
- package/locales/bg-BG/file.json +91 -0
- package/locales/bg-BG/knowledgeBase.json +31 -0
- package/locales/bg-BG/portal.json +1 -0
- package/locales/de-DE/chat.json +46 -3
- package/locales/de-DE/common.json +1 -0
- package/locales/de-DE/components.json +2 -0
- package/locales/de-DE/error.json +1 -0
- package/locales/de-DE/file.json +91 -0
- package/locales/de-DE/knowledgeBase.json +31 -0
- package/locales/de-DE/portal.json +1 -0
- package/locales/en-US/chat.json +46 -3
- package/locales/en-US/common.json +1 -0
- package/locales/en-US/components.json +2 -0
- package/locales/en-US/error.json +1 -0
- package/locales/en-US/file.json +91 -0
- package/locales/en-US/knowledgeBase.json +31 -0
- package/locales/en-US/portal.json +1 -0
- package/locales/es-ES/chat.json +46 -3
- package/locales/es-ES/common.json +1 -0
- package/locales/es-ES/components.json +2 -0
- package/locales/es-ES/error.json +1 -0
- package/locales/es-ES/file.json +91 -0
- package/locales/es-ES/knowledgeBase.json +31 -0
- package/locales/es-ES/portal.json +1 -0
- package/locales/fr-FR/chat.json +46 -3
- package/locales/fr-FR/common.json +1 -0
- package/locales/fr-FR/components.json +2 -0
- package/locales/fr-FR/error.json +1 -0
- package/locales/fr-FR/file.json +91 -0
- package/locales/fr-FR/knowledgeBase.json +31 -0
- package/locales/fr-FR/portal.json +1 -0
- package/locales/it-IT/chat.json +46 -3
- package/locales/it-IT/common.json +1 -0
- package/locales/it-IT/components.json +2 -0
- package/locales/it-IT/error.json +1 -0
- package/locales/it-IT/file.json +91 -0
- package/locales/it-IT/knowledgeBase.json +31 -0
- package/locales/it-IT/portal.json +1 -0
- package/locales/ja-JP/chat.json +46 -3
- package/locales/ja-JP/common.json +1 -0
- package/locales/ja-JP/components.json +2 -0
- package/locales/ja-JP/error.json +1 -0
- package/locales/ja-JP/file.json +91 -0
- package/locales/ja-JP/knowledgeBase.json +31 -0
- package/locales/ja-JP/portal.json +1 -0
- package/locales/ko-KR/chat.json +46 -3
- package/locales/ko-KR/common.json +1 -0
- package/locales/ko-KR/components.json +2 -0
- package/locales/ko-KR/error.json +1 -0
- package/locales/ko-KR/file.json +91 -0
- package/locales/ko-KR/knowledgeBase.json +31 -0
- package/locales/ko-KR/portal.json +1 -0
- package/locales/nl-NL/chat.json +46 -3
- package/locales/nl-NL/common.json +1 -0
- package/locales/nl-NL/components.json +2 -0
- package/locales/nl-NL/error.json +1 -0
- package/locales/nl-NL/file.json +91 -0
- package/locales/nl-NL/knowledgeBase.json +31 -0
- package/locales/nl-NL/portal.json +1 -0
- package/locales/pl-PL/chat.json +46 -3
- package/locales/pl-PL/common.json +1 -0
- package/locales/pl-PL/components.json +2 -0
- package/locales/pl-PL/error.json +1 -0
- package/locales/pl-PL/file.json +91 -0
- package/locales/pl-PL/knowledgeBase.json +31 -0
- package/locales/pl-PL/portal.json +1 -0
- package/locales/pt-BR/chat.json +46 -3
- package/locales/pt-BR/common.json +1 -0
- package/locales/pt-BR/components.json +2 -0
- package/locales/pt-BR/error.json +1 -0
- package/locales/pt-BR/file.json +91 -0
- package/locales/pt-BR/knowledgeBase.json +31 -0
- package/locales/pt-BR/portal.json +1 -0
- package/locales/ru-RU/chat.json +46 -3
- package/locales/ru-RU/common.json +1 -0
- package/locales/ru-RU/components.json +2 -0
- package/locales/ru-RU/error.json +1 -0
- package/locales/ru-RU/file.json +91 -0
- package/locales/ru-RU/knowledgeBase.json +31 -0
- package/locales/ru-RU/portal.json +1 -0
- package/locales/tr-TR/chat.json +46 -3
- package/locales/tr-TR/common.json +1 -0
- package/locales/tr-TR/components.json +2 -0
- package/locales/tr-TR/error.json +1 -0
- package/locales/tr-TR/file.json +91 -0
- package/locales/tr-TR/knowledgeBase.json +31 -0
- package/locales/tr-TR/portal.json +1 -0
- package/locales/vi-VN/chat.json +46 -3
- package/locales/vi-VN/common.json +1 -0
- package/locales/vi-VN/components.json +2 -0
- package/locales/vi-VN/error.json +1 -0
- package/locales/vi-VN/file.json +91 -0
- package/locales/vi-VN/knowledgeBase.json +31 -0
- package/locales/vi-VN/portal.json +1 -0
- package/locales/zh-CN/chat.json +46 -3
- package/locales/zh-CN/common.json +1 -0
- package/locales/zh-CN/components.json +2 -0
- package/locales/zh-CN/error.json +1 -0
- package/locales/zh-CN/file.json +91 -0
- package/locales/zh-CN/knowledgeBase.json +31 -0
- package/locales/zh-CN/portal.json +1 -0
- package/locales/zh-TW/chat.json +46 -3
- package/locales/zh-TW/common.json +1 -0
- package/locales/zh-TW/components.json +2 -0
- package/locales/zh-TW/error.json +1 -0
- package/locales/zh-TW/file.json +91 -0
- package/locales/zh-TW/knowledgeBase.json +31 -0
- package/locales/zh-TW/portal.json +1 -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/config/modelProviders/bedrock.ts +5 -5
- 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,77 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
+
import { boolean, integer, pgTable, text, unique, uniqueIndex, varchar } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { createInsertSchema } from 'drizzle-zod';
|
|
4
|
+
|
|
5
|
+
import { idGenerator, randomSlug } from '../../utils/idGenerator';
|
|
6
|
+
import { createdAt, updatedAt } from './_helpers';
|
|
7
|
+
import { users } from './user';
|
|
8
|
+
|
|
9
|
+
// ======= sessionGroups ======= //
|
|
10
|
+
|
|
11
|
+
export const sessionGroups = pgTable(
|
|
12
|
+
'session_groups',
|
|
13
|
+
{
|
|
14
|
+
id: text('id')
|
|
15
|
+
.$defaultFn(() => idGenerator('sessionGroups'))
|
|
16
|
+
.primaryKey(),
|
|
17
|
+
name: text('name').notNull(),
|
|
18
|
+
sort: integer('sort'),
|
|
19
|
+
|
|
20
|
+
userId: text('user_id')
|
|
21
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
22
|
+
.notNull(),
|
|
23
|
+
|
|
24
|
+
clientId: text('client_id'),
|
|
25
|
+
createdAt: createdAt(),
|
|
26
|
+
updatedAt: updatedAt(),
|
|
27
|
+
},
|
|
28
|
+
(table) => ({
|
|
29
|
+
clientIdUnique: unique('session_group_client_id_user_unique').on(table.clientId, table.userId),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const insertSessionGroupSchema = createInsertSchema(sessionGroups);
|
|
34
|
+
|
|
35
|
+
export type NewSessionGroup = typeof sessionGroups.$inferInsert;
|
|
36
|
+
export type SessionGroupItem = typeof sessionGroups.$inferSelect;
|
|
37
|
+
|
|
38
|
+
// ======= sessions ======= //
|
|
39
|
+
|
|
40
|
+
export const sessions = pgTable(
|
|
41
|
+
'sessions',
|
|
42
|
+
{
|
|
43
|
+
id: text('id')
|
|
44
|
+
.$defaultFn(() => idGenerator('sessions'))
|
|
45
|
+
.primaryKey(),
|
|
46
|
+
slug: varchar('slug', { length: 100 })
|
|
47
|
+
.notNull()
|
|
48
|
+
.$defaultFn(() => randomSlug()),
|
|
49
|
+
title: text('title'),
|
|
50
|
+
description: text('description'),
|
|
51
|
+
avatar: text('avatar'),
|
|
52
|
+
backgroundColor: text('background_color'),
|
|
53
|
+
|
|
54
|
+
type: text('type', { enum: ['agent', 'group'] }).default('agent'),
|
|
55
|
+
|
|
56
|
+
userId: text('user_id')
|
|
57
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
58
|
+
.notNull(),
|
|
59
|
+
groupId: text('group_id').references(() => sessionGroups.id, { onDelete: 'set null' }),
|
|
60
|
+
clientId: text('client_id'),
|
|
61
|
+
pinned: boolean('pinned').default(false),
|
|
62
|
+
|
|
63
|
+
createdAt: createdAt(),
|
|
64
|
+
updatedAt: updatedAt(),
|
|
65
|
+
},
|
|
66
|
+
(t) => ({
|
|
67
|
+
slugUserIdUnique: uniqueIndex('slug_user_id_unique').on(t.slug, t.userId),
|
|
68
|
+
|
|
69
|
+
clientIdUnique: unique('sessions_client_id_user_id_unique').on(t.clientId, t.userId),
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export const insertSessionSchema = createInsertSchema(sessions);
|
|
74
|
+
// export const selectSessionSchema = createSelectSchema(sessions);
|
|
75
|
+
|
|
76
|
+
export type NewSession = typeof sessions.$inferInsert;
|
|
77
|
+
export type SessionItem = typeof sessions.$inferSelect;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// ======== topics ======= //
|
|
2
|
+
import { boolean, pgTable, text, unique } from 'drizzle-orm/pg-core';
|
|
3
|
+
|
|
4
|
+
import { idGenerator } from '../../utils/idGenerator';
|
|
5
|
+
import { createdAt, updatedAt } from './_helpers';
|
|
6
|
+
import { sessions } from './session';
|
|
7
|
+
import { users } from './user';
|
|
8
|
+
|
|
9
|
+
export const topics = pgTable(
|
|
10
|
+
'topics',
|
|
11
|
+
{
|
|
12
|
+
clientId: text('client_id'),
|
|
13
|
+
createdAt: createdAt(),
|
|
14
|
+
favorite: boolean('favorite').default(false),
|
|
15
|
+
id: text('id')
|
|
16
|
+
.$defaultFn(() => idGenerator('topics'))
|
|
17
|
+
.primaryKey(),
|
|
18
|
+
sessionId: text('session_id').references(() => sessions.id, { onDelete: 'cascade' }),
|
|
19
|
+
title: text('title'),
|
|
20
|
+
|
|
21
|
+
updatedAt: updatedAt(),
|
|
22
|
+
userId: text('user_id')
|
|
23
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
24
|
+
.notNull(),
|
|
25
|
+
},
|
|
26
|
+
(t) => ({
|
|
27
|
+
clientIdUnique: unique('topic_client_id_user_id_unique').on(t.clientId, t.userId),
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type NewTopic = typeof topics.$inferInsert;
|
|
32
|
+
export type TopicItem = typeof topics.$inferSelect;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
integer,
|
|
5
|
-
jsonb,
|
|
6
|
-
pgTable,
|
|
7
|
-
text,
|
|
8
|
-
} from 'drizzle-orm/pg-core';
|
|
2
|
+
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
3
|
+
import { boolean, integer, jsonb, pgTable, primaryKey, text } from 'drizzle-orm/pg-core';
|
|
9
4
|
|
|
10
5
|
import { DEFAULT_PREFERENCE } from '@/const/user';
|
|
6
|
+
import { CustomPluginParams } from '@/types/tool/plugin';
|
|
11
7
|
|
|
12
8
|
import { createdAt, timestamptz, updatedAt } from './_helpers';
|
|
13
9
|
|
|
14
|
-
/**
|
|
15
|
-
* This table stores users. Users are created in Clerk, then Clerk calls a
|
|
16
|
-
* webhook at /api/webhook/clerk to inform this application a user was created.
|
|
17
|
-
*/
|
|
18
10
|
export const users = pgTable('users', {
|
|
19
|
-
// The ID will be the user's ID from Clerk
|
|
20
11
|
id: text('id').primaryKey().notNull(),
|
|
21
12
|
username: text('username').unique(),
|
|
22
13
|
email: text('email'),
|
|
@@ -43,6 +34,20 @@ export const users = pgTable('users', {
|
|
|
43
34
|
export type NewUser = typeof users.$inferInsert;
|
|
44
35
|
export type UserItem = typeof users.$inferSelect;
|
|
45
36
|
|
|
37
|
+
export const userSettings = pgTable('user_settings', {
|
|
38
|
+
id: text('id')
|
|
39
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
40
|
+
.primaryKey(),
|
|
41
|
+
|
|
42
|
+
tts: jsonb('tts'),
|
|
43
|
+
keyVaults: text('key_vaults'),
|
|
44
|
+
general: jsonb('general'),
|
|
45
|
+
languageModel: jsonb('language_model'),
|
|
46
|
+
systemAgent: jsonb('system_agent'),
|
|
47
|
+
defaultAgent: jsonb('default_agent'),
|
|
48
|
+
tool: jsonb('tool'),
|
|
49
|
+
});
|
|
50
|
+
|
|
46
51
|
export const userSubscriptions = pgTable('user_subscriptions', {
|
|
47
52
|
id: text('id').primaryKey().notNull(),
|
|
48
53
|
userId: text('user_id')
|
|
@@ -96,16 +101,26 @@ export const userBudgets = pgTable('user_budgets', {
|
|
|
96
101
|
export type NewUserBudgets = typeof userBudgets.$inferInsert;
|
|
97
102
|
export type UserBudgetItem = typeof userBudgets.$inferSelect;
|
|
98
103
|
|
|
99
|
-
export const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
export const installedPlugins = pgTable(
|
|
105
|
+
'user_installed_plugins',
|
|
106
|
+
{
|
|
107
|
+
userId: text('user_id')
|
|
108
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
109
|
+
.notNull(),
|
|
110
|
+
|
|
111
|
+
identifier: text('identifier').notNull(),
|
|
112
|
+
type: text('type', { enum: ['plugin', 'customPlugin'] }).notNull(),
|
|
113
|
+
manifest: jsonb('manifest').$type<LobeChatPluginManifest>(),
|
|
114
|
+
settings: jsonb('settings'),
|
|
115
|
+
customParams: jsonb('custom_params').$type<CustomPluginParams>(),
|
|
116
|
+
|
|
117
|
+
createdAt: createdAt(),
|
|
118
|
+
updatedAt: updatedAt(),
|
|
119
|
+
},
|
|
120
|
+
(self) => ({
|
|
121
|
+
id: primaryKey({ columns: [self.userId, self.identifier] }),
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export type NewInstalledPlugin = typeof installedPlugins.$inferInsert;
|
|
126
|
+
export type InstalledPluginItem = typeof installedPlugins.$inferSelect;
|
|
@@ -13,7 +13,7 @@ import { useFileStore } from '@/store/file';
|
|
|
13
13
|
const Clear = memo(() => {
|
|
14
14
|
const { t } = useTranslation('setting');
|
|
15
15
|
const [clearMessage] = useChatStore((s) => [s.clearMessage]);
|
|
16
|
-
const [clearImageList] = useFileStore((s) => [s.
|
|
16
|
+
const [clearImageList] = useFileStore((s) => [s.clearChatUploadFileList]);
|
|
17
17
|
const hotkeys = [META_KEY, ALT_KEY, CLEAN_MESSAGE_KEY].join('+');
|
|
18
18
|
const [confirmOpened, updateConfirmOpened] = useState(false);
|
|
19
19
|
const mobile = useIsMobile();
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { Dropdown } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import type { ItemType } from 'antd/es/menu/interface';
|
|
5
|
+
import isEqual from 'fast-deep-equal';
|
|
6
|
+
import { ArrowRight, LibraryBig } from 'lucide-react';
|
|
7
|
+
import { PropsWithChildren, memo, useState } from 'react';
|
|
8
|
+
import { useTranslation } from 'react-i18next';
|
|
9
|
+
import { Flexbox } from 'react-layout-kit';
|
|
10
|
+
|
|
11
|
+
import FileIcon from '@/components/FileIcon';
|
|
12
|
+
import RepoIcon from '@/components/RepoIcon';
|
|
13
|
+
import { AssignKnowledgeBaseModal } from '@/features/KnowledgeBaseModal';
|
|
14
|
+
import { useAgentStore } from '@/store/agent';
|
|
15
|
+
import { agentSelectors } from '@/store/agent/selectors';
|
|
16
|
+
|
|
17
|
+
import ListItem from './ListItem';
|
|
18
|
+
|
|
19
|
+
const useStyles = createStyles(({ css, prefixCls }) => ({
|
|
20
|
+
knowledgeBase: css``,
|
|
21
|
+
menu: css`
|
|
22
|
+
&.${prefixCls}-dropdown-menu {
|
|
23
|
+
padding-block: 8px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.${prefixCls}-dropdown-menu-item-group-list .${prefixCls}-dropdown-menu-item {
|
|
27
|
+
padding: 0;
|
|
28
|
+
padding-inline-start: 8px;
|
|
29
|
+
border-radius: 4px;
|
|
30
|
+
}
|
|
31
|
+
`,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const DropdownMenu = memo<PropsWithChildren>(({ children }) => {
|
|
35
|
+
const { t } = useTranslation('chat');
|
|
36
|
+
|
|
37
|
+
const { styles } = useStyles();
|
|
38
|
+
const [open, setOpen] = useState(false);
|
|
39
|
+
const files = useAgentStore(agentSelectors.currentAgentFiles, isEqual);
|
|
40
|
+
const knowledgeBases = useAgentStore(agentSelectors.currentAgentKnowledgeBases, isEqual);
|
|
41
|
+
|
|
42
|
+
const [toggleFile, toggleKnowledgeBase] = useAgentStore((s) => [
|
|
43
|
+
s.toggleFile,
|
|
44
|
+
s.toggleKnowledgeBase,
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const items: ItemType[] = [
|
|
48
|
+
// {
|
|
49
|
+
// children: [
|
|
50
|
+
// {
|
|
51
|
+
// icon: <RepoIcon />,
|
|
52
|
+
// key: 'allFiles',
|
|
53
|
+
// label: <KnowledgeBaseItem id={'all'} label={t('knowledgeBase.allFiles')} />,
|
|
54
|
+
// },
|
|
55
|
+
// {
|
|
56
|
+
// icon: <RepoIcon />,
|
|
57
|
+
// key: 'allRepos',
|
|
58
|
+
// label: <KnowledgeBaseItem id={'all'} label={t('knowledgeBase.allKnowledgeBases')} />,
|
|
59
|
+
// },
|
|
60
|
+
// ],
|
|
61
|
+
// key: 'all',
|
|
62
|
+
// label: (
|
|
63
|
+
// <Flexbox horizontal justify={'space-between'}>
|
|
64
|
+
// {t('knowledgeBase.all')}
|
|
65
|
+
// {/*<Link href={'/files'}>{t('knowledgeBase.more')}</Link>*/}
|
|
66
|
+
// </Flexbox>
|
|
67
|
+
// ),
|
|
68
|
+
// type: 'group',
|
|
69
|
+
// },
|
|
70
|
+
{
|
|
71
|
+
children: [
|
|
72
|
+
// first the files
|
|
73
|
+
...files.map((item) => ({
|
|
74
|
+
icon: <FileIcon fileName={item.name} fileType={item.type} size={20} />,
|
|
75
|
+
key: item.id,
|
|
76
|
+
label: (
|
|
77
|
+
<ListItem
|
|
78
|
+
enabled={item.enabled}
|
|
79
|
+
id={item.id}
|
|
80
|
+
label={item.name}
|
|
81
|
+
onUpdate={async (id, enabled) => {
|
|
82
|
+
await toggleFile(id, enabled);
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
),
|
|
86
|
+
})),
|
|
87
|
+
|
|
88
|
+
// then the knowledge bases
|
|
89
|
+
...knowledgeBases.map((item) => ({
|
|
90
|
+
icon: <RepoIcon />,
|
|
91
|
+
key: item.id,
|
|
92
|
+
label: (
|
|
93
|
+
<ListItem
|
|
94
|
+
enabled={item.enabled}
|
|
95
|
+
id={item.id}
|
|
96
|
+
label={item.name}
|
|
97
|
+
onUpdate={async (id, enabled) => {
|
|
98
|
+
await toggleKnowledgeBase(id, enabled);
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
),
|
|
102
|
+
})),
|
|
103
|
+
{
|
|
104
|
+
icon: (
|
|
105
|
+
<Icon
|
|
106
|
+
icon={LibraryBig}
|
|
107
|
+
size={{ fontSize: 16 }}
|
|
108
|
+
style={{ marginInlineEnd: 0, paddingInlineStart: 4 }}
|
|
109
|
+
/>
|
|
110
|
+
),
|
|
111
|
+
key: 'knowledge-base-store',
|
|
112
|
+
label: (
|
|
113
|
+
<Flexbox gap={40} horizontal justify={'space-between'} padding={'8px 12px'}>
|
|
114
|
+
{t('knowledgeBase.viewMore')} <Icon icon={ArrowRight} />
|
|
115
|
+
</Flexbox>
|
|
116
|
+
),
|
|
117
|
+
onClick: (e) => {
|
|
118
|
+
e.domEvent.stopPropagation();
|
|
119
|
+
setOpen(true);
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
className: styles.knowledgeBase,
|
|
124
|
+
key: 'relativeFilesOrKnowledgeBases',
|
|
125
|
+
label: (
|
|
126
|
+
<Flexbox horizontal justify={'space-between'}>
|
|
127
|
+
{t('knowledgeBase.relativeFilesOrKnowledgeBases')}
|
|
128
|
+
{/*<Link href={'/files'}>{t('knowledgeBase.more')}</Link>*/}
|
|
129
|
+
</Flexbox>
|
|
130
|
+
),
|
|
131
|
+
type: 'group',
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<>
|
|
137
|
+
<Dropdown
|
|
138
|
+
arrow={false}
|
|
139
|
+
menu={{
|
|
140
|
+
className: styles.menu,
|
|
141
|
+
items,
|
|
142
|
+
onClick: (e) => {
|
|
143
|
+
e.domEvent.preventDefault();
|
|
144
|
+
},
|
|
145
|
+
style: {
|
|
146
|
+
maxHeight: 500,
|
|
147
|
+
overflowY: 'scroll',
|
|
148
|
+
},
|
|
149
|
+
}}
|
|
150
|
+
placement={'top'}
|
|
151
|
+
trigger={['click']}
|
|
152
|
+
>
|
|
153
|
+
{children}
|
|
154
|
+
</Dropdown>
|
|
155
|
+
<AssignKnowledgeBaseModal open={open} setOpen={setOpen} />
|
|
156
|
+
</>
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export default DropdownMenu;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { Checkbox } from 'antd';
|
|
3
|
+
import { Loader2 } from 'lucide-react';
|
|
4
|
+
import { memo, useState } from 'react';
|
|
5
|
+
import { Center, Flexbox } from 'react-layout-kit';
|
|
6
|
+
|
|
7
|
+
interface FileItemProps {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
onUpdate: (id: string, enabled: boolean) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ListItem = memo<FileItemProps>(({ id, onUpdate, label, enabled }) => {
|
|
15
|
+
const [loading, setLoading] = useState(false);
|
|
16
|
+
|
|
17
|
+
const updateState = async () => {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
await onUpdate(id, !enabled);
|
|
20
|
+
setLoading(false);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Flexbox
|
|
25
|
+
gap={24}
|
|
26
|
+
horizontal
|
|
27
|
+
justify={'space-between'}
|
|
28
|
+
onClick={async (e) => {
|
|
29
|
+
e.stopPropagation();
|
|
30
|
+
updateState();
|
|
31
|
+
}}
|
|
32
|
+
padding={'8px 12px'}
|
|
33
|
+
>
|
|
34
|
+
{label}
|
|
35
|
+
{loading ? (
|
|
36
|
+
<Center width={18}>
|
|
37
|
+
<Icon icon={Loader2} spin />
|
|
38
|
+
</Center>
|
|
39
|
+
) : (
|
|
40
|
+
<Checkbox
|
|
41
|
+
checked={enabled}
|
|
42
|
+
onClick={(e) => {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
updateState();
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
)}
|
|
48
|
+
</Flexbox>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export default ListItem;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
2
|
+
import { LibraryBig, LucideLoader2 } from 'lucide-react';
|
|
3
|
+
import { Suspense, memo } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
|
|
6
|
+
import TipGuide from '@/components/TipGuide';
|
|
7
|
+
import { isServerMode } from '@/const/version';
|
|
8
|
+
import { useUserStore } from '@/store/user';
|
|
9
|
+
import { preferenceSelectors } from '@/store/user/selectors';
|
|
10
|
+
|
|
11
|
+
import DropdownMenu from './Dropdown';
|
|
12
|
+
|
|
13
|
+
const enableKnowledge = isServerMode;
|
|
14
|
+
|
|
15
|
+
const Knowledge = memo(() => {
|
|
16
|
+
const { t } = useTranslation('chat');
|
|
17
|
+
|
|
18
|
+
const [showTip, updateGuideState] = useUserStore((s) => [
|
|
19
|
+
preferenceSelectors.showUploadFileInKnowledgeBaseTip(s),
|
|
20
|
+
s.updateGuideState,
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const content = (
|
|
24
|
+
<DropdownMenu>
|
|
25
|
+
<ActionIcon
|
|
26
|
+
disable={!enableKnowledge}
|
|
27
|
+
icon={LibraryBig}
|
|
28
|
+
placement={'bottom'}
|
|
29
|
+
title={enableKnowledge ? t('knowledgeBase.title') : t('knowledgeBase.disabled')}
|
|
30
|
+
/>
|
|
31
|
+
</DropdownMenu>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Suspense fallback={<ActionIcon icon={LucideLoader2} spin />}>
|
|
36
|
+
{showTip ? (
|
|
37
|
+
<TipGuide
|
|
38
|
+
onOpenChange={() => {
|
|
39
|
+
updateGuideState({ uploadFileInKnowledgeBase: false });
|
|
40
|
+
}}
|
|
41
|
+
open={showTip}
|
|
42
|
+
placement={'top'}
|
|
43
|
+
title={t('knowledgeBase.uploadGuide')}
|
|
44
|
+
>
|
|
45
|
+
{content}
|
|
46
|
+
</TipGuide>
|
|
47
|
+
) : (
|
|
48
|
+
content
|
|
49
|
+
)}
|
|
50
|
+
</Suspense>
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export default Knowledge;
|
|
@@ -17,7 +17,7 @@ const Tools = memo(() => {
|
|
|
17
17
|
const enableFC = useUserStore(modelProviderSelectors.isModelEnabledFunctionCall(model));
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
|
-
<Suspense fallback={<ActionIcon icon={LucideLoader2} />}>
|
|
20
|
+
<Suspense fallback={<ActionIcon icon={LucideLoader2} spin />}>
|
|
21
21
|
<DropdownMenu>
|
|
22
22
|
<ActionIcon
|
|
23
23
|
disable={!enableFC}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
2
|
+
import { Upload } from 'antd';
|
|
3
|
+
import { FileUp, LucideImage } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
|
|
7
|
+
import { useAgentStore } from '@/store/agent';
|
|
8
|
+
import { agentSelectors } from '@/store/agent/slices/chat';
|
|
9
|
+
import { useFileStore } from '@/store/file';
|
|
10
|
+
import { useUserStore } from '@/store/user';
|
|
11
|
+
import { modelProviderSelectors } from '@/store/user/selectors';
|
|
12
|
+
|
|
13
|
+
const FileUpload = memo(() => {
|
|
14
|
+
const { t } = useTranslation('chat');
|
|
15
|
+
|
|
16
|
+
const upload = useFileStore((s) => s.uploadChatFiles);
|
|
17
|
+
|
|
18
|
+
const model = useAgentStore(agentSelectors.currentAgentModel);
|
|
19
|
+
const [canUpload, enabledFiles] = useUserStore((s) => [
|
|
20
|
+
modelProviderSelectors.isModelEnabledUpload(model)(s),
|
|
21
|
+
modelProviderSelectors.isModelEnabledFiles(model)(s),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Upload
|
|
26
|
+
accept={enabledFiles ? undefined : 'image/*'}
|
|
27
|
+
beforeUpload={async (file) => {
|
|
28
|
+
await upload([file]);
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
}}
|
|
32
|
+
disabled={!canUpload}
|
|
33
|
+
multiple={true}
|
|
34
|
+
showUploadList={false}
|
|
35
|
+
>
|
|
36
|
+
<ActionIcon
|
|
37
|
+
disable={!canUpload}
|
|
38
|
+
icon={enabledFiles ? FileUp : LucideImage}
|
|
39
|
+
placement={'bottom'}
|
|
40
|
+
title={t(
|
|
41
|
+
canUpload
|
|
42
|
+
? enabledFiles
|
|
43
|
+
? 'upload.clientMode.actionFiletip'
|
|
44
|
+
: 'upload.clientMode.actionTooltip'
|
|
45
|
+
: 'upload.clientMode.disabled',
|
|
46
|
+
)}
|
|
47
|
+
/>
|
|
48
|
+
</Upload>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export default FileUpload;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ActionIcon, Icon, Tooltip } from '@lobehub/ui';
|
|
2
|
+
import { Dropdown, MenuProps, Upload } from 'antd';
|
|
3
|
+
import { css, cx } from 'antd-style';
|
|
4
|
+
import { FileUp, FolderUp, ImageUp, Paperclip } from 'lucide-react';
|
|
5
|
+
import { memo } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
|
|
8
|
+
import { useAgentStore } from '@/store/agent';
|
|
9
|
+
import { agentSelectors } from '@/store/agent/slices/chat';
|
|
10
|
+
import { useFileStore } from '@/store/file';
|
|
11
|
+
import { useUserStore } from '@/store/user';
|
|
12
|
+
import { modelProviderSelectors } from '@/store/user/selectors';
|
|
13
|
+
|
|
14
|
+
const hotArea = css`
|
|
15
|
+
&::before {
|
|
16
|
+
content: '';
|
|
17
|
+
position: absolute;
|
|
18
|
+
inset: 0;
|
|
19
|
+
background-color: transparent;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const FileUpload = memo(() => {
|
|
24
|
+
const { t } = useTranslation('chat');
|
|
25
|
+
|
|
26
|
+
const upload = useFileStore((s) => s.uploadChatFiles);
|
|
27
|
+
|
|
28
|
+
const model = useAgentStore(agentSelectors.currentAgentModel);
|
|
29
|
+
|
|
30
|
+
const canUploadImage = useUserStore(modelProviderSelectors.isModelEnabledVision(model));
|
|
31
|
+
|
|
32
|
+
const items: MenuProps['items'] = [
|
|
33
|
+
{
|
|
34
|
+
disabled: !canUploadImage,
|
|
35
|
+
icon: <Icon icon={ImageUp} />,
|
|
36
|
+
key: 'upload-image',
|
|
37
|
+
label: canUploadImage ? (
|
|
38
|
+
<Upload
|
|
39
|
+
accept={'image/*'}
|
|
40
|
+
beforeUpload={async (file) => {
|
|
41
|
+
await upload([file]);
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}}
|
|
45
|
+
multiple
|
|
46
|
+
showUploadList={false}
|
|
47
|
+
>
|
|
48
|
+
<div className={cx(hotArea)}>{t('upload.action.imageUpload')}</div>
|
|
49
|
+
</Upload>
|
|
50
|
+
) : (
|
|
51
|
+
<Tooltip placement={'right'} title={t('upload.action.imageDisabled')}>
|
|
52
|
+
<div className={cx(hotArea)}>{t('upload.action.imageUpload')}</div>
|
|
53
|
+
</Tooltip>
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
icon: <Icon icon={FileUp} />,
|
|
58
|
+
key: 'upload-file',
|
|
59
|
+
label: (
|
|
60
|
+
<Upload
|
|
61
|
+
beforeUpload={async (file) => {
|
|
62
|
+
if (!canUploadImage && file.type.startsWith('image')) return false;
|
|
63
|
+
|
|
64
|
+
await upload([file]);
|
|
65
|
+
|
|
66
|
+
return false;
|
|
67
|
+
}}
|
|
68
|
+
multiple
|
|
69
|
+
showUploadList={false}
|
|
70
|
+
>
|
|
71
|
+
<div className={cx(hotArea)}>{t('upload.action.fileUpload')}</div>
|
|
72
|
+
</Upload>
|
|
73
|
+
),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
icon: <Icon icon={FolderUp} />,
|
|
77
|
+
key: 'upload-folder',
|
|
78
|
+
label: (
|
|
79
|
+
<Upload
|
|
80
|
+
beforeUpload={async (file) => {
|
|
81
|
+
if (!canUploadImage && file.type.startsWith('image')) return false;
|
|
82
|
+
|
|
83
|
+
await upload([file]);
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
}}
|
|
87
|
+
directory
|
|
88
|
+
multiple={true}
|
|
89
|
+
showUploadList={false}
|
|
90
|
+
>
|
|
91
|
+
<div className={cx(hotArea)}>{t('upload.action.folderUpload')}</div>
|
|
92
|
+
</Upload>
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Dropdown menu={{ items }} placement="top">
|
|
99
|
+
<ActionIcon icon={Paperclip} placement={'bottom'} title={t('upload.action.tooltip')} />
|
|
100
|
+
</Dropdown>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export default FileUpload;
|