🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(home): preview acceptance links in portal (#18103)
Arvin Xu067e81f7706e
diff --git a/src/features/Home/AcceptancePortalDrawer.tsx b/src/features/Home/AcceptancePortalDrawer.tsxnew file mode 100644index 00000000000..9c18510f712--- /dev/null+++ b/src/features/Home/AcceptancePortalDrawer.tsx@@ -0,0 +1,49 @@+'use client';++import { Flexbox } from '@lobehub/ui';+import { Drawer } from '@lobehub/ui/base-ui';+import { memo } from 'react';++import { PortalContent } from '@/features/Portal/router';+import { useChatStore } from '@/store/chat';+import { chatPortalSelectors } from '@/store/chat/selectors';++import { isAcceptancePortalView } from './acceptancePortalView';++/**+ * Home has no persistent chat portal column. Internal acceptance links still+ * use the shared portal stack, so host that content in a right-side drawer and+ * keep the user anchored in the inbox report they were reading.+ */+const AcceptancePortalDrawer = memo(() => {+ const [viewType, clearPortalStack] = useChatStore((state) => [+ chatPortalSelectors.currentViewType(state),+ state.clearPortalStack,+ ]);+ const open = isAcceptancePortalView(viewType);++ return (+ <Drawer+ noHeader+ closable={false}+ containerMaxWidth={'100%'}+ open={open}+ placement={'right'}+ width={'min(960px, 92vw)'}+ styles={{+ bodyContent: { height: '100%', minHeight: 0, overflow: 'hidden', padding: 0 },+ }}+ onClose={clearPortalStack}+ >+ {open && (+ <Flexbox height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>+ <PortalContent />+ </Flexbox>+ )}+ </Drawer>+ );+});++AcceptancePortalDrawer.displayName = 'AcceptancePortalDrawer';++export default AcceptancePortalDrawer;diff --git a/src/features/Home/__tests__/portraitVisibility.test.tsx b/src/features/Home/__tests__/portraitVisibility.test.tsxindex ed002a7b1ff..9b4a6715383 100644--- a/src/features/Home/__tests__/portraitVisibility.test.tsx+++ b/src/features/Home/__tests__/portraitVisibility.test.tsx@@ -1,8 +1,11 @@import { cleanup, render, screen } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';+import { PortalViewType } from '@/store/chat/slices/portal/initialState';+interface RenderHomeOptions {isLogin?: boolean;+ portalViewType?: PortalViewType;showHomePortrait?: boolean;}@@ -12,7 +15,11 @@ function translate() {return { i18n: { language: 'en-US' }, t: (key: string) => key };}-const renderHome = async ({ isLogin = true, showHomePortrait }: RenderHomeOptions = {}) => {+const renderHome = async ({+ isLogin = true,+ portalViewType,+ showHomePortrait,+}: RenderHomeOptions = {}) => {vi.resetModules();vi.doMock('react-i18next', () => ({ useTranslation: translate }));@@ -21,11 +28,17 @@ const renderHome = async ({ isLogin = true, showHomePortrait }: RenderHomeOptionvi.doMock('../HomePortrait', () => stub('home-portrait'));vi.doMock('../InputArea', () => stub('home-input-area'));vi.doMock('../PortraitBubble', () => stub('portrait-bubble'));+ vi.doMock('../AcceptancePortalDrawer', () => stub('acceptance-portal-drawer'));vi.doMock('@/features/HomeInbox', () => stub('home-inbox'));- vi.doMock('@/store/chat', () => ({- useChatStore: {- getState: () => ({ mainInputEditor: undefined }),- setState: vi.fn(),+ function selectFromChatStore(selector: (state: unknown) => unknown) {+ return selector({ portalViewType });+ }+ selectFromChatStore.getState = () => ({ mainInputEditor: undefined });+ selectFromChatStore.setState = vi.fn();+ vi.doMock('@/store/chat', () => ({ useChatStore: selectFromChatStore }));+ vi.doMock('@/store/chat/selectors', () => ({+ chatPortalSelectors: {+ currentViewType: (state: { portalViewType?: PortalViewType }) => state.portalViewType ?? null,},}));function selectFromGlobalStore(selector: (state: unknown) => unknown) {@@ -50,8 +63,10 @@ afterEach(() => {vi.doUnmock('../HomePortrait');vi.doUnmock('../InputArea');vi.doUnmock('../PortraitBubble');+ vi.doUnmock('../AcceptancePortalDrawer');vi.doUnmock('@/features/HomeInbox');vi.doUnmock('@/store/chat');+ vi.doUnmock('@/store/chat/selectors');vi.doUnmock('@/store/global');vi.doUnmock('@/store/user');});@@ -92,4 +107,16 @@ describe('Home portrait visibility', () => {expect(screen.queryByTestId('home-portrait')).not.toBeInTheDocument();expect(screen.queryByTestId('portrait-bubble')).not.toBeInTheDocument();}, 20000);++ it('loads the acceptance drawer only after an acceptance portal opens', async () => {+ await renderHome({ portalViewType: PortalViewType.Acceptance });++ expect(await screen.findByTestId('acceptance-portal-drawer')).toBeInTheDocument();+ }, 20000);++ it('does not load the acceptance drawer for unrelated portal views', async () => {+ await renderHome({ portalViewType: PortalViewType.TaskDetail });++ expect(screen.queryByTestId('acceptance-portal-drawer')).not.toBeInTheDocument();+ }, 20000);});diff --git a/src/features/Home/acceptancePortalView.test.ts b/src/features/Home/acceptancePortalView.test.tsnew file mode 100644index 00000000000..01f331c5126--- /dev/null+++ b/src/features/Home/acceptancePortalView.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from 'vitest';++import { PortalViewType } from '@/store/chat/slices/portal/initialState';++import { isAcceptancePortalView } from './acceptancePortalView';++describe('isAcceptancePortalView', () => {+ it.each([PortalViewType.Acceptance, PortalViewType.AcceptanceCheck])(+ 'hosts %s in the Home drawer',+ (viewType) => {+ expect(isAcceptancePortalView(viewType)).toBe(true);+ },+ );++ it.each([null, PortalViewType.TaskDetail, PortalViewType.VerifyReport])(+ 'leaves unrelated portal view %s to its owning surface',+ (viewType) => {+ expect(isAcceptancePortalView(viewType)).toBe(false);+ },+ );+});diff --git a/src/features/Home/acceptancePortalView.ts b/src/features/Home/acceptancePortalView.tsnew file mode 100644index 00000000000..9db3df82995--- /dev/null+++ b/src/features/Home/acceptancePortalView.ts@@ -0,0 +1,5 @@+import { PortalViewType } from '@/store/chat/slices/portal/initialState';++/** Portal views that Home can present without navigating away from the inbox. */+export const isAcceptancePortalView = (viewType: PortalViewType | null) =>+ viewType === PortalViewType.Acceptance || viewType === PortalViewType.AcceptanceCheck;diff --git a/src/features/Home/index.tsx b/src/features/Home/index.tsxindex 816098745c6..218f43d0ed4 100644--- a/src/features/Home/index.tsx+++ b/src/features/Home/index.tsx@@ -6,6 +6,7 @@ import { lazy, memo, Suspense, useCallback, useState } from 'react';import HomeInbox from '@/features/HomeInbox';import { useChatStore } from '@/store/chat';+import { chatPortalSelectors } from '@/store/chat/selectors';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';import { useTaskStore } from '@/store/task';@@ -13,6 +14,7 @@ import { taskDetailSelectors } from '@/store/task/selectors';import { useUserStore } from '@/store/user';import { authSelectors } from '@/store/user/slices/auth/selectors';+import { isAcceptancePortalView } from './acceptancePortalView';import { isHomeMinimalLayout } from './CustomizeModal/config';import HomeHeader from './HomeHeader';import HomeModeContent from './HomeModeContent';@@ -28,6 +30,7 @@ import type { HomeMode } from './types';// no-op. Lazy so the home bundle doesn't pay for the chat stack until a run is// actually opened.const TopicChatDrawer = lazy(() => import('@/features/AgentTasks/AgentTaskDetail/TopicChatDrawer'));+const AcceptancePortalDrawer = lazy(() => import('./AcceptancePortalDrawer'));/** Trailing gutter that keeps the rail's cards off the page's scroll lane. */const RAIL_GUTTER = 14;@@ -278,10 +281,14 @@ const Home = memo(() => {const [inputValue, setInputValue] = useState('');const drawerTopicId = useTaskStore(taskDetailSelectors.activeTopicDrawerTopicId);+ const portalViewType = useChatStore(chatPortalSelectors.currentViewType);+ const acceptancePortalOpen = isAcceptancePortalView(portalViewType);// Mount the drawer on first open and keep it mounted afterwards, so its// close animation can play instead of the panel vanishing with the state.const [drawerMounted, setDrawerMounted] = useState(false);if (drawerTopicId && !drawerMounted) setDrawerMounted(true);+ const [acceptanceDrawerMounted, setAcceptanceDrawerMounted] = useState(false);+ if (acceptancePortalOpen && !acceptanceDrawerMounted) setAcceptanceDrawerMounted(true);const railVisible = resolveRailVisibility({ hiddenWidgets, isLogin, showHomeRail });const railCollapsed = !railVisible;const portraitVisible = Boolean(isLogin && showHomePortrait);@@ -375,6 +382,11 @@ const Home = memo(() => {<TopicChatDrawer /></Suspense>)}+ {acceptanceDrawerMounted && (+ <Suspense fallback={null}>+ <AcceptancePortalDrawer />+ </Suspense>+ )}</Flexbox>);});diff --git a/src/features/HomeInbox/UnreadTopicList.tsx b/src/features/HomeInbox/UnreadTopicList.tsxindex ddbeec69449..9fd5127dd1b 100644--- a/src/features/HomeInbox/UnreadTopicList.tsx+++ b/src/features/HomeInbox/UnreadTopicList.tsx@@ -1,6 +1,7 @@import { AGENT_CHAT_TOPIC_URL } from '@lobechat/const';-import { agentDisplayName, type ConversationContext } from '@lobechat/types';-import { Avatar, Flexbox, Icon, Markdown, stopPropagation, Text } from '@lobehub/ui';+import type { ConversationContext } from '@lobechat/types';+import { agentDisplayName } from '@lobechat/types';+import { Avatar, Flexbox, Icon, stopPropagation, Text } from '@lobehub/ui';import { Button } from '@lobehub/ui/base-ui';import { createStaticStyles, cssVar, cx } from 'antd-style';import { ChevronDownIcon, ChevronRightIcon, MessageSquarePlus } from 'lucide-react';@@ -9,12 +10,15 @@ import { useTranslation } from 'react-i18next';import UnreadDot from '@/components/UnreadDot';import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';+import MarkdownMessage from '@/features/Conversation/Markdown';import { homeType } from '@/features/Home/components/homeType';import Time from '@/features/Home/components/Time';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { useChatStore } from '@/store/chat';import AuthorChip from './AuthorChip';+import { sanitizeInboxPreview } from './sanitizeInboxPreview';+import { useHomeInboxMarkdown } from './useHomeInboxMarkdown';import { type InboxTopic } from './useHomeInboxTopics';const DOT_WIDTH = 14;@@ -106,6 +110,8 @@ const UnreadTopicItem = memo<UnreadTopicItemProps>(const updateTopicStatus = useChatStore((s) => s.updateTopicStatus);const sendMessage = useChatStore((s) => s.sendMessage);const prefetchMessages = useChatStore((s) => s.prefetchMessages);+ const markdownProps = useHomeInboxMarkdown(topic.id);+ const assistantPreview = sanitizeInboxPreview(topic.lastAssistantMessage ?? '');const [expanded, setExpanded] = useState(false);const [read, setRead] = useState(false);@@ -202,10 +208,10 @@ const UnreadTopicItem = memo<UnreadTopicItemProps>({expanded && (<Flexbox className={bare ? styles.bareBody : styles.body} gap={8}>- {topic.lastAssistantMessage && (- <Markdown style={{ overflow: 'unset' }} variant={'chat'}>- {topic.lastAssistantMessage}- </Markdown>+ {assistantPreview && (+ <MarkdownMessage {...markdownProps} style={{ overflow: 'unset' }}>+ {assistantPreview}+ </MarkdownMessage>)}{replying ? (diff --git a/src/features/HomeInbox/sanitizeInboxPreview.test.ts b/src/features/HomeInbox/sanitizeInboxPreview.test.tsnew file mode 100644index 00000000000..ddd595b9edf--- /dev/null+++ b/src/features/HomeInbox/sanitizeInboxPreview.test.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from 'vitest';++import { sanitizeInboxPreview } from './sanitizeInboxPreview';++describe('sanitizeInboxPreview', () => {+ it('removes closed thinking blocks while preserving the answer', () => {+ expect(sanitizeInboxPreview('<think>private reasoning</think>\nFinal answer')).toBe(+ 'Final answer',+ );+ });++ it('removes an unfinished thinking block from a truncated preview', () => {+ expect(sanitizeInboxPreview('Visible answer\n<think>unfinished reasoning')).toBe(+ 'Visible answer',+ );+ });++ it('removes orphan thinking tags without dropping surrounding content', () => {+ expect(sanitizeInboxPreview('Before </think> after')).toBe('Before after');+ });++ it('leaves ordinary Markdown and acceptance links intact', () => {+ const content = 'Done: [view acceptance](/acceptance/a-1)';++ expect(sanitizeInboxPreview(content)).toBe(content);+ });+});diff --git a/src/features/HomeInbox/sanitizeInboxPreview.ts b/src/features/HomeInbox/sanitizeInboxPreview.tsnew file mode 100644index 00000000000..7604d6198e1--- /dev/null+++ b/src/features/HomeInbox/sanitizeInboxPreview.ts@@ -0,0 +1,11 @@+const CLOSED_THINK_BLOCK = /<think\b[^>]*>[\S\s]*?<\/think\s*>/gi;+const UNCLOSED_THINK_BLOCK = /<think\b[^>]*>[\S\s]*$/gi;+const ORPHAN_THINK_TAG = /<\/?think\b[^>]*>/gi;++/** Remove model reasoning from the compact Home inbox preview. */+export const sanitizeInboxPreview = (content: string) =>+ content+ .replaceAll(CLOSED_THINK_BLOCK, '')+ .replaceAll(UNCLOSED_THINK_BLOCK, '')+ .replaceAll(ORPHAN_THINK_TAG, '')+ .trim();diff --git a/src/features/HomeInbox/useHomeInboxMarkdown.test.ts b/src/features/HomeInbox/useHomeInboxMarkdown.test.tsnew file mode 100644index 00000000000..a18bc12c42b--- /dev/null+++ b/src/features/HomeInbox/useHomeInboxMarkdown.test.ts@@ -0,0 +1,16 @@+import { renderHook } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import LinkElement from '@/features/Conversation/Markdown/plugins/Link';++import { useHomeInboxMarkdown } from './useHomeInboxMarkdown';++describe('useHomeInboxMarkdown', () => {+ it('wires only the provider-free link plugin', () => {+ const { result } = renderHook(() => useHomeInboxMarkdown('message-1'));++ expect(Object.keys(result.current.components ?? {})).toEqual([LinkElement.tag]);+ expect(result.current.rehypePlugins).toEqual([LinkElement.rehypePlugin]);+ expect(result.current.remarkPlugins).toBeUndefined();+ });+});diff --git a/src/features/HomeInbox/useHomeInboxMarkdown.tsx b/src/features/HomeInbox/useHomeInboxMarkdown.tsxnew file mode 100644index 00000000000..da16b1a27c8--- /dev/null+++ b/src/features/HomeInbox/useHomeInboxMarkdown.tsx@@ -0,0 +1,32 @@+import type { MarkdownProps } from '@lobehub/ui';+import type { FC } from 'react';+import { useMemo } from 'react';++import LinkElement from '@/features/Conversation/Markdown/plugins/Link';+import type { MarkdownElementProps } from '@/features/Conversation/Markdown/plugins/type';++const rehypePlugins = LinkElement.rehypePlugin ? [LinkElement.rehypePlugin] : [];++/**+ * Home is not hosted by a ConversationProvider, so inbox previews deliberately+ * support only the provider-free link plugin. Conversation-only markup remains+ * readable as plain Markdown instead of mounting components that require chat+ * context.+ */+export const useHomeInboxMarkdown = (messageId: string): Partial<MarkdownProps> => {+ const components = useMemo(() => {+ const LinkComponent: FC = (props) => (+ <LinkElement.Component {...(props as MarkdownElementProps)} id={messageId} />+ );++ return { [LinkElement.tag]: LinkComponent };+ }, [messageId]);++ return useMemo(+ () => ({+ components,+ rehypePlugins,+ }),+ [components],+ );+};