🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(assistant): fill the screen on mobile instead of a floating window (LFE-14977) (#16000)
Nikita Kabardinfc1cd9cb4708
diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsxindex e3cdd68326..88848aa433 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx@@ -36,6 +36,8 @@ function InAppAgentWindowStoryShell({<InAppAgentWindowShellfloatingPanelHandle={floatingPanelHandle}isExpanded={isExpanded}+ onClose={() => undefined}+ openpanelRef={panelRef}>{children}diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.tsxindex ae3c05dcfe..af3f10b967 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.tsx@@ -19,6 +19,7 @@ import {SendHorizontal,Square,Trash2,+ X,} from "lucide-react";import { Button } from "@/src/components/ui/button";import {@@ -35,7 +36,7 @@ import {TooltipTrigger,} from "@/src/components/ui/tooltip";import { cn } from "@/src/utils/tailwind";-import { useIsMobile } from "@/src/hooks/use-mobile";+import { useIsHandheld } from "@/src/hooks/use-mobile";import { formatApproximateDuration } from "@/src/utils/dates";import {InAppAgentMessage,@@ -377,7 +378,6 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {hasMoreConversations,isAssistantTurnInProgress,isHeaderDragHandleEnabled = false,- isExpanded,isConversationInteractionDisabled,isLoadingMoreConversations,isSelectedConversationHydrating,@@ -403,8 +403,14 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {screenContextDescription,);const capture = usePostHogClientCapture();- // No auto-focus on mobile — it springs the keyboard and buries the panel.- const isMobile = useIsMobile();+ // A phone renders the assistant full-screen (see InAppAgentWindowShell), so+ // it drops the window chrome and never auto-focuses — that springs the+ // keyboard over the conversation.+ const isHandheld = useIsHandheld();+ // Full-screen has no expanded variant. Narrowing a desktop window into+ // handheld while expanded would otherwise keep the desktop-expanded layout+ // with no toggle left to undo it; the prop survives, so widening restores it.+ const isExpanded = props.isExpanded && !isHandheld;const isRateLimited = isInAppAgentRateLimited(error);const isComposerDisabled = isConversationInteractionDisabled;const isSubmitDisabled =@@ -509,13 +515,13 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {((previousIsInputDisabledRef.current && !isComposerDisabled) ||(previousIsAssistantTurnInProgressRef.current &&!isAssistantTurnInProgress)) &&- !isMobile;+ !isHandheld;if (input && shouldRefocusInput) {input.focus();}},- [isAssistantTurnInProgress, isComposerDisabled, isMobile],+ [isAssistantTurnInProgress, isComposerDisabled, isHandheld],);useEffect(() => {@@ -532,7 +538,11 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {return (<sectionaria-label="Assistant"- className="bg-background flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden rounded-xl border shadow/5"+ className={cn(+ "bg-background flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden rounded-xl border shadow/5",+ // Full-bleed on mobile: the drawer owns the edge, so drop the window chrome.+ isHandheld && "rounded-none border-0 shadow-none",+ )}><headerdata-in-app-agent-window-drag-handle={@@ -665,29 +675,32 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {) : null}</DropdownMenuContent></DropdownMenu>- <Tooltip delayDuration={100} disableHoverableContent>- <TooltipTrigger asChild>- <Button- type="button"- variant="ghost"- size="icon"- className="size-6"- aria-label={isExpanded ? "Collapse window" : "Expand window"}- onClick={() => {- onExpandedChange(!isExpanded);- }}- >- {isExpanded ? (- <Minimize2 className="size-3" />- ) : (- <Maximize2 className="size-3" />- )}- </Button>- </TooltipTrigger>- <TooltipContent>- {isExpanded ? "Collapse window" : "Expand window"}- </TooltipContent>- </Tooltip>+ {/* Mobile is always full-screen, so there is nothing to expand. */}+ {!isHandheld ? (+ <Tooltip delayDuration={100} disableHoverableContent>+ <TooltipTrigger asChild>+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="size-6"+ aria-label={isExpanded ? "Collapse window" : "Expand window"}+ onClick={() => {+ onExpandedChange(!isExpanded);+ }}+ >+ {isExpanded ? (+ <Minimize2 className="size-3" />+ ) : (+ <Maximize2 className="size-3" />+ )}+ </Button>+ </TooltipTrigger>+ <TooltipContent>+ {isExpanded ? "Collapse window" : "Expand window"}+ </TooltipContent>+ </Tooltip>+ ) : null}{props.showCloseButton !== false ? (<Tooltip delayDuration={100} disableHoverableContent><TooltipTrigger asChild>@@ -696,13 +709,23 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {variant="ghost"size="icon"className="size-6"- aria-label="Minimize assistant"+ // Full-screen has nothing to minimize into, and with no+ // drag-to-dismiss this is the only way out.+ aria-label={+ isHandheld ? "Close assistant" : "Minimize assistant"+ }onClick={props.onClose}>- <Minus className="size-3" />+ {isHandheld ? (+ <X className="size-3" />+ ) : (+ <Minus className="size-3" />+ )}</Button></TooltipTrigger>- <TooltipContent>Minimize assistant</TooltipContent>+ <TooltipContent>+ {isHandheld ? "Close assistant" : "Minimize assistant"}+ </TooltipContent></Tooltip>) : null}</div>@@ -710,7 +733,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {<div className="relative flex min-h-0 flex-1 flex-col"><divref={viewportRef}- className="min-h-0 flex-1 overflow-y-auto"+ // `overscroll-contain`: the conversation is the only scroller, so its+ // rubber-band must not chain out to whatever is behind it.+ className="min-h-0 flex-1 overflow-y-auto overscroll-contain"onScroll={(event) => {const viewport = event.currentTarget;const distanceFromBottom =@@ -973,7 +998,7 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {}}><textarea- autoFocus={!isExpanded && !isMobile}+ autoFocus={!isExpanded && !isHandheld}ref={setInputRef}value={input}onChange={(event) => {diff --git a/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsxindex d5da1b5b50..c507108291 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx@@ -61,17 +61,20 @@ describe("InAppAgentWindowHost", () => {HTMLElement.prototype.setPointerCapture = vi.fn();HTMLElement.prototype.releasePointerCapture = vi.fn();- // The `agent` overlay layer container normally declared in _document.+ // The overlay layer containers normally declared in _document.const overlayRoot = document.createElement("div");overlayRoot.setAttribute("data-overlay-root", "");- const agentLayer = document.createElement("div");- agentLayer.setAttribute("data-layer", "agent");- overlayRoot.appendChild(agentLayer);+ for (const layer of ["panel", "agent"]) {+ const layerNode = document.createElement("div");+ layerNode.setAttribute("data-layer", layer);+ overlayRoot.appendChild(layerNode);+ }document.body.appendChild(overlayRoot);});afterEach(() => {document.querySelector("[data-overlay-root]")?.remove();+ vi.unstubAllGlobals();});it("keeps geometry while open and resets it on close/reopen", () => {@@ -127,4 +130,36 @@ describe("InAppAgentWindowHost", () => {"88px",);});++ it("renders a full-screen drawer instead of the movable panel on a handheld", () => {+ // A landscape phone: too wide for the `md` width clause, so only the+ // coarse-pointer clause can match. Pins that the shell asks the handheld+ // predicate, not the width-only one that sent a rotated phone back to the+ // floating window.+ vi.stubGlobal(+ "matchMedia",+ vi.fn((query: string) => ({+ matches: query.includes("pointer: coarse"),+ addEventListener: vi.fn(),+ removeEventListener: vi.fn(),+ })),+ );+ mocks.open = true;++ const { rerender } = render(<InAppAgentWindowHost />);++ // No drag/resize on touch, and the drawer is the modal that scroll-locks+ // the page behind it.+ expect(screen.queryByTestId("movable-resizable-panel")).toBeNull();+ expect(document.querySelector("#in-app-agent-drawer")).not.toBeNull();++ // Closing drives the drawer's own `open` prop rather than unmounting the+ // tree from under it, so Vaul can animate itself out.+ mocks.open = false;+ rerender(<InAppAgentWindowHost />);+ expect(document.querySelector("#in-app-agent-drawer")).toHaveAttribute(+ "data-state",+ "closed",+ );+ });});diff --git a/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx b/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsxindex d6c4e2a594..53173e1a32 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx@@ -113,7 +113,9 @@ export function InAppAgentWindowHost() {floatingPanelHandle.initializeGeometry();}, [floatingPanelHandle, isExpanded, open]);- if (!canUseAgent || !open) {+ // Only `canUseAgent` gates the tree: the shell owns the `open` guard so the+ // handheld drawer stays mounted and can animate itself closed.+ if (!canUseAgent) {return null;}@@ -138,6 +140,10 @@ export function InAppAgentWindowHost() {<InAppAgentWindowShellfloatingPanelHandle={floatingPanelHandle}isExpanded={isExpanded}+ onClose={() => {+ setOpen(false);+ }}+ open={open}panelRef={panelRef}>{({ isHeaderDragHandleEnabled }) => (diff --git a/web/src/features/in-app-agent/components/InAppAgentWindowShell.tsx b/web/src/features/in-app-agent/components/InAppAgentWindowShell.tsxindex 4b493b81fb..8b3ce1fc6b 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindowShell.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindowShell.tsx@@ -8,6 +8,8 @@ import {type MovableResizablePanelSize,useMovableResizablePanelControl,} from "@/src/components/movable-resizable-panel";+import { Drawer, DrawerContent, DrawerTitle } from "@/src/components/ui/drawer";+import { useIsHandheld } from "@/src/hooks/use-mobile";const IN_APP_AGENT_WINDOW_SHELL_BOUNDS_PADDING_PX = 8;const IN_APP_AGENT_WINDOW_SHELL_DEFAULT_WIDTH_PX = 448;@@ -62,6 +64,8 @@ type InAppAgentWindowShellProps = {children: (props: { isHeaderDragHandleEnabled: boolean }) => ReactNode;floatingPanelHandle: MovableResizablePanelHandle;isExpanded: boolean;+ onClose: () => void;+ open: boolean;panelRef: RefObject<HTMLDivElement | null>;};@@ -69,9 +73,59 @@ export function InAppAgentWindowShell({children,floatingPanelHandle,isExpanded,+ onClose,+ open,panelRef,}: InAppAgentWindowShellProps) {- if (!isExpanded && !floatingPanelHandle.geometry) {+ const isHandheld = useIsHandheld();++ // A phone has one presentation: the whole screen below the banner. A real+ // (Vaul) modal drawer — the same treatment as the support / migration+ // drawers — so the page behind is scroll-locked and there is exactly one+ // scroller, and never the movable panel (drag/resize is meaningless on+ // touch). Stays mounted while closed so Vaul can animate itself out.+ //+ // `dismissible={false}`: this is a page, not a sheet, so it never follows a+ // drag and you cannot pull it down to close — the header's close button is+ // the way out. That also makes Vaul swallow every close routed through+ // `onOpenChange`, so Escape is re-armed explicitly below (it still matters in+ // a narrow desktop window, which is handheld too).+ if (isHandheld) {+ return (+ <Drawer+ open={open}+ onOpenChange={(nextOpen) => {+ if (!nextOpen) {+ onClose();+ }+ }}+ dismissible={false}+ forceDirection="bottom"+ >+ <DrawerContent+ id="in-app-agent-drawer"+ size="full"+ // `h-auto` at every breakpoint so top/bottom anchoring owns the+ // geometry: the drawer's default height variant is `h-1/3 md:h-full`,+ // and the `md:` half survives tailwind-merge — a landscape phone is+ // both handheld and wider than `md`, and `top` + `bottom` + `height`+ // over-constrains the box, dropping `bottom` and pushing the composer+ // off-screen by the banner offset. Vaul still overrides the height to+ // dodge the on-screen keyboard.+ className="top-banner-offset inset-x-0 bottom-0 h-auto rounded-none border-0 md:h-auto"+ onEscapeKeyDown={(event) => {+ event.preventDefault();+ onClose();+ }}+ >+ <DrawerTitle className="sr-only">Assistant</DrawerTitle>+ {children({ isHeaderDragHandleEnabled: false })}+ </DrawerContent>+ </Drawer>+ );+ }++ if (!open || (!isExpanded && !floatingPanelHandle.geometry)) {return null;}diff --git a/web/src/hooks/use-mobile.tsx b/web/src/hooks/use-mobile.tsxindex 48a9fd6ddf..e7ae82cdda 100644--- a/web/src/hooks/use-mobile.tsx+++ b/web/src/hooks/use-mobile.tsx@@ -3,21 +3,31 @@ import { useSyncExternalStore } from "react";// tailwind default breakpoint, corresponds to `md`, https://tailwindcss.com/docs/responsive-designconst MOBILE_BREAKPOINT = 768;const MOBILE_QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`;--function subscribe(onStoreChange: () => void) {- if (typeof window === "undefined" || !window.matchMedia) return () => {};- const mql = window.matchMedia(MOBILE_QUERY);- mql.addEventListener("change", onStoreChange);- return () => mql.removeEventListener("change", onStoreChange);-}+// Phone-sized in EITHER orientation: narrow, or a touch screen that is short+// (an iPhone in landscape is wider than `md` but only ~390px tall).+const HANDHELD_QUERY = `${MOBILE_QUERY}, (pointer: coarse) and (max-height: ${MOBILE_BREAKPOINT - 1}px)`;// Guarded so it's safe where `matchMedia` is absent (jsdom tests, SSR, old-// browsers) — treat those as non-mobile.-function getSnapshot() {- if (typeof window === "undefined" || !window.matchMedia) return false;- return window.matchMedia(MOBILE_QUERY).matches;+// browsers) — treat those as non-mobile. Module-level so the store functions+// stay referentially stable across renders.+function createMediaQueryStore(query: string) {+ return {+ subscribe(onStoreChange: () => void) {+ if (typeof window === "undefined" || !window.matchMedia) return () => {};+ const mql = window.matchMedia(query);+ mql.addEventListener("change", onStoreChange);+ return () => mql.removeEventListener("change", onStoreChange);+ },+ getSnapshot() {+ if (typeof window === "undefined" || !window.matchMedia) return false;+ return window.matchMedia(query).matches;+ },+ };}+const mobileStore = createMediaQueryStore(MOBILE_QUERY);+const handheldStore = createMediaQueryStore(HANDHELD_QUERY);+/*** True when the viewport is below the `md` breakpoint. Reads the media query* synchronously, so it is correct on the first client render (unlike an@@ -25,5 +35,23 @@ function getSnapshot() {* SSR has no viewport, so it assumes desktop and hydration corrects it.*/export function useIsMobile() {- return useSyncExternalStore(subscribe, getSnapshot, () => false);+ return useSyncExternalStore(+ mobileStore.subscribe,+ mobileStore.getSnapshot,+ () => false,+ );+}++/**+ * True on phone-sized screens in either orientation — `useIsMobile()` plus a+ * short touch screen, which is a phone held sideways. Use it for presentation+ * that a rotation must not undo (full-screen panels, suppressing drag/resize+ * affordances that need a precise pointer).+ */+export function useIsHandheld() {+ return useSyncExternalStore(+ handheldStore.subscribe,+ handheldStore.getSnapshot,+ () => false,+ );}