Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(ui): add upgrade popover to version number (#2251)

Marc Klingen140452c89e6c
diff --git a/web/src/components/LangfuseLogo.tsx b/web/src/components/LangfuseLogo.tsx
index 8b46685839..256f523d0c 100644
--- a/web/src/components/LangfuseLogo.tsx
+++ b/web/src/components/LangfuseLogo.tsx
@@ -3,6 +3,83 @@ import { AlertTriangle, Check } from "lucide-react";
import { VERSION } from "@/src/constants";
import { env } from "@/src/env.mjs";
import { cn } from "@/src/utils/tailwind";
+import {
+ Popover,
+ PopoverTrigger,
+ PopoverContent,
+} from "@/src/components/ui/popover";
+import { ArrowUp } from "lucide-react";
+import { api } from "@/src/utils/api";
+import { Button } from "@/src/components/ui/button";
+import Link from "next/link";
+
+const VersionLabel = ({ className }: { className?: string }) => {
+ const checkUpdate = api.public.checkUpdate.useQuery(undefined, {
+ refetchOnMount: false,
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ enabled: !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION, // do not check for updates on Langfuse Cloud
+ onError: (error) => console.error("checkUpdate error", error), // do not render default error message
+ });
+
+ const hasUpdate =
+ !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&
+ checkUpdate.data &&
+ checkUpdate.data.updateType;
+
+ const color =
+ checkUpdate.data?.updateType === "major"
+ ? "text-dark-red"
+ : checkUpdate.data?.updateType === "minor"
+ ? "text-dark-yellow"
+ : undefined;
+
+ return (
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button variant="ghost" size="xs" className={className}>
+ {VERSION}
+ {hasUpdate && <ArrowUp className={`ml-1 h-3 w-3 ${color}`} />}
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="max-w-[260px]">
+ {hasUpdate ? (
+ <div className="mb-4 text-center">
+ New {checkUpdate.data?.updateType} version:{" "}
+ {checkUpdate.data?.latestRelease}
+ </div>
+ ) : !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION ? (
+ <div className="mb-4 text-center">This is the latest release</div>
+ ) : null}
+ <div className="flex flex-col gap-2">
+ <Button size="sm" variant="secondary" asChild>
+ <Link
+ href="https://github.com/langfuse/langfuse/releases"
+ target="_blank"
+ >
+ GitHub Releases
+ </Link>
+ </Button>
+ <Button size="sm" variant="secondary" asChild>
+ <Link href="https://langfuse.com/changelog" target="_blank">
+ Changelog
+ </Link>
+ </Button>
+ {hasUpdate && (
+ <Button size="sm">
+ <Link
+ href="https://langfuse.com/docs/deployment/self-host#update"
+ target="_blank"
+ >
+ Update
+ </Link>
+ </Button>
+ )}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+};
export const LangfuseIcon = ({
size = 32,
@@ -65,22 +142,12 @@ export const LangfuseLogo = ({
<span
className={cn(
"ml-2 font-mono font-semibold",
- size === "sm" ? "text-sm" : "text-xl",
+ size === "sm" ? "text-sm" : "text-lg",
)}
>
Langfuse
</span>
- {version && (
- <a
- href="https://github.com/langfuse/langfuse/releases"
- target="_blank"
- rel="noopener"
- title="View releases on GitHub"
- className="ml-2 text-xs text-muted-foreground"
- >
- {VERSION}
- </a>
- )}
+ {version && <VersionLabel className="ml-2" />}
</div>
</div>
);
diff --git a/web/src/components/Support.tsx b/web/src/components/Support.tsx
index c23fd4281a..eae8d60de3 100644
--- a/web/src/components/Support.tsx
+++ b/web/src/components/Support.tsx
@@ -67,7 +67,7 @@ const supportChannels = [
title: "Slack Connect",
description: "Get a dedicated support channel for you and your team.",
href: "mailto:[email protected]?subject=Slack%20Connect%20Request&body=I'd%20like%20to%20request%20a%20dedicated%20Slack%20Connect%20channel%20for%20me%20and%20my%20team.%0D%0A%0D%0AUsers%20(emails)%20to%20include%20besides%20mine%3A%0D%0A%0D%0A",
- buttonText: "Request Slack Connect (via Email)",
+ buttonText: "Request via Email",
},
];
diff --git a/web/src/server/api/root.ts b/web/src/server/api/root.ts
index 101fcb88a0..540e3ffa77 100644
--- a/web/src/server/api/root.ts
+++ b/web/src/server/api/root.ts
@@ -17,6 +17,7 @@ import { evalRouter } from "@/src/ee/features/evals/server/router";
import { posthogIntegrationRouter } from "@/src/features/posthog-integration/posthog-integration-router";
import { llmApiKeyRouter } from "@/src/features/llm-api-key/server/router";
import { scoreConfigsRouter } from "@/src/server/api/routers/scoreConfigs";
+import { publicRouter } from "@/src/server/api/routers/public";
/**
* This is the primary router for your server.
@@ -42,6 +43,7 @@ export const appRouter = createTRPCRouter({
evals: evalRouter,
posthogIntegration: posthogIntegrationRouter,
llmApiKey: llmApiKeyRouter,
+ public: publicRouter,
});
// export type definition of API
diff --git a/web/src/server/api/routers/public.ts b/web/src/server/api/routers/public.ts
new file mode 100644
index 0000000000..5d9f3dd5e3
--- /dev/null
+++ b/web/src/server/api/routers/public.ts
@@ -0,0 +1,94 @@
+import { VERSION } from "@/src/constants/VERSION";
+import { env } from "@/src/env.mjs";
+import { createTRPCRouter, publicProcedure } from "@/src/server/api/trpc";
+import { TRPCError } from "@trpc/server";
+import { z } from "zod";
+
+const versionSchema = z.string().regex(/^v\d+\.\d+\.\d+$/); // e.g. v1.2.3
+
+const compareVersions = (
+ current: string,
+ latest: string,
+): "major" | "minor" | "patch" | null => {
+ const currentValidated = versionSchema.parse(current);
+ const latestValidated = versionSchema.parse(latest);
+
+ const parseVersion = (version: string) => {
+ if (version.startsWith("v")) {
+ version = version.slice(1);
+ }
+ return version.split(".").map(Number);
+ };
+
+ const [currentMajor, currentMinor, currentPatch] =
+ parseVersion(currentValidated);
+ const [latestMajor, latestMinor, latestPatch] = parseVersion(latestValidated);
+
+ if (latestMajor > currentMajor) return "major";
+ if (latestMajor === currentMajor && latestMinor > currentMinor)
+ return "minor";
+ if (
+ latestMajor === currentMajor &&
+ latestMinor === currentMinor &&
+ latestPatch > currentPatch
+ )
+ return "patch";
+
+ return null;
+};
+
+const ReleaseApiRes = z.array(
+ z.object({
+ repo: z.string(),
+ latestRelease: z.string(),
+ publishedAt: z.string().datetime(),
+ url: z.string().url(),
+ }),
+);
+
+export const publicRouter = createTRPCRouter({
+ checkUpdate: publicProcedure.query(async () => {
+ // Skip update check on Langfuse Cloud
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) return null;
+
+ let body;
+ try {
+ const response = await fetch(
+ `https://langfuse.com/api/latest-releases?repo=langfuse/langfuse&version=${VERSION}`,
+ );
+ body = await response.json();
+ } catch (error) {
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: "Failed to fetch or json parse the latest releases",
+ cause: error,
+ });
+ }
+
+ const releases = ReleaseApiRes.safeParse(body);
+ if (!releases.success) {
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: "Release API response is invalid",
+ });
+ }
+ const langfuseRelease = releases.data.find(
+ (release) => release.repo === "langfuse/langfuse",
+ );
+ if (!langfuseRelease) {
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: "Release API response is invalid",
+ });
+ }
+
+ const updateType = compareVersions(VERSION, langfuseRelease.latestRelease);
+
+ return {
+ updateType,
+ currentVersion: VERSION,
+ latestRelease: langfuseRelease.latestRelease,
+ url: langfuseRelease.url,
+ };
+ }),
+});