@bevel-software/platform-core-frontend 0.33.0 → 0.35.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/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 +27 -8
- package/src/modules/access/components/ManageAccessDialog.tsx +7 -7
- package/src/modules/access/index.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/index.ts +1 -1
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +88 -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 +16 -2
- package/src/modules/audit/components/AuditLogPage.tsx +11 -0
- 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 +1 -1
- package/src/modules/auth/services/account.api.ts +18 -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/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/library/__tests__/SkillPage.test.tsx +229 -24
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +51 -5
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +57 -9
- package/src/modules/library/components/skill-page/SkillPage.tsx +65 -25
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +22 -14
- package/src/modules/review/components/MarkdownDiffViewer.tsx +23 -1
- package/src/modules/review/components/ReviewPanel.tsx +8 -2
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +122 -2
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +45 -4
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +127 -12
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/workspace/components/FileViewer.tsx +1 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +58 -8
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +40 -7
- 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/__tests__/HtmlRenderer.links.test.tsx +185 -0
- 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 +37 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +59 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +15 -1
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +48 -15
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +19 -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/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/index.ts +21 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +221 -53
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +32 -48
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/treeConfirm.ts +24 -28
|
@@ -26,6 +26,10 @@ import { navigateExternal } from '../../utils/navigate-external';
|
|
|
26
26
|
* - `oauth-auto` NEVER gets a client-secret affordance. Its client was
|
|
27
27
|
* auto-registered by PKCE dynamic registration and has no secret; saving one
|
|
28
28
|
* would clobber the discovered provider row and break sign-in for everyone.
|
|
29
|
+
* - Every OTHER sign-in offers its owner the client secret in every state of
|
|
30
|
+
* the row: "Replace client secret" while one is stored, "Set client secret"
|
|
31
|
+
* while none is. The secret belongs to the tool, not to the caller's own
|
|
32
|
+
* sign-in, so whether the owner is signed in has no say in it.
|
|
29
33
|
* - Whose problem is it? A user-scope gap is the caller's to fix and always
|
|
30
34
|
* shows an action. An admin-scope gap is the OWNER's, so a non-writer sees a
|
|
31
35
|
* chip that explains the state and no button they can't act on.
|
|
@@ -147,13 +151,6 @@ export function ToolVarRow({
|
|
|
147
151
|
Signed in
|
|
148
152
|
</Badge>,
|
|
149
153
|
);
|
|
150
|
-
if (mayEditClientSecret) {
|
|
151
|
-
meta.push(
|
|
152
|
-
<Button key="secret" size="sm" variant="quiet" onClick={() => open('client-secret')}>
|
|
153
|
-
Replace client secret
|
|
154
|
-
</Button>,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
154
|
} else if (variable.authorized) {
|
|
158
155
|
description = 'Each person sets their own';
|
|
159
156
|
meta.push(
|
|
@@ -172,13 +169,7 @@ export function ToolVarRow({
|
|
|
172
169
|
// The owner hasn't declared the provider (or hasn't set its secret), so
|
|
173
170
|
// there is nothing for anyone to sign in to yet.
|
|
174
171
|
description = "The tool owner hasn't finished the sign-in setup yet.";
|
|
175
|
-
if (mayEditClientSecret) {
|
|
176
|
-
meta.push(
|
|
177
|
-
<Button key="secret" size="sm" onClick={() => open('client-secret')}>
|
|
178
|
-
Set client secret
|
|
179
|
-
</Button>,
|
|
180
|
-
);
|
|
181
|
-
} else {
|
|
172
|
+
if (!mayEditClientSecret) {
|
|
182
173
|
meta.push(
|
|
183
174
|
<Badge key="chip" tone="neutral">
|
|
184
175
|
Not set
|
|
@@ -186,6 +177,23 @@ export function ToolVarRow({
|
|
|
186
177
|
);
|
|
187
178
|
}
|
|
188
179
|
}
|
|
180
|
+
// The client secret is the owner's, not the sign-in's: whatever state the
|
|
181
|
+
// caller's own sign-in is in, an owner who may edit it can replace a stored
|
|
182
|
+
// secret (or set a missing one) from this row. Tying it to the caller being
|
|
183
|
+
// signed in left an owner replacing a connector with no way to do it here.
|
|
184
|
+
if (mayEditClientSecret) {
|
|
185
|
+
meta.push(
|
|
186
|
+
variable.adminConfigured ? (
|
|
187
|
+
<Button key="secret" size="sm" variant="quiet" onClick={() => open('client-secret')}>
|
|
188
|
+
Replace client secret
|
|
189
|
+
</Button>
|
|
190
|
+
) : (
|
|
191
|
+
<Button key="secret" size="sm" onClick={() => open('client-secret')}>
|
|
192
|
+
Set client secret
|
|
193
|
+
</Button>
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
189
197
|
} else if (variable.scope === 'admin') {
|
|
190
198
|
if (variable.adminConfigured) {
|
|
191
199
|
description = 'One value for the whole team. Already handled';
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
useKbMarkdownComponents,
|
|
10
10
|
type KbImageResolver,
|
|
11
11
|
} from '../../workspace/components/renderers/kbMarkdownPipeline';
|
|
12
|
+
import type { KbLinkTarget } from '../../workspace';
|
|
12
13
|
|
|
13
14
|
const MAX_RENDERED_LINES = 5000;
|
|
14
15
|
|
|
@@ -29,6 +30,9 @@ interface MarkdownDiffViewerProps {
|
|
|
29
30
|
onOpenFile?: (href: string) => void;
|
|
30
31
|
/** Same contract as {@link onOpenFile}, for bare node-id links. */
|
|
31
32
|
onOpenNodeId?: (id: string) => void;
|
|
33
|
+
/** Where each kind of link leads, for its anchor — `KbAppLink` in the pipeline. */
|
|
34
|
+
fileLinkTarget?: (href: string) => KbLinkTarget | null;
|
|
35
|
+
nodeIdLinkTarget?: (id: string) => KbLinkTarget | null;
|
|
32
36
|
/**
|
|
33
37
|
* Resolves a workspace image in the diff to the URL that serves it from the
|
|
34
38
|
* CHECKED-OUT tree. It applies to unchanged and added fragments only; a
|
|
@@ -76,7 +80,15 @@ interface MarkdownDiffViewerProps {
|
|
|
76
80
|
* routes, which sit outside those providers entirely. A `useNavigate()` in
|
|
77
81
|
* here would be a runtime crash in all three.
|
|
78
82
|
*/
|
|
79
|
-
export function MarkdownDiffViewer({
|
|
83
|
+
export function MarkdownDiffViewer({
|
|
84
|
+
payload,
|
|
85
|
+
onOpenFile,
|
|
86
|
+
onOpenNodeId,
|
|
87
|
+
fileLinkTarget,
|
|
88
|
+
nodeIdLinkTarget,
|
|
89
|
+
resolveImage,
|
|
90
|
+
scroll = true,
|
|
91
|
+
}: MarkdownDiffViewerProps) {
|
|
80
92
|
const data = useMemo(() => {
|
|
81
93
|
const baseline = payload.baseline ?? '';
|
|
82
94
|
const current = payload.current ?? '';
|
|
@@ -133,6 +145,8 @@ export function MarkdownDiffViewer({ payload, onOpenFile, onOpenNodeId, resolveI
|
|
|
133
145
|
blocks={data.bodyBlocks}
|
|
134
146
|
onOpenFile={onOpenFile}
|
|
135
147
|
onOpenNodeId={onOpenNodeId}
|
|
148
|
+
fileLinkTarget={fileLinkTarget}
|
|
149
|
+
nodeIdLinkTarget={nodeIdLinkTarget}
|
|
136
150
|
resolveImage={resolveImage}
|
|
137
151
|
/>
|
|
138
152
|
</div>
|
|
@@ -294,11 +308,15 @@ function DiffPreview({
|
|
|
294
308
|
blocks,
|
|
295
309
|
onOpenFile,
|
|
296
310
|
onOpenNodeId,
|
|
311
|
+
fileLinkTarget,
|
|
312
|
+
nodeIdLinkTarget,
|
|
297
313
|
resolveImage,
|
|
298
314
|
}: {
|
|
299
315
|
blocks: DisplayBlock[];
|
|
300
316
|
onOpenFile?: (href: string) => void;
|
|
301
317
|
onOpenNodeId?: (id: string) => void;
|
|
318
|
+
fileLinkTarget?: (href: string) => KbLinkTarget | null;
|
|
319
|
+
nodeIdLinkTarget?: (id: string) => KbLinkTarget | null;
|
|
302
320
|
resolveImage?: KbImageResolver;
|
|
303
321
|
}) {
|
|
304
322
|
// Images, per fragment. The caller's resolver serves the CURRENT tree, which
|
|
@@ -334,12 +352,16 @@ function DiffPreview({
|
|
|
334
352
|
const components = useKbMarkdownComponents({
|
|
335
353
|
onOpenFile,
|
|
336
354
|
onOpenNodeId,
|
|
355
|
+
fileLinkTarget,
|
|
356
|
+
nodeIdLinkTarget,
|
|
337
357
|
onMermaidError: 'source',
|
|
338
358
|
resolveImage: liveImages,
|
|
339
359
|
});
|
|
340
360
|
const baselineComponents = useKbMarkdownComponents({
|
|
341
361
|
onOpenFile,
|
|
342
362
|
onOpenNodeId,
|
|
363
|
+
fileLinkTarget,
|
|
364
|
+
nodeIdLinkTarget,
|
|
343
365
|
onMermaidError: 'source',
|
|
344
366
|
resolveImage: baselineImages,
|
|
345
367
|
});
|
|
@@ -109,14 +109,14 @@ function kindLabel(kind: PendingChange['kind']): string {
|
|
|
109
109
|
export function ReviewPanel({ onClose }: { onClose?: () => void }) {
|
|
110
110
|
const review = useReview();
|
|
111
111
|
const { refreshFileTree, kbDirName, workspaceId } = useWorkspace();
|
|
112
|
-
const { openFile, openLink } = useFileNav();
|
|
112
|
+
const { openFile, openLink, linkTarget } = useFileNav();
|
|
113
113
|
// Links inside a rendered diff. Both resolvers navigate relative to
|
|
114
114
|
// `git.status.branch`, which is CORRECT here and only here: this panel
|
|
115
115
|
// reviews the agent's uncommitted changes on the branch you are already
|
|
116
116
|
// standing on, so "the diff's branch" and "the current branch" are the same
|
|
117
117
|
// thing. (The change-request dialog is not in that position, which is why it
|
|
118
118
|
// passes no resolvers — see the comment at its MarkdownDiffViewer call.)
|
|
119
|
-
const { openNodeId } = useNodeIdNav();
|
|
119
|
+
const { openNodeId, nodeIdTarget } = useNodeIdNav();
|
|
120
120
|
const diffPath = review.fileDiff?.path ?? '';
|
|
121
121
|
// Resolved against the diffed file by `openLink`: decoded, an absolute URL
|
|
122
122
|
// keeping its own branch. The same grammar MarkdownRenderer uses.
|
|
@@ -124,6 +124,10 @@ export function ReviewPanel({ onClose }: { onClose?: () => void }) {
|
|
|
124
124
|
(href: string) => openLink(href, diffPath),
|
|
125
125
|
[openLink, diffPath],
|
|
126
126
|
);
|
|
127
|
+
const diffLinkTarget = useCallback(
|
|
128
|
+
(href: string) => linkTarget(href, diffPath),
|
|
129
|
+
[linkTarget, diffPath],
|
|
130
|
+
);
|
|
127
131
|
// Images inside a rendered diff, bound to the CHECKED-OUT workspace for the
|
|
128
132
|
// reason above: the working tree IS the diff's new state, so an image the
|
|
129
133
|
// agent added is on disk and can be shown. The viewer applies this to the
|
|
@@ -373,6 +377,8 @@ export function ReviewPanel({ onClose }: { onClose?: () => void }) {
|
|
|
373
377
|
payload={fileDiff}
|
|
374
378
|
onOpenFile={openDiffLink}
|
|
375
379
|
onOpenNodeId={openNodeId}
|
|
380
|
+
fileLinkTarget={diffLinkTarget}
|
|
381
|
+
nodeIdLinkTarget={nodeIdTarget}
|
|
376
382
|
resolveImage={resolveDiffImage}
|
|
377
383
|
scroll={false}
|
|
378
384
|
/>
|
|
@@ -103,6 +103,37 @@ describe('MarkdownDiffViewer', () => {
|
|
|
103
103
|
await userEvent.click(screen.getByText('the process'));
|
|
104
104
|
expect(onOpenNodeId).toHaveBeenCalledWith('order-intake');
|
|
105
105
|
});
|
|
106
|
+
|
|
107
|
+
it("carry the target the caller resolves: the new tab's address, target=_blank, rel=noopener", () => {
|
|
108
|
+
const nodeIdLinkTarget = vi.fn(() => ({ href: '/workspace/main/order-intake', newTab: true }));
|
|
109
|
+
render(
|
|
110
|
+
<MarkdownDiffViewer payload={withIdLink} onOpenNodeId={vi.fn()} nodeIdLinkTarget={nodeIdLinkTarget} />,
|
|
111
|
+
);
|
|
112
|
+
const link = screen.getByRole('link', { name: 'the process' });
|
|
113
|
+
expect(nodeIdLinkTarget).toHaveBeenCalledWith('order-intake');
|
|
114
|
+
expect(link).toHaveAttribute('href', '/workspace/main/order-intake');
|
|
115
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
116
|
+
expect(link).toHaveAttribute('rel', 'noopener');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("gives a file link the target the caller resolves, and follows a click through the caller", async () => {
|
|
121
|
+
const onOpenFile = vi.fn();
|
|
122
|
+
const fileLinkTarget = vi.fn(() => ({ href: '/workspace/main/Knowledge/Plan.md', newTab: true }));
|
|
123
|
+
render(
|
|
124
|
+
<MarkdownDiffViewer
|
|
125
|
+
payload={payload('Nothing\n', 'See [the plan](Plan.md)\n')}
|
|
126
|
+
onOpenFile={onOpenFile}
|
|
127
|
+
fileLinkTarget={fileLinkTarget}
|
|
128
|
+
/>,
|
|
129
|
+
);
|
|
130
|
+
const link = screen.getByRole('link', { name: 'the plan' });
|
|
131
|
+
expect(fileLinkTarget).toHaveBeenCalledWith('Plan.md');
|
|
132
|
+
expect(link).toHaveAttribute('href', '/workspace/main/Knowledge/Plan.md');
|
|
133
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
134
|
+
expect(link).toHaveAttribute('rel', 'noopener');
|
|
135
|
+
await userEvent.click(link);
|
|
136
|
+
expect(onOpenFile).toHaveBeenCalledWith('Plan.md');
|
|
106
137
|
});
|
|
107
138
|
|
|
108
139
|
it('escapes spaces in link destinations so KB links resolve', () => {
|
|
@@ -8,6 +8,8 @@ import { setUserVar, setAdminVar, deleteUserVar, setOAuthClientSecret } from '..
|
|
|
8
8
|
import { SavedKeyProbeResult } from '../probe/SavedKeyProbeResult';
|
|
9
9
|
import { useSavedKeyProbe, type SavedKeyProbe } from '../probe/useSavedKeyProbe';
|
|
10
10
|
import { announceToolCredentialsChanged } from '../../../core/events';
|
|
11
|
+
import { useConnectAsChoice } from '../../agents';
|
|
12
|
+
import { ConnectAsChoice } from '../../agents/components/ConnectAsChoice';
|
|
11
13
|
import {
|
|
12
14
|
getConnectPending,
|
|
13
15
|
startToolOAuth,
|
|
@@ -31,6 +33,20 @@ import {
|
|
|
31
33
|
* alive across that round-trip. Cleared on Finish or when the state goes stale.
|
|
32
34
|
*/
|
|
33
35
|
const MCP_OAUTH_STATE_KEY = 'mcp-oauth-state';
|
|
36
|
+
/** The "Connect as" choice made on the way, kept beside the state for the same round-trip. */
|
|
37
|
+
const MCP_OAUTH_AGENT_KEY = 'mcp-oauth-agent';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The choice to start from: the one made earlier in THIS authorization (the
|
|
41
|
+
* page came back from a tool sign-in, its query stripped), else Everything —
|
|
42
|
+
* an authorization arriving in the address that is not the remembered one is
|
|
43
|
+
* a new connection, and starts at Everything.
|
|
44
|
+
*/
|
|
45
|
+
function rememberedConnectAs(): string | null {
|
|
46
|
+
const fromUrl = new URLSearchParams(window.location.search).get('oauth');
|
|
47
|
+
if (fromUrl && fromUrl !== sessionStorage.getItem(MCP_OAUTH_STATE_KEY)) return null;
|
|
48
|
+
return sessionStorage.getItem(MCP_OAUTH_AGENT_KEY);
|
|
49
|
+
}
|
|
34
50
|
|
|
35
51
|
/**
|
|
36
52
|
* "Connect your tools" — the page a person lands on from the needs-authorization
|
|
@@ -99,6 +115,12 @@ export function ConnectToolsPage() {
|
|
|
99
115
|
// Agent-connect mode: the signed authorization state + who is asking.
|
|
100
116
|
const [agentState, setAgentState] = useState<string | null>(null);
|
|
101
117
|
const [agentName, setAgentName] = useState<string | null>(null);
|
|
118
|
+
// "Connect as": the agents on offer and the choice — Everything unless the
|
|
119
|
+
// person picks one — kept across a tool sign-in's round-trip
|
|
120
|
+
// (`rememberedConnectAs`). Finish waits until the CURRENT request's agents
|
|
121
|
+
// have answered (before that it would approve Everything unseen), and for
|
|
122
|
+
// Everything to be confirmed when they could not be loaded.
|
|
123
|
+
const connectAs = useConnectAsChoice({ initial: rememberedConnectAs, expect: agentState });
|
|
102
124
|
const [finishing, setFinishing] = useState(false);
|
|
103
125
|
// Entries the user took OUT. Everything the server sent is in by default —
|
|
104
126
|
// it used to be the other way round, and an unconfigured tool the reader had
|
|
@@ -118,6 +140,14 @@ export function ConnectToolsPage() {
|
|
|
118
140
|
*/
|
|
119
141
|
const loadSeq = useRef(0);
|
|
120
142
|
|
|
143
|
+
// The agent the list is for: the "Connect as" choice, in agent-connect mode
|
|
144
|
+
// only. A connection made as an agent loads only the connectors its file
|
|
145
|
+
// lists, so the page asks for the sign-ins and keys of those and no other —
|
|
146
|
+
// asking for hubspot's sign-in on the way to an agent that never loads
|
|
147
|
+
// hubspot sends the person off to sign in for nothing. Everything (null)
|
|
148
|
+
// lists what it always listed.
|
|
149
|
+
const chosenAgent = agentState != null ? connectAs.value : null;
|
|
150
|
+
|
|
121
151
|
/**
|
|
122
152
|
* @param quiet keep the list on screen while it refetches.
|
|
123
153
|
*
|
|
@@ -132,7 +162,7 @@ export function ConnectToolsPage() {
|
|
|
132
162
|
if (!quiet) setLoading(true);
|
|
133
163
|
setRefreshing(true);
|
|
134
164
|
try {
|
|
135
|
-
const pending = await getConnectPending();
|
|
165
|
+
const pending = await getConnectPending(chosenAgent);
|
|
136
166
|
if (loadSeq.current !== mine) return;
|
|
137
167
|
setTools(pending.tools);
|
|
138
168
|
setOauth(pending.oauth);
|
|
@@ -148,17 +178,27 @@ export function ConnectToolsPage() {
|
|
|
148
178
|
setRefreshing(false);
|
|
149
179
|
}
|
|
150
180
|
}
|
|
151
|
-
}, []);
|
|
152
|
-
|
|
181
|
+
}, [chosenAgent]);
|
|
182
|
+
|
|
183
|
+
// The first load, loud; and again, quietly, whenever the choice changes —
|
|
184
|
+
// `refresh` is remade for the chosen agent, and the list on screen is the
|
|
185
|
+
// other agent's until the new one answers, which is the one case a loud
|
|
186
|
+
// reload would have nothing to protect (no row holds a probe's verdict
|
|
187
|
+
// for a list that is about to be replaced) and still nothing to gain.
|
|
188
|
+
const loadedOnce = useRef(false);
|
|
153
189
|
useEffect(() => {
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
const quiet = loadedOnce.current;
|
|
191
|
+
loadedOnce.current = true;
|
|
192
|
+
void refresh(quiet);
|
|
156
193
|
}, [refresh]);
|
|
157
194
|
|
|
158
195
|
// Pick up (and persist) the external-agent authorization state.
|
|
159
196
|
useEffect(() => {
|
|
160
197
|
const fromUrl = new URLSearchParams(window.location.search).get('oauth');
|
|
161
198
|
if (fromUrl) {
|
|
199
|
+
// A NEW authorization starts at Everything (see `rememberedConnectAs`):
|
|
200
|
+
// a choice remembered from another one is not this connection's.
|
|
201
|
+
if (sessionStorage.getItem(MCP_OAUTH_STATE_KEY) !== fromUrl) sessionStorage.removeItem(MCP_OAUTH_AGENT_KEY);
|
|
162
202
|
sessionStorage.setItem(MCP_OAUTH_STATE_KEY, fromUrl);
|
|
163
203
|
// eslint-disable-next-line react-hooks/set-state-in-effect -- the query is read once, on arrival
|
|
164
204
|
setAgentState(fromUrl);
|
|
@@ -169,23 +209,27 @@ export function ConnectToolsPage() {
|
|
|
169
209
|
|
|
170
210
|
// Resolve who is asking; a stale/expired state silently drops the mode (the
|
|
171
211
|
// agent restarts the flow if the user takes too long).
|
|
212
|
+
const settleConnectAs = connectAs.settle;
|
|
172
213
|
useEffect(() => {
|
|
173
214
|
if (!agentState) return;
|
|
174
215
|
let cancelled = false;
|
|
175
216
|
getMcpOAuthRequest(agentState)
|
|
176
217
|
.then((r) => {
|
|
177
|
-
if (
|
|
218
|
+
if (cancelled) return;
|
|
219
|
+
setAgentName(r.clientName);
|
|
220
|
+
settleConnectAs({ agents: r.agents ?? [], failed: r.agentsUnavailable === true }, agentState);
|
|
178
221
|
})
|
|
179
222
|
.catch(() => {
|
|
180
223
|
if (cancelled) return;
|
|
181
224
|
sessionStorage.removeItem(MCP_OAUTH_STATE_KEY);
|
|
225
|
+
sessionStorage.removeItem(MCP_OAUTH_AGENT_KEY);
|
|
182
226
|
setAgentState(null);
|
|
183
227
|
setAgentName(null);
|
|
184
228
|
});
|
|
185
229
|
return () => {
|
|
186
230
|
cancelled = true;
|
|
187
231
|
};
|
|
188
|
-
}, [agentState]);
|
|
232
|
+
}, [agentState, settleConnectAs]);
|
|
189
233
|
|
|
190
234
|
// A sign-in came back to this page (the callback lands on whichever page
|
|
191
235
|
// started it): the fragment it carried is stripped, now that it has been
|
|
@@ -220,11 +264,12 @@ export function ConnectToolsPage() {
|
|
|
220
264
|
};
|
|
221
265
|
|
|
222
266
|
const onFinish = async () => {
|
|
223
|
-
if (!agentState) return;
|
|
267
|
+
if (!agentState || !connectAs.mayConnect) return;
|
|
224
268
|
setFinishing(true);
|
|
225
269
|
try {
|
|
226
|
-
const redirectTo = await completeMcpOAuth(agentState);
|
|
270
|
+
const redirectTo = await completeMcpOAuth(agentState, connectAs.value);
|
|
227
271
|
sessionStorage.removeItem(MCP_OAUTH_STATE_KEY);
|
|
272
|
+
sessionStorage.removeItem(MCP_OAUTH_AGENT_KEY);
|
|
228
273
|
window.location.href = redirectTo;
|
|
229
274
|
} catch (err) {
|
|
230
275
|
setError(err instanceof Error ? err.message : String(err));
|
|
@@ -348,12 +393,26 @@ export function ConnectToolsPage() {
|
|
|
348
393
|
variant="primary"
|
|
349
394
|
size="sm"
|
|
350
395
|
className="shrink-0"
|
|
351
|
-
disabled={finishing}
|
|
396
|
+
disabled={finishing || !connectAs.mayConnect}
|
|
352
397
|
onClick={() => void onFinish()}
|
|
353
398
|
>
|
|
354
399
|
{finishing ? 'Finishing…' : 'Finish & return to your agent'}
|
|
355
400
|
</Button>
|
|
356
401
|
</div>
|
|
402
|
+
<div className="mt-4">
|
|
403
|
+
<ConnectAsChoice
|
|
404
|
+
agents={connectAs.agents}
|
|
405
|
+
value={connectAs.value}
|
|
406
|
+
disabled={finishing}
|
|
407
|
+
hint="What this connection loads. An agent narrows it to the tools, skills and plugins its configuration lists, and only those you may read."
|
|
408
|
+
onChange={(path) => {
|
|
409
|
+
connectAs.setValue(path);
|
|
410
|
+
if (path) sessionStorage.setItem(MCP_OAUTH_AGENT_KEY, path);
|
|
411
|
+
else sessionStorage.removeItem(MCP_OAUTH_AGENT_KEY);
|
|
412
|
+
}}
|
|
413
|
+
unavailable={connectAs.unavailable}
|
|
414
|
+
/>
|
|
415
|
+
</div>
|
|
357
416
|
</Surface>
|
|
358
417
|
)}
|
|
359
418
|
|
|
@@ -378,11 +437,13 @@ export function ConnectToolsPage() {
|
|
|
378
437
|
so before they wonder why a row has no field. */}
|
|
379
438
|
{!nothingToDo && (
|
|
380
439
|
<p className="mb-5 text-ui text-ink-muted">
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
again
|
|
440
|
+
{chosenAgent
|
|
441
|
+
? 'These are the tools the chosen agent loads that need a sign-in or a key before they will work in your agent. '
|
|
442
|
+
: 'These tools need a sign-in or a key before they will work in your agent. '}
|
|
443
|
+
Authorize each connection and enter any keys below, then head back to your agent and
|
|
444
|
+
run the tool again. Anything greyed out is not yours to do — it is waiting on the
|
|
445
|
+
tool's owner, or you took it out yourself. Your values are stored securely and
|
|
446
|
+
never shown again after saving.
|
|
386
447
|
</p>
|
|
387
448
|
)}
|
|
388
449
|
|
|
@@ -394,7 +455,9 @@ export function ConnectToolsPage() {
|
|
|
394
455
|
// every shared tool works without a personal credential, so the
|
|
395
456
|
// user's only job is to finish.
|
|
396
457
|
<Banner role="status" tone="ok">
|
|
397
|
-
|
|
458
|
+
{chosenAgent
|
|
459
|
+
? 'You’re all set: none of the tools the chosen agent loads need a personal sign-in or key. Click '
|
|
460
|
+
: 'You’re all set: none of your tools need a personal sign-in or key. Click '}
|
|
398
461
|
“Finish & return to your agent” above to complete the connection.
|
|
399
462
|
</Banner>
|
|
400
463
|
) : (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
|
|
2
|
+
import { act, render, screen, fireEvent, waitFor, within } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter } from 'react-router-dom';
|
|
4
4
|
import type { ConnectPending } from '../../services/connect.api';
|
|
5
5
|
import { ConnectToolsPage } from '../ConnectToolsPage';
|
|
@@ -522,7 +522,127 @@ describe('ConnectToolsPage: inside Skills & Tools', () => {
|
|
|
522
522
|
} finally {
|
|
523
523
|
Object.defineProperty(window, 'location', { configurable: true, value: realLocation });
|
|
524
524
|
}
|
|
525
|
-
|
|
525
|
+
// Nothing chosen: the connection is made as Everything, exactly as before.
|
|
526
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', null);
|
|
526
527
|
expect(connectMock.getMcpOAuthRequest).toHaveBeenCalledWith('signed-state');
|
|
527
528
|
});
|
|
529
|
+
|
|
530
|
+
describe('"Connect as"', () => {
|
|
531
|
+
const OPS = { path: 'Agents/ops.agent', name: 'ops', description: 'Watches the dashboards.' };
|
|
532
|
+
|
|
533
|
+
/** Click Finish with the address held, as above; resolves once the browser would have left. */
|
|
534
|
+
async function finish() {
|
|
535
|
+
const realLocation = window.location;
|
|
536
|
+
Object.defineProperty(window, 'location', { configurable: true, value: { ...realLocation, href: realLocation.href } });
|
|
537
|
+
try {
|
|
538
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Finish & return to your agent' }));
|
|
539
|
+
await waitFor(() => expect(window.location.href).toBe('/agent-callback?code=abc'));
|
|
540
|
+
} finally {
|
|
541
|
+
Object.defineProperty(window, 'location', { configurable: true, value: realLocation });
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
beforeEach(() => {
|
|
546
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect?oauth=signed-state');
|
|
547
|
+
connectMock.getMcpOAuthRequest.mockResolvedValue({ clientName: 'Claude', scope: null, resource: null, agents: [OPS] });
|
|
548
|
+
connectMock.completeMcpOAuth.mockResolvedValue('/agent-callback?code=abc');
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it('offers Everything, selected, before the person approves, and each agent by name with its description', async () => {
|
|
552
|
+
renderPage();
|
|
553
|
+
const group = await screen.findByRole('group', { name: 'Connect as' });
|
|
554
|
+
expect(within(group).getByRole('radio', { name: /Everything/ })).toBeChecked();
|
|
555
|
+
expect(await within(group).findByRole('radio', { name: /ops.*Watches the dashboards\./ })).not.toBeChecked();
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it('asks nothing when there is no agent to connect as: the connection is Everything’s, as it always was', async () => {
|
|
559
|
+
connectMock.getMcpOAuthRequest.mockResolvedValue({ clientName: 'Claude', scope: null, resource: null, agents: [] });
|
|
560
|
+
renderPage();
|
|
561
|
+
// Finish waits for the agents to answer, so once it went through, the choice had its chance to appear.
|
|
562
|
+
await finish();
|
|
563
|
+
expect(screen.queryByRole('group', { name: 'Connect as' })).toBeNull();
|
|
564
|
+
expect(screen.queryByText(/Connect as/)).toBeNull();
|
|
565
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', null);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('says when the agents could not be loaded, and approves Everything only once that is confirmed', async () => {
|
|
569
|
+
connectMock.getMcpOAuthRequest.mockResolvedValue({
|
|
570
|
+
clientName: 'Claude',
|
|
571
|
+
scope: null,
|
|
572
|
+
resource: null,
|
|
573
|
+
agents: [],
|
|
574
|
+
agentsUnavailable: true,
|
|
575
|
+
});
|
|
576
|
+
renderPage();
|
|
577
|
+
expect(await screen.findByRole('alert')).toHaveTextContent(/agents couldn't be loaded/);
|
|
578
|
+
expect(screen.getByRole('button', { name: 'Finish & return to your agent' })).toBeDisabled();
|
|
579
|
+
fireEvent.click(screen.getByRole('checkbox', { name: 'Connect as Everything anyway' }));
|
|
580
|
+
await finish();
|
|
581
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', null);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('keeps Finish disabled until the agents on offer have answered', async () => {
|
|
585
|
+
let answer!: (r: unknown) => void;
|
|
586
|
+
connectMock.getMcpOAuthRequest.mockReturnValue(new Promise((resolve) => (answer = resolve)));
|
|
587
|
+
renderPage();
|
|
588
|
+
const finishButton = await screen.findByRole('button', { name: 'Finish & return to your agent' });
|
|
589
|
+
expect(finishButton).toBeDisabled();
|
|
590
|
+
await act(async () => answer({ clientName: 'Claude', scope: null, resource: null, agents: [OPS] }));
|
|
591
|
+
expect(finishButton).toBeEnabled();
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it('approving with an agent picked connects as that agent', async () => {
|
|
595
|
+
renderPage();
|
|
596
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
597
|
+
await finish();
|
|
598
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', 'Agents/ops.agent');
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it('lists the tools for the chosen agent: the list is fetched again for it, quietly, and once more for Everything', async () => {
|
|
602
|
+
renderPage();
|
|
603
|
+
// The first load, before any choice, is Everything's.
|
|
604
|
+
await screen.findByLabelText('API_KEY value');
|
|
605
|
+
expect(connectMock.getConnectPending).toHaveBeenLastCalledWith(null);
|
|
606
|
+
// The agent loads no tool that needs anything: the page says so, for that agent.
|
|
607
|
+
connectMock.getConnectPending.mockResolvedValue({ tools: [], oauth: [], toolOAuth: [] });
|
|
608
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
609
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
610
|
+
expect(await screen.findByRole('status')).toHaveTextContent(/none of the tools the chosen agent loads/);
|
|
611
|
+
// Quietly: the page never dropped to "Loading…" over the list it had.
|
|
612
|
+
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
613
|
+
// Back to Everything: fetched again, as Everything.
|
|
614
|
+
connectMock.getConnectPending.mockResolvedValue(pending(false));
|
|
615
|
+
fireEvent.click(screen.getByRole('radio', { name: /Everything/ }));
|
|
616
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith(null));
|
|
617
|
+
await screen.findByLabelText('API_KEY value');
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it('fetches the remembered agent’s list straight away when the page comes back from a sign-in', async () => {
|
|
621
|
+
const first = renderPage();
|
|
622
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
623
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
624
|
+
first.unmount();
|
|
625
|
+
connectMock.getConnectPending.mockClear();
|
|
626
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect');
|
|
627
|
+
renderPage();
|
|
628
|
+
await screen.findByRole('radio', { name: /ops/ });
|
|
629
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('keeps the choice across a tool sign-in’s round-trip, and a new authorization starts at Everything', async () => {
|
|
633
|
+
const first = renderPage();
|
|
634
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
635
|
+
first.unmount();
|
|
636
|
+
// Back from a provider: the query is gone, the session copy remains.
|
|
637
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect');
|
|
638
|
+
const back = renderPage();
|
|
639
|
+
expect(await screen.findByRole('radio', { name: /ops/ })).toBeChecked();
|
|
640
|
+
back.unmount();
|
|
641
|
+
// Another agent's authorization arrives: its choice is its own.
|
|
642
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect?oauth=another-state');
|
|
643
|
+
renderPage();
|
|
644
|
+
await screen.findByRole('radio', { name: /ops/ });
|
|
645
|
+
expect(screen.getByRole('radio', { name: /Everything/ })).toBeChecked();
|
|
646
|
+
});
|
|
647
|
+
});
|
|
528
648
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authFetch } from '../../../lib/api';
|
|
2
|
+
import type { AgentChoice } from '../../agents';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The aggregated "connect your tools" surface: everything standing between the
|
|
@@ -96,9 +97,14 @@ async function fail(res: Response, fallback: string): Promise<never> {
|
|
|
96
97
|
throw new Error(message);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
/**
|
|
101
|
+
* The caller's outstanding per-user credentials across every accessible tool —
|
|
102
|
+
* or, with `agentPath` (the consent step's "Connect as" choice), across the
|
|
103
|
+
* connectors a connection made as that agent configuration loads. Null is
|
|
104
|
+
* Everything.
|
|
105
|
+
*/
|
|
106
|
+
export async function getConnectPending(agentPath: string | null = null): Promise<ConnectPending> {
|
|
107
|
+
const res = await authFetch(agentPath ? `/api/connect/pending?agent=${encodeURIComponent(agentPath)}` : '/api/connect/pending');
|
|
102
108
|
if (!res.ok) await fail(res, "Couldn't load your tools.");
|
|
103
109
|
return (await res.json()) as ConnectPending;
|
|
104
110
|
}
|
|
@@ -141,6 +147,14 @@ export interface McpOAuthRequest {
|
|
|
141
147
|
clientName: string | null;
|
|
142
148
|
scope: string | null;
|
|
143
149
|
resource: string | null;
|
|
150
|
+
/**
|
|
151
|
+
* The agent configurations the person may connect this client as, offered below
|
|
152
|
+
* Everything. Empty when there are none (or for a request that cannot take
|
|
153
|
+
* a choice).
|
|
154
|
+
*/
|
|
155
|
+
agents?: AgentChoice[];
|
|
156
|
+
/** Set when the agents could not be listed: `agents` is then empty for that reason, not because there are none. */
|
|
157
|
+
agentsUnavailable?: boolean;
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
/** Describe the pending MCP authorization carried in the signed `state`. */
|
|
@@ -153,12 +167,13 @@ export async function getMcpOAuthRequest(state: string): Promise<McpOAuthRequest
|
|
|
153
167
|
/**
|
|
154
168
|
* Finish the MCP authorization: mint the one-time code for the signed-in user
|
|
155
169
|
* and return the agent's redirect URL the browser should navigate to.
|
|
170
|
+
* `agentPath` is the "Connect as" choice; null (the default) is Everything.
|
|
156
171
|
*/
|
|
157
|
-
export async function completeMcpOAuth(state: string): Promise<string> {
|
|
172
|
+
export async function completeMcpOAuth(state: string, agentPath: string | null = null): Promise<string> {
|
|
158
173
|
const res = await authFetch('/api/mcp/oauth/complete', {
|
|
159
174
|
method: 'POST',
|
|
160
175
|
headers: { 'Content-Type': 'application/json' },
|
|
161
|
-
body: JSON.stringify({ state }),
|
|
176
|
+
body: JSON.stringify(agentPath ? { state, agentPath } : { state }),
|
|
162
177
|
});
|
|
163
178
|
if (!res.ok) await fail(res, "Couldn't finish connecting.");
|
|
164
179
|
return ((await res.json()) as { redirectTo: string }).redirectTo;
|