@bevel-software/platform-core-frontend 0.11.2 → 0.12.1

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 (48) hide show
  1. package/THIRD-PARTY-NOTICES.md +670 -395
  2. package/package.json +6 -2
  3. package/src/lib/__tests__/api.test.ts +95 -0
  4. package/src/lib/api.ts +30 -2
  5. package/src/lib/clipboard.ts +25 -0
  6. package/src/modules/access/__tests__/useFileAccess.test.tsx +47 -0
  7. package/src/modules/access/hooks/useFileAccess.ts +23 -5
  8. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +181 -0
  9. package/src/modules/git/components/GitSyncFailedBanner.tsx +106 -0
  10. package/src/modules/library/utils/clipboard.ts +4 -20
  11. package/src/modules/secrets-vault/components/SecretsPage.tsx +313 -313
  12. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +82 -82
  13. package/src/modules/workspace/components/FileExplorer.tsx +6 -14
  14. package/src/modules/workspace/components/FileViewer.tsx +20 -4
  15. package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
  16. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +3 -1
  17. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +17 -0
  18. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +15 -0
  19. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -2
  20. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +88 -0
  21. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +309 -0
  22. package/src/modules/workspace/components/renderers/LegacyOfficeRenderer.tsx +60 -0
  23. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +261 -33
  24. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +184 -0
  25. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +195 -45
  26. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +48 -0
  27. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +176 -0
  28. package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +214 -76
  29. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +125 -0
  30. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +245 -0
  31. package/src/modules/workspace/components/renderers/__tests__/emailBody.test.ts +117 -0
  32. package/src/modules/workspace/components/renderers/__tests__/emailMessage.test.ts +404 -0
  33. package/src/modules/workspace/components/renderers/__tests__/pptxOutline.test.ts +448 -0
  34. package/src/modules/workspace/components/renderers/__tests__/readBodyCapped.test.ts +117 -0
  35. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +73 -7
  36. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +107 -0
  37. package/src/modules/workspace/components/renderers/downloadFile.ts +33 -0
  38. package/src/modules/workspace/components/renderers/emailBody.ts +168 -0
  39. package/src/modules/workspace/components/renderers/emailMessage.ts +223 -0
  40. package/src/modules/workspace/components/renderers/emlMessage.ts +91 -0
  41. package/src/modules/workspace/components/renderers/htmlSandbox.ts +9 -2
  42. package/src/modules/workspace/components/renderers/index.ts +82 -6
  43. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +9 -2
  44. package/src/modules/workspace/components/renderers/msgMessage.ts +219 -0
  45. package/src/modules/workspace/components/renderers/pptxOutline.ts +317 -0
  46. package/src/modules/workspace/components/renderers/readBodyCapped.ts +97 -0
  47. package/src/modules/workspace/components/renderers/xmlReading.ts +0 -0
  48. package/src/url-suffix-imports.d.ts +12 -0
