@bevel-software/platform-core-frontend 0.19.0 → 0.21.0
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/package.json +2 -2
- package/src/core/CoreAppShell.tsx +6 -2
- package/src/modules/access/hooks/useFileAccess.ts +2 -2
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
- package/src/modules/audit/components/AuditLogPage.tsx +373 -0
- package/src/modules/audit/components/principal-grouping.ts +49 -0
- package/src/modules/audit/services/audit.api.ts +98 -0
- package/src/modules/auth/components/LoginScreen.tsx +1 -0
- package/src/modules/git/components/BranchSwitcher.tsx +9 -3
- package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
- package/src/modules/git/components/PullNeededBanner.tsx +2 -2
- package/src/modules/git/services/error-messages.ts +2 -2
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
- package/src/modules/layout/components/SidebarFrame.tsx +26 -9
- package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
- package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
- package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
- package/src/modules/library/__tests__/ToolPage.test.tsx +20 -0
- package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
- package/src/modules/library/__tests__/title-row-actions.ts +43 -0
- package/src/modules/library/components/PluginIndexRow.tsx +37 -20
- package/src/modules/library/components/PluginPage.tsx +115 -3
- package/src/modules/library/components/tool-page/ToolPage.tsx +25 -17
- package/src/modules/library/routes/library-paths.ts +9 -2
- package/src/modules/library/services/plugins.api.ts +45 -0
- package/src/modules/library/utils/plugin-summary.ts +7 -2
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
- package/src/modules/review/components/ReviewPanel.tsx +2 -2
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +2 -1
- package/src/modules/settings/settings-nav-items.tsx +11 -9
- package/src/modules/setup/components/SetupScreen.tsx +11 -0
- package/src/modules/setup/services/setup.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
- package/src/modules/workspace/components/FileExplorer.tsx +4 -2
- package/src/modules/workspace/components/FileViewer.tsx +14 -4
- package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +60 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +99 -0
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
- package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +78 -1
- package/src/modules/workspace/utils/fileTree.ts +2 -1
- package/src/modules/workspace/utils/treeConfirm.ts +7 -3
- package/src/shared/theme/measure.ts +23 -2
- package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +0 -266
- package/src/modules/admin/components/ConnectionKeysPage.tsx +0 -269
- package/src/modules/admin/components/connection-keys-grouping.ts +0 -43
- package/src/modules/admin/services/connection-keys.api.ts +0 -47
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { Fragment, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
import { Badge, Banner, Button } from '../../../shared/components';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
import { pathForSkill, pathForTool } from '../../library/routes/library-paths';
|
|
6
|
+
import {
|
|
7
|
+
listEvents,
|
|
8
|
+
type AgentEvent,
|
|
9
|
+
type AgentEventKind,
|
|
10
|
+
type AgentEventOutcome,
|
|
11
|
+
type AuditPrincipalKind,
|
|
12
|
+
} from '../services/audit.api';
|
|
13
|
+
|
|
14
|
+
/** How many events one load brings; "Load older events" fetches the next batch. */
|
|
15
|
+
const PAGE_SIZE = 50;
|
|
16
|
+
|
|
17
|
+
const KIND_LABEL: Record<AgentEventKind, string> = {
|
|
18
|
+
capability: 'Hexis capability',
|
|
19
|
+
tool: 'Tool',
|
|
20
|
+
skill: 'Skill',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** A small square per kind — a category mark, not a status (statuses are the outcome badge). */
|
|
24
|
+
const KIND_MARK: Record<AgentEventKind, string> = {
|
|
25
|
+
capability: 'bg-accent',
|
|
26
|
+
tool: 'bg-ink-faint',
|
|
27
|
+
skill: 'bg-ok',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const OUTCOME: Record<AgentEventOutcome, { tone: 'ok' | 'danger' | 'wait'; label: string }> = {
|
|
31
|
+
ok: { tone: 'ok', label: 'ok' },
|
|
32
|
+
error: { tone: 'danger', label: 'error' },
|
|
33
|
+
denied: { tone: 'wait', label: 'needs sign-in' },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type TypeFilter = 'all' | AgentEventKind;
|
|
37
|
+
|
|
38
|
+
const TYPE_FILTERS: { id: TypeFilter; label: string }[] = [
|
|
39
|
+
{ id: 'all', label: 'All' },
|
|
40
|
+
{ id: 'capability', label: KIND_LABEL.capability },
|
|
41
|
+
{ id: 'tool', label: KIND_LABEL.tool },
|
|
42
|
+
{ id: 'skill', label: KIND_LABEL.skill },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
function timeOf(at: number): string {
|
|
46
|
+
return new Date(at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** "Today", "Yesterday", or the date — the day separator's label. */
|
|
50
|
+
function dayLabel(at: number, now: number): string {
|
|
51
|
+
const day = new Date(at);
|
|
52
|
+
const today = new Date(now);
|
|
53
|
+
const yesterday = new Date(now - 24 * 60 * 60 * 1000);
|
|
54
|
+
const date = day.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
|
|
55
|
+
if (day.toDateString() === today.toDateString()) return `Today · ${date}`;
|
|
56
|
+
if (day.toDateString() === yesterday.toDateString()) return `Yesterday · ${date}`;
|
|
57
|
+
return date;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The "What was called" cell. A skill shows just its name and opens the
|
|
62
|
+
* skill's page; a tool shows `server · tool` and opens that manual's page —
|
|
63
|
+
* both through the name-based library routes, so no catalog is needed here.
|
|
64
|
+
* A hexis capability is plain text: it has no page of its own.
|
|
65
|
+
*/
|
|
66
|
+
function WhatWasCalled({ event }: { event: AgentEvent }) {
|
|
67
|
+
const link = 'border-b border-line-strong hover:border-accent hover:text-accent';
|
|
68
|
+
if (event.kind === 'skill') {
|
|
69
|
+
return (
|
|
70
|
+
<Link to={pathForSkill(event.name)} className={link} title={`Open the ${event.name} skill`}>
|
|
71
|
+
{event.name}
|
|
72
|
+
</Link>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (event.kind === 'tool' && event.manual) {
|
|
76
|
+
return (
|
|
77
|
+
<Link to={pathForTool(event.manual)} className={link} title={`Open the ${event.manual} tool page`}>
|
|
78
|
+
<span className="text-ink-muted">{event.manual}</span>
|
|
79
|
+
<span className="text-ink-faint"> · </span>
|
|
80
|
+
{event.name}
|
|
81
|
+
</Link>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return <>{event.name}</>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* One principal's events, rendered under its row in the Audit log: filters
|
|
89
|
+
* over what has been loaded, the day-grouped table, and the way to older
|
|
90
|
+
* pages. Loads on mount — the page mounts it on the row's first expand and
|
|
91
|
+
* keeps it, so collapsing and re-expanding costs no request.
|
|
92
|
+
*/
|
|
93
|
+
export function AuditEventsPanel({
|
|
94
|
+
kind,
|
|
95
|
+
id,
|
|
96
|
+
label,
|
|
97
|
+
}: {
|
|
98
|
+
kind: AuditPrincipalKind;
|
|
99
|
+
id: string;
|
|
100
|
+
/** The row's label, for the accessible names of the controls in here. */
|
|
101
|
+
label: string;
|
|
102
|
+
}) {
|
|
103
|
+
const searchId = useId();
|
|
104
|
+
const [events, setEvents] = useState<AgentEvent[] | null>(null);
|
|
105
|
+
const [total, setTotal] = useState(0);
|
|
106
|
+
const [nextCursor, setNextCursor] = useState<string | null>(null);
|
|
107
|
+
const [error, setError] = useState<string | null>(null);
|
|
108
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
109
|
+
const [typeFilter, setTypeFilter] = useState<TypeFilter>('all');
|
|
110
|
+
const [errorsOnly, setErrorsOnly] = useState(false);
|
|
111
|
+
const [query, setQuery] = useState('');
|
|
112
|
+
// "Today" and "Yesterday" are decided against the moment the panel opened —
|
|
113
|
+
// read once, so a re-render never shifts a separator on its own.
|
|
114
|
+
const [now] = useState(() => Date.now());
|
|
115
|
+
|
|
116
|
+
// Generation of the newest first-page load: a "Try again" pressed while an
|
|
117
|
+
// earlier attempt is still out must not let that attempt land afterwards.
|
|
118
|
+
const loadGen = useRef(0);
|
|
119
|
+
const loadFirstPage = useCallback(() => {
|
|
120
|
+
const gen = ++loadGen.current;
|
|
121
|
+
listEvents(kind, id, { limit: PAGE_SIZE })
|
|
122
|
+
.then((page) => {
|
|
123
|
+
if (gen !== loadGen.current) return;
|
|
124
|
+
setEvents(page.events);
|
|
125
|
+
setTotal(page.total ?? 0);
|
|
126
|
+
setNextCursor(page.nextCursor);
|
|
127
|
+
setError(null);
|
|
128
|
+
})
|
|
129
|
+
.catch((err) => {
|
|
130
|
+
if (gen !== loadGen.current) return;
|
|
131
|
+
setError(err instanceof Error ? err.message : "Couldn't load events.");
|
|
132
|
+
});
|
|
133
|
+
}, [kind, id]);
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
loadFirstPage();
|
|
137
|
+
return () => {
|
|
138
|
+
// Unmounting retires every attempt in flight.
|
|
139
|
+
loadGen.current += 1;
|
|
140
|
+
};
|
|
141
|
+
}, [loadFirstPage]);
|
|
142
|
+
|
|
143
|
+
const loadOlder = useCallback(async () => {
|
|
144
|
+
if (!nextCursor || loadingMore) return;
|
|
145
|
+
setLoadingMore(true);
|
|
146
|
+
try {
|
|
147
|
+
const page = await listEvents(kind, id, { before: nextCursor, limit: PAGE_SIZE });
|
|
148
|
+
setEvents((prev) => [...(prev ?? []), ...page.events]);
|
|
149
|
+
// A cursor page carries no total: the first page's stands.
|
|
150
|
+
if (page.total !== null) setTotal(page.total);
|
|
151
|
+
setNextCursor(page.nextCursor);
|
|
152
|
+
setError(null);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
setError(err instanceof Error ? err.message : "Couldn't load older events.");
|
|
155
|
+
} finally {
|
|
156
|
+
setLoadingMore(false);
|
|
157
|
+
}
|
|
158
|
+
}, [kind, id, nextCursor, loadingMore]);
|
|
159
|
+
|
|
160
|
+
const q = query.trim().toLowerCase();
|
|
161
|
+
const visible = useMemo(
|
|
162
|
+
() =>
|
|
163
|
+
(events ?? []).filter(
|
|
164
|
+
(e) =>
|
|
165
|
+
(typeFilter === 'all' || e.kind === typeFilter) &&
|
|
166
|
+
(!errorsOnly || e.outcome !== 'ok') &&
|
|
167
|
+
(!q || e.name.toLowerCase().includes(q) || (e.manual ?? '').toLowerCase().includes(q)),
|
|
168
|
+
),
|
|
169
|
+
[events, typeFilter, errorsOnly, q],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Day separators are derived at render: a separator before the first event
|
|
173
|
+
// of each day, in the (newest-first) order the rows already have.
|
|
174
|
+
const rows: Array<{ day: string } | { event: AgentEvent }> = [];
|
|
175
|
+
let lastDay: string | null = null;
|
|
176
|
+
for (const event of visible) {
|
|
177
|
+
const day = dayLabel(event.at, now);
|
|
178
|
+
if (day !== lastDay) {
|
|
179
|
+
rows.push({ day });
|
|
180
|
+
lastDay = day;
|
|
181
|
+
}
|
|
182
|
+
rows.push({ event });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (error && events === null) {
|
|
186
|
+
// The panel stays mounted across a collapse, so without a way to re-ask
|
|
187
|
+
// a failed first load would be this row's permanent state.
|
|
188
|
+
return (
|
|
189
|
+
<Banner tone="danger" role="alert" className="text-detail">
|
|
190
|
+
{error}
|
|
191
|
+
<Button variant="outline" size="sm" className="ml-3" onClick={loadFirstPage}>
|
|
192
|
+
Try again
|
|
193
|
+
</Button>
|
|
194
|
+
</Banner>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (events === null) return <div className="text-xs text-ink-muted">Loading…</div>;
|
|
198
|
+
if (events.length === 0) {
|
|
199
|
+
return (
|
|
200
|
+
<div className="text-detail text-ink-muted text-center py-3">
|
|
201
|
+
Nothing called yet. Events appear here the first time this {kind === 'agent' ? 'agent' : 'key'} uses a
|
|
202
|
+
tool, a skill, or a Hexis capability.
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div className="space-y-2">
|
|
209
|
+
<div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-2 text-detail text-ink-muted">
|
|
210
|
+
<div className="flex flex-wrap gap-1" role="group" aria-label={`Filter ${label}'s events by type`}>
|
|
211
|
+
{TYPE_FILTERS.map((f) => (
|
|
212
|
+
<button
|
|
213
|
+
key={f.id}
|
|
214
|
+
type="button"
|
|
215
|
+
aria-pressed={typeFilter === f.id}
|
|
216
|
+
onClick={() => setTypeFilter(f.id)}
|
|
217
|
+
className={cn(
|
|
218
|
+
'inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-meta',
|
|
219
|
+
typeFilter === f.id
|
|
220
|
+
? 'border-line bg-white text-ink shadow-card'
|
|
221
|
+
: 'border-transparent text-ink-muted hover:bg-hover hover:text-ink',
|
|
222
|
+
)}
|
|
223
|
+
>
|
|
224
|
+
{f.id !== 'all' && <span aria-hidden className={cn('size-2 rounded-[2px]', KIND_MARK[f.id])} />}
|
|
225
|
+
{f.label}
|
|
226
|
+
</button>
|
|
227
|
+
))}
|
|
228
|
+
</div>
|
|
229
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
230
|
+
<label className="flex items-center gap-1.5 cursor-pointer select-none">
|
|
231
|
+
<input type="checkbox" checked={errorsOnly} onChange={(e) => setErrorsOnly(e.target.checked)} />
|
|
232
|
+
Errors only
|
|
233
|
+
</label>
|
|
234
|
+
<input
|
|
235
|
+
id={searchId}
|
|
236
|
+
value={query}
|
|
237
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
238
|
+
placeholder="Filter by name"
|
|
239
|
+
aria-label={`Filter ${label}'s events by name`}
|
|
240
|
+
className="bg-white border border-line rounded-sm px-2 py-1 text-detail text-ink focus:outline-none focus:border-accent min-w-[180px]"
|
|
241
|
+
/>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
|
|
245
|
+
{error && (
|
|
246
|
+
<Banner tone="danger" role="alert" className="text-detail">
|
|
247
|
+
{error}
|
|
248
|
+
</Banner>
|
|
249
|
+
)}
|
|
250
|
+
|
|
251
|
+
<div className="bg-white border border-line rounded-sm overflow-hidden">
|
|
252
|
+
<div className="overflow-x-auto">
|
|
253
|
+
<table className="w-full min-w-[560px] border-collapse text-detail">
|
|
254
|
+
<thead>
|
|
255
|
+
<tr className="text-label uppercase tracking-[0.09em] text-ink-faint">
|
|
256
|
+
<th className="text-left font-semibold px-3 py-1.5 border-b border-line">What was called</th>
|
|
257
|
+
<th className="text-left font-semibold px-3 py-1.5 border-b border-line w-40">Type</th>
|
|
258
|
+
<th className="text-left font-semibold px-3 py-1.5 border-b border-line w-32">Outcome</th>
|
|
259
|
+
<th className="text-left font-semibold px-3 py-1.5 border-b border-line w-28">When</th>
|
|
260
|
+
</tr>
|
|
261
|
+
</thead>
|
|
262
|
+
<tbody>
|
|
263
|
+
{visible.length === 0 && (
|
|
264
|
+
<tr>
|
|
265
|
+
<td colSpan={4} className="px-3 py-3 text-center text-ink-muted">
|
|
266
|
+
No events match these filters.
|
|
267
|
+
</td>
|
|
268
|
+
</tr>
|
|
269
|
+
)}
|
|
270
|
+
{rows.map((row) =>
|
|
271
|
+
'day' in row ? (
|
|
272
|
+
<tr key={`day:${row.day}`}>
|
|
273
|
+
<td colSpan={4} className="bg-sunken px-3 py-0.5 text-meta font-medium text-ink-muted">
|
|
274
|
+
{row.day}
|
|
275
|
+
</td>
|
|
276
|
+
</tr>
|
|
277
|
+
) : (
|
|
278
|
+
<Fragment key={row.event.id}>
|
|
279
|
+
<tr className="hover:bg-surface-hover">
|
|
280
|
+
<td className="px-3 py-1.5 border-t border-line font-mono text-detail">
|
|
281
|
+
<WhatWasCalled event={row.event} />
|
|
282
|
+
</td>
|
|
283
|
+
<td className="px-3 py-1.5 border-t border-line">
|
|
284
|
+
<span className="inline-flex items-center gap-1.5">
|
|
285
|
+
<span aria-hidden className={cn('size-2 rounded-[2px]', KIND_MARK[row.event.kind])} />
|
|
286
|
+
{KIND_LABEL[row.event.kind]}
|
|
287
|
+
</span>
|
|
288
|
+
</td>
|
|
289
|
+
<td className="px-3 py-1.5 border-t border-line">
|
|
290
|
+
<Badge tone={OUTCOME[row.event.outcome].tone}>{OUTCOME[row.event.outcome].label}</Badge>
|
|
291
|
+
</td>
|
|
292
|
+
<td
|
|
293
|
+
className="px-3 py-1.5 border-t border-line text-ink-muted tabular-nums whitespace-nowrap"
|
|
294
|
+
title={new Date(row.event.at).toLocaleString()}
|
|
295
|
+
>
|
|
296
|
+
{timeOf(row.event.at)}
|
|
297
|
+
</td>
|
|
298
|
+
</tr>
|
|
299
|
+
</Fragment>
|
|
300
|
+
),
|
|
301
|
+
)}
|
|
302
|
+
</tbody>
|
|
303
|
+
</table>
|
|
304
|
+
</div>
|
|
305
|
+
<div className="flex items-center justify-between gap-3 px-3 py-1.5 border-t border-line text-meta text-ink-muted">
|
|
306
|
+
<span>
|
|
307
|
+
Showing {events.length.toLocaleString()} of {total.toLocaleString()} {total === 1 ? 'event' : 'events'} ·
|
|
308
|
+
newest first
|
|
309
|
+
</span>
|
|
310
|
+
{nextCursor && (
|
|
311
|
+
<Button variant="outline" size="sm" onClick={() => void loadOlder()} disabled={loadingMore}>
|
|
312
|
+
{loadingMore ? 'Loading…' : 'Load older events'}
|
|
313
|
+
</Button>
|
|
314
|
+
)}
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
}
|