@bevel-software/platform-core-frontend 0.1.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 (203) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +70 -0
  3. package/src/core/CoreAppShell.tsx +444 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
  5. package/src/core/events.ts +29 -0
  6. package/src/core/registry.ts +336 -0
  7. package/src/css-side-effect-imports.d.ts +7 -0
  8. package/src/html-extensions.ts +12 -0
  9. package/src/index.css +49 -0
  10. package/src/index.ts +23 -0
  11. package/src/lib/api.ts +57 -0
  12. package/src/lib/utils.ts +138 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
  14. package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
  15. package/src/modules/access/api.ts +205 -0
  16. package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
  17. package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
  18. package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
  19. package/src/modules/access/hooks/useFileAccess.ts +151 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
  22. package/src/modules/admin/services/admin.api.ts +92 -0
  23. package/src/modules/admin/services/roles.api.ts +136 -0
  24. package/src/modules/admin/state/admin.context.tsx +223 -0
  25. package/src/modules/auth/components/LoginScreen.tsx +135 -0
  26. package/src/modules/auth/hooks/useAuthState.ts +59 -0
  27. package/src/modules/auth/services/auth.api.ts +24 -0
  28. package/src/modules/auth/services/microsoft-oauth.ts +57 -0
  29. package/src/modules/auth/state/auth.context.ts +18 -0
  30. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
  31. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
  32. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
  33. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
  34. package/src/modules/git/__tests__/git.api.test.ts +113 -0
  35. package/src/modules/git/__tests__/pr.api.test.ts +44 -0
  36. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
  37. package/src/modules/git/components/BranchSwitcher.tsx +527 -0
  38. package/src/modules/git/components/DiffView.tsx +30 -0
  39. package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
  40. package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
  41. package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
  42. package/src/modules/git/components/PullNeededBanner.tsx +204 -0
  43. package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
  44. package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
  45. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
  46. package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
  47. package/src/modules/git/hooks/useGitState.ts +335 -0
  48. package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
  49. package/src/modules/git/services/error-messages.ts +257 -0
  50. package/src/modules/git/services/git.api.ts +163 -0
  51. package/src/modules/git/services/pr-prompts.ts +159 -0
  52. package/src/modules/git/services/pr.api.ts +39 -0
  53. package/src/modules/git/state/auto-update.context.ts +21 -0
  54. package/src/modules/git/state/git.context.ts +82 -0
  55. package/src/modules/layout/components/AppLayout.tsx +40 -0
  56. package/src/modules/layout/components/DemoBanner.tsx +57 -0
  57. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
  58. package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
  59. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
  60. package/src/modules/layout/components/SlideOverlay.tsx +224 -0
  61. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
  62. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
  63. package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
  64. package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
  65. package/src/modules/layout/state/layout.context.ts +46 -0
  66. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
  67. package/src/modules/library/__tests__/diff.test.ts +62 -0
  68. package/src/modules/library/__tests__/loadout.test.tsx +72 -0
  69. package/src/modules/library/__tests__/status.test.ts +117 -0
  70. package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
  71. package/src/modules/library/components/CompareView.tsx +357 -0
  72. package/src/modules/library/components/DetailDialog.tsx +566 -0
  73. package/src/modules/library/components/GearIcon.tsx +12 -0
  74. package/src/modules/library/components/LibraryCard.tsx +132 -0
  75. package/src/modules/library/components/LibraryPage.tsx +254 -0
  76. package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
  77. package/src/modules/library/components/StatusGem.tsx +21 -0
  78. package/src/modules/library/components/SuggestChange.tsx +171 -0
  79. package/src/modules/library/components/particles.ts +50 -0
  80. package/src/modules/library/hooks/useLibraryData.ts +119 -0
  81. package/src/modules/library/hooks/useSkillDetail.ts +74 -0
  82. package/src/modules/library/library.css +320 -0
  83. package/src/modules/library/services/library.api.ts +164 -0
  84. package/src/modules/library/state/loadout.tsx +129 -0
  85. package/src/modules/library/state/toast.tsx +42 -0
  86. package/src/modules/library/utils/diff.ts +102 -0
  87. package/src/modules/library/utils/status.ts +116 -0
  88. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
  89. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
  90. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
  91. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
  92. package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
  93. package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
  94. package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
  95. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
  96. package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
  97. package/src/modules/pr/components/PrCancelButton.tsx +99 -0
  98. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
  99. package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
  100. package/src/modules/pr/components/PrCommentThread.tsx +168 -0
  101. package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
  102. package/src/modules/pr/components/PrDiffPane.tsx +425 -0
  103. package/src/modules/pr/components/PrFileRow.tsx +164 -0
  104. package/src/modules/pr/components/PrFilesList.tsx +53 -0
  105. package/src/modules/pr/components/PrHeader.tsx +45 -0
  106. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
  107. package/src/modules/pr/components/PrMergeButton.tsx +268 -0
  108. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
  109. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
  110. package/src/modules/pr/components/PrViewer.tsx +364 -0
  111. package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
  112. package/src/modules/pr/services/pr-approvals.api.ts +31 -0
  113. package/src/modules/pr/services/pr-cancel.api.ts +19 -0
  114. package/src/modules/pr/services/pr-comments.api.ts +45 -0
  115. package/src/modules/pr/services/pr-detail.api.ts +17 -0
  116. package/src/modules/pr/services/pr-merge.api.ts +53 -0
  117. package/src/modules/pr/services/pr-open.api.ts +30 -0
  118. package/src/modules/pr/state/pr-viewer.context.ts +34 -0
  119. package/src/modules/pr/utils/bucketize-comments.ts +55 -0
  120. package/src/modules/pr/utils/parsePatch.ts +57 -0
  121. package/src/modules/review/__tests__/review.api.test.ts +121 -0
  122. package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
  123. package/src/modules/review/components/DiffViewer.tsx +78 -0
  124. package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
  125. package/src/modules/review/components/ReviewFileRow.tsx +114 -0
  126. package/src/modules/review/components/ReviewPanel.tsx +260 -0
  127. package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
  128. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
  129. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
  130. package/src/modules/review/hooks/useReviewState.ts +256 -0
  131. package/src/modules/review/services/review.api.ts +72 -0
  132. package/src/modules/review/state/ReviewProvider.tsx +28 -0
  133. package/src/modules/review/state/review.context.ts +29 -0
  134. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
  135. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
  136. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
  137. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
  138. package/src/modules/secrets-vault/services/connect.api.ts +113 -0
  139. package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
  140. package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
  141. package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
  142. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
  143. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
  144. package/src/modules/toolbar/components/Toolbar.tsx +123 -0
  145. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
  146. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
  147. package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
  148. package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
  149. package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
  150. package/src/modules/workflow/hooks/useFileLock.ts +430 -0
  151. package/src/modules/workflow/services/lock.api.ts +139 -0
  152. package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
  153. package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
  154. package/src/modules/workflow/state/event-bus.context.ts +75 -0
  155. package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
  156. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
  157. package/src/modules/workspace/components/EditorTabs.tsx +384 -0
  158. package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
  159. package/src/modules/workspace/components/FileRoute.tsx +392 -0
  160. package/src/modules/workspace/components/FileViewer.tsx +906 -0
  161. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
  162. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
  163. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
  164. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
  165. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
  166. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
  167. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
  168. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
  169. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
  170. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
  171. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
  172. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
  173. package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
  174. package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
  175. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
  176. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
  177. package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
  178. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
  179. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
  180. package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
  181. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
  182. package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
  183. package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
  184. package/src/modules/workspace/components/renderers/index.ts +39 -0
  185. package/src/modules/workspace/components/renderers/types.ts +27 -0
  186. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
  189. package/src/modules/workspace/routing/kb-routes.ts +266 -0
  190. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
  191. package/src/modules/workspace/services/workspace.api.ts +185 -0
  192. package/src/modules/workspace/state/workspace.context.ts +235 -0
  193. package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
  194. package/src/modules/workspace/utils/diff.ts +53 -0
  195. package/src/modules/workspace/utils/fileTree.ts +179 -0
  196. package/src/modules/workspace/utils/frontmatter.ts +80 -0
  197. package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
  198. package/src/modules/workspace/utils/tab-persistence.ts +23 -0
  199. package/src/shared/components/Dialog.tsx +198 -0
  200. package/src/shared/components/PageShell.tsx +51 -0
  201. package/src/shared/components/useModalLayer.ts +35 -0
  202. package/src/shared/markdown/Markdown.tsx +62 -0
  203. package/src/test-setup.ts +59 -0
