@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,164 @@
|
|
|
1
|
+
import { t } from 'i18next';
|
|
2
|
+
import { sha256 } from 'js-sha256';
|
|
3
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
4
|
+
|
|
5
|
+
import { message } from '@/components/AntdStaticMethods';
|
|
6
|
+
import { isServerMode } from '@/const/version';
|
|
7
|
+
import { fileService } from '@/services/file';
|
|
8
|
+
import { ServerService } from '@/services/file/server';
|
|
9
|
+
import { uploadService } from '@/services/upload';
|
|
10
|
+
import { FileMetadata, UploadFileItem } from '@/types/files';
|
|
11
|
+
|
|
12
|
+
import { FileStore } from '../../store';
|
|
13
|
+
|
|
14
|
+
const serverFileService = new ServerService();
|
|
15
|
+
|
|
16
|
+
interface UploadWithProgressParams {
|
|
17
|
+
file: File;
|
|
18
|
+
knowledgeBaseId?: string;
|
|
19
|
+
onStatusUpdate: (
|
|
20
|
+
data:
|
|
21
|
+
| {
|
|
22
|
+
id: string;
|
|
23
|
+
type: 'updateFile';
|
|
24
|
+
value: Partial<UploadFileItem>;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
id: string;
|
|
28
|
+
type: 'removeFile';
|
|
29
|
+
},
|
|
30
|
+
) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface UploadWithProgressResult {
|
|
34
|
+
id: string;
|
|
35
|
+
url: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface FileUploadAction {
|
|
39
|
+
internal_uploadToClientDB: (
|
|
40
|
+
params: Omit<UploadWithProgressParams, 'knowledgeBaseId'>,
|
|
41
|
+
) => Promise<UploadWithProgressResult | undefined>;
|
|
42
|
+
internal_uploadToServer: (params: UploadWithProgressParams) => Promise<UploadWithProgressResult>;
|
|
43
|
+
uploadWithProgress: (
|
|
44
|
+
params: UploadWithProgressParams,
|
|
45
|
+
) => Promise<UploadWithProgressResult | undefined>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const createFileUploadSlice: StateCreator<
|
|
49
|
+
FileStore,
|
|
50
|
+
[['zustand/devtools', never]],
|
|
51
|
+
[],
|
|
52
|
+
FileUploadAction
|
|
53
|
+
> = (set, get) => ({
|
|
54
|
+
internal_uploadToClientDB: async ({ file, onStatusUpdate }) => {
|
|
55
|
+
if (!file.type.startsWith('image')) {
|
|
56
|
+
onStatusUpdate({ id: file.name, type: 'removeFile' });
|
|
57
|
+
message.info({
|
|
58
|
+
content: t('upload.fileOnlySupportInServerMode', {
|
|
59
|
+
ext: file.name.split('.').pop(),
|
|
60
|
+
ns: 'error',
|
|
61
|
+
}),
|
|
62
|
+
duration: 5,
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const fileArrayBuffer = await file.arrayBuffer();
|
|
68
|
+
|
|
69
|
+
const hash = sha256(fileArrayBuffer);
|
|
70
|
+
|
|
71
|
+
const data = await uploadService.uploadToClientDB(
|
|
72
|
+
{ fileType: file.type, hash, name: file.name, saveMode: 'local', size: file.size },
|
|
73
|
+
file,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
onStatusUpdate({
|
|
77
|
+
id: file.name,
|
|
78
|
+
type: 'updateFile',
|
|
79
|
+
value: {
|
|
80
|
+
fileUrl: data.url,
|
|
81
|
+
id: data.id,
|
|
82
|
+
status: 'success',
|
|
83
|
+
uploadState: { progress: 100, restTime: 0, speed: 0 },
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return data;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
internal_uploadToServer: async ({ file, onStatusUpdate, knowledgeBaseId }) => {
|
|
91
|
+
const fileArrayBuffer = await file.arrayBuffer();
|
|
92
|
+
|
|
93
|
+
// 1. check file hash
|
|
94
|
+
const hash = sha256(fileArrayBuffer);
|
|
95
|
+
|
|
96
|
+
const checkStatus = await serverFileService.checkFileHash(hash);
|
|
97
|
+
let metadata: FileMetadata;
|
|
98
|
+
|
|
99
|
+
// 2. if file exist, just skip upload
|
|
100
|
+
if (checkStatus.isExist) {
|
|
101
|
+
metadata = checkStatus.metadata as FileMetadata;
|
|
102
|
+
onStatusUpdate({
|
|
103
|
+
id: file.name,
|
|
104
|
+
type: 'updateFile',
|
|
105
|
+
value: { status: 'processing', uploadState: { progress: 100, restTime: 0, speed: 0 } },
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
// 2. if file don't exist, need upload files
|
|
109
|
+
metadata = await uploadService.uploadWithProgress(file, (status, upload) => {
|
|
110
|
+
onStatusUpdate({
|
|
111
|
+
id: file.name,
|
|
112
|
+
type: 'updateFile',
|
|
113
|
+
value: { status: status === 'success' ? 'processing' : status, uploadState: upload },
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 3. use more powerful file type detector to get file type
|
|
119
|
+
let fileType = file.type;
|
|
120
|
+
|
|
121
|
+
if (!file.type) {
|
|
122
|
+
const { fileTypeFromBuffer } = await import('file-type');
|
|
123
|
+
|
|
124
|
+
const type = await fileTypeFromBuffer(fileArrayBuffer);
|
|
125
|
+
fileType = type?.mime || 'text/plain';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 4. create file to db
|
|
129
|
+
const data = await fileService.createFile(
|
|
130
|
+
{
|
|
131
|
+
createdAt: Date.now(),
|
|
132
|
+
fileType,
|
|
133
|
+
hash,
|
|
134
|
+
metadata,
|
|
135
|
+
name: file.name,
|
|
136
|
+
saveMode: 'url',
|
|
137
|
+
size: file.size,
|
|
138
|
+
url: metadata.path,
|
|
139
|
+
},
|
|
140
|
+
knowledgeBaseId,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
onStatusUpdate({
|
|
144
|
+
id: file.name,
|
|
145
|
+
type: 'updateFile',
|
|
146
|
+
value: {
|
|
147
|
+
fileUrl: data.url,
|
|
148
|
+
id: data.id,
|
|
149
|
+
status: 'success',
|
|
150
|
+
uploadState: { progress: 100, restTime: 0, speed: 0 },
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return data;
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
uploadWithProgress: async ({ file, onStatusUpdate, knowledgeBaseId }) => {
|
|
158
|
+
const { internal_uploadToServer, internal_uploadToClientDB } = get();
|
|
159
|
+
|
|
160
|
+
if (isServerMode) return internal_uploadToServer({ file, knowledgeBaseId, onStatusUpdate });
|
|
161
|
+
|
|
162
|
+
return internal_uploadToClientDB({ file, onStatusUpdate });
|
|
163
|
+
},
|
|
164
|
+
});
|
package/src/store/file/store.ts
CHANGED
|
@@ -5,16 +5,27 @@ import { StateCreator } from 'zustand/vanilla';
|
|
|
5
5
|
import { createDevtools } from '../middleware/createDevtools';
|
|
6
6
|
import { FilesStoreState, initialState } from './initialState';
|
|
7
7
|
import { FileAction, createFileSlice } from './slices/chat';
|
|
8
|
+
import { FileChunkAction, createFileChunkSlice } from './slices/chunk';
|
|
9
|
+
import { FileManageAction, createFileManageSlice } from './slices/fileManager';
|
|
8
10
|
import { TTSFileAction, createTTSFileSlice } from './slices/tts';
|
|
11
|
+
import { FileUploadAction, createFileUploadSlice } from './slices/upload/action';
|
|
9
12
|
|
|
10
13
|
// =============== 聚合 createStoreFn ============ //
|
|
11
14
|
|
|
12
|
-
export type FileStore = FilesStoreState &
|
|
15
|
+
export type FileStore = FilesStoreState &
|
|
16
|
+
FileAction &
|
|
17
|
+
TTSFileAction &
|
|
18
|
+
FileManageAction &
|
|
19
|
+
FileChunkAction &
|
|
20
|
+
FileUploadAction;
|
|
13
21
|
|
|
14
22
|
const createStore: StateCreator<FileStore, [['zustand/devtools', never]]> = (...parameters) => ({
|
|
15
23
|
...initialState,
|
|
16
24
|
...createFileSlice(...parameters),
|
|
25
|
+
...createFileManageSlice(...parameters),
|
|
17
26
|
...createTTSFileSlice(...parameters),
|
|
27
|
+
...createFileChunkSlice(...parameters),
|
|
28
|
+
...createFileUploadSlice(...parameters),
|
|
18
29
|
});
|
|
19
30
|
|
|
20
31
|
// =============== 实装 useStore ============ //
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slices/crud/selectors';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
2
|
+
|
|
3
|
+
import { knowledgeBaseService } from '@/services/knowledgeBase';
|
|
4
|
+
import { useFileStore } from '@/store/file';
|
|
5
|
+
import { KnowledgeBaseStore } from '@/store/knowledgeBase/store';
|
|
6
|
+
|
|
7
|
+
export interface KnowledgeBaseContentAction {
|
|
8
|
+
addFilesToKnowledgeBase: (knowledgeBaseId: string, ids: string[]) => Promise<void>;
|
|
9
|
+
removeFilesFromKnowledgeBase: (knowledgeBaseId: string, ids: string[]) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const createContentSlice: StateCreator<
|
|
13
|
+
KnowledgeBaseStore,
|
|
14
|
+
[['zustand/devtools', never]],
|
|
15
|
+
[],
|
|
16
|
+
KnowledgeBaseContentAction
|
|
17
|
+
> = () => ({
|
|
18
|
+
addFilesToKnowledgeBase: async (knowledgeBaseId, ids) => {
|
|
19
|
+
await knowledgeBaseService.addFilesToKnowledgeBase(knowledgeBaseId, ids);
|
|
20
|
+
await useFileStore.getState().refreshFileList();
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
removeFilesFromKnowledgeBase: async (knowledgeBaseId, ids) => {
|
|
24
|
+
await knowledgeBaseService.removeFilesFromKnowledgeBase(knowledgeBaseId, ids);
|
|
25
|
+
await useFileStore.getState().refreshFileList();
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './action';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SWRResponse, mutate } from 'swr';
|
|
2
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
3
|
+
|
|
4
|
+
import { useClientDataSWR } from '@/libs/swr';
|
|
5
|
+
import { knowledgeBaseService } from '@/services/knowledgeBase';
|
|
6
|
+
import { KnowledgeBaseStore } from '@/store/knowledgeBase/store';
|
|
7
|
+
import { CreateKnowledgeBaseParams, KnowledgeBaseItem } from '@/types/knowledgeBase';
|
|
8
|
+
|
|
9
|
+
const FETCH_KNOWLEDGE_BASE_LIST_KEY = 'FETCH_KNOWLEDGE_BASE';
|
|
10
|
+
const FETCH_KNOWLEDGE_BASE_ITEM_KEY = 'FETCH_KNOWLEDGE_BASE_ITEM';
|
|
11
|
+
|
|
12
|
+
export interface KnowledgeBaseCrudAction {
|
|
13
|
+
createNewKnowledgeBase: (params: CreateKnowledgeBaseParams) => Promise<void>;
|
|
14
|
+
internal_toggleKnowledgeBaseLoading: (id: string, loading: boolean) => void;
|
|
15
|
+
refreshKnowledgeBaseList: () => Promise<void>;
|
|
16
|
+
|
|
17
|
+
removeKnowledgeBase: (id: string) => Promise<void>;
|
|
18
|
+
updateKnowledgeBase: (id: string, value: CreateKnowledgeBaseParams) => Promise<void>;
|
|
19
|
+
|
|
20
|
+
useFetchKnowledgeBaseItem: (id: string) => SWRResponse<KnowledgeBaseItem | undefined>;
|
|
21
|
+
useFetchKnowledgeBaseList: (params?: { suspense?: boolean }) => SWRResponse<KnowledgeBaseItem[]>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const createCrudSlice: StateCreator<
|
|
25
|
+
KnowledgeBaseStore,
|
|
26
|
+
[['zustand/devtools', never]],
|
|
27
|
+
[],
|
|
28
|
+
KnowledgeBaseCrudAction
|
|
29
|
+
> = (set, get) => ({
|
|
30
|
+
createNewKnowledgeBase: async (params) => {
|
|
31
|
+
await knowledgeBaseService.createKnowledgeBase(params);
|
|
32
|
+
await get().refreshKnowledgeBaseList();
|
|
33
|
+
},
|
|
34
|
+
internal_toggleKnowledgeBaseLoading: (id, loading) => {
|
|
35
|
+
set(
|
|
36
|
+
(state) => {
|
|
37
|
+
if (loading) return { knowledgeBaseLoadingIds: [...state.knowledgeBaseLoadingIds, id] };
|
|
38
|
+
|
|
39
|
+
return { knowledgeBaseLoadingIds: state.knowledgeBaseLoadingIds.filter((i) => i !== id) };
|
|
40
|
+
},
|
|
41
|
+
false,
|
|
42
|
+
'toggleKnowledgeBaseLoading',
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
refreshKnowledgeBaseList: async () => {
|
|
46
|
+
await mutate(FETCH_KNOWLEDGE_BASE_LIST_KEY);
|
|
47
|
+
},
|
|
48
|
+
removeKnowledgeBase: async (id) => {
|
|
49
|
+
await knowledgeBaseService.deleteKnowledgeBase(id);
|
|
50
|
+
await get().refreshKnowledgeBaseList();
|
|
51
|
+
},
|
|
52
|
+
updateKnowledgeBase: async (id, value) => {
|
|
53
|
+
get().internal_toggleKnowledgeBaseLoading(id, true);
|
|
54
|
+
await knowledgeBaseService.updateKnowledgeBaseList(id, value);
|
|
55
|
+
await get().refreshKnowledgeBaseList();
|
|
56
|
+
|
|
57
|
+
get().internal_toggleKnowledgeBaseLoading(id, false);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
useFetchKnowledgeBaseItem: (id) =>
|
|
61
|
+
useClientDataSWR<KnowledgeBaseItem | undefined>([FETCH_KNOWLEDGE_BASE_ITEM_KEY, id], () =>
|
|
62
|
+
knowledgeBaseService.getKnowledgeBaseById(id),
|
|
63
|
+
),
|
|
64
|
+
|
|
65
|
+
useFetchKnowledgeBaseList: (params = {}) =>
|
|
66
|
+
useClientDataSWR<KnowledgeBaseItem[]>(
|
|
67
|
+
FETCH_KNOWLEDGE_BASE_LIST_KEY,
|
|
68
|
+
() => knowledgeBaseService.getKnowledgeBaseList(),
|
|
69
|
+
{
|
|
70
|
+
fallbackData: [],
|
|
71
|
+
onSuccess: () => {
|
|
72
|
+
if (!get().initKnowledgeBaseList)
|
|
73
|
+
set({ initKnowledgeBaseList: true }, false, 'useFetchKnowledgeBaseList/init');
|
|
74
|
+
},
|
|
75
|
+
suspense: params.suspense,
|
|
76
|
+
},
|
|
77
|
+
),
|
|
78
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface KnowledgeBaseState {
|
|
2
|
+
activeKnowledgeBaseId: string | null;
|
|
3
|
+
initKnowledgeBaseList: boolean;
|
|
4
|
+
knowledgeBaseLoadingIds: string[];
|
|
5
|
+
knowledgeBaseRenamingId?: string | null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const initialKnowledgeBaseState: KnowledgeBaseState = {
|
|
9
|
+
activeKnowledgeBaseId: null,
|
|
10
|
+
initKnowledgeBaseList: false,
|
|
11
|
+
knowledgeBaseLoadingIds: [],
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { shallow } from 'zustand/shallow';
|
|
2
|
+
import { createWithEqualityFn } from 'zustand/traditional';
|
|
3
|
+
import { StateCreator } from 'zustand/vanilla';
|
|
4
|
+
|
|
5
|
+
import { createDevtools } from '../middleware/createDevtools';
|
|
6
|
+
import { KnowledgeBaseStoreState, initialState } from './initialState';
|
|
7
|
+
import { KnowledgeBaseContentAction, createContentSlice } from './slices/content';
|
|
8
|
+
import { KnowledgeBaseCrudAction, createCrudSlice } from './slices/crud';
|
|
9
|
+
|
|
10
|
+
// =============== 聚合 createStoreFn ============ //
|
|
11
|
+
|
|
12
|
+
export type KnowledgeBaseStore = KnowledgeBaseStoreState &
|
|
13
|
+
KnowledgeBaseCrudAction &
|
|
14
|
+
KnowledgeBaseContentAction;
|
|
15
|
+
|
|
16
|
+
const createStore: StateCreator<KnowledgeBaseStore, [['zustand/devtools', never]]> = (
|
|
17
|
+
...parameters
|
|
18
|
+
) => ({
|
|
19
|
+
...initialState,
|
|
20
|
+
...createCrudSlice(...parameters),
|
|
21
|
+
...createContentSlice(...parameters),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// =============== 实装 useStore ============ //
|
|
25
|
+
const devtools = createDevtools('knowledgeBase');
|
|
26
|
+
|
|
27
|
+
export const useKnowledgeBaseStore = createWithEqualityFn<KnowledgeBaseStore>()(
|
|
28
|
+
devtools(createStore),
|
|
29
|
+
shallow,
|
|
30
|
+
);
|
|
@@ -8,12 +8,20 @@ const hideSyncAlert = (s: UserStore) => s.preference.hideSyncAlert;
|
|
|
8
8
|
|
|
9
9
|
const hideSettingsMoveGuide = (s: UserStore) => s.preference.guide?.moveSettingsToAvatar;
|
|
10
10
|
|
|
11
|
+
const showUploadFileInKnowledgeBaseTip = (s: UserStore) =>
|
|
12
|
+
s.preference.guide?.uploadFileInKnowledgeBase;
|
|
13
|
+
|
|
14
|
+
const shouldTriggerFileInKnowledgeBaseTip = (s: UserStore) =>
|
|
15
|
+
!(typeof s.preference.guide?.moveSettingsToAvatar === 'boolean');
|
|
16
|
+
|
|
11
17
|
const isPreferenceInit = (s: UserStore) => s.isUserStateInit;
|
|
12
18
|
|
|
13
19
|
export const preferenceSelectors = {
|
|
14
20
|
hideSettingsMoveGuide,
|
|
15
21
|
hideSyncAlert,
|
|
16
22
|
isPreferenceInit,
|
|
23
|
+
shouldTriggerFileInKnowledgeBaseTip,
|
|
24
|
+
showUploadFileInKnowledgeBaseTip,
|
|
17
25
|
useCmdEnterToSend,
|
|
18
26
|
userAllowTrace,
|
|
19
27
|
};
|
|
@@ -10,9 +10,11 @@ const currentSystemAgent = (s: UserStore) =>
|
|
|
10
10
|
const translation = (s: UserStore) => currentSystemAgent(s).translation;
|
|
11
11
|
const topic = (s: UserStore) => currentSystemAgent(s).topic;
|
|
12
12
|
const agentMeta = (s: UserStore) => currentSystemAgent(s).agentMeta;
|
|
13
|
+
const queryRewrite = (s: UserStore) => currentSystemAgent(s).queryRewrite;
|
|
13
14
|
|
|
14
15
|
export const systemAgentSelectors = {
|
|
15
16
|
agentMeta,
|
|
17
|
+
queryRewrite,
|
|
16
18
|
topic,
|
|
17
19
|
translation,
|
|
18
20
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Image } from '@lobehub/ui';
|
|
2
2
|
import { createStyles } from 'antd-style';
|
|
3
|
-
import {
|
|
4
|
-
import { CSSProperties, memo, useCallback } from 'react';
|
|
3
|
+
import { CSSProperties, memo } from 'react';
|
|
5
4
|
|
|
6
5
|
import { usePlatform } from '@/hooks/usePlatform';
|
|
7
6
|
import { useFileStore } from '@/store/file';
|
|
@@ -35,33 +34,14 @@ interface FileItemProps {
|
|
|
35
34
|
style?: CSSProperties;
|
|
36
35
|
}
|
|
37
36
|
const ImageFileItem = memo<FileItemProps>(({ editable, id, alwaysShowClose }) => {
|
|
38
|
-
const [useFetchFile
|
|
37
|
+
const [useFetchFile] = useFileStore((s) => [s.useFetchFile]);
|
|
39
38
|
const IMAGE_SIZE = editable ? MIN_IMAGE_SIZE : '100%';
|
|
40
39
|
const { data, isLoading } = useFetchFile(id);
|
|
41
40
|
const { styles, cx } = useStyles();
|
|
42
41
|
const { isSafari } = usePlatform();
|
|
43
42
|
|
|
44
|
-
const handleRemoveFile = useCallback(
|
|
45
|
-
(e: any) => {
|
|
46
|
-
e.stopPropagation();
|
|
47
|
-
removeFile(id);
|
|
48
|
-
},
|
|
49
|
-
[id],
|
|
50
|
-
);
|
|
51
|
-
|
|
52
43
|
return (
|
|
53
44
|
<Image
|
|
54
|
-
actions={
|
|
55
|
-
editable && (
|
|
56
|
-
<ActionIcon
|
|
57
|
-
className={styles.deleteButton}
|
|
58
|
-
glass
|
|
59
|
-
icon={Trash}
|
|
60
|
-
onClick={handleRemoveFile}
|
|
61
|
-
size={'small'}
|
|
62
|
-
/>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
45
|
alt={data?.name || id || ''}
|
|
66
46
|
alwaysShowActions={alwaysShowClose}
|
|
67
47
|
height={isSafari ? 'auto' : '100%'}
|
package/src/types/agent/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
import { FileItem } from '@/types/files';
|
|
4
|
+
import { KnowledgeBaseItem } from '@/types/knowledgeBase';
|
|
3
5
|
import { FewShots, LLMParams } from '@/types/llm';
|
|
4
6
|
|
|
5
7
|
export type TTSServer = 'openai' | 'edge' | 'microsoft';
|
|
@@ -18,6 +20,12 @@ export interface LobeAgentTTSConfig {
|
|
|
18
20
|
export interface LobeAgentConfig {
|
|
19
21
|
chatConfig: LobeAgentChatConfig;
|
|
20
22
|
fewShots?: FewShots;
|
|
23
|
+
files?: FileItem[];
|
|
24
|
+
id?: string;
|
|
25
|
+
/**
|
|
26
|
+
* knowledge bases
|
|
27
|
+
*/
|
|
28
|
+
knowledgeBases?: KnowledgeBaseItem[];
|
|
21
29
|
/**
|
|
22
30
|
* 角色所使用的语言模型
|
|
23
31
|
* @default gpt-4o-mini
|
|
@@ -39,6 +47,7 @@ export interface LobeAgentConfig {
|
|
|
39
47
|
* 系统角色
|
|
40
48
|
*/
|
|
41
49
|
systemRole: string;
|
|
50
|
+
|
|
42
51
|
/**
|
|
43
52
|
* 语音服务
|
|
44
53
|
*/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export enum AsyncTaskType {
|
|
2
|
+
Chunking = 'chunk',
|
|
3
|
+
Embedding = 'embedding',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum AsyncTaskStatus {
|
|
7
|
+
Error = 'error',
|
|
8
|
+
Pending = 'pending',
|
|
9
|
+
Processing = 'processing',
|
|
10
|
+
Success = 'success',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum AsyncTaskErrorType {
|
|
14
|
+
SDKError = 'SDKError',
|
|
15
|
+
ServerError = 'ServerError',
|
|
16
|
+
Timeout = 'TaskTimeout',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AsyncTaskError {
|
|
20
|
+
body: string | { detail: string };
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FileParsingTask {
|
|
25
|
+
chunkCount?: number | null;
|
|
26
|
+
chunkingError?: AsyncTaskError | null;
|
|
27
|
+
chunkingStatus?: AsyncTaskStatus | null;
|
|
28
|
+
embeddingError?: AsyncTaskError | null;
|
|
29
|
+
embeddingStatus?: AsyncTaskStatus | null;
|
|
30
|
+
finishEmbedding?: boolean;
|
|
31
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export enum ChunkStatus {
|
|
2
|
+
Error = 'error',
|
|
3
|
+
Processing = 'processing',
|
|
4
|
+
Success = 'success',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Elements {
|
|
8
|
+
element_id: string;
|
|
9
|
+
metadata: ChunkMetadata;
|
|
10
|
+
text: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ChunkMetadata {
|
|
15
|
+
coordinates: Coordinates;
|
|
16
|
+
languages: string[];
|
|
17
|
+
pageNumber?: number;
|
|
18
|
+
parent_id?: string;
|
|
19
|
+
text_as_html?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Coordinates {
|
|
23
|
+
layout_height: number;
|
|
24
|
+
layout_width: number;
|
|
25
|
+
points: number[][];
|
|
26
|
+
system: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FileChunk {
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
id: string;
|
|
32
|
+
index: number;
|
|
33
|
+
metadata: ChunkMetadata | null;
|
|
34
|
+
pageNumber?: number;
|
|
35
|
+
parentId?: string | null;
|
|
36
|
+
text: string;
|
|
37
|
+
type: string;
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface SemanticSearchChunk {
|
|
42
|
+
id: string;
|
|
43
|
+
metadata: ChunkMetadata | null;
|
|
44
|
+
pageNumber?: number | null;
|
|
45
|
+
similarity: number;
|
|
46
|
+
text: string | null;
|
|
47
|
+
type: string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ChatSemanticSearchChunk = Omit<SemanticSearchChunk, 'metadata' | 'type'>;
|
|
51
|
+
|
|
52
|
+
export * from './document';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export enum FilesTabs {
|
|
2
|
+
All = 'all',
|
|
3
|
+
Audios = 'audios',
|
|
4
|
+
Documents = 'documents',
|
|
5
|
+
Images = 'images',
|
|
6
|
+
Videos = 'videos',
|
|
7
|
+
Websites = 'websites',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
export interface FilePreview {
|
|
14
|
+
base64Url?: string;
|
|
15
|
+
data?: ArrayBuffer;
|
|
16
|
+
fileType: string;
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
saveMode: 'local' | 'url';
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FileItem {
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
size: number;
|
|
29
|
+
type: string;
|
|
30
|
+
updatedAt: Date;
|
|
31
|
+
url: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export * from './list';
|
|
35
|
+
export * from './upload';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { AsyncTaskStatus } from '@/types/asyncTask';
|
|
4
|
+
|
|
5
|
+
export interface FileListItem {
|
|
6
|
+
chunkCount: number | null;
|
|
7
|
+
chunkingError: any | null;
|
|
8
|
+
chunkingStatus?: AsyncTaskStatus | null;
|
|
9
|
+
createdAt: Date;
|
|
10
|
+
embeddingError: any | null;
|
|
11
|
+
embeddingStatus?: AsyncTaskStatus | null;
|
|
12
|
+
fileType: string;
|
|
13
|
+
finishEmbedding: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
size: number;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
url: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum SortType {
|
|
22
|
+
Asc = 'asc',
|
|
23
|
+
Desc = 'desc',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const QueryFileListSchema = z.object({
|
|
27
|
+
category: z.string().optional(),
|
|
28
|
+
knowledgeBaseId: z.string().optional(),
|
|
29
|
+
q: z.string().nullable().optional(),
|
|
30
|
+
showFilesInKnowledgeBase: z.boolean().default(false),
|
|
31
|
+
sortType: z.enum(['desc', 'asc']).optional(),
|
|
32
|
+
sorter: z.enum(['createdAt', 'size']).optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type QueryFileListSchemaType = z.infer<typeof QueryFileListSchema>;
|
|
36
|
+
|
|
37
|
+
export interface QueryFileListParams {
|
|
38
|
+
category?: string;
|
|
39
|
+
knowledgeBaseId?: string;
|
|
40
|
+
q?: string | null;
|
|
41
|
+
showFilesInKnowledgeBase?: boolean;
|
|
42
|
+
sortType?: string;
|
|
43
|
+
sorter?: string;
|
|
44
|
+
}
|