AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(frontend): collapsible expert chat groups in sidebar with per-group load more (#13795)
Ubbe3aa7bccf11a2
diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/RecentChats.tsx b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/RecentChats.tsxindex 4e980aa4d8..c94051d273 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/RecentChats.tsx+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/RecentChats.tsx@@ -2,18 +2,12 @@import { DeleteChatDialog } from "@/app/(platform)/copilot/components/DeleteChatDialog/DeleteChatDialog";import { ShareChatDialog } from "@/app/(platform)/copilot/sharing/ShareChatDialog";-import {- Avatar,- AvatarFallback,- AvatarImage,-} from "@/components/atoms/Avatar/Avatar";-import { getExpertAccent } from "@/app/(platform)/marketplace/components/ExpertsSection/helpers";import { groupSessionsByExpert } from "@/app/(platform)/copilot/useSessionList";import { useExpertMap } from "@/app/(platform)/copilot/useExpertMap";import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";import { SidebarMenu } from "@/components/ui/sidebar";import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";-import { cn } from "@/lib/utils";+import { ExpertChatGroup } from "./components/ExpertChatGroup/ExpertChatGroup";import { RecentChatItem } from "./components/RecentChatItem/RecentChatItem";import { groupSessionsByDate } from "./helpers";import { useRecentChats } from "./useRecentChats";@@ -82,74 +76,37 @@ export function RecentChats() {);}- const groups = isExpertsEnabled- ? groupSessionsByExpert(sessions).map((group) => ({- key: group.expertId ?? "autopilot",- label: group.expertId- ? (expertsById.get(group.expertId)?.name ?? "Expert")- : "Autopilot",- avatarUrl: group.expertId- ? (expertsById.get(group.expertId)?.avatarUrl ?? null)- : null,- role: group.expertId- ? (expertsById.get(group.expertId)?.role ?? null)- : null,- showAvatar: true,- sessions: group.sessions,- }))- : groupSessionsByDate(sessions).map((group) => ({- key: group.label,- label: group.label,- avatarUrl: null,- role: null,- showAvatar: false,- sessions: group.sessions,- }));-return (<><div className="mt-2 flex flex-col gap-4">- {groups.map((group) => (- <div key={group.key}>- <div- className={cn(- "flex items-center px-2 pb-1.5",- group.showAvatar- ? "gap-2 text-[13px] font-medium text-zinc-900"- : "gap-1.5 text-xs font-medium text-zinc-500",- )}- >- {group.showAvatar && (- <Avatar className="h-5 w-5">- {group.avatarUrl ? (- <AvatarImage src={group.avatarUrl} alt={group.label} />- ) : null}- <AvatarFallback className="text-[9px]">- {group.label}- </AvatarFallback>- </Avatar>- )}- <span className="truncate">{group.label}</span>- {group.role ? (- <span- className={cn(- "shrink-0 rounded-full px-1.5 py-px text-[10px] font-medium",- getExpertAccent(group.role).pill,- )}- >- {group.role}- </span>- ) : null}- </div>- {group.showAvatar ? (- <div className="ml-[17px] border-l border-zinc-200 pl-1.5">+ {isExpertsEnabled+ ? groupSessionsByExpert(sessions).map((group) => {+ const expert = group.expertId+ ? expertsById.get(group.expertId)+ : null;+ return (+ // Keyed by expert id so each group's collapse/reveal state+ // survives the session list's periodic refetch.+ <ExpertChatGroup+ key={group.expertId ?? "autopilot"}+ label={+ group.expertId ? (expert?.name ?? "Expert") : "Autopilot"+ }+ avatarUrl={expert?.avatarUrl ?? null}+ role={expert?.role ?? null}+ sessions={group.sessions}+ renderItem={renderItem}+ />+ );+ })+ : groupSessionsByDate(sessions).map((group) => (+ <div key={group.label}>+ <div className="flex items-center gap-1.5 px-2 pb-1.5 text-xs font-medium text-zinc-500">+ <span className="truncate">{group.label}</span>+ </div><SidebarMenu>{group.sessions.map(renderItem)}</SidebarMenu></div>- ) : (- <SidebarMenu>{group.sessions.map(renderItem)}</SidebarMenu>- )}- </div>- ))}+ ))}</div>{hasMore && (diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/expert-groups.test.tsx b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/expert-groups.test.tsxnew file mode 100644index 0000000000..b46d07a1b9--- /dev/null+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/expert-groups.test.tsx@@ -0,0 +1,213 @@+import { getGetV2ListSessionsMockHandler200 } from "@/app/api/__generated__/endpoints/chat/chat.msw";+import { getListExpertsMockHandler } from "@/app/api/__generated__/endpoints/experts/experts.msw";+import type { Expert } from "@/app/api/__generated__/models/expert";+import { SESSION_LIST_REFETCH_INTERVAL_MS } from "@/app/(platform)/copilot/useSessionList";+import { SidebarProvider } from "@/components/ui/sidebar";+import { server } from "@/mocks/mock-server";+import {+ fireEvent,+ render,+ screen,+ waitFor,+} from "@/tests/integrations/test-utils";+import { http, HttpResponse } from "msw";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import { RecentChats } from "../RecentChats";++vi.mock("@/services/feature-flags/use-get-flag", async (importOriginal) => {+ const actual =+ await importOriginal<+ typeof import("@/services/feature-flags/use-get-flag")+ >();+ return {+ ...actual,+ useGetFlag: (flag: string) => flag === "hire-experts",+ };+});++const mariaExpert: Expert = {+ id: "expert-maria",+ name: "Maria",+ avatar_url: "https://example.com/maria.png",+ role: "Marketing Strategist",+ bio: null,+ skills: [],+ tagline: "Grows your brand while you sleep",+ identity: "You are Maria, a senior marketing strategist.",+ is_template: false,+ source_template_id: "template-maria",+ is_archived: false,+ workflows: [],+};++function makeSession(args: { id: string; title: string; expertId?: string }) {+ return {+ id: args.id,+ title: args.title,+ is_processing: false,+ created_at: "2026-06-30T10:00:00",+ updated_at: "2026-06-30T10:00:00",+ expert_id: args.expertId ?? null,+ };+}++function makeSessions(count: number, expertId?: string) {+ const prefix = expertId ?? "autopilot";+ return Array.from({ length: count }, (_, index) =>+ makeSession({+ id: `${prefix}-${index + 1}`,+ title: `${prefix} chat ${index + 1}`,+ expertId,+ }),+ );+}++function renderRecentChats() {+ return render(+ <SidebarProvider>+ <RecentChats />+ </SidebarProvider>,+ );+}++beforeEach(() => {+ vi.useFakeTimers({ shouldAdvanceTime: true });+});++afterEach(() => {+ vi.useRealTimers();+ server.resetHandlers();+});++describe("RecentChats — expert groups", () => {+ it("collapses and expands a group when its header is clicked", async () => {+ const sessions = makeSessions(2);+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertsMockHandler([]),+ );+ renderRecentChats();++ expect(await screen.findByText("autopilot chat 1")).toBeDefined();++ const header = screen.getByRole("button", { name: "Autopilot chats" });+ fireEvent.click(header);+ expect(screen.queryByText("autopilot chat 1")).toBeNull();++ fireEvent.click(header);+ expect(await screen.findByText("autopilot chat 1")).toBeDefined();+ });++ it("shows only the first 6 chats and reveals more via Load more", async () => {+ const sessions = makeSessions(14);+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertsMockHandler([]),+ );+ renderRecentChats();++ expect(await screen.findByText("autopilot chat 6")).toBeDefined();+ expect(screen.queryByText("autopilot chat 7")).toBeNull();++ const loadMore = () =>+ screen.getByRole("button", { name: "Load more Autopilot chats" });++ fireEvent.click(loadMore());+ expect(await screen.findByText("autopilot chat 12")).toBeDefined();+ expect(screen.queryByText("autopilot chat 13")).toBeNull();++ fireEvent.click(loadMore());+ expect(await screen.findByText("autopilot chat 14")).toBeDefined();+ expect(+ screen.queryByRole("button", { name: "Load more Autopilot chats" }),+ ).toBeNull();+ });++ it("groups expert chats under the expert's name with independent previews", async () => {+ const sessions = [...makeSessions(8), ...makeSessions(7, mariaExpert.id)];+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertsMockHandler([mariaExpert]),+ );+ renderRecentChats();++ expect(+ await screen.findByRole("button", { name: "Maria chats" }),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: "Autopilot chats" }),+ ).toBeDefined();++ expect(screen.getByText("expert-maria chat 6")).toBeDefined();+ expect(screen.queryByText("expert-maria chat 7")).toBeNull();+ expect(screen.queryByText("autopilot chat 7")).toBeNull();++ fireEvent.click(+ screen.getByRole("button", { name: "Load more Maria chats" }),+ );+ expect(await screen.findByText("expert-maria chat 7")).toBeDefined();+ expect(screen.queryByText("autopilot chat 7")).toBeNull();+ });++ it("falls back to a generic Expert label when the expert is unknown", async () => {+ const sessions = makeSessions(2, "expert-ghost");+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertsMockHandler([]),+ );+ renderRecentChats();++ expect(+ await screen.findByRole("button", { name: "Expert chats" }),+ ).toBeDefined();+ expect(screen.getByText("expert-ghost chat 1")).toBeDefined();+ });++ it("keeps the group-level and list-level Load more buttons distinct", async () => {+ const sessions = makeSessions(8);+ server.use(+ getGetV2ListSessionsMockHandler200({+ sessions,+ total: sessions.length + 10,+ }),+ getListExpertsMockHandler([]),+ );+ renderRecentChats();++ expect(+ await screen.findByRole("button", { name: "Load more Autopilot chats" }),+ ).toBeDefined();+ expect(screen.getByRole("button", { name: "Load more" })).toBeDefined();+ });++ it("keeps collapse and reveal state across session list refetches", async () => {+ const sessions = [...makeSessions(8), ...makeSessions(2, mariaExpert.id)];+ let listCalls = 0;+ server.use(+ http.get("*/api/chat/sessions", () => {+ listCalls++;+ return HttpResponse.json({ sessions, total: sessions.length });+ }),+ getListExpertsMockHandler([mariaExpert]),+ );+ renderRecentChats();++ fireEvent.click(+ await screen.findByRole("button", {+ name: "Load more Autopilot chats",+ }),+ );+ expect(await screen.findByText("autopilot chat 7")).toBeDefined();++ fireEvent.click(await screen.findByRole("button", { name: "Maria chats" }));+ expect(screen.queryByText("expert-maria chat 1")).toBeNull();++ const callsBefore = listCalls;+ vi.advanceTimersByTime(SESSION_LIST_REFETCH_INTERVAL_MS);+ await waitFor(() => expect(listCalls).toBeGreaterThan(callsBefore));++ expect(screen.getByText("autopilot chat 7")).toBeDefined();+ expect(screen.queryByText("expert-maria chat 1")).toBeNull();+ });+});diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/components/ExpertChatGroup/ExpertChatGroup.tsx b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/components/ExpertChatGroup/ExpertChatGroup.tsxnew file mode 100644index 0000000000..52e946ac72--- /dev/null+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/components/ExpertChatGroup/ExpertChatGroup.tsx@@ -0,0 +1,89 @@+"use client";++import { getExpertAccent } from "@/app/(platform)/marketplace/components/ExpertsSection/helpers";+import type { SessionSummaryResponse } from "@/app/api/__generated__/models/sessionSummaryResponse";+import {+ Avatar,+ AvatarFallback,+ AvatarImage,+} from "@/components/atoms/Avatar/Avatar";+import { Icon } from "@/components/atoms/Icon/Icon";+import {+ Collapsible,+ CollapsibleContent,+ CollapsibleTrigger,+} from "@/components/ui/collapsible";+import { SidebarMenu } from "@/components/ui/sidebar";+import { cn } from "@/lib/utils";+import { ArrowDown01Icon } from "@hugeicons/core-free-icons";+import { ReactNode, useState } from "react";++export const EXPERT_GROUP_PREVIEW_COUNT = 6;++interface Props {+ label: string;+ avatarUrl: string | null;+ role: string | null;+ sessions: SessionSummaryResponse[];+ renderItem: (session: SessionSummaryResponse) => ReactNode;+}++export function ExpertChatGroup({+ label,+ avatarUrl,+ role,+ sessions,+ renderItem,+}: Props) {+ const [visibleCount, setVisibleCount] = useState(EXPERT_GROUP_PREVIEW_COUNT);+ const visibleSessions = sessions.slice(0, visibleCount);+ const hasHiddenSessions = sessions.length > visibleSessions.length;++ return (+ <Collapsible defaultOpen className="group/expert-group">+ <CollapsibleTrigger+ aria-label={`${label} chats`}+ className="mb-1 flex w-full items-center gap-2 rounded-md px-2 py-0.5 text-left text-[13px] font-medium text-zinc-900 hover:bg-zinc-100"+ >+ <Avatar className="h-5 w-5">+ {avatarUrl ? <AvatarImage src={avatarUrl} alt={label} /> : null}+ <AvatarFallback className="text-[9px]">+ {label.charAt(0).toUpperCase()}+ </AvatarFallback>+ </Avatar>+ <span className="truncate">{label}</span>+ {role ? (+ <span+ className={cn(+ "shrink-0 rounded-full px-1.5 py-px text-[10px] font-medium",+ getExpertAccent(role).pill,+ )}+ >+ {role}+ </span>+ ) : null}+ <Icon+ icon={ArrowDown01Icon}+ className="ease-[cubic-bezier(0.33,1,0.68,1)] ml-auto size-4 shrink-0 text-zinc-400 transition-transform duration-200 group-data-[state=open]/expert-group:rotate-180 motion-reduce:transition-none"+ />+ </CollapsibleTrigger>+ <CollapsibleContent className="overflow-hidden data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down motion-reduce:animate-none">+ <div className="ml-[17px] border-l border-zinc-200 pl-1.5">+ <SidebarMenu>{visibleSessions.map(renderItem)}</SidebarMenu>+ {hasHiddenSessions && (+ <button+ type="button"+ aria-label={`Load more ${label} chats`}+ onClick={() =>+ setVisibleCount((count) => count + EXPERT_GROUP_PREVIEW_COUNT)+ }+ className="mt-0.5 w-full rounded-md px-2 py-1 text-left text-xs font-medium text-zinc-500 hover:bg-zinc-100 hover:text-zinc-800"+ >+ Load more+ </button>+ )}+ </div>+ </CollapsibleContent>+ </Collapsible>+ );+}