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.
fix(frontend): open a fresh expert page from the sidebar + and reveal the group chevron on hover (#15102)
Abhimanyu Yadavfd04c4c257e4
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-threads.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-threads.test.tsxindex b1989fae5c..9bad373572 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-threads.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-threads.test.tsx@@ -26,6 +26,7 @@ import { useRecipientPicker } from "../components/EmptySession/useRecipientPickeimport { ChatMessagesContainer } from "../components/ChatMessagesContainer/ChatMessagesContainer";import { ChatSidebar } from "../components/ChatSidebar/ChatSidebar";import { useChatSession } from "../useChatSession";+import { getNewChatHref } from "@/components/layout/AppSidebar/components/RecentChats/helpers";import { useCopilotUIStore } from "../store";import { groupSessionsByExpert } from "../useSessionList";@@ -243,6 +244,24 @@ function KeyedSessionHost() {return <ExpertSessionHarness key={`chat-host-${sessionId ?? "new"}`} />;}+/** Stands in for the sidebar's "New chat with Maria" link: following it+ * lands on the href `getNewChatHref` builds, which replaces the whole query+ * string, so whatever session was open is dropped along the way. Each key+ * goes through its own setter, like the real New Chat handler. */+function SidebarNewChatLink() {+ const [, setExpertId] = useQueryState("expertId", parseAsString);+ const [, setSessionId] = useQueryState("sessionId", parseAsString);+ const [, setNewThread] = useQueryState("new", parseAsString);+ function follow() {+ const href = getNewChatHref("expert-maria", new Set(["expert-maria"]));+ const target = new URL(href ?? "/home", "http://localhost");+ void setSessionId(target.searchParams.get("sessionId"));+ void setExpertId(target.searchParams.get("expertId"));+ void setNewThread(target.searchParams.get("new"));+ }+ return <button onClick={follow}>New chat with Maria</button>;+}+const NuqsWrapper = withNuqsTestingAdapter({searchParams: "?expertId=expert-maria",hasMemory: true,@@ -445,6 +464,136 @@ describe("useChatSession — expert sessions", () => {expect(listedSessions).toBe(0);});+ it("opens a fresh expert page from the sidebar + while that expert's chat is running, and again after", async () => {+ const runningSession = makeSession({+ id: "s-maria-running",+ title: "Maria thread",+ expert_id: "expert-maria",+ is_processing: true,+ });+ let adoptionLookups = 0;+ const writesToRunningSession: string[] = [];+ server.use(+ http.get("*/api/chat/sessions", ({ request }) => {+ if (new URL(request.url).searchParams.get("expert_id")) {+ adoptionLookups += 1;+ }+ return HttpResponse.json({ sessions: [runningSession], total: 1 });+ }),+ http.get("*/api/chat/sessions/s-maria-running", () =>+ HttpResponse.json({+ ...runningSession,+ user_id: "user-1",+ messages: [],+ active_stream: { started_at: "2026-01-01T00:00:00Z" },+ }),+ ),+ http.all("*/api/chat/sessions/s-maria-running/*", ({ request }) => {+ writesToRunningSession.push(`${request.method} ${request.url}`);+ return HttpResponse.json({});+ }),+ http.post("*/api/chat/sessions", () =>+ HttpResponse.json({+ id: "s-maria-fresh",+ created_at: "2026-01-03T00:00:00Z",+ user_id: "user-1",+ expert_id: "expert-maria",+ }),+ ),+ http.get("*/api/chat/sessions/s-maria-fresh", () =>+ HttpResponse.json({+ id: "s-maria-fresh",+ created_at: "2026-01-03T00:00:00Z",+ updated_at: "2026-01-03T00:00:00Z",+ user_id: "user-1",+ expert_id: "expert-maria",+ messages: [],+ }),+ ),+ http.get("*/api/chat/transports", () =>+ HttpResponse.json({+ transports: [+ {+ auth_provider: "platform",+ credential_id: null,+ label: "AutoGPT Platform",+ available: true,+ default: true,+ },+ ],+ }),+ ),+ );+ // The adapter only commits the URL after nuqs's throttle, so the test+ // reads it back here rather than trusting the optimistic hook state.+ let committedUrl = new URLSearchParams(+ "?expertId=expert-maria&sessionId=s-maria-running",+ );+ const RunningWrapper = withNuqsTestingAdapter({+ searchParams: committedUrl.toString(),+ hasMemory: true,+ onUrlUpdate: (event) => {+ committedUrl = event.searchParams;+ },+ });++ render(+ <CredentialsProvidersContext.Provider value={{}}>+ <RunningWrapper>+ <SidebarNewChatLink />+ <KeyedSessionHost />+ </RunningWrapper>+ </CredentialsProvidersContext.Provider>,+ );+ expect(screen.getByTestId("session-id").textContent).toBe(+ "s-maria-running",+ );++ // Clicks happen inside waitFor, as in the New Chat test below: the+ // testing adapter resets nuqs's update queue whenever it re-renders, so+ // a click that lands while a previous URL commit is still rendering can+ // be dropped. Re-clicking is idempotent (sets the same values).+ async function followSidebarLink() {+ await waitFor(() => {+ fireEvent.click(+ screen.getByRole("button", { name: "New chat with Maria" }),+ );+ expect(screen.getByTestId("session-id").textContent).toBe("none");+ });+ await waitFor(() => expect(committedUrl.get("sessionId")).toBeNull());+ }++ // First click: the running thread is dropped for the fresh page, and the+ // remount must not go looking for Maria's latest thread to re-adopt.+ await followSidebarLink();+ expect(screen.getByTestId("expert-id").textContent).toBe("expert-maria");+ expect(committedUrl.get("expertId")).toBe("expert-maria");+ expect(committedUrl.get("new")).toBe("1");+ await new Promise((resolve) => setTimeout(resolve, 50));+ expect(screen.getByTestId("session-id").textContent).toBe("none");+ expect(adoptionLookups).toBe(0);++ // Start a task on the fresh page, then hit + again: the second fresh page+ // must not bounce into either Maria thread.+ fireEvent.click(screen.getByRole("button", { name: "create" }));+ await waitFor(() => {+ expect(screen.getByTestId("session-id").textContent).toBe(+ "s-maria-fresh",+ );+ });+ await waitFor(() =>+ expect(committedUrl.get("sessionId")).toBe("s-maria-fresh"),+ );+ await followSidebarLink();+ await new Promise((resolve) => setTimeout(resolve, 50));+ expect(screen.getByTestId("session-id").textContent).toBe("none");+ expect(screen.getByTestId("expert-id").textContent).toBe("expert-maria");+ expect(committedUrl.get("new")).toBe("1");+ expect(adoptionLookups).toBe(0);+ // Leaving the running chat is navigation only: nothing was sent to it.+ expect(writesToRunningSession).toEqual([]);+ });+it("stays on a fresh session after New Chat instead of re-adopting the expert's thread", async () => {server.use(http.get("*/api/chat/sessions", ({ request }) => {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.tsxindex 59359b0e6d..13044699f7 100644--- 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.tsx@@ -292,7 +292,11 @@ describe("RecentChats — expert groups", () => {const mariaLink = await screen.findByRole("link", {name: "New chat with Maria",});- expect(mariaLink.getAttribute("href")).toBe("/home?expertId=expert-maria");+ // `new=1` is what stops the page adopting Maria's latest thread, which+ // is exactly the chat the + is meant to step out of.+ expect(mariaLink.getAttribute("href")).toBe(+ "/home?expertId=expert-maria&new=1",+ );expect(screen.getByRole("link", { name: "New chat with Otto" })@@ -303,4 +307,68 @@ describe("RecentChats — expert groups", () => {screen.queryByRole("link", { name: "New chat with Max" }),).toBeNull();});++ it("keeps the + link fresh even when the expert's latest chat is running", async () => {+ const sessions = [+ makeSession({+ id: "maria-running",+ title: "maria running chat",+ expertId: mariaExpert.id,+ isProcessing: true,+ }),+ ...makeSessions(1, mariaExpert.id),+ ];+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertIdentitiesMockHandler([mariaExpert]),+ );+ renderRecentChats();++ const mariaLink = await screen.findByRole("link", {+ name: "New chat with Maria",+ });+ const href = new URL(mariaLink.getAttribute("href") ?? "", "http://x");+ expect(href.pathname).toBe("/home");+ expect(href.searchParams.get("expertId")).toBe(mariaExpert.id);+ expect(href.searchParams.get("new")).toBe("1");+ expect(href.searchParams.has("sessionId")).toBe(false);+ });++ it("hides the group chevron at rest on desktop and reveals it on hover or focus", async () => {+ const sessions = [...makeSessions(1), ...makeSessions(1, mariaExpert.id)];+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ getListExpertIdentitiesMockHandler([mariaExpert]),+ );+ renderRecentChats();++ const header = await screen.findByRole("button", { name: "Maria chats" });+ const chevron = [...header.querySelectorAll("svg")].at(-1);+ expect(chevron).toBeDefined();+ const classes = chevron!.classList;+ // Hidden at rest, but only above the touch breakpoint: a phone has no+ // hover state to reveal it with.+ expect(classes.contains("md:opacity-0")).toBe(true);+ expect(classes.contains("group-hover/expert-header:opacity-100")).toBe(+ true,+ );+ expect(+ classes.contains("group-focus-within/expert-header:opacity-100"),+ ).toBe(true);+ // Hidden via opacity, so the slot stays reserved and the open/closed+ // rotation still applies: no layout shift on hover.+ expect(classes.contains("size-5")).toBe(true);+ expect(+ classes.contains("group-data-[state=open]/expert-group:rotate-180"),+ ).toBe(true);+ expect(classes.contains("hidden")).toBe(false);++ // The Otto group has no reveal-on-hover + link of its own to lean on, so+ // its chevron must carry the same treatment.+ const ottoChevron = [...groupHeader("Otto").querySelectorAll("svg")].at(-1);+ expect(ottoChevron?.classList.contains("md:opacity-0")).toBe(true);+ expect(+ ottoChevron?.classList.contains("group-hover/expert-header:opacity-100"),+ ).toBe(true);+ });});diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.tsindex 93e4d108ef..a8e59eded0 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts@@ -1,6 +1,10 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { getDateGroupLabel, groupSessionsByDate } from "../helpers";+import {+ getDateGroupLabel,+ getNewChatHref,+ groupSessionsByDate,+} from "../helpers";// Pin "now" so the day-relative labels are deterministic.const NOW = new Date("2026-06-30T12:00:00Z");@@ -109,3 +113,27 @@ describe("groupSessionsByDate", () => {expect(groups[0].label).toBe("20. Juni");});});++describe("getNewChatHref", () => {+ const active = new Set(["expert-maria", "expert/slash"]);++ it("sends the Otto group to the plain home page", () => {+ expect(getNewChatHref(null, active)).toBe("/home");+ });++ it("addresses an active expert and asks for a fresh thread", () => {+ expect(getNewChatHref("expert-maria", active)).toBe(+ "/home?expertId=expert-maria&new=1",+ );+ });++ it("encodes the expert id", () => {+ expect(getNewChatHref("expert/slash", active)).toBe(+ "/home?expertId=expert%2Fslash&new=1",+ );+ });++ it("gives fired experts no link at all", () => {+ expect(getNewChatHref("expert-max", active)).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.tsxindex b9189af4d6..90aa8d88a0 100644--- 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.tsx@@ -101,10 +101,14 @@ export function ExpertChatGroup({className={cn("ml-auto shrink-0", CHEVRON_SIZE_CLASS)}/>)}+ {/* Hidden at rest on desktop like the new-chat link, and revealed+ by the same header hover / focus-within so keyboard users see+ it the moment the trigger takes focus. Opacity keeps its slot,+ so nothing shifts. On touch widths it stays visible. */}<Iconicon={ArrowDown01Icon}className={cn(- "ease-[cubic-bezier(0.33,1,0.68,1)] shrink-0 text-zinc-400 transition-transform duration-200 group-data-[state=open]/expert-group:rotate-180 motion-reduce:transition-none",+ "ease-[cubic-bezier(0.33,1,0.68,1)] shrink-0 text-zinc-400 transition-[opacity,transform] duration-200 group-focus-within/expert-header:opacity-100 group-hover/expert-header:opacity-100 group-data-[state=open]/expert-group:rotate-180 motion-reduce:transition-none md:opacity-0",CHEVRON_SIZE_CLASS,!newChatHref && "ml-auto",)}diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.tsindex 2fbcb85f1e..e18643e66e 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts@@ -59,12 +59,14 @@ export function groupSessionsByDate<T extends { updated_at: string }>(}// Fired experts can't be addressed, so their group gets no new-chat entry:-// the deep link would only fall back to Otto.+// the deep link would only fall back to Otto. `new=1` keeps the page on the+// fresh new-task state: without it `useChatSession` adopts the expert's+// latest thread, which is exactly the chat the user is trying to leave.export function getNewChatHref(expertId: string | null,activeExpertIds: ReadonlySet<string>,) {if (!expertId) return "/home";if (!activeExpertIds.has(expertId)) return null;- return `/home?expertId=${encodeURIComponent(expertId)}`;+ return `/home?expertId=${encodeURIComponent(expertId)}&new=1`;}