import * as React from 'react' import { cn } from '../utils/cn' import { LogsListProps, LogEntry } from '../types/logs.types' import { LogSeverityDot } from './log-severity-dot' import { ToolIcon } from './tool-icon' const formatTimestamp = (timestamp: string | Date): string => { const date = timestamp instanceof Date ? timestamp : new Date(timestamp) // UTC getters so the timestamp is identical on server (UTC) and client // (local) — otherwise React #418 hydration mismatch. const year = date.getUTCFullYear() const month = String(date.getUTCMonth() + 1).padStart(2, '0') const day = String(date.getUTCDate()).padStart(2, '0') const hours = String(date.getUTCHours()).padStart(2, '0') const minutes = String(date.getUTCMinutes()).padStart(2, '0') return `${year}/${month}/${day},${hours}:${minutes}` } const LogCard: React.FC<{ log: LogEntry isLast: boolean showConnector: boolean onClick?: () => void }> = ({ log, isLast, showConnector, onClick }) => { return (
{ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() onClick?.() } }} >

{log.title}

{formatTimestamp(log.timestamp)}

{log.toolType && ( )}
{showConnector && !isLast && ( ) } export const LogsList = React.forwardRef< HTMLDivElement, LogsListProps >(({ logs, maxHeight = '400px', showConnector = true, onLogClick, loading = false, emptyMessage = 'No logs to display', className }, ref) => { const containerRef = React.useRef(null) const isFullHeight = maxHeight === '100%' const getContainerStyles = () => { if (isFullHeight) return undefined return { maxHeight, minHeight: '200px' } } const getContainerClasses = () => { if (isFullHeight) return 'h-full' return '' } if (loading) { return (
Loading logs...
) } if (logs.length === 0) { return (
{emptyMessage}
) } return (
{logs.map((log, index) => ( onLogClick?.(log)} /> ))}
) }) LogsList.displayName = 'LogsList'