@milabench/bujang 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +108 -2
  2. package/dist/api.d.ts +151 -0
  3. package/dist/components/AutocompleteInput.d.ts +15 -0
  4. package/dist/components/MonacoEditor.d.ts +11 -0
  5. package/dist/components/toaster.d.ts +2 -0
  6. package/dist/components/tooltip.d.ts +11 -0
  7. package/dist/constants.d.ts +3 -0
  8. package/dist/context.d.ts +44 -0
  9. package/dist/hooks/useColorMode.d.ts +4 -0
  10. package/dist/hooks/usePageTitle.d.ts +2 -0
  11. package/dist/index.d.ts +26 -0
  12. package/dist/index.js +5036 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/paths.d.ts +26 -0
  15. package/dist/routes.d.ts +22 -0
  16. package/dist/theme.css +72 -0
  17. package/dist/toast.d.ts +18 -0
  18. package/dist/types.d.ts +474 -0
  19. package/dist/views/AgentActivityView.d.ts +8 -0
  20. package/dist/views/JobDetails.d.ts +2 -0
  21. package/dist/views/JobLogs.d.ts +4 -0
  22. package/dist/views/JobSubmit.d.ts +22 -0
  23. package/dist/views/JobSubmitView.d.ts +2 -0
  24. package/dist/views/JobsView.d.ts +4 -0
  25. package/dist/views/LogDisplay.d.ts +11 -0
  26. package/dist/views/PipelinesView.d.ts +2 -0
  27. package/dist/views/ScheduledJobsView.d.ts +2 -0
  28. package/package.json +70 -4
  29. package/src/api.ts +602 -0
  30. package/src/components/AutocompleteInput.tsx +253 -0
  31. package/src/components/MonacoEditor.tsx +163 -0
  32. package/src/components/toaster.tsx +38 -0
  33. package/src/components/tooltip.tsx +52 -0
  34. package/src/constants.ts +3 -0
  35. package/src/context.tsx +106 -0
  36. package/src/hooks/useColorMode.ts +31 -0
  37. package/src/hooks/usePageTitle.ts +21 -0
  38. package/src/index.ts +33 -0
  39. package/src/paths.ts +71 -0
  40. package/src/routes.tsx +55 -0
  41. package/src/theme.css +72 -0
  42. package/src/toast.ts +35 -0
  43. package/src/types.ts +542 -0
  44. package/src/views/AgentActivityView.tsx +262 -0
  45. package/src/views/JobDetails.tsx +675 -0
  46. package/src/views/JobLogs.tsx +987 -0
  47. package/src/views/JobSubmit.tsx +1272 -0
  48. package/src/views/JobSubmitView.tsx +69 -0
  49. package/src/views/JobsView.tsx +736 -0
  50. package/src/views/LogDisplay.tsx +171 -0
  51. package/src/views/PipelinesView.tsx +1318 -0
  52. package/src/views/ScheduledJobsView.tsx +735 -0
