@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,82 @@
1
+ import { createContext, useContext } from 'react';
2
+ import type {
3
+ BranchInfo,
4
+ CommitAttribution,
5
+ WorkingTreeStatus,
6
+ } from '@bevel-software/platform-shared';
7
+
8
+ export interface GitContextValue {
9
+ status: WorkingTreeStatus | null;
10
+ branches: BranchInfo[];
11
+ availability: 'loading' | 'error' | 'ready';
12
+ lastError: string | null;
13
+ /**
14
+ * Re-fetch the working-tree status and update the context. Returns the
15
+ * fresh status so callers that need to react to the new value (e.g. a
16
+ * post-chat handler reconciling the URL against an agent-driven branch
17
+ * switch) don't have to wait for React state to flush.
18
+ */
19
+ refreshStatus(): Promise<WorkingTreeStatus | null>;
20
+ /** `fresh` forces a server-side `git fetch --prune`, bypassing the implicit
21
+ * fetch TTL — use it for user-initiated refreshes (e.g. opening the branch
22
+ * selector) so remote create/delete from another workspace reflects at once. */
23
+ refreshBranches(opts?: { fresh?: boolean }): Promise<void>;
24
+ /**
25
+ * Create a new draft branch (server-side) and refresh the local branch
26
+ * list. Does NOT change the active branch — the caller is responsible
27
+ * for navigating to the new branch's URL, which triggers the per-branch
28
+ * workspace bootstrap. Under the per-branch workspace model there is no
29
+ * separate "switch" step.
30
+ */
31
+ createBranch(name: string, fromBase?: string): Promise<void>;
32
+ /**
33
+ * Delete a local branch. `onlyIfNoRemote` (default false) gates the call on
34
+ * the remote counterpart being absent — used by the PR-prune flow so we
35
+ * can't nuke a branch still in use by others.
36
+ */
37
+ deleteBranch(name: string, opts?: { onlyIfNoRemote?: boolean }): Promise<void>;
38
+ // `forkToDraft` removed: identical in behaviour to `createBranch` under
39
+ // save=share + per-branch workspaces (no dirty-tree carry-along ever
40
+ // happens). Use `createBranch` and navigate to the new branch's URL.
41
+ /**
42
+ * `git pull --rebase` the current branch from origin, then refresh status
43
+ * and branches. Throws on failure (network, auth, rebase abort) so the
44
+ * caller can surface a message; on success the banner driving this call
45
+ * unmounts automatically once `unmergedFromUpstream` flips to false. Status
46
+ * refresh runs even when the pull fails so the UI reflects the resulting
47
+ * server state. App-level auto-update code calls this only for clean
48
+ * protected branches.
49
+ */
50
+ pull(): Promise<void>;
51
+ /**
52
+ * Resolve which protected branch `branch` was forked from, or null if
53
+ * `branch` is itself protected / can't be resolved.
54
+ */
55
+ fetchForkBase(branch: string): Promise<string | null>;
56
+ revert(sha: string): Promise<CommitAttribution>;
57
+ fetchFileHistory(path: string, limit?: number): Promise<CommitAttribution[]>;
58
+ fetchFileDiff(path: string, sha: string): Promise<string>;
59
+ /**
60
+ * Unified diff of `path` between two branches. Read-only; nothing is
61
+ * checked out or written. `fromBranch` and `toBranch` must be names from
62
+ * `branches` (local or origin-only). Empty string means the file is
63
+ * identical on both sides.
64
+ */
65
+ fetchFileComparison(
66
+ path: string,
67
+ fromBranch: string,
68
+ toBranch: string,
69
+ ): Promise<string>;
70
+ // `fetchWorkingStatus` + `fetchWorkingDiff` removed: under save=share the
71
+ // working tree is never dirty, so both surfaces always report the empty
72
+ // state. Cross-branch comparison + commit history cover the meaningful
73
+ // diff cases.
74
+ }
75
+
76
+ export const GitContext = createContext<GitContextValue | null>(null);
77
+
78
+ export function useGit(): GitContextValue {
79
+ const ctx = useContext(GitContext);
80
+ if (!ctx) throw new Error('useGit must be used within GitContext.Provider');
81
+ return ctx;
82
+ }
@@ -0,0 +1,40 @@
1
+ import type { ReactNode } from 'react';
2
+ import { useMediaQuery } from '../hooks/useMediaQuery';
3
+ import { ResizableThreePaneLayout } from './ResizableThreePaneLayout';
4
+ import { MobileChatLayout } from './MobileChatLayout';
5
+ import type { LayoutController } from '../state/layout.context';
6
+ import type { PaneDef } from '../../../core/registry';
7
+
8
+ interface AppLayoutProps {
9
+ /** Optional now that the Toolbar lives above the app surfaces in the shell. */
10
+ header?: ReactNode;
11
+ /** Registry-driven pane list (preferred). */
12
+ panes?: PaneDef[];
13
+ /**
14
+ * Reports the pane controller to an ancestor provider (the shell), so a
15
+ * toolbar OUTSIDE this layout can drive the pane toggles. Called with null
16
+ * on unmount (app switched away → no panes to toggle).
17
+ */
18
+ onController?: (controller: LayoutController | null) => void;
19
+ // Legacy named slots, kept as a convenience/compat signature.
20
+ explorer?: ReactNode;
21
+ viewer?: ReactNode;
22
+ chat?: ReactNode;
23
+ }
24
+
25
+ // Tailwind's `md` breakpoint. Below this width the three-pane layout is
26
+ // unusable, so we swap in the chat-first mobile layout.
27
+ const MOBILE_QUERY = '(max-width: 767px)';
28
+
29
+ export function AppLayout(props: AppLayoutProps) {
30
+ const isMobile = useMediaQuery(MOBILE_QUERY);
31
+ // The mobile layout pins the chat pane full-screen, so it only makes sense
32
+ // when a 'chat' pane is registered at all; without one (core-only builds)
33
+ // the resizable layout is used at every width.
34
+ const hasChatPane = props.panes
35
+ ? props.panes.some((p) => p.id === 'chat')
36
+ : props.chat !== undefined;
37
+ const Layout =
38
+ isMobile && hasChatPane ? MobileChatLayout : ResizableThreePaneLayout;
39
+ return <Layout {...props} />;
40
+ }
@@ -0,0 +1,57 @@
1
+ import { Clock } from 'lucide-react';
2
+
3
+ /**
4
+ * App-wide demo notice. Renders for every authenticated user to make clear the
5
+ * deployment is an evaluation copy and to carry a real expiry date — the gentle
6
+ * urgency cue for converting from the free demo to a paid plan.
7
+ *
8
+ * The expiry is per-tenant, set via the `DEMO_EXPIRY` env var (an ISO date such
9
+ * as `2026-07-06`), injected into the bundle by Vite `define`. When the var is
10
+ * unset or unparseable the banner does not render at all — production tenants
11
+ * simply leave it blank.
12
+ */
13
+ // Module-scoped declaration: the `process.env.DEMO_EXPIRY` token below is
14
+ // statically replaced by the consuming bundler (Vite `define`), so this file
15
+ // must typecheck without @types/node — consumers of this raw-source package
16
+ // don't necessarily load node typings in their browser tsconfig.
17
+ declare const process: { env: Record<string, string | undefined> };
18
+
19
+ const rawExpiry = process.env.DEMO_EXPIRY ?? '';
20
+ const parsed = rawExpiry ? new Date(rawExpiry) : null;
21
+ const DEMO_EXPIRY = parsed && !Number.isNaN(parsed.getTime()) ? parsed : null;
22
+
23
+ const EXPIRY_LABEL = DEMO_EXPIRY?.toLocaleDateString(undefined, {
24
+ day: 'numeric',
25
+ month: 'long',
26
+ year: 'numeric',
27
+ });
28
+
29
+ export function DemoBanner() {
30
+ // No expiry configured for this tenant → not a demo deployment.
31
+ if (!DEMO_EXPIRY) return null;
32
+
33
+ const now = new Date();
34
+ const msLeft = DEMO_EXPIRY.getTime() - now.getTime();
35
+ const daysLeft = Math.ceil(msLeft / (1000 * 60 * 60 * 24));
36
+ const expired = msLeft <= 0;
37
+
38
+ return (
39
+ <div
40
+ role="status"
41
+ className="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm shrink-0"
42
+ >
43
+ <Clock size={16} className="shrink-0" />
44
+ <span className="flex-1">
45
+ <span className="font-semibold">Demo version.</span>{' '}
46
+ {expired ? (
47
+ <>This demo expired on {EXPIRY_LABEL}. Contact Bevel to keep your knowledge base live.</>
48
+ ) : (
49
+ <>
50
+ This is a free evaluation that expires on {EXPIRY_LABEL}
51
+ {daysLeft <= 14 && ` (${daysLeft} ${daysLeft === 1 ? 'day' : 'days'} left)`}.
52
+ </>
53
+ )}
54
+ </span>
55
+ </div>
56
+ );
57
+ }
@@ -0,0 +1,104 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { Loader2 } from 'lucide-react';
3
+ import { API_UNREACHABLE_EVENT } from '../../../lib/api';
4
+
5
+ /** How often to re-probe `/api/health` while the backend is down. */
6
+ const HEALTH_POLL_MS = 3_000;
7
+
8
+ /** Abort a probe that hangs (black-holed connection) — the probe loop gates
9
+ on each probe finishing, so a stuck fetch would freeze the overlay. */
10
+ const HEALTH_PROBE_TIMEOUT_MS = 5_000;
11
+
12
+ /**
13
+ * Probe the backend. Bypasses `authFetch` on purpose: the health route is
14
+ * unauthenticated, and a probe must never itself dispatch the
15
+ * unreachable event this overlay listens for. A timed-out probe counts as
16
+ * unhealthy.
17
+ */
18
+ async function backendHealthy(): Promise<boolean> {
19
+ const controller = new AbortController();
20
+ const timer = setTimeout(() => controller.abort(), HEALTH_PROBE_TIMEOUT_MS);
21
+ try {
22
+ const res = await fetch('/api/health', { cache: 'no-store', signal: controller.signal });
23
+ if (!res.ok) return false;
24
+ const body = (await res.json()) as { status?: string };
25
+ return body.status === 'ok';
26
+ } catch {
27
+ return false;
28
+ } finally {
29
+ clearTimeout(timer);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Full-screen "we're updating" screen for backend downtime (Coolify rebuild /
35
+ * container restart). Flow:
36
+ *
37
+ * 1. `authFetch` dispatches API_UNREACHABLE_EVENT when a request fails at
38
+ * the transport level (network error, or a 502/503/504 from the proxy
39
+ * in front of a dead upstream).
40
+ * 2. On that signal we confirm via `/api/health` — a single flaky request
41
+ * must not take over the whole screen. Only a failed probe shows the
42
+ * overlay.
43
+ * 3. While down, re-probe every HEALTH_POLL_MS. When health comes back the
44
+ * page reloads so the browser picks up the freshly deployed frontend
45
+ * bundle instead of running the old one against the new backend. If the
46
+ * user has unsaved work, FileViewer's `beforeunload` guard makes the
47
+ * browser ask before the reload discards it.
48
+ *
49
+ * This only covers users with the app already open. A fresh page load during
50
+ * the rebuild is answered by the proxy before our code runs — that error page
51
+ * is Coolify/Traefik configuration, not frontend code (see docs/deploy.md).
52
+ */
53
+ export function MaintenanceOverlay() {
54
+ const [down, setDown] = useState(false);
55
+
56
+ useEffect(() => {
57
+ let cancelled = false;
58
+ // Collapse overlapping signals: many in-flight requests fail at once
59
+ // when the backend goes away, but one probe loop is enough.
60
+ let probing = false;
61
+
62
+ const onUnreachable = async () => {
63
+ if (probing || cancelled) return;
64
+ probing = true;
65
+ try {
66
+ if (await backendHealthy()) return; // isolated failure, not downtime
67
+ if (cancelled) return;
68
+ setDown(true);
69
+ while (!cancelled) {
70
+ await new Promise((r) => setTimeout(r, HEALTH_POLL_MS));
71
+ if (await backendHealthy()) {
72
+ window.location.reload();
73
+ return;
74
+ }
75
+ }
76
+ } finally {
77
+ probing = false;
78
+ }
79
+ };
80
+
81
+ window.addEventListener(API_UNREACHABLE_EVENT, onUnreachable);
82
+ return () => {
83
+ cancelled = true;
84
+ window.removeEventListener(API_UNREACHABLE_EVENT, onUnreachable);
85
+ };
86
+ }, []);
87
+
88
+ if (!down) return null;
89
+
90
+ return (
91
+ <div className="fixed inset-0 z-[100] flex flex-col items-center justify-center gap-4 bg-white/95 backdrop-blur-sm text-center px-6">
92
+ <Loader2 size={32} className="animate-spin text-bevel" />
93
+ <div>
94
+ <p className="text-lg font-medium text-slate-800">
95
+ We&rsquo;re installing an update
96
+ </p>
97
+ <p className="mt-1 text-sm text-slate-600">
98
+ This usually takes a minute or two. The page will refresh
99
+ automatically as soon as everything is back.
100
+ </p>
101
+ </div>
102
+ </div>
103
+ );
104
+ }
@@ -0,0 +1,153 @@
1
+ import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
2
+ import { useLocation, useMatch, useNavigate } from 'react-router-dom';
3
+ import { X } from 'lucide-react';
4
+ import { LayoutContext, type LayoutController } from '../state/layout.context';
5
+ import { KB_ROUTE_PREFIX, kbFileUrl } from '../../workspace/routing/kb-routes';
6
+ import { SlideOverlay } from './SlideOverlay';
7
+ import type { PaneDef } from '../../../core/registry';
8
+
9
+ interface MobileChatLayoutProps {
10
+ header?: ReactNode;
11
+ /** Reports the pane controller upward (null on unmount) — see AppLayout. */
12
+ onController?: (controller: LayoutController | null) => void;
13
+ /**
14
+ * Registry-driven pane list (preferred). This layout is chat-first, so it
15
+ * picks the well-known 'explorer' / 'viewer' / 'chat' panes out of the
16
+ * list — AppLayout only selects it when a 'chat' pane is registered.
17
+ */
18
+ panes?: PaneDef[];
19
+ // Legacy named slots, kept as a convenience/compat signature.
20
+ explorer?: ReactNode;
21
+ viewer?: ReactNode;
22
+ chat?: ReactNode;
23
+ }
24
+
25
+ export function MobileChatLayout({
26
+ header,
27
+ panes,
28
+ onController,
29
+ explorer: explorerSlot,
30
+ viewer: viewerSlot,
31
+ chat: chatSlot,
32
+ }: MobileChatLayoutProps) {
33
+ const explorer = panes
34
+ ? panes.find((p) => p.id === 'explorer')?.node
35
+ : explorerSlot;
36
+ const viewer = panes ? panes.find((p) => p.id === 'viewer')?.node : viewerSlot;
37
+ const chat = panes ? panes.find((p) => p.id === 'chat')?.node : chatSlot;
38
+ const [isExplorerOpen, setIsExplorerOpen] = useState(false);
39
+ const location = useLocation();
40
+ const navigate = useNavigate();
41
+
42
+ // Auto-close the explorer drawer whenever the URL changes (e.g. user tapped
43
+ // a file in the tree). Without this the drawer would stay open over the chat
44
+ // and obscure the viewer sheet that's about to slide in.
45
+ const pathname = location.pathname;
46
+ useEffect(() => {
47
+ setIsExplorerOpen(false);
48
+ }, [pathname]);
49
+
50
+ const toggleExplorer = useCallback(() => {
51
+ setIsExplorerOpen((v) => !v);
52
+ }, []);
53
+
54
+ // Chat is always full-screen on mobile, so its toggle is hidden and the
55
+ // collapse flag is locked to false. Toggle is a no-op to satisfy the contract.
56
+ const noopToggleChat = useCallback(() => {}, []);
57
+
58
+ const controller = useMemo<LayoutController>(
59
+ () => ({
60
+ // The drawer's open state is conceptually the opposite of "collapsed".
61
+ // Toolbar reads isExplorerCollapsed to drive the hamburger's pressed
62
+ // state and tooltip — mapping open→!collapsed keeps that wiring honest.
63
+ isExplorerCollapsed: !isExplorerOpen,
64
+ isChatCollapsed: false,
65
+ canToggleExplorer: true,
66
+ canToggleChat: false,
67
+ toggleExplorer,
68
+ toggleChat: noopToggleChat,
69
+ }),
70
+ [isExplorerOpen, toggleExplorer, noopToggleChat],
71
+ );
72
+
73
+ // Mirror the controller to the shell (whose provider wraps the toolbar) —
74
+ // same object as the inner provider below, so the two stay consistent.
75
+ useEffect(() => {
76
+ onController?.(controller);
77
+ return () => onController?.(null);
78
+ }, [controller, onController]);
79
+
80
+ // Viewer sheet visibility is URL-driven: open iff the URL is on the KB route
81
+ // AND points at a file (the `*` segment is non-empty). Closing the sheet
82
+ // navigates back to the branch root, which the same match treats as closed.
83
+ //
84
+ // `useMatch` returns params already URI-decoded (React Router v6+), so use
85
+ // them as-is — re-decoding would throw URIError on legitimate names like
86
+ // `release-50%` whose URL form is `release-50%25`.
87
+ const match = useMatch(`${KB_ROUTE_PREFIX}/:branch/*`);
88
+ const branch = match?.params.branch ?? null;
89
+ const filePath = match?.params['*'] ?? '';
90
+ const isViewerOpen = !!branch && filePath.length > 0;
91
+
92
+ const closeViewer = useCallback(() => {
93
+ if (!branch) return;
94
+ navigate(kbFileUrl(branch));
95
+ }, [branch, navigate]);
96
+
97
+ return (
98
+ <LayoutContext.Provider value={controller}>
99
+ <div className="flex flex-col h-full bg-white text-slate-900">
100
+ {header}
101
+ <div className="flex-1 min-h-0">
102
+ {chat}
103
+ </div>
104
+ </div>
105
+
106
+ <SlideOverlay
107
+ open={isExplorerOpen}
108
+ onClose={() => setIsExplorerOpen(false)}
109
+ side="left"
110
+ ariaLabel="File explorer"
111
+ panelClassName="w-[85vw] max-w-sm flex flex-col"
112
+ >
113
+ <div className="flex-1 min-h-0 overflow-hidden">{explorer}</div>
114
+ </SlideOverlay>
115
+
116
+ <SlideOverlay
117
+ open={isViewerOpen}
118
+ onClose={closeViewer}
119
+ side="bottom"
120
+ ariaLabel="File preview"
121
+ panelClassName="h-[92vh] rounded-t-2xl flex flex-col"
122
+ swipeToClose
123
+ >
124
+ {/* The drag-handle area is a sibling of the close button, not its
125
+ ancestor. SlideOverlay's `closest('[data-swipe-handle="true"]')`
126
+ check therefore only fires when the gesture starts on the grip
127
+ zone — taps on the close button walk up past a header that does
128
+ NOT carry the attribute and so don't initiate a drag. */}
129
+ <div className="h-9 flex items-center px-2 shrink-0 border-b border-slate-200">
130
+ <div
131
+ data-swipe-handle="true"
132
+ className="flex-1 self-stretch flex items-center justify-center cursor-grab touch-none"
133
+ aria-label="Swipe down to close"
134
+ >
135
+ <div className="w-10 h-1 rounded-full bg-slate-300" aria-hidden="true" />
136
+ </div>
137
+ <button
138
+ type="button"
139
+ onClick={closeViewer}
140
+ className="p-1.5 rounded hover:bg-slate-100 text-slate-600 hover:text-slate-900"
141
+ title="Close file"
142
+ aria-label="Close file"
143
+ >
144
+ <X size={16} />
145
+ </button>
146
+ </div>
147
+ <div className="flex-1 min-h-0 overflow-hidden">
148
+ {isViewerOpen ? viewer : null}
149
+ </div>
150
+ </SlideOverlay>
151
+ </LayoutContext.Provider>
152
+ );
153
+ }
@@ -0,0 +1,203 @@
1
+ import {
2
+ Fragment,
3
+ useCallback,
4
+ useEffect,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ type ReactNode,
9
+ type RefObject,
10
+ } from 'react';
11
+ import {
12
+ Group,
13
+ Panel,
14
+ Separator,
15
+ useDefaultLayout,
16
+ type PanelImperativeHandle,
17
+ type PanelSize,
18
+ } from 'react-resizable-panels';
19
+ import { LayoutContext, type LayoutController } from '../state/layout.context';
20
+ import type { PaneDef } from '../../../core/registry';
21
+
22
+ const LAYOUT_ID = 'bevel-shell-v1';
23
+ const SEPARATOR_CLASS =
24
+ 'w-px bg-slate-100 hover:bg-bevel-deep/60 data-[dragging=true]:bg-bevel-deep transition-colors outline-none focus-visible:bg-bevel-deep cursor-col-resize';
25
+
26
+ function getSafeLocalStorage(): Storage | undefined {
27
+ if (typeof window === 'undefined') return undefined;
28
+ try {
29
+ const storage = window.localStorage;
30
+ const probeKey = `${LAYOUT_ID}:storage-probe`;
31
+ storage.setItem(probeKey, '1');
32
+ storage.removeItem(probeKey);
33
+ return storage;
34
+ } catch {
35
+ return undefined;
36
+ }
37
+ }
38
+
39
+ interface ResizableThreePaneLayoutProps {
40
+ header?: ReactNode;
41
+ /**
42
+ * Registry-driven pane list (preferred). When provided, panel ids — and
43
+ * therefore the persisted layout shape — derive from this list.
44
+ */
45
+ panes?: PaneDef[];
46
+ /** Reports the pane controller upward (null on unmount) — see AppLayout. */
47
+ onController?: (controller: LayoutController | null) => void;
48
+ // Legacy named slots, kept as a convenience/compat signature (converted to
49
+ // the same pane list internally with the historical sizing defaults).
50
+ explorer?: ReactNode;
51
+ viewer?: ReactNode;
52
+ chat?: ReactNode;
53
+ }
54
+
55
+ export function ResizableThreePaneLayout({
56
+ header,
57
+ panes,
58
+ onController,
59
+ explorer,
60
+ viewer,
61
+ chat,
62
+ }: ResizableThreePaneLayoutProps) {
63
+ const paneList = useMemo<PaneDef[]>(() => {
64
+ if (panes && panes.length > 0) {
65
+ return [...panes].sort((a, b) => (a.order ?? 100) - (b.order ?? 100));
66
+ }
67
+ const legacy: PaneDef[] = [];
68
+ if (explorer !== undefined) {
69
+ legacy.push({
70
+ id: 'explorer',
71
+ node: explorer,
72
+ defaultSize: '17%',
73
+ minSize: '10%',
74
+ maxSize: '35%',
75
+ collapsible: true,
76
+ });
77
+ }
78
+ if (viewer !== undefined) {
79
+ legacy.push({ id: 'viewer', node: viewer, minSize: '30%' });
80
+ }
81
+ if (chat !== undefined) {
82
+ legacy.push({
83
+ id: 'chat',
84
+ node: chat,
85
+ defaultSize: '26%',
86
+ minSize: '18%',
87
+ maxSize: '50%',
88
+ collapsible: true,
89
+ });
90
+ }
91
+ return legacy;
92
+ }, [panes, explorer, viewer, chat]);
93
+
94
+ // The pane *ids* must be referentially stable across renders even though
95
+ // the pane nodes (fresh JSX) are not — useDefaultLayout keys the persisted
96
+ // layout on them.
97
+ const idsKey = paneList.map((p) => p.id).join('|');
98
+ const panelIds = useMemo(() => idsKey.split('|'), [idsKey]);
99
+
100
+ // One stable imperative-handle ref per pane id (a plain `{ current }`
101
+ // object satisfies the `panelRef` contract). Created lazily so the map
102
+ // adapts to whatever panes are registered.
103
+ const panelRefs = useRef(
104
+ new Map<string, RefObject<PanelImperativeHandle | null>>(),
105
+ );
106
+ const getPanelRef = (id: string): RefObject<PanelImperativeHandle | null> => {
107
+ let ref = panelRefs.current.get(id);
108
+ if (!ref) {
109
+ ref = { current: null };
110
+ panelRefs.current.set(id, ref);
111
+ }
112
+ return ref;
113
+ };
114
+
115
+ const storage = useMemo(() => getSafeLocalStorage(), []);
116
+ const { defaultLayout, onLayoutChanged } = useDefaultLayout({
117
+ id: LAYOUT_ID,
118
+ panelIds,
119
+ storage,
120
+ });
121
+
122
+ const [collapsedById, setCollapsedById] = useState<Record<string, boolean>>(
123
+ {},
124
+ );
125
+
126
+ const togglePane = useCallback((id: string) => {
127
+ const panel = panelRefs.current.get(id)?.current;
128
+ if (!panel) return;
129
+ if (panel.isCollapsed()) panel.expand();
130
+ else panel.collapse();
131
+ }, []);
132
+
133
+ const handlePaneResize = useCallback((id: string, size: PanelSize) => {
134
+ const isCollapsed = size.asPercentage === 0;
135
+ setCollapsedById((prev) =>
136
+ prev[id] === isCollapsed ? prev : { ...prev, [id]: isCollapsed },
137
+ );
138
+ }, []);
139
+
140
+ const collapsibleIds = useMemo(
141
+ () => new Set(paneList.filter((p) => p.collapsible).map((p) => p.id)),
142
+ [paneList],
143
+ );
144
+
145
+ const controller = useMemo<LayoutController>(
146
+ () => ({
147
+ isExplorerCollapsed: !!collapsedById['explorer'],
148
+ isChatCollapsed: !!collapsedById['chat'],
149
+ canToggleExplorer: collapsibleIds.has('explorer'),
150
+ canToggleChat: collapsibleIds.has('chat'),
151
+ toggleExplorer: () => togglePane('explorer'),
152
+ toggleChat: () => togglePane('chat'),
153
+ isPaneCollapsed: (id: string) => !!collapsedById[id],
154
+ canTogglePane: (id: string) => collapsibleIds.has(id),
155
+ togglePane,
156
+ }),
157
+ [collapsedById, collapsibleIds, togglePane],
158
+ );
159
+
160
+ // Mirror the controller to the shell (whose provider wraps the toolbar).
161
+ // The inner provider below still serves this layout's own subtree — same
162
+ // object, so the two are always consistent.
163
+ useEffect(() => {
164
+ onController?.(controller);
165
+ return () => onController?.(null);
166
+ }, [controller, onController]);
167
+
168
+ return (
169
+ <LayoutContext.Provider value={controller}>
170
+ <div className="flex flex-col h-full bg-white text-slate-900">
171
+ {header}
172
+ <Group
173
+ orientation="horizontal"
174
+ defaultLayout={defaultLayout}
175
+ onLayoutChanged={onLayoutChanged}
176
+ className="flex flex-1 min-h-0"
177
+ >
178
+ {paneList.map((pane, index) => (
179
+ <Fragment key={pane.id}>
180
+ {index > 0 && <Separator className={SEPARATOR_CLASS} />}
181
+ <Panel
182
+ id={pane.id}
183
+ panelRef={getPanelRef(pane.id)}
184
+ defaultSize={pane.defaultSize}
185
+ minSize={pane.minSize}
186
+ maxSize={pane.maxSize}
187
+ collapsible={pane.collapsible}
188
+ collapsedSize={pane.collapsible ? '0%' : undefined}
189
+ onResize={
190
+ pane.collapsible
191
+ ? (size: PanelSize) => handlePaneResize(pane.id, size)
192
+ : undefined
193
+ }
194
+ >
195
+ {pane.node}
196
+ </Panel>
197
+ </Fragment>
198
+ ))}
199
+ </Group>
200
+ </div>
201
+ </LayoutContext.Provider>
202
+ );
203
+ }