🪢 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
/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
import Image from "next/image";
import { useState } from "react";
import {
Dialog,
DialogBody,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/src/components/ui/dialog";
import { Switch } from "@/src/components/design-system/Switch/Switch";
import { Button } from "@/src/components/ui/button";
import { cn } from "@/src/utils/tailwind";
import {
featurePreviewLabels,
type PersonalFeaturePreviewFlag,
} from "@/src/features/feature-flags/available-flags";
import modernSessionDarkIllustration from "../assets/modern-session-dark.svg";
import modernSessionLightIllustration from "../assets/modern-session-light.svg";
/** Flags the Feature Preview modal can toggle. Keep in sync with the
* userAccount.setFeaturePreviewEnabled allowlist and available-flags.ts. */
export type PreviewFlag = PersonalFeaturePreviewFlag;
type PreviewIllustration = {
light: React.ComponentProps<typeof Image>["src"];
dark: React.ComponentProps<typeof Image>["src"];
alt: string;
width?: number;
height?: number;
};
type PreviewRegistryItem = {
flag: PreviewFlag;
description: string;
details: string;
feedbackUrl: string;
illustration?: PreviewIllustration;
};
/** Per-preview dynamic state, supplied by ControlledFeaturePreviewModal (which
* owns the session + the toggle mutation). The static content lives here. */
export type PreviewState = {
enabled: boolean;
disabled?: boolean;
warningReason?: string;
onToggle: (enabled: boolean) => void;
isToggling?: boolean;
};
// Static registry — one entry per preview, in sidebar order.
// Previews may include separate light/dark illustrations.
const PREVIEW_REGISTRY: PreviewRegistryItem[] = [
{
flag: "langfuseTopics",
description:
"Discover common topics across traces, with summaries and an interactive topic map.",
details:
"Choose traces and facets, run the topic pipeline, and explore the resulting clusters and trace summaries.",
feedbackUrl: "https://github.com/orgs/langfuse/discussions",
},
{
flag: "sessionViewV2",
description:
"Navigate every trace in a session from one continuous conversation feed, with tools and structured data available on demand.",
details:
"Redesigned Session View replaces separate trace cards with a compact minimap and a virtualized feed. Jump between traces, keep the active trace in view, or temporarily show inline tool calls and system prompts.",
feedbackUrl: "https://github.com/orgs/langfuse/discussions/18687",
illustration: {
light: modernSessionLightIllustration,
dark: modernSessionDarkIllustration,
alt: "Redesigned Session View with a continuous session conversation feed.",
},
},
];
const FEATURE_PREVIEW_MODAL_TITLE = "Feature Preview";
const FEATURE_PREVIEW_MODAL_SUBTITLE =
"Try upcoming and experimental product experiences before they become generally available.";
export type FeaturePreviewModalProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
/** Dynamic state per preview flag. Only previews with an entry here render. */
state: Partial<Record<PreviewFlag, PreviewState>>;
};
export function FeaturePreviewModal({
open,
onOpenChange,
state,
}: FeaturePreviewModalProps) {
const items = PREVIEW_REGISTRY.filter((item) => state[item.flag]);
const [selectedFlag, setSelectedFlag] = useState<PreviewFlag | null>(
items[0]?.flag ?? null,
);
// A removed preview falls back without synchronizing derived props into state.
const selected = items.find((i) => i.flag === selectedFlag) ?? items[0];
const selectedState = selected ? state[selected.flag] : undefined;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
size="lg"
closeOnInteractionOutside
overlayMode="blocking"
className="border-border bg-background text-foreground max-h-[88vh] p-0 shadow-2xl sm:rounded-2xl"
>
<DialogHeader>
<DialogTitle className="text-foreground text-lg font-bold">
{FEATURE_PREVIEW_MODAL_TITLE}
</DialogTitle>
<DialogDescription className="mt-0">
{FEATURE_PREVIEW_MODAL_SUBTITLE}
</DialogDescription>
</DialogHeader>
<DialogBody className="grid min-h-0 gap-0 overflow-hidden p-0 md:grid-cols-[220px_1fr]">
<aside className="border-border bg-muted/20 border-b p-3 md:border-r md:border-b-0">
<div className="flex gap-2 overflow-x-auto md:flex-col md:overflow-x-visible">
{items.map((item) => {
const isSelected = item.flag === selected?.flag;
return (
<button
key={item.flag}
type="button"
onClick={() => setSelectedFlag(item.flag)}
aria-pressed={isSelected}
className={cn(
"flex min-w-48 items-start rounded-md border px-3 py-3 text-left transition-colors md:min-w-0",
isSelected
? "bg-muted text-foreground border-transparent"
: "text-muted-foreground hover:bg-muted/50 border-transparent",
)}
>
<span className="min-w-0">
<span className="block text-sm font-bold">
{featurePreviewLabels[item.flag]}
</span>
<span className="text-muted-foreground mt-1 line-clamp-2 block text-xs">
{getPreviewStatusLabel(state[item.flag])}
</span>
</span>
</button>
);
})}
</div>
</aside>
<section className="bg-background min-h-0 overflow-y-auto p-6">
{selected && selectedState ? (
<>
{selectedState.warningReason ? (
<div className="mb-4 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-3 py-2 text-sm text-yellow-800 dark:text-yellow-200">
{selectedState.warningReason}
</div>
) : null}
<div className="flex items-start justify-between gap-6">
<div>
<h2 className="text-foreground text-xl font-bold">
{featurePreviewLabels[selected.flag]}
</h2>
<p className="text-muted-foreground mt-2 max-w-2xl text-sm">
{selected.description}
</p>
<Button asChild className="mt-4">
<a
href={selected.feedbackUrl}
target="_blank"
rel="noopener noreferrer"
>
Give feedback
</a>
</Button>
</div>
<div className="flex shrink-0 flex-col items-end gap-2">
<Switch
checked={selectedState.enabled}
disabled={
selectedState.disabled === true ||
selectedState.isToggling === true
}
onCheckedChange={selectedState.onToggle}
aria-label={`Toggle ${featurePreviewLabels[selected.flag]}`}
/>
</div>
</div>
{selected.flag === "sessionViewV2" &&
state.sessionViewV2Timeline ? (
<div className="border-border mt-5 flex items-start justify-between gap-6 border-t pt-5">
<div>
<h3 className="text-foreground text-sm font-bold">
{featurePreviewLabels.sessionViewV2Timeline}
</h3>
<p className="text-muted-foreground mt-1 max-w-2xl text-sm">
Use the redesigned timeline to navigate session events
in chronological order.
</p>
{state.sessionViewV2Timeline.warningReason ? (
<p className="mt-2 text-xs text-yellow-800 dark:text-yellow-200">
{state.sessionViewV2Timeline.warningReason}
</p>
) : null}
</div>
<Switch
checked={state.sessionViewV2Timeline.enabled}
disabled={
state.sessionViewV2Timeline.disabled === true ||
state.sessionViewV2Timeline.isToggling === true
}
onCheckedChange={state.sessionViewV2Timeline.onToggle}
aria-label={`Toggle ${featurePreviewLabels.sessionViewV2Timeline}`}
/>
</div>
) : null}
{selected.illustration && (
<PreviewMockupPanel illustration={selected.illustration} />
)}
<p className="text-muted-foreground mt-5 text-sm">
{selected.details}
</p>
</>
) : null}
</section>
</DialogBody>
</DialogContent>
</Dialog>
);
}
function getPreviewStatusLabel(state: PreviewState | undefined) {
if (state?.enabled) return "Enabled";
if (state?.disabled) return "Unavailable";
return "Available";
}
function PreviewMockupPanel({
illustration,
}: {
illustration: PreviewIllustration;
}) {
return (
<div className="border-border bg-muted/30 mt-6 overflow-hidden rounded-2xl border shadow-inner">
<Image
src={illustration.light}
alt={illustration.alt}
width={illustration.width}
height={illustration.height}
className="block h-auto w-full dark:hidden"
/>
<Image
src={illustration.dark}
alt={illustration.alt}
width={illustration.width}
height={illustration.height}
className="hidden h-auto w-full dark:block"
/>
</div>
);
}