@milabench/bujang 0.1.12 → 0.1.13

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.
@@ -16,10 +16,12 @@ import {
16
16
  NativeSelect,
17
17
  Checkbox,
18
18
  Alert,
19
+ Textarea,
19
20
  } from '@chakra-ui/react';
20
21
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
21
22
  import { Link } from 'react-router-dom';
22
23
  import {
24
+ LuBot,
23
25
  LuDatabase,
24
26
  LuFolder,
25
27
  LuInfo,
@@ -86,6 +88,7 @@ const SECTIONS: { id: string; label: string }[] = [
86
88
  { id: 'secrets', label: 'Secrets' },
87
89
  { id: 'folders', label: 'Folders' },
88
90
  { id: 'database', label: 'Database' },
91
+ { id: 'mcp', label: 'Agents (MCP)' },
89
92
  ];
90
93
 
91
94
  const formatBytes = (n: number | null | undefined) => {
@@ -160,7 +163,7 @@ const OriginBadge: React.FC<{ origin: SettingsOrigin }> = ({ origin }) => {
160
163
  };
161
164
 
162
165
  /** Badges of an editable field: origin, env override, restart needed */
163
- const FieldBadges: React.FC<{ field: SettingsField; fileLabel?: string }> = ({ field }) => (
166
+ const FieldBadges: React.FC<{ field: SettingsField<unknown>; fileLabel?: string }> = ({ field }) => (
164
167
  <HStack gap={1} wrap="wrap">
165
168
  <OriginBadge origin={field.origin} />
166
169
  {field.env && (
@@ -231,6 +234,45 @@ const GeneralCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
231
234
 
232
235
  // ─── Folders ────────────────────────────────────────────────────────
233
236
 
237
+ /** show_examples: list the example scripts and pipelines (built-in, *_example*); saved at once */
238
+ const ExamplesToggle: React.FC<{ info: SettingsInfo }> = ({ info }) => {
239
+ const queryClient = useQueryClient();
240
+ const field = info.fields.show_examples;
241
+ const editable = info.writable && !!info.user_file.path && !field.overridden;
242
+ const save = useMutation({
243
+ mutationFn: (value: boolean) => updateSettings({ show_examples: value }),
244
+ onSuccess: (out) => {
245
+ queryClient.setQueryData(SETTINGS_KEY, out.settings);
246
+ // the dropdowns of the submit, scheduled jobs and pipelines pages
247
+ queryClient.invalidateQueries({ queryKey: ['slurm-templates'] });
248
+ queryClient.invalidateQueries({ queryKey: ['pipeline-template-files'] });
249
+ },
250
+ onError: fail('Could not save show_examples'),
251
+ });
252
+ return (
253
+ <Field.Root>
254
+ <HStack justify="space-between" w="100%" wrap="wrap" gap={2}>
255
+ <Checkbox.Root
256
+ checked={field.value !== false}
257
+ disabled={!editable || save.isPending}
258
+ onCheckedChange={(e) => save.mutate(!!e.checked)}
259
+ >
260
+ <Checkbox.HiddenInput />
261
+ <Checkbox.Control />
262
+ <Checkbox.Label color="var(--color-text)" fontSize="sm">
263
+ List the example scripts and pipelines (show_examples)
264
+ </Checkbox.Label>
265
+ </Checkbox.Root>
266
+ <FieldBadges field={field} />
267
+ </HStack>
268
+ <Field.HelperText color="var(--color-text-muted)">
269
+ The built-in examples and the files named <Mono>*_example*</Mono> (plugins). Unchecked, they are left out
270
+ of the script and pipeline lists but still found by name. Your saved scripts are always listed.
271
+ </Field.HelperText>
272
+ </Field.Root>
273
+ );
274
+ };
275
+
234
276
  export const FoldersCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
235
277
  const queryClient = useQueryClient();
236
278
  const { local_cache, workdir } = info.fields;
@@ -309,6 +351,8 @@ export const FoldersCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
309
351
  </HStack>
310
352
  )}
311
353
 
354
+ <ExamplesToggle info={info} />
355
+
312
356
  <KV
313
357
  rows={[
314
358
  [
@@ -928,6 +972,91 @@ export const SecretsCard: React.FC<{ writable: boolean }> = ({ writable }) => {
928
972
  );
929
973
  };
930
974
 
975
+ // ─── Agents (MCP) ───────────────────────────────────────────────────
976
+
977
+ /** mcp_instructions: what the MCP server tells the agents when they connect */
978
+ const McpCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
979
+ const queryClient = useQueryClient();
980
+ const field = info.fields.mcp_instructions;
981
+ const fallback = info.general.mcp.default_instructions;
982
+ const initial = field.value ?? fallback;
983
+ const [text, setText] = useState(initial);
984
+ useEffect(() => setText(initial), [initial]);
985
+
986
+ const save = useMutation({
987
+ // the default text sent back: nothing to keep in the user file
988
+ mutationFn: (value: string | null) =>
989
+ updateSettings({ mcp_instructions: value && value.trim() !== fallback.trim() ? value : null }),
990
+ onSuccess: (out) => {
991
+ queryClient.setQueryData(SETTINGS_KEY, out.settings);
992
+ toaster.create({
993
+ title: 'Agent instructions saved',
994
+ description: out.applied.length
995
+ ? 'Agents get them from their next connection.'
996
+ : 'They are overridden: see the badges.',
997
+ type: 'success',
998
+ });
999
+ },
1000
+ onError: fail('Could not save the agent instructions'),
1001
+ });
1002
+
1003
+ const editable = info.writable && !!info.user_file.path && !field.overridden && field.editable;
1004
+ const isDefault = field.value == null;
1005
+ return (
1006
+ <Section
1007
+ id="mcp"
1008
+ icon={<LuBot />}
1009
+ title="Agents (MCP)"
1010
+ subtitle={<>
1011
+ What the MCP server tells an agent when it connects: how to use the tools, what to log, your house
1012
+ rules. It is sent at the start of every agent session, keep it short. Sessions already open keep the
1013
+ instructions they started with.
1014
+ </>}
1015
+ >
1016
+ <Field.Root>
1017
+ <HStack justify="space-between" w="100%" wrap="wrap" gap={2}>
1018
+ <Field.Label color="var(--color-text)">
1019
+ Instructions (<Mono>mcp_instructions</Mono>){isDefault ? ', the default ones' : ''}
1020
+ </Field.Label>
1021
+ <FieldBadges field={field} />
1022
+ </HStack>
1023
+ <Textarea
1024
+ {...inputStyle}
1025
+ size="sm"
1026
+ fontFamily="mono"
1027
+ rows={8}
1028
+ value={text}
1029
+ maxLength={4000}
1030
+ disabled={!editable || save.isPending}
1031
+ onChange={(e) => setText(e.target.value)}
1032
+ />
1033
+ <Field.HelperText color="var(--color-text-muted)">
1034
+ {text.length} / 4000 characters. Empty or unchanged: the default instructions.
1035
+ </Field.HelperText>
1036
+ </Field.Root>
1037
+ <HStack gap={2}>
1038
+ <Button
1039
+ size="sm"
1040
+ colorPalette="blue"
1041
+ disabled={!editable || text === initial || save.isPending}
1042
+ loading={save.isPending}
1043
+ onClick={() => save.mutate(text)}
1044
+ >
1045
+ Save
1046
+ </Button>
1047
+ <Button
1048
+ size="sm"
1049
+ variant="outline"
1050
+ disabled={!editable || isDefault || save.isPending}
1051
+ onClick={() => save.mutate(null)}
1052
+ >
1053
+ Back to the default
1054
+ </Button>
1055
+ </HStack>
1056
+ </Section>
1057
+ );
1058
+ };
1059
+
931
1060
  // ─── Page ───────────────────────────────────────────────────────────
932
1061
 
933
1062
  export const SettingsView: React.FC = () => {
@@ -965,6 +1094,7 @@ export const SettingsView: React.FC = () => {
965
1094
  <SecretsCard writable={info.writable} />
966
1095
  <FoldersCard info={info} />
967
1096
  <DatabaseCard info={info} />
1097
+ <McpCard info={info} />
968
1098
  </VStack>
969
1099
  )}
970
1100
  </Box>