@@ -0,0 +1,736 @@
1
+ import React from 'react';
2
+ import { Link, useNavigate } from 'react-router-dom';
3
+ import { useBujangPaths } from '../context';
4
+ import {
5
+ Box,
6
+ Heading,
7
+ Text,
8
+ VStack,
9
+ HStack,
10
+ Button,
11
+ Badge,
12
+ Table,
13
+ Card,
14
+ Spinner,
15
+ Alert,
16
+ IconButton,
17
+ } from '@chakra-ui/react';
18
+ import { toaster } from '../toast';
19
+ import { Tooltip } from '../components/tooltip';
20
+ import {
21
+ LuPlus,
22
+ LuEye,
23
+ LuTrash2,
24
+ LuRefreshCw,
25
+ LuInfo,
26
+ LuCircleCheck,
27
+ LuTriangleAlert,
28
+ LuClock,
29
+ } from 'react-icons/lu';
30
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
31
+ import {
32
+ getSlurmJobs,
33
+ getSlurmPersistedJobs,
34
+ cancelSlurmJob,
35
+ rerunSlurmJob,
36
+ getSlurmClusterStatus,
37
+ } from '../api';
38
+ import type { SlurmJob, PersitedJobInfo, ApiError } from '../types';
39
+ import { usePageTitle } from '../hooks/usePageTitle';
40
+ import { AgentBadge } from './AgentActivityView';
41
+ import { NO_JOB_ID, NO_JOB_STATE, NO_JR_JOB_ID } from '../constants';
42
+
43
+ type JobsViewProps = Record<string, never>;
44
+
45
+ const getStatusColor = (status: string) => {
46
+ switch (status?.toLowerCase()) {
47
+ case 'running':
48
+ case 'r':
49
+ return 'green';
50
+ case 'pending':
51
+ case 'pd':
52
+ return 'yellow';
53
+ case 'completed':
54
+ case 'cd':
55
+ return 'blue';
56
+ case 'failed':
57
+ case 'f':
58
+ return 'red';
59
+ case 'cancelled':
60
+ case 'ca':
61
+ return 'gray';
62
+ default:
63
+ return 'gray';
64
+ }
65
+ };
66
+
67
+ const getStatusIcon = (status: string) => {
68
+ switch (status?.toLowerCase()) {
69
+ case 'running':
70
+ case 'r':
71
+ return <LuCircleCheck color="var(--color-status-running)" />;
72
+ case 'pending':
73
+ case 'pd':
74
+ return <LuClock color="var(--color-status-pending)" />;
75
+ case 'completed':
76
+ case 'cd':
77
+ return <LuCircleCheck color="var(--color-status-completed)" />;
78
+ case 'failed':
79
+ case 'f':
80
+ return <LuTriangleAlert color="var(--color-status-failed)" />;
81
+ default:
82
+ return <LuInfo color="var(--color-status-cancelled)" />;
83
+ }
84
+ };
85
+
86
+ export const JobsView: React.FC<JobsViewProps> = () => {
87
+ usePageTitle('Jobs');
88
+
89
+ const queryClient = useQueryClient();
90
+ const navigate = useNavigate();
91
+ const paths = useBujangPaths();
92
+
93
+ const freshnessGreen = getComputedStyle(document.documentElement).getPropertyValue('--color-freshness-good').trim() || '#48bb78';
94
+ const freshnessBrown = getComputedStyle(document.documentElement).getPropertyValue('--color-freshness-stale').trim() || '#7b341e';
95
+
96
+ // Helper function to convert hex to RGB
97
+ const hexToRgb = (hex: string): [number, number, number] => {
98
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
99
+ return result
100
+ ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)]
101
+ : [72, 187, 120]; // fallback to green
102
+ };
103
+
104
+
105
+ // Queries
106
+ const { data: activeJobsData, isLoading: activeJobsLoading, error: activeJobsError } = useQuery({
107
+ queryKey: ['slurm-jobs'],
108
+ queryFn: getSlurmJobs,
109
+ refetchOnWindowFocus: false,
110
+ staleTime: 30000, // Consider data fresh for 30 seconds
111
+ });
112
+
113
+ const { data: persistedJobsData, isLoading: persistedJobsLoading, error: persistedJobsError } = useQuery<PersitedJobInfo[]>({
114
+ queryKey: ['slurm-persisted-jobs'],
115
+ queryFn: getSlurmPersistedJobs,
116
+ refetchOnWindowFocus: false,
117
+ staleTime: 30000, // Consider data fresh for 30 seconds
118
+ });
119
+
120
+ const { data: clusterStatus, isLoading: clusterStatusLoading } = useQuery({
121
+ queryKey: ['slurm-cluster-status'],
122
+ queryFn: getSlurmClusterStatus,
123
+ refetchOnWindowFocus: false,
124
+ staleTime: 30000, // Consider data fresh for 30 seconds
125
+ refetchInterval: 60000, // Refetch every minute
126
+ retry: false, // Don't retry on error to avoid excessive requests when cluster is down
127
+ });
128
+
129
+ // Separate active jobs and persisted jobs
130
+ const activeJobs = activeJobsData || [];
131
+ const persistedJobs = persistedJobsData || [];
132
+
133
+
134
+
135
+ const cancelJobMutation = useMutation({
136
+ mutationFn: cancelSlurmJob,
137
+ onSuccess: (data) => {
138
+ toaster.create({
139
+ title: 'Job Cancelled',
140
+ description: data.message || 'Job cancelled successfully',
141
+ type: 'success',
142
+ duration: 5000,
143
+ });
144
+ queryClient.invalidateQueries({ queryKey: ['slurm-jobs'] });
145
+ queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
146
+ },
147
+ onError: (error: ApiError) => {
148
+ toaster.create({
149
+ title: 'Cancellation Failed',
150
+ description: error.message || 'Failed to cancel job',
151
+ type: 'error',
152
+ duration: 5000,
153
+ });
154
+ },
155
+ });
156
+
157
+ const rerunJobMutation = useMutation({
158
+ mutationFn: rerunSlurmJob,
159
+ onSuccess: (data) => {
160
+ toaster.create({
161
+ title: 'Job Rerun',
162
+ description: data.message || 'Job rerun successfully',
163
+ type: 'success',
164
+ duration: 5000,
165
+ });
166
+ queryClient.invalidateQueries({ queryKey: ['slurm-jobs'] });
167
+ queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
168
+ },
169
+ onError: (error: ApiError) => {
170
+ toaster.create({
171
+ title: 'Error Rerunning Job',
172
+ description: error.message || 'Failed to rerun job',
173
+ type: 'error',
174
+ duration: 5000,
175
+ });
176
+ },
177
+ });
178
+
179
+
180
+
181
+ const handleCancelJob = (jobId: string) => {
182
+ if (window.confirm(`Are you sure you want to cancel job ${jobId}?`)) {
183
+ cancelJobMutation.mutate(jobId);
184
+ }
185
+ };
186
+
187
+ const handleRerunJob = (jrJobId: string) => {
188
+ if (window.confirm(`Are you sure you want to rerun job ${jrJobId}?`)) {
189
+ rerunJobMutation.mutate(jrJobId);
190
+ }
191
+ };
192
+
193
+
194
+
195
+ return (
196
+ <Box p={6} h="100%" bg="var(--color-bg-page)">
197
+ <VStack align="stretch" gap={6} h="100%">
198
+
199
+ {/* Header Section */}
200
+ <Box>
201
+ <HStack justify="space-between" align="center" mb={4}>
202
+ <HStack gap={3} align="center">
203
+ <Heading size="xl" fontWeight="bold" color="var(--color-text)">
204
+ Jobs
205
+ </Heading>
206
+ {clusterStatusLoading ? (
207
+ <Tooltip
208
+ positioning={{ placement: 'bottom', offset: { mainAxis: 8 } }}
209
+ content="Checking cluster status..."
210
+ >
211
+ <Spinner size="sm" />
212
+ </Tooltip>
213
+ ) : clusterStatus ? (
214
+ <Tooltip
215
+ positioning={{ placement: 'bottom', offset: { mainAxis: 8 } }}
216
+ content={
217
+ clusterStatus.status === 'offline' && clusterStatus.reason
218
+ ? `${clusterStatus.reason}`
219
+ : clusterStatus.status === 'online'
220
+ ? 'Cluster is online and ready to accept jobs'
221
+ : 'Cluster status'
222
+ }
223
+ >
224
+ <Badge
225
+ colorScheme={clusterStatus.status === 'online' ? 'green' : 'red'}
226
+ variant="solid"
227
+ fontSize="sm"
228
+ px={4}
229
+ py={1.5}
230
+ borderRadius="full"
231
+ cursor="help"
232
+ fontWeight="medium"
233
+ >
234
+ {clusterStatus.status === 'online' ? '✓ Online' : '✗ Offline'}
235
+ </Badge>
236
+ </Tooltip>
237
+ ) : (
238
+ <Tooltip
239
+ positioning={{ placement: 'bottom', offset: { mainAxis: 8 } }}
240
+ content="Unable to determine cluster status"
241
+ >
242
+ <Badge
243
+ colorScheme="gray"
244
+ variant="solid"
245
+ fontSize="sm"
246
+ px={4}
247
+ py={1.5}
248
+ borderRadius="full"
249
+ cursor="help"
250
+ fontWeight="medium"
251
+ >
252
+ Status Unknown
253
+ </Badge>
254
+ </Tooltip>
255
+ )}
256
+ </HStack>
257
+
258
+ <HStack gap={2}>
259
+ <Button
260
+ onClick={() => navigate(paths.submitJob())}
261
+ size="sm"
262
+ fontWeight="medium"
263
+ bg="var(--color-primary)"
264
+ color="var(--color-primary-text)"
265
+ _hover={{ bg: 'var(--color-primary-hover)' }}
266
+ >
267
+ <LuPlus style={{ marginRight: '4px', fontSize: '16px' }} />
268
+ Submit New Job
269
+ </Button>
270
+
271
+ <Button
272
+ variant="outline"
273
+ onClick={() => {
274
+ queryClient.invalidateQueries({ queryKey: ['slurm-jobs'] });
275
+ queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
276
+ queryClient.invalidateQueries({ queryKey: ['slurm-cluster-status'] });
277
+ }}
278
+ loading={activeJobsLoading || persistedJobsLoading || clusterStatusLoading}
279
+ size="sm"
280
+ fontWeight="medium"
281
+ >
282
+ <LuRefreshCw style={{ marginRight: '4px', fontSize: '16px' }} />
283
+ Refresh
284
+ </Button>
285
+ </HStack>
286
+ </HStack>
287
+ </Box>
288
+
289
+ {/* Active Jobs Table */}
290
+ <Card.Root
291
+ bg="var(--color-bg-card)"
292
+ borderWidth="1px"
293
+ borderColor="var(--color-border)"
294
+ borderRadius="lg"
295
+ boxShadow="sm"
296
+ overflow="hidden"
297
+ padding="10px"
298
+ >
299
+ <Card.Header
300
+ bg="var(--color-bg-header)"
301
+ borderBottomWidth="1px"
302
+ borderBottomColor="var(--color-border)"
303
+ py={4}
304
+ px={6}
305
+ >
306
+ <HStack justify="space-between" align="center">
307
+ <Heading size="md" fontWeight="semibold" color="var(--color-text)">
308
+ Active Jobs
309
+ </Heading>
310
+ <Badge
311
+ colorScheme="blue"
312
+ variant="subtle"
313
+ fontSize="xs"
314
+ px={2}
315
+ py={1}
316
+ >
317
+ {activeJobs.length} {activeJobs.length === 1 ? 'job' : 'jobs'}
318
+ </Badge>
319
+ </HStack>
320
+ </Card.Header>
321
+ <Card.Body p={0}>
322
+ {(activeJobsError) ? (
323
+ <Alert.Root status="error">
324
+ <Alert.Indicator />
325
+ <Alert.Content>
326
+ <Alert.Title>Error loading active jobs!</Alert.Title>
327
+ <Alert.Description>
328
+ {activeJobsError?.message || 'Failed to load active jobs'}
329
+ </Alert.Description>
330
+ </Alert.Content>
331
+ </Alert.Root>
332
+ ) : (activeJobsLoading) ? (
333
+ <Box textAlign="center" py={12}>
334
+ <Spinner size="lg" color="var(--color-primary)" />
335
+ <Text mt={4} color="var(--color-text-muted)" fontSize="sm">
336
+ Loading active jobs...
337
+ </Text>
338
+ </Box>
339
+ ) : (
340
+ <Box overflowX="auto">
341
+ {activeJobs.length === 0 ? (
342
+ <Box textAlign="center" py={12}>
343
+ <Text color="var(--color-text-muted)" fontSize="md">
344
+ No active jobs found
345
+ </Text>
346
+ <Text color="var(--color-text-muted)" fontSize="sm" mt={2}>
347
+ Submit a new job to get started
348
+ </Text>
349
+ </Box>
350
+ ) : (
351
+ <Table.ScrollArea maxH="35vh" overflowY="auto">
352
+ <Table.Root variant="line" size="md" stickyHeader>
353
+ <Table.Header bg="var(--color-bg-header)">
354
+ <Table.Row>
355
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} pl={6} pr={4} fontSize="sm">Job ID</Table.ColumnHeader>
356
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">JR Job ID</Table.ColumnHeader>
357
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Name</Table.ColumnHeader>
358
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Status</Table.ColumnHeader>
359
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Cluster</Table.ColumnHeader>
360
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Partition</Table.ColumnHeader>
361
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">User</Table.ColumnHeader>
362
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Time</Table.ColumnHeader>
363
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Actions</Table.ColumnHeader>
364
+ </Table.Row>
365
+ </Table.Header>
366
+ <Table.Body>
367
+ {activeJobs.map((job: SlurmJob, index: number) => (
368
+ <Table.Row
369
+ key={job.job_id}
370
+ _hover={{ bg: 'var(--color-bg-hover)' }}
371
+ bg={index % 2 === 0 ? 'transparent' : 'var(--color-bg-stripe)'}
372
+ >
373
+ <Table.Cell pl={6} pr={4}>
374
+ <Text fontWeight="semibold" color="var(--color-text)">
375
+ {job.job_id}
376
+ </Text>
377
+ </Table.Cell>
378
+ <Table.Cell>
379
+ <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">
380
+ {job.jr_job_id}
381
+ </Text>
382
+ </Table.Cell>
383
+ <Table.Cell>
384
+ <Text color="var(--color-text)">{job.name || 'N/A'}<AgentBadge tag={job.agent} /></Text>
385
+ </Table.Cell>
386
+ <Table.Cell>
387
+ <HStack gap={2}>
388
+ {getStatusIcon(job.job_state?.[0] || '')}
389
+ <Badge colorScheme={getStatusColor(job.job_state?.[0] || '')}>
390
+ {job.job_state?.[0] || NO_JOB_STATE}
391
+ </Badge>
392
+ </HStack>
393
+ </Table.Cell>
394
+ <Table.Cell>
395
+ <Text color="var(--color-text)" fontSize="sm">mila</Text>
396
+ </Table.Cell>
397
+ <Table.Cell>
398
+ <Text color="var(--color-text)">{job.partition || 'N/A'}</Text>
399
+ </Table.Cell>
400
+ <Table.Cell>
401
+ <Text color="var(--color-text)">{job.user_name || 'N/A'}</Text>
402
+ </Table.Cell>
403
+ <Table.Cell>
404
+ <Text color="var(--color-text)">
405
+ {typeof job.time_limit === 'string'
406
+ ? job.time_limit
407
+ : job.time_limit?.number
408
+ ? `${job.time_limit.number}min`
409
+ : 'N/A'
410
+ }
411
+ </Text>
412
+ </Table.Cell>
413
+ <Table.Cell>
414
+ <HStack gap={2}>
415
+ <Tooltip
416
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
417
+ content="View Details"
418
+ >
419
+ <Link
420
+ to={paths.jobDetails(job.job_id || NO_JOB_ID, typeof job.jr_job_id === 'string' ? job.jr_job_id : NO_JR_JOB_ID)}
421
+ >
422
+ <IconButton
423
+ aria-label="View job details"
424
+ size="md"
425
+ variant="ghost"
426
+ >
427
+ <LuInfo />
428
+ </IconButton>
429
+ </Link>
430
+ </Tooltip>
431
+ <Tooltip
432
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
433
+ content="View Logs"
434
+ >
435
+ <Link
436
+ to={paths.jobLogs(job.job_id || NO_JOB_ID, job.jr_job_id || NO_JR_JOB_ID)}
437
+ >
438
+ <IconButton
439
+ aria-label="View job logs"
440
+ size="md"
441
+ variant="ghost"
442
+ >
443
+ <LuEye />
444
+ </IconButton>
445
+ </Link>
446
+ </Tooltip>
447
+ {(job.job_state?.[0]?.toLowerCase() === 'running' ||
448
+ job.job_state?.[0]?.toLowerCase() === 'pending') && (
449
+ <Tooltip
450
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
451
+ content="Cancel Job"
452
+ >
453
+ <IconButton
454
+ aria-label="Cancel job"
455
+ size="md"
456
+ variant="ghost"
457
+ colorScheme="red"
458
+ onClick={() => job.job_id && handleCancelJob(job.job_id)}
459
+ >
460
+ <LuTrash2 />
461
+ </IconButton>
462
+ </Tooltip>
463
+ )}
464
+ </HStack>
465
+ </Table.Cell>
466
+ </Table.Row>
467
+ ))}
468
+ </Table.Body>
469
+ </Table.Root>
470
+ </Table.ScrollArea>
471
+ )}
472
+ </Box>
473
+ )}
474
+ </Card.Body>
475
+ </Card.Root>
476
+
477
+ {/* Persisted Jobs Table */}
478
+ <Card.Root
479
+ bg="var(--color-bg-card)"
480
+ borderWidth="1px"
481
+ borderColor="var(--color-border)"
482
+ borderRadius="lg"
483
+ boxShadow="sm"
484
+ overflow="hidden"
485
+ flex="1"
486
+ minH="300px"
487
+ display="flex"
488
+ flexDirection="column"
489
+ padding="10px"
490
+ >
491
+ <Card.Header
492
+ bg="var(--color-bg-header)"
493
+ borderBottomWidth="1px"
494
+ borderBottomColor="var(--color-border)"
495
+ py={4}
496
+ px={6}
497
+ >
498
+ <HStack justify="space-between" align="center">
499
+ <Heading size="md" fontWeight="semibold" color="var(--color-text)">
500
+ Persisted Jobs
501
+ </Heading>
502
+ <Badge
503
+ colorScheme="purple"
504
+ variant="subtle"
505
+ fontSize="xs"
506
+ px={2}
507
+ py={1}
508
+ >
509
+ {persistedJobs.length} {persistedJobs.length === 1 ? 'job' : 'jobs'}
510
+ </Badge>
511
+ </HStack>
512
+ </Card.Header>
513
+ <Card.Body overflowY="auto" p={0} flex="1" minH={0} maxH="70vh">
514
+ {(persistedJobsError) ? (
515
+ <Alert.Root status="error">
516
+ <Alert.Indicator />
517
+ <Alert.Content>
518
+ <Alert.Title>Error loading persisted jobs!</Alert.Title>
519
+ <Alert.Description>
520
+ {persistedJobsError?.message || 'Failed to load persisted jobs'}
521
+ </Alert.Description>
522
+ </Alert.Content>
523
+ </Alert.Root>
524
+ ) : (persistedJobsLoading) ? (
525
+ <Box textAlign="center" py={12}>
526
+ <Spinner size="lg" color="var(--color-primary)" />
527
+ <Text mt={4} color="var(--color-text-muted)" fontSize="sm">
528
+ Loading persisted jobs...
529
+ </Text>
530
+ </Box>
531
+ ) : (
532
+ <>
533
+ {persistedJobs.length === 0 ? (
534
+ <Box textAlign="center" py={12}>
535
+ <Text color="var(--color-text-muted)" fontSize="md">
536
+ No persisted jobs found
537
+ </Text>
538
+ <Text color="var(--color-text-muted)" fontSize="sm" mt={2}>
539
+ Completed jobs will appear here
540
+ </Text>
541
+ </Box>
542
+ ) : (
543
+ <Table.Root variant="line" size="md" stickyHeader>
544
+ <Table.Header bg="var(--color-bg-header)">
545
+ <Table.Row>
546
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} pl={6} pr={4} fontSize="sm">Job ID</Table.ColumnHeader>
547
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">JR Job ID</Table.ColumnHeader>
548
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Name</Table.ColumnHeader>
549
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Status</Table.ColumnHeader>
550
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Cluster</Table.ColumnHeader>
551
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Partition</Table.ColumnHeader>
552
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">User</Table.ColumnHeader>
553
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Time</Table.ColumnHeader>
554
+ <Table.ColumnHeader fontWeight="semibold" color="var(--color-text)" py={2} px={4} fontSize="sm">Actions</Table.ColumnHeader>
555
+ </Table.Row>
556
+ </Table.Header>
557
+ <Table.Body>
558
+ {persistedJobs.map((persistedJobInfo: PersitedJobInfo, index: number) => {
559
+ const job = persistedJobInfo.info;
560
+ const acc = persistedJobInfo.acc;
561
+ const jrJobId = persistedJobInfo.name;
562
+
563
+ // Use accounting data when available, fallback to info object
564
+ const jobId = acc?.job_id?.toString() || job.job_id || '-';
565
+ const jobName = acc?.name || job.name || job.job_name || 'Persisted Job';
566
+ const jobStatus = acc?.state?.current?.[0] || job.job_state?.[0] || 'PENDING';
567
+ const partition = acc?.partition || job.partition || 'N/A';
568
+ const user = acc?.user || job.user_name || job.user || 'N/A';
569
+
570
+ // Calculate freshness - 2 weeks = 14 * 24 * 60 * 60 = 1209600 seconds
571
+ const maxAge = 14 * 24 * 60 * 60; // 2 weeks in seconds
572
+ const freshnessRatio = Math.min(persistedJobInfo.freshness / maxAge, 1);
573
+
574
+ // Calculate color from green (0) to brown (1)
575
+ const getFreshnessColor = (ratio: number) => {
576
+ if (ratio <= 0) return freshnessGreen;
577
+ if (ratio >= 1) return freshnessBrown;
578
+
579
+ // Interpolate between green and brown
580
+ const green = hexToRgb(freshnessGreen);
581
+ const brown = hexToRgb(freshnessBrown);
582
+
583
+ const r = Math.round(green[0] + (brown[0] - green[0]) * ratio);
584
+ const g = Math.round(green[1] + (brown[1] - green[1]) * ratio);
585
+ const b = Math.round(green[2] + (brown[2] - green[2]) * ratio);
586
+
587
+ return `rgb(${r}, ${g}, ${b})`;
588
+ };
589
+
590
+ // Format duration for tooltip
591
+ const formatDuration = (seconds: number) => {
592
+ const days = Math.floor(seconds / (24 * 60 * 60));
593
+ const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60));
594
+ const minutes = Math.floor((seconds % (60 * 60)) / 60);
595
+
596
+ if (days > 0) {
597
+ return `${days}d ${hours}h ${minutes}m ago`;
598
+ } else if (hours > 0) {
599
+ return `${hours}h ${minutes}m ago`;
600
+ } else {
601
+ return `${minutes}m ago`;
602
+ }
603
+ };
604
+
605
+ // Format time limit - prefer accounting data
606
+ let timeLimit = 'N/A';
607
+ if (acc?.time?.limit?.number) {
608
+ timeLimit = `${acc.time.limit.number}min`;
609
+ } else if (typeof job.time_limit === 'string') {
610
+ timeLimit = job.time_limit;
611
+ } else if (job.time_limit?.number) {
612
+ timeLimit = `${job.time_limit.number}min`;
613
+ }
614
+
615
+ return (
616
+ <Table.Row
617
+ key={`persisted-${jrJobId}`}
618
+ _hover={{ bg: 'var(--color-bg-hover)' }}
619
+ bg={index % 2 === 0 ? 'transparent' : 'var(--color-bg-stripe)'}
620
+ >
621
+ <Table.Cell pl={6} pr={4}>
622
+ <HStack gap={2}>
623
+ <Tooltip
624
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
625
+ content={formatDuration(persistedJobInfo.freshness)}
626
+ >
627
+ <Box
628
+ width="12px"
629
+ height="12px"
630
+ backgroundColor={getFreshnessColor(freshnessRatio)}
631
+ borderRadius="2px"
632
+ cursor="pointer"
633
+ border="1px solid"
634
+ borderColor="var(--color-border)"
635
+ />
636
+ </Tooltip>
637
+ <Text fontWeight="semibold" color="var(--color-text)">{jobId}</Text>
638
+ </HStack>
639
+ </Table.Cell>
640
+ <Table.Cell>
641
+ <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">
642
+ {jrJobId}
643
+ </Text>
644
+ </Table.Cell>
645
+ <Table.Cell>
646
+ <Text color="var(--color-text)">{jobName}<AgentBadge tag={persistedJobInfo.agent} /></Text>
647
+ </Table.Cell>
648
+ <Table.Cell>
649
+ <HStack gap={2}>
650
+ {getStatusIcon(jobStatus)}
651
+ <Badge colorScheme={getStatusColor(jobStatus)}>
652
+ {jobStatus}
653
+ </Badge>
654
+ </HStack>
655
+ </Table.Cell>
656
+ <Table.Cell>
657
+ <Text color="var(--color-text)" fontSize="sm">{persistedJobInfo.cluster || 'mila'}</Text>
658
+ </Table.Cell>
659
+ <Table.Cell>
660
+ <Text color="var(--color-text)">{partition}</Text>
661
+ </Table.Cell>
662
+ <Table.Cell>
663
+ <Text color="var(--color-text)">{user}</Text>
664
+ </Table.Cell>
665
+ <Table.Cell>
666
+ <Text color="var(--color-text)">{timeLimit}</Text>
667
+ </Table.Cell>
668
+ <Table.Cell>
669
+ <HStack gap={2}>
670
+ <Tooltip
671
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
672
+ content="View Details"
673
+ >
674
+ <Link
675
+ to={paths.jobDetails(jobId, jrJobId)}
676
+ >
677
+ <IconButton
678
+ aria-label="View job details"
679
+ size="sm"
680
+ variant="ghost"
681
+ >
682
+ <LuInfo />
683
+ </IconButton>
684
+ </Link>
685
+ </Tooltip>
686
+ <Tooltip
687
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
688
+ content="View Logs"
689
+ >
690
+ <Link
691
+ to={paths.jobLogs(jobId, jrJobId)}
692
+ >
693
+ <IconButton
694
+ aria-label="View job logs"
695
+ size="sm"
696
+ variant="ghost"
697
+ >
698
+ <LuEye />
699
+ </IconButton>
700
+ </Link>
701
+ </Tooltip>
702
+ <Tooltip
703
+ positioning={{ placement: 'top', offset: { mainAxis: 8 } }}
704
+ content="Rerun Job"
705
+ >
706
+ <IconButton
707
+ aria-label="Rerun job"
708
+ size="sm"
709
+ variant="ghost"
710
+ colorScheme="blue"
711
+ onClick={() => handleRerunJob(jrJobId)}
712
+ >
713
+ <LuRefreshCw />
714
+ </IconButton>
715
+ </Tooltip>
716
+ </HStack>
717
+ </Table.Cell>
718
+ </Table.Row>
719
+ );
720
+ })}
721
+ </Table.Body>
722
+ </Table.Root>
723
+ )}
724
+ </>
725
+ )}
726
+ </Card.Body>
727
+ </Card.Root>
728
+
729
+
730
+ </VStack>
731
+ </Box>
732
+ );
733
+ };
734
+
735
+
736
+