@shellui/core 0.7.0-beta.1 → 0.8.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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/package.json +3 -3
  4. package/schemas/shellui.config.schema.json +45 -2
  5. package/src/app.tsx +2 -0
  6. package/src/features/auth/AuthProvider.tsx +212 -97
  7. package/src/features/auth/appBackend/configSchema.spec.ts +1 -0
  8. package/src/features/auth/appBackend/frameAuth.ts +5 -0
  9. package/src/features/auth/backends/shellui.spec.ts +110 -0
  10. package/src/features/auth/backends/shellui.ts +47 -20
  11. package/src/features/auth/backends/types.ts +5 -0
  12. package/src/features/auth/hooks/useAuth.tsx +6 -1
  13. package/src/features/auth/types.ts +5 -0
  14. package/src/features/auth/utils/bffAuthClient.spec.ts +313 -0
  15. package/src/features/auth/utils/bffAuthClient.ts +171 -49
  16. package/src/features/auth/utils/buildSessionFromParams.ts +5 -2
  17. package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +12 -0
  18. package/src/features/auth/utils/buildSessionFromTokenPayload.ts +3 -1
  19. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +140 -4
  20. package/src/features/auth/utils/canRestoreStoredSession.ts +47 -0
  21. package/src/features/auth/utils/cliCallback.ts +5 -0
  22. package/src/features/auth/utils/identityBrowserLogout.spec.ts +185 -0
  23. package/src/features/auth/utils/identityBrowserLogout.ts +174 -0
  24. package/src/features/auth/utils/index.ts +21 -3
  25. package/src/features/auth/utils/isBffAuthEnabled.ts +10 -2
  26. package/src/features/auth/utils/normalizeAuthSettings.spec.ts +9 -0
  27. package/src/features/auth/utils/normalizeAuthSettings.ts +3 -1
  28. package/src/features/auth/utils/pkce.spec.ts +29 -1
  29. package/src/features/auth/utils/pkce.ts +106 -2
  30. package/src/features/config/types.ts +37 -5
  31. package/src/features/mcp/mcpActivityErrorCodeI18n.spec.ts +32 -0
  32. package/src/features/mcp/mcpActivityErrorCodeI18n.ts +30 -0
  33. package/src/features/mcp/mcpAgentActivityMerge.spec.ts +91 -0
  34. package/src/features/mcp/mcpAgentActivityMerge.ts +53 -0
  35. package/src/features/mcp/mcpAgentActivityPresentation.spec.ts +129 -0
  36. package/src/features/mcp/mcpAgentActivityPresentation.ts +201 -0
  37. package/src/features/mcp/mcpAgentsConnect.spec.ts +215 -0
  38. package/src/features/mcp/mcpAgentsConnect.ts +189 -0
  39. package/src/features/mcp/mcpToolActivityRegistry.spec.ts +9 -0
  40. package/src/features/mcp/mcpToolActivityRegistry.ts +20 -0
  41. package/src/features/mcp/mcpToolApprovalsApi.spec.ts +113 -0
  42. package/src/features/mcp/mcpToolApprovalsApi.ts +162 -0
  43. package/src/features/mcp/personalAgentsApi.spec.ts +661 -0
  44. package/src/features/mcp/personalAgentsApi.ts +697 -0
  45. package/src/features/settings/SettingsIcons.tsx +28 -0
  46. package/src/features/settings/SettingsRoutes.tsx +8 -0
  47. package/src/features/settings/SettingsView.tsx +90 -26
  48. package/src/features/settings/components/McpAgentActivitySection.spec.tsx +255 -0
  49. package/src/features/settings/components/McpAgentActivitySection.tsx +481 -0
  50. package/src/features/settings/components/McpAgents.spec.tsx +336 -0
  51. package/src/features/settings/components/McpAgents.tsx +654 -0
  52. package/src/features/settings/components/McpPendingApprovals.spec.tsx +201 -0
  53. package/src/features/settings/components/McpPendingApprovals.tsx +168 -0
  54. package/src/features/settings/components/McpPersonalStatusPrefetch.tsx +21 -0
  55. package/src/features/settings/hooks/useMcpPendingToolApprovals.ts +69 -0
  56. package/src/features/settings/hooks/useMcpPersonalStatus.ts +83 -0
  57. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +44 -1
  58. package/src/features/settings/utils/buildSettingsForPropagation.ts +30 -1
  59. package/src/features/settings/utils/isMcpAgentsSettingsEligible.spec.ts +25 -0
  60. package/src/features/settings/utils/isMcpAgentsSettingsEligible.ts +14 -0
  61. package/src/features/settings/utils/loadMcpPersonalStatus.spec.ts +76 -0
  62. package/src/features/settings/utils/loadMcpPersonalStatus.ts +84 -0
  63. package/src/features/settings/utils/mcpPersonalStatusCache.spec.ts +77 -0
  64. package/src/features/settings/utils/mcpPersonalStatusCache.ts +95 -0
  65. package/src/features/settings/utils/shouldShowMcpAgentsSettings.spec.ts +66 -0
  66. package/src/features/settings/utils/shouldShowMcpAgentsSettings.ts +16 -0
  67. package/src/i18n/translations/en/settings.json +201 -0
  68. package/src/i18n/translations/fr/settings.json +201 -0
  69. package/src/index.ts +1 -0
  70. package/src/service-worker/sw.ts +4 -2
