import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogBody, } from "@/src/components/ui/dialog"; import { Button } from "@/src/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/src/components/ui/select"; import { Label } from "@/src/components/ui/label"; import { api } from "@/src/utils/api"; import { CopyIcon, ExternalLinkIcon } from "lucide-react"; import { copyTextToClipboard } from "@/src/utils/clipboard"; type PromptSelectionDialogProps = { isOpen: boolean; onClose: () => void; onSelect?: (tag: string) => void; projectId: string; }; export function PromptSelectionDialog({ isOpen, onClose, onSelect, projectId, }: PromptSelectionDialogProps) { const [selectedPromptName, setSelectedPromptName] = useState(""); const [selectedTag, setSelectedTag] = useState(""); const [selectionType, setSelectionType] = useState<"version" | "label">( "label", ); const [selectedVersionOrLabel, setSelectedVersionOrLabel] = useState(""); const copySelectedTag = useCallback(() => { copyTextToClipboard(selectedTag); }, [selectedTag]); useEffect(() => { if (isOpen) { setSelectedPromptName(""); setSelectedTag(""); setSelectionType("label"); setSelectedVersionOrLabel(""); } }, [isOpen]); useEffect(() => { if (selectedPromptName && selectedVersionOrLabel) { if (selectionType === "version") { setSelectedTag( `@@@langfusePrompt:name=${selectedPromptName}|version=${selectedVersionOrLabel}@@@`, ); } else { setSelectedTag( `@@@langfusePrompt:name=${selectedPromptName}|label=${selectedVersionOrLabel}@@@`, ); } } else { setSelectedTag(""); } }, [selectedPromptName, selectedVersionOrLabel, selectionType]); const { data: promptOptions } = api.prompts.getPromptLinkOptions.useQuery( { projectId, }, { enabled: Boolean(projectId), refetchOnMount: false, refetchOnWindowFocus: false, refetchOnReconnect: false, staleTime: Infinity, }, ); const selectedPrompt = promptOptions?.find( (option) => option.name === selectedPromptName, ); const handleConfirm = useCallback(() => { if (!selectedTag) return; if (onSelect) { onSelect(selectedTag); } else { copySelectedTag(); } onClose(); }, [copySelectedTag, selectedTag, onSelect, onClose]); return ( Add inline prompt reference

Referenced prompts are dynamically resolved and inserted when fetched via API/SDK. This enables modular design—create complex prompts from reusable, independently maintained components.

Only text prompts can be referenced inline.

{selectedPromptName && (
)} {selectedPromptName && (
{selectedVersionOrLabel && ( )}
)}
{selectedTag && (
{selectedTag}

{onSelect ? "This tag will be inserted into the prompt content." : "This tag will be copied to clipboard to be then inserted into the prompt"}

)}
); }