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): mobile AutoPilot parity + builder warning (#13232)
Krzysztof Czerwinski9a00e05749da
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/MobileWarning.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/MobileWarning.tsxnew file mode 100644index 0000000000..ca5a5f06d9--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/MobileWarning.tsx@@ -0,0 +1,42 @@+"use client";++import { Button } from "@/components/atoms/Button/Button";+import { Text } from "@/components/atoms/Text/Text";+import { Dialog } from "@/components/molecules/Dialog/Dialog";+import { DeviceMobileIcon } from "@phosphor-icons/react";+import { useMobileWarning } from "./useMobileWarning";++export function MobileWarning() {+ const { isOpen, dismiss, suppress } = useMobileWarning();++ return (+ <Dialog+ title="Builder works best on desktop"+ controlled={{+ isOpen,+ set: (next) => {+ if (!next) dismiss();+ },+ }}+ >+ <Dialog.Content>+ <div className="flex flex-col items-center gap-4 px-1 py-2 text-center">+ <DeviceMobileIcon className="h-10 w-10 text-amber-600" />+ <Text variant="body" className="text-zinc-700">+ The agent builder relies on canvas interactions that don't work+ well on this screen size. For the best experience, switch to a+ desktop browser.+ </Text>+ <div className="mt-2 flex w-full flex-col gap-2 sm:flex-row sm:justify-center">+ <Button variant="secondary" size="small" onClick={dismiss}>+ Continue anyway+ </Button>+ <Button variant="ghost" size="small" onClick={suppress}>+ Don't show again+ </Button>+ </div>+ </div>+ </Dialog.Content>+ </Dialog>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/__tests__/MobileWarning.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/__tests__/MobileWarning.test.tsxnew file mode 100644index 0000000000..1cc6d643df--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/__tests__/MobileWarning.test.tsx@@ -0,0 +1,124 @@+import {+ fireEvent,+ render,+ screen,+ waitFor,+} from "@/tests/integrations/test-utils";+import {+ afterAll,+ afterEach,+ beforeAll,+ beforeEach,+ describe,+ expect,+ it,+ vi,+} from "vitest";+import { MobileWarning } from "../MobileWarning";++const mockUseBreakpoint = vi.fn();++vi.mock("@/lib/hooks/useBreakpoint", async (importOriginal) => {+ const actual =+ await importOriginal<typeof import("@/lib/hooks/useBreakpoint")>();+ return {+ ...actual,+ useBreakpoint: () => mockUseBreakpoint(),+ };+});++describe("MobileWarning", () => {+ const originalSetPointerCapture = HTMLElement.prototype.setPointerCapture;+ const originalReleasePointerCapture =+ HTMLElement.prototype.releasePointerCapture;+ const originalHasPointerCapture = HTMLElement.prototype.hasPointerCapture;++ beforeAll(() => {+ HTMLElement.prototype.setPointerCapture = vi.fn();+ HTMLElement.prototype.releasePointerCapture = vi.fn();+ HTMLElement.prototype.hasPointerCapture = vi.fn(() => false);+ });++ afterAll(() => {+ HTMLElement.prototype.setPointerCapture = originalSetPointerCapture;+ HTMLElement.prototype.releasePointerCapture = originalReleasePointerCapture;+ HTMLElement.prototype.hasPointerCapture = originalHasPointerCapture;+ });++ beforeEach(() => {+ mockUseBreakpoint.mockReturnValue("sm");+ window.localStorage.clear();+ });++ afterEach(() => {+ mockUseBreakpoint.mockReset();+ window.localStorage.clear();+ });++ it("renders the warning on mobile breakpoints", async () => {+ render(<MobileWarning />);+ expect(+ await screen.findByText(/builder works best on desktop/i),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: /continue anyway/i }),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: /don.t show again/i }),+ ).toBeDefined();+ });++ it("does not render the warning on large breakpoints", () => {+ mockUseBreakpoint.mockReturnValue("lg");+ render(<MobileWarning />);+ expect(screen.queryByText(/builder works best on desktop/i)).toBeNull();+ expect(+ screen.queryByRole("button", { name: /continue anyway/i }),+ ).toBeNull();+ });++ it.each(["base", "sm", "md"] as const)(+ "renders the warning at the %s breakpoint (mobile boundary coverage)",+ async (bp) => {+ mockUseBreakpoint.mockReturnValue(bp);+ render(<MobileWarning />);+ expect(+ await screen.findByText(/builder works best on desktop/i),+ ).toBeDefined();+ },+ );++ it("dismisses for the session when the user clicks 'Continue anyway'", async () => {+ render(<MobileWarning />);+ const dialog = await screen.findByRole("dialog");+ fireEvent.click(+ await screen.findByRole("button", { name: /continue anyway/i }),+ );+ await waitFor(() => {+ expect(dialog.getAttribute("data-state")).toBe("closed");+ });+ expect(+ window.localStorage.getItem("builder-mobile-warning-suppressed"),+ ).toBeNull();+ });++ it("persists the suppressed state when the user clicks 'Don't show again'", async () => {+ render(<MobileWarning />);+ const dialog = await screen.findByRole("dialog");+ fireEvent.click(+ await screen.findByRole("button", { name: /don.t show again/i }),+ );+ await waitFor(() => {+ expect(dialog.getAttribute("data-state")).toBe("closed");+ });+ expect(+ window.localStorage.getItem("builder-mobile-warning-suppressed"),+ ).toBe("1");+ });++ it("does not render when previously suppressed in this browser", () => {+ window.localStorage.setItem("builder-mobile-warning-suppressed", "1");+ render(<MobileWarning />);+ expect(screen.queryByText(/builder works best on desktop/i)).toBeNull();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/useMobileWarning.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/useMobileWarning.tsnew file mode 100644index 0000000000..2923250df9--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/MobileWarning/useMobileWarning.ts@@ -0,0 +1,37 @@+import { useBreakpoint } from "@/lib/hooks/useBreakpoint";+import { Key, storage } from "@/services/storage/local-storage";+import { useEffect, useState } from "react";++export function useMobileWarning() {+ const breakpoint = useBreakpoint();+ const [isDismissed, setIsDismissed] = useState(false);+ // Default true so the warning never flashes open before the mount effect has+ // had a chance to read the localStorage flag.+ const [isSuppressed, setIsSuppressed] = useState(true);+ const [isReady, setIsReady] = useState(false);++ useEffect(() => {+ setIsSuppressed(storage.get(Key.BUILDER_MOBILE_WARNING_SUPPRESSED) === "1");+ // Defer the open-flip past the first paint so the Dialog's internal+ // breakpoint hook has settled — otherwise it briefly mounts the desktop+ // modal variant on mobile before switching to the drawer.+ const id = requestAnimationFrame(() => setIsReady(true));+ return () => cancelAnimationFrame(id);+ }, []);++ const isMobile =+ breakpoint === "base" || breakpoint === "sm" || breakpoint === "md";++ const isOpen = isReady && isMobile && !isDismissed && !isSuppressed;++ function dismiss() {+ setIsDismissed(true);+ }++ function suppress() {+ storage.set(Key.BUILDER_MOBILE_WARNING_SUPPRESSED, "1");+ setIsSuppressed(true);+ }++ return { isOpen, dismiss, suppress };+}diff --git a/autogpt_platform/frontend/src/app/(platform)/build/page.tsx b/autogpt_platform/frontend/src/app/(platform)/build/page.tsxindex a8ed8a5e8e..9bc36c6b39 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/page.tsx@@ -1,6 +1,7 @@"use client";import { ReactFlowProvider } from "@xyflow/react";import { Flow } from "./components/FlowEditor/Flow/Flow";+import { MobileWarning } from "./components/MobileWarning/MobileWarning";export default function BuilderPage() {return (@@ -8,6 +9,7 @@ export default function BuilderPage() {<ReactFlowProvider><Flow /></ReactFlowProvider>+ <MobileWarning /></div>);}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsxindex 30abc59000..e0a10cb220 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx@@ -59,7 +59,10 @@ export function NotificationToggle() {)}</Button></PopoverTrigger>- <PopoverContent align="start" className="w-56 p-3">+ {/* z-[80]: must layer above the AutoPilot mobile drawer+ (overlay z-[60], content z-[70] in MobileDrawer.tsx) so the+ popover doesn't render under the drawer's blur. */}+ <PopoverContent align="start" className="z-[80] w-56 p-3"><div className="flex flex-col gap-3"><label className="flex items-center justify-between"><span className="text-sm text-zinc-700">Notifications</span>diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsxindex 6ed858f663..0eaa201cd5 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx@@ -9,8 +9,6 @@ import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";import {MagnifyingGlass,PlusIcon,- SpeakerHigh,- SpeakerSlash,SpinnerGapIcon,X,} from "@phosphor-icons/react";@@ -25,7 +23,9 @@ import { useSessionList } from "../../useSessionList";import { ChatSearchResults } from "../ChatSearchModal/ChatSearchResults";import { useChatSearch } from "../ChatSearchModal/useChatSearch";import { ChatSessionBlock } from "../ChatSessionBlock/ChatSessionBlock";+import { NotificationToggle } from "../ChatSidebar/components/NotificationToggle/NotificationToggle";import { DeleteChatDialog } from "../DeleteChatDialog/DeleteChatDialog";+import { UsagePopover } from "../UsageLimits/UsagePopover/UsagePopover";export function MobileDrawer() {const { isUserLoading, isLoggedIn } = useSupabase();@@ -37,8 +37,6 @@ export function MobileDrawer() {const {completedSessionIDs,clearCompletedSession,- isSoundEnabled,- toggleSound,isDrawerOpen,setDrawerOpen,isSearchOpen,@@ -107,21 +105,8 @@ export function MobileDrawer() {Your chats</Drawer.Title><div className="flex items-center gap-1">- <button- onClick={toggleSound}- className="rounded p-1.5 text-zinc-400 transition-colors hover:text-zinc-600"- aria-label={- isSoundEnabled- ? "Disable notification sound"- : "Enable notification sound"- }- >- {isSoundEnabled ? (- <SpeakerHigh className="h-4 w-4" />- ) : (- <SpeakerSlash className="h-4 w-4" />- )}- </button>+ <UsagePopover />+ <NotificationToggle />{isChatSearchEnabled ? (<ShadcnButtontype="button"@@ -145,6 +130,7 @@ export function MobileDrawer() {size="icon"aria-label="Close sessions"onClick={closeDrawer}+ className="ml-3"><X width="1rem" height="1rem" /></Button>diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/__tests__/MobileDrawerControls.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/__tests__/MobileDrawerControls.test.tsxnew file mode 100644index 0000000000..1c7a4bb99e--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/__tests__/MobileDrawerControls.test.tsx@@ -0,0 +1,115 @@+import { getGetV2ListSessionsMockHandler200 } from "@/app/api/__generated__/endpoints/chat/chat.msw";+import { server } from "@/mocks/mock-server";+import { render, screen } from "@/tests/integrations/test-utils";+import { http, HttpResponse } from "msw";+import {+ afterAll,+ beforeAll,+ beforeEach,+ describe,+ expect,+ it,+ vi,+} from "vitest";+import { useCopilotUIStore } from "../../../store";+import { MobileDrawer } from "../MobileDrawer";++vi.mock("@/lib/supabase/hooks/useSupabase", () => ({+ useSupabase: () => ({ isUserLoading: false, isLoggedIn: true }),+}));++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: () => true,+ };+});++vi.mock("@/components/molecules/Popover/Popover", () => {+ function Popover({ children }: { children: React.ReactNode }) {+ return <div>{children}</div>;+ }+ function PopoverTrigger({ children }: { children: React.ReactNode }) {+ return <div>{children}</div>;+ }+ function PopoverContent({ children }: { children: React.ReactNode }) {+ return <div>{children}</div>;+ }+ return { Popover, PopoverTrigger, PopoverContent };+});++vi.mock("../../UsageLimits/StorageBar", () => ({+ StorageBar: () => null,+}));++function mockUsageResponse() {+ const future = new Date(Date.now() + 3600 * 1000).toISOString();+ server.use(+ http.get("*/api/chat/usage", () =>+ HttpResponse.json({+ daily: { percent_used: 10, resets_at: future },+ weekly: { percent_used: 20, resets_at: future },+ tier: "BASIC",+ }),+ ),+ );+}++describe("MobileDrawer controls", () => {+ const originalSetPointerCapture = HTMLElement.prototype.setPointerCapture;+ const originalReleasePointerCapture =+ HTMLElement.prototype.releasePointerCapture;+ const originalHasPointerCapture = HTMLElement.prototype.hasPointerCapture;++ beforeAll(() => {+ HTMLElement.prototype.setPointerCapture = vi.fn();+ HTMLElement.prototype.releasePointerCapture = vi.fn();+ HTMLElement.prototype.hasPointerCapture = vi.fn(() => false);+ });++ afterAll(() => {+ HTMLElement.prototype.setPointerCapture = originalSetPointerCapture;+ HTMLElement.prototype.releasePointerCapture = originalReleasePointerCapture;+ HTMLElement.prototype.hasPointerCapture = originalHasPointerCapture;+ });++ beforeEach(() => {+ useCopilotUIStore.setState({+ isDrawerOpen: true,+ isSearchOpen: false,+ completedSessionIDs: new Set<string>(),+ isNotificationsEnabled: false,+ isSoundEnabled: true,+ });+ server.use(getGetV2ListSessionsMockHandler200({ sessions: [], total: 0 }));+ mockUsageResponse();+ });++ it("surfaces the usage and notification controls inside the drawer header", async () => {+ render(<MobileDrawer />);++ expect(+ await screen.findByRole("button", { name: /usage limits/i }),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: /notification settings/i }),+ ).toBeDefined();+ });++ it("does not render the legacy standalone sound toggle (folded into NotificationToggle)", async () => {+ render(<MobileDrawer />);++ // Wait for header to render so we don't false-pass before mount.+ await screen.findByRole("button", { name: /usage limits/i });++ expect(+ screen.queryByRole("button", {+ name: /enable notification sound|disable notification sound/i,+ }),+ ).toBeNull();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsxindex ff9f87cffa..6f2002d651 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx@@ -30,7 +30,10 @@ export function UsagePopover() {<ChartBarIcon className="!size-5" weight="light" /></Button></PopoverTrigger>- <PopoverContent align="start" className="w-72 p-4">+ {/* z-[80]: must layer above the AutoPilot mobile drawer+ (overlay z-[60], content z-[70] in MobileDrawer.tsx) so the+ popover doesn't render under the drawer's blur. */}+ <PopoverContent align="start" className="z-[80] w-72 p-4"><div className="flex flex-col gap-4"><div className="flex items-center gap-2"><Text variant="body-medium" className="text-neutral-800">diff --git a/autogpt_platform/frontend/src/services/storage/local-storage.ts b/autogpt_platform/frontend/src/services/storage/local-storage.tsindex 5d732bd9d2..b949f0e5d9 100644--- a/autogpt_platform/frontend/src/services/storage/local-storage.ts+++ b/autogpt_platform/frontend/src/services/storage/local-storage.ts@@ -23,6 +23,7 @@ export enum Key {COPILOT_DRY_RUN = "copilot-dry-run",TOP_UP_MODAL_LAST_SHOWN = "top-up-modal-last-shown",LOW_CREDIT_BANNER_DISMISSED = "low-credit-banner-dismissed",+ BUILDER_MOBILE_WARNING_SUPPRESSED = "builder-mobile-warning-suppressed",}function get(key: Key) {