🤯 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(goal): add the standard topic menu to the goal chat header (#21178)
Arvin Xu0db912fe2010
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 954ed81d45d..aff2edae00a 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -553,6 +553,7 @@"goalBatch.waves.title": "Waves","goalChat.newTopic": "New conversation","goalChat.noTopics": "No conversations yet",+ "goalChat.openTopic": "Go to original topic","goalChat.title": "Ask about progress","goalChat.welcome": "Ask the agent about this goal — how it's going, what's blocking, or what happens next.","goalDetail.acceptance": "Acceptance checks",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex eb4459d0930..baf6d8fe0d7 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -553,6 +553,7 @@"goalBatch.waves.title": "分批执行","goalChat.newTopic": "新对话","goalChat.noTopics": "还没有对话",+ "goalChat.openTopic": "前往原话题","goalChat.title": "问问进展","goalChat.welcome": "向助理询问这个目标:进展如何、卡在哪里、接下来会做什么。","goalDetail.acceptance": "验收检查",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 2263afa8189..a854f7e8ca4 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -2274,6 +2274,7 @@ export default {'goalAcceptance.title': 'Acceptance standard','goalChat.newTopic': 'New conversation','goalChat.noTopics': 'No conversations yet',+ 'goalChat.openTopic': 'Go to original topic','goalChat.title': 'Ask about progress','goalChat.welcome':"Ask the agent about this goal — how it's going, what's blocking, or what happens next.",diff --git a/src/features/AgentGoals/GoalChat/Toolbar.tsx b/src/features/AgentGoals/GoalChat/Toolbar.tsxindex 414ca1d957a..00788539281 100644--- a/src/features/AgentGoals/GoalChat/Toolbar.tsx+++ b/src/features/AgentGoals/GoalChat/Toolbar.tsx@@ -1,4 +1,3 @@-import { agentDisplayName } from '@lobechat/types';import { ActionIcon, Flexbox, Popover, Text } from '@lobehub/ui';import { Clock3Icon, PanelRightCloseIcon, PlusIcon } from 'lucide-react';import { memo, useState } from 'react';@@ -9,25 +8,31 @@ import { conversationSelectors, useConversationStore } from '@/features/Conversaimport NavHeader from '@/features/NavHeader';import TopicItem from '@/features/PageEditor/Copilot/TopicSelector/TopicItem';import { useFetchAgentChatTopics } from '@/hooks/useFetchChatTopics';-import { useAgentStore } from '@/store/agent';-import { agentSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import { topicSelectors } from '@/store/chat/slices/topic/selectors';+import TopicActions from './TopicActions';+interface ToolbarProps {+ /** Shown while the open conversation has no titled topic. @default the side chat's title */+ fallbackTitle?: string;onCollapse: () => void;+ /** Hand a new conversation to another panel, after the topic is cleared. */+ onNewTopic?: () => void;+ /** Open a topic picked from history. @default switch this panel to it */+ onSelectTopic?: (topicId: string) => void;}-/** Topic title + new-conversation + history — the agent's conversation list. */-const Toolbar = memo<ToolbarProps>(({ onCollapse }) => {+/**+ * Topic title + topic menu, then new-conversation + history — laid out like the+ * agent conversation header. Shared by the side chat and the supervision record+ * so both goal-page conversations carry the same header.+ */+const Toolbar = memo<ToolbarProps>(({ fallbackTitle, onCollapse, onNewTopic, onSelectTopic }) => {const { t } = useTranslation('chat');const [topicPopoverOpen, setTopicPopoverOpen] = useState(false);const agentId = useConversationStore(conversationSelectors.agentId);- const agentTitle = useAgentStore((s) =>- agentDisplayName(agentSelectors.getAgentMetaById(agentId)(s)),- );-useFetchAgentChatTopics(agentId);const [activeTopicId, switchTopic, topics] = useChatStore((s) => [@@ -38,22 +43,30 @@ const Toolbar = memo<ToolbarProps>(({ onCollapse }) => {const currentTopic = useChatStore(topicSelectors.currentActiveTopic);const isLoadingTopics = topics === undefined;- const topicTitle = currentTopic?.title || t('goalChat.title');+ const topicTitle = currentTopic?.title || fallbackTitle || t('goalChat.title');const hasTopics = !!topics && topics.length > 0;return (<NavHeadershowTogglePanelButton={false}left={- <Text- style={{ fontSize: 13, fontWeight: 500, marginLeft: 8 }}- type={'secondary'}- ellipsis={{- tooltipWhenOverflow: true,- }}- >- {agentTitle ? `${agentTitle} · ${topicTitle}` : topicTitle}- </Text>+ <Flexbox allowShrink horizontal align={'center'} gap={4} style={{ minWidth: 0 }}>+ <Text+ ellipsis={{ tooltipWhenOverflow: true }}+ style={{ fontSize: 14, fontWeight: 600, marginLeft: 8, minWidth: 0 }}+ >+ {topicTitle}+ </Text>+ {agentId && currentTopic && (+ <TopicActions+ agentId={agentId}+ fav={currentTopic.favorite}+ status={currentTopic.status}+ topicId={currentTopic.id}+ topicTitle={currentTopic.title}+ />+ )}+ </Flexbox>}right={<>@@ -61,7 +74,12 @@ const Toolbar = memo<ToolbarProps>(({ onCollapse }) => {icon={PlusIcon}size={DESKTOP_HEADER_ICON_SMALL_SIZE}title={t('goalChat.newTopic')}- onClick={() => switchTopic(null)}+ onClick={() => {+ // Clear first: the side chat keeps the agent's open topic when it+ // mounts, so a hand-off would otherwise land back on this one.+ void switchTopic(null);+ onNewTopic?.();+ }}/><Popoveropen={isLoadingTopics ? false : topicPopoverOpen}@@ -81,11 +99,14 @@ const Toolbar = memo<ToolbarProps>(({ onCollapse }) => {{topics!.map((topic) => (<TopicItemactive={topic.id === activeTopicId}+ agentId={agentId}+ fav={topic.favorite}key={topic.id}+ status={topic.status}topicId={topic.id}topicTitle={topic.title}onClose={() => setTopicPopoverOpen(false)}- onTopicChange={(id) => switchTopic(id)}+ onTopicChange={(id) => (onSelectTopic ? onSelectTopic(id) : switchTopic(id))}/>))}</Flexbox>diff --git a/src/features/AgentGoals/GoalChat/TopicActions.tsx b/src/features/AgentGoals/GoalChat/TopicActions.tsxnew file mode 100644index 00000000000..6e1ac2f1e16--- /dev/null+++ b/src/features/AgentGoals/GoalChat/TopicActions.tsx@@ -0,0 +1,20 @@+import { ActionIcon, DropdownMenu } from '@lobehub/ui';+import { MoreHorizontalIcon } from 'lucide-react';+import { memo } from 'react';++import { type GoalTopicMenuParams, useGoalTopicMenu } from './useGoalTopicMenu';++/** The topic "…" beside the goal chat title. */+const TopicActions = memo<GoalTopicMenuParams>((props) => {+ const items = useGoalTopicMenu(props);++ return (+ <DropdownMenu items={items}>+ <ActionIcon icon={MoreHorizontalIcon} size={'small'} />+ </DropdownMenu>+ );+});++TopicActions.displayName = 'GoalChatTopicActions';++export default TopicActions;diff --git a/src/features/AgentGoals/GoalChat/index.tsx b/src/features/AgentGoals/GoalChat/index.tsxindex 0c9c01fdf86..8d7468ce7c5 100644--- a/src/features/AgentGoals/GoalChat/index.tsx+++ b/src/features/AgentGoals/GoalChat/index.tsx@@ -30,10 +30,11 @@ interface ConversationProps {initialMessage?: string;onCollapse: () => void;onInitialMessageConsumed?: () => void;+ onSelectTopic?: (topicId: string) => void;}const Conversation = memo<ConversationProps>(- ({ initialMessage, onCollapse, onInitialMessageConsumed }) => {+ ({ initialMessage, onCollapse, onInitialMessageConsumed, onSelectTopic }) => {const useFetchAgentConfig = useAgentStore((s) => s.useFetchAgentConfig);const currentAgentId = useConversationStore(conversationSelectors.agentId);@@ -48,7 +49,7 @@ const Conversation = memo<ConversationProps>(return (<DragUploadZone style={{ flex: 1, height: '100%' }} onUploadFiles={handleUploadFiles}><Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>- <Toolbar onCollapse={onCollapse} />+ <Toolbar onCollapse={onCollapse} onSelectTopic={onSelectTopic} /><Flexbox flex={1} style={{ overflow: 'hidden' }}><ChatList welcome={<Welcome />} /></Flexbox>@@ -72,6 +73,8 @@ interface GoalChatProps {initialTopicId?: string;onCollapse: () => void;onInitialMessageConsumed?: () => void;+ /** Open a topic picked from history. @default switch the panel to it in place */+ onSelectTopic?: (topicId: string) => void;}/**@@ -80,12 +83,21 @@ interface GoalChatProps {* with the current goal overview injected — "how is this going?" just works.*/const GoalChat = memo<GoalChatProps>(- ({ agentId, goalId, initialMessage, initialTopicId, onCollapse, onInitialMessageConsumed }) => (+ ({+ agentId,+ goalId,+ initialMessage,+ initialTopicId,+ onCollapse,+ onInitialMessageConsumed,+ onSelectTopic,+ }) => (<GoalChatProvider agentId={agentId} goalId={goalId} initialTopicId={initialTopicId}><ConversationinitialMessage={initialMessage}onCollapse={onCollapse}onInitialMessageConsumed={onInitialMessageConsumed}+ onSelectTopic={onSelectTopic}/></GoalChatProvider>),diff --git a/src/features/AgentGoals/GoalChat/useGoalTopicMenu.test.ts b/src/features/AgentGoals/GoalChat/useGoalTopicMenu.test.tsnew file mode 100644index 00000000000..0ca87c0c0d7--- /dev/null+++ b/src/features/AgentGoals/GoalChat/useGoalTopicMenu.test.ts@@ -0,0 +1,36 @@+/**+ * @vitest-environment happy-dom+ */+import { renderHook } from '@testing-library/react';+import { describe, expect, it, vi } from 'vitest';++import { useGoalTopicMenu } from './useGoalTopicMenu';++const navigateMock = vi.hoisted(() => vi.fn());++vi.mock('@/features/PageEditor/Copilot/TopicSelector/useDropdownMenu', () => ({+ useDropdownMenu: () => () => [{ key: 'rename' }, { key: 'delete' }],+}));++vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({+ useWorkspaceAwareNavigate: () => navigateMock,+}));++describe('useGoalTopicMenu', () => {+ it('leads the standard topic menu with a jump to the original topic', () => {+ const { result } = renderHook(() =>+ useGoalTopicMenu({ agentId: 'agt_1', topicId: 'tpc_1', topicTitle: 'Progress' }),+ );++ const items = result.current() as { key?: string; onClick?: () => void; type?: string }[];+ expect(items.map((item) => item.key ?? item.type)).toEqual([+ 'openTopic',+ 'divider',+ 'rename',+ 'delete',+ ]);++ items[0].onClick?.();+ expect(navigateMock).toHaveBeenCalledWith('/agent/agt_1/tpc_1');+ });+});diff --git a/src/features/AgentGoals/GoalChat/useGoalTopicMenu.ts b/src/features/AgentGoals/GoalChat/useGoalTopicMenu.tsnew file mode 100644index 00000000000..ddd1de648bb--- /dev/null+++ b/src/features/AgentGoals/GoalChat/useGoalTopicMenu.ts@@ -0,0 +1,54 @@+import { AGENT_CHAT_TOPIC_URL } from '@lobechat/const';+import type { ChatTopicStatus } from '@lobechat/types';+import type { DropdownItem } from '@lobehub/ui';+import { MessageSquareShare } from 'lucide-react';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { useDropdownMenu } from '@/features/PageEditor/Copilot/TopicSelector/useDropdownMenu';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';++const noop = () => {};++export interface GoalTopicMenuParams {+ agentId: string;+ fav?: boolean;+ status?: ChatTopicStatus | null;+ topicId: string;+ topicTitle: string;+}++/** The standard topic menu, led by a jump to the topic's own conversation page. */+export const useGoalTopicMenu = ({+ agentId,+ fav,+ status,+ topicId,+ topicTitle,+}: GoalTopicMenuParams): (() => DropdownItem[]) => {+ const { t } = useTranslation('chat');+ const navigate = useWorkspaceAwareNavigate();++ const topicMenu = useDropdownMenu({+ agentId,+ fav,+ onClose: noop,+ status,+ topicId,+ topicTitle,+ });++ return useCallback(+ () => [+ {+ icon: MessageSquareShare,+ key: 'openTopic',+ label: t('goalChat.openTopic'),+ onClick: () => navigate(AGENT_CHAT_TOPIC_URL(agentId, topicId)),+ },+ { type: 'divider' as const },+ ...topicMenu(),+ ],+ [agentId, navigate, t, topicId, topicMenu],+ );+};diff --git a/src/features/AgentGoals/GoalDetailPage.test.tsx b/src/features/AgentGoals/GoalDetailPage.test.tsxindex 28ab80c5881..dfbeaa6d74c 100644--- a/src/features/AgentGoals/GoalDetailPage.test.tsx+++ b/src/features/AgentGoals/GoalDetailPage.test.tsx@@ -100,8 +100,29 @@ vi.mock('@/features/WideScreenContainer', () => ({default: ({ children }: { children: ReactNode }) => <div>{children}</div>,}));vi.mock('./GoalChat', () => ({- default: ({ agentId, initialMessage }: { agentId: string; initialMessage?: string }) => (- <div data-agent-id={agentId} data-initial-message={initialMessage} data-testid="goal-chat" />+ default: ({+ agentId,+ initialMessage,+ initialTopicId,+ onSelectTopic,+ }: {+ agentId: string;+ initialMessage?: string;+ initialTopicId?: string;+ onSelectTopic?: (topicId: string) => void;+ }) => (+ <div+ data-agent-id={agentId}+ data-initial-message={initialMessage}+ data-initial-topic-id={initialTopicId}+ data-testid="goal-chat"+ >+ {onSelectTopic && (+ <button data-testid="goal-chat-pick-record" onClick={() => onSelectTopic('tpc_manager')}>+ pick record+ </button>+ )}+ </div>),}));vi.mock('./GoalDetailActions', () => ({ default: () => null }));@@ -122,10 +143,12 @@ vi.mock('./GoalSupervision', () => ({GoalSupervision: ({initialMessage,onOpenChat,+ onSelectTopic,topicId,}: {initialMessage?: string;onOpenChat?: () => void;+ onSelectTopic?: (topicId: string) => void;topicId: string;}) => (<div data-initial-message={initialMessage} data-testid="goal-supervision">@@ -135,6 +158,14 @@ vi.mock('./GoalSupervision', () => ({open chat</button>)}+ {onSelectTopic && (+ <button+ data-testid="goal-supervision-pick-topic"+ onClick={() => onSelectTopic('tpc_other')}+ >+ pick topic+ </button>+ )}</div>),}));@@ -239,6 +270,23 @@ describe('GoalDetailPage', () => {expect(screen.getByTestId('goal-right-panel')).toHaveAttribute('data-expand', 'true');});+ // Both panels share one header with a history list: another topic picked from+ // the record opens as the editable side conversation on that topic, and the+ // record picked from the side conversation opens as the record again.+ it('routes a topic picked from history to the panel that owns it', () => {+ render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);++ fireEvent.click(screen.getByTestId('goal-supervisor-toggle'));+ fireEvent.click(screen.getByTestId('goal-supervision-pick-topic'));++ expect(screen.queryByTestId('goal-supervision')).not.toBeInTheDocument();+ expect(screen.getByTestId('goal-chat')).toHaveAttribute('data-initial-topic-id', 'tpc_other');++ fireEvent.click(screen.getByTestId('goal-chat-pick-record'));++ expect(screen.getByTestId('goal-supervision')).toHaveTextContent('tpc_manager');+ });+it('leaves drill-downs to the workspace portal host on the agent-less route', () => {mocks.showPortal = true;render(diff --git a/src/features/AgentGoals/GoalDetailPage.tsx b/src/features/AgentGoals/GoalDetailPage.tsxindex dc8685585af..20758c00cda 100644--- a/src/features/AgentGoals/GoalDetailPage.tsx+++ b/src/features/AgentGoals/GoalDetailPage.tsx@@ -203,6 +203,18 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {// message landing, so the reply is never invisible behind a drill-down. A// managed goal whose main Agent has no supervision record yet gets one from// this very turn: the panel opens now and moves there once it exists.+ // A topic picked from either panel's history: the supervision record opens as+ // the record, any other topic as the side conversation on that topic.+ const selectTopic = (topicId: string) => {+ if (!supervisingAgentId || topicId === chat.topicId) return;+ clearPortalStack();+ chat.openConversation(+ managerConversation?.topicId === topicId+ ? { agentId: managerConversation.agentId, topicId }+ : { agentId: supervisingAgentId, topicId },+ );+ };+const revealConversation = () => {setGraphFullscreen(false);clearPortalStack();@@ -373,7 +385,9 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {hasWorkspaceSidePanel ? null : (<PortalContent />)- ) : supervisingAgentId && chat.topicId ? (+ ) : supervisingAgentId &&+ chat.topicId &&+ chat.topicId === managerConversation?.topicId ? (<GoalSupervisionagentId={supervisingAgentId}goalId={goalId}@@ -384,6 +398,7 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {onInitialMessageConsumed={chat.consumeInitialMessage}// A question that should not land in the manager's own record.onOpenChat={() => chat.openConversation({ agentId: supervisingAgentId })}+ onSelectTopic={selectTopic}/>) : chat.awaitingRecord ? (// The supervision record is on its way: show it loading, not the@@ -400,6 +415,7 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {key={`${goalId}:${supervisingAgentId}:${chat.request}`}onCollapse={() => chat.setOpen(false)}onInitialMessageConsumed={chat.consumeInitialMessage}+ onSelectTopic={managerConversation ? selectTopic : undefined}/>) : null}</RightPanel>diff --git a/src/features/AgentGoals/GoalSupervision.tsx b/src/features/AgentGoals/GoalSupervision.tsxindex ce9e045bbb2..45f9e0c5b80 100644--- a/src/features/AgentGoals/GoalSupervision.tsx+++ b/src/features/AgentGoals/GoalSupervision.tsx@@ -1,27 +1,16 @@-import { AGENT_CHAT_TOPIC_URL } from '@lobechat/const';import { agentDisplayName } from '@lobechat/types';-import { copyToClipboard, type DropdownItem, DropdownMenu, Flexbox } from '@lobehub/ui';-import { ActionIcon, Text, toast } from '@lobehub/ui';-import {- CopyIcon,- ExternalLink,- MessagesSquareIcon,- MoreHorizontal,- PanelRightCloseIcon,-} from 'lucide-react';-import { memo, useCallback, useMemo } from 'react';+import { Flexbox, Text } from '@lobehub/ui';+import { memo, useCallback } from 'react';import { useTranslation } from 'react-i18next';-import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';import { ChatList } from '@/features/Conversation';import MessageItem from '@/features/Conversation/Messages';-import NavHeader from '@/features/NavHeader';-import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { useAgentStore } from '@/store/agent';import { agentSelectors } from '@/store/agent/selectors';import { GoalChatProvider } from './GoalChat/GoalChatProvider';import GoalConversationInput from './GoalChat/GoalConversationInput';+import Toolbar from './GoalChat/Toolbar';interface GoalSupervisionProps {agentId: string;@@ -32,6 +21,8 @@ interface GoalSupervisionProps {onInitialMessageConsumed?: () => void;/** Hand the panel back to the agent's editable side conversation. */onOpenChat?: () => void;+ /** Open a topic picked from the conversation history. */+ onSelectTopic?: (topicId: string) => void;topicId: string;}@@ -65,6 +56,7 @@ export const GoalSupervision = ({onCollapse,onInitialMessageConsumed,onOpenChat,+ onSelectTopic,topicId,}: GoalSupervisionProps) => {const { t } = useTranslation('chat');@@ -78,64 +70,16 @@ export const GoalSupervision = ({(index: number, id: string) => <MessageItem disableEditing id={id} index={index} />,[],);- const navigate = useWorkspaceAwareNavigate();- // Opening the record in the agent's own chat gives it the full page; the id is- // one click away for referencing it elsewhere (`lh topic view`, a bug report),- // like a task run's.- const menuItems = useMemo<DropdownItem[]>(- () => [- // A fresh side conversation, for a question that should not land in the- // manager's own record.- ...(onOpenChat- ? [- {- icon: MessagesSquareIcon,- key: 'openChat',- label: t('goalChat.title'),- onClick: onOpenChat,- },- ]- : []),- {- icon: ExternalLink,- key: 'openAgentTopic',- label: t('taskDetail.topicMenu.openAgentTopic'),- onClick: () => navigate(AGENT_CHAT_TOPIC_URL(agentId, topicId)),- },- {- icon: CopyIcon,- key: 'copyTopicId',- label: t('taskDetail.topicMenu.copyId'),- onClick: async () => {- await copyToClipboard(topicId);- toast.success(t('copySuccess', { ns: 'common' }));- },- },- ],- [agentId, navigate, onOpenChat, t, topicId],- );-return (<GoalChatProvider agentId={agentId} goalId={goalId} initialTopicId={topicId}><Flexbox height={'100%'} style={{ overflow: 'hidden' }}>- <NavHeader- showTogglePanelButton={false}- left={- <Flexbox horizontal align={'center'} gap={4} style={{ minWidth: 0 }}>- <Text ellipsis>{agentTitle || t('goalProcess.manager.title')}</Text>- <DropdownMenu items={menuItems}>- <ActionIcon icon={MoreHorizontal} size={'small'} />- </DropdownMenu>- </Flexbox>- }- right={- <ActionIcon- icon={PanelRightCloseIcon}- size={DESKTOP_HEADER_ICON_SMALL_SIZE}- title={t('close', { ns: 'common' })}- onClick={onCollapse}- />- }+ {/* The side chat's header: the record is a topic like any other, so it+ gets the same title, topic menu, new-conversation and history. */}+ <Toolbar+ fallbackTitle={agentTitle || t('goalProcess.manager.title')}+ onCollapse={onCollapse}+ onNewTopic={onOpenChat}+ onSelectTopic={onSelectTopic}/><Flexbox flex={1} style={{ minHeight: 0, overflow: 'hidden' }}><ChatList disableActionsBar itemContent={itemContent} welcome={<WaitingForFirstRun />} />