@milabench/bujang 0.1.7 → 0.1.9

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.
package/dist/paths.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { IconType } from 'react-icons';
2
2
  /** Names of the bujang views. */
3
- export type BujangView = 'jobs' | 'submitJob' | 'jobDetails' | 'jobLogs' | 'pipelines' | 'pipelineDetails' | 'scheduled' | 'agent' | 'settings';
3
+ export type BujangView = 'jobs' | 'submitJob' | 'jobDetails' | 'jobLogs' | 'pipelines' | 'pipelineDetails' | 'scheduled' | 'agent' | 'janitor' | 'settings';
4
4
  /** URL builders the views use to link to each other. */
5
5
  export interface BujangPaths {
6
6
  jobs: () => string;
@@ -13,8 +13,13 @@ export interface BujangPaths {
13
13
  scheduled: () => string;
14
14
  /** Agent activity, optionally filtered on one session. */
15
15
  agent: (session?: string) => string;
16
- /** Settings: folders, database, SSH, secrets (read-only unless the server allows edits). */
17
- settings: () => string;
16
+ /** Janitor: background tasks (running, periodic, history), sync queue, cleanups. `section`: a card id. */
17
+ janitor: (section?: string) => string;
18
+ /**
19
+ * Settings: folders, database, SSH, secrets (read-only unless the server allows edits).
20
+ * `section` links to one card: general, folders, database, ssh, secrets.
21
+ */
22
+ settings: (section?: string) => string;
18
23
  }
19
24
  /** Default URL layout (react-router patterns), relative to the host's basePath. */
20
25
  export declare const defaultRoutePatterns: Record<BujangView, string>;
package/dist/routes.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface BujangRouteObject {
15
15
  /**
16
16
  * Route objects for the default bujang URL layout under `basePath`:
17
17
  * /jobs, /jobs/submit, /jobrunner/:slurmJobId/:jrJobId, /joblogs/:slurmJobId/:jrJobId,
18
- * /pipelines, /pipelines/:pipelineName, /scheduled, /agent, /settings.
18
+ * /pipelines, /pipelines/:pipelineName, /scheduled, /agent, /janitor, /settings.
19
19
  */
20
20
  export declare function bujangRoutes(options?: BujangRoutesOptions): BujangRouteObject[];
21
21
  /** The same routes as <Route> elements, to drop inside a host's <Routes>. */
package/dist/types.d.ts CHANGED
@@ -128,6 +128,13 @@ export interface SlurmJobSubmitRequest {
128
128
  nodelist?: string;
129
129
  dependency?: [string, string][];
130
130
  }
131
+ /** A file attached to a submission: lands in <job folder>/input/<name> ($JR_INPUT_DIR). */
132
+ export interface JobAttachment {
133
+ /** Relative path, sub folders allowed (data/train.csv). */
134
+ name: string;
135
+ /** base64 */
136
+ content: string;
137
+ }
131
138
  export interface SlurmJobSubmitResponse {
132
139
  success: boolean;
133
140
  job_id?: string;
@@ -420,6 +427,8 @@ export interface PushFolderResponse {
420
427
  }
421
428
  export interface EarlySyncResponse {
422
429
  status: "ok" | "notok";
430
+ /** Why the rsync from the compute node failed (its stderr), when it ran */
431
+ error?: string | null;
423
432
  }
424
433
  export interface ScheduledJob {
425
434
  _id: number;
@@ -534,6 +543,19 @@ export interface SettingsDatabaseTable {
534
543
  name: string;
535
544
  exists: boolean;
536
545
  rows: number | null;
546
+ /** What the table holds (known tables only). */
547
+ description?: string | null;
548
+ }
549
+ /** A SQLite file of the local cache (state.db, fakeslurm.db). */
550
+ export interface SettingsLocalDatabase {
551
+ name: string;
552
+ path: string;
553
+ description: string;
554
+ exists: boolean;
555
+ /** Bytes, with the -wal / -shm files. */
556
+ size: number | null;
557
+ tables: SettingsDatabaseTable[];
558
+ error: string | null;
537
559
  }
538
560
  export interface SettingsDatabase {
539
561
  host_provided: boolean;
@@ -548,6 +570,8 @@ export interface SettingsDatabase {
548
570
  enabled: boolean;
549
571
  tables: SettingsDatabaseTable[];
550
572
  error: string | null;
573
+ /** The SQLite files of the local cache, whatever the database above is. */
574
+ local?: SettingsLocalDatabase[];
551
575
  }
552
576
  export interface SettingsMcp {
553
577
  /** Served by this app itself (bujang serve), at `path`. */
@@ -709,6 +733,39 @@ export interface SshTestResponse {
709
733
  file: string | null;
710
734
  results: SshCheckResult[];
711
735
  }
736
+ /** An ssh login started from the UI (POST /ssh/login): ssh's prompts (MFA, password, host key) come back here */
737
+ export type SshLoginState = 'starting' | 'prompt' | 'waiting' | 'ok' | 'failed' | 'cancelled';
738
+ export interface SshLogin {
739
+ id: string;
740
+ host: string;
741
+ cluster: string | null;
742
+ state: SshLoginState;
743
+ /** the prompt waiting for an answer (state "prompt") */
744
+ prompt: string | null;
745
+ /** secret: masked input; confirm: a yes / no question (host key) */
746
+ kind: 'secret' | 'confirm' | null;
747
+ /** what ssh printed so far: the instructions of the server (Duo menu, ...) */
748
+ info: string[];
749
+ message: string;
750
+ prompts: number;
751
+ started: number;
752
+ finished: number | null;
753
+ }
754
+ /** GET /ssh/connections: the ssh hosts of the clusters and their shared connection (ControlMaster) */
755
+ export interface SshConnection {
756
+ host: string;
757
+ cluster: string;
758
+ /** the login node of the cluster (else an ssh executor host: data mover) */
759
+ login_node: boolean;
760
+ /** open: connected; no: not connected; none: the ssh config keeps no shared connection for the host */
761
+ master: 'open' | 'no' | 'none';
762
+ login: SshLogin | null;
763
+ }
764
+ export interface SshConnections {
765
+ writable: boolean;
766
+ read_only_reason: string | null;
767
+ hosts: SshConnection[];
768
+ }
712
769
  /** GET /update: the running version against the latest release on PyPI (checked once a day). */
713
770
  export interface UpdateCheck {
714
771
  /** BUJANG_UPDATE_CHECK=0 turns the check off */
@@ -801,6 +858,133 @@ export interface SyncStatus {
801
858
  /** seconds between two background syncs, null when the server does not run them */
802
859
  interval: number | null;
803
860
  jobs: number;
804
- synced?: Record<string, boolean>;
861
+ /** per cluster: true synced, false failed, 'recent': not asked, a full rsync ran less than min_refresh_interval ago */
862
+ synced?: Record<string, boolean | 'recent'>;
805
863
  skipped?: string;
806
864
  }
865
+ export type JanitorStatus = 'ok' | 'failed' | 'timeout' | 'skipped';
866
+ /** A background task running now. */
867
+ export interface JanitorTask {
868
+ id: string;
869
+ name: string;
870
+ /** rsync | scp | ssh | periodic | cleanup | request | task */
871
+ kind: string;
872
+ cluster: string | null;
873
+ started: number;
874
+ pid: number | null;
875
+ detail: Record<string, unknown>;
876
+ }
877
+ /** One finished task. */
878
+ export interface JanitorRun {
879
+ id: string;
880
+ name: string;
881
+ kind: string;
882
+ cluster: string | null;
883
+ /** rsync / scp: pull (cluster -> here) or push */
884
+ direction: 'pull' | 'push' | null;
885
+ started: number;
886
+ ended: number;
887
+ duration: number;
888
+ /** Seconds spent waiting for the cluster's sync queue. */
889
+ waited: number | null;
890
+ status: JanitorStatus;
891
+ error: string | null;
892
+ detail: Record<string, unknown>;
893
+ /** Bytes received / sent (rsync --stats, scp, ssh output); a sync or book keeping adds up its rsyncs. */
894
+ bytes_in: number | null;
895
+ bytes_out: number | null;
896
+ }
897
+ export interface JanitorStat {
898
+ name: string;
899
+ kind: string;
900
+ cluster: string | null;
901
+ runs: number;
902
+ failures: number;
903
+ total: number;
904
+ mean: number;
905
+ p95: number | null;
906
+ max: number;
907
+ waited: number;
908
+ last: number;
909
+ last_status: JanitorStatus | null;
910
+ bytes_in: number | null;
911
+ bytes_out: number | null;
912
+ }
913
+ export interface JanitorQueueTicket {
914
+ id: string;
915
+ cluster: string;
916
+ what: string | null;
917
+ queued: number;
918
+ pid: number | null;
919
+ /** null: waiting its turn */
920
+ started: number | null;
921
+ expires: number;
922
+ }
923
+ export interface JanitorPeriodic {
924
+ /** APScheduler job id, null when only its history is known */
925
+ id: string | null;
926
+ name: string;
927
+ interval: number | null;
928
+ next_run: number | null;
929
+ last: JanitorRun | null;
930
+ }
931
+ export interface JanitorOverview {
932
+ now: number;
933
+ history_days: number;
934
+ active: JanitorTask[];
935
+ queue: JanitorQueueTicket[];
936
+ periodic: JanitorPeriodic[];
937
+ stats: {
938
+ day: JanitorStat[];
939
+ week: JanitorStat[];
940
+ };
941
+ /** Calls to each cluster over the last day (rsync, scp, ssh). */
942
+ clusters: Record<string, {
943
+ calls: number;
944
+ rsyncs: number;
945
+ seconds: number;
946
+ failures: number;
947
+ waited: number;
948
+ bytes_in: number;
949
+ bytes_out: number;
950
+ }>;
951
+ archive_roots: string[];
952
+ }
953
+ export interface JanitorCleanupInfo {
954
+ organizers: {
955
+ name: string;
956
+ values: {
957
+ value: string;
958
+ jobs: number;
959
+ }[];
960
+ }[];
961
+ }
962
+ export interface JanitorSkipped {
963
+ jr_job_id: string;
964
+ value?: string;
965
+ reason: string;
966
+ }
967
+ export interface JanitorArchiveItem {
968
+ jr_job_id: string;
969
+ value: string;
970
+ cluster: string | null;
971
+ from: string;
972
+ to: string;
973
+ }
974
+ export interface JanitorArchiveResult {
975
+ would_move?: JanitorArchiveItem[];
976
+ moved?: JanitorArchiveItem[];
977
+ skipped: JanitorSkipped[];
978
+ }
979
+ export interface JanitorStaleItem {
980
+ jr_job_id: string;
981
+ cluster: string | null;
982
+ folder: string;
983
+ modified: number | null;
984
+ state: string | string[] | null;
985
+ }
986
+ export interface JanitorStaleResult {
987
+ would_remove?: JanitorStaleItem[];
988
+ removed?: JanitorStaleItem[];
989
+ skipped: JanitorSkipped[];
990
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function formatDuration(s: number | null | undefined): string;
3
+ export declare function formatBytes(n: number | null | undefined): string;
4
+ export declare const JanitorView: React.FC;
5
+ export default JanitorView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milabench/bujang",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/api.ts CHANGED
@@ -41,6 +41,14 @@ import type {
41
41
  SshPlan,
42
42
  SshPlanRequest,
43
43
  SshTestResponse,
44
+ SshConnections,
45
+ SshLogin,
46
+ JobAttachment,
47
+ JanitorOverview,
48
+ JanitorRun,
49
+ JanitorCleanupInfo,
50
+ JanitorArchiveResult,
51
+ JanitorStaleResult,
44
52
  } from './types';
45
53
 
46
54
  export const DEFAULT_API_BASE = '/api/slurm';
@@ -369,6 +377,8 @@ export const submitSlurmJob = async (request: {
369
377
  export?: string;
370
378
  nodelist?: string;
371
379
  dependency?: [string, string][];
380
+ /** Files for the job: <job folder>/input/<name> on the cluster before it starts ($JR_INPUT_DIR). */
381
+ files?: JobAttachment[];
372
382
  }): Promise<SlurmJobSubmitResponse> => {
373
383
  try {
374
384
  const response = await api.post('/submit', request);
@@ -634,6 +644,44 @@ export const testSshConnections = async (
634
644
  };
635
645
 
636
646
 
647
+ /** The ssh hosts of the clusters and whether their shared connection is open (local check, fast). */
648
+ export const getSshConnections = async (cluster?: string): Promise<SshConnections> => {
649
+ try {
650
+ const response = await api.get('/ssh/connections', { params: { cluster: cluster || undefined } });
651
+ return response.data;
652
+ } catch (error) { return handleError(error); }
653
+ };
654
+
655
+ /** Open the shared connection of a host (or of the login node of `cluster`); poll getSshLogin for the prompts. */
656
+ export const startSshLogin = async (request: { host?: string; cluster?: string }): Promise<SshLogin> => {
657
+ try {
658
+ const response = await api.post('/ssh/login', request);
659
+ return response.data;
660
+ } catch (error) { return handleError(error); }
661
+ };
662
+
663
+ export const getSshLogin = async (id: string): Promise<SshLogin> => {
664
+ try {
665
+ const response = await api.get(`/ssh/login/${encodeURIComponent(id)}`);
666
+ return response.data;
667
+ } catch (error) { return handleError(error); }
668
+ };
669
+
670
+ /** The answer of the waiting prompt (MFA passcode, ...): handed to ssh, never stored. */
671
+ export const answerSshLogin = async (id: string, answer: string): Promise<SshLogin> => {
672
+ try {
673
+ const response = await api.post(`/ssh/login/${encodeURIComponent(id)}/answer`, { answer });
674
+ return response.data;
675
+ } catch (error) { return handleError(error); }
676
+ };
677
+
678
+ export const cancelSshLogin = async (id: string): Promise<SshLogin> => {
679
+ try {
680
+ const response = await api.post(`/ssh/login/${encodeURIComponent(id)}/cancel`, {});
681
+ return response.data;
682
+ } catch (error) { return handleError(error); }
683
+ };
684
+
637
685
  // Pipeline template file management (matching server endpoints)
638
686
  export const getPipelineTemplatesList = async (): Promise<string[]> => {
639
687
  try {
@@ -806,3 +854,65 @@ export const getAgentActivity = async (
806
854
  return response.data;
807
855
  } catch (error) { return handleError(error); }
808
856
  };
857
+
858
+ /** A browser File as a submission attachment (base64). */
859
+ export const fileToAttachment = (file: File, name: string = file.name): Promise<JobAttachment> =>
860
+ new Promise((resolve, reject) => {
861
+ const reader = new FileReader();
862
+ reader.onerror = () => reject(reader.error);
863
+ reader.onload = () => {
864
+ const url = String(reader.result);
865
+ resolve({ name, content: url.slice(url.indexOf(',') + 1) });
866
+ };
867
+ reader.readAsDataURL(file);
868
+ });
869
+
870
+ // ─── Janitor ───────────────────────────────────────────────────────
871
+
872
+ export const getJanitor = async (): Promise<JanitorOverview> => {
873
+ try {
874
+ const response = await api.get('/janitor');
875
+ return response.data;
876
+ } catch (error) { return handleError(error); }
877
+ };
878
+
879
+ export const getJanitorHistory = async (
880
+ params: { name?: string; kind?: string; cluster?: string; status?: string; since?: number; limit?: number } = {},
881
+ ): Promise<{ runs: JanitorRun[] }> => {
882
+ try {
883
+ const response = await api.get('/janitor/history', { params });
884
+ return response.data;
885
+ } catch (error) { return handleError(error); }
886
+ };
887
+
888
+ export const getJanitorCleanup = async (): Promise<JanitorCleanupInfo> => {
889
+ try {
890
+ const response = await api.get('/janitor/cleanup');
891
+ return response.data;
892
+ } catch (error) { return handleError(error); }
893
+ };
894
+
895
+ export const janitorArchive = async (
896
+ body: { organizer: string; value?: string | null; dry_run: boolean },
897
+ ): Promise<JanitorArchiveResult> => {
898
+ try {
899
+ const response = await api.post('/janitor/archive', body);
900
+ return response.data;
901
+ } catch (error) { return handleError(error); }
902
+ };
903
+
904
+ export const janitorRemoveStale = async (
905
+ body: { older_than_days: number; dry_run: boolean },
906
+ ): Promise<JanitorStaleResult> => {
907
+ try {
908
+ const response = await api.post('/janitor/remove-stale', body);
909
+ return response.data;
910
+ } catch (error) { return handleError(error); }
911
+ };
912
+
913
+ export const janitorPrune = async (): Promise<{ removed: number }> => {
914
+ try {
915
+ const response = await api.post('/janitor/prune');
916
+ return response.data;
917
+ } catch (error) { return handleError(error); }
918
+ };
@@ -0,0 +1,120 @@
1
+ import React, { useEffect } from 'react';
2
+ import { Box, Card, Heading, HStack, IconButton, Text, VStack } from '@chakra-ui/react';
3
+ import { useLocation, useNavigate } from 'react-router-dom';
4
+ import { LuLink } from 'react-icons/lu';
5
+ import { toaster } from '../toast';
6
+ import { Tooltip } from './tooltip';
7
+
8
+ /**
9
+ * Scroll to the card named by the URL hash (/settings#ssh) once the page has its content
10
+ * (`ready`), and again when the hash changes.
11
+ */
12
+ export function useHashScroll(ready: boolean = true) {
13
+ const { hash } = useLocation();
14
+ useEffect(() => {
15
+ if (!ready || !hash) return;
16
+ const id = decodeURIComponent(hash.slice(1));
17
+ // after the cards have rendered
18
+ const timer = window.setTimeout(() => {
19
+ document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
20
+ }, 50);
21
+ return () => window.clearTimeout(timer);
22
+ }, [hash, ready]);
23
+ }
24
+
25
+ /**
26
+ * A card with an anchor: `id` is its URL hash (/settings#ssh). The link button next to the title
27
+ * goes there and copies the full link, to give someone the card itself. The card the URL names is
28
+ * outlined.
29
+ */
30
+ export const LinkableCard: React.FC<{
31
+ id: string;
32
+ icon?: React.ReactNode;
33
+ title: string;
34
+ subtitle?: React.ReactNode;
35
+ actions?: React.ReactNode;
36
+ children: React.ReactNode;
37
+ }> = ({ id, icon, title, subtitle, actions, children }) => {
38
+ const location = useLocation();
39
+ const navigate = useNavigate();
40
+ const targeted = decodeURIComponent(location.hash.slice(1)) === id;
41
+
42
+ const copyLink = () => {
43
+ navigate({ pathname: location.pathname, search: location.search, hash: id }, { replace: true });
44
+ const url = `${window.location.origin}${location.pathname}${location.search}#${encodeURIComponent(id)}`;
45
+ navigator.clipboard?.writeText(url).then(
46
+ () => toaster.create({ title: 'Link copied', description: url, type: 'success', duration: 2500 }),
47
+ () => undefined,
48
+ );
49
+ };
50
+
51
+ return (
52
+ <Card.Root
53
+ id={id}
54
+ bg="var(--color-bg-card)"
55
+ border="1px solid"
56
+ borderColor={targeted ? 'var(--color-primary)' : 'var(--color-border)'}
57
+ boxShadow={targeted ? '0 0 0 1px var(--color-primary)' : undefined}
58
+ scrollMarginTop="16px"
59
+ className="bujang-linkable-card"
60
+ >
61
+ <Card.Header pb={2}>
62
+ <HStack justify="space-between" align="start" gap={4} wrap="wrap">
63
+ <VStack align="start" gap={1}>
64
+ <HStack gap={2} color="var(--color-text)">
65
+ {icon}
66
+ <Heading size="md">{title}</Heading>
67
+ <Tooltip content="Link to this card (copied)" showArrow>
68
+ <IconButton
69
+ aria-label={`Link to ${title}`}
70
+ size="2xs"
71
+ variant="ghost"
72
+ color="var(--color-text-muted)"
73
+ onClick={copyLink}
74
+ >
75
+ <LuLink />
76
+ </IconButton>
77
+ </Tooltip>
78
+ </HStack>
79
+ {subtitle && <Text fontSize="sm" color="var(--color-text-muted)">{subtitle}</Text>}
80
+ </VStack>
81
+ {actions}
82
+ </HStack>
83
+ </Card.Header>
84
+ <Card.Body pt={2}>
85
+ <VStack align="stretch" gap={4}>{children}</VStack>
86
+ </Card.Body>
87
+ </Card.Root>
88
+ );
89
+ };
90
+
91
+ /** Numbered steps of a how-to (a card that walks someone through a setup). */
92
+ export const Steps: React.FC<{ steps: { title: React.ReactNode; body?: React.ReactNode }[] }> = ({ steps }) => (
93
+ <VStack align="stretch" gap={2}>
94
+ {steps.map((step, i) => (
95
+ <HStack key={i} align="start" gap={3}>
96
+ <Box
97
+ flexShrink={0}
98
+ w="22px"
99
+ h="22px"
100
+ borderRadius="full"
101
+ bg="var(--color-primary)"
102
+ color="white"
103
+ fontSize="xs"
104
+ fontWeight="bold"
105
+ display="flex"
106
+ alignItems="center"
107
+ justifyContent="center"
108
+ >
109
+ {i + 1}
110
+ </Box>
111
+ <Box minW={0}>
112
+ <Text fontSize="sm" fontWeight="semibold" color="var(--color-text)">{step.title}</Text>
113
+ {step.body && <Box fontSize="sm" color="var(--color-text-muted)">{step.body}</Box>}
114
+ </Box>
115
+ </HStack>
116
+ ))}
117
+ </VStack>
118
+ );
119
+
120
+ export default LinkableCard;