| 1 | import { LLMInteraction } from "../../hooks/useLLMLog"; |
| 2 | import useLLMSummary from "../../hooks/useLLMSummary"; |
| 3 | import StatusIcon from "./StatusIcon"; |
| 4 | |
| 5 | export interface ListItemProps { |
| 6 | interactionId: string; |
| 7 | interaction: LLMInteraction; |
| 8 | selected: boolean; |
| 9 | onClickInteraction: (interactionId: string) => void; |
| 10 | } |
| 11 | |
| 12 | function formatTimestamp(timestamp: number) { |
| 13 | const date = new Date(timestamp); |
| 14 | |
| 15 | const hours = date.getHours().toString().padStart(2, "0"); |
| 16 | const minutes = date.getMinutes().toString().padStart(2, "0"); |
| 17 | const seconds = date.getSeconds(); |
| 18 | const milliseconds = date.getMilliseconds(); |
| 19 | |
| 20 | // Format seconds with one decimal place |
| 21 | const secondsFormatted = `${seconds}.${Math.floor(milliseconds / 100)}`; |
| 22 | |
| 23 | return `${hours}:${minutes}:${secondsFormatted.padStart(4, "0")}`; |
| 24 | } |
| 25 | |
| 26 | export default function ListItem({ |
| 27 | interactionId, |
| 28 | interaction, |
| 29 | onClickInteraction, |
| 30 | selected, |
| 31 | }: ListItemProps) { |
| 32 | const summary = useLLMSummary(interaction); |
| 33 | |
| 34 | return ( |
| 35 | <li |
| 36 | className={ |
| 37 | "w-full cursor-pointer pb-[3px] pl-[4px] pr-[4px] pt-[3px] " + |
| 38 | (selected |
| 39 | ? "bg-[color:var(--vscode-list-inactiveSelectionBackground)]" + |
| 40 | " text-[color:var(--vscode-list-inctiveSelectionForeground)]" + |
| 41 | " group-focus-within:bg-[color:var(--vscode-list-activeSelectionBackground)]" + |
| 42 | " group-focus-within:text-[color:var(--vscode-list-activeSelectionForeground)]" |
| 43 | : "hover:bg-[color:var(--vscode-list-inactiveSelectionBackground)]") |
| 44 | } |
| 45 | key={interactionId} |
| 46 | onClick={() => onClickInteraction(interactionId)} |
| 47 | > |
| 48 | <StatusIcon interaction={interaction}></StatusIcon>{" "} |
| 49 | <span className="inline-block w-[70px]"> |
| 50 | {interaction.start ? formatTimestamp(interaction.start.timestamp) : ""} |
| 51 | </span> |
| 52 | <span className="inline-block">{summary.type}</span> |
| 53 | </li> |
| 54 | ); |
| 55 | } |