@bevel-software/platform-core-frontend 0.13.3 → 0.13.6

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.
@@ -35,7 +35,7 @@ These declare a licence in their manifest but ship no licence file, and their
35
35
  text embeds a copyright holder we must not invent. They are redistributed under
36
36
  the declared licence; refer to the upstream project for the notice.
37
37
 
38
- - `@napi-rs/canvas-win32-x64-msvc@0.1.100` — MIT <https://github.com/Brooooooklyn/canvas#readme>
38
+ - `@napi-rs/canvas-win32-x64-msvc@1.0.8` — MIT <https://github.com/Brooooooklyn/canvas#readme>
39
39
  - `dingbat-to-unicode@1.0.1` — BSD-2-Clause — © Michael Williamson <https://github.com/mwilliamson/dingbat-to-unicode#readme>
40
40
  - `format@0.2.2` — MIT — © Sami Samhuri <http://samhuri.net/proj/format>
41
41
  - `isarray@1.0.0` — MIT — © Julian Gruber <https://github.com/juliangruber/isarray>
@@ -49,8 +49,8 @@ the declared licence; refer to the upstream project for the notice.
49
49
  - **@iconify/types@2.0.0** — MIT — see licence text #5 <https://github.com/iconify/iconify>
50
50
  - **@iconify/utils@3.1.4** — MIT — see licence text #6 <https://iconify.design/docs/libraries/utils/>
51
51
  - **@mermaid-js/parser@1.2.0** — MIT — see licence text #7 <https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/parser/#readme>
52
- - **@napi-rs/canvas@0.1.100** — MIT — see licence text #8 <https://github.com/Brooooooklyn/canvas#readme>
53
- - **@napi-rs/canvas-win32-x64-msvc@0.1.100** — MIT — no licence file shipped <https://github.com/Brooooooklyn/canvas#readme>
52
+ - **@napi-rs/canvas@1.0.8** — MIT — see licence text #8 <https://github.com/Brooooooklyn/canvas#readme>
53
+ - **@napi-rs/canvas-win32-x64-msvc@1.0.8** — MIT — no licence file shipped <https://github.com/Brooooooklyn/canvas#readme>
54
54
  - **@tailwindcss/typography@0.5.20** — MIT — see licence text #9 <https://github.com/tailwindlabs/tailwindcss-typography#readme>
55
55
  - **@types/d3@7.4.3** — MIT — see licence text #10 <https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/d3>
56
56
  - **@types/d3-array@3.2.2** — MIT — see licence text #10 <https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/d3-array>
@@ -272,7 +272,7 @@ the declared licence; refer to the upstream project for the notice.
272
272
  - **parse5@7.3.0** — MIT — see licence text #86 <https://parse5.js.org>
273
273
  - **path-data-parser@0.1.0** — MIT — see licence text #87 <https://github.com/pshihn/path-data-parser#readme>
274
274
  - **path-is-absolute@1.0.1** — MIT — see licence text #88 <https://github.com/sindresorhus/path-is-absolute#readme>
275
- - **pdfjs-dist@5.7.284** — Apache-2.0 — see licence text #89 <https://mozilla.github.io/pdf.js/>
275
+ - **pdfjs-dist@6.2.108** — Apache-2.0 — see licence text #89 <https://mozilla.github.io/pdf.js/>
276
276
  - **points-on-curve@0.2.0** — MIT — see licence text #87 <https://github.com/pshihn/bezier-points#readme>
277
277
  - **points-on-path@0.2.1** — MIT — see licence text #90 <https://github.com/pshihn/points-on-path#readme>
278
278
  - **postal-mime@3.0.0** — MIT-0 — see licence text #91 <https://postal-mime.postalsys.com>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.13.3",
3
+ "version": "0.13.6",
4
4
  "description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -33,7 +33,7 @@
33
33
  "lucide-react": "^1.7.0",
34
34
  "mammoth": "^1.12.0",
35
35
  "mermaid": "^11.16.1",
36
- "pdfjs-dist": "^5.4.624",
36
+ "pdfjs-dist": "^6.2.108",
37
37
  "postal-mime": "^3.0.0",
38
38
  "react-markdown": "^10.1.0",
39
39
  "react-resizable-panels": "^4.10.0",
@@ -45,7 +45,7 @@
45
45
  "tailwind-merge": "^3.5.0",