@@ -0,0 +1,113 @@
1
+ import { authFetch } from '../../../lib/api';
2
+
3
+ /**
4
+ * The aggregated "connect your tools" surface: everything the signed-in person
5
+ * still needs to provide before the tools they can reach will work in their own
6
+ * agent. It lists ONLY per-user items (never the admin/shared ones), split into
7
+ * plain values (API keys) they enter and OAuth sign-ins they authorize.
8
+ */
9
+
10
+ export interface ConnectVar {
11
+ /** Bare variable name (e.g. `API_KEY`). */
12
+ name: string;
13
+ label: string | null;
14
+ /** The stored key — `<manual>_<VAR>`. */
15
+ key: string;
16
+ /** The caller's own value exists. */
17
+ configured: boolean;
18
+ }
19
+
20
+ export interface ConnectTool {
21
+ slug: string;
22
+ name: string;
23
+ path: string;
24
+ type: 'inline' | 'http' | 'mcp';
25
+ variables: ConnectVar[];
26
+ }
27
+
28
+ export interface ConnectOAuth {
29
+ id: string;
30
+ key: string;
31
+ label: string | null;
32
+ authorized: boolean;
33
+ }
34
+
35
+ /** An OAuth-backed variable declared BY a tool — authorized via the tool-scoped start. */
36
+ export interface ConnectToolOAuth {
37
+ slug: string;
38
+ varName: string;
39
+ toolName: string;
40
+ key: string;
41
+ label: string | null;
42
+ authorized: boolean;
43
+ /**
44
+ * Authorized, but the token's granted permissions no longer cover what the tool
45
+ * declares now (a scope was added since sign-in) — show Reconnect, not Connected.
46
+ */
47
+ needsReauth: boolean;
48
+ }
49
+
50
+ export interface ConnectPending {
51
+ tools: ConnectTool[];
52
+ oauth: ConnectOAuth[];
53
+ toolOAuth: ConnectToolOAuth[];
54
+ }
55
+
56
+ /** Throw the response's `{ error }` message, or `fallback` for a non-JSON body. */
57
+ async function fail(res: Response, fallback: string): Promise<never> {
58
+ let message = fallback;
59
+ try {
60
+ const body = (await res.json()) as { error?: string };
61
+ if (body?.error) message = body.error;
62
+ } catch {
63
+ // non-JSON body — keep the fallback
64
+ }
65
+ throw new Error(message);
66
+ }
67
+
68
+ /** The caller's outstanding per-user credentials across every accessible tool. */
69
+ export async function getConnectPending(): Promise<ConnectPending> {
70
+ const res = await authFetch('/api/connect/pending');
71
+ if (!res.ok) await fail(res, "Couldn't load your tools.");
72
+ return (await res.json()) as ConnectPending;
73
+ }
74
+
75
+ /** Start a tool-scoped OAuth sign-in for one of a tool's OAuth-backed variables. */
76
+ export async function startToolOAuth(slug: string, varName: string): Promise<string> {
77
+ const res = await authFetch(
78
+ `/api/secrets/tools/${encodeURIComponent(slug)}/vars/${encodeURIComponent(varName)}/oauth/start`,
79
+ { method: 'POST' },
80
+ );
81
+ if (!res.ok) await fail(res, "Couldn't start sign-in.");
82
+ return ((await res.json()) as { url: string }).url;
83
+ }
84
+
85
+ // ---- MCP OAuth (an external agent connecting via our authorization server) ----
86
+
87
+ export interface McpOAuthRequest {
88
+ /** The connecting MCP client's self-declared display name (e.g. "Claude"). */
89
+ clientName: string | null;
90
+ scope: string | null;
91
+ resource: string | null;
92
+ }
93
+
94
+ /** Describe the pending MCP authorization carried in the signed `state`. */
95
+ export async function getMcpOAuthRequest(state: string): Promise<McpOAuthRequest> {
96
+ const res = await authFetch(`/api/mcp/oauth/request?state=${encodeURIComponent(state)}`);
97
+ if (!res.ok) await fail(res, "Couldn't load the connection request.");
98
+ return (await res.json()) as McpOAuthRequest;
99
+ }
100
+
101
+ /**
102
+ * Finish the MCP authorization: mint the one-time code for the signed-in user
103
+ * and return the agent's redirect URL the browser should navigate to.
104
+ */
105
+ export async function completeMcpOAuth(state: string): Promise<string> {
106
+ const res = await authFetch('/api/mcp/oauth/complete', {
107
+ method: 'POST',
108
+ headers: { 'Content-Type': 'application/json' },
109
+ body: JSON.stringify({ state }),
110
+ });
111
+ if (!res.ok) await fail(res, "Couldn't finish connecting.");
112
+ return ((await res.json()) as { redirectTo: string }).redirectTo;
113
+ }
@@ -0,0 +1,82 @@
1
+ import { authFetch } from '../../../lib/api';
2
+
3
+ export type SecretKind = 'static' | 'oauth';
4
+
5
+ /** A stored secret as shown in the UI — never carries the value/token material. */
6
+ export interface SecretSummary {
7
+ id: string;
8
+ key: string;
9
+ kind: SecretKind;
10
+ label: string | null;
11
+ /** For `oauth`: whether the user has completed the authorization flow. */
12
+ authorized?: boolean;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ }
16
+
17
+ export interface OAuthProviderConfig {
18
+ authorizationUrl: string;
19
+ tokenUrl: string;
20
+ clientId: string;
21
+ clientSecret?: string;
22
+ scopes?: string[];
23
+ /** Extra static params appended to the authorization request (e.g. `audience`). */
24
+ authParams?: Record<string, string>;
25
+ }
26
+
27
+ async function unwrap(res: Response, fallback: string): Promise<never> {
28
+ let message = fallback;
29
+ try {
30
+ const body = (await res.json()) as { error?: string };
31
+ if (body?.error) message = body.error;
32
+ } catch {
33
+ // non-JSON body — keep the fallback
34
+ }
35
+ throw new Error(message);
36
+ }
37
+
38
+ export async function listSecrets(): Promise<SecretSummary[]> {
39
+ const res = await authFetch('/api/secrets');
40
+ if (!res.ok) await unwrap(res, "Couldn't load your secrets.");
41
+ return ((await res.json()) as { secrets: SecretSummary[] }).secrets;
42
+ }
43
+
44
+ export async function putStaticSecret(input: {
45
+ key: string;
46
+ value: string;
47
+ label?: string | null;
48
+ }): Promise<SecretSummary> {
49
+ const res = await authFetch('/api/secrets/static', {
50
+ method: 'POST',
51
+ headers: { 'Content-Type': 'application/json' },
52
+ body: JSON.stringify(input),
53
+ });
54
+ if (!res.ok) await unwrap(res, "Couldn't save this secret.");
55
+ return ((await res.json()) as { secret: SecretSummary }).secret;
56
+ }
57
+
58
+ export async function createOAuthSecret(input: {
59
+ key: string;
60
+ label?: string | null;
61
+ provider: OAuthProviderConfig;
62
+ }): Promise<SecretSummary> {
63
+ const res = await authFetch('/api/secrets/oauth', {
64
+ method: 'POST',
65
+ headers: { 'Content-Type': 'application/json' },
66
+ body: JSON.stringify(input),
67
+ });
68
+ if (!res.ok) await unwrap(res, "Couldn't save this OAuth secret.");
69
+ return ((await res.json()) as { secret: SecretSummary }).secret;
70
+ }
71
+
72
+ export async function deleteSecret(id: string): Promise<void> {
73
+ const res = await authFetch(`/api/secrets/${encodeURIComponent(id)}`, { method: 'DELETE' });
74
+ if (!res.ok && res.status !== 204) await unwrap(res, "Couldn't remove this secret.");
75
+ }
76
+
77
+ /** Fetch the provider consent URL for an oauth secret; the caller navigates to it. */
78
+ export async function startOAuth(id: string): Promise<string> {
79
+ const res = await authFetch(`/api/secrets/${encodeURIComponent(id)}/oauth/start`);
80
+ if (!res.ok) await unwrap(res, "Couldn't start authorization.");
81
+ return ((await res.json()) as { url: string }).url;
82
+ }
@@ -0,0 +1,116 @@
1
+ import { authFetch } from '../../../lib/api';
2
+
3
+ /**
4
+ * Per-tool secrets API. A `.tool` manual declares which `${VAR}`s are set by the
5
+ * tool owner (`admin`, one shared value) vs by each end user (`user`). These
6
+ * calls drive both the `.tool` editor sidebar and the Secrets page.
7
+ */
8
+
9
+ export type ToolVarScope = 'admin' | 'user';
10
+
11
+ export interface ToolVarStatus {
12
+ /** Bare variable name (e.g. `API_KEY`). */
13
+ name: string;
14
+ scope: ToolVarScope;
15
+ label: string | null;
16
+ /** The stored key — `<manual>_<VAR>`. */
17
+ key: string;
18
+ /** A shared (admin) value exists. */
19
+ adminConfigured: boolean;
20
+ /** The caller's own value exists. */
21
+ userConfigured: boolean;
22
+ /** This variable is filled by an OAuth sign-in, not a typed value. */
23
+ oauth?: boolean;
24
+ /** For an oauth var: the caller has completed sign-in (a token exists). */
25
+ authorized?: boolean;
26
+ /** For an oauth var: authorized, but the token doesn't cover all declared scopes. */
27
+ needsReauth?: boolean;
28
+ /** For an oauth var: the declared scopes the token was NOT granted (what it can't do). */
29
+ missingScopes?: string[];
30
+ }
31
+
32
+ /**
33
+ * For a `type: mcp` tool, the setup requirement auto-discovery found:
34
+ * - `open` — no auth; nothing to configure.
35
+ * - `oauth-auto` — sign-in was set up automatically (appears as a user var).
36
+ * - `oauth-manual` — the server needs sign-in but couldn't be set up
37
+ * automatically; a tool writer must declare the provider in
38
+ * the `.tool` file and set its client secret. `reason` says why.
39
+ */
40
+ export interface ToolSetup {
41
+ kind: 'open' | 'oauth-auto' | 'oauth-manual';
42
+ reason?: string;
43
+ }
44
+
45
+ export interface ToolSecrets {
46
+ slug: string;
47
+ name: string;
48
+ path: string;
49
+ type: 'inline' | 'http' | 'mcp';
50
+ /** MCP auto-discovery setup requirement; `null` for non-mcp tools. */
51
+ setup: ToolSetup | null;
52
+ /** Whether the caller may set this tool's admin (shared) secrets. */
53
+ canWrite: boolean;
54
+ variables: ToolVarStatus[];
55
+ }
56
+
57
+ async function unwrap(res: Response, fallback: string): Promise<never> {
58
+ let message = fallback;
59
+ try {
60
+ const body = (await res.json()) as { error?: string };
61
+ if (body?.error) message = body.error;
62
+ } catch {
63
+ // non-JSON body — keep the fallback
64
+ }
65
+ throw new Error(message);
66
+ }
67
+
68
+ /** All accessible tools with their variables + config status; `path` narrows to one tool. */
69
+ export async function listToolSecrets(path?: string): Promise<ToolSecrets[]> {
70
+ const q = path ? `?path=${encodeURIComponent(path)}` : '';
71
+ const res = await authFetch(`/api/secrets/tools${q}`);
72
+ if (!res.ok) await unwrap(res, "Couldn't load tool secrets.");
73
+ return ((await res.json()) as { tools: ToolSecrets[] }).tools;
74
+ }
75
+
76
+ const varPath = (slug: string, varName: string, tier: ToolVarScope) =>
77
+ `/api/secrets/tools/${encodeURIComponent(slug)}/vars/${encodeURIComponent(varName)}/${tier}`;
78
+
79
+ async function putVar(slug: string, varName: string, tier: ToolVarScope, value: string, label?: string | null): Promise<void> {
80
+ const res = await authFetch(varPath(slug, varName, tier), {
81
+ method: 'PUT',
82
+ headers: { 'Content-Type': 'application/json' },
83
+ body: JSON.stringify({ value, label: label ?? null }),
84
+ });
85
+ if (!res.ok) await unwrap(res, "Couldn't save this secret.");
86
+ }
87
+
88
+ async function deleteVar(slug: string, varName: string, tier: ToolVarScope): Promise<void> {
89
+ const res = await authFetch(varPath(slug, varName, tier), { method: 'DELETE' });
90
+ if (!res.ok && res.status !== 204) await unwrap(res, "Couldn't remove this secret.");
91
+ }
92
+
93
+ /**
94
+ * Store the confidential OAuth CLIENT SECRET for a tool's declared sign-in
95
+ * provider — the owner-side half of a manual OAuth setup. Requires write access
96
+ * to the `.tool`; the public provider config is pinned server-side from the
97
+ * file's own `oauth` declaration.
98
+ */
99
+ export async function setOAuthClientSecret(slug: string, varName: string, clientSecret: string): Promise<void> {
100
+ const res = await authFetch(
101
+ `/api/secrets/tools/${encodeURIComponent(slug)}/vars/${encodeURIComponent(varName)}/oauth/admin`,
102
+ {
103
+ method: 'PUT',
104
+ headers: { 'Content-Type': 'application/json' },
105
+ body: JSON.stringify({ clientSecret }),
106
+ },
107
+ );
108
+ if (!res.ok) await unwrap(res, "Couldn't save the client secret.");
109
+ }
110
+
111
+ export const setAdminVar = (slug: string, varName: string, value: string, label?: string | null) =>
112
+ putVar(slug, varName, 'admin', value, label);
113
+ export const setUserVar = (slug: string, varName: string, value: string, label?: string | null) =>
114
+ putVar(slug, varName, 'user', value, label);
115
+ export const deleteAdminVar = (slug: string, varName: string) => deleteVar(slug, varName, 'admin');
116
+ export const deleteUserVar = (slug: string, varName: string) => deleteVar(slug, varName, 'user');
@@ -0,0 +1,250 @@
1
+ import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Boxes, KeyRound, LibraryBig, Lock, Settings, Users } from 'lucide-react';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { useAdmin } from '../../admin/state/admin.context';
5
+ import { useAppRegistry, type AdminMenuItem } from '../../../core/registry';
6
+
7
+ const MENU_ID = 'app-settings-menu';
8
+
9
+ const ITEM_CLASS =
10
+ 'flex w-full items-center gap-2 px-3 py-1.5 text-sm text-left text-slate-700 hover:bg-slate-100';
11
+
12
+ /** One gear-menu row: shared `role="menuitem"` button shell around icon + label. */
13
+ function MenuItem({
14
+ icon,
15
+ onSelect,
16
+ children,
17
+ }: {
18
+ icon: React.ReactNode;
19
+ onSelect: () => void;
20
+ children: React.ReactNode;
21
+ }) {
22
+ return (
23
+ <button type="button" role="menuitem" onClick={onSelect} className={ITEM_CLASS}>
24
+ {icon}
25
+ {children}
26
+ </button>
27
+ );
28
+ }
29
+
30
+ /**
31
+ * The core gear-menu rows. Everything else (Connectors, Watchlist, Routines,
32
+ * Connected apps, feedback, LLM configuration, user accounts, …) is
33
+ * registry-contributed — see `enterprise/admin-menu-items.tsx`. The `order`
34
+ * values interleave the two lists to reproduce the historical row order.
35
+ *
36
+ * All core rows NAVIGATE — the settings surfaces are standalone routed pages
37
+ * below the persistent toolbar, not dialogs. The `dialog` contract on
38
+ * {@link AdminMenuItem} stays supported for registry-contributed rows.
39
+ */
40
+ const CORE_MENU_ITEMS: AdminMenuItem[] = [
41
+ {
42
+ id: 'skills-and-tools',
43
+ order: 35,
44
+ icon: <LibraryBig size={14} />,
45
+ label: 'Skills & Tools',
46
+ onSelect: ({ navigate, closeMenu }) => {
47
+ navigate('/skills-and-tools');
48
+ closeMenu();
49
+ },
50
+ },
51
+ {
52
+ id: 'external-agent-access',
53
+ order: 40,
54
+ icon: <KeyRound size={14} />,
55
+ label: 'External agent access',
56
+ onSelect: ({ navigate, closeMenu }) => {
57
+ navigate('/external-agent-access');
58
+ closeMenu();
59
+ },
60
+ },
61
+ {
62
+ id: 'secrets',
63
+ order: 50,
64
+ icon: <Lock size={14} />,
65
+ label: 'Secrets',
66
+ onSelect: ({ navigate, closeMenu }) => {
67
+ navigate('/secrets');
68
+ closeMenu();
69
+ },
70
+ },
71
+ {
72
+ id: 'browse-tools',
73
+ order: 70,
74
+ icon: <Boxes size={14} />,
75
+ label: 'Browse available tools',
76
+ onSelect: ({ navigate, closeMenu }) => {
77
+ navigate('/tools');
78
+ closeMenu();
79
+ },
80
+ },
81
+ {
82
+ id: 'roles-members',
83
+ section: 'admin',
84
+ order: 10,
85
+ icon: <Users size={14} />,
86
+ label: 'Roles & Members',
87
+ onSelect: ({ navigate, closeMenu }) => {
88
+ navigate('/roles-and-members');
89
+ closeMenu();
90
+ },
91
+ },
92
+ ];
93
+
94
+ /**
95
+ * The single toolbar menu behind the gear icon. Renders the core rows above
96
+ * plus whatever the app registry contributes (`registry.adminMenuItems`),
97
+ * merged by section + order:
98
+ *
99
+ * - Top section (all users): today that merge yields Connectors, Watchlist,
100
+ * Routines, External agent access, Secrets, Connected apps, Browse tools,
101
+ * Give us feedback.
102
+ * - "Admin only" section (admins): Roles & Members, User accounts,
103
+ * LLM Configuration, Feedback Inbox.
104
+ *
105
+ * Core rows all navigate (the settings surfaces are standalone routed
106
+ * pages). Registry rows may still be dialog rows: those don't navigate —
107
+ * selecting the row closes the menu and opens the row's dialog. Dialogs are
108
+ * mounted here persistently (driven by an open flag per row) so they survive
109
+ * the (transient) dropdown, exactly as the pre-registry static dialogs did.
110
+ *
111
+ * Open/close mechanics mirror PrHeaderOverflowMenu: click toggles, an outside
112
+ * mousedown or Escape closes. Rendered for all users; the admin section is
113
+ * gated on `isAdmin`, and the trigger's unread badge only shows for admins.
114
+ */
115
+ export function AdminMenu() {
116
+ const navigate = useNavigate();
117
+ const { isAdmin, unreadCount } = useAdmin();
118
+ const registry = useAppRegistry();
119
+ const [open, setOpen] = useState(false);
120
+ // Per-row dialog open flags, keyed by item id. A plain map (rather than one
121
+ // "active dialog" slot) preserves the historical behavior where two dialogs
122
+ // opened in sequence can coexist until each is closed on its own.
123
+ const [openDialogs, setOpenDialogs] = useState<Record<string, boolean>>({});
124
+ const ref = useRef<HTMLDivElement>(null);
125
+ const buttonRef = useRef<HTMLButtonElement>(null);
126
+
127
+ const { defaultItems, adminItems } = useMemo(() => {
128
+ const all = [...CORE_MENU_ITEMS, ...registry.adminMenuItems];
129
+ const bySection = (section: 'default' | 'admin') =>
130
+ all
131
+ .filter((item) => (item.section ?? 'default') === section)
132
+ .sort((a, b) => (a.order ?? 100) - (b.order ?? 100));
133
+ return { defaultItems: bySection('default'), adminItems: bySection('admin') };
134
+ }, [registry]);
135
+
136
+ // Only admins have the Feedback Inbox, so the unread badge is admin-only too.
137
+ const showBadge = isAdmin && unreadCount > 0;
138
+
139
+ // Close and hand focus back to the trigger, so keyboard/screen-reader users
140
+ // don't get dropped onto document.body when a focused menu item unmounts.
141
+ const close = () => {
142
+ setOpen(false);
143
+ buttonRef.current?.focus();
144
+ };
145
+
146
+ useEffect(() => {
147
+ if (!open) return;
148
+ const onMouseDown = (e: MouseEvent) => {
149
+ if (ref.current && !ref.current.contains(e.target as Node)) {
150
+ close();
151
+ }
152
+ };
153
+ const onKey = (e: KeyboardEvent) => {
154
+ if (e.key === 'Escape') close();
155
+ };
156
+ document.addEventListener('mousedown', onMouseDown);
157
+ document.addEventListener('keydown', onKey);
158
+ return () => {
159
+ document.removeEventListener('mousedown', onMouseDown);
160
+ document.removeEventListener('keydown', onKey);
161
+ };
162
+ }, [open]);
163
+
164
+ // Open a dialog from a menu row: close the menu first (so focus/scroll state
165
+ // is clean), then flip the dialog open.
166
+ const openDialog = (id: string) => {
167
+ close();
168
+ setOpenDialogs((prev) => ({ ...prev, [id]: true }));
169
+ };
170
+ const closeDialog = (id: string) => {
171
+ setOpenDialogs((prev) => ({ ...prev, [id]: false }));
172
+ };
173
+
174
+ const handleSelect = (item: AdminMenuItem) => {
175
+ if (item.dialog) {
176
+ openDialog(item.id);
177
+ return;
178
+ }
179
+ item.onSelect?.({ closeMenu: close, navigate });
180
+ };
181
+
182
+ const renderRow = (item: AdminMenuItem) => (
183
+ <MenuItem key={item.id} icon={item.icon} onSelect={() => handleSelect(item)}>
184
+ {item.label}
185
+ </MenuItem>
186
+ );
187
+
188
+ const renderDialogs = (items: AdminMenuItem[]) =>
189
+ items
190
+ .filter((item) => item.dialog)
191
+ .map((item) => (
192
+ <Fragment key={item.id}>
193
+ {item.dialog!({
194
+ open: !!openDialogs[item.id],
195
+ onClose: () => closeDialog(item.id),
196
+ })}
197
+ </Fragment>
198
+ ));
199
+
200
+ return (
201
+ <div ref={ref} className="relative">
202
+ <button
203
+ ref={buttonRef}
204
+ type="button"
205
+ onClick={() => setOpen((v) => !v)}
206
+ className="relative p-1.5 rounded hover:bg-slate-100 text-slate-600 hover:text-slate-900"
207
+ title="Menu"
208
+ aria-label={showBadge ? `Menu, ${unreadCount} new feedback` : 'Menu'}
209
+ aria-haspopup="menu"
210
+ aria-expanded={open}
211
+ aria-controls={open ? MENU_ID : undefined}
212
+ >
213
+ <Settings size={16} />
214
+ {showBadge && (
215
+ <span
216
+ className="absolute top-0.5 right-0.5 block w-2 h-2 rounded-full bg-red-500 ring-2 ring-white"
217
+ aria-hidden="true"
218
+ />
219
+ )}
220
+ </button>
221
+ {open && (
222
+ <div
223
+ id={MENU_ID}
224
+ role="menu"
225
+ className="absolute right-0 top-full mt-1 z-40 bg-white border border-slate-200 rounded shadow-md py-1 flex flex-col items-stretch min-w-[13rem]"
226
+ >
227
+ {defaultItems.map(renderRow)}
228
+
229
+ {isAdmin && adminItems.length > 0 && (
230
+ <div role="group" aria-labelledby="admin-menu-admin-section-label">
231
+ <div
232
+ role="presentation"
233
+ id="admin-menu-admin-section-label"
234
+ className="mt-1 pt-1 border-t border-slate-200 px-3 pb-0.5 text-[10px] font-semibold uppercase tracking-wide text-slate-400"
235
+ >
236
+ Admin only
237
+ </div>
238
+ {adminItems.map(renderRow)}
239
+ </div>
240
+ )}
241
+ </div>
242
+ )}
243
+
244
+ {/* Dialogs opened by the menu rows above. Mounted at the menu root so they
245
+ persist independently of the (transient) dropdown. */}
246
+ {renderDialogs(defaultItems)}
247
+ {isAdmin && renderDialogs(adminItems)}
248
+ </div>
249
+ );
250
+ }
@@ -0,0 +1,108 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Check, ChevronDown } from 'lucide-react';
3
+ import { useLocation, useNavigate } from 'react-router-dom';
4
+ import { activeAppId, useAppRegistry, type AppDef } from '../../../core/registry';
5
+
6
+ const MENU_ID = 'app-switcher-menu';
7
+
8
+ /**
9
+ * The clickable brand in the toolbar's top-left: shows the product name and
10
+ * opens the app switcher — the list of top-level surfaces (core apps +
11
+ * registry-contributed ones) the user can move between.
12
+ *
13
+ * Open/close mechanics mirror AdminMenu: click toggles, an outside mousedown
14
+ * or Escape closes, and closing hands focus back to the trigger.
15
+ */
16
+ export function AppSwitcher() {
17
+ const navigate = useNavigate();
18
+ const location = useLocation();
19
+ const registry = useAppRegistry();
20
+ const [open, setOpen] = useState(false);
21
+ const ref = useRef<HTMLDivElement>(null);
22
+ const buttonRef = useRef<HTMLButtonElement>(null);
23
+
24
+ // The shell merges the core apps into the registry (see CoreAppShell), so
25
+ // this list is complete — core Knowledge / Skills & Tools plus extensions.
26
+ const apps = useMemo(
27
+ () => [...registry.apps].sort((a, b) => (a.order ?? 100) - (b.order ?? 100)),
28
+ [registry],
29
+ );
30
+ const activeId = activeAppId(apps, location.pathname);
31
+
32
+ const close = () => {
33
+ setOpen(false);
34
+ buttonRef.current?.focus();
35
+ };
36
+
37
+ useEffect(() => {
38
+ if (!open) return;
39
+ const onMouseDown = (e: MouseEvent) => {
40
+ if (ref.current && !ref.current.contains(e.target as Node)) {
41
+ close();
42
+ }
43
+ };
44
+ const onKey = (e: KeyboardEvent) => {
45
+ if (e.key === 'Escape') close();
46
+ };
47
+ document.addEventListener('mousedown', onMouseDown);
48
+ document.addEventListener('keydown', onKey);
49
+ return () => {
50
+ document.removeEventListener('mousedown', onMouseDown);
51
+ document.removeEventListener('keydown', onKey);
52
+ };
53
+ }, [open]);
54
+
55
+ const select = (app: AppDef) => {
56
+ close();
57
+ if (app.id !== activeId) navigate(app.path);
58
+ };
59
+
60
+ return (
61
+ <div ref={ref} className="relative">
62
+ <button
63
+ ref={buttonRef}
64
+ type="button"
65
+ onClick={() => setOpen((v) => !v)}
66
+ className="flex items-center gap-1 px-1.5 py-1 rounded hover:bg-slate-100 text-slate-900"
67
+ title="Switch app"
68
+ aria-label="Switch app"
69
+ aria-haspopup="menu"
70
+ aria-expanded={open}
71
+ aria-controls={open ? MENU_ID : undefined}
72
+ >
73
+ <span className="text-sm font-semibold tracking-wide">Bevel</span>
74
+ <ChevronDown size={14} className="text-slate-500" />
75
+ </button>
76
+ {open && (
77
+ <div
78
+ id={MENU_ID}
79
+ role="menu"
80
+ className="absolute left-0 top-full mt-1 w-64 rounded-md border border-slate-200 bg-white py-1 shadow-lg z-50"
81
+ >
82
+ <div className="px-3 pt-1 pb-1.5 text-[10px] font-semibold uppercase tracking-wider text-slate-400">
83
+ Apps
84
+ </div>
85
+ {apps.map((app) => (
86
+ <button
87
+ key={app.id}
88
+ type="button"
89
+ role="menuitem"
90
+ onClick={() => select(app)}
91
+ className="flex w-full items-start gap-2 px-3 py-2 text-left hover:bg-slate-100"
92
+ >
93
+ <span className="w-4 pt-0.5 shrink-0 text-slate-700">
94
+ {app.id === activeId && <Check size={14} aria-label="Current app" />}
95
+ </span>
96
+ <span className="min-w-0">
97
+ <span className="block text-sm text-slate-800">{app.label}</span>
98
+ {app.description && (
99
+ <span className="block text-xs text-slate-500">{app.description}</span>
100
+ )}
101
+ </span>
102
+ </button>
103
+ ))}
104
+ </div>
105
+ )}
106
+ </div>
107
+ );
108
+ }