@bevel-software/platform-core-frontend 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +1 -1
- package/src/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
|
@@ -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
|
+
});
|
|
@@ -119,6 +119,20 @@ describe('the html-views guide section agrees with the renderer', () => {
|
|
|
119
119
|
expect(bridge.posted).toEqual([]);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
it('says a modified or middle click opens a new tab, and the bridge asks the app for one', () => {
|
|
123
|
+
expect(flat).toContain(
|
|
124
|
+
'A click on a link with Ctrl, Cmd or Shift held, or with the middle button, opens its destination in a new tab, as a browser does with a link: a bare fragment opens the page\'s own file at that section in a new tab, and the page stays where it is.',
|
|
125
|
+
);
|
|
126
|
+
const bridge = runBridge({ ids: ['totals'] });
|
|
127
|
+
bridge.click('#totals', { ctrlKey: true });
|
|
128
|
+
bridge.click('../Knowledge/Alice.md', { button: 1 });
|
|
129
|
+
expect(bridge.scrolled).toEqual([]);
|
|
130
|
+
expect(bridge.posted).toEqual([
|
|
131
|
+
{ type: 'bevel.navigate', href: '#totals', newTab: true },
|
|
132
|
+
{ type: 'bevel.navigate', href: '../Knowledge/Alice.md', newTab: true },
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
122
136
|
it('names the addresses only a script may open, and the app opens exactly those beyond the markup', () => {
|
|
123
137
|
expect(flat).toContain(
|
|
124
138
|
'A call from a script may also open `tel:`, `sms:`, `geo:` and a protocol-relative `//host/path` address in a new tab, though a link written in the markup cannot keep one.',
|
|
@@ -144,19 +158,22 @@ describe('the html-views guide section agrees with the renderer', () => {
|
|
|
144
158
|
const named = new Set([...guide.matchAll(/window\.bevel\??\.(\w+)/g)].map((m) => m[1]!));
|
|
145
159
|
expect([...named].sort()).toEqual(Object.keys(runBridge().bevel).sort());
|
|
146
160
|
expect([...named].sort()).toEqual(Object.keys(runBridge({}, { toolBridge: true }).bevel).sort());
|
|
147
|
-
expect([...named].sort()).toEqual(['navigate', 'openNode', 'requireTools', 'tools']);
|
|
161
|
+
expect([...named].sort()).toEqual(['branch', 'navigate', 'openNode', 'requireTools', 'tools']);
|
|
148
162
|
expect(flat).toContain('A distribution may add data members of its own to `window.bevel`');
|
|
149
163
|
});
|
|
150
164
|
|
|
151
|
-
it('names the
|
|
165
|
+
it('names the five functions of window.bevel.tools the runtime defines, where it is null, and requireTools with its card', async () => {
|
|
152
166
|
const named = [...new Set([...guide.matchAll(/window\.bevel\.tools\.(\w+)\(/g)].map((m) => m[1]!))].sort();
|
|
153
167
|
const onFilePage = runBridge({}, { toolBridge: true });
|
|
154
168
|
expect(named).toEqual(Object.keys(onFilePage.bevel.tools as object).sort());
|
|
155
|
-
expect(named).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo']);
|
|
169
|
+
expect(named).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo', 'uploadFile']);
|
|
156
170
|
|
|
157
171
|
// Null everywhere else, and the guide tells a page to check before every use.
|
|
158
172
|
expect(runBridge().bevel.tools).toBeNull();
|
|
159
|
-
expect(flat).toContain('`window.bevel.tools` is `null` wherever tools are not available: on the embed
|
|
173
|
+
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.');
|
|
174
|
+
// Where it is answered: the hosts htmlToolBridge.ts lists, the skill page beside the file page.
|
|
175
|
+
expect(flat).toContain('On the app\'s file page, and on a skill\'s page in the Library');
|
|
176
|
+
expect(flat).toContain('resolves `true` at once, with nothing shown, on the app\'s file page and on a skill\'s page.');
|
|
160
177
|
expect(flat).toContain('Check it before every use, and render the page without tools when it is `null`');
|
|
161
178
|
|
|
162
179
|
// The consent rule and the two cards, in the app's words.
|
|
@@ -165,6 +182,14 @@ describe('the html-views guide section agrees with the renderer', () => {
|
|
|
165
182
|
expect(flat).toContain('Deny runs nothing and rejects the call with `denied`');
|
|
166
183
|
expect(flat).toContain('"<page name> uses tools that are only available in the platform", with Continue without tools and Open in the platform');
|
|
167
184
|
|
|
185
|
+
// uploadFile: its arguments, the promise, the consent rule and the size limit.
|
|
186
|
+
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');
|
|
187
|
+
expect(flat).toContain("`mode` is `create` (the default), `overwrite` or `update`");
|
|
188
|
+
expect(flat).toContain("The promise resolves with `apply_file_upload`'s answer, `{ destination, count, total, files }`");
|
|
189
|
+
expect(flat).toContain("a file over the deployment's upload limit (the message names it)");
|
|
190
|
+
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.');
|
|
191
|
+
expect(flat).toContain("The upload's token stays in the app; the page never sees it.");
|
|
192
|
+
|
|
168
193
|
// requireTools exists on both, asks the app, and resolves with its answer.
|
|
169
194
|
for (const [bridge, answer] of [[runBridge(), false], [onFilePage, true]] as const) {
|
|
170
195
|
const required = (bridge.bevel.requireTools as () => Promise<boolean>)();
|