@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.
- package/LICENSE +21 -0
- package/README.md +3 -1
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +45 -2
- package/src/app.tsx +2 -0
- package/src/features/auth/AuthProvider.tsx +212 -97
- package/src/features/auth/appBackend/configSchema.spec.ts +1 -0
- package/src/features/auth/appBackend/frameAuth.ts +5 -0
- package/src/features/auth/backends/shellui.spec.ts +110 -0
- package/src/features/auth/backends/shellui.ts +47 -20
- package/src/features/auth/backends/types.ts +5 -0
- package/src/features/auth/hooks/useAuth.tsx +6 -1
- package/src/features/auth/types.ts +5 -0
- package/src/features/auth/utils/bffAuthClient.spec.ts +313 -0
- package/src/features/auth/utils/bffAuthClient.ts +171 -49
- package/src/features/auth/utils/buildSessionFromParams.ts +5 -2
- package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +12 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.ts +3 -1
- package/src/features/auth/utils/canRestoreStoredSession.spec.ts +140 -4
- package/src/features/auth/utils/canRestoreStoredSession.ts +47 -0
- package/src/features/auth/utils/cliCallback.ts +5 -0
- package/src/features/auth/utils/identityBrowserLogout.spec.ts +185 -0
- package/src/features/auth/utils/identityBrowserLogout.ts +174 -0
- package/src/features/auth/utils/index.ts +21 -3
- package/src/features/auth/utils/isBffAuthEnabled.ts +10 -2
- package/src/features/auth/utils/normalizeAuthSettings.spec.ts +9 -0
- package/src/features/auth/utils/normalizeAuthSettings.ts +3 -1
- package/src/features/auth/utils/pkce.spec.ts +29 -1
- package/src/features/auth/utils/pkce.ts +106 -2
- package/src/features/config/types.ts +37 -5
- package/src/features/mcp/mcpActivityErrorCodeI18n.spec.ts +32 -0
- package/src/features/mcp/mcpActivityErrorCodeI18n.ts +30 -0
- package/src/features/mcp/mcpAgentActivityMerge.spec.ts +91 -0
- package/src/features/mcp/mcpAgentActivityMerge.ts +53 -0
- package/src/features/mcp/mcpAgentActivityPresentation.spec.ts +129 -0
- package/src/features/mcp/mcpAgentActivityPresentation.ts +201 -0
- package/src/features/mcp/mcpAgentsConnect.spec.ts +215 -0
- package/src/features/mcp/mcpAgentsConnect.ts +189 -0
- package/src/features/mcp/mcpToolActivityRegistry.spec.ts +9 -0
- package/src/features/mcp/mcpToolActivityRegistry.ts +20 -0
- package/src/features/mcp/mcpToolApprovalsApi.spec.ts +113 -0
- package/src/features/mcp/mcpToolApprovalsApi.ts +162 -0
- package/src/features/mcp/personalAgentsApi.spec.ts +661 -0
- package/src/features/mcp/personalAgentsApi.ts +697 -0
- package/src/features/settings/SettingsIcons.tsx +28 -0
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +90 -26
- package/src/features/settings/components/McpAgentActivitySection.spec.tsx +255 -0
- package/src/features/settings/components/McpAgentActivitySection.tsx +481 -0
- package/src/features/settings/components/McpAgents.spec.tsx +336 -0
- package/src/features/settings/components/McpAgents.tsx +654 -0
- package/src/features/settings/components/McpPendingApprovals.spec.tsx +201 -0
- package/src/features/settings/components/McpPendingApprovals.tsx +168 -0
- package/src/features/settings/components/McpPersonalStatusPrefetch.tsx +21 -0
- package/src/features/settings/hooks/useMcpPendingToolApprovals.ts +69 -0
- package/src/features/settings/hooks/useMcpPersonalStatus.ts +83 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +44 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +30 -1
- package/src/features/settings/utils/isMcpAgentsSettingsEligible.spec.ts +25 -0
- package/src/features/settings/utils/isMcpAgentsSettingsEligible.ts +14 -0
- package/src/features/settings/utils/loadMcpPersonalStatus.spec.ts +76 -0
- package/src/features/settings/utils/loadMcpPersonalStatus.ts +84 -0
- package/src/features/settings/utils/mcpPersonalStatusCache.spec.ts +77 -0
- package/src/features/settings/utils/mcpPersonalStatusCache.ts +95 -0
- package/src/features/settings/utils/shouldShowMcpAgentsSettings.spec.ts +66 -0
- package/src/features/settings/utils/shouldShowMcpAgentsSettings.ts +16 -0
- package/src/features/storage/StorageBridge.paths.spec.ts +286 -0
- package/src/features/storage/StorageBridge.tsx +25 -5
- package/src/features/storage/resolveStorageBridgeTarget.spec.ts +51 -0
- package/src/features/storage/resolveStorageBridgeTarget.ts +24 -0
- package/src/i18n/translations/en/settings.json +201 -0
- package/src/i18n/translations/fr/settings.json +201 -0
- package/src/index.ts +1 -0
- package/src/service-worker/sw.ts +4 -2
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import en from '../../../i18n/translations/en/settings.json';
|
|
6
|
+
import fr from '../../../i18n/translations/fr/settings.json';
|
|
7
|
+
import {
|
|
8
|
+
MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS,
|
|
9
|
+
agentPromptContainsCredentialMaterial,
|
|
10
|
+
buildAgentPrompt,
|
|
11
|
+
} from '../../mcp/mcpAgentsConnect';
|
|
12
|
+
import type { McpAgentSummary } from '../../mcp/personalAgentsApi';
|
|
13
|
+
import { McpAgents } from './McpAgents';
|
|
14
|
+
|
|
15
|
+
const page = vi.hoisted(() => ({
|
|
16
|
+
language: 'en',
|
|
17
|
+
aiUrl: 'https://ai.example/' as string | null,
|
|
18
|
+
visibility: 'visible',
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const api = vi.hoisted(() => ({
|
|
22
|
+
fetchMcpPersonalAgents: vi.fn(),
|
|
23
|
+
createMcpPersonalAgent: vi.fn(),
|
|
24
|
+
revokeMcpPersonalAgent: vi.fn(),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const dialogMock = vi.hoisted(() => vi.fn());
|
|
28
|
+
const toastMock = vi.hoisted(() => vi.fn());
|
|
29
|
+
const writeText = vi.hoisted(() => vi.fn());
|
|
30
|
+
|
|
31
|
+
vi.mock('../../mcp/personalAgentsApi', async (importOriginal) => {
|
|
32
|
+
const actual = await importOriginal<typeof import('../../mcp/personalAgentsApi')>();
|
|
33
|
+
return {
|
|
34
|
+
...actual,
|
|
35
|
+
fetchMcpPersonalAgents: api.fetchMcpPersonalAgents,
|
|
36
|
+
createMcpPersonalAgent: api.createMcpPersonalAgent,
|
|
37
|
+
revokeMcpPersonalAgent: api.revokeMcpPersonalAgent,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
vi.mock('../../config/useConfig', () => ({
|
|
42
|
+
useConfig: () => ({
|
|
43
|
+
config: {
|
|
44
|
+
title: 'Acme',
|
|
45
|
+
backend: { type: 'shellui', url: 'https://id.example', companyId: '42' },
|
|
46
|
+
...(page.aiUrl ? { aiService: { url: page.aiUrl } } : {}),
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
vi.mock('../../auth/hooks/useAuth', () => ({
|
|
52
|
+
useAuth: () => ({
|
|
53
|
+
isAuthenticated: true,
|
|
54
|
+
session: { accessToken: 'session-token' },
|
|
55
|
+
user: { id: 'user-1' },
|
|
56
|
+
}),
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
vi.mock('../hooks/useMcpPersonalStatus', () => ({
|
|
60
|
+
useMcpPersonalStatus: () => ({
|
|
61
|
+
status: {
|
|
62
|
+
mcpEnabled: true,
|
|
63
|
+
mcpUrl: null,
|
|
64
|
+
globalMcpUrl: 'https://saas.example/mcp',
|
|
65
|
+
globalIdentity: false,
|
|
66
|
+
},
|
|
67
|
+
loading: false,
|
|
68
|
+
error: false,
|
|
69
|
+
refresh: vi.fn(),
|
|
70
|
+
}),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
vi.mock('../hooks/useMcpPendingToolApprovals', () => ({
|
|
74
|
+
useMcpPendingToolApprovals: () => ({
|
|
75
|
+
approvals: [],
|
|
76
|
+
pendingCount: 0,
|
|
77
|
+
refresh: vi.fn(),
|
|
78
|
+
}),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
vi.mock('react-i18next', () => ({
|
|
82
|
+
useTranslation: () => ({
|
|
83
|
+
t: (key: string, opts?: Record<string, string | number>) => {
|
|
84
|
+
const catalog = page.language.startsWith('fr') ? fr : en;
|
|
85
|
+
const parts = key.replace('mcpAgents.', '').split('.');
|
|
86
|
+
let raw: unknown = catalog.mcpAgents;
|
|
87
|
+
for (const part of parts) {
|
|
88
|
+
if (raw && typeof raw === 'object' && part in raw) {
|
|
89
|
+
raw = (raw as Record<string, unknown>)[part];
|
|
90
|
+
} else {
|
|
91
|
+
raw = key;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const text = typeof raw === 'string' ? raw : key;
|
|
96
|
+
return text.replace(/\{\{(\w+)\}\}/g, (_, name: string) => String(opts?.[name] ?? ''));
|
|
97
|
+
},
|
|
98
|
+
i18n: {
|
|
99
|
+
get language() {
|
|
100
|
+
return page.language;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
vi.mock('@shellui/sdk', async (importOriginal) => {
|
|
107
|
+
const actual = await importOriginal<typeof import('@shellui/sdk')>();
|
|
108
|
+
return {
|
|
109
|
+
...actual,
|
|
110
|
+
shellui: {
|
|
111
|
+
...actual.shellui,
|
|
112
|
+
dialog: (...args: unknown[]) => dialogMock(...args),
|
|
113
|
+
toast: (...args: unknown[]) => toastMock(...args),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
119
|
+
|
|
120
|
+
const MCP_URL = 'https://ai.example/c/42/mcp';
|
|
121
|
+
|
|
122
|
+
function connection(overrides: Partial<McpAgentSummary> = {}): McpAgentSummary {
|
|
123
|
+
return {
|
|
124
|
+
id: 'oauth-1',
|
|
125
|
+
kind: 'oauth',
|
|
126
|
+
name: 'Cursor on my laptop',
|
|
127
|
+
accessMode: 'ask',
|
|
128
|
+
readLevel: 'safe',
|
|
129
|
+
allowDestructiveWithoutAsking: false,
|
|
130
|
+
servicesAllowed: ['identity', 'storage'],
|
|
131
|
+
expiresAt: '2026-12-01T00:00:00.000Z',
|
|
132
|
+
pausedAt: null,
|
|
133
|
+
revokedAt: null,
|
|
134
|
+
isActive: true,
|
|
135
|
+
createdAt: '2026-06-01T00:00:00.000Z',
|
|
136
|
+
oauthClientId: 'client-1',
|
|
137
|
+
personalTokenId: null,
|
|
138
|
+
...overrides,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let container: HTMLDivElement;
|
|
143
|
+
let root: Root;
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
page.language = 'en';
|
|
147
|
+
page.aiUrl = 'https://ai.example/';
|
|
148
|
+
page.visibility = 'visible';
|
|
149
|
+
Object.defineProperty(document, 'visibilityState', {
|
|
150
|
+
configurable: true,
|
|
151
|
+
get: () => page.visibility,
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(navigator, 'clipboard', {
|
|
154
|
+
configurable: true,
|
|
155
|
+
value: { writeText },
|
|
156
|
+
});
|
|
157
|
+
writeText.mockReset();
|
|
158
|
+
writeText.mockResolvedValue(undefined);
|
|
159
|
+
dialogMock.mockReset();
|
|
160
|
+
toastMock.mockReset();
|
|
161
|
+
api.fetchMcpPersonalAgents.mockReset();
|
|
162
|
+
api.createMcpPersonalAgent.mockReset();
|
|
163
|
+
api.revokeMcpPersonalAgent.mockReset();
|
|
164
|
+
api.fetchMcpPersonalAgents.mockResolvedValue([]);
|
|
165
|
+
container = document.createElement('div');
|
|
166
|
+
document.body.appendChild(container);
|
|
167
|
+
root = createRoot(container);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
afterEach(() => {
|
|
171
|
+
act(() => root.unmount());
|
|
172
|
+
container.remove();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
async function renderPage() {
|
|
176
|
+
await act(async () => {
|
|
177
|
+
root.render(<McpAgents />);
|
|
178
|
+
});
|
|
179
|
+
await act(async () => {
|
|
180
|
+
await Promise.resolve();
|
|
181
|
+
await Promise.resolve();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function buttonByText(label: string): HTMLButtonElement | undefined {
|
|
186
|
+
return Array.from(container.querySelectorAll('button')).find((btn) => btn.textContent === label);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
describe('McpAgents connect prompt', () => {
|
|
190
|
+
it('shows the company MCP URL, the OAuth prompt, and the three steps', async () => {
|
|
191
|
+
await renderPage();
|
|
192
|
+
|
|
193
|
+
expect(container.textContent).toContain('Connect an agent');
|
|
194
|
+
expect(container.textContent).toContain(MCP_URL);
|
|
195
|
+
expect(container.textContent).toContain('Paste the prompt into your agent.');
|
|
196
|
+
expect(container.textContent).toContain('Open the link it shows.');
|
|
197
|
+
expect(container.textContent).toContain('Check the code and choose Allow.');
|
|
198
|
+
|
|
199
|
+
const prompt = container.querySelector('pre')?.textContent ?? '';
|
|
200
|
+
expect(prompt).toBe(buildAgentPrompt(MCP_URL, 'en'));
|
|
201
|
+
expect(prompt).not.toContain('session-token');
|
|
202
|
+
expect(agentPromptContainsCredentialMaterial(prompt.replace(MCP_URL, ''))).toBe(false);
|
|
203
|
+
|
|
204
|
+
const details = container.querySelector('details');
|
|
205
|
+
expect(details).toBeTruthy();
|
|
206
|
+
expect(details?.open).toBe(false);
|
|
207
|
+
expect(details?.textContent).toContain('Clients that only accept a static secret');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('copies the prompt and the URL without a secret', async () => {
|
|
211
|
+
await renderPage();
|
|
212
|
+
|
|
213
|
+
await act(async () => {
|
|
214
|
+
buttonByText('Copy prompt')?.click();
|
|
215
|
+
await Promise.resolve();
|
|
216
|
+
});
|
|
217
|
+
expect(writeText).toHaveBeenCalledWith(buildAgentPrompt(MCP_URL, 'en'));
|
|
218
|
+
|
|
219
|
+
await act(async () => {
|
|
220
|
+
buttonByText('Copy URL')?.click();
|
|
221
|
+
await Promise.resolve();
|
|
222
|
+
});
|
|
223
|
+
expect(writeText).toHaveBeenCalledWith(MCP_URL);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('shows the French prompt and steps', async () => {
|
|
227
|
+
page.language = 'fr';
|
|
228
|
+
await renderPage();
|
|
229
|
+
|
|
230
|
+
const prompt = container.querySelector('pre')?.textContent ?? '';
|
|
231
|
+
expect(prompt).toBe(buildAgentPrompt(MCP_URL, 'fr'));
|
|
232
|
+
expect(container.textContent).toContain("Collez l'invite dans votre agent.");
|
|
233
|
+
expect(container.textContent).toContain("Ouvrez le lien qu'il affiche.");
|
|
234
|
+
expect(container.textContent).toContain('Vérifiez le code, puis choisissez Autoriser.');
|
|
235
|
+
expect(agentPromptContainsCredentialMaterial(prompt.replace(MCP_URL, ''))).toBe(false);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('explains when the MCP URL is missing', async () => {
|
|
239
|
+
page.aiUrl = null;
|
|
240
|
+
await renderPage();
|
|
241
|
+
|
|
242
|
+
expect(container.textContent).toContain('MCP URL is not configured.');
|
|
243
|
+
expect(container.querySelector('pre')).toBeNull();
|
|
244
|
+
expect(buttonByText('Copy prompt')).toBeUndefined();
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('McpAgents static secret', () => {
|
|
249
|
+
it('keeps the secret out of the prompt and inside the 90-day cap', async () => {
|
|
250
|
+
api.createMcpPersonalAgent.mockResolvedValue({
|
|
251
|
+
agent: connection({
|
|
252
|
+
id: 'personal-1',
|
|
253
|
+
kind: 'personal',
|
|
254
|
+
name: 'Laptop agent',
|
|
255
|
+
oauthClientId: null,
|
|
256
|
+
personalTokenId: 'pt-1',
|
|
257
|
+
servicesAllowed: ['identity', 'storage', 'hosting', 'email'],
|
|
258
|
+
}),
|
|
259
|
+
accessToken: 'static-secret-value',
|
|
260
|
+
tokenType: 'Bearer',
|
|
261
|
+
expiresAt: '2027-02-01T00:00:00.000Z',
|
|
262
|
+
resource: MCP_URL,
|
|
263
|
+
});
|
|
264
|
+
api.fetchMcpPersonalAgents.mockResolvedValue([]);
|
|
265
|
+
|
|
266
|
+
await renderPage();
|
|
267
|
+
expect(container.textContent).not.toContain('static-secret-value');
|
|
268
|
+
|
|
269
|
+
await act(async () => {
|
|
270
|
+
buttonByText('Create secret')?.click();
|
|
271
|
+
await Promise.resolve();
|
|
272
|
+
await Promise.resolve();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const input = api.createMcpPersonalAgent.mock.calls[0]?.[3] as { expiresAt?: string };
|
|
276
|
+
const lifetimeMs = Date.parse(input.expiresAt ?? '') - Date.now();
|
|
277
|
+
expect(lifetimeMs).toBeLessThan(MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS * 86_400_000);
|
|
278
|
+
expect(lifetimeMs).toBeGreaterThan(89 * 86_400_000);
|
|
279
|
+
|
|
280
|
+
expect(container.textContent).toContain('static-secret-value');
|
|
281
|
+
expect(container.textContent).toContain('Shellui shows it only once.');
|
|
282
|
+
const prompt = container.querySelector('pre')?.textContent ?? '';
|
|
283
|
+
expect(prompt).toBe(buildAgentPrompt(MCP_URL, 'en'));
|
|
284
|
+
expect(prompt).not.toContain('static-secret-value');
|
|
285
|
+
expect(container.querySelector('details')?.open).toBe(true);
|
|
286
|
+
|
|
287
|
+
await act(async () => {
|
|
288
|
+
buttonByText('Hide secret')?.click();
|
|
289
|
+
});
|
|
290
|
+
expect(container.textContent).not.toContain('static-secret-value');
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe('McpAgents connections', () => {
|
|
295
|
+
it('renders an OAuth connection and reloads when the tab is visible again', async () => {
|
|
296
|
+
const oauth = connection();
|
|
297
|
+
api.fetchMcpPersonalAgents.mockResolvedValueOnce([]).mockResolvedValue([oauth]);
|
|
298
|
+
|
|
299
|
+
await renderPage();
|
|
300
|
+
expect(container.textContent).toContain('No active connections.');
|
|
301
|
+
|
|
302
|
+
page.visibility = 'visible';
|
|
303
|
+
await act(async () => {
|
|
304
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
305
|
+
await Promise.resolve();
|
|
306
|
+
await Promise.resolve();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(container.textContent).toContain('Cursor on my laptop');
|
|
310
|
+
expect(container.textContent).toContain('Signed in with OAuth');
|
|
311
|
+
expect(container.textContent).toContain('Expires');
|
|
312
|
+
expect(container.textContent).toContain('Services: identity, storage');
|
|
313
|
+
expect(buttonByText('Revoke')).toBeTruthy();
|
|
314
|
+
expect(container.textContent).not.toContain('All regional services');
|
|
315
|
+
|
|
316
|
+
const personal = connection({
|
|
317
|
+
id: 'personal-2',
|
|
318
|
+
kind: 'personal',
|
|
319
|
+
name: 'Static laptop',
|
|
320
|
+
oauthClientId: null,
|
|
321
|
+
personalTokenId: 'pt-2',
|
|
322
|
+
servicesAllowed: ['identity'],
|
|
323
|
+
});
|
|
324
|
+
api.fetchMcpPersonalAgents.mockResolvedValue([personal]);
|
|
325
|
+
await act(async () => {
|
|
326
|
+
window.dispatchEvent(new Event('focus'));
|
|
327
|
+
await Promise.resolve();
|
|
328
|
+
await Promise.resolve();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
expect(container.textContent).toContain('Static laptop');
|
|
332
|
+
expect(container.textContent).toContain('Static secret');
|
|
333
|
+
expect(container.textContent).toContain('All regional services');
|
|
334
|
+
expect(buttonByText('Revoke')).toBeTruthy();
|
|
335
|
+
});
|
|
336
|
+
});
|