@shellui/core 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/README.md +1 -1
  2. package/package.json +29 -29
  3. package/schemas/shellui.config.schema.json +4 -0
  4. package/src/components/contentIframeSandbox.spec.ts +51 -8
  5. package/src/components/contentIframeSandbox.ts +60 -19
  6. package/src/features/auth/appBackend/childFrames.ts +3 -8
  7. package/src/features/auth/appBackend/identity.ts +1 -3
  8. package/src/features/auth/appBackend/silentSignIn.ts +1 -2
  9. package/src/features/auth/appBackend/tokenExchange.ts +1 -2
  10. package/src/features/auth/shellAccountRequests.ts +1 -2
  11. package/src/features/config/types.ts +12 -11
  12. package/src/features/layouts/floating/FloatingSidebar.tsx +1 -2
  13. package/src/features/legal/legalDocuments.ts +1 -4
  14. package/src/features/mcp/mcpAgentActivityPresentation.ts +1 -2
  15. package/src/features/mcp/mcpAgentsConnect.spec.ts +62 -0
  16. package/src/features/mcp/mcpAgentsConnect.ts +49 -0
  17. package/src/features/mcp/personalAgentsApi.ts +1 -6
  18. package/src/features/security/trustedFrames.spec.ts +44 -0
  19. package/src/features/security/trustedFrames.ts +35 -0
  20. package/src/features/settings/SettingsProvider.spec.tsx +167 -0
  21. package/src/features/settings/SettingsProvider.tsx +17 -0
  22. package/src/features/settings/components/McpAgents.spec.tsx +31 -2
  23. package/src/features/settings/components/McpAgents.tsx +11 -3
  24. package/src/features/settings/components/McpPendingApprovals.tsx +147 -136
  25. package/src/features/sonner/SonnerContext.tsx +1 -6
  26. package/src/features/storage/uploads/handleTrackedUpload.spec.ts +1 -2
  27. package/src/routes/utils/navigationRouteAccess.ts +1 -4
package/README.md CHANGED
@@ -6,7 +6,7 @@ React runtime for Shellui, the open-source app shell: navigation, layouts, light
6
6
  npm install @shellui/core
7
7
  ```
8
8
 
9
- Shellui **0.8.1** is the current stable release: `npm install @shellui/core@0.8.1`.
9
+ Shellui **0.8.3** is the current stable release: `npm install @shellui/core@0.8.3`.
10
10
 
11
11
  ```typescript
12
12
  import type { ShellUIConfig } from '@shellui/core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "React runtime for Shellui, the open-source app shell. Renders navigation, layouts, themes with light and dark modes, sign-in and identity, and hosts your apps as micro frontends in one interface. MIT licensed.",
5
5
  "homepage": "https://shellui.com",
