import { ItemBadge } from "@/src/components/ItemBadge"; import { Skeleton } from "@/src/components/ui/skeleton"; import { useExtractVariables } from "@/src/features/evals/hooks/useExtractVariables"; import { type VariableMapping } from "@/src/features/evals/utils/evaluator-form-utils"; import { cn } from "@/src/utils/tailwind"; import { type RouterOutput } from "@/src/utils/types"; import { type EvalTemplate } from "@langfuse/shared"; import Link from "next/link"; import { Fragment, useMemo } from "react"; const VARIABLE_COLORS = [ "text-primary-accent", "text-dark-yellow", "text-dark-blue", "text-dark-green", "text-dark-red", ]; export const getVariableColor = (index: number) => { return VARIABLE_COLORS[index % VARIABLE_COLORS.length]; }; // Component for colored variable display const ColoredVariable = ({ value, index, }: { value: unknown; index: number; }) => { // Rotate through colors const color = getVariableColor(index); // Format the value based on its type const renderValue = () => { if (value === null || value === undefined) { return ""; } if (typeof value === "string") { // Check if the string is a JSON stringified string (starts and ends with quotes) if (value.startsWith('"') && value.endsWith('"') && value.length >= 2) { try { // Attempt to parse it as JSON const parsed = JSON.parse(value); if (typeof parsed === "string") { // If it was a string, return the unquoted version return parsed; } } catch { // If parsing fails, it's not a JSON string literal, so return as-is } } // Display strings directly return value === "" ? "" : value; } if (typeof value === "object") { // Pretty print objects and arrays return JSON.stringify(value, null, 2); } // For other primitives (numbers, booleans) return String(value); }; const displayValue = renderValue(); const isLarge = typeof displayValue === "string" && displayValue.length > 1000; return ( {isLarge ? displayValue.substring(0, 1000) + "..." : displayValue} ); }; // Custom wrapper for prompt that renders fragments with colored variables const ColoredPromptView = ({ fragments, className, }: { fragments: Array<{ type: "text" | "variable"; content?: string; name?: string; value?: unknown; colorIndex?: number; }>; className?: string; }) => { return (
{fragments.map((fragment, idx) => (
{fragment.type === "text" ? (
fragment.content
) : (
)}
))}
Loading variables...