@bevel-software/platform-core-frontend 0.4.0 → 0.4.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 (30) hide show
  1. package/package.json +2 -2
  2. package/src/core/__tests__/ShellRoutes.test.tsx +95 -95
  3. package/src/lib/utils.ts +138 -138
  4. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +156 -156
  5. package/src/modules/admin/components/UserAccountsPage.tsx +353 -353
  6. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
  7. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -200
  8. package/src/modules/library/__tests__/loadout.test.tsx +72 -72
  9. package/src/modules/library/__tests__/status.test.ts +117 -117
  10. package/src/modules/library/components/ChangeRequestDock.tsx +47 -47
  11. package/src/modules/library/components/CompareView.tsx +357 -357
  12. package/src/modules/library/components/DetailDialog.tsx +566 -566
  13. package/src/modules/library/components/GearIcon.tsx +12 -12
  14. package/src/modules/library/components/LibraryCard.tsx +132 -132
  15. package/src/modules/library/components/LibraryPage.tsx +254 -254
  16. package/src/modules/library/components/LoadoutSidebar.tsx +156 -156
  17. package/src/modules/library/components/StatusGem.tsx +21 -21
  18. package/src/modules/library/components/SuggestChange.tsx +171 -171
  19. package/src/modules/library/components/particles.ts +50 -50
  20. package/src/modules/library/library.css +320 -320
  21. package/src/modules/library/state/loadout.tsx +129 -129
  22. package/src/modules/library/utils/status.ts +116 -116
  23. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -276
  24. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -51
  25. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -108
  26. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
  27. package/src/modules/workspace/components/FileExplorer.tsx +1068 -1068
  28. package/src/modules/workspace/components/FileViewer.tsx +906 -906
  29. package/src/modules/workspace/utils/fileTree.ts +179 -179
  30. package/src/shared/components/PageShell.tsx +51 -51
