@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,171 @@
1
+ import React, { useRef, useState, useEffect } from 'react';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import {
4
+ Box,
5
+ Heading,
6
+ Text,
7
+ HStack,
8
+ Card,
9
+ Spinner,
10
+ Alert,
11
+ Badge,
12
+ Code
13
+ } from '@chakra-ui/react';
14
+
15
+ interface LogDisplayProps {
16
+ logType: 'stdout' | 'stderr';
17
+ jrJobId: string;
18
+ isJobFinished: boolean;
19
+ formatFileSize: (bytes: number) => string;
20
+ fetchLogData: (jrJobId: string, start?: number, end?: number) => Promise<string>;
21
+ getSlurmJobLogSize: (jrJobId: string) => Promise<number>;
22
+ }
23
+
24
+ export const LogDisplay: React.FC<LogDisplayProps> = ({
25
+ logType,
26
+ jrJobId,
27
+ isJobFinished,
28
+ formatFileSize,
29
+ fetchLogData,
30
+ getSlurmJobLogSize
31
+ }) => {
32
+ // Internal state for truncation and log size
33
+ const [isTruncated, setIsTruncated] = useState(false);
34
+ const [logSize, setLogSize] = useState<number | null>(null);
35
+ // Track previous job finished state to detect when job just finished
36
+ const [prevIsJobFinished, setPrevIsJobFinished] = useState(isJobFinished);
37
+ const logRef = useRef<HTMLDivElement>(null);
38
+
39
+ const displayName = logType === 'stdout' ? 'Standard Output (stdout)' : 'Standard Error (stderr)';
40
+ const logBgColor = logType === 'stdout' ? 'var(--color-log-stdout-bg)' : 'var(--color-log-stderr-bg)';
41
+ const logTextColor = logType === 'stdout' ? 'var(--color-log-stdout-text)' : 'var(--color-log-stderr-text)';
42
+
43
+ const MAX_SIZE = 5 * 1024 * 1024; // 5MB
44
+ const CHUNK_SIZE = 500 * 1024;
45
+
46
+ // Custom function to load logs with chunked loading for large files
47
+ const loadLogsChunked = async (jrJobId: string): Promise<string> => {
48
+ // Get log size first
49
+ const logSize = await getSlurmJobLogSize(jrJobId);
50
+ setLogSize(logSize);
51
+
52
+ // If size is small enough, load normally
53
+ if (logSize <= MAX_SIZE) {
54
+ setIsTruncated(false);
55
+ return await fetchLogData(jrJobId);
56
+ }
57
+
58
+ // For large files, load only the last 5MB to avoid browser performance issues
59
+ const start = Math.max(0, logSize - CHUNK_SIZE);
60
+ const end = logSize * 2;
61
+ setIsTruncated(true);
62
+
63
+ return await fetchLogData(jrJobId, start, end);
64
+ };
65
+
66
+ // Get log data with auto-refresh every 30 seconds
67
+ const {
68
+ data: logData,
69
+ isLoading,
70
+ error,
71
+ refetch
72
+ } = useQuery({
73
+ queryKey: [`slurm-job-${logType}-full`, jrJobId],
74
+ queryFn: () => loadLogsChunked(jrJobId),
75
+ enabled: !!jrJobId,
76
+ refetchInterval: isJobFinished ? false : 30000, // Disable refresh if job is finished
77
+ refetchIntervalInBackground: true,
78
+ });
79
+
80
+ // Effect to perform final refresh when job finishes
81
+ useEffect(() => {
82
+ // If job just finished (changed from false to true), do a final refresh
83
+ if (!prevIsJobFinished && isJobFinished) {
84
+ console.log(`Job finished, performing final ${logType} refresh`);
85
+ // Wait a short delay to ensure any final output is written
86
+ setTimeout(() => {
87
+ refetch();
88
+ }, 2000); // 2 second delay to allow final output to be written
89
+ }
90
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- tracks the previous value of isJobFinished to detect the false->true transition that triggers a delayed (timer-based) refetch; not a pure derivation.
91
+ setPrevIsJobFinished(isJobFinished);
92
+ }, [isJobFinished, prevIsJobFinished, refetch, logType]);
93
+
94
+ // Auto-scroll effect
95
+ useEffect(() => {
96
+ if (logData && logRef.current) {
97
+ logRef.current.scrollTop = logRef.current.scrollHeight;
98
+ }
99
+ }, [logData]);
100
+
101
+ return (
102
+ <Card.Root bg="var(--color-bg-card)" padding="10px" border="1px solid" borderColor="var(--color-border)" className="logview" flex={1} minH={0} display="flex" flexDirection="column">
103
+ <Card.Header paddingBottom="5px" flexShrink={0}>
104
+ <HStack justify="space-between">
105
+ <Heading size="md">{displayName}</Heading>
106
+
107
+ <HStack justify="space-between">
108
+ {isTruncated && logSize && (
109
+ <Badge colorScheme="orange">
110
+ Truncated ({formatFileSize(CHUNK_SIZE)}/{formatFileSize(logSize)})
111
+ </Badge>
112
+ )}
113
+ <Badge colorScheme={isJobFinished ? "gray" : "green"}>
114
+ {isJobFinished ? "Manual refresh" : "Auto-refresh"}
115
+ </Badge>
116
+ </HStack>
117
+ </HStack>
118
+ </Card.Header>
119
+ <Card.Body flex="1" minH={0} display="flex" flexDirection="column">
120
+ {error ? (
121
+ <Alert.Root status="error">
122
+ <Alert.Indicator />
123
+ <Alert.Content>
124
+ <Alert.Title>Error loading {logType}</Alert.Title>
125
+ <Alert.Description>
126
+ {error?.message || `Failed to load ${logType}`}
127
+ </Alert.Description>
128
+ </Alert.Content>
129
+ </Alert.Root>
130
+ ) : isLoading ? (
131
+ <Box textAlign="center" py={8}>
132
+ <Spinner size="lg" />
133
+ <Text mt={4}>Loading {logType}...</Text>
134
+ </Box>
135
+ ) : (
136
+ <Box flex="1" minH={0} display="flex" flexDirection="column">
137
+ {logData ? (
138
+ <Code
139
+ ref={logRef}
140
+ display="block"
141
+ whiteSpace="pre-wrap"
142
+ fontSize="sm"
143
+ p={4}
144
+ bg={logBgColor}
145
+ color={logTextColor}
146
+ borderRadius="md"
147
+ overflowY="auto"
148
+ fontFamily="mono"
149
+ flex="1"
150
+ minH={0}
151
+ onCopy={(event) => {
152
+ const selection = window.getSelection();
153
+ if (selection) {
154
+ event.clipboardData.setData("text/plain", selection.toString());
155
+ }
156
+ event.preventDefault();
157
+ }}
158
+ >
159
+ {logData}
160
+ </Code>
161
+ ) : (
162
+ <Text color="var(--color-text-muted)" textAlign="center" py={8}>
163
+ No {logType} content available
164
+ </Text>
165
+ )}
166
+ </Box>
167
+ )}
168
+ </Card.Body>
169
+ </Card.Root>
170
+ );
171
+ };