@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.
Files changed (52) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +6 -2
  3. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  4. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  5. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  6. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  7. package/src/modules/audit/components/principal-grouping.ts +49 -0
  8. package/src/modules/audit/services/audit.api.ts +98 -0
  9. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  10. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  11. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  12. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  13. package/src/modules/git/services/error-messages.ts +2 -2
  14. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  15. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  16. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  17. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  18. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  19. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  20. package/src/modules/library/__tests__/ToolPage.test.tsx +20 -0
  21. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  22. package/src/modules/library/__tests__/title-row-actions.ts +43 -0
  23. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  24. package/src/modules/library/components/PluginPage.tsx +115 -3
  25. package/src/modules/library/components/tool-page/ToolPage.tsx +25 -17
  26. package/src/modules/library/routes/library-paths.ts +9 -2
  27. package/src/modules/library/services/plugins.api.ts +45 -0
  28. package/src/modules/library/utils/plugin-summary.ts +7 -2
  29. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  30. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  31. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  32. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  33. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +2 -1
  34. package/src/modules/settings/settings-nav-items.tsx +11 -9
  35. package/src/modules/setup/components/SetupScreen.tsx +11 -0
  36. package/src/modules/setup/services/setup.api.ts +1 -1
  37. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  38. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  39. package/src/modules/workspace/components/FileViewer.tsx +14 -4
  40. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  41. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +60 -0
  42. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +99 -0
  43. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  44. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  45. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +78 -1
  46. package/src/modules/workspace/utils/fileTree.ts +2 -1
  47. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  48. package/src/shared/theme/measure.ts +23 -2
  49. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +0 -266
  50. package/src/modules/admin/components/ConnectionKeysPage.tsx +0 -269
  51. package/src/modules/admin/components/connection-keys-grouping.ts +0 -43
  52. package/src/modules/admin/services/connection-keys.api.ts +0 -47