@@ -1,313 +1,313 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { Link } from 'react-router-dom';
3
- import { Badge, Banner, Button, Surface, TextField } from '../../../shared/components';
4
- import { PageShell } from '../../../shared/components/PageShell';
5
- import { pathForTool } from '../../library/routes/library-paths';
6
- import { ToolLogo } from '../../library/components/ToolLogo';
7
- import {
8
- listSecrets,
9
- createOAuthSecret,
10
- deleteSecret,
11
- startOAuth,
12
- type SecretSummary,
13
- } from '../services/secrets.api';
14
- import { listToolSecrets, type ToolSecrets } from '../services/tool-secrets.api';
15
- import { ToolSecretsPanel } from './ToolSecretsPanel';
16
-
17
- /**
18
- * The Secrets page, routed standalone at `/secrets` (below the persistent
19
- * toolbar). Primary surface is PER-TOOL: each `.tool` manual declares which
20
- * `${VAR}`s are set by the tool owner (shared) vs by each user, and the panels
21
- * let the right people fill the right values. OAuth credentials (per-user)
22
- * live under "Advanced" — the callback/refresh flow is keyed by secret id.
23
- *
24
- * `/secrets` is also the standalone-secret OAuth landing: the backend
25
- * callback returns the browser here with the outcome in the URL fragment
26
- * (`#authorized` / `#error`), which the page surfaces and then strips.
27
- *
28
- * Visually this is the Library's sibling: tool logos lead the cards, statuses
29
- * say `Connected` / `Set` / `Needs …` in the same grammar, and everything sits
30
- * on the shared components rather than hand-rolled borders.
31
- */
32
- /**
33
- * The OAuth-callback outcome carried in the URL fragment
34
- * (`#authorized` / `#error=<message>`), or null when there is none.
35
- * `URLSearchParams` already percent-decodes, so the value is used as-is (a
36
- * second `decodeURIComponent` would corrupt messages containing `%`).
37
- */
38
- function readHashOutcome(): { kind: 'authorized' | 'error'; text: string } | null {
39
- const hash = window.location.hash.replace(/^#/, '');
40
- if (!hash) return null;
41
- const params = new URLSearchParams(hash);
42
- if (params.has('authorized')) return { kind: 'authorized', text: 'Authorization complete.' };
43
- if (params.has('error'))
44
- return { kind: 'error', text: params.get('error') || 'Authorization failed.' };
45
- return null;
46
- }
47
-
48
- export function SecretsPage() {
49
- const [tools, setTools] = useState<ToolSecrets[]>([]);
50
- const [secrets, setSecrets] = useState<SecretSummary[]>([]);
51
- const [loading, setLoading] = useState(true);
52
- const [error, setError] = useState<string | null>(null);
53
- // Read ONCE, synchronously, before the fragment is stripped below. Kept in
54
- // its own slot (not the API `error` above) so the initial refresh() — whose
55
- // success path clears the API error — can't race the outcome away.
56
- const [oauthOutcome] = useState(readHashOutcome);
57
-
58
- const refresh = useCallback(async () => {
59
- setLoading(true);
60
- try {
61
- const [t, s] = await Promise.all([listToolSecrets(), listSecrets()]);
62
- setTools(t);
63
- setSecrets(s);
64
- setError(null);
65
- } catch (err) {
66
- setError(err instanceof Error ? err.message : String(err));
67
- } finally {
68
- setLoading(false);
69
- }
70
- }, []);
71
-
72
- useEffect(() => {
73
- void refresh();
74
- }, [refresh]);
75
-
76
- // Strip the consumed fragment so a refresh doesn't re-announce the outcome.
77
- useEffect(() => {
78
- if (oauthOutcome) window.history.replaceState(null, '', window.location.pathname);
79
- }, [oauthOutcome]);
80
-
81
- // A live API error wins over the (historical) callback outcome; otherwise
82
- // the callback error stays visible even after the list load succeeds.
83
- const shownError = error ?? (oauthOutcome?.kind === 'error' ? oauthOutcome.text : null);
84
- const notice = oauthOutcome?.kind === 'authorized' ? oauthOutcome.text : null;
85
-
86
- const oauthSecrets = secrets.filter((s) => s.kind === 'oauth');
87
-
88
- const onDelete = async (id: string) => {
89
- try {
90
- await deleteSecret(id);
91
- await refresh();
92
- } catch (err) {
93
- setError(err instanceof Error ? err.message : String(err));
94
- }
95
- };
96
-
97
- const onAuthorize = async (id: string) => {
98
- try {
99
- const url = await startOAuth(id);
100
- window.location.href = url;
101
- } catch (err) {
102
- setError(err instanceof Error ? err.message : String(err));
103
- }
104
- };
105
-
106
- return (
107
- <PageShell
108
- title="Secrets"
109
- actions={
110
- <Button variant="quiet" size="sm" disabled={loading} onClick={() => void refresh()}>
111
- Refresh
112
- </Button>
113
- }
114
- >
115
- {shownError && (
116
- <Banner role="alert" tone="danger" className="mb-3">
117
- {shownError}
118
- </Banner>
119
- )}
120
- {notice && (
121
- <Banner role="status" tone="ok" className="mb-3">
122
- {notice}
123
- </Banner>
124
- )}
125
-
126
- <p className="mb-5 text-ui text-ink-muted">
127
- Secrets back the{' '}
128
- <code className="rounded-sm bg-sunken px-1 py-0.5 font-mono text-meta text-ink">
129
- {'${VARIABLE}'}
130
- </code>{' '}
131
- placeholders in your tool manuals. Each tool declares which variables its owner sets once
132
- (shared by everyone) and which each user sets for themselves. Values are never displayed
133
- after saving.
134
- </p>
135
-
136
- {loading ? (
137
- <p className="py-10 text-center text-ui text-ink-faint">Loading…</p>
138
- ) : tools.length === 0 ? (
139
- <p className="py-10 text-center text-ui text-ink-faint">
140
- No tools you can access declare secrets yet.
141
- </p>
142
- ) : (
143
- <ul className="mb-6 flex flex-col gap-2.5">
144
- {tools.map((tool) => (
145
- <li key={tool.slug}>
146
- <Surface tone="surface" radius="xl" elevation="card" padded>
147
- <div className="mb-3 flex items-center gap-2.5">
148
- <ToolLogo slug={tool.slug} name={tool.name} />
149
- {/* The tool's own page is where its description, capabilities
150
- and owner-side setup live — this panel only shows the
151
- values. */}
152
- <Link
153
- to={pathForTool(tool.slug)}
154
- className="truncate rounded-xs text-ui font-semibold text-ink hover:underline"
155
- aria-label={`Open ${tool.name}`}
156
- >
157
- {tool.name}
158
- </Link>
159
- <span className="truncate text-meta text-ink-faint">{tool.path}</span>
160
- {tool.canWrite && (
161
- <Badge tone="outline" size="xs" className="ml-auto shrink-0">
162
- You can edit shared secrets
163
- </Badge>
164
- )}
165
- </div>
166
- <ToolSecretsPanel tool={tool} onChanged={() => void refresh()} />
167
- </Surface>
168
- </li>
169
- ))}
170
- </ul>
171
- )}
172
-
173
- <details>
174
- <summary className="cursor-pointer text-detail font-semibold text-ink-muted">
175
- Advanced: OAuth credentials
176
- </summary>
177
- <div className="mt-3 flex flex-col gap-3.5">
178
- <p className="text-detail text-ink-muted">
179
- OAuth secrets are per-user. Name the variable key exactly as the tool references it{' '}
180
- <code className="rounded-sm bg-sunken px-1 py-0.5 font-mono text-meta text-ink">
181
- {'<Manual>_<VAR>'}
182
- </code>
183
- , then sign in to complete the flow.
184
- </p>
185
- {oauthSecrets.length > 0 && (
186
- <ul className="flex flex-col gap-1.5">
187
- {oauthSecrets.map((s) => (
188
- <li
189
- key={s.id}
190
- className="flex items-center gap-2 rounded-lg border border-line bg-surface px-3 py-2.5"
191
- >
192
- <code className="rounded-sm bg-sunken px-1.5 py-0.5 font-mono text-meta text-ink">
193
- {`\${${s.key}}`}
194
- </code>
195
- <Badge tone={s.authorized ? 'ok' : 'wait'} size="xs" className="shrink-0">
196
- {s.authorized ? 'Connected' : 'Needs your sign-in'}
197
- </Badge>
198
- <span className="ml-auto flex shrink-0 items-center gap-1.5">
199
- <Button variant="outline" size="tiny" onClick={() => void onAuthorize(s.id)}>
200
- {s.authorized ? 'Reconnect' : 'Sign in'}
201
- </Button>
202
- {/* The accessible name has to START with the visible word
203
- (WCAG 2.5.3): "Delete secret" meant voice control could
204
- not act on a button that reads "Remove". The key is what
205
- makes it unambiguous in a list of otherwise identical
206
- rows, so it comes after. */}
207
- <Button
208
- variant="quiet"
209
- size="tiny"
210
- aria-label={`Remove ${s.key}`}
211
- onClick={() => void onDelete(s.id)}
212
- >
213
- Remove
214
- </Button>
215
- </span>
216
- </li>
217
- ))}
218
- </ul>
219
- )}
220
- <Surface tone="sunken" radius="lg" elevation="none" padded>
221
- <OAuthSecretForm onSaved={() => void refresh()} onError={setError} />
222
- </Surface>
223
- </div>
224
- </details>
225
- </PageShell>
226
- );
227
- }
228
-
229
- function OAuthSecretForm({ onSaved, onError }: { onSaved: () => void; onError: (m: string) => void }) {
230
- const [key, setKey] = useState('');
231
- const [authorizationUrl, setAuthorizationUrl] = useState('');
232
- const [tokenUrl, setTokenUrl] = useState('');
233
- const [clientId, setClientId] = useState('');
234
- const [clientSecret, setClientSecret] = useState('');
235
- const [scopes, setScopes] = useState('');
236
- const [busy, setBusy] = useState(false);
237
-
238
- const submit = async () => {
239
- setBusy(true);
240
- try {
241
- await createOAuthSecret({
242
- key: key.trim(),
243
- provider: {
244
- authorizationUrl: authorizationUrl.trim(),
245
- tokenUrl: tokenUrl.trim(),
246
- clientId: clientId.trim(),
247
- clientSecret: clientSecret.trim() || undefined,
248
- scopes: scopes.split(/[\s,]+/).filter(Boolean),
249
- },
250
- });
251
- onSaved();
252
- } catch (err) {
253
- onError(err instanceof Error ? err.message : String(err));
254
- } finally {
255
- setBusy(false);
256
- }
257
- };
258
-
259
- return (
260
- <div className="flex flex-col gap-2.5">
261
- <Field label="Variable key (Manual_VAR)">
262
- <TextField
263
- className="w-full"
264
- value={key}
265
- onChange={(e) => setKey(e.target.value)}
266
- placeholder="github_GITHUB_TOKEN"
267
- />
268
- </Field>
269
- <Field label="Authorization URL">
270
- <TextField className="w-full" value={authorizationUrl} onChange={(e) => setAuthorizationUrl(e.target.value)} />
271
- </Field>
272
- <Field label="Token URL">
273
- <TextField className="w-full" value={tokenUrl} onChange={(e) => setTokenUrl(e.target.value)} />
274
- </Field>
275
- <Field label="Client ID">
276
- <TextField className="w-full" value={clientId} onChange={(e) => setClientId(e.target.value)} />
277
- </Field>
278
- <Field label="Client secret (optional)">
279
- <TextField
280
- className="w-full"
281
- type="password"
282
- value={clientSecret}
283
- onChange={(e) => setClientSecret(e.target.value)}
284
- />
285
- </Field>
286
- <Field label="Scopes (space or comma separated)">
287
- <TextField className="w-full" value={scopes} onChange={(e) => setScopes(e.target.value)} />
288
- </Field>
289
- <p className="text-detail text-ink-muted">
290
- Save first, then click “Sign in” on the secret to complete the flow.
291
- </p>
292
- <div>
293
- <Button
294
- variant="primary"
295
- size="sm"
296
- disabled={busy || !key.trim() || !authorizationUrl.trim() || !tokenUrl.trim() || !clientId.trim()}
297
- onClick={() => void submit()}
298
- >
299
- Save OAuth secret
300
- </Button>
301
- </div>
302
- </div>
303
- );
304
- }
305
-
306
- function Field({ label, children }: { label: string; children: React.ReactNode }) {
307
- return (
308
- <label className="block">
309
- <span className="mb-0.5 block text-detail font-medium text-ink-muted">{label}</span>
310
- {children}
311
- </label>
312
- );
313
- }
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { Badge, Banner, Button, Surface, TextField } from '../../../shared/components';
4
+ import { PageShell } from '../../../shared/components/PageShell';
5
+ import { pathForTool } from '../../library/routes/library-paths';
6
+ import { ToolLogo } from '../../library/components/ToolLogo';
7
+ import {
8
+ listSecrets,
9
+ createOAuthSecret,
10
+ deleteSecret,
11
+ startOAuth,
12
+ type SecretSummary,
13
+ } from '../services/secrets.api';
14
+ import { listToolSecrets, type ToolSecrets } from '../services/tool-secrets.api';
15
+ import { ToolSecretsPanel } from './ToolSecretsPanel';
16
+
17
+ /**
18
+ * The Secrets page, routed standalone at `/secrets` (below the persistent
19
+ * toolbar). Primary surface is PER-TOOL: each `.tool` manual declares which
20
+ * `${VAR}`s are set by the tool owner (shared) vs by each user, and the panels
21
+ * let the right people fill the right values. OAuth credentials (per-user)
22
+ * live under "Advanced" — the callback/refresh flow is keyed by secret id.
23
+ *
24
+ * `/secrets` is also the standalone-secret OAuth landing: the backend
25
+ * callback returns the browser here with the outcome in the URL fragment
26
+ * (`#authorized` / `#error`), which the page surfaces and then strips.
27
+ *
28
+ * Visually this is the Library's sibling: tool logos lead the cards, statuses
29
+ * say `Connected` / `Set` / `Needs …` in the same grammar, and everything sits
30
+ * on the shared components rather than hand-rolled borders.
31
+ */
32
+ /**
33
+ * The OAuth-callback outcome carried in the URL fragment
34
+ * (`#authorized` / `#error=<message>`), or null when there is none.
35
+ * `URLSearchParams` already percent-decodes, so the value is used as-is (a
36
+ * second `decodeURIComponent` would corrupt messages containing `%`).
37
+ */
38
+ function readHashOutcome(): { kind: 'authorized' | 'error'; text: string } | null {
39
+ const hash = window.location.hash.replace(/^#/, '');
40
+ if (!hash) return null;
41
+ const params = new URLSearchParams(hash);
42
+ if (params.has('authorized')) return { kind: 'authorized', text: 'Authorization complete.' };
43
+ if (params.has('error'))
44
+ return { kind: 'error', text: params.get('error') || 'Authorization failed.' };
45
+ return null;
46
+ }
47
+
48
+ export function SecretsPage() {
49
+ const [tools, setTools] = useState<ToolSecrets[]>([]);
50
+ const [secrets, setSecrets] = useState<SecretSummary[]>([]);
51
+ const [loading, setLoading] = useState(true);
52
+ const [error, setError] = useState<string | null>(null);
53
+ // Read ONCE, synchronously, before the fragment is stripped below. Kept in
54
+ // its own slot (not the API `error` above) so the initial refresh() — whose
55
+ // success path clears the API error — can't race the outcome away.
56
+ const [oauthOutcome] = useState(readHashOutcome);
57
+
58
+ const refresh = useCallback(async () => {
59
+ setLoading(true);
60
+ try {
61
+ const [t, s] = await Promise.all([listToolSecrets(), listSecrets()]);
62
+ setTools(t);
63
+ setSecrets(s);
64
+ setError(null);
65
+ } catch (err) {
66
+ setError(err instanceof Error ? err.message : String(err));
67
+ } finally {
68
+ setLoading(false);
69
+ }
70
+ }, []);
71
+
72
+ useEffect(() => {
73
+ void refresh();
74
+ }, [refresh]);
75
+
76
+ // Strip the consumed fragment so a refresh doesn't re-announce the outcome.
77
+ useEffect(() => {
78
+ if (oauthOutcome) window.history.replaceState(null, '', window.location.pathname);
79
+ }, [oauthOutcome]);
80
+
81
+ // A live API error wins over the (historical) callback outcome; otherwise
82
+ // the callback error stays visible even after the list load succeeds.
83
+ const shownError = error ?? (oauthOutcome?.kind === 'error' ? oauthOutcome.text : null);
84
+ const notice = oauthOutcome?.kind === 'authorized' ? oauthOutcome.text : null;
85
+
86
+ const oauthSecrets = secrets.filter((s) => s.kind === 'oauth');
87
+
88
+ const onDelete = async (id: string) => {
89
+ try {
90
+ await deleteSecret(id);
91
+ await refresh();
92
+ } catch (err) {
93
+ setError(err instanceof Error ? err.message : String(err));
94
+ }
95
+ };
96
+
97
+ const onAuthorize = async (id: string) => {
98
+ try {
99
+ const url = await startOAuth(id);
100
+ window.location.href = url;
101
+ } catch (err) {
102
+ setError(err instanceof Error ? err.message : String(err));
103
+ }
104
+ };
105
+
106
+ return (
107
+ <PageShell
108
+ title="Secrets"
109
+ actions={
110
+ <Button variant="quiet" size="sm" disabled={loading} onClick={() => void refresh()}>
111
+ Refresh
112
+ </Button>
113
+ }
114
+ >
115
+ {shownError && (
116
+ <Banner role="alert" tone="danger" className="mb-3">
117
+ {shownError}
118
+ </Banner>
119
+ )}
120
+ {notice && (
121
+ <Banner role="status" tone="ok" className="mb-3">
122
+ {notice}
123
+ </Banner>
124
+ )}
125
+
126
+ <p className="mb-5 text-ui text-ink-muted">
127
+ Secrets back the{' '}
128
+ <code className="rounded-sm bg-sunken px-1 py-0.5 font-mono text-meta text-ink">
129
+ {'${VARIABLE}'}
130
+ </code>{' '}
131
+ placeholders in your tool manuals. Each tool declares which variables its owner sets once
132
+ (shared by everyone) and which each user sets for themselves. Values are never displayed
133
+ after saving.
134
+ </p>
135
+
136
+ {loading ? (
137
+ <p className="py-10 text-center text-ui text-ink-faint">Loading…</p>
138
+ ) : tools.length === 0 ? (
139
+ <p className="py-10 text-center text-ui text-ink-faint">
140
+ No tools you can access declare secrets yet.
141
+ </p>
142
+ ) : (
143
+ <ul className="mb-6 flex flex-col gap-2.5">
144
+ {tools.map((tool) => (
145
+ <li key={tool.slug}>
146
+ <Surface tone="surface" radius="xl" elevation="card" padded>
147
+ <div className="mb-3 flex items-center gap-2.5">
148
+ <ToolLogo slug={tool.slug} name={tool.name} />
149
+ {/* The tool's own page is where its description, capabilities
150
+ and owner-side setup live — this panel only shows the
151
+ values. */}
152
+ <Link
153
+ to={pathForTool(tool.slug)}
154
+ className="truncate rounded-xs text-ui font-semibold text-ink hover:underline"
155
+ aria-label={`Open ${tool.name}`}
156
+ >
157
+ {tool.name}
158
+ </Link>
159
+ <span className="truncate text-meta text-ink-faint">{tool.path}</span>
160
+ {tool.canWrite && (
161
+ <Badge tone="outline" size="xs" className="ml-auto shrink-0">
162
+ You can edit shared secrets
163
+ </Badge>
164
+ )}
165
+ </div>
166
+ <ToolSecretsPanel tool={tool} onChanged={() => void refresh()} />
167
+ </Surface>
168
+ </li>
169
+ ))}
170
+ </ul>
171
+ )}
172
+
173
+ <details>
174
+ <summary className="cursor-pointer text-detail font-semibold text-ink-muted">
175
+ Advanced: OAuth credentials
176
+ </summary>
177
+ <div className="mt-3 flex flex-col gap-3.5">
178
+ <p className="text-detail text-ink-muted">
179
+ OAuth secrets are per-user. Name the variable key exactly as the tool references it{' '}
180
+ <code className="rounded-sm bg-sunken px-1 py-0.5 font-mono text-meta text-ink">
181
+ {'<Manual>_<VAR>'}
182
+ </code>
183
+ , then sign in to complete the flow.
184
+ </p>
185
+ {oauthSecrets.length > 0 && (
186
+ <ul className="flex flex-col gap-1.5">
187
+ {oauthSecrets.map((s) => (
188
+ <li
189
+ key={s.id}
190
+ className="flex items-center gap-2 rounded-lg border border-line bg-surface px-3 py-2.5"
191
+ >
192
+ <code className="rounded-sm bg-sunken px-1.5 py-0.5 font-mono text-meta text-ink">
193
+ {`\${${s.key}}`}
194
+ </code>
195
+ <Badge tone={s.authorized ? 'ok' : 'wait'} size="xs" className="shrink-0">
196
+ {s.authorized ? 'Connected' : 'Needs your sign-in'}
197
+ </Badge>
198
+ <span className="ml-auto flex shrink-0 items-center gap-1.5">
199
+ <Button variant="outline" size="tiny" onClick={() => void onAuthorize(s.id)}>
200
+ {s.authorized ? 'Reconnect' : 'Sign in'}
201
+ </Button>
202
+ {/* The accessible name has to START with the visible word
203
+ (WCAG 2.5.3): "Delete secret" meant voice control could
204
+ not act on a button that reads "Remove". The key is what
205
+ makes it unambiguous in a list of otherwise identical
206
+ rows, so it comes after. */}
207
+ <Button
208
+ variant="quiet"
209
+ size="tiny"
210
+ aria-label={`Remove ${s.key}`}
211
+ onClick={() => void onDelete(s.id)}
212
+ >
213
+ Remove
214
+ </Button>
215
+ </span>
216
+ </li>
217
+ ))}
218
+ </ul>
219
+ )}
220
+ <Surface tone="sunken" radius="lg" elevation="none" padded>
221
+ <OAuthSecretForm onSaved={() => void refresh()} onError={setError} />
222
+ </Surface>
223
+ </div>
224
+ </details>
225
+ </PageShell>
226
+ );
227
+ }
228
+
229
+ function OAuthSecretForm({ onSaved, onError }: { onSaved: () => void; onError: (m: string) => void }) {
230
+ const [key, setKey] = useState('');
231
+ const [authorizationUrl, setAuthorizationUrl] = useState('');
232
+ const [tokenUrl, setTokenUrl] = useState('');
233
+ const [clientId, setClientId] = useState('');
234
+ const [clientSecret, setClientSecret] = useState('');
235
+ const [scopes, setScopes] = useState('');
236
+ const [busy, setBusy] = useState(false);
237
+
238
+ const submit = async () => {
239
+ setBusy(true);
240
+ try {
241
+ await createOAuthSecret({
242
+ key: key.trim(),
243
+ provider: {
244
+ authorizationUrl: authorizationUrl.trim(),
245
+ tokenUrl: tokenUrl.trim(),
246
+ clientId: clientId.trim(),
247
+ clientSecret: clientSecret.trim() || undefined,
248
+ scopes: scopes.split(/[\s,]+/).filter(Boolean),
249
+ },
250
+ });
251
+ onSaved();
252
+ } catch (err) {
253
+ onError(err instanceof Error ? err.message : String(err));
254
+ } finally {
255
+ setBusy(false);
256
+ }
257
+ };
258
+
259
+ return (
260
+ <div className="flex flex-col gap-2.5">
261
+ <Field label="Variable key (Manual_VAR)">
262
+ <TextField
263
+ className="w-full"
264
+ value={key}
265
+ onChange={(e) => setKey(e.target.value)}
266
+ placeholder="github_GITHUB_TOKEN"
267
+ />
268
+ </Field>
269
+ <Field label="Authorization URL">
270
+ <TextField className="w-full" value={authorizationUrl} onChange={(e) => setAuthorizationUrl(e.target.value)} />
271
+ </Field>
272
+ <Field label="Token URL">
273
+ <TextField className="w-full" value={tokenUrl} onChange={(e) => setTokenUrl(e.target.value)} />
274
+ </Field>
275
+ <Field label="Client ID">
276
+ <TextField className="w-full" value={clientId} onChange={(e) => setClientId(e.target.value)} />
277
+ </Field>
278
+ <Field label="Client secret (optional)">
279
+ <TextField
280
+ className="w-full"
281
+ type="password"
282
+ value={clientSecret}
283
+ onChange={(e) => setClientSecret(e.target.value)}
284
+ />
285
+ </Field>
286
+ <Field label="Scopes (space or comma separated)">
287
+ <TextField className="w-full" value={scopes} onChange={(e) => setScopes(e.target.value)} />
288
+ </Field>
289
+ <p className="text-detail text-ink-muted">
290
+ Save first, then click “Sign in” on the secret to complete the flow.
291
+ </p>
292
+ <div>
293
+ <Button
294
+ variant="primary"
295
+ size="sm"
296
+ disabled={busy || !key.trim() || !authorizationUrl.trim() || !tokenUrl.trim() || !clientId.trim()}
297
+ onClick={() => void submit()}
298
+ >
299
+ Save OAuth secret
300
+ </Button>
301
+ </div>
302
+ </div>
303
+ );
304
+ }
305
+
306
+ function Field({ label, children }: { label: string; children: React.ReactNode }) {
307
+ return (
308
+ <label className="block">
309
+ <span className="mb-0.5 block text-detail font-medium text-ink-muted">{label}</span>
310
+ {children}
311
+ </label>
312
+ );
313
+ }