🤯 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(channels): inline Agent profile links in reply failure popovers (#21883)
AmAzing-b41e06048970
diff --git a/src/features/AgentSidebar/Header/Nav.tsx b/src/features/AgentSidebar/Header/Nav.tsxindex 2556968d038..978bb46ad10 100644--- a/src/features/AgentSidebar/Header/Nav.tsx+++ b/src/features/AgentSidebar/Header/Nav.tsx@@ -30,6 +30,8 @@ import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfiimport { useUserStore } from '@/store/user';import { labPreferSelectors } from '@/store/user/selectors';+import { isAgentProfileRoute } from './isAgentProfileRoute';+const Nav = memo(() => {const { t } = useTranslation('chat');const { t: tTopic } = useTranslation('topic');@@ -40,10 +42,7 @@ const Nav = memo(() => {// The profile entry now owns a group of sub-views — profile / channels /// statistics — switched by a Segmented in the page header, so all three keep// this entry lit instead of leaving the sidebar with nothing selected.- const isProfileActive =- pathname.includes('/profile') ||- pathname.includes('/channel') ||- pathname.endsWith('/statistics');+ const isProfileActive = isAgentProfileRoute(pathname);const isGoalsActive = pathname.endsWith('/goals');// 下钻页 /self-evolving/:domainId 也算在这个入口下,否则点进去侧边栏就失焦了const isSelfLearningActive = pathname.includes('/self-evolving');diff --git a/src/features/AgentSidebar/Header/isAgentProfileRoute.test.ts b/src/features/AgentSidebar/Header/isAgentProfileRoute.test.tsnew file mode 100644index 00000000000..75d8848d2af--- /dev/null+++ b/src/features/AgentSidebar/Header/isAgentProfileRoute.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest';++import { isAgentProfileRoute } from './isAgentProfileRoute';++describe('isAgentProfileRoute', () => {+ it.each([+ '/agent/agt_1/profile',+ '/agent/agt_1/channel',+ '/agent/agt_1/channel/slack',+ '/agent/agt_1/statistics',+ '/acme/agent/agt_1/profile',+ '/acme/agent/agt_1/channel/slack',+ '/acme/agent/agt_1/statistics/',+ '/_dangerous_local_dev_proxy/acme/agent/agt_1/profile',+ ])('selects the profile entry on %s', (pathname) => {+ expect(isAgentProfileRoute(pathname)).toBe(true);+ });++ it.each([+ '/channels/chn_1',+ '/acme/channels/chn_1',+ '/project/pro_1/channels/chn_1',+ '/agent/agt_1',+ '/agent/agt_1/tpc_1',+ '/channel-team/agent/agt_1',+ '/profile-team/agent/agt_1',+ '/agent/agt_1/channel-topic',+ '/group/grp_1/profile',+ '/settings/profile',+ ])('does not select the profile entry on %s', (pathname) => {+ expect(isAgentProfileRoute(pathname)).toBe(false);+ });+});diff --git a/src/features/AgentSidebar/Header/isAgentProfileRoute.ts b/src/features/AgentSidebar/Header/isAgentProfileRoute.tsnew file mode 100644index 00000000000..bb2c9609690--- /dev/null+++ b/src/features/AgentSidebar/Header/isAgentProfileRoute.ts@@ -0,0 +1,8 @@+/**+ * Match Agent subroutes, not arbitrary substrings: `/channels/:id` and workspace+ * slugs such as `channel-team` must not light up the profile entry.+ */+export const isAgentProfileRoute = (pathname: string) =>+ /^(?:\/[^/]+)?\/agent\/[^/]+\/(?:profile|channel(?:\/[^/]+)?|statistics)\/?$/.test(+ pathname.replace(/^\/_dangerous_local_dev_proxy(?=\/)/, ''),+ );diff --git a/src/features/Channels/MessageReceipts.tsx b/src/features/Channels/MessageReceipts.tsxindex 3b08412338f..347a6d654c4 100644--- a/src/features/Channels/MessageReceipts.tsx+++ b/src/features/Channels/MessageReceipts.tsx@@ -7,13 +7,13 @@ import { useTranslation } from 'react-i18next';import AgentAvatar from '@/components/AgentAvatar';import AsyncError from '@/components/AsyncError';-import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { channelActions } from '@/store/channel';import { ChannelStatus } from './ChannelStatus';import { channelJobStatus, channelJobTone, isChannelJobActive } from './jobStatus';import { memberAvatar, memberName } from './memberName';import { statusStyles, styles } from './styles';+import { useOpenReplyAgent } from './useOpenReplyAgent';export interface ReplyEntry {agentId?: string | null;@@ -47,8 +47,8 @@ export function ReplyDetail({entry: ReplyEntry;}) {const { t } = useTranslation('channel');- const navigate = useWorkspaceAwareNavigate();const { close } = usePopoverContext();+ const openAgent = useOpenReplyAgent(agentId, close);const [stopping, setStopping] = useState(false);const [error, setError] = useState<unknown>();const stop = async () => {@@ -74,9 +74,29 @@ export function ReplyDetail({size={24}title={name}/>- <Text ellipsis style={{ flex: 1 }} weight={500}>- {name}- </Text>+ <Flexbox flex={1} style={{ minWidth: 0 }}>+ {agentId ? (+ <Button+ aria-label={t('openAgentNamed', { name })}+ icon={ExternalLink}+ iconPosition="end"+ outdent="start"+ size="small"+ style={{ alignSelf: 'flex-start', maxWidth: '100%', minWidth: 0 }}+ title={t('openAgentNamed', { name })}+ type="text"+ onClick={openAgent}+ >+ <Text ellipsis as="span" style={{ minWidth: 0 }} weight={500}>+ {name}+ </Text>+ </Button>+ ) : (+ <Text ellipsis weight={500}>+ {name}+ </Text>+ )}+ </Flexbox><ChannelStatus label={t(channelJobStatus(job))} tone={channelJobTone(job)} /></Flexbox>{job.status === 'failed' && (@@ -88,34 +108,18 @@ export function ReplyDetail({<span {...stylex.props(styles.muted)}>{t('receipt.failedHint')}</span></Flexbox>)}- {((job.canStop && isChannelJobActive(job)) || agentId) && (- <Flexbox horizontal gap={4} wrap="wrap">- {job.canStop && isChannelJobActive(job) && (- <Button- danger- icon={Square}- loading={stopping}- size="small"- type="text"- onClick={() => void stop()}- >- {t('stopReply')}- </Button>- )}- {agentId && (- <Button- icon={ExternalLink}- size="small"- type="text"- onClick={() => {- close();- navigate(`/agent/${agentId}`);- }}- >- {t('openAgent')}- </Button>- )}- </Flexbox>+ {job.canStop && isChannelJobActive(job) && (+ <Button+ danger+ icon={Square}+ loading={stopping}+ size="small"+ style={{ alignSelf: 'flex-start' }}+ type="text"+ onClick={() => void stop()}+ >+ {t('stopReply')}+ </Button>)}{error !== undefined && <AsyncError error={error} variant="inline" />}</Flexbox>diff --git a/src/features/Channels/useOpenReplyAgent.test.ts b/src/features/Channels/useOpenReplyAgent.test.tsnew file mode 100644index 00000000000..6f40a595dc2--- /dev/null+++ b/src/features/Channels/useOpenReplyAgent.test.ts@@ -0,0 +1,49 @@+import { act, renderHook } from '@testing-library/react';+import { createElement, type ReactNode } from 'react';+import { MemoryRouter, useLocation } from 'react-router';+import { afterEach, describe, expect, it, vi } from 'vitest';++import * as workspace from '@/business/client/hooks/useActiveWorkspaceSlug';++import { useOpenReplyAgent } from './useOpenReplyAgent';++const wrapper = ({ children }: { children: ReactNode }) =>+ createElement(MemoryRouter, { initialEntries: ['/channels/chn_1'] }, children);++afterEach(() => vi.restoreAllMocks());++describe('useOpenReplyAgent', () => {+ it.each([+ [null, '/agent/agt_1/profile'],+ ['acme', '/acme/agent/agt_1/profile'],+ ])('opens the profile rather than a blank chat in workspace %s', (slug, destination) => {+ vi.spyOn(workspace, 'getActiveWorkspaceSlug').mockReturnValue(slug);+ let pathnameWhenClosed: string | undefined;+ const close = vi.fn(() => {+ pathnameWhenClosed = result.current.pathname;+ });+ const { result } = renderHook(+ () => ({ open: useOpenReplyAgent('agt_1', close), pathname: useLocation().pathname }),+ { wrapper },+ );++ act(() => result.current.open());++ expect(close).toHaveBeenCalledOnce();+ expect(pathnameWhenClosed).toBe('/channels/chn_1');+ expect(result.current.pathname).toBe(destination);+ });++ it.each([null, undefined, ''])('does not navigate when the Agent is unavailable (%s)', (id) => {+ const close = vi.fn();+ const { result } = renderHook(+ () => ({ open: useOpenReplyAgent(id, close), pathname: useLocation().pathname }),+ { wrapper },+ );++ act(() => result.current.open());++ expect(close).not.toHaveBeenCalled();+ expect(result.current.pathname).toBe('/channels/chn_1');+ });+});diff --git a/src/features/Channels/useOpenReplyAgent.ts b/src/features/Channels/useOpenReplyAgent.tsnew file mode 100644index 00000000000..968c891e2b5--- /dev/null+++ b/src/features/Channels/useOpenReplyAgent.ts@@ -0,0 +1,12 @@+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';++/** Leave the reply popover before opening the Agent that owns the reply. */+export const useOpenReplyAgent = (agentId: string | null | undefined, close: () => void) => {+ const navigate = useWorkspaceAwareNavigate();++ return () => {+ if (!agentId) return;+ close();+ navigate(`/agent/${agentId}/profile`);+ };+};