46
46
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
47
47
  "yaml": "^2.9.0",
48
- "@bevel-software/platform-shared": "0.13.3"
48
+ "@bevel-software/platform-shared": "0.13.6"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/jest-dom": "^6.9.1",
@@ -45,6 +45,9 @@ vi.mock('../services/library.api', () => ({
45
45
  getSkill: libraryMock.getSkill,
46
46
  }));
47
47
 
48
+ const sourceMock = vi.hoisted(() => ({ readFileOnBranch: vi.fn() }));
49
+ vi.mock('../../change-requests/services/change-requests.api', () => sourceMock);
50
+
48
51
  vi.mock('../../secrets-vault/services/connect.api', () => ({ startToolOAuth: vi.fn() }));
49
52
  vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
50
53
 
@@ -72,6 +75,29 @@ const DETAIL: ToolManualDetail = {
72
75
  ],
73
76
  };
74
77
 
78
+ /**
79
+ * A `.tool` with everything a formatter would be tempted to touch: the `---`
80
+ * fences, a folded description, a comment, and a fenced template carrying an
81
+ * unexpanded `${VAR}`. The section shows these bytes or it shows a lie.
82
+ */
83
+ const SOURCE = [
84
+ '---',
85
+ 'name: heyreach',
86
+ 'description: >-',
87
+ ' Runs LinkedIn',
88
+ ' outreach campaigns.',
89
+ '---',
90
+ '',
91
+ '# heyreach',
92
+ '',
93
+ '<!-- keep me: a reader is here precisely for this -->',
94
+ '',
95
+ '```http',
96
+ 'GET https://api.heyreach.io/campaigns',
97
+ 'Authorization: Bearer ${HEYREACH_API_KEY}',
98
+ '```',
99
+ '',
100
+ ].join('\n');
75
101
  const workspace = {
76
102
  workspaceId: 'target-company-state',
77
103
  kbDirName: 'knowledge-base',
@@ -126,6 +152,7 @@ beforeEach(() => {
126
152
  toolsMock.getMcpServer.mockClear();
127
153
  libraryMock.listSkills.mockReset().mockResolvedValue([]);
128
154
  libraryMock.getSkill.mockReset().mockResolvedValue({ allowedTools: [] });
155
+ sourceMock.readFileOnBranch.mockReset().mockResolvedValue(SOURCE);
129
156
  });
130
157
 
131
158
  describe('ToolPage: frame', () => {
@@ -364,3 +391,124 @@ describe('ToolPage: OAuth round-trip', () => {
364
391
  );
365
392
  });
366
393
  });
