@bevel-software/platform-core-frontend 0.4.0 → 0.5.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.
- package/package.json +5 -3
- package/src/core/CoreAppShell.tsx +195 -56
- package/src/core/__tests__/AppChrome.test.tsx +125 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +130 -95
- package/src/core/__tests__/bootstrap.test.ts +63 -0
- package/src/core/bootstrap.ts +73 -0
- package/src/core/events.ts +12 -0
- package/src/core/registry.ts +58 -9
- package/src/index.css +100 -11
- package/src/index.ts +24 -23
- package/src/lib/utils.ts +114 -138
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
- package/src/modules/access/api.ts +49 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +172 -156
- package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
- package/src/modules/admin/components/UserAccountsPage.tsx +361 -353
- package/src/modules/admin/state/admin.context.tsx +15 -6
- package/src/modules/auth/components/AccountPage.tsx +11 -11
- package/src/modules/auth/components/LoginScreen.tsx +12 -12
- package/src/modules/auth/services/sso.ts +47 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
- package/src/modules/change-requests/__tests__/author.test.ts +48 -0
- package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
- package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
- package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
- package/src/modules/change-requests/change-requests.css +22 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
- package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
- package/src/modules/change-requests/services/change-requests.api.ts +45 -0
- package/src/modules/change-requests/services/propose.api.ts +162 -0
- package/src/modules/change-requests/utils/author.ts +47 -0
- package/src/modules/change-requests/utils/conflict.ts +38 -0
- package/src/modules/change-requests/utils/diff.ts +80 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
- package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
- package/src/modules/git/components/BranchSwitcher.tsx +68 -31
- package/src/modules/git/components/DiffView.tsx +4 -4
- package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
- package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
- package/src/modules/git/components/PullNeededBanner.tsx +6 -13
- package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
- package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
- package/src/modules/git/hooks/useGitState.ts +15 -14
- package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
- package/src/modules/git/services/error-messages.ts +7 -7
- package/src/modules/git/services/git.api.ts +17 -11
- package/src/modules/git/services/pr-prompts.ts +2 -2
- package/src/modules/git/state/git.context.ts +10 -1
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
- package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
- package/src/modules/layout/breakpoints.ts +6 -0
- package/src/modules/layout/components/AppLayout.tsx +17 -5
- package/src/modules/layout/components/DemoBanner.tsx +10 -1
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
- package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
- package/src/modules/layout/components/SidebarFrame.tsx +317 -0
- package/src/modules/layout/components/SidebarToggle.tsx +86 -0
- package/src/modules/layout/components/SlideOverlay.tsx +1 -1
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
- package/src/modules/layout/state/sidebar.ts +200 -0
- package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
- package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
- package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
- package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
- package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
- package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
- package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
- package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
- package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
- package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
- package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
- package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
- package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
- package/src/modules/library/__tests__/auth-harness.tsx +37 -0
- package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
- package/src/modules/library/__tests__/status.test.ts +210 -117
- package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
- package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
- package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
- package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +71 -47
- package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
- package/src/modules/library/components/GroupIndexRow.tsx +63 -0
- package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
- package/src/modules/library/components/GroupPage.tsx +373 -0
- package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
- package/src/modules/library/components/GroupsSidebar.tsx +338 -0
- package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
- package/src/modules/library/components/LibraryCard.tsx +153 -132
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +138 -254
- package/src/modules/library/components/LockGlyph.tsx +31 -0
- package/src/modules/library/components/LockedGroupView.tsx +159 -0
- package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
- package/src/modules/library/components/NewGroupDialog.tsx +112 -0
- package/src/modules/library/components/NewSkillPanel.tsx +151 -0
- package/src/modules/library/components/PageActions.tsx +156 -0
- package/src/modules/library/components/PendingSkillReview.tsx +63 -0
- package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
- package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
- package/src/modules/library/components/StatusDot.tsx +25 -0
- package/src/modules/library/components/ToolLogo.tsx +171 -0
- package/src/modules/library/components/group-page-parts.tsx +419 -0
- package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
- package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
- package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
- package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
- package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
- package/src/modules/library/hooks/useJoinRequests.ts +114 -0
- package/src/modules/library/hooks/useLibraryData.ts +134 -119
- package/src/modules/library/hooks/useSkillDetail.ts +119 -74
- package/src/modules/library/hooks/useToolPage.ts +145 -0
- package/src/modules/library/library.css +108 -320
- package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
- package/src/modules/library/routes/library-paths.ts +191 -0
- package/src/modules/library/services/groups.api.ts +189 -0
- package/src/modules/library/services/library.api.ts +291 -164
- package/src/modules/library/services/tools.api.ts +60 -0
- package/src/modules/library/state/library-context.ts +22 -0
- package/src/modules/library/state/library-data.tsx +223 -0
- package/src/modules/library/state/toast.context.ts +32 -0
- package/src/modules/library/state/toast.tsx +84 -42
- package/src/modules/library/utils/clipboard.ts +33 -0
- package/src/modules/library/utils/group-summary.ts +68 -0
- package/src/modules/library/utils/names.ts +30 -0
- package/src/modules/library/utils/navigate-external.ts +15 -0
- package/src/modules/library/utils/oauth-fragment.ts +32 -0
- package/src/modules/library/utils/personal-group.ts +36 -0
- package/src/modules/library/utils/status.ts +199 -116
- package/src/modules/library/utils/toast-duration.ts +16 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
- package/src/modules/onboarding/agent-clients.ts +48 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
- package/src/modules/onboarding/components/RootLanding.tsx +54 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
- package/src/modules/onboarding/paths.ts +9 -0
- package/src/modules/onboarding/state/onboarding.ts +191 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
- package/src/modules/pr/services/pr-approvals.api.ts +19 -0
- package/src/modules/pr/services/pr-cancel.api.ts +11 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
- package/src/modules/review/components/DiffViewer.tsx +4 -4
- package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
- package/src/modules/review/components/ReviewFileRow.tsx +10 -10
- package/src/modules/review/components/ReviewPanel.tsx +49 -17
- package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
- package/src/modules/secrets-vault/components/SecretsPage.tsx +313 -276
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +82 -51
- package/src/modules/secrets-vault/services/connect.api.ts +24 -3
- package/src/modules/settings/components/DeploymentPage.tsx +90 -0
- package/src/modules/settings/components/SettingsLayout.tsx +135 -0
- package/src/modules/settings/components/SettingsNav.tsx +114 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
- package/src/modules/settings/settings-nav-items.tsx +166 -0
- package/src/modules/setup/__tests__/setup.test.tsx +540 -0
- package/src/modules/setup/components/SetupGate.tsx +67 -0
- package/src/modules/setup/components/SetupScreen.tsx +573 -0
- package/src/modules/setup/services/setup.api.ts +106 -0
- package/src/modules/setup/utils/git-host.ts +34 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +131 -108
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
- package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
- package/src/modules/toolbar/components/Toolbar.tsx +56 -54
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
- package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
- package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
- package/src/modules/workspace/components/EditorTabs.tsx +82 -50
- package/src/modules/workspace/components/FileExplorer.tsx +1292 -1068
- package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
- package/src/modules/workspace/components/FileRoute.tsx +89 -84
- package/src/modules/workspace/components/FileViewer.tsx +1312 -906
- package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
- package/src/modules/workspace/components/KbFileRail.tsx +128 -0
- package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
- package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
- package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
- package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
- package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
- package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
- package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
- package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
- package/src/modules/workspace/components/renderers/index.ts +78 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
- package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
- package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
- package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
- package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
- package/src/modules/workspace/services/workspace.api.ts +9 -2
- package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
- package/src/modules/workspace/state/open-change-requests.tsx +185 -0
- package/src/modules/workspace/state/workspace.context.ts +9 -0
- package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
- package/src/modules/workspace/utils/diff.ts +130 -53
- package/src/modules/workspace/utils/fileTree.ts +182 -179
- package/src/modules/workspace/workspace.css +28 -0
- package/src/shared/components/Badge.tsx +62 -0
- package/src/shared/components/Banner.tsx +58 -0
- package/src/shared/components/Button.tsx +90 -0
- package/src/shared/components/Dialog.tsx +6 -6
- package/src/shared/components/Field.tsx +45 -0
- package/src/shared/components/IconButton.tsx +74 -0
- package/src/shared/components/ListRow.tsx +96 -0
- package/src/shared/components/Menu.tsx +88 -0
- package/src/shared/components/PageShell.tsx +54 -51
- package/src/shared/components/Surface.tsx +86 -0
- package/src/shared/components/__tests__/primitives.test.tsx +333 -0
- package/src/shared/components/index.ts +48 -0
- package/src/shared/components/useDismissableMenu.ts +71 -0
- package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
- package/src/shared/theme/index.css +12 -0
- package/src/shared/theme/measure.ts +64 -0
- package/src/shared/theme/shadows.css +34 -0
- package/src/shared/theme/tokens.css +193 -0
- package/src/test-setup.ts +9 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
- package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
- package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
- package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
- package/src/modules/library/__tests__/diff.test.ts +0 -62
- package/src/modules/library/__tests__/loadout.test.tsx +0 -72
- package/src/modules/library/components/CompareView.tsx +0 -357
- package/src/modules/library/components/DetailDialog.tsx +0 -566
- package/src/modules/library/components/GearIcon.tsx +0 -12
- package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
- package/src/modules/library/components/StatusGem.tsx +0 -21
- package/src/modules/library/components/SuggestChange.tsx +0 -171
- package/src/modules/library/components/particles.ts +0 -50
- package/src/modules/library/state/loadout.tsx +0 -129
- package/src/modules/library/utils/diff.ts +0 -102
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
- package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
- package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
- package/src/modules/pr/components/PrCancelButton.tsx +0 -99
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
- package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
- package/src/modules/pr/components/PrCommentThread.tsx +0 -168
- package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
- package/src/modules/pr/components/PrDiffPane.tsx +0 -425
- package/src/modules/pr/components/PrFileRow.tsx +0 -164
- package/src/modules/pr/components/PrFilesList.tsx +0 -53
- package/src/modules/pr/components/PrHeader.tsx +0 -45
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
- package/src/modules/pr/components/PrMergeButton.tsx +0 -268
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
- package/src/modules/pr/components/PrViewer.tsx +0 -364
- package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
- package/src/modules/pr/state/pr-viewer.context.ts +0 -34
- package/src/modules/pr/utils/bucketize-comments.ts +0 -55
- package/src/modules/pr/utils/parsePatch.ts +0 -57
- package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { Badge, Button, ListRow, TextField } from '../../../../shared/components';
|
|
3
|
+
import { startToolOAuth } from '../../../secrets-vault/services/connect.api';
|
|
4
|
+
import {
|
|
5
|
+
deleteAdminVar,
|
|
6
|
+
setAdminVar,
|
|
7
|
+
setOAuthClientSecret,
|
|
8
|
+
setUserVar,
|
|
9
|
+
type ToolVarStatus,
|
|
10
|
+
} from '../../../secrets-vault/services/tool-secrets.api';
|
|
11
|
+
import { navigateExternal } from '../../utils/navigate-external';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One `${VAR}` a tool declares, and the single next action for it.
|
|
15
|
+
*
|
|
16
|
+
* The matrix below is the whole point of this component. A variable is
|
|
17
|
+
* described by five orthogonal-looking flags (`scope`, `oauth`,
|
|
18
|
+
* `adminConfigured`, `userConfigured`, `authorized`/`needsReauth`) plus the
|
|
19
|
+
* caller's `canWrite`, and the naive rendering of that is a row with four
|
|
20
|
+
* competing controls on it. The rules that collapse it to ONE affordance:
|
|
21
|
+
*
|
|
22
|
+
* - `adminConfigured` is OVERLOADED. On a typed variable it means "a shared
|
|
23
|
+
* value exists". On an OAuth variable it means "the owner finished the
|
|
24
|
+
* provider setup" — nothing about the caller's own sign-in. Reading it as
|
|
25
|
+
* "already handled" on an OAuth row would hide the Sign in button.
|
|
26
|
+
* - `oauth-auto` NEVER gets a client-secret affordance. Its client was
|
|
27
|
+
* auto-registered by PKCE dynamic registration and has no secret; saving one
|
|
28
|
+
* would clobber the discovered provider row and break sign-in for everyone.
|
|
29
|
+
* - Whose problem is it? A user-scope gap is the caller's to fix and always
|
|
30
|
+
* shows an action. An admin-scope gap is the OWNER's, so a non-writer sees a
|
|
31
|
+
* chip that explains the state and no button they can't act on.
|
|
32
|
+
*
|
|
33
|
+
* Secret values are write-only throughout: `type="password"`, held in local
|
|
34
|
+
* state, cleared on save or cancel. Nothing here ever reads a stored value.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export interface ToolVarRowProps {
|
|
38
|
+
slug: string;
|
|
39
|
+
variable: ToolVarStatus;
|
|
40
|
+
/** The caller may set this tool's shared (owner-side) secrets. */
|
|
41
|
+
canWrite: boolean;
|
|
42
|
+
setupKind: 'open' | 'oauth-auto' | 'oauth-manual' | null;
|
|
43
|
+
/** Where the OAuth round-trip should land — a bare path, no fragment. */
|
|
44
|
+
returnTo: string;
|
|
45
|
+
/**
|
|
46
|
+
* Bumped by the section's banner to open this row's editor from a distance
|
|
47
|
+
* ("Add key" up top is the same act as "Add key" on the row). Monotonic
|
|
48
|
+
* counter rather than a boolean so pressing the banner twice re-opens a row
|
|
49
|
+
* the user has since cancelled.
|
|
50
|
+
*/
|
|
51
|
+
editSignal?: number;
|
|
52
|
+
onChanged(): void;
|
|
53
|
+
onError(message: string): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type Editor = 'value' | 'client-secret' | null;
|
|
57
|
+
|
|
58
|
+
export function ToolVarRow({
|
|
59
|
+
slug,
|
|
60
|
+
variable,
|
|
61
|
+
canWrite,
|
|
62
|
+
setupKind,
|
|
63
|
+
returnTo,
|
|
64
|
+
editSignal,
|
|
65
|
+
onChanged,
|
|
66
|
+
onError,
|
|
67
|
+
}: ToolVarRowProps) {
|
|
68
|
+
const [editor, setEditor] = useState<Editor>(null);
|
|
69
|
+
const [value, setValue] = useState('');
|
|
70
|
+
const [busy, setBusy] = useState(false);
|
|
71
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
72
|
+
|
|
73
|
+
const label = variable.label ?? variable.name;
|
|
74
|
+
|
|
75
|
+
// Opening from a distance is a PROP CHANGE, not an event, so the editor state
|
|
76
|
+
// is adjusted during render against the previous signal — React's documented
|
|
77
|
+
// pattern for deriving state from a changed prop. It used to be an effect,
|
|
78
|
+
// which set state after paint: one frame of the row rendered closed, and the
|
|
79
|
+
// synchronous setState in an effect body is what `set-state-in-effect` flags.
|
|
80
|
+
// `seenSignal` starts undefined rather than at `editSignal` so a row that
|
|
81
|
+
// MOUNTS with a signal already on it still opens, as the effect version did.
|
|
82
|
+
const [seenSignal, setSeenSignal] = useState<number | undefined>(undefined);
|
|
83
|
+
if (editSignal !== seenSignal) {
|
|
84
|
+
setSeenSignal(editSignal);
|
|
85
|
+
if (editSignal) {
|
|
86
|
+
setValue('');
|
|
87
|
+
setEditor('value');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The scroll stays an effect: it is a real DOM side effect and has to happen
|
|
92
|
+
// after the editor it scrolls to has been committed. The banner's button
|
|
93
|
+
// targets exactly one row; scrolling brings the editor to where the click
|
|
94
|
+
// happened conceptually — "fix THIS".
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!editSignal) return;
|
|
97
|
+
rootRef.current?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
98
|
+
}, [editSignal]);
|
|
99
|
+
|
|
100
|
+
function open(next: Exclude<Editor, null>) {
|
|
101
|
+
setValue('');
|
|
102
|
+
setEditor(next);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function close() {
|
|
106
|
+
setValue('');
|
|
107
|
+
setEditor(null);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Every write funnels through here so busy/close/report is identical. */
|
|
111
|
+
async function run(action: () => Promise<void>) {
|
|
112
|
+
setBusy(true);
|
|
113
|
+
try {
|
|
114
|
+
await action();
|
|
115
|
+
close();
|
|
116
|
+
onChanged();
|
|
117
|
+
} catch (err) {
|
|
118
|
+
onError(err instanceof Error ? err.message : String(err));
|
|
119
|
+
} finally {
|
|
120
|
+
setBusy(false);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function signIn() {
|
|
125
|
+
setBusy(true);
|
|
126
|
+
try {
|
|
127
|
+
const url = await startToolOAuth(slug, variable.name, { returnTo });
|
|
128
|
+
navigateExternal(url);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
onError(err instanceof Error ? err.message : String(err));
|
|
131
|
+
setBusy(false);
|
|
132
|
+
}
|
|
133
|
+
// On success the browser is leaving; leaving `busy` set keeps the button
|
|
134
|
+
// from being clicked twice during the redirect.
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const meta: ReactNode[] = [];
|
|
138
|
+
let description: string;
|
|
139
|
+
|
|
140
|
+
if (variable.oauth) {
|
|
141
|
+
// An OAuth client secret only exists for a MANUALLY declared provider.
|
|
142
|
+
const mayEditClientSecret = canWrite && setupKind !== 'oauth-auto';
|
|
143
|
+
|
|
144
|
+
if (variable.authorized && !variable.needsReauth) {
|
|
145
|
+
description = 'Each person sets their own';
|
|
146
|
+
meta.push(
|
|
147
|
+
<Badge key="chip" tone="ok">
|
|
148
|
+
Connected
|
|
149
|
+
</Badge>,
|
|
150
|
+
);
|
|
151
|
+
if (mayEditClientSecret) {
|
|
152
|
+
meta.push(
|
|
153
|
+
<Button key="secret" size="tiny" variant="quiet" onClick={() => open('client-secret')}>
|
|
154
|
+
Replace client secret
|
|
155
|
+
</Button>,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
} else if (variable.authorized) {
|
|
159
|
+
description = 'Each person sets their own';
|
|
160
|
+
meta.push(
|
|
161
|
+
<Button key="reauth" size="sm" disabled={busy} onClick={() => void signIn()}>
|
|
162
|
+
Sign in again
|
|
163
|
+
</Button>,
|
|
164
|
+
);
|
|
165
|
+
} else if (variable.adminConfigured) {
|
|
166
|
+
description = 'Each person sets their own';
|
|
167
|
+
meta.push(
|
|
168
|
+
<Button key="signin" size="sm" disabled={busy} onClick={() => void signIn()}>
|
|
169
|
+
Sign in
|
|
170
|
+
</Button>,
|
|
171
|
+
);
|
|
172
|
+
} else {
|
|
173
|
+
// The owner hasn't declared the provider (or hasn't set its secret), so
|
|
174
|
+
// there is nothing for anyone to sign in to yet.
|
|
175
|
+
description = "The tool owner hasn't finished the sign-in setup yet.";
|
|
176
|
+
if (mayEditClientSecret) {
|
|
177
|
+
meta.push(
|
|
178
|
+
<Button key="secret" size="tiny" onClick={() => open('client-secret')}>
|
|
179
|
+
Set client secret
|
|
180
|
+
</Button>,
|
|
181
|
+
);
|
|
182
|
+
} else {
|
|
183
|
+
meta.push(
|
|
184
|
+
<Badge key="chip" tone="neutral">
|
|
185
|
+
Not set
|
|
186
|
+
</Badge>,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} else if (variable.scope === 'admin') {
|
|
191
|
+
if (variable.adminConfigured) {
|
|
192
|
+
description = 'One value for the whole team. Already handled';
|
|
193
|
+
meta.push(
|
|
194
|
+
<Badge key="chip" tone="ok">
|
|
195
|
+
Set by an Admin
|
|
196
|
+
</Badge>,
|
|
197
|
+
);
|
|
198
|
+
if (canWrite) {
|
|
199
|
+
meta.push(
|
|
200
|
+
<Button key="replace" size="tiny" variant="quiet" onClick={() => open('value')}>
|
|
201
|
+
Replace
|
|
202
|
+
</Button>,
|
|
203
|
+
<Button
|
|
204
|
+
key="remove"
|
|
205
|
+
size="tiny"
|
|
206
|
+
variant="quiet"
|
|
207
|
+
disabled={busy}
|
|
208
|
+
onClick={() => void run(() => deleteAdminVar(slug, variable.name))}
|
|
209
|
+
>
|
|
210
|
+
Remove
|
|
211
|
+
</Button>,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// No "— already handled" here: the chip right next to it says the
|
|
216
|
+
// opposite, and the prototype's single string contradicts itself once
|
|
217
|
+
// the value is missing.
|
|
218
|
+
description = 'One value for the whole team';
|
|
219
|
+
if (canWrite) {
|
|
220
|
+
meta.push(
|
|
221
|
+
<Button key="set" size="tiny" onClick={() => open('value')}>
|
|
222
|
+
Set key
|
|
223
|
+
</Button>,
|
|
224
|
+
);
|
|
225
|
+
} else {
|
|
226
|
+
meta.push(
|
|
227
|
+
<Badge key="chip" tone="neutral">
|
|
228
|
+
Not set
|
|
229
|
+
</Badge>,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
description = 'Each person sets their own';
|
|
235
|
+
if (variable.userConfigured) {
|
|
236
|
+
meta.push(
|
|
237
|
+
<Badge key="chip" tone="ok">
|
|
238
|
+
Connected
|
|
239
|
+
</Badge>,
|
|
240
|
+
);
|
|
241
|
+
} else {
|
|
242
|
+
meta.push(
|
|
243
|
+
<Button key="add" size="sm" onClick={() => open('value')}>
|
|
244
|
+
Add key
|
|
245
|
+
</Button>,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const isClientSecret = editor === 'client-secret';
|
|
251
|
+
const save = () => {
|
|
252
|
+
const secret = value;
|
|
253
|
+
if (isClientSecret) {
|
|
254
|
+
return run(() => setOAuthClientSecret(slug, variable.name, secret));
|
|
255
|
+
}
|
|
256
|
+
return run(() =>
|
|
257
|
+
variable.scope === 'admin'
|
|
258
|
+
? setAdminVar(slug, variable.name, secret)
|
|
259
|
+
: setUserVar(slug, variable.name, secret),
|
|
260
|
+
);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<div ref={rootRef} className="flex flex-col gap-1.5">
|
|
265
|
+
<ListRow density="row" label={label} description={description} meta={meta} />
|
|
266
|
+
|
|
267
|
+
{editor && (
|
|
268
|
+
<div className="flex items-center gap-2 rounded-lg border border-line bg-surface px-3.5 py-3">
|
|
269
|
+
<TextField
|
|
270
|
+
type="password"
|
|
271
|
+
className="flex-1"
|
|
272
|
+
autoComplete="off"
|
|
273
|
+
aria-label={
|
|
274
|
+
isClientSecret ? `Client secret for ${variable.name}` : `Value for ${variable.name}`
|
|
275
|
+
}
|
|
276
|
+
value={value}
|
|
277
|
+
onChange={(e) => setValue(e.target.value)}
|
|
278
|
+
/>
|
|
279
|
+
<Button variant="primary" size="sm" disabled={busy || !value} onClick={() => void save()}>
|
|
280
|
+
Save
|
|
281
|
+
</Button>
|
|
282
|
+
<Button variant="quiet" size="sm" disabled={busy} onClick={close}>
|
|
283
|
+
Cancel
|
|
284
|
+
</Button>
|
|
285
|
+
</div>
|
|
286
|
+
)}
|
|
287
|
+
</div>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
3
|
+
import { grantAccess } from '../../access/api';
|
|
4
|
+
import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
|
|
5
|
+
import {
|
|
6
|
+
listJoinRequests,
|
|
7
|
+
reconcileJoinRequest,
|
|
8
|
+
type JoinProposal,
|
|
9
|
+
type JoinRequest,
|
|
10
|
+
} from '../services/groups.api';
|
|
11
|
+
import { useLibraryToast } from '../state/toast.context';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The join requests one group's managers can answer, and the two ways to
|
|
15
|
+
* answer them.
|
|
16
|
+
*
|
|
17
|
+
* ACCEPTING IS A GRANT, NOT A MERGE. A proposal is "give this principal this
|
|
18
|
+
* verb on the group folder", so accepting it calls the ordinary access-grant
|
|
19
|
+
* API — the same endpoint the Manage-access dialog uses, with the same gate,
|
|
20
|
+
* lock and commit. The request's branch is never merged, so nothing else it
|
|
21
|
+
* carries can ride in on an approval, and a request naming five people can be
|
|
22
|
+
* answered with two yeses and three ignores.
|
|
23
|
+
*
|
|
24
|
+
* The request then retires ITSELF: it is open exactly while its `access.md`
|
|
25
|
+
* grants something the default branch does not, so once the accepted grant
|
|
26
|
+
* lands the diff is empty and the server closes it and deletes the branch.
|
|
27
|
+
* `reconcile` just asks for that check immediately instead of waiting for the
|
|
28
|
+
* next listing (which does it too).
|
|
29
|
+
*
|
|
30
|
+
* Fetching is unconditional and degrades to `[]` — the endpoint answers `[]`
|
|
31
|
+
* to non-managers rather than 403, so "am I a manager here" stays a question
|
|
32
|
+
* only the server answers.
|
|
33
|
+
*/
|
|
34
|
+
export interface JoinRequestsState {
|
|
35
|
+
requests: JoinRequest[];
|
|
36
|
+
/** Grant one proposal, then settle the request if that was the last one. */
|
|
37
|
+
accept(request: JoinRequest, proposal: JoinProposal): Promise<void>;
|
|
38
|
+
/** Decline the whole request — reject the change request. */
|
|
39
|
+
decline(request: JoinRequest): Promise<void>;
|
|
40
|
+
reload(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useJoinRequests(group: string, folder: string | null): JoinRequestsState {
|
|
44
|
+
const [requests, setRequests] = useState<JoinRequest[]>([]);
|
|
45
|
+
const [revision, setRevision] = useState(0);
|
|
46
|
+
const toast = useLibraryToast();
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
let cancelled = false;
|
|
50
|
+
listJoinRequests(group)
|
|
51
|
+
.then((rows) => {
|
|
52
|
+
if (!cancelled) setRequests(rows);
|
|
53
|
+
})
|
|
54
|
+
.catch(() => {
|
|
55
|
+
// Silent: a manager surface that fails must not put an error banner in
|
|
56
|
+
// front of somebody who came to read a skill.
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
cancelled = true;
|
|
60
|
+
};
|
|
61
|
+
}, [group, revision]);
|
|
62
|
+
|
|
63
|
+
const reload = useCallback(() => setRevision((r) => r + 1), []);
|
|
64
|
+
|
|
65
|
+
const accept = useCallback(
|
|
66
|
+
async (request: JoinRequest, proposal: JoinProposal) => {
|
|
67
|
+
if (!folder) return;
|
|
68
|
+
try {
|
|
69
|
+
await grantAccess(encodeURIComponent(DEFAULT_BRANCH), {
|
|
70
|
+
path: folder,
|
|
71
|
+
kind: 'folder',
|
|
72
|
+
verb: proposal.verb,
|
|
73
|
+
principal: proposal.principal,
|
|
74
|
+
});
|
|
75
|
+
} catch (err) {
|
|
76
|
+
toast(err instanceof Error ? err.message : "Couldn't grant that: try again.", 'danger');
|
|
77
|
+
setRevision((r) => r + 1);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Drop the accepted proposal locally so the row goes immediately; the
|
|
81
|
+
// refetch below is what makes it true.
|
|
82
|
+
setRequests((rows) =>
|
|
83
|
+
rows.map((r) =>
|
|
84
|
+
r.number === request.number
|
|
85
|
+
? {
|
|
86
|
+
...r,
|
|
87
|
+
proposals: r.proposals.filter(
|
|
88
|
+
(p) => !(p.id === proposal.id && p.verb === proposal.verb),
|
|
89
|
+
),
|
|
90
|
+
}
|
|
91
|
+
: r,
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
toast(`${proposal.label} now has ${proposal.verb} access.`);
|
|
95
|
+
await reconcileJoinRequest(group, request.number).catch(() => false);
|
|
96
|
+
setRevision((r) => r + 1);
|
|
97
|
+
},
|
|
98
|
+
[folder, group, toast],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const decline = useCallback(
|
|
102
|
+
async (request: JoinRequest) => {
|
|
103
|
+
try {
|
|
104
|
+
await cancelPullRequest(request.number);
|
|
105
|
+
} catch {
|
|
106
|
+
toast("Couldn't dismiss that: try again.", 'danger');
|
|
107
|
+
}
|
|
108
|
+
setRevision((r) => r + 1);
|
|
109
|
+
},
|
|
110
|
+
[toast],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return { requests, accept, decline, reload };
|
|
114
|
+
}
|
|
@@ -1,119 +1,134 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
3
|
-
import { fetchFileAccessBatch } from '../../access/api';
|
|
4
|
-
import { listToolSecrets, type ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
getSkill,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
} from '../services/library.api';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
3
|
+
import { fetchFileAccessBatch } from '../../access/api';
|
|
4
|
+
import { listToolSecrets, type ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
5
|
+
import {
|
|
6
|
+
defaultWorkspaceId,
|
|
7
|
+
getSkill,
|
|
8
|
+
listPendingSkills,
|
|
9
|
+
listSkills,
|
|
10
|
+
type LibrarySkillSummary,
|
|
11
|
+
type PendingSkillSummary,
|
|
12
|
+
} from '../services/library.api';
|
|
13
|
+
import {
|
|
14
|
+
listMyChangeRequests,
|
|
15
|
+
listOpenChangeRequests,
|
|
16
|
+
} from '../../change-requests/services/change-requests.api';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* All the list-level data the Library gallery needs, loaded in parallel:
|
|
20
|
+
*
|
|
21
|
+
* - skills — `GET /api/skills` (default-branch catalog, canRead-filtered)
|
|
22
|
+
* - tools — `GET /api/secrets/tools` (variables + per-user config status
|
|
23
|
+
* + per-tool `canWrite`)
|
|
24
|
+
* - ownership — "owned by me" = write access on the skill's `SKILL.md`
|
|
25
|
+
* (`POST /workspace/:id/access/batch` on the default-branch
|
|
26
|
+
* workspace); tools reuse the `canWrite` the secrets route
|
|
27
|
+
* already computes
|
|
28
|
+
* - change requests — all open + the caller's own, for the review layer
|
|
29
|
+
* - pending skills — `GET /api/skills/pending`, the skills that exist only on
|
|
30
|
+
* an open change request's branch (author + approvers only)
|
|
31
|
+
*
|
|
32
|
+
* Non-critical failures degrade to empty sets rather than blocking the page —
|
|
33
|
+
* only the skills+tools pair failing surfaces as a load error.
|
|
34
|
+
*/
|
|
35
|
+
export interface LibraryData {
|
|
36
|
+
loading: boolean;
|
|
37
|
+
error: string | null;
|
|
38
|
+
skills: LibrarySkillSummary[];
|
|
39
|
+
/**
|
|
40
|
+
* Proposed skills, not yet released. Kept SEPARATE from `skills` all the way
|
|
41
|
+
* up to the gallery: everything downstream of `skills` treats an entry as a
|
|
42
|
+
* thing that exists and can be opened, and a proposal is neither.
|
|
43
|
+
*/
|
|
44
|
+
pendingSkills: PendingSkillSummary[];
|
|
45
|
+
tools: ToolSecrets[];
|
|
46
|
+
/** Skill names (folder ids) whose SKILL.md the caller can write. */
|
|
47
|
+
ownedSkills: Set<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Per-skill `allowed-tools` frontmatter (name → entries), used to derive
|
|
50
|
+
* which integrations a skill needs. Loaded via one `getSkill` per catalog
|
|
51
|
+
* entry — the browser skill surface has no bulk endpoint for frontmatter.
|
|
52
|
+
*/
|
|
53
|
+
allowedToolsBySkill: Map<string, string[]>;
|
|
54
|
+
/** Open change requests, all authors. */
|
|
55
|
+
crs: PullRequestSummary[];
|
|
56
|
+
/** Numbers of the caller's own change requests. */
|
|
57
|
+
myCrNumbers: Set<number>;
|
|
58
|
+
reload(): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useLibraryData(): LibraryData {
|
|
62
|
+
const [state, setState] = useState<Omit<LibraryData, 'reload'>>({
|
|
63
|
+
loading: true,
|
|
64
|
+
error: null,
|
|
65
|
+
skills: [],
|
|
66
|
+
pendingSkills: [],
|
|
67
|
+
tools: [],
|
|
68
|
+
ownedSkills: new Set(),
|
|
69
|
+
allowedToolsBySkill: new Map(),
|
|
70
|
+
crs: [],
|
|
71
|
+
myCrNumbers: new Set(),
|
|
72
|
+
});
|
|
73
|
+
const [revision, setRevision] = useState(0);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let cancelled = false;
|
|
77
|
+
setState((s) => ({ ...s, loading: true, error: null }));
|
|
78
|
+
|
|
79
|
+
(async () => {
|
|
80
|
+
const [skills, tools] = await Promise.all([listSkills(), listToolSecrets()]);
|
|
81
|
+
|
|
82
|
+
const [ownership, crs, mine, pending, details] = await Promise.all([
|
|
83
|
+
skills.length
|
|
84
|
+
? fetchFileAccessBatch(
|
|
85
|
+
defaultWorkspaceId(),
|
|
86
|
+
skills.map((s) => `${s.path}/SKILL.md`),
|
|
87
|
+
).catch(() => ({ results: {} as Record<string, boolean> }))
|
|
88
|
+
: Promise.resolve({ results: {} as Record<string, boolean> }),
|
|
89
|
+
listOpenChangeRequests().catch(() => [] as PullRequestSummary[]),
|
|
90
|
+
listMyChangeRequests().catch(() => [] as PullRequestSummary[]),
|
|
91
|
+
listPendingSkills().catch(() => [] as PendingSkillSummary[]),
|
|
92
|
+
Promise.all(
|
|
93
|
+
skills.map(
|
|
94
|
+
(s): Promise<[string, string[]]> =>
|
|
95
|
+
getSkill(s.name)
|
|
96
|
+
.then((d): [string, string[]] => [s.name, d.allowedTools ?? []])
|
|
97
|
+
.catch((): [string, string[]] => [s.name, []]),
|
|
98
|
+
),
|
|
99
|
+
),
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
if (cancelled) return;
|
|
103
|
+
const ownedSkills = new Set(
|
|
104
|
+
skills.filter((s) => ownership.results[`${s.path}/SKILL.md`] === true).map((s) => s.name),
|
|
105
|
+
);
|
|
106
|
+
setState({
|
|
107
|
+
loading: false,
|
|
108
|
+
error: null,
|
|
109
|
+
skills,
|
|
110
|
+
pendingSkills: pending,
|
|
111
|
+
tools,
|
|
112
|
+
ownedSkills,
|
|
113
|
+
allowedToolsBySkill: new Map(details),
|
|
114
|
+
crs: crs.filter((c) => c.state === 'open'),
|
|
115
|
+
myCrNumbers: new Set(mine.map((c) => c.number)),
|
|
116
|
+
});
|
|
117
|
+
})().catch((err) => {
|
|
118
|
+
if (cancelled) return;
|
|
119
|
+
setState((s) => ({
|
|
120
|
+
...s,
|
|
121
|
+
loading: false,
|
|
122
|
+
error: err instanceof Error ? err.message : "Couldn't load the library.",
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return () => {
|
|
127
|
+
cancelled = true;
|
|
128
|
+
};
|
|
129
|
+
}, [revision]);
|
|
130
|
+
|
|
131
|
+
const reload = useCallback(() => setRevision((r) => r + 1), []);
|
|
132
|
+
|
|
133
|
+
return { ...state, reload };
|
|
134
|
+
}
|