🪢 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): Clean up `Callout` component (#16539)
Ben Bachem6273b849160a
diff --git a/web/.storybook/main.ts b/web/.storybook/main.tsindex eb849ec649..1bd974baa9 100644--- a/web/.storybook/main.ts+++ b/web/.storybook/main.ts@@ -11,6 +11,7 @@ import {const STORY_EXTENSIONS = "@(js|jsx|mjs|ts|tsx)";const DESIGN_COMPONENT_STORIES = [+ "Callout/Callout","Checkbox/Checkbox","Codeblock/Codeblock","Dropzone/Dropzone",diff --git a/web/src/components/DismissController.tsx b/web/src/components/DismissController.tsxnew file mode 100644index 0000000000..75168cf722--- /dev/null+++ b/web/src/components/DismissController.tsx@@ -0,0 +1,62 @@+"use client";++import { useSyncExternalStore } from "react";++import useLocalStorage from "@/src/components/useLocalStorage";++const DEFAULT_TTL_MS = 30 * 24 * 60 * 60 * 1000;++type DismissedItem = {+ id: string;+ dismissedAt: number;+};++type DismissControllerRenderProps = {+ onDismiss: () => void;+};++export type DismissControllerProps = {+ id: string;+ family: "callouts";+ ttlMs?: number;+ onDismiss?: () => void;+ children: (props: DismissControllerRenderProps) => React.ReactElement;+};++const subscribe = () => () => {};+const getClientSnapshot = () => true;+const getServerSnapshot = () => false;++export function DismissController({+ id,+ family,+ ttlMs = DEFAULT_TTL_MS,+ onDismiss,+ children,+}: DismissControllerProps) {+ const [dismissedItems, setDismissedItems] = useLocalStorage<DismissedItem[]>(+ `${id}-dismissed-${family}`,+ [],+ );+ const isHydrated = useSyncExternalStore(+ subscribe,+ getClientSnapshot,+ getServerSnapshot,+ );+ const dismissedItem = dismissedItems.find((item) => item.id === id);+ const isVisible =+ isHydrated &&+ (!dismissedItem || Date.now() - dismissedItem.dismissedAt > ttlMs);++ if (!isVisible) return null;++ return children({+ onDismiss: () => {+ setDismissedItems((currentItems) => [+ ...currentItems.filter((item) => item.id !== id),+ { id, dismissedAt: Date.now() },+ ]);+ onDismiss?.();+ },+ });+}diff --git a/web/src/components/design-system/Callout/Callout.stories.tsx b/web/src/components/design-system/Callout/Callout.stories.tsxnew file mode 100644index 0000000000..bff4c67ae9--- /dev/null+++ b/web/src/components/design-system/Callout/Callout.stories.tsx@@ -0,0 +1,81 @@+import { Bot } from "lucide-react";+import { expect, fn, userEvent, within } from "storybook/test";++import preview from "../../../../.storybook/preview";+import { Button } from "../../ui/button";+import { Callout } from "./Callout";++const meta = preview.meta({+ component: Callout,+});++const message = (+ <div className="flex items-start gap-2 sm:items-center">+ <Bot className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />+ <span>+ <span className="font-bold">+ Langfuse works great with your AI agents.+ </span>{" "}+ Connect your tools to your Langfuse data.+ </span>+ </div>+);++export const Default = meta.story({+ args: {+ variant: "info",+ align: "middle",+ children: message,+ actions: null,+ onDismiss: fn(),+ },+});++export const Warning = meta.story({+ args: {+ variant: "warning",+ align: "top",+ children: (+ <span>+ <span className="font-bold">Heads up:</span> this workspace is close to+ its ingestion limit.+ </span>+ ),+ actions: null,+ onDismiss: fn(),+ },+});++export const WithActions = meta.story({+ args: {+ variant: "info",+ align: "middle",+ children: message,+ actions: (+ <Button size="sm" variant="secondary">+ Learn more+ </Button>+ ),+ onDismiss: fn(),+ },+});++export const Dismisses = meta.story({+ name: "(Test) Dismisses",+ args: {+ variant: "info",+ align: "middle",+ children: <span>This callout can be dismissed.</span>,+ actions: null,+ onDismiss: fn(),+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);++ await userEvent.click(+ await canvas.findByRole("button", { name: "Dismiss" }),+ );++ await expect(args.onDismiss).toHaveBeenCalledOnce();+ },+});diff --git a/web/src/components/design-system/Callout/Callout.tsx b/web/src/components/design-system/Callout/Callout.tsxnew file mode 100644index 0000000000..caffb5c295--- /dev/null+++ b/web/src/components/design-system/Callout/Callout.tsx@@ -0,0 +1,77 @@+"use client";++import { cva } from "class-variance-authority";+import { X } from "lucide-react";++import { AlertDescription } from "@/src/components/ui/alert";+import { Button } from "@/src/components/ui/button";++const calloutVariants = cva("relative w-full rounded-lg border p-3", {+ variants: {+ variant: {+ info: "border-light-blue bg-light-blue dark:border-light-blue dark:bg-light-blue",+ warning:+ "border-light-yellow bg-light-yellow dark:border-light-yellow dark:bg-light-yellow",+ },+ },+});++const contentVariants = cva("flex min-w-0 flex-1 flex-col gap-2", {+ variants: {+ align: {+ top: "sm:items-start",+ middle: "sm:items-center",+ },+ },+});++const descriptionVariants = cva("ml-1 flex items-start gap-2", {+ variants: {+ align: {+ top: null,+ middle: "sm:items-center",+ },+ },+});++export type CalloutProps = {+ variant: "info" | "warning";+ align: "top" | "middle";+ children: React.ReactElement;+ actions: React.ReactElement | null;+ onDismiss: () => void;+};++export function Callout({+ variant,+ align,+ children,+ actions,+ onDismiss,+}: CalloutProps) {+ return (+ <div role="alert" className={calloutVariants({ variant })}>+ <AlertDescription className={descriptionVariants({ align })}>+ <div+ className={`${contentVariants({ align })} sm:flex-row sm:justify-between`}+ >+ <div className="text-foreground min-w-0 text-sm">{children}</div>+ {actions ? (+ <div className="flex shrink-0 items-center gap-2 self-end sm:ml-4 sm:self-auto">+ {actions}+ </div>+ ) : null}+ </div>+ <Button+ variant="ghost"+ size="sm"+ onClick={onDismiss}+ className="text-muted-foreground hover:text-foreground h-6 w-6 shrink-0 p-0"+ aria-label="Dismiss"+ >+ <X className="h-4 w-4" />+ </Button>+ </AlertDescription>+ </div>+ );+}diff --git a/web/src/components/ui/callout.stories.tsx b/web/src/components/ui/callout.stories.tsxdeleted file mode 100644index 648b9956d4..0000000000--- a/web/src/components/ui/callout.stories.tsx+++ /dev/null@@ -1,54 +0,0 @@-import { Bot } from "lucide-react";-import preview from "../../../.storybook/preview";-import { Button } from "./button";-import { Callout } from "./callout";--const meta = preview.meta({- component: Callout,-});--// Message and actions share a row from `sm` up; below that the actions drop-// under the full-width message so it is not squeezed into a narrow column-// (LFE-14490). Dismiss keeps its corner either way. Resize the Storybook canvas-// across 640px to see the switch (CSS-only; jsdom story tests do not apply-// media queries).-export const WithActions = meta.story({- args: {- id: "callout-story:with-actions",- variant: "info",- align: "middle",- actions: () => (- <Button size="sm" variant="secondary">- Learn more- </Button>- ),- children: (- <div className="flex items-start gap-2 sm:items-center">- <Bot className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />- <span>- <span className="font-bold">- Langfuse works great with your AI coding agents.- </span>{" "}- Connect Claude Code, Codex, and other agents to your data with the- Langfuse Agent Skill, MCP server, and CLI.- </span>- </div>- ),- },-});--// Without actions the message keeps the full width at every size, minus the-// dismiss control.-export const WarningWithoutActions = meta.story({- args: {- id: "callout-story:no-actions",- variant: "warning",- align: "top",- children: (- <span>- <span className="font-bold">Heads up:</span> this workspace is close to- its ingestion limit for the current billing period.- </span>- ),- },-});diff --git a/web/src/components/ui/callout.tsx b/web/src/components/ui/callout.tsxdeleted file mode 100644index b5b198bd13..0000000000--- a/web/src/components/ui/callout.tsx+++ /dev/null@@ -1,126 +0,0 @@-/* eslint-disable @repo/no-style-props */-import { Alert, AlertDescription } from "@/src/components/ui/alert";-import { Button } from "@/src/components/ui/button";-import useLocalStorage from "@/src/components/useLocalStorage";-import { X } from "lucide-react";-import { useEffect, useState } from "react";--const DEFAULT_STORAGE_KEY = "dismissed-callouts";-const DEFAULT_TTL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days--interface Callout {- id: string;- dismissedAt: number;-}--export interface CalloutProps {- id: string;- ttlMs?: number;- variant?: "info" | "warning";- align?: "top" | "middle";- children: React.ReactNode;- onDismiss?: () => void;- actions?: () => React.ReactNode;- className?: string;-}--export function Callout({- id: id,- ttlMs = DEFAULT_TTL_MS,- variant = "info",- align = "middle",- children,- onDismiss,- actions,- className,-}: CalloutProps) {- const [dismissedCallouts, setDismissedCallouts] = useLocalStorage<Callout[]>(- id + "-" + DEFAULT_STORAGE_KEY,- [],- );- const [isVisible, setIsVisible] = useState(false);-- useEffect(() => {- // Check if this callout is dismissed and not expired- const dismissedCallout = dismissedCallouts.find((c) => c.id === id);-- if (!dismissedCallout) {- setIsVisible(true);- return;- }-- const now = Date.now();- const isExpired = now - dismissedCallout.dismissedAt > ttlMs;-- if (isExpired) {- // Remove expired dismissal- setDismissedCallouts(dismissedCallouts.filter((c) => c.id !== id));- setIsVisible(true);- } else {- setIsVisible(false);- }- }, [id, dismissedCallouts, ttlMs, setDismissedCallouts]);-- const handleDismiss = () => {- // Add this callout to dismissed list- const now = Date.now();- const updatedDismissedCallouts = dismissedCallouts.filter(- (c) => c.id !== id,- );- updatedDismissedCallouts.push({ id: id, dismissedAt: now });- setDismissedCallouts(updatedDismissedCallouts);-- // Call optional callback- onDismiss?.();-- setIsVisible(false);- };-- if (!isVisible) return null;-- const variantClass =- variant === "warning"- ? "border-light-yellow bg-light-yellow dark:border-light-yellow dark:bg-light-yellow"- : "border-light-blue bg-light-blue dark:border-light-blue dark:bg-light-blue";- // Vertical alignment only applies once text and actions share a row (sm+);- // below that the column stacks them and the cross axis is horizontal.- const alignmentClass =- align === "middle" ? "sm:items-center" : "sm:items-start";-- const alignmentOverrides =- align === "middle"- ? "[&>svg]:top-1/2 [&>svg]:-translate-y-1/2 [&>svg+div]:translate-y-0"- : "";-- return (- <Alert- className={`${variantClass} ${alignmentOverrides} ${className ?? ""}`}- >- {/* Dismiss stays outside the stacking wrapper so it keeps its corner- position; only the actions drop below the message on narrow widths. */}- <AlertDescription- className={`ml-1 flex items-start gap-2 ${align === "middle" ? "sm:items-center" : ""}`}- >- <div- className={`flex min-w-0 flex-1 flex-col gap-2 sm:flex-row sm:justify-between ${alignmentClass}`}- >- <div className="text-foreground min-w-0 text-sm">{children}</div>- {actions && (- <div className="flex shrink-0 items-center gap-2 self-end sm:ml-4 sm:self-auto">- {actions()}- </div>- )}- </div>- <Button- variant="ghost"- size="sm"- onClick={handleDismiss}- className="text-muted-foreground hover:text-foreground h-6 w-6 shrink-0 p-0"- aria-label="Dismiss"- >- <X className="h-4 w-4" />- </Button>- </AlertDescription>- </Alert>- );-}diff --git a/web/src/features/developer-tools/components/AgentToolsBanner.tsx b/web/src/features/developer-tools/components/AgentToolsBanner.tsxindex 7235ef01f1..4dec190c3c 100644--- a/web/src/features/developer-tools/components/AgentToolsBanner.tsx+++ b/web/src/features/developer-tools/components/AgentToolsBanner.tsx@@ -1,4 +1,5 @@-import { Callout } from "@/src/components/ui/callout";+import { Callout } from "@/src/components/design-system/Callout/Callout";+import { DismissController } from "@/src/components/DismissController";import { Button } from "@/src/components/ui/button";import Link from "next/link";import { Bot } from "lucide-react";@@ -13,29 +14,34 @@ const DOCS_HREF =*/export function AgentToolsBanner() {return (- <Callout- className="mb-4"- id="agent-tools-banner:v1"- variant="info"- align="middle"- actions={() => (- <Button asChild size="sm" variant="secondary">- <Link href={DOCS_HREF} target="_blank">- Learn more- </Link>- </Button>+ <DismissController id="agent-tools-banner:v1" family="callouts">+ {({ onDismiss }) => (+ <div className="mb-4">+ <Callout+ variant="info"+ align="middle"+ actions={+ <Button asChild size="sm" variant="secondary">+ <Link href={DOCS_HREF} target="_blank">+ Learn more+ </Link>+ </Button>+ }+ onDismiss={onDismiss}+ >+ <div className="flex items-start gap-2 sm:items-center">+ <Bot className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />+ <span>+ <span className="font-bold">+ Langfuse works great with your AI coding agents.+ </span>{" "}+ Connect Claude Code, Codex, and other agents to your data with+ the Langfuse Agent Skill, MCP server, and CLI.+ </span>+ </div>+ </Callout>+ </div>)}- >- <div className="flex items-start gap-2 sm:items-center">- <Bot className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />- <span>- <span className="font-bold">- Langfuse works great with your AI coding agents.- </span>{" "}- Connect Claude Code, Codex, and other agents to your data with the- Langfuse Agent Skill, MCP server, and CLI.- </span>- </div>- </Callout>+ </DismissController>);}diff --git a/web/src/features/evals/pages/remap-evaluator.tsx b/web/src/features/evals/pages/remap-evaluator.tsxindex 8cb290a4c7..54f6ae23d7 100644--- a/web/src/features/evals/pages/remap-evaluator.tsx+++ b/web/src/features/evals/pages/remap-evaluator.tsx@@ -11,7 +11,8 @@ import { type PartialConfig } from "@/src/features/evals/types";import { Alert, AlertDescription } from "@/src/components/ui/alert";import { Skeleton } from "@/src/components/ui/skeleton";import { Button } from "@/src/components/ui/button";-import { Callout } from "@/src/components/ui/callout";+import { Callout } from "@/src/components/design-system/Callout/Callout";+import { DismissController } from "@/src/components/DismissController";import { Separator } from "@/src/components/ui/separator";import {DropdownMenu,@@ -173,55 +174,63 @@ export default function RemapEvaluatorPage() {><div className="space-y-4">{v4UpgradeUiEnabled ? (- <Callout+ <DismissControllerid={"v4-evaluator-upgrade:" + evalConfigId}+ family="callouts"ttlMs={7 * 24 * 60 * 60 * 1000}- variant="info"- align="top"- actions={() => (- <>- {isInAppAgentLauncherVisible ? (- <Button- size="sm"- variant="secondary"- onClick={handleUseAssistant}- >- <BotMessageSquare className="mr-1.5 h-4 w-4" />- Use Assistant to help with upgrade- </Button>- ) : null}- <Button asChild size="sm" variant="secondary">- <a- href={V4_DOCS_URL}- target="_blank"- rel="noopener noreferrer"- >- Docs- </a>- </Button>- </>- )}>- <div className="flex items-start gap-2">- <Zap className="mt-0.5 h-4 w-4 shrink-0" />- <span>- <span className="font-bold">- This evaluator needs an upgrade for Langfuse v4.- </span>{" "}- Evaluators are moving to observation-level. Upgrade this- configuration to keep its scores aligned with the v4 data model.{" "}- <a- href={EVAL_MIGRATION_DOCS_URL}- target="_blank"- rel="noopener noreferrer"- className="underline"- >- Learn more about evaluator upgrades- </a>- .- </span>- </div>- </Callout>+ {({ onDismiss }) => (+ <Callout+ variant="info"+ align="top"+ actions={+ <>+ {isInAppAgentLauncherVisible ? (+ <Button+ size="sm"+ variant="secondary"+ onClick={handleUseAssistant}+ >+ <BotMessageSquare className="mr-1.5 h-4 w-4" />+ Use Assistant to help with upgrade+ </Button>+ ) : null}+ <Button asChild size="sm" variant="secondary">+ <a+ href={V4_DOCS_URL}+ target="_blank"+ rel="noopener noreferrer"+ >+ Docs+ </a>+ </Button>+ </>+ }+ onDismiss={onDismiss}+ >+ <div className="flex items-start gap-2">+ <Zap className="mt-0.5 h-4 w-4 shrink-0" />+ <span>+ <span className="font-bold">+ This evaluator needs an upgrade for Langfuse v4.+ </span>{" "}+ Evaluators are moving to observation-level. Upgrade this+ configuration to keep its scores aligned with the v4 data+ model.{" "}+ <a+ href={EVAL_MIGRATION_DOCS_URL}+ target="_blank"+ rel="noopener noreferrer"+ className="underline"+ >+ Learn more about evaluator upgrades+ </a>+ .+ </span>+ </div>+ </Callout>+ )}+ </DismissController>) : null}<div className="min-w-0"><p className="text-muted-foreground text-sm">diff --git a/web/src/features/v4-migration/V4MigrationBanner.tsx b/web/src/features/v4-migration/V4MigrationBanner.tsxindex 9c753f2d85..1b4a17d7e1 100644--- a/web/src/features/v4-migration/V4MigrationBanner.tsx+++ b/web/src/features/v4-migration/V4MigrationBanner.tsx@@ -1,7 +1,8 @@import Link from "next/link";import { useSession } from "next-auth/react";import { Zap } from "lucide-react";-import { Callout } from "@/src/components/ui/callout";+import { Callout } from "@/src/components/design-system/Callout/Callout";+import { DismissController } from "@/src/components/DismissController";import { Button } from "@/src/components/ui/button";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { useAccountV4MigrationData } from "@/src/features/v4-migration/hooks/useV4MigrationData";@@ -48,52 +49,60 @@ export function V4MigrationBanner() {}return (- <Callout- className="mb-4"+ <DismissControllerid="v4-migration-banner:v1"+ family="callouts"ttlMs={DISMISS_TTL_MS}- variant="info"- align="middle"- actions={() => (- <>- <Button asChild size="sm" variant="secondary">- <Link- href="/v4-migration"- onClick={() =>- capture("v4_migration:overview_banner_status_clicked")- }- >- Check status- </Link>- </Button>- <Button asChild size="sm" variant="secondary">- <a- href={V4_DOCS_URL}- target="_blank"- rel="noopener noreferrer"- onClick={() =>- capture("v4_migration:overview_banner_docs_clicked")- }- >- Docs- </a>- </Button>- </>- )}>- <div className="flex items-start gap-2 sm:items-center">- <Zap className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />- <span>- <span className="font-bold">- Langfuse v4 is here: real-time and up to 165× faster.- </span>{" "}- {projectsNeedingMigration === statuses.length- ? projectsNeedingMigration === 1- ? "Your project needs an upgrade."- : "All projects need an upgrade."- : `${projectsNeedingMigration} of your ${statuses.length} projects ${projectsNeedingMigration === 1 ? "needs" : "need"} an upgrade.`}- </span>- </div>- </Callout>+ {({ onDismiss }) => (+ <div className="mb-4">+ <Callout+ variant="info"+ align="middle"+ actions={+ <>+ <Button asChild size="sm" variant="secondary">+ <Link+ href="/v4-migration"+ onClick={() =>+ capture("v4_migration:overview_banner_status_clicked")+ }+ >+ Check status+ </Link>+ </Button>+ <Button asChild size="sm" variant="secondary">+ <a+ href={V4_DOCS_URL}+ target="_blank"+ rel="noopener noreferrer"+ onClick={() =>+ capture("v4_migration:overview_banner_docs_clicked")+ }+ >+ Docs+ </a>+ </Button>+ </>+ }+ onDismiss={onDismiss}+ >+ <div className="flex items-start gap-2 sm:items-center">+ <Zap className="mt-0.5 h-4 w-4 shrink-0 sm:mt-0" />+ <span>+ <span className="font-bold">+ Langfuse v4 is here: real-time and up to 165× faster.+ </span>{" "}+ {projectsNeedingMigration === statuses.length+ ? projectsNeedingMigration === 1+ ? "Your project needs an upgrade."+ : "All projects need an upgrade."+ : `${projectsNeedingMigration} of your ${statuses.length} projects ${projectsNeedingMigration === 1 ? "needs" : "need"} an upgrade.`}+ </span>+ </div>+ </Callout>+ </div>+ )}+ </DismissController>);}