Skip to content

🀯 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.

✨ feat(entity-link): render internal entity links inline on reading surfaces (#20236)

Arvin Xu6d91d0d47c6a
diff --git a/src/features/AgentGoals/GoalDetailPage.test.tsx b/src/features/AgentGoals/GoalDetailPage.test.tsx
new file mode 100644
index 00000000000..a07dfb1d81c
--- /dev/null
+++ b/src/features/AgentGoals/GoalDetailPage.test.tsx
@@ -0,0 +1,141 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { fireEvent, render, screen } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { WorkspaceSidePanelProvider } from '@/features/RightPanel/WorkspaceSidePanel';
+
+import GoalDetailPage from './GoalDetailPage';
+
+const mocks = vi.hoisted(() => ({ showPortal: false }));
+
+const snapshot = {
+ goal: {
+ agentId: 'agt_manager',
+ config: { manager: true, managerState: { topicId: 'tpc_manager' } },
+ id: 'goal_1',
+ projectId: null,
+ requirement: null,
+ status: 'review',
+ title: 'Ship it',
+ },
+ nodes: [],
+};
+
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+vi.mock('@/store/goal', () => ({
+ goalSelectors: { goalGraph: () => () => snapshot },
+ useGoalStore: (selector: (s: any) => unknown) =>
+ selector({
+ pauseGoal: vi.fn(),
+ resumeGoal: vi.fn(),
+ useFetchGoalGraph: () => ({ error: undefined, isLoading: false, mutate: vi.fn() }),
+ }),
+}));
+
+vi.mock('@/store/chat', () => ({
+ useChatStore: (selector: (s: any) => unknown) => selector({ clearPortalStack: vi.fn() }),
+}));
+
+vi.mock('@/store/chat/selectors', () => ({
+ chatPortalSelectors: { currentViewType: () => undefined, showPortal: () => mocks.showPortal },
+}));
+
+vi.mock('@/store/global', () => ({
+ useGlobalStore: Object.assign(
+ (selector: (s: any) => unknown) => selector({ toggleLeftPanel: vi.fn() }),
+ { getState: () => ({ toggleLeftPanel: vi.fn() }) },
+ ),
+}));
+
+vi.mock('@/store/global/selectors', () => ({
+ systemStatusSelectors: { showLeftPanel: () => false },
+}));
+
+vi.mock('@/hooks/usePermission', () => ({ usePermission: () => ({ allowed: true }) }));
+
+vi.mock('@/features/Portal/usePortalPanelWidth', () => ({
+ usePortalPanelWidth: () => ({ maxWidth: 800, minWidth: 300, updateWidth: vi.fn(), width: 400 }),
+}));
+
+vi.mock('@/features/RightPanel', () => ({
+ default: ({ children, expand }: { children: ReactNode; expand: boolean }) => (
+ <div data-expand={String(expand)} data-testid="goal-right-panel">
+ {children}
+ </div>
+ ),
+}));
+
+vi.mock('@/features/RightPanel/ToggleRightPanelButton', () => ({ default: () => null }));
+vi.mock('@/features/Portal/router', () => ({
+ PortalContent: () => <div data-testid="goal-portal-content" />,
+}));
+vi.mock('@/features/NavHeader', () => ({
+ default: ({ left, right }: { left: ReactNode; right: ReactNode }) => (
+ <div>
+ {left}
+ {right}
+ </div>
+ ),
+}));
+vi.mock('@/features/AgentBreadcrumb', () => ({ default: () => null }));
+vi.mock('@/features/AgentBreadcrumb/useAgentRoutePath', () => ({
+ useAgentRoutePath: () => () => '/',
+}));
+vi.mock('@/features/WideScreenContainer', () => ({
+ default: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+}));
+vi.mock('./GoalChat', () => ({ default: () => <div data-testid="goal-chat" /> }));
+vi.mock('./GoalDetailActions', () => ({ default: () => null }));
+vi.mock('./GoalHeaderMetrics', () => ({ default: () => null }));
+vi.mock('./GoalRequirement', () => ({ default: () => null }));
+vi.mock('./NorthStarMetrics', () => ({ default: () => null }));
+vi.mock('./ProcessControl', () => ({ default: () => null }));
+vi.mock('./GoalSupervision', () => ({
+ GoalSupervision: ({ topicId }: { topicId: string }) => (
+ <div data-testid="goal-supervision">{topicId}</div>
+ ),
+}));
+
+describe('GoalDetailPage', () => {
+ beforeEach(() => {
+ mocks.showPortal = false;
+ });
+
+ // On the agent-less route the task workspace owns the portal host, but the
+ // supervision trace has no other home: "View trace" must still open it.
+ it('opens the supervision trace on the agent-less workspace route', () => {
+ render(
+ <WorkspaceSidePanelProvider>
+ <GoalDetailPage goalId={'goal_1'} />
+ </WorkspaceSidePanelProvider>,
+ );
+
+ fireEvent.click(screen.getByText('goalProcess.manager.viewTrace'));
+
+ expect(screen.getByTestId('goal-supervision')).toHaveTextContent('tpc_manager');
+ expect(screen.getByTestId('goal-right-panel')).toHaveAttribute('data-expand', 'true');
+ });
+
+ it('leaves drill-downs to the workspace portal host on the agent-less route', () => {
+ mocks.showPortal = true;
+ render(
+ <WorkspaceSidePanelProvider>
+ <GoalDetailPage goalId={'goal_1'} />
+ </WorkspaceSidePanelProvider>,
+ );
+
+ expect(screen.queryByTestId('goal-portal-content')).not.toBeInTheDocument();
+ expect(screen.getByTestId('goal-right-panel')).toHaveAttribute('data-expand', 'false');
+ });
+
+ it('hosts drill-downs itself outside the task workspace', () => {
+ mocks.showPortal = true;
+ render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);
+
+ expect(screen.getByTestId('goal-portal-content')).toBeInTheDocument();
+ });
+});
diff --git a/src/features/AgentGoals/GoalDetailPage.tsx b/src/features/AgentGoals/GoalDetailPage.tsx
index 1fafcb25e13..6a57e399e42 100644
--- a/src/features/AgentGoals/GoalDetailPage.tsx
+++ b/src/features/AgentGoals/GoalDetailPage.tsx
@@ -18,6 +18,7 @@ import { PortalContent } from '@/features/Portal/router';
import { usePortalPanelWidth } from '@/features/Portal/usePortalPanelWidth';
import RightPanel from '@/features/RightPanel';
import ToggleRightPanelButton from '@/features/RightPanel/ToggleRightPanelButton';
+import { useWorkspaceSidePanel } from '@/features/RightPanel/WorkspaceSidePanel';
import WideScreenContainer from '@/features/WideScreenContainer';
import { usePermission } from '@/hooks/usePermission';
import { useChatStore } from '@/store/chat';
@@ -71,6 +72,9 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
const showPortal = useChatStore(chatPortalSelectors.showPortal);
const currentViewType = useChatStore(chatPortalSelectors.currentViewType);
+ // On the agent-less `/goal/:goalId` route an ancestor layout already owns the
+ // side panel; mounting ours as well would give the surface two portal hosts.
+ const hasWorkspaceSidePanel = useWorkspaceSidePanel();
const chat = useGoalChatPanel(goalId, agentId);
const clearPortalStack = useChatStore((s) => s.clearPortalStack);
@@ -254,9 +258,15 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
(metric / node β†’ task detail β†’ topic) rides its view stack, and the
header's back arrow and close come for free. When no drill-down is
open, the panel hosts the conversation with the goal's responsible
- agent so a user can just ask about progress. */}
+ agent so a user can just ask about progress.
+
+ On the agent-less route the task workspace already mounts the portal
+ host, so a drill-down renders there and this panel stays out of the
+ way: a second host would render the same detail twice while squeezing
+ the goal column to nothing beside it. The goal conversation and the
+ supervision trace have no other home, so those still mount here. */}
<RightPanel
- expand={(showPortal || chatVisible) && !graphFullscreen}
+ expand={(showPortal ? !hasWorkspaceSidePanel : chatVisible) && !graphFullscreen}
maxWidth={maxWidth}
minWidth={minWidth}
width={width}
@@ -267,7 +277,9 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
}}
>
{graphFullscreen ? null : showPortal ? (
- <PortalContent />
+ hasWorkspaceSidePanel ? null : (
+ <PortalContent />
+ )
) : chat.agentId && chat.topicId ? (
<GoalSupervision
agentId={chat.agentId}
diff --git a/src/features/AgentGoals/ProcessControl/DeliverableReader.tsx b/src/features/AgentGoals/ProcessControl/DeliverableReader.tsx
index 9e548294ce3..5b820001e82 100644
--- a/src/features/AgentGoals/ProcessControl/DeliverableReader.tsx
+++ b/src/features/AgentGoals/ProcessControl/DeliverableReader.tsx
@@ -9,6 +9,7 @@ import { useEffect, useRef } from 'react';
import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
+import { EntityLinkHostProvider, useEntityMarkdown } from '@/features/EntityLink';
import { isSafeExternalUrl } from '@/features/Work/descriptors';
import { useActivityTime } from '@/hooks/useActivityTime';
import { useClientDataSWR } from '@/libs/swr';
@@ -157,6 +158,7 @@ const SidebarItem = ({
};
const DocumentBody = ({ documentId }: { documentId: string }) => {
+ const markdownProps = useEntityMarkdown();
const { data: document, isLoading } = useClientDataSWR(
portalKeys.documentHeader(documentId),
() => documentService.getDocumentById(documentId),
@@ -174,7 +176,9 @@ const DocumentBody = ({ documentId }: { documentId: string }) => {
return (
<div className={styles.doc} data-testid={'deliverable-reader-document'}>
- <Markdown variant={'chat'}>{document?.content ?? ''}</Markdown>
+ <Markdown variant={'chat'} {...markdownProps}>
+ {document?.content ?? ''}
+ </Markdown>
</div>
);
};
@@ -416,7 +420,11 @@ const DeliverableReader = ({ index, items, onClose, onIndexChange }: Deliverable
<Flexbox flex={1} style={{ minWidth: 0 }}>
<Header index={index} item={current} total={items.length} onIndexChange={onIndexChange} />
<div className={styles.body}>
- <Body item={current} key={current.artifact.workVersionId} />
+ {/* The reader covers the page it was opened from, so a detail opened
+ in a side panel would be invisible β€” entity links navigate. */}
+ <EntityLinkHostProvider portal={false} onDismiss={onClose}>
+ <Body item={current} key={current.artifact.workVersionId} />
+ </EntityLinkHostProvider>
</div>
</Flexbox>
</div>,
diff --git a/src/features/AgentGoals/ProcessControl/Findings.tsx b/src/features/AgentGoals/ProcessControl/Findings.tsx
index 67b4616a509..7789450cde2 100644
--- a/src/features/AgentGoals/ProcessControl/Findings.tsx
+++ b/src/features/AgentGoals/ProcessControl/Findings.tsx
@@ -7,6 +7,7 @@ import { ChevronRight } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useActivityTime } from '@/hooks/useActivityTime';
import type { GoalGraphView, GoalNodeView } from './goalGraphViewModel';
@@ -58,6 +59,7 @@ const FindingRow = memo<{ onSelect: (nodeId: string) => void; view: GoalNodeView
({ onSelect, view }) => {
const { t } = useTranslation('chat');
const [open, setOpen] = useState(false);
+ const markdownProps = useEntityMarkdown();
const { text, title } = useActivityTime(view.node.resolvedAt ?? view.node.createdAt);
const answered = view.answers[0];
@@ -114,7 +116,7 @@ const FindingRow = memo<{ onSelect: (nodeId: string) => void; view: GoalNodeView
{/* The description is the producing run's handoff β€” actual Markdown
(tables, code blocks), not plain text. Render it as such. */}
{view.node.description && (
- <Markdown fontSize={13} variant={'chat'}>
+ <Markdown fontSize={13} variant={'chat'} {...markdownProps}>
{view.node.description}
</Markdown>
)}
diff --git a/src/features/AgentGoals/ProcessControl/GoalCriteriaResults.tsx b/src/features/AgentGoals/ProcessControl/GoalCriteriaResults.tsx
index b70673e4f61..0dbe3ce03d3 100644
--- a/src/features/AgentGoals/ProcessControl/GoalCriteriaResults.tsx
+++ b/src/features/AgentGoals/ProcessControl/GoalCriteriaResults.tsx
@@ -15,6 +15,7 @@ import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import AsyncError from '@/components/AsyncError';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useChatStore } from '@/store/chat';
import { SectionTitle } from './GoalResultFollowUps';
@@ -105,6 +106,7 @@ const IMAGE_TYPES = new Set(['screenshot', 'gif']);
const EvidenceItem = ({ item }: { item: EvidenceLike }) => {
const { t } = useTranslation('chat');
const openDocument = useChatStore((s) => s.openDocument);
+ const markdownProps = useEntityMarkdown();
const caption = item.description || item.fileName;
if (IMAGE_TYPES.has(item.type) && item.fileUrl)
@@ -137,7 +139,7 @@ const EvidenceItem = ({ item }: { item: EvidenceLike }) => {
{caption}
</Text>
)}
- <Markdown fontSize={13} variant={'chat'}>
+ <Markdown fontSize={13} variant={'chat'} {...markdownProps}>
{item.content}
</Markdown>
</Flexbox>
diff --git a/src/features/AgentGoals/ProcessControl/GoalResult.tsx b/src/features/AgentGoals/ProcessControl/GoalResult.tsx
index 1ee246bd324..d676d3514e0 100644
--- a/src/features/AgentGoals/ProcessControl/GoalResult.tsx
+++ b/src/features/AgentGoals/ProcessControl/GoalResult.tsx
@@ -4,6 +4,7 @@ import { Flexbox, Markdown } from '@lobehub/ui';
import { Skeleton } from '@lobehub/ui/base-ui';
import { Divider } from 'antd';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useClientDataSWR } from '@/libs/swr';
import { portalKeys } from '@/libs/swr/keys';
import { documentService } from '@/services/document';
@@ -33,6 +34,7 @@ import { useGoalResultData } from './useGoalResultData';
const FinalDocument = ({ documentId }: { documentId: string }) => {
// The graph carries only the document id; its content is read for the page.
+ const markdownProps = useEntityMarkdown();
const { data: document, isLoading } = useClientDataSWR(
portalKeys.documentHeader(documentId),
() => documentService.getDocumentById(documentId),
@@ -48,7 +50,11 @@ const FinalDocument = ({ documentId }: { documentId: string }) => {
</Flexbox>
);
- return <Markdown variant={'chat'}>{document?.content ?? ''}</Markdown>;
+ return (
+ <Markdown variant={'chat'} {...markdownProps}>
+ {document?.content ?? ''}
+ </Markdown>
+ );
};
interface GoalResultProps {
diff --git a/src/features/AgentGoals/ProcessControl/ResultDeliverables.tsx b/src/features/AgentGoals/ProcessControl/ResultDeliverables.tsx
index 3feccf31955..f8df1df47f1 100644
--- a/src/features/AgentGoals/ProcessControl/ResultDeliverables.tsx
+++ b/src/features/AgentGoals/ProcessControl/ResultDeliverables.tsx
@@ -7,6 +7,7 @@ import { ArrowRight, PackageOpen, SearchIcon, SearchX, X } from 'lucide-react';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useActivityTime } from '@/hooks/useActivityTime';
import { useClientDataSWR } from '@/libs/swr';
import { portalKeys } from '@/libs/swr/keys';
@@ -145,6 +146,9 @@ const DeliverableRow = ({ item, onOpen }: { item: DeliverableItem; onOpen: () =>
};
const PrimaryExcerpt = ({ documentId }: { documentId: string }) => {
+ // The card is a preview, not a reader: `aria-hidden` rows keep the inline
+ // entity chips (no raw URLs) but take no click of their own.
+ const markdownProps = useEntityMarkdown();
const { data: document, isLoading } = useClientDataSWR(
portalKeys.documentHeader(documentId),
() => documentService.getDocumentById(documentId),
@@ -162,7 +166,7 @@ const PrimaryExcerpt = ({ documentId }: { documentId: string }) => {
if (!excerpt) return null;
return (
<div aria-hidden className={styles.excerpt}>
- <Markdown fontSize={13} variant={'chat'}>
+ <Markdown fontSize={13} variant={'chat'} {...markdownProps}>
{excerpt}
</Markdown>
</div>
diff --git a/src/features/AgentGoals/ProcessControl/ResultTrail.tsx b/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
index 8dc899d6b80..87fca49b8b4 100644
--- a/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
+++ b/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
@@ -15,6 +15,7 @@ import {
import { type ReactNode, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useActivityTime } from '@/hooks/useActivityTime';
import { useChatStore } from '@/store/chat';
import { shinyTextStyles } from '@/styles';
@@ -253,6 +254,7 @@ const TrailItem = ({
const TrailFinding = ({ view }: { view: GoalNodeView }) => {
const { t } = useTranslation('chat');
const [open, setOpen] = useState(false);
+ const markdownProps = useEntityMarkdown();
const description = view.node.description;
const summary = summaryOf(description);
@@ -283,7 +285,7 @@ const TrailFinding = ({ view }: { view: GoalNodeView }) => {
/>
{open && description && (
<div className={styles.evidence}>
- <Markdown fontSize={13} variant={'chat'}>
+ <Markdown fontSize={13} variant={'chat'} {...markdownProps}>
{description}
</Markdown>
</div>
@@ -491,6 +493,7 @@ const StoryChapter = ({
}) => {
const openChapter = useChatStore((s) => s.openGoalReportChapter);
const { chapter } = view;
+ const markdownProps = useEntityMarkdown();
const hasItems = view.findings.length > 0 || view.artifacts.length > 0;
return (
@@ -508,7 +511,7 @@ const StoryChapter = ({
</>
}
>
- <Markdown className={styles.narrative} fontSize={14} variant={'chat'}>
+ <Markdown className={styles.narrative} fontSize={14} variant={'chat'} {...markdownProps}>
{chapter.narrative}
</Markdown>
{hasItems && (
diff --git a/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx b/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx
index 7ac941ad8d1..7130f879b02 100644
--- a/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx
+++ b/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx
@@ -5,6 +5,8 @@ import { render, screen } from '@testing-library/react';
import type { ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { useWorkspaceSidePanel } from '@/features/RightPanel/WorkspaceSidePanel';
+
import TaskWorkspaceLayout from './TaskWorkspaceLayout';
const mocks = vi.hoisted(() => ({
@@ -18,10 +20,17 @@ const mocks = vi.hoisted(() => ({
vi.mock('react-router', async () => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const actual = (await vi.importActual('react-router')) as typeof import('react-router');
+ const { useWorkspaceSidePanel } = await import('@/features/RightPanel/WorkspaceSidePanel');
+
+ const Outlet = () => (
+ <div data-testid="task-workspace-outlet">
+ <span data-testid="side-panel-host">{String(useWorkspaceSidePanel())}</span>
+ </div>
+ );
return {
...actual,
- Outlet: () => <div data-testid="task-workspace-outlet">outlet</div>,
+ Outlet,
};
});
@@ -78,6 +87,10 @@ vi.mock('@/hooks/useIsMobile', () => ({
useIsMobile: () => mocks.isMobile,
}));
+const SidePanelProbe = () => (
+ <span data-testid="side-panel-host">{String(useWorkspaceSidePanel())}</span>
+);
+
describe('TaskWorkspaceLayout', () => {
beforeEach(() => {
mocks.isMobile = false;
@@ -128,4 +141,19 @@ describe('TaskWorkspaceLayout', () => {
expect(screen.getByTestId('mobile-task-portal')).toBeInTheDocument();
expect(screen.queryByTestId('task-agent-manager')).not.toBeInTheDocument();
});
+
+ // The routed page must be able to tell that the side panel is already taken:
+ // a second portal host would render the same detail twice and squeeze the
+ // page's own content to nothing beside its copy (review feedback, r1).
+ it('tells the routed page that the layout already owns the side panel', () => {
+ render(<TaskWorkspaceLayout />);
+
+ expect(screen.getByTestId('side-panel-host')).toHaveTextContent('true');
+ });
+
+ it('reports no layout-owned side panel outside the workspace layout', () => {
+ render(<SidePanelProbe />);
+
+ expect(screen.getByTestId('side-panel-host')).toHaveTextContent('false');
+ });
});
diff --git a/src/features/AgentTasks/TaskWorkspaceLayout.tsx b/src/features/AgentTasks/TaskWorkspaceLayout.tsx
index 75c8f1fd723..191574860c0 100644
--- a/src/features/AgentTasks/TaskWorkspaceLayout.tsx
+++ b/src/features/AgentTasks/TaskWorkspaceLayout.tsx
@@ -6,18 +6,24 @@ import { Outlet } from 'react-router';
import AgentTaskManager from '@/features/AgentTaskManager';
import MobilePortal from '@/features/Portal/Mobile';
+import { WorkspaceSidePanelProvider } from '@/features/RightPanel/WorkspaceSidePanel';
import { useIsMobile } from '@/hooks/useIsMobile';
const TaskWorkspaceLayout = memo(() => {
const isMobile = useIsMobile();
+ // This layout owns the side panel: the task manager or the mobile portal is
+ // the one host for every route under it, so the routed page must not mount a
+ // second one (see WorkspaceSidePanel).
return (
- <Flexbox flex={1} height={'100%'} horizontal={!isMobile} width={'100%'}>
- <Flexbox flex={1} style={{ minWidth: 0 }}>
- <Outlet />
+ <WorkspaceSidePanelProvider>
+ <Flexbox flex={1} height={'100%'} horizontal={!isMobile} width={'100%'}>
+ <Flexbox flex={1} style={{ minWidth: 0 }}>
+ <Outlet />
+ </Flexbox>
+ {isMobile ? <MobilePortal /> : <AgentTaskManager />}
</Flexbox>
- {isMobile ? <MobilePortal /> : <AgentTaskManager />}
- </Flexbox>
+ </WorkspaceSidePanelProvider>
);
});
diff --git a/src/features/Conversation/Markdown/plugins/Link/index.ts b/src/features/Conversation/Markdown/plugins/Link/index.ts
index ae5b50ec18d..15c42dcefbb 100644
--- a/src/features/Conversation/Markdown/plugins/Link/index.ts
+++ b/src/features/Conversation/Markdown/plugins/Link/index.ts
@@ -1,15 +1,22 @@
import { type FC } from 'react';
+import { EntityLinkElement } from '@/features/EntityLink';
+
import { type MarkdownElement, type MarkdownElementProps } from '../type';
-import { LOBE_LINK_TAG } from './parse';
-import { rehypeLobeLink } from './rehypePlugin';
-import Render from './Render';
+/**
+ * Binds the host-agnostic entity-link capability to the conversation markdown
+ * plugin registry.
+ *
+ * The parsing, rendering and click behaviour live in `@/features/EntityLink`:
+ * the conversation is one host among several, and reading surfaces mount the
+ * same element through `useEntityMarkdown()`.
+ */
const LinkElement: MarkdownElement = {
- Component: Render as FC<MarkdownElementProps>,
- rehypePlugin: rehypeLobeLink,
+ Component: EntityLinkElement.Component as FC<MarkdownElementProps>,
+ rehypePlugin: EntityLinkElement.rehypePlugin,
scope: 'all',
- tag: LOBE_LINK_TAG,
+ tag: EntityLinkElement.tag,
};
export default LinkElement;
diff --git a/src/features/Conversation/Markdown/plugins/LocalFileLink/rehypePlugin.test.ts b/src/features/Conversation/Markdown/plugins/LocalFileLink/rehypePlugin.test.ts
index d0ef422856c..e8ec102978d 100644
--- a/src/features/Conversation/Markdown/plugins/LocalFileLink/rehypePlugin.test.ts
+++ b/src/features/Conversation/Markdown/plugins/LocalFileLink/rehypePlugin.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from 'vitest';
-import { rehypeLobeLink } from '../Link/rehypePlugin';
+import { rehypeLobeLink } from '@/features/EntityLink/rehypePlugin';
+
import { LOBE_LOCAL_FILE_LINK_TAG } from './parse';
import { rehypeLocalFileLink } from './rehypePlugin';
diff --git a/src/features/DailyBrief/BriefActionLink.tsx b/src/features/DailyBrief/BriefActionLink.tsx
index 3eaf43d0823..91becbcebce 100644
--- a/src/features/DailyBrief/BriefActionLink.tsx
+++ b/src/features/DailyBrief/BriefActionLink.tsx
@@ -8,7 +8,7 @@ import { memo, useCallback } from 'react';
import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';
import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';
-import { parseInternalLink } from '@/features/Conversation/Markdown/plugins/Link/internalLink';
+import { parseInternalLink } from '@/features/EntityLink';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { useChatStore } from '@/store/chat';
import { useGlobalStore } from '@/store/global';
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/FaviconIcon.tsx b/src/features/EntityLink/Render/FaviconIcon.tsx
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/Render/FaviconIcon.tsx
rename to src/features/EntityLink/Render/FaviconIcon.tsx
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx b/src/features/EntityLink/Render/InternalEntityLink.tsx
similarity index 89%
rename from src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx
rename to src/features/EntityLink/Render/InternalEntityLink.tsx
index 08b577106cb..47a97cfbd74 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityLink.tsx
+++ b/src/features/EntityLink/Render/InternalEntityLink.tsx
@@ -23,6 +23,7 @@ import { agentDocumentService, agentDocumentSWRKeys } from '@/services/agentDocu
import { useAgentStore } from '@/store/agent';
import { useChatStore } from '@/store/chat';
+import { useEntityLinkHostDismiss, useEntityLinkPortal } from '../host';
import { type InternalLinkReference, isBareLinkLabel, isEntityIdLabel } from '../internalLink';
import {
getPreviewData,
@@ -86,6 +87,8 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,
const { t } = useTranslation('chat');
const navigate = useWorkspaceAwareNavigate();
const activeAgentId = useAgentStore((s) => s.activeAgentId);
+ const portalAvailable = useEntityLinkPortal(reference.type);
+ const dismissHost = useEntityLinkHostDismiss();
const [
openAcceptance,
openAgentDetail,
@@ -177,6 +180,23 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,
return;
}
+ // A surface with no portal panel cannot show the detail beside its
+ // content: `open*` would set state nothing renders, leaving a click that
+ // does nothing. The entity's own route is the destination that works
+ // there β€” never a new browser tab for our own content.
+ if (!portalAvailable) {
+ // Electron registers no standalone acceptance route, so navigating
+ // there lands on a dead destination. An overlay over a portal-capable
+ // page can close and let that page's panel show the report instead.
+ if (isDesktop && reference.type === 'acceptance' && dismissHost) {
+ dismissHost();
+ openAcceptance(reference.acceptanceId);
+ return;
+ }
+ navigate(reference.pathname);
+ return;
+ }
+
switch (reference.type) {
case 'acceptance': {
// The conversation is the working surface β€” the acceptance opens
@@ -221,6 +241,7 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,
[
activeAgentId,
agentDocuments,
+ dismissHost,
navigate,
openAcceptance,
openAgentDetail,
@@ -228,6 +249,7 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,
openGoal,
openTaskDetail,
openVerifyReport,
+ portalAvailable,
reference,
resolveAgentDocuments,
shouldResolveAgentDocument,
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityPreview.tsx b/src/features/EntityLink/Render/InternalEntityPreview.tsx
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/Render/InternalEntityPreview.tsx
rename to src/features/EntityLink/Render/InternalEntityPreview.tsx
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/LinearIcon.tsx b/src/features/EntityLink/Render/LinearIcon.tsx
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/Render/LinearIcon.tsx
rename to src/features/EntityLink/Render/LinearIcon.tsx
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx b/src/features/EntityLink/Render/LinkChip.tsx
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/Render/LinkChip.tsx
rename to src/features/EntityLink/Render/LinkChip.tsx
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx b/src/features/EntityLink/Render/index.test.tsx
similarity index 87%
rename from src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
rename to src/features/EntityLink/Render/index.test.tsx
index 8a395cfa463..23672472399 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/index.test.tsx
+++ b/src/features/EntityLink/Render/index.test.tsx
@@ -5,6 +5,7 @@ import { RENDERER_HANDLED_LINK_ATTR } from '@lobechat/desktop-bridge';
import { fireEvent, render } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { EntityLinkHostProvider, type EntityLinkPortalScope } from '../host';
import Render from './index';
import { InternalEntityPreview } from './InternalEntityPreview';
@@ -121,6 +122,16 @@ const renderLink = (properties: Record<string, unknown>) =>
</Render>,
);
+/** The same link inside a host that declares what it can open in a panel. */
+const renderLinkInHost = (properties: Record<string, unknown>, portal: EntityLinkPortalScope) =>
+ render(
+ <EntityLinkHostProvider portal={portal}>
+ <Render id="msg-1" node={{ properties }} tagName="lobeLink" type="element">
+ {null}
+ </Render>
+ </EntityLinkHostProvider>,
+ );
+
afterEach(() => {
mockShowIcon = true;
mockConst.isDesktop = false;
@@ -615,3 +626,74 @@ describe('Link Render β€” open an external link in the side browser', () => {
expect(mockOpenDocument).not.toHaveBeenCalled();
});
});
+
+describe('Link Render β€” host portal scope', () => {
+ it('navigates instead of opening a detail when the host has no panel', () => {
+ const { getByRole } = renderLinkInHost(
+ { linkHref: '/acceptance/acceptance-1', linkKind: 'generic', linkLabel: 'Acceptance' },
+ false,
+ );
+
+ fireEvent.click(getByRole('link', { name: 'Acceptance' }));
+
+ // A full-screen reader covers the page: a panel opened behind it would be
+ // invisible, so the entity's own route is the only destination that works.
+ expect(mockNavigate).toHaveBeenCalledWith('/acceptance/acceptance-1');
+ expect(mockOpenAcceptance).not.toHaveBeenCalled();
+ });
+
+ it('closes the covering reader and opens the acceptance panel on desktop', () => {
+ // Electron registers no standalone `/acceptance` route, so the navigation
+ // fallback would land on a dead destination.
+ mockConst.isDesktop = true;
+ const onDismiss = vi.fn();
+ const { getByRole } = render(
+ <EntityLinkHostProvider portal={false} onDismiss={onDismiss}>
+ <Render
+ id="msg-1"
+ tagName="lobeLink"
+ type="element"
+ node={{
+ properties: {
+ linkHref: '/acceptance/acceptance-1',
+ linkKind: 'generic',
+ linkLabel: 'Acceptance',
+ },
+ }}
+ >
+ {null}
+ </Render>
+ </EntityLinkHostProvider>,
+ );
+
+ fireEvent.click(getByRole('link', { name: 'Acceptance' }));
+
+ expect(onDismiss).toHaveBeenCalledOnce();
+ expect(mockOpenAcceptance).toHaveBeenCalledWith('acceptance-1');
+ expect(mockNavigate).not.toHaveBeenCalled();
+ });
+
+ it('navigates entity kinds the host cannot present', () => {
+ const { getByRole } = renderLinkInHost(
+ { linkHref: '/task/T-198', linkKind: 'generic', linkLabel: 'T-198' },
+ ['acceptance'],
+ );
+
+ fireEvent.click(getByRole('link', { name: 'T-198' }));
+
+ expect(mockNavigate).toHaveBeenCalledWith('/task/T-198');
+ expect(mockOpenTaskDetail).not.toHaveBeenCalled();
+ });
+
+ it('still opens the kinds the host can present', () => {
+ const { getByRole } = renderLinkInHost(
+ { linkHref: '/acceptance/acceptance-1', linkKind: 'generic', linkLabel: 'Acceptance' },
+ ['acceptance'],
+ );
+
+ fireEvent.click(getByRole('link', { name: 'Acceptance' }));
+
+ expect(mockOpenAcceptance).toHaveBeenCalledWith('acceptance-1');
+ expect(mockNavigate).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx b/src/features/EntityLink/Render/index.tsx
similarity index 81%
rename from src/features/Conversation/Markdown/plugins/Link/Render/index.tsx
rename to src/features/EntityLink/Render/index.tsx
index de91228169e..3f8a7d472d3 100644
--- a/src/features/Conversation/Markdown/plugins/Link/Render/index.tsx
+++ b/src/features/EntityLink/Render/index.tsx
@@ -8,9 +8,8 @@ import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';
import { useUserStore } from '@/store/user';
import { userGeneralSettingsSelectors } from '@/store/user/selectors';
-import { type MarkdownElementProps } from '../../type';
import { parseInternalLink } from '../internalLink';
-import { type LobeLinkKind } from '../parse';
+import { type EntityLinkElementProps, type EntityLinkProperties } from '../types';
import FaviconIcon from './FaviconIcon';
import { InternalEntityLink } from './InternalEntityLink';
import LinearIcon from './LinearIcon';
@@ -18,15 +17,9 @@ import LinkChip from './LinkChip';
const ICON_SIZE = 15;
-interface LobeLinkProperties {
- linkDomain?: string;
- linkHref?: string;
- linkKind?: LobeLinkKind;
- linkLabel?: string;
-}
-
-const Render = memo<MarkdownElementProps<LobeLinkProperties>>(({ node }) => {
- const { linkHref, linkKind, linkLabel, linkDomain } = node?.properties || {};
+const Render = memo<EntityLinkElementProps>(({ node }) => {
+ const properties: EntityLinkProperties = node?.properties ?? {};
+ const { linkHref, linkKind, linkLabel, linkDomain } = properties;
const showIcon = useUserStore(userGeneralSettingsSelectors.enableMessageLinkIcon);
const workspaces = useWorkspaces();
diff --git a/src/features/EntityLink/element.ts b/src/features/EntityLink/element.ts
new file mode 100644
index 00000000000..b82e1974711
--- /dev/null
+++ b/src/features/EntityLink/element.ts
@@ -0,0 +1,24 @@
+import { type FC } from 'react';
+
+import { LOBE_LINK_TAG } from './parse';
+import { rehypeLobeLink } from './rehypePlugin';
+import Render from './Render';
+import { type EntityLinkElementProps } from './types';
+
+/**
+ * The entity-link markdown element, host-agnostic: one rehype pass that rewrites
+ * internal anchors into `<lobeLink>`, plus the renderer that turns them into
+ * inline chips.
+ *
+ * The conversation mounts it through its markdown plugin registry; every other
+ * reading surface mounts the same element through `useEntityMarkdown()`, so one
+ * place owns what an internal link looks like and where it opens.
+ */
+export const EntityLinkElement = {
+ Component: Render as FC<EntityLinkElementProps>,
+ rehypePlugin: rehypeLobeLink,
+ scope: 'all' as const,
+ tag: LOBE_LINK_TAG,
+};
+
+export default EntityLinkElement;
diff --git a/src/features/EntityLink/host.tsx b/src/features/EntityLink/host.tsx
new file mode 100644
index 00000000000..a4a0a57fd73
--- /dev/null
+++ b/src/features/EntityLink/host.tsx
@@ -0,0 +1,55 @@
+'use client';
+
+import { createContext, type FC, type PropsWithChildren, use } from 'react';
+
+import { type InternalLinkReference } from './internalLink';
+
+/**
+ * Which entity details this surface can show in a side panel.
+ *
+ * - `true` β€” every kind. The conversation, the goal page, the task manager and
+ * the mobile portal all mount `PortalContent`, which renders any view.
+ * - a list β€” only those kinds. Home mounts the acceptance drawer and nothing
+ * else, so anything else must fall back to its own route.
+ * - `false` β€” none. A full-screen reader has no panel to open into.
+ */
+export type EntityLinkPortalScope = boolean | readonly InternalLinkReference['type'][];
+
+/**
+ * Defaults to `true` because that is the behaviour every existing surface
+ * already has: a host only declares a scope when it cannot render every detail.
+ */
+const EntityLinkPortalContext = createContext<EntityLinkPortalScope>(true);
+
+/**
+ * How a host that covers a portal-capable page gets out of the way. Set only by
+ * overlays (the deliverable reader): closing them uncovers a page whose side
+ * panel can show the detail, for destinations that have no route on every
+ * platform.
+ */
+const EntityLinkDismissContext = createContext<(() => void) | undefined>(undefined);
+
+export const EntityLinkHostProvider: FC<
+ PropsWithChildren<{ onDismiss?: () => void; portal: EntityLinkPortalScope }>
+> = ({ children, onDismiss, portal }) => (
+ <EntityLinkPortalContext value={portal}>
+ <EntityLinkDismissContext value={onDismiss}>{children}</EntityLinkDismissContext>
+ </EntityLinkPortalContext>
+);
+
+/** The covering host's close callback, when it has one β€” see {@link EntityLinkHostProvider}. */
+export const useEntityLinkHostDismiss = (): (() => void) | undefined =>
+ use(EntityLinkDismissContext);
+
+/**
+ * Whether this host can open `referenceType`'s detail in a panel. A `route`
+ * link has no detail of its own, so it always resolves by navigation.
+ */
+export const useEntityLinkPortal = (referenceType: InternalLinkReference['type']): boolean => {
+ const scope = use(EntityLinkPortalContext);
+
+ if (referenceType === 'route') return false;
+ if (typeof scope === 'boolean') return scope;
+
+ return scope.includes(referenceType);
+};
diff --git a/src/features/EntityLink/index.ts b/src/features/EntityLink/index.ts
new file mode 100644
index 00000000000..e71f3ecaf83
--- /dev/null
+++ b/src/features/EntityLink/index.ts
@@ -0,0 +1,9 @@
+export { default as EntityLinkElement } from './element';
+export { EntityLinkHostProvider, useEntityLinkPortal } from './host';
+export type { InternalLinkReference } from './internalLink';
+export { isBareLinkLabel, isEntityIdLabel, parseInternalLink } from './internalLink';
+export type { LobeLinkKind, ParsedLobeLink } from './parse';
+export { LOBE_LINK_TAG, parseLobeLink } from './parse';
+export { default as EntityLinkRender } from './Render';
+export type { EntityLinkElementProps, EntityLinkProperties } from './types';
+export { useEntityMarkdown } from './useEntityMarkdown';
diff --git a/src/features/Conversation/Markdown/plugins/Link/internalLink.test.ts b/src/features/EntityLink/internalLink.test.ts
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/internalLink.test.ts
rename to src/features/EntityLink/internalLink.test.ts
diff --git a/src/features/Conversation/Markdown/plugins/Link/internalLink.ts b/src/features/EntityLink/internalLink.ts
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/internalLink.ts
rename to src/features/EntityLink/internalLink.ts
diff --git a/src/features/Conversation/Markdown/plugins/Link/parse.test.ts b/src/features/EntityLink/parse.test.ts
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/parse.test.ts
rename to src/features/EntityLink/parse.test.ts
diff --git a/src/features/Conversation/Markdown/plugins/Link/parse.ts b/src/features/EntityLink/parse.ts
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/parse.ts
rename to src/features/EntityLink/parse.ts
diff --git a/src/features/Conversation/Markdown/plugins/Link/rehypePlugin.ts b/src/features/EntityLink/rehypePlugin.ts
similarity index 100%
rename from src/features/Conversation/Markdown/plugins/Link/rehypePlugin.ts
rename to src/features/EntityLink/rehypePlugin.ts
diff --git a/src/features/EntityLink/types.ts b/src/features/EntityLink/types.ts
new file mode 100644
index 00000000000..a74f8b59df8
--- /dev/null
+++ b/src/features/EntityLink/types.ts
@@ -0,0 +1,26 @@
+import { type ReactNode } from 'react';
+
+import { type LobeLinkKind } from './parse';
+
+/** Properties the rehype pass stamps onto a rewritten `<lobeLink>` element. */
+export interface EntityLinkProperties {
+ linkDomain?: string;
+ linkHref?: string;
+ linkKind?: LobeLinkKind;
+ linkLabel?: string;
+}
+
+/**
+ * Props the markdown element pipeline hands the entity-link renderer.
+ *
+ * Every field is optional on purpose: the conversation plugin registry passes
+ * `id` / `tagName` / `type`, a bare reading surface passes only `node`, and the
+ * looser shape is what lets both mount this one element.
+ */
+export interface EntityLinkElementProps {
+ children?: ReactNode;
+ id?: string;
+ node?: { properties?: EntityLinkProperties };
+ tagName?: string;
+ type?: string;
+}
diff --git a/src/features/EntityLink/useEntityMarkdown.test.ts b/src/features/EntityLink/useEntityMarkdown.test.ts
new file mode 100644
index 00000000000..c47eb6c7c1f
--- /dev/null
+++ b/src/features/EntityLink/useEntityMarkdown.test.ts
@@ -0,0 +1,15 @@
+import { renderHook } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+
+import EntityLinkElement from './element';
+import { useEntityMarkdown } from './useEntityMarkdown';
+
+describe('useEntityMarkdown', () => {
+ it('mounts only the provider-free entity link element', () => {
+ const { result } = renderHook(() => useEntityMarkdown());
+
+ expect(Object.keys(result.current.components ?? {})).toEqual([EntityLinkElement.tag]);
+ expect(result.current.rehypePlugins).toEqual([EntityLinkElement.rehypePlugin]);
+ expect(result.current.remarkPlugins).toBeUndefined();
+ });
+});
diff --git a/src/features/EntityLink/useEntityMarkdown.ts b/src/features/EntityLink/useEntityMarkdown.ts
new file mode 100644
index 00000000000..182a4a22929
--- /dev/null
+++ b/src/features/EntityLink/useEntityMarkdown.ts
@@ -0,0 +1,28 @@
+'use client';
+
+import { type MarkdownProps } from '@lobehub/ui';
+import { useMemo } from 'react';
+
+import EntityLinkElement from './element';
+
+/**
+ * Markdown props for surfaces that read LobeHub-authored content outside the
+ * conversation β€” a goal's delivered document, a deliverable reader, a report
+ * chapter.
+ *
+ * Internal links (acceptance / task / goal / document / agent / verify) render
+ * as inline chips carrying the entity's own title, with the hover preview and
+ * the same click destination the conversation uses, instead of a raw URL that
+ * navigates the reader away.
+ *
+ * Only the provider-free link element is mounted: the rest of the conversation
+ * plugin set needs chat context these hosts do not provide.
+ */
+export const useEntityMarkdown = (): Partial<MarkdownProps> => {
+ const components = useMemo(() => ({ [EntityLinkElement.tag]: EntityLinkElement.Component }), []);
+
+ return useMemo(
+ () => ({ components, rehypePlugins: [EntityLinkElement.rehypePlugin] }),
+ [components],
+ );
+};
diff --git a/src/features/Home/HomeModeContent.tsx b/src/features/Home/HomeModeContent.tsx
index 5065fc73385..94bc5ea90e9 100644
--- a/src/features/Home/HomeModeContent.tsx
+++ b/src/features/Home/HomeModeContent.tsx
@@ -16,6 +16,9 @@ import TaskStatusIcon from '@/features/AgentTasks/features/TaskStatusIcon';
import TaskTriggerTag from '@/features/AgentTasks/features/TaskTriggerTag';
import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';
import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';
+// Deep import, not the feature barrel: the inbox renderer loads lazily with
+// HomeInbox, and this surface must not pull it into its own chunk.
+import { EntityLinkHostProvider } from '@/features/EntityLink/host';
import HomeInbox from '@/features/HomeInbox';
import AuthorChip from '@/features/HomeInbox/AuthorChip';
import { filterTopicsForInboxScope } from '@/features/HomeInbox/scopeTogglePlacement';
@@ -38,6 +41,7 @@ import { useUserStore } from '@/store/user';
import { authSelectors, userProfileSelectors } from '@/store/user/slices/auth/selectors';
import { markdownToTxt } from '@/utils/markdownToTxt';
+import { HOME_ENTITY_PORTAL_SCOPE } from './acceptancePortalView';
import GroupBlock from './components/GroupBlock';
import { homeType } from './components/homeType';
import RunningGlyph from './components/RunningGlyph';
@@ -538,7 +542,9 @@ const HomeModeContent = memo<HomeModeContentProps>(({ inlineRail, mode, onSugges
return (
<Flexbox gap={32}>
{starters}
- <HomeInbox inlineRail variant={'main'} />
+ <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
+ <HomeInbox inlineRail variant={'main'} />
+ </EntityLinkHostProvider>
<Recommendations variant={'main'} />
</Flexbox>
);
@@ -546,12 +552,14 @@ const HomeModeContent = memo<HomeModeContentProps>(({ inlineRail, mode, onSugges
return (
<Flexbox gap={32}>
- <HomeInbox
- inlineRail={inlineRail}
- scope={scope}
- variant={'main'}
- onScopeChange={setScope}
- />
+ <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
+ <HomeInbox
+ inlineRail={inlineRail}
+ scope={scope}
+ variant={'main'}
+ onScopeChange={setScope}
+ />
+ </EntityLinkHostProvider>
{!recentsHidden && (state !== 'ready' || topicRecents.length > 0) && (
<GroupBlock
actionAlwaysVisible
@@ -614,7 +622,9 @@ const HomeModeContent = memo<HomeModeContentProps>(({ inlineRail, mode, onSugges
// hidden β€” task mode never surfaces them, folded or not.
return (
<Flexbox gap={32}>
- <HomeInbox hideNeedsYou hideUnread inlineRail variant={'main'} />
+ <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
+ <HomeInbox hideNeedsYou hideUnread inlineRail variant={'main'} />
+ </EntityLinkHostProvider>
{taskBlocks}
<Recommendations variant={'main'} />
</Flexbox>
diff --git a/src/features/Home/acceptancePortalView.ts b/src/features/Home/acceptancePortalView.ts
index 9db3df82995..852e967dfcd 100644
--- a/src/features/Home/acceptancePortalView.ts
+++ b/src/features/Home/acceptancePortalView.ts
@@ -1,5 +1,14 @@
+import { type InternalLinkReference } from '@/features/EntityLink';
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;
+
+/**
+ * Entity details the inbox can open in the acceptance drawer. Everything else β€”
+ * a task, a goal, a document β€” has no panel here and follows its own route.
+ */
+export const HOME_ENTITY_PORTAL_SCOPE = [
+ 'acceptance',
+] as const satisfies readonly InternalLinkReference['type'][];
diff --git a/src/features/Home/index.tsx b/src/features/Home/index.tsx
index e25646c04d0..3d03641a3e8 100644
--- a/src/features/Home/index.tsx
+++ b/src/features/Home/index.tsx
@@ -6,6 +6,9 @@ import { lazy, memo, Suspense, useCallback, useEffect, useState } from 'react';
import { useHomeUsageWidgetActive } from '@/business/client/features/HomeUsageWidget';
import { useHomePromoLine } from '@/business/client/features/useHomePromoLine';
+// Deep import, not the feature barrel: the inbox renderer loads lazily with
+// HomeInbox, and Home must not pull it into its own chunk for one provider.
+import { EntityLinkHostProvider } from '@/features/EntityLink/host';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
@@ -15,7 +18,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 { HOME_ENTITY_PORTAL_SCOPE, isAcceptancePortalView } from './acceptancePortalView';
import { isHomeMinimalLayout } from './CustomizeModal/config';
import HomeHeader from './HomeHeader';
import HomeModeContent from './HomeModeContent';
@@ -451,7 +454,11 @@ const Home = memo(() => {
inert={railCollapsed}
>
<Suspense fallback={null}>
- <HomeInbox {...RAIL_INBOX_PROPS} variant={'rail'} />
+ {/* The inbox reads assistant replies, which carry internal entity
+ links; only the acceptance drawer can show a detail here. */}
+ <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
+ <HomeInbox {...RAIL_INBOX_PROPS} variant={'rail'} />
+ </EntityLinkHostProvider>
</Suspense>
</aside>
)}
diff --git a/src/features/HomeInbox/UnreadTopicList.tsx b/src/features/HomeInbox/UnreadTopicList.tsx
index 16c12a00863..1b2199c099e 100644
--- a/src/features/HomeInbox/UnreadTopicList.tsx
+++ b/src/features/HomeInbox/UnreadTopicList.tsx
@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
import UnreadDot from '@/components/UnreadDot';
import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { homeType } from '@/features/Home/components/homeType';
import Time from '@/features/Home/components/Time';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
@@ -17,7 +18,6 @@ import { useChatStore } from '@/store/chat';
import AuthorChip from './AuthorChip';
import { sanitizeInboxPreview } from './sanitizeInboxPreview';
-import { useHomeInboxMarkdown } from './useHomeInboxMarkdown';
import { type InboxTopic } from './useHomeInboxTopics';
const MarkdownMessage = lazy(() => import('@/features/Conversation/Markdown'));
@@ -111,7 +111,7 @@ 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 markdownProps = useEntityMarkdown();
const assistantPreview = sanitizeInboxPreview(topic.lastAssistantMessage ?? '');
const [expanded, setExpanded] = useState(false);
diff --git a/src/features/HomeInbox/useHomeInboxMarkdown.test.ts b/src/features/HomeInbox/useHomeInboxMarkdown.test.ts
deleted file mode 100644
index a18bc12c42b..00000000000
--- a/src/features/HomeInbox/useHomeInboxMarkdown.test.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-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.tsx
deleted file mode 100644
index da16b1a27c8..00000000000
--- a/src/features/HomeInbox/useHomeInboxMarkdown.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-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],
- );
-};
diff --git a/src/features/Portal/GoalReport/Body.tsx b/src/features/Portal/GoalReport/Body.tsx
index 0f52e9e32e2..77a9afb623e 100644
--- a/src/features/Portal/GoalReport/Body.tsx
+++ b/src/features/Portal/GoalReport/Body.tsx
@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';
import AsyncError from '@/components/AsyncError';
import Graph from '@/features/AgentGoals/ProcessControl/Graph';
import { chapterMap } from '@/features/AgentGoals/ProcessControl/Graph/chapterMap';
+import { useEntityMarkdown } from '@/features/EntityLink';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
@@ -58,6 +59,7 @@ const Unavailable = ({ children }: { children: string }) => (
export const ReportBody = memo(() => {
const { t } = useTranslation('chat');
const view = useChatStore(chatPortalSelectors.goalReportView);
+ const markdownProps = useEntityMarkdown();
const { error, isLoading, mutate, story } = useReportGraph(view?.goalId);
if (!view) return null;
@@ -73,7 +75,9 @@ export const ReportBody = memo(() => {
{story.metadata.headline}
</Text>
{content ? (
- <Markdown variant={'chat'}>{content}</Markdown>
+ <Markdown variant={'chat'} {...markdownProps}>
+ {content}
+ </Markdown>
) : (
<Text type={'secondary'}>{t('goalProcess.result.story.reportEmpty')}</Text>
)}
diff --git a/src/features/RightPanel/WorkspaceSidePanel.tsx b/src/features/RightPanel/WorkspaceSidePanel.tsx
new file mode 100644
index 00000000000..0ecee2d8391
--- /dev/null
+++ b/src/features/RightPanel/WorkspaceSidePanel.tsx
@@ -0,0 +1,19 @@
+'use client';
+
+import { createContext, type FC, type PropsWithChildren, use } from 'react';
+
+/**
+ * Whether an ancestor layout already mounts this workspace's side panel.
+ *
+ * A routed page that would otherwise carry its own panel reads this and stays
+ * out of the way. Two portal hosts on one surface render the same detail in
+ * both panels, and the page's own content is squeezed out beside them β€” so a
+ * link that opens a detail looks like it replaced the page it was clicked in.
+ */
+const WorkspaceSidePanelContext = createContext(false);
+
+export const WorkspaceSidePanelProvider: FC<PropsWithChildren> = ({ children }) => (
+ <WorkspaceSidePanelContext value={true}>{children}</WorkspaceSidePanelContext>
+);
+
+export const useWorkspaceSidePanel = () => use(WorkspaceSidePanelContext);
diff --git a/src/features/Settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx b/src/features/Settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx
index 901bd0a76f8..60990888446 100644
--- a/src/features/Settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx
+++ b/src/features/Settings/chat-appearance/features/ChatAppearance/LinkIconPreview.tsx
@@ -5,8 +5,7 @@ import { memo } from 'react';
import { Trans } from 'react-i18next';
import { OFFICIAL_SITE } from '@/const/url';
-import { type LobeLinkKind } from '@/features/Conversation/Markdown/plugins/Link/parse';
-import LinkRender from '@/features/Conversation/Markdown/plugins/Link/Render';
+import { EntityLinkRender, type LobeLinkKind } from '@/features/EntityLink';
const styles = createStaticStyles(({ css, cssVar }) => ({
bubble: css`
@@ -34,14 +33,14 @@ interface SampleLinkProps {
// Reuse the real message link renderer so the preview reflects the live
// `enableMessageLinkIcon` setting exactly as chat messages do.
const SampleLink = memo<SampleLinkProps>(({ kind, href, label, domain }) => (
- <LinkRender
+ <EntityLinkRender
id={`link-icon-preview-${kind}`}
node={{ properties: { linkDomain: domain, linkHref: href, linkKind: kind, linkLabel: label } }}
tagName="lobeLink"
type="element"
>
{null}
- </LinkRender>
+ </EntityLinkRender>
));
const LinkIconPreview = memo(() => (