@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,215 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import en from '../../i18n/translations/en/settings.json';
|
|
3
|
+
import fr from '../../i18n/translations/fr/settings.json';
|
|
4
|
+
import {
|
|
5
|
+
AGENT_CONNECT_STEPS,
|
|
6
|
+
MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS,
|
|
7
|
+
agentIncludesSaasScope,
|
|
8
|
+
agentPromptContainsCredentialMaterial,
|
|
9
|
+
buildAgentPrompt,
|
|
10
|
+
buildCompanyMcpUrl,
|
|
11
|
+
defaultPersonalAgentExpiresAt,
|
|
12
|
+
formatDefaultAgentName,
|
|
13
|
+
getDefaultPersonalAgentServices,
|
|
14
|
+
isAbsoluteHttpUrl,
|
|
15
|
+
isActiveMcpConnection,
|
|
16
|
+
isGlobalIdentitySession,
|
|
17
|
+
resolveAgentConnectPromptLocale,
|
|
18
|
+
} from './mcpAgentsConnect';
|
|
19
|
+
import type { McpAgentSummary } from './personalAgentsApi';
|
|
20
|
+
|
|
21
|
+
describe('buildCompanyMcpUrl', () => {
|
|
22
|
+
it('builds /c/{company}/mcp on the ai host', () => {
|
|
23
|
+
expect(buildCompanyMcpUrl('http://localhost:8006/', '42')).toBe(
|
|
24
|
+
'http://localhost:8006/c/42/mcp',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('falls back to identity status url when ai url is missing', () => {
|
|
29
|
+
expect(buildCompanyMcpUrl(null, '1', 'https://ai.test/c/1/mcp')).toBe(
|
|
30
|
+
'https://ai.test/c/1/mcp',
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('isGlobalIdentitySession', () => {
|
|
36
|
+
it('reads globalIdentity from status when present', () => {
|
|
37
|
+
expect(
|
|
38
|
+
isGlobalIdentitySession({
|
|
39
|
+
mcpEnabled: true,
|
|
40
|
+
mcpUrl: null,
|
|
41
|
+
globalMcpUrl: null,
|
|
42
|
+
globalIdentity: false,
|
|
43
|
+
}),
|
|
44
|
+
).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('is false when globalIdentity is omitted or false', () => {
|
|
48
|
+
expect(isGlobalIdentitySession({ mcpEnabled: true, mcpUrl: null, globalMcpUrl: null })).toBe(
|
|
49
|
+
false,
|
|
50
|
+
);
|
|
51
|
+
expect(isGlobalIdentitySession(null)).toBe(false);
|
|
52
|
+
expect(
|
|
53
|
+
isGlobalIdentitySession({
|
|
54
|
+
mcpEnabled: true,
|
|
55
|
+
mcpUrl: null,
|
|
56
|
+
globalMcpUrl: null,
|
|
57
|
+
globalIdentity: true,
|
|
58
|
+
}),
|
|
59
|
+
).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('getDefaultPersonalAgentServices', () => {
|
|
64
|
+
it('includes every regional service and optional saas', () => {
|
|
65
|
+
expect(getDefaultPersonalAgentServices(false)).toEqual([
|
|
66
|
+
'identity',
|
|
67
|
+
'storage',
|
|
68
|
+
'hosting',
|
|
69
|
+
'email',
|
|
70
|
+
]);
|
|
71
|
+
expect(getDefaultPersonalAgentServices(true)).toContain('saas');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('isAbsoluteHttpUrl', () => {
|
|
76
|
+
it('accepts http and https and rejects relative paths', () => {
|
|
77
|
+
expect(isAbsoluteHttpUrl('https://ai.test/c/1/mcp')).toBe(true);
|
|
78
|
+
expect(isAbsoluteHttpUrl('http://localhost:8006/c/1/mcp')).toBe(true);
|
|
79
|
+
expect(isAbsoluteHttpUrl('/c/1/mcp')).toBe(false);
|
|
80
|
+
expect(isAbsoluteHttpUrl('')).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('resolveAgentConnectPromptLocale', () => {
|
|
85
|
+
it('selects French only for fr language tags', () => {
|
|
86
|
+
expect(resolveAgentConnectPromptLocale('fr')).toBe('fr');
|
|
87
|
+
expect(resolveAgentConnectPromptLocale('fr-CA')).toBe('fr');
|
|
88
|
+
expect(resolveAgentConnectPromptLocale('en-US')).toBe('en');
|
|
89
|
+
expect(resolveAgentConnectPromptLocale(null)).toBe('en');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('buildAgentPrompt', () => {
|
|
94
|
+
const mcpUrl = 'https://ai.test/c/1/mcp';
|
|
95
|
+
const english = [
|
|
96
|
+
'Connect to this Shellui company over MCP.',
|
|
97
|
+
'',
|
|
98
|
+
`MCP URL: ${mcpUrl}`,
|
|
99
|
+
'',
|
|
100
|
+
'Add this URL as a remote MCP server and sign in with OAuth.',
|
|
101
|
+
'If this client is headless or a CLI, use device login.',
|
|
102
|
+
'Show the link and the code, then wait until I approve them.',
|
|
103
|
+
].join('\n');
|
|
104
|
+
const french = [
|
|
105
|
+
'Connectez cette entreprise Shellui en MCP.',
|
|
106
|
+
'',
|
|
107
|
+
`URL MCP : ${mcpUrl}`,
|
|
108
|
+
'',
|
|
109
|
+
'Ajoutez cette URL comme serveur MCP distant et connectez-vous avec OAuth.',
|
|
110
|
+
'Si le client est sans interface ou en ligne de commande, utilisez device login.',
|
|
111
|
+
'Montrez le lien et le code, puis attendez que je les approuve.',
|
|
112
|
+
].join('\n');
|
|
113
|
+
|
|
114
|
+
it('uses the English OAuth prompt and the company MCP URL', () => {
|
|
115
|
+
expect(buildAgentPrompt(mcpUrl)).toBe(english);
|
|
116
|
+
expect(buildAgentPrompt(mcpUrl, 'en')).toBe(english);
|
|
117
|
+
expect(buildAgentPrompt(` ${mcpUrl} `, 'en')).toBe(english);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('uses the French OAuth prompt for fr', () => {
|
|
121
|
+
expect(buildAgentPrompt(mcpUrl, 'fr')).toBe(french);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('does not interpolate a token passed in place of the locale', () => {
|
|
125
|
+
const leaked = 'shh-static-secret-value';
|
|
126
|
+
const prompt = buildAgentPrompt(mcpUrl, leaked as 'en');
|
|
127
|
+
expect(prompt).toBe(english);
|
|
128
|
+
expect(prompt).not.toContain(leaked);
|
|
129
|
+
expect(agentPromptContainsCredentialMaterial(prompt.replace(mcpUrl, ''))).toBe(false);
|
|
130
|
+
expect(agentPromptContainsCredentialMaterial(french.replace(mcpUrl, ''))).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('rejects a URL that is not absolute http(s)', () => {
|
|
134
|
+
expect(() => buildAgentPrompt('/c/1/mcp')).toThrow(/absolute http/);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('matches the settings steps the page renders', () => {
|
|
138
|
+
expect(Object.values(en.mcpAgents.connect.steps)).toEqual([...AGENT_CONNECT_STEPS.en]);
|
|
139
|
+
expect(Object.values(fr.mcpAgents.connect.steps)).toEqual([...AGENT_CONNECT_STEPS.fr]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
function translationKeyPaths(value: unknown, prefix = ''): string[] {
|
|
144
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
145
|
+
return [prefix];
|
|
146
|
+
}
|
|
147
|
+
return Object.entries(value).flatMap(([key, child]) =>
|
|
148
|
+
translationKeyPaths(child, prefix ? `${prefix}.${key}` : key),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
describe('mcpAgents translations', () => {
|
|
153
|
+
it('keeps English and French keys aligned', () => {
|
|
154
|
+
expect(translationKeyPaths(en.mcpAgents).sort()).toEqual(
|
|
155
|
+
translationKeyPaths(fr.mcpAgents).sort(),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('defaultPersonalAgentExpiresAt', () => {
|
|
161
|
+
it('stays inside Identity default maximum of 90 days', () => {
|
|
162
|
+
const fromMs = Date.parse('2026-11-09T17:05:00.000Z');
|
|
163
|
+
const expiresMs = Date.parse(defaultPersonalAgentExpiresAt(fromMs));
|
|
164
|
+
const maxMs = fromMs + MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS * 86_400_000;
|
|
165
|
+
expect(expiresMs).toBeLessThan(maxMs);
|
|
166
|
+
expect(maxMs - expiresMs).toBe(60_000);
|
|
167
|
+
expect(expiresMs - fromMs).toBeLessThan(365 * 86_400_000);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('formatDefaultAgentName', () => {
|
|
172
|
+
it('uses Agent · short date', () => {
|
|
173
|
+
expect(formatDefaultAgentName('en-US', new Date('2026-11-05T12:00:00Z'))).toMatch(
|
|
174
|
+
/^Agent · Nov/,
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('isActiveMcpConnection', () => {
|
|
180
|
+
const base: McpAgentSummary = {
|
|
181
|
+
id: 'a1',
|
|
182
|
+
kind: 'personal',
|
|
183
|
+
name: 'Test',
|
|
184
|
+
accessMode: 'ask',
|
|
185
|
+
readLevel: 'safe',
|
|
186
|
+
allowDestructiveWithoutAsking: false,
|
|
187
|
+
servicesAllowed: ['identity'],
|
|
188
|
+
expiresAt: '2099-01-01T00:00:00Z',
|
|
189
|
+
pausedAt: null,
|
|
190
|
+
revokedAt: null,
|
|
191
|
+
isActive: true,
|
|
192
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
193
|
+
oauthClientId: null,
|
|
194
|
+
personalTokenId: 'p1',
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
it('is false when revoked or expired', () => {
|
|
198
|
+
expect(isActiveMcpConnection(base)).toBe(true);
|
|
199
|
+
expect(isActiveMcpConnection({ ...base, revokedAt: '2026-02-01T00:00:00Z' })).toBe(false);
|
|
200
|
+
expect(
|
|
201
|
+
isActiveMcpConnection({ ...base, expiresAt: '2020-01-01T00:00:00Z' }, 1_700_000_000_000),
|
|
202
|
+
).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('agentIncludesSaasScope', () => {
|
|
207
|
+
it('detects saas in services_allowed', () => {
|
|
208
|
+
expect(
|
|
209
|
+
agentIncludesSaasScope({ servicesAllowed: ['identity', 'saas'] } as McpAgentSummary),
|
|
210
|
+
).toBe(true);
|
|
211
|
+
expect(agentIncludesSaasScope({ servicesAllowed: ['identity'] } as McpAgentSummary)).toBe(
|
|
212
|
+
false,
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MCP_PERSONAL_SERVICE_OPTIONS,
|
|
3
|
+
type McpAgentSummary,
|
|
4
|
+
type McpPersonalService,
|
|
5
|
+
type McpPersonalStatus,
|
|
6
|
+
} from './personalAgentsApi';
|
|
7
|
+
|
|
8
|
+
/** Regional services selectable for personal agent tokens (`ai` is added server-side). */
|
|
9
|
+
export const MCP_REGIONAL_PERSONAL_SERVICES = MCP_PERSONAL_SERVICE_OPTIONS.filter(
|
|
10
|
+
(service): service is Exclude<McpPersonalService, 'saas'> => service !== 'saas',
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export function buildCompanyMcpUrl(
|
|
14
|
+
aiServiceUrl: string | null | undefined,
|
|
15
|
+
companyId: string,
|
|
16
|
+
fallbackUrl?: string | null,
|
|
17
|
+
): string | null {
|
|
18
|
+
const base = aiServiceUrl?.trim().replace(/\/+$/, '') || '';
|
|
19
|
+
const tenant = companyId.trim();
|
|
20
|
+
if (base && tenant) {
|
|
21
|
+
return `${base}/c/${encodeURIComponent(tenant)}/mcp`;
|
|
22
|
+
}
|
|
23
|
+
const fallback = fallbackUrl?.trim();
|
|
24
|
+
return fallback || null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isAbsoluteHttpUrl(value: string | null | undefined): boolean {
|
|
28
|
+
if (!value?.trim()) return false;
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(value.trim());
|
|
31
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Locales for the copy-paste "Connect an agent" prompt.
|
|
39
|
+
* Admin apps must show these strings unchanged. The prompt names the company
|
|
40
|
+
* MCP URL and OAuth (device login for a headless client or a CLI). It must
|
|
41
|
+
* never include an access token, refresh token, device code, or user code.
|
|
42
|
+
*/
|
|
43
|
+
export const AGENT_CONNECT_PROMPT_LOCALES = ['en', 'fr'] as const;
|
|
44
|
+
|
|
45
|
+
export type AgentConnectPromptLocale = (typeof AGENT_CONNECT_PROMPT_LOCALES)[number];
|
|
46
|
+
|
|
47
|
+
export function resolveAgentConnectPromptLocale(
|
|
48
|
+
language: string | null | undefined,
|
|
49
|
+
): AgentConnectPromptLocale {
|
|
50
|
+
const base = language?.toLowerCase().split('-')[0];
|
|
51
|
+
return base === 'fr' ? 'fr' : 'en';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Exact steps shown under the prompt. Keep in sync with settings.json. */
|
|
55
|
+
export const AGENT_CONNECT_STEPS: Record<
|
|
56
|
+
AgentConnectPromptLocale,
|
|
57
|
+
readonly [string, string, string]
|
|
58
|
+
> = {
|
|
59
|
+
en: [
|
|
60
|
+
'Paste the prompt into your agent.',
|
|
61
|
+
'Open the link it shows.',
|
|
62
|
+
'Check the code and choose Allow.',
|
|
63
|
+
],
|
|
64
|
+
fr: [
|
|
65
|
+
"Collez l'invite dans votre agent.",
|
|
66
|
+
"Ouvrez le lien qu'il affiche.",
|
|
67
|
+
'Vérifiez le code, puis choisissez Autoriser.',
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function englishAgentPrompt(mcpUrl: string): string {
|
|
72
|
+
return [
|
|
73
|
+
'Connect to this Shellui company over MCP.',
|
|
74
|
+
'',
|
|
75
|
+
`MCP URL: ${mcpUrl}`,
|
|
76
|
+
'',
|
|
77
|
+
'Add this URL as a remote MCP server and sign in with OAuth.',
|
|
78
|
+
'If this client is headless or a CLI, use device login.',
|
|
79
|
+
'Show the link and the code, then wait until I approve them.',
|
|
80
|
+
].join('\n');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function frenchAgentPrompt(mcpUrl: string): string {
|
|
84
|
+
return [
|
|
85
|
+
'Connectez cette entreprise Shellui en MCP.',
|
|
86
|
+
'',
|
|
87
|
+
`URL MCP : ${mcpUrl}`,
|
|
88
|
+
'',
|
|
89
|
+
'Ajoutez cette URL comme serveur MCP distant et connectez-vous avec OAuth.',
|
|
90
|
+
'Si le client est sans interface ou en ligne de commande, utilisez device login.',
|
|
91
|
+
'Montrez le lien et le code, puis attendez que je les approuve.',
|
|
92
|
+
].join('\n');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Copy-paste prompt for an agent. `locale` selects English or French.
|
|
97
|
+
* Any other value falls back to English and is not interpolated.
|
|
98
|
+
*/
|
|
99
|
+
export function buildAgentPrompt(mcpUrl: string, locale: AgentConnectPromptLocale = 'en'): string {
|
|
100
|
+
const url = mcpUrl.trim();
|
|
101
|
+
if (!isAbsoluteHttpUrl(url)) {
|
|
102
|
+
throw new Error('Company MCP URL must be an absolute http(s) URL.');
|
|
103
|
+
}
|
|
104
|
+
return locale === 'fr' ? frenchAgentPrompt(url) : englishAgentPrompt(url);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const CREDENTIAL_MARKERS = [
|
|
108
|
+
'token',
|
|
109
|
+
'bearer',
|
|
110
|
+
'secret',
|
|
111
|
+
'password',
|
|
112
|
+
'device_code',
|
|
113
|
+
'user_code',
|
|
114
|
+
'authorization',
|
|
115
|
+
'eyj',
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
/** True when copy-paste text contains credential-shaped words. */
|
|
119
|
+
export function agentPromptContainsCredentialMaterial(prompt: string): boolean {
|
|
120
|
+
const haystack = prompt.toLowerCase();
|
|
121
|
+
return CREDENTIAL_MARKERS.some((marker) => haystack.includes(marker));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function isGlobalIdentitySession(status: McpPersonalStatus | null): boolean {
|
|
125
|
+
return status?.globalIdentity === true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function getDefaultPersonalAgentServices(includeSaas: boolean): McpPersonalService[] {
|
|
129
|
+
const services: McpPersonalService[] = [...MCP_REGIONAL_PERSONAL_SERVICES];
|
|
130
|
+
if (includeSaas) {
|
|
131
|
+
services.push('saas');
|
|
132
|
+
}
|
|
133
|
+
return services;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function formatDefaultAgentName(locale: string, at: Date = new Date()): string {
|
|
137
|
+
let dateLabel: string;
|
|
138
|
+
try {
|
|
139
|
+
dateLabel = new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric' }).format(at);
|
|
140
|
+
} catch {
|
|
141
|
+
dateLabel = at.toISOString().slice(0, 10);
|
|
142
|
+
}
|
|
143
|
+
return `Agent · ${dateLabel}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function formatConnectionDate(iso: string, locale: string): string {
|
|
147
|
+
try {
|
|
148
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(new Date(iso));
|
|
149
|
+
} catch {
|
|
150
|
+
return iso;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function formatAgentExpiry(iso: string | null, locale: string): string | null {
|
|
155
|
+
if (!iso?.trim()) return null;
|
|
156
|
+
return formatConnectionDate(iso, locale);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function isActiveMcpConnection(agent: McpAgentSummary, nowMs = Date.now()): boolean {
|
|
160
|
+
if (agent.revokedAt) return false;
|
|
161
|
+
if (!agent.isActive) return false;
|
|
162
|
+
if (agent.expiresAt && new Date(agent.expiresAt).getTime() <= nowMs) return false;
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function agentIncludesSaasScope(agent: McpAgentSummary): boolean {
|
|
167
|
+
return agent.servicesAllowed.some((service) => service.toLowerCase() === 'saas');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Identity `MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS` default (clamped to 1..366 days).
|
|
172
|
+
* `POST /api/v1/mcp/personal/agents/create` rejects a later `expires_at`.
|
|
173
|
+
* Personal status does not return the live setting, so the client uses this default.
|
|
174
|
+
*/
|
|
175
|
+
export const MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS = 90;
|
|
176
|
+
|
|
177
|
+
const DAY_MS = 86_400_000;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Stay strictly inside Identity's `expires_at > now + max` check when the browser
|
|
181
|
+
* clock is a little ahead of the server.
|
|
182
|
+
*/
|
|
183
|
+
const PERSONAL_AGENT_EXPIRY_SKEW_MS = 60_000;
|
|
184
|
+
|
|
185
|
+
/** Default personal-agent expiry when the UI does not expose a picker. */
|
|
186
|
+
export function defaultPersonalAgentExpiresAt(fromMs = Date.now()): string {
|
|
187
|
+
const lifetimeMs = MCP_PERSONAL_AGENT_MAX_LIFETIME_DAYS * DAY_MS - PERSONAL_AGENT_EXPIRY_SKEW_MS;
|
|
188
|
+
return new Date(fromMs + lifetimeMs).toISOString();
|
|
189
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { humanizeMcpToolName } from './mcpToolActivityRegistry';
|
|
3
|
+
|
|
4
|
+
describe('mcpToolActivityRegistry', () => {
|
|
5
|
+
it('labels known tools', () => {
|
|
6
|
+
expect(humanizeMcpToolName('storage_delete')).toBe('Delete stored object');
|
|
7
|
+
expect(humanizeMcpToolName('unknown_tool_xyz')).toBeNull();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known MCP tool names from Shellui fixtures. Unknown tools fall back to a neutral technical label in the UI.
|
|
3
|
+
*/
|
|
4
|
+
const TOOL_LABELS: Record<string, string> = {
|
|
5
|
+
storage_delete: 'Delete stored object',
|
|
6
|
+
identity_list_users: 'List directory members',
|
|
7
|
+
hosting_deploy: 'Deploy hosting',
|
|
8
|
+
hosting_deployments_list: 'List deployments',
|
|
9
|
+
projects_list: 'List projects',
|
|
10
|
+
companies_list: 'List companies',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function humanizeMcpToolName(toolName: string): string | null {
|
|
14
|
+
const key = toolName.trim();
|
|
15
|
+
if (!key) return null;
|
|
16
|
+
const direct = TOOL_LABELS[key];
|
|
17
|
+
if (direct) return direct;
|
|
18
|
+
const lower = key.toLowerCase();
|
|
19
|
+
return TOOL_LABELS[lower] ?? null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { ShellUIConfig } from '../config/types';
|
|
3
|
+
import {
|
|
4
|
+
decideMcpToolApproval,
|
|
5
|
+
fetchMcpPendingToolApprovals,
|
|
6
|
+
getMcpSettingsCompanyDisplayName,
|
|
7
|
+
mcpApprovalExpiresInMinutes,
|
|
8
|
+
parseMcpPendingToolApproval,
|
|
9
|
+
parseMcpPendingToolApprovalsList,
|
|
10
|
+
} from './mcpToolApprovalsApi';
|
|
11
|
+
|
|
12
|
+
describe('parseMcpPendingToolApproval', () => {
|
|
13
|
+
it('maps snake_case fields', () => {
|
|
14
|
+
expect(
|
|
15
|
+
parseMcpPendingToolApproval({
|
|
16
|
+
id: 'ap-1',
|
|
17
|
+
tool_name: 'storage_delete',
|
|
18
|
+
agent_name: 'Cursor',
|
|
19
|
+
expires_at: '2026-11-05T16:00:00Z',
|
|
20
|
+
short_action_summary: 'Remove draft.pdf',
|
|
21
|
+
is_destructive: true,
|
|
22
|
+
}),
|
|
23
|
+
).toMatchObject({
|
|
24
|
+
id: 'ap-1',
|
|
25
|
+
toolName: 'storage_delete',
|
|
26
|
+
agentName: 'Cursor',
|
|
27
|
+
shortActionSummary: 'Remove draft.pdf',
|
|
28
|
+
isDestructive: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('returns null when required fields are missing', () => {
|
|
33
|
+
expect(parseMcpPendingToolApproval({ id: 'x' })).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('parseMcpPendingToolApprovalsList', () => {
|
|
38
|
+
it('uses pending_count when provided', () => {
|
|
39
|
+
expect(
|
|
40
|
+
parseMcpPendingToolApprovalsList({
|
|
41
|
+
pending_count: 3,
|
|
42
|
+
approvals: [],
|
|
43
|
+
}),
|
|
44
|
+
).toEqual({ pendingCount: 3, approvals: [] });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('falls back to approvals length', () => {
|
|
48
|
+
const list = parseMcpPendingToolApprovalsList({
|
|
49
|
+
approvals: [
|
|
50
|
+
{
|
|
51
|
+
id: '1',
|
|
52
|
+
tool_name: 't',
|
|
53
|
+
agent_name: 'a',
|
|
54
|
+
expires_at: '2026-11-05T16:00:00Z',
|
|
55
|
+
is_destructive: false,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
expect(list?.pendingCount).toBe(1);
|
|
60
|
+
expect(list?.approvals).toHaveLength(1);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('mcpApprovalExpiresInMinutes', () => {
|
|
65
|
+
it('returns at least one minute while time remains', () => {
|
|
66
|
+
const now = Date.parse('2026-11-05T15:00:00Z');
|
|
67
|
+
expect(mcpApprovalExpiresInMinutes('2026-11-05T15:00:30Z', now)).toBe(1);
|
|
68
|
+
expect(mcpApprovalExpiresInMinutes('2026-11-05T15:02:00Z', now)).toBe(2);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns zero after expiry', () => {
|
|
72
|
+
const now = Date.parse('2026-11-05T16:00:01Z');
|
|
73
|
+
expect(mcpApprovalExpiresInMinutes('2026-11-05T16:00:00Z', now)).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('getMcpSettingsCompanyDisplayName', () => {
|
|
78
|
+
it('prefers config title', () => {
|
|
79
|
+
expect(getMcpSettingsCompanyDisplayName({ title: 'Acme' } as ShellUIConfig)).toBe('Acme');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('mcp tool approval fetch helpers', () => {
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
vi.unstubAllGlobals();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('fetchMcpPendingToolApprovals sends bearer and company_id', async () => {
|
|
89
|
+
const fetchMock = vi.fn().mockResolvedValue({
|
|
90
|
+
ok: true,
|
|
91
|
+
json: async () => ({ pending_count: 0, approvals: [] }),
|
|
92
|
+
});
|
|
93
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
94
|
+
|
|
95
|
+
await fetchMcpPendingToolApprovals('https://id.example.com', 'tok', '7');
|
|
96
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
97
|
+
expect(url).toBe('https://id.example.com/api/v1/mcp/approvals?company_id=7');
|
|
98
|
+
expect(init.headers).toMatchObject({ Authorization: 'Bearer tok' });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('decideMcpToolApproval posts decision', async () => {
|
|
102
|
+
const fetchMock = vi.fn().mockResolvedValue({
|
|
103
|
+
ok: true,
|
|
104
|
+
json: async () => ({}),
|
|
105
|
+
});
|
|
106
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
107
|
+
|
|
108
|
+
await decideMcpToolApproval('https://id.example.com', 'tok', '1', 'ap-9', 'deny');
|
|
109
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
110
|
+
expect(url).toContain('/api/v1/mcp/approvals/ap-9/decide');
|
|
111
|
+
expect(JSON.parse(String(init.body))).toEqual({ decision: 'deny' });
|
|
112
|
+
});
|
|
113
|
+
});
|