394
+
395
+ /**
396
+ * The `.tool` itself, at the bottom of the page.
397
+ *
398
+ * The four things worth pinning are the four the section can get wrong in a
399
+ * way nobody notices: it must be CLOSED (a reader who wanted the tool, not its
400
+ * file, sees no change), the text must be the file's BYTES (a view that
401
+ * reformats is worse than no view — it invents a source that does not exist),
402
+ * a failed read must cost the section and nothing else, and the read must not
403
+ * happen until it is asked for.
404
+ */
405
+ describe('ToolPage: source', () => {
406
+ const toggle = () => screen.getByRole('button', { name: 'Source' });
407
+
408
+ it('is closed on first visit, with the file path beside its label', async () => {
409
+ renderPage();
410
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
411
+
412
+ expect(toggle()).toHaveAttribute('aria-expanded', 'false');
413
+ expect(screen.getByText('Plugins/GTM/heyreach.tool')).toBeInTheDocument();
414
+ expect(document.querySelector('pre')).toBeNull();
415
+ });
416
+
417
+ it('reads nothing until it is opened, and then exactly once', async () => {
418
+ renderPage();
419
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
420
+ // The whole point of the disclosure: no reader pays for a file they did
421
+ // not ask to see.
422
+ expect(sourceMock.readFileOnBranch).not.toHaveBeenCalled();
423
+
424
+ fireEvent.click(toggle());
425
+ await waitFor(() => expect(sourceMock.readFileOnBranch).toHaveBeenCalledTimes(1));
426
+ // The OFFICIAL version — the file the platform runs, not a draft branch.
427
+ expect(sourceMock.readFileOnBranch).toHaveBeenCalledWith(
428
+ 'target-company-state',
429
+ 'Plugins/GTM/heyreach.tool',
430
+ );
431
+ });
432
+
433
+ it('shows the file verbatim — fences, comments, folding and all', async () => {
434
+ renderPage();
435
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
436
+ fireEvent.click(toggle());
437
+
438
+ await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
439
+ // Byte for byte. Not "contains", not "matches after trimming".
440
+ expect(document.querySelector('pre')!.textContent).toBe(SOURCE);
441
+ expect(toggle()).toHaveAttribute('aria-expanded', 'true');
442
+ });
443
+
444
+ it('offers no way to edit what it shows', async () => {
445
+ renderPage();
446
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
447
+ fireEvent.click(toggle());
448
+ await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
449
+
450
+ expect(document.querySelector('textarea')).toBeNull();
451
+ expect(document.querySelector('pre')!.closest('[contenteditable]')).toBeNull();
452
+ expect(screen.queryByRole('button', { name: 'Save' })).toBeNull();
453
+ });
454
+
455
+ it('opening it changes nothing above it', async () => {
456
+ renderPage();
457
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
458
+ fireEvent.click(toggle());
459
+ await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
460
+
461
+ expect(screen.getByText('Runs LinkedIn outreach campaigns.')).toBeInTheDocument();
462
+ expect(screen.getByRole('heading', { name: 'What it lets the assistant do' })).toBeInTheDocument();
463
+ expect(screen.getByRole('heading', { name: 'Powers these skills' })).toBeInTheDocument();
464
+ expect(screen.getByText('Managed by the Admins.')).toBeInTheDocument();
465
+ });
466
+
467
+ it('shows a short message in place of the content when the file cannot be read, and retries on reopen', async () => {
468
+ sourceMock.readFileOnBranch.mockRejectedValueOnce(new Error('HTTP 404'));
469
+ renderPage();
470
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
471
+
472
+ fireEvent.click(toggle());
473
+ expect(await screen.findByText("Couldn't load the source.")).toBeInTheDocument();
474
+ expect(document.querySelector('pre')).toBeNull();
475
+ // The page around it is untouched — a missing file is not a broken page.
476
+ expect(screen.getByRole('heading', { name: 'heyreach', level: 1 })).toBeInTheDocument();
477
+ expect(screen.getByText('Runs LinkedIn outreach campaigns.')).toBeInTheDocument();
478
+
479
+ fireEvent.click(toggle()); // close
480
+ fireEvent.click(toggle()); // open again — a failed read is never the final answer
481
+ await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
482
+ expect(document.querySelector('pre')!.textContent).toBe(SOURCE);
483
+ });
484
+
485
+ it.each(['inline', 'http', 'mcp'] as const)('is present on a %s tool', async (type) => {
486
+ secretsMock.listToolSecrets.mockResolvedValue([{ ...GITHUB, type }]);
487
+ toolsMock.getToolDetail.mockResolvedValue({ ...DETAIL, type, capabilities: [] });
488
+
489
+ renderPage();
490
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
491
+ expect(toggle()).toHaveAttribute('aria-expanded', 'false');
492
+ });
493
+
494
+ it('shows the mcp.json for a tool declared through a plugin, like every other type', async () => {
495
+ const MCP_JSON = '{\n "mcpServers": {\n "notion": { "url": "https://mcp.notion.com/mcp" }\n }\n}\n';
496
+ secretsMock.listToolSecrets.mockResolvedValue([
497
+ { ...GITHUB, slug: 'notion', name: 'notion', type: 'mcp', path: 'Plugins/GTM/mcp.json' },
498
+ ]);
499
+ toolsMock.getToolDetail.mockResolvedValue({ ...DETAIL, slug: 'notion', name: 'notion' });
500
+ sourceMock.readFileOnBranch.mockResolvedValue(MCP_JSON);
501
+
502
+ renderPage({ slug: 'notion' });
503
+ await screen.findByRole('heading', { name: 'notion', level: 1 });
504
+ expect(screen.getByText('Plugins/GTM/mcp.json')).toBeInTheDocument();
505
+
506
+ fireEvent.click(toggle());
507
+ await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
508
+ expect(sourceMock.readFileOnBranch).toHaveBeenCalledWith(
509
+ 'target-company-state',
510
+ 'Plugins/GTM/mcp.json',
511
+ );
512
+ expect(document.querySelector('pre')!.textContent).toBe(MCP_JSON);
513
+ });
514
+ });
@@ -1,7 +1,10 @@
1
- import { useEffect, useState, type ReactNode } from 'react';
1
+ import { useEffect, useId, useState, type ReactNode } from 'react';
2
2
  import { Link, useNavigate, useParams } from 'react-router-dom';
