@bevel-software/platform-core-frontend 0.32.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
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import type { JsonSchema, Tool as UtcpTool } from '@utcp/sdk';
|
|
3
3
|
import { authFetch } from '../../lib/api';
|
|
4
|
+
import { useConfirm } from '../../shared/components';
|
|
5
|
+
import { fetchToolHints, setToolReadOnly, type ToolHint, type ToolHints } from './tool-hints.api';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A read-only explorer for the tools Bevel exposes to external agents — it
|
|
@@ -20,7 +22,100 @@ import { authFetch } from '../../lib/api';
|
|
|
20
22
|
* agent's loopback and never surfaced to users, so the UI doesn't offer them.)
|
|
21
23
|
* Tool EXECUTION is unchanged: it always requires a key / internal token at the
|
|
22
24
|
* tool endpoints (a JWT is admitted on the manual only, never to invoke a tool).
|
|
25
|
+
*
|
|
26
|
+
* Each platform tool, and each code-mode meta-tool, also shows the read-only
|
|
27
|
+
* hint MCP clients are given for it (`GET /api/tool-hints`). An admin gets a
|
|
28
|
+
* toggle and a reset; everyone else sees the value. The meta-tools are not in
|
|
29
|
+
* the manual — they are the MCP servers' own — so they sit in a section of
|
|
30
|
+
* their own below the endpoints.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** The manual tag the deployment puts on a read-only tool; shown as the hint control, not as a chip. */
|
|
34
|
+
const READ_ONLY_TAG = 'read-only';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* What each code-mode meta-tool does, in a line. The MCP servers build their
|
|
38
|
+
* full descriptions per connection, so the page carries its own summary.
|
|
23
39
|
*/
|
|
40
|
+
const META_TOOL_SUMMARIES: Record<string, string> = {
|
|
41
|
+
list_tools: 'Lists every tool registered on the connection, by the name a chain calls it with.',
|
|
42
|
+
tools_info: 'Answers the TypeScript interface of the tools it is asked about.',
|
|
43
|
+
call_tool_chain: 'Runs JavaScript that calls any of the tools, writing ones included, in one round trip.',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Change one tool's hint: a value, or `null` to put the built-in value back. */
|
|
47
|
+
type SetHint = (hint: ToolHint, readOnly: boolean | null) => void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The read-only hint of one tool: a switch and a reset for an admin, the value
|
|
51
|
+
* alone for anyone else.
|
|
52
|
+
*/
|
|
53
|
+
function ReadOnlyControl({
|
|
54
|
+
hint,
|
|
55
|
+
canEdit,
|
|
56
|
+
busy,
|
|
57
|
+
onSet,
|
|
58
|
+
}: {
|
|
59
|
+
hint: ToolHint;
|
|
60
|
+
canEdit: boolean;
|
|
61
|
+
busy: boolean;
|
|
62
|
+
onSet: SetHint;
|
|
63
|
+
}) {
|
|
64
|
+
// Whether, and from what, an admin changed the value is for admins: anyone
|
|
65
|
+
// else is shown what clients are told and nothing more (nor sent the rest).
|
|
66
|
+
const overridden = canEdit && hint.override != null;
|
|
67
|
+
const builtInLabel = hint.builtIn ? 'read-only' : 'not read-only';
|
|
68
|
+
return (
|
|
69
|
+
<span className="flex items-center gap-2 shrink-0" data-testid={`read-only-${hint.name}`}>
|
|
70
|
+
{canEdit ? (
|
|
71
|
+
<label className="flex items-center gap-1.5 text-[11px] text-ink-muted cursor-pointer">
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
role="switch"
|
|
75
|
+
aria-checked={hint.readOnly}
|
|
76
|
+
aria-label={`Read-only: ${hint.name}`}
|
|
77
|
+
disabled={busy}
|
|
78
|
+
onClick={() => onSet(hint, !hint.readOnly)}
|
|
79
|
+
className={`relative inline-flex h-4 w-7 items-center rounded-full transition-colors disabled:opacity-50 ${
|
|
80
|
+
hint.readOnly ? 'bg-emerald-600' : 'bg-line'
|
|
81
|
+
}`}
|
|
82
|
+
>
|
|
83
|
+
<span
|
|
84
|
+
className={`inline-block h-3 w-3 rounded-full bg-white shadow transition-transform ${
|
|
85
|
+
hint.readOnly ? 'translate-x-3.5' : 'translate-x-0.5'
|
|
86
|
+
}`}
|
|
87
|
+
/>
|
|
88
|
+
</button>
|
|
89
|
+
Read-only
|
|
90
|
+
</label>
|
|
91
|
+
) : (
|
|
92
|
+
<span
|
|
93
|
+
className={`text-[10px] px-1.5 py-0.5 rounded-xs ${
|
|
94
|
+
hint.readOnly ? 'bg-emerald-50 text-emerald-700' : 'bg-sunken text-ink-muted'
|
|
95
|
+
}`}
|
|
96
|
+
>
|
|
97
|
+
{hint.readOnly ? 'Read-only' : 'Not read-only'}
|
|
98
|
+
</span>
|
|
99
|
+
)}
|
|
100
|
+
{overridden && (
|
|
101
|
+
<span className="text-[10px] text-amber-700" title={`Built-in value: ${builtInLabel}`}>
|
|
102
|
+
overridden
|
|
103
|
+
</span>
|
|
104
|
+
)}
|
|
105
|
+
{overridden && (
|
|
106
|
+
<button
|
|
107
|
+
type="button"
|
|
108
|
+
disabled={busy}
|
|
109
|
+
onClick={() => onSet(hint, null)}
|
|
110
|
+
aria-label={`Reset ${hint.name} to its built-in value (${builtInLabel})`}
|
|
111
|
+
className="text-[10px] font-medium px-1.5 py-0.5 rounded-xs border border-line text-ink-muted hover:bg-hover disabled:opacity-50"
|
|
112
|
+
>
|
|
113
|
+
Reset
|
|
114
|
+
</button>
|
|
115
|
+
)}
|
|
116
|
+
</span>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
24
119
|
|
|
25
120
|
/**
|
|
26
121
|
* `${API_URL}/api/agent/tools/x` → `/api/agent/tools/x`; undefined unless this is
|
|
@@ -175,27 +270,30 @@ function SchemaView({ schema, depth = 0 }: { schema: JsonSchema; depth?: number
|
|
|
175
270
|
);
|
|
176
271
|
}
|
|
177
272
|
|
|
178
|
-
function ToolCard({ tool }: { tool: UtcpTool }) {
|
|
273
|
+
function ToolCard({ tool, hintControl }: { tool: UtcpTool; hintControl?: ReactNode }) {
|
|
179
274
|
const [open, setOpen] = useState(false);
|
|
180
275
|
const http = httpPath(tool);
|
|
181
276
|
const input = unwrapBody(tool.inputs);
|
|
182
277
|
return (
|
|
183
278
|
<div className="border border-line rounded-lg bg-white">
|
|
184
|
-
<
|
|
185
|
-
<
|
|
186
|
-
|
|
187
|
-
<span className="flex
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
279
|
+
<div className="flex items-start gap-2 pr-4">
|
|
280
|
+
<button onClick={() => setOpen((v) => !v)} className="flex-1 min-w-0 text-left pl-4 py-3 flex items-start gap-3">
|
|
281
|
+
<span className="text-ink-faint mt-0.5">{open ? '▾' : '▸'}</span>
|
|
282
|
+
<span className="flex-1 min-w-0">
|
|
283
|
+
<span className="flex items-center gap-2 flex-wrap">
|
|
284
|
+
<code className="text-sm font-semibold text-ink">{tool.name}</code>
|
|
285
|
+
<span className="text-[10px] font-mono uppercase tracking-wide text-ink-faint">
|
|
286
|
+
{http ? `${http.method} ${http.path}` : tool.tool_call_template?.call_template_type ?? 'unknown'}
|
|
287
|
+
</span>
|
|
288
|
+
{tool.tags?.filter((t) => t !== READ_ONLY_TAG).map((t) => (
|
|
289
|
+
<span key={t} className="text-[10px] px-1.5 py-0.5 rounded bg-sunken text-ink-muted">{t}</span>
|
|
290
|
+
))}
|
|
191
291
|
</span>
|
|
192
|
-
{tool.
|
|
193
|
-
<span key={t} className="text-[10px] px-1.5 py-0.5 rounded bg-sunken text-ink-muted">{t}</span>
|
|
194
|
-
))}
|
|
292
|
+
<span className="block text-xs text-ink-muted leading-snug mt-1 line-clamp-2">{tool.description}</span>
|
|
195
293
|
</span>
|
|
196
|
-
|
|
197
|
-
</span>
|
|
198
|
-
</
|
|
294
|
+
</button>
|
|
295
|
+
{hintControl && <span className="pt-3">{hintControl}</span>}
|
|
296
|
+
</div>
|
|
199
297
|
{open && (
|
|
200
298
|
<div className="px-4 pb-4 pt-1 space-y-4 border-t border-line">
|
|
201
299
|
<p className="text-xs text-ink-muted leading-snug whitespace-pre-wrap">{tool.description}</p>
|
|
@@ -262,6 +360,71 @@ export function ToolsExplorerPage() {
|
|
|
262
360
|
const [loading, setLoading] = useState(false);
|
|
263
361
|
const [error, setError] = useState<string | null>(null);
|
|
264
362
|
const [filter, setFilter] = useState('');
|
|
363
|
+
const [hints, setHints] = useState<ToolHints | null>(null);
|
|
364
|
+
const [hintError, setHintError] = useState<string | null>(null);
|
|
365
|
+
// Every tool with a save in flight: saves of different tools may overlap,
|
|
366
|
+
// and each keeps its own control busy until its own request settles.
|
|
367
|
+
const [savingHints, setSavingHints] = useState<ReadonlySet<string>>(() => new Set());
|
|
368
|
+
const savingRef = useRef(new Set<string>());
|
|
369
|
+
const confirm = useConfirm();
|
|
370
|
+
|
|
371
|
+
// The read-only hints, with the session: the same for every key pasted
|
|
372
|
+
// below, since they are the deployment's, not a key's. A failure costs the
|
|
373
|
+
// controls, never the catalog.
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
let live = true;
|
|
376
|
+
fetchToolHints()
|
|
377
|
+
.then((h) => live && setHints(h))
|
|
378
|
+
.catch((err: unknown) => live && setHintError(err instanceof Error ? err.message : String(err)));
|
|
379
|
+
return () => {
|
|
380
|
+
live = false;
|
|
381
|
+
};
|
|
382
|
+
}, []);
|
|
383
|
+
|
|
384
|
+
const hintByName = useMemo(() => new Map((hints?.tools ?? []).map((h) => [h.name, h])), [hints]);
|
|
385
|
+
const metaHints = useMemo(() => (hints?.tools ?? []).filter((h) => h.kind === 'meta'), [hints]);
|
|
386
|
+
|
|
387
|
+
const setHint = useCallback<SetHint>(
|
|
388
|
+
(hint, readOnly) => {
|
|
389
|
+
void (async () => {
|
|
390
|
+
// Telling clients a WRITING tool only reads is what lets them run it
|
|
391
|
+
// without asking: said, and confirmed, before it is saved. The other
|
|
392
|
+
// direction only makes clients more careful, and asks nothing.
|
|
393
|
+
if (readOnly === true && !hint.builtIn) {
|
|
394
|
+
const { confirmed } = await confirm({
|
|
395
|
+
title: `Mark ${hint.name} as read-only?`,
|
|
396
|
+
message:
|
|
397
|
+
`${hint.name} can change the knowledge base. Marked read-only, MCP clients such as Claude will stop ` +
|
|
398
|
+
'asking before they run it, so it can change the knowledge base without anyone approving the call.',
|
|
399
|
+
confirmLabel: 'Mark read-only',
|
|
400
|
+
destructive: true,
|
|
401
|
+
});
|
|
402
|
+
if (!confirmed) return;
|
|
403
|
+
}
|
|
404
|
+
// A second click on a tool whose save is still in flight is dropped.
|
|
405
|
+
if (savingRef.current.has(hint.name)) return;
|
|
406
|
+
savingRef.current.add(hint.name);
|
|
407
|
+
setSavingHints(new Set(savingRef.current));
|
|
408
|
+
setHintError(null);
|
|
409
|
+
try {
|
|
410
|
+
const saved = await setToolReadOnly(hint.name, readOnly);
|
|
411
|
+
setHints((h) => (h ? { ...h, tools: h.tools.map((t) => (t.name === saved.name ? saved : t)) } : h));
|
|
412
|
+
} catch (err) {
|
|
413
|
+
setHintError(err instanceof Error ? err.message : String(err));
|
|
414
|
+
} finally {
|
|
415
|
+
savingRef.current.delete(hint.name);
|
|
416
|
+
setSavingHints(new Set(savingRef.current));
|
|
417
|
+
}
|
|
418
|
+
})();
|
|
419
|
+
},
|
|
420
|
+
[confirm],
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const hintControl = (name: string) => {
|
|
424
|
+
const hint = hintByName.get(name);
|
|
425
|
+
if (!hint || !hints) return undefined;
|
|
426
|
+
return <ReadOnlyControl hint={hint} canEdit={hints.canEdit} busy={savingHints.has(name)} onSet={setHint} />;
|
|
427
|
+
};
|
|
265
428
|
|
|
266
429
|
const load = useCallback(async () => {
|
|
267
430
|
if (!bearer.trim()) return;
|
|
@@ -361,8 +524,15 @@ export function ToolsExplorerPage() {
|
|
|
361
524
|
{error && <div className="text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5">{error}</div>}
|
|
362
525
|
</div>
|
|
363
526
|
|
|
527
|
+
{hintError && (
|
|
528
|
+
<div className="text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5">{hintError}</div>
|
|
529
|
+
)}
|
|
530
|
+
|
|
364
531
|
{tools && (
|
|
365
|
-
|
|
532
|
+
<section aria-labelledby="endpoint-tools" className="space-y-2" data-testid="endpoint-section">
|
|
533
|
+
<h2 id="endpoint-tools" className="text-sm font-semibold text-ink">
|
|
534
|
+
Endpoints of this deployment
|
|
535
|
+
</h2>
|
|
366
536
|
<div className="flex items-center justify-between">
|
|
367
537
|
<input
|
|
368
538
|
value={filter}
|
|
@@ -374,10 +544,39 @@ export function ToolsExplorerPage() {
|
|
|
374
544
|
</div>
|
|
375
545
|
<div className="space-y-2">
|
|
376
546
|
{shown.map((t) => (
|
|
377
|
-
<ToolCard key={t.name} tool={t} />
|
|
547
|
+
<ToolCard key={t.name} tool={t} hintControl={hintControl(t.name)} />
|
|
378
548
|
))}
|
|
379
549
|
</div>
|
|
380
|
-
|
|
550
|
+
</section>
|
|
551
|
+
)}
|
|
552
|
+
|
|
553
|
+
{metaHints.length > 0 && (
|
|
554
|
+
<section aria-labelledby="code-mode-tools" className="space-y-2" data-testid="code-mode-section">
|
|
555
|
+
<div className="space-y-1">
|
|
556
|
+
<h2 id="code-mode-tools" className="text-sm font-semibold text-ink">
|
|
557
|
+
Code mode
|
|
558
|
+
</h2>
|
|
559
|
+
<p className="text-xs text-ink-muted">
|
|
560
|
+
These tools are features of the MCP servers (<code>/api/mcp</code> and <code>hexis-mcp</code>), not
|
|
561
|
+
endpoints of this deployment: they list the tools above and run code that calls them. Their read-only
|
|
562
|
+
hint is what MCP clients are told about them.
|
|
563
|
+
</p>
|
|
564
|
+
</div>
|
|
565
|
+
{metaHints.map((hint) => (
|
|
566
|
+
<div
|
|
567
|
+
key={hint.name}
|
|
568
|
+
className="border border-line rounded-lg bg-white px-4 py-3 flex items-start gap-3"
|
|
569
|
+
>
|
|
570
|
+
<span className="flex-1 min-w-0">
|
|
571
|
+
<code className="text-sm font-semibold text-ink">{hint.name}</code>
|
|
572
|
+
<span className="block text-xs text-ink-muted leading-snug mt-1">
|
|
573
|
+
{META_TOOL_SUMMARIES[hint.name] ?? ''}
|
|
574
|
+
</span>
|
|
575
|
+
</span>
|
|
576
|
+
{hintControl(hint.name)}
|
|
577
|
+
</div>
|
|
578
|
+
))}
|
|
579
|
+
</section>
|
|
381
580
|
)}
|
|
382
581
|
</div>
|
|
383
582
|
</div>
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import { ConfirmProvider } from '../../../shared/components';
|
|
4
|
+
import { ToolsExplorerPage } from '../ToolsExplorerPage';
|
|
5
|
+
import type { ToolHint } from '../tool-hints.api';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The read-only hints on the Tools page: what MCP clients are told about each
|
|
9
|
+
* platform tool and each code-mode meta-tool, a toggle and a reset for an
|
|
10
|
+
* admin, the value alone for everyone else, and the meta-tools in a section of
|
|
11
|
+
* their own.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const authFetch = vi.fn<(url: string, init?: RequestInit) => Promise<Response>>();
|
|
15
|
+
vi.mock('../../../lib/api', () => ({ authFetch: (url: string, init?: RequestInit) => authFetch(url, init) }));
|
|
16
|
+
|
|
17
|
+
const httpTool = (name: string, tags: string[]) => ({
|
|
18
|
+
name,
|
|
19
|
+
description: `the ${name} tool`,
|
|
20
|
+
inputs: { type: 'object', properties: {} },
|
|
21
|
+
outputs: { type: 'object', properties: {} },
|
|
22
|
+
tags,
|
|
23
|
+
tool_call_template: { call_template_type: 'http', url: `\${API_URL}/api/agent/tools/${name}`, http_method: 'POST' },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const hint = (name: string, kind: ToolHint['kind'], builtIn: boolean, override: boolean | null = null): ToolHint => ({
|
|
27
|
+
name,
|
|
28
|
+
kind,
|
|
29
|
+
builtIn,
|
|
30
|
+
override,
|
|
31
|
+
readOnly: override ?? builtIn,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/** The deployment: its manual, its hints, and every PUT the page sends. */
|
|
35
|
+
function serve(canEdit: boolean, hints: ToolHint[]) {
|
|
36
|
+
const puts: Array<{ name: string; readOnly: unknown }> = [];
|
|
37
|
+
authFetch.mockImplementation(async (url, init) => {
|
|
38
|
+
if (url === '/api/agent/utcp') {
|
|
39
|
+
return Response.json({ tools: [httpTool('read_file', ['workspace', 'read-only']), httpTool('write_file', ['workspace', 'write'])] });
|
|
40
|
+
}
|
|
41
|
+
if (url === '/api/tool-hints') return Response.json({ canEdit, tools: hints });
|
|
42
|
+
const put = /^\/api\/tool-hints\/(.+)$/.exec(url);
|
|
43
|
+
if (put && init?.method === 'PUT') {
|
|
44
|
+
const name = decodeURIComponent(put[1]!);
|
|
45
|
+
const { readOnly } = JSON.parse(String(init.body)) as { readOnly: boolean | null };
|
|
46
|
+
puts.push({ name, readOnly });
|
|
47
|
+
const current = hints.find((h) => h.name === name)!;
|
|
48
|
+
return Response.json(hint(name, current.kind, current.builtIn!, readOnly));
|
|
49
|
+
}
|
|
50
|
+
return new Response('{}', { status: 404 });
|
|
51
|
+
});
|
|
52
|
+
return { puts };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const HINTS = [
|
|
56
|
+
hint('read_file', 'platform', true),
|
|
57
|
+
hint('write_file', 'platform', false),
|
|
58
|
+
hint('list_tools', 'meta', true),
|
|
59
|
+
hint('tools_info', 'meta', true),
|
|
60
|
+
hint('call_tool_chain', 'meta', false),
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
function renderPage() {
|
|
64
|
+
render(
|
|
65
|
+
<ConfirmProvider>
|
|
66
|
+
<ToolsExplorerPage />
|
|
67
|
+
</ConfirmProvider>,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
authFetch.mockReset();
|
|
73
|
+
vi.restoreAllMocks();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('the Tools page, for an admin', () => {
|
|
77
|
+
it('shows a read-only toggle at its effective value on every platform tool and every meta-tool', async () => {
|
|
78
|
+
serve(true, HINTS);
|
|
79
|
+
renderPage();
|
|
80
|
+
expect(await screen.findByRole('switch', { name: 'Read-only: read_file' })).toHaveAttribute('aria-checked', 'true');
|
|
81
|
+
expect(screen.getByRole('switch', { name: 'Read-only: write_file' })).toHaveAttribute('aria-checked', 'false');
|
|
82
|
+
const codeMode = screen.getByTestId('code-mode-section');
|
|
83
|
+
for (const [name, value] of [['list_tools', 'true'], ['tools_info', 'true'], ['call_tool_chain', 'false']] as const) {
|
|
84
|
+
expect(within(codeMode).getByRole('switch', { name: `Read-only: ${name}` })).toHaveAttribute('aria-checked', value);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('turns a reader off with no question asked', async () => {
|
|
89
|
+
const { puts } = serve(true, HINTS);
|
|
90
|
+
renderPage();
|
|
91
|
+
fireEvent.click(await screen.findByRole('switch', { name: 'Read-only: read_file' }));
|
|
92
|
+
await waitFor(() => expect(puts).toEqual([{ name: 'read_file', readOnly: false }]));
|
|
93
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
94
|
+
await waitFor(() =>
|
|
95
|
+
expect(screen.getByRole('switch', { name: 'Read-only: read_file' })).toHaveAttribute('aria-checked', 'false'),
|
|
96
|
+
);
|
|
97
|
+
expect(within(screen.getByTestId('read-only-read_file')).getByText('overridden')).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('warns before marking a writer read-only; Cancel changes nothing, confirming saves it', async () => {
|
|
101
|
+
const { puts } = serve(true, HINTS);
|
|
102
|
+
renderPage();
|
|
103
|
+
fireEvent.click(await screen.findByRole('switch', { name: 'Read-only: write_file' }));
|
|
104
|
+
let dialog = await screen.findByRole('dialog');
|
|
105
|
+
expect(dialog.textContent).toMatch(/stop\s+asking before they run it/);
|
|
106
|
+
expect(dialog.textContent).toContain('change the knowledge base');
|
|
107
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
|
108
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
109
|
+
expect(puts).toEqual([]);
|
|
110
|
+
expect(screen.getByRole('switch', { name: 'Read-only: write_file' })).toHaveAttribute('aria-checked', 'false');
|
|
111
|
+
|
|
112
|
+
fireEvent.click(screen.getByRole('switch', { name: 'Read-only: write_file' }));
|
|
113
|
+
dialog = await screen.findByRole('dialog');
|
|
114
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Mark read-only' }));
|
|
115
|
+
await waitFor(() => expect(puts).toEqual([{ name: 'write_file', readOnly: true }]));
|
|
116
|
+
await waitFor(() =>
|
|
117
|
+
expect(screen.getByRole('switch', { name: 'Read-only: write_file' })).toHaveAttribute('aria-checked', 'true'),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('warns the same way for `call_tool_chain`', async () => {
|
|
122
|
+
const { puts } = serve(true, HINTS);
|
|
123
|
+
renderPage();
|
|
124
|
+
fireEvent.click(await screen.findByRole('switch', { name: 'Read-only: call_tool_chain' }));
|
|
125
|
+
const dialog = await screen.findByRole('dialog');
|
|
126
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Mark read-only' }));
|
|
127
|
+
await waitFor(() => expect(puts).toEqual([{ name: 'call_tool_chain', readOnly: true }]));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('resets an overridden tool by removing the override', async () => {
|
|
131
|
+
const { puts } = serve(true, [hint('read_file', 'platform', true, false), ...HINTS.slice(1)]);
|
|
132
|
+
renderPage();
|
|
133
|
+
fireEvent.click(await screen.findByRole('button', { name: /Reset read_file/ }));
|
|
134
|
+
await waitFor(() => expect(puts).toEqual([{ name: 'read_file', readOnly: null }]));
|
|
135
|
+
await waitFor(() =>
|
|
136
|
+
expect(screen.getByRole('switch', { name: 'Read-only: read_file' })).toHaveAttribute('aria-checked', 'true'),
|
|
137
|
+
);
|
|
138
|
+
expect(screen.queryByRole('button', { name: /Reset read_file/ })).toBeNull();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('keeps each tool busy until its own save settles, when two saves overlap', async () => {
|
|
142
|
+
serve(true, HINTS);
|
|
143
|
+
// Hold every PUT until the test releases it, by tool name.
|
|
144
|
+
const served = authFetch.getMockImplementation()!;
|
|
145
|
+
const release = new Map<string, () => void>();
|
|
146
|
+
authFetch.mockImplementation(async (url, init) => {
|
|
147
|
+
if (init?.method === 'PUT') {
|
|
148
|
+
const name = decodeURIComponent(url.split('/').pop()!);
|
|
149
|
+
await new Promise<void>((resolve) => release.set(name, resolve));
|
|
150
|
+
}
|
|
151
|
+
return served(url, init);
|
|
152
|
+
});
|
|
153
|
+
renderPage();
|
|
154
|
+
const readFile = await screen.findByRole('switch', { name: 'Read-only: read_file' });
|
|
155
|
+
const listTools = screen.getByRole('switch', { name: 'Read-only: list_tools' });
|
|
156
|
+
fireEvent.click(readFile);
|
|
157
|
+
await waitFor(() => expect(readFile).toBeDisabled());
|
|
158
|
+
fireEvent.click(listTools);
|
|
159
|
+
await waitFor(() => expect(listTools).toBeDisabled());
|
|
160
|
+
expect(readFile).toBeDisabled();
|
|
161
|
+
|
|
162
|
+
await waitFor(() => expect(release.has('list_tools') && release.has('read_file')).toBe(true));
|
|
163
|
+
release.get('list_tools')!();
|
|
164
|
+
await waitFor(() => expect(listTools).not.toBeDisabled());
|
|
165
|
+
expect(readFile).toBeDisabled();
|
|
166
|
+
release.get('read_file')!();
|
|
167
|
+
await waitFor(() => expect(readFile).not.toBeDisabled());
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('the Tools page, for everyone else', () => {
|
|
172
|
+
it('shows each effective value and no toggle or reset', async () => {
|
|
173
|
+
// What the route sends a non-admin: the effective value, without the built-in one or the override.
|
|
174
|
+
const effectiveOnly = [hint('read_file', 'platform', true), hint('write_file', 'platform', false, true), ...HINTS.slice(2)].map(
|
|
175
|
+
({ name, kind, readOnly }) => ({ name, kind, readOnly }),
|
|
176
|
+
);
|
|
177
|
+
serve(false, effectiveOnly);
|
|
178
|
+
renderPage();
|
|
179
|
+
expect(await within(await screen.findByTestId('read-only-read_file')).findByText('Read-only')).toBeInTheDocument();
|
|
180
|
+
expect(within(screen.getByTestId('read-only-write_file')).getByText('Read-only')).toBeInTheDocument();
|
|
181
|
+
expect(within(screen.getByTestId('read-only-call_tool_chain')).getByText('Not read-only')).toBeInTheDocument();
|
|
182
|
+
expect(screen.queryAllByRole('switch')).toEqual([]);
|
|
183
|
+
expect(screen.queryByRole('button', { name: /Reset/ })).toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('does not say a value was overridden, even when a response carries the override', async () => {
|
|
187
|
+
serve(false, [hint('read_file', 'platform', true), hint('write_file', 'platform', false, true), ...HINTS.slice(2)]);
|
|
188
|
+
renderPage();
|
|
189
|
+
expect(await within(await screen.findByTestId('read-only-write_file')).findByText('Read-only')).toBeInTheDocument();
|
|
190
|
+
expect(screen.queryByText('overridden')).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('the two sections', () => {
|
|
195
|
+
it('lists the endpoints and, apart from them, the code-mode meta-tools as MCP features', async () => {
|
|
196
|
+
serve(false, HINTS);
|
|
197
|
+
renderPage();
|
|
198
|
+
const endpoints = await screen.findByTestId('endpoint-section');
|
|
199
|
+
const codeMode = await screen.findByTestId('code-mode-section');
|
|
200
|
+
expect(within(endpoints).getByRole('heading', { name: 'Endpoints of this deployment' })).toBeInTheDocument();
|
|
201
|
+
expect(within(endpoints).getByText('read_file')).toBeInTheDocument();
|
|
202
|
+
expect(within(endpoints).queryByText('call_tool_chain')).toBeNull();
|
|
203
|
+
|
|
204
|
+
expect(within(codeMode).getByRole('heading', { name: 'Code mode' })).toBeInTheDocument();
|
|
205
|
+
expect(codeMode.textContent).toContain('features of the MCP servers');
|
|
206
|
+
expect(codeMode.textContent).toContain('not endpoints of this deployment');
|
|
207
|
+
for (const name of ['list_tools', 'tools_info', 'call_tool_chain']) {
|
|
208
|
+
expect(within(codeMode).getByText(name)).toBeInTheDocument();
|
|
209
|
+
}
|
|
210
|
+
expect(within(codeMode).queryByText('read_file')).toBeNull();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('does not show the read-only tag as a chip: the hint control says it', async () => {
|
|
214
|
+
serve(false, HINTS);
|
|
215
|
+
renderPage();
|
|
216
|
+
const endpoints = await screen.findByTestId('endpoint-section');
|
|
217
|
+
await within(endpoints).findByText('read_file');
|
|
218
|
+
expect(within(endpoints).queryByText('read-only')).toBeNull();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { authFetch } from '../../lib/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What MCP clients are told about one tool's effect — `GET /api/tool-hints`.
|
|
5
|
+
* Mirrors `ToolReadOnlyEntry` in the backend's `read-only-hints.contract.ts`;
|
|
6
|
+
* `builtIn` and `override` are sent to an admin only.
|
|
7
|
+
*/
|
|
8
|
+
export interface ToolHint {
|
|
9
|
+
name: string;
|
|
10
|
+
/** `platform`: an endpoint of this deployment. `meta`: a feature of the MCP servers. */
|
|
11
|
+
kind: 'platform' | 'meta';
|
|
12
|
+
/** What the tool's own declaration makes it. Admins only. */
|
|
13
|
+
builtIn?: boolean;
|
|
14
|
+
/** The admin's override, or null when there is none. Admins only. */
|
|
15
|
+
override?: boolean | null;
|
|
16
|
+
/** What clients are told. */
|
|
17
|
+
readOnly: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ToolHints {
|
|
21
|
+
/** Whether the signed-in person may change a hint (an admin). */
|
|
22
|
+
canEdit: boolean;
|
|
23
|
+
tools: ToolHint[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function fetchToolHints(): Promise<ToolHints> {
|
|
27
|
+
const res = await authFetch('/api/tool-hints');
|
|
28
|
+
if (!res.ok) throw new Error(`Could not load the read-only hints (HTTP ${res.status}).`);
|
|
29
|
+
return res.json();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Set a tool's override, or remove it with `null`; answers the tool as it now stands. */
|
|
33
|
+
export async function setToolReadOnly(name: string, readOnly: boolean | null): Promise<ToolHint> {
|
|
34
|
+
const res = await authFetch(`/api/tool-hints/${encodeURIComponent(name)}`, {
|
|
35
|
+
method: 'PUT',
|
|
36
|
+
headers: { 'Content-Type': 'application/json' },
|
|
37
|
+
body: JSON.stringify({ readOnly }),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
const body = (await res.json().catch(() => null)) as { error?: string } | null;
|
|
41
|
+
throw new Error(body?.error ?? `Could not save the override (HTTP ${res.status}).`);
|
|
42
|
+
}
|
|
43
|
+
return res.json();
|
|
44
|
+
}
|
|
@@ -6,3 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { useFileLock, type AcquireOutcome } from './hooks/useFileLock';
|
|
8
8
|
export { LockApiError, SELF_HOLD_MESSAGE } from './services/lock.api';
|
|
9
|
+
// The server's pushed events, for a component that shows one in place.
|
|
10
|
+
export { useEventBusSubscription } from './hooks/useEventBusSubscription';
|
|
11
|
+
export { canonicalizeWorkspaceId, useEventBus } from './state/event-bus.context';
|
|
12
|
+
// The one provider of that bus — the app shell mounts it once per tab, and a
|
|
13
|
+
// test that drives a component with server events mounts the same one over a
|
|
14
|
+
// stand-in EventSource.
|
|
15
|
+
export { EventBusProvider } from './state/EventBusProvider';
|