import { Check, Save } from "lucide-react"; import { useRouter } from "next/router"; import { useState } from "react"; import { Button } from "@/src/components/ui/button"; import { InputCommand, InputCommandEmpty, InputCommandGroup, InputCommandInput, InputCommandItem, InputCommandList, } from "@/src/components/ui/input-command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/src/components/ui/popover"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/src/components/ui/tooltip"; import { usePlaygroundContext } from "@/src/features/playground/page/context"; import usePlaygroundCache from "@/src/features/playground/page/hooks/usePlaygroundCache"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL"; import { api } from "@/src/utils/api"; import { cn } from "@/src/utils/tailwind"; import DocPopup from "@/src/components/layouts/doc-popup"; import { PromptType } from "@langfuse/shared"; interface SaveToPromptButtonProps { className?: string; } export const SaveToPromptButton: React.FC = ({ className, }) => { const [selectedPromptId, setSelectedPromptId] = useState(""); const { modelParams, messages, output, promptVariables } = usePlaygroundContext(); const capture = usePostHogClientCapture(); const router = useRouter(); const projectId = useProjectIdFromURL(); const { setPlaygroundCache } = usePlaygroundCache(); const allChatPromptNamesWithIds = api.prompts.allNames .useQuery( { projectId: projectId as string, // Typecast as query is enabled only when projectId is present type: PromptType.Chat, }, { enabled: Boolean(projectId) }, ) .data?.map((prompt) => ({ name: prompt.name, id: prompt.id, })) ?? []; const handleNewPrompt = async () => { capture("playground:save_to_new_prompt_button_click", { projectId }); setPlaygroundCache({ modelParams, messages, output, promptVariables, }); await router.push( `/project/${projectId}/prompts/new?loadPlaygroundCache=true`, ); }; const handleNewPromptVersion = async () => { capture("playground:save_to_prompt_version_button_click", { projectId }); setPlaygroundCache({ modelParams, messages, output, promptVariables, }); await router.push( `/project/${projectId}/prompts/new?promptId=${selectedPromptId}&loadPlaygroundCache=true`, ); }; return ( Save as prompt No chat prompt found {allChatPromptNamesWithIds.map((chatPrompt) => ( { const promptId = allChatPromptNamesWithIds.find( (prompt) => prompt.name === currentValue, )?.id ?? ""; setSelectedPromptId( promptId === selectedPromptId ? "" : promptId, ); }} > {chatPrompt.name} ))} ); }; export function Divider() { return (

or

); }