@milabench/bujang 0.0.0-stage → 0.1.2

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,1318 @@
1
+ import React, { useState, useMemo } from 'react';
2
+ import { Tooltip } from '../components/tooltip'
3
+ import {
4
+ Box,
5
+ Heading,
6
+ Text,
7
+ VStack,
8
+ HStack,
9
+ Button,
10
+ Table,
11
+ Badge,
12
+ Dialog,
13
+ Input,
14
+ Select,
15
+ IconButton,
16
+ Alert,
17
+ Tabs,
18
+ Card,
19
+ Field,
20
+ Flex,
21
+ Spacer,
22
+ Separator,
23
+ Link,
24
+ useListCollection
25
+ } from '@chakra-ui/react';
26
+ import { Link as RouterLink } from 'react-router-dom';
27
+ import { useBujangPaths } from '../context';
28
+ import { NO_JOB_ID } from '../constants';
29
+ import { toaster } from '../toast';
30
+ import {
31
+ LuPlus,
32
+ LuTrash2,
33
+ } from 'react-icons/lu';
34
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
35
+ import {
36
+ getSlurmProfiles,
37
+ getSlurmTemplates,
38
+ getPipelineTemplatesList,
39
+ savePipelineToFile,
40
+ loadPipelineFromFile,
41
+ runPipelineTemplate,
42
+ getPipelineRuns,
43
+ getPipelineRunStatus
44
+ } from '../api';
45
+ import type {
46
+ Pipeline,
47
+ PipelineRun,
48
+ PipelineNode,
49
+ PipelineJob,
50
+ PipelineSequential,
51
+ PipelineParallel,
52
+ SlurmProfile,
53
+ ApiError,
54
+ PipelineTemplatePayload,
55
+ PipelineRunSummary,
56
+ PipelineRunStatus
57
+ } from '../types';
58
+ import { usePageTitle } from '../hooks/usePageTitle';
59
+
60
+ const getStatusColor = (status: string) => {
61
+ switch (status) {
62
+ case 'completed': return 'green';
63
+ case 'running': return 'blue';
64
+ case 'failed': return 'red';
65
+ case 'cancelled': return 'gray';
66
+ case 'pending': return 'yellow';
67
+ default: return 'gray';
68
+ }
69
+ };
70
+
71
+ interface JobNodeData {
72
+ type: 'job' | 'sequential' | 'parallel';
73
+ script?: string;
74
+ profile?: string;
75
+ // kept as is from the pipeline file (not editable here yet)
76
+ env?: Record<string, string>;
77
+ name?: string;
78
+ children: JobNodeData[];
79
+ }
80
+
81
+ /**
82
+ * Shape of a loaded pipeline template file. Current saves always write the
83
+ * `{ type: 'pipeline', name, definition, job_id }` server format; the other
84
+ * fields are a defensive fallback for template files written in an older,
85
+ * pre-server format.
86
+ */
87
+ interface PipelineTemplateFileData {
88
+ type?: string;
89
+ name?: string;
90
+ definition?: PipelineNode;
91
+ job_id?: string | null;
92
+ // Legacy format fallback
93
+ pipelineName?: string;
94
+ rootNode?: JobNodeData;
95
+ }
96
+
97
+ // Profile names repeat between clusters and between the node types of a cluster (1-gpu, 4-gpu, ...):
98
+ // jobs reference "<cluster>/<node>/<name>" ("<cluster>/<name>" for profiles without a node type)
99
+ const profileKey = (profile?: SlurmProfile): string => {
100
+ if (!profile) return 'default';
101
+ const cluster = profile.cluster || 'mila';
102
+ return profile.node ? `${cluster}/${profile.node}/${profile.name}` : `${cluster}/${profile.name}`;
103
+ };
104
+
105
+ // Older templates stored a shorter key, map it to the first matching profile (the backend does the same)
106
+ const normalizeProfile = (value: string | undefined, profiles: SlurmProfile[]): string | undefined => {
107
+ if (!value) return value;
108
+ const parts = value.split('/');
109
+ const name = parts[parts.length - 1];
110
+ const cluster = parts.length > 1 ? parts[0] : undefined;
111
+ const node = parts.length > 2 ? parts[1] : undefined;
112
+ const match = profiles.find((p) =>
113
+ p.name === name
114
+ && (cluster === undefined || (p.cluster || 'mila') === cluster)
115
+ && (node === undefined || p.node === node));
116
+ return match ? profileKey(match) : value;
117
+ };
118
+
119
+ // Convert backend PipelineNode format to frontend JobNodeData format.
120
+ // Pure function of its argument (no component state/props involved), so it
121
+ // lives at module scope rather than being redefined (and needing to be
122
+ // re-memoized) on every render.
123
+ const convertFromBackendFormat = (node: PipelineNode): JobNodeData => {
124
+ if (node.type === 'job') {
125
+ return {
126
+ type: 'job',
127
+ script: node.script || '',
128
+ profile: node.profile || '',
129
+ env: node.env,
130
+ children: [] // Jobs can have children in UI for UX
131
+ };
132
+ } else if (node.type === 'sequential') {
133
+ return {
134
+ type: 'sequential',
135
+ name: node.name || 'Unnamed Sequential',
136
+ children: (node.jobs || []).map(convertFromBackendFormat)
137
+ };
138
+ } else {
139
+ return {
140
+ type: 'parallel',
141
+ name: node.name || 'Unnamed Parallel',
142
+ children: (node.jobs || []).map(convertFromBackendFormat)
143
+ };
144
+ }
145
+ };
146
+
147
+ const JobNode: React.FC<{
148
+ node: JobNodeData;
149
+ onUpdate: (node: JobNodeData) => void;
150
+ onDelete: () => void;
151
+ profiles: SlurmProfile[];
152
+ templates: string[];
153
+ depth?: number;
154
+ canDelete?: boolean;
155
+ }> = ({ node, onUpdate, onDelete, profiles, templates, depth = 0, canDelete = true }) => {
156
+ const handleTypeChange = (newType: 'job' | 'sequential' | 'parallel') => {
157
+ const updatedNode = {
158
+ ...node,
159
+ type: newType,
160
+ // Set default values based on type but keep children for UX
161
+ script: newType === 'job' ? (node.script || templates[0] || '') : undefined,
162
+ profile: newType === 'job' ? (node.profile || profileKey(profiles[0])) : undefined,
163
+ name: newType !== 'job' ? (node.name || `New ${newType}`) : undefined
164
+ };
165
+ onUpdate(updatedNode);
166
+ };
167
+
168
+ const handleFieldChange = (field: string, value: string) => {
169
+ const updatedNode = { ...node, [field]: value };
170
+ onUpdate(updatedNode);
171
+ };
172
+
173
+ const handleAddChild = () => {
174
+ const newChild: JobNodeData = {
175
+ type: 'job',
176
+ script: templates[0] || '',
177
+ profile: profileKey(profiles[0]),
178
+ children: []
179
+ };
180
+
181
+ const updatedNode = {
182
+ ...node,
183
+ children: [...node.children, newChild]
184
+ };
185
+ onUpdate(updatedNode);
186
+ };
187
+
188
+ const handleChildUpdate = (index: number, updatedChild: JobNodeData) => {
189
+ const updatedNode = {
190
+ ...node,
191
+ children: node.children.map((child, i) => i === index ? updatedChild : child)
192
+ };
193
+ onUpdate(updatedNode);
194
+ };
195
+
196
+ const handleChildDelete = (index: number) => {
197
+ const updatedNode = {
198
+ ...node,
199
+ children: node.children.filter((_, i) => i !== index)
200
+ };
201
+ onUpdate(updatedNode);
202
+ };
203
+
204
+ const getNodeBgColor = (nodeType: string) => {
205
+ switch (nodeType) {
206
+ case 'job': return 'var(--color-pipeline-job-bg)';
207
+ case 'sequential': return 'var(--color-pipeline-seq-bg)';
208
+ case 'parallel': return 'var(--color-pipeline-par-bg)';
209
+ default: return 'var(--color-bg-card)';
210
+ }
211
+ };
212
+
213
+ const getNodeBorderColor = (nodeType: string) => {
214
+ switch (nodeType) {
215
+ case 'job': return 'var(--color-pipeline-job-border)';
216
+ case 'sequential': return 'var(--color-pipeline-seq-border)';
217
+ case 'parallel': return 'var(--color-pipeline-par-border)';
218
+ default: return 'var(--color-border)';
219
+ }
220
+ };
221
+
222
+ // Collections for Select components
223
+ const nodeTypeItems = useMemo(() => [
224
+ { label: 'Job', value: 'job' },
225
+ { label: 'Sequential', value: 'sequential' },
226
+ { label: 'Parallel', value: 'parallel' }
227
+ ], []);
228
+
229
+ const templatesItems = useMemo(() =>
230
+ templates.map(template => ({ label: template, value: template })),
231
+ [templates]
232
+ );
233
+
234
+ const profilesItems = useMemo(() =>
235
+ profiles.map(profile => ({
236
+ label: `${profile.cluster || 'mila'} / ${profile.name}`
237
+ + (profile.node ? ` (${profile.node})` : '')
238
+ + (profile.executor === 'ssh' ? ' - ssh, no slurm' : ''),
239
+ value: profileKey(profile),
240
+ })),
241
+ [profiles]
242
+ );
243
+ const selectedProfile = normalizeProfile(node.profile, profiles);
244
+
245
+ const nodeTypeCollection = useListCollection({ initialItems: nodeTypeItems });
246
+ const templatesCollection = useListCollection({ initialItems: templatesItems });
247
+ const profilesCollection = useListCollection({ initialItems: profilesItems });
248
+
249
+ const renderNodeHeader = () => {
250
+ return (
251
+ <VStack gap={3} align="stretch">
252
+ <HStack gap={3} justify="space-between" flexWrap="wrap" align="flex-end">
253
+ <HStack gap={3} flex={1} minW="300px" align="flex-end">
254
+ <VStack align="start" gap={1} w="140px">
255
+ <Text fontSize="xs" fontWeight="medium" color="var(--color-text)" visibility="hidden">Type</Text>
256
+ <Select.Root
257
+ size="sm"
258
+ collection={nodeTypeCollection.collection}
259
+ value={[node.type]}
260
+ onValueChange={(details) => handleTypeChange(details.value[0] as 'job' | 'sequential' | 'parallel')}
261
+ w="100%"
262
+ >
263
+ <Select.HiddenSelect />
264
+ <Select.Control
265
+ bg={getNodeBgColor(node.type)}
266
+ borderColor={getNodeBorderColor(node.type)}
267
+ borderRadius="md"
268
+ h="32px"
269
+ >
270
+ <Select.Trigger>
271
+ <Select.ValueText fontWeight="semibold" color="var(--color-text)" />
272
+ </Select.Trigger>
273
+ <Select.IndicatorGroup>
274
+ <Select.Indicator />
275
+ </Select.IndicatorGroup>
276
+ </Select.Control>
277
+ <Select.Positioner>
278
+ <Select.Content>
279
+ {nodeTypeItems.map((item) => (
280
+ <Select.Item key={item.value} item={item}>
281
+ <Select.ItemText>{item.label}</Select.ItemText>
282
+ </Select.Item>
283
+ ))}
284
+ </Select.Content>
285
+ </Select.Positioner>
286
+ </Select.Root>
287
+ </VStack>
288
+
289
+ {node.type === 'job' ? (
290
+ <>
291
+ <VStack align="start" gap={1} flex={1}>
292
+ <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Script</Text>
293
+ <Select.Root
294
+ size="sm"
295
+ collection={templatesCollection.collection}
296
+ value={node.script ? [node.script] : []}
297
+ onValueChange={(details) => handleFieldChange('script', details.value[0] || '')}
298
+ flex={1}
299
+ >
300
+ <Select.HiddenSelect />
301
+ <Select.Control
302
+ bg="var(--color-input-bg)"
303
+ borderColor="var(--color-input-border)"
304
+ borderRadius="md"
305
+ _focus={{ borderColor: 'var(--color-primary)' }}
306
+ h="32px"
307
+ >
308
+ <Select.Trigger>
309
+ <Select.ValueText placeholder="Select template" color="var(--color-text)" />
310
+ </Select.Trigger>
311
+ <Select.IndicatorGroup>
312
+ <Select.Indicator />
313
+ </Select.IndicatorGroup>
314
+ </Select.Control>
315
+ <Select.Positioner>
316
+ <Select.Content>
317
+ {templatesItems.map((item) => (
318
+ <Select.Item key={item.value} item={item}>
319
+ <Select.ItemText>{item.label}</Select.ItemText>
320
+ </Select.Item>
321
+ ))}
322
+ </Select.Content>
323
+ </Select.Positioner>
324
+ </Select.Root>
325
+ </VStack>
326
+ <VStack align="start" gap={1} w="380px">
327
+ <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Resources</Text>
328
+ <Select.Root
329
+ size="sm"
330
+ collection={profilesCollection.collection}
331
+ value={selectedProfile ? [selectedProfile] : []}
332
+ onValueChange={(details) => handleFieldChange('profile', details.value[0] || '')}
333
+ w="100%"
334
+ >
335
+ <Select.HiddenSelect />
336
+ <Select.Control
337
+ bg="var(--color-input-bg)"
338
+ borderColor="var(--color-input-border)"
339
+ borderRadius="md"
340
+ _focus={{ borderColor: 'var(--color-primary)' }}
341
+ h="32px"
342
+ >
343
+ <Select.Trigger>
344
+ <Select.ValueText placeholder="Select profile" color="var(--color-text)" />
345
+ </Select.Trigger>
346
+ <Select.IndicatorGroup>
347
+ <Select.Indicator />
348
+ </Select.IndicatorGroup>
349
+ </Select.Control>
350
+ <Select.Positioner>
351
+ <Select.Content>
352
+ {profilesItems.map((item) => (
353
+ <Select.Item key={item.value} item={item}>
354
+ <Select.ItemText>{item.label}</Select.ItemText>
355
+ </Select.Item>
356
+ ))}
357
+ </Select.Content>
358
+ </Select.Positioner>
359
+ </Select.Root>
360
+ </VStack>
361
+ </>
362
+ ) : (
363
+ <VStack align="start" gap={1} flex={1}>
364
+ <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Name</Text>
365
+ <Input
366
+ pl="10px"
367
+ size="sm"
368
+ value={node.name || ''}
369
+ onChange={(e) => handleFieldChange('name', e.target.value)}
370
+ placeholder="Enter name"
371
+ w="100%"
372
+ bg="var(--color-input-bg)"
373
+ borderColor="var(--color-input-border)"
374
+ color="var(--color-text)"
375
+ _focus={{ borderColor: 'var(--color-primary)' }}
376
+ borderRadius="md"
377
+ h="32px"
378
+ />
379
+ </VStack>
380
+ )}
381
+ </HStack>
382
+
383
+ <HStack gap={2}>
384
+ {node.type !== 'job' && (
385
+ <Button
386
+ size="sm"
387
+ onClick={handleAddChild}
388
+ bg="var(--color-primary)"
389
+ color="var(--color-primary-text)"
390
+ _hover={{ bg: 'var(--color-primary-hover)' }}
391
+ borderRadius="md"
392
+ >
393
+ + Add
394
+ </Button>
395
+ )}
396
+ {canDelete && (
397
+ <IconButton
398
+ aria-label="Delete"
399
+ size="sm"
400
+ colorScheme="red"
401
+ variant="ghost"
402
+ onClick={onDelete}
403
+ borderRadius="md"
404
+ >
405
+ <LuTrash2 />
406
+ </IconButton>
407
+ )}
408
+ </HStack>
409
+ </HStack>
410
+ </VStack>
411
+ );
412
+ };
413
+
414
+ const renderChildren = () => {
415
+ // Don't display children for job nodes at all
416
+ if (node.type === 'job' || node.children.length === 0) return null;
417
+
418
+ // Show children for sequential and parallel types only
419
+ return (
420
+ <VStack align="stretch" pl={6} gap={1}>
421
+ {node.children.map((child, index) => (
422
+ <Box key={index}>
423
+ <JobNode
424
+ node={child}
425
+ onUpdate={(updatedChild) => handleChildUpdate(index, updatedChild)}
426
+ onDelete={() => handleChildDelete(index)}
427
+ profiles={profiles}
428
+ templates={templates}
429
+ depth={depth + 1}
430
+ canDelete={true}
431
+ />
432
+ </Box>
433
+ ))}
434
+ </VStack>
435
+ );
436
+ };
437
+
438
+ if (node.type === 'job') {
439
+ return (
440
+ <Box ml={depth * 2} bg="var(--color-bg-card)" padding="2px" borderRadius="md" border="1px" borderColor="var(--color-border)" mb={1}>
441
+ {renderNodeHeader()}
442
+ {renderChildren()}
443
+ </Box>
444
+ );
445
+ }
446
+
447
+ return (
448
+ <Box
449
+ ml={depth * 2}
450
+ padding="10px"
451
+ border="1px"
452
+ borderColor="var(--color-border)"
453
+ borderRadius="lg"
454
+ mb={1}
455
+ bg="var(--color-bg-card)"
456
+ boxShadow="sm"
457
+ >
458
+ <Box p={4}>
459
+ {renderNodeHeader()}
460
+ </Box>
461
+ {renderChildren()}
462
+ </Box>
463
+ );
464
+ };
465
+
466
+ const PipelineNodeDisplay: React.FC<{ node: PipelineNode; depth?: number }> = ({ node, depth = 0 }) => {
467
+ const indent = depth * 20;
468
+
469
+ const renderNode = () => {
470
+ if (node.type === 'job') {
471
+ const job = node as PipelineJob;
472
+ return (
473
+ <HStack>
474
+ <Badge colorScheme="orange">Job</Badge>
475
+ <Text fontWeight="bold" color="var(--color-text)">{job.script}</Text>
476
+ <Badge variant="outline">{job.profile}</Badge>
477
+ {job.executor === 'ssh' && <Badge variant="outline">ssh {job.host}</Badge>}
478
+ {job.slurm_jobid && <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">slurm {job.slurm_jobid}</Text>}
479
+ {job.job_id && <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">{job.job_id}</Text>}
480
+ </HStack>
481
+ );
482
+ }
483
+
484
+ if (node.type === 'sequential') {
485
+ const seq = node as PipelineSequential;
486
+ return (<>
487
+ <HStack>
488
+ <Badge colorScheme="green">Sequential</Badge>
489
+ <Text fontWeight="bold" color="var(--color-text)">{seq.name}</Text>
490
+ </HStack>
491
+ <VStack align="stretch" pl={6} gap={1}>
492
+ {seq.jobs.map((job, index) => (
493
+ <Box key={index}>
494
+ <PipelineNodeDisplay node={job} depth={depth + 1} />
495
+ </Box>
496
+ ))}
497
+ </VStack>
498
+ </>
499
+ );
500
+ }
501
+
502
+ if (node.type === 'parallel') {
503
+ const par = node as PipelineParallel;
504
+ return (<>
505
+ <HStack>
506
+ <Badge colorScheme="blue">Parallel</Badge>
507
+ <Text fontWeight="bold" color="var(--color-text)">{par.name}</Text>
508
+ </HStack>
509
+ <VStack align="stretch" pl={6} gap={1}>
510
+ {par.jobs.map((job, index) => (
511
+ <Box key={index}>
512
+ <PipelineNodeDisplay node={job} depth={depth + 1} />
513
+ </Box>
514
+ ))}
515
+ </VStack>
516
+ </>);
517
+ }
518
+
519
+ return null;
520
+ };
521
+
522
+ return (
523
+ <Box ml={indent} padding="0px" margin="0px" className="here">
524
+ {renderNode()}
525
+ </Box>
526
+ )
527
+ };
528
+
529
+ const PipelineBuilder: React.FC<{
530
+ isOpen: boolean;
531
+ onClose: () => void;
532
+ profiles: SlurmProfile[];
533
+ templates: string[];
534
+ loadedTemplateData?: PipelineTemplateFileData | null;
535
+ onSaveTemplate: (data: PipelineTemplatePayload) => void;
536
+ }> = ({ isOpen, onClose, profiles, templates, loadedTemplateData, onSaveTemplate }) => {
537
+ const [pipelineName, setPipelineName] = useState('');
538
+ const [rootNode, setRootNode] = useState<JobNodeData>({
539
+ type: 'sequential',
540
+ name: 'Main Sequence',
541
+ children: []
542
+ });
543
+
544
+ // Load template data when provided
545
+ React.useEffect(() => {
546
+ if (loadedTemplateData) {
547
+ // Handle server format: { type: 'pipeline', name: '...', definition: {...}, job_id: null }
548
+ if (loadedTemplateData.type === 'pipeline') {
549
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- hydrates local editable pipeline-editor state from an externally-provided template prop (loaded asynchronously by the parent); rootNode/pipelineName are also independently mutated by user edits below, so this can't be replaced by a plain render-time derivation.
550
+ setPipelineName(loadedTemplateData.name || '');
551
+ if (loadedTemplateData.definition) {
552
+ setRootNode(convertFromBackendFormat(loadedTemplateData.definition));
553
+ }
554
+ } else {
555
+ // Fallback for old format (if any)
556
+ setPipelineName(loadedTemplateData.pipelineName || '');
557
+ setRootNode(loadedTemplateData.rootNode || {
558
+ type: 'sequential',
559
+ name: 'Main Sequence',
560
+ children: []
561
+ });
562
+ }
563
+ }
564
+ }, [loadedTemplateData]);
565
+
566
+ const handleSavePipeline = () => {
567
+ if (!pipelineName) return;
568
+
569
+ // Convert JobNodeData to PipelineNode, filtering out job children
570
+ const convertNode = (node: JobNodeData): PipelineNode => {
571
+ if (node.type === 'job') {
572
+ return {
573
+ type: 'job',
574
+ script: node.script || '',
575
+ profile: node.profile || '',
576
+ ...(node.env && Object.keys(node.env).length ? { env: node.env } : {})
577
+ };
578
+ } else if (node.type === 'sequential') {
579
+ return {
580
+ type: 'sequential',
581
+ name: node.name || 'Unnamed Sequential',
582
+ jobs: node.children.map(convertNode)
583
+ };
584
+ } else {
585
+ return {
586
+ type: 'parallel',
587
+ name: node.name || 'Unnamed Parallel',
588
+ jobs: node.children.map(convertNode)
589
+ };
590
+ }
591
+ };
592
+
593
+ // Save as template file - format expected by server
594
+ const templateData: PipelineTemplatePayload = {
595
+ name: pipelineName, // used for filename
596
+ type: 'pipeline', // required by JobNode.from_json
597
+ definition: convertNode(rootNode), // the actual pipeline structure
598
+ job_id: null // optional field
599
+ };
600
+
601
+ onSaveTemplate(templateData);
602
+
603
+ // Reset form
604
+ setPipelineName('');
605
+ setRootNode({
606
+ type: 'sequential',
607
+ name: 'Main Sequence',
608
+ children: []
609
+ });
610
+ onClose();
611
+ };
612
+
613
+ return (
614
+ <Dialog.Root open={isOpen} onOpenChange={(details) => { if (!details.open) onClose(); }}>
615
+ <Dialog.Backdrop />
616
+ <Dialog.Positioner>
617
+ <Dialog.Content maxW="6xl" maxH="90vh">
618
+ <Dialog.Header>
619
+ <Dialog.Title>Pipeline</Dialog.Title>
620
+ <Dialog.CloseTrigger />
621
+ </Dialog.Header>
622
+ <Dialog.Body overflowY="auto">
623
+ <VStack gap={6} align="stretch">
624
+ <Field.Root required>
625
+ <Field.Label>Pipeline Name</Field.Label>
626
+ <Input
627
+ value={pipelineName}
628
+ onChange={(e) => setPipelineName(e.target.value)}
629
+ placeholder="Enter pipeline name"
630
+ />
631
+ </Field.Root>
632
+
633
+ <Separator />
634
+
635
+ <Box>
636
+ <HStack mb={4}>
637
+ <Heading size="md" color="var(--color-text)">Pipeline Structure</Heading>
638
+ </HStack>
639
+
640
+ <Box
641
+ border="1px"
642
+ borderColor="var(--color-border)"
643
+ borderRadius="lg"
644
+ p={6}
645
+ bg="var(--color-bg-page)"
646
+ boxShadow="sm"
647
+ >
648
+ <JobNode
649
+ node={rootNode}
650
+ onUpdate={setRootNode}
651
+ onDelete={() => { }} // Root can't be deleted
652
+ profiles={profiles}
653
+ templates={templates}
654
+ canDelete={false}
655
+ />
656
+ </Box>
657
+ </Box>
658
+ </VStack>
659
+ </Dialog.Body>
660
+ <Dialog.Footer>
661
+ <Button
662
+ variant="ghost"
663
+ mr={3}
664
+ onClick={onClose}
665
+ color="var(--color-text)"
666
+ _hover={{ bg: 'var(--color-bg-hover)' }}
667
+ >
668
+ Cancel
669
+ </Button>
670
+ <Button
671
+ onClick={handleSavePipeline}
672
+ disabled={!pipelineName}
673
+ bg="var(--color-primary)"
674
+ color="var(--color-primary-text)"
675
+ _hover={{ bg: 'var(--color-primary-hover)' }}
676
+ fontWeight="medium"
677
+ >
678
+ Save Pipeline
679
+ </Button>
680
+ </Dialog.Footer>
681
+ </Dialog.Content>
682
+ </Dialog.Positioner>
683
+ </Dialog.Root>
684
+ );
685
+ };
686
+
687
+ // PipelinesHeader Component
688
+ const PipelinesHeader: React.FC<{
689
+ onCreateOpen: () => void;
690
+ }> = ({ onCreateOpen }) => {
691
+ return (
692
+ <>
693
+ <Flex align="center" flexWrap="wrap" gap={4}>
694
+ <Heading size="lg" color="var(--color-text)">Pipeline Management</Heading>
695
+ <Spacer />
696
+ <Button
697
+ onClick={onCreateOpen}
698
+ bg="var(--color-primary)"
699
+ color="var(--color-primary-text)"
700
+ _hover={{ bg: 'var(--color-primary-hover)' }}
701
+ fontWeight="medium"
702
+ borderRadius="md"
703
+ >
704
+ <HStack gap={2} as="span">
705
+ <LuPlus />
706
+ <Text>New Pipeline</Text>
707
+ </HStack>
708
+ </Button>
709
+ </Flex>
710
+
711
+ <Text color="var(--color-text-muted)">
712
+ Manage and run SLURM job pipelines with dependencies and scheduling.
713
+ </Text>
714
+ </>
715
+ );
716
+ };
717
+
718
+ // PipelineTemplatesTable Component
719
+ const PipelineTemplatesTable: React.FC<{
720
+ pipelineTemplateFiles: string[];
721
+ onLoadTemplate: (fileName: string) => Promise<Record<string, unknown>>;
722
+ onTemplateLoaded: (templateData: PipelineTemplateFileData) => void;
723
+ isLoading: boolean;
724
+ onRun: (fileName: string) => void;
725
+ runningTemplate: string | null;
726
+ }> = ({ pipelineTemplateFiles, onLoadTemplate, onTemplateLoaded, isLoading, onRun, runningTemplate }) => {
727
+ if (pipelineTemplateFiles.length === 0) {
728
+ return (
729
+ <Alert.Root status="info">
730
+ <Alert.Indicator />
731
+ <Alert.Content>
732
+ <Alert.Description>
733
+ No pipeline templates saved yet. Create a pipeline and save it as a template to get started.
734
+ </Alert.Description>
735
+ </Alert.Content>
736
+ </Alert.Root>
737
+ );
738
+ }
739
+
740
+ return (
741
+ <VStack align="stretch" gap={3}>
742
+ <Table.Root>
743
+ <Table.Header bg="var(--color-bg-header)">
744
+ <Table.Row>
745
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" fontWeight="semibold" pl={4}>Template Name</Table.ColumnHeader>
746
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" fontWeight="semibold" pr={4}>Actions</Table.ColumnHeader>
747
+ </Table.Row>
748
+ </Table.Header>
749
+ <Table.Body>
750
+ {pipelineTemplateFiles.map((fileName) => (
751
+ <Table.Row
752
+ key={fileName}
753
+ _hover={{ bg: 'var(--color-bg-hover)' }}
754
+ borderColor="var(--color-border)"
755
+ transition="background-color 0.2s"
756
+ >
757
+ <Table.Cell fontWeight="medium" color="var(--color-text)" borderColor="var(--color-border)" py={3} pl={4}>
758
+ {fileName}
759
+ </Table.Cell>
760
+ <Table.Cell borderColor="var(--color-border)" py={3} pr={4}>
761
+ <HStack gap={2}>
762
+ <Tooltip content="Load template to create new pipeline">
763
+ <Button
764
+ size="sm"
765
+ onClick={() => {
766
+ onLoadTemplate(fileName).then((raw) => {
767
+ onTemplateLoaded(raw as PipelineTemplateFileData);
768
+ });
769
+ }}
770
+ loading={isLoading}
771
+ bg="var(--color-primary)"
772
+ color="var(--color-primary-text)"
773
+ _hover={{ bg: 'var(--color-primary-hover)' }}
774
+ fontWeight="medium"
775
+ >
776
+ Open
777
+ </Button>
778
+ </Tooltip>
779
+ <Tooltip content="Submit every job of the pipeline with its dependencies">
780
+ <Button
781
+ size="sm"
782
+ variant="outline"
783
+ onClick={() => onRun(fileName)}
784
+ loading={runningTemplate === fileName}
785
+ disabled={runningTemplate !== null}
786
+ borderColor="var(--color-border)"
787
+ color="var(--color-text)"
788
+ _hover={{ bg: 'var(--color-bg-hover)' }}
789
+ fontWeight="medium"
790
+ >
791
+ Run
792
+ </Button>
793
+ </Tooltip>
794
+ </HStack>
795
+ </Table.Cell>
796
+ </Table.Row>
797
+ ))}
798
+ </Table.Body>
799
+ </Table.Root>
800
+ </VStack>
801
+ );
802
+ };
803
+
804
+ // PipelineStructureModal Component
805
+ const PipelineStructureModal: React.FC<{
806
+ pipeline: Pipeline | null;
807
+ onClose: () => void;
808
+ }> = ({ pipeline, onClose }) => {
809
+ return (
810
+ <Dialog.Root open={!!pipeline} onOpenChange={(details) => { if (!details.open) onClose(); }} size="xl">
811
+ <Dialog.Backdrop />
812
+ <Dialog.Positioner>
813
+ <Dialog.Content maxW="xl">
814
+ <Dialog.Header>
815
+ <Dialog.Title>Pipeline Structure: {pipeline?.name}</Dialog.Title>
816
+ <Dialog.CloseTrigger />
817
+ </Dialog.Header>
818
+ <Dialog.Body>
819
+ {pipeline && (
820
+ <Box border="1px" borderColor="var(--color-border)" borderRadius="md" p={4} bg="var(--color-bg-card)">
821
+ <PipelineNodeDisplay node={pipeline.definition} />
822
+ </Box>
823
+ )}
824
+ </Dialog.Body>
825
+ <Dialog.Footer>
826
+ <Button
827
+ onClick={onClose}
828
+ bg="var(--color-primary)"
829
+ color="var(--color-primary-text)"
830
+ _hover={{ bg: 'var(--color-primary-hover)' }}
831
+ fontWeight="medium"
832
+ >
833
+ Close
834
+ </Button>
835
+ </Dialog.Footer>
836
+ </Dialog.Content>
837
+ </Dialog.Positioner>
838
+ </Dialog.Root>
839
+ );
840
+ };
841
+
842
+ // PipelineRunDetailsModal Component
843
+ const PipelineRunDetailsModal: React.FC<{
844
+ run: PipelineRun | null;
845
+ onClose: () => void;
846
+ }> = ({ run, onClose }) => {
847
+ return (
848
+ <Dialog.Root open={!!run} onOpenChange={(details) => { if (!details.open) onClose(); }} size="xl">
849
+ <Dialog.Backdrop />
850
+ <Dialog.Positioner>
851
+ <Dialog.Content maxW="xl">
852
+ <Dialog.Header>
853
+ <Dialog.Title>Pipeline Run Details: {run?.id}</Dialog.Title>
854
+ <Dialog.CloseTrigger />
855
+ </Dialog.Header>
856
+ <Dialog.Body>
857
+ {run && (
858
+ <VStack align="start" gap={4}>
859
+ <HStack>
860
+ <Text fontWeight="bold" color="var(--color-text)">Status:</Text>
861
+ <Badge colorScheme={getStatusColor(run.status)}>
862
+ {run.status}
863
+ </Badge>
864
+ </HStack>
865
+ <HStack>
866
+ <Text fontWeight="bold" color="var(--color-text)">Pipeline:</Text>
867
+ <Text color="var(--color-text)">{run.pipeline.name}</Text>
868
+ </HStack>
869
+ <HStack>
870
+ <Text fontWeight="bold" color="var(--color-text)">Created:</Text>
871
+ <Text color="var(--color-text)">{new Date(run.created_at).toLocaleString()}</Text>
872
+ </HStack>
873
+ {run.jobs.length > 0 && (
874
+ <Box width="100%">
875
+ <Text fontWeight="bold" mb={2} color="var(--color-text)">Jobs:</Text>
876
+ <Table.Root size="sm" variant="line">
877
+ <Table.Header bg="var(--color-bg-header)">
878
+ <Table.Row>
879
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Job ID</Table.ColumnHeader>
880
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Slurm ID</Table.ColumnHeader>
881
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Status</Table.ColumnHeader>
882
+ </Table.Row>
883
+ </Table.Header>
884
+ <Table.Body>
885
+ {run.jobs.map((job) => (
886
+ <Table.Row
887
+ key={job.job_id}
888
+ _hover={{ bg: 'var(--color-bg-hover)' }}
889
+ borderColor="var(--color-border)"
890
+ >
891
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
892
+ <JobLogsLink jobId={job.job_id} slurmJobId={job.slurm_jobid}>{job.job_id}</JobLogsLink>
893
+ </Table.Cell>
894
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
895
+ {job.slurm_jobid || '-'}
896
+ </Table.Cell>
897
+ <Table.Cell borderColor="var(--color-border)">
898
+ <Badge colorScheme={getStatusColor(job.status)} size="sm">
899
+ {job.status}
900
+ </Badge>
901
+ </Table.Cell>
902
+ </Table.Row>
903
+ ))}
904
+ </Table.Body>
905
+ </Table.Root>
906
+ </Box>
907
+ )}
908
+ </VStack>
909
+ )}
910
+ </Dialog.Body>
911
+ <Dialog.Footer>
912
+ <Button
913
+ onClick={onClose}
914
+ bg="var(--color-primary)"
915
+ color="var(--color-primary-text)"
916
+ _hover={{ bg: 'var(--color-primary-hover)' }}
917
+ fontWeight="medium"
918
+ >
919
+ Close
920
+ </Button>
921
+ </Dialog.Footer>
922
+ </Dialog.Content>
923
+ </Dialog.Positioner>
924
+ </Dialog.Root>
925
+ );
926
+ };
927
+
928
+ // Step states: sacct/squeue states for slurm steps (HELD = waiting on an ssh step),
929
+ // runner states for ssh steps (data mover)
930
+ const stepStateColor = (state?: string): string => {
931
+ switch (state) {
932
+ case 'COMPLETED': return 'green';
933
+ case 'RUNNING': case 'COMPLETING': case 'CONFIGURING': return 'blue';
934
+ case 'PENDING': case 'HELD': case 'STARTING': case 'SUBMITTED': case 'REQUEUED': return 'yellow';
935
+ case 'FAILED': case 'DEPENDENCY_FAILED': case 'TIMEOUT': case 'OUT_OF_MEMORY':
936
+ case 'NODE_FAIL': case 'BOOT_FAIL': case 'DEADLINE': case 'PREEMPTED': return 'red';
937
+ case 'CANCELLED': return 'gray';
938
+ default: return 'gray';
939
+ }
940
+ };
941
+
942
+ const runStateColor = (status?: string, state?: string): string => {
943
+ if (status === 'submitting') return 'yellow';
944
+ if (status === 'failed') return 'red';
945
+ switch (state) {
946
+ case 'completed': return 'green';
947
+ case 'failed': return 'red';
948
+ case 'failing': return 'orange';
949
+ case 'running': return 'blue';
950
+ default: return 'gray';
951
+ }
952
+ };
953
+
954
+ const JobLogsLink: React.FC<{ jobId?: string | null; slurmJobId?: string | null; children: React.ReactNode }> = ({ jobId, slurmJobId, children }) => {
955
+ const paths = useBujangPaths();
956
+ if (!jobId) return <>{children}</>;
957
+ // ssh steps have no slurm id, the log page reads their job folder
958
+ return (
959
+ <Link asChild colorPalette="blue" variant="underline">
960
+ <RouterLink to={paths.jobLogs(slurmJobId || NO_JOB_ID, jobId)}>{children}</RouterLink>
961
+ </Link>
962
+ );
963
+ };
964
+
965
+ const isRunOver = (run?: PipelineRunStatus): boolean =>
966
+ !!run && (run.status === 'failed' || run.state === 'completed' || run.state === 'failed');
967
+
968
+ // Progress of one run: steps with their state and the pipeline log, refreshed until it is over
969
+ const PipelineRunProgress: React.FC<{ runId: string }> = ({ runId }) => {
970
+ const { data: run, error, dataUpdatedAt, isFetching } = useQuery<PipelineRunStatus, ApiError>({
971
+ queryKey: ['pipeline-run', runId],
972
+ queryFn: () => getPipelineRunStatus(runId),
973
+ refetchInterval: (query) => {
974
+ const current = query.state.data;
975
+ if (isRunOver(current)) return false;
976
+ return current?.status === 'submitting' ? 3000 : 10000;
977
+ },
978
+ });
979
+
980
+ const logRef = React.useRef<HTMLPreElement | null>(null);
981
+ React.useEffect(() => {
982
+ // follow the end of the log
983
+ if (logRef.current) logRef.current.scrollTop = logRef.current.scrollHeight;
984
+ }, [run?.log]);
985
+
986
+ if (error) {
987
+ return (
988
+ <Alert.Root status="error">
989
+ <Alert.Indicator />
990
+ <Alert.Content>
991
+ <Alert.Description>Failed to load run {runId}: {error.message}</Alert.Description>
992
+ </Alert.Content>
993
+ </Alert.Root>
994
+ );
995
+ }
996
+ if (!run) {
997
+ return <Text color="var(--color-text-muted)">Loading {runId}...</Text>;
998
+ }
999
+
1000
+ const label = run.status === 'submitted' ? (run.state || 'unknown') : run.status;
1001
+
1002
+ return (
1003
+ <VStack align="stretch" gap={4}>
1004
+ <HStack gap={3} flexWrap="wrap">
1005
+ <Heading size="md" color="var(--color-text)">{run.name || runId}</Heading>
1006
+ <Badge colorPalette={runStateColor(run.status, run.state)} size="lg">{label}</Badge>
1007
+ <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">{runId}</Text>
1008
+ <Spacer />
1009
+ <Text fontSize="xs" color="var(--color-text-muted)">
1010
+ {isRunOver(run) ? 'finished, ' : isFetching ? 'refreshing... ' : 'refreshes every 10s, '}
1011
+ updated {new Date(dataUpdatedAt).toLocaleTimeString()}
1012
+ </Text>
1013
+ </HStack>
1014
+
1015
+ {run.status === 'submitting' && (
1016
+ <Text color="var(--color-text-muted)">Submitting the jobs (uploads and data mover steps take a few seconds each)...</Text>
1017
+ )}
1018
+
1019
+ {run.status === 'failed' && (
1020
+ <Alert.Root status="error">
1021
+ <Alert.Indicator />
1022
+ <Alert.Content>
1023
+ <Alert.Title>Submission failed, the jobs already submitted were cancelled</Alert.Title>
1024
+ <Alert.Description>{run.error}</Alert.Description>
1025
+ </Alert.Content>
1026
+ </Alert.Root>
1027
+ )}
1028
+
1029
+ {run.steps && run.steps.length > 0 && (
1030
+ <Table.Root size="sm" variant="line">
1031
+ <Table.Header bg="var(--color-bg-header)">
1032
+ <Table.Row>
1033
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Step</Table.ColumnHeader>
1034
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Runs on</Table.ColumnHeader>
1035
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Waits on</Table.ColumnHeader>
1036
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">State</Table.ColumnHeader>
1037
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Job folder</Table.ColumnHeader>
1038
+ </Table.Row>
1039
+ </Table.Header>
1040
+ <Table.Body>
1041
+ {run.steps.map((step) => (
1042
+ <Table.Row key={step.job_id || step.step} borderColor="var(--color-border)">
1043
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
1044
+ <JobLogsLink jobId={step.job_id} slurmJobId={step.executor === 'ssh' ? null : step.slurm_jobid}>{step.step}</JobLogsLink>
1045
+ </Table.Cell>
1046
+ <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
1047
+ {step.executor === 'ssh' ? `ssh ${step.host}` : `slurm ${step.slurm_jobid ?? '-'}`}
1048
+ <Text as="span" color="var(--color-text-muted)"> ({step.profile})</Text>
1049
+ </Table.Cell>
1050
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text-muted)" borderColor="var(--color-border)">
1051
+ {step.after && step.after.length > 0 ? step.after.join(', ') : '-'}
1052
+ </Table.Cell>
1053
+ <Table.Cell borderColor="var(--color-border)">
1054
+ <Badge colorPalette={stepStateColor(step.state)}>{step.state || 'UNKNOWN'}</Badge>
1055
+ </Table.Cell>
1056
+ <Table.Cell fontFamily="mono" fontSize="xs" color="var(--color-text-muted)" borderColor="var(--color-border)">
1057
+ <JobLogsLink jobId={step.job_id} slurmJobId={step.executor === 'ssh' ? null : step.slurm_jobid}>{step.job_id}</JobLogsLink>
1058
+ </Table.Cell>
1059
+ </Table.Row>
1060
+ ))}
1061
+ </Table.Body>
1062
+ </Table.Root>
1063
+ )}
1064
+
1065
+ {run.status === 'submitted' && (
1066
+ <Box>
1067
+ <Text fontWeight="semibold" mb={2} color="var(--color-text)">pipeline.log</Text>
1068
+ <Box
1069
+ as="pre"
1070
+ ref={logRef}
1071
+ fontFamily="mono"
1072
+ fontSize="xs"
1073
+ whiteSpace="pre-wrap"
1074
+ wordBreak="break-word"
1075
+ maxH="420px"
1076
+ overflowY="auto"
1077
+ p={3}
1078
+ borderRadius="md"
1079
+ border="1px solid"
1080
+ borderColor="var(--color-border)"
1081
+ bg="var(--color-bg-page)"
1082
+ color="var(--color-text)"
1083
+ >
1084
+ {run.log || '(empty)'}
1085
+ </Box>
1086
+ </Box>
1087
+ )}
1088
+ </VStack>
1089
+ );
1090
+ };
1091
+
1092
+ // List of runs, most recent first
1093
+ const PipelineRunsList: React.FC<{
1094
+ runs: PipelineRunSummary[];
1095
+ activeRunId: string | null;
1096
+ onSelect: (runId: string) => void;
1097
+ }> = ({ runs, activeRunId, onSelect }) => {
1098
+ if (runs.length === 0) {
1099
+ return <Text color="var(--color-text-muted)">No pipeline run yet: use Run on a template.</Text>;
1100
+ }
1101
+ return (
1102
+ <Table.Root size="sm" variant="line">
1103
+ <Table.Header bg="var(--color-bg-header)">
1104
+ <Table.Row>
1105
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Pipeline</Table.ColumnHeader>
1106
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Run</Table.ColumnHeader>
1107
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Started</Table.ColumnHeader>
1108
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Submission</Table.ColumnHeader>
1109
+ </Table.Row>
1110
+ </Table.Header>
1111
+ <Table.Body>
1112
+ {runs.map((run) => (
1113
+ <Table.Row
1114
+ key={run.run_id}
1115
+ cursor="pointer"
1116
+ onClick={() => onSelect(run.run_id)}
1117
+ bg={run.run_id === activeRunId ? 'var(--color-bg-hover)' : undefined}
1118
+ _hover={{ bg: 'var(--color-bg-hover)' }}
1119
+ borderColor="var(--color-border)"
1120
+ >
1121
+ <Table.Cell fontWeight="medium" color="var(--color-text)" borderColor="var(--color-border)">{run.name}</Table.Cell>
1122
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text-muted)" borderColor="var(--color-border)">{run.run_id}</Table.Cell>
1123
+ <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">{new Date(run.started * 1000).toLocaleString()}</Table.Cell>
1124
+ <Table.Cell borderColor="var(--color-border)">
1125
+ <Badge colorPalette={runStateColor(run.status)}>{run.status}</Badge>
1126
+ </Table.Cell>
1127
+ </Table.Row>
1128
+ ))}
1129
+ </Table.Body>
1130
+ </Table.Root>
1131
+ );
1132
+ };
1133
+
1134
+ export const PipelinesView: React.FC = () => {
1135
+ usePageTitle('Pipelines');
1136
+ const queryClient = useQueryClient();
1137
+ const [isCreateOpen, setIsCreateOpen] = useState(false);
1138
+ const onCreateOpen = () => setIsCreateOpen(true);
1139
+ const onCreateClose = () => setIsCreateOpen(false);
1140
+ const [selectedPipeline, setSelectedPipeline] = useState<Pipeline | null>(null);
1141
+ const [selectedRun, setSelectedRun] = useState<PipelineRun | null>(null);
1142
+ const [loadedTemplateData, setLoadedTemplateData] = useState<PipelineTemplateFileData | null>(null);
1143
+ const [tab, setTab] = useState<string>('templates');
1144
+ const [activeRunId, setActiveRunId] = useState<string | null>(null);
1145
+
1146
+ // Queries
1147
+ const { data: profiles = [] } = useQuery({
1148
+ queryKey: ['slurm-profiles'],
1149
+ queryFn: getSlurmProfiles
1150
+ });
1151
+
1152
+ const { data: templates = [] } = useQuery({
1153
+ queryKey: ['slurm-templates'],
1154
+ queryFn: getSlurmTemplates
1155
+ });
1156
+
1157
+ const { data: pipelineTemplateFiles = [] } = useQuery({
1158
+ queryKey: ['pipeline-template-files'],
1159
+ queryFn: getPipelineTemplatesList
1160
+ });
1161
+
1162
+ const { data: pipelineRuns = [] } = useQuery({
1163
+ queryKey: ['pipeline-runs'],
1164
+ queryFn: getPipelineRuns,
1165
+ enabled: tab === 'runs',
1166
+ refetchInterval: 15000,
1167
+ });
1168
+ // the most recent run unless one was picked
1169
+ const shownRunId = activeRunId ?? pipelineRuns[0]?.run_id ?? null;
1170
+
1171
+ // Mutations
1172
+ const savePipelineTemplateMutation = useMutation({
1173
+ mutationFn: savePipelineToFile,
1174
+ onSuccess: () => {
1175
+ queryClient.invalidateQueries({ queryKey: ['pipeline-template-files'] });
1176
+ toaster.create({
1177
+ title: 'Pipeline template saved',
1178
+ type: 'success',
1179
+ duration: 3000
1180
+ });
1181
+ },
1182
+ onError: (error: ApiError) => {
1183
+ toaster.create({
1184
+ title: 'Failed to save pipeline template',
1185
+ description: error.message,
1186
+ type: 'error',
1187
+ duration: 5000
1188
+ });
1189
+ }
1190
+ });
1191
+
1192
+ const loadPipelineTemplateMutation = useMutation({
1193
+ mutationFn: loadPipelineFromFile,
1194
+ onSuccess: () => {
1195
+ toaster.create({
1196
+ title: 'Pipeline template loaded',
1197
+ type: 'success',
1198
+ duration: 3000
1199
+ });
1200
+ },
1201
+ onError: (error: ApiError) => {
1202
+ toaster.create({
1203
+ title: 'Failed to load pipeline template',
1204
+ description: error.message,
1205
+ type: 'error',
1206
+ duration: 5000
1207
+ });
1208
+ }
1209
+ });
1210
+
1211
+ const runPipelineMutation = useMutation({
1212
+ mutationFn: runPipelineTemplate,
1213
+ onSuccess: (data) => {
1214
+ // submitted in the background: follow it in the Runs tab
1215
+ setActiveRunId(data.run_id);
1216
+ setTab('runs');
1217
+ queryClient.invalidateQueries({ queryKey: ['pipeline-runs'] });
1218
+ toaster.create({
1219
+ title: `Pipeline ${data.name} started`,
1220
+ description: `Run ${data.run_id}: submitting the jobs`,
1221
+ type: 'info',
1222
+ duration: 4000
1223
+ });
1224
+ },
1225
+ onError: (error: ApiError) => {
1226
+ toaster.create({
1227
+ title: 'Failed to run pipeline',
1228
+ description: error.message,
1229
+ type: 'error',
1230
+ duration: 8000
1231
+ });
1232
+ }
1233
+ });
1234
+
1235
+ return (
1236
+ <Box p={6} bg="var(--color-bg-page)" minH="100vh">
1237
+ <VStack gap={6} align="stretch">
1238
+ <PipelinesHeader onCreateOpen={onCreateOpen} />
1239
+
1240
+ <Tabs.Root value={tab} onValueChange={(details) => setTab(details.value)}>
1241
+ <Tabs.List>
1242
+ <Tabs.Trigger value="templates">Templates</Tabs.Trigger>
1243
+ <Tabs.Trigger value="runs">Runs</Tabs.Trigger>
1244
+ </Tabs.List>
1245
+
1246
+ <Tabs.Content value="templates" p={0} pt={4}>
1247
+ <Card.Root
1248
+ bg="var(--color-bg-card)"
1249
+ borderColor="var(--color-border)"
1250
+ borderRadius="lg"
1251
+ boxShadow="sm"
1252
+ >
1253
+ <Card.Header borderBottom="1px" borderColor="var(--color-border)">
1254
+ <Heading size="md" color="var(--color-text)">Pipeline Templates</Heading>
1255
+ </Card.Header>
1256
+ <Card.Body pt={4}>
1257
+ <PipelineTemplatesTable
1258
+ pipelineTemplateFiles={pipelineTemplateFiles}
1259
+ onLoadTemplate={(fileName) => loadPipelineTemplateMutation.mutateAsync(fileName)}
1260
+ onTemplateLoaded={(templateData) => {
1261
+ setLoadedTemplateData(templateData);
1262
+ onCreateOpen();
1263
+ }}
1264
+ isLoading={loadPipelineTemplateMutation.isPending}
1265
+ onRun={(fileName) => runPipelineMutation.mutate(fileName)}
1266
+ runningTemplate={runPipelineMutation.isPending ? (runPipelineMutation.variables ?? null) : null}
1267
+ />
1268
+ </Card.Body>
1269
+ </Card.Root>
1270
+
1271
+ </Tabs.Content>
1272
+
1273
+ <Tabs.Content value="runs" p={0} pt={4}>
1274
+ <VStack align="stretch" gap={4}>
1275
+ {shownRunId && (
1276
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
1277
+ <Card.Body>
1278
+ <PipelineRunProgress key={shownRunId} runId={shownRunId} />
1279
+ </Card.Body>
1280
+ </Card.Root>
1281
+ )}
1282
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
1283
+ <Card.Header borderBottom="1px" borderColor="var(--color-border)">
1284
+ <Heading size="md" color="var(--color-text)">Runs</Heading>
1285
+ </Card.Header>
1286
+ <Card.Body pt={4}>
1287
+ <PipelineRunsList runs={pipelineRuns} activeRunId={shownRunId} onSelect={setActiveRunId} />
1288
+ </Card.Body>
1289
+ </Card.Root>
1290
+ </VStack>
1291
+ </Tabs.Content>
1292
+ </Tabs.Root>
1293
+ </VStack>
1294
+
1295
+ <PipelineBuilder
1296
+ isOpen={isCreateOpen}
1297
+ onClose={() => {
1298
+ setLoadedTemplateData(null);
1299
+ onCreateClose();
1300
+ }}
1301
+ profiles={profiles}
1302
+ templates={templates}
1303
+ loadedTemplateData={loadedTemplateData}
1304
+ onSaveTemplate={(data) => savePipelineTemplateMutation.mutate(data)}
1305
+ />
1306
+
1307
+ <PipelineStructureModal
1308
+ pipeline={selectedPipeline}
1309
+ onClose={() => setSelectedPipeline(null)}
1310
+ />
1311
+
1312
+ <PipelineRunDetailsModal
1313
+ run={selectedRun}
1314
+ onClose={() => setSelectedRun(null)}
1315
+ />
1316
+ </Box>
1317
+ );
1318
+ };