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.

💄 style(messages): list only agents and groups with a conversation (#22867)

Arvin Xuea529e34f19e
diff --git a/src/features/MessageList/Body.test.tsx b/src/features/MessageList/Body.test.tsx
index c023c518607..d394e2ad8f0 100644
--- a/src/features/MessageList/Body.test.tsx
+++ b/src/features/MessageList/Body.test.tsx
@@ -18,6 +18,8 @@ const home = vi.hoisted(() => ({
items: [] as unknown[],
mutate: () => {},
recents: [] as unknown[],
+ recentsError: undefined as unknown,
+ revalidateRecents: vi.fn(async () => {}),
}));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
@@ -51,7 +53,8 @@ vi.mock('@/hooks/useFetchAgentList', () => ({
useFetchAgentList: () => ({ error: home.error, mutate: home.mutate }),
}));
vi.mock('@/components/AsyncError', () => ({
- default: () => createElement('div', {}, 'Agents failed'),
+ default: ({ error, onRetry }: { error: unknown; onRetry: () => void }) =>
+ createElement('button', { onClick: onRetry }, `Failed: ${String(error)}`),
}));
vi.mock('@/features/AgentRoute/useResolvedAgentRouteId', () => ({
resolveInboxAgentRouteId: (id: string) => id,
@@ -59,7 +62,12 @@ vi.mock('@/features/AgentRoute/useResolvedAgentRouteId', () => ({
vi.mock('@/store/home', () => ({
useHomeStore: (selector: (state: object) => unknown) =>
- selector({ useFetchConversationRecents: () => {} }),
+ selector({
+ useFetchConversationRecents: () => ({
+ error: home.recentsError,
+ revalidate: home.revalidateRecents,
+ }),
+ }),
}));
vi.mock('@/store/home/selectors', () => ({
homeAgentListSelectors: { allAgents: () => home.items, isAgentListInit: () => home.isInit },
@@ -114,6 +122,8 @@ beforeEach(() => {
home.isInit = false;
home.items = [];
home.recents = [];
+ home.recentsError = undefined;
+ home.revalidateRecents.mockClear();
});
describe('MessageList Body', () => {
@@ -130,7 +140,7 @@ describe('MessageList Body', () => {
render(createElement(Body));
- expect(screen.getByText('Agents failed')).toBeInTheDocument();
+ expect(screen.getByText('Failed: Error: network')).toBeInTheDocument();
expect(screen.queryByText('Loading agents')).not.toBeInTheDocument();
expect(screen.getByText('Lobe AI row')).toBeInTheDocument();
expect(screen.getByText('# Team')).toBeInTheDocument();
@@ -141,6 +151,7 @@ describe('MessageList Body', () => {
home.items = [
{ id: 'a', pinned: false, title: 'Agent A', type: 'agent', updatedAt: new Date() },
];
+ home.recents = [{ agentId: 'a', routePath: '/agent/a', type: 'topic', updatedAt: new Date() }];
render(createElement(Body));
@@ -166,6 +177,73 @@ describe('MessageList Body', () => {
expect(group).not.toHaveTextContent('Agent A');
expect(group).not.toHaveTextContent('Lobe AI row');
});
+
+ // A failed recents request with nothing cached kept the skeleton up with no way to retry.
+ it('replaces the skeleton with a recents retry when recents fail', () => {
+ home.isInit = true;
+ home.items = [
+ { id: 'a', pinned: false, title: 'Agent A', type: 'agent', updatedAt: new Date() },
+ ];
+ home.recents = undefined as unknown as unknown[];
+ home.recentsError = 'recents down';
+
+ render(createElement(Body));
+
+ expect(screen.queryByText('Loading agents')).not.toBeInTheDocument();
+ fireEvent.click(screen.getByText('Failed: recents down'));
+ expect(home.revalidateRecents).toHaveBeenCalledTimes(1);
+ });
+
+ // A first topic started in an idle agent never reached the recents, so leaving it dropped the row.
+ it('refreshes recents when the routed conversation changes, not on mount', () => {
+ home.isInit = true;
+ home.pathname = '/agent/a';
+
+ const { rerender } = render(createElement(Body, { key: 'list' }));
+ expect(home.revalidateRecents).not.toHaveBeenCalled();
+
+ home.pathname = '/agent/b';
+ // A new props object re-renders the memoized Body with the new route.
+ rerender(createElement(Body, { 'data-route': 'b', 'key': 'list' } as object));
+
+ expect(home.revalidateRecents).toHaveBeenCalledTimes(1);
+ });
+
+ it('waits for recents before deciding which agents have a conversation', () => {
+ home.isInit = true;
+ home.items = [
+ { id: 'a', pinned: false, title: 'Agent A', type: 'agent', updatedAt: new Date() },
+ ];
+ home.recents = undefined as unknown as unknown[];
+
+ render(createElement(Body));
+
+ expect(screen.getByText('Loading agents')).toBeInTheDocument();
+ });
+
+ // Every agent and group got a row, so the list read like Contacts instead of open conversations.
+ it('lists only agents with a conversation, and every agent while searching', () => {
+ home.isInit = true;
+ home.items = [
+ { id: 'a', pinned: false, title: 'Talked', type: 'agent', updatedAt: new Date() },
+ { id: 'b', pinned: false, title: 'Idle', type: 'agent', updatedAt: new Date() },
+ { id: 'c', pinned: false, title: 'Direct', type: 'agent', updatedAt: new Date() },
+ ];
+ home.recents = [{ agentId: 'a', routePath: '/agent/a', type: 'topic', updatedAt: new Date() }];
+ home.channels = [{ agentId: 'c', createdAt: new Date(), id: 'chn_c', projectId: null }];
+
+ const { unmount } = render(createElement(Body));
+
+ expect(screen.getByText('Talked')).toBeInTheDocument();
+ expect(screen.getByText('Direct')).toBeInTheDocument();
+ expect(screen.queryByText('Idle')).not.toBeInTheDocument();
+
+ unmount();
+ home.query = 'idle';
+ render(createElement(Body));
+
+ expect(screen.getByText('Idle')).toBeInTheDocument();
+ });
});
describe('MessageList Body Channel rows', () => {
@@ -261,6 +339,9 @@ describe('MessageList Body active row', () => {
it('leaves Agent rows unhighlighted inside a group Channel', () => {
home.isInit = true;
home.items = [agent];
+ home.recents = [
+ { agentId: 'agt_nasa', routePath: '/agent/agt_nasa', type: 'topic', updatedAt: new Date() },
+ ];
home.pathname = '/channels/chn_000000000002';
home.channels = [{ agentId: null, id: 'chn_000000000002' }];
diff --git a/src/features/MessageList/Body.tsx b/src/features/MessageList/Body.tsx
index 865f5ee2188..1a52d5430f6 100644
--- a/src/features/MessageList/Body.tsx
+++ b/src/features/MessageList/Body.tsx
@@ -6,7 +6,7 @@ import { Flexbox } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
import isEqual from 'fast-deep-equal';
import { Archive } from 'lucide-react';
-import { memo, useMemo, useState } from 'react';
+import { memo, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
@@ -96,11 +96,21 @@ const Body = memo(() => {
const { t } = useTranslation(['common', 'channel']);
const { error: agentsError, mutate: retryAgents } = useFetchAgentList();
const isInit = useHomeStore(homeAgentListSelectors.isAgentListInit);
- useHomeStore((s) => s.useFetchConversationRecents)(ALL_RECENTS_LIMIT);
+ const { error: recentsError, revalidate: revalidateRecents } = useHomeStore(
+ (s) => s.useFetchConversationRecents,
+ )(ALL_RECENTS_LIMIT);
const items = useHomeStore(homeAgentListSelectors.allAgents, isEqual);
const recents = useHomeStore(homeRecentSelectors.conversationRecents(RECENTS_QUERY_KEY));
const activeRouteId = useActiveRouteId();
+ // The open conversation keeps its row, so a first topic started there only needs to reach the
+ // recents by the time the person moves on: refresh them whenever the routed conversation changes.
+ const lastRouteIdRef = useRef(activeRouteId);
+ useEffect(() => {
+ if (lastRouteIdRef.current === activeRouteId) return;
+ lastRouteIdRef.current = activeRouteId;
+ void revalidateRecents();
+ }, [activeRouteId, revalidateRecents]);
const channelsEnabled = useChannelsEnabled();
const allChannels = useChannelStore(channelSelectors.list);
const { query } = useMessageSearch();
@@ -156,7 +166,10 @@ const Body = memo(() => {
const entries = useMemo(
() =>
buildConversationEntries(
- buildConversationSections(items, recents, directChannels),
+ buildConversationSections(items, recents, directChannels, {
+ activeId: activeRouteId,
+ includeIdle: !!query.trim(),
+ }),
{
activeAt: inboxActivity(inboxUpdatedAt, inboxTopic, inboxChannel),
channel: inboxChannel,
@@ -169,6 +182,7 @@ const Body = memo(() => {
items,
recents,
directChannels,
+ activeRouteId,
inboxUpdatedAt,
inboxTitle,
inboxTopic,
@@ -203,9 +217,9 @@ const Body = memo(() => {
<ConversationItem activeRouteId={activeRouteId} conversation={entry} key={entry.item.id} />
);
- // Only the agent rows wait on the agent list: Lobe AI and Channels load on
- // their own, so a slow or failed agent-list request must not hide them.
- const agentsLoading = !isInit && items.length === 0;
+ // Only the agent rows wait on the agent list and recents (which decide what has a conversation):
+ // Lobe AI and Channels load on their own, so a slow or failed request must not hide them.
+ const agentsLoading = (!isInit && items.length === 0) || recents === undefined;
return (
<Flexbox gap={1} paddingBlock={'0 12px'} paddingInline={6}>
@@ -218,6 +232,12 @@ const Body = memo(() => {
{agentsLoading ? (
agentsError ? (
<AsyncError error={agentsError} variant="inline" onRetry={() => void retryAgents()} />
+ ) : recents === undefined && recentsError ? (
+ <AsyncError
+ error={recentsError}
+ variant="inline"
+ onRetry={() => void revalidateRecents()}
+ />
) : (
<SkeletonList paddingBlock={8} />
)
diff --git a/src/features/MessageList/conversations.test.ts b/src/features/MessageList/conversations.test.ts
index 3db94c08a19..4d32d17f821 100644
--- a/src/features/MessageList/conversations.test.ts
+++ b/src/features/MessageList/conversations.test.ts
@@ -50,11 +50,39 @@ describe('buildConversationSections', () => {
);
expect(pinned.map((c) => c.item.id)).toEqual(['p']);
- expect(recent.map((c) => c.item.id)).toEqual(['a', 'g', 'b']);
+ // Documents are not conversation activity, so `b` has no conversation and no row.
+ expect(recent.map((c) => c.item.id)).toEqual(['a', 'g']);
expect(recent[0].preview).toBe('newest reply');
expect(recent[1].preview).toBe('group topic');
- // Documents are not conversation activity.
- expect(recent[2].activeAt).toEqual(new Date('2026-10-02'));
+ });
+
+ it('lists only agents and groups that have a conversation', () => {
+ const items = [
+ agent('talked', '2026-10-01'),
+ agent('idle', '2026-10-09'),
+ agent('idle-group', '2026-10-09', { type: 'group' }),
+ agent('open', '2026-10-01'),
+ agent('pinned', '2026-10-01', { pinned: true }),
+ ];
+ const recents = [topic({ agentId: 'talked', updatedAt: '2026-10-02' })];
+
+ const { pinned, recent } = buildConversationSections(items, recents, undefined, {
+ activeId: 'open',
+ });
+
+ expect(pinned.map((c) => c.item.id)).toEqual(['pinned']);
+ expect(recent.map((c) => c.item.id)).toEqual(['talked', 'open']);
+ });
+
+ it('keeps every agent while searching so a new conversation can start', () => {
+ const { recent } = buildConversationSections(
+ [agent('idle', '2026-10-09'), agent('idle-group', '2026-10-08', { type: 'group' })],
+ [],
+ undefined,
+ { includeIdle: true },
+ );
+
+ expect(recent.map((c) => c.item.id)).toEqual(['idle', 'idle-group']);
});
it('attributes a group topic that also carries the supervisor agentId to the group', () => {
@@ -70,17 +98,17 @@ describe('buildConversationSections', () => {
],
);
- expect(recent.map((c) => c.item.id)).toEqual(['g', 'sup']);
+ // The supervisor has no conversation of its own, so it never shows the group's reply.
+ expect(recent.map((c) => c.item.id)).toEqual(['g']);
expect(recent[0].preview).toBe('group reply');
- // The supervisor only keeps its own timestamp and never shows the group's reply.
- expect(recent[1].activeAt).toEqual(new Date('2026-09-01'));
- expect(recent[1].preview).toBeUndefined();
});
it('drops duplicate ids and falls back to the description', () => {
const { recent } = buildConversationSections(
[agent('a', '2026-10-01', { description: 'helps' }), agent('a', '2026-10-01')],
undefined,
+ undefined,
+ { includeIdle: true },
);
expect(recent).toHaveLength(1);
@@ -104,7 +132,8 @@ describe('buildConversationSections with direct Channels', () => {
new Map([['a', direct]]),
);
- expect(recent.map((c) => c.item.id)).toEqual(['a', 'b']);
+ // `b` has neither a direct Channel nor a topic.
+ expect(recent.map((c) => c.item.id)).toEqual(['a']);
expect(recent[0]).toMatchObject({
activeAt: new Date('2026-10-09'),
preview: 'Done, see the PR',
@@ -150,6 +179,8 @@ describe('buildConversationEntries', () => {
agent('p', '2026-09-01', { pinned: true, title: 'Pinned' }),
],
undefined,
+ undefined,
+ { includeIdle: true },
);
const ids = (entries: ReturnType<typeof buildConversationEntries>) =>
entries.map((e) =>
diff --git a/src/features/MessageList/conversations.ts b/src/features/MessageList/conversations.ts
index d53a9e962b4..f004ae426fc 100644
--- a/src/features/MessageList/conversations.ts
+++ b/src/features/MessageList/conversations.ts
@@ -105,13 +105,24 @@ export const inboxActivity = (
/**
* Turn the sidebar agent/group list into IM-style conversations: each row
* carries a preview of its latest topic and is ordered by latest activity,
- * pinned rows first.
+ * pinned rows first. Only conversations that exist get a row — a direct Channel
+ * or a topic; the rest stay in Contacts. Pinned rows and the open one stay,
+ * and a search lists every agent so a new conversation can start from it.
*/
export const buildConversationSections = (
items: SidebarAgentItem[],
recents: RecentItem[] | undefined,
/** The person's direct Channel per agent id. A row that opens one shows that conversation. */
directChannels?: Map<string, ChannelListItem>,
+ {
+ activeId,
+ includeIdle = false,
+ }: {
+ /** The routed conversation, kept so the open chat always has its row. */
+ activeId?: string;
+ /** Keep agents and groups without any conversation yet. */
+ includeIdle?: boolean;
+ } = {},
): ConversationSections => {
const latestByOwner = topicsByOwner(recents);
@@ -136,6 +147,8 @@ export const buildConversationSections = (
}
const latest = latestByOwner.get(item.id);
+ if (!latest && !includeIdle && !item.pinned && item.id !== activeId) continue;
+
const latestTime = latest ? toTime(latest.updatedAt) : 0;
conversations.push({