@bevel-software/platform-core-frontend 0.1.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/LICENSE +202 -0
- package/package.json +70 -0
- package/src/core/CoreAppShell.tsx +444 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
- package/src/core/events.ts +29 -0
- package/src/core/registry.ts +336 -0
- package/src/css-side-effect-imports.d.ts +7 -0
- package/src/html-extensions.ts +12 -0
- package/src/index.css +49 -0
- package/src/index.ts +23 -0
- package/src/lib/api.ts +57 -0
- package/src/lib/utils.ts +138 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
- package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
- package/src/modules/access/api.ts +205 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
- package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
- package/src/modules/access/hooks/useFileAccess.ts +151 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
- package/src/modules/admin/services/admin.api.ts +92 -0
- package/src/modules/admin/services/roles.api.ts +136 -0
- package/src/modules/admin/state/admin.context.tsx +223 -0
- package/src/modules/auth/components/LoginScreen.tsx +135 -0
- package/src/modules/auth/hooks/useAuthState.ts +59 -0
- package/src/modules/auth/services/auth.api.ts +24 -0
- package/src/modules/auth/services/microsoft-oauth.ts +57 -0
- package/src/modules/auth/state/auth.context.ts +18 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
- package/src/modules/git/__tests__/git.api.test.ts +113 -0
- package/src/modules/git/__tests__/pr.api.test.ts +44 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
- package/src/modules/git/components/BranchSwitcher.tsx +527 -0
- package/src/modules/git/components/DiffView.tsx +30 -0
- package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
- package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
- package/src/modules/git/components/PullNeededBanner.tsx +204 -0
- package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
- package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
- package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
- package/src/modules/git/hooks/useGitState.ts +335 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
- package/src/modules/git/services/error-messages.ts +257 -0
- package/src/modules/git/services/git.api.ts +163 -0
- package/src/modules/git/services/pr-prompts.ts +159 -0
- package/src/modules/git/services/pr.api.ts +39 -0
- package/src/modules/git/state/auto-update.context.ts +21 -0
- package/src/modules/git/state/git.context.ts +82 -0
- package/src/modules/layout/components/AppLayout.tsx +40 -0
- package/src/modules/layout/components/DemoBanner.tsx +57 -0
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
- package/src/modules/layout/components/SlideOverlay.tsx +224 -0
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
- package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
- package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
- package/src/modules/layout/state/layout.context.ts +46 -0
- package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
- package/src/modules/library/__tests__/diff.test.ts +62 -0
- package/src/modules/library/__tests__/loadout.test.tsx +72 -0
- package/src/modules/library/__tests__/status.test.ts +117 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
- package/src/modules/library/components/CompareView.tsx +357 -0
- package/src/modules/library/components/DetailDialog.tsx +566 -0
- package/src/modules/library/components/GearIcon.tsx +12 -0
- package/src/modules/library/components/LibraryCard.tsx +132 -0
- package/src/modules/library/components/LibraryPage.tsx +254 -0
- package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
- package/src/modules/library/components/StatusGem.tsx +21 -0
- package/src/modules/library/components/SuggestChange.tsx +171 -0
- package/src/modules/library/components/particles.ts +50 -0
- package/src/modules/library/hooks/useLibraryData.ts +119 -0
- package/src/modules/library/hooks/useSkillDetail.ts +74 -0
- package/src/modules/library/library.css +320 -0
- package/src/modules/library/services/library.api.ts +164 -0
- package/src/modules/library/state/loadout.tsx +129 -0
- package/src/modules/library/state/toast.tsx +42 -0
- package/src/modules/library/utils/diff.ts +102 -0
- package/src/modules/library/utils/status.ts +116 -0
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
- package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
- package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
- package/src/modules/pr/components/PrCancelButton.tsx +99 -0
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
- package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
- package/src/modules/pr/components/PrCommentThread.tsx +168 -0
- package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
- package/src/modules/pr/components/PrDiffPane.tsx +425 -0
- package/src/modules/pr/components/PrFileRow.tsx +164 -0
- package/src/modules/pr/components/PrFilesList.tsx +53 -0
- package/src/modules/pr/components/PrHeader.tsx +45 -0
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
- package/src/modules/pr/components/PrMergeButton.tsx +268 -0
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
- package/src/modules/pr/components/PrViewer.tsx +364 -0
- package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
- package/src/modules/pr/services/pr-approvals.api.ts +31 -0
- package/src/modules/pr/services/pr-cancel.api.ts +19 -0
- package/src/modules/pr/services/pr-comments.api.ts +45 -0
- package/src/modules/pr/services/pr-detail.api.ts +17 -0
- package/src/modules/pr/services/pr-merge.api.ts +53 -0
- package/src/modules/pr/services/pr-open.api.ts +30 -0
- package/src/modules/pr/state/pr-viewer.context.ts +34 -0
- package/src/modules/pr/utils/bucketize-comments.ts +55 -0
- package/src/modules/pr/utils/parsePatch.ts +57 -0
- package/src/modules/review/__tests__/review.api.test.ts +121 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
- package/src/modules/review/components/DiffViewer.tsx +78 -0
- package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
- package/src/modules/review/components/ReviewFileRow.tsx +114 -0
- package/src/modules/review/components/ReviewPanel.tsx +260 -0
- package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
- package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
- package/src/modules/review/hooks/useReviewState.ts +256 -0
- package/src/modules/review/services/review.api.ts +72 -0
- package/src/modules/review/state/ReviewProvider.tsx +28 -0
- package/src/modules/review/state/review.context.ts +29 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
- package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
- package/src/modules/secrets-vault/services/connect.api.ts +113 -0
- package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
- package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
- package/src/modules/toolbar/components/Toolbar.tsx +123 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
- package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
- package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
- package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
- package/src/modules/workflow/hooks/useFileLock.ts +430 -0
- package/src/modules/workflow/services/lock.api.ts +139 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
- package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
- package/src/modules/workflow/state/event-bus.context.ts +75 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
- package/src/modules/workspace/components/EditorTabs.tsx +384 -0
- package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
- package/src/modules/workspace/components/FileRoute.tsx +392 -0
- package/src/modules/workspace/components/FileViewer.tsx +906 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
- package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
- package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
- package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
- package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
- package/src/modules/workspace/components/renderers/index.ts +39 -0
- package/src/modules/workspace/components/renderers/types.ts +27 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
- package/src/modules/workspace/routing/kb-routes.ts +266 -0
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
- package/src/modules/workspace/services/workspace.api.ts +185 -0
- package/src/modules/workspace/state/workspace.context.ts +235 -0
- package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
- package/src/modules/workspace/utils/diff.ts +53 -0
- package/src/modules/workspace/utils/fileTree.ts +179 -0
- package/src/modules/workspace/utils/frontmatter.ts +80 -0
- package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
- package/src/modules/workspace/utils/tab-persistence.ts +23 -0
- package/src/shared/components/Dialog.tsx +198 -0
- package/src/shared/components/PageShell.tsx +51 -0
- package/src/shared/components/useModalLayer.ts +35 -0
- package/src/shared/markdown/Markdown.tsx +62 -0
- package/src/test-setup.ts +59 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { JsonSchema, Tool as UtcpTool } from '@utcp/sdk';
|
|
3
|
+
import { authFetch } from '../../lib/api';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A read-only explorer for the tools Bevel exposes to external agents — it
|
|
7
|
+
* fetches the UTCP manual and renders every tool: its description, transport
|
|
8
|
+
* (HTTP path / streaming / whatever the call template says), input + output
|
|
9
|
+
* schemas, and a one-line "how to call" note. No in-browser runner: tools span
|
|
10
|
+
* transports (HTTP, MCP, streaming, …) and we don't reimplement a UTCP client
|
|
11
|
+
* here — invoke them via a real UTCP client or the MCP server.
|
|
12
|
+
*
|
|
13
|
+
* The page lives behind the app login (see `AuthGate` in `App.tsx`). By default
|
|
14
|
+
* it loads the catalog with the user's SESSION: `GET /api/agent/utcp` accepts a
|
|
15
|
+
* browser JWT for this read-only manual (a spec, no secrets), so a logged-in user
|
|
16
|
+
* browses with zero pasting and nothing write-scoped or bearer-portable ever
|
|
17
|
+
* reaches the browser. The optional key box below hits the SAME endpoint with a
|
|
18
|
+
* pasted `<tenant>_…` external API key instead — useful for verifying exactly what a
|
|
19
|
+
* specific key can see. (Internal `<tenant>-int_…` tokens are server-minted for the
|
|
20
|
+
* agent's loopback and never surfaced to users, so the UI doesn't offer them.)
|
|
21
|
+
* Tool EXECUTION is unchanged: it always requires a key / internal token at the
|
|
22
|
+
* tool endpoints (a JWT is admitted on the manual only, never to invoke a tool).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `${API_URL}/api/agent/tools/x` → `/api/agent/tools/x`; undefined unless this is
|
|
27
|
+
* an http tool pointing at a path on this server. The base `CallTemplate` from
|
|
28
|
+
* the SDK only guarantees `call_template_type`; the http variant's `url` /
|
|
29
|
+
* `http_method` ride its open index signature, so we read them under the
|
|
30
|
+
* `'http'` guard without coupling the page to `@utcp/http`. Non-http transports
|
|
31
|
+
* (MCP, streaming, …) fall through to undefined and render the generic note.
|
|
32
|
+
*/
|
|
33
|
+
function httpPath(t: UtcpTool): { method: string; path: string } | undefined {
|
|
34
|
+
const tpl = t.tool_call_template;
|
|
35
|
+
if (tpl?.call_template_type !== 'http') return undefined;
|
|
36
|
+
const url = typeof tpl.url === 'string' ? tpl.url : undefined;
|
|
37
|
+
if (!url) return undefined;
|
|
38
|
+
const path = url.replace(/^\$\{API_URL\}/, '');
|
|
39
|
+
if (!path.startsWith('/')) return undefined;
|
|
40
|
+
const method = typeof tpl.http_method === 'string' ? tpl.http_method : 'POST';
|
|
41
|
+
return { method: method.toUpperCase(), path };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A schema's item shape; the SDK types `items` as `JsonSchema | JsonSchema[]`, so collapse to one. */
|
|
45
|
+
function itemSchema(s: JsonSchema): JsonSchema | undefined {
|
|
46
|
+
return Array.isArray(s.items) ? s.items[0] : s.items;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Unwrap the `{ body: <flat> }` envelope the manual adds — the real request body is the flat schema. */
|
|
50
|
+
function unwrapBody(inputs: JsonSchema): JsonSchema {
|
|
51
|
+
return inputs?.properties?.body ?? inputs;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function typeLabel(s: JsonSchema): string {
|
|
55
|
+
if (s.enum) return s.enum.map((e) => JSON.stringify(e)).join(' | ');
|
|
56
|
+
const t = Array.isArray(s.type) ? s.type.join(' | ') : s.type ?? 'any';
|
|
57
|
+
const item = itemSchema(s);
|
|
58
|
+
if (t === 'array' && item) return `${typeLabel(item)}[]`;
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A runnable placeholder value for a field, so the example body is copy-and-edit-ready. */
|
|
63
|
+
function sampleValue(s: JsonSchema): unknown {
|
|
64
|
+
if (s.enum && s.enum.length) return s.enum[0];
|
|
65
|
+
const t = Array.isArray(s.type) ? s.type[0] : s.type;
|
|
66
|
+
switch (t) {
|
|
67
|
+
case 'integer':
|
|
68
|
+
case 'number':
|
|
69
|
+
return 0;
|
|
70
|
+
case 'boolean':
|
|
71
|
+
return false;
|
|
72
|
+
case 'array': {
|
|
73
|
+
const item = itemSchema(s);
|
|
74
|
+
return item ? [sampleValue(item)] : [];
|
|
75
|
+
}
|
|
76
|
+
case 'object':
|
|
77
|
+
return sampleBody(s);
|
|
78
|
+
default:
|
|
79
|
+
return `<${typeLabel(s)}>`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Build a skeleton request body from an (already-unwrapped) input schema. */
|
|
84
|
+
function sampleBody(schema: JsonSchema): Record<string, unknown> {
|
|
85
|
+
const out: Record<string, unknown> = {};
|
|
86
|
+
for (const [name, sub] of Object.entries(schema.properties ?? {})) out[name] = sampleValue(sub);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A ready-to-run curl for an HTTP tool. The manual carries `${API_URL}` /
|
|
92
|
+
* `${CONNECTION_KEY}` placeholders; we resolve the URL to THIS server's origin
|
|
93
|
+
* and leave the key as a `$Bevel_KEY` shell var. The request body is the flat
|
|
94
|
+
* input (the def's `body_field: 'body'` rides the `body` arg's value straight
|
|
95
|
+
* into the JSON body), so the example is the unwrapped input schema, not the
|
|
96
|
+
* `{ body: … }` envelope.
|
|
97
|
+
*/
|
|
98
|
+
function curlSnippet(http: { method: string; path: string }, input: JsonSchema): string {
|
|
99
|
+
const url = `${window.location.origin}${http.path}`;
|
|
100
|
+
const body = JSON.stringify(sampleBody(input), null, 2);
|
|
101
|
+
return [
|
|
102
|
+
`curl -X ${http.method} '${url}' \\`,
|
|
103
|
+
` -H 'Authorization: Bearer '"$Bevel_KEY" \\`,
|
|
104
|
+
` -H 'Content-Type: application/json' \\`,
|
|
105
|
+
` -d '${body}'`,
|
|
106
|
+
].join('\n');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function CopyButton({ text }: { text: string }) {
|
|
110
|
+
const [status, setStatus] = useState<'idle' | 'copied' | 'failed'>('idle');
|
|
111
|
+
const resetTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
112
|
+
|
|
113
|
+
// Reset to 'idle' after a delay, cancelling any pending reset first so rapid
|
|
114
|
+
// clicks don't queue overlapping timers.
|
|
115
|
+
const scheduleReset = () => {
|
|
116
|
+
if (resetTimer.current) clearTimeout(resetTimer.current);
|
|
117
|
+
resetTimer.current = setTimeout(() => setStatus('idle'), 1500);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Clear a pending timer on unmount so it never fires after teardown.
|
|
121
|
+
useEffect(() => () => {
|
|
122
|
+
if (resetTimer.current) clearTimeout(resetTimer.current);
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<button
|
|
127
|
+
onClick={() => {
|
|
128
|
+
navigator.clipboard
|
|
129
|
+
.writeText(text)
|
|
130
|
+
.then(() => {
|
|
131
|
+
setStatus('copied');
|
|
132
|
+
scheduleReset();
|
|
133
|
+
})
|
|
134
|
+
.catch(() => {
|
|
135
|
+
// Clipboard can reject (insecure context / denied permission) — surface
|
|
136
|
+
// it on the button instead of silently swallowing the rejection.
|
|
137
|
+
setStatus('failed');
|
|
138
|
+
scheduleReset();
|
|
139
|
+
});
|
|
140
|
+
}}
|
|
141
|
+
className="text-[10px] font-medium px-2 py-0.5 rounded border border-slate-200 text-slate-500 hover:bg-slate-50"
|
|
142
|
+
>
|
|
143
|
+
{status === 'copied' ? 'Copied' : status === 'failed' ? 'Copy failed' : 'Copy'}
|
|
144
|
+
</button>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function SchemaView({ schema, depth = 0 }: { schema: JsonSchema; depth?: number }) {
|
|
149
|
+
const props = schema.properties;
|
|
150
|
+
if (!props || Object.keys(props).length === 0) {
|
|
151
|
+
return <div className="text-xs text-slate-400 italic">no fields</div>;
|
|
152
|
+
}
|
|
153
|
+
const required = new Set(schema.required ?? []);
|
|
154
|
+
return (
|
|
155
|
+
<div className={depth > 0 ? 'pl-3 border-l border-slate-200 space-y-1.5' : 'space-y-1.5'}>
|
|
156
|
+
{Object.entries(props).map(([name, sub]) => (
|
|
157
|
+
<div key={name} className="text-xs">
|
|
158
|
+
<div className="flex items-baseline gap-2 flex-wrap">
|
|
159
|
+
<code className="font-medium text-slate-800">{name}</code>
|
|
160
|
+
<span className="text-slate-400 font-mono">{typeLabel(sub)}</span>
|
|
161
|
+
{required.has(name) ? (
|
|
162
|
+
<span className="text-[10px] uppercase tracking-wide text-amber-600">required</span>
|
|
163
|
+
) : (
|
|
164
|
+
<span className="text-[10px] uppercase tracking-wide text-slate-300">optional</span>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
{sub.description && <div className="text-slate-500 leading-snug mt-0.5">{sub.description}</div>}
|
|
168
|
+
{sub.type === 'object' && sub.properties && <SchemaView schema={sub} depth={depth + 1} />}
|
|
169
|
+
{sub.type === 'array' && itemSchema(sub)?.properties && (
|
|
170
|
+
<SchemaView schema={itemSchema(sub)!} depth={depth + 1} />
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
))}
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function ToolCard({ tool }: { tool: UtcpTool }) {
|
|
179
|
+
const [open, setOpen] = useState(false);
|
|
180
|
+
const http = httpPath(tool);
|
|
181
|
+
const input = unwrapBody(tool.inputs);
|
|
182
|
+
return (
|
|
183
|
+
<div className="border border-slate-200 rounded-lg bg-white">
|
|
184
|
+
<button onClick={() => setOpen((v) => !v)} className="w-full text-left px-4 py-3 flex items-start gap-3">
|
|
185
|
+
<span className="text-slate-300 mt-0.5">{open ? '▾' : '▸'}</span>
|
|
186
|
+
<span className="flex-1 min-w-0">
|
|
187
|
+
<span className="flex items-center gap-2 flex-wrap">
|
|
188
|
+
<code className="text-sm font-semibold text-slate-800">{tool.name}</code>
|
|
189
|
+
<span className="text-[10px] font-mono uppercase tracking-wide text-slate-400">
|
|
190
|
+
{http ? `${http.method} ${http.path}` : tool.tool_call_template?.call_template_type ?? 'unknown'}
|
|
191
|
+
</span>
|
|
192
|
+
{tool.tags?.map((t) => (
|
|
193
|
+
<span key={t} className="text-[10px] px-1.5 py-0.5 rounded bg-slate-100 text-slate-500">{t}</span>
|
|
194
|
+
))}
|
|
195
|
+
</span>
|
|
196
|
+
<span className="block text-xs text-slate-500 leading-snug mt-1 line-clamp-2">{tool.description}</span>
|
|
197
|
+
</span>
|
|
198
|
+
</button>
|
|
199
|
+
{open && (
|
|
200
|
+
<div className="px-4 pb-4 pt-1 space-y-4 border-t border-slate-100">
|
|
201
|
+
<p className="text-xs text-slate-600 leading-snug whitespace-pre-wrap">{tool.description}</p>
|
|
202
|
+
<section>
|
|
203
|
+
<h4 className="text-xs font-semibold text-slate-700 mb-1.5">Input</h4>
|
|
204
|
+
<SchemaView schema={input} />
|
|
205
|
+
</section>
|
|
206
|
+
{tool.outputs && (
|
|
207
|
+
<section>
|
|
208
|
+
<h4 className="text-xs font-semibold text-slate-700 mb-1.5">Output</h4>
|
|
209
|
+
<SchemaView schema={tool.outputs} />
|
|
210
|
+
</section>
|
|
211
|
+
)}
|
|
212
|
+
<section>
|
|
213
|
+
<h4 className="text-xs font-semibold text-slate-700 mb-1.5">How to call</h4>
|
|
214
|
+
{http ? (
|
|
215
|
+
<div className="space-y-2">
|
|
216
|
+
<p className="text-xs text-slate-500 leading-snug">
|
|
217
|
+
<code className="text-emerald-700 font-semibold">{http.method}</code>{' '}
|
|
218
|
+
<code className="text-slate-600">{http.path}</code> with{' '}
|
|
219
|
+
<code className="text-slate-600">Authorization: Bearer <key></code> and the input above as the JSON
|
|
220
|
+
body. Or call it through any UTCP client / the MCP server at <code>/api/mcp</code>.
|
|
221
|
+
</p>
|
|
222
|
+
<div className="relative">
|
|
223
|
+
<div className="absolute top-1.5 right-1.5">
|
|
224
|
+
<CopyButton text={curlSnippet(http, input)} />
|
|
225
|
+
</div>
|
|
226
|
+
<pre className="text-[11px] font-mono text-slate-700 bg-slate-50 border border-slate-200 rounded p-2.5 overflow-auto whitespace-pre">
|
|
227
|
+
{curlSnippet(http, input)}
|
|
228
|
+
</pre>
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
) : (
|
|
232
|
+
<p className="text-xs text-slate-500 leading-snug">
|
|
233
|
+
Transport <code>{tool.tool_call_template?.call_template_type ?? 'unknown'}</code> — invoke it with a UTCP
|
|
234
|
+
client (or via the MCP server at <code>/api/mcp</code>), not a plain HTTP request.
|
|
235
|
+
</p>
|
|
236
|
+
)}
|
|
237
|
+
</section>
|
|
238
|
+
<section>
|
|
239
|
+
<div className="flex items-center justify-between mb-1.5">
|
|
240
|
+
<h4 className="text-xs font-semibold text-slate-700">Raw UTCP schema</h4>
|
|
241
|
+
<CopyButton text={JSON.stringify(tool, null, 2)} />
|
|
242
|
+
</div>
|
|
243
|
+
<p className="text-[11px] text-slate-400 leading-snug mb-1.5">
|
|
244
|
+
The full tool definition served by <code>/api/agent/utcp</code> — inputs, outputs and the{' '}
|
|
245
|
+
<code>tool_call_template</code> (endpoint, method, headers, body wrapping). Resolve{' '}
|
|
246
|
+
<code>${'{API_URL}'}</code> to this server's origin and <code>${'{CONNECTION_KEY}'}</code> to your{' '}
|
|
247
|
+
<code>{'<tenant>_…'}</code> key to call it from a script.
|
|
248
|
+
</p>
|
|
249
|
+
<pre className="text-[11px] font-mono text-slate-700 bg-slate-50 border border-slate-200 rounded p-2.5 overflow-auto whitespace-pre max-h-80">
|
|
250
|
+
{JSON.stringify(tool, null, 2)}
|
|
251
|
+
</pre>
|
|
252
|
+
</section>
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function ToolsExplorerPage() {
|
|
260
|
+
const [bearer, setBearer] = useState('');
|
|
261
|
+
const [tools, setTools] = useState<UtcpTool[] | null>(null);
|
|
262
|
+
const [loading, setLoading] = useState(false);
|
|
263
|
+
const [error, setError] = useState<string | null>(null);
|
|
264
|
+
const [filter, setFilter] = useState('');
|
|
265
|
+
|
|
266
|
+
const load = useCallback(async () => {
|
|
267
|
+
if (!bearer.trim()) return;
|
|
268
|
+
setLoading(true);
|
|
269
|
+
setError(null);
|
|
270
|
+
try {
|
|
271
|
+
const r = await fetch('/api/agent/utcp', { headers: { Authorization: `Bearer ${bearer.trim()}` } });
|
|
272
|
+
if (!r.ok) {
|
|
273
|
+
setError(`Could not load the catalog (HTTP ${r.status}). Check your external API key.`);
|
|
274
|
+
setTools(null);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const manual = (await r.json()) as { tools?: UtcpTool[] };
|
|
278
|
+
setTools(manual.tools ?? []);
|
|
279
|
+
} catch (err) {
|
|
280
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
281
|
+
setTools(null);
|
|
282
|
+
} finally {
|
|
283
|
+
setLoading(false);
|
|
284
|
+
}
|
|
285
|
+
}, [bearer]);
|
|
286
|
+
|
|
287
|
+
// Default load: the read-only manual gated by the user's own session (the same
|
|
288
|
+
// `/api/agent/utcp` endpoint also accepts a browser JWT) — no key to paste, no
|
|
289
|
+
// write-scoped/portable credential in the browser.
|
|
290
|
+
const loadViaSession = useCallback(async () => {
|
|
291
|
+
setLoading(true);
|
|
292
|
+
setError(null);
|
|
293
|
+
try {
|
|
294
|
+
const r = await authFetch('/api/agent/utcp');
|
|
295
|
+
if (!r.ok) {
|
|
296
|
+
setError(`Could not load the catalog (HTTP ${r.status}).`);
|
|
297
|
+
setTools(null);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const manual = (await r.json()) as { tools?: UtcpTool[] };
|
|
301
|
+
setTools(manual.tools ?? []);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
304
|
+
setTools(null);
|
|
305
|
+
} finally {
|
|
306
|
+
setLoading(false);
|
|
307
|
+
}
|
|
308
|
+
}, []);
|
|
309
|
+
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
void loadViaSession();
|
|
312
|
+
}, [loadViaSession]);
|
|
313
|
+
|
|
314
|
+
const shown = useMemo(() => {
|
|
315
|
+
if (!tools) return [];
|
|
316
|
+
const q = filter.trim().toLowerCase();
|
|
317
|
+
return q
|
|
318
|
+
? tools.filter((t) => t.name.toLowerCase().includes(q) || t.description.toLowerCase().includes(q) || (t.tags ?? []).some((x) => x.toLowerCase().includes(q)))
|
|
319
|
+
: tools;
|
|
320
|
+
}, [tools, filter]);
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<div className="h-full overflow-auto bg-slate-50">
|
|
324
|
+
<div className="max-w-3xl mx-auto px-6 py-8 space-y-6">
|
|
325
|
+
<header className="space-y-1">
|
|
326
|
+
<h1 className="text-lg font-semibold text-slate-800">Bevel tools</h1>
|
|
327
|
+
<p className="text-sm text-slate-500">
|
|
328
|
+
Every tool Bevel exposes to external agents — the same surface available over MCP at{' '}
|
|
329
|
+
<code className="text-slate-600">/api/mcp</code>. Loaded with your session below; or browse as a specific
|
|
330
|
+
external API key to see exactly what it can reach.
|
|
331
|
+
</p>
|
|
332
|
+
</header>
|
|
333
|
+
|
|
334
|
+
<div className="bg-white border border-slate-200 rounded-lg p-3 space-y-2">
|
|
335
|
+
<label className="block text-xs font-medium text-slate-700">
|
|
336
|
+
Browse as a specific external API key (<code>{'<tenant>_…'}</code>) — optional
|
|
337
|
+
</label>
|
|
338
|
+
<div className="flex gap-2">
|
|
339
|
+
<input
|
|
340
|
+
type="password"
|
|
341
|
+
value={bearer}
|
|
342
|
+
onChange={(e) => setBearer(e.target.value)}
|
|
343
|
+
onKeyDown={(e) => e.key === 'Enter' && !loading && void load()}
|
|
344
|
+
placeholder="<tenant>_…"
|
|
345
|
+
spellCheck={false}
|
|
346
|
+
className="flex-1 text-xs font-mono border border-slate-200 rounded px-2 py-1.5 text-slate-800"
|
|
347
|
+
/>
|
|
348
|
+
<button
|
|
349
|
+
onClick={() => void load()}
|
|
350
|
+
disabled={loading || !bearer.trim()}
|
|
351
|
+
className="text-xs font-medium px-3 py-1.5 rounded bg-slate-800 text-white disabled:opacity-40"
|
|
352
|
+
>
|
|
353
|
+
{loading ? 'Loading…' : 'Load'}
|
|
354
|
+
</button>
|
|
355
|
+
</div>
|
|
356
|
+
{error && <div className="text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5">{error}</div>}
|
|
357
|
+
</div>
|
|
358
|
+
|
|
359
|
+
{tools && (
|
|
360
|
+
<>
|
|
361
|
+
<div className="flex items-center justify-between">
|
|
362
|
+
<input
|
|
363
|
+
value={filter}
|
|
364
|
+
onChange={(e) => setFilter(e.target.value)}
|
|
365
|
+
placeholder="Filter tools…"
|
|
366
|
+
className="text-xs border border-slate-200 rounded px-2 py-1.5 text-slate-800 w-56"
|
|
367
|
+
/>
|
|
368
|
+
<span className="text-xs text-slate-400">{shown.length} of {tools.length} tools</span>
|
|
369
|
+
</div>
|
|
370
|
+
<div className="space-y-2">
|
|
371
|
+
{shown.map((t) => (
|
|
372
|
+
<ToolCard key={t.name} tool={t} />
|
|
373
|
+
))}
|
|
374
|
+
</div>
|
|
375
|
+
</>
|
|
376
|
+
)}
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import type { WorkflowEvent } from '@bevel-software/platform-shared';
|
|
3
|
+
import { useEventBus, type EventHandler } from '../state/event-bus.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Subscribe to a single event kind for the lifetime of the calling
|
|
7
|
+
* component. The handler is re-bound when `kind` or `handler` identity
|
|
8
|
+
* changes — wrap your handler in `useCallback` (or move it outside the
|
|
9
|
+
* component) if you want a stable subscription.
|
|
10
|
+
*
|
|
11
|
+
* No-op when used outside the EventBusProvider (e.g. in unit tests that
|
|
12
|
+
* don't mount it). That lets components subscribe unconditionally
|
|
13
|
+
* without each test having to scaffold the bus.
|
|
14
|
+
*/
|
|
15
|
+
export function useEventBusSubscription<K extends WorkflowEvent['kind']>(
|
|
16
|
+
kind: K,
|
|
17
|
+
handler: EventHandler<K>,
|
|
18
|
+
): void {
|
|
19
|
+
const bus = useEventBus();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!bus) return;
|
|
22
|
+
return bus.subscribe(kind, handler);
|
|
23
|
+
}, [bus, kind, handler]);
|
|
24
|
+
}
|