@shellui/core 0.5.4-alpha.1 → 0.6.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.
- package/README.md +2 -0
- package/package.json +6 -4
- package/schemas/shellui.config.schema.json +104 -64
- package/src/app.tsx +5 -3
- package/src/components/ContentView.tsx +26 -5
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/sonner.spec.tsx +138 -0
- package/src/components/ui/sonner.tsx +5 -5
- package/src/components/ui/switch.tsx +1 -1
- package/src/features/admin/AdminView.tsx +14 -3
- package/src/features/ai/AiBridge.tsx +106 -0
- package/src/features/ai/AiUnavailableResponder.tsx +39 -0
- package/src/features/ai/README.md +52 -0
- package/src/features/ai/ShellAiHost.tsx +24 -0
- package/src/features/ai/adapters/ollama.ts +170 -0
- package/src/features/ai/adapters/promptApi.spec.ts +135 -0
- package/src/features/ai/adapters/promptApi.ts +222 -0
- package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
- package/src/features/ai/adapters/webllm.spec.ts +527 -0
- package/src/features/ai/adapters/webllm.ts +142 -0
- package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
- package/src/features/ai/aiDisabledResponses.ts +32 -0
- package/src/features/ai/browserInstallStore.spec.ts +58 -0
- package/src/features/ai/browserInstallStore.ts +76 -0
- package/src/features/ai/catalog.ts +31 -0
- package/src/features/ai/createRegistry.ts +83 -0
- package/src/features/ai/developHarness.spec.ts +108 -0
- package/src/features/ai/developHarness.ts +161 -0
- package/src/features/ai/engine/formatAiError.spec.ts +85 -0
- package/src/features/ai/engine/formatAiError.ts +132 -0
- package/src/features/ai/engine/mapInitProgress.ts +9 -0
- package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
- package/src/features/ai/engine/vite-worker.d.ts +6 -0
- package/src/features/ai/engine/webllm.worker.ts +51 -0
- package/src/features/ai/engine/webllmEngine.ts +1011 -0
- package/src/features/ai/handleRequest.spec.ts +288 -0
- package/src/features/ai/handleRequest.ts +325 -0
- package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
- package/src/features/ai/isAiFeatureEnabled.ts +9 -0
- package/src/features/ai/promptApiSupport.spec.ts +64 -0
- package/src/features/ai/promptApiSupport.ts +117 -0
- package/src/features/ai/registry.spec.ts +100 -0
- package/src/features/ai/registry.ts +131 -0
- package/src/features/ai/status.spec.ts +92 -0
- package/src/features/ai/status.ts +85 -0
- package/src/features/ai/types.ts +100 -0
- package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
- package/src/features/ai/webLlmBrowserSupport.ts +92 -0
- package/src/features/alertDialog/DialogContext.tsx +3 -1
- package/src/features/auth/AuthProvider.tsx +254 -39
- package/src/features/auth/backends/index.ts +8 -0
- package/src/features/auth/backends/shellui.spec.ts +201 -0
- package/src/features/auth/backends/shellui.ts +93 -16
- package/src/features/auth/backends/supabase.ts +8 -0
- package/src/features/auth/backends/types.ts +16 -1
- package/src/features/auth/components/LoginButton.tsx +26 -2
- package/src/features/auth/components/LoginView.tsx +119 -134
- package/src/features/auth/components/OAuthCallbackView.tsx +12 -3
- package/src/features/auth/components/SessionLoadingView.tsx +21 -0
- package/src/features/auth/hooks/useAuth.tsx +12 -0
- package/src/features/auth/shellAccountRequests.ts +76 -0
- package/src/features/auth/utils/authRequestError.spec.ts +11 -0
- package/src/features/auth/utils/authRequestError.ts +10 -1
- package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
- package/src/features/auth/utils/authSessionPersistence.ts +12 -0
- package/src/features/auth/utils/index.ts +5 -0
- package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
- package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
- package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
- package/src/features/auth/utils/shareInFlight.ts +14 -0
- package/src/features/config/ConfigProvider.ts +9 -1
- package/src/features/config/types.ts +43 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
- package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
- package/src/features/layouts/utils.ts +6 -2
- package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
- package/src/features/security/trustedFrames.spec.ts +65 -0
- package/src/features/security/trustedFrames.ts +52 -0
- package/src/features/settings/SettingsIcons.tsx +17 -0
- package/src/features/settings/SettingsProvider.tsx +28 -3
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +21 -4
- package/src/features/settings/components/Ai.tsx +830 -0
- package/src/features/settings/components/Develop.tsx +4 -0
- package/src/features/settings/components/Storage.tsx +197 -32
- package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
- package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
- package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
- package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
- package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
- package/src/features/storage/uploads/UploadToaster.tsx +2 -44
- package/src/features/storage/uploads/uploadQueue.ts +128 -308
- package/src/features/storage/uploads/useUploadQueue.ts +7 -3
- package/src/features/transfers/TransferToastCard.tsx +467 -0
- package/src/features/transfers/TransferToaster.tsx +50 -0
- package/src/features/transfers/index.ts +33 -0
- package/src/features/transfers/transferQueue.spec.ts +97 -0
- package/src/features/transfers/transferQueue.ts +442 -0
- package/src/features/transfers/types.ts +38 -0
- package/src/features/transfers/useTransferQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +49 -2
- package/src/i18n/translations/en/settings.json +152 -2
- package/src/i18n/translations/fr/common.json +49 -2
- package/src/i18n/translations/fr/settings.json +152 -2
- package/src/index.css +57 -4
- package/src/index.ts +1 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { Button } from '../../components/ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Tooltip,
|
|
6
|
+
TooltipContent,
|
|
7
|
+
TooltipProvider,
|
|
8
|
+
TooltipTrigger,
|
|
9
|
+
} from '../../components/ui/tooltip';
|
|
10
|
+
import { cn } from '../../lib/utils';
|
|
11
|
+
import { formatBytes } from '../storage/quota';
|
|
12
|
+
import type { TransferItem } from './types';
|
|
13
|
+
import {
|
|
14
|
+
closeTransferToaster,
|
|
15
|
+
getItemPercent,
|
|
16
|
+
interruptAllTransfers,
|
|
17
|
+
interruptTransfer,
|
|
18
|
+
removeTransfer,
|
|
19
|
+
setTransferToastExpanded,
|
|
20
|
+
} from './transferQueue';
|
|
21
|
+
import { useTransferQueue } from './useTransferQueue';
|
|
22
|
+
|
|
23
|
+
function ChevronIcon({ expanded }: { expanded: boolean }) {
|
|
24
|
+
return (
|
|
25
|
+
<svg
|
|
26
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
27
|
+
width="16"
|
|
28
|
+
height="16"
|
|
29
|
+
viewBox="0 0 24 24"
|
|
30
|
+
fill="none"
|
|
31
|
+
stroke="currentColor"
|
|
32
|
+
strokeWidth="2"
|
|
33
|
+
strokeLinecap="round"
|
|
34
|
+
strokeLinejoin="round"
|
|
35
|
+
className={cn('transition-transform duration-200', expanded ? 'rotate-0' : 'rotate-180')}
|
|
36
|
+
>
|
|
37
|
+
<path d="m6 9 6 6 6-6" />
|
|
38
|
+
</svg>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function CloseIcon() {
|
|
43
|
+
return (
|
|
44
|
+
<svg
|
|
45
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
46
|
+
width="16"
|
|
47
|
+
height="16"
|
|
48
|
+
viewBox="0 0 24 24"
|
|
49
|
+
fill="none"
|
|
50
|
+
stroke="currentColor"
|
|
51
|
+
strokeWidth="2"
|
|
52
|
+
strokeLinecap="round"
|
|
53
|
+
strokeLinejoin="round"
|
|
54
|
+
>
|
|
55
|
+
<path d="M18 6 6 18" />
|
|
56
|
+
<path d="m6 6 12 12" />
|
|
57
|
+
</svg>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function CheckIcon() {
|
|
62
|
+
return (
|
|
63
|
+
<svg
|
|
64
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
65
|
+
width="14"
|
|
66
|
+
height="14"
|
|
67
|
+
viewBox="0 0 24 24"
|
|
68
|
+
fill="none"
|
|
69
|
+
stroke="currentColor"
|
|
70
|
+
strokeWidth="2.5"
|
|
71
|
+
strokeLinecap="round"
|
|
72
|
+
strokeLinejoin="round"
|
|
73
|
+
>
|
|
74
|
+
<path d="M20 6 9 17l-5-5" />
|
|
75
|
+
</svg>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function AlertIcon() {
|
|
80
|
+
return (
|
|
81
|
+
<svg
|
|
82
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
83
|
+
width="14"
|
|
84
|
+
height="14"
|
|
85
|
+
viewBox="0 0 24 24"
|
|
86
|
+
fill="none"
|
|
87
|
+
stroke="currentColor"
|
|
88
|
+
strokeWidth="2"
|
|
89
|
+
strokeLinecap="round"
|
|
90
|
+
strokeLinejoin="round"
|
|
91
|
+
>
|
|
92
|
+
<circle
|
|
93
|
+
cx="12"
|
|
94
|
+
cy="12"
|
|
95
|
+
r="10"
|
|
96
|
+
/>
|
|
97
|
+
<line
|
|
98
|
+
x1="12"
|
|
99
|
+
x2="12"
|
|
100
|
+
y1="8"
|
|
101
|
+
y2="12"
|
|
102
|
+
/>
|
|
103
|
+
<line
|
|
104
|
+
x1="12"
|
|
105
|
+
x2="12.01"
|
|
106
|
+
y1="16"
|
|
107
|
+
y2="16"
|
|
108
|
+
/>
|
|
109
|
+
</svg>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function CircularProgress({
|
|
114
|
+
percent,
|
|
115
|
+
tone,
|
|
116
|
+
}: {
|
|
117
|
+
percent: number;
|
|
118
|
+
tone: 'primary' | 'destructive' | 'muted';
|
|
119
|
+
}) {
|
|
120
|
+
const radius = 10;
|
|
121
|
+
const circumference = 2 * Math.PI * radius;
|
|
122
|
+
const offset = circumference - (percent / 100) * circumference;
|
|
123
|
+
const stroke =
|
|
124
|
+
tone === 'destructive'
|
|
125
|
+
? 'stroke-destructive'
|
|
126
|
+
: tone === 'muted'
|
|
127
|
+
? 'stroke-muted-foreground'
|
|
128
|
+
: 'stroke-primary';
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<svg
|
|
132
|
+
className="size-8 -rotate-90"
|
|
133
|
+
viewBox="0 0 24 24"
|
|
134
|
+
aria-hidden
|
|
135
|
+
>
|
|
136
|
+
<circle
|
|
137
|
+
cx="12"
|
|
138
|
+
cy="12"
|
|
139
|
+
r={radius}
|
|
140
|
+
fill="none"
|
|
141
|
+
className="stroke-muted"
|
|
142
|
+
strokeWidth="2.5"
|
|
143
|
+
/>
|
|
144
|
+
<circle
|
|
145
|
+
cx="12"
|
|
146
|
+
cy="12"
|
|
147
|
+
r={radius}
|
|
148
|
+
fill="none"
|
|
149
|
+
className={stroke}
|
|
150
|
+
strokeWidth="2.5"
|
|
151
|
+
strokeLinecap="round"
|
|
152
|
+
strokeDasharray={circumference}
|
|
153
|
+
strokeDashoffset={offset}
|
|
154
|
+
style={{ transition: 'stroke-dashoffset 160ms ease-out' }}
|
|
155
|
+
/>
|
|
156
|
+
</svg>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function StatusGlyph({
|
|
161
|
+
active,
|
|
162
|
+
error,
|
|
163
|
+
percent,
|
|
164
|
+
}: {
|
|
165
|
+
active: boolean;
|
|
166
|
+
error: boolean;
|
|
167
|
+
percent: number;
|
|
168
|
+
}) {
|
|
169
|
+
if (active) {
|
|
170
|
+
return (
|
|
171
|
+
<CircularProgress
|
|
172
|
+
percent={percent}
|
|
173
|
+
tone="primary"
|
|
174
|
+
/>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (error) {
|
|
178
|
+
return (
|
|
179
|
+
<div className="flex size-8 items-center justify-center rounded-full bg-destructive/10 text-destructive">
|
|
180
|
+
<AlertIcon />
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return (
|
|
185
|
+
<div className="flex size-8 items-center justify-center rounded-full bg-primary/10 text-primary">
|
|
186
|
+
<CheckIcon />
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function ProgressTrack({
|
|
192
|
+
percent,
|
|
193
|
+
tone = 'primary',
|
|
194
|
+
}: {
|
|
195
|
+
percent: number;
|
|
196
|
+
tone?: 'primary' | 'destructive';
|
|
197
|
+
}) {
|
|
198
|
+
return (
|
|
199
|
+
<div
|
|
200
|
+
className="h-1.5 w-full overflow-hidden rounded-full bg-muted"
|
|
201
|
+
role="progressbar"
|
|
202
|
+
aria-valuemin={0}
|
|
203
|
+
aria-valuemax={100}
|
|
204
|
+
aria-valuenow={percent}
|
|
205
|
+
>
|
|
206
|
+
<div
|
|
207
|
+
className={cn(
|
|
208
|
+
'h-full rounded-full transition-[width] duration-200 ease-out',
|
|
209
|
+
tone === 'destructive' ? 'bg-destructive' : 'bg-primary',
|
|
210
|
+
)}
|
|
211
|
+
style={{ width: `${percent}%` }}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function IconButton({
|
|
218
|
+
label,
|
|
219
|
+
onClick,
|
|
220
|
+
children,
|
|
221
|
+
}: {
|
|
222
|
+
label: string;
|
|
223
|
+
onClick: () => void;
|
|
224
|
+
children: ReactNode;
|
|
225
|
+
}) {
|
|
226
|
+
return (
|
|
227
|
+
<Tooltip>
|
|
228
|
+
<TooltipTrigger asChild>
|
|
229
|
+
<Button
|
|
230
|
+
type="button"
|
|
231
|
+
variant="ghost"
|
|
232
|
+
size="icon"
|
|
233
|
+
data-transfer-action=""
|
|
234
|
+
aria-label={label}
|
|
235
|
+
className="size-7 shrink-0 text-muted-foreground hover:text-foreground [touch-action:manipulation]"
|
|
236
|
+
onClick={(event) => {
|
|
237
|
+
event.stopPropagation();
|
|
238
|
+
onClick();
|
|
239
|
+
}}
|
|
240
|
+
>
|
|
241
|
+
{children}
|
|
242
|
+
</Button>
|
|
243
|
+
</TooltipTrigger>
|
|
244
|
+
<TooltipContent
|
|
245
|
+
side="top"
|
|
246
|
+
align="center"
|
|
247
|
+
collisionPadding={12}
|
|
248
|
+
>
|
|
249
|
+
{label}
|
|
250
|
+
</TooltipContent>
|
|
251
|
+
</Tooltip>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function FileRow({ item, locale }: { item: TransferItem; locale: string }) {
|
|
256
|
+
const { t } = useTranslation('common');
|
|
257
|
+
const percent = getItemPercent(item);
|
|
258
|
+
const isActive = item.status === 'active';
|
|
259
|
+
const sizeLabel = item.size > 0 ? formatBytes(item.size, locale) : null;
|
|
260
|
+
const completeLabel =
|
|
261
|
+
item.kind === 'download'
|
|
262
|
+
? t('transfers.statusDownloadComplete')
|
|
263
|
+
: t('transfers.statusUploadComplete');
|
|
264
|
+
const activeLabel =
|
|
265
|
+
item.kind === 'download' ? t('transfers.statusDownloading') : t('transfers.statusUploading');
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<div className="flex flex-col gap-1.5 py-2">
|
|
269
|
+
<div className="flex items-start gap-2">
|
|
270
|
+
<div className="min-w-0 flex-1">
|
|
271
|
+
<p
|
|
272
|
+
className={cn(
|
|
273
|
+
'truncate text-sm font-medium leading-tight',
|
|
274
|
+
item.status === 'cancelled' && 'text-muted-foreground',
|
|
275
|
+
)}
|
|
276
|
+
>
|
|
277
|
+
{item.name}
|
|
278
|
+
</p>
|
|
279
|
+
<p
|
|
280
|
+
className={cn(
|
|
281
|
+
'mt-0.5 text-xs',
|
|
282
|
+
item.status === 'error'
|
|
283
|
+
? 'break-words text-destructive whitespace-normal'
|
|
284
|
+
: 'text-muted-foreground',
|
|
285
|
+
)}
|
|
286
|
+
>
|
|
287
|
+
{item.status === 'error'
|
|
288
|
+
? item.error || t('transfers.statusError')
|
|
289
|
+
: isActive
|
|
290
|
+
? [sizeLabel, t('transfers.progressPercent', { percent })]
|
|
291
|
+
.filter(Boolean)
|
|
292
|
+
.join(' · ')
|
|
293
|
+
: item.status === 'success'
|
|
294
|
+
? [sizeLabel, completeLabel].filter(Boolean).join(' · ')
|
|
295
|
+
: t('transfers.statusCancelled')}
|
|
296
|
+
</p>
|
|
297
|
+
{isActive ? <span className="sr-only">{activeLabel}</span> : null}
|
|
298
|
+
</div>
|
|
299
|
+
<IconButton
|
|
300
|
+
label={isActive ? t('transfers.cancelItem') : t('transfers.removeItem')}
|
|
301
|
+
onClick={() => (isActive ? interruptTransfer(item.id) : removeTransfer(item.id))}
|
|
302
|
+
>
|
|
303
|
+
<CloseIcon />
|
|
304
|
+
</IconButton>
|
|
305
|
+
</div>
|
|
306
|
+
{isActive ? <ProgressTrack percent={percent} /> : null}
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function TransferToastCard() {
|
|
312
|
+
const { t, i18n } = useTranslation('common');
|
|
313
|
+
const { items, summary, expanded } = useTransferQueue();
|
|
314
|
+
const locale = i18n.language || 'en';
|
|
315
|
+
const hasErrors = summary.error > 0;
|
|
316
|
+
const subtitleParts: string[] = [];
|
|
317
|
+
|
|
318
|
+
let title: string;
|
|
319
|
+
if (summary.active > 0) {
|
|
320
|
+
if (summary.activeDownloads > 0 && summary.activeUploads === 0) {
|
|
321
|
+
title = t('transfers.titleDownloading', { count: summary.activeDownloads });
|
|
322
|
+
} else if (summary.activeUploads > 0 && summary.activeDownloads === 0) {
|
|
323
|
+
title = t('transfers.titleUploading', { count: summary.activeUploads });
|
|
324
|
+
} else {
|
|
325
|
+
title = t('transfers.titleTransferring', { count: summary.active });
|
|
326
|
+
}
|
|
327
|
+
} else if (summary.error > 0 && summary.success > 0) {
|
|
328
|
+
title = t('transfers.titleMixed', { success: summary.success, errors: summary.error });
|
|
329
|
+
} else if (summary.error > 0) {
|
|
330
|
+
title = t('transfers.titleFailed', { count: summary.error });
|
|
331
|
+
} else if (summary.success > 0) {
|
|
332
|
+
const downloads = items.filter(
|
|
333
|
+
(item) => item.status === 'success' && item.kind === 'download',
|
|
334
|
+
).length;
|
|
335
|
+
const uploads = items.filter(
|
|
336
|
+
(item) => item.status === 'success' && item.kind === 'upload',
|
|
337
|
+
).length;
|
|
338
|
+
if (downloads > 0 && uploads === 0) {
|
|
339
|
+
title = t('transfers.titleDownloadComplete', { count: downloads });
|
|
340
|
+
} else if (uploads > 0 && downloads === 0) {
|
|
341
|
+
title = t('transfers.titleUploadComplete', { count: uploads });
|
|
342
|
+
} else {
|
|
343
|
+
title = t('transfers.titleComplete', { count: summary.success });
|
|
344
|
+
}
|
|
345
|
+
} else if (summary.cancelled > 0) {
|
|
346
|
+
title = t('transfers.titleCancelled', { count: summary.cancelled });
|
|
347
|
+
} else {
|
|
348
|
+
title = t('transfers.titleCancelled', { count: summary.total });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (summary.active > 0 && summary.bytesTotal > 0) {
|
|
352
|
+
subtitleParts.push(
|
|
353
|
+
t('transfers.bytesProgress', {
|
|
354
|
+
transferred: formatBytes(summary.bytesTransferred, locale),
|
|
355
|
+
total: formatBytes(summary.bytesTotal, locale),
|
|
356
|
+
}),
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
if (hasErrors) {
|
|
360
|
+
subtitleParts.push(t('transfers.errorCount', { count: summary.error }));
|
|
361
|
+
}
|
|
362
|
+
if (summary.cancelled > 0) {
|
|
363
|
+
subtitleParts.push(t('transfers.cancelledCount', { count: summary.cancelled }));
|
|
364
|
+
}
|
|
365
|
+
if (summary.active > 0 && summary.total > summary.active) {
|
|
366
|
+
subtitleParts.push(
|
|
367
|
+
t('transfers.itemsProgress', {
|
|
368
|
+
done: summary.success + summary.error,
|
|
369
|
+
total: summary.total,
|
|
370
|
+
}),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<TooltipProvider delayDuration={200}>
|
|
376
|
+
<div
|
|
377
|
+
className="w-[min(24rem,calc(100vw-1.5rem))] overflow-hidden rounded-xl border border-border bg-background text-foreground shadow-lg"
|
|
378
|
+
data-transfer-toast=""
|
|
379
|
+
data-upload-toast=""
|
|
380
|
+
role="status"
|
|
381
|
+
aria-live="polite"
|
|
382
|
+
aria-busy={summary.active > 0}
|
|
383
|
+
>
|
|
384
|
+
<div className="flex items-start gap-3 p-3">
|
|
385
|
+
<StatusGlyph
|
|
386
|
+
active={summary.active > 0}
|
|
387
|
+
error={hasErrors && summary.active === 0}
|
|
388
|
+
percent={summary.percent}
|
|
389
|
+
/>
|
|
390
|
+
<button
|
|
391
|
+
type="button"
|
|
392
|
+
className="min-w-0 flex-1 cursor-pointer text-left [touch-action:manipulation]"
|
|
393
|
+
aria-expanded={expanded}
|
|
394
|
+
aria-label={expanded ? t('transfers.collapse') : t('transfers.expand')}
|
|
395
|
+
onClick={() => setTransferToastExpanded(!expanded)}
|
|
396
|
+
>
|
|
397
|
+
<p
|
|
398
|
+
className="truncate text-sm font-medium leading-tight"
|
|
399
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
400
|
+
>
|
|
401
|
+
{title}
|
|
402
|
+
</p>
|
|
403
|
+
{subtitleParts.length > 0 ? (
|
|
404
|
+
<p className="mt-0.5 truncate text-xs text-muted-foreground">
|
|
405
|
+
{subtitleParts.join(' · ')}
|
|
406
|
+
</p>
|
|
407
|
+
) : null}
|
|
408
|
+
</button>
|
|
409
|
+
<div className="flex items-center">
|
|
410
|
+
<IconButton
|
|
411
|
+
label={expanded ? t('transfers.collapse') : t('transfers.expand')}
|
|
412
|
+
onClick={() => setTransferToastExpanded(!expanded)}
|
|
413
|
+
>
|
|
414
|
+
<ChevronIcon expanded={expanded} />
|
|
415
|
+
</IconButton>
|
|
416
|
+
<IconButton
|
|
417
|
+
label={summary.active > 0 ? t('transfers.closeAndCancel') : t('transfers.dismiss')}
|
|
418
|
+
onClick={() => closeTransferToaster()}
|
|
419
|
+
>
|
|
420
|
+
<CloseIcon />
|
|
421
|
+
</IconButton>
|
|
422
|
+
</div>
|
|
423
|
+
</div>
|
|
424
|
+
<div className="px-3 pb-3">
|
|
425
|
+
<ProgressTrack
|
|
426
|
+
percent={summary.percent}
|
|
427
|
+
tone={hasErrors && summary.active === 0 ? 'destructive' : 'primary'}
|
|
428
|
+
/>
|
|
429
|
+
</div>
|
|
430
|
+
<div
|
|
431
|
+
className={cn(
|
|
432
|
+
'grid transition-[grid-template-rows] duration-300 ease-out',
|
|
433
|
+
expanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]',
|
|
434
|
+
)}
|
|
435
|
+
>
|
|
436
|
+
<div className="overflow-hidden">
|
|
437
|
+
<div className="border-t border-border px-3">
|
|
438
|
+
<div className="max-h-[min(14rem,calc(var(--shellui-app-height,100dvh)-14rem))] overflow-y-auto overscroll-contain divide-y divide-border">
|
|
439
|
+
{items.map((item) => (
|
|
440
|
+
<FileRow
|
|
441
|
+
key={item.id}
|
|
442
|
+
item={item}
|
|
443
|
+
locale={locale}
|
|
444
|
+
/>
|
|
445
|
+
))}
|
|
446
|
+
</div>
|
|
447
|
+
{summary.active > 0 ? (
|
|
448
|
+
<div className="flex justify-end py-2">
|
|
449
|
+
<Button
|
|
450
|
+
type="button"
|
|
451
|
+
variant="ghost"
|
|
452
|
+
size="sm"
|
|
453
|
+
data-transfer-action=""
|
|
454
|
+
className="h-8 text-xs text-muted-foreground [touch-action:manipulation]"
|
|
455
|
+
onClick={() => interruptAllTransfers()}
|
|
456
|
+
>
|
|
457
|
+
{t('transfers.cancelAll')}
|
|
458
|
+
</Button>
|
|
459
|
+
</div>
|
|
460
|
+
) : null}
|
|
461
|
+
</div>
|
|
462
|
+
</div>
|
|
463
|
+
</div>
|
|
464
|
+
</div>
|
|
465
|
+
</TooltipProvider>
|
|
466
|
+
);
|
|
467
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { shellui } from '@shellui/sdk';
|
|
4
|
+
import { TransferToastCard } from './TransferToastCard';
|
|
5
|
+
import {
|
|
6
|
+
startUploadToastDemo,
|
|
7
|
+
TRANSFER_TOAST_ID,
|
|
8
|
+
UPLOAD_TOAST_DEMO_MESSAGE,
|
|
9
|
+
} from './transferQueue';
|
|
10
|
+
import { useTransferQueue } from './useTransferQueue';
|
|
11
|
+
import { Z_INDEX } from '../../lib/z-index';
|
|
12
|
+
|
|
13
|
+
function isShellUiRoot(): boolean {
|
|
14
|
+
return typeof window !== 'undefined' && window.parent === window;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Transfer progress toast at the outermost Shellui window (uploads + AI downloads).
|
|
19
|
+
* Nested iframes never render it — they post work up so the root can show this
|
|
20
|
+
* panel above modals and keep it while the user navigates.
|
|
21
|
+
*/
|
|
22
|
+
export function TransferToaster() {
|
|
23
|
+
const isRoot = isShellUiRoot();
|
|
24
|
+
const { items } = useTransferQueue();
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isRoot) return;
|
|
28
|
+
return shellui.addMessageListener(UPLOAD_TOAST_DEMO_MESSAGE, () => {
|
|
29
|
+
startUploadToastDemo();
|
|
30
|
+
});
|
|
31
|
+
}, [isRoot]);
|
|
32
|
+
|
|
33
|
+
if (!isRoot || items.length === 0) return null;
|
|
34
|
+
|
|
35
|
+
return createPortal(
|
|
36
|
+
<div
|
|
37
|
+
id={TRANSFER_TOAST_ID}
|
|
38
|
+
className="pointer-events-none fixed right-[max(0.75rem,env(safe-area-inset-right,0px))] bottom-[max(5rem,calc(5rem+env(safe-area-inset-bottom,0px)))] md:right-[max(1rem,env(safe-area-inset-right,0px))] md:bottom-[max(1rem,env(safe-area-inset-bottom,0px))]"
|
|
39
|
+
style={{ zIndex: Z_INDEX.TOAST }}
|
|
40
|
+
>
|
|
41
|
+
<div className="pointer-events-auto origin-bottom animate-in fade-in-0 slide-in-from-bottom-2 duration-200">
|
|
42
|
+
<TransferToastCard />
|
|
43
|
+
</div>
|
|
44
|
+
</div>,
|
|
45
|
+
document.body,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @deprecated Prefer TransferToaster — same component. */
|
|
50
|
+
export const UploadToaster = TransferToaster;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type { TransferItem, TransferItemStatus, TransferKind, TransferQueueSummary } from './types';
|
|
2
|
+
export {
|
|
3
|
+
TRANSFER_TOAST_ID,
|
|
4
|
+
UPLOAD_TOAST_ID,
|
|
5
|
+
UPLOAD_TOAST_DEMO_MESSAGE,
|
|
6
|
+
TRANSFER_TOAST_AUTO_DISMISS_MS,
|
|
7
|
+
UPLOAD_TOAST_AUTO_DISMISS_MS,
|
|
8
|
+
subscribeTransferQueue,
|
|
9
|
+
getTransferQueue,
|
|
10
|
+
isTransferToastExpanded,
|
|
11
|
+
setTransferToastExpanded,
|
|
12
|
+
getItemPercent,
|
|
13
|
+
getTransferSummary,
|
|
14
|
+
addTransfer,
|
|
15
|
+
setTransferProgress,
|
|
16
|
+
completeTransfer,
|
|
17
|
+
failTransfer,
|
|
18
|
+
markTransferCancelled,
|
|
19
|
+
interruptTransfer,
|
|
20
|
+
removeTransfer,
|
|
21
|
+
dismissFinishedTransfers,
|
|
22
|
+
interruptAllTransfers,
|
|
23
|
+
closeTransferToaster,
|
|
24
|
+
resetTransferQueue,
|
|
25
|
+
requestUploadToastDemo,
|
|
26
|
+
startUploadToastDemo,
|
|
27
|
+
isTransferSignalAborted,
|
|
28
|
+
type AddTransferInput,
|
|
29
|
+
type SetTransferProgressInput,
|
|
30
|
+
} from './transferQueue';
|
|
31
|
+
export { useTransferQueue } from './useTransferQueue';
|
|
32
|
+
export { TransferToaster, UploadToaster } from './TransferToaster';
|
|
33
|
+
export { TransferToastCard } from './TransferToastCard';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { mapInitProgress } from '../ai/engine/mapInitProgress.js';
|
|
3
|
+
import {
|
|
4
|
+
addTransfer,
|
|
5
|
+
closeTransferToaster,
|
|
6
|
+
completeTransfer,
|
|
7
|
+
failTransfer,
|
|
8
|
+
getItemPercent,
|
|
9
|
+
getTransferQueue,
|
|
10
|
+
getTransferSummary,
|
|
11
|
+
interruptTransfer,
|
|
12
|
+
resetTransferQueue,
|
|
13
|
+
setTransferProgress,
|
|
14
|
+
TRANSFER_TOAST_AUTO_DISMISS_MS,
|
|
15
|
+
} from './transferQueue';
|
|
16
|
+
|
|
17
|
+
describe('transferQueue', () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.useFakeTimers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
resetTransferQueue();
|
|
24
|
+
vi.useRealTimers();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('tracks upload and download progress in one queue', () => {
|
|
28
|
+
addTransfer({
|
|
29
|
+
id: 'up',
|
|
30
|
+
kind: 'upload',
|
|
31
|
+
name: 'a.pdf',
|
|
32
|
+
detail: 'a.pdf',
|
|
33
|
+
size: 100,
|
|
34
|
+
});
|
|
35
|
+
addTransfer({
|
|
36
|
+
id: 'dl',
|
|
37
|
+
kind: 'download',
|
|
38
|
+
name: 'Llama 3.2',
|
|
39
|
+
detail: 'Llama-3.2-1B-Instruct-q4f16_1-MLC',
|
|
40
|
+
size: 700_000_000,
|
|
41
|
+
});
|
|
42
|
+
setTransferProgress('up', { loaded: 50, total: 100 });
|
|
43
|
+
setTransferProgress('dl', { ratio: 0.25 });
|
|
44
|
+
|
|
45
|
+
const summary = getTransferSummary();
|
|
46
|
+
expect(summary.total).toBe(2);
|
|
47
|
+
expect(summary.active).toBe(2);
|
|
48
|
+
expect(summary.activeUploads).toBe(1);
|
|
49
|
+
expect(summary.activeDownloads).toBe(1);
|
|
50
|
+
expect(getItemPercent(getTransferQueue().find((i) => i.id === 'dl')!)).toBe(25);
|
|
51
|
+
expect(getTransferQueue().find((i) => i.id === 'dl')?.bytesTransferred).toBe(175_000_000);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('supports ratio-only progress when size is unknown', () => {
|
|
55
|
+
addTransfer({ id: 'dl', kind: 'download', name: 'Model', size: 0 });
|
|
56
|
+
setTransferProgress('dl', { ratio: 0.4 });
|
|
57
|
+
expect(getItemPercent(getTransferQueue()[0]!)).toBe(40);
|
|
58
|
+
expect(getTransferSummary().percent).toBe(40);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('interrupts a download and marks it cancelled', () => {
|
|
62
|
+
const { signal } = addTransfer({ id: 'dl', kind: 'download', name: 'Model', size: 10 });
|
|
63
|
+
interruptTransfer('dl');
|
|
64
|
+
expect(signal.aborted).toBe(true);
|
|
65
|
+
expect(getTransferQueue()).toMatchObject([{ id: 'dl', status: 'cancelled' }]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('auto-dismisses after successful transfers', () => {
|
|
69
|
+
addTransfer({ id: 'a', kind: 'upload', name: 'a.pdf', size: 10 });
|
|
70
|
+
completeTransfer('a');
|
|
71
|
+
vi.advanceTimersByTime(TRANSFER_TOAST_AUTO_DISMISS_MS);
|
|
72
|
+
expect(getTransferQueue()).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('keeps errors visible', () => {
|
|
76
|
+
addTransfer({ id: 'a', kind: 'download', name: 'Model', size: 10 });
|
|
77
|
+
failTransfer('a', 'WebGPU lost');
|
|
78
|
+
vi.advanceTimersByTime(TRANSFER_TOAST_AUTO_DISMISS_MS * 2);
|
|
79
|
+
expect(getTransferQueue()).toHaveLength(1);
|
|
80
|
+
expect(getTransferQueue()[0]?.status).toBe('error');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('closeTransferToaster clears the queue', () => {
|
|
84
|
+
addTransfer({ id: 'a', kind: 'download', name: 'Model', size: 10 });
|
|
85
|
+
closeTransferToaster();
|
|
86
|
+
expect(getTransferQueue()).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('mapInitProgress', () => {
|
|
91
|
+
it('clamps WebLLM init progress reports to 0–1', () => {
|
|
92
|
+
expect(mapInitProgress({ progress: 0.42 })).toBe(0.42);
|
|
93
|
+
expect(mapInitProgress({ progress: -1 })).toBe(0);
|
|
94
|
+
expect(mapInitProgress({ progress: 2 })).toBe(1);
|
|
95
|
+
expect(mapInitProgress({ progress: Number.NaN })).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
});
|