3
+ import { ChevronRight } from 'lucide-react';
4
+ import { cn } from '../../../../lib/utils';
3
5
  import { Banner, Button, buttonClasses } from '../../../../shared/components';
4
6
  import { useToolPage } from '../../hooks/useToolPage';
7
+ import { useToolSource } from '../../hooks/useToolSource';
5
8
  import { McpServerSection } from './McpServerSection';
6
9
  import { libraryHomeForItemPath, LIBRARY_ROOT } from '../../routes/library-paths';
7
10
  import { readOAuthFragment } from '../../utils/oauth-fragment';
@@ -175,6 +178,10 @@ export function ToolPage({
175
178
  Managed by the Admins.
176
179
  </div>
177
180
 
181
+ {/* Last, and for EVERY type: `path` is the file the platform reads to
182
+ make this tool — the `.tool`, or the plugin `mcp.json` that declares
183
+ the server. */}
184
+ <SourceSection path={tool.path} />
178
185
  </Article>
179
186
  );
180
187
  }
@@ -241,6 +248,82 @@ function PoweredSkillsSection({
241
248
  );
242
249
  }
243
250
 
251
+ /**
252
+ * The definition file, as text, behind a closed disclosure.
253
+ *
254
+ * A WINDOW, NOT AN EDITOR. The file is edited where files are edited; showing
255
+ * it here is what saves a developer the trip to the knowledge tree to answer
256
+ * "which template does this capability use" — and nothing in this section can
257
+ * change it.
258
+ *
259
+ * Closed by default is the mechanism, not just the default: the read hangs off
260
+ * the open state (`useToolSource`), so a reader who never opens the section
261
+ * never costs a file read, and everything above it renders the same whether
262
+ * the read succeeds, fails, or never happens.
263
+ */
264
+ function SourceSection({ path }: { path: string }) {
265
+ const [open, setOpen] = useState(false);
266
+ const source = useToolSource(path, open);
267
+ const panelId = useId();
268
+ const buttonId = useId();
269
+ // Open and neither settled state: the read is in flight.
270
+ const loading = open && source.status !== 'loaded' && source.status !== 'error';
271
+
272
+ return (
273
+ <section className="mt-8">
274
+ <div className="flex flex-wrap items-baseline gap-x-2.5 gap-y-1">
275
+ <button
276
+ id={buttonId}
277
+ type="button"
278
+ onClick={() => setOpen((v) => !v)}
279
+ aria-expanded={open}
280
+ aria-controls={panelId}
281
+ className="flex items-center gap-1.5 text-label font-semibold uppercase text-ink-faint transition-colors hover:text-ink"
282
+ >
283
+ <ChevronRight
284
+ size={11}
285
+ className={cn('transition-transform duration-150', open && 'rotate-90')}
286
+ />
287
+ Source
288
+ </button>
289
+ <span className="min-w-0 truncate font-mono text-meta text-ink-faint" title={path}>
290
+ {path}
291
+ </span>
292
+ </div>
293
+
294
+ {/* Always in the tree, so `aria-controls` never points at nothing; the
295
+ CONTENT is what is conditional, which is what keeps the read lazy.
296
+
297
+ A labelled region that is live and busy while the read runs: a
298
+ screen reader otherwise hears the button flip to "expanded" and
299
+ then nothing, because the content arrives a fetch later. `polite`
300
+ — the source is worth hearing, not worth interrupting for. */}
301
+ <div
302
+ id={panelId}
303
+ role="region"
304
+ aria-labelledby={buttonId}
305
+ aria-live="polite"
306
+ aria-busy={loading}
307
+ hidden={!open}
308
+ >
309
+ {open &&
310
+ (source.status === 'error' ? (
311
+ <p className="mt-2.5 text-detail text-ink-muted">Couldn't load the source.</p>
312
+ ) : source.status === 'loaded' ? (
313
+ /* `whitespace-pre` and nothing else: the bytes are shown as the
314
+ platform stores them — no wrapping, reindenting or trimming.
315
+ Long lines scroll rather than fold. */
316
+ <pre className="mt-2.5 max-h-[32rem] select-text overflow-auto whitespace-pre rounded-lg border border-line bg-sunken p-3 font-mono text-meta leading-relaxed text-ink">
317
+ {source.content}
318
+ </pre>
319
+ ) : (
320
+ <p className="mt-2.5 text-detail text-ink-faint">Loading the source…</p>
321
+ ))}
322
+ </div>
323
+ </section>
324
+ );
325
+ }
326
+
244
327
  /** A malformed escape is a bad link, not a crash — fall back to the raw segment. */
