import type { ColumnDef } from "@tanstack/react-table"; import { getCountryFromIP } from "./ip_lookup"; import moment from "moment"; import React from "react"; import { CountryCell } from "./country_cell"; import { getProviderLogoAndName } from "../provider_info_helpers"; import { Tooltip } from "antd"; import { TimeCell } from "./time_cell"; export type LogEntry = { request_id: string; api_key: string; team_id: string; model: string; api_base?: string; call_type: string; spend: number; total_tokens: number; prompt_tokens: number; completion_tokens: number; startTime: string; endTime: string; user?: string; end_user?: string; custom_llm_provider?: string; metadata?: Record; cache_hit: string; cache_key?: string; request_tags?: Record; requester_ip_address?: string; messages: string | any[] | Record; response: string | any[] | Record; }; export const columns: ColumnDef[] = [ { id: "expander", header: () => null, cell: ({ row }) => { return row.getCanExpand() ? ( ) : ( "●" ); }, }, { header: "Time", accessorKey: "startTime", cell: (info: any) => , }, { header: "Request ID", accessorKey: "request_id", cell: (info: any) => ( {String(info.getValue() || "")} ), }, { header: "Country", accessorKey: "requester_ip_address", cell: (info: any) => , }, { header: "Team", accessorKey: "metadata.user_api_key_team_alias", cell: (info: any) => {String(info.getValue() || "-")}, }, { header: "Key Name", accessorKey: "metadata.user_api_key_alias", cell: (info: any) => {String(info.getValue() || "-")}, }, { header: "Request", accessorKey: "messages", cell: (info: any) => { const messages = info.getValue(); try { const content = typeof messages === "string" ? JSON.parse(messages) : messages; let displayText = ""; if (Array.isArray(content)) { displayText = formatMessage(content[0]?.content); } else { displayText = formatMessage(content); } return {displayText}; } catch (e) { return ( {formatMessage(messages)} ); } }, }, { header: "Model", accessorKey: "model", cell: (info: any) => { const row = info.row.original; const provider = row.custom_llm_provider; const modelName = String(info.getValue() || ""); return (
{provider && ( { const target = e.target as HTMLImageElement; target.style.display = 'none'; }} /> )} {modelName}
); }, }, { header: "Tokens", accessorKey: "total_tokens", cell: (info: any) => { const row = info.row.original; return ( {String(row.total_tokens || "0")} ({String(row.prompt_tokens || "0")}+ {String(row.completion_tokens || "0")}) ); }, }, { header: "Internal User", accessorKey: "user", cell: (info: any) => {String(info.getValue() || "-")}, }, { header: "End User", accessorKey: "end_user", cell: (info: any) => {String(info.getValue() || "-")}, }, { header: "Cost", accessorKey: "spend", cell: (info: any) => ( ${Number(info.getValue() || 0).toFixed(6)} ), }, { header: "Tags", accessorKey: "request_tags", cell: (info: any) => { const tags = info.getValue(); if (!tags || Object.keys(tags).length === 0) return "-"; return (
{Object.entries(tags).map(([key, value]) => ( {key}: {String(value)} ))}
); }, }, ]; const formatMessage = (message: any): string => { if (!message) return "N/A"; if (typeof message === "string") return message; if (typeof message === "object") { // Handle the {text, type} object specifically if (message.text) return message.text; if (message.content) return message.content; return JSON.stringify(message); } return String(message); };