@shellui/core 0.5.3 → 0.6.0-beta.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 (113) hide show
  1. package/README.md +2 -0
  2. package/package.json +6 -4
  3. package/schemas/shellui.config.schema.json +104 -64
  4. package/src/app.tsx +5 -3
  5. package/src/components/ContentView.tsx +14 -23
  6. package/src/components/LoadingOverlay.tsx +1 -1
  7. package/src/components/ui/sonner.spec.tsx +138 -0
  8. package/src/components/ui/sonner.tsx +5 -5
  9. package/src/components/ui/switch.tsx +1 -1
  10. package/src/features/admin/AdminView.tsx +14 -3
  11. package/src/features/ai/AiBridge.tsx +106 -0
  12. package/src/features/ai/AiUnavailableResponder.tsx +39 -0
  13. package/src/features/ai/README.md +52 -0
  14. package/src/features/ai/ShellAiHost.tsx +24 -0
  15. package/src/features/ai/adapters/ollama.ts +170 -0
  16. package/src/features/ai/adapters/promptApi.spec.ts +135 -0
  17. package/src/features/ai/adapters/promptApi.ts +222 -0
  18. package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
  19. package/src/features/ai/adapters/webllm.spec.ts +527 -0
  20. package/src/features/ai/adapters/webllm.ts +142 -0
  21. package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
  22. package/src/features/ai/aiDisabledResponses.ts +32 -0
  23. package/src/features/ai/browserInstallStore.spec.ts +58 -0
  24. package/src/features/ai/browserInstallStore.ts +76 -0
  25. package/src/features/ai/catalog.ts +31 -0
  26. package/src/features/ai/createRegistry.ts +83 -0
  27. package/src/features/ai/developHarness.spec.ts +108 -0
  28. package/src/features/ai/developHarness.ts +161 -0
  29. package/src/features/ai/engine/formatAiError.spec.ts +85 -0
  30. package/src/features/ai/engine/formatAiError.ts +132 -0
  31. package/src/features/ai/engine/mapInitProgress.ts +9 -0
  32. package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
  33. package/src/features/ai/engine/vite-worker.d.ts +6 -0
  34. package/src/features/ai/engine/webllm.worker.ts +51 -0
  35. package/src/features/ai/engine/webllmEngine.ts +1011 -0
  36. package/src/features/ai/handleRequest.spec.ts +288 -0
  37. package/src/features/ai/handleRequest.ts +325 -0
  38. package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
  39. package/src/features/ai/isAiFeatureEnabled.ts +9 -0
  40. package/src/features/ai/promptApiSupport.spec.ts +64 -0
  41. package/src/features/ai/promptApiSupport.ts +117 -0
  42. package/src/features/ai/registry.spec.ts +100 -0
  43. package/src/features/ai/registry.ts +131 -0
  44. package/src/features/ai/status.spec.ts +92 -0
  45. package/src/features/ai/status.ts +85 -0
  46. package/src/features/ai/types.ts +100 -0
  47. package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
  48. package/src/features/ai/webLlmBrowserSupport.ts +92 -0
  49. package/src/features/alertDialog/DialogContext.tsx +3 -1
  50. package/src/features/auth/AuthProvider.tsx +254 -39
  51. package/src/features/auth/backends/index.ts +8 -0
  52. package/src/features/auth/backends/shellui.spec.ts +201 -0
  53. package/src/features/auth/backends/shellui.ts +93 -16
  54. package/src/features/auth/backends/supabase.ts +8 -0
  55. package/src/features/auth/backends/types.ts +16 -1
  56. package/src/features/auth/components/LoginButton.tsx +26 -2
  57. package/src/features/auth/components/LoginView.tsx +114 -133
  58. package/src/features/auth/components/SessionLoadingView.tsx +21 -0
  59. package/src/features/auth/hooks/useAuth.tsx +12 -0
  60. package/src/features/auth/shellAccountRequests.ts +76 -0
  61. package/src/features/auth/utils/authRequestError.ts +4 -1
  62. package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
  63. package/src/features/auth/utils/authSessionPersistence.ts +12 -0
  64. package/src/features/auth/utils/index.ts +4 -0
  65. package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
  66. package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
  67. package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
  68. package/src/features/auth/utils/shareInFlight.ts +14 -0
  69. package/src/features/config/ConfigProvider.ts +9 -1
  70. package/src/features/config/types.ts +43 -0
  71. package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
  72. package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
  73. package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
  74. package/src/features/layouts/floating/layoutChromeStore.ts +3 -1
  75. package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
  76. package/src/features/layouts/utils.ts +6 -2
  77. package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
  78. package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
  79. package/src/features/security/trustedFrames.spec.ts +65 -0
  80. package/src/features/security/trustedFrames.ts +52 -0
  81. package/src/features/settings/SettingsIcons.tsx +17 -0
  82. package/src/features/settings/SettingsProvider.tsx +29 -4
  83. package/src/features/settings/SettingsRoutes.tsx +8 -0
  84. package/src/features/settings/SettingsView.tsx +21 -4
  85. package/src/features/settings/components/Ai.tsx +830 -0
  86. package/src/features/settings/components/Develop.tsx +4 -0
  87. package/src/features/settings/components/Storage.tsx +197 -32
  88. package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
  89. package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
  90. package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
  91. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
  92. package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
  93. package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
  94. package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
  95. package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
  96. package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
  97. package/src/features/storage/uploads/UploadToaster.tsx +2 -44
  98. package/src/features/storage/uploads/uploadQueue.ts +128 -308
  99. package/src/features/storage/uploads/useUploadQueue.ts +7 -3
  100. package/src/features/transfers/TransferToastCard.tsx +467 -0
  101. package/src/features/transfers/TransferToaster.tsx +50 -0
  102. package/src/features/transfers/index.ts +33 -0
  103. package/src/features/transfers/transferQueue.spec.ts +97 -0
  104. package/src/features/transfers/transferQueue.ts +442 -0
  105. package/src/features/transfers/types.ts +38 -0
  106. package/src/features/transfers/useTransferQueue.ts +30 -0
  107. package/src/i18n/translations/en/common.json +46 -2
  108. package/src/i18n/translations/en/settings.json +151 -2
  109. package/src/i18n/translations/fr/common.json +46 -2
  110. package/src/i18n/translations/fr/settings.json +151 -2
  111. package/src/index.css +57 -4
  112. package/src/index.ts +1 -0
  113. package/src/routes/components/NavigationItemRoute.tsx +2 -1