@@ -1,276 +1,276 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { RefreshCw, Trash2, ShieldCheck, ExternalLink, Wrench } from 'lucide-react';
3
- import { PageShell } from '../../../shared/components/PageShell';
4
- import {
5
- listSecrets,
6
- createOAuthSecret,
7
- deleteSecret,
8
- startOAuth,
9
- type SecretSummary,
10
- } from '../services/secrets.api';
11
- import { listToolSecrets, type ToolSecrets } from '../services/tool-secrets.api';
12
- import { ToolSecretsPanel } from './ToolSecretsPanel';
13
-
14
- /**
15
- * The Secrets page, routed standalone at `/secrets` (below the persistent
16
- * toolbar). Primary surface is PER-TOOL: each `.tool` manual declares which
17
- * `${VAR}`s are set by the tool owner (shared) vs by each user, and the panels
18
- * let the right people fill the right values. OAuth credentials (per-user)
19
- * live under "Advanced" — the callback/refresh flow is keyed by secret id.
20
- *
21
- * `/secrets` is also the standalone-secret OAuth landing: the backend
22
- * callback returns the browser here with the outcome in the URL fragment
23
- * (`#authorized` / `#error`), which the page surfaces and then strips.
24
- */
25
- /**
26
- * The OAuth-callback outcome carried in the URL fragment
27
- * (`#authorized` / `#error=<message>`), or null when there is none.
28
- * `URLSearchParams` already percent-decodes, so the value is used as-is (a
29
- * second `decodeURIComponent` would corrupt messages containing `%`).
30
- */
31
- function readHashOutcome(): { kind: 'authorized' | 'error'; text: string } | null {
32
- const hash = window.location.hash.replace(/^#/, '');
33
- if (!hash) return null;
34
- const params = new URLSearchParams(hash);
35
- if (params.has('authorized')) return { kind: 'authorized', text: 'Authorization complete.' };
36
- if (params.has('error'))
37
- return { kind: 'error', text: params.get('error') || 'Authorization failed.' };
38
- return null;
39
- }
40
-
41
- export function SecretsPage() {
42
- const [tools, setTools] = useState<ToolSecrets[]>([]);
43
- const [secrets, setSecrets] = useState<SecretSummary[]>([]);
44
- const [loading, setLoading] = useState(true);
45
- const [error, setError] = useState<string | null>(null);
46
- // Read ONCE, synchronously, before the fragment is stripped below. Kept in
47
- // its own slot (not the API `error` above) so the initial refresh() — whose
48
- // success path clears the API error — can't race the outcome away.
49
- const [oauthOutcome] = useState(readHashOutcome);
50
-
51
- const refresh = useCallback(async () => {
52
- setLoading(true);
53
- try {
54
- const [t, s] = await Promise.all([listToolSecrets(), listSecrets()]);
55
- setTools(t);
56
- setSecrets(s);
57
- setError(null);
58
- } catch (err) {
59
- setError(err instanceof Error ? err.message : String(err));
60
- } finally {
61
- setLoading(false);
62
- }
63
- }, []);
64
-
65
- useEffect(() => {
66
- void refresh();
67
- }, [refresh]);
68
-
69
- // Strip the consumed fragment so a refresh doesn't re-announce the outcome.
70
- useEffect(() => {
71
- if (oauthOutcome) window.history.replaceState(null, '', window.location.pathname);
72
- }, [oauthOutcome]);
73
-
74
- // A live API error wins over the (historical) callback outcome; otherwise
75
- // the callback error stays visible even after the list load succeeds.
76
- const shownError = error ?? (oauthOutcome?.kind === 'error' ? oauthOutcome.text : null);
77
- const notice = oauthOutcome?.kind === 'authorized' ? oauthOutcome.text : null;
78
-
79
- const oauthSecrets = secrets.filter((s) => s.kind === 'oauth');
80
-
81
- const onDelete = async (id: string) => {
82
- try {
83
- await deleteSecret(id);
84
- await refresh();
85
- } catch (err) {
86
- setError(err instanceof Error ? err.message : String(err));
87
- }
88
- };
89
-
90
- const onAuthorize = async (id: string) => {
91
- try {
92
- const url = await startOAuth(id);
93
- window.location.href = url;
94
- } catch (err) {
95
- setError(err instanceof Error ? err.message : String(err));
96
- }
97
- };
98
-
99
- return (
100
- <PageShell
101
- title="Secrets"
102
- actions={
103
- <button
104
- onClick={() => void refresh()}
105
- disabled={loading}
106
- className="rounded p-1.5 hover:bg-slate-200/60 text-slate-600"
107
- aria-label="Refresh"
108
- >
109
- <RefreshCw size={14} className={loading ? 'animate-spin' : ''} />
110
- </button>
111
- }
112
- >
113
- {shownError && (
114
- <div className="mb-3 rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700">{shownError}</div>
115
- )}
116
- {notice && (
117
- <div className="mb-3 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-700">
118
- {notice}
119
- </div>
120
- )}
121
-
122
- <p className="mb-4 max-w-2xl text-xs text-slate-500">
123
- Secrets back the <code className="rounded bg-slate-100 px-1">{'${VARIABLE}'}</code> placeholders in your tool
124
- manuals. Each tool declares which variables its owner sets once (shared by everyone) and which each user sets
125
- for themselves. Values are never displayed after saving.
126
- </p>
127
-
128
- {loading ? (
129
- <div className="text-xs text-slate-400">Loading…</div>
130
- ) : tools.length === 0 ? (
131
- <div className="rounded border border-dashed border-slate-200 px-4 py-6 text-center text-xs text-slate-400">
132
- No tools you can access declare secrets yet.
133
- </div>
134
- ) : (
135
- <ul className="mb-6 max-w-2xl space-y-3">
136
- {tools.map((tool) => (
137
- <li key={tool.slug} className="rounded border border-slate-200 p-3">
138
- <div className="mb-2 flex items-center gap-2">
139
- <Wrench size={13} className="text-slate-500" />
140
- <span className="text-xs font-semibold text-slate-700">{tool.name}</span>
141
- <span className="text-[10px] text-slate-400">{tool.path}</span>
142
- {tool.canWrite && (
143
- <span className="ml-auto rounded bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-500">
144
- you can edit shared secrets
145
- </span>
146
- )}
147
- </div>
148
- <ToolSecretsPanel tool={tool} onChanged={() => void refresh()} />
149
- </li>
150
- ))}
151
- </ul>
152
- )}
153
-
154
- <details className="max-w-2xl">
155
- <summary className="cursor-pointer text-xs font-medium text-slate-600">Advanced — OAuth credentials</summary>
156
- <div className="mt-3 space-y-4">
157
- <p className="text-[11px] text-slate-400">
158
- OAuth secrets are per-user. Name the variable key exactly as the tool references it —
159
- <code className="rounded bg-slate-100 px-1">{'<Manual>_<VAR>'}</code> — then click Authorize to complete
160
- the flow.
161
- </p>
162
- {oauthSecrets.length > 0 && (
163
- <ul className="divide-y divide-slate-100 rounded border border-slate-200">
164
- {oauthSecrets.map((s) => (
165
- <li key={s.id} className="flex items-center gap-3 px-3 py-2">
166
- <code className="rounded bg-slate-100 px-1.5 py-0.5 text-xs font-medium text-slate-700">
167
- {`\${${s.key}}`}
168
- </code>
169
- {s.authorized ? (
170
- <span className="flex items-center gap-1 text-[11px] text-emerald-600">
171
- <ShieldCheck size={12} /> authorized
172
- </span>
173
- ) : (
174
- <span className="text-[11px] text-amber-600">not authorized</span>
175
- )}
176
- <div className="ml-auto flex items-center gap-1">
177
- <button
178
- onClick={() => void onAuthorize(s.id)}
179
- className="flex items-center gap-1 rounded px-2 py-1 text-xs text-blue-600 hover:bg-blue-50"
180
- >
181
- <ExternalLink size={12} /> {s.authorized ? 'Re-authorize' : 'Authorize'}
182
- </button>
183
- <button
184
- onClick={() => void onDelete(s.id)}
185
- className="rounded p-1 text-slate-400 hover:bg-red-50 hover:text-red-600"
186
- aria-label="Delete secret"
187
- >
188
- <Trash2 size={14} />
189
- </button>
190
- </div>
191
- </li>
192
- ))}
193
- </ul>
194
- )}
195
- <div className="rounded border border-slate-200 p-4">
196
- <OAuthSecretForm onSaved={() => void refresh()} onError={setError} />
197
- </div>
198
- </div>
199
- </details>
200
- </PageShell>
201
- );
202
- }
203
-
204
- const inputCls =
205
- 'w-full rounded border border-slate-300 px-2 py-1.5 text-xs focus:border-slate-500 focus:outline-none';
206
-
207
- function OAuthSecretForm({ onSaved, onError }: { onSaved: () => void; onError: (m: string) => void }) {
208
- const [key, setKey] = useState('');
209
- const [authorizationUrl, setAuthorizationUrl] = useState('');
210
- const [tokenUrl, setTokenUrl] = useState('');
211
- const [clientId, setClientId] = useState('');
212
- const [clientSecret, setClientSecret] = useState('');
213
- const [scopes, setScopes] = useState('');
214
- const [busy, setBusy] = useState(false);
215
-
216
- const submit = async () => {
217
- setBusy(true);
218
- try {
219
- await createOAuthSecret({
220
- key: key.trim(),
221
- provider: {
222
- authorizationUrl: authorizationUrl.trim(),
223
- tokenUrl: tokenUrl.trim(),
224
- clientId: clientId.trim(),
225
- clientSecret: clientSecret.trim() || undefined,
226
- scopes: scopes.split(/[\s,]+/).filter(Boolean),
227
- },
228
- });
229
- onSaved();
230
- } catch (err) {
231
- onError(err instanceof Error ? err.message : String(err));
232
- } finally {
233
- setBusy(false);
234
- }
235
- };
236
-
237
- return (
238
- <div className="space-y-2">
239
- <Field label="Variable key (Manual_VAR)">
240
- <input className={inputCls} value={key} onChange={(e) => setKey(e.target.value)} placeholder="github_GITHUB_TOKEN" />
241
- </Field>
242
- <Field label="Authorization URL">
243
- <input className={inputCls} value={authorizationUrl} onChange={(e) => setAuthorizationUrl(e.target.value)} />
244
- </Field>
245
- <Field label="Token URL">
246
- <input className={inputCls} value={tokenUrl} onChange={(e) => setTokenUrl(e.target.value)} />
247
- </Field>
248
- <Field label="Client ID">
249
- <input className={inputCls} value={clientId} onChange={(e) => setClientId(e.target.value)} />
250
- </Field>
251
- <Field label="Client secret (optional)">
252
- <input className={inputCls} type="password" value={clientSecret} onChange={(e) => setClientSecret(e.target.value)} />
253
- </Field>
254
- <Field label="Scopes (space or comma separated)">
255
- <input className={inputCls} value={scopes} onChange={(e) => setScopes(e.target.value)} />
256
- </Field>
257
- <p className="text-[11px] text-slate-400">Save first, then click “Authorize” on the secret to complete the flow.</p>
258
- <button
259
- onClick={() => void submit()}
260
- disabled={busy || !key.trim() || !authorizationUrl.trim() || !tokenUrl.trim() || !clientId.trim()}
261
- className="rounded bg-slate-800 px-3 py-1.5 text-xs font-medium text-white disabled:opacity-40"
262
- >
263
- Save OAuth secret
264
- </button>
265
- </div>
266
- );
267
- }
268
-
269
- function Field({ label, children }: { label: string; children: React.ReactNode }) {
270
- return (
271
- <label className="block">
272
- <span className="mb-0.5 block text-[11px] font-medium text-slate-500">{label}</span>
273
- {children}
274
- </label>
275
- );
276
- }
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { RefreshCw, Trash2, ShieldCheck, ExternalLink, Wrench } from 'lucide-react';
3
+ import { PageShell } from '../../../shared/components/PageShell';
4
+ import {
5
+ listSecrets,
6
+ createOAuthSecret,
7
+ deleteSecret,
8
+ startOAuth,
9
+ type SecretSummary,
10
+ } from '../services/secrets.api';
11
+ import { listToolSecrets, type ToolSecrets } from '../services/tool-secrets.api';
12
+ import { ToolSecretsPanel } from './ToolSecretsPanel';
13
+
14
+ /**
15
+ * The Secrets page, routed standalone at `/secrets` (below the persistent
16
+ * toolbar). Primary surface is PER-TOOL: each `.tool` manual declares which
17
+ * `${VAR}`s are set by the tool owner (shared) vs by each user, and the panels
18
+ * let the right people fill the right values. OAuth credentials (per-user)
19
+ * live under "Advanced" — the callback/refresh flow is keyed by secret id.
20
+ *
21
+ * `/secrets` is also the standalone-secret OAuth landing: the backend
22
+ * callback returns the browser here with the outcome in the URL fragment
23
+ * (`#authorized` / `#error`), which the page surfaces and then strips.
24
+ */
25
+ /**
26
+ * The OAuth-callback outcome carried in the URL fragment
27
+ * (`#authorized` / `#error=<message>`), or null when there is none.
28
+ * `URLSearchParams` already percent-decodes, so the value is used as-is (a
29
+ * second `decodeURIComponent` would corrupt messages containing `%`).
30
+ */
31
+ function readHashOutcome(): { kind: 'authorized' | 'error'; text: string } | null {
32
+ const hash = window.location.hash.replace(/^#/, '');
33
+ if (!hash) return null;
34
+ const params = new URLSearchParams(hash);
35
+ if (params.has('authorized')) return { kind: 'authorized', text: 'Authorization complete.' };
36
+ if (params.has('error'))
37
+ return { kind: 'error', text: params.get('error') || 'Authorization failed.' };
38
+ return null;
39
+ }
40
+
41
+ export function SecretsPage() {
42
+ const [tools, setTools] = useState<ToolSecrets[]>([]);
43
+ const [secrets, setSecrets] = useState<SecretSummary[]>([]);
44
+ const [loading, setLoading] = useState(true);
45
+ const [error, setError] = useState<string | null>(null);
46
+ // Read ONCE, synchronously, before the fragment is stripped below. Kept in
47
+ // its own slot (not the API `error` above) so the initial refresh() — whose
48
+ // success path clears the API error — can't race the outcome away.
49
+ const [oauthOutcome] = useState(readHashOutcome);
50
+
51
+ const refresh = useCallback(async () => {
52
+ setLoading(true);
53
+ try {
54
+ const [t, s] = await Promise.all([listToolSecrets(), listSecrets()]);
55
+ setTools(t);
56
+ setSecrets(s);
57
+ setError(null);
58
+ } catch (err) {
59
+ setError(err instanceof Error ? err.message : String(err));
60
+ } finally {
61
+ setLoading(false);
62
+ }
63
+ }, []);
64
+
65
+ useEffect(() => {
66
+ void refresh();
67
+ }, [refresh]);
68
+
69
+ // Strip the consumed fragment so a refresh doesn't re-announce the outcome.
70
+ useEffect(() => {
71
+ if (oauthOutcome) window.history.replaceState(null, '', window.location.pathname);
72
+ }, [oauthOutcome]);
73
+
74
+ // A live API error wins over the (historical) callback outcome; otherwise
75
+ // the callback error stays visible even after the list load succeeds.
76
+ const shownError = error ?? (oauthOutcome?.kind === 'error' ? oauthOutcome.text : null);
77
+ const notice = oauthOutcome?.kind === 'authorized' ? oauthOutcome.text : null;
78
+
79
+ const oauthSecrets = secrets.filter((s) => s.kind === 'oauth');
80
+
81
+ const onDelete = async (id: string) => {
82
+ try {
83
+ await deleteSecret(id);
84
+ await refresh();
85
+ } catch (err) {
86
+ setError(err instanceof Error ? err.message : String(err));
87
+ }
88
+ };
89
+
90
+ const onAuthorize = async (id: string) => {
91
+ try {
92
+ const url = await startOAuth(id);
93
+ window.location.href = url;
94
+ } catch (err) {
95
+ setError(err instanceof Error ? err.message : String(err));
96
+ }
97
+ };
98
+
99
+ return (
100
+ <PageShell
101
+ title="Secrets"
102
+ actions={
103
+ <button
104
+ onClick={() => void refresh()}
105
+ disabled={loading}
106
+ className="rounded p-1.5 hover:bg-slate-200/60 text-slate-600"
107
+ aria-label="Refresh"
108
+ >
109
+ <RefreshCw size={14} className={loading ? 'animate-spin' : ''} />
110
+ </button>
111
+ }
112
+ >
113
+ {shownError && (
114
+ <div className="mb-3 rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700">{shownError}</div>
115
+ )}
116
+ {notice && (
117
+ <div className="mb-3 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-700">
118
+ {notice}
119
+ </div>
120
+ )}
121
+
122
+ <p className="mb-4 max-w-2xl text-xs text-slate-500">
123
+ Secrets back the <code className="rounded bg-slate-100 px-1">{'${VARIABLE}'}</code> placeholders in your tool
124
+ manuals. Each tool declares which variables its owner sets once (shared by everyone) and which each user sets
125
+ for themselves. Values are never displayed after saving.
126
+ </p>
127
+
128
+ {loading ? (
129
+ <div className="text-xs text-slate-400">Loading…</div>
130
+ ) : tools.length === 0 ? (
131
+ <div className="rounded border border-dashed border-slate-200 px-4 py-6 text-center text-xs text-slate-400">
132
+ No tools you can access declare secrets yet.
133
+ </div>
134
+ ) : (
135
+ <ul className="mb-6 max-w-2xl space-y-3">
136
+ {tools.map((tool) => (
137
+ <li key={tool.slug} className="rounded border border-slate-200 p-3">
138
+ <div className="mb-2 flex items-center gap-2">
139
+ <Wrench size={13} className="text-slate-500" />
140
+ <span className="text-xs font-semibold text-slate-700">{tool.name}</span>
141
+ <span className="text-[10px] text-slate-400">{tool.path}</span>
142
+ {tool.canWrite && (
143
+ <span className="ml-auto rounded bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-500">
144
+ you can edit shared secrets
145
+ </span>
146
+ )}
147
+ </div>
148
+ <ToolSecretsPanel tool={tool} onChanged={() => void refresh()} />
149
+ </li>
150
+ ))}
151
+ </ul>
152
+ )}
153
+
154
+ <details className="max-w-2xl">
155
+ <summary className="cursor-pointer text-xs font-medium text-slate-600">Advanced — OAuth credentials</summary>
156
+ <div className="mt-3 space-y-4">
157
+ <p className="text-[11px] text-slate-400">
158
+ OAuth secrets are per-user. Name the variable key exactly as the tool references it —
159
+ <code className="rounded bg-slate-100 px-1">{'<Manual>_<VAR>'}</code> — then click Authorize to complete
160
+ the flow.
161
+ </p>
162
+ {oauthSecrets.length > 0 && (
163
+ <ul className="divide-y divide-slate-100 rounded border border-slate-200">
164
+ {oauthSecrets.map((s) => (
165
+ <li key={s.id} className="flex items-center gap-3 px-3 py-2">
166
+ <code className="rounded bg-slate-100 px-1.5 py-0.5 text-xs font-medium text-slate-700">
167
+ {`\${${s.key}}`}
168
+ </code>
169
+ {s.authorized ? (
170
+ <span className="flex items-center gap-1 text-[11px] text-emerald-600">
171
+ <ShieldCheck size={12} /> authorized
172
+ </span>
173
+ ) : (
174
+ <span className="text-[11px] text-amber-600">not authorized</span>
175
+ )}
176
+ <div className="ml-auto flex items-center gap-1">
177
+ <button
178
+ onClick={() => void onAuthorize(s.id)}
179
+ className="flex items-center gap-1 rounded px-2 py-1 text-xs text-blue-600 hover:bg-blue-50"
180
+ >
181
+ <ExternalLink size={12} /> {s.authorized ? 'Re-authorize' : 'Authorize'}
182
+ </button>
183
+ <button
184
+ onClick={() => void onDelete(s.id)}
185
+ className="rounded p-1 text-slate-400 hover:bg-red-50 hover:text-red-600"
186
+ aria-label="Delete secret"
187
+ >
188
+ <Trash2 size={14} />
189
+ </button>
190
+ </div>
191
+ </li>
192
+ ))}
193
+ </ul>
194
+ )}
195
+ <div className="rounded border border-slate-200 p-4">
196
+ <OAuthSecretForm onSaved={() => void refresh()} onError={setError} />
197
+ </div>
198
+ </div>
199
+ </details>
200
+ </PageShell>
201
+ );
202
+ }
203
+
204
+ const inputCls =
205
+ 'w-full rounded border border-slate-300 px-2 py-1.5 text-xs focus:border-slate-500 focus:outline-none';
206
+
207
+ function OAuthSecretForm({ onSaved, onError }: { onSaved: () => void; onError: (m: string) => void }) {
208
+ const [key, setKey] = useState('');
209
+ const [authorizationUrl, setAuthorizationUrl] = useState('');
210
+ const [tokenUrl, setTokenUrl] = useState('');
211
+ const [clientId, setClientId] = useState('');
212
+ const [clientSecret, setClientSecret] = useState('');
213
+ const [scopes, setScopes] = useState('');
214
+ const [busy, setBusy] = useState(false);
215
+
216
+ const submit = async () => {
217
+ setBusy(true);
218
+ try {
219
+ await createOAuthSecret({
220
+ key: key.trim(),
221
+ provider: {
222
+ authorizationUrl: authorizationUrl.trim(),
223
+ tokenUrl: tokenUrl.trim(),
224
+ clientId: clientId.trim(),
225
+ clientSecret: clientSecret.trim() || undefined,
226
+ scopes: scopes.split(/[\s,]+/).filter(Boolean),
227
+ },
228
+ });
229
+ onSaved();
230
+ } catch (err) {
231
+ onError(err instanceof Error ? err.message : String(err));
232
+ } finally {
233
+ setBusy(false);
234
+ }
235
+ };
236
+
237
+ return (
238
+ <div className="space-y-2">
239
+ <Field label="Variable key (Manual_VAR)">
240
+ <input className={inputCls} value={key} onChange={(e) => setKey(e.target.value)} placeholder="github_GITHUB_TOKEN" />
241
+ </Field>
242
+ <Field label="Authorization URL">
243
+ <input className={inputCls} value={authorizationUrl} onChange={(e) => setAuthorizationUrl(e.target.value)} />
244
+ </Field>
245
+ <Field label="Token URL">
246
+ <input className={inputCls} value={tokenUrl} onChange={(e) => setTokenUrl(e.target.value)} />
247
+ </Field>
248
+ <Field label="Client ID">
249
+ <input className={inputCls} value={clientId} onChange={(e) => setClientId(e.target.value)} />
250
+ </Field>
251
+ <Field label="Client secret (optional)">
252
+ <input className={inputCls} type="password" value={clientSecret} onChange={(e) => setClientSecret(e.target.value)} />
253
+ </Field>
254
+ <Field label="Scopes (space or comma separated)">
255
+ <input className={inputCls} value={scopes} onChange={(e) => setScopes(e.target.value)} />
256
+ </Field>
257
+ <p className="text-[11px] text-slate-400">Save first, then click “Authorize” on the secret to complete the flow.</p>
258
+ <button
259
+ onClick={() => void submit()}
260
+ disabled={busy || !key.trim() || !authorizationUrl.trim() || !tokenUrl.trim() || !clientId.trim()}
261
+ className="rounded bg-slate-800 px-3 py-1.5 text-xs font-medium text-white disabled:opacity-40"
262
+ >
263
+ Save OAuth secret
264
+ </button>
265
+ </div>
266
+ );
267
+ }
268
+
269
+ function Field({ label, children }: { label: string; children: React.ReactNode }) {
270
+ return (
271
+ <label className="block">
272
+ <span className="mb-0.5 block text-[11px] font-medium text-slate-500">{label}</span>
273
+ {children}
274
+ </label>
275
+ );
276
+ }