@bevel-software/platform-core-frontend 0.26.0 → 0.28.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 (206) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ProductName.test.tsx +46 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  6. package/src/core/__tests__/core-contributions.test.ts +16 -0
  7. package/src/core/core-contributions.ts +17 -0
  8. package/src/core/maker-url.ts +30 -0
  9. package/src/core/registry.ts +78 -1
  10. package/src/index.css +23 -5
  11. package/src/index.ts +5 -0
  12. package/src/lib/__tests__/latest-request.test.ts +48 -0
  13. package/src/lib/latest-request.ts +45 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  16. package/src/modules/access/api.ts +19 -3
  17. package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
  18. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  19. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  20. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  21. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  23. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  24. package/src/modules/admin/services/roles.api.ts +14 -1
  25. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  26. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  27. package/src/modules/auth/components/LoginScreen.tsx +101 -73
  28. package/src/modules/auth/services/account.api.ts +59 -3
  29. package/src/modules/auth/services/sso.ts +30 -10
  30. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  31. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  32. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  33. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  34. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  35. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  36. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  37. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  38. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  39. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  40. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  41. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  42. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  43. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  44. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  45. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  46. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  47. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  48. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  49. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  50. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  51. package/src/modules/embed/components/EmbedView.tsx +545 -0
  52. package/src/modules/embed/embed-config.ts +132 -0
  53. package/src/modules/embed/embed-host.ts +120 -0
  54. package/src/modules/embed/mount.tsx +80 -0
  55. package/src/modules/embed/services/embed-token.ts +22 -0
  56. package/src/modules/embed/services/embed.api.ts +158 -0
  57. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  58. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  59. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  60. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  61. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  62. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  63. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  64. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  65. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  66. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  67. package/src/modules/git/index.ts +15 -0
  68. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  69. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  70. package/src/modules/git/services/error-messages.ts +58 -1
  71. package/src/modules/git/services/pull-failure.ts +68 -0
  72. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  73. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  74. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  75. package/src/modules/layout/breakpoints.ts +8 -0
  76. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  77. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  78. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  79. package/src/modules/library/components/LibraryPage.tsx +22 -0
  80. package/src/modules/library/components/PluginExtras.tsx +23 -6
  81. package/src/modules/library/components/PluginPage.tsx +6 -1
  82. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  83. package/src/modules/library/services/plugins.api.ts +4 -1
  84. package/src/modules/library/state/plugins-revision.ts +28 -0
  85. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  86. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  87. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  88. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
  89. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
  90. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
  91. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  92. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  93. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  94. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  95. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  96. package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
  97. package/src/modules/onboarding/components/InviteButton.tsx +139 -0
  98. package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
  99. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  100. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  101. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  102. package/src/modules/onboarding/first-page-prompt.ts +123 -0
  103. package/src/modules/onboarding/invite-emails.ts +313 -0
  104. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  105. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  106. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  107. package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
  108. package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
  109. package/src/modules/onboarding/state/onboarding.ts +133 -59
  110. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  111. package/src/modules/settings/settings-nav-items.tsx +8 -3
  112. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  113. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  114. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  115. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  116. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  117. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  118. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  119. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  120. package/src/modules/setup/components/SetupGate.tsx +46 -1
  121. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  122. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  123. package/src/modules/setup/services/setup.api.ts +3 -3
  124. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  125. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  126. package/src/modules/toolbar/commands/actions.tsx +330 -0
  127. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  128. package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
  129. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  130. package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
  131. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  132. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  133. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  134. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  135. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
  136. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  137. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
  138. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  139. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  140. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  141. package/src/modules/toolbar/search/rank.ts +111 -0
  142. package/src/modules/toolbar/search/sources.ts +169 -0
  143. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  144. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  145. package/src/modules/workflow/services/lock.api.ts +17 -2
  146. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  147. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  148. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  149. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  150. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  151. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  152. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  153. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  154. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  155. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  156. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  157. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  158. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  159. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  160. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  161. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  162. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  163. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  164. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  165. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  166. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  167. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  168. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  169. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  170. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  171. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  172. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  173. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  174. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  175. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  176. package/src/modules/workspace/components/renderers/index.ts +26 -0
  177. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  178. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  179. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  180. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  181. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  182. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  183. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  184. package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
  185. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
  186. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  189. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  190. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  191. package/src/modules/workspace/state/editable-page.ts +42 -0
  192. package/src/modules/workspace/state/workspace.context.ts +13 -4
  193. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  194. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  195. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  196. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  197. package/src/modules/workspace/utils/fileTree.ts +49 -14
  198. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  199. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  200. package/src/shared/components/ConfirmProvider.tsx +156 -0
  201. package/src/shared/components/Dialog.tsx +7 -0
  202. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  203. package/src/shared/components/confirm-context.ts +94 -0
  204. package/src/shared/components/index.ts +3 -0
  205. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  206. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -1,10 +1,9 @@
