import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Status, StatusBarColors, Statuses } from "@/lib/constants/logs"; import type { MCPToolLogEntry } from "@/lib/types/logs"; import { ColumnDef } from "@tanstack/react-table"; import { ArrowUpDown, Trash2 } from "lucide-react"; import { format, isValid } from "date-fns"; // Helper function to validate status and return a safe Status value const getValidatedStatus = (status: string): Status => { // Check if status is a valid Status by checking against Statuses array if (Statuses.includes(status as Status)) { return status as Status; } // Fallback to "processing" for unknown statuses return "processing"; }; export const createMCPColumns = ( handleDelete: (log: MCPToolLogEntry) => Promise, hasDeleteAccess: boolean, ): ColumnDef[] => [ { accessorKey: "status", header: "", size: 8, maxSize: 8, cell: ({ row }) => { const status = getValidatedStatus(row.original.status); return
; }, }, { accessorKey: "timestamp", header: ({ column }) => ( ), size: 230, cell: ({ row }) => { const timestamp = row.original.timestamp; const date = new Date(timestamp); return
{isValid(date) ? format(date, "yyyy-MM-dd hh:mm:ss aa (XXX)") : "Invalid date"}
; }, }, { accessorKey: "tool_name", header: "Tool Name", size: 300, cell: ({ row }) => { const toolName = row.getValue("tool_name") as string; return {toolName}; }, }, { accessorKey: "server_label", header: "Server", size: 150, cell: ({ row }) => { const serverLabel = row.getValue("server_label") as string; return serverLabel ? ( {serverLabel} ) : ( - ); }, }, { accessorKey: "latency", header: ({ column }) => ( ), size: 120, cell: ({ row }) => { const latency = row.original.latency; return (
{latency === undefined || latency === null ? "N/A" : `${latency.toLocaleString()}ms`}
); }, }, { accessorKey: "cost", header: "Cost", size: 120, cell: ({ row }) => { const cost = row.original.cost; const isValidNumber = typeof cost === "number" && Number.isFinite(cost); return
{isValidNumber ? `${cost.toFixed(4)}` : "N/A"}
; }, }, { id: "actions", size: 72, cell: ({ row }) => { const log = row.original; return ( ); }, }, ];