@bevel-software/platform-core-frontend 0.32.0 → 0.34.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 +2 -2
- package/src/core/CoreAppShell.tsx +1 -1
- package/src/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { useFileNav } from '../../routing/kb-routes';
|
|
3
|
+
import { useRendererSurface } from './rendererSurface';
|
|
4
|
+
import { Button, Dialog } from '../../../../shared/components';
|
|
5
|
+
import {
|
|
6
|
+
PageConsent,
|
|
7
|
+
PageToolsClient,
|
|
8
|
+
answerToolCall,
|
|
9
|
+
asToolCall,
|
|
10
|
+
pageName,
|
|
11
|
+
useOpenPageInPlatform,
|
|
12
|
+
usePageTools,
|
|
13
|
+
} from './htmlToolBridge';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The card the app shows over a page, outside its frame: the page cannot draw,
|
|
17
|
+
* see or answer it. `write`: the page's first writing call asks the viewer.
|
|
18
|
+
* `platform`: a page that needs tools asked for them where there are none.
|
|
19
|
+
*/
|
|
20
|
+
type PageCard = { kind: 'write' | 'platform'; answer: (ok: boolean | null) => void };
|
|
21
|
+
|
|
22
|
+
export interface HtmlToolBridgeOptions {
|
|
23
|
+
/** The renderer's frame: only messages from its window are answered, and only to it. */
|
|
24
|
+
iframeRef: RefObject<HTMLIFrameElement | null>;
|
|
25
|
+
/** The file the renderer shows, as its own props name it: what the cards name, and what Open in the platform opens. */
|
|
26
|
+
filePath: string;
|
|
27
|
+
/**
|
|
28
|
+
* The page VIEW's identity, compared with `Object.is`: change it whenever
|
|
29
|
+
* the frame's document goes — a reload, a rebuilt document, the frame
|
|
30
|
+
* unmounted (Edit). The viewer's answer about writes holds for one view;
|
|
31
|
+
* when the key changes an open card closes, every call the old view made
|
|
32
|
+
* that has not yet run is answered `closed` and runs nothing, and no reply
|
|
33
|
+
* to the old view's calls is posted into the new one — a document rebuilt
|
|
34
|
+
* in the same frame keeps the frame's window, so the window alone cannot
|
|
35
|
+
* tell the two apart. A key that does not change across a reload keeps the
|
|
36
|
+
* consent across it.
|
|
37
|
+
*/
|
|
38
|
+
viewKey: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface HtmlToolBridgeResult {
|
|
42
|
+
/**
|
|
43
|
+
* What to build the frame's document with — `buildSandboxedHtml`'s
|
|
44
|
+
* `toolBridge`: the identity minted for this view's document, which the
|
|
45
|
+
* runtime stamps on every message so the app answers only the document it
|
|
46
|
+
* built, and whether that document gets the tools (`tools: false` leaves
|
|
47
|
+
* it `bevel.tools = null`, still asking `requireTools()` as itself). A new
|
|
48
|
+
* identity per `viewKey`, so a renderer that builds its document from this
|
|
49
|
+
* value rebuilds it when the view changes, as it must.
|
|
50
|
+
*/
|
|
51
|
+
toolBridge: { documentId: string; tools: boolean };
|
|
52
|
+
/** The two cards, for the renderer to render beside its frame. */
|
|
53
|
+
cards: ReactNode;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A document's identity: unique per view, meaningful to nobody else. */
|
|
57
|
+
function newDocumentId(): string {
|
|
58
|
+
return `doc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The app's half of a page's `window.bevel.tools` and `requireTools()`, for
|
|
63
|
+
* any renderer that shows an HTML page in a sandboxed frame: which pages get
|
|
64
|
+
* tools (the app's file page, never a surface), the viewer's tool client, the
|
|
65
|
+
* per-view consent, the cards, and the frame's tool messages. A renderer
|
|
66
|
+
* passes its frame, its file and its view key, builds its document with
|
|
67
|
+
* `toolBridge`, and renders `cards` — it holds no bridge logic of its own.
|
|
68
|
+
*/
|
|
69
|
+
export function useHtmlToolBridge({ iframeRef, filePath, viewKey }: HtmlToolBridgeOptions): HtmlToolBridgeResult {
|
|
70
|
+
const { openFilePage } = useFileNav();
|
|
71
|
+
const surface = useRendererSurface();
|
|
72
|
+
// The viewer's tools, for a page on a host that provides them (the file
|
|
73
|
+
// page, the skill page — `PageToolsContext` lists them) and never on a
|
|
74
|
+
// surface. Everywhere else the page gets `bevel.tools = null`.
|
|
75
|
+
const pageTools = usePageTools();
|
|
76
|
+
const openPageInPlatform = useOpenPageInPlatform();
|
|
77
|
+
const toolPagePath = surface === null && pageTools ? pageTools.pagePath : null;
|
|
78
|
+
const toolsClient = useMemo(() => (toolPagePath ? new PageToolsClient(toolPagePath) : null), [toolPagePath]);
|
|
79
|
+
const [card, setCard] = useState<PageCard | null>(null);
|
|
80
|
+
const cardRef = useRef<PageCard | null>(null);
|
|
81
|
+
// The viewer's answer about this page's writes holds for one VIEW of it: a
|
|
82
|
+
// new frame document (a reload, a saved edit, another file) asks again.
|
|
83
|
+
const consentRef = useRef<PageConsent | null>(null);
|
|
84
|
+
// Which document this view's is: an identity minted per `viewKey` — for
|
|
85
|
+
// every view, tools or not, since a page without tools still asks
|
|
86
|
+
// `requireTools()` — built into the document, and stamped by its runtime
|
|
87
|
+
// on every message. The window is not enough — a document rebuilt in the
|
|
88
|
+
// same frame element keeps the frame's window, and a message the old
|
|
89
|
+
// document queued can be delivered after the new one is committed. A
|
|
90
|
+
// message is answered only when it carries the current identity, and its
|
|
91
|
+
// reply is posted only while that identity is still current. The ref flips
|
|
92
|
+
// in the SAME commit that puts the new document in the frame (a layout
|
|
93
|
+
// effect), so nothing decided in the gap before passive effects run finds
|
|
94
|
+
// the old one current.
|
|
95
|
+
const documentId = useMemo(() => {
|
|
96
|
+
void viewKey; // a new identity per view, whatever the key's value
|
|
97
|
+
return newDocumentId();
|
|
98
|
+
}, [viewKey]);
|
|
99
|
+
const documentIdRef = useRef(documentId);
|
|
100
|
+
useLayoutEffect(() => {
|
|
101
|
+
documentIdRef.current = documentId;
|
|
102
|
+
}, [documentId]);
|
|
103
|
+
|
|
104
|
+
/** Show one of the app's cards over the page and resolve with the viewer's answer. A card already up answers this ask too. */
|
|
105
|
+
const showCard = useCallback((kind: PageCard['kind']): Promise<boolean | null> => {
|
|
106
|
+
const open = cardRef.current;
|
|
107
|
+
if (open && open.kind === kind) {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const first = open.answer;
|
|
110
|
+
open.answer = (ok) => {
|
|
111
|
+
first(ok);
|
|
112
|
+
resolve(ok);
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const next: PageCard = { kind, answer: resolve };
|
|
118
|
+
cardRef.current = next;
|
|
119
|
+
setCard(next);
|
|
120
|
+
});
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
/** Close the card with the viewer's answer, or null when the view went before they gave one. */
|
|
124
|
+
const closeCard = useCallback((ok: boolean | null) => {
|
|
125
|
+
const open = cardRef.current;
|
|
126
|
+
cardRef.current = null;
|
|
127
|
+
setCard(null);
|
|
128
|
+
open?.answer(ok);
|
|
129
|
+
}, []);
|
|
130
|
+
|
|
131
|
+
// When the page's view ends its consent is closed — a call the old view
|
|
132
|
+
// made that is still deciding (the manual lookup in flight) or waiting is
|
|
133
|
+
// answered `closed` and runs nothing — and a card left open answers no:
|
|
134
|
+
// nothing the old view asked for runs in, or asks from, the new one. A
|
|
135
|
+
// layout effect, like the generation above: the old view's consent is
|
|
136
|
+
// closed in the commit that ends it, not after the paint that follows.
|
|
137
|
+
useLayoutEffect(
|
|
138
|
+
() => () => {
|
|
139
|
+
consentRef.current?.close();
|
|
140
|
+
consentRef.current = null;
|
|
141
|
+
closeCard(null);
|
|
142
|
+
},
|
|
143
|
+
[viewKey, closeCard],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// A page's `window.bevel.tools` calls and its `requireTools()`, posted by
|
|
147
|
+
// the runtime in the frame (see `htmlSandbox.ts`), answered here with the
|
|
148
|
+
// viewer's session.
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
function onToolMessage(event: MessageEvent) {
|
|
151
|
+
const iframeWin = iframeRef.current?.contentWindow;
|
|
152
|
+
if (!iframeWin || event.source !== iframeWin) return;
|
|
153
|
+
const data = event.data as { type?: unknown; requestId?: unknown; documentId?: unknown } | null;
|
|
154
|
+
// Only from the document this view built: a message from one the view
|
|
155
|
+
// has since replaced — queued before the change, delivered after it,
|
|
156
|
+
// through the same window — is nobody's to answer.
|
|
157
|
+
const asked = documentIdRef.current;
|
|
158
|
+
if (data?.documentId !== asked) return;
|
|
159
|
+
const reply = (message: unknown) => {
|
|
160
|
+
// Only to the document that asked: a reloaded frame is a new window,
|
|
161
|
+
// and a document rebuilt in the same window carries a new identity.
|
|
162
|
+
// A reply to a document that is gone reaches nobody.
|
|
163
|
+
if (documentIdRef.current === asked && iframeRef.current?.contentWindow === iframeWin) {
|
|
164
|
+
iframeWin.postMessage(message, '*');
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
if (data && data.type === 'bevel.tools.require' && typeof data.requestId === 'string') {
|
|
168
|
+
const requestId = data.requestId;
|
|
169
|
+
if (toolsClient) {
|
|
170
|
+
reply({ type: 'bevel.tools.require.response', requestId, ok: true, result: true });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
void showCard('platform').then(() =>
|
|
174
|
+
// Either way the page that asked carries on without tools: Open in
|
|
175
|
+
// the platform opened it elsewhere, it did not give it tools here.
|
|
176
|
+
reply({ type: 'bevel.tools.require.response', requestId, ok: true, result: false }),
|
|
177
|
+
);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const call = asToolCall(data);
|
|
181
|
+
if (!call) return;
|
|
182
|
+
if (!toolsClient) {
|
|
183
|
+
reply({
|
|
184
|
+
type: 'bevel.tool.response',
|
|
185
|
+
requestId: call.requestId,
|
|
186
|
+
ok: false,
|
|
187
|
+
error: 'Tools are only available on the page in the platform.',
|
|
188
|
+
code: 'unavailable',
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
consentRef.current ??= new PageConsent(() => showCard('write'));
|
|
193
|
+
void answerToolCall(call, toolsClient, consentRef.current).then(reply);
|
|
194
|
+
}
|
|
195
|
+
window.addEventListener('message', onToolMessage);
|
|
196
|
+
return () => window.removeEventListener('message', onToolMessage);
|
|
197
|
+
}, [iframeRef, toolsClient, showCard]);
|
|
198
|
+
|
|
199
|
+
const openInPlatform = useCallback(() => {
|
|
200
|
+
closeCard(false);
|
|
201
|
+
// The host's own way when it has one (a skill page, whose filePath is
|
|
202
|
+
// relative to the skill); otherwise the file page, by an address that
|
|
203
|
+
// asks for it outright: on the embed the surface opens it through the
|
|
204
|
+
// host in a new tab, which carries no router state, and a page inside a
|
|
205
|
+
// skill's folder would otherwise open as that skill's page again.
|
|
206
|
+
if (openPageInPlatform) openPageInPlatform();
|
|
207
|
+
else openFilePage(filePath);
|
|
208
|
+
}, [closeCard, openPageInPlatform, openFilePage, filePath]);
|
|
209
|
+
|
|
210
|
+
const cards = (
|
|
211
|
+
<>
|
|
212
|
+
<Dialog
|
|
213
|
+
open={card?.kind === 'write'}
|
|
214
|
+
onClose={() => closeCard(false)}
|
|
215
|
+
title={`${pageName(filePath)} wants to write to the knowledge base`}
|
|
216
|
+
size="md"
|
|
217
|
+
footer={
|
|
218
|
+
<>
|
|
219
|
+
<Button variant="outline" onClick={() => closeCard(false)}>
|
|
220
|
+
Deny
|
|
221
|
+
</Button>
|
|
222
|
+
<Button variant="primary" onClick={() => closeCard(true)}>
|
|
223
|
+
Allow while open
|
|
224
|
+
</Button>
|
|
225
|
+
</>
|
|
226
|
+
}
|
|
227
|
+
>
|
|
228
|
+
<p className="font-mono text-detail text-ink-muted break-all">{toolPagePath ?? filePath}</p>
|
|
229
|
+
</Dialog>
|
|
230
|
+
<Dialog
|
|
231
|
+
open={card?.kind === 'platform'}
|
|
232
|
+
onClose={() => closeCard(false)}
|
|
233
|
+
title={`${pageName(filePath)} uses tools that are only available in the platform`}
|
|
234
|
+
size="md"
|
|
235
|
+
footer={
|
|
236
|
+
<>
|
|
237
|
+
<Button variant="outline" onClick={() => closeCard(false)}>
|
|
238
|
+
Continue without tools
|
|
239
|
+
</Button>
|
|
240
|
+
<Button variant="primary" onClick={openInPlatform}>
|
|
241
|
+
Open in the platform
|
|
242
|
+
</Button>
|
|
243
|
+
</>
|
|
244
|
+
}
|
|
245
|
+
>
|
|
246
|
+
<p className="font-mono text-detail text-ink-muted break-all">{filePath}</p>
|
|
247
|
+
</Dialog>
|
|
248
|
+
</>
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const toolBridge = useMemo(() => ({ documentId, tools: toolPagePath !== null }), [documentId, toolPagePath]);
|
|
252
|
+
return { toolBridge, cards };
|
|
253
|
+
}
|
|
@@ -43,6 +43,12 @@ describe('useLinksOut', () => {
|
|
|
43
43
|
expect(out).toEqual([]);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
it('lists a page whose name merely starts with http', () => {
|
|
47
|
+
expect(run('Knowledge/A.md', 'The [notes](http-notes.md).')).toEqual([
|
|
48
|
+
{ label: 'notes', target: 'http-notes.md' },
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
|
|
46
52
|
it('lists a destination once however many times it is linked', () => {
|
|
47
53
|
const out = run('Knowledge/A.md', '[One](Same.md) then [again](Same.md).');
|
|
48
54
|
expect(out).toEqual([{ label: 'One', target: 'Same.md' }]);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
|
+
import { useLatestRef } from '../../../shared/components';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The file page's "fill the window" view — the host's, never a renderer's.
|
|
7
|
+
*
|
|
8
|
+
* The URL IS the state: `?fullscreen=1` on the file's address. There is no
|
|
9
|
+
* React state beside it, so a reload, a shared link and the button all reach
|
|
10
|
+
* the same view the same way. Entering and leaving REPLACE the history entry:
|
|
11
|
+
* the view is a way of looking at the same file, not a place of its own, so
|
|
12
|
+
* Back leaves the file rather than the view.
|
|
13
|
+
*
|
|
14
|
+
* "Full screen" is the browser's viewport, not the Fullscreen API: no
|
|
15
|
+
* permission prompt, it works when the app is itself framed, and the address
|
|
16
|
+
* bar stays so the URL can be copied.
|
|
17
|
+
*/
|
|
18
|
+
export const FULL_SCREEN_PARAM = 'fullscreen';
|
|
19
|
+
|
|
20
|
+
export interface FullScreenView {
|
|
21
|
+
fullscreen: boolean;
|
|
22
|
+
enter(): void;
|
|
23
|
+
leave(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useFullScreenView(): FullScreenView {
|
|
27
|
+
const location = useLocation();
|
|
28
|
+
const navigate = useNavigate();
|
|
29
|
+
const fullscreen = new URLSearchParams(location.search).get(FULL_SCREEN_PARAM) === '1';
|
|
30
|
+
// Read at the moment of the toggle, so the handlers stay stable.
|
|
31
|
+
const locationRef = useLatestRef(location);
|
|
32
|
+
|
|
33
|
+
const setParam = useCallback(
|
|
34
|
+
(on: boolean) => {
|
|
35
|
+
const current = locationRef.current;
|
|
36
|
+
const params = new URLSearchParams(current.search);
|
|
37
|
+
if (on) params.set(FULL_SCREEN_PARAM, '1');
|
|
38
|
+
else params.delete(FULL_SCREEN_PARAM);
|
|
39
|
+
const search = params.toString();
|
|
40
|
+
// The same entry under a different view: its router state (a
|
|
41
|
+
// `startEditing` request not yet acted on) and its hash ride along.
|
|
42
|
+
navigate(
|
|
43
|
+
{ pathname: current.pathname, search: search ? `?${search}` : '', hash: current.hash },
|
|
44
|
+
{ replace: true, state: current.state },
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
[locationRef, navigate],
|
|
48
|
+
);
|
|
49
|
+
const enter = useCallback(() => setParam(true), [setParam]);
|
|
50
|
+
const leave = useCallback(() => setParam(false), [setParam]);
|
|
51
|
+
return { fullscreen, enter, leave };
|
|
52
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { useEventBus, canonicalizeWorkspaceId } from '../../workflow
|
|
2
|
+
import { useEventBus, canonicalizeWorkspaceId } from '../../workflow';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The extensions the raw file route serves as pictures, which is what a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { currentBranchModel, isProtectedBranch, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
3
|
-
import { fetchFileAccessBatch } from '../../access
|
|
3
|
+
import { fetchFileAccessBatch } from '../../access';
|
|
4
4
|
import { useWorkspace } from '../state/workspace.context';
|
|
5
5
|
import { useMergedWorkspaceTree } from './useMergedWorkspaceTree';
|
|
6
6
|
import { findEntryByPath } from '../utils/fileTree';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
+
import { isExternalHref } from '../../../shared/markdown/hrefs';
|
|
2
3
|
|
|
3
4
|
export interface LinkOut {
|
|
4
5
|
/** The link's visible text. */
|
|
@@ -22,13 +23,18 @@ const MARKDOWN_LINK_RE = /\[([^\]]+)\]\(<?([^)>\s]+(?:\s[^)>]*)?)>?\)/g;
|
|
|
22
23
|
* backlinks would need an index that does not exist. If one ever lands, the
|
|
23
24
|
* rail gains a second section; it does not change this one.
|
|
24
25
|
*
|
|
25
|
-
* The predicate is
|
|
26
|
-
* the renderer
|
|
26
|
+
* The predicate is the markdown pipeline's `.md` rule — the internal-link
|
|
27
|
+
* test the renderer uses for a page link where it has no link-target
|
|
28
|
+
* resolver:
|
|
27
29
|
*
|
|
28
|
-
* !href
|
|
30
|
+
* !isExternalHref(href) && !href.startsWith('#') && /\.md(#|$)/.test(href)
|
|
29
31
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
+
* (a scheme, not a prefix: `http-notes.md` is a page of the workspace)
|
|
33
|
+
* so the rail lists the PAGES this one links to, and nothing that would take
|
|
34
|
+
* the reader off the workspace. It is narrower than the file page's clicks on
|
|
35
|
+
* purpose: with a resolver the pipeline also opens a link to an HTML page, a
|
|
36
|
+
* PDF or an image in a new tab, and follows a bare node-id link, none of
|
|
37
|
+
* which this rail lists — it is a list of pages, not of everything clickable.
|
|
32
38
|
*
|
|
33
39
|
* Non-markdown content yields `[]`, which the rail renders as no section
|
|
34
40
|
* rather than an empty one.
|
|
@@ -43,7 +49,7 @@ export function useLinksOut(path: string | null, content: string | null): LinkOu
|
|
|
43
49
|
for (const match of content.matchAll(MARKDOWN_LINK_RE)) {
|
|
44
50
|
const label = match[1].trim();
|
|
45
51
|
const target = match[2].trim();
|
|
46
|
-
if (target
|
|
52
|
+
if (isExternalHref(target) || target.startsWith('#')) continue;
|
|
47
53
|
if (!/\.md(#|$)/.test(target)) continue;
|
|
48
54
|
// One row per destination: a node linked three times is one place you
|
|
49
55
|
// can go, not three.
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
isProtectedBranch,
|
|
6
6
|
type FileTreeEntry,
|
|
7
7
|
} from '@bevel-software/platform-shared';
|
|
8
|
-
import { useEventBus, canonicalizeWorkspaceId } from '../../workflow
|
|
9
|
-
import { AuthContext } from '../../auth
|
|
10
|
-
import { fetchFileAccess } from '../../access
|
|
8
|
+
import { useEventBus, canonicalizeWorkspaceId } from '../../workflow';
|
|
9
|
+
import { AuthContext } from '../../auth';
|
|
10
|
+
import { fetchFileAccess } from '../../access';
|
|
11
11
|
import {
|
|
12
12
|
ensureKnowledgeSuggestionWorkspace,
|
|
13
13
|
ensureKnowledgeChangeRequest,
|
|
14
14
|
type KnowledgeSuggestionTarget,
|
|
15
|
-
} from '../../change-requests
|
|
15
|
+
} from '../../change-requests';
|
|
16
16
|
import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../core/events';
|
|
17
17
|
import type {
|
|
18
18
|
HydrateResult,
|
|
@@ -21,20 +21,68 @@
|
|
|
21
21
|
* of such a mount has to name; `kbFilePageUrl`, the file page's address
|
|
22
22
|
* even for a file a skill's page would otherwise claim, and
|
|
23
23
|
* `asksForFilePage`, whether a location's query makes that ask.
|
|
24
|
+
* - `PageToolsContext`: the page-tool bridge, for a mount that is the
|
|
25
|
+
* platform itself (the skill page) — see `htmlToolBridge.ts` for the
|
|
26
|
+
* hosts that provide it and the ones that must not.
|
|
24
27
|
* - `OpenPageInPlatformContext`: how an HTML page mounted there is taken
|
|
25
28
|
* to the file page when it needs tools and the viewer picks Open in the
|
|
26
29
|
* platform (a skill page provides it; without it the renderer opens the
|
|
27
|
-
* file's own address).
|
|
30
|
+
* file's own address). `PageLinkHomeContext`: the file such a page's
|
|
31
|
+
* links resolve against, where its `filePath` is not one (a skill page).
|
|
32
|
+
* - `useHtmlToolBridge`, `PageToolsContext` and their types: the page
|
|
33
|
+
* tool bridge a distribution's own HTML renderer calls to answer a page's
|
|
34
|
+
* `window.bevel.tools` exactly as the app's renderer does, and the
|
|
35
|
+
* file page's provider its tests mount it under.
|
|
36
|
+
* - `useFileNav` and `useNodeIdNav` (with `KbLinkTarget`, `OpenLinkOptions`
|
|
37
|
+
* and `stripJunkBeforeKbDir`): where a link inside rendered content leads
|
|
38
|
+
* and how it is followed — the one rule for those links, which a surface
|
|
39
|
+
* rendering a file of the knowledge base outside the file page (a skill
|
|
40
|
+
* page, a review diff) follows too. `scrollToHeading`: how such a surface
|
|
41
|
+
* goes to a section of its own markdown file.
|
|
28
42
|
*/
|
|
29
43
|
export {
|
|
30
44
|
CanDownloadContext,
|
|
31
45
|
isViewOnlyFile,
|
|
46
|
+
OpenPageInPlatformContext,
|
|
47
|
+
PageToolsContext,
|
|
32
48
|
pickFileRenderer,
|
|
33
49
|
RendererSurfaceContext,
|
|
50
|
+
useHtmlToolBridge,
|
|
34
51
|
useKbGraphLoader,
|
|
35
52
|
useRendererSurface,
|
|
53
|
+
type HtmlToolBridgeOptions,
|
|
54
|
+
type HtmlToolBridgeResult,
|
|
55
|
+
type PageTools,
|
|
36
56
|
type RendererSurface,
|
|
37
57
|
} from './components/renderers';
|
|
38
58
|
export { RendererWorkspaceContext } from './components/renderers/rendererWorkspace';
|
|
39
59
|
export { asksForFilePage, kbFilePageUrl, kbFileUrl, resolveKbHref } from './routing/kb-routes';
|
|
40
|
-
export {
|
|
60
|
+
export { PageLinkHomeContext } from './components/renderers/htmlToolBridge';
|
|
61
|
+
export type { KbLinkTarget } from './components/renderers/KbAppLink';
|
|
62
|
+
export { scrollToHeading } from './components/renderers/scrollToHeading';
|
|
63
|
+
// Reached by other modules; exported here so they stop importing the files.
|
|
64
|
+
export { useCreatePage } from './hooks/useCreatePage';
|
|
65
|
+
export { useMergedWorkspaceTree } from './hooks/useMergedWorkspaceTree';
|
|
66
|
+
export { useOpenChangeRequests } from './hooks/useOpenChangeRequests';
|
|
67
|
+
export { useWorkspaceImageResolver } from './hooks/useWorkspaceImageResolver';
|
|
68
|
+
export {
|
|
69
|
+
KB_ROUTE_PREFIX,
|
|
70
|
+
openExternalHref,
|
|
71
|
+
safeDecode,
|
|
72
|
+
stripJunkBeforeKbDir,
|
|
73
|
+
useFileNav,
|
|
74
|
+
useFileNodeId,
|
|
75
|
+
useNodeIdNav,
|
|
76
|
+
type OpenLinkOptions,
|
|
77
|
+
} from './routing/kb-routes';
|
|
78
|
+
export { WorkspaceApiError, deleteFile, getOrCreateWorkspace, listFiles, readFile, writeFile } from './services/workspace.api';
|
|
79
|
+
export type { SkillToolWarning } from './services/workspace.api';
|
|
80
|
+
export { useEditablePage } from './state/editable-page';
|
|
81
|
+
export { WorkspaceContext, libraryUploadTarget, useWorkspace } from './state/workspace.context';
|
|
82
|
+
export type { WorkspaceContextValue } from './state/workspace.context';
|
|
83
|
+
export { computeDiff } from './utils/diff';
|
|
84
|
+
export type { DiffLine } from './utils/diff';
|
|
85
|
+
export { displayFileName, fileNameTooltip } from './utils/display-file-name';
|
|
86
|
+
export { checkoutRoot, findEntryByPath, knowledgeFiles, pathExistsInTree } from './utils/fileTree';
|
|
87
|
+
export { labelFor, parseFrontmatter } from './utils/frontmatter';
|
|
88
|
+
export type { FrontmatterData } from './utils/frontmatter';
|