🤯 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(chat-input): search every agent from the @ mention menu (#23730)
AmAzing-b3379e58cb16
diff --git a/src/features/ChatInput/InputEditor/useMentionCategories.test.ts b/src/features/ChatInput/InputEditor/useMentionCategories.test.tsnew file mode 100644index 00000000000..bae934290fc--- /dev/null+++ b/src/features/ChatInput/InputEditor/useMentionCategories.test.ts@@ -0,0 +1,139 @@+import type { SidebarAgentItem } from '@lobechat/types';+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useDiscoverStore } from '@/store/discover';+import { useHomeStore } from '@/store/home';+import { useToolStore } from '@/store/tool';++import { useMentionCategories } from './useMentionCategories';++const state = vi.hoisted(() => ({+ currentAgentId: 'agent-current',+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++vi.mock('@/hooks/usePermission', () => ({+ usePermission: () => ({ allowed: false }),+}));++vi.mock('../hooks/useAgentId', () => ({+ useAgentId: () => state.currentAgentId,+}));++// Context store: no group-chat mentionItems, i.e. the agent picker path.+vi.mock('../store', () => ({+ useChatInputStore: <T>(selector: (s: { mentionItems?: unknown }) => T) =>+ selector({ mentionItems: undefined }),+}));++vi.mock('./ActionTag/useInstalledSkillsAndTools', () => ({+ useInstalledSkillsAndTools: () => [],+}));++// More agents than the menu previews at once; every one must stay a mention+// candidate so Fuse search can still reach the ones the preview never shows.+const AGENT_COUNT = 30;++const makeAgent = (id: string, overrides: Partial<SidebarAgentItem> = {}): SidebarAgentItem => ({+ id,+ pinned: false,+ title: `Agent ${id}`,+ type: 'agent',+ ...overrides,+});++const seedHomeStore = (lists: {+ agentGroups?: { id: string; items: SidebarAgentItem[] }[];+ pinnedAgents?: SidebarAgentItem[];+ privateAgentGroups?: { id: string; items: SidebarAgentItem[] }[];+ privatePinnedAgents?: SidebarAgentItem[];+ privateUngroupedAgents?: SidebarAgentItem[];+ ungroupedAgents?: SidebarAgentItem[];+}) => {+ useHomeStore.setState({+ agentGroups: [],+ pinnedAgents: [],+ privateAgentGroups: [],+ privatePinnedAgents: [],+ privateUngroupedAgents: [],+ ungroupedAgents: [],+ ...lists,+ } as never);+};++const agentIdsInCategory = (categoryId: string) => {+ const { result } = renderHook(() => useMentionCategories());+ const category = result.current.categories.find((c) => c.id === categoryId);+ return new Set(category?.items.map((item) => item.metadata?.id as string) ?? []);+};++beforeEach(() => {+ state.currentAgentId = 'agent-current';++ // Market fetch hooks are store methods; stub them so the hook runs without+ // network. Permission is denied anyway, so no market rows would merge.+ const disabledListFetch = () => ({ queryKey: undefined });+ useDiscoverStore.setState({+ useFetchAssistantList: disabledListFetch,+ useFetchSkillList: disabledListFetch,+ } as never);+ const fetchAgentSkillsStub = () => ({});+ useToolStore.setState({ useFetchAgentSkills: fetchAgentSkillsStub } as never);+});++describe('useMentionCategories', () => {+ it('offers every eligible agent as a mention candidate, not just the previewed ones', () => {+ const pinned = [makeAgent('agent-pinned-1'), makeAgent('agent-pinned-2')];+ const ungrouped = [makeAgent('agent-current')].concat(+ Array.from({ length: AGENT_COUNT - pinned.length - 1 }, (_, i) =>+ makeAgent(`agent-${String(i + 1).padStart(3, '0')}`),+ ),+ );+ const oldest = ungrouped.at(-1);++ seedHomeStore({ pinnedAgents: pinned, ungroupedAgents: ungrouped });++ const ids = agentIdsInCategory('agent');+ const expected = new Set([...pinned, ...ungrouped].map((a) => a.id));+ expected.delete('agent-current');++ expect(ids).toEqual(expected);+ expect(ids.has(oldest.id)).toBe(true);+ });++ describe('private agents', () => {+ const PRIVATE_COUNT = 12;++ it('offers every private agent when the current agent is itself private', () => {+ const privateAgents = [makeAgent('agent-current')].concat(+ Array.from({ length: PRIVATE_COUNT - 1 }, (_, i) => makeAgent(`agent-private-${i}`)),+ );+ seedHomeStore({+ privateUngroupedAgents: privateAgents,+ ungroupedAgents: [makeAgent('agent-workspace-1')],+ });++ const ids = agentIdsInCategory('agent-private');+ expect(ids.size).toBe(PRIVATE_COUNT - 1);+ for (const agent of privateAgents.slice(1)) {+ expect(ids.has(agent.id)).toBe(true);+ }+ });++ it('hides private agents when the current agent is shared', () => {+ seedHomeStore({+ privateUngroupedAgents: Array.from({ length: PRIVATE_COUNT }, (_, i) =>+ makeAgent(`agent-private-${i}`),+ ),+ ungroupedAgents: [makeAgent('agent-current'), makeAgent('agent-workspace-1')],+ });++ const { result } = renderHook(() => useMentionCategories());+ expect(result.current.categories.some((c) => c.id === 'agent-private')).toBe(false);+ });+ });+});diff --git a/src/features/ChatInput/InputEditor/useMentionCategories.tsx b/src/features/ChatInput/InputEditor/useMentionCategories.tsxindex fb3e322627e..a7c9de32d5a 100644--- a/src/features/ChatInput/InputEditor/useMentionCategories.tsx+++ b/src/features/ChatInput/InputEditor/useMentionCategories.tsx@@ -34,7 +34,6 @@ import MentionItemIcon from './MentionItemIcon';import type { MentionCategory } from './MentionMenu/types';import { AGENT_CATEGORY_IDS, mergeIntoCategory, SKILL_PRECEDING_IDS } from './mentionMenuSections';-const MAX_AGENT_ITEMS = 20;const MAX_TOPIC_LABEL = 50;type MenuOptionWithMetadata = { key: string; metadata?: Record<string, unknown> };@@ -213,13 +212,10 @@ export const useMentionCategories = (): MentionSource => {installedAgentSources.add(currentAgent.forkedFromIdentifier);}- // Quota stays at MAX_AGENT_ITEMS total. When the user has private agents- // we reserve up to half for them so they don't get drowned out by a long- // workspace list.- const privateBudget = isCurrentContextPrivate ? Math.min(privateCandidates.length, 10) : 0;- const workspaceBudget = MAX_AGENT_ITEMS - privateBudget;- const privateItems = privateCandidates.slice(0, privateBudget).map(toItem);- const workspaceItems = workspaceCandidates.slice(0, workspaceBudget).map(toItem);+ // Every candidate stays searchable; the menu caps what it renders+ // (`limitMentionGroups`), private sections first.+ const privateItems = isCurrentContextPrivate ? privateCandidates.map(toItem) : [];+ const workspaceItems = workspaceCandidates.map(toItem);if (privateItems.length > 0) {categories.push({