@bevel-software/platform-core-frontend 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/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 +3 -4
- package/src/modules/access/components/ManageAccessDialog.tsx +7 -7
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- 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 +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditLogPage.tsx +9 -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/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/components/skill-page/SkillFilePane.tsx +57 -9
- package/src/modules/library/components/skill-page/SkillPage.tsx +65 -25
- 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 +112 -2
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +38 -4
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +26 -0
- 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/fileTree.ts +1 -1
|
@@ -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,117 @@ 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('says when the agents could not be loaded, and approves Everything only once that is confirmed', async () => {
|
|
559
|
+
connectMock.getMcpOAuthRequest.mockResolvedValue({
|
|
560
|
+
clientName: 'Claude',
|
|
561
|
+
scope: null,
|
|
562
|
+
resource: null,
|
|
563
|
+
agents: [],
|
|
564
|
+
agentsUnavailable: true,
|
|
565
|
+
});
|
|
566
|
+
renderPage();
|
|
567
|
+
expect(await screen.findByRole('alert')).toHaveTextContent(/agents couldn't be loaded/);
|
|
568
|
+
expect(screen.getByRole('button', { name: 'Finish & return to your agent' })).toBeDisabled();
|
|
569
|
+
fireEvent.click(screen.getByRole('checkbox', { name: 'Connect as Everything anyway' }));
|
|
570
|
+
await finish();
|
|
571
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', null);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('keeps Finish disabled until the agents on offer have answered', async () => {
|
|
575
|
+
let answer!: (r: unknown) => void;
|
|
576
|
+
connectMock.getMcpOAuthRequest.mockReturnValue(new Promise((resolve) => (answer = resolve)));
|
|
577
|
+
renderPage();
|
|
578
|
+
const finishButton = await screen.findByRole('button', { name: 'Finish & return to your agent' });
|
|
579
|
+
expect(finishButton).toBeDisabled();
|
|
580
|
+
await act(async () => answer({ clientName: 'Claude', scope: null, resource: null, agents: [OPS] }));
|
|
581
|
+
expect(finishButton).toBeEnabled();
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('approving with an agent picked connects as that agent', async () => {
|
|
585
|
+
renderPage();
|
|
586
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
587
|
+
await finish();
|
|
588
|
+
expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', 'Agents/ops.agent');
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('lists the tools for the chosen agent: the list is fetched again for it, quietly, and once more for Everything', async () => {
|
|
592
|
+
renderPage();
|
|
593
|
+
// The first load, before any choice, is Everything's.
|
|
594
|
+
await screen.findByLabelText('API_KEY value');
|
|
595
|
+
expect(connectMock.getConnectPending).toHaveBeenLastCalledWith(null);
|
|
596
|
+
// The agent loads no tool that needs anything: the page says so, for that agent.
|
|
597
|
+
connectMock.getConnectPending.mockResolvedValue({ tools: [], oauth: [], toolOAuth: [] });
|
|
598
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
599
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
600
|
+
expect(await screen.findByRole('status')).toHaveTextContent(/none of the tools the chosen agent loads/);
|
|
601
|
+
// Quietly: the page never dropped to "Loading…" over the list it had.
|
|
602
|
+
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
603
|
+
// Back to Everything: fetched again, as Everything.
|
|
604
|
+
connectMock.getConnectPending.mockResolvedValue(pending(false));
|
|
605
|
+
fireEvent.click(screen.getByRole('radio', { name: /Everything/ }));
|
|
606
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith(null));
|
|
607
|
+
await screen.findByLabelText('API_KEY value');
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it('fetches the remembered agent’s list straight away when the page comes back from a sign-in', async () => {
|
|
611
|
+
const first = renderPage();
|
|
612
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
613
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
614
|
+
first.unmount();
|
|
615
|
+
connectMock.getConnectPending.mockClear();
|
|
616
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect');
|
|
617
|
+
renderPage();
|
|
618
|
+
await screen.findByRole('radio', { name: /ops/ });
|
|
619
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenLastCalledWith('Agents/ops.agent'));
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it('keeps the choice across a tool sign-in’s round-trip, and a new authorization starts at Everything', async () => {
|
|
623
|
+
const first = renderPage();
|
|
624
|
+
fireEvent.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
625
|
+
first.unmount();
|
|
626
|
+
// Back from a provider: the query is gone, the session copy remains.
|
|
627
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect');
|
|
628
|
+
const back = renderPage();
|
|
629
|
+
expect(await screen.findByRole('radio', { name: /ops/ })).toBeChecked();
|
|
630
|
+
back.unmount();
|
|
631
|
+
// Another agent's authorization arrives: its choice is its own.
|
|
632
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect?oauth=another-state');
|
|
633
|
+
renderPage();
|
|
634
|
+
await screen.findByRole('radio', { name: /ops/ });
|
|
635
|
+
expect(screen.getByRole('radio', { name: /Everything/ })).toBeChecked();
|
|
636
|
+
});
|
|
637
|
+
});
|
|
528
638
|
});
|
|
@@ -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;
|
|
@@ -23,6 +23,8 @@ import { AgentInstructionsCard } from './AgentInstructionsCard';
|
|
|
23
23
|
import { CONNECT_TOOLS_PATH } from '../../library';
|
|
24
24
|
import { CoworkSetupSteps } from './CoworkSetupSteps';
|
|
25
25
|
import { useAdmin } from '../../admin';
|
|
26
|
+
import { connectedAsLabel, listAgentChoices, useConnectAsChoice } from '../../agents';
|
|
27
|
+
import { ConnectAsChoice } from '../../agents/components/ConnectAsChoice';
|
|
26
28
|
import {
|
|
27
29
|
type ExternalApiKeySummary,
|
|
28
30
|
type MintedExternalApiKey,
|
|
@@ -96,6 +98,10 @@ export function ExternalAgentAccessPage() {
|
|
|
96
98
|
const [loadError, setLoadError] = useState<string | null>(null);
|
|
97
99
|
|
|
98
100
|
const [label, setLabel] = useState('');
|
|
101
|
+
// "Connect as" for a new key: Everything unless an agent is picked. Until
|
|
102
|
+
// the agents answer, a key would be minted as Everything by default; when
|
|
103
|
+
// they could not be loaded, an Everything key waits to be confirmed.
|
|
104
|
+
const connectAs = useConnectAsChoice();
|
|
99
105
|
const [creating, setCreating] = useState(false);
|
|
100
106
|
const [createError, setCreateError] = useState<string | null>(null);
|
|
101
107
|
|
|
@@ -128,15 +134,34 @@ export function ExternalAgentAccessPage() {
|
|
|
128
134
|
void refresh();
|
|
129
135
|
}, [refresh]);
|
|
130
136
|
|
|
137
|
+
// The agents a key may be minted as. A failure costs only the choice —
|
|
138
|
+
// Everything is always on offer — and is shown, not passed off as none.
|
|
139
|
+
const settleConnectAs = connectAs.settle;
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
let cancelled = false;
|
|
142
|
+
listAgentChoices().then(
|
|
143
|
+
(agents) => {
|
|
144
|
+
if (!cancelled) settleConnectAs({ agents });
|
|
145
|
+
},
|
|
146
|
+
() => {
|
|
147
|
+
if (!cancelled) settleConnectAs({ agents: [], failed: true });
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
return () => {
|
|
151
|
+
cancelled = true;
|
|
152
|
+
};
|
|
153
|
+
}, [settleConnectAs]);
|
|
154
|
+
|
|
131
155
|
async function handleCreate() {
|
|
132
156
|
const trimmed = label.trim();
|
|
133
|
-
if (trimmed.length === 0 || trimmed.length > MAX_LABEL_LEN || creating) return;
|
|
157
|
+
if (trimmed.length === 0 || trimmed.length > MAX_LABEL_LEN || creating || !connectAs.mayConnect) return;
|
|
134
158
|
setCreating(true);
|
|
135
159
|
setCreateError(null);
|
|
136
160
|
try {
|
|
137
|
-
const minted = await createExternalApiKey(trimmed);
|
|
161
|
+
const minted = await createExternalApiKey(trimmed, connectAs.value);
|
|
138
162
|
setReveal(minted);
|
|
139
163
|
setLabel('');
|
|
164
|
+
connectAs.setValue(null);
|
|
140
165
|
// Optimistic-ish: refresh the list so the new row shows up underneath
|
|
141
166
|
// the reveal modal.
|
|
142
167
|
void refresh();
|
|
@@ -172,7 +197,7 @@ export function ExternalAgentAccessPage() {
|
|
|
172
197
|
}
|
|
173
198
|
|
|
174
199
|
const trimmed = label.trim();
|
|
175
|
-
const canSubmit = trimmed.length > 0 && trimmed.length <= MAX_LABEL_LEN && !creating;
|
|
200
|
+
const canSubmit = trimmed.length > 0 && trimmed.length <= MAX_LABEL_LEN && !creating && connectAs.mayConnect;
|
|
176
201
|
|
|
177
202
|
// Surface the keys that matter: active keys first (most-recently-used at the
|
|
178
203
|
// top, never-used ones last among the active), with disconnected keys sunk
|
|
@@ -535,6 +560,14 @@ export function ExternalAgentAccessPage() {
|
|
|
535
560
|
{creating ? 'Creating…' : 'Create key'}
|
|
536
561
|
</button>
|
|
537
562
|
</div>
|
|
563
|
+
<ConnectAsChoice
|
|
564
|
+
agents={connectAs.agents}
|
|
565
|
+
value={connectAs.value}
|
|
566
|
+
disabled={creating}
|
|
567
|
+
hint="What the key loads. An agent narrows it to the tools, skills and plugins its configuration lists, and only those you may read."
|
|
568
|
+
onChange={connectAs.setValue}
|
|
569
|
+
unavailable={connectAs.unavailable}
|
|
570
|
+
/>
|
|
538
571
|
{createError && (
|
|
539
572
|
<div className="text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5">
|
|
540
573
|
{createError}
|
|
@@ -575,7 +608,8 @@ export function ExternalAgentAccessPage() {
|
|
|
575
608
|
<div className="flex-1 min-w-0">
|
|
576
609
|
<div className="font-medium truncate">{k.label}</div>
|
|
577
610
|
<div className="text-[11px] text-ink-muted">
|
|
578
|
-
|
|
611
|
+
<span title={k.agentPath ?? undefined}>As {connectedAsLabel(k.agentPath)}</span> · Created{' '}
|
|
612
|
+
{formatRelative(k.createdAt)} · Last used {formatRelative(k.lastUsedAt)}
|
|
579
613
|
{/* A key an admin took is not one you can reconnect — say so,
|
|
580
614
|
or people try. Your own disconnect keeps its word. */}
|
|
581
615
|
{revoked &&
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen, within } from '@testing-library/react';
|
|
2
|
+
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
|
5
5
|
import { ExternalAgentAccessPage } from '../ExternalAgentAccessPage';
|
|
@@ -22,7 +22,8 @@ import { GITHUB_LINK_KIND, configureMarketplaceGitUrl } from '../../../../shared
|
|
|
22
22
|
* regression cases below name all six.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
const { listMock, createMock, instructionsMock, facadeMock, registrationMock, adminState } = vi.hoisted(() => ({
|
|
25
|
+
const { listMock, createMock, instructionsMock, facadeMock, registrationMock, adminState, agentChoicesMock } = vi.hoisted(() => ({
|
|
26
|
+
agentChoicesMock: vi.fn(),
|
|
26
27
|
listMock: vi.fn(),
|
|
27
28
|
createMock: vi.fn(),
|
|
28
29
|
instructionsMock: vi.fn(),
|
|
@@ -49,6 +50,12 @@ vi.mock('../../../settings/services/github-facade.api', () => ({
|
|
|
49
50
|
fetchMarketplaceRegistration: registrationMock,
|
|
50
51
|
}));
|
|
51
52
|
|
|
53
|
+
// The agents a key may be minted as ("Connect as").
|
|
54
|
+
vi.mock('../../../agents/services/agent-choices.api', async (importOriginal) => ({
|
|
55
|
+
...(await importOriginal<typeof import('../../../agents/services/agent-choices.api')>()),
|
|
56
|
+
listAgentChoices: agentChoicesMock,
|
|
57
|
+
}));
|
|
58
|
+
|
|
52
59
|
vi.mock('../../services/external-api-keys.api', () => ({
|
|
53
60
|
listExternalApiKeys: listMock,
|
|
54
61
|
createExternalApiKey: createMock,
|
|
@@ -91,6 +98,9 @@ beforeEach(() => {
|
|
|
91
98
|
registrationMock.mockReset();
|
|
92
99
|
registrationMock.mockResolvedValue(true);
|
|
93
100
|
listMock.mockResolvedValue([]);
|
|
101
|
+
agentChoicesMock.mockReset();
|
|
102
|
+
agentChoicesMock.mockResolvedValue([]);
|
|
103
|
+
createMock.mockClear();
|
|
94
104
|
instructionsMock.mockResolvedValue({
|
|
95
105
|
instructions: 'Search the knowledge base first.',
|
|
96
106
|
header: 'Search the knowledge base first.',
|
|
@@ -792,6 +802,85 @@ describe('the Marketplaces tab', () => {
|
|
|
792
802
|
});
|
|
793
803
|
});
|
|
794
804
|
|
|
805
|
+
describe('minting a key as an agent ("Connect as")', () => {
|
|
806
|
+
const OPS = { path: 'Agents/ops.agent', name: 'ops', description: 'Watches the dashboards.' };
|
|
807
|
+
|
|
808
|
+
it('offers Everything, selected by default, then each agent by name with its description', async () => {
|
|
809
|
+
agentChoicesMock.mockResolvedValue([OPS]);
|
|
810
|
+
const user = userEvent.setup();
|
|
811
|
+
mount(PUBLIC_URL);
|
|
812
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
813
|
+
const group = screen.getByRole('group', { name: 'Connect as' });
|
|
814
|
+
const everything = within(group).getByRole('radio', { name: /Everything/ });
|
|
815
|
+
expect(everything).toBeChecked();
|
|
816
|
+
const ops = await within(group).findByRole('radio', { name: /ops.*Watches the dashboards\./ });
|
|
817
|
+
expect(ops).not.toBeChecked();
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it('mints as Everything unless an agent is picked, and as the agent when one is', async () => {
|
|
821
|
+
agentChoicesMock.mockResolvedValue([OPS]);
|
|
822
|
+
const user = userEvent.setup();
|
|
823
|
+
mount(PUBLIC_URL);
|
|
824
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
825
|
+
await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'CI');
|
|
826
|
+
await user.click(screen.getByRole('button', { name: 'Create key' }));
|
|
827
|
+
expect(createMock).toHaveBeenLastCalledWith('CI', null);
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it('records the picked agent on the key', async () => {
|
|
831
|
+
agentChoicesMock.mockResolvedValue([OPS]);
|
|
832
|
+
const user = userEvent.setup();
|
|
833
|
+
mount(PUBLIC_URL);
|
|
834
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
835
|
+
await user.click(await screen.findByRole('radio', { name: /ops/ }));
|
|
836
|
+
await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'Pipeline');
|
|
837
|
+
await user.click(screen.getByRole('button', { name: 'Create key' }));
|
|
838
|
+
expect(createMock).toHaveBeenLastCalledWith('Pipeline', 'Agents/ops.agent');
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it('says when the agents could not be loaded, and mints Everything only once that is confirmed', async () => {
|
|
842
|
+
agentChoicesMock.mockRejectedValue(new Error('down'));
|
|
843
|
+
const user = userEvent.setup();
|
|
844
|
+
mount(PUBLIC_URL);
|
|
845
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
846
|
+
expect(await screen.findByRole('alert')).toHaveTextContent(/agents couldn't be loaded/);
|
|
847
|
+
await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'CI');
|
|
848
|
+
const create = screen.getByRole('button', { name: 'Create key' });
|
|
849
|
+
expect(create).toBeDisabled();
|
|
850
|
+
await user.click(screen.getByRole('checkbox', { name: 'Connect as Everything anyway' }));
|
|
851
|
+
expect(create).toBeEnabled();
|
|
852
|
+
await user.click(create);
|
|
853
|
+
expect(createMock).toHaveBeenLastCalledWith('CI', null);
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
it('keeps Create key disabled until the agents on offer have answered', async () => {
|
|
857
|
+
let answer!: (agents: (typeof OPS)[]) => void;
|
|
858
|
+
agentChoicesMock.mockReturnValue(new Promise((resolve) => (answer = resolve)));
|
|
859
|
+
const user = userEvent.setup();
|
|
860
|
+
mount(PUBLIC_URL);
|
|
861
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
862
|
+
await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'CI');
|
|
863
|
+
const create = screen.getByRole('button', { name: 'Create key' });
|
|
864
|
+
expect(create).toBeDisabled();
|
|
865
|
+
await act(async () => answer([OPS]));
|
|
866
|
+
expect(create).toBeEnabled();
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
it('shows each key beside what it connects as', async () => {
|
|
870
|
+
listMock.mockResolvedValue([
|
|
871
|
+
{ id: 'k1', kind: 'key', label: 'Laptop', createdAt: Date.now(), lastUsedAt: null, revokedAt: null, revokedBy: null, agentPath: null },
|
|
872
|
+
{ id: 'k2', kind: 'key', label: 'Pipeline', createdAt: Date.now(), lastUsedAt: null, revokedAt: null, revokedBy: null, agentPath: 'Agents/ops.agent' },
|
|
873
|
+
]);
|
|
874
|
+
const user = userEvent.setup();
|
|
875
|
+
mount(PUBLIC_URL);
|
|
876
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
877
|
+
await screen.findByText('Pipeline');
|
|
878
|
+
const rowOf = (label: string) => screen.getByText(label).closest('li') as HTMLElement;
|
|
879
|
+
expect(rowOf('Laptop')).toHaveTextContent('As Everything');
|
|
880
|
+
expect(rowOf('Pipeline')).toHaveTextContent('As ops');
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
|
|
795
884
|
describe('the one-click install link', () => {
|
|
796
885
|
it('offers Add to Claude on a reachable deployment', () => {
|
|
797
886
|
mount(PUBLIC_URL);
|
|
@@ -16,6 +16,8 @@ export interface ExternalApiKeySummary {
|
|
|
16
16
|
revokedBy: 'owner' | 'admin' | null;
|
|
17
17
|
/** Never set on a key the owner can see: a deleted key leaves their listings. */
|
|
18
18
|
deletedAt?: number | null;
|
|
19
|
+
/** The agent configuration the key connects as (a knowledge-base path), or null for Everything. */
|
|
20
|
+
agentPath?: string | null;
|
|
19
21
|
/** Model-proxy usage for this key today + the daily cap (in tokens). */
|
|
20
22
|
llmUsage?: { usedTodayTokens: number; dailyTokenCap: number };
|
|
21
23
|
}
|
|
@@ -44,11 +46,12 @@ export async function listExternalApiKeys(): Promise<ExternalApiKeySummary[]> {
|
|
|
44
46
|
return res.json() as Promise<ExternalApiKeySummary[]>;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/** Mint a key. `agentPath` is its "Connect as" choice; null (the default) is Everything. */
|
|
50
|
+
export async function createExternalApiKey(label: string, agentPath: string | null = null): Promise<MintedExternalApiKey> {
|
|
48
51
|
const res = await authFetch('/api/mcp/external-api-keys', {
|
|
49
52
|
method: 'POST',
|
|
50
53
|
headers: { 'Content-Type': 'application/json' },
|
|
51
|
-
body: JSON.stringify({ label }),
|
|
54
|
+
body: JSON.stringify(agentPath ? { label, agentPath } : { label }),
|
|
52
55
|
});
|
|
53
56
|
if (!res.ok) await unwrap(res, "Couldn't create external API key.");
|
|
54
57
|
return res.json() as Promise<MintedExternalApiKey>;
|
|
@@ -968,6 +968,32 @@ describe('FileExplorer right-click: Download menu (per-path access)', () => {
|
|
|
968
968
|
});
|
|
969
969
|
});
|
|
970
970
|
|
|
971
|
+
// A link INSIDE a file opens a new tab; the tree is the app's own navigation
|
|
972
|
+
// and is not one. A click on a file row moves this tab to that file, as it
|
|
973
|
+
// always has, whatever view the tab was in.
|
|
974
|
+
describe('FileExplorer: a file click navigates this tab', () => {
|
|
975
|
+
beforeEach(() => {
|
|
976
|
+
cleanup();
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it('opens the clicked file in place, with no new tab', async () => {
|
|
980
|
+
const open = vi.spyOn(window, 'open').mockImplementation(() => null);
|
|
981
|
+
renderExplorer({
|
|
982
|
+
fileTree: {
|
|
983
|
+
name: '.',
|
|
984
|
+
relativePath: '.',
|
|
985
|
+
type: 'directory',
|
|
986
|
+
children: [{ name: 'Plan.md', relativePath: 'Plan.md', type: 'file' }],
|
|
987
|
+
},
|
|
988
|
+
initialEntries: [`/workspace/alice%2Fdraft/${kbPath('Other.md')}?fullscreen=1`],
|
|
989
|
+
});
|
|
990
|
+
await userEvent.setup().click(screen.getByText('Plan.md'));
|
|
991
|
+
expect(screen.getByTestId('location-pathname').textContent).toBe(`/workspace/alice%2Fdraft/${kbPath('Plan.md')}`);
|
|
992
|
+
expect(open).not.toHaveBeenCalled();
|
|
993
|
+
open.mockRestore();
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
|
|
971
997
|
// Regression coverage for the FileTreeNode collapse state machine. PR #113
|
|
972
998
|
// derived `autoExpanded` reactively without an escape hatch, so clicking the
|
|
973
999
|
// chevron on a folder that contained the open file did nothing — the user's
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { Pencil, Eye, RotateCw } from 'lucide-react';
|
|
3
|
+
import { useLocation } from 'react-router-dom';
|
|
3
4
|
import { useFileNav } from '../../routing/kb-routes';
|
|
4
5
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
5
6
|
import { buildSandboxedHtml, sanitizeAgentHtml } from './htmlSandbox';
|
|
6
7
|
import { useRendererSurface } from './rendererSurface';
|
|
8
|
+
import { usePageLinkHome } from './htmlToolBridge';
|
|
7
9
|
import { useHtmlToolBridge } from './useHtmlToolBridge';
|
|
8
10
|
import {
|
|
9
11
|
HTML_FRAME_KEY_STEP,
|
|
@@ -49,11 +51,20 @@ export function HtmlRenderer({
|
|
|
49
51
|
onSaveStateChange,
|
|
50
52
|
readOnly = false,
|
|
51
53
|
}: FileRendererProps) {
|
|
52
|
-
const { openLink } = useFileNav();
|
|
54
|
+
const { openLink, branch: tabBranch } = useFileNav();
|
|
55
|
+
// The fragment this tab's address arrived with (`Board.html#totals`, from a
|
|
56
|
+
// section link opened in a new tab or a shared address). It names a place
|
|
57
|
+
// in the PAGE, which lives in the frame, where the app's address never
|
|
58
|
+
// reaches: the frame is handed it as `bevel.jump` once it has loaded, the
|
|
59
|
+
// same message a click on a section link inside the page is answered with.
|
|
60
|
+
const { hash: arrivalHash } = useLocation();
|
|
53
61
|
const surface = useRendererSurface();
|
|
54
62
|
// Whether the surface's host grows with the page (an issue panel) rather
|
|
55
63
|
// than giving it a pane to scroll in (the app, the MCP App's pane).
|
|
56
64
|
const sizesToContent = surface?.sizesToContent === true;
|
|
65
|
+
// The file this page's links resolve against, where the host's `filePath`
|
|
66
|
+
// is not a workspace path on this tab's branch (a skill page).
|
|
67
|
+
const linkHome = usePageLinkHome();
|
|
57
68
|
const [mode, setMode] = useState<'preview' | 'edit'>('preview');
|
|
58
69
|
/**
|
|
59
70
|
* The frame's height where the host grows with the page: the standard
|
|
@@ -133,12 +144,16 @@ export function HtmlRenderer({
|
|
|
133
144
|
libModuleSources: [],
|
|
134
145
|
bodyHtml: sanitizeAgentHtml(savedValue),
|
|
135
146
|
toolBridge,
|
|
147
|
+
// The branch the page is viewed on — the real home of a page whose
|
|
148
|
+
// host is not a workspace path (a skill page), else the file page's
|
|
149
|
+
// tab: the same branch its links resolve on. Absent on a surface.
|
|
150
|
+
branch: linkHome?.branch ?? tabBranch ?? undefined,
|
|
136
151
|
});
|
|
137
152
|
return { srcdoc, error: null };
|
|
138
153
|
} catch (err) {
|
|
139
154
|
return { srcdoc: null, error: err instanceof Error ? err.message : 'Failed to build preview' };
|
|
140
155
|
}
|
|
141
|
-
}, [mode, savedValue, filePath, toolBridge]);
|
|
156
|
+
}, [mode, savedValue, filePath, toolBridge, linkHome, tabBranch]);
|
|
142
157
|
const bundledSrcdoc = preview?.srcdoc ?? null;
|
|
143
158
|
const previewError = preview?.error ?? null;
|
|
144
159
|
|
|
@@ -152,21 +167,36 @@ export function HtmlRenderer({
|
|
|
152
167
|
// node — both post a `bevel.navigate` message (the iframe sandbox can't
|
|
153
168
|
// navigate the host window itself). `openLink` resolves the href the same
|
|
154
169
|
// way the markdown renderer does (absolute `/workspace/…` URLs keep their
|
|
155
|
-
// branch; relative paths resolve against this file) and
|
|
156
|
-
//
|
|
170
|
+
// branch; relative paths resolve against this file) and follows it by the
|
|
171
|
+
// rule for links inside a file: another file opens in a new tab, and this
|
|
172
|
+
// page — its state, its scroll, its full-screen view — stays as it was.
|
|
173
|
+
// A link to a section of this same page (`Roadmap.html#q3` from inside
|
|
174
|
+
// Roadmap.html) is handed back to the frame as `bevel.jump`, which scrolls
|
|
175
|
+
// it the way the bridge scrolls a bare `#q3`: a fragment on the app's own
|
|
176
|
+
// address would never reach the frame. A host whose `filePath` is not a
|
|
177
|
+
// workspace path on this tab's branch (a skill page) names the page's real
|
|
178
|
+
// home through `PageLinkHomeContext`.
|
|
157
179
|
useEffect(() => {
|
|
158
180
|
function onNavMessage(event: MessageEvent) {
|
|
159
181
|
const iframeWin = iframeRef.current?.contentWindow;
|
|
160
182
|
if (!iframeWin || event.source !== iframeWin) return;
|
|
161
|
-
const msg = event.data as { type?: unknown; href?: unknown } | null;
|
|
183
|
+
const msg = event.data as { type?: unknown; href?: unknown; newTab?: unknown } | null;
|
|
162
184
|
if (!msg || typeof msg !== 'object' || msg.type !== 'bevel.navigate') return;
|
|
163
185
|
const href = typeof msg.href === 'string' ? msg.href : null;
|
|
164
186
|
if (!href) return;
|
|
165
|
-
openLink(href, filePath
|
|
187
|
+
openLink(href, linkHome?.path ?? filePath, {
|
|
188
|
+
homeBranch: linkHome?.branch,
|
|
189
|
+
// A modified or middle click in the page, which the frame cannot
|
|
190
|
+
// open a tab for itself (see the nav bridge in `htmlSandbox.ts`).
|
|
191
|
+
newTab: msg.newTab === true,
|
|
192
|
+
onSection: (hash) => {
|
|
193
|
+
if (hash) iframeWin.postMessage({ type: 'bevel.jump', hash }, '*');
|
|
194
|
+
},
|
|
195
|
+
});
|
|
166
196
|
}
|
|
167
197
|
window.addEventListener('message', onNavMessage);
|
|
168
198
|
return () => window.removeEventListener('message', onNavMessage);
|
|
169
|
-
}, [openLink, filePath]);
|
|
199
|
+
}, [openLink, filePath, linkHome]);
|
|
170
200
|
|
|
171
201
|
useEffect(() => {
|
|
172
202
|
frameHeightRef.current = frameHeight;
|
|
@@ -310,6 +340,9 @@ export function HtmlRenderer({
|
|
|
310
340
|
// iframe cannot exfiltrate, navigate, popup, or fetch.
|
|
311
341
|
sandbox="allow-scripts"
|
|
312
342
|
referrerPolicy="no-referrer"
|
|
343
|
+
onLoad={(e) => {
|
|
344
|
+
if (arrivalHash) e.currentTarget.contentWindow?.postMessage({ type: 'bevel.jump', hash: arrivalHash }, '*');
|
|
345
|
+
}}
|
|
313
346
|
// In a pane the frame fills it and scrolls inside; where the host
|
|
314
347
|
// grows with the page, the frame has the reader's height (a
|
|
315
348
|
// flex-grown frame in an auto-height column would collapse to the
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an in-app link inside rendered content leads, as the app's file-nav
|
|
3
|
+
* hook answers it (`useFileNav().linkTarget`, `useNodeIdNav().nodeIdTarget`):
|
|
4
|
+
* `href` is the address the click opens, `newTab` whether it opens there in a
|
|
5
|
+
* new tab (another file) or in this one (a section of the file on screen).
|
|
6
|
+
*/
|
|
7
|
+
export interface KbLinkTarget {
|
|
8
|
+
href: string;
|
|
9
|
+
newTab: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An in-app link the caller follows on click (`onOpen`, with the destination
|
|
14
|
+
* as written). With a `target` the anchor carries the address the click goes
|
|
15
|
+
* to, and — when that is a new tab — `target="_blank"` and `rel="noopener"`,
|
|
16
|
+
* so a middle-click, the context menu and a screen reader all agree with the
|
|
17
|
+
* click. A click the reader modified (Ctrl, ⌘, Shift, Alt) or made with
|
|
18
|
+
* another button is left to the browser, on a new-tab link and a section link
|
|
19
|
+
* alike: the anchor's `href` is already the address the click would open, so
|
|
20
|
+
* the browser does with it what it does with any link — a Ctrl-click on a
|
|
21
|
+
* section link opens that section in a new tab rather than moving this one.
|
|
22
|
+
* Without a `target` (no resolver) the anchor is what it always was, every
|
|
23
|
+
* click taken by `onOpen`: its `href` is the destination as written, not an
|
|
24
|
+
* address the browser could follow.
|
|
25
|
+
*/
|
|
26
|
+
export function KbAppLink({
|
|
27
|
+
href,
|
|
28
|
+
target,
|
|
29
|
+
onOpen,
|
|
30
|
+
className = 'cursor-pointer',
|
|
31
|
+
children,
|
|
32
|
+
...props
|
|
33
|
+
}: {
|
|
34
|
+
href: string;
|
|
35
|
+
target: KbLinkTarget | null;
|
|
36
|
+
onOpen: () => void;
|
|
37
|
+
className?: string;
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
}) {
|
|
40
|
+
const newTab = target?.newTab === true;
|
|
41
|
+
return (
|
|
42
|
+
<a
|
|
43
|
+
{...props}
|
|
44
|
+
href={target?.href ?? href}
|
|
45
|
+
{...(newTab ? { target: '_blank', rel: 'noopener' } : {})}
|
|
46
|
+
onClick={(e) => {
|
|
47
|
+
if (target && (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onOpen();
|
|
50
|
+
}}
|
|
51
|
+
className={className}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
</a>
|
|
55
|
+
);
|
|
56
|
+
}
|