@@ -1,266 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { render, screen, waitFor, within } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { ConnectionKeysPage } from '../components/ConnectionKeysPage';
5
- import { groupByAccount } from '../components/connection-keys-grouping';
6
- import { AdminContext } from '../state/admin.context';
7
- import {
8
- listConnectionKeys,
9
- revokeConnectionKey,
10
- type AdminConnectionKey,
11
- } from '../services/connection-keys.api';
12
-
13
- vi.mock('../services/connection-keys.api', () => ({
14
- listConnectionKeys: vi.fn(),
15
- revokeConnectionKey: vi.fn(),
16
- }));
17
-
18
- const ALICE = { id: 'u-alice', email: 'alice@example.com', name: 'Alice' };
19
- const BOB = { id: 'u-bob', email: 'bob@example.com', name: 'Bob' };
20
-
21
- const DAY = 24 * 60 * 60 * 1000;
22
- const NOW = Date.now();
23
-
24
- const ALICE_CI: AdminConnectionKey = {
25
- id: 'k-ci',
26
- label: 'CI pipeline',
27
- kind: 'key',
28
- createdAt: NOW - 10 * DAY,
29
- lastUsedAt: NOW - 2 * 60 * 60 * 1000,
30
- revokedAt: null,
31
- revokedBy: null,
32
- user: ALICE,
33
- };
34
- const ALICE_LAPTOP: AdminConnectionKey = {
35
- id: 'k-laptop',
36
- label: 'Laptop',
37
- kind: 'key',
38
- createdAt: NOW - 3 * DAY,
39
- lastUsedAt: null,
40
- revokedAt: null,
41
- revokedBy: null,
42
- user: ALICE,
43
- };
44
- const BOB_OLD: AdminConnectionKey = {
45
- id: 'k-old',
46
- label: 'Old script',
47
- kind: 'key',
48
- createdAt: NOW - 40 * DAY,
49
- lastUsedAt: NOW - 30 * DAY,
50
- revokedAt: NOW - 20 * DAY,
51
- revokedBy: 'owner',
52
- user: BOB,
53
- };
54
- const BOB_LINK: AdminConnectionKey = {
55
- id: 'k-link',
56
- label: 'Claude',
57
- kind: 'github-link',
58
- createdAt: NOW - 1 * DAY,
59
- lastUsedAt: NOW - 60 * 1000,
60
- revokedAt: null,
61
- revokedBy: null,
62
- user: BOB,
63
- };
64
-
65
- function renderPage(opts: { isAdmin?: boolean } = {}) {
66
- return render(
67
- <AdminContext.Provider
68
- value={{
69
- isAdmin: opts.isAdmin ?? true,
70
- unreadCount: 0,
71
- lastSeen: null,
72
- markSeen: () => {},
73
- refresh: () => {},
74
- rolesConfigCorrupted: false,
75
- rolesConfigErrors: [],
76
- runRolesRecovery: async () => {},
77
- }}
78
- >
79
- <ConnectionKeysPage />
80
- </AdminContext.Provider>,
81
- );
82
- }
83
-
84
- beforeEach(() => {
85
- vi.mocked(listConnectionKeys)
86
- .mockReset()
87
- .mockResolvedValue([ALICE_LAPTOP, ALICE_CI, BOB_OLD, BOB_LINK]);
88
- vi.mocked(revokeConnectionKey).mockReset().mockResolvedValue(undefined);
89
- });
90
-
91
- describe('groupByAccount', () => {
92
- it('groups in server order, live keys first, most recently used at the top', () => {
93
- const groups = groupByAccount([ALICE_LAPTOP, ALICE_CI, BOB_OLD, BOB_LINK], true);
94
- expect(groups.map((g) => g.user.id)).toEqual(['u-alice', 'u-bob']);
95
- // Alice: CI was used, Laptop never → CI first despite Laptop being newer.
96
- expect(groups[0].keys.map((k) => k.id)).toEqual(['k-ci', 'k-laptop']);
97
- // Bob: the live link outranks the revoked key.
98
- expect(groups[1].keys.map((k) => k.id)).toEqual(['k-link', 'k-old']);
99
- });
100
-
101
- it('drops revoked keys (and accounts left empty) when they are hidden', () => {
102
- const groups = groupByAccount([BOB_OLD, ALICE_CI], false);
103
- expect(groups.map((g) => g.user.id)).toEqual(['u-alice']);
104
- });
105
- });
106
-
107
- describe('ConnectionKeysPage', () => {
108
- it('shows the admins-only state (and never loads) for non-admins', () => {
109
- renderPage({ isAdmin: false });
110
- expect(screen.getByText(/Admins only/)).toBeInTheDocument();
111
- expect(listConnectionKeys).not.toHaveBeenCalled();
112
- });
113
-
114
- it('lists live keys per account with created / last used, hiding disconnected ones by default', async () => {
115
- renderPage();
116
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
117
-
118
- const alice = screen.getByRole('region', { name: 'Keys for alice@example.com' });
119
- expect(within(alice).getByText('Alice')).toBeInTheDocument();
120
- expect(within(alice).getByText('Created 1w ago')).toBeInTheDocument();
121
- expect(within(alice).getByText('Last used 2h ago')).toBeInTheDocument();
122
- expect(within(alice).getByText('Created 3d ago')).toBeInTheDocument();
123
- expect(within(alice).getByText('Last used never')).toBeInTheDocument();
124
- expect(
125
- within(alice).getByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
126
- ).toBeInTheDocument();
127
-
128
- const bob = screen.getByRole('region', { name: 'Keys for bob@example.com' });
129
- expect(within(bob).getByText('Claude link')).toBeInTheDocument();
130
- expect(within(bob).queryByText('Old script')).not.toBeInTheDocument();
131
-
132
- expect(screen.getByText(/3 live keys · 1 disconnected/)).toBeInTheDocument();
133
- });
134
-
135
- it('reveals disconnected keys, without a revoke button, when toggled', async () => {
136
- renderPage();
137
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
138
-
139
- await userEvent.click(screen.getByRole('checkbox', { name: 'Show disconnected keys' }));
140
-
141
- const bob = screen.getByRole('region', { name: 'Keys for bob@example.com' });
142
- expect(within(bob).getByText('Old script')).toBeInTheDocument();
143
- expect(within(bob).getByText(/Disconnected by owner 2w ago/)).toBeInTheDocument();
144
- expect(
145
- within(bob).queryByRole('button', { name: 'Revoke Old script for bob@example.com' }),
146
- ).not.toBeInTheDocument();
147
- });
148
-
149
- it('revokes after confirmation and reloads the list', async () => {
150
- renderPage();
151
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
152
-
153
- await userEvent.click(
154
- screen.getByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
155
- );
156
- const dialog = await screen.findByRole('dialog');
157
- expect(within(dialog).getByText(/Alice \(alice@example.com\)/)).toBeInTheDocument();
158
- expect(revokeConnectionKey).not.toHaveBeenCalled();
159
-
160
- await userEvent.click(within(dialog).getByRole('button', { name: 'Revoke key' }));
161
-
162
- await waitFor(() => expect(revokeConnectionKey).toHaveBeenCalledWith('k-ci'));
163
- await waitFor(() => expect(listConnectionKeys).toHaveBeenCalledTimes(2));
164
- });
165
-
166
- it('cancelling the confirm revokes nothing', async () => {
167
- renderPage();
168
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
169
-
170
- await userEvent.click(
171
- screen.getByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
172
- );
173
- const dialog = await screen.findByRole('dialog');
174
- await userEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
175
-
176
- expect(revokeConnectionKey).not.toHaveBeenCalled();
177
- expect(listConnectionKeys).toHaveBeenCalledTimes(1);
178
- });
179
-
180
- it('surfaces a failed revoke inline and keeps the rows it had', async () => {
181
- renderPage();
182
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
183
- vi.mocked(revokeConnectionKey).mockRejectedValueOnce(new Error('Token not found'));
184
-
185
- await userEvent.click(
186
- screen.getByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
187
- );
188
- await userEvent.click(
189
- within(await screen.findByRole('dialog')).getByRole('button', { name: 'Revoke key' }),
190
- );
191
-
192
- expect(await screen.findByRole('alert')).toHaveTextContent('Token not found');
193
- expect(screen.getByText('CI pipeline')).toBeInTheDocument();
194
- });
195
-
196
- it('keeps a revoked key disconnected when the reload after revoking fails', async () => {
197
- renderPage();
198
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
199
- vi.mocked(listConnectionKeys).mockRejectedValueOnce(new Error('Could not load connection keys'));
200
-
201
- await userEvent.click(
202
- screen.getByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
203
- );
204
- await userEvent.click(
205
- within(await screen.findByRole('dialog')).getByRole('button', { name: 'Revoke key' }),
206
- );
207
-
208
- expect(await screen.findByRole('alert')).toHaveTextContent('Could not load connection keys');
209
- // The server said yes, so the row is disconnected regardless of the reload:
210
- // hidden with the other disconnected keys, and never offering Revoke again.
211
- expect(
212
- screen.queryByRole('button', { name: 'Revoke CI pipeline for alice@example.com' }),
213
- ).not.toBeInTheDocument();
214
- await userEvent.click(screen.getByRole('checkbox', { name: 'Show disconnected keys' }));
215
- expect(screen.getByText('CI pipeline')).toBeInTheDocument();
216
- expect(screen.getByText(/2 live keys · 2 disconnected/)).toBeInTheDocument();
217
- });
218
-
219
- it('ignores a stale list response that lands after a newer one', async () => {
220
- // Two revokes back to back: the reload from the FIRST resolves last, still
221
- // showing the second key as live. It must not win over the newer reload.
222
- const deferred = () => {
223
- let resolve!: (rows: AdminConnectionKey[]) => void;
224
- const promise = new Promise<AdminConnectionKey[]>((r) => (resolve = r));
225
- return { promise, resolve };
226
- };
227
- const first = deferred();
228
- const second = deferred();
229
- vi.mocked(listConnectionKeys)
230
- .mockReset()
231
- .mockResolvedValueOnce([ALICE_CI, ALICE_LAPTOP])
232
- .mockReturnValueOnce(first.promise)
233
- .mockReturnValueOnce(second.promise);
234
- renderPage();
235
- await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
236
-
237
- const revoke = async (name: string) => {
238
- await userEvent.click(screen.getByRole('button', { name }));
239
- await userEvent.click(
240
- within(await screen.findByRole('dialog')).getByRole('button', { name: 'Revoke key' }),
241
- );
242
- };
243
- await revoke('Revoke CI pipeline for alice@example.com');
244
- await revoke('Revoke Laptop for alice@example.com');
245
- await waitFor(() => expect(listConnectionKeys).toHaveBeenCalledTimes(3));
246
-
247
- const ciRevoked = { ...ALICE_CI, revokedAt: NOW };
248
- second.resolve([ciRevoked, { ...ALICE_LAPTOP, revokedAt: NOW }]);
249
- await waitFor(() => expect(screen.getByText(/0 live keys · 2 disconnected/)).toBeInTheDocument());
250
-
251
- // The stale reload: taken at face value, Laptop would come back to life.
252
- first.resolve([ciRevoked, ALICE_LAPTOP]);
253
- await new Promise((r) => setTimeout(r, 0));
254
- expect(screen.getByText(/0 live keys · 2 disconnected/)).toBeInTheDocument();
255
- expect(
256
- screen.queryByRole('button', { name: 'Revoke Laptop for alice@example.com' }),
257
- ).not.toBeInTheDocument();
258
- });
259
-
260
- it('shows the load error and no empty state when the first load fails', async () => {
261
- vi.mocked(listConnectionKeys).mockRejectedValueOnce(new Error('Could not load connection keys'));
262
- renderPage();
263
- expect(await screen.findByRole('alert')).toHaveTextContent('Could not load connection keys');
264
- expect(screen.queryByText(/No connection keys/)).not.toBeInTheDocument();
265
- });
266
- });
@@ -1,269 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { PageShell } from '../../../shared/components/PageShell';
3
- import { Dialog } from '../../../shared/components/Dialog';
4
- import { formatRelativeTime } from '../../../lib/utils';
5
- import { GITHUB_LINK_KIND } from '../../../shared/marketplace-url';
6
- import { useAdmin } from '../state/admin.context';
7
- import {
8
- listConnectionKeys,
9
- revokeConnectionKey,
10
- type AdminConnectionKey,
11
- } from '../services/connection-keys.api';
12
- import { groupByAccount } from './connection-keys-grouping';
13
-
14
- /**
15
- * The shared formatter, plus the one word it deliberately leaves to the caller:
16
- * a key that has never been used has no instant to describe.
17
- */
18
- function formatRelative(ts: number | null): string {
19
- return formatRelativeTime(ts) || 'never';
20
- }
21
-
22
- /** The exact instant, for a hover — the row shows the relative form. */
23
- function formatAbsolute(ts: number | null): string | undefined {
24
- return ts === null ? undefined : new Date(ts).toLocaleString();
25
- }
26
-
27
- /**
28
- * The Connection keys page (`/connection-keys`, admins only): every
29
- * connection key on the deployment, grouped per account, with when it was
30
- * created, when it was last used, and a revoke. It exists so a leaked or
31
- * forgotten key can be cut off without signing in as its owner. Revoking
32
- * keeps the row (dimmed, "Disconnected") so its last use stays visible;
33
- * only the owner can delete it for good, from their own External agent
34
- * access page. Disconnected keys are hidden by default — on a busy
35
- * deployment they outnumber the live ones — and a toggle brings them back.
36
- */
37
- export function ConnectionKeysPage() {
38
- const { isAdmin } = useAdmin();
39
- const [keys, setKeys] = useState<AdminConnectionKey[] | null>(null);
40
- const [error, setError] = useState<string | null>(null);
41
- const [showRevoked, setShowRevoked] = useState(false);
42
- // The key awaiting revoke confirmation; non-null drives the confirm
43
- // Dialog. `revoking` keeps the confirm open while the request is in flight.
44
- const [pendingRevoke, setPendingRevoke] = useState<AdminConnectionKey | null>(null);
45
- const [revoking, setRevoking] = useState(false);
46
-
47
- // Generation of the newest load. Two revokes in quick succession start two
48
- // reloads, and the older one can land last — carrying a key the newer one
49
- // already saw revoked. Only the latest load may write `keys`.
50
- const loadGen = useRef(0);
51
- const refresh = useCallback(() => {
52
- const gen = ++loadGen.current;
53
- listConnectionKeys()
54
- .then((rows) => {
55
- if (gen !== loadGen.current) return;
56
- setKeys(rows);
57
- setError(null);
58
- })
59
- .catch((err) => {
60
- if (gen !== loadGen.current) return;
61
- setError(err instanceof Error ? err.message : "Couldn't load connection keys.");
62
- // `keys` is deliberately left alone: a reload that fails keeps the
63
- // rows it had, and a first load that fails stays `null` rather than
64
- // rendering "No connection keys" for a deployment we cannot reach.
65
- });
66
- }, []);
67
-
68
- useEffect(() => {
69
- if (isAdmin) refresh();
70
- }, [isAdmin, refresh]);
71
-
72
- const groups = useMemo(() => (keys ? groupByAccount(keys, showRevoked) : []), [keys, showRevoked]);
73
- const liveCount = keys?.filter((k) => k.revokedAt === null).length ?? 0;
74
- const revokedCount = (keys?.length ?? 0) - liveCount;
75
-
76
- async function confirmRevoke() {
77
- if (!pendingRevoke || revoking) return;
78
- setRevoking(true);
79
- setError(null);
80
- try {
81
- const { id } = pendingRevoke;
82
- await revokeConnectionKey(id);
83
- // The server has revoked it; say so at once rather than waiting on the
84
- // reload. If that reload fails, the row must not sit there looking live
85
- // with a Revoke button — the agent holding this key is already cut off.
86
- setKeys((prev) =>
87
- prev
88
- ? prev.map((k) =>
89
- k.id === id && k.revokedAt === null
90
- ? { ...k, revokedAt: Date.now(), revokedBy: 'admin' as const }
91
- : k,
92
- )
93
- : prev,
94
- );
95
- setPendingRevoke(null);
96
- refresh();
97
- } catch (err) {
98
- setPendingRevoke(null);
99
- setError(err instanceof Error ? err.message : "Couldn't revoke this key.");
100
- } finally {
101
- setRevoking(false);
102
- }
103
- }
104
-
105
- if (!isAdmin) {
106
- return (
107
- <PageShell title="Connection keys">
108
- <div className="text-sm text-ink-muted">
109
- Admins only. Your own keys are on the External agent access page.
110
- </div>
111
- </PageShell>
112
- );
113
- }
114
-
115
- return (
116
- <>
117
- <PageShell title="Connection keys">
118
- <div className="space-y-4">
119
- <p className="text-xs text-ink-muted leading-snug">
120
- Every connection key on this deployment, per account. Revoking a key cuts off the
121
- external agent using it immediately; the key stays listed as disconnected so you can
122
- still see when it was last used. Only its owner can delete it for good.
123
- </p>
124
-
125
- {error && (
126
- <div
127
- className="text-xs text-red-600 bg-red-50 border border-red-200 rounded-sm px-2 py-1.5"
128
- role="alert"
129
- >
130
- {error}
131
- </div>
132
- )}
133
-
134
- {keys !== null && (
135
- <div className="flex items-center justify-between gap-3 text-xs text-ink-muted">
136
- <span>
137
- {liveCount} live {liveCount === 1 ? 'key' : 'keys'}
138
- {revokedCount > 0 && ` · ${revokedCount} disconnected`}
139
- </span>
140
- {revokedCount > 0 && (
141
- <label className="flex items-center gap-1.5 cursor-pointer select-none">
142
- <input
143
- type="checkbox"
144
- checked={showRevoked}
145
- onChange={(e) => setShowRevoked(e.target.checked)}
146
- />
147
- Show disconnected keys
148
- </label>
149
- )}
150
- </div>
151
- )}
152
-
153
- {keys === null ? (
154
- error ? null : <div className="text-xs text-ink-muted">Loading…</div>
155
- ) : groups.length === 0 ? (
156
- <div className="text-xs text-ink-muted">
157
- {keys.length === 0 ? 'No connection keys on this deployment.' : 'No live connection keys.'}
158
- </div>
159
- ) : (
160
- <div className="space-y-4">
161
- {groups.map((group) => {
162
- const live = group.keys.filter((k) => k.revokedAt === null).length;
163
- return (
164
- <section key={group.user.id} aria-label={`Keys for ${group.user.email}`}>
165
- <div className="flex items-baseline gap-2 px-1 pb-1.5">
166
- <span className="text-sm font-medium truncate">{group.user.name}</span>
167
- <span className="text-meta text-ink-muted truncate">{group.user.email}</span>
168
- <span className="ml-auto text-meta text-ink-muted whitespace-nowrap">
169
- {live} live
170
- </span>
171
- </div>
172
- <ul className="divide-y divide-line border border-line rounded-sm">
173
- {group.keys.map((k) => {
174
- const revoked = k.revokedAt !== null;
175
- return (
176
- <li
177
- key={k.id}
178
- className={`flex items-center gap-3 px-3 py-2 text-sm ${
179
- revoked ? 'opacity-60' : ''
180
- }`}
181
- >
182
- <div className="flex-1 min-w-0">
183
- <div className="font-medium truncate">
184
- {k.label}
185
- {k.kind === GITHUB_LINK_KIND && (
186
- <span className="ml-1.5 text-meta font-normal text-ink-muted">
187
- Claude link
188
- </span>
189
- )}
190
- </div>
191
- <div className="text-meta text-ink-muted">
192
- <span title={formatAbsolute(k.createdAt)}>
193
- Created {formatRelative(k.createdAt)}
194
- </span>
195
- {' · '}
196
- <span title={formatAbsolute(k.lastUsedAt)}>
197
- Last used {formatRelative(k.lastUsedAt)}
198
- </span>
199
- {revoked && (
200
- <>
201
- {' · '}
202
- <span title={formatAbsolute(k.revokedAt)}>
203
- {k.revokedBy === 'admin' ? 'Revoked by an admin' : 'Disconnected by owner'}{' '}
204
- {formatRelative(k.revokedAt)}
205
- </span>
206
- </>
207
- )}
208
- </div>
209
- </div>
210
- {!revoked && (
211
- <button
212
- onClick={() => setPendingRevoke(k)}
213
- className="text-xs px-2 py-1 rounded-sm text-red-700 hover:bg-red-50 border border-red-200"
214
- title="Revoke this key. The external agent using it will lose access."
215
- aria-label={`Revoke ${k.label} for ${group.user.email}`}
216
- >
217
- Revoke
218
- </button>
219
- )}
220
- </li>
221
- );
222
- })}
223
- </ul>
224
- </section>
225
- );
226
- })}
227
- </div>
228
- )}
229
- </div>
230
- </PageShell>
231
-
232
- <Dialog
233
- open={pendingRevoke !== null}
234
- onClose={() => setPendingRevoke(null)}
235
- title="Revoke connection key"
236
- size="sm"
237
- busy={revoking}
238
- footer={
239
- <>
240
- <button
241
- onClick={() => setPendingRevoke(null)}
242
- disabled={revoking}
243
- className="px-3 py-1.5 text-sm rounded-sm text-ink hover:bg-hover border border-line disabled:opacity-50"
244
- >
245
- Cancel
246
- </button>
247
- <button
248
- onClick={confirmRevoke}
249
- disabled={revoking}
250
- className="px-3 py-1.5 text-sm rounded-sm bg-red-600 hover:bg-red-700 text-white disabled:opacity-50 disabled:hover:bg-red-600"
251
- >
252
- {revoking ? 'Revoking…' : 'Revoke key'}
253
- </button>
254
- </>
255
- }
256
- >
257
- <p className="text-xs text-ink leading-snug">
258
- Revoke <span className="font-medium">{pendingRevoke?.label}</span> belonging to{' '}
259
- <span className="font-medium">
260
- {pendingRevoke?.user.name} ({pendingRevoke?.user.email})
261
- </span>
262
- ? Whatever is using it loses access immediately. The key stays listed as disconnected
263
- so its last use remains visible; its owner can delete it for good from their External
264
- agent access page.
265
- </p>
266
- </Dialog>
267
- </>
268
- );
269
- }
@@ -1,43 +0,0 @@
1
- import type { AdminConnectionKey } from '../services/connection-keys.api';
2
-
3
- export interface AccountGroup {
4
- user: AdminConnectionKey['user'];
5
- keys: AdminConnectionKey[];
6
- }
7
-
8
- /**
9
- * One list from the server, grouped per account in the order the server
10
- * returned it (owner email). Within an account: live keys first, most
11
- * recently used at the top, so the row an admin is hunting for — the key
12
- * that is still being used — is never below the ones that are not.
13
- *
14
- * Lives beside {@link ConnectionKeysPage} rather than in it: a component
15
- * file that also exports a plain function breaks fast refresh.
16
- */
17
- export function groupByAccount(
18
- keys: AdminConnectionKey[],
19
- includeRevoked: boolean,
20
- ): AccountGroup[] {
21
- const groups: AccountGroup[] = [];
22
- const byUser = new Map<string, AccountGroup>();
23
- for (const key of keys) {
24
- if (!includeRevoked && key.revokedAt !== null) continue;
25
- let group = byUser.get(key.user.id);
26
- if (!group) {
27
- group = { user: key.user, keys: [] };
28
- byUser.set(key.user.id, group);
29
- groups.push(group);
30
- }
31
- group.keys.push(key);
32
- }
33
- for (const group of groups) {
34
- group.keys.sort((a, b) => {
35
- const aRevoked = a.revokedAt !== null;
36
- const bRevoked = b.revokedAt !== null;
37
- if (aRevoked !== bRevoked) return aRevoked ? 1 : -1;
38
- const byUse = (b.lastUsedAt ?? 0) - (a.lastUsedAt ?? 0);
39
- return byUse !== 0 ? byUse : b.createdAt - a.createdAt;
40
- });
41
- }
42
- return groups;
43
- }
@@ -1,47 +0,0 @@
1
- import { authFetch } from '../../../lib/api';
2
-
3
- /**
4
- * One row of the admin Connection keys overview
5
- * (`GET /api/admin/connection-keys`): a key plus the account it belongs to.
6
- * Never carries the plaintext — that was shown to the owner exactly once.
7
- */
8
- export interface AdminConnectionKey {
9
- id: string;
10
- label: string;
11
- /** `key` for a hand-made key; another kind for one a flow minted (a Claude link). */
12
- kind: string;
13
- createdAt: number;
14
- lastUsedAt: number | null;
15
- revokedAt: number | null;
16
- /** Who ended it once revoked: the owner, or an admin. Null while live. */
17
- revokedBy: 'owner' | 'admin' | null;
18
- user: {
19
- id: string;
20
- email: string;
21
- name: string;
22
- };
23
- }
24
-
25
- async function readError(res: Response, fallback: string): Promise<string> {
26
- const body = await res.json().catch(() => ({}));
27
- return (body as { error?: string }).error || fallback;
28
- }
29
-
30
- /** Every connection key on the deployment, ordered by owner email then newest-first. */
31
- export async function listConnectionKeys(): Promise<AdminConnectionKey[]> {
32
- const res = await authFetch('/api/admin/connection-keys');
33
- if (!res.ok) throw new Error(await readError(res, 'Could not load connection keys'));
34
- const body = (await res.json()) as { keys: AdminConnectionKey[] };
35
- return body.keys;
36
- }
37
-
38
- /**
39
- * Revoke (disconnect) any account's key. The row is kept so its last-used
40
- * time stays auditable; the agent holding the key loses access at once.
41
- */
42
- export async function revokeConnectionKey(id: string): Promise<void> {
43
- const res = await authFetch(`/api/admin/connection-keys/${encodeURIComponent(id)}`, {
44
- method: 'DELETE',
45
- });
46
- if (!res.ok) throw new Error(await readError(res, 'Could not revoke this key'));
47
- }