🤯 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
🐛 fix(task): keep artifact previews in run drawer (#19641)
YuTengjing170161bb93f4
diff --git a/src/features/AgentTaskManager/index.tsx b/src/features/AgentTaskManager/index.tsxindex 1d79b462a69..042ff4e2a59 100644--- a/src/features/AgentTaskManager/index.tsx+++ b/src/features/AgentTaskManager/index.tsx@@ -1,5 +1,6 @@import { memo } from 'react';+import { useTopicDrawerArtifactPortal } from '@/features/AgentTasks/hooks/useTopicDrawerArtifactPortal';import { PortalContent } from '@/features/Portal/router';import RightPanel from '@/features/RightPanel';import { useChatStore } from '@/store/chat';@@ -21,20 +22,25 @@ const AgentTaskManager = memo<AgentTaskManagerProps>(({ preferredAgentId, viewedsystemStatusSelectors.showTaskAgentPanel(s),s.toggleTaskAgentPanel,]);- const portalView = useChatStore(chatPortalSelectors.currentViewType);- const showAcceptance =- portalView === PortalViewType.Acceptance || portalView === PortalViewType.AcceptanceCheck;+ const [portalView, showPortal] = useChatStore((s) => [+ chatPortalSelectors.currentViewType(s),+ chatPortalSelectors.showStandalonePortal(s),+ ]);+ const showArtifactInTopicDrawer = useTopicDrawerArtifactPortal();+ const showPortalInTaskPanel = showPortal && !showArtifactInTopicDrawer;return (<RightPaneldefaultWidth={420}- expand={expand}+ expand={expand || showPortalInTaskPanel}maxWidth={720}minWidth={320}width={portalView === PortalViewType.AcceptanceCheck ? 640 : undefined}onExpandChange={(next) => toggleTaskAgentPanel(next)}>- {showAcceptance ? (+ {/* Artifact cards in the run drawer keep that reading context. Other task+ portals render here because Tasks routes have no desktop Portal host. */}+ {showPortalInTaskPanel ? (<PortalContent />) : (<TaskAgentProvider preferredAgentId={preferredAgentId} viewedTaskId={viewedTaskId}>diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsxindex a6190f58ad6..7dc26870756 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx@@ -15,8 +15,15 @@ const mocks = vi.hoisted(() => ({useHydrateAgentConfig: vi.fn(),},chatState: {- dbMessagesMap: {} as Record<string, unknown[]>,+ closeArtifact: vi.fn(),+ clearPortalStack: vi.fn(),+ dbMessagesMap: {+ 'topic-chat-key': [{ id: 'message-1' }],+ } as Record<string, { id: string }[]>,+ messagesMap: {} as Record<string, { id: string }[]>,+ portalStack: [] as { artifact?: { id: string }; taskId?: string; type: string }[],replaceMessages: vi.fn(),+ showPortal: false,},permission: {allowed: true,@@ -180,6 +187,14 @@ vi.mock('@/features/Conversation/Markdown/plugins/Task', () => ({TaskCardScopeProvider: ({ children }: { children?: ReactNode }) => <>{children}</>,}));+vi.mock('@/features/Portal/router', () => ({+ PortalContent: ({ onClose }: { onClose?: () => void }) => (+ <button data-testid="artifact-portal" onClick={onClose}>+ artifact portal+ </button>+ ),+}));+vi.mock('@/features/ShareModal', () => ({useShareModal: () => ({openShareModal: vi.fn(),@@ -254,6 +269,17 @@ describe('TopicChatDrawer', () => {beforeEach(() => {mocks.agentState.useHydrateAgentConfig.mockClear();mocks.chatState.replaceMessages.mockClear();+ mocks.chatState.portalStack = [];+ mocks.chatState.showPortal = false;+ mocks.chatState.closeArtifact.mockClear();+ mocks.chatState.closeArtifact.mockImplementation(() => {+ mocks.chatState.portalStack = mocks.chatState.portalStack.slice(0, -1);+ });+ mocks.chatState.clearPortalStack.mockClear();+ mocks.chatState.clearPortalStack.mockImplementation(() => {+ mocks.chatState.portalStack = [];+ mocks.chatState.showPortal = false;+ });mocks.navigate.mockClear();mocks.taskState.closeTopicDrawer.mockClear();mocks.taskState.activeTopicDrawerTopicId = 'topic-1';@@ -388,6 +414,43 @@ describe('TopicChatDrawer', () => {expect(mocks.navigate).toHaveBeenCalledWith('/agent/agt_assignee/topic-1');});+ it('closes an artifact inside the run drawer without clearing its parent task portal', () => {+ mocks.chatState.portalStack = [+ { taskId: 'T-1', type: 'taskDetail' },+ { artifact: { id: 'message-1' }, type: 'artifact' },+ ];+ mocks.chatState.showPortal = true;++ const view = render(<TopicChatDrawer />);++ expect(view.getByTestId('topic-panel')).toBeInTheDocument();+ expect(view.getByTestId('artifact-portal')).toBeInTheDocument();+ expect(view.queryByTestId('chat-list')).not.toBeInTheDocument();+ expect(mocks.taskState.closeTopicDrawer).not.toHaveBeenCalled();++ fireEvent.click(view.getByTestId('artifact-portal'));+ expect(mocks.chatState.closeArtifact).toHaveBeenCalledOnce();+ expect(mocks.chatState.clearPortalStack).not.toHaveBeenCalled();++ view.unmount();+ const conversationView = render(<TopicChatDrawer />);++ expect(conversationView.getByTestId('chat-list')).toBeInTheDocument();+ expect(conversationView.queryByTestId('artifact-portal')).not.toBeInTheDocument();+ expect(mocks.taskState.closeTopicDrawer).not.toHaveBeenCalled();+ });++ it('does not take over an artifact opened by another conversation', () => {+ mocks.chatState.portalStack = [{ artifact: { id: 'another-message' }, type: 'artifact' }];+ mocks.chatState.showPortal = true;++ const view = render(<TopicChatDrawer />);++ expect(view.getByTestId('chat-list')).toBeInTheDocument();+ expect(view.queryByTestId('artifact-portal')).not.toBeInTheDocument();+ expect(mocks.taskState.closeTopicDrawer).not.toHaveBeenCalled();+ });+it('uses a resizable bottom-right floating panel', () => {const { getByTestId } = render(<TopicChatDrawer />);diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsxindex fb33a164171..2c154ebd5bb 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx@@ -22,6 +22,7 @@ import ChatList from '@/features/Conversation/ChatList';import { ConversationProvider } from '@/features/Conversation/ConversationProvider';import { TaskCardScopeProvider } from '@/features/Conversation/Markdown/plugins/Task';import MessageItem from '@/features/Conversation/Messages';+import { PortalContent } from '@/features/Portal/router';import { useShareModal } from '@/features/ShareModal';import { LazySharePopover as SharePopover } from '@/features/SharePopover/lazy';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';@@ -40,6 +41,7 @@ import { authSelectors } from '@/store/user/selectors';import { isForbiddenError } from '@/utils/forbiddenError';import AssigneeAvatar from '../../features/AssigneeAvatar';+import { useTopicDrawerArtifactPortal } from '../../hooks/useTopicDrawerArtifactPortal';import FeedbackInput from './FeedbackInput';const SHARE_ICON_SIZE = { blockSize: 32, size: 16 } as const;@@ -136,6 +138,8 @@ const TopicChatDrawer = memo(() => {const closeTopicDrawer = useTaskStore((s) => s.closeTopicDrawer);const deleteTopic = useTaskStore((s) => s.deleteTopic);const useFetchTaskDetail = useTaskStore((s) => s.useFetchTaskDetail);+ const showArtifactPortal = useTopicDrawerArtifactPortal();+ const closeArtifact = useChatStore((s) => s.closeArtifact);const enableTopicLinkShare = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);const { allowed: canShare, reason } = usePermission('edit_own_content');const { allowed: canEditTask } = usePermission('create_content');@@ -351,7 +355,14 @@ const TopicChatDrawer = memo(() => {task: a run opened from the home inbox may have no parent task at all,and gating on one renders a titled but empty panel. */}<Freeze frozen={!open}>- {open && <TopicChatDrawerBody agentId={agentId!} topicId={topicId!} />}+ {open &&+ (showArtifactPortal ? (+ <Flexbox height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>+ <PortalContent onClose={closeArtifact} />+ </Flexbox>+ ) : (+ <TopicChatDrawerBody agentId={agentId!} topicId={topicId!} />+ ))}</Freeze></FloatingPanel>);diff --git a/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx b/src/features/AgentTasks/TaskWorkspaceLayout.test.tsxindex 657d4498512..7ac941ad8d1 100644--- a/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx+++ b/src/features/AgentTasks/TaskWorkspaceLayout.test.tsx@@ -2,12 +2,17 @@* @vitest-environment happy-dom*/import { render, screen } from '@testing-library/react';+import type { ReactNode } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';import TaskWorkspaceLayout from './TaskWorkspaceLayout';const mocks = vi.hoisted(() => ({isMobile: false,+ portalView: null as null | string,+ showArtifactInTopicDrawer: false,+ showPortal: false,+ taskAgentPanelExpanded: true,}));vi.mock('react-router', async () => {@@ -20,8 +25,50 @@ vi.mock('react-router', async () => {};});-vi.mock('@/features/AgentTaskManager', () => ({- default: () => <div data-testid="task-agent-manager" />,+vi.mock('@/features/AgentTaskManager/Conversation', () => ({+ default: () => <div data-testid="task-agent-conversation" />,+}));++vi.mock('@/features/AgentTaskManager/TaskAgentProvider', () => ({+ TaskAgentProvider: ({ children }: { children: ReactNode }) => children,+}));++vi.mock('@/features/AgentTasks/hooks/useTopicDrawerArtifactPortal', () => ({+ useTopicDrawerArtifactPortal: () => mocks.showArtifactInTopicDrawer,+}));++vi.mock('@/features/Portal/router', () => ({+ PortalContent: () => <div data-testid="task-agent-portal" />,+}));++vi.mock('@/features/RightPanel', () => ({+ default: ({ children, expand }: { children: ReactNode; expand: boolean }) => (+ <div data-expand={String(expand)} data-testid="task-agent-manager">+ {children}+ </div>+ ),+}));++vi.mock('@/store/chat', () => ({+ useChatStore: (selector: (state: unknown) => unknown) =>+ selector({+ portalStack: mocks.portalView ? [{ type: mocks.portalView }] : [],+ showPortal: mocks.showPortal,+ }),+}));++vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (state: unknown) => unknown) =>+ selector({+ showTaskAgentPanel: mocks.taskAgentPanelExpanded,+ toggleTaskAgentPanel: vi.fn(),+ }),+}));++vi.mock('@/store/global/selectors', () => ({+ systemStatusSelectors: {+ showTaskAgentPanel: (state: { showTaskAgentPanel: boolean }) => state.showTaskAgentPanel,+ },}));vi.mock('@/features/Portal/Mobile', () => ({@@ -34,6 +81,10 @@ vi.mock('@/hooks/useIsMobile', () => ({describe('TaskWorkspaceLayout', () => {beforeEach(() => {mocks.isMobile = false;+ mocks.portalView = null;+ mocks.showArtifactInTopicDrawer = false;+ mocks.showPortal = false;+ mocks.taskAgentPanelExpanded = true;});it('renders the task workspace without mutating global NavPanel state', () => {@@ -41,6 +92,32 @@ describe('TaskWorkspaceLayout', () => {expect(screen.getByTestId('task-workspace-outlet')).toBeInTheDocument();expect(screen.getByTestId('task-agent-manager')).toBeInTheDocument();+ expect(screen.getByTestId('task-agent-conversation')).toBeInTheDocument();+ });++ it('renders portal content when an artifact is opened from a task conversation', () => {+ mocks.portalView = 'artifact';+ mocks.showPortal = true;+ mocks.taskAgentPanelExpanded = false;++ render(<TaskWorkspaceLayout />);++ expect(screen.getByTestId('task-agent-portal')).toBeInTheDocument();+ expect(screen.queryByTestId('task-agent-conversation')).not.toBeInTheDocument();+ expect(screen.getByTestId('task-agent-manager')).toHaveAttribute('data-expand', 'true');+ });++ it('leaves an artifact from the run drawer out of the task assistant panel', () => {+ mocks.portalView = 'artifact';+ mocks.showArtifactInTopicDrawer = true;+ mocks.showPortal = true;+ mocks.taskAgentPanelExpanded = false;++ render(<TaskWorkspaceLayout />);++ expect(screen.queryByTestId('task-agent-portal')).not.toBeInTheDocument();+ expect(screen.getByTestId('task-agent-conversation')).toBeInTheDocument();+ expect(screen.getByTestId('task-agent-manager')).toHaveAttribute('data-expand', 'false');});it('mounts the Portal surface instead of the desktop task manager on mobile', () => {diff --git a/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.test.ts b/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.test.tsnew file mode 100644index 00000000000..6eb7dd72644--- /dev/null+++ b/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.test.ts@@ -0,0 +1,40 @@+import { describe, expect, it } from 'vitest';++import { PortalViewType } from '@/store/chat/slices/portal/initialState';++import { resolveTopicDrawerPortalHostViewType } from './useTopicDrawerArtifactPortal';++describe('resolveTopicDrawerPortalHostViewType', () => {+ it.each([PortalViewType.TaskDetail, PortalViewType.TaskResult])(+ 'keeps the %s portal mounted while its drawer owns the artifact',+ (parentViewType) => {+ expect(+ resolveTopicDrawerPortalHostViewType({+ currentViewType: PortalViewType.Artifact,+ parentViewType,+ showArtifactPortal: true,+ }),+ ).toBe(parentViewType);+ },+ );++ it('keeps the artifact in the outer host when no task portal owns it', () => {+ expect(+ resolveTopicDrawerPortalHostViewType({+ currentViewType: PortalViewType.Artifact,+ parentViewType: PortalViewType.TaskDetail,+ showArtifactPortal: false,+ }),+ ).toBe(PortalViewType.Artifact);+ });++ it('does not preserve an unrelated parent portal', () => {+ expect(+ resolveTopicDrawerPortalHostViewType({+ currentViewType: PortalViewType.Artifact,+ parentViewType: PortalViewType.Goal,+ showArtifactPortal: true,+ }),+ ).toBe(PortalViewType.Artifact);+ });+});diff --git a/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.ts b/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.tsnew file mode 100644index 00000000000..a3ab6cfb6b3--- /dev/null+++ b/src/features/AgentTasks/hooks/useTopicDrawerArtifactPortal.ts@@ -0,0 +1,78 @@+import { useMemo } from 'react';++import { useChatStore } from '@/store/chat';+import { chatPortalSelectors } from '@/store/chat/selectors';+import { PortalViewType } from '@/store/chat/slices/portal/initialState';+import { messageMapKey } from '@/store/chat/utils/messageMapKey';+import { useTaskStore } from '@/store/task';+import { taskDetailSelectors } from '@/store/task/selectors';++interface ResolveTopicDrawerPortalHostViewTypeOptions {+ currentViewType: PortalViewType | null;+ parentViewType: PortalViewType | null;+ showArtifactPortal: boolean;+}++export const resolveTopicDrawerPortalHostViewType = ({+ currentViewType,+ parentViewType,+ showArtifactPortal,+}: ResolveTopicDrawerPortalHostViewTypeOptions): PortalViewType | null => {+ if (+ showArtifactPortal &&+ currentViewType === PortalViewType.Artifact &&+ (parentViewType === PortalViewType.TaskDetail || parentViewType === PortalViewType.TaskResult)+ ) {+ return parentViewType;+ }++ return currentViewType;+};++/**+ * Whether the visible artifact belongs to the conversation hosted by the open run drawer.+ */+export const useTopicDrawerArtifactPortal = () => {+ const [topicId, agentId] = useTaskStore((s) => [+ taskDetailSelectors.activeTopicDrawerTopicId(s),+ taskDetailSelectors.topicDrawerAgentId(s),+ ]);++ const chatKey = useMemo(() => {+ if (!agentId || !topicId) return;++ return messageMapKey({ agentId, scope: 'main', topicId });+ }, [agentId, topicId]);++ return useChatStore((s) => {+ if (+ !chatKey ||+ !chatPortalSelectors.showStandalonePortal(s) ||+ !chatPortalSelectors.showArtifactUI(s)+ ) {+ return false;+ }++ const artifactMessageId = chatPortalSelectors.artifactMessageId(s);+ if (!artifactMessageId) return false;++ return [s.messagesMap[chatKey], s.dbMessagesMap[chatKey]].some((messages) =>+ messages?.some((message) => message.id === artifactMessageId),+ );+ });+};++/**+ * Keeps a parent Task portal mounted while its open run drawer hosts the top Artifact view.+ */+export const useTopicDrawerPortalHostViewType = () => {+ const showArtifactPortal = useTopicDrawerArtifactPortal();++ return useChatStore((s) =>+ resolveTopicDrawerPortalHostViewType({+ currentViewType: chatPortalSelectors.currentViewType(s),+ parentViewType: s.portalStack.at(-2)?.type ?? null,+ showArtifactPortal,+ }),+ );+};diff --git a/src/features/Portal/components/Header.tsx b/src/features/Portal/components/Header.tsxindex bb2991aa93b..791e4fec171 100644--- a/src/features/Portal/components/Header.tsx+++ b/src/features/Portal/components/Header.tsx@@ -19,10 +19,11 @@ import { useChatStore } from '@/store/chat';import { chatPortalSelectors } from '@/store/chat/selectors';const Header = memo<{+ onClose?: () => void;paddingInline?: number;rightExtra?: ReactNode;title: ReactNode;-}>(({ paddingInline = 8, rightExtra, title }) => {+}>(({ onClose, paddingInline = 8, rightExtra, title }) => {const { t } = useTranslation('common');const location = useLocation();const navigate = useWorkspaceAwareNavigate();@@ -64,6 +65,11 @@ const Header = memo<{size={DESKTOP_HEADER_ICON_SMALL_SIZE}title={t('close')}onClick={() => {+ if (onClose) {+ onClose();+ return;+ }+if (params.aid && params.topicId && isTopicPageRoute) {navigate(AGENT_CHAT_TOPIC_URL(params.aid, params.topicId));return;diff --git a/src/features/Portal/router.tsx b/src/features/Portal/router.tsxindex 0748106975f..2384c1425db 100644--- a/src/features/Portal/router.tsx+++ b/src/features/Portal/router.tsx@@ -68,29 +68,38 @@ const HomeImpl: PortalImpl = {};interface PortalContentProps {+ onClose?: () => void;renderBody?: (body: React.ReactNode) => React.ReactNode;+ viewType?: PortalViewType | null;}/*** Portal content with Wrapper support* Uses the view stack to determine which component to render*/-export const PortalContent = memo<PortalContentProps>(({ renderBody }) => {- const viewType = useChatStore(chatPortalSelectors.currentViewType);- const ViewImpl = viewType ? VIEW_COMPONENTS[viewType] : HomeImpl;+export const PortalContent = memo<PortalContentProps>(+ ({ onClose, renderBody, viewType: viewTypeOverride }) => {+ const currentViewType = useChatStore(chatPortalSelectors.currentViewType);+ const viewType = viewTypeOverride ?? currentViewType;+ const ViewImpl = viewType ? VIEW_COMPONENTS[viewType] : HomeImpl;- const Wrapper = ViewImpl?.Wrapper || Fragment;- const CustomHeader = ViewImpl?.Header;- const Body = ViewImpl?.Body || HomeBody;- const Title = ViewImpl?.Title || HomeTitle;+ const Wrapper = ViewImpl?.Wrapper || Fragment;+ const CustomHeader = ViewImpl?.Header;+ const Body = ViewImpl?.Body || HomeBody;+ const Title = ViewImpl?.Title || HomeTitle;- const headerContent = CustomHeader ? <CustomHeader /> : <Header title={<Title />} />;- const bodyContent = <Body />;+ const headerContent = CustomHeader ? (+ <CustomHeader />+ ) : (+ <Header title={<Title />} onClose={onClose} />+ );+ const bodyContent = <Body />;- return (- <Wrapper>- {headerContent}- {renderBody ? renderBody(bodyContent) : bodyContent}- </Wrapper>- );-});+ return (+ <Wrapper>+ {headerContent}+ {renderBody ? renderBody(bodyContent) : bodyContent}+ </Wrapper>+ );+ },+);diff --git a/src/routes/(main)/agent/features/Portal/_layout/Desktop.tsx b/src/routes/(main)/agent/features/Portal/_layout/Desktop.tsxindex 4ae33763807..2426523b9ca 100644--- a/src/routes/(main)/agent/features/Portal/_layout/Desktop.tsx+++ b/src/routes/(main)/agent/features/Portal/_layout/Desktop.tsx@@ -1,9 +1,12 @@+import { useTopicDrawerPortalHostViewType } from '@/features/AgentTasks/hooks/useTopicDrawerArtifactPortal';import { PortalContent } from '@/features/Portal/router';import Body from '../features/Body';const Layout = () => {- return <PortalContent renderBody={(body) => <Body>{body}</Body>} />;+ const viewType = useTopicDrawerPortalHostViewType();++ return <PortalContent renderBody={(body) => <Body>{body}</Body>} viewType={viewType} />;};export default Layout;diff --git a/src/routes/(main)/agent/features/Portal/features/Portal.tsx b/src/routes/(main)/agent/features/Portal/features/Portal.tsxindex dd6f679186d..1c97abd3771 100644--- a/src/routes/(main)/agent/features/Portal/features/Portal.tsx+++ b/src/routes/(main)/agent/features/Portal/features/Portal.tsx@@ -5,6 +5,7 @@ import { createStaticStyles, useResponsive } from 'antd-style';import { type PropsWithChildren } from 'react';import { Activity, memo, useState } from 'react';+import { useTopicDrawerPortalHostViewType } from '@/features/AgentTasks/hooks/useTopicDrawerArtifactPortal';import { usePortalPanelWidth } from '@/features/Portal/usePortalPanelWidth';import { useChatStore } from '@/store/chat';import { chatPortalSelectors, portalThreadSelectors } from '@/store/chat/selectors';@@ -32,11 +33,11 @@ const styles = createStaticStyles(({ css, cssVar }) => ({}));const PortalPanel = memo(({ children }: PropsWithChildren) => {- const [showPortal, currentViewType, showThread] = useChatStore((s) => [+ const [showPortal, showThread] = useChatStore((s) => [chatPortalSelectors.showStandalonePortal(s),- chatPortalSelectors.currentViewType(s),portalThreadSelectors.showThread(s),]);+ const currentViewType = useTopicDrawerPortalHostViewType();// legacy threads live outside the view stack, so they surface as an empty stackconst viewType = currentViewType ?? (showThread ? PortalViewType.Thread : null);diff --git a/src/store/chat/slices/portal/action.test.ts b/src/store/chat/slices/portal/action.test.tsindex 46b32faf906..06a910d1291 100644--- a/src/store/chat/slices/portal/action.test.ts+++ b/src/store/chat/slices/portal/action.test.ts@@ -274,6 +274,40 @@ describe('chatDockSlice', () => {});describe('openArtifact', () => {+ it('keeps a parent task portal addressable while its run artifact is open', () => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ result.current.openTaskDetail('task-1');+ result.current.openArtifact({+ id: 'msg-1',+ identifier: 'artifact-1',+ title: 'Run Artifact',+ type: 'text/html',+ });+ });++ expect(chatPortalSelectors.currentViewType(result.current)).toBe(PortalViewType.Artifact);+ expect(chatPortalSelectors.taskDetailId(result.current)).toBe('task-1');+ });++ it('keeps a parent task result portal addressable while its run artifact is open', () => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ result.current.openTaskResult('task-1');+ result.current.openArtifact({+ id: 'msg-1',+ identifier: 'artifact-1',+ title: 'Run Artifact',+ type: 'text/html',+ });+ });++ expect(chatPortalSelectors.currentViewType(result.current)).toBe(PortalViewType.Artifact);+ expect(chatPortalSelectors.taskResultId(result.current)).toBe('task-1');+ });+it('should push Artifact view and open portal', () => {const { result } = renderHook(() => useChatStore());diff --git a/src/store/chat/slices/portal/selectors.ts b/src/store/chat/slices/portal/selectors.tsindex 9311cec98b4..14caa3fac14 100644--- a/src/store/chat/slices/portal/selectors.ts+++ b/src/store/chat/slices/portal/selectors.ts@@ -68,6 +68,14 @@ const getViewData = <T extends PortalViewType>(return null;};+const getStackViewData = <T extends PortalViewType>(+ s: ChatStoreState,+ type: T,+): Extract<PortalViewData, { type: T }> | null => {+ const view = s.portalStack.findLast((item) => item.type === type);+ return (view as Extract<PortalViewData, { type: T }> | undefined) ?? null;+};+const agentDetailId = (s: ChatStoreState): string | undefined => {const view = getViewData(s, PortalViewType.AgentDetail);return view?.agentId;@@ -245,12 +253,12 @@ const messageDetailId = (s: ChatStoreState): string | undefined => {// Task Detail selectorsconst taskDetailId = (s: ChatStoreState): string | undefined => {- const view = getViewData(s, PortalViewType.TaskDetail);+ const view = getStackViewData(s, PortalViewType.TaskDetail);return view?.taskId;};const taskResultId = (s: ChatStoreState): string | undefined => {- const view = getViewData(s, PortalViewType.TaskResult);+ const view = getStackViewData(s, PortalViewType.TaskResult);return view?.taskId;};