1
1
  import { useState, useEffect } from 'react';
2
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
2
+ import { useRendererWorkspaceId } from './rendererWorkspace';
3
3
  import { RetryReadButton } from './RetryReadButton';
4
4
  import { useReadRetry } from './useReadRetry';
5
5
  import { useImageRevision } from '../../hooks/useImageRevision';
6
- import { authFetch } from '../../../../lib/api';
7
- import { rawFileUrl } from '../../services/workspace.api';
6
+ import { useRendererRawRead } from './rendererRawRead';
8
7
  import type { FileRendererProps } from './types';
9
8
 
10
9
  /** How the read of one image ended. */
@@ -33,28 +32,21 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
33
32
  */
34
33
  const revision = useImageRevision(workspaceId);
35
34
  /**
36
- * A past save, when Version history mounted this. The revision above is
37
- * then deliberately NOT folded in: the bytes at a commit cannot change, so
38
- * `&v=` would only defeat the browser cache, and the revision bumps on every
39
- * save of the file — which for a version pane means a re-read of a version
40
- * that is not what changed.
35
+ * Where the picture's bytes come from — the workspace raw route under the
36
+ * session in the app, the surface's own route in an embed. It folds the
37
+ * save this viewer is bound to in itself, so a version pane needs nothing
38
+ * extra here.
41
39
  */
42
- const fileRef = useRendererFileRef();
43
- /**
44
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
45
- * depend on exactly what it reads. Depending on `fileRef` itself would put
46
- * a context object in the dependency list.
47
- */
48
- const versionRef = fileRef?.ref ?? null;
49
- const versionSide = fileRef?.side;
40
+ const rawRead = useRendererRawRead();
50
41
  /**
51
42
  * The cache key of a WORKING-TREE read, and nothing else. Folding the
52
43
  * revision into a version read would not just waste a request: a teammate
53
44
  * saving the file while a past save is on screen would bump it, the read
54
45
  * effect would re-run, and the picture the reader is looking at would blink
55
- * back to "Loading image…" for bytes that cannot have changed.
46
+ * back to "Loading image…" for bytes that cannot have changed. Which kind
47
+ * of read this is belongs to the raw source, so that is what is asked.
56
48
  */
57
- const revisionKey = versionRef === null ? revision : null;
49
+ const revisionKey = rawRead?.pinnedToVersion ? null : revision;
58
50
  // Blob and failure in ONE value, so the cleanup that drops the old blob
59
51
  // drops the old failure with it — a second `useState` would need a reset in
60
52
  // the effect body, which costs a cascading render on every path change.
@@ -63,20 +55,12 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
63
55
  const { attempt, retry } = useReadRetry();
64
56
 
65
57
  useEffect(() => {
66
- if (!workspaceId) return;
58
+ if (!rawRead) return;
67
59
 
68
60
  let revoked = false;
69
61
  (async () => {
70
62
  try {
71
- const res = await authFetch(
72
- rawFileUrl(
73
- workspaceId,
74
- filePath,
75
- versionRef === null
76
- ? { version: revisionKey ?? undefined }
77
- : { ref: versionRef, side: versionSide },
78
- ),
79
- );
63
+ const res = await rawRead.fetch(filePath, { version: revisionKey ?? undefined });
80
64
  if (revoked) return;
81
65
  if (!res.ok) {
82
66
  setRead({ objectUrl: null, error: `Couldn't load this image (HTTP ${res.status}).` });
@@ -99,7 +83,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
99
83
  return prev === NOT_READ ? prev : NOT_READ;
100
84
  });
101
85
  };
102
- }, [workspaceId, filePath, revisionKey, versionRef, versionSide, attempt]);
86
+ }, [rawRead, filePath, revisionKey, attempt]);
103
87
 
