π€― 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
π style: sidebar project create action (#21390)
Arvin Xu5e3621b20e22
diff --git a/packages/database/src/models/__tests__/project.test.ts b/packages/database/src/models/__tests__/project.test.tsindex ae691b28ff9..55440322d61 100644--- a/packages/database/src/models/__tests__/project.test.ts+++ b/packages/database/src/models/__tests__/project.test.ts@@ -1,7 +1,7 @@import { randomUUID } from 'node:crypto';import { INBOX_SESSION_ID } from '@lobechat/const';-import { and, eq } from 'drizzle-orm';+import { and, eq, inArray } from 'drizzle-orm';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { getTestDB } from '../../core/getTestDB';@@ -219,6 +219,47 @@ describe('ProjectModel', () => {expect(await model.list({ limit: 1, offset: 1 })).toHaveLength(1);});+ it('lists projects with their main agent display meta', async () => {+ const project = await createProject(model, { name: 'Apollo' });+ const styled = await createProject(model, { name: 'Gemini' });+ const cleared = await createProject(model, { name: 'Cleared' });+ await serverDB+ .update(agents)+ .set({ avatar: 'π', backgroundColor: '#000', name: 'Ada' })+ .where(eq(agents.id, styled.coordinatorAgentId));+ await serverDB+ .update(projects)+ .set({ coordinatorAgentId: null })+ .where(eq(projects.id, cleared.id));++ const coordinators = await serverDB+ .select({ avatar: agents.avatar, id: agents.id, title: agents.title })+ .from(agents)+ .where(inArray(agents.id, [project.coordinatorAgentId, styled.coordinatorAgentId]));+ const titleOf = (id: string) => coordinators.find((agent) => agent.id === id)?.title;+ const rows = await model.list();++ // A freshly created coordinator has no avatar; its meta must still be listed.+ expect(+ coordinators.find((agent) => agent.id === project.coordinatorAgentId)?.avatar,+ ).toBeNull();+ expect(rows.find((row) => row.id === project.id)?.coordinatorAgent).toEqual({+ avatar: null,+ backgroundColor: null,+ id: project.coordinatorAgentId,+ name: null,+ title: titleOf(project.coordinatorAgentId),+ });+ expect(rows.find((row) => row.id === styled.id)?.coordinatorAgent).toEqual({+ avatar: 'π',+ backgroundColor: '#000',+ id: styled.coordinatorAgentId,+ name: 'Ada',+ title: titleOf(styled.coordinatorAgentId),+ });+ expect(rows.find((row) => row.id === cleared.id)?.coordinatorAgent).toBeNull();+ });+it('does not expose or mutate another user project in personal mode', async () => {const project = await createProject(otherModel, { name: 'Private effort' });expect(await model.findById(project.id)).toBeNull();diff --git a/packages/database/src/models/project.ts b/packages/database/src/models/project.tsindex 0215384524a..0a324dfc24b 100644--- a/packages/database/src/models/project.ts+++ b/packages/database/src/models/project.ts@@ -59,6 +59,19 @@ export interface ProjectKnowledgeBaseInput {export type ProjectKnowledgeBasePatch = Partial<Omit<ProjectKnowledgeBaseInput, 'knowledgeBaseId'>>;+/** Display meta of a project's main agent, joined into list rows only. */+export interface ProjectCoordinatorAgentMeta {+ avatar: string | null;+ backgroundColor: string | null;+ id: string;+ name: string | null;+ title: string | null;+}++export type ProjectListRow = typeof projects.$inferSelect & {+ coordinatorAgent: ProjectCoordinatorAgentMeta | null;+};+export interface ProjectModelOptions {/*** Workspace owners and admins manage the agent members of every readable@@ -264,16 +277,33 @@ export class ProjectModel {return project ?? null;}- async list(options: { limit?: number; offset?: number; statuses?: ProjectStatus[] } = {}) {+ async list(+ options: { limit?: number; offset?: number; statuses?: ProjectStatus[] } = {},+ ): Promise<ProjectListRow[]> {const { limit = 50, offset = 0, statuses } = options;const statusWhere = statuses?.length ? inArray(projects.status, statuses) : undefined;- return this.db- .select()+ const rows = await this.db+ .select({+ // Drizzle nulls a left-joined object when its first column is null, so the+ // non-null id leads; coordinators usually have no avatar.+ coordinatorAgent: {+ id: agents.id,+ avatar: agents.avatar,+ backgroundColor: agents.backgroundColor,+ name: agents.name,+ title: agents.title,+ },+ project: projects,+ }).from(projects)+ .leftJoin(agents, eq(agents.id, projects.coordinatorAgentId)).where(and(this.readable(), statusWhere)).orderBy(desc(projects.updatedAt)).limit(limit).offset(offset);+ // Coordinators are virtual agents the client agent list never loads, so the+ // list carries their display meta for the owner column.+ return rows.map(({ coordinatorAgent, project }) => ({ ...project, coordinatorAgent }));}async update(id: string, input: UpdateProjectInput) {diff --git a/src/features/HomeSidebar/Body/Project/index.tsx b/src/features/HomeSidebar/Body/Project/index.tsxindex bf49f055e2d..5f42a7f99b7 100644--- a/src/features/HomeSidebar/Body/Project/index.tsx+++ b/src/features/HomeSidebar/Body/Project/index.tsx@@ -8,6 +8,7 @@ import {AccordionTrigger,ActionIcon,cx,+ Flexbox,Text,} from '@lobehub/ui';import { ArrowRightIcon, PlusIcon } from 'lucide-react';@@ -57,12 +58,20 @@ const Project = memo<ProjectProps>(({ itemKey }) => {accordionStyles.actionBorderless,)}>- <ActionIcon- icon={ArrowRightIcon}- size="small"- title={t('list.viewAll')}- onClick={() => navigate('/projects')}- />+ <Flexbox horizontal align="center" gap={2}>+ <ActionIcon+ icon={ArrowRightIcon}+ size="small"+ title={t('list.viewAll')}+ onClick={() => navigate('/projects')}+ />+ <ActionIcon+ icon={PlusIcon}+ size="small"+ title={t('create.title')}+ onClick={() => openCreateProjectModal()}+ />+ </Flexbox></div></AccordionHeader><AccordionPanel>diff --git a/src/features/Projects/List/index.tsx b/src/features/Projects/List/index.tsxindex 7ee7800c761..3220f10231a 100644--- a/src/features/Projects/List/index.tsx+++ b/src/features/Projects/List/index.tsx@@ -1,9 +1,13 @@'use client';+import { DEFAULT_AVATAR } from '@lobechat/const';+import { agentDisplayName } from '@lobechat/types';import {+ Avatar,Center,ContextMenuTrigger,createStaticStyles,+ cssVar,Empty,Flexbox,Icon,@@ -33,6 +37,7 @@ import { useTranslation } from 'react-i18next';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import AsyncError from '@/components/AsyncError';import { PROJECT_STATUS_VISUALS, resolveProjectStatus } from '@/components/ExecutionStatus';+import AssigneeAvatar from '@/features/AgentTasks/features/AssigneeAvatar';import NavHeader from '@/features/NavHeader';import SkeletonList from '@/features/NavPanel/components/SkeletonList';import { openCreateProjectModal } from '@/features/Projects/CreateProjectModal';@@ -61,7 +66,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({`,identifier: css`flex: none;- min-width: 72px;color: ${cssVar.colorTextTertiary};`,link: css`@@ -75,6 +79,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({color: inherit;`,owner: css`+ display: flex;flex: none;width: 20px;`,@@ -120,6 +125,33 @@ const ProjectOwnerAvatar = memo<{ userId: string }>(({ userId }) => {ProjectOwnerAvatar.displayName = 'ProjectOwnerAvatar';+const ProjectCoordinatorAvatar = memo<{ project: ProjectListItem }>(({ project }) => {+ const { coordinatorAgent } = project;+ const label = coordinatorAgent ? agentDisplayName(coordinatorAgent) : undefined;++ return (+ <span className={styles.owner}>+ {coordinatorAgent && label ? (+ <Tooltip title={label}>+ <Avatar+ avatar={coordinatorAgent.avatar || DEFAULT_AVATAR}+ background={coordinatorAgent.backgroundColor || cssVar.colorBgContainer}+ shape={'circle'}+ size={20}+ variant={'outlined'}+ />+ </Tooltip>+ ) : (+ // Rows without joined meta (a cleared main agent, which resolves to LobeAI,+ // or a row inserted from a create response before the list refreshes).+ <AssigneeAvatar tooltip agentId={project.coordinatorAgentId} size={20} />+ )}+ </span>+ );+});++ProjectCoordinatorAvatar.displayName = 'ProjectCoordinatorAvatar';+const ProjectRow = memo<{ project: ProjectListItem }>(({ project }) => {const { t } = useTranslation(['project', 'common']);const [deleting, setDeleting] = useState(false);@@ -165,15 +197,18 @@ const ProjectRow = memo<{ project: ProjectListItem }>(({ project }) => {<Tooltip title={t(`acceptance.status.${status}`)}><Icon color={statusVisual.color} icon={statusVisual.icon} size={16} /></Tooltip>- <Flexbox flex={1} style={{ minWidth: 0 }}>+ <Flexbox horizontal align={'center'} flex={1} gap={8} style={{ minWidth: 0 }}><Text ellipsis weight={500}>{project.name}</Text>+ <Text className={styles.identifier} fontSize={12}>+ {project.identifier}+ </Text>+ </Flexbox>+ <Flexbox horizontal align={'center'} flex={'none'} gap={4}>+ <ProjectOwnerAvatar userId={project.userId} />+ <ProjectCoordinatorAvatar project={project} /></Flexbox>- <Text className={styles.identifier} fontSize={12}>- {project.identifier}- </Text>- <ProjectOwnerAvatar userId={project.userId} /><TextclassName={styles.updatedAt}fontSize={12}diff --git a/src/store/project/projection.ts b/src/store/project/projection.tsindex 36cae1b0edb..59ad46618ff 100644--- a/src/store/project/projection.ts+++ b/src/store/project/projection.ts@@ -3,7 +3,13 @@ import type { projectService } from '@/services/project';type ProjectListResponse = Awaited<ReturnType<typeof projectService.listAll>>;type ProjectDetailResponse = Awaited<ReturnType<typeof projectService.detail>>;-export type ProjectListItem = ProjectListResponse['data'][number];+type ProjectListRow = ProjectListResponse['data'][number];+/**+ * List and detail replicas share one project entity, and only `project.list`+ * joins the main agent's display meta, so rows from create / detail lack it.+ */+export type ProjectListItem = Omit<ProjectListRow, 'coordinatorAgent'> &+ Partial<Pick<ProjectListRow, 'coordinatorAgent'>>;export type ProjectDetail = ProjectDetailResponse['data'];/** The sidebar / list page reads every project, so the list has one entry. */