🪢 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
perf(ui): add virtualized single session view (#2066)
Marc Klingen83359e6fc661
diff --git a/packages/shared/prisma/seed.ts b/packages/shared/prisma/seed.tsindex 581a8ff11e..52e8f72f5e 100644--- a/packages/shared/prisma/seed.ts+++ b/packages/shared/prisma/seed.ts@@ -459,7 +459,7 @@ function createObjects(const session =Math.random() > 0.3? {- id: `session-${i % 10}`,+ id: `session-${i % 3}`,projectId: projectId,}: undefined;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d73e3909ff..2d4ef28dca 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -351,6 +351,9 @@ importers:'@tanstack/react-table':specifier: ^8.11.8version: 8.13.2([email protected])([email protected])+ '@tanstack/react-virtual':+ specifier: ^3.5.0+ version: 3.5.0([email protected])([email protected])'@tremor/react':specifier: 3.11.1@@ -2606,7 +2609,7 @@ packages:react: ^16 || ^17 || ^18react-dom: ^16 || ^17 || ^18dependencies:- '@tanstack/react-virtual': 3.2.0([email protected])([email protected])+ '@tanstack/react-virtual': 3.5.0([email protected])([email protected])client-only: 0.0.1react: 18.2.0react-dom: 18.2.0([email protected])@@ -6036,13 +6039,13 @@ packages:react-dom: 18.2.0([email protected])dev: false- resolution: {integrity: sha512-OEdMByf2hEfDa6XDbGlZN8qO6bTjlNKqjM3im9JG+u3mCL8jALy0T/67oDI001raUUPh1Bdmfn4ZvPOV5knpcg==}+ resolution: {integrity: sha512-rtvo7KwuIvqK9zb0VZ5IL7fiJAEnG+0EiFZz8FUOs+2mhGqdGmjKIaT1XU7Zq0eFqL0jonLlhbayJI/J2SA/Bw==}peerDependencies:react: ^16.8.0 || ^17.0.0 || ^18.0.0react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0dependencies:- '@tanstack/virtual-core': 3.2.0+ '@tanstack/virtual-core': 3.5.0react: 18.2.0react-dom: 18.2.0([email protected])dev: false@@ -6052,8 +6055,8 @@ packages:engines: {node: '>=12'}dev: false- /@tanstack/[email protected]:- resolution: {integrity: sha512-P5XgYoAw/vfW65byBbJQCw+cagdXDT/qH6wmABiLt4v4YBT2q2vqCOhihe+D1Nt325F/S/0Tkv6C5z0Lv+VBQQ==}+ /@tanstack/[email protected]:+ resolution: {integrity: sha512-KnPRCkQTyqhanNC0K63GBG3wA8I+D1fQuVnAvcBF8f13akOKeQp1gSbu6f77zCxhEk727iV5oQnbHLYzHrECLg==}dev: false/@testing-library/[email protected]:diff --git a/web/package.json b/web/package.jsonindex 34b4467083..d539c1226b 100644--- a/web/package.json+++ b/web/package.json@@ -68,6 +68,7 @@"@tailwindcss/forms": "^0.5.7","@tanstack/react-query": "^4.36.1","@tanstack/react-table": "^8.11.8",+ "@tanstack/react-virtual": "^3.5.0","@tremor/react": "3.11.1","@trpc/client": "^10.45.0","@trpc/next": "^10.45.0",diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsxindex 85fd3192e0..1346314989 100644--- a/web/src/components/session/index.tsx+++ b/web/src/components/session/index.tsx@@ -13,13 +13,32 @@ import { useDetailPageLists } from "@/src/features/navigate-detail-pages/contextimport { api } from "@/src/utils/api";import { usdFormatter } from "@/src/utils/numbers";import Link from "next/link";-import { useEffect } from "react";+import { useEffect, useRef } from "react";+import { useWindowVirtualizer } from "@tanstack/react-virtual";+import { type RouterOutput } from "@/src/utils/types";+import {+ DataTableRowHeightSwitch,+ type RowHeight,+ useRowHeightLocalStorage,+} from "@/src/components/table/data-table-row-height-switch";+import { ScrollArea } from "@/src/components/ui/scroll-area";++// do not use the usual table row heights here+const rowHeightMapping: Record<RowHeight, number> = {+ s: 200,+ m: 350,+ l: 700,+};export const SessionPage: React.FC<{sessionId: string;projectId: string;}> = ({ sessionId, projectId }) => {const { setDetailPageList } = useDetailPageLists();+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage(+ "single-session",+ "s",+ );const session = api.sessions.byId.useQuery({sessionId,@@ -77,6 +96,11 @@ export const SessionPage: React.FC<{}listKey="sessions"/>,+ <DataTableRowHeightSwitch+ rowHeight={rowHeight}+ setRowHeight={setRowHeight}+ key="height"+ />,]}/><div className="flex flex-wrap gap-2">@@ -97,36 +121,95 @@ export const SessionPage: React.FC<{</Badge>)}</div>- <div className="mt-5 flex flex-col gap-2 border-t pt-5">- {session.data?.traces.map((trace) => (- <Card- className="border-border-gray-150 group grid gap-3 p-2 shadow-none hover:border-gray-300 md:grid-cols-3"- key={trace.id}- >- <SessionIO traceId={trace.id} />- <div className="-mt-1 p-1 opacity-50 transition-opacity group-hover:opacity-100">- <Link- href={`/project/${projectId}/traces/${trace.id}`}- className="text-xs hover:underline"- >- Trace: {trace.name} ({trace.id}) ↗- </Link>- <div className="text-xs text-gray-500">- {trace.timestamp.toLocaleString()}- </div>- <div className="mb-1 mt-2 text-xs text-gray-500">Scores</div>- <div className="flex flex-wrap content-start items-start gap-1">- <GroupedScoreBadges scores={trace.scores} />- </div>- <ManualScoreButton- projectId={projectId}- traceId={trace.id}- scores={trace.scores}- variant="badge"- />- </div>- </Card>- ))}+ {session.data && (+ <TraceCardList+ session={session.data}+ projectId={projectId}+ rowHeight={rowHeightMapping[rowHeight]}+ />+ )}+ </div>+ );+};++const TraceCardList = ({+ session,+ projectId,+ rowHeight,+}: {+ session: RouterOutput["sessions"]["byId"];+ projectId: string;+ rowHeight: number;+}) => {+ const listVirtualizationRef = useRef<HTMLDivElement | null>(null);++ const virtualizer = useWindowVirtualizer({+ count: session.traces.length,+ estimateSize: () => rowHeight,+ overscan: 5,+ scrollMargin: listVirtualizationRef.current?.offsetTop ?? 0,+ gap: 10,+ });+ useEffect(() => {+ // re-measure when rowHeight changes to update the virtualizer+ virtualizer.measure();+ }, [rowHeight, virtualizer]);+ return (+ <div className="mt-5 border-t pt-5">+ <div+ ref={listVirtualizationRef}+ style={{+ height: `${virtualizer.getTotalSize()}px`,+ position: "relative",+ }}+ >+ {virtualizer+ .getVirtualItems()+ .map((virtualItem) => ({+ virtualItem,+ trace: session.traces[virtualItem.index],+ }))+ .map(({ virtualItem, trace }) => (+ <Card+ className="border-border-gray-150 group grid w-full gap-3 overflow-hidden p-2 shadow-none hover:border-gray-300 md:grid-cols-3"+ key={virtualItem.key}+ data-index={virtualItem.index}+ style={{+ position: "absolute",+ top: 0,+ left: 0,+ height: `${rowHeight}px`,+ transform: `translateY(${virtualItem.start - virtualizer.options.scrollMargin}px)`,+ }}+ >+ <ScrollArea className="col-span-2 pr-3">+ <SessionIO traceId={trace.id} />+ </ScrollArea>+ <ScrollArea>+ <div className="-mt-1 overflow-y-auto p-1 opacity-50 transition-opacity group-hover:opacity-100">+ <Link+ href={`/project/${projectId}/traces/${trace.id}`}+ className="text-xs hover:underline"+ >+ Trace: {trace.name} ({trace.id}) ↗+ </Link>+ <div className="text-xs text-gray-500">+ {trace.timestamp.toLocaleString()}+ </div>+ <div className="mb-1 mt-2 text-xs text-gray-500">Scores</div>+ <div className="flex flex-wrap content-start items-start gap-1">+ <GroupedScoreBadges scores={trace.scores} />+ </div>+ <ManualScoreButton+ projectId={projectId}+ traceId={trace.id}+ scores={trace.scores}+ variant="badge"+ />+ </div>+ </ScrollArea>+ </Card>+ ))}</div></div>);@@ -145,8 +228,9 @@ const SessionIO = ({ traceId }: { traceId: string }) => {refetchOnMount: false, // prevents refetching loops},);+return (- <div className="col-span-2 flex flex-col gap-2 p-0">+ <div className="flex flex-col gap-2 overflow-x-hidden overflow-y-scroll p-0">{!trace.data ? (<JsonSkeletonclassName="h-full w-full overflow-hidden px-2 py-1"