🪢 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
refactor(web): thin fat pages into feature Page components (#17711)
Nikita Kabardin967806c43ab9
diff --git a/web/src/__tests__/account-settings-sign-out-all-sessions.clienttest.tsx b/web/src/__tests__/account-settings-sign-out-all-sessions.clienttest.tsxindex 3504a05445..766f8d9e03 100644--- a/web/src/__tests__/account-settings-sign-out-all-sessions.clienttest.tsx+++ b/web/src/__tests__/account-settings-sign-out-all-sessions.clienttest.tsx@@ -95,7 +95,7 @@ vi.mock("@/src/features/v4-migration/useV4UpgradeUiEnabled", () => ({useV4UpgradeUiFlag: () => false,}));-import AccountSettingsPage from "@/src/pages/account/settings/index";+import AccountSettingsPage from "@/src/features/account/AccountSettingsPage";describe("SignOutAllSessionsButton", () => {beforeEach(() => {diff --git a/web/src/__tests__/organization-settings-pages.clienttest.tsx b/web/src/__tests__/organization-settings-pages.clienttest.tsxindex ce6c563708..43c6569d9c 100644--- a/web/src/__tests__/organization-settings-pages.clienttest.tsx+++ b/web/src/__tests__/organization-settings-pages.clienttest.tsx@@ -6,7 +6,7 @@ import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";import { useIsCloudBillingAvailable } from "@/src/ee/features/billing/utils/isCloudBilling";import { useV4UpgradeUiFlag } from "@/src/features/v4-migration/useV4UpgradeUiEnabled";-import { useOrganizationSettingsPages } from "@/src/pages/organization/[organizationId]/settings";+import { useOrganizationSettingsPages } from "@/src/features/organizations/OrganizationSettingsPage";vi.mock("@/src/components/PagedSettingsContainer", () => ({PagedSettingsContainer: () => null,diff --git a/web/src/features/account/AccountSettingsPage.tsx b/web/src/features/account/AccountSettingsPage.tsxnew file mode 100644index 0000000000..8fb5e72873--- /dev/null+++ b/web/src/features/account/AccountSettingsPage.tsx@@ -0,0 +1,392 @@+/* eslint-disable @repo/no-abstracted-overlay-trigger */+import { PagedSettingsContainer } from "@/src/components/PagedSettingsContainer";+import Header from "@/src/components/layouts/header";+import { Card } from "@/src/components/ui/card";+import { Button } from "@/src/components/ui/button";+import { Input } from "@/src/components/ui/input";+import { api, reportNonTrpcError } from "@/src/utils/api";+import * as z from "zod";+import { zodResolver } from "@hookform/resolvers/zod";+import { useForm } from "react-hook-form";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormMessage,+} from "@/src/components/ui/form";+import {+ Dialog,+ DialogBody,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/src/components/ui/dialog";+import { useSession } from "next-auth/react";+import { signOutCleanly } from "@/src/features/auth/lib/signOut";+import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";+import ContainerPage from "@/src/components/layouts/container-page";+import { useRouter } from "next/router";+import { StringNoHTML } from "@langfuse/shared";+import Link from "next/link";+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";+import { showErrorToast } from "@/src/features/notifications/showErrorToast";+import { useV4UpgradeUiFlag } from "@/src/features/v4-migration/useV4UpgradeUiEnabled";+import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";++const displayNameSchema = z.object({+ name: StringNoHTML.min(1, "Name cannot be empty").max(+ 100,+ "Name must be at most 100 characters",+ ),+});++function UpdateDisplayName() {+ const { data: session, update: updateSession } = useSession();+ const utils = api.useUtils();++ const form = useForm({+ resolver: zodResolver(displayNameSchema),+ defaultValues: {+ name: "",+ },+ });++ const updateDisplayName = api.userAccount.updateDisplayName.useMutation({+ onSuccess: async () => {+ await updateSession();+ await utils.invalidate();+ form.reset();+ showSuccessToast({+ title: "Display Name Updated",+ description: "Your display name has been successfully updated.",+ });+ },+ onError: (error) => form.setError("name", { message: error.message }),+ });++ function onSubmit(values: z.infer<typeof displayNameSchema>) {+ updateDisplayName.mutate({ name: values.name });+ }++ return (+ <div>+ <Header title="Display Name" />+ <Card className="p-3">+ {form.getValues().name !== "" ? (+ <p className="text-primary mb-4 text-sm">+ Your display name will be updated from "+ {session?.user?.name ?? ""}+ " to "+ <b>{form.watch().name}</b>".+ </p>+ ) : (+ <p className="text-primary mb-4 text-sm">+ Your display name is currently "+ <b>{session?.user?.name ?? ""}</b>+ ".+ </p>+ )}+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex-1">+ <FormField+ control={form.control}+ name="name"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input+ placeholder={session?.user?.name ?? ""}+ {...field}+ className="flex-1"+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <Button+ variant="secondary"+ type="submit"+ loading={updateDisplayName.isPending}+ disabled={form.getValues().name === ""}+ className="mt-4"+ >+ Save+ </Button>+ </form>+ </Form>+ </Card>+ </div>+ );+}++function DeleteAccountButton() {+ const { data: session } = useSession();+ const userEmail = session?.user?.email ?? "";++ const { data: canDeleteData } = api.userAccount.checkCanDelete.useQuery();+ const deleteAccount = api.userAccount.delete.useMutation();++ const formSchema = z.object({+ email: z.string().refine((val) => val === userEmail, {+ message: `Please enter your email address: ${userEmail}`,+ }),+ });++ const form = useForm({+ resolver: zodResolver(formSchema),+ defaultValues: {+ email: "",+ },+ });++ const canDelete = canDeleteData?.canDelete ?? false;+ const blockingOrganizations = canDeleteData?.blockingOrganizations ?? [];++ const onSubmit = async () => {+ if (!canDelete) return;+ try {+ await deleteAccount.mutateAsync();+ showSuccessToast({+ title: "Account Deleted",+ description: "Your account has been successfully deleted.",+ });+ await new Promise((resolve) => setTimeout(resolve, 2000));+ await signOutCleanly();+ } catch (error) {+ reportNonTrpcError(error, "account");+ showErrorToast(+ "Failed to Delete Account",+ error instanceof Error ? error.message : "An unexpected error occurred",+ );+ }+ };++ return (+ <Dialog>+ <DialogTrigger asChild>+ <Button variant="destructive-secondary">Delete Account</Button>+ </DialogTrigger>+ <DialogContent className="sm:max-w-[425px]">+ <DialogHeader>+ <DialogTitle className="text-lg font-bold">+ Delete Account+ </DialogTitle>+ <DialogDescription>+ {!canDelete && blockingOrganizations.length > 0 ? (+ <div>+ <p className="mb-2">+ You cannot delete your account because you are the last owner+ of the following organization(s):+ </p>+ <ul className="list-inside list-disc space-y-1">+ {blockingOrganizations.map((org) => (+ <li key={org.id}>+ <Link+ href={`/organization/${org.id}/settings`}+ className="text-primary hover:text-primary/80 font-bold underline"+ >+ {org.name}+ </Link>+ </li>+ ))}+ </ul>+ <p className="mt-2">+ Please add another owner or delete these organizations before+ deleting your account.+ </p>+ </div>+ ) : (+ `To confirm, type your email address "${userEmail}" in the input box`+ )}+ </DialogDescription>+ </DialogHeader>+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">+ {canDelete && (+ <DialogBody>+ <FormField+ control={form.control}+ name="email"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input placeholder={userEmail} {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </DialogBody>+ )}+ <DialogFooter>+ <Button+ type="submit"+ variant="destructive"+ loading={deleteAccount.isPending}+ disabled={!canDelete}+ className="w-full"+ >+ Delete Account+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}++function SignOutAllSessionsButton() {+ const signOutAllSessions = api.userAccount.signOutAllSessions.useMutation();++ const onConfirm = async () => {+ try {+ await signOutAllSessions.mutateAsync();+ showSuccessToast({+ title: "Signed Out of All Sessions",+ description: "All sessions have been invalidated.",+ });+ } catch (error) {+ reportNonTrpcError(error, "account");+ showErrorToast(+ "Failed to Sign Out of All Sessions",+ error instanceof Error ? error.message : "An unexpected error occurred",+ );+ throw error;+ }++ // Sessions are already revoked server-side at this point, so a failure to+ // clear local state must not be reported as a failed revocation.+ try {+ await signOutCleanly();+ } catch (error) {+ reportNonTrpcError(error, "account");+ }+ };++ return (+ <ConfirmationDialogController+ title="Sign Out of All Sessions"+ text="This will sign you out on this device and every other device where you are currently signed in. You will need to sign in again."+ confirmLabel="Sign Out of All Sessions"+ variant="destructive"+ loading={signOutAllSessions.isPending}+ onConfirm={onConfirm}+ >+ {({ openDialog }) => (+ <Button variant="destructive-secondary" onClick={openDialog}>+ Sign Out of All Sessions+ </Button>+ )}+ </ConfirmationDialogController>+ );+}++type AccountSettingsPage = {+ title: string;+ slug: string;+ show?: boolean | (() => boolean);+ cmdKKeywords?: string[];+} & ({ content: React.ReactNode } | { href: string });++export function useAccountSettingsPages(): AccountSettingsPage[] {+ const { data: session } = useSession();+ const userEmail = session?.user?.email ?? "";+ const showV4Migration = useV4UpgradeUiFlag();++ return getAccountSettingsPages({ userEmail, showV4Migration });+}++const getAccountSettingsPages = ({+ userEmail,+ showV4Migration,+}: {+ userEmail: string;+ showV4Migration: boolean;+}): AccountSettingsPage[] => [+ {+ title: "General",+ slug: "index",+ cmdKKeywords: [+ "account",+ "user",+ "profile",+ "email",+ "password",+ "name",+ "display",+ "delete",+ "remove",+ ],+ content: (+ <div className="flex flex-col gap-6">+ <div>+ <Header title="Email" />+ <Card className="p-3">+ <p className="text-primary text-sm">+ Your email address: <b>{userEmail}</b>+ </p>+ </Card>+ </div>+ <UpdateDisplayName />+ <div>+ <Header title="Password" />+ <Card className="p-3">+ <p className="text-primary mb-4 text-sm">+ To change your password, we will email a one-time code to your+ address. Enter the code together with your new password.+ </p>+ <Button asChild variant="secondary">+ <Link href="/auth/reset-password">Change Password</Link>+ </Button>+ </Card>+ </div>+ <SettingsDangerZone+ items={[+ {+ title: "Sign out of all sessions",+ description:+ "Invalidate every active session for your account, including this device. You will need to sign in again.",+ button: <SignOutAllSessionsButton />,+ },+ {+ title: "Delete your account",+ description:+ "You can delete your account if you are not the last owner of any organization. If you are the last owner, please add another owner or delete the organization and all projects first.",+ button: <DeleteAccountButton />,+ },+ ]}+ />+ </div>+ ),+ },+ {+ title: "v4 Migration",+ slug: "v4-migration",+ href: "/v4-migration",+ show: showV4Migration,+ },+];++export default function AccountSettingsPage() {+ const router = useRouter();+ const pages = useAccountSettingsPages();++ return (+ <ContainerPage+ headerProps={{+ title: "Account Settings",+ }}+ >+ <PagedSettingsContainer+ activeSlug={router.query.page as string | undefined}+ pages={pages}+ />+ </ContainerPage>+ );+}diff --git a/web/src/features/account/index.ts b/web/src/features/account/index.tsnew file mode 100644index 0000000000..ac4b307541--- /dev/null+++ b/web/src/features/account/index.ts@@ -0,0 +1 @@+export { useAccountSettingsPages } from "@/src/features/account/AccountSettingsPage";diff --git a/web/src/features/auth/EnterpriseSsoRequiredPage.tsx b/web/src/features/auth/EnterpriseSsoRequiredPage.tsxnew file mode 100644index 0000000000..c36a686325--- /dev/null+++ b/web/src/features/auth/EnterpriseSsoRequiredPage.tsx@@ -0,0 +1,233 @@+import Head from "next/head";+import Link from "next/link";+import { useRouter } from "next/router";+import { useEffect, useMemo, useState } from "react";+import { signIn } from "next-auth/react";+import { zodResolver } from "@hookform/resolvers/zod";+import * as z from "zod";+import { useForm } from "react-hook-form";+import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";+import { Button } from "@/src/components/ui/button";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/src/components/ui/form";+import { Input } from "@/src/components/ui/input";+import { env } from "@/src/env.mjs";+import { reportError } from "@/src/utils/reportError";+import { isJsonParseSyntaxError } from "@/src/features/auth/lib/expectedAuthErrors";++const enterpriseSsoFormSchema = z.object({+ email: z.email(),+});++const PROVIDER_LABELS: Record<string, string> = {+ google: "Google",+ github: "GitHub",+ "github-enterprise": "GitHub Enterprise",+ gitlab: "GitLab",+ "azure-ad": "Azure AD",+ okta: "Okta",+ authentik: "Authentik",+ onelogin: "OneLogin",+ auth0: "Auth0",+ cognito: "Cognito",+ keycloak: "Keycloak",+ jumpcloud: "JumpCloud",+ workos: "WorkOS",+ wordpress: "WordPress",+ custom: "Custom OAuth",+};++export default function EnterpriseSsoRequiredPage() {+ const router = useRouter();+ const [error, setError] = useState<string | null>(null);+ const [loading, setLoading] = useState(false);++ const emailFromQuery =+ typeof router.query.email === "string" ? router.query.email : "";+ const attemptedProvider =+ typeof router.query.attemptedProvider === "string"+ ? router.query.attemptedProvider+ : undefined;+ const callbackUrl =+ typeof router.query.callbackUrl === "string"+ ? router.query.callbackUrl+ : undefined;++ const friendlyProviderName = useMemo(() => {+ if (!attemptedProvider) return undefined;+ return (+ PROVIDER_LABELS[attemptedProvider] ?? attemptedProvider.replace(/-/g, " ")+ );+ }, [attemptedProvider]);++ const form = useForm<z.infer<typeof enterpriseSsoFormSchema>>({+ resolver: zodResolver(enterpriseSsoFormSchema),+ defaultValues: {+ email: emailFromQuery,+ },+ });++ useEffect(() => {+ if (emailFromQuery) {+ form.setValue("email", emailFromQuery);+ }+ }, [emailFromQuery, form]);++ async function onSubmit(values: z.infer<typeof enterpriseSsoFormSchema>) {+ setError(null);+ setLoading(true);++ const domain = values.email.split("@")[1]?.toLowerCase();+ if (!domain) {+ form.setError("email", { message: "Invalid email address" });+ setLoading(false);+ return;+ }++ try {+ const response = await fetch(+ `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/auth/check-sso`,+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ domain }),+ },+ );++ if (response.ok) {+ const { providerId } = (await response.json()) as {+ providerId: string;+ };+ await signIn(providerId, {+ callbackUrl,+ });+ return;+ }++ if (response.status === 404) {+ setError(+ "We couldn't find a custom Enterprise SSO configuration for this domain. Double-check your company email or contact your administrator.",+ );+ return;+ }++ const data = (await response.json().catch(() => null)) as {+ message?: string;+ } | null;+ setError(+ data?.message ??+ "Unable to start the Enterprise SSO sign-in flow. Please try again.",+ );+ } catch (err) {+ reportError(err, {+ area: "auth.enterpriseSso",+ expected: isJsonParseSyntaxError(err),+ extra: { context: "auth.enterpriseSso" },+ });+ setError(+ "Something went wrong while checking your Enterprise SSO configuration. Please try again.",+ );+ } finally {+ setLoading(false);+ }+ }++ const description = friendlyProviderName+ ? `You tried signing in with ${friendlyProviderName}, but this domain requires your company's custom Enterprise SSO.`+ : "This domain requires your company's custom Enterprise SSO.";++ return (+ <>+ <Head>+ <title>Enterprise SSO Required | Langfuse</title>+ </Head>+ <div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8">+ <div className="sm:mx-auto sm:w-full sm:max-w-md">+ <div className="mx-auto w-fit">+ <LangfuseIcon />+ </div>+ <h1 className="text-primary mt-6 text-center text-2xl font-bold">+ Use your Enterprise SSO+ </h1>+ <p className="text-muted-foreground mt-2 text-center text-sm leading-6">+ {description} Enter your company email so we can send you to the+ correct identity provider.+ </p>+ </div>++ <div className="border-border bg-card mt-10 rounded-lg border px-6 py-8 shadow-sm sm:mx-auto sm:w-full sm:max-w-md">+ <Form {...form}>+ <form className="space-y-6" onSubmit={form.handleSubmit(onSubmit)}>+ <FormField+ control={form.control}+ name="email"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Email</FormLabel>+ <FormControl>+ <Input+ placeholder="[email protected]"+ allowPasswordManager+ autoComplete="email"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <Button+ type="submit"+ className="w-full"+ loading={loading}+ disabled={loading}+ >+ Continue with Enterprise SSO+ </Button>+ </form>+ </Form>+ {error ? (+ <div className="text-destructive mt-4 text-center text-sm font-bold">+ {error}+ <br />+ Contact{" "}+ <a+ href="mailto:[email protected]"+ className="text-link hover:text-link-hover"+ >+ </a>{" "}+ if this keeps happening.+ </div>+ ) : null}+ <div className="text-muted-foreground mt-6 text-center text-sm">+ <Link+ href="/auth/sign-in"+ className="text-link hover:text-link-hover"+ >+ Back to other sign-in options+ </Link>+ </div>+ </div>++ <div className="text-muted-foreground mt-4 text-center text-xs">+ Need help? Contact{" "}+ <a+ href="mailto:[email protected]"+ className="text-link hover:text-link-hover"+ >+ </a>+ .+ </div>+ </div>+ </>+ );+}diff --git a/web/src/features/command-k-menu/CommandMenu.tsx b/web/src/features/command-k-menu/CommandMenu.tsxindex fdb12bce47..e8d6c60af1 100644--- a/web/src/features/command-k-menu/CommandMenu.tsx+++ b/web/src/features/command-k-menu/CommandMenu.tsx@@ -16,8 +16,8 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import { useDebounce } from "@/src/hooks/useDebounce";import { useCommandMenu } from "@/src/features/command-k-menu/CommandMenuProvider";import { useProjectSettingsPages } from "@/src/features/projects";-import { useOrganizationSettingsPages } from "@/src/pages/organization/[organizationId]/settings";-import { useAccountSettingsPages } from "@/src/pages/account/settings";+import { useOrganizationSettingsPages } from "@/src/features/organizations";+import { useAccountSettingsPages } from "@/src/features/account";import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";import { api } from "@/src/utils/api";import { type NavigationItem } from "@/src/components/layouts/utilities/routes";diff --git a/web/src/features/datasets/DatasetCompareChartsPage.tsx b/web/src/features/datasets/DatasetCompareChartsPage.tsxnew file mode 100644index 0000000000..942ca4f960--- /dev/null+++ b/web/src/features/datasets/DatasetCompareChartsPage.tsx@@ -0,0 +1,333 @@+/* eslint-disable no-nested-ternary */+import { Button } from "@/src/components/ui/button";+import { MultiSelectKeyValues } from "@/src/features/scores/components/multi-select-key-values";+import { FlaskConical, List } from "lucide-react";+import { useRouter } from "next/router";+import { useEffect, useState } from "react";+import { MarkdownJsonView } from "@/src/components/ui/MarkdownJsonView";+import {+ Dialog,+ DialogContent,+ DialogTrigger,+} from "@/src/components/ui/dialog";+import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import { DatasetAnalytics } from "@/src/features/datasets/components/DatasetAnalytics";+import { CompareViewAdapter } from "@/src/features/scores/adapters";+import {+ RESOURCE_METRICS,+ isEmptyChart,+} from "@/src/features/dashboard/lib/score-analytics-utils";+import {+ compareViewChartDataToDataPoints,+ getCompareViewChartUnit,+} from "@/src/features/dashboard/lib/chart-data-adapters";+import { Chart } from "@/src/features/widgets/chart-library/Chart";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import Page from "@/src/components/layouts/page";+import { SubHeaderLabel } from "@/src/components/layouts/header";+import {+ SidePanel,+ SidePanelContent,+ SidePanelHeader,+ SidePanelTitle,+} from "@/src/components/ui/side-panel";+import useLocalStorage from "@/src/components/useLocalStorage";+import { getScoreDataTypeIcon } from "@/src/features/scores/lib/scoreColumns";+import { useDatasetRunsCompare } from "@/src/features/datasets/hooks/useDatasetRunsCompare";+import { useDatasetRunCompareChartData } from "@/src/features/datasets/hooks/useDatasetRunCompareChartData";+import { Skeleton } from "@/src/components/ui/skeleton";+import {+ DATASET_RUN_COMPARE_TABS,+ getDatasetRunCompareTabs,+} from "@/src/features/navigation/utils/dataset-run-compare-tabs";+import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";+import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";+import { toExperimentsResultsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";++function DatasetCompareChartsLegacy() {+ const router = useRouter();+ const capture = usePostHogClientCapture();+ const projectId = router.query.projectId as string;+ const datasetId = router.query.datasetId as string;++ const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =+ useState(false);++ const [selectedMetrics, setSelectedMetrics] = useLocalStorage<string[]>(+ `${projectId}-dataset-compare-metrics`,+ RESOURCE_METRICS.map((metric) => metric.key),+ );++ const hasExperimentWriteAccess = useHasProjectAccess({+ projectId,+ scope: "promptExperiments:CUD",+ });++ const {+ runIds,+ runs,+ dataset,+ handleExperimentSettled: handleExperimentSettledBase,+ setRunState,+ setLocalRuns,+ } = useDatasetRunsCompare(projectId, datasetId);++ const { chartDataMap, scoreAnalyticsOptions, scoreKeyToData, isLoading } =+ useDatasetRunCompareChartData(projectId, datasetId, runIds);++ const handleExperimentSettled = async (data?: {+ success: boolean;+ datasetId: string;+ runId: string;+ runName: string;+ }) => {+ setIsCreateExperimentDialogOpen(false);+ await handleExperimentSettledBase(data);+ };++ return (+ <Page+ headerProps={{+ title: `Compare experiments: ${dataset.data?.name ?? datasetId}`,+ tabsProps: {+ tabs: getDatasetRunCompareTabs(projectId, datasetId),+ activeTab: DATASET_RUN_COMPARE_TABS.CHARTS,+ },+ breadcrumb: [+ {+ name: "Datasets",+ href: `/project/${projectId}/datasets`,+ },+ {+ name: dataset.data?.name ?? datasetId,+ href: `/project/${projectId}/datasets/${datasetId}`,+ },+ {+ name: "Experiments",+ href: `/project/${projectId}/datasets/${datasetId}/experiments`,+ },+ ],+ help: {+ description: "Compare your experiments side by side",+ },+ actionButtonsRight: (+ <>+ <Dialog+ key="create-experiment-dialog"+ open={isCreateExperimentDialogOpen}+ onOpenChange={setIsCreateExperimentDialogOpen}+ >+ <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>+ <Button+ variant="outline"+ disabled={!hasExperimentWriteAccess}+ onClick={() => capture("dataset_run:new_form_open")}+ >+ <FlaskConical className="h-4 w-4" />+ <span className="ml-2 hidden md:block">New experiment</span>+ </Button>+ </DialogTrigger>+ <DialogContent className="max-h-[90vh] overflow-y-auto">+ <CreateExperimentsForm+ key={`create-experiment-form-${datasetId}`}+ projectId={projectId as string}+ setFormOpen={setIsCreateExperimentDialogOpen}+ defaultValues={{+ datasetId,+ }}+ handleExperimentSettled={handleExperimentSettled}+ showSDKRunInfoPage+ />+ </DialogContent>+ </Dialog>+ <MultiSelectKeyValues+ key="select-runs"+ title="Experiments"+ showSelectedValueStrings={false}+ placeholder="Select runs to compare"+ className="w-fit"+ variant="outline"+ hideClearButton+ iconLeft={<List className="mr-2 h-4 w-4" />}+ options={runs.map((run) => ({+ key: run.key,+ value: run.value,+ disabled: runIds?.includes(run.key) && runIds.length === 1,+ }))}+ values={runs.filter((run) => runIds?.includes(run.key))}+ onValueChange={(values, changedValueId, selectedValueKeys) => {+ if (values.length === 0) return;+ if (changedValueId) {+ if (selectedValueKeys?.has(changedValueId)) {+ capture("dataset_run:compare_run_added");+ setRunState({+ runs: [...(runIds ?? []), changedValueId],+ });+ setLocalRuns([]);+ } else {+ capture("dataset_run:compare_run_removed");+ setRunState({+ runs: runIds?.filter((id) => id !== changedValueId) ?? [],+ });+ setLocalRuns([]);+ }+ }+ }}+ />+ </>+ ),+ }}+ >+ <div className="grid flex-1 grid-cols-[1fr_auto] overflow-hidden">+ <div className="flex h-full flex-col gap-2 overflow-hidden px-3 py-2">+ <div className="flex w-full justify-end">+ <DatasetAnalytics+ key="dataset-analytics"+ scoreOptions={scoreAnalyticsOptions}+ selectedMetrics={selectedMetrics}+ setSelectedMetrics={setSelectedMetrics}+ />+ </div>+ <div className="overflow-y-auto">+ {Boolean(selectedMetrics.length) && Boolean(chartDataMap?.size) ? (+ <div className="grid w-full grid-cols-2 gap-4 xl:grid-cols-3">+ {selectedMetrics.map((key) => {+ if (isLoading) {+ return <Skeleton key={key} className="h-52 w-full" />;+ }++ const adapter = new CompareViewAdapter(chartDataMap, key);+ const { chartData, chartLabels } = adapter.toChartData();++ const scoreData = scoreKeyToData.get(key);+ const title = scoreData+ ? `${getScoreDataTypeIcon(scoreData.dataType)} ${scoreData.name} (${scoreData.source.toLowerCase()})`+ : (RESOURCE_METRICS.find((metric) => metric.key === key)+ ?.label ?? key);++ if (isEmptyChart({ data: chartData })) {+ return (+ <div+ key={key}+ className="flex min-h-[200px] max-w-full min-w-0 flex-col gap-2"+ >+ <span className="shrink-0 text-sm font-bold">+ {title}+ </span>+ <NoDataOrLoading+ isLoading={false}+ className="min-h-32 flex-1"+ />+ </div>+ );+ }++ const dataPoints = compareViewChartDataToDataPoints(+ chartData,+ chartLabels,+ key,+ );++ const chartType =+ chartLabels.length === 1+ ? "LINE_TIME_SERIES"+ : "BAR_TIME_SERIES";++ return (+ <div+ key={key}+ className="flex min-h-[200px] max-w-full min-w-0 flex-col gap-2"+ >+ <span className="shrink-0 text-sm font-bold">+ {title}+ </span>+ <div className="min-h-[200px] min-w-0 flex-1">+ <Chart+ chartType={chartType}+ data={dataPoints}+ rowLimit={Math.max(dataPoints.length, 1)}+ chartConfig={{+ type: chartType,+ unit: getCompareViewChartUnit(key),+ }}+ // The x-axis is dataset-run names — long and cluttered;+ // show them on hover instead of on the axis.+ hideXAxisLabels+ />+ </div>+ </div>+ );+ })}+ </div>+ ) : isLoading ? (+ <Skeleton className="h-52 w-full" />+ ) : (+ <span className="text-muted-foreground -mt-2 text-sm">+ {Boolean(chartDataMap?.size)+ ? "All charts hidden. Enable them in the Charts dropdown."+ : "Select more than one run to generate charts."}+ </span>+ )}+ </div>+ </div>+ <SidePanel+ mobileTitle={dataset.data?.name ?? datasetId}+ id="compare-dataset-runs"+ scrollable={false}+ >+ <SidePanelHeader>+ <SidePanelTitle>{dataset.data?.name}</SidePanelTitle>+ </SidePanelHeader>+ <SidePanelContent className="overflow-y-auto p-1">+ <div className="w-full space-y-4">+ <div>+ <SubHeaderLabel title="Description" />+ <span className="text-muted-foreground text-sm">+ {dataset.data?.description ?? "No description"}+ </span>+ </div>+ {dataset.data?.metadata && (+ <div>+ <SubHeaderLabel title="Metadata" />+ <MarkdownJsonView content={dataset.data?.metadata} />+ </div>+ )}+ </div>+ </SidePanelContent>+ </SidePanel>+ </div>+ </Page>+ );+}++function asArrayValue(value: string | string[] | undefined) {+ if (!value) return [];+ return Array.isArray(value) ? value : [value];+}++export default function DatasetCompareChartsPage() {+ const router = useRouter();+ const projectId = router.query.projectId as string;+ const runsQuery = router.query.runs;+ const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();++ useEffect(() => {+ if (+ !router.isReady ||+ isInitializing ||+ !isExperimentsBetaActive ||+ !projectId+ ) {+ return;+ }++ router.replace(toExperimentsResultsUrl(projectId, asArrayValue(runsQuery)));+ }, [isExperimentsBetaActive, isInitializing, projectId, router, runsQuery]);++ if (!router.isReady || isInitializing || isExperimentsBetaActive) {+ return <Skeleton className="h-full w-full" />;+ }++ return <DatasetCompareChartsLegacy />;+}diff --git a/web/src/features/datasets/DatasetComparePage.tsx b/web/src/features/datasets/DatasetComparePage.tsxnew file mode 100644index 0000000000..2f77736f85--- /dev/null+++ b/web/src/features/datasets/DatasetComparePage.tsx@@ -0,0 +1,267 @@+import { Button } from "@/src/components/ui/button";+import { DatasetCompareRunsTable } from "@/src/features/datasets/components/DatasetCompareRunsTable";+import { MultiSelectKeyValues } from "@/src/features/scores/components/multi-select-key-values";+import { FlaskConical, List } from "lucide-react";+import { useRouter } from "next/router";+import { useEffect, useState } from "react";+import {+ Dialog,+ DialogContent,+ DialogTrigger,+} from "@/src/components/ui/dialog";+import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import Page from "@/src/components/layouts/page";+import {+ DATASET_RUN_COMPARE_TABS,+ getDatasetRunCompareTabs,+} from "@/src/features/navigation/utils/dataset-run-compare-tabs";+import { useDatasetRunsCompare } from "@/src/features/datasets/hooks/useDatasetRunsCompare";+import {+ ActiveCellProvider,+ useActiveCell,+} from "@/src/features/datasets/contexts/ActiveCellContext";+import { SidePanel, SidePanelContent } from "@/src/components/ui/side-panel";+import { AnnotationPanel } from "@/src/features/datasets/components/AnnotationPanel";+import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";+import { toExperimentsResultsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";+import { Spinner } from "@/src/components/design-system/Spinner/Spinner";++function DatasetCompareLegacy() {+ const router = useRouter();+ const capture = usePostHogClientCapture();+ const projectId = router.query.projectId as string;+ const datasetId = router.query.datasetId as string;++ const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =+ useState(false);+ const [isAnnotationPanelOpen, setIsAnnotationPanelOpen] = useState(false);++ const hasExperimentWriteAccess = useHasProjectAccess({+ projectId,+ scope: "promptExperiments:CUD",+ });++ const {+ runIds,+ runs,+ dataset,+ runsData,+ handleExperimentSettled: handleExperimentSettledBase,+ setRunState,+ setLocalRuns,+ } = useDatasetRunsCompare(projectId, datasetId);++ const { activeCell, clearActiveCell } = useActiveCell();++ const handleExperimentSettled = async (data?: {+ success: boolean;+ datasetId: string;+ runId: string;+ runName: string;+ }) => {+ setIsCreateExperimentDialogOpen(false);+ await handleExperimentSettledBase(data);+ };++ // Clear annotation state on URL change (filters, navigation, etc.)+ useEffect(() => {+ clearActiveCell();+ }, [router.query, clearActiveCell]);++ // Open panel when cell becomes active, close when cleared+ useEffect(() => {+ setIsAnnotationPanelOpen(!!activeCell);+ }, [activeCell]);++ // Clear active cell when panel manually closed+ const handlePanelOpenChange = (open: boolean) => {+ if (!open) {+ clearActiveCell();+ }+ setIsAnnotationPanelOpen(open);+ };++ if (!runsData.data || runs.length === 0) {+ return (+ <div className="flex h-full items-center justify-center">+ <Spinner size="xl" variant="muted" />+ </div>+ );+ }++ return (+ <Page+ headerProps={{+ title: `Compare runs: ${dataset.data?.name ?? datasetId}`,+ breadcrumb: [+ {+ name: "Datasets",+ href: `/project/${projectId}/datasets`,+ },+ {+ name: dataset.data?.name ?? datasetId,+ href: `/project/${projectId}/datasets/${datasetId}`,+ },+ {+ name: "Experiments",+ href: `/project/${projectId}/datasets/${datasetId}/experiments`,+ },+ ],+ help: {+ description: "Compare your dataset runs side by side",+ },+ tabsProps: {+ tabs: getDatasetRunCompareTabs(projectId, datasetId),+ activeTab: DATASET_RUN_COMPARE_TABS.COMPARE,+ },+ actionButtonsRight: (+ <>+ <Dialog+ key="create-experiment-dialog"+ open={isCreateExperimentDialogOpen}+ onOpenChange={setIsCreateExperimentDialogOpen}+ >+ <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>+ <Button+ variant="outline"+ disabled={!hasExperimentWriteAccess}+ onClick={() => capture("dataset_run:new_form_open")}+ >+ <FlaskConical className="h-4 w-4" />+ <span className="ml-2 hidden md:block">New experiment</span>+ </Button>+ </DialogTrigger>+ <DialogContent className="max-h-[90vh] overflow-y-auto">+ <CreateExperimentsForm+ key={`create-experiment-form-${datasetId}`}+ projectId={projectId as string}+ setFormOpen={setIsCreateExperimentDialogOpen}+ defaultValues={{+ datasetId,+ }}+ handleExperimentSettled={handleExperimentSettled}+ showSDKRunInfoPage+ />+ </DialogContent>+ </Dialog>+ <MultiSelectKeyValues+ key="select-runs"+ title="Experiments"+ showSelectedValueStrings={false}+ placeholder="Select runs to compare"+ className="w-fit"+ variant="outline"+ hideClearButton+ iconLeft={<List className="mr-2 h-4 w-4" />}+ options={runs.map((run) => ({+ key: run.key,+ value: run.value,+ disabled: runIds?.includes(run.key) && runIds.length === 1,+ }))}+ values={runs.filter((run) => runIds?.includes(run.key))}+ onValueChange={(values, changedValueId, selectedValueKeys) => {+ if (values.length === 0) return;+ if (changedValueId) {+ if (selectedValueKeys?.has(changedValueId)) {+ capture("dataset_run:compare_run_added");+ setRunState({+ runs: [...(runIds ?? []), changedValueId],+ });+ setLocalRuns([]);+ } else {+ capture("dataset_run:compare_run_removed");+ const newRunIds =+ runIds?.filter((id) => id !== changedValueId) ?? [];++ // Clear baseline if the removed run was the baseline+ const baselineRunId = router.query.baseline as+ | string+ | undefined;+ if (baselineRunId === changedValueId) {+ const { baseline, ...restQuery } = router.query;+ router.push({+ pathname: router.pathname,+ query: { ...restQuery, runs: newRunIds },+ });+ } else {+ setRunState({ runs: newRunIds });+ }+ setLocalRuns([]);+ }+ }+ }}+ />+ </>+ ),+ }}+ >+ <div className="grid flex-1 grid-cols-[1fr_auto] overflow-hidden">+ <div className="flex h-full flex-col overflow-hidden">+ <DatasetCompareRunsTable+ key={runIds?.join(",") ?? "empty"}+ projectId={projectId}+ datasetId={datasetId}+ runIds={runIds ?? []}+ />+ </div>+ <SidePanel+ id="annotation-panel"+ openState={{+ open: isAnnotationPanelOpen,+ onOpenChange: handlePanelOpenChange,+ }}+ mobileTitle="Annotate"+ >+ <SidePanelContent className="h-full">+ {activeCell ? (+ <AnnotationPanel projectId={projectId} />+ ) : (+ <div className="flex items-center justify-center p-4">+ <span className="text-muted-foreground text-sm">+ Loading annotation data...+ </span>+ </div>+ )}+ </SidePanelContent>+ </SidePanel>+ </div>+ </Page>+ );+}++function asArrayValue(value: string | string[] | undefined) {+ if (!value) return [];+ return Array.isArray(value) ? value : [value];+}++export default function DatasetComparePage() {+ const router = useRouter();+ const projectId = router.query.projectId as string;+ const runsQuery = router.query.runs;+ const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();++ useEffect(() => {+ if (+ !router.isReady ||+ isInitializing ||+ !isExperimentsBetaActive ||+ !projectId+ ) {+ return;+ }++ router.replace(toExperimentsResultsUrl(projectId, asArrayValue(runsQuery)));+ }, [isExperimentsBetaActive, isInitializing, projectId, router, runsQuery]);++ if (!router.isReady || isInitializing || isExperimentsBetaActive) {+ return <Spinner size="xl" variant="muted" />;+ }++ return (+ <ActiveCellProvider>+ <DatasetCompareLegacy />+ </ActiveCellProvider>+ );+}diff --git a/web/src/features/datasets/DatasetExperimentsPage.tsx b/web/src/features/datasets/DatasetExperimentsPage.tsxnew file mode 100644index 0000000000..8f906351e3--- /dev/null+++ b/web/src/features/datasets/DatasetExperimentsPage.tsx@@ -0,0 +1,397 @@+import { DatasetRunsTable } from "@/src/features/datasets/components/DatasetRunsTable";+import { api } from "@/src/utils/api";+import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";+import { useState, useCallback } from "react";+import { FlaskConical, MoreVertical } from "lucide-react";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/src/components/ui/dialog";+import { Button } from "@/src/components/ui/button";+import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";+import { DatasetAnalytics } from "@/src/features/datasets/components/DatasetAnalytics";+import { RESOURCE_METRICS } from "@/src/features/dashboard/lib/score-analytics-utils";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import Page from "@/src/components/layouts/page";+import {+ getDatasetTabs,+ DATASET_TABS,+} from "@/src/features/navigation/utils/dataset-tabs";+import { TemplateSelector } from "@/src/features/evals/components/template-selector";+import { useEvaluatorDefaults } from "@/src/features/experiments/hooks/useEvaluatorDefaults";+import { useExperimentEvaluatorData } from "@/src/features/experiments/hooks/useExperimentEvaluatorData";+import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";+import {+ EvaluatorForm,+ useEvaluatorFormTemplate,+} from "@/src/features/evals/components/evaluator-form";+import useLocalStorage from "@/src/components/useLocalStorage";+import { getDatasetBreadcrumb } from "@/src/features/datasets/utils/getDatasetBreadcrumb";+import { ExperimentsTable } from "@/src/features/experiments/components/table";+import { singleRunToExperimentsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";+import { Skeleton } from "@/src/components/ui/skeleton";+import {+ RouteParamsPendingFallback,+ useReadyRouteParams,+} from "@/src/hooks/useReadyRouteParams";+import { DatasetActionMenu } from "@/src/features/datasets/components/DatasetActionMenu";++export default function DatasetExperimentsPage() {+ const route = useReadyRouteParams(["projectId", "datasetId"]);+ if (!route.ready) return <RouteParamsPendingFallback />;+ return (+ <DatasetExperimentsView+ projectId={route.params.projectId}+ datasetId={route.params.datasetId}+ />+ );+}++function DatasetExperimentsView({+ projectId,+ datasetId,+}: {+ projectId: string;+ datasetId: string;+}) {+ const capture = usePostHogClientCapture();+ const utils = api.useUtils();+ const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =+ useState(false);+ const [selectedMetrics, setSelectedMetrics] = useLocalStorage<string[]>(+ `${projectId}-${datasetId}-chart-metrics`,+ RESOURCE_METRICS.map((metric) => metric.key),+ );++ const [scoreOptions, setScoreOptions] = useState<+ {+ key: string;+ value: string;+ }[]+ >([]);++ const dataset = api.datasets.byId.useQuery(+ {+ datasetId,+ projectId,+ },+ { enabled: Boolean(projectId) && Boolean(datasetId) },+ );++ const hasReadAccess = useHasProjectAccess({+ projectId,+ scope: "evalJobExecution:read",+ });++ const hasExperimentWriteAccess = useHasProjectAccess({+ projectId,+ scope: "promptExperiments:CUD",+ });+ const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();++ const handleExperimentSuccess = async (data?: {+ success: boolean;+ datasetId: string;+ runId: string;+ runName: string;+ }) => {+ setIsCreateExperimentDialogOpen(false);+ if (!data) return;++ if (isExperimentsBetaActive) {+ utils.experiments.all.invalidate();+ utils.experiments.countAll.invalidate();+ // The empty-window fallback is its own query, and a new run belongs in+ // it: without this it keeps serving its cached list.+ utils.experiments.mostRecent.invalidate();+ } else {+ utils.datasets.runsByDatasetId.invalidate();+ utils.datasets.baseRunDataByDatasetId.invalidate();+ }++ showSuccessToast({+ title: "Experiment triggered successfully",+ description: "Waiting for experiment to complete...",+ link: {+ text: "View experiment",+ href: isExperimentsBetaActive+ ? singleRunToExperimentsUrl(projectId, data.runId)+ : `/project/${projectId}/datasets/${data.datasetId}/compare?runs=${data.runId}`,+ },+ });+ };++ const hasEvaluationRuleReadAccess = useHasProjectAccess({+ projectId,+ scope: "evaluationRule:read",+ });++ const hasEvaluationRuleWriteAccess = useHasProjectAccess({+ projectId,+ scope: "evaluationRule:CUD",+ });++ const hasEvaluatorReadAccess = useHasProjectAccess({+ projectId,+ scope: "evaluator:read",+ });++ const evalTemplates = api.evals.latestTemplates.useQuery(+ { projectId },+ {+ enabled:+ !isExperimentsBetaActive &&+ hasEvaluatorReadAccess &&+ Boolean(projectId),+ },+ );++ const evaluators = api.evals.jobConfigsByTarget.useQuery(+ { projectId, targetObject: ["dataset", "experiment"] },+ {+ enabled:+ !isExperimentsBetaActive && hasEvaluationRuleReadAccess && !!datasetId,+ },+ );++ const { createDefaultEvaluator } = useEvaluatorDefaults();++ const {+ selectedEvaluatorData,+ showEvaluatorForm,+ handleConfigureEvaluator,+ handleCloseEvaluatorForm,+ handleEvaluatorSuccess,+ handleSelectEvaluator,+ } = useExperimentEvaluatorData({+ datasetId,+ createDefaultEvaluator,+ evaluatorsData: evaluators.data,+ evalTemplatesData: evalTemplates.data,+ refetchEvaluators: evaluators.refetch,+ });+ const evalTemplate = useEvaluatorFormTemplate({+ evalTemplates: evalTemplates.data?.templates ?? [],+ evalTemplate: selectedEvaluatorData?.evaluator.evalTemplate,+ templateId: selectedEvaluatorData?.templateId,+ });+ // Callback for preprocessing evaluator form values+ // For experiment evaluators, we only run on new data (not historic)+ const preprocessFormValues = useCallback((values: any) => values, []);++ const breadcrumb = getDatasetBreadcrumb(+ projectId,+ datasetId,+ dataset.data?.name,+ );++ if (isInitializing) {+ return <Skeleton className="h-full w-full" />;+ }++ if (isExperimentsBetaActive) {+ return (+ <Page+ headerProps={{+ title: dataset.data?.name ?? "",+ itemType: "DATASET",+ breadcrumb,+ tabsProps: {+ tabs: getDatasetTabs(projectId, datasetId),+ activeTab: DATASET_TABS.EXPERIMENTS,+ },+ actionButtonsRight: (+ <>+ <Dialog+ open={isCreateExperimentDialogOpen}+ onOpenChange={setIsCreateExperimentDialogOpen}+ >+ <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>+ <Button+ disabled={!hasExperimentWriteAccess}+ onClick={() => capture("dataset_run:new_form_open")}+ >+ <FlaskConical className="h-4 w-4" />+ <span className="ml-2 hidden md:block">Run experiment</span>+ </Button>+ </DialogTrigger>+ <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">+ <CreateExperimentsForm+ key={`create-experiment-form-${datasetId}`}+ projectId={projectId as string}+ setFormOpen={setIsCreateExperimentDialogOpen}+ defaultValues={{+ datasetId,+ }}+ handleExperimentSuccess={handleExperimentSuccess}+ showSDKRunInfoPage+ />+ </DialogContent>+ </Dialog>+ </>+ ),+ }}+ >+ <ExperimentsTable+ projectId={projectId}+ fixedFilter={[+ {+ column: "experimentDatasetId",+ type: "stringOptions",+ operator: "any of",+ value: [datasetId],+ },+ ]}+ sessionFilterContextId={`dataset-${datasetId}`}+ showControlsInPageHeader+ />+ </Page>+ );+ }++ return (+ <Page+ headerProps={{+ title: dataset.data?.name ?? "",+ itemType: "DATASET",+ breadcrumb,+ help: dataset.data?.description+ ? {+ description: dataset.data.description,+ }+ : undefined,+ tabsProps: {+ tabs: getDatasetTabs(projectId, datasetId),+ activeTab: DATASET_TABS.EXPERIMENTS,+ },+ actionButtonsRight: (+ <>+ <Dialog+ open={isCreateExperimentDialogOpen}+ onOpenChange={setIsCreateExperimentDialogOpen}+ >+ <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>+ <Button+ disabled={!hasExperimentWriteAccess}+ onClick={() => capture("dataset_run:new_form_open")}+ >+ <FlaskConical className="h-4 w-4" />+ <span className="ml-2 hidden md:block">Run experiment</span>+ </Button>+ </DialogTrigger>+ <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">+ <CreateExperimentsForm+ key={`create-experiment-form-${datasetId}`}+ projectId={projectId as string}+ setFormOpen={setIsCreateExperimentDialogOpen}+ defaultValues={{+ datasetId,+ }}+ handleExperimentSuccess={handleExperimentSuccess}+ showSDKRunInfoPage+ />+ </DialogContent>+ </Dialog>++ {hasEvaluationRuleReadAccess && hasEvaluatorReadAccess ? (+ <div className="w-fit">+ <TemplateSelector+ projectId={projectId}+ datasetId={datasetId}+ evalTemplates={evalTemplates.data?.templates ?? []}+ onConfigureTemplate={handleConfigureEvaluator}+ onSelectEvaluator={handleSelectEvaluator}+ disabled={!hasEvaluationRuleWriteAccess}+ />+ </div>+ ) : null}++ <DatasetAnalytics+ key="dataset-analytics"+ scoreOptions={scoreOptions}+ selectedMetrics={selectedMetrics}+ setSelectedMetrics={setSelectedMetrics}+ />++ <DetailPageNav+ currentId={datasetId}+ path={(entry) =>+ `/project/${projectId}/datasets/${entry.id}/experiments`+ }+ listKey="datasets"+ />+ <DatasetActionMenu+ projectId={projectId}+ datasetId={datasetId}+ datasetName={dataset.data?.name ?? ""}+ datasetDescription={dataset.data?.description ?? undefined}+ datasetMetadata={dataset.data?.metadata}+ datasetInputSchema={dataset.data?.inputSchema ?? undefined}+ datasetExpectedOutputSchema={+ dataset.data?.expectedOutputSchema ?? undefined+ }+ manageEvaluatorsHref={+ hasReadAccess+ ? `/project/${projectId}/evals?target=dataset`+ : undefined+ }+ >+ {({ getTriggerProps }) => (+ <Button+ variant="outline"+ size="icon"+ aria-label="Dataset actions"+ {...getTriggerProps()}+ >+ <MoreVertical className="h-4 w-4" />+ </Button>+ )}+ </DatasetActionMenu>+ </>+ ),+ }}+ >+ <DatasetRunsTable+ projectId={projectId}+ datasetId={datasetId}+ selectedMetrics={selectedMetrics}+ setScoreOptions={setScoreOptions}+ />+ {/* Dialog for configuring evaluators */}+ {selectedEvaluatorData && evalTemplate && (+ <Dialog+ open={showEvaluatorForm}+ onOpenChange={(open) => {+ if (!open) {+ handleCloseEvaluatorForm();+ }+ }}+ >+ <DialogContent className="max-h-[90vh] max-w-(--breakpoint-md) overflow-y-auto">+ <DialogHeader>+ <DialogTitle>+ {selectedEvaluatorData.evaluator.id ? "Edit" : "Configure"}{" "}+ Evaluator+ </DialogTitle>+ </DialogHeader>+ <EvaluatorForm+ useDialog={true}+ projectId={projectId}+ evalTemplate={evalTemplate}+ existingEvaluator={selectedEvaluatorData.evaluator}+ mode={selectedEvaluatorData.evaluator.id ? "edit" : "create"}+ hideTargetSection={!selectedEvaluatorData.evaluator.id}+ onFormSuccess={handleEvaluatorSuccess}+ preprocessFormValues={preprocessFormValues}+ />+ </DialogContent>+ </Dialog>+ )}+ </Page>+ );+}diff --git a/web/src/features/mixpanel-integration/MixpanelIntegrationPage.tsx b/web/src/features/mixpanel-integration/MixpanelIntegrationPage.tsxnew file mode 100644index 0000000000..108eb78aa6--- /dev/null+++ b/web/src/features/mixpanel-integration/MixpanelIntegrationPage.tsx@@ -0,0 +1,427 @@+/* eslint-disable no-nested-ternary */+import { MixpanelLogo } from "@/src/components/MixpanelLogo";+import Header from "@/src/components/layouts/header";+import ContainerPage from "@/src/components/layouts/container-page";+import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";+import { Button } from "@/src/components/ui/button";+import {+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/src/components/ui/form";+import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";+import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";+import { Switch } from "@/src/components/design-system/Switch/Switch";+import {+ Tooltip,+ TooltipTrigger,+ TooltipContent,+} from "@/src/components/ui/tooltip";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import {+ mixpanelIntegrationFormSchema,+ MIXPANEL_REGIONS,+ type MixpanelRegion,+} from "@/src/features/mixpanel-integration/types";+import {+ LEGACY_ANALYTICS_EXPORTER_CUTOFF,+ validateExportSource,+ type V4WriteMode,+ type ExportSourceContext,+} from "@langfuse/shared";+import { Alert } from "@/src/components/design-system/Alert/Alert";+// Shared export-source UI adapters; policy in export-source-policy.ts.+import {+ buildExportSourceContext,+ getExportSourceFieldState,+ getExportSourceUnavailableMessage,+ isExportSourceSelectable,+} from "@/src/features/analytics-integrations/exportSource";+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";+import { useQueryProject } from "@/src/features/projects/hooks";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import { api } from "@/src/utils/api";+import { type RouterOutput } from "@/src/utils/types";+import { zodResolver } from "@hookform/resolvers/zod";+import { Card } from "@/src/components/ui/card";+import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";+import Link from "next/link";+import { useRouter } from "next/router";+import { useMemo } from "react";+import { useForm } from "react-hook-form";+import { type z } from "zod";+import { Info, ExternalLink } from "lucide-react";++export default function MixpanelIntegrationPage() {+ const router = useRouter();+ const projectId = router.query.projectId as string;++ const hasAccess = useHasProjectAccess({+ projectId,+ scope: "integrations:CRUD",+ });+ const state = api.mixpanelIntegration.get.useQuery(+ { projectId },+ {+ enabled: hasAccess,+ },+ );++ const { project } = useQueryProject();++ const status =+ state.isLoading || !hasAccess+ ? undefined+ : state.data?.config?.enabled+ ? "active"+ : "inactive";++ return (+ <ContainerPage+ headerProps={{+ title: "Mixpanel Integration",+ breadcrumb: [+ { name: "Settings", href: `/project/${projectId}/settings` },+ ],+ actionButtonsLeft: <>{status && <StatusBadge type={status} />}</>,+ actionButtonsRight: (+ <Button asChild variant="secondary">+ <Link href="https://langfuse.com/integrations/analytics/mixpanel">+ Integration Docs ↗+ </Link>+ </Button>+ ),+ }}+ >+ <p className="text-primary mb-4 text-sm">+ Integrate with{" "}+ <Link href="https://mixpanel.com" className="underline">+ Mixpanel+ </Link>{" "}+ to sync your Langfuse traces, generations, and scores for advanced+ product analytics. Upon activation, all historical data from your+ project will be synced. After the initial sync, new data is+ automatically synced every hour to keep your Mixpanel dashboards up to+ date.+ </p>+ {!hasAccess && (+ <p className="text-sm">+ Your current role does not grant you access to these settings, please+ reach out to your project admin or owner.+ </p>+ )}+ {hasAccess && (+ <>+ <Header title="Configuration" />+ <Card className="p-3">+ <MixpanelLogo className="text-foreground mb-4 w-20" />+ {!state.data || !project ? (+ <IntegrationSettingsSkeleton />+ ) : (+ <MixpanelIntegrationSettingsForm+ // Draft lifetime = entity identity, so background refetches+ // cannot reset a draft in progress.+ key={`${projectId}:${state.data.config ? "configured" : "new"}`}+ state={state.data.config ?? undefined}+ projectId={projectId}+ writeMode={state.data.writeMode}+ projectCreatedAt={project.createdAt}+ />+ )}+ </Card>+ </>+ )}+ {state.data?.config?.enabled && (+ <>+ <Header title="Status" className="mt-8" />+ <p className="text-primary text-sm">+ Data synced until:{" "}+ {state.data?.config?.lastSyncAt+ ? new Date(state.data.config.lastSyncAt).toLocaleString()+ : "Never (pending)"}+ </p>+ </>+ )}+ </ContainerPage>+ );+}++const MixpanelIntegrationSettingsForm = ({+ state,+ projectId,+ writeMode,+ projectCreatedAt,+}: {+ state?: NonNullable<RouterOutput["mixpanelIntegration"]["get"]["config"]>;+ projectId: string;+ writeMode: V4WriteMode;+ // Raw ISO string, not a Date: a Date built in the parent's JSX would be a new+ // reference on every render and would defeat the memo below.+ projectCreatedAt: string;+}) => {+ const capture = usePostHogClientCapture();+ const { isLangfuseCloud } = useLangfuseCloudRegion();+ const integrationCreatedAt = state?.createdAt;+ const exportSourceCtx: ExportSourceContext = useMemo(+ () =>+ buildExportSourceContext({+ writeMode,+ isCloud: isLangfuseCloud,+ projectCreatedAt: new Date(projectCreatedAt),+ integrationCreatedAt: integrationCreatedAt+ ? new Date(integrationCreatedAt)+ : null,+ exporterCutoff: LEGACY_ANALYTICS_EXPORTER_CUTOFF,+ }),+ [writeMode, isLangfuseCloud, projectCreatedAt, integrationCreatedAt],+ );+ const {+ options: exportSourceOptions,+ showField: showExportSourceField,+ defaultValue: defaultExportSource,+ } = getExportSourceFieldState(state?.exportSource, exportSourceCtx);++ // Blocked-save validation instead of silent rewrite.+ const formSchema = useMemo(+ () =>+ mixpanelIntegrationFormSchema.superRefine((data, ctx) => {+ // The credential is write-only: blank keeps the saved token, so it is+ // only required when no integration exists yet.+ if (!state && !data.mixpanelProjectToken) {+ ctx.addIssue({+ code: "custom",+ path: ["mixpanelProjectToken"],+ message: "Mixpanel Project Token is required",+ });+ }+ if (!isExportSourceSelectable(data.exportSource, exportSourceCtx)) {+ ctx.addIssue({+ code: "custom",+ path: ["exportSource"],+ message:+ "This export source is not available on this deployment. Select an available export source to save.",+ });+ }+ }),+ [exportSourceCtx, state],+ );++ const mixpanelForm = useForm({+ resolver: zodResolver(formSchema),+ defaultValues: {+ mixpanelRegion:+ (state?.mixpanelRegion as MixpanelRegion) ??+ MIXPANEL_REGIONS[0].subdomain,+ mixpanelProjectToken: "",+ enabled: state?.enabled ?? false,+ exportSource: defaultExportSource,+ },+ });++ const watchedExportSource = mixpanelForm.watch("exportSource");+ const watchedValidation =+ watchedExportSource != null+ ? validateExportSource(watchedExportSource, exportSourceCtx)+ : ({ ok: true } as const);++ const utils = api.useUtils();+ const mut = api.mixpanelIntegration.update.useMutation({+ onSuccess: () => {+ utils.mixpanelIntegration.invalidate();+ },+ });+ const mutDelete = api.mixpanelIntegration.delete.useMutation({+ onSuccess: () => {+ utils.mixpanelIntegration.invalidate();+ },+ });++ async function onSubmit(+ values: z.infer<typeof mixpanelIntegrationFormSchema>,+ ) {+ capture("integrations:mixpanel_form_submitted");+ mut.mutate({+ projectId,+ ...values,+ });+ }++ return (+ <Form {...mixpanelForm}>+ <form+ className="space-y-3"+ onSubmit={mixpanelForm.handleSubmit(onSubmit)}+ >+ <FormField+ control={mixpanelForm.control}+ name="mixpanelRegion"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Mixpanel Region</FormLabel>+ <FormControl>+ <SelectInput+ onValueChange={field.onChange}+ value={field.value}+ placeholder="Select a region"+ options={MIXPANEL_REGIONS.map((region) => ({+ value: region.subdomain,+ label: region.description,+ }))}+ />+ </FormControl>+ <FormDescription>+ Select the Mixpanel region where your project is hosted+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={mixpanelForm.control}+ name="mixpanelProjectToken"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Mixpanel Project Token</FormLabel>+ <FormControl>+ <PasswordInput+ {...field}+ placeholder={state?.mixpanelProjectTokenDisplay}+ />+ </FormControl>+ <FormDescription>+ {state+ ? "Leave blank to keep the current token."+ : "You can find your Project Token in your Mixpanel project settings"}+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ {showExportSourceField && (+ <FormField+ control={mixpanelForm.control}+ name="exportSource"+ render={({ field }) => (+ <FormItem>+ <FormLabel className="flex items-center gap-1.5 pt-2">+ Export Source+ <Tooltip>+ <TooltipTrigger>+ <Info className="text-muted-foreground h-3.5 w-3.5" />+ </TooltipTrigger>+ <TooltipContent+ side="bottom"+ className="max-w-[350px] space-y-2 p-3"+ >+ {exportSourceOptions.map((option) => (+ <div key={option.value} className="space-y-0.5">+ <div className="font-bold">{option.label}</div>+ <div className="text-muted-foreground text-xs">+ {option.description}+ </div>+ </div>+ ))}+ <div className="border-t pt-2">+ <a+ href="https://langfuse.com/docs/integrations/export-sources"+ target="_blank"+ rel="noopener noreferrer"+ className="text-muted-foreground hover:text-primary inline-flex items-center gap-1 text-xs hover:underline"+ >+ For further information see+ <ExternalLink className="h-3 w-3" />+ </a>+ </div>+ </TooltipContent>+ </Tooltip>+ </FormLabel>+ <FormControl>+ <SelectInput+ onValueChange={field.onChange}+ value={field.value}+ placeholder="Select data to export"+ options={exportSourceOptions.map((option) => {+ if (option.unavailable) {+ return {+ value: option.value,+ label: `${option.label} (not available on this deployment)`,+ disabled: true as const,+ disabledReason: "Not available on this deployment.",+ };+ }++ return { value: option.value, label: option.label };+ })}+ />+ </FormControl>+ <FormDescription>+ Choose which data sources to export to Mixpanel. Scores are+ always included.+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ )}+ {!watchedValidation.ok && (+ <Alert variant="destructive">+ <Alert.Title>+ Saved export source is no longer available+ </Alert.Title>+ <Alert.Description>+ {getExportSourceUnavailableMessage(watchedValidation.reason)}+ </Alert.Description>+ </Alert>+ )}+ <FormField+ control={mixpanelForm.control}+ name="enabled"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Enabled</FormLabel>+ <FormControl>+ <div className="mt-1 ml-4">+ <Switch+ id="mixpanel-integration-enabled"+ checked={field.value}+ onCheckedChange={() => {+ field.onChange(!field.value);+ }}+ />+ </div>+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </form>+ <div className="mt-8 flex gap-2">+ <Button+ loading={mut.isPending}+ onClick={mixpanelForm.handleSubmit(onSubmit)}+ >+ Save+ </Button>+ <Button+ variant="ghost"+ loading={mutDelete.isPending}+ disabled={!state}+ onClick={() => {+ if (+ confirm(+ "Are you sure you want to reset the Mixpanel integration for this project?",+ )+ )+ mutDelete.mutate({ projectId });+ }}+ >+ Reset+ </Button>+ </div>+ </Form>+ );+};diff --git a/web/src/features/models/ModelDetailPage.tsx b/web/src/features/models/ModelDetailPage.tsxnew file mode 100644index 0000000000..a06094d839--- /dev/null+++ b/web/src/features/models/ModelDetailPage.tsx@@ -0,0 +1,328 @@+import { useRouter } from "next/router";+import { api } from "@/src/utils/api";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import {+ Card,+ CardContent,+ CardHeader,+ CardTitle,+} from "@/src/components/ui/card";+import { DeleteModelButton } from "@/src/features/models/components/DeleteModelButton";+import { EditModelButton } from "@/src/features/models/components/EditModelButton";+import { CloneModelButton } from "@/src/features/models/components/CloneModelButton";+import { TestModelMatchButton } from "@/src/features/models/components/test-match/TestModelMatchButton";+import { JSONView } from "@/src/components/ui/CodeJsonViewer";+import Link from "next/link";+import { Button } from "@/src/components/ui/button";+import { getMaxDecimals } from "@/src/features/models/fns/getMaxDecimals";+import Decimal from "decimal.js";+import { PriceUnitSelector } from "@/src/features/models/components/PriceUnitSelector";+import { useMemo, useState } from "react";+import { usePriceUnitMultiplier } from "@/src/features/models/hooks/usePriceUnitMultiplier";+import Generations from "@/src/features/tracing-tables/observations/ObservationsTable";+import Page from "@/src/components/layouts/page";+import { SquareArrowOutUpRight, Info as InfoIcon } from "lucide-react";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/src/components/ui/select";+import {+ HoverCard,+ HoverCardContent,+ HoverCardTrigger,+} from "@/src/components/ui/hover-card";+import { CodeMirrorEditor } from "@/src/components/editor";++const resolvePricingTier = <T extends { id: string }>(+ tiers: T[],+ selectedTierId: string | null,+ defaultTier: T | null,+): T | null => {+ if (selectedTierId) {+ return tiers.find((tier) => tier.id === selectedTierId) ?? defaultTier;+ }+ return defaultTier;+};++export default function ModelDetailPage() {+ const router = useRouter();+ const { priceUnit, priceUnitMultiplier } = usePriceUnitMultiplier();+ const projectId = router.query.projectId as string;+ const modelId = router.query.modelId as string;+ const pricingTierParam = router.query.pricingTier as string | undefined;+ const hasWriteAccess = useHasProjectAccess({+ projectId,+ scope: "models:CUD",+ });++ const { data: model, isLoading } = api.models.getById.useQuery(+ { projectId, modelId },+ { enabled: !!projectId && !!modelId },+ );++ // Get default tier or first tier by priority+ const defaultTier = useMemo(() => {+ if (!model?.pricingTiers || model.pricingTiers.length === 0) return null;+ return model.pricingTiers.find((t) => t.isDefault) || model.pricingTiers[0];+ }, [model?.pricingTiers]);++ // Keep user selection local and derive the initial linked tier during render.+ const [selectedTierId, setSelectedTierId] = useState<string | null>(null);++ // Get the active tier (selected or default)+ const activeTier = useMemo(() => {+ if (!model?.pricingTiers) return null;+ return resolvePricingTier(+ model.pricingTiers,+ selectedTierId ?? pricingTierParam ?? null,+ defaultTier,+ );+ }, [model?.pricingTiers, selectedTierId, pricingTierParam, defaultTier]);++ const maxDecimals = useMemo(+ () =>+ Math.max(+ ...Object.values(activeTier?.prices ?? {}).map((price) =>+ getMaxDecimals(price, priceUnitMultiplier),+ ),+ ),+ [activeTier?.prices, priceUnitMultiplier],+ );++ // If not found, redirect to models page+ if (!isLoading && !model) {+ return (+ <div className="flex min-h-screen flex-col items-center justify-center">+ <div className="mb-4 text-xl font-bold">Model not found</div>+ <Button variant="outline" asChild>+ <Link href={`/project/${projectId}/settings/models`}>+ Return to Models page+ </Link>+ </Button>+ </div>+ );+ }++ const isLangfuseModel = !Boolean(model?.projectId);++ if (isLoading || !model) {+ return <div className="p-3">Loading...</div>;+ }++ return (+ <Page+ scrollable+ headerProps={{+ title: model.modelName,+ help: {+ description: "Model configuration and pricing details",+ href: "https://langfuse.com/docs/model-usage-and-cost",+ },+ breadcrumb: [+ {+ name: "Settings",+ href: `/project/${router.query.projectId as string}/settings`,+ },+ {+ name: "Models",+ href: `/project/${router.query.projectId as string}/settings/models`,+ },+ { name: model.modelName },+ ],+ actionButtonsRight: (+ <div className="flex gap-2">+ {hasWriteAccess && (+ <>+ <TestModelMatchButton projectId={projectId} variant="outline" />+ {!isLangfuseModel ? (+ <>+ <EditModelButton projectId={projectId} modelData={model} />+ <DeleteModelButton+ projectId={projectId}+ modelData={model}+ onSuccess={() => {+ router.push(`/project/${projectId}/settings/models`);+ }}+ />+ </>+ ) : (+ <CloneModelButton projectId={projectId} modelData={model} />+ )}+ </>+ )}+ </div>+ ),+ }}+ >+ <div className="grid grid-cols-2 gap-6 p-2">+ <Card>+ <CardHeader>+ <CardTitle>Model configuration</CardTitle>+ </CardHeader>+ <CardContent className="grid gap-4">+ <div>+ <div className="text-muted-foreground text-sm font-bold">+ Match Pattern+ </div>+ <div className="mt-1 font-mono text-sm">{model.matchPattern}</div>+ </div>++ <div>+ <div className="text-muted-foreground text-sm font-bold">+ Maintained by+ </div>+ <div className="mt-1 text-sm">+ {isLangfuseModel ? "Langfuse" : "User"}+ </div>+ </div>++ <div>+ <div className="text-muted-foreground text-sm font-bold">+ Tokenizer+ </div>+ <div className="mt-1 text-sm">{model.tokenizerId || "None"}</div>+ </div>++ {model.tokenizerId && (+ <div>+ <div className="text-muted-foreground text-sm font-bold">+ Tokenizer Config+ </div>+ <pre className="bg-muted mt-1 rounded p-2 text-sm">+ <JSONView json={model.tokenizerConfig} />+ </pre>+ </div>+ )}+ </CardContent>+ </Card>++ <Card id="pricing-section">+ <CardHeader>+ <div className="flex flex-col gap-2">+ <CardTitle>Pricing</CardTitle>+ {model.pricingTiers.length > 1 && (+ <div className="flex items-center gap-4">+ <label className="text-muted-foreground text-sm font-bold">+ Pricing Tier+ </label>+ <Select+ value={activeTier?.id ?? ""}+ onValueChange={setSelectedTierId}+ >+ <SelectTrigger className="w-[200px]">+ <SelectValue placeholder="Select tier" />+ </SelectTrigger>+ <SelectContent>+ {model.pricingTiers.map((tier) => (+ <SelectItem key={tier.id} value={tier.id}>+ {tier.name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ {activeTier && !activeTier.isDefault && (+ <HoverCard openDelay={200} closeDelay={100}>+ <HoverCardTrigger asChild>+ <Button+ variant="ghost"+ className="text-muted-foreground hover:text-accent-foreground inline-flex h-auto items-center gap-1.5 p-0 text-xs hover:bg-transparent"+ size="sm"+ >+ <InfoIcon className="h-3 w-3" />+ <span>Conditions</span>+ </Button>+ </HoverCardTrigger>+ <HoverCardContent+ className="max-h-[80vh] w-[400px] overflow-auto"+ collisionPadding={20}+ >+ <p className="text-sm font-bold">+ Pricing Tier Conditions+ </p>+ <p className="text-muted-foreground pt-2 text-sm">+ This tier is applied when the following conditions are+ met:+ </p>+ <div className="mt-2">+ <CodeMirrorEditor+ mode="json"+ value={JSON.stringify(+ activeTier.conditions,+ null,+ 2,+ )}+ onChange={() => {}} // Read-only+ className="max-h-[250px] overflow-y-auto"+ editable={false}+ />+ </div>+ </HoverCardContent>+ </HoverCard>+ )}+ </div>+ )}+ </div>+ </CardHeader>+ <CardContent>+ <div className="flex flex-col gap-2">+ <div className="border-border text-muted-foreground grid grid-cols-2 gap-2 border-b text-sm font-bold">+ <span>Usage Type</span>+ <span className="flex items-center gap-2">+ <span>Price {priceUnit}</span>+ <PriceUnitSelector />+ </span>+ </div>+ {activeTier &&+ Object.entries(activeTier.prices)+ // Sort by price ascending+ .sort((a, b) => a[1] - b[1])+ .map(([usageType, price]) => (+ <div+ key={usageType}+ className="grid grid-cols-2 gap-2 rounded px-1 py-0.5 text-sm"+ >+ <span className="break-all">{usageType}</span>+ <span className="text-left font-mono">+ $+ {new Decimal(price)+ .mul(priceUnitMultiplier)+ .toFixed(maxDecimals)}+ </span>+ </div>+ ))}+ </div>+ </CardContent>+ </Card>++ <Card className="col-span-2 min-w-0">+ <CardHeader>+ <CardTitle className="flex items-center justify-between">+ <span>Model observations</span>+ <Button variant="ghost" asChild>+ <Link+ href={`/project/${projectId}/observations`}+ className="flex items-center gap-1"+ >+ <span className="text-sm">View all</span>+ <SquareArrowOutUpRight className="h-4 w-4" />+ </Link>+ </Button>+ </CardTitle>+ </CardHeader>+ <CardContent className="min-w-0">+ <div className="flex h-[calc(100vh-20rem)] min-h-0 min-w-0 flex-col overflow-hidden">+ <Generations+ projectId={projectId}+ omittedFilter={["model"]}+ modelId={model.id}+ />+ </div>+ </CardContent>+ </Card>+ </div>+ </Page>+ );+}diff --git a/web/src/features/organizations/OrganizationSettingsPage.tsx b/web/src/features/organizations/OrganizationSettingsPage.tsxnew file mode 100644index 0000000000..551e74292d--- /dev/null+++ b/web/src/features/organizations/OrganizationSettingsPage.tsx@@ -0,0 +1,362 @@+import { PagedSettingsContainer } from "@/src/components/PagedSettingsContainer";+import Header from "@/src/components/layouts/header";+import { Button } from "@/src/components/ui/button";+import { ConnectedMembershipInvitesSettingsTable } from "@/src/features/rbac/components/MembershipInvitesSettingsTable/ConnectedMembershipInvitesSettingsTable";+import { ConnectedMembersSettingsTable } from "@/src/features/rbac/components/MembersSettingsTable/ConnectedMembersSettingsTable";+import { JSONView } from "@/src/components/ui/CodeJsonViewer";+import RenameOrganization from "@/src/features/organizations/components/RenameOrganization";+import { DeleteOrganizationDialogController } from "@/src/features/organizations/components/DeleteOrganizationDialogController";+import { useQueryOrganization } from "@/src/features/organizations/hooks";+import { useRouter } from "next/router";+import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";+import { BillingSettings } from "@/src/ee/features/billing/components/BillingSettings";+import { useHasEntitlement, usePlan } from "@/src/features/entitlements/hooks";+import ContainerPage from "@/src/components/layouts/container-page";+import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";+import { SSOSettings } from "@/src/ee/features/sso-settings/components/SSOSettings";+import { isCloudPlan } from "@langfuse/shared";+import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";+import { ApiKeyList } from "@/src/features/public-api/components/ApiKeyList";+import AIFeatureSwitch from "@/src/features/organizations/components/AIFeatureSwitch";+import { useIsCloudBillingAvailable } from "@/src/ee/features/billing/utils/isCloudBilling";+import { env } from "@/src/env.mjs";+import { OrgAuditLogsSettingsPage } from "@/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage";+import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";+import { useV4UpgradeUiFlag } from "@/src/features/v4-migration/useV4UpgradeUiEnabled";+import { OrganizationFeaturePreviewsSettings } from "@/src/features/feature-flags/components/OrganizationFeaturePreviewsSettings";+import useIsFeatureEnabled from "@/src/features/feature-flags/hooks/useIsFeatureEnabled";+import {+ GatewayApiKeysPage,+ GatewayConfigurationPage,+ GatewayModelsPage,+ GatewayProvidersPage,+} from "@/src/features/ai-gateway";+import useSessionStorage from "@/src/components/useSessionStorage";+import { api } from "@/src/utils/api";++type OrganizationSettingsPage = {+ title: string;+ slug: string;+ section?: string;+ show?: boolean | (() => boolean);+ cmdKKeywords?: string[];+} & ({ content: React.ReactNode } | { href: string });++export function useOrganizationSettingsPages(): OrganizationSettingsPage[] {+ const { organization } = useQueryProjectOrOrganization();+ const showBillingSettings = useHasEntitlement("cloud-billing");+ const hasAdminApiEntitlement = useHasEntitlement("admin-api");+ const hasOrgApiKeyAccess = useHasOrganizationAccess({+ organizationId: organization?.id,+ scope: "organization:CRUD_apiKeys",+ });+ const showOrgApiKeySettings = hasAdminApiEntitlement && hasOrgApiKeyAccess;+ const showAuditLogs = useHasEntitlement("audit-logs");+ const canUpdateOrganization = useHasOrganizationAccess({+ organizationId: organization?.id,+ scope: "organization:update",+ });+ const canManageGateway = useHasOrganizationAccess({+ organizationId: organization?.id,+ scope: "gateway:manage",+ });+ const plan = usePlan();+ const isLangfuseCloud = isCloudPlan(plan) ?? false;+ const isCloudBillingAvailable = useIsCloudBillingAvailable();+ const showV4Migration = useV4UpgradeUiFlag();+ const isAiGatewayEnabled = useIsFeatureEnabled("aiGateway", {+ enableForAdmins: false,+ organizationId: organization?.id,+ });++ if (!organization) return [];++ return getOrganizationSettingsPages({+ organization,+ showBillingSettings: showBillingSettings && isCloudBillingAvailable,+ showOrgApiKeySettings,+ showAuditLogs,+ isLangfuseCloud,+ showV4Migration,+ showAiGateway: canManageGateway && isAiGatewayEnabled,+ showFeaturePreviews:+ canUpdateOrganization && organization.id !== env.NEXT_PUBLIC_DEMO_ORG_ID,+ });+}++export const getOrganizationSettingsPages = ({+ organization,+ showBillingSettings,+ showOrgApiKeySettings,+ showAuditLogs,+ isLangfuseCloud,+ showV4Migration,+ showAiGateway,+ showFeaturePreviews,+}: {+ organization: {+ id: string;+ name: string;+ metadata: Record<string, unknown>;+ projects: Array<{+ id: string;+ name: string;+ deletedAt?: Date | string | null;+ }>;+ };+ showBillingSettings: boolean;+ showOrgApiKeySettings: boolean;+ showAuditLogs: boolean;+ isLangfuseCloud: boolean;+ showV4Migration: boolean;+ showAiGateway: boolean;+ showFeaturePreviews: boolean;+}): OrganizationSettingsPage[] => [+ {+ title: "General",+ slug: "index",+ section: "Organization",+ cmdKKeywords: ["name", "id", "delete"],+ content: (+ <div className="flex flex-col gap-6">+ <RenameOrganization />+ <div>+ <Header title="Debug Information" />+ <JSONView+ title="Metadata"+ json={{+ name: organization.name,+ id: organization.id,+ ...organization.metadata,+ ...(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION && {+ cloudRegion: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,+ }),+ }}+ />+ </div>+ <AIFeatureSwitch />+ <SettingsDangerZone+ items={[+ {+ title: "Delete this organization",+ description:+ "Once you delete an organization, there is no going back. Please be certain.",+ button: (+ <DeleteOrganizationDialogController>+ {({ disabled, openDialog }) => (+ <Button+ variant="destructive-secondary"+ disabled={disabled !== undefined}+ onClick={openDialog}+ >+ Delete Organization+ </Button>+ )}+ </DeleteOrganizationDialogController>+ ),+ },+ ]}+ />+ </div>+ ),+ },+ {+ title: "Feature Previews",+ slug: "feature-previews",+ section: "Organization",+ cmdKKeywords: ["feature", "preview", "flags", "beta"],+ content: <OrganizationFeaturePreviewsSettings orgId={organization.id} />,+ show: showFeaturePreviews,+ },+ {+ title: "API Keys",+ slug: "api-keys",+ section: "Organization",+ content: (+ <div className="flex flex-col gap-6">+ <ApiKeyList entityId={organization.id} scope="organization" />+ </div>+ ),+ show: showOrgApiKeySettings,+ },+ {+ title: "Members",+ slug: "members",+ section: "Organization",+ cmdKKeywords: ["invite", "user", "rbac"],+ content: <OrganizationMembersSettings orgId={organization.id} />,+ },+ {+ title: "Audit Logs",+ slug: "audit-logs",+ section: "Organization",+ cmdKKeywords: ["audit", "logs", "history", "changes"],+ content: <OrgAuditLogsSettingsPage orgId={organization.id} />,+ show: showAuditLogs,+ },+ {+ title: "Billing",+ slug: "billing",+ section: "Organization",+ cmdKKeywords: ["payment", "subscription", "plan", "invoice"],+ content: <BillingSettings />,+ show: showBillingSettings,+ },+ {+ title: "SSO",+ slug: "sso",+ section: "Organization",+ cmdKKeywords: [+ "sso",+ "login",+ "auth",+ "okta",+ "saml",+ "azure",+ "domain",+ "dns",+ "txt",+ "verify",+ ],+ content: <SSOSettings orgId={organization.id} />,+ show: isLangfuseCloud,+ },+ {+ title: "Projects",+ slug: "projects",+ section: "Organization",+ href: `/organization/${organization.id}`,+ },+ {+ title: "v4 Migration",+ slug: "v4-migration",+ section: "Organization",+ href: "/v4-migration",+ show: showV4Migration,+ },+ {+ title: "Configuration",+ slug: "ai-gateway",+ section: "AI Gateway",+ cmdKKeywords: ["gateway", "llm", "configuration", "instrumentation"],+ content: (+ <GatewayConfigurationPage+ organizationId={organization.id}+ projects={organization.projects}+ />+ ),+ show: showAiGateway,+ },+ {+ title: "Provider credentials",+ slug: "ai-gateway-providers",+ section: "AI Gateway",+ cmdKKeywords: [+ "gateway",+ "providers",+ "credentials",+ "openai",+ "anthropic",+ ],+ content: <GatewayProvidersPage organizationId={organization.id} />,+ show: showAiGateway,+ },+ {+ title: "Models",+ slug: "ai-gateway-models",+ section: "AI Gateway",+ cmdKKeywords: ["gateway", "models", "discovery", "sync"],+ content: <GatewayModelsPage organizationId={organization.id} />,+ show: showAiGateway,+ },+ {+ title: "Gateway API keys",+ slug: "ai-gateway-api-keys",+ section: "AI Gateway",+ cmdKKeywords: ["gateway", "api", "keys", "metadata", "credentials"],+ content: <GatewayApiKeysPage organizationId={organization.id} />,+ show: showAiGateway,+ },+];++const OrganizationSettingsPage = () => {+ const organization = useQueryOrganization();+ const router = useRouter();+ const { page } = router.query;+ const pages = useOrganizationSettingsPages();++ if (!organization) {+ return (+ <ContainerPage+ headerProps={{+ title: "Organization Settings",+ }}+ >+ <NoDataOrLoading isLoading />+ </ContainerPage>+ );+ }++ return (+ <ContainerPage+ headerProps={{+ title: "Organization Settings",+ }}+ extendRight={router.query.page === "ai-gateway-models"}+ fullHeight={router.query.page === "ai-gateway-models"}+ >+ <PagedSettingsContainer+ activeSlug={page as string | undefined}+ pages={pages}+ fullHeight={router.query.page === "ai-gateway-models"}+ />+ </ContainerPage>+ );+};++export default OrganizationSettingsPage;++function OrganizationMembersSettings({ orgId }: { orgId: string }) {+ const [invitesPagination, setInvitesPagination] = useSessionStorage(+ `orgInvites_${orgId}_pagination`,+ { pageIndex: 0, pageSize: 10 },+ );++ const hasViewAccess = useHasOrganizationAccess({+ organizationId: orgId,+ scope: "organizationMembers:read",+ });++ const membershipInvites = api.members.allInvitesFromOrg.useQuery(+ {+ orgId,+ page: invitesPagination.pageIndex,+ limit: invitesPagination.pageSize,+ },+ { enabled: hasViewAccess },+ );++ return (+ <div className="flex flex-col gap-6">+ <div>+ <Header title="Organization Members" />+ <ConnectedMembersSettingsTable orgId={orgId} />+ </div>+ {hasViewAccess && (+ <div+ className={+ membershipInvites.data?.totalCount === 0 ? "hidden" : undefined+ }+ >+ <Header title="Membership Invites" />+ <ConnectedMembershipInvitesSettingsTable+ orgId={orgId}+ query={membershipInvites}+ paginationState={invitesPagination}+ setPaginationState={setInvitesPagination}+ />+ </div>+ )}+ </div>+ );+}diff --git a/web/src/features/organizations/index.ts b/web/src/features/organizations/index.tsindex 23e38ca77e..34fb990cd1 100644--- a/web/src/features/organizations/index.ts+++ b/web/src/features/organizations/index.ts@@ -1 +1,2 @@export { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";+export { useOrganizationSettingsPages } from "@/src/features/organizations/OrganizationSettingsPage";diff --git a/web/src/features/prompts/PromptMetricsPage.tsx b/web/src/features/prompts/PromptMetricsPage.tsxnew file mode 100644index 0000000000..16adb9716a--- /dev/null+++ b/web/src/features/prompts/PromptMetricsPage.tsx@@ -0,0 +1,459 @@+/* eslint-disable no-nested-ternary */+import { DataTable } from "@/src/components/table/data-table";+import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";+import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";+import { type LangfuseColumnDef } from "@/src/components/table/types";+import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";+import { useRouter } from "next/router";+import { api } from "@/src/utils/api";+import { NumberParam, useQueryParams, withDefault } from "use-query-params";+import { type RouterOutput } from "@/src/utils/types";+import { createLinkTableColumn } from "@/src/components/design-system/table/columns/createLinkTableColumn";+import { createNumberTableColumn } from "@/src/components/design-system/table/columns/createNumberTableColumn";+import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";+import { numberFormatter, usdFormatter } from "@/src/utils/numbers";+import { formatIntervalSeconds } from "@/src/utils/dates";+import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";+import { Skeleton } from "@/src/components/ui/skeleton";+import { type ScoreAggregate } from "@langfuse/shared";+import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";+import Page from "@/src/components/layouts/page";+import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";+import { TruncatedLabels } from "@/src/components/TruncatedLabels";+import {+ getPromptTabs,+ PROMPT_TABS,+} from "@/src/features/navigation/utils/prompt-tabs";+import { useScoreColumns } from "@/src/features/scores/hooks/useScoreColumns";+import {+ scoreFilters,+ addPrefixToScoreKeys,+} from "@/src/features/scores/lib/scoreColumns";+import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";+import { useTableDateRange } from "@/src/hooks/useTableDateRange";+import { toAbsoluteTimeRange } from "@/src/utils/date-range-utils";+import { useMemo } from "react";+import { TableHeaderControls } from "@/src/components/table/table-header-controls";++export type PromptVersionTableRow = {+ version: number;+ labels: string[];+ medianLatency?: number | null;+ medianInputTokens?: number | null;+ medianOutputTokens?: number | null;+ medianCost?: number | null;+ generationCount?: bigint | null;+ traceScores?: ScoreAggregate;+ generationScores?: ScoreAggregate;+ lastUsed?: string | null;+ firstUsed?: string | null;+};++type PromptCoreOutput = RouterOutput["prompts"]["allVersions"];+type PromptMetricsOutput = RouterOutput["prompts"]["versionMetrics"];+type PromptMetric = PromptMetricsOutput[number];+type PromptCoreData = PromptCoreOutput["promptVersions"][number];++function joinPromptCoreAndMetricData(+ promptCoreData?: PromptCoreOutput,+ promptMetricsData?: PromptMetricsOutput,+): {+ status: "loading" | "error" | "success";+ combinedData: (PromptCoreData & Partial<PromptMetric>)[] | undefined;+} {+ if (!promptCoreData) return { status: "loading", combinedData: undefined };++ const { promptVersions } = promptCoreData;++ if (!promptMetricsData)+ return { status: "success", combinedData: promptVersions };++ const promptMetricsMap = promptMetricsData.reduce(+ (acc, metric: PromptMetric) => {+ acc.set(metric.id, metric);+ return acc;+ },+ new Map<string, PromptMetric>(),+ );++ const combinedData = promptVersions.map((coreData) => {+ const metric = promptMetricsMap.get(coreData.id);+ return {+ ...coreData,+ ...(metric && metric),+ };+ });++ return { status: "success", combinedData };+}++export default function PromptMetricsPage({+ promptName: promptNameProp,+ // Defaults to true because this component always renders its own `Page`, so+ // the header controls slot is available. Set false if ever embedded without+ // a `Page` ancestor, to fall back to the toolbar.+ showControlsInPageHeader = true,+}: { promptName?: string; showControlsInPageHeader?: boolean } = {}) {+ const router = useRouter();+ const projectId = useProjectIdFromURL() ?? "";+ const promptNameFromQuery = router.query.promptName;+ const promptName =+ promptNameProp ||+ (typeof promptNameFromQuery === "string"+ ? decodeURIComponent(promptNameFromQuery)+ : "");++ const [paginationState, setPaginationState] = useQueryParams({+ pageIndex: withDefault(NumberParam, 0),+ pageSize: withDefault(NumberParam, 50),+ });+ const [orderByState, setOrderByState] = useOrderByState({+ column: "startTime",+ order: "DESC",+ });+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage(+ "promptVersion",+ "s",+ );+ const { timeRange, setTimeRange } = useTableDateRange(projectId, {+ defaultRelativeAggregation: "last30Days",+ });+ const dateRange = useMemo(+ () => ("range" in timeRange ? toAbsoluteTimeRange(timeRange) : timeRange),+ [timeRange],+ );++ const promptVersions = api.prompts.allVersions.useQuery(+ {+ projectId,+ name: promptName,+ page: paginationState.pageIndex,+ limit: paginationState.pageSize,+ },+ { enabled: Boolean(projectId) },+ );++ const promptIds = promptVersions.isSuccess+ ? promptVersions.data?.promptVersions.map((prompt) => prompt.id)+ : [];++ const promptMetrics = api.prompts.versionMetrics.useQuery(+ {+ projectId,+ promptIds,+ fromTimestamp: dateRange?.from,+ toTimestamp: dateRange?.to,+ },+ {+ enabled: Boolean(projectId) && promptVersions.isSuccess,+ trpc: {+ context: {+ skipBatch: true,+ },+ },+ },+ );++ const { scoreColumns: traceScoreColumns, isLoading: isTraceColumnLoading } =+ useScoreColumns<PromptVersionTableRow>({+ scoreColumnKey: "traceScores",+ projectId: projectId,+ filter: scoreFilters.forTraceLevel(),+ prefix: "Trace",+ });++ const {+ scoreColumns: generationScoreColumns,+ isLoading: isGenerationColumnLoading,+ } = useScoreColumns<PromptVersionTableRow>({+ scoreColumnKey: "generationScores",+ projectId: projectId,+ filter: scoreFilters.forObservations(),+ prefix: "Generation",+ });++ const columns: LangfuseColumnDef<PromptVersionTableRow>[] = [+ createLinkTableColumn<PromptVersionTableRow, number>({+ accessorKey: "version",+ header: "Version",+ isPinnedLeft: true,+ size: 80,+ getCell: (version) => {+ if (typeof version !== "number") return undefined;++ return {+ type: "link",+ props: {+ path: `/project/${projectId}/prompts/${encodeURIComponent(promptName)}/?version=${version}`,+ value: String(version),+ },+ };+ },+ }),+ {+ accessorKey: "labels",+ id: "labels",+ header: "Labels",+ isPinnedLeft: true,+ size: 160,+ cell: ({ row }) => {+ const values: string[] = row.getValue("labels");+ return (+ values &&+ values.length > 0 && (+ <TruncatedLabels+ labels={values}+ maxVisibleLabels={3}+ className="-mr-8 flex max-h-full flex-wrap gap-1"+ showSimpleBadges={true}+ />+ )+ );+ },+ enableHiding: true,+ },+ createNumberTableColumn<PromptVersionTableRow>({+ accessorKey: "medianLatency",+ header: "Median latency",+ size: 140,+ formatter: (value) => formatIntervalSeconds(value / 1000, 3),+ getValue: (value) => {+ if (!promptMetrics.isSuccess) return { type: "loading" };+ if (!value) return undefined;++ return value;+ },+ enableHiding: true,+ }),+ createNumberTableColumn<PromptVersionTableRow>({+ accessorKey: "medianInputTokens",+ header: "Median input tokens",+ size: 160,+ enableHiding: true,+ formatter: (value) => String(value),+ getValue: (value) => {+ if (!promptMetrics.isSuccess) return { type: "loading" };+ if (!value) return undefined;++ return value;+ },+ }),+ createNumberTableColumn<PromptVersionTableRow>({+ accessorKey: "medianOutputTokens",+ header: "Median output tokens",+ size: 170,+ enableHiding: true,+ formatter: (value) => String(value),+ getValue: (value) => {+ if (!promptMetrics.isSuccess) return { type: "loading" };+ if (!value) return undefined;++ return value;+ },+ }),+ createNumberTableColumn<PromptVersionTableRow>({+ accessorKey: "medianCost",+ header: "Median cost",+ size: 120,+ formatter: (value) => usdFormatter(value),+ getValue: (value) => {+ if (!promptMetrics.isSuccess) return { type: "loading" };+ if (!value) return undefined;++ return value;+ },+ enableHiding: true,+ }),+ createNumberTableColumn<PromptVersionTableRow, bigint>({+ accessorKey: "generationCount",+ header: "Generations count",+ size: 150,+ enableHiding: true,+ formatter: (value) => numberFormatter(value, 0),+ getValue: (value) =>+ promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },+ }),+ {+ accessorKey: "traceScores",+ header: "Trace Scores",+ id: "traceScores",+ enableHiding: true,+ columns: traceScoreColumns,+ cell: () => {+ return isTraceColumnLoading ? (+ <Skeleton className="h-3 w-1/2"></Skeleton>+ ) : null;+ },+ },+ {+ accessorKey: "generationScores",+ header: "Generation Scores",+ id: "generationScores",+ enableHiding: true,+ columns: generationScoreColumns,+ cell: () => {+ return isGenerationColumnLoading ? (+ <Skeleton className="h-3 w-1/2"></Skeleton>+ ) : null;+ },+ },+ createTextTableColumn<PromptVersionTableRow>({+ accessorKey: "lastUsed",+ header: "Last used",+ enableHiding: true,+ size: 150,+ headerTooltip: {+ description:+ "This is calculated based on the selected date range, not the full usage history.",+ },+ mapValue: (value) =>+ promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },+ }),+ createTextTableColumn<PromptVersionTableRow>({+ accessorKey: "firstUsed",+ header: "First used",+ size: 150,+ enableHiding: true,+ headerTooltip: {+ description:+ "This is calculated based on the selected date range, not the full usage history.",+ },+ mapValue: (value) =>+ promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },+ }),+ ];++ const [columnVisibility, setColumnVisibilityState] =+ useColumnVisibility<PromptVersionTableRow>(+ `promptVersionsColumnVisibility-${projectId}`,+ columns,+ );++ const [columnOrder, setColumnOrder] = useColumnOrder<PromptVersionTableRow>(+ "promptVersionsColumnOrder",+ columns,+ );++ const totalCount = promptVersions?.data?.totalCount ?? null;++ const { combinedData } = joinPromptCoreAndMetricData(+ promptVersions.data,+ promptMetrics.data,+ );++ const rows: PromptVersionTableRow[] =+ promptVersions.isSuccess && !!combinedData+ ? combinedData.map((prompt) => {+ return {+ version: prompt.version,+ labels: prompt.labels,+ medianLatency: prompt.medianLatency,+ medianInputTokens: prompt.medianInputTokens,+ medianOutputTokens: prompt.medianOutputTokens,+ medianCost: prompt.medianTotalCost,+ generationCount: prompt.observationCount,+ traceScores: addPrefixToScoreKeys(+ prompt.traceScores ?? {},+ "Trace",+ ),+ generationScores: addPrefixToScoreKeys(+ prompt.observationScores ?? {},+ "Generation",+ ),+ lastUsed:+ prompt.lastUsed?.toLocaleString() ?? "No linked generation yet",+ firstUsed:+ prompt.firstUsed?.toLocaleString() ?? "No linked generation yet",+ };+ })+ : [];++ return (+ <Page+ headerProps={{+ title: promptName,+ itemType: "PROMPT",+ help: {+ description:+ "You can use this prompt within your application through the Langfuse SDKs and integrations. Refer to the documentation for more information.",+ href: "https://langfuse.com/docs/prompt-management/get-started",+ },+ breadcrumb: [+ {+ name: "Prompts",+ href: `/project/${projectId}/prompts/`,+ },+ {+ name: promptName ?? router.query.promptName,+ href: `/project/${projectId}/prompts/${encodeURIComponent(promptName)}`,+ },+ { name: `Metrics` },+ ],+ actionButtonsRight: (+ <DetailPageNav+ key="nav"+ currentId={promptName}+ path={(entry) => `/project/${projectId}/prompts/${entry.id}`}+ listKey="prompts"+ />+ ),+ tabsProps: {+ tabs: getPromptTabs(projectId, promptName),+ activeTab: PROMPT_TABS.METRICS,+ },+ }}+ >+ {showControlsInPageHeader && (+ <TableHeaderControls+ timeRange={timeRange}+ setTimeRange={setTimeRange}+ />+ )}+ <div className="gap-3">+ <DataTableToolbar+ tableName="prompt-versions"+ columns={columns}+ timeRange={showControlsInPageHeader ? undefined : timeRange}+ setTimeRange={showControlsInPageHeader ? undefined : setTimeRange}+ rowHeight={rowHeight}+ setRowHeight={setRowHeight}+ columnVisibility={columnVisibility}+ setColumnVisibility={setColumnVisibilityState}+ columnOrder={columnOrder}+ setColumnOrder={setColumnOrder}+ />+ </div>+ <DataTable+ tableName="promptVersions"+ columns={columns}+ data={+ promptVersions.isLoading+ ? { isLoading: true, isError: false }+ : promptVersions.error+ ? {+ isLoading: false,+ isError: true,+ error: promptVersions.error.message,+ }+ : {+ isLoading: false,+ isError: false,+ data: rows,+ }+ }+ pagination={{+ totalCount,+ onChange: setPaginationState,+ state: paginationState,+ }}+ setOrderBy={setOrderByState}+ orderBy={orderByState}+ columnVisibility={columnVisibility}+ onColumnVisibilityChange={setColumnVisibilityState}+ columnOrder={columnOrder}+ onColumnOrderChange={setColumnOrder}+ rowHeight={rowHeight}+ />+ </Page>+ );+}diff --git a/web/src/features/score-analytics/README.md b/web/src/features/score-analytics/README.mdindex e3cd812e9f..727fd43456 100644--- a/web/src/features/score-analytics/README.md+++ b/web/src/features/score-analytics/README.md@@ -363,7 +363,7 @@ if (isSingleScoreColors(colors)) {## File Locations Reference-**Page**: `/web/src/pages/project/[projectId]/scores/analytics.tsx`+**Page**: `/web/src/features/scores/ScoresAnalyticsPage.tsx`**Feature Directory**: `/web/src/features/score-analytics/`diff --git a/web/src/features/scores/ScoresAnalyticsPage.tsx b/web/src/features/scores/ScoresAnalyticsPage.tsxnew file mode 100644index 0000000000..e45ebe07c8--- /dev/null+++ b/web/src/features/scores/ScoresAnalyticsPage.tsx@@ -0,0 +1,285 @@+/* eslint-disable no-nested-ternary */+import { useRouter } from "next/router";+import { useMemo, useEffect, useRef } from "react";+import Page from "@/src/components/layouts/page";+import {+ getScoresTabs,+ SCORES_TABS,+} from "@/src/features/navigation/utils/scores-tabs";+import { useAnalyticsUrlState } from "@/src/features/score-analytics/lib/analytics-url-state";+import { type ScoreOption } from "@/src/features/score-analytics/components/charts/ScoreCombobox";+import { useDashboardDateRange } from "@/src/hooks/useDashboardDateRange";+import {+ toAbsoluteTimeRange,+ getOptimalInterval,+} from "@/src/utils/date-range-utils";+import { BarChart3 } from "lucide-react";+import { api } from "@/src/utils/api";+import {+ ScoreAnalyticsProvider,+ type DataType,+} from "@/src/features/score-analytics/components/ScoreAnalyticsProvider";+import { ScoreAnalyticsHeader } from "@/src/features/score-analytics/components/ScoreAnalyticsHeader";+import { ScoreAnalyticsDashboard } from "@/src/features/score-analytics/components/ScoreAnalyticsDashboard";+import { Spinner } from "@/src/components/design-system/Spinner/Spinner";++/**+ * Score Analytics V2 - Refactored Architecture+ *+ * This page uses the new Provider + Hook + Smart Cards pattern:+ * - ScoreAnalyticsProvider: Fetches & transforms data once, exposes via Context+ * - ScoreAnalyticsHeader: Score selectors, filters, time range picker+ * - ScoreAnalyticsDashboard: 2x2 responsive grid with 4 smart cards+ * - Smart Cards: Self-contained components that consume Provider context+ * - StatisticsCard: Summary metrics and comparison stats+ * - TimelineChartCard: Time series trends+ * - DistributionChartCard: Score distributions+ * - HeatmapCard: Score comparison heatmaps+ *+ */+export default function ScoresAnalyticsPage() {+ const router = useRouter();+ const projectId = router.query.projectId as string;++ const urlStateHook = useAnalyticsUrlState();+ const { state: urlState, setScore2 } = urlStateHook;++ const { timeRange, setTimeRange } = useDashboardDateRange();++ // Fetch available scores from API+ const {+ data: scoresData,+ isLoading: scoresLoading,+ error: scoresError,+ } = api.scoreAnalytics.getScoreIdentifiers.useQuery(+ { projectId },+ { enabled: !!projectId },+ );++ // Transform API data to ScoreOption format and sort by dataType+ const scoreOptions: ScoreOption[] = useMemo(() => {+ if (!scoresData?.scores) return [];++ // Define sort order for data types+ const typeOrder: Record<string, number> = {+ BOOLEAN: 0,+ CATEGORICAL: 1,+ NUMERIC: 2,+ };++ return scoresData.scores+ .map((score) => ({+ value: score.value,+ name: score.name,+ dataType: score.dataType,+ source: score.source,+ }))+ .sort((a, b) => {+ // Sort by dataType first+ const typeA = typeOrder[a.dataType] ?? 999;+ const typeB = typeOrder[b.dataType] ?? 999;+ if (typeA !== typeB) return typeA - typeB;++ // Then by name alphabetically+ return a.name.localeCompare(b.name);+ });+ }, [scoresData]);++ // Parse selected scores to get their data types+ const score1DataType = useMemo(() => {+ if (!urlState.score1) return undefined;+ const selected = scoreOptions.find((opt) => opt.value === urlState.score1);+ return selected?.dataType;+ }, [urlState.score1, scoreOptions]);++ // Determine which score types are compatible with score1+ // Same-type pairing only: NUMERIC with NUMERIC, BOOLEAN with BOOLEAN, CATEGORICAL with CATEGORICAL+ const compatibleScore2DataTypes = useMemo(() => {+ if (!score1DataType) return undefined;++ // Only allow same-type pairing+ return [score1DataType];+ }, [score1DataType]);++ // Clear score2 when score1's dataType changes+ const prevScore1DataTypeRef = useRef<string | undefined>(undefined);+ useEffect(() => {+ // Skip on initial render+ if (prevScore1DataTypeRef.current === undefined) {+ prevScore1DataTypeRef.current = score1DataType;+ return;+ }++ // If dataType has changed and there's a score2 selected, clear it+ if (prevScore1DataTypeRef.current !== score1DataType && urlState.score2) {+ setScore2(undefined);+ }++ prevScore1DataTypeRef.current = score1DataType;+ }, [score1DataType, urlState.score2, setScore2]);++ // Parse score identifiers (format: "name-dataType-source")+ const parsedScore1 = useMemo(() => {+ if (!urlState.score1) return undefined;+ const selected = scoreOptions.find((opt) => opt.value === urlState.score1);+ if (!selected) return undefined;+ return {+ name: selected.name,+ dataType: selected.dataType as DataType,+ source: selected.source,+ };+ }, [urlState.score1, scoreOptions]);++ const parsedScore2 = useMemo(() => {+ if (!urlState.score2) return undefined;+ const selected = scoreOptions.find((opt) => opt.value === urlState.score2);+ if (!selected) return undefined;+ return {+ name: selected.name,+ dataType: selected.dataType as DataType,+ source: selected.source,+ };+ }, [urlState.score2, scoreOptions]);++ // Convert time range to absolute dates+ const absoluteTimeRange = useMemo(+ () => toAbsoluteTimeRange(timeRange),+ [timeRange],+ );++ // Calculate optimal interval based on time range+ const interval = useMemo(() => {+ if (!absoluteTimeRange) return { count: 1, unit: "day" as const };+ return getOptimalInterval(absoluteTimeRange.from, absoluteTimeRange.to);+ }, [absoluteTimeRange]);++ // Determine query params for Provider+ const queryParams = useMemo(() => {+ if (+ !parsedScore1 ||+ !projectId ||+ !absoluteTimeRange?.from ||+ !absoluteTimeRange?.to+ ) {+ return undefined;+ }++ return {+ projectId,+ score1: parsedScore1,+ score2: parsedScore2,+ fromTimestamp: absoluteTimeRange.from,+ toTimestamp: absoluteTimeRange.to,+ interval,+ objectType: urlState.objectType,+ };+ }, [+ parsedScore1,+ parsedScore2,+ projectId,+ absoluteTimeRange,+ interval,+ urlState.objectType,+ ]);++ // UI state flags+ const hasError = !!scoresError;+ const hasNoScores =+ !scoresLoading && scoreOptions.length === 0 && !scoresError;+ const hasNoSelection = !hasError && !hasNoScores && !urlState.score1;++ return (+ <Page+ headerProps={{+ title: "Scores",+ breadcrumb: [{ name: "Scores", href: `/project/${projectId}/scores` }],+ help: {+ description:+ "A score is an evaluation of a trace or observation. It can be created from user feedback, model-based evaluations, or manual review. See docs to learn more.",+ href: "https://langfuse.com/docs/evaluation/overview",+ },+ tabsProps: {+ tabs: getScoresTabs(projectId),+ activeTab: SCORES_TABS.ANALYTICS,+ },+ }}+ >+ <div className="flex max-h-full flex-col gap-0">+ {/* Header Controls */}+ {!hasError && !hasNoScores && (+ <ScoreAnalyticsHeader+ scoreOptions={scoreOptions}+ timeRange={timeRange}+ onTimeRangeChange={setTimeRange}+ compatibleScore2DataTypes={compatibleScore2DataTypes}+ />+ )}++ {/* Content Section */}+ <div className="max-h-full overflow-y-auto p-4 pt-6">+ {hasError ? (+ <div className="bg-destructive/10 flex flex-col items-center justify-center gap-4 rounded-lg border p-12">+ <BarChart3 className="text-destructive h-12 w-12" />+ <div className="text-center">+ <h3 className="text-lg font-bold">Error Loading Scores</h3>+ <p className="text-muted-foreground mt-2 text-sm">+ Failed to load score data. Please try refreshing the page.+ </p>+ </div>+ </div>+ ) : hasNoScores ? (+ <div className="bg-muted/20 flex flex-col items-center justify-center gap-4 rounded-lg border p-12">+ <BarChart3 className="text-muted-foreground h-12 w-12" />+ <div className="text-center">+ <h3 className="text-lg font-bold">No Scores Available</h3>+ <p className="text-muted-foreground mt-2 text-sm">+ Create scores by adding evaluations to your traces and+ observations.+ </p>+ </div>+ </div>+ ) : hasNoSelection ? (+ <div className="bg-muted/20 flex flex-col items-center justify-center gap-6 rounded-lg border p-12">+ <BarChart3 className="text-muted-foreground h-16 w-16" />+ <div className="max-w-2xl text-center">+ <h3 className="text-2xl font-bold">Select a Score</h3>+ <p className="text-muted-foreground mt-3 text-base">+ Choose one or two scores from the dropdowns above to view+ analytics+ </p>+ <div className="text-muted-foreground mt-6 space-y-3 text-sm">+ <div className="bg-background/50 rounded-lg p-4">+ <p className="text-foreground mb-1 font-bold">+ Single score selected:+ </p>+ <p>View distribution and trends over time</p>+ </div>+ <div className="bg-background/50 rounded-lg p-4">+ <p className="text-foreground mb-1 font-bold">+ Two scores selected:+ </p>+ <p>+ Compare scores with heatmaps, correlation analysis, and+ statistical metrics+ </p>+ </div>+ </div>+ </div>+ </div>+ ) : queryParams ? (+ <ScoreAnalyticsProvider params={queryParams}>+ <ScoreAnalyticsDashboard />+ </ScoreAnalyticsProvider>+ ) : (+ <div className="flex flex-col items-center justify-center gap-4 rounded-lg border p-12">+ <Spinner size="xxl" variant="muted" />+ <p className="text-muted-foreground text-sm">+ Loading analytics data...+ </p>+ </div>+ )}+ </div>+ </div>+ </Page>+ );+}diff --git a/web/src/features/slack/SlackIntegrationPage.tsx b/web/src/features/slack/SlackIntegrationPage.tsxnew file mode 100644index 0000000000..9c74a0db97--- /dev/null+++ b/web/src/features/slack/SlackIntegrationPage.tsx@@ -0,0 +1,214 @@+/* eslint-disable no-nested-ternary */+import ContainerPage from "@/src/components/layouts/container-page";+import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";+import { AutomationButton } from "@/src/features/automations/components/AutomationButton";+import { SlackConnectionCard } from "@/src/features/slack/components/SlackConnectionCard";+import {+ ChannelSelector,+ type SlackChannel,+} from "@/src/features/slack/components/ChannelSelector";+import { SlackTestMessageButton } from "@/src/features/slack/components/SlackTestMessageButton";+import { api } from "@/src/utils/api";+import { useRouter } from "next/router";+import { useState, useEffect } from "react";+import { Badge } from "@/src/components/ui/badge";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/src/components/ui/card";++export default function SlackIntegrationPage() {+ const router = useRouter();+ const projectId = router.query.projectId as string;++ // Handle popup OAuth completion+ useEffect(() => {+ // Check if this page is opened in a popup window+ const isPopup = window.opener && window.opener !== window;++ if (isPopup) {+ // Check for OAuth completion parameters+ const urlParams = new URLSearchParams(window.location.search);+ const success = urlParams.get("success");+ const error = urlParams.get("error");+ const teamName = urlParams.get("team_name");++ if (success === "true") {+ // Send success message to parent window+ window.opener.postMessage(+ {+ type: "slack-oauth-success",+ teamName: teamName || "your Slack workspace",+ },+ window.location.origin,+ );++ // Close popup+ window.close();+ } else if (error) {+ // Send error message to parent window+ window.opener.postMessage(+ {+ type: "slack-oauth-error",+ error: error,+ },+ window.location.origin,+ );++ // Close popup+ window.close();+ }+ }+ }, [router.query]);++ const { data: integrationStatus, isLoading } =+ api.slack.getIntegrationStatus.useQuery(+ { projectId },+ { enabled: !!projectId },+ );++ const status = isLoading+ ? undefined+ : integrationStatus?.isConnected+ ? "active"+ : "inactive";++ const [selectedChannel, setSelectedChannel] = useState<SlackChannel | null>(+ null,+ );++ // Check user permissions+ const hasAccess = useHasProjectAccess({+ projectId,+ scope: "automations:CUD",+ });++ // Channel was typed by name rather than selected from the list+ const isManualEntry = selectedChannel?.id.startsWith("#") ?? false;++ return (+ <ContainerPage+ headerProps={{+ title: "Slack Integration",+ breadcrumb: [+ { name: "Settings", href: `/project/${projectId}/settings` },+ ],+ actionButtonsLeft: <>{status && <StatusBadge type={status} />}</>,+ actionButtonsRight: <AutomationButton projectId={projectId} />,+ }}+ >+ <div className="space-y-6">+ {/* Connection Configuration */}+ <SlackConnectionCard projectId={projectId} showConnectButton={true} />++ {/* Test Channel Section - Only show when connected */}+ {integrationStatus?.isConnected && (+ <Card>+ <CardHeader>+ <CardTitle className="flex items-center gap-2">+ Test Integration+ </CardTitle>+ <CardDescription>+ Test your Slack integration by sending a message to a channel.+ </CardDescription>+ </CardHeader>+ <CardContent className="space-y-4">+ <div>+ <h4 className="mb-2 text-sm font-bold">Select Test Channel</h4>+ <div className="max-w-md">+ <ChannelSelector+ projectId={projectId}+ selectedChannelId={selectedChannel?.id}+ selectedChannel={selectedChannel}+ onChannelSelect={setSelectedChannel}+ placeholder="Choose a channel to test"+ showRefreshButton={true}+ />+ </div>+ </div>++ {selectedChannel && (+ <div className="space-y-4 border-t pt-4">+ <div>+ <h4 className="mb-3 text-sm font-bold">+ Channel Information+ </h4>+ <div className="grid gap-4 md:grid-cols-2">+ <div>+ <p className="text-sm font-bold">Channel Name</p>+ <p className="text-muted-foreground text-sm">+ #{selectedChannel.name}+ </p>+ </div>+ <div>+ <p className="text-sm font-bold">Channel Type</p>+ {isManualEntry ? (+ <span className="text-muted-foreground text-xs">+ Available after sending a test message+ </span>+ ) : (+ <Badge variant="outline" className="text-xs">+ {selectedChannel.isPrivate ? "Private" : "Public"}+ </Badge>+ )}+ </div>+ <div>+ <p className="text-sm font-bold">Channel ID</p>+ {isManualEntry ? (+ <span className="text-muted-foreground text-xs">+ Available after sending a test message+ </span>+ ) : (+ <p className="text-muted-foreground font-mono text-sm">+ {selectedChannel.id}+ </p>+ )}+ </div>+ </div>+ </div>++ <div className="flex items-center gap-3">+ <SlackTestMessageButton+ projectId={projectId}+ selectedChannel={selectedChannel}+ hasAccess={hasAccess}+ disabled={false}+ onSuccess={(channelInfo) => {+ setSelectedChannel((prev) =>+ prev+ ? {+ ...prev,+ id: channelInfo.id,+ name: channelInfo.name ?? prev.name,+ isPrivate:+ channelInfo.isPrivate ?? prev.isPrivate,+ }+ : prev,+ );+ }}+ />+ </div>+ </div>+ )}++ {!selectedChannel && (+ <div className="text-muted-foreground text-sm">+ Select a channel above to view its details and test message+ delivery. For private channels, invite the app first with{" "}+ <code className="bg-muted rounded px-1 py-0.5">+ /invite @Langfuse+ </code>{" "}+ in that channel.+ </div>+ )}+ </CardContent>+ </Card>+ )}+ </div>+ </ContainerPage>+ );+}diff --git a/web/src/pages/account/settings/index.tsx b/web/src/pages/account/settings/index.tsxindex 8fb5e72873..cf3fdbd07d 100644--- a/web/src/pages/account/settings/index.tsx+++ b/web/src/pages/account/settings/index.tsx@@ -1,392 +1,4 @@-/* eslint-disable @repo/no-abstracted-overlay-trigger */-import { PagedSettingsContainer } from "@/src/components/PagedSettingsContainer";-import Header from "@/src/components/layouts/header";-import { Card } from "@/src/components/ui/card";-import { Button } from "@/src/components/ui/button";-import { Input } from "@/src/components/ui/input";-import { api, reportNonTrpcError } from "@/src/utils/api";-import * as z from "zod";-import { zodResolver } from "@hookform/resolvers/zod";-import { useForm } from "react-hook-form";-import {- Form,- FormControl,- FormField,- FormItem,- FormMessage,-} from "@/src/components/ui/form";-import {- Dialog,- DialogBody,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/src/components/ui/dialog";-import { useSession } from "next-auth/react";-import { signOutCleanly } from "@/src/features/auth/lib/signOut";-import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";-import ContainerPage from "@/src/components/layouts/container-page";-import { useRouter } from "next/router";-import { StringNoHTML } from "@langfuse/shared";-import Link from "next/link";-import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";-import { showErrorToast } from "@/src/features/notifications/showErrorToast";-import { useV4UpgradeUiFlag } from "@/src/features/v4-migration/useV4UpgradeUiEnabled";-import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";--const displayNameSchema = z.object({- name: StringNoHTML.min(1, "Name cannot be empty").max(- 100,- "Name must be at most 100 characters",- ),-});--function UpdateDisplayName() {- const { data: session, update: updateSession } = useSession();- const utils = api.useUtils();-- const form = useForm({- resolver: zodResolver(displayNameSchema),- defaultValues: {- name: "",- },- });-- const updateDisplayName = api.userAccount.updateDisplayName.useMutation({- onSuccess: async () => {- await updateSession();- await utils.invalidate();- form.reset();- showSuccessToast({- title: "Display Name Updated",- description: "Your display name has been successfully updated.",- });- },- onError: (error) => form.setError("name", { message: error.message }),- });-- function onSubmit(values: z.infer<typeof displayNameSchema>) {- updateDisplayName.mutate({ name: values.name });- }-- return (- <div>- <Header title="Display Name" />- <Card className="p-3">- {form.getValues().name !== "" ? (- <p className="text-primary mb-4 text-sm">- Your display name will be updated from "- {session?.user?.name ?? ""}- " to "- <b>{form.watch().name}</b>".- </p>- ) : (- <p className="text-primary mb-4 text-sm">- Your display name is currently "- <b>{session?.user?.name ?? ""}</b>- ".- </p>- )}- <Form {...form}>- <form onSubmit={form.handleSubmit(onSubmit)} className="flex-1">- <FormField- control={form.control}- name="name"- render={({ field }) => (- <FormItem>- <FormControl>- <Input- placeholder={session?.user?.name ?? ""}- {...field}- className="flex-1"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- <Button- variant="secondary"- type="submit"- loading={updateDisplayName.isPending}- disabled={form.getValues().name === ""}- className="mt-4"- >- Save- </Button>- </form>- </Form>- </Card>- </div>- );-}--function DeleteAccountButton() {- const { data: session } = useSession();- const userEmail = session?.user?.email ?? "";-- const { data: canDeleteData } = api.userAccount.checkCanDelete.useQuery();- const deleteAccount = api.userAccount.delete.useMutation();-- const formSchema = z.object({- email: z.string().refine((val) => val === userEmail, {- message: `Please enter your email address: ${userEmail}`,- }),- });-- const form = useForm({- resolver: zodResolver(formSchema),- defaultValues: {- email: "",- },- });-- const canDelete = canDeleteData?.canDelete ?? false;- const blockingOrganizations = canDeleteData?.blockingOrganizations ?? [];-- const onSubmit = async () => {- if (!canDelete) return;- try {- await deleteAccount.mutateAsync();- showSuccessToast({- title: "Account Deleted",- description: "Your account has been successfully deleted.",- });- await new Promise((resolve) => setTimeout(resolve, 2000));- await signOutCleanly();- } catch (error) {- reportNonTrpcError(error, "account");- showErrorToast(- "Failed to Delete Account",- error instanceof Error ? error.message : "An unexpected error occurred",- );- }- };-- return (- <Dialog>- <DialogTrigger asChild>- <Button variant="destructive-secondary">Delete Account</Button>- </DialogTrigger>- <DialogContent className="sm:max-w-[425px]">- <DialogHeader>- <DialogTitle className="text-lg font-bold">- Delete Account- </DialogTitle>- <DialogDescription>- {!canDelete && blockingOrganizations.length > 0 ? (- <div>- <p className="mb-2">- You cannot delete your account because you are the last owner- of the following organization(s):- </p>- <ul className="list-inside list-disc space-y-1">- {blockingOrganizations.map((org) => (- <li key={org.id}>- <Link- href={`/organization/${org.id}/settings`}- className="text-primary hover:text-primary/80 font-bold underline"- >- {org.name}- </Link>- </li>- ))}- </ul>- <p className="mt-2">- Please add another owner or delete these organizations before- deleting your account.- </p>- </div>- ) : (- `To confirm, type your email address "${userEmail}" in the input box`- )}- </DialogDescription>- </DialogHeader>- <Form {...form}>- <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">- {canDelete && (- <DialogBody>- <FormField- control={form.control}- name="email"- render={({ field }) => (- <FormItem>- <FormControl>- <Input placeholder={userEmail} {...field} />- </FormControl>- <FormMessage />- </FormItem>- )}- />- </DialogBody>- )}- <DialogFooter>- <Button- type="submit"- variant="destructive"- loading={deleteAccount.isPending}- disabled={!canDelete}- className="w-full"- >- Delete Account- </Button>- </DialogFooter>- </form>- </Form>- </DialogContent>- </Dialog>- );-}--function SignOutAllSessionsButton() {- const signOutAllSessions = api.userAccount.signOutAllSessions.useMutation();-- const onConfirm = async () => {- try {- await signOutAllSessions.mutateAsync();- showSuccessToast({- title: "Signed Out of All Sessions",- description: "All sessions have been invalidated.",- });- } catch (error) {- reportNonTrpcError(error, "account");- showErrorToast(- "Failed to Sign Out of All Sessions",- error instanceof Error ? error.message : "An unexpected error occurred",- );- throw error;- }-- // Sessions are already revoked server-side at this point, so a failure to- // clear local state must not be reported as a failed revocation.- try {- await signOutCleanly();- } catch (error) {- reportNonTrpcError(error, "account");- }- };-- return (- <ConfirmationDialogController- title="Sign Out of All Sessions"- text="This will sign you out on this device and every other device where you are currently signed in. You will need to sign in again."- confirmLabel="Sign Out of All Sessions"- variant="destructive"- loading={signOutAllSessions.isPending}- onConfirm={onConfirm}- >- {({ openDialog }) => (- <Button variant="destructive-secondary" onClick={openDialog}>- Sign Out of All Sessions- </Button>- )}- </ConfirmationDialogController>- );-}--type AccountSettingsPage = {- title: string;- slug: string;- show?: boolean | (() => boolean);- cmdKKeywords?: string[];-} & ({ content: React.ReactNode } | { href: string });--export function useAccountSettingsPages(): AccountSettingsPage[] {- const { data: session } = useSession();- const userEmail = session?.user?.email ?? "";- const showV4Migration = useV4UpgradeUiFlag();-- return getAccountSettingsPages({ userEmail, showV4Migration });-}--const getAccountSettingsPages = ({- userEmail,- showV4Migration,-}: {- userEmail: string;- showV4Migration: boolean;-}): AccountSettingsPage[] => [- {- title: "General",- slug: "index",- cmdKKeywords: [- "account",- "user",- "profile",- "email",- "password",- "name",- "display",- "delete",- "remove",- ],- content: (- <div className="flex flex-col gap-6">- <div>- <Header title="Email" />- <Card className="p-3">- <p className="text-primary text-sm">- Your email address: <b>{userEmail}</b>- </p>- </Card>- </div>- <UpdateDisplayName />- <div>- <Header title="Password" />- <Card className="p-3">- <p className="text-primary mb-4 text-sm">- To change your password, we will email a one-time code to your- address. Enter the code together with your new password.- </p>- <Button asChild variant="secondary">- <Link href="/auth/reset-password">Change Password</Link>- </Button>- </Card>- </div>- <SettingsDangerZone- items={[- {- title: "Sign out of all sessions",- description:- "Invalidate every active session for your account, including this device. You will need to sign in again.",- button: <SignOutAllSessionsButton />,- },- {- title: "Delete your account",- description:- "You can delete your account if you are not the last owner of any organization. If you are the last owner, please add another owner or delete the organization and all projects first.",- button: <DeleteAccountButton />,- },- ]}- />- </div>- ),- },- {- title: "v4 Migration",- slug: "v4-migration",- href: "/v4-migration",- show: showV4Migration,- },-];--export default function AccountSettingsPage() {- const router = useRouter();- const pages = useAccountSettingsPages();-- return (- <ContainerPage- headerProps={{- title: "Account Settings",- }}- >- <PagedSettingsContainer- activeSlug={router.query.page as string | undefined}- pages={pages}- />- </ContainerPage>- );-}+export {+ default,+ useAccountSettingsPages,+} from "@/src/features/account/AccountSettingsPage";diff --git a/web/src/pages/auth/enterprise-sso-required.tsx b/web/src/pages/auth/enterprise-sso-required.tsxindex c36a686325..f546b2b5b6 100644--- a/web/src/pages/auth/enterprise-sso-required.tsx+++ b/web/src/pages/auth/enterprise-sso-required.tsx@@ -1,233 +1 @@-import Head from "next/head";-import Link from "next/link";-import { useRouter } from "next/router";-import { useEffect, useMemo, useState } from "react";-import { signIn } from "next-auth/react";-import { zodResolver } from "@hookform/resolvers/zod";-import * as z from "zod";-import { useForm } from "react-hook-form";-import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";-import { Button } from "@/src/components/ui/button";-import {- Form,- FormControl,- FormField,- FormItem,- FormLabel,- FormMessage,-} from "@/src/components/ui/form";-import { Input } from "@/src/components/ui/input";-import { env } from "@/src/env.mjs";-import { reportError } from "@/src/utils/reportError";-import { isJsonParseSyntaxError } from "@/src/features/auth/lib/expectedAuthErrors";--const enterpriseSsoFormSchema = z.object({- email: z.email(),-});--const PROVIDER_LABELS: Record<string, string> = {- google: "Google",- github: "GitHub",- "github-enterprise": "GitHub Enterprise",- gitlab: "GitLab",- "azure-ad": "Azure AD",- okta: "Okta",- authentik: "Authentik",- onelogin: "OneLogin",- auth0: "Auth0",- cognito: "Cognito",- keycloak: "Keycloak",- jumpcloud: "JumpCloud",- workos: "WorkOS",- wordpress: "WordPress",- custom: "Custom OAuth",-};--export default function EnterpriseSsoRequiredPage() {- const router = useRouter();- const [error, setError] = useState<string | null>(null);- const [loading, setLoading] = useState(false);-- const emailFromQuery =- typeof router.query.email === "string" ? router.query.email : "";- const attemptedProvider =- typeof router.query.attemptedProvider === "string"- ? router.query.attemptedProvider- : undefined;- const callbackUrl =- typeof router.query.callbackUrl === "string"- ? router.query.callbackUrl- : undefined;-- const friendlyProviderName = useMemo(() => {- if (!attemptedProvider) return undefined;- return (- PROVIDER_LABELS[attemptedProvider] ?? attemptedProvider.replace(/-/g, " ")- );- }, [attemptedProvider]);-- const form = useForm<z.infer<typeof enterpriseSsoFormSchema>>({- resolver: zodResolver(enterpriseSsoFormSchema),- defaultValues: {- email: emailFromQuery,- },- });-- useEffect(() => {- if (emailFromQuery) {- form.setValue("email", emailFromQuery);- }- }, [emailFromQuery, form]);-- async function onSubmit(values: z.infer<typeof enterpriseSsoFormSchema>) {- setError(null);- setLoading(true);-- const domain = values.email.split("@")[1]?.toLowerCase();- if (!domain) {- form.setError("email", { message: "Invalid email address" });- setLoading(false);- return;- }-- try {- const response = await fetch(- `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/auth/check-sso`,- {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ domain }),- },- );-- if (response.ok) {- const { providerId } = (await response.json()) as {- providerId: string;- };- await signIn(providerId, {- callbackUrl,- });- return;- }-- if (response.status === 404) {- setError(- "We couldn't find a custom Enterprise SSO configuration for this domain. Double-check your company email or contact your administrator.",- );- return;- }-- const data = (await response.json().catch(() => null)) as {- message?: string;- } | null;- setError(- data?.message ??- "Unable to start the Enterprise SSO sign-in flow. Please try again.",- );- } catch (err) {- reportError(err, {- area: "auth.enterpriseSso",- expected: isJsonParseSyntaxError(err),- extra: { context: "auth.enterpriseSso" },- });- setError(- "Something went wrong while checking your Enterprise SSO configuration. Please try again.",- );- } finally {- setLoading(false);- }- }-- const description = friendlyProviderName- ? `You tried signing in with ${friendlyProviderName}, but this domain requires your company's custom Enterprise SSO.`- : "This domain requires your company's custom Enterprise SSO.";-- return (- <>- <Head>- <title>Enterprise SSO Required | Langfuse</title>- </Head>- <div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8">- <div className="sm:mx-auto sm:w-full sm:max-w-md">- <div className="mx-auto w-fit">- <LangfuseIcon />- </div>- <h1 className="text-primary mt-6 text-center text-2xl font-bold">- Use your Enterprise SSO- </h1>- <p className="text-muted-foreground mt-2 text-center text-sm leading-6">- {description} Enter your company email so we can send you to the- correct identity provider.- </p>- </div>-- <div className="border-border bg-card mt-10 rounded-lg border px-6 py-8 shadow-sm sm:mx-auto sm:w-full sm:max-w-md">- <Form {...form}>- <form className="space-y-6" onSubmit={form.handleSubmit(onSubmit)}>- <FormField- control={form.control}- name="email"- render={({ field }) => (- <FormItem>- <FormLabel>Email</FormLabel>- <FormControl>- <Input- placeholder="[email protected]"- allowPasswordManager- autoComplete="email"- {...field}- />- </FormControl>- <FormMessage />- </FormItem>- )}- />-- <Button- type="submit"- className="w-full"- loading={loading}- disabled={loading}- >- Continue with Enterprise SSO- </Button>- </form>- </Form>- {error ? (- <div className="text-destructive mt-4 text-center text-sm font-bold">- {error}- <br />- Contact{" "}- <a- href="mailto:[email protected]"- className="text-link hover:text-link-hover"- >- </a>{" "}- if this keeps happening.- </div>- ) : null}- <div className="text-muted-foreground mt-6 text-center text-sm">- <Link- href="/auth/sign-in"- className="text-link hover:text-link-hover"- >- Back to other sign-in options- </Link>- </div>- </div>-- <div className="text-muted-foreground mt-4 text-center text-xs">- Need help? Contact{" "}- <a- href="mailto:[email protected]"- className="text-link hover:text-link-hover"- >- </a>- .- </div>- </div>- </>- );-}+export { default } from "@/src/features/auth/EnterpriseSsoRequiredPage";diff --git a/web/src/pages/organization/[organizationId]/settings/[page].tsx b/web/src/pages/organization/[organizationId]/settings/[page].tsxindex a7bbdfee96..d49160d62e 100644--- a/web/src/pages/organization/[organizationId]/settings/[page].tsx+++ b/web/src/pages/organization/[organizationId]/settings/[page].tsx@@ -1,3 +1 @@-import OrgSettingsPage from "@/src/pages/organization/[organizationId]/settings";--export default OrgSettingsPage;+export { default } from "@/src/features/organizations/OrganizationSettingsPage";diff --git a/web/src/pages/organization/[organizationId]/settings/index.tsx b/web/src/pages/organization/[organizationId]/settings/index.tsxindex d86dc9f67e..10fed7a5da 100644--- a/web/src/pages/organization/[organizationId]/settings/index.tsx+++ b/web/src/pages/organization/[organizationId]/settings/index.tsx@@ -1,351 +1,5 @@-import { PagedSettingsContainer } from "@/src/components/PagedSettingsContainer";-import Header from "@/src/components/layouts/header";-import { Button } from "@/src/components/ui/button";-import { ConnectedMembershipInvitesSettingsTable } from "@/src/features/rbac/components/MembershipInvitesSettingsTable/ConnectedMembershipInvitesSettingsTable";-import { ConnectedMembersSettingsTable } from "@/src/features/rbac/components/MembersSettingsTable/ConnectedMembersSettingsTable";-import { JSONView } from "@/src/components/ui/CodeJsonViewer";-import RenameOrganization from "@/src/features/organizations/components/RenameOrganization";-import { DeleteOrganizationDialogController } from "@/src/features/organizations/components/DeleteOrganizationDialogController";-import { useQueryOrganization } from "@/src/features/organizations/hooks";-import { useRouter } from "next/router";-import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";-import { BillingSettings } from "@/src/ee/features/billing/components/BillingSettings";-import { useHasEntitlement, usePlan } from "@/src/features/entitlements/hooks";-import ContainerPage from "@/src/components/layouts/container-page";-import { SSOSettings } from "@/src/ee/features/sso-settings/components/SSOSettings";-import { isCloudPlan } from "@langfuse/shared";-import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";-import { ApiKeyList } from "@/src/features/public-api/components/ApiKeyList";-import AIFeatureSwitch from "@/src/features/organizations/components/AIFeatureSwitch";-import { useIsCloudBillingAvailable } from "@/src/ee/features/billing/utils/isCloudBilling";-import { env } from "@/src/env.mjs";-import { OrgAuditLogsSettingsPage } from "@/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage";-import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";-import { useV4UpgradeUiFlag } from "@/src/features/v4-migration/useV4UpgradeUiEnabled";-import { OrganizationFeaturePreviewsSettings } from "@/src/features/feature-flags/components/OrganizationFeaturePreviewsSettings";-import useIsFeatureEnabled from "@/src/features/feature-flags/hooks/useIsFeatureEnabled";-import {- GatewayApiKeysPage,- GatewayConfigurationPage,- GatewayModelsPage,- GatewayProvidersPage,-} from "@/src/features/ai-gateway";-import useSessionStorage from "@/src/components/useSessionStorage";-import { api } from "@/src/utils/api";--type OrganizationSettingsPage = {- title: string;- slug: string;- section?: string;- show?: boolean | (() => boolean);- cmdKKeywords?: string[];-} & ({ content: React.ReactNode } | { href: string });--export function useOrganizationSettingsPages(): OrganizationSettingsPage[] {- const { organization } = useQueryProjectOrOrganization();- const showBillingSettings = useHasEntitlement("cloud-billing");- const hasAdminApiEntitlement = useHasEntitlement("admin-api");- const hasOrgApiKeyAccess = useHasOrganizationAccess({- organizationId: organization?.id,- scope: "organization:CRUD_apiKeys",- });- const showOrgApiKeySettings = hasAdminApiEntitlement && hasOrgApiKeyAccess;- const showAuditLogs = useHasEntitlement("audit-logs");- const canUpdateOrganization = useHasOrganizationAccess({- organizationId: organization?.id,- scope: "organization:update",- });- const canManageGateway = useHasOrganizationAccess({- organizationId: organization?.id,- scope: "gateway:manage",- });- const plan = usePlan();- const isLangfuseCloud = isCloudPlan(plan) ?? false;- const isCloudBillingAvailable = useIsCloudBillingAvailable();- const showV4Migration = useV4UpgradeUiFlag();- const isAiGatewayEnabled = useIsFeatureEnabled("aiGateway", {- enableForAdmins: false,- organizationId: organization?.id,- });-- if (!organization) return [];-- return getOrganizationSettingsPages({- organization,- showBillingSettings: showBillingSettings && isCloudBillingAvailable,- showOrgApiKeySettings,- showAuditLogs,- isLangfuseCloud,- showV4Migration,- showAiGateway: canManageGateway && isAiGatewayEnabled,- showFeaturePreviews:- canUpdateOrganization && organization.id !== env.NEXT_PUBLIC_DEMO_ORG_ID,- });-}--export const getOrganizationSettingsPages = ({- organization,- showBillingSettings,- showOrgApiKeySettings,- showAuditLogs,- isLangfuseCloud,- showV4Migration,- showAiGateway,- showFeaturePreviews,-}: {- organization: {- id: string;- name: string;- metadata: Record<string, unknown>;- projects: Array<{- id: string;- name: string;- deletedAt?: Date | string | null;- }>;- };- showBillingSettings: boolean;- showOrgApiKeySettings: boolean;- showAuditLogs: boolean;- isLangfuseCloud: boolean;- showV4Migration: boolean;- showAiGateway: boolean;- showFeaturePreviews: boolean;-}): OrganizationSettingsPage[] => [- {- title: "General",- slug: "index",- section: "Organization",- cmdKKeywords: ["name", "id", "delete"],- content: (- <div className="flex flex-col gap-6">- <RenameOrganization />- <div>- <Header title="Debug Information" />- <JSONView- title="Metadata"- json={{- name: organization.name,- id: organization.id,- ...organization.metadata,- ...(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION && {- cloudRegion: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,- }),- }}- />- </div>- <AIFeatureSwitch />- <SettingsDangerZone- items={[- {- title: "Delete this organization",- description:- "Once you delete an organization, there is no going back. Please be certain.",- button: (- <DeleteOrganizationDialogController>- {({ disabled, openDialog }) => (- <Button- variant="destructive-secondary"- disabled={disabled !== undefined}- onClick={openDialog}- >- Delete Organization- </Button>- )}- </DeleteOrganizationDialogController>- ),- },- ]}- />- </div>- ),- },- {- title: "Feature Previews",- slug: "feature-previews",- section: "Organization",- cmdKKeywords: ["feature", "preview", "flags", "beta"],- content: <OrganizationFeaturePreviewsSettings orgId={organization.id} />,- show: showFeaturePreviews,- },- {- title: "API Keys",- slug: "api-keys",- section: "Organization",- content: (- <div className="flex flex-col gap-6">- <ApiKeyList entityId={organization.id} scope="organization" />- </div>- ),- show: showOrgApiKeySettings,- },- {- title: "Members",- slug: "members",- section: "Organization",- cmdKKeywords: ["invite", "user", "rbac"],- content: <OrganizationMembersSettings orgId={organization.id} />,- },- {- title: "Audit Logs",- slug: "audit-logs",- section: "Organization",- cmdKKeywords: ["audit", "logs", "history", "changes"],- content: <OrgAuditLogsSettingsPage orgId={organization.id} />,- show: showAuditLogs,- },- {- title: "Billing",- slug: "billing",- section: "Organization",- cmdKKeywords: ["payment", "subscription", "plan", "invoice"],- content: <BillingSettings />,- show: showBillingSettings,- },- {- title: "SSO",- slug: "sso",- section: "Organization",- cmdKKeywords: [- "sso",- "login",- "auth",- "okta",- "saml",- "azure",- "domain",- "dns",- "txt",- "verify",- ],- content: <SSOSettings orgId={organization.id} />,- show: isLangfuseCloud,- },- {- title: "Projects",- slug: "projects",- section: "Organization",- href: `/organization/${organization.id}`,- },- {- title: "v4 Migration",- slug: "v4-migration",- section: "Organization",- href: "/v4-migration",- show: showV4Migration,- },- {- title: "Configuration",- slug: "ai-gateway",- section: "AI Gateway",- cmdKKeywords: ["gateway", "llm", "configuration", "instrumentation"],- content: (- <GatewayConfigurationPage- organizationId={organization.id}- projects={organization.projects}- />- ),- show: showAiGateway,- },- {- title: "Provider credentials",- slug: "ai-gateway-providers",- section: "AI Gateway",- cmdKKeywords: [- "gateway",- "providers",- "credentials",- "openai",- "anthropic",- ],- content: <GatewayProvidersPage organizationId={organization.id} />,- show: showAiGateway,- },- {- title: "Models",- slug: "ai-gateway-models",- section: "AI Gateway",- cmdKKeywords: ["gateway", "models", "discovery", "sync"],- content: <GatewayModelsPage organizationId={organization.id} />,- show: showAiGateway,- },- {- title: "Gateway API keys",- slug: "ai-gateway-api-keys",- section: "AI Gateway",- cmdKKeywords: ["gateway", "api", "keys", "metadata", "credentials"],- content: <GatewayApiKeysPage organizationId={organization.id} />,- show: showAiGateway,- },-];--const OrgSettingsPage = () => {- const organization = useQueryOrganization();- const router = useRouter();- const { page } = router.query;- const pages = useOrganizationSettingsPages();-- if (!organization) return null;-- return (- <ContainerPage- headerProps={{- title: "Organization Settings",- }}- extendRight={router.query.page === "ai-gateway-models"}- fullHeight={router.query.page === "ai-gateway-models"}- >- <PagedSettingsContainer- activeSlug={page as string | undefined}- pages={pages}- fullHeight={router.query.page === "ai-gateway-models"}- />- </ContainerPage>- );-};--function OrganizationMembersSettings({ orgId }: { orgId: string }) {- const [invitesPagination, setInvitesPagination] = useSessionStorage(- `orgInvites_${orgId}_pagination`,- { pageIndex: 0, pageSize: 10 },- );-- const hasViewAccess = useHasOrganizationAccess({- organizationId: orgId,- scope: "organizationMembers:read",- });-- const membershipInvites = api.members.allInvitesFromOrg.useQuery(- {- orgId,- page: invitesPagination.pageIndex,- limit: invitesPagination.pageSize,- },- { enabled: hasViewAccess },- );-- return (- <div className="flex flex-col gap-6">- <div>- <Header title="Organization Members" />- <ConnectedMembersSettingsTable orgId={orgId} />- </div>- {hasViewAccess && (- <div- className={- membershipInvites.data?.totalCount === 0 ? "hidden" : undefined- }- >- <Header title="Membership Invites" />- <ConnectedMembershipInvitesSettingsTable- orgId={orgId}- query={membershipInvites}- paginationState={invitesPagination}- setPaginationState={setInvitesPagination}- />- </div>- )}- </div>- );-}--export default OrgSettingsPage;+export {+ default,+ useOrganizationSettingsPages,+ getOrganizationSettingsPages,+} from "@/src/features/organizations/OrganizationSettingsPage";diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/charts.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/charts.tsxindex 28d138d1c5..5efda4bc5e 100644--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/charts.tsx+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/charts.tsx@@ -1,333 +1 @@-/* eslint-disable no-nested-ternary */-import { Button } from "@/src/components/ui/button";-import { MultiSelectKeyValues } from "@/src/features/scores/components/multi-select-key-values";-import { FlaskConical, List } from "lucide-react";-import { useRouter } from "next/router";-import { useEffect, useState } from "react";-import { MarkdownJsonView } from "@/src/components/ui/MarkdownJsonView";-import {- Dialog,- DialogContent,- DialogTrigger,-} from "@/src/components/ui/dialog";-import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import { DatasetAnalytics } from "@/src/features/datasets/components/DatasetAnalytics";-import { CompareViewAdapter } from "@/src/features/scores/adapters";-import {- RESOURCE_METRICS,- isEmptyChart,-} from "@/src/features/dashboard/lib/score-analytics-utils";-import {- compareViewChartDataToDataPoints,- getCompareViewChartUnit,-} from "@/src/features/dashboard/lib/chart-data-adapters";-import { Chart } from "@/src/features/widgets/chart-library/Chart";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import Page from "@/src/components/layouts/page";-import { SubHeaderLabel } from "@/src/components/layouts/header";-import {- SidePanel,- SidePanelContent,- SidePanelHeader,- SidePanelTitle,-} from "@/src/components/ui/side-panel";-import useLocalStorage from "@/src/components/useLocalStorage";-import { getScoreDataTypeIcon } from "@/src/features/scores/lib/scoreColumns";-import { useDatasetRunsCompare } from "@/src/features/datasets/hooks/useDatasetRunsCompare";-import { useDatasetRunCompareChartData } from "@/src/features/datasets/hooks/useDatasetRunCompareChartData";-import { Skeleton } from "@/src/components/ui/skeleton";-import {- DATASET_RUN_COMPARE_TABS,- getDatasetRunCompareTabs,-} from "@/src/features/navigation/utils/dataset-run-compare-tabs";-import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";-import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";-import { toExperimentsResultsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";--function DatasetCompareChartsLegacy() {- const router = useRouter();- const capture = usePostHogClientCapture();- const projectId = router.query.projectId as string;- const datasetId = router.query.datasetId as string;-- const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =- useState(false);-- const [selectedMetrics, setSelectedMetrics] = useLocalStorage<string[]>(- `${projectId}-dataset-compare-metrics`,- RESOURCE_METRICS.map((metric) => metric.key),- );-- const hasExperimentWriteAccess = useHasProjectAccess({- projectId,- scope: "promptExperiments:CUD",- });-- const {- runIds,- runs,- dataset,- handleExperimentSettled: handleExperimentSettledBase,- setRunState,- setLocalRuns,- } = useDatasetRunsCompare(projectId, datasetId);-- const { chartDataMap, scoreAnalyticsOptions, scoreKeyToData, isLoading } =- useDatasetRunCompareChartData(projectId, datasetId, runIds);-- const handleExperimentSettled = async (data?: {- success: boolean;- datasetId: string;- runId: string;- runName: string;- }) => {- setIsCreateExperimentDialogOpen(false);- await handleExperimentSettledBase(data);- };-- return (- <Page- headerProps={{- title: `Compare experiments: ${dataset.data?.name ?? datasetId}`,- tabsProps: {- tabs: getDatasetRunCompareTabs(projectId, datasetId),- activeTab: DATASET_RUN_COMPARE_TABS.CHARTS,- },- breadcrumb: [- {- name: "Datasets",- href: `/project/${projectId}/datasets`,- },- {- name: dataset.data?.name ?? datasetId,- href: `/project/${projectId}/datasets/${datasetId}`,- },- {- name: "Experiments",- href: `/project/${projectId}/datasets/${datasetId}/experiments`,- },- ],- help: {- description: "Compare your experiments side by side",- },- actionButtonsRight: (- <>- <Dialog- key="create-experiment-dialog"- open={isCreateExperimentDialogOpen}- onOpenChange={setIsCreateExperimentDialogOpen}- >- <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>- <Button- variant="outline"- disabled={!hasExperimentWriteAccess}- onClick={() => capture("dataset_run:new_form_open")}- >- <FlaskConical className="h-4 w-4" />- <span className="ml-2 hidden md:block">New experiment</span>- </Button>- </DialogTrigger>- <DialogContent className="max-h-[90vh] overflow-y-auto">- <CreateExperimentsForm- key={`create-experiment-form-${datasetId}`}- projectId={projectId as string}- setFormOpen={setIsCreateExperimentDialogOpen}- defaultValues={{- datasetId,- }}- handleExperimentSettled={handleExperimentSettled}- showSDKRunInfoPage- />- </DialogContent>- </Dialog>- <MultiSelectKeyValues- key="select-runs"- title="Experiments"- showSelectedValueStrings={false}- placeholder="Select runs to compare"- className="w-fit"- variant="outline"- hideClearButton- iconLeft={<List className="mr-2 h-4 w-4" />}- options={runs.map((run) => ({- key: run.key,- value: run.value,- disabled: runIds?.includes(run.key) && runIds.length === 1,- }))}- values={runs.filter((run) => runIds?.includes(run.key))}- onValueChange={(values, changedValueId, selectedValueKeys) => {- if (values.length === 0) return;- if (changedValueId) {- if (selectedValueKeys?.has(changedValueId)) {- capture("dataset_run:compare_run_added");- setRunState({- runs: [...(runIds ?? []), changedValueId],- });- setLocalRuns([]);- } else {- capture("dataset_run:compare_run_removed");- setRunState({- runs: runIds?.filter((id) => id !== changedValueId) ?? [],- });- setLocalRuns([]);- }- }- }}- />- </>- ),- }}- >- <div className="grid flex-1 grid-cols-[1fr_auto] overflow-hidden">- <div className="flex h-full flex-col gap-2 overflow-hidden px-3 py-2">- <div className="flex w-full justify-end">- <DatasetAnalytics- key="dataset-analytics"- scoreOptions={scoreAnalyticsOptions}- selectedMetrics={selectedMetrics}- setSelectedMetrics={setSelectedMetrics}- />- </div>- <div className="overflow-y-auto">- {Boolean(selectedMetrics.length) && Boolean(chartDataMap?.size) ? (- <div className="grid w-full grid-cols-2 gap-4 xl:grid-cols-3">- {selectedMetrics.map((key) => {- if (isLoading) {- return <Skeleton key={key} className="h-52 w-full" />;- }-- const adapter = new CompareViewAdapter(chartDataMap, key);- const { chartData, chartLabels } = adapter.toChartData();-- const scoreData = scoreKeyToData.get(key);- const title = scoreData- ? `${getScoreDataTypeIcon(scoreData.dataType)} ${scoreData.name} (${scoreData.source.toLowerCase()})`- : (RESOURCE_METRICS.find((metric) => metric.key === key)- ?.label ?? key);-- if (isEmptyChart({ data: chartData })) {- return (- <div- key={key}- className="flex min-h-[200px] max-w-full min-w-0 flex-col gap-2"- >- <span className="shrink-0 text-sm font-bold">- {title}- </span>- <NoDataOrLoading- isLoading={false}- className="min-h-32 flex-1"- />- </div>- );- }-- const dataPoints = compareViewChartDataToDataPoints(- chartData,- chartLabels,- key,- );-- const chartType =- chartLabels.length === 1- ? "LINE_TIME_SERIES"- : "BAR_TIME_SERIES";-- return (- <div- key={key}- className="flex min-h-[200px] max-w-full min-w-0 flex-col gap-2"- >- <span className="shrink-0 text-sm font-bold">- {title}- </span>- <div className="min-h-[200px] min-w-0 flex-1">- <Chart- chartType={chartType}- data={dataPoints}- rowLimit={Math.max(dataPoints.length, 1)}- chartConfig={{- type: chartType,- unit: getCompareViewChartUnit(key),- }}- // The x-axis is dataset-run names — long and cluttered;- // show them on hover instead of on the axis.- hideXAxisLabels- />- </div>- </div>- );- })}- </div>- ) : isLoading ? (- <Skeleton className="h-52 w-full" />- ) : (- <span className="text-muted-foreground -mt-2 text-sm">- {Boolean(chartDataMap?.size)- ? "All charts hidden. Enable them in the Charts dropdown."- : "Select more than one run to generate charts."}- </span>- )}- </div>- </div>- <SidePanel- mobileTitle={dataset.data?.name ?? datasetId}- id="compare-dataset-runs"- scrollable={false}- >- <SidePanelHeader>- <SidePanelTitle>{dataset.data?.name}</SidePanelTitle>- </SidePanelHeader>- <SidePanelContent className="overflow-y-auto p-1">- <div className="w-full space-y-4">- <div>- <SubHeaderLabel title="Description" />- <span className="text-muted-foreground text-sm">- {dataset.data?.description ?? "No description"}- </span>- </div>- {dataset.data?.metadata && (- <div>- <SubHeaderLabel title="Metadata" />- <MarkdownJsonView content={dataset.data?.metadata} />- </div>- )}- </div>- </SidePanelContent>- </SidePanel>- </div>- </Page>- );-}--function asArrayValue(value: string | string[] | undefined) {- if (!value) return [];- return Array.isArray(value) ? value : [value];-}--export default function DatasetCompare() {- const router = useRouter();- const projectId = router.query.projectId as string;- const runsQuery = router.query.runs;- const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();-- useEffect(() => {- if (- !router.isReady ||- isInitializing ||- !isExperimentsBetaActive ||- !projectId- ) {- return;- }-- router.replace(toExperimentsResultsUrl(projectId, asArrayValue(runsQuery)));- }, [isExperimentsBetaActive, isInitializing, projectId, router, runsQuery]);-- if (!router.isReady || isInitializing || isExperimentsBetaActive) {- return <Skeleton className="h-full w-full" />;- }-- return <DatasetCompareChartsLegacy />;-}+export { default } from "@/src/features/datasets/DatasetCompareChartsPage";diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/index.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/index.tsxindex b8ad76bd07..fc8c9f132b 100644--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/index.tsx+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/compare/index.tsx@@ -1,267 +1 @@-import { Button } from "@/src/components/ui/button";-import { DatasetCompareRunsTable } from "@/src/features/datasets/components/DatasetCompareRunsTable";-import { MultiSelectKeyValues } from "@/src/features/scores/components/multi-select-key-values";-import { FlaskConical, List } from "lucide-react";-import { useRouter } from "next/router";-import { useEffect, useState } from "react";-import {- Dialog,- DialogContent,- DialogTrigger,-} from "@/src/components/ui/dialog";-import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import Page from "@/src/components/layouts/page";-import {- DATASET_RUN_COMPARE_TABS,- getDatasetRunCompareTabs,-} from "@/src/features/navigation/utils/dataset-run-compare-tabs";-import { useDatasetRunsCompare } from "@/src/features/datasets/hooks/useDatasetRunsCompare";-import {- ActiveCellProvider,- useActiveCell,-} from "@/src/features/datasets/contexts/ActiveCellContext";-import { SidePanel, SidePanelContent } from "@/src/components/ui/side-panel";-import { AnnotationPanel } from "@/src/features/datasets/components/AnnotationPanel";-import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";-import { toExperimentsResultsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";-import { Spinner } from "@/src/components/design-system/Spinner/Spinner";--function DatasetCompareLegacy() {- const router = useRouter();- const capture = usePostHogClientCapture();- const projectId = router.query.projectId as string;- const datasetId = router.query.datasetId as string;-- const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =- useState(false);- const [isAnnotationPanelOpen, setIsAnnotationPanelOpen] = useState(false);-- const hasExperimentWriteAccess = useHasProjectAccess({- projectId,- scope: "promptExperiments:CUD",- });-- const {- runIds,- runs,- dataset,- runsData,- handleExperimentSettled: handleExperimentSettledBase,- setRunState,- setLocalRuns,- } = useDatasetRunsCompare(projectId, datasetId);-- const { activeCell, clearActiveCell } = useActiveCell();-- const handleExperimentSettled = async (data?: {- success: boolean;- datasetId: string;- runId: string;- runName: string;- }) => {- setIsCreateExperimentDialogOpen(false);- await handleExperimentSettledBase(data);- };-- // Clear annotation state on URL change (filters, navigation, etc.)- useEffect(() => {- clearActiveCell();- }, [router.query, clearActiveCell]);-- // Open panel when cell becomes active, close when cleared- useEffect(() => {- setIsAnnotationPanelOpen(!!activeCell);- }, [activeCell]);-- // Clear active cell when panel manually closed- const handlePanelOpenChange = (open: boolean) => {- if (!open) {- clearActiveCell();- }- setIsAnnotationPanelOpen(open);- };-- if (!runsData.data || runs.length === 0) {- return (- <div className="flex h-full items-center justify-center">- <Spinner size="xl" variant="muted" />- </div>- );- }-- return (- <Page- headerProps={{- title: `Compare runs: ${dataset.data?.name ?? datasetId}`,- breadcrumb: [- {- name: "Datasets",- href: `/project/${projectId}/datasets`,- },- {- name: dataset.data?.name ?? datasetId,- href: `/project/${projectId}/datasets/${datasetId}`,- },- {- name: "Experiments",- href: `/project/${projectId}/datasets/${datasetId}/experiments`,- },- ],- help: {- description: "Compare your dataset runs side by side",- },- tabsProps: {- tabs: getDatasetRunCompareTabs(projectId, datasetId),- activeTab: DATASET_RUN_COMPARE_TABS.COMPARE,- },- actionButtonsRight: (- <>- <Dialog- key="create-experiment-dialog"- open={isCreateExperimentDialogOpen}- onOpenChange={setIsCreateExperimentDialogOpen}- >- <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>- <Button- variant="outline"- disabled={!hasExperimentWriteAccess}- onClick={() => capture("dataset_run:new_form_open")}- >- <FlaskConical className="h-4 w-4" />- <span className="ml-2 hidden md:block">New experiment</span>- </Button>- </DialogTrigger>- <DialogContent className="max-h-[90vh] overflow-y-auto">- <CreateExperimentsForm- key={`create-experiment-form-${datasetId}`}- projectId={projectId as string}- setFormOpen={setIsCreateExperimentDialogOpen}- defaultValues={{- datasetId,- }}- handleExperimentSettled={handleExperimentSettled}- showSDKRunInfoPage- />- </DialogContent>- </Dialog>- <MultiSelectKeyValues- key="select-runs"- title="Experiments"- showSelectedValueStrings={false}- placeholder="Select runs to compare"- className="w-fit"- variant="outline"- hideClearButton- iconLeft={<List className="mr-2 h-4 w-4" />}- options={runs.map((run) => ({- key: run.key,- value: run.value,- disabled: runIds?.includes(run.key) && runIds.length === 1,- }))}- values={runs.filter((run) => runIds?.includes(run.key))}- onValueChange={(values, changedValueId, selectedValueKeys) => {- if (values.length === 0) return;- if (changedValueId) {- if (selectedValueKeys?.has(changedValueId)) {- capture("dataset_run:compare_run_added");- setRunState({- runs: [...(runIds ?? []), changedValueId],- });- setLocalRuns([]);- } else {- capture("dataset_run:compare_run_removed");- const newRunIds =- runIds?.filter((id) => id !== changedValueId) ?? [];-- // Clear baseline if the removed run was the baseline- const baselineRunId = router.query.baseline as- | string- | undefined;- if (baselineRunId === changedValueId) {- const { baseline, ...restQuery } = router.query;- router.push({- pathname: router.pathname,- query: { ...restQuery, runs: newRunIds },- });- } else {- setRunState({ runs: newRunIds });- }- setLocalRuns([]);- }- }- }}- />- </>- ),- }}- >- <div className="grid flex-1 grid-cols-[1fr_auto] overflow-hidden">- <div className="flex h-full flex-col overflow-hidden">- <DatasetCompareRunsTable- key={runIds?.join(",") ?? "empty"}- projectId={projectId}- datasetId={datasetId}- runIds={runIds ?? []}- />- </div>- <SidePanel- id="annotation-panel"- openState={{- open: isAnnotationPanelOpen,- onOpenChange: handlePanelOpenChange,- }}- mobileTitle="Annotate"- >- <SidePanelContent className="h-full">- {activeCell ? (- <AnnotationPanel projectId={projectId} />- ) : (- <div className="flex items-center justify-center p-4">- <span className="text-muted-foreground text-sm">- Loading annotation data...- </span>- </div>- )}- </SidePanelContent>- </SidePanel>- </div>- </Page>- );-}--function asArrayValue(value: string | string[] | undefined) {- if (!value) return [];- return Array.isArray(value) ? value : [value];-}--export default function DatasetCompare() {- const router = useRouter();- const projectId = router.query.projectId as string;- const runsQuery = router.query.runs;- const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();-- useEffect(() => {- if (- !router.isReady ||- isInitializing ||- !isExperimentsBetaActive ||- !projectId- ) {- return;- }-- router.replace(toExperimentsResultsUrl(projectId, asArrayValue(runsQuery)));- }, [isExperimentsBetaActive, isInitializing, projectId, router, runsQuery]);-- if (!router.isReady || isInitializing || isExperimentsBetaActive) {- return <Spinner size="xl" variant="muted" />;- }-- return (- <ActiveCellProvider>- <DatasetCompareLegacy />- </ActiveCellProvider>- );-}+export { default } from "@/src/features/datasets/DatasetComparePage";diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/experiments/index.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/experiments/index.tsxindex 8f906351e3..b923898862 100644--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/experiments/index.tsx+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/experiments/index.tsx@@ -1,397 +1 @@-import { DatasetRunsTable } from "@/src/features/datasets/components/DatasetRunsTable";-import { api } from "@/src/utils/api";-import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";-import { useState, useCallback } from "react";-import { FlaskConical, MoreVertical } from "lucide-react";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/src/components/ui/dialog";-import { Button } from "@/src/components/ui/button";-import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";-import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";-import { DatasetAnalytics } from "@/src/features/datasets/components/DatasetAnalytics";-import { RESOURCE_METRICS } from "@/src/features/dashboard/lib/score-analytics-utils";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import Page from "@/src/components/layouts/page";-import {- getDatasetTabs,- DATASET_TABS,-} from "@/src/features/navigation/utils/dataset-tabs";-import { TemplateSelector } from "@/src/features/evals/components/template-selector";-import { useEvaluatorDefaults } from "@/src/features/experiments/hooks/useEvaluatorDefaults";-import { useExperimentEvaluatorData } from "@/src/features/experiments/hooks/useExperimentEvaluatorData";-import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";-import {- EvaluatorForm,- useEvaluatorFormTemplate,-} from "@/src/features/evals/components/evaluator-form";-import useLocalStorage from "@/src/components/useLocalStorage";-import { getDatasetBreadcrumb } from "@/src/features/datasets/utils/getDatasetBreadcrumb";-import { ExperimentsTable } from "@/src/features/experiments/components/table";-import { singleRunToExperimentsUrl } from "@/src/features/experiments/utils/experimentUrlTranslation";-import { Skeleton } from "@/src/components/ui/skeleton";-import {- RouteParamsPendingFallback,- useReadyRouteParams,-} from "@/src/hooks/useReadyRouteParams";-import { DatasetActionMenu } from "@/src/features/datasets/components/DatasetActionMenu";--export default function DatasetExperimentsPage() {- const route = useReadyRouteParams(["projectId", "datasetId"]);- if (!route.ready) return <RouteParamsPendingFallback />;- return (- <DatasetExperimentsView- projectId={route.params.projectId}- datasetId={route.params.datasetId}- />- );-}--function DatasetExperimentsView({- projectId,- datasetId,-}: {- projectId: string;- datasetId: string;-}) {- const capture = usePostHogClientCapture();- const utils = api.useUtils();- const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =- useState(false);- const [selectedMetrics, setSelectedMetrics] = useLocalStorage<string[]>(- `${projectId}-${datasetId}-chart-metrics`,- RESOURCE_METRICS.map((metric) => metric.key),- );-- const [scoreOptions, setScoreOptions] = useState<- {- key: string;- value: string;- }[]- >([]);-- const dataset = api.datasets.byId.useQuery(- {- datasetId,- projectId,- },- { enabled: Boolean(projectId) && Boolean(datasetId) },- );-- const hasReadAccess = useHasProjectAccess({- projectId,- scope: "evalJobExecution:read",- });-- const hasExperimentWriteAccess = useHasProjectAccess({- projectId,- scope: "promptExperiments:CUD",- });- const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();-- const handleExperimentSuccess = async (data?: {- success: boolean;- datasetId: string;- runId: string;- runName: string;- }) => {- setIsCreateExperimentDialogOpen(false);- if (!data) return;-- if (isExperimentsBetaActive) {- utils.experiments.all.invalidate();- utils.experiments.countAll.invalidate();- // The empty-window fallback is its own query, and a new run belongs in- // it: without this it keeps serving its cached list.- utils.experiments.mostRecent.invalidate();- } else {- utils.datasets.runsByDatasetId.invalidate();- utils.datasets.baseRunDataByDatasetId.invalidate();- }-- showSuccessToast({- title: "Experiment triggered successfully",- description: "Waiting for experiment to complete...",- link: {- text: "View experiment",- href: isExperimentsBetaActive- ? singleRunToExperimentsUrl(projectId, data.runId)- : `/project/${projectId}/datasets/${data.datasetId}/compare?runs=${data.runId}`,- },- });- };-- const hasEvaluationRuleReadAccess = useHasProjectAccess({- projectId,- scope: "evaluationRule:read",- });-- const hasEvaluationRuleWriteAccess = useHasProjectAccess({- projectId,- scope: "evaluationRule:CUD",- });-- const hasEvaluatorReadAccess = useHasProjectAccess({- projectId,- scope: "evaluator:read",- });-- const evalTemplates = api.evals.latestTemplates.useQuery(- { projectId },- {- enabled:- !isExperimentsBetaActive &&- hasEvaluatorReadAccess &&- Boolean(projectId),- },- );-- const evaluators = api.evals.jobConfigsByTarget.useQuery(- { projectId, targetObject: ["dataset", "experiment"] },- {- enabled:- !isExperimentsBetaActive && hasEvaluationRuleReadAccess && !!datasetId,- },- );-- const { createDefaultEvaluator } = useEvaluatorDefaults();-- const {- selectedEvaluatorData,- showEvaluatorForm,- handleConfigureEvaluator,- handleCloseEvaluatorForm,- handleEvaluatorSuccess,- handleSelectEvaluator,- } = useExperimentEvaluatorData({- datasetId,- createDefaultEvaluator,- evaluatorsData: evaluators.data,- evalTemplatesData: evalTemplates.data,- refetchEvaluators: evaluators.refetch,- });- const evalTemplate = useEvaluatorFormTemplate({- evalTemplates: evalTemplates.data?.templates ?? [],- evalTemplate: selectedEvaluatorData?.evaluator.evalTemplate,- templateId: selectedEvaluatorData?.templateId,- });- // Callback for preprocessing evaluator form values- // For experiment evaluators, we only run on new data (not historic)- const preprocessFormValues = useCallback((values: any) => values, []);-- const breadcrumb = getDatasetBreadcrumb(- projectId,- datasetId,- dataset.data?.name,- );-- if (isInitializing) {- return <Skeleton className="h-full w-full" />;- }-- if (isExperimentsBetaActive) {- return (- <Page- headerProps={{- title: dataset.data?.name ?? "",- itemType: "DATASET",- breadcrumb,- tabsProps: {- tabs: getDatasetTabs(projectId, datasetId),- activeTab: DATASET_TABS.EXPERIMENTS,- },- actionButtonsRight: (- <>- <Dialog- open={isCreateExperimentDialogOpen}- onOpenChange={setIsCreateExperimentDialogOpen}- >- <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>- <Button- disabled={!hasExperimentWriteAccess}- onClick={() => capture("dataset_run:new_form_open")}- >- <FlaskConical className="h-4 w-4" />- <span className="ml-2 hidden md:block">Run experiment</span>- </Button>- </DialogTrigger>- <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">- <CreateExperimentsForm- key={`create-experiment-form-${datasetId}`}- projectId={projectId as string}- setFormOpen={setIsCreateExperimentDialogOpen}- defaultValues={{- datasetId,- }}- handleExperimentSuccess={handleExperimentSuccess}- showSDKRunInfoPage- />- </DialogContent>- </Dialog>- </>- ),- }}- >- <ExperimentsTable- projectId={projectId}- fixedFilter={[- {- column: "experimentDatasetId",- type: "stringOptions",- operator: "any of",- value: [datasetId],- },- ]}- sessionFilterContextId={`dataset-${datasetId}`}- showControlsInPageHeader- />- </Page>- );- }-- return (- <Page- headerProps={{- title: dataset.data?.name ?? "",- itemType: "DATASET",- breadcrumb,- help: dataset.data?.description- ? {- description: dataset.data.description,- }- : undefined,- tabsProps: {- tabs: getDatasetTabs(projectId, datasetId),- activeTab: DATASET_TABS.EXPERIMENTS,- },- actionButtonsRight: (- <>- <Dialog- open={isCreateExperimentDialogOpen}- onOpenChange={setIsCreateExperimentDialogOpen}- >- <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>- <Button- disabled={!hasExperimentWriteAccess}- onClick={() => capture("dataset_run:new_form_open")}- >- <FlaskConical className="h-4 w-4" />- <span className="ml-2 hidden md:block">Run experiment</span>- </Button>- </DialogTrigger>- <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">- <CreateExperimentsForm- key={`create-experiment-form-${datasetId}`}- projectId={projectId as string}- setFormOpen={setIsCreateExperimentDialogOpen}- defaultValues={{- datasetId,- }}- handleExperimentSuccess={handleExperimentSuccess}- showSDKRunInfoPage- />- </DialogContent>- </Dialog>-- {hasEvaluationRuleReadAccess && hasEvaluatorReadAccess ? (- <div className="w-fit">- <TemplateSelector- projectId={projectId}- datasetId={datasetId}- evalTemplates={evalTemplates.data?.templates ?? []}- onConfigureTemplate={handleConfigureEvaluator}- onSelectEvaluator={handleSelectEvaluator}- disabled={!hasEvaluationRuleWriteAccess}- />- </div>- ) : null}-- <DatasetAnalytics- key="dataset-analytics"- scoreOptions={scoreOptions}- selectedMetrics={selectedMetrics}- setSelectedMetrics={setSelectedMetrics}- />-- <DetailPageNav- currentId={datasetId}- path={(entry) =>- `/project/${projectId}/datasets/${entry.id}/experiments`- }- listKey="datasets"- />- <DatasetActionMenu- projectId={projectId}- datasetId={datasetId}- datasetName={dataset.data?.name ?? ""}- datasetDescription={dataset.data?.description ?? undefined}- datasetMetadata={dataset.data?.metadata}- datasetInputSchema={dataset.data?.inputSchema ?? undefined}- datasetExpectedOutputSchema={- dataset.data?.expectedOutputSchema ?? undefined- }- manageEvaluatorsHref={- hasReadAccess- ? `/project/${projectId}/evals?target=dataset`- : undefined- }- >- {({ getTriggerProps }) => (- <Button- variant="outline"- size="icon"- aria-label="Dataset actions"- {...getTriggerProps()}- >- <MoreVertical className="h-4 w-4" />- </Button>- )}- </DatasetActionMenu>- </>- ),- }}- >- <DatasetRunsTable- projectId={projectId}- datasetId={datasetId}- selectedMetrics={selectedMetrics}- setScoreOptions={setScoreOptions}- />- {/* Dialog for configuring evaluators */}- {selectedEvaluatorData && evalTemplate && (- <Dialog- open={showEvaluatorForm}- onOpenChange={(open) => {- if (!open) {- handleCloseEvaluatorForm();- }- }}- >- <DialogContent className="max-h-[90vh] max-w-(--breakpoint-md) overflow-y-auto">- <DialogHeader>- <DialogTitle>- {selectedEvaluatorData.evaluator.id ? "Edit" : "Configure"}{" "}- Evaluator- </DialogTitle>- </DialogHeader>- <EvaluatorForm- useDialog={true}- projectId={projectId}- evalTemplate={evalTemplate}- existingEvaluator={selectedEvaluatorData.evaluator}- mode={selectedEvaluatorData.evaluator.id ? "edit" : "create"}- hideTargetSection={!selectedEvaluatorData.evaluator.id}- onFormSuccess={handleEvaluatorSuccess}- preprocessFormValues={preprocessFormValues}- />- </DialogContent>- </Dialog>- )}- </Page>- );-}+export { default } from "@/src/features/datasets/DatasetExperimentsPage";diff --git a/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx b/web/src/pages/project/[projectId]/prompts/[[...folder]].tsxindex fd26790a0b..fdfdb86e41 100644--- a/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx+++ b/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx@@ -9,7 +9,7 @@ import { api } from "@/src/utils/api";import { PromptsOnboarding } from "@/src/components/onboarding/PromptsOnboarding";import { useEntitlementLimit } from "@/src/features/entitlements/hooks";import { PromptDetail } from "@/src/features/prompts/components/prompt-detail";-import PromptMetrics from "./metrics";+import PromptMetrics from "@/src/features/prompts/PromptMetricsPage";import { useQueryParams, StringParam } from "use-query-params";import { useState } from "react";import { AutomationButton } from "@/src/features/automations/components/AutomationButton";diff --git a/web/src/pages/project/[projectId]/prompts/metrics.tsx b/web/src/pages/project/[projectId]/prompts/metrics.tsxindex f3b0d52e65..594be23047 100644--- a/web/src/pages/project/[projectId]/prompts/metrics.tsx+++ b/web/src/pages/project/[projectId]/prompts/metrics.tsx@@ -1,459 +1 @@-/* eslint-disable no-nested-ternary */-import { DataTable } from "@/src/components/table/data-table";-import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";-import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";-import { type LangfuseColumnDef } from "@/src/components/table/types";-import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";-import { useRouter } from "next/router";-import { api } from "@/src/utils/api";-import { NumberParam, useQueryParams, withDefault } from "use-query-params";-import { type RouterOutput } from "@/src/utils/types";-import { createLinkTableColumn } from "@/src/components/design-system/table/columns/createLinkTableColumn";-import { createNumberTableColumn } from "@/src/components/design-system/table/columns/createNumberTableColumn";-import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";-import { numberFormatter, usdFormatter } from "@/src/utils/numbers";-import { formatIntervalSeconds } from "@/src/utils/dates";-import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";-import { Skeleton } from "@/src/components/ui/skeleton";-import { type ScoreAggregate } from "@langfuse/shared";-import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";-import Page from "@/src/components/layouts/page";-import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";-import { TruncatedLabels } from "@/src/components/TruncatedLabels";-import {- getPromptTabs,- PROMPT_TABS,-} from "@/src/features/navigation/utils/prompt-tabs";-import { useScoreColumns } from "@/src/features/scores/hooks/useScoreColumns";-import {- scoreFilters,- addPrefixToScoreKeys,-} from "@/src/features/scores/lib/scoreColumns";-import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";-import { useTableDateRange } from "@/src/hooks/useTableDateRange";-import { toAbsoluteTimeRange } from "@/src/utils/date-range-utils";-import { useMemo } from "react";-import { TableHeaderControls } from "@/src/components/table/table-header-controls";--export type PromptVersionTableRow = {- version: number;- labels: string[];- medianLatency?: number | null;- medianInputTokens?: number | null;- medianOutputTokens?: number | null;- medianCost?: number | null;- generationCount?: bigint | null;- traceScores?: ScoreAggregate;- generationScores?: ScoreAggregate;- lastUsed?: string | null;- firstUsed?: string | null;-};--type PromptCoreOutput = RouterOutput["prompts"]["allVersions"];-type PromptMetricsOutput = RouterOutput["prompts"]["versionMetrics"];-type PromptMetric = PromptMetricsOutput[number];-type PromptCoreData = PromptCoreOutput["promptVersions"][number];--function joinPromptCoreAndMetricData(- promptCoreData?: PromptCoreOutput,- promptMetricsData?: PromptMetricsOutput,-): {- status: "loading" | "error" | "success";- combinedData: (PromptCoreData & Partial<PromptMetric>)[] | undefined;-} {- if (!promptCoreData) return { status: "loading", combinedData: undefined };-- const { promptVersions } = promptCoreData;-- if (!promptMetricsData)- return { status: "success", combinedData: promptVersions };-- const promptMetricsMap = promptMetricsData.reduce(- (acc, metric: PromptMetric) => {- acc.set(metric.id, metric);- return acc;- },- new Map<string, PromptMetric>(),- );-- const combinedData = promptVersions.map((coreData) => {- const metric = promptMetricsMap.get(coreData.id);- return {- ...coreData,- ...(metric && metric),- };- });-- return { status: "success", combinedData };-}--export default function PromptVersionTable({- promptName: promptNameProp,- // Defaults to true because this component always renders its own `Page`, so- // the header controls slot is available. Set false if ever embedded without- // a `Page` ancestor, to fall back to the toolbar.- showControlsInPageHeader = true,-}: { promptName?: string; showControlsInPageHeader?: boolean } = {}) {- const router = useRouter();- const projectId = useProjectIdFromURL() ?? "";- const promptNameFromQuery = router.query.promptName;- const promptName =- promptNameProp ||- (typeof promptNameFromQuery === "string"- ? decodeURIComponent(promptNameFromQuery)- : "");-- const [paginationState, setPaginationState] = useQueryParams({- pageIndex: withDefault(NumberParam, 0),- pageSize: withDefault(NumberParam, 50),- });- const [orderByState, setOrderByState] = useOrderByState({- column: "startTime",- order: "DESC",- });- const [rowHeight, setRowHeight] = useRowHeightLocalStorage(- "promptVersion",- "s",- );- const { timeRange, setTimeRange } = useTableDateRange(projectId, {- defaultRelativeAggregation: "last30Days",- });- const dateRange = useMemo(- () => ("range" in timeRange ? toAbsoluteTimeRange(timeRange) : timeRange),- [timeRange],- );-- const promptVersions = api.prompts.allVersions.useQuery(- {- projectId,- name: promptName,- page: paginationState.pageIndex,- limit: paginationState.pageSize,- },- { enabled: Boolean(projectId) },- );-- const promptIds = promptVersions.isSuccess- ? promptVersions.data?.promptVersions.map((prompt) => prompt.id)- : [];-- const promptMetrics = api.prompts.versionMetrics.useQuery(- {- projectId,- promptIds,- fromTimestamp: dateRange?.from,- toTimestamp: dateRange?.to,- },- {- enabled: Boolean(projectId) && promptVersions.isSuccess,- trpc: {- context: {- skipBatch: true,- },- },- },- );-- const { scoreColumns: traceScoreColumns, isLoading: isTraceColumnLoading } =- useScoreColumns<PromptVersionTableRow>({- scoreColumnKey: "traceScores",- projectId: projectId,- filter: scoreFilters.forTraceLevel(),- prefix: "Trace",- });-- const {- scoreColumns: generationScoreColumns,- isLoading: isGenerationColumnLoading,- } = useScoreColumns<PromptVersionTableRow>({- scoreColumnKey: "generationScores",- projectId: projectId,- filter: scoreFilters.forObservations(),- prefix: "Generation",- });-- const columns: LangfuseColumnDef<PromptVersionTableRow>[] = [- createLinkTableColumn<PromptVersionTableRow, number>({- accessorKey: "version",- header: "Version",- isPinnedLeft: true,- size: 80,- getCell: (version) => {- if (typeof version !== "number") return undefined;-- return {- type: "link",- props: {- path: `/project/${projectId}/prompts/${encodeURIComponent(promptName)}/?version=${version}`,- value: String(version),- },- };- },- }),- {- accessorKey: "labels",- id: "labels",- header: "Labels",- isPinnedLeft: true,- size: 160,- cell: ({ row }) => {- const values: string[] = row.getValue("labels");- return (- values &&- values.length > 0 && (- <TruncatedLabels- labels={values}- maxVisibleLabels={3}- className="-mr-8 flex max-h-full flex-wrap gap-1"- showSimpleBadges={true}- />- )- );- },- enableHiding: true,- },- createNumberTableColumn<PromptVersionTableRow>({- accessorKey: "medianLatency",- header: "Median latency",- size: 140,- formatter: (value) => formatIntervalSeconds(value / 1000, 3),- getValue: (value) => {- if (!promptMetrics.isSuccess) return { type: "loading" };- if (!value) return undefined;-- return value;- },- enableHiding: true,- }),- createNumberTableColumn<PromptVersionTableRow>({- accessorKey: "medianInputTokens",- header: "Median input tokens",- size: 160,- enableHiding: true,- formatter: (value) => String(value),- getValue: (value) => {- if (!promptMetrics.isSuccess) return { type: "loading" };- if (!value) return undefined;-- return value;- },- }),- createNumberTableColumn<PromptVersionTableRow>({- accessorKey: "medianOutputTokens",- header: "Median output tokens",- size: 170,- enableHiding: true,- formatter: (value) => String(value),- getValue: (value) => {- if (!promptMetrics.isSuccess) return { type: "loading" };- if (!value) return undefined;-- return value;- },- }),- createNumberTableColumn<PromptVersionTableRow>({- accessorKey: "medianCost",- header: "Median cost",- size: 120,- formatter: (value) => usdFormatter(value),- getValue: (value) => {- if (!promptMetrics.isSuccess) return { type: "loading" };- if (!value) return undefined;-- return value;- },- enableHiding: true,- }),- createNumberTableColumn<PromptVersionTableRow, bigint>({- accessorKey: "generationCount",- header: "Generations count",- size: 150,- enableHiding: true,- formatter: (value) => numberFormatter(value, 0),- getValue: (value) =>- promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },- }),- {- accessorKey: "traceScores",- header: "Trace Scores",- id: "traceScores",- enableHiding: true,- columns: traceScoreColumns,- cell: () => {- return isTraceColumnLoading ? (- <Skeleton className="h-3 w-1/2"></Skeleton>- ) : null;- },- },- {- accessorKey: "generationScores",- header: "Generation Scores",- id: "generationScores",- enableHiding: true,- columns: generationScoreColumns,- cell: () => {- return isGenerationColumnLoading ? (- <Skeleton className="h-3 w-1/2"></Skeleton>- ) : null;- },- },- createTextTableColumn<PromptVersionTableRow>({- accessorKey: "lastUsed",- header: "Last used",- enableHiding: true,- size: 150,- headerTooltip: {- description:- "This is calculated based on the selected date range, not the full usage history.",- },- mapValue: (value) =>- promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },- }),- createTextTableColumn<PromptVersionTableRow>({- accessorKey: "firstUsed",- header: "First used",- size: 150,- enableHiding: true,- headerTooltip: {- description:- "This is calculated based on the selected date range, not the full usage history.",- },- mapValue: (value) =>- promptMetrics.isSuccess ? (value ?? undefined) : { type: "loading" },- }),- ];-- const [columnVisibility, setColumnVisibilityState] =- useColumnVisibility<PromptVersionTableRow>(- `promptVersionsColumnVisibility-${projectId}`,- columns,- );-- const [columnOrder, setColumnOrder] = useColumnOrder<PromptVersionTableRow>(- "promptVersionsColumnOrder",- columns,- );-- const totalCount = promptVersions?.data?.totalCount ?? null;-- const { combinedData } = joinPromptCoreAndMetricData(- promptVersions.data,- promptMetrics.data,- );-- const rows: PromptVersionTableRow[] =- promptVersions.isSuccess && !!combinedData- ? combinedData.map((prompt) => {- return {- version: prompt.version,- labels: prompt.labels,- medianLatency: prompt.medianLatency,- medianInputTokens: prompt.medianInputTokens,- medianOutputTokens: prompt.medianOutputTokens,- medianCost: prompt.medianTotalCost,- generationCount: prompt.observationCount,- traceScores: addPrefixToScoreKeys(- prompt.traceScores ?? {},- "Trace",- ),- generationScores: addPrefixToScoreKeys(- prompt.observationScores ?? {},- "Generation",- ),- lastUsed:- prompt.lastUsed?.toLocaleString() ?? "No linked generation yet",- firstUsed:- prompt.firstUsed?.toLocaleString() ?? "No linked generation yet",- };- })- : [];-- return (- <Page- headerProps={{- title: promptName,- itemType: "PROMPT",- help: {- description:- "You can use this prompt within your application through the Langfuse SDKs and integrations. Refer to the documentation for more information.",- href: "https://langfuse.com/docs/prompt-management/get-started",- },- breadcrumb: [- {- name: "Prompts",- href: `/project/${projectId}/prompts/`,- },- {- name: promptName ?? router.query.promptName,- href: `/project/${projectId}/prompts/${encodeURIComponent(promptName)}`,- },- { name: `Metrics` },- ],- actionButtonsRight: (- <DetailPageNav- key="nav"- currentId={promptName}- path={(entry) => `/project/${projectId}/prompts/${entry.id}`}- listKey="prompts"- />- ),- tabsProps: {- tabs: getPromptTabs(projectId, promptName),- activeTab: PROMPT_TABS.METRICS,- },- }}- >- {showControlsInPageHeader && (- <TableHeaderControls- timeRange={timeRange}- setTimeRange={setTimeRange}- />- )}- <div className="gap-3">- <DataTableToolbar- tableName="prompt-versions"- columns={columns}- timeRange={showControlsInPageHeader ? undefined : timeRange}- setTimeRange={showControlsInPageHeader ? undefined : setTimeRange}- rowHeight={rowHeight}- setRowHeight={setRowHeight}- columnVisibility={columnVisibility}- setColumnVisibility={setColumnVisibilityState}- columnOrder={columnOrder}- setColumnOrder={setColumnOrder}- />- </div>- <DataTable- tableName="promptVersions"- columns={columns}- data={- promptVersions.isLoading- ? { isLoading: true, isError: false }- : promptVersions.error- ? {- isLoading: false,- isError: true,- error: promptVersions.error.message,- }- : {- isLoading: false,- isError: false,- data: rows,- }- }- pagination={{- totalCount,- onChange: setPaginationState,- state: paginationState,- }}- setOrderBy={setOrderByState}- orderBy={orderByState}- columnVisibility={columnVisibility}- onColumnVisibilityChange={setColumnVisibilityState}- columnOrder={columnOrder}- onColumnOrderChange={setColumnOrder}- rowHeight={rowHeight}- />- </Page>- );-}+export { default } from "@/src/features/prompts/PromptMetricsPage";diff --git a/web/src/pages/project/[projectId]/scores/analytics.tsx b/web/src/pages/project/[projectId]/scores/analytics.tsxindex a668ac1639..37786ae90b 100644--- a/web/src/pages/project/[projectId]/scores/analytics.tsx+++ b/web/src/pages/project/[projectId]/scores/analytics.tsx@@ -1,285 +1 @@-/* eslint-disable no-nested-ternary */-import { useRouter } from "next/router";-import { useMemo, useEffect, useRef } from "react";-import Page from "@/src/components/layouts/page";-import {- getScoresTabs,- SCORES_TABS,-} from "@/src/features/navigation/utils/scores-tabs";-import { useAnalyticsUrlState } from "@/src/features/score-analytics/lib/analytics-url-state";-import { type ScoreOption } from "@/src/features/score-analytics/components/charts/ScoreCombobox";-import { useDashboardDateRange } from "@/src/hooks/useDashboardDateRange";-import {- toAbsoluteTimeRange,- getOptimalInterval,-} from "@/src/utils/date-range-utils";-import { BarChart3 } from "lucide-react";-import { api } from "@/src/utils/api";-import {- ScoreAnalyticsProvider,- type DataType,-} from "@/src/features/score-analytics/components/ScoreAnalyticsProvider";-import { ScoreAnalyticsHeader } from "@/src/features/score-analytics/components/ScoreAnalyticsHeader";-import { ScoreAnalyticsDashboard } from "@/src/features/score-analytics/components/ScoreAnalyticsDashboard";-import { Spinner } from "@/src/components/design-system/Spinner/Spinner";--/**- * Score Analytics V2 - Refactored Architecture- *- * This page uses the new Provider + Hook + Smart Cards pattern:- * - ScoreAnalyticsProvider: Fetches & transforms data once, exposes via Context- * - ScoreAnalyticsHeader: Score selectors, filters, time range picker- * - ScoreAnalyticsDashboard: 2x2 responsive grid with 4 smart cards- * - Smart Cards: Self-contained components that consume Provider context- * - StatisticsCard: Summary metrics and comparison stats- * - TimelineChartCard: Time series trends- * - DistributionChartCard: Score distributions- * - HeatmapCard: Score comparison heatmaps- *- */-export default function ScoresAnalyticsV2Page() {- const router = useRouter();- const projectId = router.query.projectId as string;-- const urlStateHook = useAnalyticsUrlState();- const { state: urlState, setScore2 } = urlStateHook;-- const { timeRange, setTimeRange } = useDashboardDateRange();-- // Fetch available scores from API- const {- data: scoresData,- isLoading: scoresLoading,- error: scoresError,- } = api.scoreAnalytics.getScoreIdentifiers.useQuery(- { projectId },- { enabled: !!projectId },- );-- // Transform API data to ScoreOption format and sort by dataType- const scoreOptions: ScoreOption[] = useMemo(() => {- if (!scoresData?.scores) return [];-- // Define sort order for data types- const typeOrder: Record<string, number> = {- BOOLEAN: 0,- CATEGORICAL: 1,- NUMERIC: 2,- };-- return scoresData.scores- .map((score) => ({- value: score.value,- name: score.name,- dataType: score.dataType,- source: score.source,- }))- .sort((a, b) => {- // Sort by dataType first- const typeA = typeOrder[a.dataType] ?? 999;- const typeB = typeOrder[b.dataType] ?? 999;- if (typeA !== typeB) return typeA - typeB;-- // Then by name alphabetically- return a.name.localeCompare(b.name);- });- }, [scoresData]);-- // Parse selected scores to get their data types- const score1DataType = useMemo(() => {- if (!urlState.score1) return undefined;- const selected = scoreOptions.find((opt) => opt.value === urlState.score1);- return selected?.dataType;- }, [urlState.score1, scoreOptions]);-- // Determine which score types are compatible with score1- // Same-type pairing only: NUMERIC with NUMERIC, BOOLEAN with BOOLEAN, CATEGORICAL with CATEGORICAL- const compatibleScore2DataTypes = useMemo(() => {- if (!score1DataType) return undefined;-- // Only allow same-type pairing- return [score1DataType];- }, [score1DataType]);-- // Clear score2 when score1's dataType changes- const prevScore1DataTypeRef = useRef<string | undefined>(undefined);- useEffect(() => {- // Skip on initial render- if (prevScore1DataTypeRef.current === undefined) {- prevScore1DataTypeRef.current = score1DataType;- return;- }-- // If dataType has changed and there's a score2 selected, clear it- if (prevScore1DataTypeRef.current !== score1DataType && urlState.score2) {- setScore2(undefined);- }-- prevScore1DataTypeRef.current = score1DataType;- }, [score1DataType, urlState.score2, setScore2]);-- // Parse score identifiers (format: "name-dataType-source")- const parsedScore1 = useMemo(() => {- if (!urlState.score1) return undefined;- const selected = scoreOptions.find((opt) => opt.value === urlState.score1);- if (!selected) return undefined;- return {- name: selected.name,- dataType: selected.dataType as DataType,- source: selected.source,- };- }, [urlState.score1, scoreOptions]);-- const parsedScore2 = useMemo(() => {- if (!urlState.score2) return undefined;- const selected = scoreOptions.find((opt) => opt.value === urlState.score2);- if (!selected) return undefined;- return {- name: selected.name,- dataType: selected.dataType as DataType,- source: selected.source,- };- }, [urlState.score2, scoreOptions]);-- // Convert time range to absolute dates- const absoluteTimeRange = useMemo(- () => toAbsoluteTimeRange(timeRange),- [timeRange],- );-- // Calculate optimal interval based on time range- const interval = useMemo(() => {- if (!absoluteTimeRange) return { count: 1, unit: "day" as const };- return getOptimalInterval(absoluteTimeRange.from, absoluteTimeRange.to);- }, [absoluteTimeRange]);-- // Determine query params for Provider- const queryParams = useMemo(() => {- if (- !parsedScore1 ||- !projectId ||- !absoluteTimeRange?.from ||- !absoluteTimeRange?.to- ) {- return undefined;- }-- return {- projectId,- score1: parsedScore1,- score2: parsedScore2,- fromTimestamp: absoluteTimeRange.from,- toTimestamp: absoluteTimeRange.to,- interval,- objectType: urlState.objectType,- };- }, [- parsedScore1,- parsedScore2,- projectId,- absoluteTimeRange,- interval,- urlState.objectType,- ]);-- // UI state flags- const hasError = !!scoresError;- const hasNoScores =- !scoresLoading && scoreOptions.length === 0 && !scoresError;- const hasNoSelection = !hasError && !hasNoScores && !urlState.score1;-- return (- <Page- headerProps={{- title: "Scores",- breadcrumb: [{ name: "Scores", href: `/project/${projectId}/scores` }],- help: {- description:- "A score is an evaluation of a trace or observation. It can be created from user feedback, model-based evaluations, or manual review. See docs to learn more.",- href: "https://langfuse.com/docs/evaluation/overview",- },- tabsProps: {- tabs: getScoresTabs(projectId),- activeTab: SCORES_TABS.ANALYTICS,- },- }}- >- <div className="flex max-h-full flex-col gap-0">- {/* Header Controls */}- {!hasError && !hasNoScores && (- <ScoreAnalyticsHeader- scoreOptions={scoreOptions}- timeRange={timeRange}- onTimeRangeChange={setTimeRange}- compatibleScore2DataTypes={compatibleScore2DataTypes}- />- )}-- {/* Content Section */}- <div className="max-h-full overflow-y-auto p-4 pt-6">- {hasError ? (- <div className="bg-destructive/10 flex flex-col items-center justify-center gap-4 rounded-lg border p-12">- <BarChart3 className="text-destructive h-12 w-12" />- <div className="text-center">- <h3 className="text-lg font-bold">Error Loading Scores</h3>- <p className="text-muted-foreground mt-2 text-sm">- Failed to load score data. Please try refreshing the page.- </p>- </div>- </div>- ) : hasNoScores ? (- <div className="bg-muted/20 flex flex-col items-center justify-center gap-4 rounded-lg border p-12">- <BarChart3 className="text-muted-foreground h-12 w-12" />- <div className="text-center">- <h3 className="text-lg font-bold">No Scores Available</h3>- <p className="text-muted-foreground mt-2 text-sm">- Create scores by adding evaluations to your traces and- observations.- </p>- </div>- </div>- ) : hasNoSelection ? (- <div className="bg-muted/20 flex flex-col items-center justify-center gap-6 rounded-lg border p-12">- <BarChart3 className="text-muted-foreground h-16 w-16" />- <div className="max-w-2xl text-center">- <h3 className="text-2xl font-bold">Select a Score</h3>- <p className="text-muted-foreground mt-3 text-base">- Choose one or two scores from the dropdowns above to view- analytics- </p>- <div className="text-muted-foreground mt-6 space-y-3 text-sm">- <div className="bg-background/50 rounded-lg p-4">- <p className="text-foreground mb-1 font-bold">- Single score selected:- </p>- <p>View distribution and trends over time</p>- </div>- <div className="bg-background/50 rounded-lg p-4">- <p className="text-foreground mb-1 font-bold">- Two scores selected:- </p>- <p>- Compare scores with heatmaps, correlation analysis, and- statistical metrics- </p>- </div>- </div>- </div>- </div>- ) : queryParams ? (- <ScoreAnalyticsProvider params={queryParams}>- <ScoreAnalyticsDashboard />- </ScoreAnalyticsProvider>- ) : (- <div className="flex flex-col items-center justify-center gap-4 rounded-lg border p-12">- <Spinner size="xxl" variant="muted" />- <p className="text-muted-foreground text-sm">- Loading analytics data...- </p>- </div>- )}- </div>- </div>- </Page>- );-}+export { default } from "@/src/features/scores/ScoresAnalyticsPage";diff --git a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsxindex e804184ab5..af2f44e1d3 100644--- a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx@@ -1,427 +1 @@-/* eslint-disable no-nested-ternary */-import { MixpanelLogo } from "@/src/components/MixpanelLogo";-import Header from "@/src/components/layouts/header";-import ContainerPage from "@/src/components/layouts/container-page";-import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";-import { Button } from "@/src/components/ui/button";-import {- Form,- FormControl,- FormDescription,- FormField,- FormItem,- FormLabel,- FormMessage,-} from "@/src/components/ui/form";-import { PasswordInput } from "@/src/components/design-system/PasswordInput/PasswordInput";-import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";-import { Switch } from "@/src/components/design-system/Switch/Switch";-import {- Tooltip,- TooltipTrigger,- TooltipContent,-} from "@/src/components/ui/tooltip";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import {- mixpanelIntegrationFormSchema,- MIXPANEL_REGIONS,- type MixpanelRegion,-} from "@/src/features/mixpanel-integration/types";-import {- LEGACY_ANALYTICS_EXPORTER_CUTOFF,- validateExportSource,- type V4WriteMode,- type ExportSourceContext,-} from "@langfuse/shared";-import { Alert } from "@/src/components/design-system/Alert/Alert";-// Shared export-source UI adapters; policy in export-source-policy.ts.-import {- buildExportSourceContext,- getExportSourceFieldState,- getExportSourceUnavailableMessage,- isExportSourceSelectable,-} from "@/src/features/analytics-integrations/exportSource";-import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";-import { useQueryProject } from "@/src/features/projects/hooks";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import { api } from "@/src/utils/api";-import { type RouterOutput } from "@/src/utils/types";-import { zodResolver } from "@hookform/resolvers/zod";-import { Card } from "@/src/components/ui/card";-import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";-import Link from "next/link";-import { useRouter } from "next/router";-import { useMemo } from "react";-import { useForm } from "react-hook-form";-import { type z } from "zod";-import { Info, ExternalLink } from "lucide-react";--export default function MixpanelIntegrationSettings() {- const router = useRouter();- const projectId = router.query.projectId as string;-- const hasAccess = useHasProjectAccess({- projectId,- scope: "integrations:CRUD",- });- const state = api.mixpanelIntegration.get.useQuery(- { projectId },- {- enabled: hasAccess,- },- );-- const { project } = useQueryProject();-- const status =- state.isLoading || !hasAccess- ? undefined- : state.data?.config?.enabled- ? "active"- : "inactive";-- return (- <ContainerPage- headerProps={{- title: "Mixpanel Integration",- breadcrumb: [- { name: "Settings", href: `/project/${projectId}/settings` },- ],- actionButtonsLeft: <>{status && <StatusBadge type={status} />}</>,- actionButtonsRight: (- <Button asChild variant="secondary">- <Link href="https://langfuse.com/integrations/analytics/mixpanel">- Integration Docs ↗- </Link>- </Button>- ),- }}- >- <p className="text-primary mb-4 text-sm">- Integrate with{" "}- <Link href="https://mixpanel.com" className="underline">- Mixpanel- </Link>{" "}- to sync your Langfuse traces, generations, and scores for advanced- product analytics. Upon activation, all historical data from your- project will be synced. After the initial sync, new data is- automatically synced every hour to keep your Mixpanel dashboards up to- date.- </p>- {!hasAccess && (- <p className="text-sm">- Your current role does not grant you access to these settings, please- reach out to your project admin or owner.- </p>- )}- {hasAccess && (- <>- <Header title="Configuration" />- <Card className="p-3">- <MixpanelLogo className="text-foreground mb-4 w-20" />- {!state.data || !project ? (- <IntegrationSettingsSkeleton />- ) : (- <MixpanelIntegrationSettingsForm- // Draft lifetime = entity identity, so background refetches- // cannot reset a draft in progress.- key={`${projectId}:${state.data.config ? "configured" : "new"}`}- state={state.data.config ?? undefined}- projectId={projectId}- writeMode={state.data.writeMode}- projectCreatedAt={project.createdAt}- />- )}- </Card>- </>- )}- {state.data?.config?.enabled && (- <>- <Header title="Status" className="mt-8" />- <p className="text-primary text-sm">- Data synced until:{" "}- {state.data?.config?.lastSyncAt- ? new Date(state.data.config.lastSyncAt).toLocaleString()- : "Never (pending)"}- </p>- </>- )}- </ContainerPage>- );-}--const MixpanelIntegrationSettingsForm = ({- state,- projectId,- writeMode,- projectCreatedAt,-}: {- state?: NonNullable<RouterOutput["mixpanelIntegration"]["get"]["config"]>;- projectId: string;- writeMode: V4WriteMode;- // Raw ISO string, not a Date: a Date built in the parent's JSX would be a new- // reference on every render and would defeat the memo below.- projectCreatedAt: string;-}) => {- const capture = usePostHogClientCapture();- const { isLangfuseCloud } = useLangfuseCloudRegion();- const integrationCreatedAt = state?.createdAt;- const exportSourceCtx: ExportSourceContext = useMemo(- () =>- buildExportSourceContext({- writeMode,- isCloud: isLangfuseCloud,- projectCreatedAt: new Date(projectCreatedAt),- integrationCreatedAt: integrationCreatedAt- ? new Date(integrationCreatedAt)- : null,- exporterCutoff: LEGACY_ANALYTICS_EXPORTER_CUTOFF,- }),- [writeMode, isLangfuseCloud, projectCreatedAt, integrationCreatedAt],- );- const {- options: exportSourceOptions,- showField: showExportSourceField,- defaultValue: defaultExportSource,- } = getExportSourceFieldState(state?.exportSource, exportSourceCtx);-- // Blocked-save validation instead of silent rewrite.- const formSchema = useMemo(- () =>- mixpanelIntegrationFormSchema.superRefine((data, ctx) => {- // The credential is write-only: blank keeps the saved token, so it is- // only required when no integration exists yet.- if (!state && !data.mixpanelProjectToken) {- ctx.addIssue({- code: "custom",- path: ["mixpanelProjectToken"],- message: "Mixpanel Project Token is required",- });- }- if (!isExportSourceSelectable(data.exportSource, exportSourceCtx)) {- ctx.addIssue({- code: "custom",- path: ["exportSource"],- message:- "This export source is not available on this deployment. Select an available export source to save.",- });- }- }),- [exportSourceCtx, state],- );-- const mixpanelForm = useForm({- resolver: zodResolver(formSchema),- defaultValues: {- mixpanelRegion:- (state?.mixpanelRegion as MixpanelRegion) ??- MIXPANEL_REGIONS[0].subdomain,- mixpanelProjectToken: "",- enabled: state?.enabled ?? false,- exportSource: defaultExportSource,- },- });-- const watchedExportSource = mixpanelForm.watch("exportSource");- const watchedValidation =- watchedExportSource != null- ? validateExportSource(watchedExportSource, exportSourceCtx)- : ({ ok: true } as const);-- const utils = api.useUtils();- const mut = api.mixpanelIntegration.update.useMutation({- onSuccess: () => {- utils.mixpanelIntegration.invalidate();- },- });- const mutDelete = api.mixpanelIntegration.delete.useMutation({- onSuccess: () => {- utils.mixpanelIntegration.invalidate();- },- });-- async function onSubmit(- values: z.infer<typeof mixpanelIntegrationFormSchema>,- ) {- capture("integrations:mixpanel_form_submitted");- mut.mutate({- projectId,- ...values,- });- }-- return (- <Form {...mixpanelForm}>- <form- className="space-y-3"- onSubmit={mixpanelForm.handleSubmit(onSubmit)}- >- <FormField- control={mixpanelForm.control}- name="mixpanelRegion"- render={({ field }) => (- <FormItem>- <FormLabel>Mixpanel Region</FormLabel>- <FormControl>- <SelectInput- onValueChange={field.onChange}- value={field.value}- placeholder="Select a region"- options={MIXPANEL_REGIONS.map((region) => ({- value: region.subdomain,- label: region.description,- }))}- />- </FormControl>- <FormDescription>- Select the Mixpanel region where your project is hosted- </FormDescription>- <FormMessage />- </FormItem>- )}- />- <FormField- control={mixpanelForm.control}- name="mixpanelProjectToken"- render={({ field }) => (- <FormItem>- <FormLabel>Mixpanel Project Token</FormLabel>- <FormControl>- <PasswordInput- {...field}- placeholder={state?.mixpanelProjectTokenDisplay}- />- </FormControl>- <FormDescription>- {state- ? "Leave blank to keep the current token."- : "You can find your Project Token in your Mixpanel project settings"}- </FormDescription>- <FormMessage />- </FormItem>- )}- />- {showExportSourceField && (- <FormField- control={mixpanelForm.control}- name="exportSource"- render={({ field }) => (- <FormItem>- <FormLabel className="flex items-center gap-1.5 pt-2">- Export Source- <Tooltip>- <TooltipTrigger>- <Info className="text-muted-foreground h-3.5 w-3.5" />- </TooltipTrigger>- <TooltipContent- side="bottom"- className="max-w-[350px] space-y-2 p-3"- >- {exportSourceOptions.map((option) => (- <div key={option.value} className="space-y-0.5">- <div className="font-bold">{option.label}</div>- <div className="text-muted-foreground text-xs">- {option.description}- </div>- </div>- ))}- <div className="border-t pt-2">- <a- href="https://langfuse.com/docs/integrations/export-sources"- target="_blank"- rel="noopener noreferrer"- className="text-muted-foreground hover:text-primary inline-flex items-center gap-1 text-xs hover:underline"- >- For further information see- <ExternalLink className="h-3 w-3" />- </a>- </div>- </TooltipContent>- </Tooltip>- </FormLabel>- <FormControl>- <SelectInput- onValueChange={field.onChange}- value={field.value}- placeholder="Select data to export"- options={exportSourceOptions.map((option) => {- if (option.unavailable) {- return {- value: option.value,- label: `${option.label} (not available on this deployment)`,- disabled: true as const,- disabledReason: "Not available on this deployment.",- };- }-- return { value: option.value, label: option.label };- })}- />- </FormControl>- <FormDescription>- Choose which data sources to export to Mixpanel. Scores are- always included.- </FormDescription>- <FormMessage />- </FormItem>- )}- />- )}- {!watchedValidation.ok && (- <Alert variant="destructive">- <Alert.Title>- Saved export source is no longer available- </Alert.Title>- <Alert.Description>- {getExportSourceUnavailableMessage(watchedValidation.reason)}- </Alert.Description>- </Alert>- )}- <FormField- control={mixpanelForm.control}- name="enabled"- render={({ field }) => (- <FormItem>- <FormLabel>Enabled</FormLabel>- <FormControl>- <div className="mt-1 ml-4">- <Switch- id="mixpanel-integration-enabled"- checked={field.value}- onCheckedChange={() => {- field.onChange(!field.value);- }}- />- </div>- </FormControl>- <FormMessage />- </FormItem>- )}- />- </form>- <div className="mt-8 flex gap-2">- <Button- loading={mut.isPending}- onClick={mixpanelForm.handleSubmit(onSubmit)}- >- Save- </Button>- <Button- variant="ghost"- loading={mutDelete.isPending}- disabled={!state}- onClick={() => {- if (- confirm(- "Are you sure you want to reset the Mixpanel integration for this project?",- )- )- mutDelete.mutate({ projectId });- }}- >- Reset- </Button>- </div>- </Form>- );-};+export { default } from "@/src/features/mixpanel-integration/MixpanelIntegrationPage";diff --git a/web/src/pages/project/[projectId]/settings/integrations/slack.tsx b/web/src/pages/project/[projectId]/settings/integrations/slack.tsxindex 3c43cb3b8c..8d8b345667 100644--- a/web/src/pages/project/[projectId]/settings/integrations/slack.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/slack.tsx@@ -1,214 +1 @@-/* eslint-disable no-nested-ternary */-import ContainerPage from "@/src/components/layouts/container-page";-import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";-import { AutomationButton } from "@/src/features/automations/components/AutomationButton";-import { SlackConnectionCard } from "@/src/features/slack/components/SlackConnectionCard";-import {- ChannelSelector,- type SlackChannel,-} from "@/src/features/slack/components/ChannelSelector";-import { SlackTestMessageButton } from "@/src/features/slack/components/SlackTestMessageButton";-import { api } from "@/src/utils/api";-import { useRouter } from "next/router";-import { useState, useEffect } from "react";-import { Badge } from "@/src/components/ui/badge";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import {- Card,- CardContent,- CardDescription,- CardHeader,- CardTitle,-} from "@/src/components/ui/card";--export default function SlackIntegrationSettings() {- const router = useRouter();- const projectId = router.query.projectId as string;-- // Handle popup OAuth completion- useEffect(() => {- // Check if this page is opened in a popup window- const isPopup = window.opener && window.opener !== window;-- if (isPopup) {- // Check for OAuth completion parameters- const urlParams = new URLSearchParams(window.location.search);- const success = urlParams.get("success");- const error = urlParams.get("error");- const teamName = urlParams.get("team_name");-- if (success === "true") {- // Send success message to parent window- window.opener.postMessage(- {- type: "slack-oauth-success",- teamName: teamName || "your Slack workspace",- },- window.location.origin,- );-- // Close popup- window.close();- } else if (error) {- // Send error message to parent window- window.opener.postMessage(- {- type: "slack-oauth-error",- error: error,- },- window.location.origin,- );-- // Close popup- window.close();- }- }- }, [router.query]);-- const { data: integrationStatus, isLoading } =- api.slack.getIntegrationStatus.useQuery(- { projectId },- { enabled: !!projectId },- );-- const status = isLoading- ? undefined- : integrationStatus?.isConnected- ? "active"- : "inactive";-- const [selectedChannel, setSelectedChannel] = useState<SlackChannel | null>(- null,- );-- // Check user permissions- const hasAccess = useHasProjectAccess({- projectId,- scope: "automations:CUD",- });-- // Channel was typed by name rather than selected from the list- const isManualEntry = selectedChannel?.id.startsWith("#") ?? false;-- return (- <ContainerPage- headerProps={{- title: "Slack Integration",- breadcrumb: [- { name: "Settings", href: `/project/${projectId}/settings` },- ],- actionButtonsLeft: <>{status && <StatusBadge type={status} />}</>,- actionButtonsRight: <AutomationButton projectId={projectId} />,- }}- >- <div className="space-y-6">- {/* Connection Configuration */}- <SlackConnectionCard projectId={projectId} showConnectButton={true} />-- {/* Test Channel Section - Only show when connected */}- {integrationStatus?.isConnected && (- <Card>- <CardHeader>- <CardTitle className="flex items-center gap-2">- Test Integration- </CardTitle>- <CardDescription>- Test your Slack integration by sending a message to a channel.- </CardDescription>- </CardHeader>- <CardContent className="space-y-4">- <div>- <h4 className="mb-2 text-sm font-bold">Select Test Channel</h4>- <div className="max-w-md">- <ChannelSelector- projectId={projectId}- selectedChannelId={selectedChannel?.id}- selectedChannel={selectedChannel}- onChannelSelect={setSelectedChannel}- placeholder="Choose a channel to test"- showRefreshButton={true}- />- </div>- </div>-- {selectedChannel && (- <div className="space-y-4 border-t pt-4">- <div>- <h4 className="mb-3 text-sm font-bold">- Channel Information- </h4>- <div className="grid gap-4 md:grid-cols-2">- <div>- <p className="text-sm font-bold">Channel Name</p>- <p className="text-muted-foreground text-sm">- #{selectedChannel.name}- </p>- </div>- <div>- <p className="text-sm font-bold">Channel Type</p>- {isManualEntry ? (- <span className="text-muted-foreground text-xs">- Available after sending a test message- </span>- ) : (- <Badge variant="outline" className="text-xs">- {selectedChannel.isPrivate ? "Private" : "Public"}- </Badge>- )}- </div>- <div>- <p className="text-sm font-bold">Channel ID</p>- {isManualEntry ? (- <span className="text-muted-foreground text-xs">- Available after sending a test message- </span>- ) : (- <p className="text-muted-foreground font-mono text-sm">- {selectedChannel.id}- </p>- )}- </div>- </div>- </div>-- <div className="flex items-center gap-3">- <SlackTestMessageButton- projectId={projectId}- selectedChannel={selectedChannel}- hasAccess={hasAccess}- disabled={false}- onSuccess={(channelInfo) => {- setSelectedChannel((prev) =>- prev- ? {- ...prev,- id: channelInfo.id,- name: channelInfo.name ?? prev.name,- isPrivate:- channelInfo.isPrivate ?? prev.isPrivate,- }- : prev,- );- }}- />- </div>- </div>- )}-- {!selectedChannel && (- <div className="text-muted-foreground text-sm">- Select a channel above to view its details and test message- delivery. For private channels, invite the app first with{" "}- <code className="bg-muted rounded px-1 py-0.5">- /invite @Langfuse- </code>{" "}- in that channel.- </div>- )}- </CardContent>- </Card>- )}- </div>- </ContainerPage>- );-}+export { default } from "@/src/features/slack/SlackIntegrationPage";diff --git a/web/src/pages/project/[projectId]/settings/models/[modelId].tsx b/web/src/pages/project/[projectId]/settings/models/[modelId].tsxindex a06094d839..2613e71ef3 100644--- a/web/src/pages/project/[projectId]/settings/models/[modelId].tsx+++ b/web/src/pages/project/[projectId]/settings/models/[modelId].tsx@@ -1,328 +1 @@-import { useRouter } from "next/router";-import { api } from "@/src/utils/api";-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import {- Card,- CardContent,- CardHeader,- CardTitle,-} from "@/src/components/ui/card";-import { DeleteModelButton } from "@/src/features/models/components/DeleteModelButton";-import { EditModelButton } from "@/src/features/models/components/EditModelButton";-import { CloneModelButton } from "@/src/features/models/components/CloneModelButton";-import { TestModelMatchButton } from "@/src/features/models/components/test-match/TestModelMatchButton";-import { JSONView } from "@/src/components/ui/CodeJsonViewer";-import Link from "next/link";-import { Button } from "@/src/components/ui/button";-import { getMaxDecimals } from "@/src/features/models/fns/getMaxDecimals";-import Decimal from "decimal.js";-import { PriceUnitSelector } from "@/src/features/models/components/PriceUnitSelector";-import { useMemo, useState } from "react";-import { usePriceUnitMultiplier } from "@/src/features/models/hooks/usePriceUnitMultiplier";-import Generations from "@/src/features/tracing-tables/observations/ObservationsTable";-import Page from "@/src/components/layouts/page";-import { SquareArrowOutUpRight, Info as InfoIcon } from "lucide-react";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/src/components/ui/select";-import {- HoverCard,- HoverCardContent,- HoverCardTrigger,-} from "@/src/components/ui/hover-card";-import { CodeMirrorEditor } from "@/src/components/editor";--const resolvePricingTier = <T extends { id: string }>(- tiers: T[],- selectedTierId: string | null,- defaultTier: T | null,-): T | null => {- if (selectedTierId) {- return tiers.find((tier) => tier.id === selectedTierId) ?? defaultTier;- }- return defaultTier;-};--export default function ModelDetailPage() {- const router = useRouter();- const { priceUnit, priceUnitMultiplier } = usePriceUnitMultiplier();- const projectId = router.query.projectId as string;- const modelId = router.query.modelId as string;- const pricingTierParam = router.query.pricingTier as string | undefined;- const hasWriteAccess = useHasProjectAccess({- projectId,- scope: "models:CUD",- });-- const { data: model, isLoading } = api.models.getById.useQuery(- { projectId, modelId },- { enabled: !!projectId && !!modelId },- );-- // Get default tier or first tier by priority- const defaultTier = useMemo(() => {- if (!model?.pricingTiers || model.pricingTiers.length === 0) return null;- return model.pricingTiers.find((t) => t.isDefault) || model.pricingTiers[0];- }, [model?.pricingTiers]);-- // Keep user selection local and derive the initial linked tier during render.- const [selectedTierId, setSelectedTierId] = useState<string | null>(null);-- // Get the active tier (selected or default)- const activeTier = useMemo(() => {- if (!model?.pricingTiers) return null;- return resolvePricingTier(- model.pricingTiers,- selectedTierId ?? pricingTierParam ?? null,- defaultTier,- );- }, [model?.pricingTiers, selectedTierId, pricingTierParam, defaultTier]);-- const maxDecimals = useMemo(- () =>- Math.max(- ...Object.values(activeTier?.prices ?? {}).map((price) =>- getMaxDecimals(price, priceUnitMultiplier),- ),- ),- [activeTier?.prices, priceUnitMultiplier],- );-- // If not found, redirect to models page- if (!isLoading && !model) {- return (- <div className="flex min-h-screen flex-col items-center justify-center">- <div className="mb-4 text-xl font-bold">Model not found</div>- <Button variant="outline" asChild>- <Link href={`/project/${projectId}/settings/models`}>- Return to Models page- </Link>- </Button>- </div>- );- }-- const isLangfuseModel = !Boolean(model?.projectId);-- if (isLoading || !model) {- return <div className="p-3">Loading...</div>;- }-- return (- <Page- scrollable- headerProps={{- title: model.modelName,- help: {- description: "Model configuration and pricing details",- href: "https://langfuse.com/docs/model-usage-and-cost",- },- breadcrumb: [- {- name: "Settings",- href: `/project/${router.query.projectId as string}/settings`,- },- {- name: "Models",- href: `/project/${router.query.projectId as string}/settings/models`,- },- { name: model.modelName },- ],- actionButtonsRight: (- <div className="flex gap-2">- {hasWriteAccess && (- <>- <TestModelMatchButton projectId={projectId} variant="outline" />- {!isLangfuseModel ? (- <>- <EditModelButton projectId={projectId} modelData={model} />- <DeleteModelButton- projectId={projectId}- modelData={model}- onSuccess={() => {- router.push(`/project/${projectId}/settings/models`);- }}- />- </>- ) : (- <CloneModelButton projectId={projectId} modelData={model} />- )}- </>- )}- </div>- ),- }}- >- <div className="grid grid-cols-2 gap-6 p-2">- <Card>- <CardHeader>- <CardTitle>Model configuration</CardTitle>- </CardHeader>- <CardContent className="grid gap-4">- <div>- <div className="text-muted-foreground text-sm font-bold">- Match Pattern- </div>- <div className="mt-1 font-mono text-sm">{model.matchPattern}</div>- </div>-- <div>- <div className="text-muted-foreground text-sm font-bold">- Maintained by- </div>- <div className="mt-1 text-sm">- {isLangfuseModel ? "Langfuse" : "User"}- </div>- </div>-- <div>- <div className="text-muted-foreground text-sm font-bold">- Tokenizer- </div>- <div className="mt-1 text-sm">{model.tokenizerId || "None"}</div>- </div>-- {model.tokenizerId && (- <div>- <div className="text-muted-foreground text-sm font-bold">- Tokenizer Config- </div>- <pre className="bg-muted mt-1 rounded p-2 text-sm">- <JSONView json={model.tokenizerConfig} />- </pre>- </div>- )}- </CardContent>- </Card>-- <Card id="pricing-section">- <CardHeader>- <div className="flex flex-col gap-2">- <CardTitle>Pricing</CardTitle>- {model.pricingTiers.length > 1 && (- <div className="flex items-center gap-4">- <label className="text-muted-foreground text-sm font-bold">- Pricing Tier- </label>- <Select- value={activeTier?.id ?? ""}- onValueChange={setSelectedTierId}- >- <SelectTrigger className="w-[200px]">- <SelectValue placeholder="Select tier" />- </SelectTrigger>- <SelectContent>- {model.pricingTiers.map((tier) => (- <SelectItem key={tier.id} value={tier.id}>- {tier.name}- </SelectItem>- ))}- </SelectContent>- </Select>- {activeTier && !activeTier.isDefault && (- <HoverCard openDelay={200} closeDelay={100}>- <HoverCardTrigger asChild>- <Button- variant="ghost"- className="text-muted-foreground hover:text-accent-foreground inline-flex h-auto items-center gap-1.5 p-0 text-xs hover:bg-transparent"- size="sm"- >- <InfoIcon className="h-3 w-3" />- <span>Conditions</span>- </Button>- </HoverCardTrigger>- <HoverCardContent- className="max-h-[80vh] w-[400px] overflow-auto"- collisionPadding={20}- >- <p className="text-sm font-bold">- Pricing Tier Conditions- </p>- <p className="text-muted-foreground pt-2 text-sm">- This tier is applied when the following conditions are- met:- </p>- <div className="mt-2">- <CodeMirrorEditor- mode="json"- value={JSON.stringify(- activeTier.conditions,- null,- 2,- )}- onChange={() => {}} // Read-only- className="max-h-[250px] overflow-y-auto"- editable={false}- />- </div>- </HoverCardContent>- </HoverCard>- )}- </div>- )}- </div>- </CardHeader>- <CardContent>- <div className="flex flex-col gap-2">- <div className="border-border text-muted-foreground grid grid-cols-2 gap-2 border-b text-sm font-bold">- <span>Usage Type</span>- <span className="flex items-center gap-2">- <span>Price {priceUnit}</span>- <PriceUnitSelector />- </span>- </div>- {activeTier &&- Object.entries(activeTier.prices)- // Sort by price ascending- .sort((a, b) => a[1] - b[1])- .map(([usageType, price]) => (- <div- key={usageType}- className="grid grid-cols-2 gap-2 rounded px-1 py-0.5 text-sm"- >- <span className="break-all">{usageType}</span>- <span className="text-left font-mono">- $- {new Decimal(price)- .mul(priceUnitMultiplier)- .toFixed(maxDecimals)}- </span>- </div>- ))}- </div>- </CardContent>- </Card>-- <Card className="col-span-2 min-w-0">- <CardHeader>- <CardTitle className="flex items-center justify-between">- <span>Model observations</span>- <Button variant="ghost" asChild>- <Link- href={`/project/${projectId}/observations`}- className="flex items-center gap-1"- >- <span className="text-sm">View all</span>- <SquareArrowOutUpRight className="h-4 w-4" />- </Link>- </Button>- </CardTitle>- </CardHeader>- <CardContent className="min-w-0">- <div className="flex h-[calc(100vh-20rem)] min-h-0 min-w-0 flex-col overflow-hidden">- <Generations- projectId={projectId}- omittedFilter={["model"]}- modelId={model.id}- />- </div>- </CardContent>- </Card>- </div>- </Page>- );-}+export { default } from "@/src/features/models/ModelDetailPage";