Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | 'use client';
import { SkillEventType } from '@shared/types/data/skill-event';
import { Badge } from '@web/components/ui/badge';
import { Button } from '@web/components/ui/button';
import { Card, CardContent } from '@web/components/ui/card';
import { PageHeader } from '@web/components/ui/page-header';
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from '@web/components/ui/pagination';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@web/components/ui/select';
import { Skeleton } from '@web/components/ui/skeleton';
import { useSmartBack } from '@web/hooks/use-smart-back';
import { useAgents } from '@web/providers/agents';
import { useSkillEvents } from '@web/providers/skill-events';
import { useSkills } from '@web/providers/skills';
import {
CalendarIcon,
CheckCircle2,
FilterXIcon,
LayersIcon,
PlusIcon,
RefreshCwIcon,
SparklesIcon,
XCircle,
XIcon,
} from 'lucide-react';
import { nanoid } from 'nanoid';
import type { ReactElement } from 'react';
import { useEffect } from 'react';
const EVENT_TYPE_CONFIG = {
[SkillEventType.MODEL_ADDED]: {
label: 'Model Added',
icon: PlusIcon,
color: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200',
borderColor: 'border-green-200 dark:border-green-800',
},
[SkillEventType.MODEL_REMOVED]: {
label: 'Model Removed',
icon: XIcon,
color: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200',
borderColor: 'border-red-200 dark:border-red-800',
},
[SkillEventType.EVALUATION_ADDED]: {
label: 'Evaluation Added',
icon: PlusIcon,
color: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200',
borderColor: 'border-green-200 dark:border-green-800',
},
[SkillEventType.EVALUATION_REMOVED]: {
label: 'Evaluation Removed',
icon: XIcon,
color: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200',
borderColor: 'border-red-200 dark:border-red-800',
},
[SkillEventType.REFLECTION]: {
label: 'Reflection',
icon: RefreshCwIcon,
color: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200',
borderColor: 'border-blue-200 dark:border-blue-800',
},
[SkillEventType.CLUSTERS_UPDATED]: {
label: 'Clusters Updated',
icon: RefreshCwIcon,
color:
'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200',
borderColor: 'border-purple-200 dark:border-purple-800',
},
[SkillEventType.EVALUATION_REGENERATED]: {
label: 'Evaluation Regenerated',
icon: LayersIcon,
color:
'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200',
borderColor: 'border-purple-200 dark:border-purple-800',
},
[SkillEventType.PARTITION_RESET]: {
label: 'Partition Reset',
icon: RefreshCwIcon,
color:
'bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200',
borderColor: 'border-orange-200 dark:border-orange-800',
},
[SkillEventType.DESCRIPTION_UPDATED]: {
label: 'Description Updated',
icon: CalendarIcon,
color: 'bg-cyan-100 text-cyan-800 dark:bg-cyan-900 dark:text-cyan-200',
borderColor: 'border-cyan-200 dark:border-cyan-800',
},
[SkillEventType.PARTITIONS_RECLUSTERED]: {
label: 'Partitions Reclustered',
icon: LayersIcon,
color:
'bg-indigo-100 text-indigo-800 dark:bg-indigo-900 dark:text-indigo-200',
borderColor: 'border-indigo-200 dark:border-indigo-800',
},
[SkillEventType.OPTIMIZATION_ENABLED]: {
label: 'Optimization Enabled',
icon: CheckCircle2,
color:
'bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200',
borderColor: 'border-emerald-200 dark:border-emerald-800',
},
[SkillEventType.OPTIMIZATION_DISABLED]: {
label: 'Optimization Disabled',
icon: XCircle,
color: 'bg-slate-100 text-slate-800 dark:bg-slate-900 dark:text-slate-200',
borderColor: 'border-slate-200 dark:border-slate-800',
},
[SkillEventType.CONTEXT_GENERATED]: {
label: 'Context Generated',
icon: SparklesIcon,
color: 'bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200',
borderColor: 'border-amber-200 dark:border-amber-800',
},
};
export function SkillEventsView(): ReactElement {
const { selectedAgent } = useAgents();
const { selectedSkill } = useSkills();
const {
events,
isLoading,
setSkillId,
page,
setPage,
hasMore,
eventType,
setEventType,
scope,
setScope,
clearFilters,
} = useSkillEvents();
const goBack = useSmartBack();
useEffect(() => {
if (!selectedSkill) {
setSkillId(null);
return;
}
setSkillId(selectedSkill.id);
setPage(1); // Reset to page 1 when skill changes
clearFilters(); // Clear filters when skill changes
}, [selectedSkill, setSkillId, setPage, clearFilters]);
// Early return if no skill or agent selected
if (!selectedSkill || !selectedAgent) {
return (
<>
<PageHeader
title="Events"
description="No skill selected. Please select a skill to view its events."
/>
<div className="p-6">
<div className="text-center text-muted-foreground">
No skill selected. Please select a skill to view its events.
</div>
</div>
</>
);
}
return (
<>
<PageHeader
title={`Events for ${selectedSkill.name}`}
description="Track important changes and updates to this skill"
showBackButton={true}
onBack={goBack}
/>
<div className="p-6">
{/* Filters */}
<div className="mb-6 flex flex-wrap gap-3">
<Select
value={eventType || 'all'}
onValueChange={(value) => {
setEventType(value === 'all' ? null : (value as SkillEventType));
setPage(1);
}}
>
<SelectTrigger className="w-[200px]">
<SelectValue placeholder="Event Type" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All Event Types</SelectItem>
<SelectItem value={SkillEventType.MODEL_ADDED}>
Model Added
</SelectItem>
<SelectItem value={SkillEventType.MODEL_REMOVED}>
Model Removed
</SelectItem>
<SelectItem value={SkillEventType.EVALUATION_ADDED}>
Evaluation Added
</SelectItem>
<SelectItem value={SkillEventType.EVALUATION_REMOVED}>
Evaluation Removed
</SelectItem>
<SelectItem value={SkillEventType.EVALUATION_REGENERATED}>
Evaluation Regenerated
</SelectItem>
<SelectItem value={SkillEventType.REFLECTION}>
Reflection
</SelectItem>
<SelectItem value={SkillEventType.PARTITION_RESET}>
Reset
</SelectItem>
<SelectItem value={SkillEventType.DESCRIPTION_UPDATED}>
Description Updated
</SelectItem>
<SelectItem value={SkillEventType.PARTITIONS_RECLUSTERED}>
Partitions Reclustered
</SelectItem>
<SelectItem value={SkillEventType.OPTIMIZATION_ENABLED}>
Optimization Enabled
</SelectItem>
<SelectItem value={SkillEventType.OPTIMIZATION_DISABLED}>
Optimization Disabled
</SelectItem>
<SelectItem value={SkillEventType.CLUSTERS_UPDATED}>
Clusters Updated
</SelectItem>
<SelectItem value={SkillEventType.CONTEXT_GENERATED}>
Context Generated
</SelectItem>
</SelectContent>
</Select>
<Select
value={scope}
onValueChange={(value) => {
setScope(value as 'all' | 'skill-wide' | 'cluster-specific');
setPage(1);
}}
>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Scope" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All Events</SelectItem>
<SelectItem value="skill-wide">Skill-wide</SelectItem>
<SelectItem value="cluster-specific">Cluster-specific</SelectItem>
</SelectContent>
</Select>
{(eventType || scope !== 'all') && (
<Button
variant="outline"
size="sm"
onClick={() => {
clearFilters();
}}
>
<FilterXIcon className="h-4 w-4 mr-2" />
Clear Filters
</Button>
)}
</div>
{isLoading ? (
<div className="space-y-2">
{Array.from({ length: 5 }).map(() => (
<Card key={nanoid()}>
<CardContent className="py-3">
<div className="flex gap-3 items-center">
<Skeleton className="h-8 w-8 rounded-md" />
<div className="flex-1 space-y-1">
<Skeleton className="h-3 w-32" />
<Skeleton className="h-3 w-24" />
</div>
</div>
</CardContent>
</Card>
))}
</div>
) : events.length === 0 ? (
<Card>
<CardContent className="pt-16 pb-16 text-center">
<CalendarIcon className="h-16 w-16 text-muted-foreground mx-auto mb-4" />
<h3 className="text-lg font-semibold mb-2">No events yet</h3>
<p className="text-muted-foreground">
Events will appear here as you make changes to this skill
</p>
</CardContent>
</Card>
) : (
<>
<div className="space-y-2">
{events.map((event) => {
const config = EVENT_TYPE_CONFIG[event.event_type];
const Icon = config.icon;
const eventTime = new Date(event.created_at);
const timeString = eventTime.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
return (
<Card
key={event.id}
className={`border-l-4 ${config.borderColor}`}
>
<CardContent className="py-3">
<div className="flex gap-3 items-center">
<div className={`p-2 rounded-md ${config.color}`}>
<Icon className="w-4 h-4" />
</div>
<div className="flex-1 min-w-0 flex items-center justify-between gap-4">
<div className="flex items-center gap-2 flex-wrap">
<Badge
variant="outline"
className="text-xs font-medium"
>
{config.label}
</Badge>
{event.cluster_id ? (
<Badge variant="secondary" className="text-xs">
Cluster-specific
</Badge>
) : (
<Badge variant="secondary" className="text-xs">
Skill-wide
</Badge>
)}
{event.metadata.model_name ? (
<span className="text-sm font-medium">
{String(event.metadata.model_name)}
</span>
) : null}
</div>
<div className="flex items-center gap-1.5 text-xs text-muted-foreground whitespace-nowrap">
<CalendarIcon className="w-3 h-3" />
<span>{timeString}</span>
</div>
</div>
</div>
</CardContent>
</Card>
);
})}
</div>
{/* Pagination */}
{(page > 1 || hasMore) && (
<div className="mt-6">
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious
onClick={() => setPage(Math.max(1, page - 1))}
disabled={page === 1}
/>
</PaginationItem>
<PaginationItem>
<PaginationLink isActive>{page}</PaginationLink>
</PaginationItem>
{hasMore && (
<PaginationItem>
<PaginationNext
onClick={() => setPage(page + 1)}
disabled={!hasMore}
/>
</PaginationItem>
)}
</PaginationContent>
</Pagination>
</div>
)}
</>
)}
</div>
</>
);
}
|