104
88
  if (read.error) {
105
89
  return (
@@ -115,6 +115,13 @@ interface KbMarkdownViewProps {
115
115
  * images render as plain `<img>` tags. See `KbImage` in the pipeline.
116
116
  */
117
117
  resolveImage?: KbImageResolver;
118
+ /**
119
+ * Which links `onOpenFile` gets — see `linkPolicy` in the pipeline. The
120
+ * app leaves external destinations to the browser; a surface inside
121
+ * somebody else's frame takes every one of them, because a plain anchor
122
+ * there navigates the frame rather than opening a tab.
123
+ */
124
+ linkPolicy?: 'browser' | 'surface';
118
125
  /** Optional container ref (used by the file viewer for deep-link scroll). */
119
126
  containerRef?: Ref<HTMLDivElement>;
120
127
  /**
@@ -139,7 +146,7 @@ interface KbMarkdownViewProps {
139
146
  * frontmatter panel, with navigation injected via `onOpenFile` so it carries no
140
147
  * dependency on workspace routing or context.
141
148
  */
142
- export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, containerRef, scroll = true, className }: KbMarkdownViewProps) {
149
+ export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, linkPolicy, containerRef, scroll = true, className }: KbMarkdownViewProps) {
143
150
  const { data: frontmatter, body } = useMemo(() => parseFrontmatter(source), [source]);
144
151
  // CommonMark rejects unescaped spaces in link destinations, so a KB link like
145
152
  // `[Foo](Some File.md)` would render as plain text. Wrap space-bearing
@@ -147,7 +154,7 @@ export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink,
147
154
  // rule covers an image's `![alt](Some Shot.png)` tail.
148
155
  const normalizedBody = useMemo(() => escapeSpacesInLinkDestinations(body), [body]);
149
156
 
150
- const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage });
157
+ const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage, linkPolicy });
151
158
 
