@shellui/core 0.5.4-alpha.1 → 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.
- 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 +114 -133
- 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.ts +4 -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 +4 -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 +46 -2
- package/src/i18n/translations/en/settings.json +151 -2
- package/src/i18n/translations/fr/common.json +46 -2
- package/src/i18n/translations/fr/settings.json +151 -2
- package/src/index.css +57 -4
- package/src/index.ts +1 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { postShellMessage } from '@shellui/sdk';
|
|
2
|
+
import type { TransferItem, TransferItemStatus, TransferKind, TransferQueueSummary } from './types';
|
|
3
|
+
|
|
4
|
+
export const TRANSFER_TOAST_ID = 'shellui-transfer-progress';
|
|
5
|
+
/** @deprecated Prefer TRANSFER_TOAST_ID; kept for upload demo message listeners. */
|
|
6
|
+
export const UPLOAD_TOAST_ID = TRANSFER_TOAST_ID;
|
|
7
|
+
export const UPLOAD_TOAST_DEMO_MESSAGE = 'SHELLUI_UPLOAD_TOAST_DEMO';
|
|
8
|
+
/** Brief pause so the success state is visible before the toaster hides. */
|
|
9
|
+
export const TRANSFER_TOAST_AUTO_DISMISS_MS = 2500;
|
|
10
|
+
export const UPLOAD_TOAST_AUTO_DISMISS_MS = TRANSFER_TOAST_AUTO_DISMISS_MS;
|
|
11
|
+
|
|
12
|
+
type TransferListener = () => void;
|
|
13
|
+
|
|
14
|
+
export type AddTransferInput = {
|
|
15
|
+
id?: string;
|
|
16
|
+
kind: TransferKind;
|
|
17
|
+
name: string;
|
|
18
|
+
detail?: string;
|
|
19
|
+
meta?: Record<string, string>;
|
|
20
|
+
size?: number;
|
|
21
|
+
demo?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const listeners = new Set<TransferListener>();
|
|
25
|
+
const abortControllers = new Map<string, AbortController>();
|
|
26
|
+
const demoTimers = new Map<string, ReturnType<typeof setInterval>>();
|
|
27
|
+
const demoStartTimeouts: ReturnType<typeof setTimeout>[] = [];
|
|
28
|
+
|
|
29
|
+
let items: TransferItem[] = [];
|
|
30
|
+
let expanded = false;
|
|
31
|
+
let autoDismissTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
32
|
+
|
|
33
|
+
function clearAutoDismissTimeout(): void {
|
|
34
|
+
if (autoDismissTimeout === null) return;
|
|
35
|
+
clearTimeout(autoDismissTimeout);
|
|
36
|
+
autoDismissTimeout = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hide the toaster a few seconds after every transfer finishes successfully.
|
|
41
|
+
* Errors and in-progress transfers keep the panel open; cancelled-only queues stay too.
|
|
42
|
+
*/
|
|
43
|
+
function scheduleAutoDismissIfNeeded(): void {
|
|
44
|
+
clearAutoDismissTimeout();
|
|
45
|
+
const summary = getTransferSummary();
|
|
46
|
+
if (summary.active > 0 || summary.error > 0 || summary.success === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
autoDismissTimeout = setTimeout(() => {
|
|
50
|
+
autoDismissTimeout = null;
|
|
51
|
+
const current = getTransferSummary();
|
|
52
|
+
if (current.active > 0 || current.error > 0 || current.success === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
resetTransferQueue();
|
|
56
|
+
}, TRANSFER_TOAST_AUTO_DISMISS_MS);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function emit(): void {
|
|
60
|
+
listeners.forEach((listener) => listener());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function createId(): string {
|
|
64
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
65
|
+
return crypto.randomUUID();
|
|
66
|
+
}
|
|
67
|
+
return `transfer-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function patchItem(id: string, patch: Partial<TransferItem>): void {
|
|
71
|
+
const index = items.findIndex((item) => item.id === id);
|
|
72
|
+
if (index === -1) return;
|
|
73
|
+
items = items.map((item) => (item.id === id ? { ...item, ...patch } : item));
|
|
74
|
+
emit();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function clearDemoStartTimeouts(): void {
|
|
78
|
+
demoStartTimeouts.forEach((timeout) => clearTimeout(timeout));
|
|
79
|
+
demoStartTimeouts.length = 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function clearDemoTimer(id: string): void {
|
|
83
|
+
const timer = demoTimers.get(id);
|
|
84
|
+
if (timer !== undefined) {
|
|
85
|
+
clearInterval(timer);
|
|
86
|
+
demoTimers.delete(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function subscribeTransferQueue(listener: TransferListener): () => void {
|
|
91
|
+
listeners.add(listener);
|
|
92
|
+
return () => {
|
|
93
|
+
listeners.delete(listener);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function getTransferQueue(): TransferItem[] {
|
|
98
|
+
return items;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function isTransferToastExpanded(): boolean {
|
|
102
|
+
return expanded;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function setTransferToastExpanded(value: boolean): void {
|
|
106
|
+
if (expanded === value) return;
|
|
107
|
+
expanded = value;
|
|
108
|
+
emit();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getItemPercent(item: TransferItem): number {
|
|
112
|
+
if (item.status === 'success') return 100;
|
|
113
|
+
if (typeof item.progressRatio === 'number' && Number.isFinite(item.progressRatio)) {
|
|
114
|
+
return Math.min(100, Math.max(0, Math.round(item.progressRatio * 100)));
|
|
115
|
+
}
|
|
116
|
+
if (item.size <= 0) return 0;
|
|
117
|
+
return Math.min(100, Math.max(0, Math.round((item.bytesTransferred / item.size) * 100)));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getTransferSummary(list: TransferItem[] = items): TransferQueueSummary {
|
|
121
|
+
const active = list.filter((item) => item.status === 'active').length;
|
|
122
|
+
const success = list.filter((item) => item.status === 'success').length;
|
|
123
|
+
const error = list.filter((item) => item.status === 'error').length;
|
|
124
|
+
const cancelled = list.filter((item) => item.status === 'cancelled').length;
|
|
125
|
+
const activeUploads = list.filter(
|
|
126
|
+
(item) => item.status === 'active' && item.kind === 'upload',
|
|
127
|
+
).length;
|
|
128
|
+
const activeDownloads = list.filter(
|
|
129
|
+
(item) => item.status === 'active' && item.kind === 'download',
|
|
130
|
+
).length;
|
|
131
|
+
|
|
132
|
+
const bytesTransferred = list.reduce((sum, item) => {
|
|
133
|
+
if (item.status === 'success') return sum + (item.size || item.bytesTransferred);
|
|
134
|
+
if (item.status === 'active') {
|
|
135
|
+
if (typeof item.progressRatio === 'number' && item.size > 0) {
|
|
136
|
+
return sum + Math.round(item.size * Math.min(1, Math.max(0, item.progressRatio)));
|
|
137
|
+
}
|
|
138
|
+
return sum + Math.min(item.bytesTransferred, item.size || item.bytesTransferred);
|
|
139
|
+
}
|
|
140
|
+
return sum;
|
|
141
|
+
}, 0);
|
|
142
|
+
const bytesTotal = list.reduce((sum, item) => sum + item.size, 0);
|
|
143
|
+
|
|
144
|
+
let percent: number;
|
|
145
|
+
if (bytesTotal > 0) {
|
|
146
|
+
percent = Math.min(100, Math.max(0, Math.round((bytesTransferred / bytesTotal) * 100)));
|
|
147
|
+
} else if (active > 0) {
|
|
148
|
+
const ratios = list
|
|
149
|
+
.filter((item) => item.status === 'active')
|
|
150
|
+
.map((item) =>
|
|
151
|
+
typeof item.progressRatio === 'number' ? Math.min(1, Math.max(0, item.progressRatio)) : 0,
|
|
152
|
+
);
|
|
153
|
+
const avg =
|
|
154
|
+
ratios.length > 0 ? ratios.reduce((sum, value) => sum + value, 0) / ratios.length : 0;
|
|
155
|
+
percent = Math.round(avg * 100);
|
|
156
|
+
} else if (list.length > 0) {
|
|
157
|
+
percent = 100;
|
|
158
|
+
} else {
|
|
159
|
+
percent = 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
total: list.length,
|
|
164
|
+
active,
|
|
165
|
+
success,
|
|
166
|
+
error,
|
|
167
|
+
cancelled,
|
|
168
|
+
bytesTransferred,
|
|
169
|
+
bytesTotal,
|
|
170
|
+
percent,
|
|
171
|
+
activeUploads,
|
|
172
|
+
activeDownloads,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function addTransfer(input: AddTransferInput): { id: string; signal: AbortSignal } {
|
|
177
|
+
clearAutoDismissTimeout();
|
|
178
|
+
const id = input.id ?? createId();
|
|
179
|
+
const existing = abortControllers.get(id);
|
|
180
|
+
existing?.abort();
|
|
181
|
+
clearDemoTimer(id);
|
|
182
|
+
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
abortControllers.set(id, controller);
|
|
185
|
+
|
|
186
|
+
const next: TransferItem = {
|
|
187
|
+
id,
|
|
188
|
+
kind: input.kind,
|
|
189
|
+
name: input.name,
|
|
190
|
+
detail: input.detail,
|
|
191
|
+
meta: input.meta,
|
|
192
|
+
size: Math.max(0, input.size ?? 0),
|
|
193
|
+
bytesTransferred: 0,
|
|
194
|
+
progressRatio: 0,
|
|
195
|
+
status: 'active',
|
|
196
|
+
demo: input.demo,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
items = [...items.filter((item) => item.id !== id), next];
|
|
200
|
+
emit();
|
|
201
|
+
return { id, signal: controller.signal };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export type SetTransferProgressInput = {
|
|
205
|
+
loaded?: number;
|
|
206
|
+
total?: number;
|
|
207
|
+
/** Fractional 0–1 progress from the engine (preferred when bytes are coarse). */
|
|
208
|
+
ratio?: number;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export function setTransferProgress(id: string, input: SetTransferProgressInput): void {
|
|
212
|
+
const item = items.find((entry) => entry.id === id);
|
|
213
|
+
if (!item || item.status !== 'active') return;
|
|
214
|
+
|
|
215
|
+
const patch: Partial<TransferItem> = {};
|
|
216
|
+
if (typeof input.total === 'number' && input.total > 0) {
|
|
217
|
+
patch.size = input.total;
|
|
218
|
+
}
|
|
219
|
+
if (typeof input.ratio === 'number' && Number.isFinite(input.ratio)) {
|
|
220
|
+
const ratio = Math.min(1, Math.max(0, input.ratio));
|
|
221
|
+
patch.progressRatio = ratio;
|
|
222
|
+
const size = patch.size ?? item.size;
|
|
223
|
+
if (size > 0) {
|
|
224
|
+
patch.bytesTransferred = Math.round(size * ratio);
|
|
225
|
+
}
|
|
226
|
+
} else if (typeof input.loaded === 'number') {
|
|
227
|
+
patch.bytesTransferred = Math.max(0, input.loaded);
|
|
228
|
+
const size = patch.size ?? item.size;
|
|
229
|
+
if (size > 0) {
|
|
230
|
+
patch.progressRatio = Math.min(1, Math.max(0, input.loaded / size));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
patchItem(id, patch);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function completeTransfer(id: string): void {
|
|
237
|
+
const item = items.find((entry) => entry.id === id);
|
|
238
|
+
if (!item || item.status !== 'active') return;
|
|
239
|
+
abortControllers.delete(id);
|
|
240
|
+
clearDemoTimer(id);
|
|
241
|
+
patchItem(id, {
|
|
242
|
+
status: 'success',
|
|
243
|
+
bytesTransferred: item.size || item.bytesTransferred,
|
|
244
|
+
progressRatio: 1,
|
|
245
|
+
error: undefined,
|
|
246
|
+
});
|
|
247
|
+
scheduleAutoDismissIfNeeded();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function failTransfer(id: string, message: string): void {
|
|
251
|
+
const item = items.find((entry) => entry.id === id);
|
|
252
|
+
if (!item || item.status !== 'active') return;
|
|
253
|
+
abortControllers.delete(id);
|
|
254
|
+
clearDemoTimer(id);
|
|
255
|
+
patchItem(id, { status: 'error', error: message });
|
|
256
|
+
clearAutoDismissTimeout();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function markTransferCancelled(id: string): void {
|
|
260
|
+
if (!items.some((item) => item.id === id)) return;
|
|
261
|
+
abortControllers.delete(id);
|
|
262
|
+
clearDemoTimer(id);
|
|
263
|
+
patchItem(id, { status: 'cancelled' });
|
|
264
|
+
scheduleAutoDismissIfNeeded();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Abort an in-progress transfer and keep it visible as cancelled. */
|
|
268
|
+
export function interruptTransfer(id: string): void {
|
|
269
|
+
const item = items.find((entry) => entry.id === id);
|
|
270
|
+
if (!item || item.status !== 'active') return;
|
|
271
|
+
abortControllers.get(id)?.abort();
|
|
272
|
+
markTransferCancelled(id);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Remove a finished (or cancelled) item from the toaster. */
|
|
276
|
+
export function removeTransfer(id: string): void {
|
|
277
|
+
const item = items.find((entry) => entry.id === id);
|
|
278
|
+
if (!item) return;
|
|
279
|
+
if (item.status === 'active') {
|
|
280
|
+
abortControllers.get(id)?.abort();
|
|
281
|
+
}
|
|
282
|
+
abortControllers.delete(id);
|
|
283
|
+
clearDemoTimer(id);
|
|
284
|
+
const next = items.filter((entry) => entry.id !== id);
|
|
285
|
+
if (next.length === items.length) return;
|
|
286
|
+
items = next;
|
|
287
|
+
if (items.length === 0) {
|
|
288
|
+
expanded = false;
|
|
289
|
+
clearAutoDismissTimeout();
|
|
290
|
+
}
|
|
291
|
+
emit();
|
|
292
|
+
if (items.length > 0) {
|
|
293
|
+
scheduleAutoDismissIfNeeded();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function dismissFinishedTransfers(): void {
|
|
298
|
+
clearAutoDismissTimeout();
|
|
299
|
+
const keep = items.filter((item) => item.status === 'active');
|
|
300
|
+
items.forEach((item) => {
|
|
301
|
+
if (item.status === 'active') return;
|
|
302
|
+
abortControllers.delete(item.id);
|
|
303
|
+
clearDemoTimer(item.id);
|
|
304
|
+
});
|
|
305
|
+
if (keep.length === items.length) return;
|
|
306
|
+
items = keep;
|
|
307
|
+
if (items.length === 0) expanded = false;
|
|
308
|
+
emit();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function interruptAllTransfers(): void {
|
|
312
|
+
const active = items.filter((item) => item.status === 'active');
|
|
313
|
+
if (active.length === 0) return;
|
|
314
|
+
active.forEach((item) => {
|
|
315
|
+
abortControllers.get(item.id)?.abort();
|
|
316
|
+
markTransferCancelled(item.id);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Close the toaster: cancel leftover transfers and hide the panel. */
|
|
321
|
+
export function closeTransferToaster(): void {
|
|
322
|
+
resetTransferQueue();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function resetTransferQueue(): void {
|
|
326
|
+
clearAutoDismissTimeout();
|
|
327
|
+
abortControllers.forEach((controller) => controller.abort());
|
|
328
|
+
abortControllers.clear();
|
|
329
|
+
demoTimers.forEach((timer) => clearInterval(timer));
|
|
330
|
+
demoTimers.clear();
|
|
331
|
+
clearDemoStartTimeouts();
|
|
332
|
+
items = [];
|
|
333
|
+
expanded = false;
|
|
334
|
+
emit();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const DEMO_FILES: Array<{
|
|
338
|
+
name: string;
|
|
339
|
+
path: string;
|
|
340
|
+
bucket: string;
|
|
341
|
+
size: number;
|
|
342
|
+
durationMs: number;
|
|
343
|
+
outcome: Extract<TransferItemStatus, 'success' | 'error'>;
|
|
344
|
+
error?: string;
|
|
345
|
+
}> = [
|
|
346
|
+
{
|
|
347
|
+
name: 'quarterly-report.pdf',
|
|
348
|
+
path: 'docs/quarterly-report.pdf',
|
|
349
|
+
bucket: 'company',
|
|
350
|
+
size: 2_450_000,
|
|
351
|
+
durationMs: 3600,
|
|
352
|
+
outcome: 'success',
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: 'team-offsite.jpg',
|
|
356
|
+
path: 'photos/team-offsite.jpg',
|
|
357
|
+
bucket: 'company',
|
|
358
|
+
size: 6_200_000,
|
|
359
|
+
durationMs: 7200,
|
|
360
|
+
outcome: 'success',
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: 'budget.xlsx',
|
|
364
|
+
path: 'docs/budget.xlsx',
|
|
365
|
+
bucket: 'company',
|
|
366
|
+
size: 840_000,
|
|
367
|
+
durationMs: 2400,
|
|
368
|
+
outcome: 'error',
|
|
369
|
+
error: 'Quota exceeded',
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: 'archive.zip',
|
|
373
|
+
path: 'backup/archive.zip',
|
|
374
|
+
bucket: 'company',
|
|
375
|
+
size: 18_500_000,
|
|
376
|
+
durationMs: 9800,
|
|
377
|
+
outcome: 'success',
|
|
378
|
+
},
|
|
379
|
+
];
|
|
380
|
+
|
|
381
|
+
function clearDemoUploads(): void {
|
|
382
|
+
clearDemoStartTimeouts();
|
|
383
|
+
items
|
|
384
|
+
.filter((item) => item.demo)
|
|
385
|
+
.forEach((item) => {
|
|
386
|
+
abortControllers.get(item.id)?.abort();
|
|
387
|
+
abortControllers.delete(item.id);
|
|
388
|
+
clearDemoTimer(item.id);
|
|
389
|
+
});
|
|
390
|
+
items = items.filter((item) => !item.demo);
|
|
391
|
+
if (items.length === 0) expanded = false;
|
|
392
|
+
emit();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Ask the root shell to show the demo toaster (no-op network). Safe to call from iframes. */
|
|
396
|
+
export function requestUploadToastDemo(): void {
|
|
397
|
+
if (typeof window === 'undefined') return;
|
|
398
|
+
const message = { type: UPLOAD_TOAST_DEMO_MESSAGE, payload: {} };
|
|
399
|
+
postShellMessage(message);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Simulated uploads for the Develop panel — no network requests. */
|
|
403
|
+
export function startUploadToastDemo(): void {
|
|
404
|
+
clearDemoUploads();
|
|
405
|
+
expanded = false;
|
|
406
|
+
|
|
407
|
+
DEMO_FILES.forEach((spec, index) => {
|
|
408
|
+
const timeout = setTimeout(() => {
|
|
409
|
+
const { id, signal } = addTransfer({
|
|
410
|
+
kind: 'upload',
|
|
411
|
+
name: spec.name,
|
|
412
|
+
detail: spec.path,
|
|
413
|
+
meta: { bucket: spec.bucket, path: spec.path },
|
|
414
|
+
size: spec.size,
|
|
415
|
+
demo: true,
|
|
416
|
+
});
|
|
417
|
+
const startedAt = Date.now();
|
|
418
|
+
const timer = setInterval(() => {
|
|
419
|
+
if (signal.aborted) {
|
|
420
|
+
clearDemoTimer(id);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const ratio = Math.min(1, (Date.now() - startedAt) / spec.durationMs);
|
|
424
|
+
setTransferProgress(id, { loaded: Math.round(spec.size * ratio), total: spec.size });
|
|
425
|
+
if (ratio < 1) return;
|
|
426
|
+
clearDemoTimer(id);
|
|
427
|
+
if (spec.outcome === 'error') {
|
|
428
|
+
failTransfer(id, spec.error || 'Upload failed');
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
completeTransfer(id);
|
|
432
|
+
}, 80);
|
|
433
|
+
demoTimers.set(id, timer);
|
|
434
|
+
}, index * 180);
|
|
435
|
+
demoStartTimeouts.push(timeout);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function isTransferSignalAborted(id: string, signal?: AbortSignal): boolean {
|
|
440
|
+
const item = items.find((entry) => entry.id === id);
|
|
441
|
+
return Boolean(signal?.aborted) || !item || item.status === 'cancelled';
|
|
442
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type TransferKind = 'upload' | 'download';
|
|
2
|
+
|
|
3
|
+
/** In-flight transfers use `active`; finished states match the upload toaster UX. */
|
|
4
|
+
export type TransferItemStatus = 'active' | 'success' | 'error' | 'cancelled';
|
|
5
|
+
|
|
6
|
+
export type TransferItem = {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: TransferKind;
|
|
9
|
+
name: string;
|
|
10
|
+
/** Secondary context: storage path for uploads, model id for downloads. */
|
|
11
|
+
detail?: string;
|
|
12
|
+
/** Optional metadata (e.g. bucket for uploads). */
|
|
13
|
+
meta?: Record<string, string>;
|
|
14
|
+
size: number;
|
|
15
|
+
bytesTransferred: number;
|
|
16
|
+
/**
|
|
17
|
+
* Fractional progress 0–1 from the producer (WebLLM init reports, etc.).
|
|
18
|
+
* Used when byte totals are coarse or unknown.
|
|
19
|
+
*/
|
|
20
|
+
progressRatio?: number;
|
|
21
|
+
status: TransferItemStatus;
|
|
22
|
+
error?: string;
|
|
23
|
+
demo?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type TransferQueueSummary = {
|
|
27
|
+
total: number;
|
|
28
|
+
active: number;
|
|
29
|
+
success: number;
|
|
30
|
+
error: number;
|
|
31
|
+
cancelled: number;
|
|
32
|
+
bytesTransferred: number;
|
|
33
|
+
bytesTotal: number;
|
|
34
|
+
percent: number;
|
|
35
|
+
/** Counts by kind among currently active items. */
|
|
36
|
+
activeUploads: number;
|
|
37
|
+
activeDownloads: number;
|
|
38
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
getTransferQueue,
|
|
4
|
+
getTransferSummary,
|
|
5
|
+
isTransferToastExpanded,
|
|
6
|
+
subscribeTransferQueue,
|
|
7
|
+
} from './transferQueue';
|
|
8
|
+
import type { TransferItem, TransferQueueSummary } from './types';
|
|
9
|
+
|
|
10
|
+
export function useTransferQueue(): {
|
|
11
|
+
items: TransferItem[];
|
|
12
|
+
summary: TransferQueueSummary;
|
|
13
|
+
expanded: boolean;
|
|
14
|
+
} {
|
|
15
|
+
const [items, setItems] = useState<TransferItem[]>(getTransferQueue);
|
|
16
|
+
const [expanded, setExpanded] = useState(isTransferToastExpanded);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
return subscribeTransferQueue(() => {
|
|
20
|
+
setItems(getTransferQueue());
|
|
21
|
+
setExpanded(isTransferToastExpanded());
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
items,
|
|
27
|
+
summary: getTransferSummary(items),
|
|
28
|
+
expanded,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"navigationError": "Navigation error",
|
|
11
11
|
"navigationNotAllowed": "This URL is not configured in the app navigation.",
|
|
12
|
+
"sessionLoading": "Restoring your session…",
|
|
12
13
|
"adminShell": {
|
|
13
14
|
"djangoAdmin": "Django admin"
|
|
14
15
|
},
|
|
@@ -21,7 +22,8 @@
|
|
|
21
22
|
"noEmail": "No email",
|
|
22
23
|
"userFallback": "User",
|
|
23
24
|
"goToLoginAriaLabel": "Go to login",
|
|
24
|
-
"openAccountMenuAriaLabel": "Open account menu for {{name}}"
|
|
25
|
+
"openAccountMenuAriaLabel": "Open account menu for {{name}}",
|
|
26
|
+
"loadingAccount": "Loading account…"
|
|
25
27
|
},
|
|
26
28
|
"loginPage": {
|
|
27
29
|
"welcomeBack": "Welcome back",
|
|
@@ -47,7 +49,10 @@
|
|
|
47
49
|
"noMethodsEnabled": "No login method is currently enabled in backend auth settings.",
|
|
48
50
|
"cancel": "Cancel",
|
|
49
51
|
"brandingIframeTitle": "Login branding",
|
|
50
|
-
"
|
|
52
|
+
"magicLinkSentTitle": "Check your email",
|
|
53
|
+
"magicLinkSentDescription": "Open the sign-in link we sent to",
|
|
54
|
+
"magicLinkChangeEmail": "Use a different email",
|
|
55
|
+
"magicLinkChangeEmailIn": "Use a different email ({{seconds}}s)",
|
|
51
56
|
"enterEmail": "Please enter your email address.",
|
|
52
57
|
"couldNotSendMagicLink": "Could not send magic link.",
|
|
53
58
|
"methodUnsupported": "This backend does not support {{method}} login.",
|
|
@@ -96,6 +101,45 @@
|
|
|
96
101
|
"statusError": "Failed",
|
|
97
102
|
"statusCancelled": "Cancelled"
|
|
98
103
|
},
|
|
104
|
+
"transfers": {
|
|
105
|
+
"titleUploading_one": "Uploading {{count}} file",
|
|
106
|
+
"titleUploading_other": "Uploading {{count}} files",
|
|
107
|
+
"titleDownloading_one": "Downloading {{count}} model",
|
|
108
|
+
"titleDownloading_other": "Downloading {{count}} models",
|
|
109
|
+
"titleTransferring_one": "{{count}} transfer in progress",
|
|
110
|
+
"titleTransferring_other": "{{count}} transfers in progress",
|
|
111
|
+
"titleUploadComplete_one": "{{count}} file uploaded",
|
|
112
|
+
"titleUploadComplete_other": "{{count}} files uploaded",
|
|
113
|
+
"titleDownloadComplete_one": "{{count}} model ready",
|
|
114
|
+
"titleDownloadComplete_other": "{{count}} models ready",
|
|
115
|
+
"titleComplete_one": "{{count}} transfer complete",
|
|
116
|
+
"titleComplete_other": "{{count}} transfers complete",
|
|
117
|
+
"titleFailed_one": "{{count}} transfer failed",
|
|
118
|
+
"titleFailed_other": "{{count}} transfers failed",
|
|
119
|
+
"titleMixed": "{{success}} complete, {{errors}} failed",
|
|
120
|
+
"titleCancelled_one": "{{count}} transfer cancelled",
|
|
121
|
+
"titleCancelled_other": "{{count}} transfers cancelled",
|
|
122
|
+
"bytesProgress": "{{transferred}} of {{total}}",
|
|
123
|
+
"itemsProgress": "{{done}} of {{total}} done",
|
|
124
|
+
"progressPercent": "{{percent}}%",
|
|
125
|
+
"errorCount_one": "{{count}} error",
|
|
126
|
+
"errorCount_other": "{{count}} errors",
|
|
127
|
+
"cancelledCount_one": "{{count}} cancelled",
|
|
128
|
+
"cancelledCount_other": "{{count}} cancelled",
|
|
129
|
+
"expand": "Show details",
|
|
130
|
+
"collapse": "Hide details",
|
|
131
|
+
"dismiss": "Dismiss",
|
|
132
|
+
"closeAndCancel": "Cancel remaining transfers and close",
|
|
133
|
+
"cancelItem": "Cancel",
|
|
134
|
+
"removeItem": "Remove",
|
|
135
|
+
"cancelAll": "Cancel all",
|
|
136
|
+
"statusUploading": "Uploading",
|
|
137
|
+
"statusDownloading": "Downloading",
|
|
138
|
+
"statusUploadComplete": "Uploaded",
|
|
139
|
+
"statusDownloadComplete": "Ready",
|
|
140
|
+
"statusError": "Failed",
|
|
141
|
+
"statusCancelled": "Cancelled"
|
|
142
|
+
},
|
|
99
143
|
"storagePicker": {
|
|
100
144
|
"title": "Select files or folders",
|
|
101
145
|
"description": "Choose items, then confirm."
|