🪢 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(trace): mobile tabbed trace view — Tree/Timeline/Graph/Info (LFE-11067) (#15408)
Nikita Kabardin2ef672535d0c
diff --git a/web/src/components/trace/Trace.tsx b/web/src/components/trace/Trace.tsxindex fc85ad98fb..8fcf8f71a8 100644--- a/web/src/components/trace/Trace.tsx+++ b/web/src/components/trace/Trace.tsx@@ -14,7 +14,8 @@ import { TraceLayoutDesktop } from "./components/_layout/TraceLayoutDesktop";import { TracePanelNavigation } from "./components/_layout/TracePanelNavigation";import { TracePanelDetail } from "./components/_layout/TracePanelDetail";import { TracePanelNavigationLayoutDesktop } from "./components/_layout/TracePanelNavigationLayoutDesktop";-import { TracePanelNavigationLayoutMobile } from "./components/_layout/TracePanelNavigationLayoutMobile";+import { TraceTree } from "./components/TraceTree";+import { TraceTimeline } from "./components/TraceTimeline";import { useIsMobile } from "@/src/hooks/use-mobile";import { useTraceComments } from "./api/useTraceComments";import { useViewPreferences } from "./contexts/ViewPreferencesContext";@@ -147,25 +148,22 @@ function DesktopTraceContent({* MobileTraceContent - Mobile layout composition** Purpose:- * - Composes mobile-specific layout structure- * - Vertical accordion-style panels- * - Navigation panel (top, collapsible) + Detail panel (bottom)+ * - Composes the mobile tab layout: Tree · Timeline · Graph · Info.+ * - Tree/Timeline/Graph are full-height navigators; selecting an observation in+ * any of them jumps to the Info tab (see TraceLayoutMobile for the wiring).+ * - Renders the navigators directly (not via TracePanelNavigation): the+ * tree/timeline choice is a tab here, not the desktop `?view` toggle. Search+ * has no mobile entry point yet — its input lives in the desktop-only+ * navigation header — so no TraceSearchList is wired on mobile (follow-up).*/function MobileTraceContent({ shouldShowGraph }: { shouldShowGraph: boolean }) {return (- <div className="h-full w-full">- <TraceLayoutMobile>- <TraceLayoutMobile.NavigationPanel>- <TracePanelNavigationLayoutMobile- secondaryContent={shouldShowGraph ? <TraceGraphView /> : undefined}- >- <TracePanelNavigation />- </TracePanelNavigationLayoutMobile>- </TraceLayoutMobile.NavigationPanel>- <TraceLayoutMobile.DetailPanel>- <TracePanelDetail />- </TraceLayoutMobile.DetailPanel>- </TraceLayoutMobile>- </div>+ <TraceLayoutMobile+ showGraph={shouldShowGraph}+ tree={<TraceTree />}+ timeline={<TraceTimeline />}+ graph={shouldShowGraph ? <TraceGraphView /> : null}+ info={<TracePanelDetail />}+ />);}diff --git a/web/src/components/trace/components/TraceGraphView/TraceGraphView.tsx b/web/src/components/trace/components/TraceGraphView/TraceGraphView.tsxindex a99325fa83..29a275fb81 100644--- a/web/src/components/trace/components/TraceGraphView/TraceGraphView.tsx+++ b/web/src/components/trace/components/TraceGraphView/TraceGraphView.tsx@@ -13,6 +13,7 @@ import { useActiveObservationIds } from "../../contexts/PlayheadContext";import { useViewPreferences } from "../../contexts/ViewPreferencesContext";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { useTraceAnalyticsDimensions } from "../../hooks/useTraceAnalyticsDimensions";+import { useMobileLayoutContextOptional } from "../_layout/TraceLayoutMobile";export function TraceGraphView() {const { agentGraphData, isLoading } = useTraceGraphData();@@ -20,6 +21,11 @@ export function TraceGraphView() {const { graphViewMode, setGraphViewMode } = useViewPreferences();const capture = usePostHogClientCapture();const analyticsDimensions = useTraceAnalyticsDimensions();+ // Optional (null on desktop): jump to the Info tab when a canvas click selects+ // an observation. The graph writes `?observation=` directly, so the tab effect+ // already covers a genuine change; this also handles cycling a repeated node+ // back to the same id, where the URL param wouldn't change.+ const mobileLayout = useMobileLayoutContextOptional();// Analytics live here (not in the feature component) so the feature module// stays free of trace-view context dependencies.const handleObservationSelect = useCallback(() => {@@ -28,7 +34,8 @@ export function TraceGraphView() {graphViewMode,...analyticsDimensions,});- }, [capture, graphViewMode, analyticsDimensions]);+ mobileLayout?.switchToInfoTab();+ }, [capture, graphViewMode, analyticsDimensions, mobileLayout]);const handleViewModeChange = useCallback((mode: GraphViewMode) => {// Clicking the already-active segment is a no-op — don't count it.diff --git a/web/src/components/trace/components/TraceTimeline/index.tsx b/web/src/components/trace/components/TraceTimeline/index.tsxindex 41f32724f9..20eaed2a4e 100644--- a/web/src/components/trace/components/TraceTimeline/index.tsx+++ b/web/src/components/trace/components/TraceTimeline/index.tsx@@ -56,6 +56,7 @@ import {GUTTER_VISUAL_DEPTH,} from "../_shared/visual-depth";import { useDesktopLayoutContextOptional } from "../_layout/TraceLayoutDesktop";+import { useMobileLayoutContextOptional } from "../_layout/TraceLayoutMobile";import { type TreeNode } from "../../lib/types";import { cn } from "@/src/utils/tailwind";@@ -247,6 +248,9 @@ export function TraceTimeline() {const analyticsDimensions = useTraceAnalyticsDimensions();// Optional (null in the mobile layout): reopen the detail panel on select.const layout = useDesktopLayoutContextOptional();+ // Optional (null on desktop): its presence also means the timeline is+ // rendered inside a narrow mobile tab, and selecting jumps to the Info tab.+ const mobileLayout = useMobileLayoutContextOptional();// The chart is the single vertical scroller; the gutter content is a one-way// transform projection of it (gutterInnerRef), so the two panes can't drift.@@ -258,8 +262,14 @@ export function TraceTimeline() {// whole row (caption + chart), which CSS :hover can't do across two panes.const [hoveredNodeId, setHoveredNodeId] = useState<string | null>(null);- // Resizable name gutter so users can trade name space for chart space.- const [gutterWidth, setGutterWidth] = useState(GUTTER_WIDTH_DEFAULT);+ // Resizable name gutter so users can trade name space for chart space. On+ // mobile the timeline lives in a narrow tab, so start the gutter at its MIN+ // and let the waterfall (the point of the timeline) claim the rest — the+ // chart pane keeps its own horizontal scroll, so the bars scroll within the+ // tab instead of overflowing the page.+ const [gutterWidth, setGutterWidth] = useState(() =>+ mobileLayout ? GUTTER_WIDTH_MIN : GUTTER_WIDTH_DEFAULT,+ );const startGutterResize = useCallback((e: React.PointerEvent) => {e.preventDefault();@@ -525,8 +535,10 @@ export function TraceTimeline() {// Reopen the detail panel on any select — including re-clicking the// already-selected row, where the URL param wouldn't fire an effect.layout?.expandDetailPanel();+ // Mobile: jump to the Info tab on the same re-click path (no-op on desktop).+ mobileLayout?.switchToInfoTab();},- [setSelectedNodeId, layout, capture, analyticsDimensions],+ [setSelectedNodeId, layout, mobileLayout, capture, analyticsDimensions],);const handleHoverNode = useCallback((node: TreeNode) => {diff --git a/web/src/components/trace/components/TraceTree.tsx b/web/src/components/trace/components/TraceTree.tsxindex ba42284953..ebae4bc845 100644--- a/web/src/components/trace/components/TraceTree.tsx+++ b/web/src/components/trace/components/TraceTree.tsx@@ -19,6 +19,7 @@ import { useSelection } from "../contexts/SelectionContext";import { useIsObservationActive } from "../contexts/PlayheadContext";import { useHandlePrefetchObservation } from "../hooks/useHandlePrefetchObservation";import { useDesktopLayoutContextOptional } from "./_layout/TraceLayoutDesktop";+import { useMobileLayoutContextOptional } from "./_layout/TraceLayoutMobile";import { type TreeNode } from "../lib/types";import { cn } from "@/src/utils/tailwind";import type Decimal from "decimal.js";@@ -96,6 +97,10 @@ export function TraceTree() {// Optional (null on mobile): reopen the detail panel on select, including// re-selecting the already-selected node.const layout = useDesktopLayoutContextOptional();+ // Optional (null on desktop): jump to the Info tab on select, including+ // re-selecting the already-selected node (URL param unchanged → the tab+ // effect wouldn't fire).+ const mobileLayout = useMobileLayoutContextOptional();const handleSelectNode = (id: string | null) => {if (id) {capture("trace_detail:node_selected", {@@ -105,6 +110,7 @@ export function TraceTree() {}setSelectedNodeId(id);layout?.expandDetailPanel();+ if (id) mobileLayout?.switchToInfoTab();};// TODO: Extract aggregation logic to shared utility - duplicated in tree-building.ts and TraceTimeline/index.tsxdiff --git a/web/src/components/trace/components/_layout/TraceLayoutMobile.tsx b/web/src/components/trace/components/_layout/TraceLayoutMobile.tsxindex b053e5d2b2..6c912e19db 100644--- a/web/src/components/trace/components/_layout/TraceLayoutMobile.tsx+++ b/web/src/components/trace/components/_layout/TraceLayoutMobile.tsx@@ -1,96 +1,160 @@/**- * TraceLayoutMobile - Touch-friendly vertical layout for mobile devices+ * TraceLayoutMobile - Tabbed, full-height trace view for mobile devices.*- * Purpose:- * - Provide mobile-optimized UI without resizable panels- * - Vertical stack: navigation at top, detail below- * - No drag handles (confusing on touch devices)+ * Replaces the old accordion (a ~384px-capped navigation stacked over a cramped+ * detail, with no way to switch tree/timeline and the graph jammed into a 256px+ * slot). Instead: a top tab bar — Tree · Timeline · Graph · Info — where each+ * body fills the viewport. Tree/Timeline/Graph are full-height navigators;+ * selecting an observation in any of them jumps to the Info tab (which reuses+ * the shared detail panel). See MobileTraceContent in Trace.tsx for composition.*- * Layout:- * - Navigation is collapsible (accordion-style)- * - Detail takes remaining space- * - All content scrollable within sections+ * Mobile-only: this component (and its context) render solely under the mobile+ * path. Desktop uses TraceLayoutDesktop and never mounts this.+ *+ * Tab state lives in the `?mobileTab` URL param (shareable + back-able), never+ * mirrored into local state. The default is computed once at mount: a deep link+ * / row click that already targeted an observation opens on Info, otherwise on+ * Tree.+ *+ * Selection → Info wiring is purely imperative: all three navigators+ * (Tree/Timeline/Graph) call `switchToInfoTab()` on select, so selecting a node+ * jumps to Info. There is deliberately NO reactive selection→tab effect — see+ * `switchToInfoTab` for why one would corrupt Back/Forward.*/-import { useState, createContext, useContext, type ReactNode } from "react";-import { Button } from "@/src/components/ui/button";-import { ChevronDown, ChevronUp } from "lucide-react";--// Context for sharing accordion state with compound components-interface TraceLayoutMobileContext {- isNavigationExpanded: boolean;- setIsNavigationExpanded: (expanded: boolean) => void;-}+import {+ createContext,+ useContext,+ useCallback,+ useMemo,+ useState,+ type ReactNode,+} from "react";+import { StringParam, useQueryParam } from "use-query-params";+import {+ TabsBar,+ TabsBarContent,+ TabsBarList,+ TabsBarTrigger,+} from "@/src/components/ui/tabs-bar";+import { useSelection } from "../../contexts/SelectionContext";-const LayoutContext = createContext<TraceLayoutMobileContext | null>(null);+export type MobileTraceTab = "tree" | "timeline" | "graph" | "info";+const VALID_TABS: MobileTraceTab[] = ["tree", "timeline", "graph", "info"];-function useLayoutContext() {- const context = useContext(LayoutContext);- if (!context) {- throw new Error(- "TraceLayoutMobile compound components must be used within TraceLayoutMobile",- );- }- return context;+function isValidTab(value: string | null | undefined): value is MobileTraceTab {+ return VALID_TABS.includes(value as MobileTraceTab);}-// Export hook for use in TracePanelNavigationLayoutMobile-export function useMobileLayoutContext() {- return useLayoutContext();+// Mirror of TraceLayoutDesktop's layout context: exposes the imperative+// tab-switch so shared navigators can wire mobile behavior additively.+interface MobileLayoutContextValue {+ switchToInfoTab: () => void;}-export function TraceLayoutMobile({ children }: { children: ReactNode }) {- const [isNavigationExpanded, setIsNavigationExpanded] = useState(true);-- const contextValue: TraceLayoutMobileContext = {- isNavigationExpanded,- setIsNavigationExpanded,- };+const MobileLayoutContext = createContext<MobileLayoutContextValue | null>(+ null,+);- return (- <LayoutContext.Provider value={contextValue}>- <div className="flex h-full w-full flex-col">{children}</div>- </LayoutContext.Provider>- );+/**+ * Safe variant for components rendered in BOTH desktop and mobile layouts+ * (desktop has no provider): returns null instead of throwing, so a `?.` call+ * is a no-op on desktop and keeps the desktop path byte-identical.+ */+export function useMobileLayoutContextOptional() {+ return useContext(MobileLayoutContext);}-// Compound component: Navigation section with accordion-TraceLayoutMobile.NavigationPanel = function Navigation({- children,+const TAB_BODY_CLASS = "mt-0 flex min-h-0 flex-1 flex-col overflow-hidden";++export function TraceLayoutMobile({+ tree,+ timeline,+ graph,+ info,+ showGraph,}: {- children: ReactNode;+ tree: ReactNode;+ timeline: ReactNode;+ graph: ReactNode;+ info: ReactNode;+ /** Reused from TraceContent; hides the Graph tab when the trace has no graph. */+ showGraph: boolean;}) {- const { isNavigationExpanded, setIsNavigationExpanded } = useLayoutContext();+ const [tabParam, setTabParam] = useQueryParam("mobileTab", StringParam);+ const { selectedNodeId } = useSelection();++ // Mount-time default only (captured once, never re-derived): a selection that+ // was already present when the view opened lands on Info; otherwise Tree.+ const [initialTab] = useState<MobileTraceTab>(() =>+ selectedNodeId ? "info" : "tree",+ );++ const requestedTab = isValidTab(tabParam) ? tabParam : initialTab;+ // The Graph tab is conditionally rendered; if a stale/shared URL asks for it+ // while it's unavailable, fall back to Tree.+ const activeTab: MobileTraceTab =+ requestedTab === "graph" && !showGraph ? "tree" : requestedTab;++ // Auto-switch to Info writes PUSH, not replace. Every navigator's select+ // handler writes the `?observation=` param (pushIn) and calls this in the+ // SAME tick, so with use-query-params batching (`enableBatching`, set in+ // _app.tsx) both writes fold into ONE navigation whose updateType is taken+ // from the LAST enqueued write — pushIn here keeps the combined selection+tab+ // change as a single pushed history entry, so Back returns to the+ // pre-selection view. (replaceIn would downgrade the whole batch to+ // history.replaceState and drop that entry, so Back would leave the trace.)+ //+ // There is deliberately NO reactive selection→tab effect. All three+ // navigators call this imperatively, so an effect keyed on `selectedNodeId`+ // would be redundant on forward selections — and would BREAK Back/Forward: a+ // POP that restores an older `{observation, mobileTab=tree}` entry changes+ // `selectedNodeId`, which an effect cannot distinguish from a live tap, so it+ // would immediately overwrite the just-restored tab back to Info and trap the+ // user (LFE-11067). Letting the restored URL win outright is correct.+ const switchToInfoTab = useCallback(() => {+ setTabParam("info", "pushIn");+ }, [setTabParam]);++ const contextValue = useMemo<MobileLayoutContextValue>(+ () => ({ switchToInfoTab }),+ [switchToInfoTab],+ );return (- <div className="flex shrink-0 flex-col border-b">- {/* Accordion Header */}- <Button- variant="ghost"- className="flex w-full justify-between rounded-none px-4 py-3 text-left"- onClick={() => setIsNavigationExpanded(!isNavigationExpanded)}+ <MobileLayoutContext.Provider value={contextValue}>+ <TabsBar+ value={activeTab}+ onValueChange={(value) => setTabParam(value, "pushIn")}+ className="h-full w-full">- <span className="font-bold">Navigation</span>- {isNavigationExpanded ? (- <ChevronUp className="h-4 w-4" />- ) : (- <ChevronDown className="h-4 w-4" />- )}- </Button>+ <TabsBarList className="shrink-0 px-2">+ <TabsBarTrigger value="tree">Tree</TabsBarTrigger>+ <TabsBarTrigger value="timeline">Timeline</TabsBarTrigger>+ {showGraph && <TabsBarTrigger value="graph">Graph</TabsBarTrigger>}+ <TabsBarTrigger value="info">Info</TabsBarTrigger>+ </TabsBarList>- {/* Navigation Content - Collapsible */}- {isNavigationExpanded && (- <div className="max-h-96 overflow-y-auto">{children}</div>- )}- </div>+ {/* Inactive tabs unmount (Radix default). On memory-constrained mobile+ that keeps a single heavy subtree live at a time (two virtualizers,+ the elk graph layout, and the detail JSON never all mount at once);+ the cost is that a navigator's scroll/zoom resets when revisited —+ an accepted v1 tradeoff (follow-up: preserve navigator state). */}+ <TabsBarContent value="tree" className={TAB_BODY_CLASS}>+ {tree}+ </TabsBarContent>+ <TabsBarContent value="timeline" className={TAB_BODY_CLASS}>+ {timeline}+ </TabsBarContent>+ {showGraph && (+ <TabsBarContent value="graph" className={TAB_BODY_CLASS}>+ {graph}+ </TabsBarContent>+ )}+ <TabsBarContent value="info" className={TAB_BODY_CLASS}>+ {info}+ </TabsBarContent>+ </TabsBar>+ </MobileLayoutContext.Provider>);-};--// Compound component: Detail section-TraceLayoutMobile.DetailPanel = function Detail({- children,-}: {- children: ReactNode;-}) {- return <div className="flex-1 overflow-y-auto">{children}</div>;-};+}diff --git a/web/src/components/trace/components/_layout/TracePanelNavigationLayoutMobile.tsx b/web/src/components/trace/components/_layout/TracePanelNavigationLayoutMobile.tsxdeleted file mode 100644index e80e8a0d0c..0000000000--- a/web/src/components/trace/components/_layout/TracePanelNavigationLayoutMobile.tsx+++ /dev/null@@ -1,61 +0,0 @@-/**- * TracePanelNavigationLayoutMobile - Mobile-specific layout wrapper for navigation panel- *- * Responsibility:- * - Wrap navigation content with mobile-optimized layout structure- * - Position TracePanelNavigationHiddenNotice above content- * - Provide scrollable container for navigation content- * - Render graph view below tree/timeline when enabled (collapsible)- *- * Hooks:- * - None (pure layout component)- * - useViewPreferences() - for showGraph preference- * - useTraceGraphData() - for isGraphViewAvailable- *- * Re-renders when:- * - Children change (TracePanelNavigation content)- * - showGraph or isGraphViewAvailable changes- * - Does NOT re-render when selection changes (isolated to detail panel)- */--import { type ReactNode, useState } from "react";-import { ChevronDown, ChevronUp } from "lucide-react";-import { Button } from "@/src/components/ui/button";-import { TracePanelNavigationHiddenNotice } from "./TracePanelNavigationHiddenNotice";--export function TracePanelNavigationLayoutMobile({- children,- secondaryContent,-}: {- children: ReactNode;- secondaryContent?: ReactNode;-}) {- const [isGraphExpanded, setIsGraphExpanded] = useState(false);-- return (- <div className="flex h-full flex-col">- <TracePanelNavigationHiddenNotice />- <div className="flex-1 overflow-hidden">{children}</div>- {secondaryContent && (- <div className="border-t">- <Button- variant="ghost"- size="sm"- onClick={() => setIsGraphExpanded(!isGraphExpanded)}- className="flex w-full items-center justify-between px-2 py-1"- >- <span className="text-xs font-bold">Graph View</span>- {isGraphExpanded ? (- <ChevronUp className="h-3.5 w-3.5" />- ) : (- <ChevronDown className="h-3.5 w-3.5" />- )}- </Button>- {isGraphExpanded && (- <div className="h-64 overflow-hidden">{secondaryContent}</div>- )}- </div>- )}- </div>- );-}