152
159
  return (
153
160
  <div
@@ -8,6 +8,7 @@ import {
8
8
  useCanonicalFileUrl,
9
9
  } from '../../routing/kb-routes';
10
10
  import { useRendererWorkspaceId } from './rendererWorkspace';
11
+ import { useRendererSurface } from './rendererSurface';
11
12
  import { WorkspaceContext } from '../../state/workspace.context';
12
13
  import { markdownLinkForPaste } from '../../utils/pasteLink';
13
14
  import { useWorkspaceImageResolver } from '../../hooks/useWorkspaceImageResolver';
@@ -166,6 +167,8 @@ export function MarkdownRenderer({
166
167
  // new picture.
167
168
  const workspaceId = useRendererWorkspaceId();
168
169
  const resolveImage = useWorkspaceImageResolver(workspaceId, filePath);
170
+ // Whether this renderer is mounted outside the app — see `linkPolicy` below.
171
+ const surface = useRendererSurface();
169
172
 
170
173
  const save = useCallback(async (): Promise<boolean> => {
171
174
  if (readOnly || value === savedValue) return true;
@@ -266,6 +269,11 @@ export function MarkdownRenderer({
266
269
  onOpenNodeId={openNodeId}
267
270
  headingLink={headingLink}
268
271
  resolveImage={resolveImage}
272
+ // On a renderer surface (the embed) EVERY outgoing link is the
273
+ // surface's to open: there is no `allow-popups` inside a host's
274
+ // frame, so a plain `target="_blank"` anchor navigates the frame
275
+ // away instead of opening a tab. In the app the browser keeps them.
276
+ linkPolicy={surface ? 'surface' : 'browser'}
269
277
  containerRef={scrollContainerRef}
270
278
  // The document column scrolls; this view does not. See the prop's
271
279
  // docstring — the embed and the library dialog keep the default.
@@ -4,11 +4,9 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist';
4
4
  import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
5
5
  import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
6
6
  import { Button } from '../../../../shared/components';
7
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
8
7
  import { RetryReadButton } from './RetryReadButton';
9
8
  import { useReadRetry } from './useReadRetry';
10
- import { authFetch } from '../../../../lib/api';
11
- import { rawFileUrl } from '../../services/workspace.api';
9
+ import { useRendererRawRead } from './rendererRawRead';
12
10
  import { DownloadFileButton } from './DownloadFileButton';
13
11
  import type { FileRendererProps } from './types';
14
12
 
@@ -38,16 +36,15 @@ GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
38
36
  * `onSave` / `onValueChange` / `readOnly`.
39
37
  */
40
38
  export function PdfRenderer({ filePath }: FileRendererProps) {
41
- const workspaceId = useRendererWorkspaceId();
42
- /** A past save, when Version history mounted this; null = the working tree. */
43
- const fileRef = useRendererFileRef();
44
39
  /**
45
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
46
- * depend on exactly what it reads. Depending on `fileRef` itself would put
47
- * a context object in the dependency list.
40
+ * Where this file's bytes come from. In the app that is the workspace raw
41
+ * route under the session, for the workspace this viewer is pointed at and
42
+ * the save it is bound to; on a renderer surface (the embed) it is that
43
+ * surface's own route, with its own credential. Null until there is a
44
+ * workspace to read from — the same "nothing to read yet" the guard in the
45
+ * effect below has always had.
48
46
  */
49
- const versionRef = fileRef?.ref ?? null;
50
- const versionSide = fileRef?.side;
47
+ const rawRead = useRendererRawRead();
51
48
  const { attempt, retry } = useReadRetry();
52
49
  const [doc, setDoc] = useState<PDFDocumentProxy | null>(null);
53
50
  const [pageNumber, setPageNumber] = useState(1);
@@ -75,23 +72,21 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
75
72
  const [width, setWidth] = useState(0);
76
73
 
77
74
  useEffect(() => {
78
- // Reset stale state from a prior filePath / workspaceId before starting
79
- // the new load — including teardown (workspaceId → null). The rendered-
80
- // page ref dies with its document (task.destroy frees the pages).
75
+ // Reset stale state from a prior filePath / raw source before starting
76
+ // the new load — teardown (no source at all) included. The rendered-page
77
+ // ref dies with its document (task.destroy frees the pages).
81
78
  setDoc(null);
82
79
  setPageNumber(1);
83
80
  setError(null);
84
81
  renderedPageRef.current = null;
85
82
 
86
- if (!workspaceId) return;
83
+ if (!rawRead) return;
87
84
 
88
85
  let cancelled = false;
89
86
  let loadingTask: PDFDocumentLoadingTask | null = null;
90
87
  (async () => {
91
88
  try {
92
- const res = await authFetch(
93
- rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
94
- );
89
+ const res = await rawRead.fetch(filePath);
95
90
  if (cancelled) return;
96
91
  if (!res.ok) {
97
92
  setError(`Failed to load PDF (HTTP ${res.status})`);
@@ -140,7 +135,7 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
140
135
  loadingTask?.destroy().catch(() => {});
141
136
  loadingTaskRef.current = null;
142
137
  };
143
- }, [workspaceId, filePath, versionRef, versionSide, attempt]);
138
+ }, [rawRead, filePath, attempt]);
144
139
 
145
140
  // Track the page column's width so the canvas re-renders to fit it. The
146
141
  // container only mounts once the document is loaded, hence the `doc` dep.
@@ -1,10 +1,8 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Presentation } from 'lucide-react';
3
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
3
  import { RetryReadButton } from './RetryReadButton';
5
4
  import { useReadRetry } from './useReadRetry';
6
- import { authFetch } from '../../../../lib/api';
7
- import { rawFileUrl } from '../../services/workspace.api';
5
+ import { useRendererRawRead } from './rendererRawRead';
8
6
  import { DownloadFileButton } from './DownloadFileButton';
9
7
  import { extractPptxOutline, type PptxSlide } from './pptxOutline';
10
8
  import { readBodyCapped } from './readBodyCapped';
@@ -50,16 +48,15 @@ const MAX_ARCHIVE_BYTES = 200 * 1024 * 1024;
50
48
  const MAX_LINES_PER_SLIDE = 500;
51
49
 
52
50
  export function PptxRenderer({ filePath }: FileRendererProps) {
53
- const workspaceId = useRendererWorkspaceId();
54
- /** A past save, when Version history mounted this; null = the working tree. */
55
- const fileRef = useRendererFileRef();
56
51
  /**
57
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
58
- * depend on exactly what it reads. Depending on `fileRef` itself would put
59
- * a context object in the dependency list.
52
+ * Where this file's bytes come from. In the app that is the workspace raw
53
+ * route under the session, for the workspace this viewer is pointed at and
54
+ * the save it is bound to; on a renderer surface (the embed) it is that
55
+ * surface's own route, with its own credential. Null until there is a
56
+ * workspace to read from — the same "nothing to read yet" the guard in the
57
+ * effect below has always had.
60
58
  */
61
- const versionRef = fileRef?.ref ?? null;
62
- const versionSide = fileRef?.side;
59
+ const rawRead = useRendererRawRead();
63
60
  const { attempt, retry } = useReadRetry();
64
61
  const [slides, setSlides] = useState<PptxSlide[] | null>(null);
65
62
  const [error, setError] = useState<string | null>(null);
@@ -67,7 +64,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
67
64
  useEffect(() => {
68
65
  setSlides(null);
69
66
  setError(null);
70
- if (!workspaceId) return;
67
+ if (!rawRead) return;
71
68
 
72
69
  let cancelled = false;
73
70
  // `cancelled` only stops this effect from PUBLISHING; the request itself
@@ -76,10 +73,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
76
73
  const abort = new AbortController();
77
74
  (async () => {
78
75
  try {
79
- const res = await authFetch(
80
- rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
81
- { signal: abort.signal },
82
- );
76
+ const res = await rawRead.fetch(filePath, { signal: abort.signal });
83
77
  if (cancelled) return;
84
78
  if (!res.ok) {
85
79
  setError(`Failed to load presentation (HTTP ${res.status})`);
@@ -109,7 +103,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
109
103
  cancelled = true;
110
104
  abort.abort();
111
105
  };
112
- }, [workspaceId, filePath, versionRef, versionSide, attempt]);
106
+ }, [rawRead, filePath, attempt]);
113
107
 
114
108
  if (error) {
115
109
  return (
@@ -3,11 +3,12 @@ import { parse as parseYaml } from 'yaml';
3
3
  import { extractFrontmatter } from '@bevel-software/platform-shared';
4
4
  import type { FileRendererProps, RendererSaveState } from './types';
5
5
  import { authFetch } from '../../../../lib/api';
6
- import { Surface } from '../../../../shared/components';
6
+ import { Surface, useConfirm } from '../../../../shared/components';
7
7
  import { Markdown } from '../../../../shared/markdown/Markdown';
8
8
  import { ToolForm } from './ToolForm';
9
9
  import { ToolSecretsPanel } from '../../../secrets-vault/components/ToolSecretsPanel';
10
10
  import { listToolSecrets, type ToolSecrets } from '../../../secrets-vault/services/tool-secrets.api';
11
+ import { useRendererSurface } from './rendererSurface';
11
12
 
12
13
  /**
13
14
  * Whether the Form view can render this file: THE TOOL IS THE FRONTMATTER, so
@@ -103,6 +104,7 @@ export function ToolRenderer({
103
104
  readOnly = false,
104
105
  }: FileRendererProps) {
105
106
  const [value, setValue] = useState(content);
107
+ const confirm = useConfirm();
106
108
  const [savedValue, setSavedValue] = useState(savedContent ?? content);
107
109
  const [saveState, setSaveState] = useState<RendererSaveState>('idle');
108
110
  const [saveError, setSaveError] = useState<string | null>(null);
@@ -118,6 +120,15 @@ export function ToolRenderer({
118
120
 
119
121
  const dirty = !readOnly && value !== savedValue;
120
122
 
123
+ // The three panels on the right — the Secrets Vault palette, this tool's
124
+ // secrets and the live Preview — act under the SIGNED-IN SESSION: they
125
+ // read the caller's vault and run the manual through the app's API. On a
126
+ // renderer surface (the embed, in a chat or an Atlassian panel) there is
127
+ // no session, only the embed token, which none of those routes take. So
128
+ // they are not drawn there, and their requests are not made: the file is
129
+ // still read and edited as text, and the rest belongs to the app.
130
+ const surface = useRendererSurface();
131
+
121
132
  useEffect(() => {
122
133
  setValue(content);
123
134
  setSavedValue(savedContent ?? content);
@@ -143,6 +154,7 @@ export function ToolRenderer({
143
154
 
144
155
  // Load the caller's Secrets Vault keys for the insert palette.
145
156
  useEffect(() => {
157
+ if (surface) return;
146
158
  let cancelled = false;
147
159
  (async () => {
148
160
  try {
@@ -157,7 +169,7 @@ export function ToolRenderer({
157
169
  return () => {
158
170
  cancelled = true;
159
171
  };
160
- }, []);
172
+ }, [surface]);
161
173
 
162
174
  // Load THIS tool's declared variables + their config status (for the per-tool
163
175
  // secrets panel). Matched from the default-branch catalog by file path (with a
@@ -184,8 +196,9 @@ export function ToolRenderer({
184
196
  }, [filePath]);
185
197
 
186
198
  useEffect(() => {
199
+ if (surface) return;
187
200
  void loadToolSecrets();
188
- }, [loadToolSecrets]);
201
+ }, [loadToolSecrets, surface]);
189
202
 
190
203
  const save = useCallback(async (): Promise<boolean> => {
191
204
  if (readOnly || value === savedValue) return true;
@@ -322,6 +335,9 @@ export function ToolRenderer({
322
335
  )}
323
336
  </div>
324
337
 
338
+ {/* On a surface the aside holds the scaffolds at most, so a read-only
339
+ embedded view draws no empty column beside the document. */}
340
+ {!(surface && readOnly) && (
325
341
  <aside className="flex w-72 shrink-0 flex-col gap-4 overflow-y-auto p-3">
326
342
  {!readOnly && (
327
343
  <section>
@@ -330,10 +346,17 @@ export function ToolRenderer({
330
346
  {(['inline', 'http', 'mcp'] as const).map((t) => (
331
347
  <button
332
348
  key={t}
333
- onClick={() => {
334
- if (!value.trim() || window.confirm('Replace the file contents with this scaffold?')) {
335
- updateValue(SCAFFOLDS[t]);
349
+ onClick={async () => {
350
+ if (value.trim()) {
351
+ const { confirmed } = await confirm({
352
+ title: 'Replace with scaffold',
353
+ message: 'Replace the file contents with this scaffold?',
354
+ confirmLabel: 'Replace',
355
+ destructive: true,
356
+ });
357
+ if (!confirmed) return;
336
358
  }
359
+ updateValue(SCAFFOLDS[t]);
337
360
  }}
338
361
  className="rounded-xs bg-sunken px-2 py-1 text-meta text-ink-muted hover:bg-hover"
339
362
  >
@@ -344,7 +367,7 @@ export function ToolRenderer({
344
367
  </section>
345
368
  )}
346
369
 
347
- {!readOnly && (
370
+ {!readOnly && !surface && (
348
371
  <section>
349
372
  <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secret variables</h3>
350
373
  {secretKeys.length === 0 ? (
@@ -368,6 +391,7 @@ export function ToolRenderer({
368
391
  </section>
369
392
  )}
370
393
 
394
+ {!surface && (
371
395
  <section>
372
396
  <h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secrets for this tool</h3>
373
397
  {toolSecrets ? (
@@ -379,7 +403,9 @@ export function ToolRenderer({
379
403
  </p>
380
404
  )}
381
405
  </section>
406
+ )}
382
407
 
408
+ {!surface && (
383
409
  <section>
384
410
  <div className="mb-1 flex items-center gap-2">
385
411
  <h3 className="text-meta font-semibold uppercase tracking-wide text-ink-faint">Preview</h3>
@@ -416,7 +442,9 @@ export function ToolRenderer({
416
442
  </div>
417
443
  )}
418
444
  </section>
445
+ )}
419
446
  </aside>
447
+ )}
420
448
  </Surface>
421
449
  );
422
450
  }
@@ -1,10 +1,8 @@
1
1
  import { useEffect, useMemo, useState } from 'react';
2
2
  import * as XLSX from 'xlsx';
3
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
3
  import { RetryReadButton } from './RetryReadButton';
5
4
  import { useReadRetry } from './useReadRetry';
6
- import { authFetch } from '../../../../lib/api';
7
- import { rawFileUrl } from '../../services/workspace.api';
5
+ import { useRendererRawRead } from './rendererRawRead';
8
6
  import { DownloadFileButton } from './DownloadFileButton';
9
7
  import { readBodyCapped } from './readBodyCapped';
10
8
  import type { FileRendererProps } from './types';
@@ -98,16 +96,15 @@ interface SheetView {
98
96
  * as raw serial numbers / decimals.
99
97
  */
100
98
  export function XlsxRenderer({ filePath }: FileRendererProps) {
101
- const workspaceId = useRendererWorkspaceId();
102
- /** A past save, when Version history mounted this; null = the working tree. */
103
- const fileRef = useRendererFileRef();
104
99
  /**
105
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
106
- * depend on exactly what it reads. Depending on `fileRef` itself would put
107
- * a context object in the dependency list.
100
+ * Where this file's bytes come from. In the app that is the workspace raw
101
+ * route under the session, for the workspace this viewer is pointed at and
102
+ * the save it is bound to; on a renderer surface (the embed) it is that
103
+ * surface's own route, with its own credential. Null until there is a
104
+ * workspace to read from — the same "nothing to read yet" the guard in the
105
+ * effect below has always had.
108
106
  */
109
- const versionRef = fileRef?.ref ?? null;
110
- const versionSide = fileRef?.side;
107
+ const rawRead = useRendererRawRead();
111
108
  const { attempt, retry } = useReadRetry();
112
109
  const [workbook, setWorkbook] = useState<XLSX.WorkBook | null>(null);
113
110
  const [activeSheet, setActiveSheet] = useState(0);
@@ -117,7 +114,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
117
114
  setWorkbook(null);
118
115
  setActiveSheet(0);
119
116
  setError(null);
120
- if (!workspaceId) return;
117
+ if (!rawRead) return;
121
118
 
122
119
  let cancelled = false;
123
120
  // Cleanup ABORTS, not just flags: flipping `cancelled` alone left an
@@ -125,10 +122,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
125
122
  const controller = new AbortController();
126
123
  (async () => {
127
124
  try {
128
- const res = await authFetch(
129
- rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
130
- { signal: controller.signal },
131
- );
125
+ const res = await rawRead.fetch(filePath, { signal: controller.signal });
132
126
  if (cancelled) return;
133
127
  if (!res.ok) {
134
128
  setError(`Failed to load spreadsheet (HTTP ${res.status})`);
@@ -177,7 +171,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
177
171
  cancelled = true;
178
172
  controller.abort();
179
173
  };
180
- }, [workspaceId, filePath, versionRef, versionSide, attempt]);
174
+ }, [rawRead, filePath, attempt]);
181
175
 
182
176
  // Convert ONLY the sheet on screen, when it is on screen. `XLSX.read` has
183
177
  // already materialized every cell (SheetJS has no partial parse), but
@@ -0,0 +1,73 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3
+ import {
4
+ WorkspaceContext,
5
+ type WorkspaceContextValue,
6
+ } from '../../../state/workspace.context';
7
+ import { ConfirmProvider } from '../../../../../shared/components';
8
+
9
+ const apiMock = vi.hoisted(() => ({ authFetch: vi.fn() }));
10
+ vi.mock('../../../../../lib/api', () => ({ authFetch: apiMock.authFetch }));
11
+
12
+ import { EmailRenderer } from '../EmailRenderer';
13
+
14
+ /**
15
+ * Opening a link inside an email asks first, showing the real address — in
16
+ * the app's own dialog, which the browser cannot silence.
17
+ */
18
+
19
+ const URL = 'https://example.com/offer?id=7';
20
+ const EML = new TextEncoder().encode(
21
+ [
22
+ 'From: Ada <ada@example.com>',
23
+ 'Subject: Offer',
24
+ 'MIME-Version: 1.0',
25
+ 'Content-Type: text/html; charset=utf-8',
26
+ '',
27
+ `<p>See <a href="${URL}">our offer</a>.</p>`,
28
+ '',
29
+ ].join('\r\n'),
30
+ ).buffer as ArrayBuffer;
31
+
32
+ let openSpy: MockInstance<Window['open']>;
33
+ let confirmSpy: MockInstance<Window['confirm']>;
34
+ beforeEach(() => {
35
+ apiMock.authFetch.mockReset();
36
+ apiMock.authFetch.mockResolvedValue({ ok: true, arrayBuffer: async () => EML });
37
+ openSpy = vi.spyOn(window, 'open').mockReturnValue(null);
38
+ // The browser's dialogs suppressed: never the thing that answers.
39
+ confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
40
+ });
41
+ afterEach(() => {
42
+ expect(confirmSpy).not.toHaveBeenCalled();
43
+ vi.restoreAllMocks();
44
+ });
45
+
46
+ async function clickOpen() {
47
+ render(
48
+ <ConfirmProvider>
49
+ <WorkspaceContext.Provider value={{ workspaceId: 'ws-1' } as unknown as WorkspaceContextValue}>
50
+ <EmailRenderer filePath="Inbox/offer.eml" content="" onSave={async () => {}} />
51
+ </WorkspaceContext.Provider>
52
+ </ConfirmProvider>,
53
+ );
54
+ fireEvent.click(await screen.findByTitle('Open in a new tab'));
55
+ return screen.findByRole('dialog');
56
+ }
57
+
58
+ describe('a link in an email', () => {
59
+ it("asks with today's question and the address; Cancel opens nothing", async () => {
60
+ const dialog = await clickOpen();
61
+ expect(dialog.textContent).toContain(`Open this link?\n\n${URL}`);
62
+ expect(within(dialog).queryByText("Don't ask again")).toBeNull();
63
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
64
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
65
+ expect(openSpy).not.toHaveBeenCalled();
66
+ });
67
+
68
+ it('Open opens it in a new tab', async () => {
69
+ const dialog = await clickOpen();
70
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Open' }));
71
+ await waitFor(() => expect(openSpy).toHaveBeenCalledWith(URL, '_blank', 'noopener,noreferrer'));
72
+ });
73
+ });
@@ -0,0 +1,64 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3
+ import { ToolRenderer } from '../ToolRenderer';
4
+ import { ConfirmProvider } from '../../../../../shared/components';
5
+
6
+ /**
7
+ * "Replace with scaffold" over a file that already has contents asks first —
8
+ * in the app's own dialog, which the browser cannot silence. Without it, a
9
+ * suppressed built-in confirm answered "no" and the button did nothing.
10
+ */
11
+
12
+ beforeEach(() => {
13
+ vi.stubGlobal(
14
+ 'fetch',
15
+ vi.fn(async () => ({ ok: true, status: 200, json: async () => ({ secrets: [], tools: [] }) })),
16
+ );
17
+ });
18
+
19
+ afterEach(() => {
20
+ vi.unstubAllGlobals();
21
+ vi.restoreAllMocks();
22
+ });
23
+
24
+ function renderTool(content: string) {
25
+ const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
26
+ render(
27
+ <ConfirmProvider>
28
+ <ToolRenderer content={content} filePath="Tools/my_tool.tool" onSave={async () => undefined} />
29
+ </ConfirmProvider>,
30
+ );
31
+ const textarea = () => document.querySelector('textarea') as HTMLTextAreaElement;
32
+ return { confirmSpy, textarea };
33
+ }
34
+
35
+ describe('the .tool scaffold', () => {
36
+ it("asks with today's question; Cancel keeps the contents", async () => {
37
+ const { confirmSpy, textarea } = renderTool('not: [a manual');
38
+ fireEvent.click(screen.getByRole('button', { name: 'http' }));
39
+ const dialog = await screen.findByRole('dialog');
40
+ expect(dialog.textContent).toContain('Replace the file contents with this scaffold?');
41
+ expect(within(dialog).queryByText("Don't ask again")).toBeNull();
42
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
43
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
44
+ expect(textarea().value).toBe('not: [a manual');
45
+ expect(confirmSpy).not.toHaveBeenCalled();
46
+ });
47
+
48
+ it('Replace puts the scaffold in, even with the browser\'s dialogs suppressed', async () => {
49
+ const { confirmSpy, textarea } = renderTool('not: [a manual');
50
+ fireEvent.click(screen.getByRole('button', { name: 'http' }));
51
+ fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Replace' }));
52
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
53
+ await waitFor(() => expect(textarea().value).toContain('type: http'));
54
+ expect(confirmSpy).not.toHaveBeenCalled();
55
+ });
56
+
57
+ it('an empty file takes the scaffold without a question, as today', async () => {
58
+ renderTool('');
59
+ fireEvent.click(screen.getByRole('button', { name: 'inline' }));
60
+ // An empty file opens in the form view; the scaffold makes it unsaved.
61
+ expect(await screen.findByText('● unsaved')).toBeInTheDocument();
62
+ expect(screen.queryByRole('dialog')).toBeNull();
63
+ });
64
+ });