@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,41 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { shareInFlight, type InFlightSlot } from './shareInFlight';
|
|
3
|
+
|
|
4
|
+
describe('shareInFlight', () => {
|
|
5
|
+
it('runs once and shares the same promise for concurrent callers', async () => {
|
|
6
|
+
const slot: InFlightSlot<string> = { current: null };
|
|
7
|
+
const run = vi.fn(async () => {
|
|
8
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
9
|
+
return 'ok';
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const [a, b] = await Promise.all([shareInFlight(slot, run), shareInFlight(slot, run)]);
|
|
13
|
+
|
|
14
|
+
expect(a).toBe('ok');
|
|
15
|
+
expect(b).toBe('ok');
|
|
16
|
+
expect(run).toHaveBeenCalledTimes(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('allows a new run after the previous promise settles', async () => {
|
|
20
|
+
const slot: InFlightSlot<number> = { current: null };
|
|
21
|
+
const run = vi.fn(async () => 1);
|
|
22
|
+
|
|
23
|
+
await shareInFlight(slot, run);
|
|
24
|
+
await shareInFlight(slot, run);
|
|
25
|
+
|
|
26
|
+
expect(run).toHaveBeenCalledTimes(2);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('clears the slot after rejection so a later caller can retry', async () => {
|
|
30
|
+
const slot: InFlightSlot<string> = { current: null };
|
|
31
|
+
const failing = vi.fn(async () => {
|
|
32
|
+
throw new Error('boom');
|
|
33
|
+
});
|
|
34
|
+
const succeeding = vi.fn(async () => 'recovered');
|
|
35
|
+
|
|
36
|
+
await expect(shareInFlight(slot, failing)).rejects.toThrow('boom');
|
|
37
|
+
await expect(shareInFlight(slot, succeeding)).resolves.toBe('recovered');
|
|
38
|
+
expect(failing).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(succeeding).toHaveBeenCalledTimes(1);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deduplicate concurrent async work so callers share one promise until it settles.
|
|
3
|
+
* Needed for React StrictMode double-mount (refs reset; module slots do not).
|
|
4
|
+
*/
|
|
5
|
+
export type InFlightSlot<T> = { current: Promise<T> | null };
|
|
6
|
+
|
|
7
|
+
export const shareInFlight = <T>(slot: InFlightSlot<T>, run: () => Promise<T>): Promise<T> => {
|
|
8
|
+
if (!slot.current) {
|
|
9
|
+
slot.current = run().finally(() => {
|
|
10
|
+
slot.current = null;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return slot.current;
|
|
14
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext, useState, createElement, type ReactNode } from 'react';
|
|
2
|
-
import { getLogger } from '@shellui/sdk';
|
|
2
|
+
import { getLogger, shellui } from '@shellui/sdk';
|
|
3
3
|
import type { ShellUIConfig } from './types';
|
|
4
4
|
import shelluiConfig from '@shellui/config';
|
|
5
|
+
import { deriveAllowedMessageOrigins } from '../messaging/deriveAllowedMessageOrigins';
|
|
5
6
|
|
|
6
7
|
const logger = getLogger('shellcore');
|
|
7
8
|
|
|
@@ -30,6 +31,13 @@ export function ConfigProvider(props: ConfigProviderProps): ReturnType<typeof cr
|
|
|
30
31
|
if (typeof window !== 'undefined' && __SHELLUI_TARGET__ === 'tauri') {
|
|
31
32
|
(window as Window & { __SHELLUI_TAURI__?: boolean }).__SHELLUI_TAURI__ = true;
|
|
32
33
|
}
|
|
34
|
+
// Allowlist companion origins before any child mounts iframes (avoids dropping
|
|
35
|
+
// early SHELLUI_SETTINGS_REQUESTED from localhost companions).
|
|
36
|
+
if (typeof window !== 'undefined') {
|
|
37
|
+
shellui.configureMessageSecurity({
|
|
38
|
+
allowedOrigins: deriveAllowedMessageOrigins(resolved),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
33
41
|
if (process.env.NODE_ENV === 'development' && !configLogged) {
|
|
34
42
|
configLogged = true;
|
|
35
43
|
logger.info('Config loaded from @shellui/config', {
|
|
@@ -246,6 +246,19 @@ export interface StorageConfig {
|
|
|
246
246
|
showInSettings?: boolean;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/**
|
|
250
|
+
* On-device AI product feature (Ollama + browser / WebLLM).
|
|
251
|
+
* Distinct from the per-user Settings → AI “Allow apps to use AI” toggle.
|
|
252
|
+
*/
|
|
253
|
+
export interface AiConfig {
|
|
254
|
+
/**
|
|
255
|
+
* Deploy-time opt-in for the whole AI feature. Default: false.
|
|
256
|
+
* Only `true` enables it. Otherwise: no AiBridge, no Settings → AI, SDK AI calls answer
|
|
257
|
+
* `unavailable`, and no WebLLM chunk/worker is loaded. Opt in with `"ai": { "enabled": true }`.
|
|
258
|
+
*/
|
|
259
|
+
enabled?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
249
262
|
/**
|
|
250
263
|
* Optional hosting-service wiring for `shellui deploy` preview uploads.
|
|
251
264
|
* Preview sites expire after 7 days unless redeployed to the same slug.
|
|
@@ -272,6 +285,24 @@ export interface HostingConfig {
|
|
|
272
285
|
showInAdmin?: boolean;
|
|
273
286
|
}
|
|
274
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Optional email-service wiring for Admin → Email and iframe apps.
|
|
290
|
+
* When `email` is set and `url` is omitted, the shell uses `https://email.shellui.com`.
|
|
291
|
+
*/
|
|
292
|
+
export interface EmailConfig {
|
|
293
|
+
/**
|
|
294
|
+
* Base URL of email-service.
|
|
295
|
+
* Default: `https://email.shellui.com` when `email` is set and this is omitted.
|
|
296
|
+
* Local: `http://localhost:8003`.
|
|
297
|
+
*/
|
|
298
|
+
url?: string;
|
|
299
|
+
/**
|
|
300
|
+
* When false, hide Admin → Email.
|
|
301
|
+
* Default: true (shown) when `email` is set.
|
|
302
|
+
*/
|
|
303
|
+
showInAdmin?: boolean;
|
|
304
|
+
}
|
|
305
|
+
|
|
275
306
|
/**
|
|
276
307
|
* Custom navigation section for the staff administration panel.
|
|
277
308
|
* Admin app URL remains `backend.adminUrl` / `backend.adminPathname`.
|
|
@@ -333,11 +364,23 @@ export interface ShellUIConfig {
|
|
|
333
364
|
* when `url` is set unless `storage.showInSettings` is false.
|
|
334
365
|
*/
|
|
335
366
|
storage?: StorageConfig;
|
|
367
|
+
/**
|
|
368
|
+
* On-device AI (Ollama + browser WebLLM). Disabled by default; set `enabled: true` to
|
|
369
|
+
* show Settings → AI and accept SDK AI calls. `@mlc-ai/web-llm` is never loaded otherwise.
|
|
370
|
+
* See docs/features/ai.md. Distinct from Settings → AI “Allow apps to use AI”.
|
|
371
|
+
*/
|
|
372
|
+
ai?: AiConfig;
|
|
336
373
|
/**
|
|
337
374
|
* Hosting-service connection. Propagated to iframes via SDK settings.
|
|
338
375
|
* Enables `shellui deploy` when `url` is set.
|
|
339
376
|
*/
|
|
340
377
|
hosting?: HostingConfig;
|
|
378
|
+
/**
|
|
379
|
+
* Email-service connection. Propagated to iframes via SDK settings.
|
|
380
|
+
* When `email` is set and `url` is omitted, the shell sends `https://email.shellui.com`.
|
|
381
|
+
* `showInAdmin: false` hides Admin → Email.
|
|
382
|
+
*/
|
|
383
|
+
email?: EmailConfig;
|
|
341
384
|
/**
|
|
342
385
|
* Single theme: built-in name, path to a theme JSON/folder, or inline theme object.
|
|
343
386
|
* When set without `themes`, only this theme is available in the selector.
|
|
@@ -751,7 +751,7 @@ export function AppBarLayout({
|
|
|
751
751
|
variant = 'app-bar',
|
|
752
752
|
}: AppBarLayoutProps) {
|
|
753
753
|
const { i18n } = useTranslation();
|
|
754
|
-
const { isAuthenticated } = useAuth();
|
|
754
|
+
const { isAuthenticated, isLoading: isAuthLoading } = useAuth();
|
|
755
755
|
const { settings } = useSettings();
|
|
756
756
|
const location = useLocation();
|
|
757
757
|
const isMobile = useIsMobile();
|
|
@@ -772,8 +772,13 @@ export function AppBarLayout({
|
|
|
772
772
|
});
|
|
773
773
|
const authAwareNavigation = useMemo(
|
|
774
774
|
() =>
|
|
775
|
-
filterNavigationForAuthState(
|
|
776
|
-
|
|
775
|
+
filterNavigationForAuthState(
|
|
776
|
+
navigation,
|
|
777
|
+
isAuthenticated,
|
|
778
|
+
settings.developerFeatures.enabled,
|
|
779
|
+
isAuthLoading,
|
|
780
|
+
),
|
|
781
|
+
[navigation, isAuthenticated, settings.developerFeatures.enabled, isAuthLoading],
|
|
777
782
|
);
|
|
778
783
|
|
|
779
784
|
const { endNavItems, navigationItems, startSections, activePathPrefix } = useMemo(() => {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { NavigationGroup, NavigationItem } from '../config/types';
|
|
3
|
+
import { filterNavigationForAuthState } from './utils';
|
|
4
|
+
|
|
5
|
+
const home: NavigationItem = { label: 'Home', path: '', url: 'http://localhost:5173/' };
|
|
6
|
+
const login: NavigationItem = { label: 'Sign in', path: 'sign-in', url: '/login' };
|
|
7
|
+
const dashboard: NavigationItem = {
|
|
8
|
+
label: 'Dashboard',
|
|
9
|
+
path: 'dashboard',
|
|
10
|
+
url: 'http://localhost:5173/dashboard',
|
|
11
|
+
hideWhenLoggedOut: true,
|
|
12
|
+
};
|
|
13
|
+
const accountGroup: NavigationGroup = { title: 'Account', items: [login, dashboard] };
|
|
14
|
+
|
|
15
|
+
const paths = (navigation: (NavigationItem | NavigationGroup)[]) =>
|
|
16
|
+
navigation.flatMap((item) =>
|
|
17
|
+
'items' in item ? item.items.map((navItem) => navItem.path) : [item.path],
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
describe('filterNavigationForAuthState', () => {
|
|
21
|
+
it('shows login entries and hides logged-in entries when signed out', () => {
|
|
22
|
+
expect(paths(filterNavigationForAuthState([home, login, dashboard], false))).toEqual([
|
|
23
|
+
'',
|
|
24
|
+
'sign-in',
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('hides login entries when signed in', () => {
|
|
29
|
+
expect(paths(filterNavigationForAuthState([home, login, dashboard], true))).toEqual([
|
|
30
|
+
'',
|
|
31
|
+
'dashboard',
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('hides login and logged-in entries while the session restore is loading', () => {
|
|
36
|
+
expect(
|
|
37
|
+
paths(filterNavigationForAuthState([home, login, dashboard], false, false, true)),
|
|
38
|
+
).toEqual(['']);
|
|
39
|
+
expect(filterNavigationForAuthState([accountGroup], false, false, true)).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -41,7 +41,7 @@ export interface FloatingLayoutProps {
|
|
|
41
41
|
/** Adaptive layout: floating glass chrome over full-bleed content (tabs/dock + sidebar). */
|
|
42
42
|
export function FloatingLayout({ title, appIcon, navigation = [] }: FloatingLayoutProps) {
|
|
43
43
|
const { i18n } = useTranslation();
|
|
44
|
-
const { isAuthenticated } = useAuth();
|
|
44
|
+
const { isAuthenticated, isLoading: isAuthLoading } = useAuth();
|
|
45
45
|
const { settings } = useSettings();
|
|
46
46
|
const { navigationItem } = useNavigationItems();
|
|
47
47
|
const viewport = useViewport();
|
|
@@ -52,12 +52,17 @@ export function FloatingLayout({ title, appIcon, navigation = [] }: FloatingLayo
|
|
|
52
52
|
|
|
53
53
|
const hasCustomLoginNav = useMemo(() => hasLoginNavigationItem(navigation), [navigation]);
|
|
54
54
|
// Same rule as sidebar / app-bar: show account menu when logged in (login nav item is filtered out).
|
|
55
|
-
const showAuthButton = !hasCustomLoginNav || isAuthenticated;
|
|
55
|
+
const showAuthButton = !hasCustomLoginNav || isAuthenticated || isAuthLoading;
|
|
56
56
|
|
|
57
57
|
const authAwareNavigation = useMemo(
|
|
58
58
|
() =>
|
|
59
|
-
filterNavigationForAuthState(
|
|
60
|
-
|
|
59
|
+
filterNavigationForAuthState(
|
|
60
|
+
navigation,
|
|
61
|
+
isAuthenticated,
|
|
62
|
+
settings.developerFeatures.enabled,
|
|
63
|
+
isAuthLoading,
|
|
64
|
+
),
|
|
65
|
+
[navigation, isAuthenticated, settings.developerFeatures.enabled, isAuthLoading],
|
|
61
66
|
);
|
|
62
67
|
|
|
63
68
|
const { startNav, endItems } = useMemo(() => {
|
|
@@ -94,7 +94,7 @@ const SidebarLayoutContent = ({
|
|
|
94
94
|
}: SidebarLayoutProps) => {
|
|
95
95
|
const { i18n } = useTranslation();
|
|
96
96
|
const location = useLocation();
|
|
97
|
-
const { isAuthenticated } = useAuth();
|
|
97
|
+
const { isAuthenticated, isLoading: isAuthLoading } = useAuth();
|
|
98
98
|
const { settings } = useSettings();
|
|
99
99
|
const { navigationItem } = useNavigationItems();
|
|
100
100
|
const isMobile = useIsMobile();
|
|
@@ -140,8 +140,13 @@ const SidebarLayoutContent = ({
|
|
|
140
140
|
const hasCustomLoginNav = useMemo(() => hasLoginNavigationItem(navigation), [navigation]);
|
|
141
141
|
const authAwareNavigation = useMemo(
|
|
142
142
|
() =>
|
|
143
|
-
filterNavigationForAuthState(
|
|
144
|
-
|
|
143
|
+
filterNavigationForAuthState(
|
|
144
|
+
navigation,
|
|
145
|
+
isAuthenticated,
|
|
146
|
+
settings.developerFeatures.enabled,
|
|
147
|
+
isAuthLoading,
|
|
148
|
+
),
|
|
149
|
+
[navigation, isAuthenticated, settings.developerFeatures.enabled, isAuthLoading],
|
|
145
150
|
);
|
|
146
151
|
const { startNav, endItems } = useMemo(() => {
|
|
147
152
|
const viewportNav = filterNavigationByViewport(
|
|
@@ -203,7 +208,7 @@ const SidebarLayoutContent = ({
|
|
|
203
208
|
<SidebarInner
|
|
204
209
|
startNav={startNav}
|
|
205
210
|
endItems={endItems}
|
|
206
|
-
showAuthButton={!hasCustomLoginNav || isAuthenticated}
|
|
211
|
+
showAuthButton={!hasCustomLoginNav || isAuthenticated || isAuthLoading}
|
|
207
212
|
title={title}
|
|
208
213
|
appIcon={appIcon}
|
|
209
214
|
/>
|
|
@@ -226,13 +226,17 @@ export function hasLoginNavigationItem(navigation: (NavigationItem | NavigationG
|
|
|
226
226
|
/**
|
|
227
227
|
* Hide login navigation entries only when authenticated, so custom login entries
|
|
228
228
|
* can still be used while signed out (e.g. open login in modal/drawer).
|
|
229
|
+
* While the initial session restore runs (`isAuthLoading`), login entries are hidden too:
|
|
230
|
+
* the account skeleton takes their place until the auth state is known.
|
|
229
231
|
*/
|
|
230
232
|
export function filterNavigationForAuthState(
|
|
231
233
|
navigation: (NavigationItem | NavigationGroup)[],
|
|
232
234
|
isAuthenticated: boolean,
|
|
233
235
|
isDevModeEnabled = false,
|
|
236
|
+
isAuthLoading = false,
|
|
234
237
|
): (NavigationItem | NavigationGroup)[] {
|
|
235
238
|
if (navigation.length === 0) return navigation;
|
|
239
|
+
const hideLoginEntries = isAuthenticated || isAuthLoading;
|
|
236
240
|
return navigation
|
|
237
241
|
.map((item) => {
|
|
238
242
|
if ('title' in item && 'items' in item) {
|
|
@@ -240,7 +244,7 @@ export function filterNavigationForAuthState(
|
|
|
240
244
|
const visibleItems = group.items.filter((navItem) => {
|
|
241
245
|
if (navItem.hideWhenLoggedOut && !isAuthenticated) return false;
|
|
242
246
|
if (navItem.requiresDevMode && !isDevModeEnabled) return false;
|
|
243
|
-
if (
|
|
247
|
+
if (hideLoginEntries && isLoginNavigationUrl(navItem.url)) return false;
|
|
244
248
|
return true;
|
|
245
249
|
});
|
|
246
250
|
if (visibleItems.length === 0) return null;
|
|
@@ -249,7 +253,7 @@ export function filterNavigationForAuthState(
|
|
|
249
253
|
const navItem = item as NavigationItem;
|
|
250
254
|
if (navItem.hideWhenLoggedOut && !isAuthenticated) return null;
|
|
251
255
|
if (navItem.requiresDevMode && !isDevModeEnabled) return null;
|
|
252
|
-
if (
|
|
256
|
+
if (hideLoginEntries && isLoginNavigationUrl(navItem.url)) return null;
|
|
253
257
|
return item;
|
|
254
258
|
})
|
|
255
259
|
.filter((item): item is NavigationItem | NavigationGroup => item !== null);
|
|
@@ -727,7 +727,7 @@ function getBrowserTimezone(): string {
|
|
|
727
727
|
export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: WindowsLayoutProps) {
|
|
728
728
|
const location = useLocation();
|
|
729
729
|
const { i18n } = useTranslation();
|
|
730
|
-
const { isAuthenticated } = useAuth();
|
|
730
|
+
const { isAuthenticated, isLoading: isAuthLoading } = useAuth();
|
|
731
731
|
const { settings } = useSettings();
|
|
732
732
|
/** Fullscreen phone chrome — includes iPhone landscape (wide but short). */
|
|
733
733
|
const phoneMode = useWindowsPhoneMode();
|
|
@@ -735,8 +735,13 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
735
735
|
const hasCustomLoginNav = useMemo(() => hasLoginNavigationItem(navigation), [navigation]);
|
|
736
736
|
const authAwareNavigation = useMemo(
|
|
737
737
|
() =>
|
|
738
|
-
filterNavigationForAuthState(
|
|
739
|
-
|
|
738
|
+
filterNavigationForAuthState(
|
|
739
|
+
navigation,
|
|
740
|
+
isAuthenticated,
|
|
741
|
+
settings.developerFeatures.enabled,
|
|
742
|
+
isAuthLoading,
|
|
743
|
+
),
|
|
744
|
+
[navigation, isAuthenticated, settings.developerFeatures.enabled, isAuthLoading],
|
|
740
745
|
);
|
|
741
746
|
const timeZone = settings.region?.timezone ?? getBrowserTimezone();
|
|
742
747
|
const { startSections, endNavItems, navigationItems } = useMemo(() => {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
1
|
import { shellui } from '@shellui/sdk';
|
|
3
2
|
import { useConfig } from '../config/useConfig';
|
|
4
3
|
import { deriveAllowedMessageOrigins } from './deriveAllowedMessageOrigins';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Applies config-derived companion origins to the SDK message security policy.
|
|
7
|
+
*
|
|
8
|
+
* Must run during render (not a late `useEffect`) so localhost companions are
|
|
9
|
+
* allowlisted before ContentView iframes can send privileged postMessages.
|
|
8
10
|
*/
|
|
9
11
|
export function MessagingSecurityBootstrap() {
|
|
10
12
|
const { config } = useConfig();
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}, [config]);
|
|
14
|
+
shellui.configureMessageSecurity({
|
|
15
|
+
allowedOrigins: deriveAllowedMessageOrigins(config),
|
|
16
|
+
});
|
|
17
17
|
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
@@ -1,12 +1,57 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import type { ShellUIConfig } from '../config/types';
|
|
3
3
|
import {
|
|
4
|
+
getAiRequestTrustDenial,
|
|
4
5
|
getStorageRequestTrustDenial,
|
|
5
6
|
isRegisteredTrustedFrame,
|
|
7
|
+
isShellSettingsFrameMessage,
|
|
6
8
|
isTrustedFrameForAuthToken,
|
|
7
9
|
resolveRegisteredFrameSrc,
|
|
8
10
|
} from './trustedFrames';
|
|
9
11
|
|
|
12
|
+
describe('isShellSettingsFrameMessage', () => {
|
|
13
|
+
const shellOrigin = 'http://localhost:4000';
|
|
14
|
+
const registry = (entries: Array<[string, string]>) => ({
|
|
15
|
+
getAllIframes: () =>
|
|
16
|
+
entries.map(
|
|
17
|
+
([uuid, src]) => [uuid, { src } as HTMLIFrameElement] as [string, HTMLIFrameElement],
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('accepts messages from the shell window itself', () => {
|
|
22
|
+
expect(isShellSettingsFrameMessage([], registry([]), '/__settings', shellOrigin)).toBe(true);
|
|
23
|
+
expect(isShellSettingsFrameMessage(undefined, registry([]), '/__settings', shellOrigin)).toBe(
|
|
24
|
+
true,
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('accepts a direct same-origin settings frame', () => {
|
|
29
|
+
const frames = registry([['f1', `${shellOrigin}/__settings/user`]]);
|
|
30
|
+
expect(isShellSettingsFrameMessage(['f1'], frames, '/__settings', shellOrigin)).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('rejects messages relayed from nested frames', () => {
|
|
34
|
+
const frames = registry([['f1', `${shellOrigin}/__settings/user`]]);
|
|
35
|
+
expect(isShellSettingsFrameMessage(['f1', 'nested'], frames, '/__settings', shellOrigin)).toBe(
|
|
36
|
+
false,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('rejects non-settings or cross-origin frames', () => {
|
|
41
|
+
const frames = registry([
|
|
42
|
+
['app', `${shellOrigin}/apps/billing`],
|
|
43
|
+
['evil', 'http://evil.test/__settings/user'],
|
|
44
|
+
['prefix', `${shellOrigin}/__settings-fake/user`],
|
|
45
|
+
]);
|
|
46
|
+
expect(isShellSettingsFrameMessage(['app'], frames, '/__settings', shellOrigin)).toBe(false);
|
|
47
|
+
expect(isShellSettingsFrameMessage(['evil'], frames, '/__settings', shellOrigin)).toBe(false);
|
|
48
|
+
expect(isShellSettingsFrameMessage(['prefix'], frames, '/__settings', shellOrigin)).toBe(false);
|
|
49
|
+
expect(isShellSettingsFrameMessage(['unknown'], frames, '/__settings', shellOrigin)).toBe(
|
|
50
|
+
false,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
10
55
|
const config = {
|
|
11
56
|
navigation: [
|
|
12
57
|
{
|
|
@@ -127,3 +172,23 @@ describe('getStorageRequestTrustDenial', () => {
|
|
|
127
172
|
});
|
|
128
173
|
});
|
|
129
174
|
});
|
|
175
|
+
|
|
176
|
+
describe('getAiRequestTrustDenial', () => {
|
|
177
|
+
it('allows trusted companion frames', () => {
|
|
178
|
+
expect(getAiRequestTrustDenial(['trusted-uuid'], registry, config)).toBeNull();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('denies default (non-opt-in) companion frames', () => {
|
|
182
|
+
expect(getAiRequestTrustDenial(['default-uuid'], registry, config)).toEqual({
|
|
183
|
+
message: 'AI request rejected: untrusted frame',
|
|
184
|
+
code: 'untrusted_frame',
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('denies unregistered senders', () => {
|
|
189
|
+
expect(getAiRequestTrustDenial(['missing-uuid'], registry, config)).toEqual({
|
|
190
|
+
message: 'AI request rejected: untrusted frame',
|
|
191
|
+
code: 'untrusted_frame',
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -60,6 +60,40 @@ export function isRegisteredTrustedFrame(frameSrc: string | null, config?: Shell
|
|
|
60
60
|
return Boolean(frameSrc && isTrustedFrameForAuthToken(frameSrc, config));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Whether a message came from the shell window itself or directly from a shell-owned
|
|
65
|
+
* frame under `settingsPath` (e.g. the user settings modal). Messages relayed through
|
|
66
|
+
* a nested frame (more than one hop) are rejected, so embedded apps cannot trigger
|
|
67
|
+
* account-level actions.
|
|
68
|
+
*/
|
|
69
|
+
export function isShellSettingsFrameMessage(
|
|
70
|
+
from: string[] | undefined,
|
|
71
|
+
frameRegistry: FrameRegistryLike,
|
|
72
|
+
settingsPath: string,
|
|
73
|
+
shellOrigin: string,
|
|
74
|
+
): boolean {
|
|
75
|
+
const hops = (from ?? []).filter(Boolean);
|
|
76
|
+
if (hops.length === 0) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (hops.length !== 1) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const frameSrc = resolveRegisteredFrameSrc(hops, frameRegistry);
|
|
83
|
+
if (!frameSrc) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const url = new URL(frameSrc, shellOrigin);
|
|
88
|
+
const base = `/${settingsPath.replace(/^\/+|\/+$/g, '')}`;
|
|
89
|
+
return (
|
|
90
|
+
url.origin === shellOrigin && (url.pathname === base || url.pathname.startsWith(`${base}/`))
|
|
91
|
+
);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
63
97
|
export type StorageTrustDenial = { message: string; status: 403 };
|
|
64
98
|
|
|
65
99
|
/**
|
|
@@ -77,3 +111,21 @@ export function getStorageRequestTrustDenial(
|
|
|
77
111
|
}
|
|
78
112
|
return null;
|
|
79
113
|
}
|
|
114
|
+
|
|
115
|
+
export type AiTrustDenial = { message: string; code: 'untrusted_frame' };
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns an AI error when the request sender is missing from the frame
|
|
119
|
+
* registry or fails the trusted-frame policy (same opt-in as JWT / storage).
|
|
120
|
+
*/
|
|
121
|
+
export function getAiRequestTrustDenial(
|
|
122
|
+
from: string[] | undefined,
|
|
123
|
+
frameRegistry: FrameRegistryLike,
|
|
124
|
+
config?: ShellUIConfig,
|
|
125
|
+
): AiTrustDenial | null {
|
|
126
|
+
const frameSrc = resolveRegisteredFrameSrc(from, frameRegistry);
|
|
127
|
+
if (!isRegisteredTrustedFrame(frameSrc, config)) {
|
|
128
|
+
return { message: 'AI request rejected: untrusted frame', code: 'untrusted_frame' };
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
@@ -376,6 +376,23 @@ export const HardDriveIcon = () => (
|
|
|
376
376
|
</svg>
|
|
377
377
|
);
|
|
378
378
|
|
|
379
|
+
export const SparklesIcon = () => (
|
|
380
|
+
<svg
|
|
381
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
382
|
+
width="16"
|
|
383
|
+
height="16"
|
|
384
|
+
viewBox="0 0 24 24"
|
|
385
|
+
fill="none"
|
|
386
|
+
stroke="currentColor"
|
|
387
|
+
strokeWidth="2"
|
|
388
|
+
strokeLinecap="round"
|
|
389
|
+
strokeLinejoin="round"
|
|
390
|
+
>
|
|
391
|
+
<path d="M12 3l1.5 5.5L19 10l-5.5 1.5L12 17l-1.5-5.5L5 10l5.5-1.5L12 3z" />
|
|
392
|
+
<path d="M19 15l.75 2.25L22 18l-2.25.75L19 21l-.75-2.25L16 18l2.25-.75L19 15z" />
|
|
393
|
+
</svg>
|
|
394
|
+
);
|
|
395
|
+
|
|
379
396
|
export const RefreshCwIcon = () => (
|
|
380
397
|
<svg
|
|
381
398
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useRef,
|
|
3
|
+
useState,
|
|
4
|
+
useEffect,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useMemo,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from 'react';
|
|
2
10
|
import {
|
|
3
11
|
getLogger,
|
|
4
12
|
shellui,
|
|
@@ -71,6 +79,12 @@ const defaultSettings: Settings = {
|
|
|
71
79
|
serviceWorker: {
|
|
72
80
|
enabled: false,
|
|
73
81
|
},
|
|
82
|
+
ai: {
|
|
83
|
+
enabled: true,
|
|
84
|
+
defaultModelId: null,
|
|
85
|
+
ollamaEnabled: true,
|
|
86
|
+
browserEnabled: true,
|
|
87
|
+
},
|
|
74
88
|
user: null,
|
|
75
89
|
accessToken: null,
|
|
76
90
|
};
|
|
@@ -151,6 +165,16 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
151
165
|
// Migrate from legacy "caching" key if present; default off for new installs
|
|
152
166
|
enabled: parsed.serviceWorker?.enabled ?? parsed.caching?.enabled ?? false,
|
|
153
167
|
},
|
|
168
|
+
ai: {
|
|
169
|
+
enabled: parsed.ai?.enabled ?? defaultSettings.ai.enabled,
|
|
170
|
+
defaultModelId:
|
|
171
|
+
parsed.ai?.defaultModelId !== undefined
|
|
172
|
+
? parsed.ai.defaultModelId
|
|
173
|
+
: defaultSettings.ai.defaultModelId,
|
|
174
|
+
ollamaEnabled: parsed.ai?.ollamaEnabled ?? defaultSettings.ai.ollamaEnabled,
|
|
175
|
+
browserEnabled: parsed.ai?.browserEnabled ?? defaultSettings.ai.browserEnabled,
|
|
176
|
+
ollamaBaseUrl: parsed.ai?.ollamaBaseUrl ?? defaultSettings.ai.ollamaBaseUrl,
|
|
177
|
+
},
|
|
154
178
|
user: parsed.user ?? null,
|
|
155
179
|
accessToken: null,
|
|
156
180
|
};
|
|
@@ -388,8 +412,9 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
388
412
|
}
|
|
389
413
|
}, [authUser, config]);
|
|
390
414
|
|
|
391
|
-
// Listen for settings updates from parent/other nodes
|
|
392
|
-
|
|
415
|
+
// Listen for settings updates from parent/other nodes.
|
|
416
|
+
// useLayoutEffect so SETTINGS_REQUESTED handlers exist before companion paint races.
|
|
417
|
+
useLayoutEffect(() => {
|
|
393
418
|
if (typeof window === 'undefined') {
|
|
394
419
|
return;
|
|
395
420
|
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
PackageIcon,
|
|
9
9
|
RefreshDoubleIcon,
|
|
10
10
|
HardDriveIcon,
|
|
11
|
+
SparklesIcon,
|
|
11
12
|
} from './SettingsIcons';
|
|
12
13
|
import { Appearance } from './components/Appearance';
|
|
13
14
|
import { LanguageAndRegion } from './components/LanguageAndRegion';
|
|
@@ -18,6 +19,7 @@ import { DataPrivacy } from './components/DataPrivacy';
|
|
|
18
19
|
import { ServiceWorker } from './components/ServiceWorker';
|
|
19
20
|
import { LegalDocumentsPanel } from './components/LegalDocumentsPanel';
|
|
20
21
|
import { Storage } from './components/Storage';
|
|
22
|
+
import { Ai } from './components/Ai';
|
|
21
23
|
import { isTauri } from '../../service-worker/register';
|
|
22
24
|
|
|
23
25
|
export const createSettingsRoutes = (t: (key: string) => string) => [
|
|
@@ -39,6 +41,12 @@ export const createSettingsRoutes = (t: (key: string) => string) => [
|
|
|
39
41
|
path: 'data-privacy',
|
|
40
42
|
element: <DataPrivacy />,
|
|
41
43
|
},
|
|
44
|
+
{
|
|
45
|
+
name: t('routes.ai'),
|
|
46
|
+
icon: SparklesIcon,
|
|
47
|
+
path: 'ai',
|
|
48
|
+
element: <Ai />,
|
|
49
|
+
},
|
|
42
50
|
{
|
|
43
51
|
name: t('routes.storage'),
|
|
44
52
|
icon: HardDriveIcon,
|