6
6
  "repository": {
@@ -61,36 +61,36 @@
61
61
  "author": "Shellui",
62
62
  "license": "MIT",
63
63
  "dependencies": {
64
- "@mlc-ai/web-llm": "0.2.85",
65
- "@radix-ui/react-alert-dialog": "^1.1.15",
66
- "@radix-ui/react-collapsible": "^1.1.12",
67
- "@radix-ui/react-dialog": "^1.1.15",
68
- "@radix-ui/react-dropdown-menu": "^2.1.16",
69
- "@radix-ui/react-separator": "^1.1.8",
70
- "@radix-ui/react-slot": "^1.2.4",
71
- "@radix-ui/react-tabs": "^1.1.21",
72
- "@radix-ui/react-tooltip": "^1.2.8",
64
+ "@mlc-ai/web-llm": "0.2.88",
65
+ "@radix-ui/react-alert-dialog": "^1.2.1",
66
+ "@radix-ui/react-collapsible": "^1.2.1",
67
+ "@radix-ui/react-dialog": "^1.3.1",
68
+ "@radix-ui/react-dropdown-menu": "^2.2.1",
69
+ "@radix-ui/react-separator": "^1.2.0",
70
+ "@radix-ui/react-slot": "^1.5.0",
71
+ "@radix-ui/react-tabs": "^1.2.1",
72
+ "@radix-ui/react-tooltip": "^1.4.1",
73
73
  "@sentry/react": "^10.39.0",
74
- "@supabase/supabase-js": "^2.99.3",
74
+ "@supabase/supabase-js": "^2.119.0",
75
75
  "class-variance-authority": "^0.7.1",
76
76
  "clsx": "^2.1.1",
77
77
  "i18next": "^25.8.11",
78
78
  "react-i18next": "^16.5.4",
79
- "react-icons": "^5.6.0",
79
+ "react-icons": "^5.7.0",
80
80
  "react-markdown": "^10.1.0",
81
81
  "react-router": "^7.18.4",
82
- "roarr": "^7.21.4",
83
- "sonner": "^2.0.7",
84
- "tailwind-merge": "^3.5.0",
85
- "tailwindcss": "^4.2.0",
82
+ "roarr": "^7.21.7",
83
+ "sonner": "^2.0.8",
84
+ "tailwind-merge": "^3.7.0",
85
+ "tailwindcss": "^4.3.5",
86
86
  "vaul": "^1.1.2",
87
- "workbox-cacheable-response": "^7.4.0",
88
- "workbox-expiration": "^7.4.0",
89
- "workbox-precaching": "^7.4.0",
90
- "workbox-routing": "^7.4.0",
91
- "workbox-strategies": "^7.4.0",
92
- "workbox-window": "^7.4.0",
93
- "@shellui/sdk": "0.8.1"
87
+ "workbox-cacheable-response": "^7.4.1",
88
+ "workbox-expiration": "^7.4.1",
89
+ "workbox-precaching": "^7.4.1",
90
+ "workbox-routing": "^7.4.1",
91
+ "workbox-strategies": "^7.4.1",
92
+ "workbox-window": "^7.4.1",
93
+ "@shellui/sdk": "0.8.3"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "react": "^18.0.0 || ^19.0.0",
@@ -100,16 +100,16 @@
100
100
  "access": "public"
101
101
  },
102
102
  "devDependencies": {
103
- "@tailwindcss/typography": "^0.5.19",
104
- "@types/react": "^19.2.14",
105
- "@types/react-dom": "^19.2.3",
103
+ "@tailwindcss/typography": "^0.5.20",
104
+ "@types/react": "^19.3.0",
105
+ "@types/react-dom": "^19.3.0",
106
106
  "happy-dom": "^21.0.4",
107
- "react": "^19.2.4",
108
- "react-dom": "^19.2.4",
107
+ "react": "^19.3.1",
108
+ "react-dom": "^19.3.1",
109
109
  "tailwindcss-animate": "^1.0.7",
110
110
  "ts-json-schema-generator": "^2.9.0",
111
111
  "typescript": "^5.9.3",
112
- "vitest": "^4.1.12"
112
+ "vitest": "^5.1.0"
113
113
  },
114
114
  "scripts": {
115
115
  "test": "node scripts/test.js",
@@ -407,6 +407,10 @@
407
407
  "type": "string",
408
408
  "description": "Base URL of ai-service. Required for apps to get AI. There is no built-in default. Local: `http://localhost:8006`."
409
409
  },
410
+ "mcpUrl": {
411
+ "type": "string",
412
+ "description": "Full Shellui account MCP URL. Path must be exactly `/mcp`. When set, Settings shows this URL for MCP / AI agents, even if `backend.companyId` is also set. Use it for the global MCP (saas tools), for example `https://ai.example/mcp`. Omit it in a regional project so Settings can use `{url}/c/{companyId}/mcp`."
413
+ },
410
414
  "showInAdmin": {
411
415
  "type": "boolean",
412
416
  "description": "When false, hide Admin → AI. Default: true (shown) when `aiService` is set."
@@ -1,25 +1,68 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { LEGACY_POPUP_ESCAPE_TOKEN, resolveContentIframeSandbox } from './contentIframeSandbox';
1
+ import { afterEach, describe, expect, test, vi } from 'vitest';
2
+ import {
3
+ LEGACY_POPUP_ESCAPE_TOKEN,
4
+ resetContentIframeSandboxWarnings,
5
+ resolveContentIframeSandbox,
6
+ } from './contentIframeSandbox';
7
+
8
+ const WITH_ORIGIN = ['allow-forms', 'allow-popups', 'allow-same-origin', 'allow-scripts'];
9
+ const OPAQUE = ['allow-forms', 'allow-popups', 'allow-scripts'];
3
10
 
4
11
  describe('resolveContentIframeSandbox', () => {
5
- test('uses tightened sandbox without popup escape', () => {
12
+ afterEach(() => {
13
+ resetContentIframeSandboxWarnings();
14
+ vi.restoreAllMocks();
15
+ });
16
+
17
+ test('keeps allow-same-origin for a cross-origin dev companion', () => {
18
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
6
19
  const sandbox = resolveContentIframeSandbox('http://localhost:5173/', 'http://localhost:4000');
7
20
  expect(sandbox).toContain('allow-scripts');
8
21
  expect(sandbox).toContain('allow-same-origin');
9
22
  expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
23
+ expect(sandbox.split(' ').sort()).toEqual([...WITH_ORIGIN].sort());
24
+ expect(warn).not.toHaveBeenCalled();
10
25
  });
11
26
 
12
- test('same-origin production companion uses the same tightened set', () => {
27
+ test('omits allow-same-origin for a same-origin production companion and warns once', () => {
28
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
13
29
  const sandbox = resolveContentIframeSandbox('/app/', 'https://example.com');
14
30
  expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
15
- expect(sandbox.split(' ').sort()).toEqual(
16
- ['allow-forms', 'allow-popups', 'allow-same-origin', 'allow-scripts'].sort(),
31
+ expect(sandbox).not.toContain('allow-same-origin');
32
+ expect(sandbox.split(' ').sort()).toEqual([...OPAQUE].sort());
33
+ expect(warn).toHaveBeenCalledTimes(1);
34
+ expect(String(warn.mock.calls[0]?.[0])).toContain('/app/');
35
+ expect(String(warn.mock.calls[0]?.[0])).toContain('https://example.com');
36
+
37
+ resolveContentIframeSandbox('/app/', 'https://example.com');
38
+ expect(warn).toHaveBeenCalledTimes(1);
39
+ });
40
+
41
+ test('keeps allow-same-origin for shell pages on the shell origin', () => {
42
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
43
+ expect(
44
+ resolveContentIframeSandbox('/__settings/ai', 'https://example.com').split(' ').sort(),
45
+ ).toEqual([...WITH_ORIGIN].sort());
46
+ expect(
47
+ resolveContentIframeSandbox('/__cookie-preferences', 'https://example.com').split(' ').sort(),
48
+ ).toEqual([...WITH_ORIGIN].sort());
49
+ expect(warn).not.toHaveBeenCalled();
50
+ });
51
+
52
+ test('does not treat a shell-path prefix on another origin as a shell page', () => {
53
+ const sandbox = resolveContentIframeSandbox(
54
+ 'https://cdn.example/__settings/user',
55
+ 'https://example.com',
17
56
  );
57
+ expect(sandbox).toContain('allow-same-origin');
18
58
  });
19
59
 
20
- test('falls back safely for invalid URLs', () => {
21
- const sandbox = resolveContentIframeSandbox('not-a-valid-url', 'http://localhost:4000');
60
+ test('omits allow-same-origin when the URL cannot be parsed', () => {
61
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
62
+ const sandbox = resolveContentIframeSandbox('http://[', 'http://localhost:4000');
22
63
  expect(sandbox).toContain('allow-scripts');
64
+ expect(sandbox).not.toContain('allow-same-origin');
23
65
  expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
66
+ expect(warn).toHaveBeenCalled();
24
67
  });
25
68
  });
@@ -1,23 +1,64 @@
1
1
  /**
2
2
  * Companion/content iframe sandbox tokens.
3
3
  *
4
- * Threat model (Track F / M-18):
5
- * - Dev: shell (:4000) and companion (:5173, :3000, …) use distinct origins; templates
6
- * set `frame-ancestors` so companions accept shell framing.
7
- * - Prod: companion is served from the same origin as the shell (`/app/`), which keeps
8
- * postMessage and cookies workable while avoiding cross-origin framing surprises.
9
- * - `allow-same-origin` + `allow-scripts` lets embedded scripts remove the sandbox
10
- * attribute when the iframe is same-origin to its document — acceptable only for
11
- * trusted navigation URLs you configure. Residual risk is documented in
12
- * docs/features/companion-isolation.md.
4
+ * Dev companions run on another origin (another localhost port). They keep
5
+ * `allow-same-origin` so cookies and storage stay on that origin.
13
6
  *
14
- * Incremental tightening: drop `allow-popups-to-escape-sandbox` (popups stay sandboxed).
7
+ * A companion URL on the shell origin (the production `/app/` path, or any
8
+ * other same-origin path that is not a shell page) does not get
9
+ * `allow-same-origin`. The frame then has its own opaque origin. The shell
10
+ * warns once per URL. Host that companion on its own origin when it needs
11
+ * cookies, storage, or a concrete postMessage origin.
12
+ *
13
+ * Shell pages (settings, cookie preferences, login, and the other shell
14
+ * routes) stay on the shell origin.
15
+ *
16
+ * `allow-popups-to-escape-sandbox` is not granted, so popups stay sandboxed.
15
17
  */
16
- const SANDBOX_CONTENT = 'allow-same-origin allow-scripts allow-forms allow-popups';
18
+ import { isShellOwnedPath } from '../features/layouts/floating/isShellOwnedPath';
17
19
 
18
- /** @deprecated use SANDBOX_CONTENT — kept for tests asserting legacy tokens are gone */
20
+ const SANDBOX_WITH_ORIGIN = 'allow-same-origin allow-scripts allow-forms allow-popups';
21
+ const SANDBOX_OPAQUE_ORIGIN = 'allow-scripts allow-forms allow-popups';
22
+
23
+ /** @deprecated use the sandbox returned by resolveContentIframeSandbox */
19
24
  export const LEGACY_POPUP_ESCAPE_TOKEN = 'allow-popups-to-escape-sandbox';
20
25
 
26
+ const warnedSameOriginCompanions = new Set<string>();
27
+
28
+ /** Test helper. Production code warns once per shell origin and companion URL. */
29
+ export function resetContentIframeSandboxWarnings(): void {
30
+ warnedSameOriginCompanions.clear();
31
+ }
32
+
33
+ function warnSameOriginCompanion(iframeUrl: string, shellOrigin: string): void {
34
+ let path = iframeUrl;
35
+ try {
36
+ path = new URL(iframeUrl, shellOrigin).pathname;
37
+ } catch {
38
+ // Keep the raw value when it is not a URL.
39
+ }
40
+ const key = `${shellOrigin} ${path}`;
41
+ if (warnedSameOriginCompanions.has(key)) return;
42
+ warnedSameOriginCompanions.add(key);
43
+ // eslint-disable-next-line no-console -- operators need this without debug logging
44
+ console.warn(
45
+ `Shellui: companion path ${path} is on the shell origin (${shellOrigin}). The content iframe sandbox omits allow-same-origin. Host this companion on its own origin so it keeps cookies, storage, and a concrete postMessage origin.`,
46
+ );
47
+ }
48
+
49
+ function isSameOriginCompanion(
50
+ iframeUrl: string,
51
+ iframeOrigin: string,
52
+ shellOrigin: string,
53
+ ): boolean {
54
+ if (iframeOrigin !== shellOrigin) return false;
55
+ try {
56
+ return !isShellOwnedPath(new URL(iframeUrl, shellOrigin).pathname);
57
+ } catch {
58
+ return true;
59
+ }
60
+ }
61
+
21
62
  /**
22
63
  * Resolve the `sandbox` attribute for a main content iframe.
23
64
  *
@@ -31,13 +72,13 @@ export function resolveContentIframeSandbox(iframeUrl: string, shellOrigin?: str
31
72
  const iframeOrigin = new URL(iframeUrl, base).origin;
32
73
  const parentOrigin =
33
74
  shellOrigin ?? (typeof window !== 'undefined' ? window.location.origin : iframeOrigin);
34
- // Same-origin vs cross-origin companions share the tightened token set today.
35
- // Cross-origin dev companions still require `allow-same-origin` for companion
36
- // cookies/localStorage on their own origin; distinct-origin framing is the isolation layer.
37
- void iframeOrigin;
38
- void parentOrigin;
39
- return SANDBOX_CONTENT;
75
+ if (isSameOriginCompanion(iframeUrl, iframeOrigin, parentOrigin)) {
76
+ warnSameOriginCompanion(iframeUrl, parentOrigin);
77
+ return SANDBOX_OPAQUE_ORIGIN;
78
+ }
79
+ return SANDBOX_WITH_ORIGIN;
40
80
  } catch {
41
- return SANDBOX_CONTENT;
81
+ warnSameOriginCompanion(iframeUrl, shellOrigin ?? 'unknown');
82
+ return SANDBOX_OPAQUE_ORIGIN;
42
83
  }
43
84
  }
@@ -22,8 +22,7 @@ export type ChildFrameServices = Record<ChildFrameServiceKey, string | null>;
22
22
  const SERVICE_KEYS: readonly ChildFrameServiceKey[] = ['email', 'storage', 'files', 'hosting'];
23
23
 
24
24
  export type ChildFrameRegistration =
25
- | { ok: true; entry: ChildFrameEntry }
26
- | { ok: false; reason: string };
25
+ { ok: true; entry: ChildFrameEntry } | { ok: false; reason: string };
27
26
 
28
27
  const entries = new Map<string, ChildFrameEntry>();
29
28
 
@@ -93,9 +92,7 @@ export function validateChildFrameRegistration(input: {
93
92
  if (from.length !== 1) return { ok: false, reason: 'not sent by a direct app frame' };
94
93
  if (!input.hostSrc) return { ok: false, reason: 'unknown host frame' };
95
94
  const payload = input.payload as
96
- | { frameId?: unknown; url?: unknown; backend?: unknown; services?: unknown }
97
- | null
98
- | undefined;
95
+ { frameId?: unknown; url?: unknown; backend?: unknown; services?: unknown } | null | undefined;
99
96
  const frameId = typeof payload?.frameId === 'string' ? payload.frameId.trim() : '';
100
97
  if (!frameId) return { ok: false, reason: 'missing frameId' };
101
98
  const childOrigin = exactOrigin(payload?.url);
@@ -110,9 +107,7 @@ export function validateChildFrameRegistration(input: {
110
107
 
111
108
  let identity: ResolvedAppBackend | null = null;
112
109
  const backend = payload?.backend as
113
- | { url?: unknown; companyId?: unknown; type?: unknown; provider?: unknown }
114
- | null
115
- | undefined;
110
+ { url?: unknown; companyId?: unknown; type?: unknown; provider?: unknown } | null | undefined;
116
111
  if (backend) {
117
112
  const backendOrigin = exactOrigin(backend.url);
118
113
  if (!backendOrigin || !originList(rules.backendOrigins).has(backendOrigin)) {
@@ -12,9 +12,7 @@ export type ResolvedAppBackend = {
12
12
  };
13
13
 
14
14
  export type FrameAppBackend =
15
- | { kind: 'shell' }
16
- | { kind: 'foreign'; identity: ResolvedAppBackend }
17
- | { kind: 'withhold' };
15
+ { kind: 'shell' } | { kind: 'foreign'; identity: ResolvedAppBackend } | { kind: 'withhold' };
18
16
 
19
17
  /** http(s) base URL without trailing slash, query, or hash. Host is lowercased. */
20
18
  export function normalizeBackendUrl(raw: string | null | undefined): string | null {
@@ -29,8 +29,7 @@ export function isSilentAuthCallbackFrame(): boolean {
29
29
  }
30
30
 
31
31
  export type SilentAuthResult =
32
- | { ok: true; authCode: string }
33
- | { ok: false; error: string; errorCode: string | null };
32
+ { ok: true; authCode: string } | { ok: false; error: string; errorCode: string | null };
34
33
 
35
34
  /**
36
35
  * Accept a silent-auth result only from the frame we opened, on this origin, for this state.
@@ -5,8 +5,7 @@ export const TOKEN_EXCHANGE_GRANT = 'urn:ietf:params:oauth:grant-type:token-exch
5
5
  export const ACCESS_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token';
6
6
 
7
7
  export type TokenExchangeOutcome =
8
- | { ok: true; session: AuthSession }
9
- | { ok: false; reason: string };
8
+ { ok: true; session: AuthSession } | { ok: false; reason: string };
10
9
 
11
10
  /**
12
11
  * RFC 8693 token exchange against a regional identity server.
@@ -5,8 +5,7 @@ type ShellUIMessageType = ShellUIMessage['type'];
5
5
  export type DeleteAccountResultStatus = 'deleted' | 'cancelled' | 'error';
6
6
 
7
7
  export type UpdateProfileResult =
8
- | { status: 'saved'; name: string }
9
- | { status: 'error'; error?: string };
8
+ { status: 'saved'; name: string } | { status: 'error'; error?: string };
10
9
 
11
10
  /** The delete confirmation dialog stays open until the user answers, so only give up after a long wait. */
12
11
  const DELETE_RESULT_TIMEOUT_MS = 10 * 60_000;
@@ -12,13 +12,7 @@ export type DrawerPosition = 'top' | 'bottom' | 'left' | 'right';
12
12
 
13
13
  /** Layout mode: 'sidebar' (default) shows navigation sidebar; 'sidebar-inset' is sidebar with a padded, rounded main frame; 'fullscreen' shows only content area; 'windows' shows a taskbar with start menu and multi-window desktop; 'app-bar' shows a compact top bar; 'app-bar-inset' is app-bar with the same padded, rounded main frame as sidebar-inset; 'floating' is glass chrome over full-bleed content (bottom tabs on phone/tablet, floating sidebar on desktop). */
14
14
  export type LayoutType =
15
- | 'sidebar'
16
- | 'sidebar-inset'
17
- | 'fullscreen'
18
- | 'windows'
19
- | 'app-bar'
20
- | 'app-bar-inset'
21
- | 'floating';
15
+ 'sidebar' | 'sidebar-inset' | 'fullscreen' | 'windows' | 'app-bar' | 'app-bar-inset' | 'floating';
22
16
 
23
17
  /** Map legacy layout ids (e.g. early `cupertino`) onto current LayoutType. */
24
18
  export function normalizeLayoutType(layout: string | null | undefined): LayoutType | undefined {
@@ -131,10 +125,7 @@ export interface SentryConfig {
131
125
  * - social_media_embedded: Social widgets, embedded content.
132
126
  */
133
127
  export type CookieConsentCategory =
134
- | 'strict_necessary'
135
- | 'functional_performance'
136
- | 'targeting'
137
- | 'social_media_embedded';
128
+ 'strict_necessary' | 'functional_performance' | 'targeting' | 'social_media_embedded';
138
129
 
139
130
  /**
140
131
  * Definition of a cookie that can be toggled by the user via cookie consent.
@@ -401,6 +392,16 @@ export interface AiServiceConfig {
401
392
  * Local: `http://localhost:8006`.
402
393
  */
403
394
  url?: string;
395
+ /**
396
+ * Full Shellui account MCP URL (path must be exactly `/mcp`).
397
+ * When set, Settings shows this URL for MCP / AI agents, even if
398
+ * `backend.companyId` is also set (as on the dashboard).
399
+ * Use this for the global MCP (saas tools), for example
400
+ * `https://ai.example/mcp` or `http://localhost:8008/mcp`.
401
+ * Omit it in a regional project so Settings can use
402
+ * `{url}/c/{companyId}/mcp`.
403
+ */
404
+ mcpUrl?: string;
404
405
  /**
405
406
  * When false, hide Admin → AI.
406
407
  * Default: true (shown) when `aiService` is set.
@@ -37,8 +37,7 @@ const isGroup = (item: NavigationItem | NavigationGroup): item is NavigationGrou
37
37
  };
38
38
 
39
39
  type NavSection =
40
- | { type: 'group'; group: NavigationGroup }
41
- | { type: 'items'; items: NavigationItem[] };
40
+ { type: 'group'; group: NavigationGroup } | { type: 'items'; items: NavigationItem[] };
42
41
 
43
42
  function buildSections(navigation: (NavigationItem | NavigationGroup)[]): NavSection[] {
44
43
  const result: NavSection[] = [];
@@ -2,10 +2,7 @@ import type { ShellUIConfig } from '../config/types';
2
2
  import urls from '../../constants/urls';
3
3
 
4
4
  export type LegalDocumentKey =
5
- | 'privacyPolicy'
6
- | 'termsOfService'
7
- | 'legalNotice'
8
- | 'dataProcessingAgreement';
5
+ 'privacyPolicy' | 'termsOfService' | 'legalNotice' | 'dataProcessingAgreement';
9
6
 
10
7
  export type LegalDocumentDescriptor = {
11
8
  key: LegalDocumentKey;
@@ -85,8 +85,7 @@ export function formatActivityWhen(iso: string, locale: string): string {
85
85
  }
86
86
 
87
87
  export type ActivityPendingLink =
88
- | { type: 'id'; approvalId: string }
89
- | { type: 'tool'; toolName: string };
88
+ { type: 'id'; approvalId: string } | { type: 'tool'; toolName: string };
90
89
 
91
90
  export function resolveActivityPendingLink(
92
91
  row: McpAgentActivityRow,
@@ -8,6 +8,8 @@ import {
8
8
  agentPromptContainsCredentialMaterial,
9
9
  buildAgentPrompt,
10
10
  buildCompanyMcpUrl,
11
+ buildGlobalMcpUrl,
12
+ resolveSettingsMcpUrl,
11
13
  defaultPersonalAgentExpiresAt,
12
14
  formatDefaultAgentName,
13
15
  getDefaultPersonalAgentServices,
@@ -32,6 +34,66 @@ describe('buildCompanyMcpUrl', () => {
32
34
  });
33
35
  });
34
36
 
37
+ describe('buildGlobalMcpUrl', () => {
38
+ it('uses a configured /mcp URL and ignores a trailing slash on the ai host', () => {
39
+ expect(buildGlobalMcpUrl('https://ai.example/', 'https://global.example/mcp')).toBe(
40
+ 'https://global.example/mcp',
41
+ );
42
+ expect(buildGlobalMcpUrl('https://ai.example/')).toBe('https://ai.example/mcp');
43
+ });
44
+
45
+ it('ignores a configured URL that is not an absolute /mcp endpoint', () => {
46
+ expect(buildGlobalMcpUrl('https://ai.example', 'https://global.example/c/1/mcp')).toBe(
47
+ 'https://ai.example/mcp',
48
+ );
49
+ expect(buildGlobalMcpUrl(null, 'not-a-url')).toBe(null);
50
+ });
51
+ });
52
+
53
+ describe('resolveSettingsMcpUrl', () => {
54
+ it('uses the configured global MCP URL even when a company id is set', () => {
55
+ expect(
56
+ resolveSettingsMcpUrl({
57
+ aiServiceUrl: 'https://ai.example',
58
+ companyId: '1',
59
+ configuredGlobalMcpUrl: 'https://global.example/mcp',
60
+ statusMcpUrl: 'https://ai.example/c/1/mcp',
61
+ }),
62
+ ).toBe('https://global.example/mcp');
63
+ });
64
+
65
+ it('uses the regional company URL when no global MCP URL is configured', () => {
66
+ expect(
67
+ resolveSettingsMcpUrl({
68
+ aiServiceUrl: 'https://ai.example/',
69
+ companyId: '42',
70
+ statusMcpUrl: 'https://unused.example/c/42/mcp',
71
+ }),
72
+ ).toBe('https://ai.example/c/42/mcp');
73
+ });
74
+
75
+ it('falls back to {ai}/mcp when there is no company id', () => {
76
+ expect(
77
+ resolveSettingsMcpUrl({
78
+ aiServiceUrl: 'https://ai.example/',
79
+ companyId: '',
80
+ statusGlobalMcpUrl: 'https://status.example/mcp',
81
+ }),
82
+ ).toBe('https://ai.example/mcp');
83
+ });
84
+
85
+ it('falls back to status global MCP URL when a configured URL is invalid', () => {
86
+ expect(
87
+ resolveSettingsMcpUrl({
88
+ aiServiceUrl: null,
89
+ companyId: '1',
90
+ configuredGlobalMcpUrl: 'https://ai.example/c/1/mcp',
91
+ statusGlobalMcpUrl: 'https://status.example/mcp',
92
+ }),
93
+ ).toBe('https://status.example/mcp');
94
+ });
95
+ });
96
+
35
97
  describe('isGlobalIdentitySession', () => {
36
98
  it('reads globalIdentity from status when present', () => {
37
99
  expect(
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  MCP_PERSONAL_SERVICE_OPTIONS,
3
+ parseValidatedGlobalMcpEndpointUrl,
3
4
  type McpAgentSummary,
4
5
  type McpPersonalService,
5
6
  type McpPersonalStatus,
@@ -24,6 +25,54 @@ export function buildCompanyMcpUrl(
24
25
  return fallback || null;
25
26
  }
26
27
 
28
+ /** `{aiServiceUrl}/mcp`, or a configured absolute `/mcp` URL. */
29
+ export function buildGlobalMcpUrl(
30
+ aiServiceUrl: string | null | undefined,
31
+ configuredMcpUrl?: string | null,
32
+ ): string | null {
33
+ const configured = parseValidatedGlobalMcpEndpointUrl(configuredMcpUrl);
34
+ if (configured) return configured;
35
+ const base = aiServiceUrl?.trim().replace(/\/+$/, '') || '';
36
+ if (!base) return null;
37
+ return parseValidatedGlobalMcpEndpointUrl(`${base}/mcp`);
38
+ }
39
+
40
+ export type ResolveSettingsMcpUrlInput = {
41
+ aiServiceUrl: string | null | undefined;
42
+ companyId: string;
43
+ /**
44
+ * Full account MCP URL from `aiService.mcpUrl`.
45
+ * When set, Settings uses the global MCP even if `companyId` is present.
46
+ */
47
+ configuredGlobalMcpUrl?: string | null;
48
+ statusMcpUrl?: string | null;
49
+ statusGlobalMcpUrl?: string | null;
50
+ };
51
+
52
+ /**
53
+ * MCP URL shown in Settings.
54
+ * A configured `aiService.mcpUrl` selects the global account MCP
55
+ * (`https://host/mcp`), for dashboard and other global shells.
56
+ * Otherwise a company id selects the regional `{ai}/c/{id}/mcp` URL.
57
+ */
58
+ export function resolveSettingsMcpUrl(input: ResolveSettingsMcpUrlInput): string | null {
59
+ const hasConfiguredGlobal = Boolean(input.configuredGlobalMcpUrl?.trim());
60
+ if (hasConfiguredGlobal) {
61
+ return (
62
+ buildGlobalMcpUrl(input.aiServiceUrl, input.configuredGlobalMcpUrl) ??
63
+ parseValidatedGlobalMcpEndpointUrl(input.statusGlobalMcpUrl)
64
+ );
65
+ }
66
+ const companyId = input.companyId.trim();
67
+ if (companyId) {
68
+ return buildCompanyMcpUrl(input.aiServiceUrl, companyId, input.statusMcpUrl);
69
+ }
70
+ return (
71
+ buildGlobalMcpUrl(input.aiServiceUrl) ??
72
+ parseValidatedGlobalMcpEndpointUrl(input.statusGlobalMcpUrl)
73
+ );
74
+ }
75
+
27
76
  export function isAbsoluteHttpUrl(value: string | null | undefined): boolean {
28
77
  if (!value?.trim()) return false;
29
78
  try {
@@ -48,12 +48,7 @@ export type McpAgentSummary = {
48
48
  export type McpActivityAccessKind = 'read' | 'write' | 'destructive' | 'unknown';
49
49
 
50
50
  export type McpActivityOutcomeKind =
51
- | 'allowed'
52
- | 'denied'
53
- | 'failed'
54
- | 'pending_approval'
55
- | 'session_used'
56
- | 'unknown';
51
+ 'allowed' | 'denied' | 'failed' | 'pending_approval' | 'session_used' | 'unknown';
57
52
 
58
53
  /**
59
54
  * Identity `error_code` for activity rows: fixed allowlist from identity (and gateway when present).
@@ -4,6 +4,7 @@ import {
4
4
  getAiRequestTrustDenial,
5
5
  getStorageRequestTrustDenial,
6
6
  isRegisteredTrustedFrame,
7
+ isShellOwnedFrameMessage,
7
8
  isShellSettingsFrameMessage,
8
9
  isShellSettingsFrameSrc,
9
10
  isTrustedFrameForAuthToken,
@@ -110,6 +111,49 @@ const registry = {
110
111
  ] as Array<[string, HTMLIFrameElement]>,
111
112
  };
112
113
 
114
+ describe('isShellOwnedFrameMessage', () => {
115
+ const shellOrigin = 'http://localhost:4000';
116
+ const framesFor = (entries: Array<[string, string]>) => ({
117
+ getAllIframes: () =>
118
+ entries.map(
119
+ ([uuid, src]) => [uuid, { src } as HTMLIFrameElement] as [string, HTMLIFrameElement],
120
+ ),
121
+ });
122
+
123
+ it('accepts the shell window', () => {
124
+ expect(isShellOwnedFrameMessage([], framesFor([]), shellOrigin)).toBe(true);
125
+ expect(isShellOwnedFrameMessage(undefined, framesFor([]), shellOrigin)).toBe(true);
126
+ });
127
+
128
+ it('accepts shell pages, including settings and cookie preferences', () => {
129
+ const frames = framesFor([
130
+ ['settings', `${shellOrigin}/__settings/ai`],
131
+ ['cookies', '/__cookie-preferences'],
132
+ ['login', `${shellOrigin}/login`],
133
+ ]);
134
+ expect(isShellOwnedFrameMessage(['settings'], frames, shellOrigin)).toBe(true);
135
+ expect(isShellOwnedFrameMessage(['cookies'], frames, shellOrigin)).toBe(true);
136
+ expect(isShellOwnedFrameMessage(['login'], frames, shellOrigin)).toBe(true);
137
+ });
138
+
139
+ it('rejects companions, including an opted-in access-token companion and a same-origin /app/ frame', () => {
140
+ const frames = framesFor([
141
+ ['companion', 'http://localhost:5175/company'],
142
+ ['app', `${shellOrigin}/app/`],
143
+ ['relay', `${shellOrigin}/__settings/user`],
144
+ ]);
145
+ expect(isShellOwnedFrameMessage(['companion'], frames, shellOrigin)).toBe(false);
146
+ expect(isShellOwnedFrameMessage(['app'], frames, shellOrigin)).toBe(false);
147
+ expect(isShellOwnedFrameMessage(['relay', 'nested'], frames, shellOrigin)).toBe(false);
148
+ expect(isShellOwnedFrameMessage(['missing'], frames, shellOrigin)).toBe(false);
149
+ });
150
+
151
+ it('rejects a shell path hosted on another origin', () => {
152
+ const frames = framesFor([['evil', 'http://evil.test/__settings/user']]);
153
+ expect(isShellOwnedFrameMessage(['evil'], frames, shellOrigin)).toBe(false);
154
+ });
155
+ });
156
+
113
157
  describe('isTrustedFrameForAuthToken', () => {
114
158
  it('does not trust navigation companions by default', () => {
115
159
  expect(isTrustedFrameForAuthToken('http://localhost:5198/widget', config)).toBe(false);