1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
import type { HistoryEvent } from "../../lib/api";
interface TimelineEventCardProps {
event: HistoryEvent;
isSelected: boolean;
onClick: () => void;
}
// Get icon and color based on event type
function getEventStyle(eventType: string, eventSubtype: string | null) {
const type = eventType.toLowerCase();
const subtype = eventSubtype?.toLowerCase();
if (type === "task") {
if (subtype === "created") return { icon: "+", color: "text-[#9bc3ff]" };
if (subtype === "started") return { icon: "\u25B6", color: "text-green-400" };
if (subtype === "completed") return { icon: "\u2713", color: "text-emerald-400" };
if (subtype === "failed") return { icon: "\u2717", color: "text-red-400" };
if (subtype === "stopped") return { icon: "\u25A0", color: "text-yellow-400" };
return { icon: "\u2022", color: "text-[#9bc3ff]" };
}
if (type === "checkpoint") {
return { icon: "\u2691", color: "text-purple-400" };
}
if (type === "phase") {
return { icon: "\u21B3", color: "text-cyan-400" };
}
if (type === "chat") {
return { icon: "\u2709", color: "text-[#75aafc]" };
}
if (type === "contract") {
return { icon: "\u2606", color: "text-[#9bc3ff]" };
}
if (type === "file") {
return { icon: "\u2630", color: "text-[#7788aa]" };
}
return { icon: "\u2022", color: "text-[#7788aa]" };
}
// Format relative time
function formatRelativeTime(dateStr: string): string {
const date = new Date(dateStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffSec = Math.floor(diffMs / 1000);
const diffMin = Math.floor(diffSec / 60);
const diffHour = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHour / 24);
if (diffSec < 60) return "just now";
if (diffMin < 60) return `${diffMin}m ago`;
if (diffHour < 24) return `${diffHour}h ago`;
if (diffDay < 7) return `${diffDay}d ago`;
return date.toLocaleDateString();
}
// Extract a preview from event data
function getEventPreview(event: HistoryEvent): string {
const data = event.eventData as Record<string, unknown>;
// Task events
if (data.taskName) return String(data.taskName);
if (data.name) return String(data.name);
// Chat events
if (data.message) {
const msg = String(data.message);
return msg.length > 50 ? msg.slice(0, 50) + "..." : msg;
}
// Checkpoint events
if (data.checkpointMessage) return String(data.checkpointMessage);
if (data.commitSha) return `Commit ${String(data.commitSha).slice(0, 7)}`;
// Phase events
if (data.phase) return `Phase: ${data.phase}`;
// Contract events
if (data.contractName) return String(data.contractName);
return "";
}
export function TimelineEventCard({ event, isSelected, onClick }: TimelineEventCardProps) {
const { icon, color } = getEventStyle(event.eventType, event.eventSubtype);
const preview = getEventPreview(event);
return (
<button
onClick={onClick}
className={`w-full text-left p-3 transition-colors ${
isSelected
? "bg-[rgba(63,111,179,0.2)] border-l-2 border-[#3f6fb3]"
: "hover:bg-[rgba(117,170,252,0.05)] border-l-2 border-transparent"
}`}
>
<div className="flex items-start gap-3">
{/* Icon */}
<div className={`font-mono text-sm ${color}`}>{icon}</div>
{/* Content */}
<div className="flex-1 min-w-0">
<div className="flex items-center justify-between gap-2">
<div className="font-mono text-xs text-[#9bc3ff] uppercase truncate">
{event.eventType}
{event.eventSubtype && (
<span className="text-[#7788aa]"> / {event.eventSubtype}</span>
)}
</div>
<div className="font-mono text-[10px] text-[#556677] shrink-0">
{formatRelativeTime(event.createdAt)}
</div>
</div>
{preview && (
<div className="font-mono text-[10px] text-[#7788aa] mt-1 truncate">
{preview}
</div>
)}
{event.phase && (
<div className="mt-1">
<span className="font-mono text-[9px] text-[#75aafc] uppercase px-1.5 py-0.5 border border-[rgba(117,170,252,0.25)]">
{event.phase}
</span>
</div>
)}
</div>
</div>
</button>
);
}
|