🤯 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
✨ feat(project): lead with the main agent and tag it as the project lead (#21380)
LiJian2ec28f4c83b6
diff --git a/locales/en-US/project.json b/locales/en-US/project.jsonindex 085138264e5..90e5fe7c761 100644--- a/locales/en-US/project.json+++ b/locales/en-US/project.json@@ -185,6 +185,7 @@"settings.workLocations": "Working directories","sidebar.agentsEmpty": "No agents are connected yet","sidebar.conversationsEmpty": "No project topics yet",+ "sidebar.coordinatorTag": "Lead","sidebar.emptyAction": "Create your first project","sidebar.librariesEmpty": "No libraries are connected yet","sidebar.newConversation": "New topic",diff --git a/locales/zh-CN/project.json b/locales/zh-CN/project.jsonindex 7fef66b8c7a..79401bee254 100644--- a/locales/zh-CN/project.json+++ b/locales/zh-CN/project.json@@ -185,6 +185,7 @@"settings.workLocations": "工作目录","sidebar.agentsEmpty": "还没有关联智能体","sidebar.conversationsEmpty": "还没有项目话题",+ "sidebar.coordinatorTag": "主管","sidebar.emptyAction": "创建第一个项目","sidebar.librariesEmpty": "还没有关联资料库","sidebar.newConversation": "新话题",diff --git a/packages/database/src/models/__tests__/project.test.ts b/packages/database/src/models/__tests__/project.test.tsindex 4a2b3d46bae..3cd991d158d 100644--- a/packages/database/src/models/__tests__/project.test.ts+++ b/packages/database/src/models/__tests__/project.test.ts@@ -281,6 +281,35 @@ describe('ProjectModel', () => {).toHaveLength(0);});+ it('lists the main agent first whatever order the other members carry', async () => {+ const project = await createProject(model, { name: 'Ordering' });+ const [agent] = await serverDB+ .insert(agents)+ .values({ title: 'Early bird', userId })+ .returning();+ await model.addAgent(project.id, { agentId: agent.id, sortOrder: -10 });++ expect((await model.listAgents(project.id))?.map(({ agent }) => agent.id)).toEqual([+ project.coordinatorAgentId,+ agent.id,+ ]);+ });++ it('still lists members of a project whose main agent was cleared', async () => {+ const project = await createProject(model, { name: 'Orphaned' });+ const [agent] = await serverDB.insert(agents).values({ title: 'Stays', userId }).returning();+ await model.addAgent(project.id, { agentId: agent.id });+ // Deleting the main agent clears the column (ON DELETE SET NULL).+ await serverDB+ .update(projects)+ .set({ coordinatorAgentId: null })+ .where(eq(projects.id, project.id));++ expect((await model.listAgents(project.id))?.map(({ agent }) => agent.id)).toEqual(+ expect.arrayContaining([agent.id]),+ );+ });+it('binds only accessible agents and knowledge bases', async () => {const project = await createProject(model, { name: 'Bindings' });const [agent] = await serverDBdiff --git a/packages/database/src/models/project.ts b/packages/database/src/models/project.tsindex 890296c76e9..94904048fd4 100644--- a/packages/database/src/models/project.ts+++ b/packages/database/src/models/project.ts@@ -310,8 +310,15 @@ export class ProjectModel {return project ?? null;}+ /** Members in project order, the main agent always first. */async listAgents(projectId: string) {- if (!(await this.findById(projectId))) return null;+ const project = await this.findById(projectId);+ if (!project) return null;+ // A cleared main agent (LobeAI fallback) has no member row to lead with. A+ // bare constant would not do instead: Postgres reads `ORDER BY 0` as a column position.+ const coordinatorFirst = project.coordinatorAgentId+ ? [sql`CASE WHEN ${projectAgents.agentId} = ${project.coordinatorAgentId} THEN 0 ELSE 1 END`]+ : [];return this.db.select({ agent: agents, binding: projectAgents }).from(projectAgents)@@ -322,7 +329,7 @@ export class ProjectModel {buildWorkspaceWhere({ userId: this.userId, workspaceId: this.workspaceId }, agents),),)- .orderBy(asc(projectAgents.sortOrder), asc(projectAgents.createdAt));+ .orderBy(...coordinatorFirst, asc(projectAgents.sortOrder), asc(projectAgents.createdAt));}async addAgent(projectId: string, input: ProjectAgentInput) {diff --git a/packages/locales/src/default/project.ts b/packages/locales/src/default/project.tsindex f95820ae4d9..b57855c9a7e 100644--- a/packages/locales/src/default/project.ts+++ b/packages/locales/src/default/project.ts@@ -243,6 +243,7 @@ export default {'sidebar.emptyAction': 'Create your first project','sidebar.agentsEmpty': 'No agents are connected yet','sidebar.conversationsEmpty': 'No project topics yet',+ 'sidebar.coordinatorTag': 'Lead','sidebar.librariesEmpty': 'No libraries are connected yet','sidebar.newConversation': 'New topic','sidebar.title': 'Projects',diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsxindex b4169f30ecc..3e96cf5f0ba 100644--- a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx@@ -5,6 +5,7 @@ import { AccordionRoot } from '@lobehub/ui';import { render, screen } from '@testing-library/react';import { describe, expect, it, vi } from 'vitest';+import { TopicListScopeContext } from '../../TopicListScope';import GroupItem from './GroupItem';vi.mock('@/store/agent', () => ({@@ -31,6 +32,8 @@ vi.mock('@lobehub/ui', async (importOriginal) => ({...(await import('~base-ui-stubs')).baseUiStubs,}));+vi.mock('@/store/projectWorkingDirectory', () => ({ useProjectDirectories: () => [] }));+vi.mock('react-i18next', () => ({useTranslation: () => ({ t: (key: string) => key }),}));@@ -56,4 +59,32 @@ describe('TopicByAgentGroupItem', () => {expect(screen.getByText('A1-目录A任务').getAttribute('data-suppress')).toBe('yes');});++ const renderInProject = (agentId: string) =>+ render(+ <TopicListScopeContext value={{ coordinatorAgentId: 'agt_lead', projectId: 'prj_1' }}>+ <AccordionRoot>+ <GroupItem+ expanded={false}+ group={{+ children: [{ createdAt: 1, id: 't1', title: 'Plan', updatedAt: 1 }],+ id: `agent:${agentId}`,+ title: agentId,+ }}+ />+ </AccordionRoot>+ </TopicListScopeContext>,+ );++ it("tags the project's main agent as its lead", () => {+ renderInProject('agt_lead');++ expect(screen.getByText('sidebar.coordinatorTag')).toBeTruthy();+ });++ it('leaves other member agents untagged', () => {+ renderInProject('agt_writer');++ expect(screen.queryByText('sidebar.coordinatorTag')).toBeNull();+ });});diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsxindex 8ff52283911..f61af791a1d 100644--- a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx@@ -12,6 +12,7 @@ import {cssVar,cx,Flexbox,+ Tag,Text,} from '@lobehub/ui';import isEqual from 'fast-deep-equal';@@ -82,6 +83,8 @@ const GroupItem = memo<GroupItemComponentProps>(({ group }) => {(isOwnBucket ? (activeMeta.title ?? activeMeta.name) : undefined) ??t('groupTitle.byAgent.unknown');+ const isCoordinator = !!agentId && agentId === scope?.coordinatorAgentId;+// Only an attributed bucket in a project-scoped list can start a topic with// its agent preselected; the `no-agent` bucket has no agent to preselect.const canAddTopic = !!scope && !!agentId;@@ -107,6 +110,11 @@ const GroupItem = memo<GroupItemComponentProps>(({ group }) => {<Text ellipsis fontSize={14} style={{ flex: 1 }}>{name}</Text>+ {isCoordinator && (+ <Tag color={'primary'} size={'small'}>+ {tProject('sidebar.coordinatorTag')}+ </Tag>+ )}</Flexbox></AccordionTrigger>{canAddTopic && (diff --git a/src/features/AgentSidebar/Topic/useScopedTopics.test.ts b/src/features/AgentSidebar/Topic/useScopedTopics.test.tsindex 03bb1f4544f..4e78ba942db 100644--- a/src/features/AgentSidebar/Topic/useScopedTopics.test.ts+++ b/src/features/AgentSidebar/Topic/useScopedTopics.test.ts@@ -4,7 +4,7 @@ import { createElement, type PropsWithChildren, useState } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';import { TopicListRevealContext, TopicListScopeContext } from './TopicListScope';-import { useScopedSidebarTopics } from './useScopedTopics';+import { pinCoordinatorGroup, useScopedSidebarTopics } from './useScopedTopics';const fixture = vi.hoisted(() => ({ topicId: undefined as string | undefined }));const updateSystemStatus = vi.hoisted(() => vi.fn());@@ -154,4 +154,41 @@ describe('Project topics use the canonical Agent sidebar rules', () => {expect(result.current.toggle.groups).toEqual(result.current.list.groups);expect(updateSystemStatus).not.toHaveBeenCalled();});++ it("puts the project's main agent first among the agent groups, below favorites", () => {+ const coordinatorWrapper = ({ children }: PropsWithChildren) =>+ createElement(+ TopicListScopeContext,+ { value: { coordinatorAgentId: 'agent-b', projectId: 'project-a' } },+ createElement(RevealHost, null, children),+ );+ const { result } = renderHook(() => useScopedSidebarTopics(20, 'updatedAt', 'byAgent', false), {+ wrapper: coordinatorWrapper,+ });+ // agent-a holds the most recently updated topic, so recency alone would lead with it.+ expect(result.current.groups.map((group) => group.id)).toEqual([+ 'favorite',+ 'agent:agent-b',+ 'agent:agent-a',+ ]);+ });+});++describe('pinCoordinatorGroup', () => {+ const group = (id: string) => ({ children: [], id, title: id });++ it('leads with the main agent when there are no favorites', () => {+ expect(+ pinCoordinatorGroup([group('agent:a'), group('agent:b'), group('no-agent')], 'b').map(+ (g) => g.id,+ ),+ ).toEqual(['agent:b', 'agent:a', 'no-agent']);+ });++ it('keeps the order when the main agent already leads or has no topics', () => {+ const groups = [group('favorite'), group('agent:b'), group('agent:a')];+ expect(pinCoordinatorGroup(groups, 'b')).toBe(groups);+ expect(pinCoordinatorGroup(groups, 'missing')).toBe(groups);+ expect(pinCoordinatorGroup(groups, undefined)).toBe(groups);+ });});diff --git a/src/features/AgentSidebar/Topic/useScopedTopics.ts b/src/features/AgentSidebar/Topic/useScopedTopics.tsindex d9f550707d8..42ccdaad44d 100644--- a/src/features/AgentSidebar/Topic/useScopedTopics.ts+++ b/src/features/AgentSidebar/Topic/useScopedTopics.ts@@ -10,7 +10,7 @@ import {useProjectDirectoryStore,useProjectTopics,} from '@/store/projectWorkingDirectory';-import type { ChatTopic, TopicGroupMode, TopicSortBy } from '@/types/topic';+import type { ChatTopic, GroupedTopic, TopicGroupMode, TopicSortBy } from '@/types/topic';import { useTopicListReveal, useTopicListScope } from './TopicListScope';@@ -33,6 +33,18 @@ export const useScopedTopics = () => {return { scope, topics, refresh: request.revalidate };};+/**+ * A project's main agent leads the agent buckets, wherever its latest topic+ * falls; favorites keep the very top, as in every other mode.+ */+export const pinCoordinatorGroup = (groups: GroupedTopic[], coordinatorAgentId?: string) => {+ const index = groups.findIndex((group) => group.id === `agent:${coordinatorAgentId}`);+ const leadIndex = groups[0]?.id === 'favorite' ? 1 : 0;+ if (!coordinatorAgentId || index <= leadIndex) return groups;+ const rest = groups.filter((_, i) => i !== index);+ return [...rest.slice(0, leadIndex), groups[index], ...rest.slice(leadIndex)];+};+export const useScopedTopic = (id?: string) =>useScopedTopics().topics?.find((topic) => topic.id === id);@@ -62,10 +74,11 @@ export const useScopedSidebarTopics = (list.find((topic) => topic.id === topicId),);}, [topics, topicId, visibleLimit, sortBy, includeCompleted]);- const groups = useMemo(- () => groupSidebarTopics(visible, groupMode, sortBy, running, directories),- [visible, groupMode, sortBy, running, directories],- );+ const coordinatorAgentId = scope?.coordinatorAgentId;+ const groups = useMemo(() => {+ const grouped = groupSidebarTopics(visible, groupMode, sortBy, running, directories);+ return groupMode === 'byAgent' ? pinCoordinatorGroup(grouped, coordinatorAgentId) : grouped;+ }, [visible, groupMode, sortBy, running, directories, coordinatorAgentId]);const hasMore =(topics ?? []).filter((topic) =>