@shellui/core 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -1
  3. package/package.json +2 -2
  4. package/schemas/shellui.config.schema.json +45 -2
  5. package/src/app.tsx +2 -0
  6. package/src/features/auth/AuthProvider.tsx +212 -97
  7. package/src/features/auth/appBackend/configSchema.spec.ts +1 -0
  8. package/src/features/auth/appBackend/frameAuth.ts +5 -0
  9. package/src/features/auth/backends/shellui.spec.ts +110 -0
  10. package/src/features/auth/backends/shellui.ts +47 -20
  11. package/src/features/auth/backends/types.ts +5 -0
  12. package/src/features/auth/hooks/useAuth.tsx +6 -1
  13. package/src/features/auth/types.ts +5 -0
  14. package/src/features/auth/utils/bffAuthClient.spec.ts +313 -0
  15. package/src/features/auth/utils/bffAuthClient.ts +171 -49
  16. package/src/features/auth/utils/buildSessionFromParams.ts +5 -2
  17. package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +12 -0
  18. package/src/features/auth/utils/buildSessionFromTokenPayload.ts +3 -1
  19. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +140 -4
  20. package/src/features/auth/utils/canRestoreStoredSession.ts +47 -0
  21. package/src/features/auth/utils/cliCallback.ts +5 -0
  22. package/src/features/auth/utils/identityBrowserLogout.spec.ts +185 -0
  23. package/src/features/auth/utils/identityBrowserLogout.ts +174 -0
  24. package/src/features/auth/utils/index.ts +21 -3
  25. package/src/features/auth/utils/isBffAuthEnabled.ts +10 -2
  26. package/src/features/auth/utils/normalizeAuthSettings.spec.ts +9 -0
  27. package/src/features/auth/utils/normalizeAuthSettings.ts +3 -1
  28. package/src/features/auth/utils/pkce.spec.ts +29 -1
  29. package/src/features/auth/utils/pkce.ts +106 -2
  30. package/src/features/config/types.ts +37 -5
  31. package/src/features/mcp/mcpActivityErrorCodeI18n.spec.ts +32 -0
  32. package/src/features/mcp/mcpActivityErrorCodeI18n.ts +30 -0
  33. package/src/features/mcp/mcpAgentActivityMerge.spec.ts +91 -0
  34. package/src/features/mcp/mcpAgentActivityMerge.ts +53 -0
  35. package/src/features/mcp/mcpAgentActivityPresentation.spec.ts +129 -0
  36. package/src/features/mcp/mcpAgentActivityPresentation.ts +201 -0
  37. package/src/features/mcp/mcpAgentsConnect.spec.ts +215 -0
  38. package/src/features/mcp/mcpAgentsConnect.ts +189 -0
  39. package/src/features/mcp/mcpToolActivityRegistry.spec.ts +9 -0
  40. package/src/features/mcp/mcpToolActivityRegistry.ts +20 -0
  41. package/src/features/mcp/mcpToolApprovalsApi.spec.ts +113 -0
  42. package/src/features/mcp/mcpToolApprovalsApi.ts +162 -0
  43. package/src/features/mcp/personalAgentsApi.spec.ts +661 -0
  44. package/src/features/mcp/personalAgentsApi.ts +697 -0
  45. package/src/features/settings/SettingsIcons.tsx +28 -0
  46. package/src/features/settings/SettingsRoutes.tsx +8 -0
  47. package/src/features/settings/SettingsView.tsx +90 -26
  48. package/src/features/settings/components/McpAgentActivitySection.spec.tsx +255 -0
  49. package/src/features/settings/components/McpAgentActivitySection.tsx +481 -0
  50. package/src/features/settings/components/McpAgents.spec.tsx +336 -0
  51. package/src/features/settings/components/McpAgents.tsx +654 -0
  52. package/src/features/settings/components/McpPendingApprovals.spec.tsx +201 -0
  53. package/src/features/settings/components/McpPendingApprovals.tsx +168 -0
  54. package/src/features/settings/components/McpPersonalStatusPrefetch.tsx +21 -0
  55. package/src/features/settings/hooks/useMcpPendingToolApprovals.ts +69 -0
  56. package/src/features/settings/hooks/useMcpPersonalStatus.ts +83 -0
  57. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +44 -1
  58. package/src/features/settings/utils/buildSettingsForPropagation.ts +30 -1
  59. package/src/features/settings/utils/isMcpAgentsSettingsEligible.spec.ts +25 -0
  60. package/src/features/settings/utils/isMcpAgentsSettingsEligible.ts +14 -0
  61. package/src/features/settings/utils/loadMcpPersonalStatus.spec.ts +76 -0
  62. package/src/features/settings/utils/loadMcpPersonalStatus.ts +84 -0
  63. package/src/features/settings/utils/mcpPersonalStatusCache.spec.ts +77 -0
  64. package/src/features/settings/utils/mcpPersonalStatusCache.ts +95 -0
  65. package/src/features/settings/utils/shouldShowMcpAgentsSettings.spec.ts +66 -0
  66. package/src/features/settings/utils/shouldShowMcpAgentsSettings.ts +16 -0
  67. package/src/features/storage/StorageBridge.paths.spec.ts +286 -0
  68. package/src/features/storage/StorageBridge.tsx +25 -5
  69. package/src/features/storage/resolveStorageBridgeTarget.spec.ts +51 -0
  70. package/src/features/storage/resolveStorageBridgeTarget.ts +24 -0
  71. package/src/i18n/translations/en/settings.json +201 -0
  72. package/src/i18n/translations/fr/settings.json +201 -0
  73. package/src/index.ts +1 -0
  74. package/src/service-worker/sw.ts +4 -2
