🪢 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
feat(agent): Move main assistant entrypoint to from side-nav to top-nav (#15160)
Lysander Kiesel44a3fe1d4757
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsxindex 2e76b5ee08..95a3915b8b 100644--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx@@ -24,6 +24,7 @@ import type { NavigationItem } from "@/src/components/layouts/utilities/routes";import type { RouteGroup } from "@/src/components/layouts/routes";import dynamic from "next/dynamic";import { ControlledFeaturePreviewModal } from "@/src/features/feature-previews/components/ControlledFeaturePreviewModal";+import { InAppAgentWindowHost } from "@/src/ee/features/in-app-agent/components/InAppAgentWindowHost";const CommandMenu = dynamic(() =>@@ -190,6 +191,10 @@ export function AuthenticatedLayout({<Toaster visibleToasts={1} /></Layer><CommandMenu mainNavigation={navigation.navigation} />+ {/* Assistant window host lives here (not in PageHeader with+ its launcher button) so the open window and its geometry+ survive route changes. */}+ <InAppAgentWindowHost /></SidebarInset></div>{hasFeaturePreviews ? (diff --git a/web/src/components/layouts/page-header.tsx b/web/src/components/layouts/page-header.tsxindex 0cfacdf6e9..94db5302ed 100644--- a/web/src/components/layouts/page-header.tsx+++ b/web/src/components/layouts/page-header.tsx@@ -2,6 +2,7 @@ import { EnvLabel } from "@/src/components/EnvLabel";import { ItemBadge, type LangfuseItemType } from "@/src/components/ItemBadge";import BreadcrumbComponent from "@/src/components/layouts/breadcrumb";import { PageHeaderControlsSlotTarget } from "@/src/components/layouts/page-header-controls-slot";+import { InAppAiAgentButton } from "@/src/components/nav/in-app-ai-agent-button";import DocPopup from "@/src/components/layouts/doc-popup";import { SidebarTrigger } from "@/src/components/ui/sidebar";import {@@ -121,6 +122,7 @@ const PageHeader = ({Empty on pages that don't use it. */}<div className="flex flex-wrap items-center gap-2"><PageHeaderControlsSlotTarget />+ <InAppAiAgentButton /></div></div></div>diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsxindex f07818ffdd..5c7139cec5 100644--- a/web/src/components/layouts/routes.tsx+++ b/web/src/components/layouts/routes.tsx@@ -26,7 +26,6 @@ import { type Entitlement } from "@/src/features/entitlements/constants/entitlemimport { type Session } from "next-auth";import { type OrganizationScope } from "@/src/features/rbac/constants/organizationAccessRights";import { SupportButton } from "@/src/components/nav/support-button";-import { InAppAiAgentButton } from "@/src/components/nav/in-app-ai-agent-button";import { BookACallButton } from "@/src/components/nav/book-a-call-button";import { V4SidebarToggle } from "@/src/features/events/components/V4SidebarToggle";import { SidebarMenuButton } from "@/src/components/ui/sidebar";@@ -246,14 +245,6 @@ export const ROUTES: Route[] = [pathname: "",menuNode: <BookACallButton />,},- {- title: "Assistant",- section: RouteSection.Secondary,- pathname: "",- show: ({ organization, projectId, isLangfuseCloud }) =>- isLangfuseCloud && organization !== undefined && projectId !== undefined,- menuNode: <InAppAiAgentButton />,- },{title: "Support",icon: LifeBuoy,diff --git a/web/src/components/nav/in-app-ai-agent-button.clienttest.tsx b/web/src/components/nav/in-app-ai-agent-button.clienttest.tsxnew file mode 100644index 0000000000..8d01acfdb2--- /dev/null+++ b/web/src/components/nav/in-app-ai-agent-button.clienttest.tsx@@ -0,0 +1,80 @@+import { fireEvent, render } from "@testing-library/react";++import { InAppAiAgentButton } from "./in-app-ai-agent-button";++const mocks = vi.hoisted(() => ({+ open: false,+ setOpen: vi.fn(),+ openAssistant: vi.fn().mockReturnValue(true),+}));++vi.mock(+ "@/src/ee/features/in-app-agent/components/InAppAiAgentProvider",+ () => ({+ useCanUseInAppAgent: () => true,+ useInAppAiAgent: () => ({+ open: mocks.open,+ setOpen: mocks.setOpen,+ openAssistant: mocks.openAssistant,+ }),+ }),+);++describe("InAppAiAgentButton", () => {+ beforeEach(() => {+ mocks.open = false;+ mocks.setOpen.mockReset();+ mocks.openAssistant.mockReset().mockReturnValue(true);+ });++ it("toggles the assistant with Cmd/Ctrl+I and leaves other shortcuts alone", () => {+ const { rerender } = render(<InAppAiAgentButton />);++ for (const modifiers of [+ {},+ { metaKey: true, altKey: true },+ { ctrlKey: true, shiftKey: true },+ { metaKey: true, repeat: true },+ ]) {+ const nonShortcut = new KeyboardEvent("keydown", {+ key: "i",+ bubbles: true,+ cancelable: true,+ ...modifiers,+ });+ fireEvent(document, nonShortcut);++ expect(nonShortcut.defaultPrevented).toBe(false);+ }++ expect(mocks.openAssistant).not.toHaveBeenCalled();+ expect(mocks.setOpen).not.toHaveBeenCalled();++ const openShortcut = new KeyboardEvent("keydown", {+ key: "i",+ bubbles: true,+ cancelable: true,+ metaKey: true,+ });+ fireEvent(document, openShortcut);++ expect(openShortcut.defaultPrevented).toBe(true);+ expect(mocks.openAssistant).toHaveBeenCalledWith("keyboard_shortcut");+ expect(mocks.setOpen).not.toHaveBeenCalled();++ mocks.open = true;+ rerender(<InAppAiAgentButton />);++ const closeShortcut = new KeyboardEvent("keydown", {+ key: "i",+ bubbles: true,+ cancelable: true,+ ctrlKey: true,+ });+ fireEvent(document, closeShortcut);++ expect(closeShortcut.defaultPrevented).toBe(true);+ expect(mocks.openAssistant).toHaveBeenCalledTimes(1);+ expect(mocks.setOpen).toHaveBeenCalledWith(false);+ });+});diff --git a/web/src/components/nav/in-app-ai-agent-button.tsx b/web/src/components/nav/in-app-ai-agent-button.tsxindex ca028f253a..c713f188bd 100644--- a/web/src/components/nav/in-app-ai-agent-button.tsx+++ b/web/src/components/nav/in-app-ai-agent-button.tsx@@ -1,225 +1,84 @@-import { useLayoutEffect, useRef, useState } from "react";+import { useCallback, useEffect } from "react";import { BotMessageSquare } from "lucide-react";import { Button } from "@/src/components/ui/button";-import { ConfirmDialog } from "@/src/components/ui/confirm-dialog";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import {- Dialog,- DialogBody,- DialogContent,- DialogFooter,- DialogHeader,- DialogTitle,-} from "@/src/components/ui/dialog";-import { DialogController } from "@/src/components/ui/dialog-controller";-import { Layer } from "@/src/components/ui/layer";-import { SidebarMenuButton } from "@/src/components/ui/sidebar";-import { ControlledInAppAgentWindow } from "@/src/ee/features/in-app-agent/components";-import {- InAppAgentWindowShell,- useInAppAgentWindowShellPanelControl,-} from "@/src/ee/features/in-app-agent/components/InAppAgentWindowShell";-import { useInAppAiAgent } from "@/src/ee/features/in-app-agent/components/InAppAiAgentProvider";-import type { InAppAgentWindowConversation } from "@/src/ee/features/in-app-agent/components/InAppAgentWindow";-import { useHasEntitlement } from "@/src/features/entitlements/hooks";-import { AIFeaturesDisabledNotice } from "@/src/features/organizations/components/AIFeaturesDisabledNotice";-import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";-import { useWatchedPromiseCallback } from "@/src/hooks/useWatchedPromiseCallback";+ useCanUseInAppAgent,+ useInAppAiAgent,+ type InAppAgentEntryPoint,+} from "@/src/ee/features/in-app-agent/components/InAppAiAgentProvider";++/** Launcher only — the assistant window itself is rendered by+ * InAppAgentWindowHost from the persistent authenticated layout, so it+ * survives the per-page remount of this button on navigation. */+export const InAppAiAgentButton = () => {+ const { open, setOpen, openAssistant } = useInAppAiAgent();+ const canUseAssistant = useCanUseInAppAgent();-function DeleteConversationDialog({- close,- conversation,- onDeleteConversation,-}: {- close: () => void;- conversation: InAppAgentWindowConversation | null;- onDeleteConversation: (conversationId: string) => Promise<void>;-}) {- const [deleteConversation, isDeletingConversation] =- useWatchedPromiseCallback(async () => {- if (!conversation) {+ const toggleAssistant = useCallback(+ (source: InAppAgentEntryPoint) => {+ if (open) {+ setOpen(false);return;}- try {- await onDeleteConversation(conversation.id);- close();- } catch {- // Error is already surfaced by the provider; keep the dialog open for retry.- }- }, [close, conversation, onDeleteConversation]);-- return (- <ConfirmDialog- open={conversation !== null}- onOpenChange={(open) => {- if (!open) {- close();- }- }}- title="Delete conversation"- description="This removes the conversation from your recent conversations. This action cannot be undone."- confirmLabel="Delete conversation"- loading={isDeletingConversation}- onConfirm={deleteConversation}- />+ openAssistant(source);+ },+ [open, openAssistant, setOpen],);-}-export const InAppAiAgentButton = () => {- const { organization } = useQueryProjectOrOrganization();- const {- deleteConversation,- isAvailable,- open,- setOpen,- isExpanded,- setIsExpanded,- } = useInAppAiAgent();- const hasInAppAgentEntitlement = useHasEntitlement("in-app-agent");- const buttonRef = useRef<HTMLButtonElement>(null);- const panelRef = useRef<HTMLDivElement>(null);- const previousPanelRectRef = useRef<DOMRect | null>(null);- const [enableDialogOpen, setEnableDialogOpen] = useState(false);-- const floatingPanelHandle = useInAppAgentWindowShellPanelControl({- anchorRef: buttonRef,- });-- useLayoutEffect(() => {- const previousRect = previousPanelRectRef.current;- const panel = panelRef.current;-- previousPanelRectRef.current = null;-- if (!previousRect || !panel) {+ useEffect(() => {+ if (!canUseAssistant) {return;}- const nextRect = panel.getBoundingClientRect();-- panel.animate(- [- {- transform: `translate(${previousRect.left - nextRect.left}px, ${previousRect.top - nextRect.top}px) scale(${nextRect.width > 0 ? previousRect.width / nextRect.width : 1}, ${nextRect.height > 0 ? previousRect.height / nextRect.height : 1})`,- },- { transform: "translate(0, 0) scale(1, 1)" },- ],- {- duration: 180,- easing: "cubic-bezier(0.2, 0, 0, 1)",- },- );- }, [isExpanded]);+ const handleKeyDown = (event: KeyboardEvent) => {+ if (+ event.repeat ||+ event.key.toLowerCase() !== "i" ||+ (!event.metaKey && !event.ctrlKey) ||+ event.altKey ||+ event.shiftKey+ ) {+ return;+ }- useLayoutEffect(() => {- if (!open || isExpanded || floatingPanelHandle.geometry) {- return;- }+ event.preventDefault();+ toggleAssistant("keyboard_shortcut");+ };- floatingPanelHandle.initializeGeometry();- }, [floatingPanelHandle, isExpanded, open]);+ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [canUseAssistant, toggleAssistant]);- if (!isAvailable || !hasInAppAgentEntitlement) {+ if (!canUseAssistant) {return null;}- const handleClick = () => {- if (organization && !organization.aiFeaturesEnabled) {- setEnableDialogOpen(true);- return;- }-- const willOpen = !open;-- if (willOpen) {- floatingPanelHandle.resetGeometry();- }-- setOpen((currentOpen) => !currentOpen);- };-return (- <>- <SidebarMenuButton- ref={buttonRef}- data-ignore-outside-interaction- isActive={open}- onClick={handleClick}- >- <BotMessageSquare className="h-4 w-4" />- Assistant- </SidebarMenuButton>- {open ? (- <DialogController<InAppAgentWindowConversation>- dialog={(close, conversation) => (- <DeleteConversationDialog- close={close}- conversation={conversation}- onDeleteConversation={deleteConversation}- />- )}- >- {(deleteConversationDialog) => (- // The assistant window lives in the `agent` overlay layer — a- // <body>-level layer container that floats above page content and- // panel surfaces, but below true modals and transient overlays by DOM- // order alone. No z-index: layer ORDER stacks it (see- // components/ui/layer.tsx). This replaces the old body portal + z-51,- // which fought the nav-user dropdown's z-60 at <body> level.- <Layer name="agent">- <InAppAgentWindowShell- floatingPanelHandle={floatingPanelHandle}- isExpanded={isExpanded}- panelRef={panelRef}- >- {({ isHeaderDragHandleEnabled }) => (- <ControlledInAppAgentWindow- isHeaderDragHandleEnabled={isHeaderDragHandleEnabled}- isExpanded={isExpanded}- onDeleteConversation={(conversation) =>- deleteConversationDialog.open(conversation)- }- onExpandedChange={(nextIsExpanded) => {- previousPanelRectRef.current =- panelRef.current?.getBoundingClientRect() ?? null;- setIsExpanded(nextIsExpanded);- }}- onClose={() => {- floatingPanelHandle.clearGeometry();- setOpen(false);- }}- />- )}- </InAppAgentWindowShell>- </Layer>- )}- </DialogController>- ) : null}- <Dialog open={enableDialogOpen} onOpenChange={setEnableDialogOpen}>- <DialogContent>- <DialogHeader>- <DialogTitle>AI features are disabled</DialogTitle>- </DialogHeader>- <DialogBody>- <AIFeaturesDisabledNotice organizationId={organization?.id}>- The assistant requires AI features to be enabled for this- organization.- </AIFeaturesDisabledNotice>- </DialogBody>- <DialogFooter>- <div className="flex justify-end">- <Button- type="button"- variant="outline"- onClick={() => setEnableDialogOpen(false)}- >- Close- </Button>- </div>- </DialogFooter>- </DialogContent>- </Dialog>- </>+ <Button+ type="button"+ variant={open ? "secondary" : "ghost"}+ size="sm"+ aria-label={open ? "Close assistant" : "Open assistant"}+ aria-pressed={open}+ data-ignore-outside-interaction+ onClick={() => toggleAssistant("top_nav")}+ className="gap-2"+ >+ <BotMessageSquare className="h-4 w-4" />+ <span className="hidden sm:inline">Assistant</span>+ <KeyboardShortcut+ className="hidden bg-transparent shadow-none md:inline-flex"+ keys={[+ typeof navigator !== "undefined" &&+ navigator.userAgent.includes("Mac")+ ? "⌘"+ : "Ctrl",+ "I",+ ]}+ />+ </Button>);};diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentDisabledDialog.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentDisabledDialog.tsxnew file mode 100644index 0000000000..2f10254c33--- /dev/null+++ b/web/src/ee/features/in-app-agent/components/InAppAgentDisabledDialog.tsx@@ -0,0 +1,49 @@+import { Button } from "@/src/components/ui/button";+import {+ Dialog,+ DialogBody,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/src/components/ui/dialog";+import { AIFeaturesDisabledNotice } from "@/src/features/organizations/components/AIFeaturesDisabledNotice";++export function InAppAgentDisabledDialog({+ open,+ onOpenChange,+ organizationId,+}: {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ organizationId?: string;+}) {+ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>AI features are disabled</DialogTitle>+ </DialogHeader>+ <DialogBody>+ <AIFeaturesDisabledNotice organizationId={organizationId}>+ The Langfuse Assistant requires AI features to be enabled for this+ organization.+ </AIFeaturesDisabledNotice>+ </DialogBody>+ <DialogFooter>+ <div className="flex justify-end">+ <Button+ type="button"+ variant="outline"+ onClick={() => {+ onOpenChange(false);+ }}+ >+ Close+ </Button>+ </div>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ );+}diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsxnew file mode 100644index 0000000000..f2f8114042--- /dev/null+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx@@ -0,0 +1,133 @@+import { fireEvent, render, screen } from "@testing-library/react";++import { InAppAgentWindowHost } from "./InAppAgentWindowHost";++const mocks = vi.hoisted(() => ({+ open: false,+ setOpen: vi.fn(),+}));++vi.mock(+ "@/src/ee/features/in-app-agent/components/InAppAiAgentProvider",+ () => ({+ useCanUseInAppAgent: () => true,+ useInAppAiAgent: () => ({+ deleteConversation: vi.fn(),+ isExpanded: false,+ open: mocks.open,+ setIsExpanded: vi.fn(),+ setOpen: mocks.setOpen,+ }),+ }),+);++vi.mock(+ "@/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow",+ () => ({+ ControlledInAppAgentWindow: () => (+ <div data-in-app-agent-window-drag-handle="true" data-testid="window" />+ ),+ }),+);++function firePointerEvent(+ element: Element,+ type: "pointerdown" | "pointermove" | "pointerup",+ init: MouseEventInit & { pointerId: number },+) {+ const event = new MouseEvent(type, {+ bubbles: true,+ cancelable: true,+ clientX: init.clientX,+ clientY: init.clientY,+ });++ Object.defineProperty(event, "pointerId", { value: init.pointerId });+ fireEvent(element, event);+}++describe("InAppAgentWindowHost", () => {+ beforeEach(() => {+ mocks.open = false;+ mocks.setOpen.mockReset();++ Object.defineProperty(window, "innerWidth", {+ configurable: true,+ writable: true,+ value: 1024,+ });+ Object.defineProperty(window, "innerHeight", {+ configurable: true,+ writable: true,+ value: 768,+ });+ HTMLElement.prototype.setPointerCapture = vi.fn();+ HTMLElement.prototype.releasePointerCapture = vi.fn();++ // The `agent` overlay layer container 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);+ document.body.appendChild(overlayRoot);+ });++ afterEach(() => {+ document.querySelector("[data-overlay-root]")?.remove();+ });++ it("keeps geometry while open and resets it on close/reopen", () => {+ const { rerender } = render(<InAppAgentWindowHost />);++ expect(screen.queryByTestId("movable-resizable-panel")).toBeNull();++ mocks.open = true;+ rerender(<InAppAgentWindowHost />);++ // Default placement: bottom-right of the 1024x768 viewport.+ const panel = screen.getByTestId("movable-resizable-panel");+ expect(panel.style.left).toBe("568px");+ expect(panel.style.top).toBe("88px");++ const dragHandle = screen.getByTestId("window");+ firePointerEvent(dragHandle, "pointerdown", {+ pointerId: 1,+ clientX: 600,+ clientY: 100,+ });+ firePointerEvent(panel, "pointermove", {+ pointerId: 1,+ clientX: 500,+ clientY: 60,+ });+ firePointerEvent(panel, "pointerup", {+ pointerId: 1,+ clientX: 500,+ clientY: 60,+ });++ expect(panel.style.left).toBe("468px");+ expect(panel.style.top).toBe("48px");++ // Re-render while still open (e.g. after a route change): the dragged+ // geometry must survive.+ rerender(<InAppAgentWindowHost />);+ expect(screen.getByTestId("movable-resizable-panel").style.left).toBe(+ "468px",+ );++ mocks.open = false;+ rerender(<InAppAgentWindowHost />);+ expect(screen.queryByTestId("movable-resizable-panel")).toBeNull();++ mocks.open = true;+ rerender(<InAppAgentWindowHost />);+ expect(screen.getByTestId("movable-resizable-panel").style.left).toBe(+ "568px",+ );+ expect(screen.getByTestId("movable-resizable-panel").style.top).toBe(+ "88px",+ );+ });+});diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.tsxnew file mode 100644index 0000000000..ae9022c297--- /dev/null+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindowHost.tsx@@ -0,0 +1,165 @@+"use client";++import { useLayoutEffect, useRef } from "react";++import { ConfirmDialog } from "@/src/components/ui/confirm-dialog";+import { DialogController } from "@/src/components/ui/dialog-controller";+import { Layer } from "@/src/components/ui/layer";+import { ControlledInAppAgentWindow } from "@/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow";+import type { InAppAgentWindowConversation } from "@/src/ee/features/in-app-agent/components/InAppAgentWindow";+import {+ InAppAgentWindowShell,+ useInAppAgentWindowShellPanelControl,+} from "@/src/ee/features/in-app-agent/components/InAppAgentWindowShell";+import {+ useCanUseInAppAgent,+ useInAppAiAgent,+} from "@/src/ee/features/in-app-agent/components/InAppAiAgentProvider";+import { useWatchedPromiseCallback } from "@/src/hooks/useWatchedPromiseCallback";++function DeleteConversationDialog({+ close,+ conversation,+ onDeleteConversation,+}: {+ close: () => void;+ conversation: InAppAgentWindowConversation | null;+ onDeleteConversation: (conversationId: string) => Promise<void>;+}) {+ const [deleteConversation, isDeletingConversation] =+ useWatchedPromiseCallback(async () => {+ if (!conversation) {+ return;+ }++ try {+ await onDeleteConversation(conversation.id);+ close();+ } catch {+ // Error is already surfaced by the provider; keep the dialog open for retry.+ }+ }, [close, conversation, onDeleteConversation]);++ return (+ <ConfirmDialog+ open={conversation !== null}+ onOpenChange={(open) => {+ if (!open) {+ close();+ }+ }}+ title="Delete conversation"+ description="This removes the conversation from your recent conversations. This action cannot be undone."+ confirmLabel="Delete conversation"+ loading={isDeletingConversation}+ onConfirm={deleteConversation}+ />+ );+}++/**+ * Hosts the floating assistant window and its drag/resize geometry. Must be+ * rendered from a scope that survives route changes (the authenticated+ * layout), NOT from per-page chrome like PageHeader — otherwise the open+ * window unmounts and its geometry resets on every navigation.+ */+export function InAppAgentWindowHost() {+ const canUseAgent = useCanUseInAppAgent();+ const { deleteConversation, open, setOpen, isExpanded, setIsExpanded } =+ useInAppAiAgent();+ const panelRef = useRef<HTMLDivElement>(null);+ const previousPanelRectRef = useRef<DOMRect | null>(null);++ const floatingPanelHandle = useInAppAgentWindowShellPanelControl();++ useLayoutEffect(() => {+ const previousRect = previousPanelRectRef.current;+ const panel = panelRef.current;++ previousPanelRectRef.current = null;++ if (!previousRect || !panel) {+ return;+ }++ const nextRect = panel.getBoundingClientRect();++ panel.animate(+ [+ {+ transform: `translate(${previousRect.left - nextRect.left}px, ${previousRect.top - nextRect.top}px) scale(${nextRect.width > 0 ? previousRect.width / nextRect.width : 1}, ${nextRect.height > 0 ? previousRect.height / nextRect.height : 1})`,+ },+ { transform: "translate(0, 0) scale(1, 1)" },+ ],+ {+ duration: 180,+ easing: "cubic-bezier(0.2, 0, 0, 1)",+ },+ );+ }, [isExpanded]);++ // Geometry follows the open state: cleared on close so every open starts+ // from the default placement, initialized on open for the floating panel.+ useLayoutEffect(() => {+ if (!open) {+ floatingPanelHandle.clearGeometry();+ return;+ }++ if (isExpanded || floatingPanelHandle.geometry) {+ return;+ }++ floatingPanelHandle.initializeGeometry();+ }, [floatingPanelHandle, isExpanded, open]);++ if (!canUseAgent || !open) {+ return null;+ }++ return (+ <DialogController<InAppAgentWindowConversation>+ dialog={(close, conversation) => (+ <DeleteConversationDialog+ close={close}+ conversation={conversation}+ onDeleteConversation={deleteConversation}+ />+ )}+ >+ {(deleteConversationDialog) => (+ // The assistant window lives in the `agent` overlay layer — a+ // <body>-level layer container that floats above page content and+ // panel surfaces, but below true modals and transient overlays by DOM+ // order alone. No z-index: layer ORDER stacks it (see+ // components/ui/layer.tsx). This replaces the old body portal + z-51,+ // which fought the nav-user dropdown's z-60 at <body> level.+ <Layer name="agent">+ <InAppAgentWindowShell+ floatingPanelHandle={floatingPanelHandle}+ isExpanded={isExpanded}+ panelRef={panelRef}+ >+ {({ isHeaderDragHandleEnabled }) => (+ <ControlledInAppAgentWindow+ isHeaderDragHandleEnabled={isHeaderDragHandleEnabled}+ isExpanded={isExpanded}+ onDeleteConversation={(conversation) => {+ deleteConversationDialog.open(conversation);+ }}+ onExpandedChange={(nextIsExpanded) => {+ previousPanelRectRef.current =+ panelRef.current?.getBoundingClientRect() ?? null;+ setIsExpanded(nextIsExpanded);+ }}+ onClose={() => {+ setOpen(false);+ }}+ />+ )}+ </InAppAgentWindowShell>+ </Layer>+ )}+ </DialogController>+ );+}diff --git a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsxindex bb4a2de467..e9cfc52d20 100644--- a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -34,6 +34,8 @@ import {import type { InAppAgentError } from "@/src/ee/features/in-app-agent/components/utils/utils";import { useHasEntitlement } from "@/src/features/entitlements/hooks";import { showErrorToast } from "@/src/features/notifications/showErrorToast";+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";+import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";import { api } from "@/src/utils/api";import {createInAppAgentQuickActionAttributionContext,@@ -51,6 +53,7 @@ import {type InAppAiAgentMessage,} from "@/src/ee/features/in-app-agent/components/utils/utils";import { evaluateSetStateAction } from "@/src/utils/evaluate-set-state-action";+import { InAppAgentDisabledDialog } from "@/src/ee/features/in-app-agent/components/InAppAgentDisabledDialog";const SELECTED_CONVERSATION_STORAGE_KEY_PREFIX ="langfuse:in-app-ai-agent-selected-conversation";@@ -60,6 +63,8 @@ const SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE ="Sandbox-enabled conversations become read-only after 8 hours. Start a new conversation to continue.";const EMPTY_MESSAGES: AgUiMessage[] = [];+export type InAppAgentEntryPoint = "top_nav" | "keyboard_shortcut";+const MastraSuspendEventSchema = z.object({type: z.literal("mastra_suspend"),toolCallId: z.string().min(1),@@ -81,6 +86,7 @@ const NOOP_CONTEXT: InAppAiAgentContextType = {isAvailable: false,open: false,setOpen: () => undefined,+ openAssistant: () => false,isExpanded: false,setIsExpanded: () => undefined,isRunning: false,@@ -126,6 +132,10 @@ type InAppAiAgentContextType = {isAvailable: boolean;open: boolean;setOpen: Dispatch<SetStateAction<boolean>>;+ /** Open the assistant from an entrypoint. Owns the AI-features gate: shows+ * the disabled dialog and returns false when the organization has AI+ * features turned off. */+ openAssistant: (source: InAppAgentEntryPoint) => boolean;isExpanded: boolean;setIsExpanded: Dispatch<SetStateAction<boolean>>;isRunning: boolean;@@ -226,6 +236,8 @@ function InAppAiAgentProviderInner({const utils = api.useUtils();const capture = usePostHogClientCapture();const session = useSession();+ const { organization } = useQueryProjectOrOrganization();+ const [enableDialogOpen, setEnableDialogOpen] = useState(false);const [_selectedConversationId, setSelectedConversationId] =useSessionStorage<string | null>(`${SELECTED_CONVERSATION_STORAGE_KEY_PREFIX}:${projectId}`,@@ -940,6 +952,21 @@ function InAppAiAgentProviderInner({[open, setOpen],);+ const openAssistant = useCallback(+ (source: InAppAgentEntryPoint) => {+ capture("in_app_agent:entry_point_click", { source });++ if (organization && !organization.aiFeaturesEnabled) {+ setEnableDialogOpen(true);+ return false;+ }++ setAgentOpen(true);+ return true;+ },+ [capture, organization, setAgentOpen],+ );+const resumeToolApproval = useCallback(async (approvalId: string, approved: boolean) => {if (selectedConversationIsWriteLocked) {@@ -1065,6 +1092,7 @@ function InAppAiAgentProviderInner({isAvailable: true,open,setOpen: setAgentOpen,+ openAssistant,isExpanded,setIsExpanded,isRunning,@@ -1105,6 +1133,7 @@ function InAppAiAgentProviderInner({loadMoreConversations,messagesWithUiState,open,+ openAssistant,pendingToolApprovals,rejectToolCall,setAgentOpen,@@ -1119,6 +1148,11 @@ function InAppAiAgentProviderInner({return (<InAppAiAgentContext.Provider value={value}>{children}+ <InAppAgentDisabledDialog+ open={enableDialogOpen}+ onOpenChange={setEnableDialogOpen}+ organizationId={organization?.id}+ /></InAppAiAgentContext.Provider>);}@@ -1245,3 +1279,19 @@ export function useInAppAiAgent() {}return ctx;}++/** Whether the current user/context may use the in-app assistant at all.+ * Shared gate for the launcher button and the window host. */+export function useCanUseInAppAgent() {+ const { isAvailable } = useInAppAiAgent();+ const hasInAppAgentEntitlement = useHasEntitlement("in-app-agent");+ const { isLangfuseCloud } = useLangfuseCloudRegion();+ const { organization } = useQueryProjectOrOrganization();++ return (+ isAvailable &&+ hasInAppAgentEntitlement &&+ isLangfuseCloud &&+ Boolean(organization)+ );+}diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex c5f406d2f3..de57a1b20c 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -279,7 +279,12 @@ export const events = {"message_sent","community_hours_click",], // also used on landing page for consistency- in_app_agent: ["new_chat_started", "new_chat_turn", "quick_action_started"],+ in_app_agent: [+ "entry_point_click",+ "new_chat_started",+ "new_chat_turn",+ "quick_action_started",+ ],cmd_k_menu: ["opened", "search_entered", "navigated"],spend_alert: ["created", "updated", "deleted"],sidebar: ["book_a_call_clicked", "v4_beta_toggled"],