@@ -16,10 +16,12 @@ import { DialogTestButtons } from './develop/DialogTestButtons';
16
16
  import { ModalTestButtons } from './develop/ModalTestButtons';
17
17
  import { DrawerTestButtons } from './develop/DrawerTestButtons';
18
18
  import { StoragePickerTestButtons } from './develop/StoragePickerTestButtons';
19
+ import { AiTestTools } from './develop/AiTestTools';
19
20
  import { ChromeActionsTestButtons } from './develop/ChromeActionsTestButtons';
20
21
  import { captureException } from '../../sentry/initSentry';
21
22
  import { useCookieConsent } from '../../cookieConsent/useCookieConsent';
22
23
  import { normalizeLayoutType, type LayoutType } from '../../config/types';
24
+ import { isAiFeatureEnabled } from '../../ai/isAiFeatureEnabled';
23
25
 
24
26
  export const Develop = () => {
25
27
  const { t } = useTranslation('settings');
@@ -35,6 +37,7 @@ export const Develop = () => {
35
37
  : [];
36
38
  const errorReportingConfigured = Boolean(config?.sentry?.dsn);
37
39
  const { isAccepted: sentryConsentAccepted } = useCookieConsent('sentry.io');
40
+ const showAiTestTools = isAiFeatureEnabled(config);
38
41
 
39
42
  return (
40
43
  <div className="space-y-6">
@@ -233,6 +236,7 @@ export const Develop = () => {
233
236
  <DrawerTestButtons />
234
237
  <StoragePickerTestButtons />
235
238
  <ChromeActionsTestButtons />
239
+ {showAiTestTools ? <AiTestTools /> : null}
236
240
  {errorReportingConfigured && (
237
241
  <div className="flex items-center justify-between">
238
242
  <div className="space-y-0.5">
@@ -1,16 +1,29 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { Button } from '../../../components/ui/button';
4
+ import {
5
+ estimateInstalledCatalogBytes,
6
+ listBrowserInstalledIds,
7
+ } from '../../ai/browserInstallStore';
8
+ import { BROWSER_MODEL_CATALOG } from '../../ai/catalog';
4
9
  import { useAuth } from '../../auth/hooks/useAuth';
10
+ import { isAiFeatureEnabled } from '../../ai/isAiFeatureEnabled';
5
11
  import { useConfig } from '../../config/useConfig';
6
12
  import {
7
13
  fetchStorageQuota,
8
14
  formatBytes,
9
15
  getStorageBaseUrl,
10
16
  getUsagePercent,
17
+ isStorageSettingsEnabled,
11
18
  type StorageQuotaBucket,
12
19
  type StorageQuotaSnapshot,
13
20
  } from '../../storage/quota';
21
+ import { useSettings } from '../hooks/useSettings';
22
+
23
+ type OriginStorageEstimate = {
24
+ usageBytes: number;
25
+ quotaBytes: number | null;
26
+ };
14
27
 
15
28
  const QuotaMeter = ({
16
29
  label,
@@ -61,12 +74,137 @@ const QuotaMeter = ({
61
74
  );
62
75
  };
63
76
 
77
+ async function readOriginStorageEstimate(): Promise<OriginStorageEstimate | null> {
78
+ const storage = (
79
+ globalThis as {
80
+ navigator?: { storage?: { estimate?: () => Promise<{ quota?: number; usage?: number }> } };
81
+ }
82
+ ).navigator?.storage;
83
+ if (!storage?.estimate) return null;
84
+ try {
85
+ const estimate = await storage.estimate();
86
+ const usageBytes =
87
+ typeof estimate.usage === 'number' && Number.isFinite(estimate.usage) ? estimate.usage : 0;
88
+ const quotaBytes =
89
+ typeof estimate.quota === 'number' && Number.isFinite(estimate.quota) && estimate.quota > 0
90
+ ? estimate.quota
91
+ : null;
92
+ return { usageBytes, quotaBytes };
93
+ } catch {
94
+ return null;
95
+ }
96
+ }
97
+
98
+ const LocalAiModelsUsage = () => {
99
+ const { t, i18n } = useTranslation('settings');
100
+ const locale = i18n.language || 'en';
101
+ const [origin, setOrigin] = useState<OriginStorageEstimate | null | undefined>(undefined);
102
+ const installedCount = listBrowserInstalledIds().length;
103
+ const catalogBytes = estimateInstalledCatalogBytes(BROWSER_MODEL_CATALOG);
104
+
105
+ useEffect(() => {
106
+ let cancelled = false;
107
+ void readOriginStorageEstimate().then((value) => {
108
+ if (!cancelled) setOrigin(value);
109
+ });
110
+ return () => {
111
+ cancelled = true;
112
+ };
113
+ }, []);
114
+
115
+ const originBucket: StorageQuotaBucket | null =
116
+ origin === undefined
117
+ ? null
118
+ : origin
119
+ ? {
120
+ usedBytes: origin.usageBytes,
121
+ maxBytes: origin.quotaBytes,
122
+ remainingBytes:
123
+ origin.quotaBytes !== null
124
+ ? Math.max(0, origin.quotaBytes - origin.usageBytes)
125
+ : null,
126
+ }
127
+ : null;
128
+
129
+ return (
130
+ <div className="space-y-4">
131
+ <div className="space-y-0.5">
132
+ <h2
133
+ className="text-sm font-medium leading-none"
134
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
135
+ >
136
+ {t('storage.aiModels.title')}
137
+ </h2>
138
+ <p className="text-sm text-muted-foreground">{t('storage.aiModels.description')}</p>
139
+ </div>
140
+
141
+ {origin === undefined ? (
142
+ <p className="text-sm text-muted-foreground">{t('storage.aiModels.loading')}</p>
143
+ ) : null}
144
+
145
+ {originBucket ? (
146
+ <QuotaMeter
147
+ label={t('storage.aiModels.originUsage')}
148
+ description={t('storage.aiModels.originHint')}
149
+ bucket={originBucket}
150
+ />
151
+ ) : origin === null ? (
152
+ <p className="text-sm text-muted-foreground">{t('storage.aiModels.estimateUnavailable')}</p>
153
+ ) : null}
154
+
155
+ <div className="space-y-2">
156
+ <div className="space-y-0.5">
157
+ <h3
158
+ className="text-sm font-medium leading-none"
159
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
160
+ >
161
+ {t('storage.aiModels.catalogEstimate')}
162
+ </h3>
163
+ <p className="text-sm text-muted-foreground">
164
+ {t('storage.aiModels.catalogEstimateHint')}
165
+ </p>
166
+ </div>
167
+ <p className="text-sm tabular-nums">
168
+ {installedCount === 0
169
+ ? t('storage.aiModels.noneInstalled')
170
+ : t('storage.aiModels.catalogUsed', {
171
+ used: formatBytes(catalogBytes, locale),
172
+ count: installedCount,
173
+ })}
174
+ </p>
175
+ {installedCount > 0 && originBucket?.maxBytes ? (
176
+ <div
177
+ className="h-2 w-full overflow-hidden rounded-full bg-muted"
178
+ role="progressbar"
179
+ aria-valuemin={0}
180
+ aria-valuemax={100}
181
+ aria-valuenow={Math.round(getUsagePercent(catalogBytes, originBucket.maxBytes) ?? 0)}
182
+ aria-label={t('storage.aiModels.catalogEstimate')}
183
+ >
184
+ <div
185
+ className="h-full rounded-full bg-primary/70 transition-[width]"
186
+ style={{
187
+ width: `${getUsagePercent(catalogBytes, originBucket.maxBytes) ?? 0}%`,
188
+ }}
189
+ />
190
+ </div>
191
+ ) : null}
192
+ </div>
193
+ </div>
194
+ );
195
+ };
196
+
64
197
  export const Storage = () => {
65
198
  const { t } = useTranslation('settings');
66
199
  const { config } = useConfig();
200
+ const { settings } = useSettings();
67
201
  const { session, isAuthenticated } = useAuth();
68
202
  const storageBaseUrl = getStorageBaseUrl(config);
69
203
  const accessToken = session?.accessToken ?? null;
204
+ const aiEnabled = isAiFeatureEnabled(config) && settings.ai?.enabled !== false;
205
+ const remoteConfigured = isStorageSettingsEnabled(config);
206
+ const showRemoteQuota = remoteConfigured && isAuthenticated && Boolean(accessToken);
207
+ const showLocalAi = aiEnabled;
70
208
 
71
209
  const [snapshot, setSnapshot] = useState<StorageQuotaSnapshot | null>(null);
72
210
  const [loading, setLoading] = useState(false);
@@ -92,45 +230,72 @@ export const Storage = () => {
92
230
  }, [accessToken, storageBaseUrl]);
93
231
 
94
232
  useEffect(() => {
95
- void load();
96
- }, [load]);
233
+ if (showRemoteQuota) {
234
+ void load();
235
+ }
236
+ }, [load, showRemoteQuota]);
97
237
 
98
- if (!isAuthenticated || !accessToken) {
99
- return <p className="text-sm text-muted-foreground">{t('storage.signInRequired')}</p>;
238
+ if (!showLocalAi && !showRemoteQuota) {
239
+ if (remoteConfigured && (!isAuthenticated || !accessToken)) {
240
+ return <p className="text-sm text-muted-foreground">{t('storage.signInRequired')}</p>;
241
+ }
242
+ return null;
100
243
  }
101
244
 
102
245
  return (
103
- <div className="space-y-6">
104
- <p className="text-sm text-muted-foreground">{t('storage.description')}</p>
246
+ <div className="space-y-8">
247
+ {showLocalAi ? <LocalAiModelsUsage /> : null}
105
248
 
106
- {loading && !snapshot ? (
107
- <p className="text-sm text-muted-foreground">{t('storage.loading')}</p>
108
- ) : null}
249
+ {remoteConfigured ? (
250
+ <div className="space-y-6">
251
+ {showLocalAi ? (
252
+ <h2
253
+ className="text-sm font-medium leading-none"
254
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
255
+ >
256
+ {t('storage.remoteTitle')}
257
+ </h2>
258
+ ) : null}
259
+ <p className="text-sm text-muted-foreground">{t('storage.description')}</p>
109
260
 
110
- {error ? (
111
- <div className="space-y-3">
112
- <p className="text-sm text-destructive">{t('storage.error')}</p>
113
- <Button
114
- variant="outline"
115
- size="sm"
116
- onClick={() => void load()}
117
- >
118
- {t('storage.retry')}
119
- </Button>
120
- </div>
121
- ) : null}
261
+ {!isAuthenticated || !accessToken ? (
262
+ <p className="text-sm text-muted-foreground">{t('storage.signInRequired')}</p>
263
+ ) : (
264
+ <>
265
+ {loading && !snapshot ? (
266
+ <p className="text-sm text-muted-foreground">{t('storage.loading')}</p>
267
+ ) : null}
122
268
 
123
- {snapshot ? (
124
- <div className="space-y-6">
125
- <QuotaMeter
126
- label={t('storage.yourUsage')}
127
- description={snapshot.user.maxBytes === null ? t('storage.noPersonalLimit') : undefined}
128
- bucket={snapshot.user}
129
- />
130
- <QuotaMeter
131
- label={t('storage.organization')}
132
- bucket={snapshot.company}
133
- />
269
+ {error ? (
270
+ <div className="space-y-3">
271
+ <p className="text-sm text-destructive">{t('storage.error')}</p>
272
+ <Button
273
+ variant="outline"
274
+ size="sm"
275
+ onClick={() => void load()}
276
+ >
277
+ {t('storage.retry')}
278
+ </Button>
279
+ </div>
280
+ ) : null}
281
+
282
+ {snapshot ? (
283
+ <div className="space-y-6">
284
+ <QuotaMeter
285
+ label={t('storage.yourUsage')}
286
+ description={
287
+ snapshot.user.maxBytes === null ? t('storage.noPersonalLimit') : undefined
288
+ }
289
+ bucket={snapshot.user}
290
+ />
291
+ <QuotaMeter
292
+ label={t('storage.organization')}
293
+ bucket={snapshot.company}
294
+ />
295
+ </div>
296
+ ) : null}
297
+ </>
298
+ )}
134
299
  </div>
135
300
  ) : null}
136
301
  </div>
@@ -1,10 +1,12 @@
1
- import { useCallback, useMemo, useState, type ReactNode } from 'react';
1
+ import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { shellui, type Settings } from '@shellui/sdk';
4
4
  import type { AuthUser } from '../../auth/hooks/useAuth';
5
+ import { requestAccountDeletion, requestProfileUpdate } from '../../auth/shellAccountRequests';
5
6
  import { decodeJwtPayload } from '../../auth/utils/decodeJwtPayload';
6
7
  import { Badge } from '../../../components/ui/badge';
7
8
  import { Button } from '../../../components/ui/button';
9
+ import { Input } from '../../../components/ui/input';
8
10
  import {
9
11
  Tooltip,
10
12
  TooltipContent,
@@ -180,6 +182,8 @@ export const UserSettingsPanel = ({
180
182
  accessToken,
181
183
  settingsAccessToken,
182
184
  rawUserSettings,
185
+ canDeleteAccount,
186
+ canEditName,
183
187
  }: {
184
188
  user: AuthUser;
185
189
  onLogout: () => Promise<void>;
@@ -187,10 +191,20 @@ export const UserSettingsPanel = ({
187
191
  accessToken: string | null;
188
192
  settingsAccessToken: string | null;
189
193
  rawUserSettings: Settings['user'];
194
+ canDeleteAccount: boolean;
195
+ canEditName: boolean;
190
196
  }) => {
191
197
  const { t, i18n } = useTranslation('settings');
192
198
  const { settings } = useSettings();
193
199
  const [isLoggingOut, setIsLoggingOut] = useState(false);
200
+ const [isDeletingAccount, setIsDeletingAccount] = useState(false);
201
+ const [isEditingName, setIsEditingName] = useState(false);
202
+ const [nameDraft, setNameDraft] = useState('');
203
+ const [isSavingName, setIsSavingName] = useState(false);
204
+ // Shown until the shell propagates the updated user back to this panel.
205
+ const [savedName, setSavedName] = useState<string | null>(null);
206
+ useEffect(() => setSavedName(null), [user.name]);
207
+ const displayName = savedName ?? user.name;
194
208
  const decodedJwtPayload = useMemo(
195
209
  () => (accessToken ? decodeJwtPayload(accessToken) : null),
196
210
  [accessToken],
@@ -231,6 +245,51 @@ export const UserSettingsPanel = ({
231
245
  setIsLoggingOut(false);
232
246
  }
233
247
  }, [onLogout]);
248
+ const startEditingName = useCallback(() => {
249
+ setNameDraft(displayName ?? '');
250
+ setIsEditingName(true);
251
+ }, [displayName]);
252
+ const cancelEditingName = useCallback(() => {
253
+ setIsEditingName(false);
254
+ setNameDraft('');
255
+ }, []);
256
+ const handleSaveName = useCallback(async () => {
257
+ const name = nameDraft.trim().replace(/\s+/g, ' ');
258
+ if (!name) return;
259
+ if (name === displayName) {
260
+ cancelEditingName();
261
+ return;
262
+ }
263
+ setIsSavingName(true);
264
+ try {
265
+ const result = await requestProfileUpdate(name);
266
+ if (result.status === 'saved') {
267
+ setSavedName(result.name);
268
+ cancelEditingName();
269
+ shellui.toast({
270
+ type: 'success',
271
+ title: t('userAccount.name.savedTitle'),
272
+ description: t('userAccount.name.savedDescription', { name: result.name }),
273
+ });
274
+ return;
275
+ }
276
+ shellui.toast({
277
+ type: 'error',
278
+ title: t('userAccount.name.errorTitle'),
279
+ description: result.error,
280
+ });
281
+ } finally {
282
+ setIsSavingName(false);
283
+ }
284
+ }, [cancelEditingName, displayName, nameDraft, t]);
285
+ const handleDeleteAccount = useCallback(async () => {
286
+ setIsDeletingAccount(true);
287
+ try {
288
+ await requestAccountDeletion();
289
+ } finally {
290
+ setIsDeletingAccount(false);
291
+ }
292
+ }, []);
234
293
  const handleCopyDeveloperDiagnostics = useCallback(
235
294
  async (label: string, value: string) => {
236
295
  if (!navigator?.clipboard?.writeText) {
@@ -379,7 +438,7 @@ export const UserSettingsPanel = ({
379
438
  )}
380
439
  <div className="min-w-0">
381
440
  <p className="truncate text-base font-medium text-foreground">
382
- {user.name || t('userAccount.profile.unknownUser')}
441
+ {displayName || t('userAccount.profile.unknownUser')}
383
442
  </p>
384
443
  <p className="truncate text-sm text-muted-foreground">
385
444
  {user.email || t('userAccount.profile.noEmail')}
@@ -390,7 +449,81 @@ export const UserSettingsPanel = ({
390
449
  <dl className="space-y-3 text-sm">
391
450
  <div>
392
451
  <dt className="text-muted-foreground">{t('userAccount.fields.name')}</dt>
393
- <dd className="mt-0.5 text-foreground">{user.name || '-'}</dd>
452
+ <dd className="mt-0.5 text-foreground">
453
+ {isEditingName ? (
454
+ <form
455
+ className="mt-1 flex items-center gap-2"
456
+ onSubmit={(event) => {
457
+ event.preventDefault();
458
+ void handleSaveName();
459
+ }}
460
+ >
461
+ <Input
462
+ autoFocus
463
+ value={nameDraft}
464
+ onChange={(event) => setNameDraft(event.target.value)}
465
+ onKeyDown={(event) => {
466
+ if (event.key === 'Escape') {
467
+ event.preventDefault();
468
+ cancelEditingName();
469
+ }
470
+ }}
471
+ maxLength={150}
472
+ autoComplete="name"
473
+ aria-label={t('userAccount.fields.name')}
474
+ disabled={isSavingName}
475
+ className="h-8 max-w-xs"
476
+ />
477
+ <Button
478
+ type="submit"
479
+ size="sm"
480
+ className="h-8"
481
+ disabled={isSavingName || !nameDraft.trim()}
482
+ >
483
+ {isSavingName ? t('userAccount.name.saving') : t('userAccount.name.save')}
484
+ </Button>
485
+ <Button
486
+ type="button"
487
+ variant="ghost"
488
+ size="sm"
489
+ className="h-8"
490
+ onClick={cancelEditingName}
491
+ disabled={isSavingName}
492
+ >
493
+ {t('userAccount.name.cancel')}
494
+ </Button>
495
+ </form>
496
+ ) : (
497
+ <span className="inline-flex items-center gap-1.5">
498
+ {displayName || '-'}
499
+ {canEditName ? (
500
+ <button
501
+ type="button"
502
+ onClick={startEditingName}
503
+ className="inline-flex size-6 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
504
+ aria-label={t('userAccount.name.edit')}
505
+ title={t('userAccount.name.edit')}
506
+ >
507
+ <svg
508
+ xmlns="http://www.w3.org/2000/svg"
509
+ width="14"
510
+ height="14"
511
+ viewBox="0 0 24 24"
512
+ fill="none"
513
+ stroke="currentColor"
514
+ strokeWidth="2"
515
+ strokeLinecap="round"
516
+ strokeLinejoin="round"
517
+ aria-hidden
518
+ >
519
+ <path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
520
+ <path d="m15 5 4 4" />
521
+ </svg>
522
+ </button>
523
+ ) : null}
524
+ </span>
525
+ )}
526
+ </dd>
394
527
  </div>
395
528
  <div>
396
529
  <dt className="text-muted-foreground">{t('userAccount.fields.email')}</dt>
@@ -424,15 +557,30 @@ export const UserSettingsPanel = ({
424
557
 
425
558
  {developerDiagnostics}
426
559
 
427
- <Button
428
- type="button"
429
- variant="secondary"
430
- className="mt-4 w-full sm:w-auto"
431
- onClick={() => void handleLogout()}
432
- disabled={isLoggingOut}
433
- >
434
- {isLoggingOut ? t('userAccount.actions.loggingOut') : t('userAccount.actions.logout')}
435
- </Button>
560
+ <div className="mt-4 flex flex-col gap-2 sm:flex-row">
561
+ <Button
562
+ type="button"
563
+ variant="secondary"
564
+ className="w-full sm:w-auto"
565
+ onClick={() => void handleLogout()}
566
+ disabled={isLoggingOut || isDeletingAccount}
567
+ >
568
+ {isLoggingOut ? t('userAccount.actions.loggingOut') : t('userAccount.actions.logout')}
569
+ </Button>
570
+ {canDeleteAccount ? (
571
+ <Button
572
+ type="button"
573
+ variant="destructive"
574
+ className="w-full sm:w-auto"
575
+ onClick={() => void handleDeleteAccount()}
576
+ disabled={isLoggingOut || isDeletingAccount}
577
+ >
578
+ {isDeletingAccount
579
+ ? t('userAccount.actions.deletingAccount')
580
+ : t('userAccount.actions.deleteAccount')}
581
+ </Button>
582
+ ) : null}
583
+ </div>
436
584
  </section>
437
585
  );
438
586
  };
@@ -20,6 +20,8 @@ export const createUserSettingsRoute = (
20
20
  accessToken: string | null;
21
21
  settingsAccessToken: string | null;
22
22
  rawUserSettings: Settings['user'];
23
+ canDeleteAccount: boolean;
24
+ canEditName: boolean;
23
25
  },
24
26
  ): SettingsRouteItem[] =>
25
27
  user
@@ -36,6 +38,8 @@ export const createUserSettingsRoute = (
36
38
  accessToken={options.accessToken}
37
39
  settingsAccessToken={options.settingsAccessToken}
38
40
  rawUserSettings={options.rawUserSettings}
41
+ canDeleteAccount={options.canDeleteAccount}
42
+ canEditName={options.canEditName}
39
43
  />
40
44
  ),
41
45
  },