@shellui/core 0.7.0 → 0.8.0

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  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/i18n/translations/en/settings.json +201 -0
  68. package/src/i18n/translations/fr/settings.json +201 -0
  69. package/src/index.ts +1 -0
  70. package/src/service-worker/sw.ts +4 -2
@@ -393,6 +393,34 @@ export const SparklesIcon = () => (
393
393
  </svg>
394
394
  );
395
395
 
396
+ export const McpAgentsIcon = () => (
397
+ <svg
398
+ xmlns="http://www.w3.org/2000/svg"
399
+ width="16"
400
+ height="16"
401
+ viewBox="0 0 24 24"
402
+ fill="none"
403
+ stroke="currentColor"
404
+ strokeWidth="2"
405
+ strokeLinecap="round"
406
+ strokeLinejoin="round"
407
+ >
408
+ <path d="M12 2v4" />
409
+ <path d="M12 18v4" />
410
+ <path d="M4.93 4.93l2.83 2.83" />
411
+ <path d="M16.24 16.24l2.83 2.83" />
412
+ <path d="M2 12h4" />
413
+ <path d="M18 12h4" />
414
+ <path d="M4.93 19.07l2.83-2.83" />
415
+ <path d="M16.24 7.76l2.83-2.83" />
416
+ <circle
417
+ cx="12"
418
+ cy="12"
419
+ r="3"
420
+ />
421
+ </svg>
422
+ );
423
+
396
424
  export const RefreshCwIcon = () => (
397
425
  <svg
398
426
  xmlns="http://www.w3.org/2000/svg"
@@ -9,6 +9,7 @@ import {
9
9
  RefreshDoubleIcon,
10
10
  HardDriveIcon,
11
11
  SparklesIcon,
12
+ McpAgentsIcon,
12
13
  } from './SettingsIcons';
13
14
  import { Appearance } from './components/Appearance';
14
15
  import { LanguageAndRegion } from './components/LanguageAndRegion';
@@ -20,6 +21,7 @@ import { ServiceWorker } from './components/ServiceWorker';
20
21
  import { LegalDocumentsPanel } from './components/LegalDocumentsPanel';
21
22
  import { Storage } from './components/Storage';
22
23
  import { Ai } from './components/Ai';
24
+ import { McpAgents } from './components/McpAgents';
23
25
  import { isTauri } from '../../service-worker/register';
24
26
 
25
27
  export const createSettingsRoutes = (t: (key: string) => string) => [
@@ -47,6 +49,12 @@ export const createSettingsRoutes = (t: (key: string) => string) => [
47
49
  path: 'ai',
48
50
  element: <Ai />,
49
51
  },
52
+ {
53
+ name: t('routes.mcpAgents'),
54
+ icon: McpAgentsIcon,
55
+ path: 'mcp-agents',
56
+ element: <McpAgents />,
57
+ },
50
58
  {
51
59
  name: t('routes.storage'),
52
60
  icon: HardDriveIcon,
@@ -15,6 +15,7 @@ import {
15
15
  SidebarMenu,
16
16
  SidebarMenuButton,
17
17
  SidebarMenuItem,
18
+ SidebarMenuSkeleton,
18
19
  SidebarProvider,
19
20
  } from '../../components/ui/sidebar';
20
21
  import { Route, Routes, useLocation, useNavigate, Navigate } from 'react-router';
@@ -36,6 +37,8 @@ import { useAuth } from '../auth/hooks/useAuth';
36
37
  import { getLegalDocuments } from '../legal/legalDocuments';
37
38
  import { shouldShowStorageSettings } from './utils/shouldShowStorageSettings';
38
39
  import { isAiFeatureEnabled } from '../ai/isAiFeatureEnabled';
40
+ import { useMcpPersonalStatus } from './hooks/useMcpPersonalStatus';
41
+ import { shouldShowMcpAgentsSettings } from './utils/shouldShowMcpAgentsSettings';
39
42
 
40
43
  export const SettingsView = () => {
41
44
  const location = useLocation();
@@ -45,6 +48,12 @@ export const SettingsView = () => {
45
48
  const { user, session, logout, isAuthenticated, supportsAccountDeletion, supportsProfileUpdate } =
46
49
  useAuth();
47
50
  const { t, i18n } = useTranslation('settings');
51
+ const { mcpEnabled: mcpAgentsNavEnabled, navPending: mcpAgentsNavPending } = useMcpPersonalStatus(
52
+ config,
53
+ session?.accessToken ?? null,
54
+ isAuthenticated,
55
+ user?.id ?? null,
56
+ );
48
57
  // Re-check isTauri after mount and after a short delay so we catch late-injected __TAURI__ in dev
49
58
  const [isTauriEnv, setIsTauriEnv] = useState(() => isTauri());
50
59
 
@@ -90,6 +99,15 @@ export const SettingsView = () => {
90
99
  if (!isAiFeatureEnabled(config)) {
91
100
  routes = routes.filter((route) => route.path !== 'ai');
92
101
  }
102
+ if (
103
+ !shouldShowMcpAgentsSettings({
104
+ config,
105
+ isAuthenticated,
106
+ mcpEnabled: mcpAgentsNavEnabled,
107
+ })
108
+ ) {
109
+ routes = routes.filter((route) => route.path !== 'mcp-agents');
110
+ }
93
111
  const aiEnabledForStorage = isAiFeatureEnabled(config) && settings.ai?.enabled !== false;
94
112
  if (
95
113
  !shouldShowStorageSettings({
@@ -101,7 +119,7 @@ export const SettingsView = () => {
101
119
  routes = routes.filter((route) => route.path !== 'storage');
102
120
  }
103
121
  return routes;
104
- }, [filteredRoutes, config, isAuthenticated, settings.ai?.enabled]);
122
+ }, [filteredRoutes, config, isAuthenticated, settings.ai?.enabled, mcpAgentsNavEnabled]);
105
123
 
106
124
  // Application settings from navigation items with settings URL
107
125
  const applicationRoutes = useMemo(() => {
@@ -159,9 +177,33 @@ export const SettingsView = () => {
159
177
  [userRoute, settingsNavRoutes, applicationRoutes],
160
178
  );
161
179
 
180
+ const mcpAgentsRoute = useMemo(
181
+ () => settingsNavRoutes.find((route) => route.path === 'mcp-agents'),
182
+ [settingsNavRoutes],
183
+ );
184
+
185
+ const isMcpAgentsNavSkeleton = (
186
+ item: (typeof settingsNavRoutes)[number] | { kind: 'mcp-agents-skeleton' },
187
+ ): item is { kind: 'mcp-agents-skeleton' } =>
188
+ 'kind' in item && item.kind === 'mcp-agents-skeleton';
189
+
162
190
  // Group routes by category
163
191
  const groupedRoutes = useMemo(() => {
164
192
  const developerOnlyPaths = ['developpers', 'service-worker'];
193
+ const preferenceLeadRoutes = settingsNavRoutes.filter((route) =>
194
+ ['appearance', 'language-and-region', 'data-privacy'].includes(route.path),
195
+ );
196
+ const preferenceTailRoutes = [
197
+ ...settingsNavRoutes.filter((route) => route.path === 'storage'),
198
+ ...settingsNavRoutes.filter((route) => route.path === 'ai'),
199
+ ];
200
+ const mcpAgentsNavRows =
201
+ mcpAgentsRoute !== undefined
202
+ ? [mcpAgentsRoute]
203
+ : mcpAgentsNavPending
204
+ ? [{ kind: 'mcp-agents-skeleton' as const }]
205
+ : [];
206
+
165
207
  const groups = [
166
208
  ...(applicationRoutes.length > 0
167
209
  ? [{ title: t('categories.applications'), routes: applicationRoutes }]
@@ -169,12 +211,10 @@ export const SettingsView = () => {
169
211
  {
170
212
  title: t('categories.preferences'),
171
213
  routes: [
172
- ...settingsNavRoutes.filter((route) =>
173
- ['appearance', 'language-and-region', 'data-privacy'].includes(route.path),
174
- ),
214
+ ...preferenceLeadRoutes,
175
215
  ...userRoute,
176
- ...settingsNavRoutes.filter((route) => route.path === 'storage'),
177
- ...settingsNavRoutes.filter((route) => route.path === 'ai'),
216
+ ...preferenceTailRoutes,
217
+ ...mcpAgentsNavRows,
178
218
  ],
179
219
  },
180
220
  {
@@ -189,7 +229,7 @@ export const SettingsView = () => {
189
229
  },
190
230
  ];
191
231
  return groups.filter((group) => group.routes.length > 0);
192
- }, [settingsNavRoutes, applicationRoutes, userRoute, t]);
232
+ }, [settingsNavRoutes, applicationRoutes, userRoute, t, mcpAgentsRoute, mcpAgentsNavPending]);
193
233
 
194
234
  // Find matching nav item by checking if URL contains or ends with the item path
195
235
  const getSelectedItemFromUrl = useCallback(() => {
@@ -260,26 +300,32 @@ export const SettingsView = () => {
260
300
  <SidebarGroupLabel>{group.title}</SidebarGroupLabel>
261
301
  <SidebarGroupContent>
262
302
  <SidebarMenu>
263
- {group.routes.map((item) => (
264
- <SidebarMenuItem key={item.name}>
265
- <SidebarMenuButton
266
- asChild
267
- isActive={item.name === selectedItem?.name}
268
- >
269
- <button
270
- onClick={() => navigate(`${urls.settings}/${item.path}`)}
271
- className="cursor-pointer"
303
+ {group.routes.map((item) =>
304
+ isMcpAgentsNavSkeleton(item) ? (
305
+ <SidebarMenuItem key="mcp-agents-skeleton">
306
+ <SidebarMenuSkeleton showIcon />
307
+ </SidebarMenuItem>
308
+ ) : (
309
+ <SidebarMenuItem key={item.name}>
310
+ <SidebarMenuButton
311
+ asChild
312
+ isActive={item.name === selectedItem?.name}
272
313
  >
273
- {'icon' in item && item.icon ? (
274
- <item.icon />
275
- ) : (
276
- <NavIcon src={'iconSrc' in item ? item.iconSrc : null} />
277
- )}
278
- <span>{item.name}</span>
279
- </button>
280
- </SidebarMenuButton>
281
- </SidebarMenuItem>
282
- ))}
314
+ <button
315
+ onClick={() => navigate(`${urls.settings}/${item.path}`)}
316
+ className="cursor-pointer"
317
+ >
318
+ {'icon' in item && item.icon ? (
319
+ <item.icon />
320
+ ) : (
321
+ <NavIcon src={'iconSrc' in item ? item.iconSrc : null} />
322
+ )}
323
+ <span>{item.name}</span>
324
+ </button>
325
+ </SidebarMenuButton>
326
+ </SidebarMenuItem>
327
+ ),
328
+ )}
283
329
  </SidebarMenu>
284
330
  </SidebarGroupContent>
285
331
  </SidebarGroup>
@@ -311,6 +357,24 @@ export const SettingsView = () => {
311
357
  <div className="flex flex-col bg-card rounded-lg overflow-hidden border border-border">
312
358
  {group.routes.map((item, itemIndex) => {
313
359
  const isLast = itemIndex === group.routes.length - 1;
360
+ if (isMcpAgentsNavSkeleton(item)) {
361
+ return (
362
+ <div
363
+ key="mcp-agents-skeleton"
364
+ className="relative"
365
+ >
366
+ {!isLast && (
367
+ <div className="absolute left-0 right-0 bottom-0 h-[1px] bg-border" />
368
+ )}
369
+ <div
370
+ className="w-full px-4 py-3"
371
+ aria-hidden
372
+ >
373
+ <SidebarMenuSkeleton showIcon />
374
+ </div>
375
+ </div>
376
+ );
377
+ }
314
378
  const iconEl =
315
379
  'icon' in item && item.icon ? (
316
380
  <item.icon />
@@ -0,0 +1,255 @@
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 type { McpAgentActivityRow, McpAgentSummary } from '../../mcp/personalAgentsApi';
7
+ import { McpAgentActivitySection } from './McpAgentActivitySection';
8
+
9
+ const api = vi.hoisted(() => ({
10
+ fetchMcpPersonalAgentActivity: vi.fn(),
11
+ fetchMcpPersonalAgentCallLogs: vi.fn(),
12
+ }));
13
+
14
+ vi.mock('../../mcp/personalAgentsApi', async (importOriginal) => {
15
+ const actual = await importOriginal<typeof import('../../mcp/personalAgentsApi')>();
16
+ return {
17
+ ...actual,
18
+ fetchMcpPersonalAgentActivity: api.fetchMcpPersonalAgentActivity,
19
+ fetchMcpPersonalAgentCallLogs: api.fetchMcpPersonalAgentCallLogs,
20
+ };
21
+ });
22
+
23
+ vi.mock('react-i18next', () => ({
24
+ useTranslation: () => ({
25
+ t: (key: string, opts?: Record<string, string>) => {
26
+ const parts = key.replace('mcpAgents.', '').split('.');
27
+ let raw: unknown = en.mcpAgents;
28
+ for (const part of parts) {
29
+ if (raw && typeof raw === 'object' && part in raw) {
30
+ raw = (raw as Record<string, unknown>)[part];
31
+ } else {
32
+ raw = key;
33
+ break;
34
+ }
35
+ }
36
+ const text = typeof raw === 'string' ? raw : key;
37
+ return text.replace(/\{\{(\w+)\}\}/g, (_, name: string) => String(opts?.[name] ?? ''));
38
+ },
39
+ i18n: { language: 'en' },
40
+ }),
41
+ }));
42
+
43
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
44
+
45
+ const agent: McpAgentSummary = {
46
+ id: 'agent-1',
47
+ kind: 'oauth',
48
+ name: 'Laptop',
49
+ accessMode: 'ask',
50
+ readLevel: 'safe',
51
+ allowDestructiveWithoutAsking: false,
52
+ servicesAllowed: ['storage'],
53
+ expiresAt: null,
54
+ pausedAt: null,
55
+ revokedAt: null,
56
+ isActive: true,
57
+ createdAt: '2026-01-01T00:00:00Z',
58
+ oauthClientId: 'client-1',
59
+ personalTokenId: null,
60
+ };
61
+
62
+ const activity = (overrides: Partial<McpAgentActivityRow>): McpAgentActivityRow => ({
63
+ timestamp: '2026-06-01T00:00:00Z',
64
+ tool: 'storage_list_bucket',
65
+ service: 'storage',
66
+ result: 'ok',
67
+ clientIp: '203.0.113.4',
68
+ companyId: '1',
69
+ companyLabel: 'Acme',
70
+ resourceLabel: null,
71
+ operationTitle: 'List bucket',
72
+ actorLabel: null,
73
+ agentName: null,
74
+ accessKind: 'read',
75
+ durationMs: 12,
76
+ outcome: 'allowed',
77
+ approvalRequestId: null,
78
+ errorCode: null,
79
+ ...overrides,
80
+ });
81
+
82
+ let container: HTMLDivElement;
83
+ let root: Root;
84
+
85
+ beforeEach(() => {
86
+ api.fetchMcpPersonalAgentActivity.mockReset();
87
+ api.fetchMcpPersonalAgentCallLogs.mockReset();
88
+ container = document.createElement('div');
89
+ document.body.appendChild(container);
90
+ root = createRoot(container);
91
+ });
92
+
93
+ afterEach(() => {
94
+ act(() => root.unmount());
95
+ container.remove();
96
+ });
97
+
98
+ async function openActivity() {
99
+ await act(async () => {
100
+ root.render(
101
+ <McpAgentActivitySection
102
+ backendUrl="https://id.example"
103
+ aiServiceUrl="https://ai.example"
104
+ accessToken="tok"
105
+ companyId="1"
106
+ enabled
107
+ agent={agent}
108
+ pendingApprovals={[]}
109
+ onJumpToApprovals={() => {}}
110
+ />,
111
+ );
112
+ });
113
+ const show = Array.from(container.querySelectorAll('button')).find(
114
+ (button) => button.textContent === 'Show activity',
115
+ );
116
+ expect(show).toBeTruthy();
117
+ await act(async () => {
118
+ show?.click();
119
+ });
120
+ await act(async () => {
121
+ await Promise.resolve();
122
+ await Promise.resolve();
123
+ });
124
+ }
125
+
126
+ describe('McpAgentActivitySection', () => {
127
+ it('merges consent with call logs and shows wrapper, error, and approval', async () => {
128
+ api.fetchMcpPersonalAgentActivity.mockResolvedValue([
129
+ activity({
130
+ timestamp: '2026-06-02T00:00:00Z',
131
+ tool: 'identity_list_users',
132
+ operationTitle: 'List members',
133
+ service: 'identity',
134
+ }),
135
+ activity({
136
+ timestamp: '2026-06-03T00:00:00Z',
137
+ tool: 'oauth.authorize.approved',
138
+ operationTitle: 'oauth.authorize.approved',
139
+ service: 'identity',
140
+ companyLabel: null,
141
+ }),
142
+ ]);
143
+ api.fetchMcpPersonalAgentCallLogs.mockResolvedValue({
144
+ count: 1,
145
+ limit: 50,
146
+ offset: 0,
147
+ callLogs: [
148
+ activity({
149
+ timestamp: '2026-06-04T00:00:00Z',
150
+ tool: 'storage_get',
151
+ operationTitle: 'Read object',
152
+ result: 'failed',
153
+ outcome: 'failed',
154
+ errorCode: 'downstream_error',
155
+ errorMessage: 'Upstream timed out',
156
+ wrapperTool: 'ai_call_tool',
157
+ approvalOutcome: 'accepted',
158
+ companyLabel: null,
159
+ clientIp: null,
160
+ actorLabel: 'dev@example.com',
161
+ }),
162
+ ],
163
+ });
164
+
165
+ await openActivity();
166
+
167
+ expect(container.textContent).toContain('Read object');
168
+ expect(container.textContent).toContain('OAuth consent approved');
169
+ expect(container.textContent).not.toContain('List members');
170
+ expect(container.textContent).toContain('via ai_call_tool');
171
+ expect(container.textContent).toContain('Upstream timed out');
172
+ expect(container.textContent).toContain('Accepted');
173
+ expect(container.textContent).toContain('dev@example.com');
174
+ expect(container.textContent).not.toContain('Acme');
175
+ expect(api.fetchMcpPersonalAgentCallLogs).toHaveBeenCalledWith(
176
+ 'https://ai.example',
177
+ 'tok',
178
+ 'agent-1',
179
+ { limit: 50, offset: 0 },
180
+ );
181
+ });
182
+
183
+ it('keeps consent rows when ai-service is unreachable', async () => {
184
+ api.fetchMcpPersonalAgentActivity.mockResolvedValue([
185
+ activity({
186
+ tool: 'oauth.device.approved',
187
+ operationTitle: 'oauth.device.approved',
188
+ service: 'identity',
189
+ }),
190
+ ]);
191
+ api.fetchMcpPersonalAgentCallLogs.mockRejectedValue(new Error('network down'));
192
+
193
+ await openActivity();
194
+
195
+ expect(container.textContent).toContain('Device login approved');
196
+ expect(container.textContent).toContain('Tool calls could not be loaded.');
197
+ expect(container.textContent).not.toContain('Unable to load activity.');
198
+ });
199
+
200
+ it('loads the next call-log page with offset', async () => {
201
+ api.fetchMcpPersonalAgentActivity.mockResolvedValue([]);
202
+ api.fetchMcpPersonalAgentCallLogs
203
+ .mockResolvedValueOnce({
204
+ count: 60,
205
+ limit: 50,
206
+ offset: 0,
207
+ callLogs: [
208
+ activity({
209
+ timestamp: '2026-06-04T00:00:00Z',
210
+ tool: 'storage_get',
211
+ operationTitle: 'Read object',
212
+ }),
213
+ ],
214
+ })
215
+ .mockResolvedValueOnce({
216
+ count: 60,
217
+ limit: 50,
218
+ offset: 50,
219
+ callLogs: [
220
+ activity({
221
+ timestamp: '2026-06-01T00:00:00Z',
222
+ tool: 'storage_delete',
223
+ operationTitle: 'Delete object',
224
+ }),
225
+ ],
226
+ });
227
+
228
+ await openActivity();
229
+ expect(container.textContent).toContain('Read object');
230
+ expect(container.textContent).not.toContain('Delete object');
231
+
232
+ const more = Array.from(container.querySelectorAll('button')).find(
233
+ (button) => button.textContent === 'Load more',
234
+ );
235
+ expect(more).toBeTruthy();
236
+ await act(async () => {
237
+ more?.click();
238
+ });
239
+ await act(async () => {
240
+ await Promise.resolve();
241
+ await Promise.resolve();
242
+ });
243
+
244
+ expect(api.fetchMcpPersonalAgentCallLogs).toHaveBeenLastCalledWith(
245
+ 'https://ai.example',
246
+ 'tok',
247
+ 'agent-1',
248
+ { limit: 50, offset: 50 },
249
+ );
250
+ expect(container.textContent).toContain('Delete object');
251
+ expect(container.textContent?.indexOf('Read object')).toBeLessThan(
252
+ container.textContent?.indexOf('Delete object') ?? -1,
253
+ );
254
+ });
255
+ });