@bevel-software/platform-core-frontend 0.34.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +40 -97
- package/src/core/KnowledgeSurface.tsx +92 -0
- package/src/core/__tests__/CoreAppShell.root-claims.test.tsx +280 -0
- package/src/core/registry.ts +110 -2
- package/src/index.ts +3 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +1 -1
- package/src/modules/access/api.ts +24 -4
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +1 -1
- package/src/modules/admin/index.ts +1 -1
- package/src/modules/agents/components/ConnectAsChoice.tsx +7 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +4 -3
- package/src/modules/audit/components/AuditLogPage.tsx +6 -4
- package/src/modules/audit/components/principal-grouping.ts +49 -49
- package/src/modules/auth/index.ts +1 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +6 -6
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +8 -8
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +1 -1
- package/src/modules/git/__tests__/pr.api.test.ts +3 -3
- package/src/modules/git/components/FileHistoryPanel.tsx +1 -1
- package/src/modules/git/components/GitSyncFailedBanner.tsx +1 -1
- package/src/modules/git/services/git.api.ts +1 -1
- package/src/modules/git/services/pr-prompts.ts +1 -1
- package/src/modules/layout/state/layout.context.ts +8 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +5 -5
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +11 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +160 -5
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +103 -28
- package/src/modules/library/services/library.api.ts +2 -2
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +8 -8
- package/src/modules/onboarding/state/agent-connection.ts +1 -1
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +96 -30
- package/src/modules/secrets-vault/components/IncludeToggle.tsx +29 -0
- package/src/modules/secrets-vault/components/ManagedConnectorCard.tsx +189 -0
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.managed.test.tsx +212 -0
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +10 -0
- package/src/modules/secrets-vault/components/__tests__/ManagedConnectorCard.test.tsx +182 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +3 -0
- package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +1 -0
- package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -0
- package/src/modules/secrets-vault/index.ts +2 -0
- package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +1 -0
- package/src/modules/secrets-vault/services/connect.api.ts +46 -5
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +21 -3
- package/src/modules/secrets-vault/utils/managed-card-state.ts +61 -0
- package/src/modules/setup/utils/__tests__/root-folders.test.ts +5 -1
- package/src/modules/setup/utils/root-folders.ts +2 -2
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +8 -1
- package/src/modules/toolbar/components/Toolbar.tsx +1 -1
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +39 -13
- package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.test.tsx +10 -10
- package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.wire.test.tsx +1 -1
- package/src/modules/{workflow → version-control}/hooks/useEventBusSubscription.ts +2 -2
- package/src/modules/{workflow → version-control}/hooks/useFileLock.ts +1 -1
- package/src/modules/{workflow → version-control}/index.ts +2 -2
- package/src/modules/{workflow → version-control}/services/__tests__/lock.api.test.ts +1 -1
- package/src/modules/{workflow → version-control}/state/EventBusProvider.tsx +6 -6
- package/src/modules/{workflow → version-control}/state/event-bus.context.ts +4 -4
- package/src/modules/workspace/components/FileExplorer.tsx +96 -41
- package/src/modules/workspace/components/FileRoute.tsx +24 -1
- package/src/modules/workspace/components/FileViewer.tsx +2 -2
- package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +191 -21
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +50 -2
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +5 -5
- package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +5 -5
- package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +9 -9
- package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +7 -7
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useWorkspaceState.ts +2 -2
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +9 -9
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +9 -1
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +32 -48
- package/src/modules/workspace/utils/fileTree.ts +10 -2
- package/src/modules/workspace/utils/treeConfirm.ts +25 -29
- /package/src/modules/{workflow → version-control}/services/lock.api.ts +0 -0
- /package/src/modules/{workflow → version-control}/state/ChangeRequestStaleBinder.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/EventBusFocusBinder.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.storage.test.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.watch.test.tsx +0 -0
|
@@ -2,12 +2,15 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { Link } from 'react-router-dom';
|
|
3
3
|
import { Badge, Banner, Button, Surface, TextField } from '../../../shared/components';
|
|
4
4
|
import { cn } from '../../../lib/utils';
|
|
5
|
-
import { pathForTool, readOAuthFragment
|
|
5
|
+
import { pathForTool, readOAuthFragment } from '../../library';
|
|
6
|
+
import { ToolLogo } from '../../library/components/ToolLogo';
|
|
6
7
|
import { startOAuth } from '../services/secrets.api';
|
|
7
|
-
import { setUserVar, setAdminVar, deleteUserVar, setOAuthClientSecret } from '../services/tool-secrets.api';
|
|
8
|
+
import { setUserVar, setAdminVar, deleteUserVar, deleteAdminVar, setOAuthClientSecret } from '../services/tool-secrets.api';
|
|
8
9
|
import { SavedKeyProbeResult } from '../probe/SavedKeyProbeResult';
|
|
9
10
|
import { useSavedKeyProbe, type SavedKeyProbe } from '../probe/useSavedKeyProbe';
|
|
10
11
|
import { announceToolCredentialsChanged } from '../../../core/events';
|
|
12
|
+
import { useAppRegistry } from '../../../core/registry';
|
|
13
|
+
import { SlotBoundary } from '../../../shared/components/SlotBoundary';
|
|
11
14
|
import { useConnectAsChoice } from '../../agents';
|
|
12
15
|
import { ConnectAsChoice } from '../../agents/components/ConnectAsChoice';
|
|
13
16
|
import {
|
|
@@ -19,6 +22,9 @@ import {
|
|
|
19
22
|
type ConnectOAuth,
|
|
20
23
|
type ConnectToolOAuth,
|
|
21
24
|
} from '../services/connect.api';
|
|
25
|
+
import { ManagedConnectorCard } from './ManagedConnectorCard';
|
|
26
|
+
import { IncludeToggle } from './IncludeToggle';
|
|
27
|
+
import { canBringOwnApp, isManagedRow } from '../utils/managed-card-state';
|
|
22
28
|
import {
|
|
23
29
|
isActionable,
|
|
24
30
|
outstandingCount,
|
|
@@ -128,6 +134,9 @@ export function ConnectToolsPage() {
|
|
|
128
134
|
// from "4 integrations need setup" came to show two.
|
|
129
135
|
const [skipped, setSkipped] = useState<Set<string>>(new Set());
|
|
130
136
|
const [wiping, setWiping] = useState<Set<string>>(new Set());
|
|
137
|
+
// The distribution's foot of the page (which connectors it offers, and
|
|
138
|
+
// enabling one), when it registers one. See `AppRegistry.connectPanel`.
|
|
139
|
+
const ConnectPanel = useAppRegistry().connectPanel;
|
|
131
140
|
|
|
132
141
|
/**
|
|
133
142
|
* Which load is allowed to publish. Saving a key refreshes, and so does the
|
|
@@ -263,6 +272,31 @@ export function ConnectToolsPage() {
|
|
|
263
272
|
}
|
|
264
273
|
};
|
|
265
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Disconnect a managed connector: the server revokes the token with the
|
|
277
|
+
* provider where it can, then deletes it here. A WORKSPACE connection is
|
|
278
|
+
* the shared row, which only a writer may remove (the server enforces it;
|
|
279
|
+
* the card offers the button to the same people).
|
|
280
|
+
*/
|
|
281
|
+
const onDisconnectManaged = async (o: ConnectToolOAuth) => {
|
|
282
|
+
const id = signInId(o);
|
|
283
|
+
setWiping((s) => new Set(s).add(id));
|
|
284
|
+
try {
|
|
285
|
+
if (o.managed?.tokenScope === 'shared') await deleteAdminVar(o.slug, o.varName);
|
|
286
|
+
else await deleteUserVar(o.slug, o.varName);
|
|
287
|
+
announceToolCredentialsChanged();
|
|
288
|
+
await refresh(true);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
291
|
+
} finally {
|
|
292
|
+
setWiping((s) => {
|
|
293
|
+
const nextSet = new Set(s);
|
|
294
|
+
nextSet.delete(id);
|
|
295
|
+
return nextSet;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
266
300
|
const onFinish = async () => {
|
|
267
301
|
if (!agentState || !connectAs.mayConnect) return;
|
|
268
302
|
setFinishing(true);
|
|
@@ -349,6 +383,10 @@ export function ConnectToolsPage() {
|
|
|
349
383
|
const outstanding = outstandingCount(listing) + standaloneOutstanding(listing);
|
|
350
384
|
const nothingToDo =
|
|
351
385
|
!loading && tools.length === 0 && oauth.length === 0 && toolOAuth.length === 0;
|
|
386
|
+
// Managed connectors get a card of their own (what they do, what they ask
|
|
387
|
+
// for); every other sign-in stays a row under "Sign-ins".
|
|
388
|
+
const connectors = toolOAuth.filter(isManagedRow);
|
|
389
|
+
const plainSignIns = toolOAuth.filter((o) => !o.managed);
|
|
352
390
|
|
|
353
391
|
// A document, like every Skills & Tools page: `LibraryLayout`'s pane is the
|
|
354
392
|
// scroller. The header sticks to the top of that pane, so the title and
|
|
@@ -476,10 +514,49 @@ export function ConnectToolsPage() {
|
|
|
476
514
|
</Banner>
|
|
477
515
|
)}
|
|
478
516
|
|
|
479
|
-
{
|
|
517
|
+
{connectors.length > 0 && (
|
|
518
|
+
<Section title="Connectors">
|
|
519
|
+
{connectors.map((o) => (
|
|
520
|
+
<ManagedConnectorCard
|
|
521
|
+
key={o.key}
|
|
522
|
+
o={o}
|
|
523
|
+
busy={wiping.has(signInId(o))}
|
|
524
|
+
// Include/skip, as every sign-in row has it: skipping a
|
|
525
|
+
// personal sign-in removes the caller's own token (the
|
|
526
|
+
// same wipe as a row's). A workspace connection is
|
|
527
|
+
// everyone's and cannot be "skipped by you": nothing
|
|
528
|
+
// takes a shared token out of one agent's connection,
|
|
529
|
+
// so the card offers no toggle rather than a hollow one.
|
|
530
|
+
on={isOn(signInId(o))}
|
|
531
|
+
onToggle={
|
|
532
|
+
o.managed.tokenScope === 'shared'
|
|
533
|
+
? undefined
|
|
534
|
+
: () =>
|
|
535
|
+
void onToggle(signInId(o), o.authorized, async (removed) => {
|
|
536
|
+
await deleteUserVar(o.slug, o.varName);
|
|
537
|
+
removed();
|
|
538
|
+
})
|
|
539
|
+
}
|
|
540
|
+
onConnect={() => void onAuthorizeTool(o.slug, o.varName)}
|
|
541
|
+
onDisconnect={() => void onDisconnectManaged(o)}
|
|
542
|
+
onOwnApp={
|
|
543
|
+
canBringOwnApp(o)
|
|
544
|
+
? async (clientId, clientSecret) => {
|
|
545
|
+
await setOAuthClientSecret(o.slug, o.varName, clientSecret, clientId);
|
|
546
|
+
announceToolCredentialsChanged();
|
|
547
|
+
await refresh(true);
|
|
548
|
+
}
|
|
549
|
+
: undefined
|
|
550
|
+
}
|
|
551
|
+
/>
|
|
552
|
+
))}
|
|
553
|
+
</Section>
|
|
554
|
+
)}
|
|
555
|
+
|
|
556
|
+
{(plainSignIns.length > 0 || oauth.length > 0) && (
|
|
480
557
|
<Section title="Sign-ins">
|
|
481
558
|
{/* OAuth-backed tool variables — authorized via the tool-scoped flow. */}
|
|
482
|
-
{
|
|
559
|
+
{plainSignIns.map((o) => {
|
|
483
560
|
const id = signInId(o);
|
|
484
561
|
const on = isOn(id);
|
|
485
562
|
// The provider was never registered, so there is no consent
|
|
@@ -659,6 +736,21 @@ export function ConnectToolsPage() {
|
|
|
659
736
|
)}
|
|
660
737
|
</>
|
|
661
738
|
)}
|
|
739
|
+
|
|
740
|
+
{/* The distribution's foot of the page — which connectors it offers
|
|
741
|
+
and enabling one — rendered whatever the lists above hold: a
|
|
742
|
+
reader with nothing to set up is exactly who comes here to
|
|
743
|
+
enable something. */}
|
|
744
|
+
{ConnectPanel && !loading && (
|
|
745
|
+
<SlotBoundary label="connect panel">
|
|
746
|
+
<ConnectPanel
|
|
747
|
+
onChanged={() => {
|
|
748
|
+
announceToolCredentialsChanged();
|
|
749
|
+
void refresh(true);
|
|
750
|
+
}}
|
|
751
|
+
/>
|
|
752
|
+
</SlotBoundary>
|
|
753
|
+
)}
|
|
662
754
|
</div>
|
|
663
755
|
</div>
|
|
664
756
|
</div>
|
|
@@ -792,32 +884,6 @@ function ConnectRow(props: RowHeadProps) {
|
|
|
792
884
|
);
|
|
793
885
|
}
|
|
794
886
|
|
|
795
|
-
/** Include/skip checkbox for a tool or sign-in row. */
|
|
796
|
-
function IncludeToggle({
|
|
797
|
-
on,
|
|
798
|
-
busy,
|
|
799
|
-
onChange,
|
|
800
|
-
}: {
|
|
801
|
-
on: boolean;
|
|
802
|
-
busy: boolean;
|
|
803
|
-
onChange: () => void;
|
|
804
|
-
}) {
|
|
805
|
-
const label = on
|
|
806
|
-
? 'Skip this tool (removes your saved keys and sign-ins for it)'
|
|
807
|
-
: 'Include this tool';
|
|
808
|
-
return (
|
|
809
|
-
<input
|
|
810
|
-
type="checkbox"
|
|
811
|
-
checked={on}
|
|
812
|
-
disabled={busy}
|
|
813
|
-
onChange={onChange}
|
|
814
|
-
title={label}
|
|
815
|
-
aria-label={label}
|
|
816
|
-
className="size-3.5 shrink-0 accent-accent disabled:opacity-40"
|
|
817
|
-
/>
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
887
|
/**
|
|
822
888
|
* One tool's keys, and the ONE probe they share.
|
|
823
889
|
*
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Include/skip checkbox for a tool, a sign-in row or a managed connector's
|
|
3
|
+
* card on the Connect page: what the agent may use. One control, so every
|
|
4
|
+
* row names the choice the same way.
|
|
5
|
+
*/
|
|
6
|
+
export function IncludeToggle({
|
|
7
|
+
on,
|
|
8
|
+
busy,
|
|
9
|
+
onChange,
|
|
10
|
+
}: {
|
|
11
|
+
on: boolean;
|
|
12
|
+
busy: boolean;
|
|
13
|
+
onChange: () => void;
|
|
14
|
+
}) {
|
|
15
|
+
const label = on
|
|
16
|
+
? 'Skip this tool (removes your saved keys and sign-ins for it)'
|
|
17
|
+
: 'Include this tool';
|
|
18
|
+
return (
|
|
19
|
+
<input
|
|
20
|
+
type="checkbox"
|
|
21
|
+
checked={on}
|
|
22
|
+
disabled={busy}
|
|
23
|
+
onChange={onChange}
|
|
24
|
+
title={label}
|
|
25
|
+
aria-label={label}
|
|
26
|
+
className="size-3.5 shrink-0 accent-accent disabled:opacity-40"
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
import { Badge, Button, Surface, TextField } from '../../../shared/components';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
import { pathForTool } from '../../library';
|
|
6
|
+
// A component is composed from its file, never from a module's entry (the
|
|
7
|
+
// Module Map: entries carry utilities and contracts; a component re-export
|
|
8
|
+
// is an import cycle waiting to happen).
|
|
9
|
+
import { ToolLogo } from '../../library/components/ToolLogo';
|
|
10
|
+
import { IncludeToggle } from './IncludeToggle';
|
|
11
|
+
import { canStartSignIn, managedCardState, type ManagedCardState, type ManagedToolOAuth } from '../utils/managed-card-state';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One managed connector on the Connect page: what connecting lets Hexis do,
|
|
15
|
+
* the permissions it asks for in plain words, and the one control the
|
|
16
|
+
* reader has — Connect, Reconnect or Disconnect. A workspace connection
|
|
17
|
+
* (one an owner makes for everyone) shows the same card to everyone and
|
|
18
|
+
* offers the controls only to a writer of the tool. The states, and what
|
|
19
|
+
* each means, are `managedCardState`'s; the words for each are below.
|
|
20
|
+
*/
|
|
21
|
+
const STATE_BADGE: Record<ManagedCardState, { text: string; tone: 'ok' | 'wait' | 'outline' | 'danger' }> = {
|
|
22
|
+
unavailable: { text: 'Not available yet', tone: 'outline' },
|
|
23
|
+
'owner-only': { text: 'Needs an owner', tone: 'outline' },
|
|
24
|
+
ready: { text: 'Ready to connect', tone: 'wait' },
|
|
25
|
+
// "Signed in", not "Connected": the card knows a token is stored, as every
|
|
26
|
+
// sign-in row on this page does. "Connected" is the one word reserved for
|
|
27
|
+
// a real call's answer (the key probe), and it is said in one place only.
|
|
28
|
+
connected: { text: 'Signed in', tone: 'ok' },
|
|
29
|
+
'needs-reconnect': { text: 'Needs reconnect', tone: 'wait' },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface ManagedConnectorCardProps {
|
|
33
|
+
o: ManagedToolOAuth;
|
|
34
|
+
busy: boolean;
|
|
35
|
+
onConnect: () => void;
|
|
36
|
+
onDisconnect: () => void;
|
|
37
|
+
/** An owner brings the deployment's own OAuth app in place of the managed one. */
|
|
38
|
+
onOwnApp?: (clientId: string, clientSecret: string) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* The include/skip position, as every sign-in row on the page carries it:
|
|
41
|
+
* what the agent may use. With `onToggle`, the card shows the same control
|
|
42
|
+
* the rows do; a skipped card is greyed and offers Include and nothing else.
|
|
43
|
+
*/
|
|
44
|
+
on?: boolean;
|
|
45
|
+
onToggle?: () => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function ManagedConnectorCard({ o, busy, onConnect, onDisconnect, onOwnApp, on = true, onToggle }: ManagedConnectorCardProps) {
|
|
49
|
+
const m = o.managed;
|
|
50
|
+
const state = managedCardState(o);
|
|
51
|
+
const skipped = onToggle !== undefined && !on;
|
|
52
|
+
const badge = skipped ? { text: 'Skipped', tone: 'outline' as const } : STATE_BADGE[state];
|
|
53
|
+
const dim = skipped || state === 'unavailable' || state === 'owner-only';
|
|
54
|
+
// Connect and Reconnect need a way to open a sign-in (the broker, or an
|
|
55
|
+
// owner's own app) and a reader allowed to; Disconnect needs only a
|
|
56
|
+
// stored token the reader may remove. `ownerOnly` is the server's word on
|
|
57
|
+
// the second part, in every state: a reader sees a workspace connection's
|
|
58
|
+
// state and none of its controls.
|
|
59
|
+
const canStart = canStartSignIn(o) && !o.ownerOnly;
|
|
60
|
+
const canDisconnect = o.authorized && !o.ownerOnly;
|
|
61
|
+
const shared = m.tokenScope === 'shared';
|
|
62
|
+
const [ownAppOpen, setOwnAppOpen] = useState(false);
|
|
63
|
+
return (
|
|
64
|
+
<Surface tone="surface" radius="xl" elevation="card" padded data-testid={`connector-${m.connectorId}`}>
|
|
65
|
+
<div className="flex items-center gap-2.5">
|
|
66
|
+
{onToggle && <IncludeToggle on={on} busy={busy} onChange={onToggle} />}
|
|
67
|
+
<ToolLogo slug={o.slug} name={m.displayName} className={cn(dim ? 'grayscale' : undefined)} />
|
|
68
|
+
<Link
|
|
69
|
+
to={pathForTool(o.slug)}
|
|
70
|
+
aria-label={`Open ${m.displayName}`}
|
|
71
|
+
className={cn('truncate text-ui font-semibold hover:underline', dim ? 'text-ink-faint' : 'text-ink')}
|
|
72
|
+
>
|
|
73
|
+
{m.displayName}
|
|
74
|
+
</Link>
|
|
75
|
+
<Badge tone={badge.tone} size="xs" className="shrink-0">
|
|
76
|
+
{!skipped && state === 'connected' && m.account ? `Signed in as ${m.account}` : badge.text}
|
|
77
|
+
</Badge>
|
|
78
|
+
<span className="ml-auto flex shrink-0 items-center gap-1.5">
|
|
79
|
+
{skipped ? (
|
|
80
|
+
// Put back the way a skipped row is: the box beside the name does
|
|
81
|
+
// the same, and an unticked box in a greyed card reads as a record
|
|
82
|
+
// of what happened, not as the way to undo it.
|
|
83
|
+
<Button variant="outline" size="tiny" disabled={busy} onClick={onToggle}>
|
|
84
|
+
Include
|
|
85
|
+
</Button>
|
|
86
|
+
) : (
|
|
87
|
+
<>
|
|
88
|
+
{canDisconnect && (
|
|
89
|
+
<Button variant="quiet" size="tiny" disabled={busy} onClick={onDisconnect}>
|
|
90
|
+
Disconnect
|
|
91
|
+
</Button>
|
|
92
|
+
)}
|
|
93
|
+
{canStart && (
|
|
94
|
+
<Button variant={state === 'connected' ? 'outline' : 'primary'} size="tiny" disabled={busy} onClick={onConnect}>
|
|
95
|
+
{state === 'connected' || state === 'needs-reconnect' ? 'Reconnect' : 'Connect'}
|
|
96
|
+
</Button>
|
|
97
|
+
)}
|
|
98
|
+
</>
|
|
99
|
+
)}
|
|
100
|
+
</span>
|
|
101
|
+
</div>
|
|
102
|
+
<p className="mt-2 text-detail text-ink-muted">{m.description}</p>
|
|
103
|
+
{m.permissions.length > 0 && (
|
|
104
|
+
<ul className="mt-2 list-disc pl-5 text-detail text-ink-muted">
|
|
105
|
+
{m.permissions.map((p) => (
|
|
106
|
+
<li key={p}>{p}</li>
|
|
107
|
+
))}
|
|
108
|
+
</ul>
|
|
109
|
+
)}
|
|
110
|
+
<p className="mt-2 text-detail text-ink-faint">
|
|
111
|
+
{shared ? 'One connection for the whole workspace, made by a tool owner.' : 'You connect your own account.'}
|
|
112
|
+
{/* Why a sign-in cannot start here, each cause in its own words: a
|
|
113
|
+
workspace connection with an own app pinned is refused that app,
|
|
114
|
+
which only the owner can remove; no broker is the admin's to fix. */}
|
|
115
|
+
{!canStartSignIn(o) &&
|
|
116
|
+
(shared && m.ownApp
|
|
117
|
+
? ' This workspace connection has your organisation’s own app pinned, which it cannot use: a tool owner removes the client secret to connect it through the managed connector.'
|
|
118
|
+
: ' This deployment is not connected to a connector broker yet; ask your admin.')}
|
|
119
|
+
{m.ownApp && !shared && ' Signing in through your organisation’s own app.'}
|
|
120
|
+
</p>
|
|
121
|
+
{onOwnApp && (
|
|
122
|
+
<div className="mt-2">
|
|
123
|
+
{ownAppOpen ? (
|
|
124
|
+
<OwnAppForm
|
|
125
|
+
onCancel={() => setOwnAppOpen(false)}
|
|
126
|
+
onSave={async (id, secret) => {
|
|
127
|
+
await onOwnApp(id, secret);
|
|
128
|
+
setOwnAppOpen(false);
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
) : (
|
|
132
|
+
<Button variant="quiet" size="tiny" onClick={() => setOwnAppOpen(true)}>
|
|
133
|
+
{m.ownApp ? 'Replace our own app' : 'Use our own app instead'}
|
|
134
|
+
</Button>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
</Surface>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* "Use our own app": a regulated customer registers its own OAuth app with
|
|
144
|
+
* the provider (redirect URI: this deployment's `/api/secrets/oauth/callback`)
|
|
145
|
+
* and pins it here. From then on the sign-in runs from this deployment, not
|
|
146
|
+
* the broker. Write-only, like every secret field on this page.
|
|
147
|
+
*/
|
|
148
|
+
function OwnAppForm({
|
|
149
|
+
onSave,
|
|
150
|
+
onCancel,
|
|
151
|
+
}: {
|
|
152
|
+
onSave: (clientId: string, clientSecret: string) => Promise<void>;
|
|
153
|
+
onCancel: () => void;
|
|
154
|
+
}) {
|
|
155
|
+
const [clientId, setClientId] = useState('');
|
|
156
|
+
const [secret, setSecret] = useState('');
|
|
157
|
+
const [busy, setBusy] = useState(false);
|
|
158
|
+
const [error, setError] = useState<string | null>(null);
|
|
159
|
+
return (
|
|
160
|
+
<div className="flex flex-col gap-1.5">
|
|
161
|
+
<p className="text-detail text-ink-muted">
|
|
162
|
+
Register an OAuth app with the provider using this deployment's redirect URI
|
|
163
|
+
(<code>/api/secrets/oauth/callback</code>), then enter its client id and secret.
|
|
164
|
+
</p>
|
|
165
|
+
<div className="flex items-center gap-2">
|
|
166
|
+
<TextField value={clientId} onChange={(e) => setClientId(e.target.value)} placeholder="Client id" aria-label="Client id" className="w-44" />
|
|
167
|
+
<TextField type="password" value={secret} onChange={(e) => setSecret(e.target.value)} placeholder="Client secret" aria-label="Client secret" className="w-44" />
|
|
168
|
+
<Button
|
|
169
|
+
variant="primary"
|
|
170
|
+
size="sm"
|
|
171
|
+
disabled={busy || !clientId.trim() || !secret.trim()}
|
|
172
|
+
onClick={() => {
|
|
173
|
+
setBusy(true);
|
|
174
|
+
setError(null);
|
|
175
|
+
onSave(clientId.trim(), secret.trim())
|
|
176
|
+
.catch((err) => setError(err instanceof Error ? err.message : String(err)))
|
|
177
|
+
.finally(() => setBusy(false));
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
Save
|
|
181
|
+
</Button>
|
|
182
|
+
<Button variant="quiet" size="sm" disabled={busy} onClick={onCancel}>
|
|
183
|
+
Cancel
|
|
184
|
+
</Button>
|
|
185
|
+
</div>
|
|
186
|
+
{error && <p className="text-detail text-danger">{error}</p>}
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import type { ConnectPending, ConnectToolOAuth } from '../../services/connect.api';
|
|
5
|
+
import { AppRegistryContext, makeRegistry, type ConnectPanelProps } from '../../../../core/registry';
|
|
6
|
+
import { ConnectToolsPage } from '../ConnectToolsPage';
|
|
7
|
+
import { TOOL_CREDENTIALS_STALE_EVENT } from '../../../../core/events';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The managed-connector half of the Connect page, at the page boundary: the
|
|
11
|
+
* distribution's panel at the foot of the page and what it may ask of the
|
|
12
|
+
* page, and a Disconnect that goes to the row the connection lives on — the
|
|
13
|
+
* caller's for a personal sign-in, the shared one for a workspace connection.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const connectMock = vi.hoisted(() => ({
|
|
17
|
+
getConnectPending: vi.fn(),
|
|
18
|
+
startToolOAuth: vi.fn(),
|
|
19
|
+
getMcpOAuthRequest: vi.fn(),
|
|
20
|
+
completeMcpOAuth: vi.fn(),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('../../services/connect.api', () => connectMock);
|
|
23
|
+
|
|
24
|
+
const varsMock = vi.hoisted(() => ({
|
|
25
|
+
setUserVar: vi.fn(),
|
|
26
|
+
setAdminVar: vi.fn(),
|
|
27
|
+
deleteUserVar: vi.fn(),
|
|
28
|
+
deleteAdminVar: vi.fn(),
|
|
29
|
+
setOAuthClientSecret: vi.fn(),
|
|
30
|
+
checkToolConnection: vi.fn(),
|
|
31
|
+
}));
|
|
32
|
+
vi.mock('../../services/tool-secrets.api', () => varsMock);
|
|
33
|
+
vi.mock('../../services/secrets.api', () => ({ startOAuth: vi.fn() }));
|
|
34
|
+
|
|
35
|
+
/** A managed sign-in row as `/connect/pending` sends it. */
|
|
36
|
+
function managedRow(over: Partial<ConnectToolOAuth> = {}, card: Partial<NonNullable<ConnectToolOAuth['managed']>> = {}): ConnectToolOAuth {
|
|
37
|
+
return {
|
|
38
|
+
slug: 'microsoft365',
|
|
39
|
+
varName: 'ACCESS_TOKEN',
|
|
40
|
+
toolName: 'microsoft365',
|
|
41
|
+
key: 'microsoft365_ACCESS_TOKEN',
|
|
42
|
+
label: 'Microsoft 365 sign-in',
|
|
43
|
+
authorized: true,
|
|
44
|
+
needsReauth: false,
|
|
45
|
+
ownerConfigured: true,
|
|
46
|
+
ownerOnly: false,
|
|
47
|
+
canWrite: false,
|
|
48
|
+
managed: {
|
|
49
|
+
connectorId: 'microsoft365',
|
|
50
|
+
scopeSet: 'read',
|
|
51
|
+
tokenScope: 'user',
|
|
52
|
+
displayName: 'Microsoft 365',
|
|
53
|
+
icon: 'Mail',
|
|
54
|
+
description: 'Lets Hexis read your mail.',
|
|
55
|
+
permissions: ['Read your mail.'],
|
|
56
|
+
scopeSetLabel: 'Read',
|
|
57
|
+
dataResidency: 'EU',
|
|
58
|
+
subprocessor: 'Microsoft',
|
|
59
|
+
account: 'alice@acme.example',
|
|
60
|
+
ownApp: false,
|
|
61
|
+
available: true,
|
|
62
|
+
...card,
|
|
63
|
+
},
|
|
64
|
+
...over,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const workspaceRow = () =>
|
|
69
|
+
managedRow(
|
|
70
|
+
{ slug: 'hubspot', varName: 'ACCESS_TOKEN', toolName: 'hubspot', key: 'hubspot_ACCESS_TOKEN', label: 'HubSpot sign-in', canWrite: true },
|
|
71
|
+
{ connectorId: 'hubspot', tokenScope: 'shared', displayName: 'HubSpot', account: 'acme.hubspot.com' },
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const listing = (...toolOAuth: ConnectToolOAuth[]): ConnectPending => ({ tools: [], oauth: [], toolOAuth });
|
|
75
|
+
|
|
76
|
+
const heard = vi.fn();
|
|
77
|
+
|
|
78
|
+
function renderPage(panel?: React.ComponentType<ConnectPanelProps>) {
|
|
79
|
+
const page = (
|
|
80
|
+
<MemoryRouter>
|
|
81
|
+
<ConnectToolsPage />
|
|
82
|
+
</MemoryRouter>
|
|
83
|
+
);
|
|
84
|
+
return render(panel ? <AppRegistryContext.Provider value={makeRegistry({ connectPanel: panel })}>{page}</AppRegistryContext.Provider> : page);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The connector's card, once the list that carries it has landed. */
|
|
88
|
+
const card = async (connectorId: string) => within(await screen.findByTestId(`connector-${connectorId}`));
|
|
89
|
+
|
|
90
|
+
beforeEach(() => {
|
|
91
|
+
window.history.replaceState(null, '', '/skills-and-tools/connect');
|
|
92
|
+
sessionStorage.clear();
|
|
93
|
+
heard.mockReset();
|
|
94
|
+
connectMock.getConnectPending.mockReset().mockResolvedValue(listing());
|
|
95
|
+
connectMock.getMcpOAuthRequest.mockReset();
|
|
96
|
+
varsMock.deleteUserVar.mockReset().mockResolvedValue(undefined);
|
|
97
|
+
varsMock.deleteAdminVar.mockReset().mockResolvedValue(undefined);
|
|
98
|
+
varsMock.checkToolConnection.mockReset();
|
|
99
|
+
window.addEventListener(TOOL_CREDENTIALS_STALE_EVENT, heard);
|
|
100
|
+
});
|
|
101
|
+
afterEach(() => window.removeEventListener(TOOL_CREDENTIALS_STALE_EVENT, heard));
|
|
102
|
+
|
|
103
|
+
describe('ConnectToolsPage: the distribution’s panel at the foot of the page', () => {
|
|
104
|
+
function Panel({ onChanged }: ConnectPanelProps) {
|
|
105
|
+
return <button onClick={onChanged}>Enable HubSpot</button>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
it('renders the registered panel once the list has loaded, and for a reader with nothing else to set up', async () => {
|
|
109
|
+
let answer!: (p: ConnectPending) => void;
|
|
110
|
+
connectMock.getConnectPending.mockReturnValue(new Promise<ConnectPending>((resolve) => (answer = resolve)));
|
|
111
|
+
renderPage(Panel);
|
|
112
|
+
// Not while the page still says "Loading…": the panel lands with the lists.
|
|
113
|
+
expect(screen.queryByRole('button', { name: 'Enable HubSpot' })).toBeNull();
|
|
114
|
+
answer(listing());
|
|
115
|
+
expect(await screen.findByRole('button', { name: 'Enable HubSpot' })).toBeInTheDocument();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('renders no panel when none is registered', async () => {
|
|
119
|
+
renderPage();
|
|
120
|
+
await screen.findByRole('heading', { name: 'Connect your tools' });
|
|
121
|
+
await waitFor(() => expect(screen.queryByText('Loading…')).toBeNull());
|
|
122
|
+
expect(screen.queryByRole('button', { name: 'Enable HubSpot' })).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('a change the panel reports is announced and the list fetched again, quietly', async () => {
|
|
126
|
+
renderPage(Panel);
|
|
127
|
+
const enable = await screen.findByRole('button', { name: 'Enable HubSpot' });
|
|
128
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenCalledTimes(1));
|
|
129
|
+
// The next listing (what the panel enabled) is held open, so the page's
|
|
130
|
+
// state WHILE it refetches is observable, not only the state after.
|
|
131
|
+
let answer!: (p: ConnectPending) => void;
|
|
132
|
+
connectMock.getConnectPending.mockReturnValue(new Promise<ConnectPending>((resolve) => (answer = resolve)));
|
|
133
|
+
fireEvent.click(enable);
|
|
134
|
+
await waitFor(() => expect(heard).toHaveBeenCalledTimes(1));
|
|
135
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenCalledTimes(2));
|
|
136
|
+
// Quietly: mid-refetch the page has not dropped to "Loading…", and the
|
|
137
|
+
// panel that asked is still mounted.
|
|
138
|
+
expect(screen.queryByText('Loading…')).toBeNull();
|
|
139
|
+
expect(screen.getByRole('button', { name: 'Enable HubSpot' })).toBeInTheDocument();
|
|
140
|
+
answer(listing(workspaceRow()));
|
|
141
|
+
expect(await screen.findByTestId('connector-hubspot')).toBeInTheDocument();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('ConnectToolsPage: skipping a managed connector, as any sign-in row can be skipped', () => {
|
|
146
|
+
it('a personal sign-in skipped has its token removed like a row’s, reads Skipped, and comes back with Include', async () => {
|
|
147
|
+
connectMock.getConnectPending.mockResolvedValue(listing(managedRow({ authorized: true })));
|
|
148
|
+
renderPage();
|
|
149
|
+
fireEvent.click((await card('microsoft365')).getByRole('checkbox', { name: /Skip this tool/ }));
|
|
150
|
+
await waitFor(() => expect(varsMock.deleteUserVar).toHaveBeenCalledWith('microsoft365', 'ACCESS_TOKEN'));
|
|
151
|
+
expect(varsMock.deleteAdminVar).not.toHaveBeenCalled();
|
|
152
|
+
expect(await (await card('microsoft365')).findByText('Skipped')).toBeInTheDocument();
|
|
153
|
+
fireEvent.click((await card('microsoft365')).getByRole('button', { name: 'Include' }));
|
|
154
|
+
await waitFor(() => expect(screen.getByTestId('connector-microsoft365')).not.toHaveTextContent('Skipped'));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('a workspace connection offers no skip: it is everyone’s, and nothing could take it out of one agent’s connection', async () => {
|
|
158
|
+
connectMock.getConnectPending.mockResolvedValue(listing(workspaceRow()));
|
|
159
|
+
renderPage();
|
|
160
|
+
const hubspot = await card('hubspot');
|
|
161
|
+
expect(hubspot.queryByRole('checkbox')).toBeNull();
|
|
162
|
+
expect(hubspot.queryByText('Skipped')).toBeNull();
|
|
163
|
+
expect(varsMock.deleteAdminVar).not.toHaveBeenCalled();
|
|
164
|
+
expect(varsMock.deleteUserVar).not.toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('ConnectToolsPage: disconnecting a managed sign-in', () => {
|
|
169
|
+
it('a personal sign-in is removed from the caller’s row, announced, and the list fetched again', async () => {
|
|
170
|
+
let answer!: (p: ConnectPending) => void;
|
|
171
|
+
connectMock.getConnectPending
|
|
172
|
+
.mockResolvedValueOnce(listing(managedRow()))
|
|
173
|
+
.mockReturnValue(new Promise<ConnectPending>((resolve) => (answer = resolve)));
|
|
174
|
+
renderPage();
|
|
175
|
+
fireEvent.click((await card('microsoft365')).getByRole('button', { name: 'Disconnect' }));
|
|
176
|
+
await waitFor(() => expect(varsMock.deleteUserVar).toHaveBeenCalledWith('microsoft365', 'ACCESS_TOKEN'));
|
|
177
|
+
expect(varsMock.deleteAdminVar).not.toHaveBeenCalled();
|
|
178
|
+
await waitFor(() => expect(heard).toHaveBeenCalledTimes(1));
|
|
179
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenCalledTimes(2));
|
|
180
|
+
// Quietly: mid-refetch the card is still on the page and nothing says "Loading…".
|
|
181
|
+
expect(screen.queryByText('Loading…')).toBeNull();
|
|
182
|
+
expect(screen.getByTestId('connector-microsoft365')).toBeInTheDocument();
|
|
183
|
+
answer(listing(managedRow({ authorized: false }, { account: null })));
|
|
184
|
+
// The refetched row: nothing stored any more.
|
|
185
|
+
expect(await (await card('microsoft365')).findByText('Ready to connect')).toBeInTheDocument();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('a workspace connection is removed from the shared row, by a writer, and the list fetched again', async () => {
|
|
189
|
+
connectMock.getConnectPending
|
|
190
|
+
.mockResolvedValueOnce(listing(workspaceRow()))
|
|
191
|
+
.mockResolvedValue(listing({ ...workspaceRow(), authorized: false, managed: { ...workspaceRow().managed!, account: null } }));
|
|
192
|
+
renderPage();
|
|
193
|
+
fireEvent.click((await card('hubspot')).getByRole('button', { name: 'Disconnect' }));
|
|
194
|
+
await waitFor(() => expect(varsMock.deleteAdminVar).toHaveBeenCalledWith('hubspot', 'ACCESS_TOKEN'));
|
|
195
|
+
expect(varsMock.deleteUserVar).not.toHaveBeenCalled();
|
|
196
|
+
await waitFor(() => expect(heard).toHaveBeenCalledTimes(1));
|
|
197
|
+
await waitFor(() => expect(connectMock.getConnectPending).toHaveBeenCalledTimes(2));
|
|
198
|
+
expect(await (await card('hubspot')).findByText('Ready to connect')).toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('a disconnect the server refuses is shown, announces nothing, and leaves the card usable', async () => {
|
|
202
|
+
connectMock.getConnectPending.mockResolvedValue(listing(managedRow()));
|
|
203
|
+
varsMock.deleteUserVar.mockRejectedValue(new Error('Nope.'));
|
|
204
|
+
renderPage();
|
|
205
|
+
const disconnect = (await card('microsoft365')).getByRole('button', { name: 'Disconnect' });
|
|
206
|
+
fireEvent.click(disconnect);
|
|
207
|
+
expect(await screen.findByText('Nope.')).toBeInTheDocument();
|
|
208
|
+
expect(heard).not.toHaveBeenCalled();
|
|
209
|
+
expect(connectMock.getConnectPending).toHaveBeenCalledTimes(1);
|
|
210
|
+
await waitFor(() => expect(disconnect).toBeEnabled());
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -555,6 +555,16 @@ describe('ConnectToolsPage: inside Skills & Tools', () => {
|
|
|
555
555
|
expect(await within(group).findByRole('radio', { name: /ops.*Watches the dashboards\./ })).not.toBeChecked();
|
|
556
556
|
});
|
|
557
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
|
+
|
|
558
568
|
it('says when the agents could not be loaded, and approves Everything only once that is confirmed', async () => {
|
|
559
569
|
connectMock.getMcpOAuthRequest.mockResolvedValue({
|
|
560
570
|
clientName: 'Claude',
|