@lobehub/lobehub 2.0.0-next.72 → 2.0.0-next.74
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/desktop-pr-build.yml +7 -3
- package/CHANGELOG.md +50 -0
- package/apps/desktop/package.json +1 -0
- package/apps/desktop/src/main/controllers/LocalFileCtr.ts +55 -11
- package/apps/desktop/src/main/controllers/__tests__/LocalFileCtr.test.ts +153 -0
- package/changelog/v1.json +18 -0
- package/locales/en-US/tool.json +12 -1
- package/locales/zh-CN/tool.json +12 -1
- package/next.config.ts +5 -5
- package/package.json +2 -1
- package/packages/electron-client-ipc/src/types/localSystem.ts +4 -0
- package/scripts/prebuild.mts +16 -6
- package/src/app/(backend)/trpc/desktop/[trpc]/route.ts +6 -6
- package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +7 -4
- package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +4 -4
- package/src/app/[variants]/(main)/(mobile)/me/(home)/features/UserBanner.tsx +5 -6
- package/src/app/[variants]/(main)/(mobile)/me/(home)/features/useCategory.tsx +5 -8
- package/src/app/[variants]/(main)/(mobile)/me/(home)/index.tsx +25 -0
- package/src/app/[variants]/(main)/(mobile)/me/(home)/layout.tsx +13 -16
- package/src/app/[variants]/(main)/(mobile)/me/profile/features/Category.tsx +6 -6
- package/src/app/[variants]/(main)/(mobile)/me/profile/features/Header.tsx +3 -3
- package/src/app/[variants]/(main)/(mobile)/me/profile/index.tsx +16 -0
- package/src/app/[variants]/(main)/(mobile)/me/profile/layout.tsx +9 -11
- package/src/app/[variants]/(main)/(mobile)/me/settings/features/Header.tsx +3 -3
- package/src/app/[variants]/(main)/(mobile)/me/settings/features/useCategory.tsx +3 -4
- package/src/app/[variants]/(main)/(mobile)/me/settings/index.tsx +16 -0
- package/src/app/[variants]/(main)/(mobile)/me/settings/layout.tsx +15 -13
- package/src/app/[variants]/(main)/changelog/_layout/Desktop/index.tsx +6 -5
- package/src/app/[variants]/(main)/changelog/_layout/Mobile/Header.tsx +3 -3
- package/src/app/[variants]/(main)/changelog/_layout/Mobile/index.tsx +5 -5
- package/src/app/[variants]/(main)/changelog/features/Post.tsx +7 -4
- package/src/app/[variants]/(main)/changelog/index.tsx +55 -0
- package/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx +6 -7
- package/src/app/[variants]/(main)/chat/_layout/Mobile.tsx +3 -3
- package/src/app/[variants]/(main)/chat/components/WorkspaceLayout.tsx +1 -14
- package/src/app/[variants]/(main)/chat/components/conversation/features/ChatHydration/index.tsx +2 -2
- package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/Desktop/MessageFromUrl.tsx +11 -13
- package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/Desktop/index.tsx +0 -1
- package/src/app/[variants]/(main)/chat/components/conversation/features/ThreadHydration.tsx +2 -2
- package/src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/TopicContent.tsx +20 -11
- package/src/app/[variants]/(main)/chat/features/PageTitle/index.tsx +1 -2
- package/src/app/[variants]/(main)/chat/index.tsx +29 -0
- package/src/app/[variants]/(main)/chat/session/features/SessionHydration.tsx +8 -6
- package/src/app/[variants]/(main)/chat/session/features/SessionListContent/Inbox/index.tsx +2 -4
- package/src/app/[variants]/(main)/chat/session/features/SessionListContent/List/index.tsx +1 -1
- package/src/app/[variants]/(main)/chat/session/layout/Mobile/SessionHeader.tsx +3 -3
- package/src/app/[variants]/(main)/chat/settings/_layout/Desktop/Header.tsx +3 -3
- package/src/app/[variants]/(main)/chat/settings/_layout/Mobile/Header.tsx +3 -3
- package/src/app/[variants]/(main)/chat/settings/features/PublishResultModal/index.tsx +3 -3
- package/src/app/[variants]/(main)/chat/{components/SettingsPage.tsx → settings/index.tsx} +6 -35
- package/src/app/[variants]/(main)/components/Link.tsx +21 -0
- package/src/app/[variants]/(main)/discover/(detail)/_layout/{Desktop.tsx → Desktop/index.tsx} +15 -7
- package/src/app/[variants]/(main)/discover/(detail)/_layout/Mobile/index.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/Block.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Overview/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/SystemRole/index.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Versions/index.tsx +4 -4
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Header.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/ActionButton/AddAgent.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/ActionButton/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/Related/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/TocList/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/StatusPage/index.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(detail)/assistant/{AssistantDetailPage.tsx → index.tsx} +18 -11
- package/src/app/[variants]/(main)/discover/(detail)/features/Breadcrumb.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Details/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Details/Versions/index.tsx +5 -5
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Details/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/ServerConfig.tsx +4 -4
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/TocList/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/mcp/{McpDetailPage.tsx → index.tsx} +15 -7
- package/src/app/[variants]/(main)/discover/(detail)/mcp/loading.tsx +1 -0
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Overview/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Parameter/ParameterItem.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Header.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/ActionButton/ChatWithModel.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/ActionButton/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/RelatedProviders/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/{ModelDetailPage.tsx → index.tsx} +17 -10
- package/src/app/[variants]/(main)/discover/(detail)/model/loading.tsx +1 -0
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/ActionButton/ProviderConfig.tsx +5 -4
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/ActionButton/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/Related/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/RelatedModels/index.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(detail)/provider/{ProviderDetailPage.tsx → index.tsx} +17 -10
- package/src/app/[variants]/(main)/discover/(detail)/provider/loading.tsx +1 -0
- package/src/app/[variants]/(main)/discover/(list)/(home)/{HomePage.tsx → index.tsx} +14 -0
- package/src/app/[variants]/(main)/discover/(list)/_layout/Desktop/Nav.tsx +2 -3
- package/src/app/[variants]/(main)/discover/(list)/_layout/Desktop/index.tsx +4 -3
- package/src/app/[variants]/(main)/discover/(list)/_layout/Mobile/Nav.tsx +3 -4
- package/src/app/[variants]/(main)/discover/(list)/_layout/Mobile/index.tsx +4 -3
- package/src/app/[variants]/(main)/discover/(list)/assistant/_layout/Desktop.tsx +3 -4
- package/src/app/[variants]/(main)/discover/(list)/assistant/_layout/Mobile.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/Item.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(list)/assistant/{AssistantPage.tsx → index.tsx} +18 -4
- package/src/app/[variants]/(main)/discover/(list)/features/SortButton/index.tsx +2 -2
- package/src/app/[variants]/(main)/discover/(list)/mcp/_layout/Desktop.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(list)/mcp/_layout/Mobile.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(list)/mcp/features/List/Item.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(list)/mcp/{McpPage.tsx → index.tsx} +9 -2
- package/src/app/[variants]/(main)/discover/(list)/model/_layout/Desktop.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(list)/model/_layout/Mobile.tsx +3 -3
- package/src/app/[variants]/(main)/discover/(list)/model/features/List/Item.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(list)/model/{ModelPage.tsx → index.tsx} +9 -2
- package/src/app/[variants]/(main)/discover/(list)/provider/features/List/Item.tsx +1 -1
- package/src/app/[variants]/(main)/discover/(list)/provider/{Client.tsx → index.tsx} +9 -2
- package/src/app/[variants]/(main)/discover/_layout/Desktop/index.tsx +4 -4
- package/src/app/[variants]/(main)/discover/_layout/Mobile/index.tsx +3 -3
- package/src/app/[variants]/(main)/discover/components/Title.tsx +1 -1
- package/src/app/[variants]/(main)/discover/features/Search.tsx +2 -2
- package/src/app/[variants]/(main)/discover/features/useNav.tsx +11 -12
- package/src/app/[variants]/(main)/hooks/useActiveTabKey.ts +40 -0
- package/src/app/[variants]/(main)/hooks/usePathname.ts +10 -0
- package/src/app/[variants]/(main)/hooks/useQuery.ts +12 -0
- package/src/app/[variants]/(main)/hooks/useRouter.ts +22 -0
- package/src/app/[variants]/(main)/hooks/useSearchParams.ts +11 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ModelSelect/index.tsx +5 -5
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicUrlSync.tsx +1 -1
- package/src/app/[variants]/(main)/image/ComingSoon.tsx +15 -0
- package/src/app/[variants]/(main)/image/_layout/Desktop/index.tsx +5 -2
- package/src/app/[variants]/(main)/image/_layout/DesktopWrapper.tsx +15 -0
- package/src/app/[variants]/(main)/image/_layout/Mobile/index.tsx +3 -1
- package/src/app/[variants]/(main)/image/features/ImageWorkspace/index.tsx +1 -2
- package/src/app/[variants]/(main)/image/index.tsx +18 -0
- package/src/app/[variants]/(main)/knowledge/_layout/Desktop.tsx +17 -0
- package/src/app/[variants]/(main)/knowledge/_layout/Mobile.tsx +17 -0
- package/src/app/[variants]/(main)/knowledge/components/KnowledgeBaseItem/index.tsx +1 -1
- package/src/app/[variants]/(main)/knowledge/components/modal/ModalPageClient.tsx +4 -4
- package/src/app/[variants]/(main)/knowledge/routes/KnowledgeBaseDetail/index.tsx +5 -8
- package/src/app/[variants]/(main)/knowledge/routes/KnowledgeBaseDetail/menu/Head.tsx +1 -1
- package/src/app/[variants]/(main)/knowledge/routes/KnowledgeHome/menu/CategoryMenu.tsx +2 -2
- package/src/app/[variants]/(main)/knowledge/routes/KnowledgeHome/menu/KnowledgeBase.tsx +1 -1
- package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/DesktopLayoutContainer.tsx +3 -2
- package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/BottomActions.tsx +4 -4
- package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/TopActions.test.tsx +9 -9
- package/src/app/[variants]/(main)/layouts/desktop/SideBar/TopActions.tsx +117 -0
- package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/index.tsx +9 -4
- package/src/app/[variants]/(main)/layouts/index.tsx +11 -0
- package/src/app/[variants]/(main)/{_layout/Mobile → layouts/mobile}/NavBar.tsx +5 -5
- package/src/app/[variants]/(main)/{_layout/Mobile → layouts/mobile}/index.tsx +10 -7
- package/src/app/[variants]/(main)/profile/(home)/desktop.tsx +26 -0
- package/src/app/[variants]/(main)/profile/(home)/index.tsx +26 -0
- package/src/app/[variants]/(main)/profile/@category/features/CategoryContent.tsx +5 -7
- package/src/app/[variants]/(main)/profile/_layout/Desktop/index.tsx +3 -2
- package/src/app/[variants]/(main)/profile/_layout/DesktopWrapper.tsx +14 -0
- package/src/app/[variants]/(main)/profile/_layout/Mobile/Header.tsx +3 -3
- package/src/app/[variants]/(main)/profile/_layout/Mobile/index.tsx +4 -3
- package/src/app/[variants]/(main)/profile/apikey/index.tsx +18 -0
- package/src/app/[variants]/(main)/profile/hooks/useCategory.tsx +6 -6
- package/src/app/[variants]/(main)/profile/security/index.tsx +29 -0
- package/src/app/[variants]/(main)/profile/stats/features/AssistantsRank.tsx +4 -4
- package/src/app/[variants]/(main)/profile/stats/features/TopicsRank.tsx +4 -4
- package/src/app/[variants]/(main)/profile/stats/index.tsx +20 -0
- package/src/app/[variants]/(main)/profile/usage/features/UsageTable.tsx +7 -9
- package/src/app/[variants]/(main)/profile/usage/index.tsx +13 -0
- package/src/app/[variants]/(main)/settings/_layout/Desktop/Header.tsx +2 -2
- package/src/app/[variants]/(main)/settings/_layout/Desktop/index.tsx +2 -2
- package/src/app/[variants]/(main)/settings/_layout/DesktopWrapper.tsx +23 -0
- package/src/app/[variants]/(main)/settings/_layout/Mobile/Header.tsx +8 -7
- package/src/app/[variants]/(main)/settings/_layout/Mobile/index.tsx +2 -5
- package/src/app/[variants]/(main)/settings/_layout/MobileWrapper.tsx +23 -0
- package/src/app/[variants]/(main)/settings/agent/AgentMenu/Menu.tsx +2 -4
- package/src/app/[variants]/(main)/settings/agent/index.tsx +2 -4
- package/src/app/[variants]/(main)/settings/provider/(list)/index.tsx +2 -3
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/All.tsx +2 -2
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/Item.tsx +38 -37
- package/src/app/[variants]/(main)/settings/provider/_layout/Mobile.tsx +2 -2
- package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +3 -3
- package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/UpdateProviderInfo/SettingModal.tsx +3 -3
- package/src/app/[variants]/DesktopRouter.tsx +40 -0
- package/src/app/[variants]/MobileRouter.tsx +41 -0
- package/src/app/[variants]/desktopRouter.config.tsx +364 -0
- package/src/app/[variants]/layout.tsx +1 -3
- package/src/app/[variants]/loaders/routeParams.ts +45 -0
- package/src/app/[variants]/loading/Server/Redirect.tsx +1 -1
- package/src/app/[variants]/mobileRouter.config.tsx +396 -0
- package/src/app/[variants]/page.tsx +17 -6
- package/src/app/desktop/devtools/page.tsx +1 -1
- package/src/app/desktop/layout.tsx +1 -1
- package/src/components/BootErrorBoundary/index.tsx +129 -0
- package/src/components/mdx/constants.ts +1 -0
- package/src/features/ChangelogModal/index.tsx +3 -3
- package/src/features/Conversation/Messages/Group/Tool/Inspector/index.tsx +23 -4
- package/src/features/KnowledgeManager/FileExplorer/index.tsx +4 -4
- package/src/features/KnowledgeManager/Header/FilesSearchBar.tsx +1 -1
- package/src/features/User/UserPanel/PanelContent.tsx +4 -3
- package/src/features/User/UserPanel/useMenu.tsx +20 -14
- package/src/features/User/__tests__/PanelContent.test.tsx +13 -7
- package/src/hooks/useDiscoverTab.ts +2 -2
- package/src/hooks/useInterceptingRoutes.test.ts +23 -26
- package/src/hooks/useInterceptingRoutes.ts +5 -4
- package/src/hooks/usePinnedAgentState.ts +6 -6
- package/src/hooks/useQuery.ts +5 -0
- package/src/hooks/useQueryParam.ts +322 -0
- package/src/hooks/useQueryRoute.test.ts +2 -12
- package/src/hooks/useQueryRoute.ts +5 -5
- package/src/hooks/useShowMobileWorkspace.ts +1 -1
- package/src/hooks/useSwitchSession.ts +4 -3
- package/src/layout/GlobalProvider/ImportSettings.tsx +22 -9
- package/src/layout/GlobalProvider/StoreInitialization.tsx +9 -1
- package/src/locales/default/tool.ts +11 -0
- package/src/proxy.ts +13 -1
- package/src/services/message/index.ts +11 -2
- package/src/store/chat/agents/createAgentExecutors.ts +31 -16
- package/src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts +218 -0
- package/src/store/chat/slices/aiChat/actions/conversationControl.ts +4 -0
- package/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts +9 -3
- package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +142 -61
- package/src/store/chat/slices/builtinTool/actions/__tests__/localSystem.test.ts +5 -6
- package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +204 -10
- package/src/store/chat/slices/builtinTool/actions/localSystem.ts +45 -182
- package/src/store/chat/slices/builtinTool/actions/search.ts +51 -26
- package/src/store/chat/slices/message/action.test.ts +182 -33
- package/src/store/chat/slices/message/actions/optimisticUpdate.ts +79 -36
- package/src/store/chat/slices/message/actions/query.ts +7 -5
- package/src/store/chat/slices/message/selectors/dbMessage.ts +11 -4
- package/src/store/chat/slices/plugin/action.test.ts +257 -54
- package/src/store/chat/slices/plugin/actions/optimisticUpdate.ts +63 -26
- package/src/store/chat/slices/plugin/actions/pluginTypes.ts +52 -19
- package/src/store/chat/slices/plugin/actions/publicApi.ts +6 -1
- package/src/store/chat/slices/plugin/actions/workflow.ts +17 -6
- package/src/store/chat/slices/thread/action.ts +2 -0
- package/src/store/global/action.test.ts +3 -3
- package/src/store/global/actions/workspacePane.ts +2 -1
- package/src/store/global/initialState.ts +10 -2
- package/src/store/user/slices/common/action.ts +4 -0
- package/src/tools/executionRuntimes.ts +3 -0
- package/src/tools/local-system/ExecutionRuntime/index.ts +407 -0
- package/src/tools/local-system/Intervention/EditLocalFile/index.tsx +89 -0
- package/src/tools/local-system/Intervention/WriteFile/index.tsx +72 -0
- package/src/tools/local-system/Intervention/index.ts +4 -0
- package/src/tools/local-system/Render/EditLocalFile/index.tsx +67 -0
- package/src/tools/local-system/Render/ReadLocalFile/ReadFileView.tsx +53 -78
- package/src/tools/local-system/Render/index.ts +2 -0
- package/src/tools/local-system/index.ts +1 -0
- package/src/tools/local-system/type.ts +4 -3
- package/src/app/[variants]/(main)/(mobile)/me/(home)/loading.tsx +0 -38
- package/src/app/[variants]/(main)/(mobile)/me/(home)/page.tsx +0 -40
- package/src/app/[variants]/(main)/(mobile)/me/profile/loading.tsx +0 -5
- package/src/app/[variants]/(main)/(mobile)/me/profile/page.tsx +0 -30
- package/src/app/[variants]/(main)/(mobile)/me/settings/loading.tsx +0 -5
- package/src/app/[variants]/(main)/(mobile)/me/settings/page.tsx +0 -30
- package/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx +0 -106
- package/src/app/[variants]/(main)/changelog/layout.tsx +0 -10
- package/src/app/[variants]/(main)/changelog/modal/page.tsx +0 -23
- package/src/app/[variants]/(main)/changelog/page.tsx +0 -78
- package/src/app/[variants]/(main)/chat/ChatRouter.tsx +0 -83
- package/src/app/[variants]/(main)/chat/_layout/ChatLayout.tsx +0 -22
- package/src/app/[variants]/(main)/chat/components/MainChatPage.tsx +0 -25
- package/src/app/[variants]/(main)/chat/error.tsx +0 -3
- package/src/app/[variants]/(main)/chat/layout.tsx +0 -10
- package/src/app/[variants]/(main)/chat/loading.tsx +0 -3
- package/src/app/[variants]/(main)/chat/not-found.tsx +0 -1
- package/src/app/[variants]/(main)/chat/page.tsx +0 -12
- package/src/app/[variants]/(main)/chat/settings/error.tsx +0 -3
- package/src/app/[variants]/(main)/chat/settings/loading.tsx +0 -3
- package/src/app/[variants]/(main)/chat/settings/not-found.tsx +0 -1
- package/src/app/[variants]/(main)/discover/(detail)/_layout/DetailLayout.tsx +0 -22
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/Client.tsx +0 -51
- package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/Client.tsx +0 -43
- package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/loading.tsx +0 -1
- package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/Client.tsx +0 -40
- package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/loading.tsx +0 -1
- package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/Client.tsx +0 -40
- package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/loading.tsx +0 -1
- package/src/app/[variants]/(main)/discover/(list)/_layout/ListLayout.tsx +0 -22
- package/src/app/[variants]/(main)/discover/(list)/assistant/AssistantLayout.tsx +0 -21
- package/src/app/[variants]/(main)/discover/(list)/mcp/Client.tsx +0 -44
- package/src/app/[variants]/(main)/discover/(list)/mcp/McpLayout.tsx +0 -21
- package/src/app/[variants]/(main)/discover/(list)/model/Client.tsx +0 -44
- package/src/app/[variants]/(main)/discover/(list)/model/ModelLayout.tsx +0 -21
- package/src/app/[variants]/(main)/discover/(list)/provider/ProviderPage.tsx +0 -43
- package/src/app/[variants]/(main)/discover/DiscoverRouter.tsx +0 -170
- package/src/app/[variants]/(main)/discover/[[...path]]/page.tsx +0 -12
- package/src/app/[variants]/(main)/discover/_layout/DiscoverLayout.tsx +0 -22
- package/src/app/[variants]/(main)/discover/error.tsx +0 -3
- package/src/app/[variants]/(main)/discover/not-found.tsx +0 -1
- package/src/app/[variants]/(main)/error.tsx +0 -3
- package/src/app/[variants]/(main)/image/layout.tsx +0 -15
- package/src/app/[variants]/(main)/image/page.tsx +0 -45
- package/src/app/[variants]/(main)/knowledge/KnowledgeRouter.tsx +0 -74
- package/src/app/[variants]/(main)/knowledge/[[...path]]/page.tsx +0 -12
- package/src/app/[variants]/(main)/knowledge/components/modal/page.tsx +0 -13
- package/src/app/[variants]/(main)/knowledge/layout.tsx +0 -12
- package/src/app/[variants]/(main)/layout.tsx +0 -10
- package/src/app/[variants]/(main)/not-found.tsx +0 -1
- package/src/app/[variants]/(main)/profile/apikey/page.tsx +0 -32
- package/src/app/[variants]/(main)/profile/error.tsx +0 -3
- package/src/app/[variants]/(main)/profile/layout.tsx +0 -11
- package/src/app/[variants]/(main)/profile/loading.tsx +0 -3
- package/src/app/[variants]/(main)/profile/not-found.tsx +0 -1
- package/src/app/[variants]/(main)/profile/security/page.tsx +0 -28
- package/src/app/[variants]/(main)/profile/stats/page.tsx +0 -23
- package/src/app/[variants]/(main)/profile/usage/page.tsx +0 -23
- package/src/app/[variants]/@modal/(.)changelog/modal/features/Cover.tsx +0 -48
- package/src/app/[variants]/@modal/(.)changelog/modal/features/Hero.tsx +0 -29
- package/src/app/[variants]/@modal/(.)changelog/modal/features/Post.tsx +0 -57
- package/src/app/[variants]/@modal/(.)changelog/modal/features/PublishedTime.tsx +0 -50
- package/src/app/[variants]/@modal/(.)changelog/modal/features/ReadDetail.tsx +0 -72
- package/src/app/[variants]/@modal/(.)changelog/modal/features/VersionTag.tsx +0 -26
- package/src/app/[variants]/@modal/(.)changelog/modal/layout.tsx +0 -41
- package/src/app/[variants]/@modal/(.)changelog/modal/loading.tsx +0 -10
- package/src/app/[variants]/@modal/(.)changelog/modal/page.tsx +0 -38
- package/src/app/[variants]/@modal/_layout/ModalLayout.tsx +0 -63
- package/src/app/[variants]/@modal/_layout/SettingModalLayout.tsx +0 -71
- package/src/app/[variants]/@modal/default.tsx +0 -3
- package/src/app/[variants]/@modal/error.tsx +0 -3
- package/src/app/[variants]/@modal/layout.tsx +0 -7
- package/src/app/[variants]/@modal/loading.tsx +0 -5
- /package/src/app/[variants]/{@modal/(.)changelog/modal → (main)/changelog}/features/Pagination.tsx +0 -0
- /package/src/app/[variants]/{@modal/(.)changelog/modal → (main)/changelog}/features/UpdateChangelogStatus.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/DetailProvider.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/Knowledge.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/KnowledgeItem.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/PluginItem.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/Plugins.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Capabilities/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Nav.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/Overview/TagList.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Details/SystemRole/TagList.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/Related/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/Summary/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/features → features}/Sidebar/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/assistant/{[...slugs]/loading.tsx → loading.tsx} +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/ActionButton/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/ConnectionTypeAlert.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/Related/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/mcp/{[slug]/features → features}/Sidebar/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/DetailProvider.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Nav.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Overview/ProviderList/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Details/Parameter/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/Related/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/RelatedProviders/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/model/{[...slugs]/features → features}/Sidebar/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/DetailProvider.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/Guide/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/Nav.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/Overview/ModelList/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Details/Overview/index.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Header.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/Related/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/RelatedModels/Item.tsx +0 -0
- /package/src/app/[variants]/(main)/discover/(detail)/provider/{[...slugs]/features → features}/Sidebar/index.tsx +0 -0
- /package/src/app/[variants]/(main)/labs/{page.tsx → index.tsx} +0 -0
- /package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/RegisterHotkeys.tsx +0 -0
- /package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/Avatar.test.tsx +0 -0
- /package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/Avatar.tsx +0 -0
- /package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/PinList/index.tsx +0 -0
- /package/src/app/[variants]/(main)/{_layout/Desktop → layouts/desktop}/SideBar/index.tsx +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useSearchParams } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
type HistoryMode = 'push' | 'replace';
|
|
5
|
+
|
|
6
|
+
// options 接口,用于 useQueryParam hook
|
|
7
|
+
interface QueryParamOptions<T> {
|
|
8
|
+
clearOnDefault?: boolean;
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
history?: HistoryMode;
|
|
11
|
+
throttleMs?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 解析器接口
|
|
15
|
+
interface Parser<T> {
|
|
16
|
+
parse: (value: string | null) => T;
|
|
17
|
+
serialize: (value: T) => string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 带默认值的解析器接口
|
|
21
|
+
interface ParserWithDefault<T> extends Parser<T> {
|
|
22
|
+
// nuqs has an optional default value on parsers
|
|
23
|
+
defaultValue?: T;
|
|
24
|
+
parse: (value: string | null) => T;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 核心钩子,用于管理单个查询参数
|
|
29
|
+
* 为 react-router-dom 替换 nuqs 的 useQueryState 功能
|
|
30
|
+
*/
|
|
31
|
+
export function useQueryParam<T>(
|
|
32
|
+
key: string,
|
|
33
|
+
parser: Parser<T> | ParserWithDefault<T>,
|
|
34
|
+
options: QueryParamOptions<T> = {},
|
|
35
|
+
): [T, (value: T | ((prev: T) => T)) => void] {
|
|
36
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
37
|
+
|
|
38
|
+
// 从 options 或 parser 本身提取 defaultValue
|
|
39
|
+
const {
|
|
40
|
+
clearOnDefault = false,
|
|
41
|
+
defaultValue = (parser as ParserWithDefault<T>)?.defaultValue,
|
|
42
|
+
history = 'push',
|
|
43
|
+
throttleMs = 0,
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
// eslint-disable-next-line no-undef
|
|
47
|
+
const throttleTimer = useRef<NodeJS.Timeout | null>(null);
|
|
48
|
+
const lastExecuteTime = useRef<number>(0);
|
|
49
|
+
|
|
50
|
+
// 使用 ref 存储最新的值,让 setValue 保持稳定
|
|
51
|
+
const searchParamsRef = useRef(searchParams);
|
|
52
|
+
const parserRef = useRef(parser);
|
|
53
|
+
const defaultValueRef = useRef(defaultValue);
|
|
54
|
+
const clearOnDefaultRef = useRef(clearOnDefault);
|
|
55
|
+
const historyRef = useRef(history);
|
|
56
|
+
|
|
57
|
+
// 每次渲染时更新 ref
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
searchParamsRef.current = searchParams;
|
|
60
|
+
parserRef.current = parser;
|
|
61
|
+
defaultValueRef.current = defaultValue;
|
|
62
|
+
clearOnDefaultRef.current = clearOnDefault;
|
|
63
|
+
historyRef.current = history;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 从 URL 解析当前值
|
|
67
|
+
const currentValue = parser.parse(searchParams.get(key));
|
|
68
|
+
const value = currentValue ?? (defaultValue as T);
|
|
69
|
+
|
|
70
|
+
// setValue 现在是稳定的,不会因为 searchParams 变化而重新创建
|
|
71
|
+
const setValue = useCallback(
|
|
72
|
+
(newValue: T | ((prev: T) => T)) => {
|
|
73
|
+
// 从 ref 读取最新值,避免闭包陈旧值问题
|
|
74
|
+
const currentSearchParams = searchParamsRef.current;
|
|
75
|
+
const currentParser = parserRef.current;
|
|
76
|
+
const currentDefaultValue = defaultValueRef.current;
|
|
77
|
+
const currentClearOnDefault = clearOnDefaultRef.current;
|
|
78
|
+
const currentHistory = historyRef.current;
|
|
79
|
+
|
|
80
|
+
// 通过函数形式获取最新值
|
|
81
|
+
const currentVal =
|
|
82
|
+
currentParser.parse(currentSearchParams.get(key)) ?? (currentDefaultValue as T);
|
|
83
|
+
const actualValue =
|
|
84
|
+
typeof newValue === 'function' ? (newValue as (prev: T) => T)(currentVal) : newValue;
|
|
85
|
+
|
|
86
|
+
const updateParams = () => {
|
|
87
|
+
// 使用函数式更新,确保基于最新的 searchParams
|
|
88
|
+
setSearchParams((prevParams) => {
|
|
89
|
+
const newSearchParams = new URLSearchParams(prevParams);
|
|
90
|
+
console.log('updateParams', newSearchParams.toString());
|
|
91
|
+
const serialized = currentParser.serialize(actualValue);
|
|
92
|
+
|
|
93
|
+
// 处理 clearOnDefault 选项
|
|
94
|
+
if (
|
|
95
|
+
currentClearOnDefault &&
|
|
96
|
+
currentDefaultValue !== undefined &&
|
|
97
|
+
serialized === currentParser.serialize(currentDefaultValue as T)
|
|
98
|
+
) {
|
|
99
|
+
newSearchParams.delete(key);
|
|
100
|
+
} else if (serialized === null || serialized === undefined) {
|
|
101
|
+
newSearchParams.delete(key);
|
|
102
|
+
} else {
|
|
103
|
+
newSearchParams.set(key, serialized);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log('updateParams', newSearchParams.toString());
|
|
107
|
+
|
|
108
|
+
return newSearchParams;
|
|
109
|
+
}, { replace: currentHistory === 'replace' });
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// 处理节流
|
|
113
|
+
if (throttleMs > 0) {
|
|
114
|
+
const now = Date.now();
|
|
115
|
+
const timeSinceLastExecute = now - lastExecuteTime.current;
|
|
116
|
+
|
|
117
|
+
if (timeSinceLastExecute >= throttleMs) {
|
|
118
|
+
// 距离上次执行已超过节流时间,立即执行
|
|
119
|
+
lastExecuteTime.current = now;
|
|
120
|
+
updateParams();
|
|
121
|
+
// 清理可能存在的定时器
|
|
122
|
+
if (throttleTimer.current) {
|
|
123
|
+
clearTimeout(throttleTimer.current);
|
|
124
|
+
throttleTimer.current = null;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
// 还在节流期内,设置定时器在剩余时间后执行最后一次
|
|
128
|
+
if (throttleTimer.current) {
|
|
129
|
+
clearTimeout(throttleTimer.current);
|
|
130
|
+
}
|
|
131
|
+
const remainingTime = throttleMs - timeSinceLastExecute;
|
|
132
|
+
throttleTimer.current = setTimeout(() => {
|
|
133
|
+
lastExecuteTime.current = Date.now();
|
|
134
|
+
updateParams();
|
|
135
|
+
throttleTimer.current = null;
|
|
136
|
+
}, remainingTime);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
updateParams();
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[key, setSearchParams, throttleMs], // 只依赖不会频繁变化的值
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// 组件卸载时清理节流计时器
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
return () => {
|
|
148
|
+
if (throttleTimer.current) {
|
|
149
|
+
clearTimeout(throttleTimer.current);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
return [value, setValue];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ===== 解析器 (Parsers) =====
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 字符串解析器 - 默认行为
|
|
161
|
+
*/
|
|
162
|
+
export const parseAsString: Parser<string | null> & {
|
|
163
|
+
withDefault: (defaultValue: string) => ParserWithDefault<string>;
|
|
164
|
+
} = {
|
|
165
|
+
parse: (value: string | null) => value,
|
|
166
|
+
serialize: (value: string | null) => value,
|
|
167
|
+
withDefault: (defaultValue: string) => ({
|
|
168
|
+
defaultValue,
|
|
169
|
+
parse: (value: string | null) => value ?? defaultValue,
|
|
170
|
+
serialize: (value: string) => value,
|
|
171
|
+
}),
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 布尔值解析器
|
|
176
|
+
*/
|
|
177
|
+
export const parseAsBoolean: Parser<boolean | null> & {
|
|
178
|
+
withDefault: (defaultValue: boolean) => ParserWithDefault<boolean>;
|
|
179
|
+
} = {
|
|
180
|
+
parse: (value: string | null) => {
|
|
181
|
+
if (value === null) return null;
|
|
182
|
+
return value === 'true' || value === '1';
|
|
183
|
+
},
|
|
184
|
+
serialize: (value: boolean | null) => {
|
|
185
|
+
if (value === null) return null;
|
|
186
|
+
return value ? 'true' : 'false';
|
|
187
|
+
},
|
|
188
|
+
withDefault: (defaultValue: boolean) => ({
|
|
189
|
+
defaultValue,
|
|
190
|
+
parse: (value: string | null) => {
|
|
191
|
+
if (value === null) return defaultValue;
|
|
192
|
+
return value === 'true' || value === '1';
|
|
193
|
+
},
|
|
194
|
+
serialize: (value: boolean) => (value ? 'true' : 'false'),
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 整数解析器
|
|
200
|
+
*/
|
|
201
|
+
export const parseAsInteger: Parser<number | null> & {
|
|
202
|
+
withDefault: (defaultValue: number) => ParserWithDefault<number>;
|
|
203
|
+
} = {
|
|
204
|
+
parse: (value: string | null) => {
|
|
205
|
+
if (value === null) return null;
|
|
206
|
+
const parsed = Number.parseInt(value, 10);
|
|
207
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
208
|
+
},
|
|
209
|
+
serialize: (value: number | null) => {
|
|
210
|
+
if (value === null) return null;
|
|
211
|
+
return value.toString();
|
|
212
|
+
},
|
|
213
|
+
withDefault: (defaultValue: number) => ({
|
|
214
|
+
defaultValue,
|
|
215
|
+
parse: (value: string | null) => {
|
|
216
|
+
if (value === null) return defaultValue;
|
|
217
|
+
const parsed = Number.parseInt(value, 10);
|
|
218
|
+
return Number.isNaN(parsed) ? defaultValue : parsed;
|
|
219
|
+
},
|
|
220
|
+
serialize: (value: number) => value.toString(),
|
|
221
|
+
}),
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 字符串枚举解析器
|
|
226
|
+
*/
|
|
227
|
+
export function parseAsStringEnum<T extends string>(validValues: readonly T[]) {
|
|
228
|
+
const parser: Parser<T | null> = {
|
|
229
|
+
parse: (value: string | null): T | null => {
|
|
230
|
+
if (value === null) return null;
|
|
231
|
+
return validValues.includes(value as T) ? (value as T) : null;
|
|
232
|
+
},
|
|
233
|
+
serialize: (value: T | null) => value,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const withDefault = (defaultValue: T): ParserWithDefault<T> => ({
|
|
237
|
+
defaultValue,
|
|
238
|
+
parse: (value: string | null): T => {
|
|
239
|
+
if (value === null) return defaultValue;
|
|
240
|
+
return validValues.includes(value as T) ? (value as T) : defaultValue;
|
|
241
|
+
},
|
|
242
|
+
serialize: (value: T) => value,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return Object.assign(parser, { withDefault });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ===== 简化的 API (Simplified API) =====
|
|
249
|
+
|
|
250
|
+
// --- 重载签名 ---
|
|
251
|
+
|
|
252
|
+
// 字符串 (无解析器或仅有 options)
|
|
253
|
+
export function useQueryState(
|
|
254
|
+
key: string,
|
|
255
|
+
options?: QueryParamOptions<string | null>,
|
|
256
|
+
): [string | null, (value: string | null | ((prev: string | null) => string | null)) => void];
|
|
257
|
+
|
|
258
|
+
// 带默认值的字符串解析器
|
|
259
|
+
// eslint-disable-next-line no-redeclare
|
|
260
|
+
export function useQueryState(
|
|
261
|
+
key: string,
|
|
262
|
+
parserWithDefault: ParserWithDefault<string>,
|
|
263
|
+
): [string, (value: string | ((prev: string) => string)) => void];
|
|
264
|
+
|
|
265
|
+
// 布尔值解析器
|
|
266
|
+
// eslint-disable-next-line no-redeclare
|
|
267
|
+
export function useQueryState(
|
|
268
|
+
key: string,
|
|
269
|
+
parser: typeof parseAsBoolean,
|
|
270
|
+
): [boolean | null, (value: boolean | null | ((prev: boolean | null) => boolean | null)) => void];
|
|
271
|
+
|
|
272
|
+
// 带默认值的布尔值解析器
|
|
273
|
+
// eslint-disable-next-line no-redeclare
|
|
274
|
+
export function useQueryState(
|
|
275
|
+
key: string,
|
|
276
|
+
parserWithDefault: ParserWithDefault<boolean>,
|
|
277
|
+
): [boolean, (value: boolean | ((prev: boolean) => boolean)) => void];
|
|
278
|
+
|
|
279
|
+
// 整数解析器
|
|
280
|
+
// eslint-disable-next-line no-redeclare
|
|
281
|
+
export function useQueryState(
|
|
282
|
+
key: string,
|
|
283
|
+
parser: typeof parseAsInteger,
|
|
284
|
+
): [number | null, (value: number | null | ((prev: number | null) => number | null)) => void];
|
|
285
|
+
|
|
286
|
+
// 带默认值的整数解析器
|
|
287
|
+
// eslint-disable-next-line no-redeclare
|
|
288
|
+
export function useQueryState(
|
|
289
|
+
key: string,
|
|
290
|
+
parserWithDefault: ParserWithDefault<number>,
|
|
291
|
+
): [number, (value: number | ((prev: number) => number)) => void];
|
|
292
|
+
|
|
293
|
+
// 带默认值的字符串枚举解析器
|
|
294
|
+
// eslint-disable-next-line no-redeclare
|
|
295
|
+
export function useQueryState<T extends string>(
|
|
296
|
+
key: string,
|
|
297
|
+
parserWithDefault: ParserWithDefault<T>,
|
|
298
|
+
): [T, (value: T | ((prev: T) => T)) => void];
|
|
299
|
+
|
|
300
|
+
// --- 单一实现 ---
|
|
301
|
+
// eslint-disable-next-line no-redeclare
|
|
302
|
+
export function useQueryState(key: string, parserOrOptions?: any): any {
|
|
303
|
+
// 修复了逻辑分派问题
|
|
304
|
+
let parser: Parser<any>;
|
|
305
|
+
let options: QueryParamOptions<any> = {};
|
|
306
|
+
|
|
307
|
+
if (!parserOrOptions) {
|
|
308
|
+
// 场景 1: useQueryState('key')
|
|
309
|
+
parser = parseAsString;
|
|
310
|
+
} else if (typeof parserOrOptions.parse === 'function') {
|
|
311
|
+
// 场景 2: useQueryState('key', parseAsInteger) 或 useQueryState('key', parseAsInteger.withDefault(10))
|
|
312
|
+
parser = parserOrOptions;
|
|
313
|
+
// 从解析器自身提取 options (例如 defaultValue)
|
|
314
|
+
options = parserOrOptions;
|
|
315
|
+
} else {
|
|
316
|
+
// 场景 3: useQueryState('key', { defaultValue: 'foo', throttleMs: 500 })
|
|
317
|
+
parser = parseAsString;
|
|
318
|
+
options = parserOrOptions;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return useQueryParam(key, parser, options);
|
|
322
|
+
}
|
|
@@ -4,18 +4,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
4
4
|
import { useQueryRoute } from './useQueryRoute';
|
|
5
5
|
|
|
6
6
|
// Mocks
|
|
7
|
-
vi.mock('
|
|
8
|
-
|
|
9
|
-
push: vi.fn((href) => href),
|
|
10
|
-
replace: vi.fn((href) => href),
|
|
11
|
-
})),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
vi.mock('nextjs-toploader/app', () => ({
|
|
15
|
-
useRouter: vi.fn(() => ({
|
|
16
|
-
push: vi.fn((href) => href),
|
|
17
|
-
replace: vi.fn((href) => href),
|
|
18
|
-
})),
|
|
7
|
+
vi.mock('react-router-dom', () => ({
|
|
8
|
+
useNavigate: vi.fn(() => vi.fn((href) => href)),
|
|
19
9
|
}));
|
|
20
10
|
|
|
21
11
|
vi.mock('@/utils/env', () => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRouter } from 'nextjs-toploader/app';
|
|
2
1
|
import qs, { type ParsedQuery } from 'query-string';
|
|
3
2
|
import { useMemo } from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
4
|
|
|
5
5
|
import { isOnServerSide } from '@/utils/env';
|
|
6
6
|
|
|
@@ -31,19 +31,19 @@ const genHref = ({ hash, replace, url, prevQuery = {}, query = {} }: GenHrefOpti
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export const useQueryRoute = () => {
|
|
34
|
-
const
|
|
34
|
+
const navigate = useNavigate();
|
|
35
35
|
|
|
36
36
|
return useMemo(
|
|
37
37
|
() => ({
|
|
38
38
|
push: (url: string, options: QueryRouteOptions = {}) => {
|
|
39
39
|
const prevQuery = qs.parse(window.location.search);
|
|
40
|
-
return
|
|
40
|
+
return navigate(genHref({ prevQuery, url, ...options }));
|
|
41
41
|
},
|
|
42
42
|
replace: (url: string, options: QueryRouteOptions = {}) => {
|
|
43
43
|
const prevQuery = qs.parse(window.location.search);
|
|
44
|
-
return
|
|
44
|
+
return navigate(genHref({ prevQuery, url, ...options }), { replace: true });
|
|
45
45
|
},
|
|
46
46
|
}),
|
|
47
|
-
[],
|
|
47
|
+
[navigate],
|
|
48
48
|
);
|
|
49
49
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { usePathname } from 'next/navigation';
|
|
2
1
|
import { useCallback } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import { useQueryRoute } from '@/hooks/useQueryRoute';
|
|
5
5
|
import { useChatStore } from '@/store/chat';
|
|
@@ -11,7 +11,8 @@ export const useSwitchSession = () => {
|
|
|
11
11
|
const togglePortal = useChatStore((s) => s.togglePortal);
|
|
12
12
|
const mobile = useServerConfigStore((s) => s.isMobile);
|
|
13
13
|
const router = useQueryRoute();
|
|
14
|
-
const
|
|
14
|
+
const location = useLocation();
|
|
15
|
+
const pathname = location.pathname;
|
|
15
16
|
|
|
16
17
|
return useCallback(
|
|
17
18
|
(id: string) => {
|
|
@@ -27,6 +28,6 @@ export const useSwitchSession = () => {
|
|
|
27
28
|
}, 50);
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
|
-
[mobile, pathname],
|
|
31
|
+
[mobile, pathname, switchSession, togglePortal, router],
|
|
31
32
|
);
|
|
32
33
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { memo, useEffect } from 'react';
|
|
3
|
+
import { memo, useEffect, useState } from 'react';
|
|
5
4
|
|
|
6
5
|
import { LOBE_URL_IMPORT_NAME } from '@/const/url';
|
|
7
6
|
import { useUserStore } from '@/store/user';
|
|
@@ -12,17 +11,31 @@ const ImportSettings = memo(() => {
|
|
|
12
11
|
s.isUserStateInit,
|
|
13
12
|
]);
|
|
14
13
|
|
|
15
|
-
//
|
|
16
|
-
const [searchParam] =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
// Read initial URL param using browser API (not router-dependent)
|
|
15
|
+
const [searchParam, setSearchParam] = useState<string>('');
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
// Read from URL on mount
|
|
19
|
+
if (typeof window !== 'undefined') {
|
|
20
|
+
const params = new URLSearchParams(window.location.search);
|
|
21
|
+
const param = params.get(LOBE_URL_IMPORT_NAME);
|
|
22
|
+
if (param) {
|
|
23
|
+
setSearchParam(param);
|
|
24
|
+
// Clear the param from URL after reading
|
|
25
|
+
params.delete(LOBE_URL_IMPORT_NAME);
|
|
26
|
+
const newUrl = `${window.location.pathname}${params.toString() ? `?${params.toString()}` : ''}${window.location.hash}`;
|
|
27
|
+
window.history.replaceState({}, '', newUrl);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
20
31
|
|
|
21
32
|
useEffect(() => {
|
|
22
33
|
// Why use `usUserStateInit`,
|
|
23
34
|
// see: https://github.com/lobehub/lobe-chat/pull/4072
|
|
24
|
-
if (searchParam && isUserStateInit)
|
|
25
|
-
|
|
35
|
+
if (searchParam && isUserStateInit) {
|
|
36
|
+
importUrlShareSettings(searchParam);
|
|
37
|
+
}
|
|
38
|
+
}, [searchParam, isUserStateInit, importUrlShareSettings]);
|
|
26
39
|
|
|
27
40
|
return null;
|
|
28
41
|
});
|
|
@@ -63,7 +63,16 @@ const StoreInitialization = memo(() => {
|
|
|
63
63
|
|
|
64
64
|
// init user state
|
|
65
65
|
useInitUserState(isLoginOnInit, serverConfig, {
|
|
66
|
+
onError: () => {
|
|
67
|
+
// 即使失败也要设置标志,避免应用卡住
|
|
68
|
+
useGlobalStore.setState({ isAppHydrated: true });
|
|
69
|
+
console.warn('[Hydration] Client state initialization failed.');
|
|
70
|
+
},
|
|
66
71
|
onSuccess: (state) => {
|
|
72
|
+
// 设置水合完成标志
|
|
73
|
+
useGlobalStore.setState({ isAppHydrated: true });
|
|
74
|
+
console.log('[Hydration] Client state initialized successfully.');
|
|
75
|
+
|
|
67
76
|
if (state.isOnboard === false) {
|
|
68
77
|
router.push('/onboard');
|
|
69
78
|
}
|
|
@@ -75,7 +84,6 @@ const StoreInitialization = memo(() => {
|
|
|
75
84
|
const mobile = useIsMobile();
|
|
76
85
|
|
|
77
86
|
useStoreUpdater('isMobile', mobile);
|
|
78
|
-
useStoreUpdater('router', router);
|
|
79
87
|
|
|
80
88
|
return null;
|
|
81
89
|
});
|
|
@@ -15,6 +15,12 @@ export default {
|
|
|
15
15
|
prompt: '提示词',
|
|
16
16
|
},
|
|
17
17
|
localFiles: {
|
|
18
|
+
editFile: {
|
|
19
|
+
newString: '替换为',
|
|
20
|
+
oldString: '查找内容',
|
|
21
|
+
replaceAll: '替换全部匹配项',
|
|
22
|
+
replaceFirst: '仅替换第一个匹配项',
|
|
23
|
+
},
|
|
18
24
|
file: '文件',
|
|
19
25
|
folder: '文件夹',
|
|
20
26
|
moveFiles: {
|
|
@@ -35,6 +41,11 @@ export default {
|
|
|
35
41
|
readFileError: '读取文件失败,请检查文件路径是否正确',
|
|
36
42
|
readFiles: '读取文件',
|
|
37
43
|
readFilesError: '读取文件失败,请检查文件路径是否正确',
|
|
44
|
+
writeFile: {
|
|
45
|
+
characters: '字符',
|
|
46
|
+
preview: '内容预览',
|
|
47
|
+
truncated: '已截断',
|
|
48
|
+
},
|
|
38
49
|
},
|
|
39
50
|
search: {
|
|
40
51
|
createNewSearch: '创建新的搜索记录',
|
package/src/proxy.ts
CHANGED
|
@@ -128,11 +128,23 @@ const defaultMiddleware = (request: NextRequest) => {
|
|
|
128
128
|
// new handle segment rewrite: /${route}${originalPathname}
|
|
129
129
|
// / -> /zh-CN__0__dark
|
|
130
130
|
// /discover -> /zh-CN__0__dark/discover
|
|
131
|
-
|
|
131
|
+
// All SPA routes that use react-router-dom should be rewritten to just /${route}
|
|
132
|
+
const spaRoutes = ['/chat', '/discover', '/knowledge', '/settings', '/image', '/labs', '/changelog', '/profile', '/me'];
|
|
133
|
+
const isSpaRoute = spaRoutes.some(route => url.pathname.startsWith(route));
|
|
134
|
+
|
|
135
|
+
let nextPathname: string;
|
|
136
|
+
if (isSpaRoute) {
|
|
137
|
+
nextPathname = `/${route}`;
|
|
138
|
+
} else {
|
|
139
|
+
nextPathname = `/${route}` + (url.pathname === '/' ? '' : url.pathname);
|
|
140
|
+
}
|
|
132
141
|
const nextURL = appEnv.MIDDLEWARE_REWRITE_THROUGH_LOCAL
|
|
133
142
|
? urlJoin(url.origin, nextPathname)
|
|
134
143
|
: nextPathname;
|
|
135
144
|
|
|
145
|
+
|
|
146
|
+
console.log('nextURL', nextURL);
|
|
147
|
+
|
|
136
148
|
logDefault('URL rewrite: %O', {
|
|
137
149
|
isLocalRewrite: appEnv.MIDDLEWARE_REWRITE_THROUGH_LOCAL,
|
|
138
150
|
nextPathname: nextPathname,
|
|
@@ -77,12 +77,21 @@ export class MessageService {
|
|
|
77
77
|
return lambdaClient.message.getHeatmaps.query();
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
updateMessageError = async (
|
|
80
|
+
updateMessageError = async (
|
|
81
|
+
id: string,
|
|
82
|
+
value: ChatMessageError,
|
|
83
|
+
options?: { sessionId?: string | null; topicId?: string | null },
|
|
84
|
+
) => {
|
|
81
85
|
const error = value.type
|
|
82
86
|
? value
|
|
83
87
|
: { body: value, message: value.message, type: 'ApplicationRuntimeError' };
|
|
84
88
|
|
|
85
|
-
return lambdaClient.message.update.mutate({
|
|
89
|
+
return lambdaClient.message.update.mutate({
|
|
90
|
+
id,
|
|
91
|
+
sessionId: options?.sessionId,
|
|
92
|
+
topicId: options?.topicId,
|
|
93
|
+
value: { error },
|
|
94
|
+
});
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
updateMessagePluginArguments = async (id: string, value: string | Record<string, any>) => {
|
|
@@ -15,6 +15,7 @@ import type { ChatToolPayload, CreateMessageParams } from '@lobechat/types';
|
|
|
15
15
|
import debug from 'debug';
|
|
16
16
|
import pMap from 'p-map';
|
|
17
17
|
|
|
18
|
+
import { LOADING_FLAT } from '@/const/message';
|
|
18
19
|
import type { ChatStore } from '@/store/chat/store';
|
|
19
20
|
|
|
20
21
|
const log = debug('lobe-store:agent-executors');
|
|
@@ -36,7 +37,9 @@ export const createAgentExecutors = (context: {
|
|
|
36
37
|
inPortalThread?: boolean;
|
|
37
38
|
inSearchWorkflow?: boolean;
|
|
38
39
|
ragQuery?: string;
|
|
40
|
+
sessionId?: string;
|
|
39
41
|
threadId?: string;
|
|
42
|
+
topicId?: string | null;
|
|
40
43
|
traceId?: string;
|
|
41
44
|
};
|
|
42
45
|
parentId: string;
|
|
@@ -75,16 +78,22 @@ export const createAgentExecutors = (context: {
|
|
|
75
78
|
llmPayload.parentMessageId = context.parentId;
|
|
76
79
|
}
|
|
77
80
|
// Create assistant message (following server-side pattern)
|
|
78
|
-
const assistantMessageItem = await context.get().optimisticCreateMessage(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const assistantMessageItem = await context.get().optimisticCreateMessage(
|
|
82
|
+
{
|
|
83
|
+
content: LOADING_FLAT,
|
|
84
|
+
model: llmPayload.model,
|
|
85
|
+
parentId: llmPayload.parentMessageId,
|
|
86
|
+
provider: llmPayload.provider,
|
|
87
|
+
role: 'assistant',
|
|
88
|
+
sessionId: state.metadata!.sessionId!,
|
|
89
|
+
threadId: state.metadata?.threadId,
|
|
90
|
+
topicId: state.metadata?.topicId,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
sessionId: state.metadata!.sessionId!,
|
|
94
|
+
topicId: state.metadata?.topicId,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
88
97
|
|
|
89
98
|
if (!assistantMessageItem) {
|
|
90
99
|
throw new Error('Failed to create assistant message');
|
|
@@ -269,13 +278,16 @@ export const createAgentExecutors = (context: {
|
|
|
269
278
|
parentId: payload.parentMessageId,
|
|
270
279
|
plugin: chatToolPayload,
|
|
271
280
|
role: 'tool',
|
|
272
|
-
sessionId:
|
|
281
|
+
sessionId: state.metadata!.sessionId!,
|
|
273
282
|
threadId: context.params.threadId,
|
|
274
283
|
tool_call_id: chatToolPayload.id,
|
|
275
|
-
topicId:
|
|
284
|
+
topicId: state.metadata?.topicId,
|
|
276
285
|
};
|
|
277
286
|
|
|
278
|
-
const createResult = await context.get().optimisticCreateMessage(toolMessageParams
|
|
287
|
+
const createResult = await context.get().optimisticCreateMessage(toolMessageParams, {
|
|
288
|
+
sessionId: state.metadata!.sessionId!,
|
|
289
|
+
topicId: state.metadata?.topicId,
|
|
290
|
+
});
|
|
279
291
|
|
|
280
292
|
if (!createResult) {
|
|
281
293
|
log(
|
|
@@ -450,13 +462,16 @@ export const createAgentExecutors = (context: {
|
|
|
450
462
|
},
|
|
451
463
|
pluginIntervention: { status: 'pending' },
|
|
452
464
|
role: 'tool',
|
|
453
|
-
sessionId:
|
|
465
|
+
sessionId: state.metadata!.sessionId!,
|
|
454
466
|
threadId: context.params.threadId,
|
|
455
467
|
tool_call_id: toolPayload.id,
|
|
456
|
-
topicId:
|
|
468
|
+
topicId: state.metadata?.topicId,
|
|
457
469
|
};
|
|
458
470
|
|
|
459
|
-
const createResult = await context.get().optimisticCreateMessage(toolMessageParams
|
|
471
|
+
const createResult = await context.get().optimisticCreateMessage(toolMessageParams, {
|
|
472
|
+
sessionId: state.metadata!.sessionId!,
|
|
473
|
+
topicId: state.metadata?.topicId,
|
|
474
|
+
});
|
|
460
475
|
|
|
461
476
|
if (!createResult) {
|
|
462
477
|
log(
|