返回 JoyAI-Echo
SessionList.tsx
1 import type { PromptStackSession } from "@/hooks/usePromptStack";
2
3 interface Props {
4 sessions: PromptStackSession[];
5 activeSession: string | null;
6 onSelect: (id: string) => void;
7 }
8
9 function formatBytes(bytes: number): string {
10 if (bytes < 1024) return `${bytes}B`;
11 if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
12 return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
13 }
14
15 export function SessionList({ sessions, activeSession, onSelect }: Props) {
16 if (sessions.length === 0) {
17 return (
18 <div className="flex h-full items-center justify-center p-4 text-sm text-muted-foreground">
19 No traces yet. Enable promptStacker in config and send messages.
20 </div>
21 );
22 }
23
24 return (
25 <div className="flex flex-col gap-1 p-2">
26 {sessions.map((s) => (
27 <button
28 key={s.id}
29 onClick={() => onSelect(s.id)}
30 className={`flex flex-col items-start gap-0.5 rounded-md px-3 py-2 text-left text-xs transition-colors ${
31 activeSession === s.id
32 ? "bg-primary/10 text-primary"
33 : "hover:bg-muted"
34 }`}
35 >
36 <span className="font-medium truncate w-full">{s.last_session_key || s.id}</span>
37 <span className="text-muted-foreground">
38 {s.turn_count} turns &middot; {formatBytes(s.size_bytes)} &middot; {s.last_model}
39 </span>
40 </button>
41 ))}
42 </div>
43 );
44 }
45
45 lines Plain Text