@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
@@ -0,0 +1,162 @@
1
+ import type { ShellUIConfig } from '../config/types';
2
+ import { getShellUILoginCompanyId } from '../auth/utils/clientLoginContext';
3
+ import { McpPersonalApiError } from './personalAgentsApi';
4
+
5
+ export type McpToolApprovalDecision = 'approve' | 'deny';
6
+
7
+ export type McpPendingToolApproval = {
8
+ id: string;
9
+ toolName: string;
10
+ agentName: string;
11
+ expiresAt: string;
12
+ shortActionSummary: string | null;
13
+ isDestructive: boolean;
14
+ };
15
+
16
+ export type McpPendingToolApprovalsList = {
17
+ pendingCount: number;
18
+ approvals: McpPendingToolApproval[];
19
+ };
20
+
21
+ export { getMcpPersonalCompanyId, getShellIdentityBackendUrl } from './personalAgentsApi';
22
+
23
+ const asString = (value: unknown): string | null =>
24
+ typeof value === 'string' && value.trim() ? value.trim() : null;
25
+
26
+ const asBool = (value: unknown): boolean => value === true;
27
+
28
+ export const parseMcpPendingToolApproval = (value: unknown): McpPendingToolApproval | null => {
29
+ if (!value || typeof value !== 'object') return null;
30
+ const record = value as Record<string, unknown>;
31
+ const id = asString(record.id);
32
+ const toolName = asString(record.tool_name);
33
+ const agentName = asString(record.agent_name);
34
+ const expiresAt = asString(record.expires_at);
35
+ if (!id || !toolName || !agentName || !expiresAt) return null;
36
+ const summary = asString(record.short_action_summary);
37
+ return {
38
+ id,
39
+ toolName,
40
+ agentName,
41
+ expiresAt,
42
+ shortActionSummary: summary,
43
+ isDestructive: asBool(record.is_destructive),
44
+ };
45
+ };
46
+
47
+ export const parseMcpPendingToolApprovalsList = (
48
+ payload: unknown,
49
+ ): McpPendingToolApprovalsList | null => {
50
+ if (!payload || typeof payload !== 'object') return null;
51
+ const record = payload as Record<string, unknown>;
52
+ const rows = Array.isArray(record.approvals) ? record.approvals : [];
53
+ const approvals = rows
54
+ .map((row) => parseMcpPendingToolApproval(row))
55
+ .filter((row): row is McpPendingToolApproval => row !== null);
56
+ const rawCount = record.pending_count;
57
+ const pendingCount =
58
+ typeof rawCount === 'number' && Number.isFinite(rawCount) && rawCount >= 0
59
+ ? rawCount
60
+ : approvals.length;
61
+ return { pendingCount, approvals };
62
+ };
63
+
64
+ /** Minutes until expiry, at least 1 while time remains. */
65
+ export function mcpApprovalExpiresInMinutes(expiresAt: string, nowMs = Date.now()): number {
66
+ const end = new Date(expiresAt).getTime();
67
+ if (!Number.isFinite(end)) return 0;
68
+ const remainingMs = end - nowMs;
69
+ if (remainingMs <= 0) return 0;
70
+ return Math.max(1, Math.ceil(remainingMs / 60_000));
71
+ }
72
+
73
+ const buildUrl = (backendUrl: string, path: string, companyId: string): URL => {
74
+ const url = new URL(`${backendUrl.replace(/\/+$/, '')}${path}`);
75
+ if (companyId) {
76
+ url.searchParams.set('company_id', companyId);
77
+ }
78
+ return url;
79
+ };
80
+
81
+ async function mcpJsonRequest<T>(
82
+ backendUrl: string,
83
+ accessToken: string,
84
+ companyId: string,
85
+ path: string,
86
+ init: RequestInit,
87
+ parse: (payload: unknown) => T | null,
88
+ ): Promise<T> {
89
+ const url = buildUrl(backendUrl, path, companyId);
90
+ const headers: Record<string, string> = {
91
+ Accept: 'application/json',
92
+ Authorization: `Bearer ${accessToken}`,
93
+ };
94
+ if (init.body) {
95
+ headers['Content-Type'] = 'application/json';
96
+ }
97
+ const response = await fetch(url.toString(), {
98
+ ...init,
99
+ headers: { ...headers, ...init.headers },
100
+ });
101
+ const payload = await response.json().catch(() => null);
102
+ if (!response.ok) {
103
+ let message = `HTTP ${response.status}`;
104
+ if (payload && typeof payload === 'object') {
105
+ const record = payload as Record<string, unknown>;
106
+ const err = record.error ?? record.detail;
107
+ if (typeof err === 'string' && err.trim()) message = err.trim();
108
+ }
109
+ throw new McpPersonalApiError(message, response.status);
110
+ }
111
+ const parsed = parse(payload);
112
+ if (!parsed) {
113
+ throw new McpPersonalApiError('Unexpected response from identity.', response.status);
114
+ }
115
+ return parsed;
116
+ }
117
+
118
+ /**
119
+ * Identity member API. OpenAPI: GET /api/v1/mcp/approvals
120
+ */
121
+ export const fetchMcpPendingToolApprovals = (
122
+ backendUrl: string,
123
+ accessToken: string,
124
+ companyId: string,
125
+ ): Promise<McpPendingToolApprovalsList> =>
126
+ mcpJsonRequest(
127
+ backendUrl,
128
+ accessToken,
129
+ companyId,
130
+ '/api/v1/mcp/approvals',
131
+ { method: 'GET' },
132
+ parseMcpPendingToolApprovalsList,
133
+ );
134
+
135
+ /**
136
+ * Identity member API. OpenAPI: POST /api/v1/mcp/approvals/{id}/decide
137
+ */
138
+ export const decideMcpToolApproval = (
139
+ backendUrl: string,
140
+ accessToken: string,
141
+ companyId: string,
142
+ approvalId: string,
143
+ decision: McpToolApprovalDecision,
144
+ ): Promise<void> =>
145
+ mcpJsonRequest(
146
+ backendUrl,
147
+ accessToken,
148
+ companyId,
149
+ `/api/v1/mcp/approvals/${encodeURIComponent(approvalId)}/decide`,
150
+ {
151
+ method: 'POST',
152
+ body: JSON.stringify({ decision }),
153
+ },
154
+ (payload) => (payload === null || typeof payload === 'object' ? {} : null),
155
+ ).then(() => undefined);
156
+
157
+ export const getMcpSettingsCompanyDisplayName = (config: ShellUIConfig | undefined): string => {
158
+ const title = config?.title?.trim();
159
+ if (title) return title;
160
+ const companyId = getShellUILoginCompanyId(config?.backend?.companyId);
161
+ return companyId || 'this company';
162
+ };