@@ -1,11 +1,18 @@
1
1
  import type {
2
2
  Settings,
3
+ SettingsAiService,
3
4
  SettingsEmail,
4
5
  SettingsHosting,
5
6
  SettingsNavigationItem,
6
7
  SettingsStorage,
7
8
  } from '@shellui/sdk';
8
- import type { EmailConfig, HostingConfig, ShellUIConfig, StorageConfig } from '../../config/types';
9
+ import type {
10
+ AiServiceConfig,
11
+ EmailConfig,
12
+ HostingConfig,
13
+ ShellUIConfig,
14
+ StorageConfig,
15
+ } from '../../config/types';
9
16
  import { flattenNavigationItems } from './flattenNavigationItems';
10
17
  import { getAvailableThemesForSettings } from './getAvailableThemesForSettings';
11
18
  import { getResolvedAppearanceForSettings } from './getResolvedAppearanceForSettings';
@@ -46,6 +53,24 @@ const propagateHosting = (hosting: HostingConfig | null | undefined): SettingsHo
46
53
  };
47
54
  };
48
55
 
56
+ /** Normalized AI service base URL from config, or null when unset or blank. */
57
+ export function getNormalizedAiServiceUrl(
58
+ aiService: AiServiceConfig | null | undefined,
59
+ ): string | null {
60
+ return aiService?.url?.trim().replace(/\/+$/, '') || null;
61
+ }
62
+
63
+ const propagateAiService = (
64
+ aiService: AiServiceConfig | null | undefined,
65
+ ): SettingsAiService | null => {
66
+ const url = getNormalizedAiServiceUrl(aiService);
67
+ if (!url) return null;
68
+ return {
69
+ url,
70
+ ...(aiService?.showInAdmin === false ? { showInAdmin: false } : {}),
71
+ };
72
+ };
73
+
49
74
  /**
50
75
  * Build settings for propagation to iframes: inject navigation, full theme object,
51
76
  * and list of available themes so apps can render theme pickers.
@@ -73,6 +98,8 @@ export const buildSettingsForPropagation = (
73
98
  email?: EmailConfig | null;
74
99
  /** Hosting for this frame. When the key is set, it replaces the shell `hosting`. */
75
100
  hosting?: HostingConfig | null;
101
+ /** AI service for this frame. When the key is set, it replaces the shell `aiService`. */
102
+ aiService?: AiServiceConfig | null;
76
103
  /** When false, omit layoutChrome (modal / drawer frames). Default true. */
77
104
  includeLayoutChrome?: boolean;
