@bevel-software/platform-core-frontend 0.31.0 → 0.33.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/modules/access/api.ts +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +4 -5
- 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/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +2 -2
- package/src/modules/auth/index.ts +12 -0
- 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/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/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 +39 -0
- 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 +19 -7
- package/src/modules/library/components/skill-page/SkillPage.tsx +19 -26
- 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 +1 -2
- package/src/modules/review/components/ReviewPanel.tsx +2 -3
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- 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 +1 -1
- 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/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/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 +137 -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 +36 -175
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +20 -3
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +63 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +14 -3
- 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 +75 -13
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +196 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -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/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +30 -1
- package/src/modules/workspace/routing/kb-routes.ts +1 -1
- 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/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
|
@@ -424,6 +424,33 @@ describe('buildSandboxedHtml', () => {
|
|
|
424
424
|
expect(out).toContain('jumpTo(href)');
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
+
// A key pressed inside the frame never reaches the app, so the app's
|
|
428
|
+
// Escape (a card's close, leaving full screen) would go deaf once the
|
|
429
|
+
// reader clicked into the page. The frame hands the parent an Escape the
|
|
430
|
+
// page did not use, and nothing else.
|
|
431
|
+
it('hands the parent an Escape the page left alone, and no other key', async () => {
|
|
432
|
+
const bridge = runBridge();
|
|
433
|
+
await bridge.press('Escape');
|
|
434
|
+
await bridge.press('a');
|
|
435
|
+
await bridge.press('Enter');
|
|
436
|
+
expect(bridge.posted).toEqual([{ type: 'bevel.key', key: 'Escape' }]);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('keeps an Escape the page cancelled to the page', async () => {
|
|
440
|
+
const bridge = runBridge();
|
|
441
|
+
await bridge.press('Escape', { alreadyPrevented: true });
|
|
442
|
+
expect(bridge.posted).toEqual([]);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// A handler the page adds after the bridge ran comes after the bridge's in
|
|
446
|
+
// the same phase; the page's word on the key is final only once the
|
|
447
|
+
// dispatch is over, so that is when the bridge reads it.
|
|
448
|
+
it('keeps an Escape to the page when a handler of its own cancels it after the bridge\'s', async () => {
|
|
449
|
+
const bridge = runBridge();
|
|
450
|
+
await bridge.press('Escape', { preventedAfter: true });
|
|
451
|
+
expect(bridge.posted).toEqual([]);
|
|
452
|
+
});
|
|
453
|
+
|
|
427
454
|
it('injects no height reporter: the frame tells its parent where a link goes, never how tall it is', () => {
|
|
428
455
|
// The frame's height is the reader's (`frameResizeHandle.ts`), never
|
|
429
456
|
// read off the page: a page laid out in the frame and measured there
|
|
@@ -600,25 +627,57 @@ describe('buildSandboxedHtml', () => {
|
|
|
600
627
|
});
|
|
601
628
|
|
|
602
629
|
describe('window.bevel.tools in the frame', () => {
|
|
603
|
-
type Tools = Record<'searchTools' | 'toolsInfo' | 'callTool' | 'callToolChain', (...a: unknown[]) => Promise<unknown>>;
|
|
630
|
+
type Tools = Record<'searchTools' | 'toolsInfo' | 'callTool' | 'callToolChain' | 'uploadFile', (...a: unknown[]) => Promise<unknown>>;
|
|
604
631
|
const toolsOf = (bridge: ReturnType<typeof runBridge>) => bridge.bevel.tools as Tools | null;
|
|
605
632
|
|
|
606
|
-
it('has the
|
|
633
|
+
it('has the five functions where the app answers tools, each posting a call with a request id', async () => {
|
|
607
634
|
const bridge = runBridge({}, { toolBridge: true });
|
|
608
635
|
const tools = toolsOf(bridge)!;
|
|
609
|
-
expect(Object.keys(tools).sort()).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo']);
|
|
636
|
+
expect(Object.keys(tools).sort()).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo', 'uploadFile']);
|
|
610
637
|
void tools.searchTools('change request');
|
|
611
638
|
void tools.toolsInfo(['read_file']);
|
|
612
639
|
void tools.callTool('read_file', { body: { path: 'a.md' } });
|
|
613
640
|
void tools.callToolChain('return 1');
|
|
641
|
+
const file = new Blob(['a,b\n']);
|
|
642
|
+
void tools.uploadFile(file, { name: 'Budget.csv', branch: 'main', destination: 'Data', mode: 'overwrite', all: true });
|
|
614
643
|
const posted = bridge.posted as Array<{ type: string; requestId: string; fn: string; args: unknown[] }>;
|
|
615
644
|
expect(posted.map((m) => [m.type, m.fn, m.args])).toEqual([
|
|
616
645
|
['bevel.tool.call', 'searchTools', ['change request']],
|
|
617
646
|
['bevel.tool.call', 'toolsInfo', [['read_file']]],
|
|
618
647
|
['bevel.tool.call', 'callTool', ['read_file', { body: { path: 'a.md' } }]],
|
|
619
648
|
['bevel.tool.call', 'callToolChain', ['return 1']],
|
|
649
|
+
// The file itself, for the parent to clone; of the options, only the four it reads.
|
|
650
|
+
['bevel.tool.call', 'uploadFile', [file, { name: 'Budget.csv', branch: 'main', destination: 'Data', mode: 'overwrite' }]],
|
|
651
|
+
]);
|
|
652
|
+
expect((posted[4]!.args as unknown[])[0]).toBe(file);
|
|
653
|
+
expect(new Set(posted.map((m) => m.requestId)).size).toBe(5);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it('stamps every message with the identity the app built the document with, and none without one', async () => {
|
|
657
|
+
// The real runtime, given the identity the app minted for this document:
|
|
658
|
+
// tool calls and requireTools alike carry it, so the app can tell this
|
|
659
|
+
// document's messages from a replaced document's. Built with `true`, the
|
|
660
|
+
// runtime posts no identity; built with `tools: false`, the document has
|
|
661
|
+
// no tools but still asks `requireTools` as itself.
|
|
662
|
+
const named = runBridge({}, { toolBridge: { documentId: 'doc-abc' } });
|
|
663
|
+
void toolsOf(named)!.callTool('read_file', { body: { path: 'a.md' } });
|
|
664
|
+
void (named.bevel.requireTools as () => Promise<boolean>)();
|
|
665
|
+
expect((named.posted as Array<Record<string, unknown>>).map((m) => [m.type, m.documentId])).toEqual([
|
|
666
|
+
['bevel.tool.call', 'doc-abc'],
|
|
667
|
+
['bevel.tools.require', 'doc-abc'],
|
|
668
|
+
]);
|
|
669
|
+
|
|
670
|
+
const anonymous = runBridge({}, { toolBridge: true });
|
|
671
|
+
void toolsOf(anonymous)!.callTool('read_file', {});
|
|
672
|
+
void (anonymous.bevel.requireTools as () => Promise<boolean>)();
|
|
673
|
+
expect((anonymous.posted as Array<Record<string, unknown>>).every((m) => !('documentId' in m))).toBe(true);
|
|
674
|
+
|
|
675
|
+
const toolless = runBridge({}, { toolBridge: { documentId: 'doc-xyz', tools: false } });
|
|
676
|
+
expect(toolsOf(toolless)).toBeNull();
|
|
677
|
+
void (toolless.bevel.requireTools as () => Promise<boolean>)();
|
|
678
|
+
expect((toolless.posted as Array<Record<string, unknown>>).map((m) => [m.type, m.documentId])).toEqual([
|
|
679
|
+
['bevel.tools.require', 'doc-xyz'],
|
|
620
680
|
]);
|
|
621
|
-
expect(new Set(posted.map((m) => m.requestId)).size).toBe(4);
|
|
622
681
|
});
|
|
623
682
|
|
|
624
683
|
it("resolves with the parent's answer and rejects with its error and code, matched by request id", async () => {
|
|
@@ -217,8 +217,9 @@ describe('answering a page: reads at once, the first write asks', () => {
|
|
|
217
217
|
});
|
|
218
218
|
|
|
219
219
|
describe('the frame messages the app reads', () => {
|
|
220
|
-
it('accepts only a well-formed call of one of the
|
|
220
|
+
it('accepts only a well-formed call of one of the five functions', () => {
|
|
221
221
|
expect(asToolCall({ type: 'bevel.tool.call', requestId: 'r', fn: 'callTool', args: ['read_file', {}] })).not.toBeNull();
|
|
222
|
+
expect(asToolCall({ type: 'bevel.tool.call', requestId: 'r', fn: 'uploadFile', args: [new Blob(['x']), {}] })).not.toBeNull();
|
|
222
223
|
expect(asToolCall({ type: 'bevel.tool.call', requestId: 'r', fn: 'eval', args: [] })).toBeNull();
|
|
223
224
|
expect(asToolCall({ type: 'bevel.tool.call', fn: 'callTool', args: [] })).toBeNull();
|
|
224
225
|
expect(asToolCall({ type: 'bevel.navigate', href: 'x' })).toBeNull();
|
|
@@ -230,3 +231,236 @@ describe('the frame messages the app reads', () => {
|
|
|
230
231
|
expect(pageName('knowledge-base/Boards/Q4.board.htm')).toBe('Q4.board');
|
|
231
232
|
});
|
|
232
233
|
});
|
|
234
|
+
|
|
235
|
+
describe('uploadFile: the agent upload path, run by the app as the viewer', () => {
|
|
236
|
+
const TOKEN = 'bevel-up_s3cret';
|
|
237
|
+
/** 2 MB of bytes that are not text, the size of the campaign's asset list. */
|
|
238
|
+
const XLSX = new File([new Uint8Array(2 * 1024 * 1024).map((_, i) => (i * 31) % 256)], 'Assets.xlsx', {
|
|
239
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
interface UploadSent {
|
|
243
|
+
url: string;
|
|
244
|
+
method: string;
|
|
245
|
+
headers: Headers;
|
|
246
|
+
body: unknown;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The hosted server, the upload endpoint and its discard, as the app's
|
|
251
|
+
* fetch sees them. `posted` answers the bytes' POST; `applied` answers the
|
|
252
|
+
* apply, given its arguments.
|
|
253
|
+
*/
|
|
254
|
+
function uploadServer(
|
|
255
|
+
opts: {
|
|
256
|
+
posted?: () => Response;
|
|
257
|
+
applied?: (args: Record<string, unknown>) => unknown;
|
|
258
|
+
} = {},
|
|
259
|
+
) {
|
|
260
|
+
const sent: UploadSent[] = [];
|
|
261
|
+
const fetchImpl = vi.fn(async (url: string, init?: RequestInit) => {
|
|
262
|
+
const method = init?.method ?? 'GET';
|
|
263
|
+
sent.push({ url, method, headers: new Headers(init?.headers), body: init?.body });
|
|
264
|
+
if (url === '/api/agent/utcp') return Response.json(MANUAL);
|
|
265
|
+
if (url === '/api/mcp/page-refusals') return new Response(null, { status: 204 });
|
|
266
|
+
if (url.startsWith('/api/agent/uploads')) {
|
|
267
|
+
if (method === 'DELETE') return new Response(null, { status: 204 });
|
|
268
|
+
return opts.posted?.() ?? Response.json({ filename: 'x', bytes: 1, kind: 'file' });
|
|
269
|
+
}
|
|
270
|
+
const rpc = JSON.parse(String(init!.body)) as { id: number; params: { name: string; arguments: { body: Record<string, unknown> } } };
|
|
271
|
+
const { name, arguments: args } = rpc.params;
|
|
272
|
+
const result =
|
|
273
|
+
name === 'request_file_upload'
|
|
274
|
+
? text({
|
|
275
|
+
uploadUrl: `https://kb.example.com/api/agent/uploads/${TOKEN}`,
|
|
276
|
+
token: TOKEN,
|
|
277
|
+
expiresAt: '2026-10-20T12:00:00.000Z',
|
|
278
|
+
expiresInSeconds: 900,
|
|
279
|
+
maxBytes: 50 * 1024 * 1024,
|
|
280
|
+
})
|
|
281
|
+
: name === 'apply_file_upload'
|
|
282
|
+
? (opts.applied?.(args.body) ??
|
|
283
|
+
text({
|
|
284
|
+
destination: args.body.destination,
|
|
285
|
+
count: 1,
|
|
286
|
+
total: 1,
|
|
287
|
+
files: [{ path: `knowledge-base/${String(args.body.destination)}/Assets.xlsx`, outcome: 'created' }],
|
|
288
|
+
}))
|
|
289
|
+
: text({ ran: name });
|
|
290
|
+
return Response.json({ jsonrpc: '2.0', id: rpc.id, result });
|
|
291
|
+
});
|
|
292
|
+
/** Each request in order: the MCP tool it called, or the method and address. */
|
|
293
|
+
const steps = () =>
|
|
294
|
+
sent
|
|
295
|
+
.filter((s) => s.url !== '/api/agent/utcp')
|
|
296
|
+
.map((s) =>
|
|
297
|
+
s.url === '/api/mcp'
|
|
298
|
+
? (JSON.parse(String(s.body)) as { params: { name: string } }).params.name
|
|
299
|
+
: `${s.method} ${s.url}`,
|
|
300
|
+
);
|
|
301
|
+
const argsOf = (tool: string) =>
|
|
302
|
+
sent
|
|
303
|
+
.filter((s) => s.url === '/api/mcp')
|
|
304
|
+
.map((s) => JSON.parse(String(s.body)) as { params: { name: string; arguments: { body: unknown } } })
|
|
305
|
+
.find((r) => r.params.name === tool)?.params.arguments.body;
|
|
306
|
+
return { sent, fetchImpl, steps, argsOf };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const sha256 = async (blob: Blob) =>
|
|
310
|
+
Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer())))
|
|
311
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
312
|
+
.join('');
|
|
313
|
+
|
|
314
|
+
it('requests a token, POSTs the bytes with the token in a header, then applies — and resolves with the apply', async () => {
|
|
315
|
+
const server = uploadServer();
|
|
316
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
317
|
+
const answer = await client.uploadFile(XLSX, { branch: 'main', destination: 'Data/Campaigns/Easter' });
|
|
318
|
+
|
|
319
|
+
expect(answer).toEqual({
|
|
320
|
+
destination: 'Data/Campaigns/Easter',
|
|
321
|
+
count: 1,
|
|
322
|
+
total: 1,
|
|
323
|
+
files: [{ path: 'knowledge-base/Data/Campaigns/Easter/Assets.xlsx', outcome: 'created' }],
|
|
324
|
+
});
|
|
325
|
+
expect(server.steps()).toEqual([
|
|
326
|
+
'request_file_upload',
|
|
327
|
+
'POST /api/agent/uploads?filename=Assets.xlsx',
|
|
328
|
+
'apply_file_upload',
|
|
329
|
+
]);
|
|
330
|
+
// Both tool calls go out as the page, so the Audit log names it as the agent.
|
|
331
|
+
for (const s of server.sent.filter((x) => x.url === '/api/mcp')) {
|
|
332
|
+
expect(decodeURIComponent(s.headers.get('X-Bevel-Page')!)).toBe(PAGE);
|
|
333
|
+
}
|
|
334
|
+
// The token in the header, never in the address; the body is the file itself, byte for byte.
|
|
335
|
+
const post = server.sent.find((s) => s.method === 'POST' && s.url.startsWith('/api/agent/uploads'))!;
|
|
336
|
+
expect(post.url).not.toContain(TOKEN);
|
|
337
|
+
expect(post.headers.get('x-upload-token')).toBe(TOKEN);
|
|
338
|
+
expect(post.body).toBeInstanceOf(Blob);
|
|
339
|
+
expect(await sha256(post.body as Blob)).toBe(await sha256(XLSX));
|
|
340
|
+
expect((post.body as Blob).size).toBe(2 * 1024 * 1024);
|
|
341
|
+
// The apply names the token, the branch and the folder, and asks for every
|
|
342
|
+
// path's outcome; `mode` is left to the tool's default, `create`.
|
|
343
|
+
expect(server.argsOf('apply_file_upload')).toEqual({ branch: 'main', token: TOKEN, destination: 'Data/Campaigns/Easter', all: true });
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('names a Blob by its `name` option, and lets that option rename a File', async () => {
|
|
347
|
+
const server = uploadServer();
|
|
348
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
349
|
+
await client.uploadFile(new Blob(['a,b\n1,2\n'], { type: 'text/csv' }), { name: 'Budget.csv', branch: 'main', destination: 'Data' });
|
|
350
|
+
await client.uploadFile(new File(['zip'], 'export.zip'), { name: 'Campaign assets.zip', branch: 'main', destination: 'Data' });
|
|
351
|
+
expect(server.steps().filter((s) => s.startsWith('POST'))).toEqual([
|
|
352
|
+
'POST /api/agent/uploads?filename=Budget.csv',
|
|
353
|
+
'POST /api/agent/uploads?filename=Campaign%20assets.zip',
|
|
354
|
+
]);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('refuses a call it cannot make before asking the server for anything', async () => {
|
|
358
|
+
const server = uploadServer();
|
|
359
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
360
|
+
await expect(client.uploadFile('not a file', { branch: 'main', destination: 'Data' })).rejects.toThrow('needs a File');
|
|
361
|
+
await expect(client.uploadFile(new Blob(['x']), { branch: 'main', destination: 'Data' })).rejects.toThrow('needs a file name');
|
|
362
|
+
await expect(client.uploadFile(XLSX, { destination: 'Data' })).rejects.toThrow('needs `branch`');
|
|
363
|
+
await expect(client.uploadFile(XLSX, { branch: 'main' })).rejects.toThrow('needs `destination`');
|
|
364
|
+
expect(server.sent).toEqual([]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('passes `mode` through to the apply', async () => {
|
|
368
|
+
for (const mode of ['create', 'overwrite', 'update']) {
|
|
369
|
+
const server = uploadServer();
|
|
370
|
+
await new PageToolsClient(PAGE, server.fetchImpl).uploadFile(XLSX, { branch: 'main', destination: 'Data', mode });
|
|
371
|
+
expect(server.argsOf('apply_file_upload')).toMatchObject({ mode });
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("rejects with the path's own refusal and code when nothing landed — `exists` under create", async () => {
|
|
376
|
+
const message = '"knowledge-base/Data/Assets.xlsx" already exists. Pass `mode: overwrite` to replace it.';
|
|
377
|
+
const server = uploadServer({
|
|
378
|
+
applied: () =>
|
|
379
|
+
text({
|
|
380
|
+
destination: 'Data',
|
|
381
|
+
count: 0,
|
|
382
|
+
total: 1,
|
|
383
|
+
files: [{ path: 'knowledge-base/Data/Assets.xlsx', outcome: 'refused', error: 'exists', message }],
|
|
384
|
+
}),
|
|
385
|
+
});
|
|
386
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
387
|
+
const err = await client.uploadFile(XLSX, { branch: 'main', destination: 'Data' }).catch((e: unknown) => e);
|
|
388
|
+
expect(err).toMatchObject({ message, code: 'exists' });
|
|
389
|
+
// The apply answered, so it spent the token itself: there is nothing to discard.
|
|
390
|
+
expect(server.steps()).toEqual(['request_file_upload', 'POST /api/agent/uploads?filename=Assets.xlsx', 'apply_file_upload']);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("rejects an upload over the limit with the server's message, applies nothing, and discards the token", async () => {
|
|
394
|
+
const limit = "That upload is 2097152 bytes, over this deployment's 1048576 byte upload limit. Send a smaller file, or split it across several uploads.";
|
|
395
|
+
const server = uploadServer({ posted: () => Response.json({ error: limit }, { status: 413 }) });
|
|
396
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
397
|
+
await expect(client.uploadFile(XLSX, { branch: 'main', destination: 'Data' })).rejects.toThrow(limit);
|
|
398
|
+
expect(server.steps()).toEqual([
|
|
399
|
+
'request_file_upload',
|
|
400
|
+
'POST /api/agent/uploads?filename=Assets.xlsx',
|
|
401
|
+
'DELETE /api/agent/uploads',
|
|
402
|
+
]);
|
|
403
|
+
const discard = server.sent.at(-1)!;
|
|
404
|
+
expect(discard.headers.get('x-upload-token')).toBe(TOKEN);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("rejects a destination the viewer may not write with the tool's refusal, and discards the staged bytes", async () => {
|
|
408
|
+
const refusal = 'You don\'t have write access to "knowledge-base/Finance". Propose it through a change request.';
|
|
409
|
+
const server = uploadServer({ applied: () => ({ isError: true, content: [{ type: 'text', text: refusal }] }) });
|
|
410
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
411
|
+
await expect(client.uploadFile(XLSX, { branch: 'main', destination: 'Finance' })).rejects.toThrow(refusal);
|
|
412
|
+
expect(server.steps()).toEqual([
|
|
413
|
+
'request_file_upload',
|
|
414
|
+
'POST /api/agent/uploads?filename=Assets.xlsx',
|
|
415
|
+
'apply_file_upload',
|
|
416
|
+
'DELETE /api/agent/uploads',
|
|
417
|
+
]);
|
|
418
|
+
expect(server.sent.at(-1)!.url).not.toContain(TOKEN);
|
|
419
|
+
expect(server.sent.at(-1)!.headers.get('x-upload-token')).toBe(TOKEN);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('counts as writing', async () => {
|
|
423
|
+
const client = new PageToolsClient(PAGE, uploadServer().fetchImpl);
|
|
424
|
+
expect(await client.mayWrite('uploadFile', [XLSX, {}])).toBe(true);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('asks on the first upload; Allow runs it, a later upload and write run without asking, and the token never reaches the page', async () => {
|
|
428
|
+
const server = uploadServer();
|
|
429
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
430
|
+
let answer: (ok: boolean) => void = () => {};
|
|
431
|
+
const ask = vi.fn(() => new Promise<boolean>((resolve) => (answer = resolve)));
|
|
432
|
+
const consent = new PageConsent(ask);
|
|
433
|
+
|
|
434
|
+
const first = answerToolCall(call('uploadFile', XLSX, { branch: 'main', destination: 'Data/Campaigns/Easter' }), client, consent);
|
|
435
|
+
await vi.waitFor(() => expect(ask).toHaveBeenCalledTimes(1));
|
|
436
|
+
expect(server.steps()).toEqual([]);
|
|
437
|
+
answer(true);
|
|
438
|
+
const reply = await first;
|
|
439
|
+
expect(reply).toMatchObject({ ok: true, result: { count: 1, destination: 'Data/Campaigns/Easter' } });
|
|
440
|
+
expect(JSON.stringify(reply)).not.toContain(TOKEN);
|
|
441
|
+
|
|
442
|
+
expect(await answerToolCall(call('uploadFile', XLSX, { branch: 'main', destination: 'Data' }), client, consent)).toMatchObject({ ok: true });
|
|
443
|
+
expect(await answerToolCall(call('callTool', 'edit_file', {}), client, consent)).toMatchObject({ ok: true });
|
|
444
|
+
expect(ask).toHaveBeenCalledTimes(1);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('Deny answers `denied`, uploads nothing, and records a refused apply_file_upload under the page', async () => {
|
|
448
|
+
const server = uploadServer();
|
|
449
|
+
const client = new PageToolsClient(PAGE, server.fetchImpl);
|
|
450
|
+
const consent = new PageConsent(() => Promise.resolve(false));
|
|
451
|
+
const reply = await answerToolCall(
|
|
452
|
+
call('uploadFile', XLSX, { branch: 'main', destination: 'Data/Campaigns/Easter', mode: 'overwrite' }),
|
|
453
|
+
client,
|
|
454
|
+
consent,
|
|
455
|
+
);
|
|
456
|
+
expect(reply).toMatchObject({ ok: false, error: DENIED, code: DENIED });
|
|
457
|
+
await vi.waitFor(() => expect(server.steps()).toEqual(['POST /api/mcp/page-refusals']));
|
|
458
|
+
// The record carries the apply's own arguments in `body` and the file's
|
|
459
|
+
// name beside them: a name is not an argument of apply_file_upload.
|
|
460
|
+
expect(JSON.parse(String(server.sent.at(-1)!.body))).toEqual({
|
|
461
|
+
page: PAGE,
|
|
462
|
+
tool: 'apply_file_upload',
|
|
463
|
+
args: { body: { branch: 'main', destination: 'Data/Campaigns/Easter', mode: 'overwrite' }, file: 'Assets.xlsx' },
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
});
|
|
@@ -148,15 +148,18 @@ describe('the html-views guide section agrees with the renderer', () => {
|
|
|
148
148
|
expect(flat).toContain('A distribution may add data members of its own to `window.bevel`');
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
it('names the
|
|
151
|
+
it('names the five functions of window.bevel.tools the runtime defines, where it is null, and requireTools with its card', async () => {
|
|
152
152
|
const named = [...new Set([...guide.matchAll(/window\.bevel\.tools\.(\w+)\(/g)].map((m) => m[1]!))].sort();
|
|
153
153
|
const onFilePage = runBridge({}, { toolBridge: true });
|
|
154
154
|
expect(named).toEqual(Object.keys(onFilePage.bevel.tools as object).sort());
|
|
155
|
-
expect(named).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo']);
|
|
155
|
+
expect(named).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo', 'uploadFile']);
|
|
156
156
|
|
|
157
157
|
// Null everywhere else, and the guide tells a page to check before every use.
|
|
158
158
|
expect(runBridge().bevel.tools).toBeNull();
|
|
159
|
-
expect(flat).toContain('`window.bevel.tools` is `null` wherever tools are not available: on the embed
|
|
159
|
+
expect(flat).toContain('`window.bevel.tools` is `null` wherever tools are not available: on the embed (a page shown on another site, or in a chat\'s MCP App pane), and in a change request\'s or a file history\'s preview of a page.');
|
|
160
|
+
// Where it is answered: the hosts htmlToolBridge.ts lists, the skill page beside the file page.
|
|
161
|
+
expect(flat).toContain('On the app\'s file page, and on a skill\'s page in the Library');
|
|
162
|
+
expect(flat).toContain('resolves `true` at once, with nothing shown, on the app\'s file page and on a skill\'s page.');
|
|
160
163
|
expect(flat).toContain('Check it before every use, and render the page without tools when it is `null`');
|
|
161
164
|
|
|
162
165
|
// The consent rule and the two cards, in the app's words.
|
|
@@ -165,6 +168,14 @@ describe('the html-views guide section agrees with the renderer', () => {
|
|
|
165
168
|
expect(flat).toContain('Deny runs nothing and rejects the call with `denied`');
|
|
166
169
|
expect(flat).toContain('"<page name> uses tools that are only available in the platform", with Continue without tools and Open in the platform');
|
|
167
170
|
|
|
171
|
+
// uploadFile: its arguments, the promise, the consent rule and the size limit.
|
|
172
|
+
expect(flat).toContain('`uploadFile(file, { branch, destination, mode })`. `file` is a `File` (from an `<input type="file">` or a drop) or a `Blob` with a `name` option');
|
|
173
|
+
expect(flat).toContain("`mode` is `create` (the default), `overwrite` or `update`");
|
|
174
|
+
expect(flat).toContain("The promise resolves with `apply_file_upload`'s answer, `{ destination, count, total, files }`");
|
|
175
|
+
expect(flat).toContain("a file over the deployment's upload limit (the message names it)");
|
|
176
|
+
expect(flat).toContain('An upload is a writing call: the first one shows the card above, and Allow while open covers it and every later upload and writing call of the page view.');
|
|
177
|
+
expect(flat).toContain("The upload's token stays in the app; the page never sees it.");
|
|
178
|
+
|
|
168
179
|
// requireTools exists on both, asks the app, and resolves with its answer.
|
|
169
180
|
for (const [bridge, answer] of [[runBridge(), false], [onFilePage, true]] as const) {
|
|
170
181
|
const required = (bridge.bevel.requireTools as () => Promise<boolean>)();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/** Everything the app posted to a frame window, shared by every channel taken on it. */
|
|
4
|
+
const postedTo = new WeakMap<Window, Array<Record<string, unknown>>>();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The two ends of the page tool bridge a test drives, shared by the app's
|
|
8
|
+
* renderer suite and the controller's own: the frame (what its runtime posts,
|
|
9
|
+
* what the app posts back) and the server (the hosted MCP endpoint and the
|
|
10
|
+
* manual, as the app's fetch sees them).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Post `data` as the frame's CURRENT document would — stamped with the
|
|
15
|
+
* identity the app built into it (`documentId="…"` in the srcdoc), as the
|
|
16
|
+
* runtime stamps every message — and collect what the app posts back. A
|
|
17
|
+
* channel taken before a view change keeps the old document's identity, so
|
|
18
|
+
* it posts as that document would.
|
|
19
|
+
*/
|
|
20
|
+
export function frameChannel(iframe: HTMLIFrameElement) {
|
|
21
|
+
const win = iframe.contentWindow!;
|
|
22
|
+
const documentId = /documentId\s*=\s*"([^"]+)"/.exec(iframe.getAttribute('srcdoc') ?? '')?.[1];
|
|
23
|
+
// One collector per window, however many channels are taken on it: a
|
|
24
|
+
// channel's `replies` are what the app posted to the window since the
|
|
25
|
+
// channel was taken, so a reply meant for a replaced document shows up on
|
|
26
|
+
// the old channel AND the new one, and neither assertion is vacuous.
|
|
27
|
+
let posted = postedTo.get(win);
|
|
28
|
+
if (!posted) {
|
|
29
|
+
posted = [];
|
|
30
|
+
postedTo.set(win, posted);
|
|
31
|
+
const all = posted;
|
|
32
|
+
vi.spyOn(win, 'postMessage').mockImplementation(((msg: Record<string, unknown>) => void all.push(msg)) as never);
|
|
33
|
+
}
|
|
34
|
+
const since = posted.length;
|
|
35
|
+
const all = posted;
|
|
36
|
+
return {
|
|
37
|
+
get replies(): Array<Record<string, unknown>> {
|
|
38
|
+
return all.slice(since);
|
|
39
|
+
},
|
|
40
|
+
documentId,
|
|
41
|
+
post: (data: unknown) =>
|
|
42
|
+
window.dispatchEvent(
|
|
43
|
+
new MessageEvent('message', {
|
|
44
|
+
data: documentId && data && typeof data === 'object' ? { documentId, ...(data as object) } : data,
|
|
45
|
+
source: win,
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The hosted server and the manual: `read_file` reads, `edit_file` writes.
|
|
53
|
+
* `mcp` records every tool the server was asked to run. With `holdManual`,
|
|
54
|
+
* the manual is not answered until `releaseManual()` — a lookup still in
|
|
55
|
+
* flight.
|
|
56
|
+
*/
|
|
57
|
+
export function stubServer({ holdManual = false }: { holdManual?: boolean } = {}) {
|
|
58
|
+
const mcp: string[] = [];
|
|
59
|
+
let releaseManual: () => void = () => undefined;
|
|
60
|
+
const manualHeld = holdManual ? new Promise<void>((resolve) => (releaseManual = resolve)) : Promise.resolve();
|
|
61
|
+
vi.stubGlobal(
|
|
62
|
+
'fetch',
|
|
63
|
+
vi.fn(async (url: string, init?: RequestInit) => {
|
|
64
|
+
if (url === '/api/agent/utcp') {
|
|
65
|
+
await manualHeld;
|
|
66
|
+
return Response.json({ tools: [{ name: 'read_file', tags: [] }, { name: 'edit_file', tags: ['write'] }] });
|
|
67
|
+
}
|
|
68
|
+
if (url === '/api/mcp/page-refusals') return new Response(null, { status: 204 });
|
|
69
|
+
const body = JSON.parse(String(init!.body)) as { id: number; params: { name: string } };
|
|
70
|
+
mcp.push(body.params.name);
|
|
71
|
+
return Response.json({
|
|
72
|
+
jsonrpc: '2.0',
|
|
73
|
+
id: body.id,
|
|
74
|
+
result: { content: [{ type: 'text', text: JSON.stringify({ ran: body.params.name }) }] },
|
|
75
|
+
});
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
return { mcp, releaseManual: () => releaseManual() };
|
|
79
|
+
}
|