🪢 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
fix(prompts): undefined prompt name when clicking on metrics (#7358)
Nimar7f40a32aa9a5
diff --git a/web/src/features/prompts/components/NewPromptForm/index.tsx b/web/src/features/prompts/components/NewPromptForm/index.tsxindex f29a1caea0..7a0d3accc5 100644--- a/web/src/features/prompts/components/NewPromptForm/index.tsx+++ b/web/src/features/prompts/components/NewPromptForm/index.tsx@@ -214,6 +214,9 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {<div><FormItem><FormLabel>Name</FormLabel>+ <FormDescription>+ Use slashes '/' in prompt names to organize them into <a target="_blank" rel="noopener noreferrer" href="https://langfuse.com/docs/prompts/get-started#prompt-folders-for-organization"><i>folders</i></a>.+ </FormDescription><FormControl><Input placeholder="Name your prompt" {...field} /></FormControl>diff --git a/web/src/features/prompts/components/prompt-detail.tsx b/web/src/features/prompts/components/prompt-detail.tsxindex 6161b27467..bd52ad1660 100644--- a/web/src/features/prompts/components/prompt-detail.tsx+++ b/web/src/features/prompts/components/prompt-detail.tsx@@ -95,23 +95,16 @@ ${labels.length > 0 ? labels.map((label) => `const prompt = await langfuse.getPrlangfuse.getPrompt("${name}", ${version})`;-export const PromptDetail = () => {+export const PromptDetail = ({ promptName: promptNameProp }: { promptName?: string } = {}) => {const projectId = useProjectIdFromURL();const capture = usePostHogClientCapture();const router = useRouter();- // Handle both [promptName] route and catch-all [...folder] route- const promptName = router.query.promptName- ? decodeURIComponent(router.query.promptName as string)- : (() => {- const folder = router.query.folder;- if (Array.isArray(folder)) {- return folder.join('/');- } else if (typeof folder === 'string') {- return folder;- }- return '';- })();+ const promptName = promptNameProp || (+ router.query.promptName+ ? decodeURIComponent(router.query.promptName as string)+ : ''+ );const [currentPromptVersion, setCurrentPromptVersion] = useQueryParam("version",NumberParam,diff --git a/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx b/web/src/pages/project/[projectId]/prompts/[[...folder]].tsxindex 2ecf528bf2..138a61dd14 100644--- a/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx+++ b/web/src/pages/project/[projectId]/prompts/[[...folder]].tsx@@ -11,6 +11,7 @@ import { useEntitlementLimit } from "@/src/features/entitlements/hooks";import { PromptDetail } from "@/src/features/prompts/components/prompt-detail";import PromptMetrics from "./metrics";import { useQueryParams, StringParam } from "use-query-params";+import React from "react";export default function PromptsWithFolder() {const router = useRouter();@@ -20,6 +21,10 @@ export default function PromptsWithFolder() {const folderQueryParam = queryParams.folder || '';// Determine view type based on route segments+ // NOTE: there is a bug here, that if the user directly accesses a prompt name which ends in `/metrics`,+ // the prompt metrics page will be shown for a non-existing prompt name. Doesn't happen if the user clicks+ // this in the UI (we URL encode here and don't strip metrics). We could resolve this with another API call+ // to check the prompt name existence.const segmentsArray = Array.isArray(routeSegments) ? routeSegments : [];const isMetricsPage = segmentsArray.length > 0 && segmentsArray[segmentsArray.length - 1] === 'metrics';const promptNameFromRoute = segmentsArray.length > 0@@ -63,9 +68,9 @@ export default function PromptsWithFolder() {// Decide what to render: metrics, detail, or folder viewif (promptNameFromRoute.length > 0) {if (isMetricsPage) {- return <PromptMetrics />;+ return <PromptMetrics promptName={promptNameFromRoute} />;}- return <PromptDetail />;+ return <PromptDetail promptName={promptNameFromRoute} />;}return (diff --git a/web/src/pages/project/[projectId]/prompts/metrics.tsx b/web/src/pages/project/[projectId]/prompts/metrics.tsxindex 1afaff191b..dcf0d4a276 100644--- a/web/src/pages/project/[projectId]/prompts/metrics.tsx+++ b/web/src/pages/project/[projectId]/prompts/metrics.tsx@@ -77,10 +77,14 @@ function joinPromptCoreAndMetricData(return { status: "success", combinedData };}-export default function PromptVersionTable() {+export default function PromptVersionTable({ promptName: promptNameProp }: { promptName?: string } = {}) {const router = useRouter();const projectId = router.query.projectId as string;- const promptName = decodeURIComponent(router.query.promptName as string);+ const promptName = promptNameProp || (+ router.query.promptName+ ? decodeURIComponent(router.query.promptName as string)+ : ''+ );const [paginationState, setPaginationState] = useQueryParams({pageIndex: withDefault(NumberParam, 0),