| 1 | import type { TraceRecord } from "@/hooks/usePromptStack"; |
| 2 | |
| 3 | interface Props { |
| 4 | trace: TraceRecord[]; |
| 5 | activeTurn: string | null; |
| 6 | onSelect: (id: string) => void; |
| 7 | } |
| 8 | |
| 9 | export function TraceTimeline({ trace, activeTurn, onSelect }: Props) { |
| 10 | if (trace.length === 0) { |
| 11 | return ( |
| 12 | <div className="flex items-center justify-center p-4 text-sm text-muted-foreground"> |
| 13 | Select a session to view traces |
| 14 | </div> |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | return ( |
| 19 | <div className="flex gap-1 overflow-x-auto p-2 border-b"> |
| 20 | {trace.map((record) => { |
| 21 | const totalChars = record.parts.reduce((sum, p) => sum + p.char_count, 0); |
| 22 | const usage = record.response.usage; |
| 23 | return ( |
| 24 | <button |
| 25 | key={record.id} |
| 26 | onClick={() => onSelect(record.id)} |
| 27 | className={`flex flex-col items-center gap-0.5 rounded-md px-3 py-2 text-xs shrink-0 transition-colors ${ |
| 28 | activeTurn === record.id |
| 29 | ? "bg-primary/10 text-primary ring-1 ring-primary/30" |
| 30 | : "hover:bg-muted" |
| 31 | }`} |
| 32 | > |
| 33 | <span className="font-mono font-medium">#{record.iteration}</span> |
| 34 | <span className="text-muted-foreground">{(totalChars / 1000).toFixed(1)}k chars</span> |
| 35 | {usage && ( |
| 36 | <span className="text-muted-foreground"> |
| 37 | {usage.prompt_tokens ?? 0}+{usage.completion_tokens ?? 0}t |
| 38 | </span> |
| 39 | )} |
| 40 | </button> |
| 41 | ); |
| 42 | })} |
| 43 | </div> |
| 44 | ); |
| 45 | } |
| 46 |