@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.
- package/README.md +108 -2
- package/dist/api.d.ts +151 -0
- package/dist/components/AutocompleteInput.d.ts +15 -0
- package/dist/components/MonacoEditor.d.ts +11 -0
- package/dist/components/toaster.d.ts +2 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/constants.d.ts +3 -0
- package/dist/context.d.ts +44 -0
- package/dist/hooks/useColorMode.d.ts +4 -0
- package/dist/hooks/usePageTitle.d.ts +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +5036 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +26 -0
- package/dist/routes.d.ts +22 -0
- package/dist/theme.css +72 -0
- package/dist/toast.d.ts +18 -0
- package/dist/types.d.ts +474 -0
- package/dist/views/AgentActivityView.d.ts +8 -0
- package/dist/views/JobDetails.d.ts +2 -0
- package/dist/views/JobLogs.d.ts +4 -0
- package/dist/views/JobSubmit.d.ts +22 -0
- package/dist/views/JobSubmitView.d.ts +2 -0
- package/dist/views/JobsView.d.ts +4 -0
- package/dist/views/LogDisplay.d.ts +11 -0
- package/dist/views/PipelinesView.d.ts +2 -0
- package/dist/views/ScheduledJobsView.d.ts +2 -0
- package/package.json +70 -4
- package/src/api.ts +602 -0
- package/src/components/AutocompleteInput.tsx +253 -0
- package/src/components/MonacoEditor.tsx +163 -0
- package/src/components/toaster.tsx +38 -0
- package/src/components/tooltip.tsx +52 -0
- package/src/constants.ts +3 -0
- package/src/context.tsx +106 -0
- package/src/hooks/useColorMode.ts +31 -0
- package/src/hooks/usePageTitle.ts +21 -0
- package/src/index.ts +33 -0
- package/src/paths.ts +71 -0
- package/src/routes.tsx +55 -0
- package/src/theme.css +72 -0
- package/src/toast.ts +35 -0
- package/src/types.ts +542 -0
- package/src/views/AgentActivityView.tsx +262 -0
- package/src/views/JobDetails.tsx +675 -0
- package/src/views/JobLogs.tsx +987 -0
- package/src/views/JobSubmit.tsx +1272 -0
- package/src/views/JobSubmitView.tsx +69 -0
- package/src/views/JobsView.tsx +736 -0
- package/src/views/LogDisplay.tsx +171 -0
- package/src/views/PipelinesView.tsx +1318 -0
- package/src/views/ScheduledJobsView.tsx +735 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Link as RouterLink, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import { useBujangPaths } from '../context';
|
|
4
|
+
import type { BujangPaths } from '../paths';
|
|
5
|
+
import {
|
|
6
|
+
Box,
|
|
7
|
+
VStack,
|
|
8
|
+
HStack,
|
|
9
|
+
Heading,
|
|
10
|
+
Text,
|
|
11
|
+
Badge,
|
|
12
|
+
Spinner,
|
|
13
|
+
Code,
|
|
14
|
+
Link,
|
|
15
|
+
Button,
|
|
16
|
+
} from '@chakra-ui/react';
|
|
17
|
+
import { useQuery } from '@tanstack/react-query';
|
|
18
|
+
import { LuBot, LuChevronDown, LuChevronRight } from 'react-icons/lu';
|
|
19
|
+
import { Tooltip } from '../components/tooltip';
|
|
20
|
+
import { getAgentActivity, getAgentSessions } from '../api';
|
|
21
|
+
import type { AgentEvent, AgentSession, AgentTag } from '../types';
|
|
22
|
+
import { usePageTitle } from '../hooks/usePageTitle';
|
|
23
|
+
|
|
24
|
+
const POLL_MS = 5_000;
|
|
25
|
+
|
|
26
|
+
const NOTE_COLORS: Record<string, string> = {
|
|
27
|
+
plan: 'blue',
|
|
28
|
+
progress: 'gray',
|
|
29
|
+
finding: 'green',
|
|
30
|
+
question: 'purple',
|
|
31
|
+
warning: 'orange',
|
|
32
|
+
info: 'gray',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function when(ts: number): string {
|
|
36
|
+
return new Date(ts * 1000).toLocaleString();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ago(ts: number): string {
|
|
40
|
+
const s = Math.max(0, Date.now() / 1000 - ts);
|
|
41
|
+
if (s < 60) return `${Math.round(s)}s ago`;
|
|
42
|
+
if (s < 3600) return `${Math.round(s / 60)}m ago`;
|
|
43
|
+
if (s < 86400) return `${Math.round(s / 3600)}h ago`;
|
|
44
|
+
return `${Math.round(s / 86400)}d ago`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function jobLink(paths: BujangPaths, jrJobId: string, jobId?: unknown) {
|
|
48
|
+
return paths.jobDetails(String(jobId || 0), jrJobId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Badge for the jobs submitted by an agent, its reason on hover */
|
|
52
|
+
export const AgentBadge: React.FC<{ tag?: AgentTag | null }> = ({ tag }) => {
|
|
53
|
+
const paths = useBujangPaths();
|
|
54
|
+
if (!tag) return null;
|
|
55
|
+
return (
|
|
56
|
+
<Tooltip content={tag.reason ? `${tag.agent}: ${tag.reason}` : tag.agent} showArrow>
|
|
57
|
+
<RouterLink to={paths.agent(tag.session)}>
|
|
58
|
+
<Badge colorPalette="purple" variant="subtle" ml={2}>
|
|
59
|
+
<LuBot /> {tag.agent}
|
|
60
|
+
</Badge>
|
|
61
|
+
</RouterLink>
|
|
62
|
+
</Tooltip>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const SessionCard: React.FC<{ s: AgentSession; selected: boolean; onSelect: () => void }> = ({ s, selected, onSelect }) => (
|
|
67
|
+
<Box
|
|
68
|
+
as="button"
|
|
69
|
+
textAlign="left"
|
|
70
|
+
w="100%"
|
|
71
|
+
p={3}
|
|
72
|
+
borderWidth="1px"
|
|
73
|
+
borderRadius="md"
|
|
74
|
+
borderColor={selected ? 'var(--color-primary, #3182ce)' : 'var(--color-border)'}
|
|
75
|
+
bg={selected ? 'var(--color-bg-hover)' : 'transparent'}
|
|
76
|
+
onClick={onSelect}
|
|
77
|
+
>
|
|
78
|
+
<HStack justify="space-between">
|
|
79
|
+
<Text fontWeight="semibold" color="var(--color-text)">{s.agent}</Text>
|
|
80
|
+
<Text fontSize="xs" color="var(--color-text-muted)">{ago(s.last)}</Text>
|
|
81
|
+
</HStack>
|
|
82
|
+
<Text fontFamily="mono" fontSize="xs" color="var(--color-text-muted)">{s.session}</Text>
|
|
83
|
+
<HStack gap={1} mt={1} wrap="wrap">
|
|
84
|
+
<Badge size="sm">{s.calls} calls</Badge>
|
|
85
|
+
{s.writes > 0 && <Badge size="sm" colorPalette="blue">{s.writes} actions</Badge>}
|
|
86
|
+
{s.jobs.length > 0 && <Badge size="sm" colorPalette="purple">{s.jobs.length} jobs</Badge>}
|
|
87
|
+
{s.pipelines.length > 0 && <Badge size="sm" colorPalette="purple">{s.pipelines.length} pipelines</Badge>}
|
|
88
|
+
{s.errors > 0 && <Badge size="sm" colorPalette="red">{s.errors} errors</Badge>}
|
|
89
|
+
</HStack>
|
|
90
|
+
{s.last_note && (
|
|
91
|
+
<Text fontSize="sm" mt={2} color="var(--color-text)" lineClamp={2}>{s.last_note}</Text>
|
|
92
|
+
)}
|
|
93
|
+
</Box>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const ResultLinks: React.FC<{ result?: Record<string, unknown> | null }> = ({ result }) => {
|
|
97
|
+
const paths = useBujangPaths();
|
|
98
|
+
if (!result) return null;
|
|
99
|
+
const jr = result.jr_job_id as string | undefined;
|
|
100
|
+
const run = result.run_id as string | undefined;
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
{jr && (
|
|
104
|
+
<Link asChild color="var(--color-link, #3182ce)" fontFamily="mono" fontSize="sm">
|
|
105
|
+
<RouterLink to={jobLink(paths, jr, result.job_id)}>{jr}{result.job_id ? ` (${String(result.job_id)})` : ''}</RouterLink>
|
|
106
|
+
</Link>
|
|
107
|
+
)}
|
|
108
|
+
{run && (
|
|
109
|
+
<Link asChild color="var(--color-link, #3182ce)" fontFamily="mono" fontSize="sm">
|
|
110
|
+
<RouterLink to={paths.pipelines()}>pipeline {run}</RouterLink>
|
|
111
|
+
</Link>
|
|
112
|
+
)}
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const EventRow: React.FC<{ e: AgentEvent; showSession: boolean }> = ({ e, showSession }) => {
|
|
118
|
+
const [open, setOpen] = useState(false);
|
|
119
|
+
const paths = useBujangPaths();
|
|
120
|
+
|
|
121
|
+
if (e.kind === 'note') {
|
|
122
|
+
const color = NOTE_COLORS[e.level || 'info'] || 'gray';
|
|
123
|
+
return (
|
|
124
|
+
<Box p={3} borderLeftWidth="4px" borderLeftColor={`${color}.400`} bg="var(--color-bg-stripe)" borderRadius="sm">
|
|
125
|
+
<HStack gap={2} mb={1}>
|
|
126
|
+
<Badge colorPalette={color}>{e.level || 'note'}</Badge>
|
|
127
|
+
<Text fontSize="xs" color="var(--color-text-muted)">{when(e.ts)}</Text>
|
|
128
|
+
{showSession && <Text fontSize="xs" color="var(--color-text-muted)">{e.agent}</Text>}
|
|
129
|
+
</HStack>
|
|
130
|
+
<Text whiteSpace="pre-wrap" color="var(--color-text)">{e.message}</Text>
|
|
131
|
+
{e.jobs && e.jobs.length > 0 && (
|
|
132
|
+
<HStack gap={2} mt={1} wrap="wrap">
|
|
133
|
+
{e.jobs.map(j => (
|
|
134
|
+
<Link key={j} asChild fontFamily="mono" fontSize="sm" color="var(--color-link, #3182ce)">
|
|
135
|
+
<RouterLink to={jobLink(paths, j)}>{j}</RouterLink>
|
|
136
|
+
</Link>
|
|
137
|
+
))}
|
|
138
|
+
</HStack>
|
|
139
|
+
)}
|
|
140
|
+
</Box>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const hasDetail = !!(e.request && Object.keys(e.request).length) || !!e.result;
|
|
145
|
+
return (
|
|
146
|
+
<Box px={3} py={2} borderWidth="1px" borderColor="var(--color-border)" borderRadius="sm"
|
|
147
|
+
opacity={e.write ? 1 : 0.75}>
|
|
148
|
+
<HStack gap={2} wrap="wrap">
|
|
149
|
+
{hasDetail ? (
|
|
150
|
+
<Button size="xs" variant="ghost" onClick={() => setOpen(!open)} px={1}>
|
|
151
|
+
{open ? <LuChevronDown /> : <LuChevronRight />}
|
|
152
|
+
</Button>
|
|
153
|
+
) : <Box w="24px" />}
|
|
154
|
+
<Badge colorPalette={!e.ok ? 'red' : e.write ? 'blue' : 'gray'}>{e.tool || e.method}</Badge>
|
|
155
|
+
<Text fontSize="xs" color="var(--color-text-muted)">{when(e.ts)}</Text>
|
|
156
|
+
{showSession && <Text fontSize="xs" color="var(--color-text-muted)">{e.agent}</Text>}
|
|
157
|
+
<Code fontSize="xs">{e.method} {e.path}</Code>
|
|
158
|
+
<Text fontSize="xs" color={e.ok ? 'var(--color-text-muted)' : 'red.500'}>
|
|
159
|
+
{e.status} · {e.duration_ms} ms
|
|
160
|
+
</Text>
|
|
161
|
+
<ResultLinks result={e.result} />
|
|
162
|
+
</HStack>
|
|
163
|
+
{e.reason && (
|
|
164
|
+
<Text mt={1} ml="32px" fontSize="sm" color="var(--color-text)" fontStyle="italic">“{e.reason}”</Text>
|
|
165
|
+
)}
|
|
166
|
+
{!e.ok && typeof e.result?.error === 'string' && (
|
|
167
|
+
<Text mt={1} ml="32px" fontSize="sm" color="red.500" whiteSpace="pre-wrap">{e.result.error as string}</Text>
|
|
168
|
+
)}
|
|
169
|
+
{open && (
|
|
170
|
+
<VStack align="stretch" mt={2} ml="32px" gap={2}>
|
|
171
|
+
{e.request && Object.entries(e.request).map(([k, v]) => (
|
|
172
|
+
<Box key={k}>
|
|
173
|
+
<Text fontSize="xs" fontWeight="semibold" color="var(--color-text-muted)">{k}</Text>
|
|
174
|
+
<Code display="block" whiteSpace="pre-wrap" p={2} fontSize="xs" maxH="400px" overflow="auto">
|
|
175
|
+
{typeof v === 'string' ? v : JSON.stringify(v, null, 2)}
|
|
176
|
+
</Code>
|
|
177
|
+
</Box>
|
|
178
|
+
))}
|
|
179
|
+
{e.result && (
|
|
180
|
+
<Box>
|
|
181
|
+
<Text fontSize="xs" fontWeight="semibold" color="var(--color-text-muted)">result</Text>
|
|
182
|
+
<Code display="block" whiteSpace="pre-wrap" p={2} fontSize="xs">
|
|
183
|
+
{JSON.stringify(e.result, null, 2)}
|
|
184
|
+
</Code>
|
|
185
|
+
</Box>
|
|
186
|
+
)}
|
|
187
|
+
</VStack>
|
|
188
|
+
)}
|
|
189
|
+
</Box>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const AgentActivityView: React.FC = () => {
|
|
194
|
+
usePageTitle('Agent Activity');
|
|
195
|
+
const [params, setParams] = useSearchParams();
|
|
196
|
+
const session = params.get('session') || '';
|
|
197
|
+
const [actionsOnly, setActionsOnly] = useState(true);
|
|
198
|
+
|
|
199
|
+
const { data: sessions, isLoading: loadingSessions } = useQuery<AgentSession[]>({
|
|
200
|
+
queryKey: ['agent-sessions'],
|
|
201
|
+
queryFn: getAgentSessions,
|
|
202
|
+
refetchInterval: POLL_MS,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const { data: events, isLoading: loadingEvents } = useQuery<AgentEvent[]>({
|
|
206
|
+
queryKey: ['agent-activity', session, actionsOnly],
|
|
207
|
+
queryFn: () => getAgentActivity({ session, writes: actionsOnly }),
|
|
208
|
+
refetchInterval: POLL_MS,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// most recent first
|
|
212
|
+
const timeline = useMemo(() => [...(events || [])].reverse(), [events]);
|
|
213
|
+
|
|
214
|
+
const select = (sid: string) => {
|
|
215
|
+
const next = new URLSearchParams(params);
|
|
216
|
+
if (sid) next.set('session', sid); else next.delete('session');
|
|
217
|
+
setParams(next);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<Box p={6}>
|
|
222
|
+
<HStack mb={4} gap={3}>
|
|
223
|
+
<LuBot size={24} />
|
|
224
|
+
<Heading size="lg">Agent Activity</Heading>
|
|
225
|
+
</HStack>
|
|
226
|
+
<Text mb={6} color="var(--color-text-muted)">
|
|
227
|
+
What the agents connected through the bujang MCP server are doing: their notes, the jobs
|
|
228
|
+
they submitted and why, and every call they made to the API. Refreshes every 5 seconds.
|
|
229
|
+
</Text>
|
|
230
|
+
|
|
231
|
+
<HStack align="start" gap={6}>
|
|
232
|
+
<VStack w="340px" flexShrink={0} align="stretch" gap={2}>
|
|
233
|
+
<Button size="sm" variant={session ? 'outline' : 'solid'} onClick={() => select('')}>
|
|
234
|
+
All sessions
|
|
235
|
+
</Button>
|
|
236
|
+
{loadingSessions && <Spinner />}
|
|
237
|
+
{sessions?.map(s => (
|
|
238
|
+
<SessionCard key={s.session} s={s} selected={s.session === session} onSelect={() => select(s.session)} />
|
|
239
|
+
))}
|
|
240
|
+
</VStack>
|
|
241
|
+
|
|
242
|
+
<VStack flex={1} align="stretch" gap={2} minW={0}>
|
|
243
|
+
<HStack justify="space-between">
|
|
244
|
+
<Text fontWeight="semibold" color="var(--color-text)">
|
|
245
|
+
{session ? `Session ${session}` : 'All sessions'}
|
|
246
|
+
</Text>
|
|
247
|
+
<Button size="xs" variant="outline" onClick={() => setActionsOnly(!actionsOnly)}>
|
|
248
|
+
{actionsOnly ? 'Show all calls (incl. monitoring)' : 'Notes and actions only'}
|
|
249
|
+
</Button>
|
|
250
|
+
</HStack>
|
|
251
|
+
{loadingEvents && <Spinner />}
|
|
252
|
+
{timeline.length === 0 && !loadingEvents && (
|
|
253
|
+
<Text fontSize="sm" color="var(--color-text-muted)" fontStyle="italic">Nothing to show.</Text>
|
|
254
|
+
)}
|
|
255
|
+
{timeline.map(e => <EventRow key={e.id} e={e} showSession={!session} />)}
|
|
256
|
+
</VStack>
|
|
257
|
+
</HStack>
|
|
258
|
+
</Box>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export default AgentActivityView;
|