import { CheckCircle2, Circle, TrashIcon } from "lucide-react"; import { Button } from "@/src/components/ui/button"; import { type PromptVariable } from "@langfuse/shared"; import { CodeMirrorEditor } from "@/src/components/editor"; import { usePlaygroundContext } from "../context"; import { useNamingConflicts } from "../hooks/useNamingConflicts"; export const PromptVariableComponent: React.FC<{ promptVariable: PromptVariable; }> = ({ promptVariable }) => { const { updatePromptVariableValue, deletePromptVariable, promptVariables, messagePlaceholders, } = usePlaygroundContext(); const { name, value, isUsed } = promptVariable; const { isVariableConflicting } = useNamingConflicts( promptVariables, messagePlaceholders, ); const hasConflict = isVariableConflicting(name); const handleInputChange = (value: string) => { updatePromptVariableValue(name, value); }; const handleDeleteVariable = () => { deletePromptVariable(name); }; const isUsedIcon = isUsed ? ( ) : ( ); const isUsedTooltip = isUsed ? "Variable is in use" : "Variable is not in use"; return (

{isUsedIcon}

{name}

handleInputChange(e)} mode="prompt" minHeight="none" className={`max-h-[10rem] w-full resize-y p-1 font-mono text-xs focus:outline-none ${hasConflict ? "border border-red-500" : ""}`} editable={true} lineNumbers={false} placeholder={name} /> {hasConflict && (

Variable name conflicts with placeholder. Names must be unique.

)}
); };