import React from "react"; import { Card, Text, Button, TabGroup, TabList, Tab, TabPanel, TabPanels } from "@tremor/react"; import { CheckCircleIcon, XCircleIcon, ClipboardCopyIcon } from "@heroicons/react/outline"; import { ResponseTimeIndicator } from "./response_time_indicator"; // Helper function to deep-parse a JSON string if possible const deepParse = (input: any) => { let parsed = input; if (typeof parsed === "string") { try { parsed = JSON.parse(parsed); } catch { return parsed; } } return parsed; }; // TableClickableErrorField component with copy-to-clipboard functionality const TableClickableErrorField: React.FC<{ label: string; value: string | null | undefined }> = ({ label, value, }) => { const [isExpanded, setIsExpanded] = React.useState(false); const [copied, setCopied] = React.useState(false); const safeValue = value?.toString() || "N/A"; const truncated = safeValue.length > 50 ? safeValue.substring(0, 50) + "..." : safeValue; const handleCopy = () => { navigator.clipboard.writeText(safeValue); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return (
{label}
                {isExpanded ? safeValue : truncated}
              
); }; // Add new interface for Redis details interface RedisDetails { redis_host?: string; redis_port?: string; redis_version?: string; startup_nodes?: string; namespace?: string; } // Add new interface for Error Details interface ErrorDetails { message: string; traceback: string; litellm_params?: any; health_check_cache_params?: any; } // Update HealthCheckDetails component to handle errors const HealthCheckDetails: React.FC<{ response: any }> = ({ response }) => { // Initialize with safe default values let errorDetails: ErrorDetails | null = null; let parsedLitellmParams: any = {}; let parsedRedisParams: any = {}; try { if (response?.error) { try { const errorMessage = typeof response.error.message === 'string' ? JSON.parse(response.error.message) : response.error.message; errorDetails = { message: errorMessage?.message || 'Unknown error', traceback: errorMessage?.traceback || 'No traceback available', litellm_params: errorMessage?.litellm_cache_params || {}, health_check_cache_params: errorMessage?.health_check_cache_params || {} }; parsedLitellmParams = deepParse(errorDetails.litellm_params) || {}; parsedRedisParams = deepParse(errorDetails.health_check_cache_params) || {}; } catch (e) { console.warn("Error parsing error details:", e); errorDetails = { message: String(response.error.message || 'Unknown error'), traceback: 'Error parsing details', litellm_params: {}, health_check_cache_params: {} }; } } else { parsedLitellmParams = deepParse(response?.litellm_cache_params) || {}; parsedRedisParams = deepParse(response?.health_check_cache_params) || {}; } } catch (e) { console.warn("Error in response parsing:", e); // Provide safe fallback values parsedLitellmParams = {}; parsedRedisParams = {}; } // Safely extract Redis details with fallbacks const redisDetails: RedisDetails = { redis_host: parsedRedisParams?.redis_client?.connection_pool?.connection_kwargs?.host || parsedRedisParams?.redis_async_client?.connection_pool?.connection_kwargs?.host || parsedRedisParams?.connection_kwargs?.host || parsedRedisParams?.host || "N/A", redis_port: parsedRedisParams?.redis_client?.connection_pool?.connection_kwargs?.port || parsedRedisParams?.redis_async_client?.connection_pool?.connection_kwargs?.port || parsedRedisParams?.connection_kwargs?.port || parsedRedisParams?.port || "N/A", redis_version: parsedRedisParams?.redis_version || "N/A", startup_nodes: (() => { try { if (parsedRedisParams?.redis_kwargs?.startup_nodes) { return JSON.stringify(parsedRedisParams.redis_kwargs.startup_nodes); } const host = parsedRedisParams?.redis_client?.connection_pool?.connection_kwargs?.host || parsedRedisParams?.redis_async_client?.connection_pool?.connection_kwargs?.host; const port = parsedRedisParams?.redis_client?.connection_pool?.connection_kwargs?.port || parsedRedisParams?.redis_async_client?.connection_pool?.connection_kwargs?.port; return host && port ? JSON.stringify([{ host, port }]) : "N/A"; } catch (e) { return "N/A"; } })(), namespace: parsedRedisParams?.namespace || "N/A", }; return (
Summary Raw Response
{(response?.status === "healthy") ? ( ) : ( )} Cache Status: {response?.status || "unhealthy"}
{/* Show error message if present */} {errorDetails && ( <> )} {/* Always show cache details, regardless of error state */} {/* Redis Details Section */} {parsedLitellmParams?.type === "redis" && ( <> )}
Error Details
Cache Details
Redis Details
                {(() => {
                  try {
                    const data = {
                      ...response,
                      litellm_cache_params: parsedLitellmParams,
                      health_check_cache_params: parsedRedisParams
                    };
                    // First parse any string JSON values
                    const prettyData = JSON.parse(JSON.stringify(data, (key, value) => {
                      if (typeof value === 'string') {
                        try {
                          return JSON.parse(value);
                        } catch {
                          return value;
                        }
                      }
                      return value;
                    }));
                    // Then stringify with proper formatting
                    return JSON.stringify(prettyData, null, 2);
                  } catch (e) {
                    return "Error formatting JSON: " + (e as Error).message;
                  }
                })()}
              
); }; export const CacheHealthTab: React.FC<{ accessToken: string | null; healthCheckResponse: any; runCachingHealthCheck: () => void; responseTimeMs?: number | null; }> = ({ accessToken, healthCheckResponse, runCachingHealthCheck, responseTimeMs }) => { const [localResponseTimeMs, setLocalResponseTimeMs] = React.useState(null); const [isLoading, setIsLoading] = React.useState(false); const handleHealthCheck = async () => { setIsLoading(true); const startTime = performance.now(); await runCachingHealthCheck(); const endTime = performance.now(); setLocalResponseTimeMs(endTime - startTime); setIsLoading(false); }; return (
{healthCheckResponse && ( )}
); };