245
328
  function safeDecode(raw: string): string {
246
329
  try {
@@ -0,0 +1,77 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
3
+ import { readFileOnBranch } from '../../change-requests/services/change-requests.api';
4
+
5
+ /**
6
+ * The raw bytes of a tool's definition file, read LAZILY — nothing is asked
7
+ * for until the caller says the source section is open.
8
+ *
9
+ * Why the official version and not the reader's current branch: the tool
10
+ * catalog is resolved against the default branch, so that is the file the
11
+ * platform actually runs AND the file whose read verdict admitted the tool to
12
+ * the page in the first place. Reading any other branch could 404 (or refuse)
13
+ * a file the listing just showed, and would show a draft as if it were live.
14
+ *
15
+ * Access needs no check here. `GET /api/workspace/:id/file` applies the same
16
+ * per-file read rule the tool listing filters on, against the same
17
+ * repo-relative path — so the endpoint is the authority, and a refusal simply
18
+ * lands as the error state.
19
+ *
20
+ * Not `useDefaultBranchFile`, which reads the same file from the same branch:
21
+ * that hook collapses "still reading" and "could not read" into one `null`,
22
+ * because its callers (a diff, an editor seed) render nothing either way. A
23
+ * disclosure must tell them apart — it owes the reader a visible answer when
24
+ * the read fails, and a silent spinner is not one.
25
+ */
26
+ export type ToolSourceStatus = 'idle' | 'loading' | 'loaded' | 'error';
27
+
28
+ export interface ToolSourceState {
29
+ status: ToolSourceStatus;
30
+ /** The file's text, verbatim — only on `loaded`. */
31
+ content: string | null;
32
+ }
33
+
34
+ const IDLE: ToolSourceState = { status: 'idle', content: null };
35
+ const LOADING: ToolSourceState = { status: 'loading', content: null };
36
+ const FAILED: ToolSourceState = { status: 'error', content: null };
37
+
38
+ export function useToolSource(path: string | null, open: boolean): ToolSourceState {
39
+ const [state, setState] = useState<ToolSourceState>(IDLE);
40
+ const requestRef = useRef(0);
41
+
42
+ /**
43
+ * `null` while closed, which is what makes the fetch lazy and what makes a
44
+ * close-then-reopen RETRY: the key changes on both edges, so a failed read is
45
+ * never cached as the section's permanent answer.
46
+ *
47
+ * Reset during render against the previous key, not in the effect — the same
48
+ * rule `useToolPage` follows. An effect would repaint the previous tool's
49
+ * source under the new heading for a frame, and the synchronous setState is
50
+ * what `react-hooks/set-state-in-effect` flags.
51
+ */
52
+ const key = open && path ? path : null;
53
+ const [seenKey, setSeenKey] = useState(key);
54
+ if (key !== seenKey) {
55
+ setSeenKey(key);
56
+ setState(key === null ? IDLE : LOADING);
57
+ }
58
+
59
+ useEffect(() => {
60
+ // Bumped on every pass, closes included, so an answer for a path the
61
+ // reader has already navigated (or closed) away from can never land.
62
+ const request = ++requestRef.current;
63
+ if (key === null) return;
64
+
65
+ readFileOnBranch(DEFAULT_BRANCH, key)
66
+ .then((content) => {
67
+ if (requestRef.current === request) setState({ status: 'loaded', content });
68
+ })
69
+ .catch(() => {
70
+ // Deliberately not the backend's message: a read refusal and a missing
71
+ // file must read the same, the way the page's not-found state does.
72
+ if (requestRef.current === request) setState(FAILED);
73
+ });
74
+ }, [key]);
75
+
76
+ return state;
77
+ }