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.

πŸ› fix(topic): list private agents first in Move topics picker (#21377)

Lobehub Coder9b42709c4781
diff --git a/src/features/AgentTopicManager/MoveTopicsModal/Content.tsx b/src/features/AgentTopicManager/MoveTopicsModal/Content.tsx
index b1560033707..fdef176f9ae 100644
--- a/src/features/AgentTopicManager/MoveTopicsModal/Content.tsx
+++ b/src/features/AgentTopicManager/MoveTopicsModal/Content.tsx
@@ -1,7 +1,7 @@
'use client';
import { AGENT_CHAT_URL, DEFAULT_INBOX_AVATAR } from '@lobechat/const';
-import { agentDisplayName } from '@lobechat/types';
+import { agentDisplayName, type SidebarAgentItem } from '@lobechat/types';
import {
Button,
createStaticStyles,
@@ -13,6 +13,7 @@ import {
toast,
useModalContext,
} from '@lobehub/ui';
+import isEqual from 'fast-deep-equal';
import { CircleCheck } from 'lucide-react';
import { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -27,6 +28,8 @@ import { useChatStore } from '@/store/chat';
import { useHomeStore } from '@/store/home';
import { homeAgentListSelectors } from '@/store/home/selectors';
+import { buildMoveTargets } from './targets';
+
type Step = 'pick' | 'confirm' | 'moving' | 'done';
export interface MoveTopicsContentProps {
@@ -38,6 +41,12 @@ export interface MoveTopicsContentProps {
}
const styles = createStaticStyles(({ css }) => ({
+ sectionHeader: css`
+ padding-block: 4px;
+ padding-inline: 8px;
+ font-size: 12px;
+ color: ${cssVar.colorTextTertiary};
+ `,
searchInput: css`
width: 100%;
padding-block: 6px;
@@ -68,7 +77,15 @@ const MoveTopicsContent = memo<MoveTopicsContentProps>(({ onMoved, sourceAgentId
const [target, setTarget] = useState<{ id: string; title: string } | null>(null);
const batchMoveTopicsToAgent = useChatStore((s) => s.batchMoveTopicsToAgent);
- const agents = useHomeStore(homeAgentListSelectors.allAgents);
+ const pinnedAgents = useHomeStore(homeAgentListSelectors.pinnedAgents, isEqual);
+ const agentGroups = useHomeStore(homeAgentListSelectors.agentGroups, isEqual);
+ const ungroupedAgents = useHomeStore(homeAgentListSelectors.ungroupedAgents, isEqual);
+ const privateAgentGroups = useHomeStore(homeAgentListSelectors.privateAgentGroups, isEqual);
+ const privatePinnedAgents = useHomeStore(homeAgentListSelectors.privatePinnedAgents, isEqual);
+ const privateUngroupedAgents = useHomeStore(
+ homeAgentListSelectors.privateUngroupedAgents,
+ isEqual,
+ );
const isAgentListInit = useHomeStore(homeAgentListSelectors.isAgentListInit);
// The inbox (default "LobeAI") agent is virtual, so it's filtered out of the
@@ -82,33 +99,66 @@ const MoveTopicsContent = memo<MoveTopicsContentProps>(({ onMoved, sourceAgentId
const count = topicIds.length;
- // Source agent is excluded β€” moving topics back to where they already live
- // would be a no-op. The inbox agent is prepended when not already present.
- const targetAgents = useMemo(() => {
- const available = agents.filter((a) => a.type === 'agent');
- const withInbox =
- inboxAgentId && !available.some((a) => a.id === inboxAgentId)
- ? [
- {
+ // Private agents get their own section on top β€” appended to the end of a
+ // long workspace list they were effectively unreachable. The source agent is
+ // excluded (no-op move) and the virtual inbox agent is added back.
+ const { privateAgents, workspaceAgents } = useMemo(
+ () =>
+ buildMoveTargets({
+ agentGroups,
+ inbox: inboxAgentId
+ ? {
avatar: inboxMeta?.avatar || DEFAULT_INBOX_AVATAR,
description: null,
id: inboxAgentId,
pinned: false,
title: agentDisplayName(inboxMeta, t('inbox.title', { ns: 'chat' })),
- type: 'agent' as const,
+ type: 'agent',
updatedAt: new Date(),
- },
- ...available,
- ]
- : available;
- return withInbox.filter((a) => a.id !== sourceAgentId);
- }, [agents, inboxAgentId, inboxMeta, sourceAgentId, t]);
-
- const filteredAgents = useMemo(() => {
- const q = search.trim().toLowerCase();
- if (!q) return targetAgents;
- return targetAgents.filter((a) => (agentDisplayName(a) ?? '').toLowerCase().includes(q));
- }, [targetAgents, search]);
+ }
+ : undefined,
+ pinnedAgents,
+ privateAgentGroups,
+ privatePinnedAgents,
+ privateUngroupedAgents,
+ search,
+ sourceAgentId,
+ ungroupedAgents,
+ }),
+ [
+ agentGroups,
+ inboxAgentId,
+ inboxMeta,
+ pinnedAgents,
+ privateAgentGroups,
+ privatePinnedAgents,
+ privateUngroupedAgents,
+ search,
+ sourceAgentId,
+ t,
+ ungroupedAgents,
+ ],
+ );
+
+ const renderAgentItems = (list: SidebarAgentItem[]) =>
+ list.map((agent) => (
+ <AgentItem
+ active={false}
+ agent={agent}
+ agentId={agent.id}
+ agentTitle={agentDisplayName(agent, t('untitledAgent', { ns: 'chat' }))}
+ avatar={agent.avatar}
+ key={agent.id}
+ onClose={() => {}}
+ onAgentChange={() => {
+ setTarget({
+ id: agent.id,
+ title: agentDisplayName(agent, t('untitledAgent', { ns: 'chat' })),
+ });
+ setStep('confirm');
+ }}
+ />
+ ));
const handleConfirm = async () => {
if (!target) return;
@@ -140,7 +190,7 @@ const MoveTopicsContent = memo<MoveTopicsContentProps>(({ onMoved, sourceAgentId
/>
{!isAgentListInit ? (
<SkeletonList rows={6} />
- ) : filteredAgents.length === 0 ? (
+ ) : privateAgents.length + workspaceAgents.length === 0 ? (
<Flexbox align={'center'} justify={'center'} padding={24}>
<Text fontSize={12} type={'secondary'}>
{t('management.bulk.moveEmpty')}
@@ -152,24 +202,22 @@ const MoveTopicsContent = memo<MoveTopicsContentProps>(({ onMoved, sourceAgentId
padding={8}
style={{ maxHeight: '50vh', overflowY: 'auto', width: '100%' }}
>
- {filteredAgents.map((agent) => (
- <AgentItem
- active={false}
- agent={agent}
- agentId={agent.id}
- agentTitle={agentDisplayName(agent, t('untitledAgent', { ns: 'chat' }))}
- avatar={agent.avatar}
- key={agent.id}
- onClose={() => {}}
- onAgentChange={() => {
- setTarget({
- id: agent.id,
- title: agentDisplayName(agent, t('untitledAgent', { ns: 'chat' })),
- });
- setStep('confirm');
- }}
- />
- ))}
+ {privateAgents.length > 0 ? (
+ <>
+ <div className={styles.sectionHeader}>
+ {t('taskManager.agentSelector.privateGroup')}
+ </div>
+ {renderAgentItems(privateAgents)}
+ {workspaceAgents.length > 0 && (
+ <div className={styles.sectionHeader}>
+ {t('taskManager.agentSelector.workspaceGroup')}
+ </div>
+ )}
+ {renderAgentItems(workspaceAgents)}
+ </>
+ ) : (
+ renderAgentItems(workspaceAgents)
+ )}
</Flexbox>
)}
</Flexbox>
diff --git a/src/features/AgentTopicManager/MoveTopicsModal/targets.test.ts b/src/features/AgentTopicManager/MoveTopicsModal/targets.test.ts
new file mode 100644
index 00000000000..88ca5416b59
--- /dev/null
+++ b/src/features/AgentTopicManager/MoveTopicsModal/targets.test.ts
@@ -0,0 +1,65 @@
+import type { SidebarAgentItem } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { buildMoveTargets } from './targets';
+
+const agent = (id: string, title = id, type: 'agent' | 'group' = 'agent'): SidebarAgentItem => ({
+ avatar: null,
+ description: null,
+ id,
+ pinned: false,
+ title,
+ type,
+ updatedAt: new Date(),
+});
+
+const empty = {
+ agentGroups: [],
+ pinnedAgents: [],
+ privateAgentGroups: [],
+ privatePinnedAgents: [],
+ privateUngroupedAgents: [],
+ ungroupedAgents: [],
+};
+
+describe('buildMoveTargets', () => {
+ it('returns private agents from every private bucket', () => {
+ const result = buildMoveTargets({
+ ...empty,
+ privateAgentGroups: [{ id: 'g', items: [agent('pg')], title: 'G' } as any],
+ privatePinnedAgents: [agent('pp')],
+ privateUngroupedAgents: [agent('pu')],
+ ungroupedAgents: [agent('w1')],
+ });
+
+ expect(result.privateAgents.map((a) => a.id)).toEqual(['pp', 'pg', 'pu']);
+ expect(result.workspaceAgents.map((a) => a.id)).toEqual(['w1']);
+ });
+
+ it('excludes the source agent, chat groups and non-matching search results', () => {
+ const result = buildMoveTargets({
+ ...empty,
+ privateUngroupedAgents: [agent('src'), agent('p1', 'Alpha'), agent('grp', 'Alpha', 'group')],
+ search: 'alp',
+ sourceAgentId: 'src',
+ ungroupedAgents: [agent('w1', 'Beta')],
+ });
+
+ expect(result.privateAgents.map((a) => a.id)).toEqual(['p1']);
+ expect(result.workspaceAgents).toEqual([]);
+ });
+
+ it('prepends the inbox agent to the workspace bucket only when missing', () => {
+ const inbox = agent('inbox', 'LobeAI');
+ expect(
+ buildMoveTargets({ ...empty, inbox, ungroupedAgents: [agent('w1')] }).workspaceAgents.map(
+ (a) => a.id,
+ ),
+ ).toEqual(['inbox', 'w1']);
+ expect(
+ buildMoveTargets({ ...empty, inbox, ungroupedAgents: [inbox] }).workspaceAgents.map(
+ (a) => a.id,
+ ),
+ ).toEqual(['inbox']);
+ });
+});
diff --git a/src/features/AgentTopicManager/MoveTopicsModal/targets.ts b/src/features/AgentTopicManager/MoveTopicsModal/targets.ts
new file mode 100644
index 00000000000..1c1ff610435
--- /dev/null
+++ b/src/features/AgentTopicManager/MoveTopicsModal/targets.ts
@@ -0,0 +1,60 @@
+import { agentDisplayName, type SidebarAgentItem, type SidebarGroup } from '@lobechat/types';
+
+export interface MoveTargetSources {
+ agentGroups: SidebarGroup[];
+ /** Virtual inbox agent, prepended to the workspace bucket when missing. */
+ inbox?: SidebarAgentItem;
+ pinnedAgents: SidebarAgentItem[];
+ privateAgentGroups: SidebarGroup[];
+ privatePinnedAgents: SidebarAgentItem[];
+ privateUngroupedAgents: SidebarAgentItem[];
+ search?: string;
+ /** Source agent β€” excluded so a no-op move can't be chosen. */
+ sourceAgentId?: string | null;
+ ungroupedAgents: SidebarAgentItem[];
+}
+
+export interface MoveTargets {
+ privateAgents: SidebarAgentItem[];
+ workspaceAgents: SidebarAgentItem[];
+}
+
+/**
+ * Split move targets into the user's private agents and the shared/workspace
+ * agents, so private agents don't get buried at the end of a long list.
+ * In personal mode the private buckets are empty and everything is "workspace".
+ */
+export const buildMoveTargets = ({
+ agentGroups,
+ inbox,
+ pinnedAgents,
+ privateAgentGroups,
+ privatePinnedAgents,
+ privateUngroupedAgents,
+ search,
+ sourceAgentId,
+ ungroupedAgents,
+}: MoveTargetSources): MoveTargets => {
+ const q = search?.trim().toLowerCase();
+ const pick = (list: SidebarAgentItem[]) =>
+ list.filter(
+ (a) =>
+ a.type === 'agent' &&
+ a.id !== sourceAgentId &&
+ (!q || (agentDisplayName(a) ?? '').toLowerCase().includes(q)),
+ );
+
+ const privateAgents = pick([
+ ...privatePinnedAgents,
+ ...privateAgentGroups.flatMap((g) => g.items),
+ ...privateUngroupedAgents,
+ ]);
+
+ const shared = [...pinnedAgents, ...agentGroups.flatMap((g) => g.items), ...ungroupedAgents];
+ const withInbox =
+ inbox && ![...shared, ...privateAgents].some((a) => a.id === inbox.id)
+ ? [inbox, ...shared]
+ : shared;
+
+ return { privateAgents, workspaceAgents: pick(withInbox) };
+};