import DiffViewer from "@/src/components/DiffViewer"; import { ScoresTableCell } from "@/src/components/scores-table-cell"; import { Badge } from "@/src/components/ui/badge"; import { Button } from "@/src/components/ui/button"; import { IOTableCell } from "@/src/components/ui/IOTableCell"; import { Dialog, DialogBody, DialogFooter, DialogHeader, DialogTitle, } from "@/src/components/ui/dialog"; import { DialogTrigger } from "@/src/components/ui/dialog"; import { DialogContent } from "@/src/components/ui/dialog"; import { type RunMetrics } from "@/src/features/datasets/components/DatasetCompareRunsTable"; import { useDatasetCompareMetrics } from "@/src/features/datasets/contexts/DatasetCompareMetricsContext"; import { api } from "@/src/utils/api"; import { formatIntervalSeconds } from "@/src/utils/dates"; import { cn } from "@/src/utils/tailwind"; import { type Prisma } from "@langfuse/shared"; import { ChartNoAxesCombined, ClockIcon, FileDiffIcon, GaugeCircle, ListCheck, } from "lucide-react"; import { useState, type ReactNode } from "react"; import { decomposeAggregateScoreKey } from "@/src/features/scores/lib/aggregateScores"; const DatasetAggregateCell = ({ scores, resourceMetrics, traceId, projectId, observationId, scoreKeyToDisplayName, actionButtons, expectedOutput: output, isHighlighted = false, }: RunMetrics & { projectId: string; scoreKeyToDisplayName: Map; actionButtons?: ReactNode; expectedOutput?: Prisma.JsonValue; isHighlighted?: boolean; }) => { const [isOpen, setIsOpen] = useState(false); const { selectedMetrics } = useDatasetCompareMetrics(); // conditionally fetch the trace or observation depending on the presence of observationId const trace = api.traces.byId.useQuery( { traceId, projectId }, { enabled: observationId === undefined, trpc: { context: { skipBatch: true, }, }, refetchOnMount: false, refetchOnWindowFocus: false, refetchOnReconnect: false, staleTime: Infinity, }, ); const observation = api.observations.byId.useQuery( { observationId: observationId as string, // disabled when observationId is undefined projectId, traceId, }, { enabled: observationId !== undefined, trpc: { context: { skipBatch: true, }, }, refetchOnMount: false, refetchOnWindowFocus: false, refetchOnReconnect: false, staleTime: Infinity, }, ); const data = observationId === undefined ? trace.data : observation.data; const scoresEntries = Object.entries(scores).sort(([keyA], [keyB]) => { const nameA = decomposeAggregateScoreKey(keyA).name; const nameB = decomposeAggregateScoreKey(keyB).name; return nameA.localeCompare(nameB); }); return (
{actionButtons}
{scoresEntries.length > 0 ? ( scoresEntries.map(([key, score]) => ( {scoreKeyToDisplayName.get(key)}: )) ) : ( No scores )}
{!!resourceMetrics.latency && ( {formatIntervalSeconds(resourceMetrics.latency)} )} {resourceMetrics.totalCost && ( {resourceMetrics.totalCost} )}
{output && data?.output && ( { setIsOpen(open); }} > event.stopPropagation()} > Expected Output → Actual Output
)}
); }; type DatasetAggregateTableCellProps = { projectId: string; scoreKeyToDisplayName: Map; value?: RunMetrics; actionButtons?: ReactNode; expectedOutput?: Prisma.JsonValue; isHighlighted?: boolean; }; export const DatasetAggregateTableCell = ({ projectId, scoreKeyToDisplayName, value, actionButtons, expectedOutput, isHighlighted = false, }: DatasetAggregateTableCellProps) => { return value ? ( ) : null; };