🪢 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: Add peek-mode local preview navigation for variable mapping previews (#12945)
marliessophie8e9521522fc8
diff --git a/web/src/features/evals/components/variable-mapping-card.tsx b/web/src/features/evals/components/variable-mapping-card.tsxindex 4b67639782..9b13931584 100644--- a/web/src/features/evals/components/variable-mapping-card.tsx+++ b/web/src/features/evals/components/variable-mapping-card.tsx@@ -51,6 +51,7 @@ import { AlertCircle, ExternalLink } from "lucide-react";import { useVariableMappingSync } from "@/src/features/evals/hooks/useVariableMappingSync";import { Button } from "@/src/components/ui/button";import Link from "next/link";+import { useRouter } from "next/router";export const VariableMappingCard = ({projectId,@@ -74,6 +75,14 @@ export const VariableMappingCard = ({hideAdvancedSettings?: boolean;}) => {const [showPreview, setShowPreview] = useState(false);+ const [selectedPreviewIds, setSelectedPreviewIds] = useState<{+ traceId?: string;+ observationId?: string;+ }>();+ const router = useRouter();+ const peekId =+ typeof router.query.peek === "string" ? router.query.peek : undefined;+ const isPeekView = Boolean(peekId);const { fields } = useFieldArray({control: form.control,@@ -89,6 +98,7 @@ export const VariableMappingCard = ({projectId,form,disabled,+ isPeekView ? (selectedPreviewIds ?? {}) : undefined,);useEffect(() => {@@ -98,8 +108,18 @@ export const VariableMappingCard = ({// For dataset and experiment targets, disable previewsetShowPreview(false);}++ if (isPeekView) {+ setSelectedPreviewIds(undefined);+ }// eslint-disable-next-line react-hooks/exhaustive-deps- }, [form.watch("target"), disabled]);+ }, [form.watch("target"), disabled, isPeekView]);++ useEffect(() => {+ if (isPeekView) {+ setSelectedPreviewIds(undefined);+ }+ }, [isPeekView, peekId]);const mappingControlButtons = (<div className="flex items-center gap-2">@@ -124,6 +144,23 @@ export const VariableMappingCard = ({? "observations": "traces"}+ onNavigate={+ isPeekView+ ? (entry) => {+ if (isEventTarget(form.watch("target"))) {+ setSelectedPreviewIds({+ traceId: entry.params?.traceId,+ observationId: entry.id,+ });+ } else {+ setSelectedPreviewIds({+ traceId: entry.id,+ observationId: undefined,+ });+ }+ }+ : undefined+ }path={(entry) => {const isEvent = isEventTarget(form.watch("target"));const basePath = hideAdvancedSettings@@ -173,7 +210,7 @@ export const VariableMappingCard = ({title="Only user-managed templates can be edited">Edit prompt- <ExternalLink className="h-4 w-4" />+ <ExternalLink className="ml-1 h-4 w-4" /></Button>)}</div>diff --git a/web/src/features/evals/hooks/useEvalConfigMappingData.ts b/web/src/features/evals/hooks/useEvalConfigMappingData.tsindex 6607942bf6..4c7c4a9344 100644--- a/web/src/features/evals/hooks/useEvalConfigMappingData.ts+++ b/web/src/features/evals/hooks/useEvalConfigMappingData.ts@@ -18,16 +18,24 @@ export function useEvalConfigMappingData(projectId: string,form: UseFormReturn<EvalFormType>,disabled = false,+ selectedPreviewIds?: {+ traceId?: string;+ observationId?: string;+ },): EvalConfigMappingData {const router = useRouter();- // Get traceId and observationId from URL query parameters+ // In full-page mode, keep using URL params. In peek mode, callers can manage preview ids locally.const traceId =- typeof router.query.traceId === "string" ? router.query.traceId : undefined;+ selectedPreviewIds?.traceId ??+ (typeof router.query.traceId === "string"+ ? router.query.traceId+ : undefined);const observationId =- typeof router.query.observationId === "string"+ selectedPreviewIds?.observationId ??+ (typeof router.query.observationId === "string"? router.query.observationId- : undefined;+ : undefined);const { previewData, isLoading } = usePreviewData(projectId,@@ -39,9 +47,15 @@ export function useEvalConfigMappingData(const targetValue = form.watch("target");const prevTargetRef = useRef(targetValue);+ const isLocallyManagedPreview = Boolean(selectedPreviewIds);// drop the traceId and observation-related params from the URL query parameters when target changesuseEffect(() => {+ if (isLocallyManagedPreview) {+ prevTargetRef.current = targetValue;+ return;+ }+if (prevTargetRef.current !== targetValue &&prevTargetRef.current !== undefined@@ -60,7 +74,7 @@ export function useEvalConfigMappingData();}prevTargetRef.current = targetValue;- }, [targetValue, router]);+ }, [targetValue, router, isLocallyManagedPreview]);const observationTypeToNames = new Map<ObservationType, Set<string>>([["SPAN", new Set()],diff --git a/web/src/features/navigate-detail-pages/DetailPageNav.tsx b/web/src/features/navigate-detail-pages/DetailPageNav.tsxindex 7b0df1e46d..5c8a86b14f 100644--- a/web/src/features/navigate-detail-pages/DetailPageNav.tsx+++ b/web/src/features/navigate-detail-pages/DetailPageNav.tsx@@ -12,26 +12,43 @@ import {import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { ChevronDown, ChevronUp } from "lucide-react";import { useRouter } from "next/router";-import { useEffect } from "react";+import { useCallback, useEffect } from "react";export const DetailPageNav = (props: {currentId: string;path: (entry: ListEntry) => string;listKey: string;+ onNavigate?: (entry: ListEntry) => void;}) => {+ const { currentId, path, listKey, onNavigate } = props;const { detailPagelists } = useDetailPageLists();- const entries = detailPagelists[props.listKey] ?? [];+ const entries = detailPagelists[listKey] ?? [];const capture = usePostHogClientCapture();const router = useRouter();- const currentIndex = entries.findIndex(- (entry) => entry.id === props.currentId,- );+ const currentIndex = entries.findIndex((entry) => entry.id === currentId);const previousPageEntry =currentIndex > 0 ? entries[currentIndex - 1] : undefined;const nextPageEntry =currentIndex < entries.length - 1 ? entries[currentIndex + 1] : undefined;+ const navigateToEntry = useCallback(+ (entry: ListEntry) => {+ if (onNavigate) {+ onNavigate(entry);+ return;+ }++ void router.push(+ path({+ id: encodeURIComponent(entry.id),+ params: entry.params,+ }),+ );+ },+ [onNavigate, path, router],+ );+// keyboard shortcuts for buttons k and juseEffect(() => {const handleKeyDown = (event: KeyboardEvent) => {@@ -50,22 +67,14 @@ export const DetailPageNav = (props: {}if (event.key === "k" && previousPageEntry) {- const newPath = props.path({- id: encodeURIComponent(previousPageEntry.id),- params: previousPageEntry.params,- });- void router.push(newPath);+ navigateToEntry(previousPageEntry);} else if (event.key === "j" && nextPageEntry) {- const newPath = props.path({- id: encodeURIComponent(nextPageEntry.id),- params: nextPageEntry.params,- });- void router.push(newPath);+ navigateToEntry(nextPageEntry);}};window.addEventListener("keydown", handleKeyDown);return () => window.removeEventListener("keydown", handleKeyDown);- }, [previousPageEntry, nextPageEntry, router, props]);+ }, [previousPageEntry, nextPageEntry, navigateToEntry]);if (entries.length > 1)return (@@ -80,12 +89,7 @@ export const DetailPageNav = (props: {onClick={() => {if (previousPageEntry) {capture("navigate_detail_pages:button_click_prev_or_next");- void router.push(- props.path({- id: encodeURIComponent(previousPageEntry.id),- params: previousPageEntry.params,- }),- );+ navigateToEntry(previousPageEntry);}}}>@@ -113,12 +117,7 @@ export const DetailPageNav = (props: {onClick={() => {if (nextPageEntry) {capture("navigate_detail_pages:button_click_prev_or_next");- void router.push(- props.path({- id: encodeURIComponent(nextPageEntry.id),- params: nextPageEntry.params,- }),- );+ navigateToEntry(nextPageEntry);}}}>