@@ -0,0 +1,654 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { shellui } from '@shellui/sdk';
4
+ import { Button } from '../../../components/ui/button';
5
+ import { Input } from '../../../components/ui/input';
6
+ import { useAuth } from '../../auth/hooks/useAuth';
7
+ import {
8
+ agentIncludesSaasScope,
9
+ buildAgentPrompt,
10
+ buildCompanyMcpUrl,
11
+ MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS,
12
+ defaultPersonalAgentExpiresAt,
13
+ formatAgentExpiry,
14
+ formatConnectionDate,
15
+ formatDefaultAgentName,
16
+ getDefaultPersonalAgentServices,
17
+ isAbsoluteHttpUrl,
18
+ isActiveMcpConnection,
19
+ isGlobalIdentitySession,
20
+ resolveAgentConnectPromptLocale,
21
+ } from '../../mcp/mcpAgentsConnect';
22
+ import {
23
+ createMcpPersonalAgent,
24
+ fetchMcpPersonalAgents,
25
+ getMcpPersonalCompanyId,
26
+ getShellIdentityBackendUrl,
27
+ revokeMcpPersonalAgent,
28
+ type CreatePersonalAgentResult,
29
+ type McpAgentSummary,
30
+ } from '../../mcp/personalAgentsApi';
31
+ import { getMcpSettingsCompanyDisplayName } from '../../mcp/mcpToolApprovalsApi';
32
+ import { useConfig } from '../../config/useConfig';
33
+ import { getNormalizedAiServiceUrl } from '../utils/buildSettingsForPropagation';
34
+ import { useMcpPersonalStatus } from '../hooks/useMcpPersonalStatus';
35
+ import { useMcpPendingToolApprovals } from '../hooks/useMcpPendingToolApprovals';
36
+ import { McpAgentActivitySection } from './McpAgentActivitySection';
37
+ import { McpPendingApprovals } from './McpPendingApprovals';
38
+
39
+ type IssuedSecret = {
40
+ accessToken: string;
41
+ };
42
+
43
+ export const McpAgents = () => {
44
+ const { t, i18n } = useTranslation('settings');
45
+ const locale = i18n.language || 'en';
46
+ const { config } = useConfig();
47
+ const { session, isAuthenticated, user } = useAuth();
48
+ const accessToken = session?.accessToken ?? null;
49
+ const backendUrl = getShellIdentityBackendUrl(config);
50
+ const companyId = getMcpPersonalCompanyId(config);
51
+ const aiServiceUrl = getNormalizedAiServiceUrl(config?.aiService);
52
+
53
+ const {
54
+ status,
55
+ loading: statusLoading,
56
+ error: statusError,
57
+ refresh: refreshStatus,
58
+ } = useMcpPersonalStatus(config, accessToken, isAuthenticated, user?.id ?? null);
59
+
60
+ const includeSaas = isGlobalIdentitySession(status);
61
+ const companyDisplayName = getMcpSettingsCompanyDisplayName(config);
62
+ const pendingEnabled = Boolean(backendUrl && accessToken && status?.mcpEnabled);
63
+ const {
64
+ approvals: pendingApprovals,
65
+ pendingCount: pendingCountState,
66
+ refresh: refreshPending,
67
+ } = useMcpPendingToolApprovals(backendUrl ?? '', accessToken ?? '', companyId, pendingEnabled);
68
+ const pendingSectionRef = useRef<HTMLElement | null>(null);
69
+
70
+ const scrollToPendingApprovals = useCallback(() => {
71
+ pendingSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });
72
+ }, []);
73
+
74
+ const globalMcpDisplayUrl = useMemo(() => {
75
+ const u = status?.globalMcpUrl?.trim() ?? '';
76
+ return u || null;
77
+ }, [status?.globalMcpUrl]);
78
+
79
+ const companyMcpUrl = useMemo(
80
+ () => buildCompanyMcpUrl(aiServiceUrl, companyId, status?.mcpUrl),
81
+ [aiServiceUrl, companyId, status?.mcpUrl],
82
+ );
83
+ const absoluteMcpUrl = useMemo(
84
+ () => (companyMcpUrl && isAbsoluteHttpUrl(companyMcpUrl) ? companyMcpUrl : null),
85
+ [companyMcpUrl],
86
+ );
87
+ const connectPrompt = useMemo(
88
+ () =>
89
+ absoluteMcpUrl
90
+ ? buildAgentPrompt(absoluteMcpUrl, resolveAgentConnectPromptLocale(locale))
91
+ : null,
92
+ [absoluteMcpUrl, locale],
93
+ );
94
+
95
+ const [agents, setAgents] = useState<McpAgentSummary[]>([]);
96
+ const [agentsLoading, setAgentsLoading] = useState(false);
97
+ const [agentsError, setAgentsError] = useState(false);
98
+ const [showRevoked, setShowRevoked] = useState(false);
99
+
100
+ const [name, setName] = useState('');
101
+ const [creating, setCreating] = useState(false);
102
+ const [createError, setCreateError] = useState<string | null>(null);
103
+ const [issuedSecret, setIssuedSecret] = useState<IssuedSecret | null>(null);
104
+ const staticDetailsRef = useRef<HTMLDetailsElement>(null);
105
+
106
+ const copyValue = useCallback(
107
+ async (label: string, value: string) => {
108
+ if (!navigator?.clipboard?.writeText) {
109
+ shellui.toast({
110
+ type: 'error',
111
+ title: t('mcpAgents.clipboard.copyFailedTitle'),
112
+ description: t('mcpAgents.clipboard.unavailable'),
113
+ });
114
+ return;
115
+ }
116
+ try {
117
+ await navigator.clipboard.writeText(value);
118
+ shellui.toast({
119
+ type: 'success',
120
+ title: t('mcpAgents.clipboard.copiedTitle'),
121
+ description: t('mcpAgents.clipboard.copiedDescription', { label }),
122
+ });
123
+ } catch {
124
+ shellui.toast({
125
+ type: 'error',
126
+ title: t('mcpAgents.clipboard.copyFailedTitle'),
127
+ description: t('mcpAgents.clipboard.failed'),
128
+ });
129
+ }
130
+ },
131
+ [t],
132
+ );
133
+
134
+ const loadAgents = useCallback(
135
+ async (options?: { silent?: boolean }) => {
136
+ if (!backendUrl || !accessToken || !status?.mcpEnabled) {
137
+ setAgents([]);
138
+ return;
139
+ }
140
+ if (!options?.silent) {
141
+ setAgentsLoading(true);
142
+ setAgentsError(false);
143
+ }
144
+ try {
145
+ const list = await fetchMcpPersonalAgents(backendUrl, accessToken, companyId);
146
+ setAgents(list);
147
+ setAgentsError(false);
148
+ } catch {
149
+ if (!options?.silent) {
150
+ setAgents([]);
151
+ setAgentsError(true);
152
+ }
153
+ } finally {
154
+ if (!options?.silent) {
155
+ setAgentsLoading(false);
156
+ }
157
+ }
158
+ },
159
+ [accessToken, backendUrl, companyId, status?.mcpEnabled],
160
+ );
161
+
162
+ useEffect(() => {
163
+ void loadAgents();
164
+ }, [loadAgents]);
165
+
166
+ useEffect(() => {
167
+ const refreshIfVisible = () => {
168
+ if (document.visibilityState === 'hidden') return;
169
+ void loadAgents({ silent: true });
170
+ };
171
+ document.addEventListener('visibilitychange', refreshIfVisible);
172
+ window.addEventListener('focus', refreshIfVisible);
173
+ return () => {
174
+ document.removeEventListener('visibilitychange', refreshIfVisible);
175
+ window.removeEventListener('focus', refreshIfVisible);
176
+ };
177
+ }, [loadAgents]);
178
+
179
+ const activeAgents = useMemo(
180
+ () => agents.filter((agent) => isActiveMcpConnection(agent)),
181
+ [agents],
182
+ );
183
+
184
+ const revokedAgents = useMemo(() => agents.filter((agent) => Boolean(agent.revokedAt)), [agents]);
185
+
186
+ const scopeLabel = useCallback(
187
+ (agent: McpAgentSummary) =>
188
+ agentIncludesSaasScope(agent)
189
+ ? t('mcpAgents.connections.scopeRegionalSaas')
190
+ : t('mcpAgents.connections.scopeRegional'),
191
+ [t],
192
+ );
193
+
194
+ const kindLabel = useCallback(
195
+ (agent: McpAgentSummary) =>
196
+ agent.kind === 'oauth'
197
+ ? t('mcpAgents.connections.kindOauth')
198
+ : t('mcpAgents.connections.kindPersonal'),
199
+ [t],
200
+ );
201
+
202
+ const handleRevoke = useCallback(
203
+ (agent: McpAgentSummary) => {
204
+ shellui.dialog({
205
+ title: t('mcpAgents.revoke.title'),
206
+ description: t('mcpAgents.revoke.description'),
207
+ mode: 'delete',
208
+ size: 'sm',
209
+ okLabel: t('mcpAgents.revoke.confirm'),
210
+ cancelLabel: t('mcpAgents.revoke.cancel'),
211
+ onOk: async () => {
212
+ if (!backendUrl || !accessToken) return;
213
+ try {
214
+ await revokeMcpPersonalAgent(backendUrl, accessToken, companyId, agent.id);
215
+ shellui.toast({
216
+ type: 'success',
217
+ title: t('mcpAgents.revoke.successTitle'),
218
+ description: t('mcpAgents.revoke.successDescription', { name: agent.name }),
219
+ });
220
+ await loadAgents();
221
+ } catch {
222
+ shellui.toast({
223
+ type: 'error',
224
+ title: t('mcpAgents.revoke.errorTitle'),
225
+ });
226
+ }
227
+ },
228
+ onCancel: () => {},
229
+ });
230
+ },
231
+ [accessToken, backendUrl, companyId, loadAgents, t],
232
+ );
233
+
234
+ const handleCreate = useCallback(async () => {
235
+ if (!backendUrl || !accessToken) return;
236
+ const trimmedName = name.trim();
237
+ const resolvedName = trimmedName || formatDefaultAgentName(locale);
238
+ if (!absoluteMcpUrl) {
239
+ setCreateError(t('mcpAgents.create.errorMissingMcpUrl'));
240
+ return;
241
+ }
242
+ setCreating(true);
243
+ setCreateError(null);
244
+ try {
245
+ const result: CreatePersonalAgentResult = await createMcpPersonalAgent(
246
+ backendUrl,
247
+ accessToken,
248
+ companyId,
249
+ {
250
+ name: resolvedName,
251
+ services: getDefaultPersonalAgentServices(includeSaas),
252
+ accessMode: 'ask',
253
+ readLevel: 'safe',
254
+ allowDestructive: false,
255
+ expiresAt: defaultPersonalAgentExpiresAt(),
256
+ },
257
+ { allowSaas: includeSaas },
258
+ );
259
+ setIssuedSecret({ accessToken: result.accessToken });
260
+ if (staticDetailsRef.current) {
261
+ staticDetailsRef.current.open = true;
262
+ }
263
+ setName('');
264
+ await loadAgents();
265
+ } catch (err) {
266
+ const raw = err instanceof Error ? err.message : '';
267
+ const message = raw.includes('exceeds the maximum allowed lifetime')
268
+ ? t('mcpAgents.create.errorExpiryTooLong')
269
+ : raw || t('mcpAgents.create.errorGeneric');
270
+ setCreateError(message);
271
+ } finally {
272
+ setCreating(false);
273
+ }
274
+ }, [
275
+ absoluteMcpUrl,
276
+ accessToken,
277
+ backendUrl,
278
+ companyId,
279
+ includeSaas,
280
+ loadAgents,
281
+ locale,
282
+ name,
283
+ t,
284
+ ]);
285
+
286
+ if (!isAuthenticated) {
287
+ return <p className="text-sm text-muted-foreground">{t('mcpAgents.signInRequired')}</p>;
288
+ }
289
+
290
+ if (statusLoading) {
291
+ return <p className="text-sm text-muted-foreground">{t('mcpAgents.status.loading')}</p>;
292
+ }
293
+
294
+ if (statusError || !status?.mcpEnabled) {
295
+ return (
296
+ <div className="space-y-3">
297
+ <p className="text-sm text-muted-foreground">
298
+ {statusError ? t('mcpAgents.status.error') : t('mcpAgents.status.unavailable')}
299
+ </p>
300
+ <Button
301
+ type="button"
302
+ variant="outline"
303
+ size="sm"
304
+ onClick={refreshStatus}
305
+ >
306
+ {t('mcpAgents.status.retry')}
307
+ </Button>
308
+ </div>
309
+ );
310
+ }
311
+
312
+ return (
313
+ <div className="space-y-8 max-w-3xl">
314
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.description')}</p>
315
+
316
+ <section className="rounded-lg border bg-card p-4 space-y-3">
317
+ <h2
318
+ className="text-sm font-medium leading-none"
319
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
320
+ >
321
+ {t('mcpAgents.global.title')}
322
+ </h2>
323
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.global.intro')}</p>
324
+ <ul className="list-disc space-y-1 pl-5 text-sm text-muted-foreground">
325
+ <li>{t('mcpAgents.global.scopeAccount')}</li>
326
+ <li>{t('mcpAgents.global.scopeRegional')}</li>
327
+ <li>{t('mcpAgents.global.sessions')}</li>
328
+ <li>{t('mcpAgents.global.approvals')}</li>
329
+ </ul>
330
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.global.prerequisite')}</p>
331
+ {globalMcpDisplayUrl ? (
332
+ <p className="text-sm text-muted-foreground">
333
+ {t('mcpAgents.global.globalMcpUrlLabel')}{' '}
334
+ <span
335
+ className="select-none font-mono text-xs text-muted-foreground/80"
336
+ translate="no"
337
+ >
338
+ {globalMcpDisplayUrl}
339
+ </span>
340
+ </p>
341
+ ) : (
342
+ <p className="text-sm text-muted-foreground">
343
+ {t('mcpAgents.global.globalMcpUrlUnknown')}
344
+ </p>
345
+ )}
346
+ {includeSaas ? (
347
+ <p className="text-sm text-foreground">{t('mcpAgents.global.statusReady')}</p>
348
+ ) : (
349
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.global.statusPending')}</p>
350
+ )}
351
+ </section>
352
+
353
+ <section className="rounded-lg border bg-card p-4 space-y-4">
354
+ <h2
355
+ className="text-sm font-medium leading-none"
356
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
357
+ >
358
+ {t('mcpAgents.connect.title')}
359
+ </h2>
360
+ {connectPrompt && absoluteMcpUrl ? (
361
+ <>
362
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.connect.intro')}</p>
363
+ <div className="space-y-2">
364
+ <p className="text-sm font-medium">{t('mcpAgents.connect.urlLabel')}</p>
365
+ <div className="flex flex-wrap items-center gap-2">
366
+ <code
367
+ className="min-w-0 break-all font-mono text-xs"
368
+ translate="no"
369
+ >
370
+ {absoluteMcpUrl}
371
+ </code>
372
+ <Button
373
+ type="button"
374
+ variant="outline"
375
+ size="sm"
376
+ onClick={() => void copyValue(t('mcpAgents.connect.copyUrl'), absoluteMcpUrl)}
377
+ >
378
+ {t('mcpAgents.connect.copyUrl')}
379
+ </Button>
380
+ </div>
381
+ </div>
382
+ <div className="space-y-2">
383
+ <p className="text-sm font-medium">{t('mcpAgents.connect.promptLabel')}</p>
384
+ <pre
385
+ className="max-h-64 overflow-auto whitespace-pre-wrap rounded-md border bg-muted px-3 py-2 text-xs"
386
+ translate="no"
387
+ children={connectPrompt}
388
+ />
389
+ <Button
390
+ type="button"
391
+ variant="outline"
392
+ size="sm"
393
+ onClick={() => void copyValue(t('mcpAgents.connect.copyPrompt'), connectPrompt)}
394
+ >
395
+ {t('mcpAgents.connect.copyPrompt')}
396
+ </Button>
397
+ </div>
398
+ <div className="space-y-2">
399
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.connect.stepsLead')}</p>
400
+ <ol className="list-decimal space-y-1 pl-5 text-sm text-muted-foreground">
401
+ <li>{t('mcpAgents.connect.steps.paste')}</li>
402
+ <li>{t('mcpAgents.connect.steps.openLink')}</li>
403
+ <li>{t('mcpAgents.connect.steps.allow')}</li>
404
+ </ol>
405
+ </div>
406
+ <details
407
+ ref={staticDetailsRef}
408
+ className="rounded-md border bg-background"
409
+ >
410
+ <summary className="cursor-pointer px-3 py-2 text-sm font-medium">
411
+ {t('mcpAgents.staticSecret.summary')}
412
+ </summary>
413
+ <div className="space-y-4 px-3 pb-3">
414
+ <p className="text-sm text-muted-foreground">
415
+ {t('mcpAgents.staticSecret.helper')}
416
+ </p>
417
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.staticSecret.once')}</p>
418
+ {issuedSecret ? (
419
+ <div className="space-y-2 rounded-md border border-amber-500/40 bg-amber-500/5 p-3">
420
+ <p className="text-sm font-medium">{t('mcpAgents.success.title')}</p>
421
+ <p className="text-sm text-muted-foreground">
422
+ {t('mcpAgents.success.warning')}
423
+ </p>
424
+ <pre
425
+ className="overflow-auto whitespace-pre-wrap rounded-md border bg-muted px-3 py-2 text-xs"
426
+ translate="no"
427
+ children={issuedSecret.accessToken}
428
+ />
429
+ <div className="flex flex-wrap gap-2">
430
+ <Button
431
+ type="button"
432
+ variant="outline"
433
+ size="sm"
434
+ onClick={() =>
435
+ void copyValue(
436
+ t('mcpAgents.success.copySecret'),
437
+ issuedSecret.accessToken,
438
+ )
439
+ }
440
+ >
441
+ {t('mcpAgents.success.copySecret')}
442
+ </Button>
443
+ <Button
444
+ type="button"
445
+ variant="outline"
446
+ size="sm"
447
+ onClick={() => setIssuedSecret(null)}
448
+ >
449
+ {t('mcpAgents.success.hide')}
450
+ </Button>
451
+ </div>
452
+ </div>
453
+ ) : null}
454
+ <h3
455
+ className="text-sm font-medium leading-none"
456
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
457
+ >
458
+ {t('mcpAgents.create.title')}
459
+ </h3>
460
+ <div className="space-y-2">
461
+ <label
462
+ className="text-sm font-medium"
463
+ htmlFor="mcp-agent-name"
464
+ >
465
+ {t('mcpAgents.create.nameLabel')}
466
+ </label>
467
+ <Input
468
+ id="mcp-agent-name"
469
+ value={name}
470
+ onChange={(event) => setName(event.target.value)}
471
+ placeholder={t('mcpAgents.create.namePlaceholder')}
472
+ />
473
+ <p className="text-sm text-muted-foreground">
474
+ {t('mcpAgents.create.nameHelper')}
475
+ </p>
476
+ </div>
477
+ <p className="text-sm text-muted-foreground">
478
+ {includeSaas
479
+ ? t('mcpAgents.create.accessHelperGlobal')
480
+ : t('mcpAgents.create.accessHelperRegional')}
481
+ </p>
482
+ <p className="text-sm text-muted-foreground">
483
+ {t('mcpAgents.create.expiryHelper', {
484
+ days: MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS,
485
+ })}
486
+ </p>
487
+ {createError ? <p className="text-sm text-destructive">{createError}</p> : null}
488
+ <div className="flex flex-wrap gap-2">
489
+ <Button
490
+ type="button"
491
+ disabled={creating}
492
+ onClick={() => void handleCreate()}
493
+ >
494
+ {creating ? t('mcpAgents.create.submitting') : t('mcpAgents.create.submit')}
495
+ </Button>
496
+ <Button
497
+ type="button"
498
+ variant="outline"
499
+ disabled={creating}
500
+ onClick={() => {
501
+ setCreateError(null);
502
+ setName('');
503
+ if (staticDetailsRef.current) {
504
+ staticDetailsRef.current.open = false;
505
+ }
506
+ }}
507
+ >
508
+ {t('mcpAgents.create.cancel')}
509
+ </Button>
510
+ </div>
511
+ </div>
512
+ </details>
513
+ </>
514
+ ) : (
515
+ <p className="text-sm text-muted-foreground">
516
+ {t('mcpAgents.create.errorMissingMcpUrl')}
517
+ </p>
518
+ )}
519
+ </section>
520
+
521
+ <McpPendingApprovals
522
+ ref={pendingSectionRef}
523
+ backendUrl={backendUrl ?? ''}
524
+ accessToken={accessToken ?? ''}
525
+ companyId={companyId}
526
+ enabled={Boolean(backendUrl && accessToken && status?.mcpEnabled)}
527
+ companyName={companyDisplayName}
528
+ approvals={pendingApprovals}
529
+ pendingCount={pendingCountState}
530
+ onRefresh={refreshPending}
531
+ />
532
+
533
+ <section className="space-y-4">
534
+ <h2
535
+ className="text-sm font-medium leading-none"
536
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
537
+ >
538
+ {t('mcpAgents.connections.title')}
539
+ </h2>
540
+
541
+ {agentsLoading ? (
542
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.connections.loading')}</p>
543
+ ) : agentsError ? (
544
+ <div className="space-y-2">
545
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.connections.error')}</p>
546
+ <Button
547
+ type="button"
548
+ variant="outline"
549
+ size="sm"
550
+ onClick={() => void loadAgents()}
551
+ >
552
+ {t('mcpAgents.connections.retry')}
553
+ </Button>
554
+ </div>
555
+ ) : activeAgents.length === 0 ? (
556
+ <p className="text-sm text-muted-foreground">{t('mcpAgents.connections.empty')}</p>
557
+ ) : (
558
+ <ul className="space-y-3">
559
+ {activeAgents.map((agent) => {
560
+ const connectedDate = formatConnectionDate(agent.createdAt, locale);
561
+ const expiryLabel = formatAgentExpiry(agent.expiresAt, locale);
562
+ return (
563
+ <li
564
+ key={agent.id}
565
+ className="rounded-lg border bg-card p-4"
566
+ >
567
+ <div className="flex flex-wrap items-start justify-between gap-3">
568
+ <div className="space-y-1 min-w-0">
569
+ <p className="text-sm font-medium">
570
+ {expiryLabel
571
+ ? t('mcpAgents.connections.connectedMetaWithExpiry', {
572
+ name: agent.name,
573
+ date: connectedDate,
574
+ expiry: expiryLabel,
575
+ })
576
+ : t('mcpAgents.connections.connectedMeta', {
577
+ name: agent.name,
578
+ date: connectedDate,
579
+ })}
580
+ </p>
581
+ <p className="text-sm text-muted-foreground">{kindLabel(agent)}</p>
582
+ {agent.kind === 'oauth' && agent.servicesAllowed.length > 0 ? (
583
+ <p className="text-sm text-muted-foreground">
584
+ {t('mcpAgents.connections.services', {
585
+ services: agent.servicesAllowed.join(', '),
586
+ })}
587
+ </p>
588
+ ) : agent.kind === 'personal' ? (
589
+ <p className="text-sm text-muted-foreground">{scopeLabel(agent)}</p>
590
+ ) : null}
591
+ </div>
592
+ <Button
593
+ type="button"
594
+ variant="destructive"
595
+ size="sm"
596
+ className="shrink-0"
597
+ onClick={() => handleRevoke(agent)}
598
+ >
599
+ {t('mcpAgents.revoke.action')}
600
+ </Button>
601
+ </div>
602
+ <McpAgentActivitySection
603
+ backendUrl={backendUrl ?? ''}
604
+ aiServiceUrl={aiServiceUrl}
605
+ accessToken={accessToken ?? ''}
606
+ companyId={companyId}
607
+ enabled={Boolean(backendUrl && accessToken && status?.mcpEnabled)}
608
+ agent={agent}
609
+ pendingApprovals={pendingApprovals}
610
+ onJumpToApprovals={scrollToPendingApprovals}
611
+ />
612
+ </li>
613
+ );
614
+ })}
615
+ </ul>
616
+ )}
617
+
618
+ {revokedAgents.length > 0 ? (
619
+ <div className="space-y-3 pt-2">
620
+ <Button
621
+ type="button"
622
+ variant="ghost"
623
+ size="sm"
624
+ className="h-auto px-0 text-muted-foreground"
625
+ onClick={() => setShowRevoked((value) => !value)}
626
+ >
627
+ {showRevoked
628
+ ? t('mcpAgents.connections.hideRevoked')
629
+ : t('mcpAgents.connections.showRevoked')}
630
+ </Button>
631
+ {showRevoked ? (
632
+ <ul className="space-y-3">
633
+ {revokedAgents.map((agent) => (
634
+ <li
635
+ key={agent.id}
636
+ className="rounded-lg border border-dashed bg-muted/30 p-4"
637
+ >
638
+ <p className="text-sm text-muted-foreground">
639
+ {t('mcpAgents.connections.revokedMeta', {
640
+ name: agent.name,
641
+ date: formatConnectionDate(agent.revokedAt ?? agent.createdAt, locale),
642
+ })}
643
+ </p>
644
+ <p className="text-sm text-muted-foreground">{kindLabel(agent)}</p>
645
+ </li>
646
+ ))}
647
+ </ul>
648
+ ) : null}
649
+ </div>
650
+ ) : null}
651
+ </section>
652
+ </div>
653
+ );
654
+ };