Skip to content

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

feat(web): add source promt name to playground window content (#17248)

tobi_klf13839452a5d
diff --git a/web/src/features/playground/page/components/JumpToPlaygroundDropdownMenuController.tsx b/web/src/features/playground/page/components/JumpToPlaygroundDropdownMenuController.tsx
index 028a6b68de..7d326177fc 100644
--- a/web/src/features/playground/page/components/JumpToPlaygroundDropdownMenuController.tsx
+++ b/web/src/features/playground/page/components/JumpToPlaygroundDropdownMenuController.tsx
@@ -7,8 +7,10 @@ import { usePersistedWindowIds } from "@/src/features/playground/page/hooks/useP
import {
type PlaygroundCache,
type PlaygroundSchema,
+ type PlaygroundSourcePrompt,
type PlaygroundTool,
} from "@/src/features/playground/page/types";
+import { getMessagesFingerprint } from "@/src/features/playground/page/utils/messagesFingerprint";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";
import {
@@ -207,6 +209,14 @@ export const JumpToPlaygroundDropdownMenuController = (
const parsePrompt = (
prompt: Prompt & { resolvedPrompt?: Prisma.JsonValue },
): PlaygroundCache => {
+ const asSourcePrompt = (
+ messages: (ChatMessage | PlaceholderMessage)[],
+ ): PlaygroundSourcePrompt => ({
+ name: prompt.name,
+ version: prompt.version,
+ initialMessagesFingerprint: getMessagesFingerprint(messages),
+ });
+
if (prompt.type === PromptType.Chat) {
try {
const inResult = normalizeInput(prompt.resolvedPrompt);
@@ -221,23 +231,22 @@ const parsePrompt = (
if (messages.length === 0) return null;
- return { messages };
+ return { messages, sourcePrompt: asSourcePrompt(messages) };
} catch {
return null;
}
} else {
// Text prompt
const promptString = prompt.resolvedPrompt;
-
- return {
- messages: [
- createEmptyMessage({
- type: ChatMessageType.System,
- role: ChatMessageRole.System,
- content: typeof promptString === "string" ? promptString : "",
- }),
- ],
- };
+ const messages = [
+ createEmptyMessage({
+ type: ChatMessageType.System,
+ role: ChatMessageRole.System,
+ content: typeof promptString === "string" ? promptString : "",
+ }),
+ ];
+
+ return { messages, sourcePrompt: asSourcePrompt(messages) };
}
};
diff --git a/web/src/features/playground/page/components/Messages.tsx b/web/src/features/playground/page/components/Messages.tsx
index 1f6b5817a5..f97c424d48 100644
--- a/web/src/features/playground/page/components/Messages.tsx
+++ b/web/src/features/playground/page/components/Messages.tsx
@@ -24,7 +24,7 @@ import {
export const Messages: React.FC<MessagesContext> = (props) => {
return (
- <div className="flex h-full flex-col space-y-4 pt-2 pr-4">
+ <div className="flex h-full flex-col space-y-4 pt-2">
<ResizablePanelGroup orientation="vertical">
<ResizablePanel minSize="10%">
<ChatMessages {...props} />
diff --git a/web/src/features/playground/page/components/MultiWindowPlayground.tsx b/web/src/features/playground/page/components/MultiWindowPlayground.tsx
index 6947c30332..e5d0e41483 100644
--- a/web/src/features/playground/page/components/MultiWindowPlayground.tsx
+++ b/web/src/features/playground/page/components/MultiWindowPlayground.tsx
@@ -2,6 +2,7 @@
import React, { useMemo, useCallback, useRef, useEffect } from "react";
import { PlaygroundProvider, usePlaygroundContext } from "../context";
import { SaveToPromptButton } from "./SaveToPromptButton";
+import { SourcePromptHeading } from "./SourcePromptHeading";
import { Button } from "@/src/components/ui/button";
import { Plus, X } from "lucide-react";
import { MULTI_WINDOW_CONFIG, type MultiWindowState } from "../types";
@@ -16,6 +17,7 @@ import {
TooltipTrigger,
} from "@/src/components/ui/tooltip";
import { useIsMobile } from "@/src/hooks/use-mobile";
+import { getMessagesFingerprint } from "@/src/features/playground/page/utils/messagesFingerprint";
/**
* MultiWindowPlayground Component
@@ -157,6 +159,15 @@ function PlaygroundWindowContent({
const { registerPageTarget, unregisterPageTarget } =
useMessageSearchActions();
const windowContainerRef = useRef<HTMLDivElement | null>(null);
+ const { messages, sourcePrompt } = playgroundContext;
+
+ const isSourcePromtEdited = useMemo(
+ () =>
+ Boolean(sourcePrompt) &&
+ getMessagesFingerprint(messages) !==
+ sourcePrompt?.initialMessagesFingerprint,
+ [messages, sourcePrompt],
+ );
const handleRemove = useCallback(() => {
onRemove(windowId);
@@ -181,9 +192,8 @@ function PlaygroundWindowContent({
ref={windowContainerRef}
className="playground-window bg-background @container flex h-full min-w-0 flex-col rounded-lg border shadow-xs"
>
- {/* Window Header */}
- <div className="bg-muted/50 relative shrink-0 border-b px-3 py-1">
- <div className="flex items-center pr-32 @xl:pr-96">
+ <div className="bg-muted/50 shrink-0 border-b">
+ <div className="relative flex items-center py-1 pr-32 pl-3 @xl:pr-96">
<div className="flex items-center gap-2">
<ModelParameters {...playgroundContext} layout="compact" />
</div>
@@ -247,7 +257,15 @@ function PlaygroundWindowContent({
<div className="flex h-full flex-col">
<ConfigurationDropdowns />
- <div className="flex-1 overflow-auto p-4">
+ <div className="relative flex-1 overflow-auto p-4">
+ {playgroundContext.sourcePrompt && (
+ <div className="absolute top-1 flex max-w-[calc(100%-4rem)] justify-end">
+ <SourcePromptHeading
+ sourcePrompt={playgroundContext.sourcePrompt}
+ isEdited={isSourcePromtEdited}
+ />
+ </div>
+ )}
<Messages {...playgroundContext} />
</div>
</div>
diff --git a/web/src/features/playground/page/components/SourcePromptHeading.tsx b/web/src/features/playground/page/components/SourcePromptHeading.tsx
new file mode 100644
index 0000000000..8d35da23d6
--- /dev/null
+++ b/web/src/features/playground/page/components/SourcePromptHeading.tsx
@@ -0,0 +1,27 @@
+import { Badge } from "@/src/components/design-system/Badge/Badge";
+import { type PlaygroundSourcePrompt } from "@/src/features/playground/page/types";
+
+type SourcePromptHeadingProps = {
+ sourcePrompt: PlaygroundSourcePrompt;
+ isEdited: boolean;
+};
+
+export const SourcePromptHeading: React.FC<SourcePromptHeadingProps> = ({
+ sourcePrompt,
+ isEdited,
+}) => {
+ const version = `v${sourcePrompt.version}`;
+
+ return (
+ <div className="text-muted-foreground flex min-w-0 items-center gap-1 text-xs leading-tight">
+ <span
+ className="min-w-0 truncate"
+ title={`${sourcePrompt.name} ${version}`}
+ >
+ {sourcePrompt.name}
+ </span>
+ <Badge size="sm" text={version} />
+ {isEdited && <span className="text-foreground shrink-0">· edited</span>}
+ </div>
+ );
+};
diff --git a/web/src/features/playground/page/context/index.tsx b/web/src/features/playground/page/context/index.tsx
index 4af8da26ba..3474577fa8 100644
--- a/web/src/features/playground/page/context/index.tsx
+++ b/web/src/features/playground/page/context/index.tsx
@@ -36,6 +36,7 @@ import type { ModelParamsContext } from "@/src/components/ModelParameters";
import { env } from "@/src/env.mjs";
import {
type PlaygroundSchema,
+ type PlaygroundSourcePrompt,
type PlaygroundTool,
type PlaceholderMessageFillIn,
type PlaygroundProviderProps,
@@ -68,6 +69,8 @@ type PlaygroundContextType = {
structuredOutputSchema: PlaygroundSchema | null;
setStructuredOutputSchema: (schema: PlaygroundSchema | null) => void;
+ sourcePrompt: PlaygroundSourcePrompt | null;
+
output: string;
outputReasoning: string;
outputJson: string;
@@ -113,6 +116,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
const capture = usePostHogClientCapture();
const projectId = useProjectIdFromURL();
const { playgroundCache, setPlaygroundCache } = usePlaygroundCache(windowId);
+ const sourcePrompt = playgroundCache?.sourcePrompt ?? null;
const [promptVariables, setPromptVariables] = useState<PromptVariable[]>([]);
const [messagePlaceholders, setMessagePlaceholders] = useState<
PlaceholderMessageFillIn[]
@@ -459,6 +463,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
messagePlaceholders,
tools,
structuredOutputSchema,
+ sourcePrompt,
});
capture("playground:execute_button_click", {
inputLength: finalMessages.length,
@@ -485,6 +490,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
capture,
setPlaygroundCache,
structuredOutputSchema,
+ sourcePrompt,
projectId,
],
);
@@ -574,6 +580,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
messagePlaceholders,
tools,
structuredOutputSchema,
+ sourcePrompt,
});
}
}, [
@@ -584,6 +591,7 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
messagePlaceholders,
tools,
structuredOutputSchema,
+ sourcePrompt,
setPlaygroundCache,
cacheLoaded,
]);
@@ -728,6 +736,8 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
structuredOutputSchema,
setStructuredOutputSchema,
+ sourcePrompt,
+
messages,
addMessage,
setMessages,
diff --git a/web/src/features/playground/page/types.ts b/web/src/features/playground/page/types.ts
index 4bd952cc8d..80a458c003 100644
--- a/web/src/features/playground/page/types.ts
+++ b/web/src/features/playground/page/types.ts
@@ -28,6 +28,12 @@ export type PlaceholderMessageFillIn = {
isUsed: boolean;
};
+export type PlaygroundSourcePrompt = {
+ name: string;
+ version: number;
+ initialMessagesFingerprint: string;
+};
+
export type PlaygroundCache = {
messages: (ChatMessage | PlaceholderMessage)[];
modelParams?: Partial<UIModelParams> &
@@ -37,6 +43,7 @@ export type PlaygroundCache = {
messagePlaceholders?: PlaceholderMessageFillIn[];
tools?: PlaygroundTool[];
structuredOutputSchema?: PlaygroundSchema | null;
+ sourcePrompt?: PlaygroundSourcePrompt | null;
} | null;
// Multi-window types and interfaces
diff --git a/web/src/features/playground/page/utils/messagesFingerprint.ts b/web/src/features/playground/page/utils/messagesFingerprint.ts
new file mode 100644
index 0000000000..36b05e17e5
--- /dev/null
+++ b/web/src/features/playground/page/utils/messagesFingerprint.ts
@@ -0,0 +1,26 @@
+import {
+ type ChatMessageWithId,
+ type ChatMessage,
+ type PlaceholderMessage,
+} from "@langfuse/shared";
+
+/**
+ * Stable string for a set of playground messages, used to tell whether a window
+ * still holds the prompt version it was opened from.
+ *
+ * `id` is dropped because the provider assigns one to every message while
+ * hydrating from the cache, and keys are sorted because equality here must not
+ * depend on property order surviving a JSON round trip.
+ */
+export const getMessagesFingerprint = (
+ messages: (ChatMessage | PlaceholderMessage | ChatMessageWithId)[],
+): string =>
+ JSON.stringify(
+ messages.map((message) => {
+ const { id: _id, ...rest } = message as ChatMessageWithId;
+
+ return Object.fromEntries(
+ Object.entries(rest).sort(([a], [b]) => a.localeCompare(b)),
+ );
+ }),
+ );