78
105
  /** Merge this frame's action-bar insets into layoutChrome. */
@@ -146,12 +173,14 @@ export const buildSettingsForPropagation = (
146
173
  const storageSource = options && 'storage' in options ? options.storage : config?.storage;
147
174
  const hostingSource = options && 'hosting' in options ? options.hosting : config?.hosting;
148
175
  const emailSource = options && 'email' in options ? options.email : config?.email;
176
+ const aiServiceSource = options && 'aiService' in options ? options.aiService : config?.aiService;
149
177
 
150
178
  result = {
151
179
  ...result,
152
180
  storage: propagateStorage(storageSource),
153
181
  hosting: propagateHosting(hostingSource),
154
182
  email: propagateEmail(emailSource),
183
+ aiService: propagateAiService(aiServiceSource),
155
184
  };
156
185
 
157
186
  const shellAuthBackendBaseUrl =
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import { isMcpAgentsSettingsEligible } from './isMcpAgentsSettingsEligible';
4
+
5
+ const shellWithAiService: ShellUIConfig = {
6
+ aiService: { url: 'https://ai.example.com' },
7
+ backend: { type: 'shellui', url: 'https://id.example.com', companyId: 1 },
8
+ } as ShellUIConfig;
9
+
10
+ describe('isMcpAgentsSettingsEligible', () => {
11
+ it('is true when aiService, auth, and shellui backend are present', () => {
12
+ expect(isMcpAgentsSettingsEligible({ config: shellWithAiService, isAuthenticated: true })).toBe(
13
+ true,
14
+ );
15
+ });
16
+
17
+ it('is false when aiService url is missing', () => {
18
+ expect(
19
+ isMcpAgentsSettingsEligible({
20
+ config: { backend: { type: 'shellui', url: 'https://id.example.com' } } as ShellUIConfig,
21
+ isAuthenticated: true,
22
+ }),
23
+ ).toBe(false);
24
+ });
25
+ });
@@ -0,0 +1,14 @@
1
+ import { getShellIdentityBackendUrl } from '../../mcp/personalAgentsApi';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import { getNormalizedAiServiceUrl } from './buildSettingsForPropagation';
4
+
5
+ /** Prerequisites for Settings MCP / AI agents (identity MCP flag is loaded separately). */
6
+ export function isMcpAgentsSettingsEligible(options: {
7
+ config: ShellUIConfig | undefined;
8
+ isAuthenticated: boolean;
9
+ }): boolean {
10
+ if (!getNormalizedAiServiceUrl(options.config?.aiService)) return false;
11
+ if (!options.isAuthenticated) return false;
12
+ if (!getShellIdentityBackendUrl(options.config)) return false;
13
+ return true;
14
+ }
@@ -0,0 +1,76 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import * as personalAgentsApi from '../../mcp/personalAgentsApi';
4
+ import { loadMcpPersonalStatus } from './loadMcpPersonalStatus';
5
+ import { readMcpPersonalStatusCache } from './mcpPersonalStatusCache';
6
+
7
+ const memoryStorage = () => {
8
+ const map = new Map<string, string>();
9
+ return {
10
+ get length() {
11
+ return map.size;
12
+ },
13
+ clear: () => map.clear(),
14
+ getItem: (key: string) => map.get(key) ?? null,
15
+ setItem: (key: string, value: string) => {
16
+ map.set(key, value);
17
+ },
18
+ removeItem: (key: string) => {
19
+ map.delete(key);
20
+ },
21
+ key: (index: number) => [...map.keys()][index] ?? null,
22
+ } satisfies Storage;
23
+ };
24
+
25
+ const shellConfig = {
26
+ aiService: { url: 'https://ai.example.com' },
27
+ backend: { type: 'shellui', url: 'https://id.example.com', companyId: 1 },
28
+ } as ShellUIConfig;
29
+
30
+ describe('loadMcpPersonalStatus', () => {
31
+ afterEach(() => {
32
+ vi.restoreAllMocks();
33
+ vi.unstubAllGlobals();
34
+ });
35
+
36
+ it('dedupes in-flight requests and writes session cache on success', async () => {
37
+ vi.stubGlobal('sessionStorage', memoryStorage());
38
+ const fetchSpy = vi.spyOn(personalAgentsApi, 'fetchMcpPersonalStatus').mockResolvedValue({
39
+ mcpEnabled: true,
40
+ mcpUrl: 'https://ai.test/mcp',
41
+ globalMcpUrl: null,
42
+ });
43
+
44
+ const input = {
45
+ config: shellConfig,
46
+ accessToken: 'access',
47
+ isAuthenticated: true,
48
+ userId: 'user-1',
49
+ };
50
+
51
+ const [a, b] = await Promise.all([loadMcpPersonalStatus(input), loadMcpPersonalStatus(input)]);
52
+
53
+ expect(fetchSpy).toHaveBeenCalledTimes(1);
54
+ expect(a).toEqual({ mcpEnabled: true, mcpUrl: 'https://ai.test/mcp', globalMcpUrl: null });
55
+ expect(b).toEqual(a);
56
+ expect(
57
+ readMcpPersonalStatusCache({
58
+ userId: 'user-1',
59
+ backendUrl: 'https://id.example.com',
60
+ companyId: '1',
61
+ }),
62
+ ).toEqual({ mcpEnabled: true, mcpUrl: 'https://ai.test/mcp', globalMcpUrl: null });
63
+ });
64
+
65
+ it('returns null without calling identity when prerequisites are missing', async () => {
66
+ const fetchSpy = vi.spyOn(personalAgentsApi, 'fetchMcpPersonalStatus');
67
+ const result = await loadMcpPersonalStatus({
68
+ config: shellConfig,
69
+ accessToken: null,
70
+ isAuthenticated: true,
71
+ userId: 'user-1',
72
+ });
73
+ expect(result).toBeNull();
74
+ expect(fetchSpy).not.toHaveBeenCalled();
75
+ });
76
+ });
@@ -0,0 +1,84 @@
1
+ import {
2
+ fetchMcpPersonalStatus,
3
+ getMcpPersonalCompanyId,
4
+ getShellIdentityBackendUrl,
5
+ type McpPersonalStatus,
6
+ } from '../../mcp/personalAgentsApi';
7
+ import type { ShellUIConfig } from '../../config/types';
8
+ import { getNormalizedAiServiceUrl } from './buildSettingsForPropagation';
9
+ import {
10
+ readMcpPersonalStatusCache,
11
+ writeMcpPersonalStatusCache,
12
+ type McpPersonalStatusCacheScope,
13
+ } from './mcpPersonalStatusCache';
14
+
15
+ export type LoadMcpPersonalStatusInput = {
16
+ config: ShellUIConfig | undefined;
17
+ accessToken: string | null;
18
+ isAuthenticated: boolean;
19
+ userId: string | null;
20
+ };
21
+
22
+ const buildScope = (input: LoadMcpPersonalStatusInput): McpPersonalStatusCacheScope | null => {
23
+ const backendUrl = getShellIdentityBackendUrl(input.config);
24
+ if (
25
+ !getNormalizedAiServiceUrl(input.config?.aiService) ||
26
+ !input.isAuthenticated ||
27
+ !backendUrl ||
28
+ !input.accessToken ||
29
+ !input.userId
30
+ ) {
31
+ return null;
32
+ }
33
+ return {
34
+ userId: input.userId,
35
+ backendUrl,
36
+ companyId: getMcpPersonalCompanyId(input.config),
37
+ };
38
+ };
39
+
40
+ let inFlightKey: string | null = null;
41
+ let inFlight: Promise<McpPersonalStatus | null> | null = null;
42
+
43
+ const scopeKey = (scope: McpPersonalStatusCacheScope): string =>
44
+ `${scope.userId}\0${scope.backendUrl}\0${scope.companyId}`;
45
+
46
+ export const loadMcpPersonalStatus = (
47
+ input: LoadMcpPersonalStatusInput,
48
+ ): Promise<McpPersonalStatus | null> => {
49
+ const scope = buildScope(input);
50
+ if (!scope || !input.accessToken) {
51
+ inFlightKey = null;
52
+ inFlight = null;
53
+ return Promise.resolve(null);
54
+ }
55
+
56
+ const key = scopeKey(scope);
57
+ if (inFlight && inFlightKey === key) {
58
+ return inFlight;
59
+ }
60
+
61
+ inFlightKey = key;
62
+ inFlight = fetchMcpPersonalStatus(scope.backendUrl, input.accessToken, scope.companyId)
63
+ .then((status) => {
64
+ writeMcpPersonalStatusCache(scope, status);
65
+ return status;
66
+ })
67
+ .catch(() => null)
68
+ .finally(() => {
69
+ if (inFlightKey === key) {
70
+ inFlightKey = null;
71
+ inFlight = null;
72
+ }
73
+ });
74
+
75
+ return inFlight;
76
+ };
77
+
78
+ export const getCachedMcpPersonalStatus = (
79
+ input: LoadMcpPersonalStatusInput,
80
+ ): McpPersonalStatus | null => {
81
+ const scope = buildScope(input);
82
+ if (!scope) return null;
83
+ return readMcpPersonalStatusCache(scope);
84
+ };
@@ -0,0 +1,77 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ clearMcpPersonalStatusCache,
4
+ MCP_PERSONAL_STATUS_CACHE_KEY,
5
+ readMcpPersonalStatusCache,
6
+ writeMcpPersonalStatusCache,
7
+ } from './mcpPersonalStatusCache';
8
+
9
+ const memoryStorage = () => {
10
+ const map = new Map<string, string>();
11
+ return {
12
+ get length() {
13
+ return map.size;
14
+ },
15
+ clear: () => map.clear(),
16
+ getItem: (key: string) => map.get(key) ?? null,
17
+ setItem: (key: string, value: string) => {
18
+ map.set(key, value);
19
+ },
20
+ removeItem: (key: string) => {
21
+ map.delete(key);
22
+ },
23
+ key: (index: number) => [...map.keys()][index] ?? null,
24
+ } satisfies Storage;
25
+ };
26
+
27
+ describe('mcpPersonalStatusCache', () => {
28
+ afterEach(() => {
29
+ vi.unstubAllGlobals();
30
+ });
31
+
32
+ it('stores only MCP flags scoped to user and identity URL', () => {
33
+ vi.stubGlobal('sessionStorage', memoryStorage());
34
+ const scope = {
35
+ userId: 'user-1',
36
+ backendUrl: 'https://id.example.com',
37
+ companyId: '7',
38
+ };
39
+ writeMcpPersonalStatusCache(scope, {
40
+ mcpEnabled: true,
41
+ mcpUrl: 'https://ai.test/mcp',
42
+ globalMcpUrl: null,
43
+ });
44
+
45
+ expect(readMcpPersonalStatusCache(scope)).toEqual({
46
+ mcpEnabled: true,
47
+ mcpUrl: 'https://ai.test/mcp',
48
+ globalMcpUrl: null,
49
+ });
50
+
51
+ writeMcpPersonalStatusCache(scope, {
52
+ mcpEnabled: true,
53
+ mcpUrl: 'https://ai.test/mcp',
54
+ globalMcpUrl: 'https://dash.example.com/mcp',
55
+ });
56
+ expect(readMcpPersonalStatusCache(scope)).toEqual({
57
+ mcpEnabled: true,
58
+ mcpUrl: 'https://ai.test/mcp',
59
+ globalMcpUrl: 'https://dash.example.com/mcp',
60
+ });
61
+ expect(readMcpPersonalStatusCache({ ...scope, userId: 'user-2' })).toBeNull();
62
+
63
+ const raw = sessionStorage.getItem(MCP_PERSONAL_STATUS_CACHE_KEY) ?? '';
64
+ expect(raw).not.toMatch(/access/i);
65
+ expect(raw).not.toMatch(/token/i);
66
+ });
67
+
68
+ it('clears cached status', () => {
69
+ vi.stubGlobal('sessionStorage', memoryStorage());
70
+ writeMcpPersonalStatusCache(
71
+ { userId: 'u', backendUrl: 'https://id.example.com', companyId: '1' },
72
+ { mcpEnabled: false, mcpUrl: null, globalMcpUrl: null },
73
+ );
74
+ clearMcpPersonalStatusCache();
75
+ expect(sessionStorage.getItem(MCP_PERSONAL_STATUS_CACHE_KEY)).toBeNull();
76
+ });
77
+ });
@@ -0,0 +1,95 @@
1
+ import type { McpPersonalStatus } from '../../mcp/personalAgentsApi';
2
+
3
+ export const MCP_PERSONAL_STATUS_CACHE_KEY = 'shellui:mcp-personal-status';
4
+
5
+ export type McpPersonalStatusCacheScope = {
6
+ userId: string;
7
+ backendUrl: string;
8
+ companyId: string;
9
+ };
10
+
11
+ type McpPersonalStatusCacheEntry = McpPersonalStatusCacheScope & {
12
+ mcpEnabled: boolean;
13
+ mcpUrl: string | null;
14
+ globalMcpUrl: string | null;
15
+ globalIdentity?: boolean;
16
+ fetchedAt: number;
17
+ };
18
+
19
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
20
+ Boolean(value) && typeof value === 'object';
21
+
22
+ const parseCacheEntry = (raw: string): McpPersonalStatusCacheEntry | null => {
23
+ try {
24
+ const parsed: unknown = JSON.parse(raw);
25
+ if (!isRecord(parsed)) return null;
26
+ const userId = typeof parsed.userId === 'string' ? parsed.userId : '';
27
+ const backendUrl = typeof parsed.backendUrl === 'string' ? parsed.backendUrl : '';
28
+ const companyId = typeof parsed.companyId === 'string' ? parsed.companyId : '';
29
+ if (!userId || !backendUrl) return null;
30
+ if (typeof parsed.mcpEnabled !== 'boolean') return null;
31
+ const mcpUrl =
32
+ parsed.mcpUrl === null ? null : typeof parsed.mcpUrl === 'string' ? parsed.mcpUrl : null;
33
+ const globalMcpUrl =
34
+ parsed.globalMcpUrl === null || parsed.globalMcpUrl === undefined
35
+ ? null
36
+ : typeof parsed.globalMcpUrl === 'string'
37
+ ? parsed.globalMcpUrl
38
+ : null;
39
+ const globalIdentity =
40
+ typeof parsed.globalIdentity === 'boolean' ? parsed.globalIdentity : undefined;
41
+ const fetchedAt = typeof parsed.fetchedAt === 'number' ? parsed.fetchedAt : 0;
42
+ return {
43
+ userId,
44
+ backendUrl,
45
+ companyId,
46
+ mcpEnabled: parsed.mcpEnabled,
47
+ mcpUrl,
48
+ globalMcpUrl,
49
+ ...(globalIdentity !== undefined ? { globalIdentity } : {}),
50
+ fetchedAt,
51
+ };
52
+ } catch {
53
+ return null;
54
+ }
55
+ };
56
+
57
+ const scopesMatch = (a: McpPersonalStatusCacheScope, b: McpPersonalStatusCacheScope): boolean =>
58
+ a.userId === b.userId && a.backendUrl === b.backendUrl && a.companyId === b.companyId;
59
+
60
+ export const readMcpPersonalStatusCache = (
61
+ scope: McpPersonalStatusCacheScope,
62
+ ): McpPersonalStatus | null => {
63
+ if (typeof sessionStorage === 'undefined') return null;
64
+ const raw = sessionStorage.getItem(MCP_PERSONAL_STATUS_CACHE_KEY);
65
+ if (!raw) return null;
66
+ const entry = parseCacheEntry(raw);
67
+ if (!entry || !scopesMatch(entry, scope)) return null;
68
+ return {
69
+ mcpEnabled: entry.mcpEnabled,
70
+ mcpUrl: entry.mcpUrl,
71
+ globalMcpUrl: entry.globalMcpUrl,
72
+ ...(entry.globalIdentity !== undefined ? { globalIdentity: entry.globalIdentity } : {}),
73
+ };
74
+ };
75
+
76
+ export const writeMcpPersonalStatusCache = (
77
+ scope: McpPersonalStatusCacheScope,
78
+ status: McpPersonalStatus,
79
+ ): void => {
80
+ if (typeof sessionStorage === 'undefined') return;
81
+ const entry: McpPersonalStatusCacheEntry = {
82
+ ...scope,
83
+ mcpEnabled: status.mcpEnabled,
84
+ mcpUrl: status.mcpUrl,
85
+ globalMcpUrl: status.globalMcpUrl,
86
+ ...(status.globalIdentity !== undefined ? { globalIdentity: status.globalIdentity } : {}),
87
+ fetchedAt: Date.now(),
88
+ };
89
+ sessionStorage.setItem(MCP_PERSONAL_STATUS_CACHE_KEY, JSON.stringify(entry));
90
+ };
91
+
92
+ export const clearMcpPersonalStatusCache = (): void => {
93
+ if (typeof sessionStorage === 'undefined') return;
94
+ sessionStorage.removeItem(MCP_PERSONAL_STATUS_CACHE_KEY);
95
+ };
@@ -0,0 +1,66 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import { shouldShowMcpAgentsSettings } from './shouldShowMcpAgentsSettings';
4
+
5
+ const shellWithAiService: ShellUIConfig = {
6
+ aiService: { url: 'https://ai.example.com' },
7
+ backend: { type: 'shellui', url: 'https://id.example.com', companyId: 1 },
8
+ } as ShellUIConfig;
9
+
10
+ describe('shouldShowMcpAgentsSettings', () => {
11
+ it('is false when aiService url is missing', () => {
12
+ expect(
13
+ shouldShowMcpAgentsSettings({
14
+ config: {
15
+ ai: { enabled: true },
16
+ backend: { type: 'shellui', url: 'https://id.example.com' },
17
+ } as ShellUIConfig,
18
+ isAuthenticated: true,
19
+ mcpEnabled: true,
20
+ }),
21
+ ).toBe(false);
22
+ });
23
+
24
+ it('is false when the user is signed out', () => {
25
+ expect(
26
+ shouldShowMcpAgentsSettings({
27
+ config: shellWithAiService,
28
+ isAuthenticated: false,
29
+ mcpEnabled: true,
30
+ }),
31
+ ).toBe(false);
32
+ });
33
+
34
+ it('is false while MCP status is unknown', () => {
35
+ expect(
36
+ shouldShowMcpAgentsSettings({
37
+ config: shellWithAiService,
38
+ isAuthenticated: true,
39
+ mcpEnabled: null,
40
+ }),
41
+ ).toBe(false);
42
+ });
43
+
44
+ it('is true when aiService, auth, backend, and MCP are ready', () => {
45
+ expect(
46
+ shouldShowMcpAgentsSettings({
47
+ config: shellWithAiService,
48
+ isAuthenticated: true,
49
+ mcpEnabled: true,
50
+ }),
51
+ ).toBe(true);
52
+ });
53
+
54
+ it('treats whitespace-only aiService url as unset', () => {
55
+ expect(
56
+ shouldShowMcpAgentsSettings({
57
+ config: {
58
+ aiService: { url: ' ' },
59
+ backend: { type: 'shellui', url: 'https://id.example.com' },
60
+ } as ShellUIConfig,
61
+ isAuthenticated: true,
62
+ mcpEnabled: true,
63
+ }),
64
+ ).toBe(false);
65
+ });
66
+ });
@@ -0,0 +1,16 @@
1
+ import type { ShellUIConfig } from '../../config/types';
2
+ import { isMcpAgentsSettingsEligible } from './isMcpAgentsSettingsEligible';
3
+
4
+ /**
5
+ * Settings → MCP / AI agents nav is shown when an AI service URL is configured, the user
6
+ * is signed in, the shell uses a Shellui identity backend, and identity reports MCP enabled.
7
+ */
8
+ export function shouldShowMcpAgentsSettings(options: {
9
+ config: ShellUIConfig | undefined;
10
+ isAuthenticated: boolean;
11
+ /** `null` while status is loading or prerequisites are missing. */
12
+ mcpEnabled: boolean | null;
13
+ }): boolean {
14
+ if (!isMcpAgentsSettingsEligible(options)) return false;
15
+ return options.mcpEnabled === true;
16
+ }