🪢 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
feat(ui): add notification card in sidebar (#4137)
Marc Klingenb88f3bed4087
diff --git a/web/src/components/app-sidebar.tsx b/web/src/components/app-sidebar.tsxindex f20c22eb80..7cc54647bc 100644--- a/web/src/components/app-sidebar.tsx+++ b/web/src/components/app-sidebar.tsx@@ -15,6 +15,7 @@ import { useRouter } from "next/router";import Link from "next/link";import { Alert, AlertDescription } from "@/src/components/ui/alert";import { LangfuseLogo } from "@/src/components/LangfuseLogo";+import { SidebarNotifications } from "@/src/components/sidebar-notifications";type AppSidebarProps = {navItems: NavMainItem[];@@ -34,12 +35,13 @@ export function AppSidebar({<div className="flex items-center gap-2 p-2"><LangfuseLogo version /></div>+ <DemoBadge /></SidebarHeader><SidebarContent><NavMain items={navItems} /><div className="flex-1" />- <div className="p-2">- <DemoBadge />+ <div className="flex flex-col gap-2 p-2">+ <SidebarNotifications /></div><NavMain items={secondaryNavItems} showFeedbackButton /></SidebarContent>@@ -59,7 +61,7 @@ const DemoBadge = () => {env.NEXT_PUBLIC_DEMO_PROJECT_ID &&routerProjectId === env.NEXT_PUBLIC_DEMO_PROJECT_ID &&Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) ? (- <Alert className="bg-light-yellow group-data-[collapsible=icon]:hidden">+ <Alert className="rounded-md bg-light-yellow group-data-[collapsible=icon]:hidden"><AlertDescription className="overflow-hidden text-ellipsis whitespace-nowrap text-xs">View-only{" "}<Linkdiff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsxindex 638782b575..95c88ea817 100644--- a/web/src/components/layouts/layout.tsx+++ b/web/src/components/layouts/layout.tsx@@ -7,10 +7,6 @@ import { env } from "@/src/env.mjs";import { Spinner } from "@/src/components/layouts/spinner";import { hasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";import { Toaster } from "@/src/components/ui/sonner";-import {- NOTIFICATIONS,- useCheckNotification,-} from "@/src/features/notifications/checkNotifications";import DOMPurify from "dompurify";import { ThemeToggle } from "@/src/features/theming/ThemeToggle";import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";@@ -106,8 +102,6 @@ export default function Layout(props: PropsWithChildren) {| undefined;const session = useSessionWithRetryOnUnauthenticated();- useCheckNotification(NOTIFICATIONS, session.status === "authenticated");-const enableExperimentalFeatures =session.data?.environment.enableExperimentalFeatures ?? false;diff --git a/web/src/components/sidebar-notifications.tsx b/web/src/components/sidebar-notifications.tsxnew file mode 100644index 0000000000..47bef610cc--- /dev/null+++ b/web/src/components/sidebar-notifications.tsx@@ -0,0 +1,125 @@+import { Button } from "@/src/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/src/components/ui/card";+import { useEffect, useState } from "react";+import { X } from "lucide-react";+import useLocalStorage from "./useLocalStorage";+import Link from "next/link";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";++type SidebarNotification = {+ id: string; // Add unique ID for each notification+ title: string;+ description: React.ReactNode;+ link: string;+ // defaults to "Learn more" if no linkContent and no linkTitle+ linkTitle?: string;+ linkContent?: React.ReactNode;+};++const notifications: SidebarNotification[] = [+ {+ id: "github-star",+ title: "Star Langfuse",+ description:+ "See the latest releases and help grow the community on GitHub.",+ link: "https://github.com/langfuse/langfuse",+ linkContent: (+ // eslint-disable-next-line @next/next/no-img-element+ <img+ alt="Langfuse Github stars"+ src="https://img.shields.io/github/stars/langfuse/langfuse?label=langfuse&style=social"+ />+ ),+ },+];++const STORAGE_KEY = "dismissed-sidebar-notifications";++export function SidebarNotifications() {+ const capture = usePostHogClientCapture();+ const [currentNotificationIndex, setCurrentNotificationIndex] = useState<+ number | null+ >(null);++ const [dismissedNotifications, setDismissedNotifications] = useLocalStorage<+ string[]+ >(STORAGE_KEY, []);++ // Find the first non-dismissed notification on mount or when dismissed list changes+ useEffect(() => {+ const firstAvailableIndex = notifications.findIndex(+ (notif) => !dismissedNotifications.includes(notif.id),+ );+ setCurrentNotificationIndex(+ firstAvailableIndex === -1 ? null : firstAvailableIndex,+ );+ }, [dismissedNotifications]);++ const dismissNotification = (id: string) => {+ setDismissedNotifications([...dismissedNotifications, id]);+ };++ if (currentNotificationIndex === null) {+ return null;+ }++ const currentNotification = notifications[currentNotificationIndex];++ return (+ <Card className="relative overflow-hidden rounded-md bg-opacity-50 shadow-none group-data-[collapsible=icon]:hidden">+ <Button+ variant="ghost"+ size="sm"+ className="absolute right-2 top-2 h-6 w-6 p-0"+ onClick={() => {+ capture("notification:dismiss_notification", {+ notification_id: currentNotification.id,+ });+ dismissNotification(currentNotification.id);+ }}+ title="Dismiss"+ >+ <X className="h-4 w-4" />+ </Button>+ <CardHeader className="p-4 pb-0">+ <CardTitle className="text-sm">{currentNotification.title}</CardTitle>+ <CardDescription>{currentNotification.description}</CardDescription>+ </CardHeader>+ <CardContent className="p-4 pt-2">+ {currentNotification.linkContent ? (+ <Link+ href={currentNotification.link}+ target="_blank"+ onClick={() => {+ capture("notification:click_link", {+ notification_id: currentNotification.id,+ });+ }}+ >+ {currentNotification.linkContent}+ </Link>+ ) : (+ <Button variant="secondary" size="sm" asChild>+ <Link+ href={currentNotification.link}+ target="_blank"+ onClick={() => {+ capture("notification:click_link", {+ notification_id: currentNotification.id,+ });+ }}+ >+ {currentNotification.linkTitle ?? "Learn more"}+ </Link>+ </Button>+ )}+ </CardContent>+ </Card>+ );+}diff --git a/web/src/features/notifications/checkNotifications.tsx b/web/src/features/notifications/checkNotifications.tsxdeleted file mode 100644index ac9681d64a..0000000000--- a/web/src/features/notifications/checkNotifications.tsx+++ /dev/null@@ -1,158 +0,0 @@-import { useEffect } from "react";-import Link from "next/link";-import { toast } from "sonner";-import useLocalStorage from "@/src/components/useLocalStorage";-import {- Notification,- type TNotification,-} from "@/src/features/notifications/Notification";-import { Button } from "@/src/components/ui/button";-import { env } from "@/src/env.mjs";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";--const ButtonWithPosthog = ({- children,- className,- notificationId,- href,-}: {- children: React.ReactNode;- className?: string;- notificationId: string;- href: string;-}) => {- const capture = usePostHogClientCapture();- return (- <Button- size="sm"- variant="secondary"- className={className}- onClick={() => {- capture("notification:click_link"),- { notificationId: notificationId, href: href };- }}- asChild- >- <Link href={href}>{children}</Link>- </Button>- );-};--export const NOTIFICATIONS: TNotification[] = [- // {- // id: 3,- // releaseDate: new Date("2024-04-26"),- // message: "Langfuse 2.0 is live on ProductHunt",- // },- {- id: 2,- releaseDate: new Date("2024-04-24"),- message: "Langfuse Launch Week #1 is in Full Swing",- description: (- <div>- <p>- {- "We're launching a new feature every day this week. We already launched:"- }- </p>- <ul className="ms-4 mt-2 list-outside list-disc">- <li>Langfuse x Posthog integration</li>- <li>Python decorator integration</li>- <li>LLM Playground</li>- <li>More to come every day until Friday</li>- </ul>- <ButtonWithPosthog- className="mt-3"- notificationId="2"- href="https://langfuse.com/launch"- >- Follow along- </ButtonWithPosthog>- </div>- ),- },- {- id: 1,- releaseDate: new Date("2024-01-29"),- message: "New: Custom model prices",- description: (- <div>- <p>- Langfuse now supports any LLM model for usage and cost tracking. The- highlights:- </p>- <ul className="ms-4 mt-2 list-outside list-disc">- <li>Define your model definitions (price, usage).</li>- <li>Optionally, ingest cost via the API/SDK</li>- <li>Support for usage in tokens, seconds and characters</li>- </ul>- {env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined && (- <p className="mt-2">- Self-hosted: The upgrade to v2 includes a breaking change. After- upgrading, you must run a migration script to ensure accurate usage- and cost calculation for previously ingested traces. Please refer to- the post for details.- </p>- )}- <ButtonWithPosthog- notificationId="1"- href="https://langfuse.com/changelog/2024-01-29-custom-model-prices"- >- Changelog post- </ButtonWithPosthog>- </div>- ),- },-];--export const useCheckNotification = (- notification: TNotification[],- authenticated: boolean,-) => {- const [lastSeenId, setLastSeenId] = useLocalStorage<number>(- "lastSeenNotificationId",- 0,- );- useEffect(() => {- if (!authenticated) {- return;- }-- const timeoutId = setTimeout(() => {- notification- .reverse()- .filter(- (n) =>- // only show notifications that are less than 30 days old- (new Date().getTime() - n.releaseDate.getTime()) /- (1000 * 60 * 60 * 24) <=- 30,- )- .forEach((n) => {- if (n.id > lastSeenId) {- toast.custom(- (t) => (- <Notification- notification={n}- setLastSeenId={setLastSeenId}- dismissToast={toast.dismiss}- toast={t}- />- ),- {- // needed to upsert toasts in case it is rendered multiple times- id: n.id.toString(),- duration: 600_000, // 10 minutes- style: {- padding: "1rem",- border: "1px solid #e2e8f0",- borderRadius: "0.5rem",- },- },- );- }- });- }, 1500);- return () => clearTimeout(timeoutId);- }, [lastSeenId, notification, setLastSeenId, authenticated]);-};