@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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import { ManagedConnectorCard } from '../ManagedConnectorCard';
|
|
5
|
+
import { managedCardState, type ManagedToolOAuth } from '../../utils/managed-card-state';
|
|
6
|
+
|
|
7
|
+
/** A managed sign-in row as `/connect/pending` sends it, with the parts under test overridden. */
|
|
8
|
+
function row(over: Partial<ManagedToolOAuth> = {}, managedOver: Partial<ManagedToolOAuth['managed']> = {}): ManagedToolOAuth {
|
|
9
|
+
return {
|
|
10
|
+
slug: 'microsoft365',
|
|
11
|
+
varName: 'ACCESS_TOKEN',
|
|
12
|
+
toolName: 'microsoft365',
|
|
13
|
+
key: 'microsoft365_ACCESS_TOKEN',
|
|
14
|
+
label: 'Microsoft 365 sign-in',
|
|
15
|
+
authorized: false,
|
|
16
|
+
needsReauth: false,
|
|
17
|
+
ownerConfigured: true,
|
|
18
|
+
ownerOnly: false,
|
|
19
|
+
canWrite: false,
|
|
20
|
+
managed: {
|
|
21
|
+
connectorId: 'microsoft365',
|
|
22
|
+
scopeSet: 'read',
|
|
23
|
+
tokenScope: 'user',
|
|
24
|
+
displayName: 'Microsoft 365',
|
|
25
|
+
icon: 'Mail',
|
|
26
|
+
description: 'Lets Hexis read your mail.',
|
|
27
|
+
permissions: ['Read your mail.'],
|
|
28
|
+
scopeSetLabel: 'Read',
|
|
29
|
+
dataResidency: 'EU',
|
|
30
|
+
subprocessor: 'Microsoft',
|
|
31
|
+
account: null,
|
|
32
|
+
ownApp: false,
|
|
33
|
+
available: true,
|
|
34
|
+
...managedOver,
|
|
35
|
+
},
|
|
36
|
+
...over,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('the state a managed connector card shows', () => {
|
|
41
|
+
it.each([
|
|
42
|
+
['ready', row()],
|
|
43
|
+
['connected', row({ authorized: true })],
|
|
44
|
+
['needs-reconnect', row({ authorized: true, needsReauth: true })],
|
|
45
|
+
['unavailable', row({}, { available: false })],
|
|
46
|
+
// A stored token still works while the broker is unreachable: the card
|
|
47
|
+
// says so, and withholds the buttons that would need the broker.
|
|
48
|
+
['connected', row({ authorized: true }, { available: false })],
|
|
49
|
+
['owner-only', row({ ownerOnly: true })],
|
|
50
|
+
// What is stored comes before who may change it: a workspace connection
|
|
51
|
+
// an owner made is connected for its readers too, and one that fell
|
|
52
|
+
// under-scoped needs a reconnect whoever has to make it.
|
|
53
|
+
['connected', row({ authorized: true, ownerOnly: true }, { tokenScope: 'shared' })],
|
|
54
|
+
['needs-reconnect', row({ authorized: true, needsReauth: true, ownerOnly: true }, { tokenScope: 'shared' })],
|
|
55
|
+
// An owner's own app makes the deployment's own flow apply: no broker needed.
|
|
56
|
+
['ready', row({}, { available: false, ownApp: true })],
|
|
57
|
+
] as const)('%s', (expected, o) => {
|
|
58
|
+
expect(managedCardState(o)).toBe(expected);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('ManagedConnectorCard', () => {
|
|
63
|
+
const renderCard = (
|
|
64
|
+
o: ManagedToolOAuth,
|
|
65
|
+
handlers: Partial<{ onConnect: () => void; onDisconnect: () => void; onOwnApp: (id: string, secret: string) => Promise<void> }> = {},
|
|
66
|
+
) =>
|
|
67
|
+
render(
|
|
68
|
+
<MemoryRouter>
|
|
69
|
+
<ManagedConnectorCard
|
|
70
|
+
o={o}
|
|
71
|
+
busy={false}
|
|
72
|
+
onConnect={handlers.onConnect ?? vi.fn()}
|
|
73
|
+
onDisconnect={handlers.onDisconnect ?? vi.fn()}
|
|
74
|
+
onOwnApp={handlers.onOwnApp}
|
|
75
|
+
/>
|
|
76
|
+
</MemoryRouter>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
it('offers Connect when nothing is stored, and says what the connector may do', () => {
|
|
80
|
+
const onConnect = vi.fn();
|
|
81
|
+
renderCard(row(), { onConnect });
|
|
82
|
+
expect(screen.getByText('Ready to connect')).toBeInTheDocument();
|
|
83
|
+
expect(screen.getByText('Read your mail.')).toBeInTheDocument();
|
|
84
|
+
fireEvent.click(screen.getByRole('button', { name: 'Connect' }));
|
|
85
|
+
expect(onConnect).toHaveBeenCalledTimes(1);
|
|
86
|
+
expect(screen.queryByRole('button', { name: 'Disconnect' })).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('shows who is signed in, with Reconnect and Disconnect', () => {
|
|
90
|
+
const onDisconnect = vi.fn();
|
|
91
|
+
renderCard(row({ authorized: true }, { account: 'alice@acme.example' }), { onDisconnect });
|
|
92
|
+
// "Signed in", never "Connected": the page says Connected only after a real call.
|
|
93
|
+
expect(screen.getByText('Signed in as alice@acme.example')).toBeInTheDocument();
|
|
94
|
+
expect(screen.queryByText(/Connected/)).toBeNull();
|
|
95
|
+
fireEvent.click(screen.getByRole('button', { name: 'Disconnect' }));
|
|
96
|
+
expect(onDisconnect).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(screen.getByRole('button', { name: 'Reconnect' })).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('says Needs reconnect when the token no longer covers the tool', () => {
|
|
101
|
+
renderCard(row({ authorized: true, needsReauth: true }));
|
|
102
|
+
expect(screen.getByText('Needs reconnect')).toBeInTheDocument();
|
|
103
|
+
expect(screen.getByRole('button', { name: 'Reconnect' })).toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('offers nothing to press while the deployment has no broker, and names the admin’s job', () => {
|
|
107
|
+
renderCard(row({}, { available: false }));
|
|
108
|
+
expect(screen.getByText('Not available yet')).toBeInTheDocument();
|
|
109
|
+
expect(screen.queryByRole('button', { name: /Connect/ })).toBeNull();
|
|
110
|
+
expect(screen.getByText(/not connected to a connector broker yet/)).toBeInTheDocument();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('keeps a stored token usable while the broker is unreachable: Disconnect stays, Reconnect goes', () => {
|
|
114
|
+
renderCard(row({ authorized: true }, { available: false, account: 'alice@acme.example' }));
|
|
115
|
+
expect(screen.getByText('Signed in as alice@acme.example')).toBeInTheDocument();
|
|
116
|
+
expect(screen.getByRole('button', { name: 'Disconnect' })).toBeInTheDocument();
|
|
117
|
+
expect(screen.queryByRole('button', { name: /Reconnect|Connect/ })).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('a workspace connection a reader cannot make is greyed as needing an owner', () => {
|
|
121
|
+
renderCard(row({ ownerOnly: true }, { tokenScope: 'shared' }));
|
|
122
|
+
expect(screen.getByText('Needs an owner')).toBeInTheDocument();
|
|
123
|
+
expect(screen.getByText(/One connection for the whole workspace/)).toBeInTheDocument();
|
|
124
|
+
expect(screen.queryByRole('button', { name: /Connect/ })).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('a workspace connection an owner made reads as signed in to a reader, who gets no control over it', () => {
|
|
128
|
+
renderCard(row({ authorized: true, ownerOnly: true }, { tokenScope: 'shared', account: 'acme.hubspot.com' }));
|
|
129
|
+
expect(screen.getByText('Signed in as acme.hubspot.com')).toBeInTheDocument();
|
|
130
|
+
expect(screen.queryByText('Needs an owner')).toBeNull();
|
|
131
|
+
expect(screen.queryByRole('button', { name: /^(?:Connect|Reconnect|Disconnect)$/ })).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('an owner can bring the deployment’s own app: the form sends the client id and the secret', async () => {
|
|
135
|
+
const onOwnApp = vi.fn(async () => undefined);
|
|
136
|
+
renderCard(row({ canWrite: true }), { onOwnApp });
|
|
137
|
+
fireEvent.click(screen.getByRole('button', { name: 'Use our own app instead' }));
|
|
138
|
+
fireEvent.change(screen.getByLabelText('Client id'), { target: { value: 'own-client' } });
|
|
139
|
+
fireEvent.change(screen.getByLabelText('Client secret'), { target: { value: 'own-secret' } });
|
|
140
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
141
|
+
await waitFor(() => expect(onOwnApp).toHaveBeenCalledWith('own-client', 'own-secret'));
|
|
142
|
+
// The form closes once the save settled.
|
|
143
|
+
await waitFor(() => expect(screen.queryByLabelText('Client id')).toBeNull());
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('a workspace connection with an own app pinned says so, not that a broker is missing', () => {
|
|
147
|
+
renderCard(row({ canWrite: true }, { tokenScope: 'shared', ownApp: true, available: true }));
|
|
148
|
+
expect(screen.getByText(/own app pinned, which it cannot use/)).toBeInTheDocument();
|
|
149
|
+
expect(screen.queryByText(/not connected to a connector broker/)).toBeNull();
|
|
150
|
+
expect(screen.queryByRole('button', { name: /^(?:Connect|Reconnect)$/ })).toBeNull();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('include/skip, as every sign-in row carries it', () => {
|
|
154
|
+
it('shows the toggle only when the page offers one, and reports a click', () => {
|
|
155
|
+
renderCard(row());
|
|
156
|
+
expect(screen.queryByRole('checkbox')).toBeNull();
|
|
157
|
+
cleanup();
|
|
158
|
+
const onToggle = vi.fn();
|
|
159
|
+
render(
|
|
160
|
+
<MemoryRouter>
|
|
161
|
+
<ManagedConnectorCard o={row({ authorized: true })} busy={false} onConnect={vi.fn()} onDisconnect={vi.fn()} on onToggle={onToggle} />
|
|
162
|
+
</MemoryRouter>,
|
|
163
|
+
);
|
|
164
|
+
fireEvent.click(screen.getByRole('checkbox', { name: /Skip this tool/ }));
|
|
165
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
166
|
+
expect(screen.getByRole('button', { name: 'Reconnect' })).toBeInTheDocument();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('a skipped card is greyed, says so, and offers Include and nothing else', () => {
|
|
170
|
+
const onToggle = vi.fn();
|
|
171
|
+
render(
|
|
172
|
+
<MemoryRouter>
|
|
173
|
+
<ManagedConnectorCard o={row({ authorized: true })} busy={false} onConnect={vi.fn()} onDisconnect={vi.fn()} on={false} onToggle={onToggle} />
|
|
174
|
+
</MemoryRouter>,
|
|
175
|
+
);
|
|
176
|
+
expect(screen.getByText('Skipped')).toBeInTheDocument();
|
|
177
|
+
expect(screen.queryByRole('button', { name: /^(?:Connect|Reconnect|Disconnect)$/ })).toBeNull();
|
|
178
|
+
fireEvent.click(screen.getByRole('button', { name: 'Include' }));
|
|
179
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -109,6 +109,7 @@ describe('SecretsPage', () => {
|
|
|
109
109
|
label: null,
|
|
110
110
|
key: 'heyreach_API_KEY',
|
|
111
111
|
adminConfigured: true,
|
|
112
|
+
adminKind: 'static',
|
|
112
113
|
userConfigured: false,
|
|
113
114
|
},
|
|
114
115
|
],
|
|
@@ -179,6 +180,7 @@ describe('SecretsPage', () => {
|
|
|
179
180
|
label: null,
|
|
180
181
|
key: 'heyreach_API_KEY',
|
|
181
182
|
adminConfigured: true,
|
|
183
|
+
adminKind: 'static',
|
|
182
184
|
userConfigured: false,
|
|
183
185
|
},
|
|
184
186
|
],
|
|
@@ -338,6 +340,7 @@ describe('SecretsPage', () => {
|
|
|
338
340
|
label: null,
|
|
339
341
|
key: 'heyreach_API_KEY',
|
|
340
342
|
adminConfigured: true,
|
|
343
|
+
adminKind: 'static',
|
|
341
344
|
userConfigured: false,
|
|
342
345
|
},
|
|
343
346
|
],
|
|
@@ -11,3 +11,5 @@ export { useSavedKeyProbe } from './probe/useSavedKeyProbe';
|
|
|
11
11
|
export { startToolOAuth } from './services/connect.api';
|
|
12
12
|
export { deleteAdminVar, listToolSecrets, setAdminVar, setOAuthClientSecret, setUserVar } from './services/tool-secrets.api';
|
|
13
13
|
export type { ProbeVerdict, ToolSecrets, ToolVarStatus } from './services/tool-secrets.api';
|
|
14
|
+
/** Whether a managed sign-in can be started from here: the one rule the Connect page and the tool page share. */
|
|
15
|
+
export { canStartSignIn } from './utils/managed-card-state';
|
|
@@ -55,6 +55,36 @@ export interface ConnectOAuth {
|
|
|
55
55
|
authorized: boolean;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* A sign-in that goes through a managed connector: Bevel's own OAuth app, a
|
|
60
|
+
* broker that does the provider round-trip, nothing for the owner to
|
|
61
|
+
* register. What the card shows comes from the connector's definition on the
|
|
62
|
+
* server; what the row can DO is the same Connect / Reconnect / Disconnect as
|
|
63
|
+
* any sign-in, plus "Connected as" once the account is known.
|
|
64
|
+
*/
|
|
65
|
+
export interface ManagedSignIn {
|
|
66
|
+
connectorId: string;
|
|
67
|
+
scopeSet: string;
|
|
68
|
+
/** `user`: each person connects their own account. `shared`: one workspace connection an owner makes. */
|
|
69
|
+
tokenScope: 'user' | 'shared';
|
|
70
|
+
displayName: string;
|
|
71
|
+
/** A lucide icon name. */
|
|
72
|
+
icon: string;
|
|
73
|
+
/** One line: what connecting lets Hexis do. */
|
|
74
|
+
description: string;
|
|
75
|
+
/** Plain-language permissions of the scope set. */
|
|
76
|
+
permissions: string[];
|
|
77
|
+
scopeSetLabel: string;
|
|
78
|
+
dataResidency: string;
|
|
79
|
+
subprocessor: string;
|
|
80
|
+
/** The connected account, once the sign-in reported one. */
|
|
81
|
+
account: string | null;
|
|
82
|
+
/** An owner replaced the managed app with the deployment's own; the ordinary flow applies. */
|
|
83
|
+
ownApp: boolean;
|
|
84
|
+
/** The deployment can start sign-ins through the broker. False ⇒ the admin has setup to do. */
|
|
85
|
+
available: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
58
88
|
/** An OAuth-backed variable declared BY a tool — authorized via the tool-scoped start. */
|
|
59
89
|
export interface ConnectToolOAuth {
|
|
60
90
|
slug: string;
|
|
@@ -63,19 +93,30 @@ export interface ConnectToolOAuth {
|
|
|
63
93
|
key: string;
|
|
64
94
|
label: string | null;
|
|
65
95
|
authorized: boolean;
|
|
96
|
+
/** Present for a managed connector's sign-in — see {@link ManagedSignIn}. */
|
|
97
|
+
managed?: ManagedSignIn;
|
|
98
|
+
/** With `managed`: whether the caller may write the tool (disconnect a shared connection, bring an own app). */
|
|
99
|
+
canWrite?: boolean;
|
|
66
100
|
/**
|
|
67
101
|
* Authorized, but the token's granted permissions no longer cover what the tool
|
|
68
102
|
* declares now (a scope was added since sign-in) — show Reconnect, not Connected.
|
|
69
103
|
*/
|
|
70
104
|
needsReauth: boolean;
|
|
71
105
|
/**
|
|
72
|
-
* The owner-side half is done
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
106
|
+
* The owner-side half is done, so Authorize can actually reach a consent
|
|
107
|
+
* screen: for an ordinary sign-in the provider registration (client secret)
|
|
108
|
+
* exists; for a MANAGED one the deployment can reach its broker, an owner
|
|
109
|
+
* pinned their own app, or a token is already stored. Until it is, nobody's
|
|
110
|
+
* sign-in can work — which is why the row is outstanding even for a person
|
|
111
|
+
* who has nothing to do about it.
|
|
76
112
|
*/
|
|
77
113
|
ownerConfigured: boolean;
|
|
78
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Not the caller's to do: an ordinary sign-in waiting on the registration
|
|
116
|
+
* above that the caller may not write, or a managed WORKSPACE connection
|
|
117
|
+
* (one an owner makes for everyone) seen by someone who may not write the
|
|
118
|
+
* tool.
|
|
119
|
+
*/
|
|
79
120
|
ownerOnly: boolean;
|
|
80
121
|
}
|
|
81
122
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authFetch } from '../../../lib/api';
|
|
2
|
+
import type { ManagedSignIn } from './connect.api';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Per-tool secrets API. A `.tool` manual declares which `${VAR}`s are set by the
|
|
@@ -17,6 +18,13 @@ export interface ToolVarStatus {
|
|
|
17
18
|
key: string;
|
|
18
19
|
/** A shared (admin) value exists. */
|
|
19
20
|
adminConfigured: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* What the shared row IS: a sign-in needs an `oauth` one, not a key left
|
|
23
|
+
* from when the variable was static. `null` when there is no shared row.
|
|
24
|
+
* The server always sends it; a consumer tests for `'oauth'` and never for
|
|
25
|
+
* "not static", which a missing field would satisfy.
|
|
26
|
+
*/
|
|
27
|
+
adminKind?: 'static' | 'oauth' | null;
|
|
20
28
|
/** The caller's own value exists. */
|
|
21
29
|
userConfigured: boolean;
|
|
22
30
|
/** This variable is filled by an OAuth sign-in, not a typed value. */
|
|
@@ -27,6 +35,8 @@ export interface ToolVarStatus {
|
|
|
27
35
|
needsReauth?: boolean;
|
|
28
36
|
/** For an oauth var: the declared scopes the token was NOT granted (what it can't do). */
|
|
29
37
|
missingScopes?: string[];
|
|
38
|
+
/** For a managed connector's sign-in: the card the Connect page shows (see `ManagedSignIn`). */
|
|
39
|
+
managed?: ManagedSignIn;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
/**
|
|
@@ -118,15 +128,23 @@ async function deleteVar(slug: string, varName: string, tier: ToolVarScope): Pro
|
|
|
118
128
|
* Store the confidential OAuth CLIENT SECRET for a tool's declared sign-in
|
|
119
129
|
* provider — the owner-side half of a manual OAuth setup. Requires write access
|
|
120
130
|
* to the `.tool`; the public provider config is pinned server-side from the
|
|
121
|
-
* file's own `oauth` declaration.
|
|
131
|
+
* file's own `oauth` declaration. A MANAGED declaration names no client, so
|
|
132
|
+
* the caller's `clientId` is used then: the deployment's own app, replacing
|
|
133
|
+
* the managed one.
|
|
122
134
|
*/
|
|
123
|
-
export async function setOAuthClientSecret(
|
|
135
|
+
export async function setOAuthClientSecret(
|
|
136
|
+
slug: string,
|
|
137
|
+
varName: string,
|
|
138
|
+
clientSecret: string,
|
|
139
|
+
/** For a managed sign-in only: the deployment's OWN app, replacing the managed one ("use our own app"). */
|
|
140
|
+
clientId?: string,
|
|
141
|
+
): Promise<void> {
|
|
124
142
|
const res = await authFetch(
|
|
125
143
|
`/api/secrets/tools/${encodeURIComponent(slug)}/vars/${encodeURIComponent(varName)}/oauth/admin`,
|
|
126
144
|
{
|
|
127
145
|
method: 'PUT',
|
|
128
146
|
headers: { 'Content-Type': 'application/json' },
|
|
129
|
-
body: JSON.stringify({ clientSecret }),
|
|
147
|
+
body: JSON.stringify(clientId ? { clientSecret, clientId } : { clientSecret }),
|
|
130
148
|
},
|
|
131
149
|
);
|
|
132
150
|
if (!res.ok) await unwrap(res, "Couldn't save the client secret.");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ConnectToolOAuth, ManagedSignIn } from '../services/connect.api';
|
|
2
|
+
|
|
3
|
+
/** A sign-in row that IS managed: the card's input, narrowed once where rows are filtered. */
|
|
4
|
+
export type ManagedToolOAuth = ConnectToolOAuth & { managed: ManagedSignIn };
|
|
5
|
+
|
|
6
|
+
export function isManagedRow(o: ConnectToolOAuth): o is ManagedToolOAuth {
|
|
7
|
+
return o.managed != null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The state a managed connector card shows, in the Library's vocabulary:
|
|
12
|
+
* - connected a token is stored (the card adds the account when known)
|
|
13
|
+
* - needs-reconnect stored, but it no longer covers what the tool asks for
|
|
14
|
+
* - unavailable nothing stored, and no way to open a sign-in from here (the admin's job)
|
|
15
|
+
* - owner-only nothing stored, and it is a workspace connection a reader cannot make
|
|
16
|
+
* - ready nothing stored yet
|
|
17
|
+
*
|
|
18
|
+
* What is STORED comes first, whoever may change it: a workspace connection
|
|
19
|
+
* an owner made is connected for every reader of the tool, and telling a
|
|
20
|
+
* reader it "needs an owner" would contradict the tool working for them.
|
|
21
|
+
* Who may press what is `ownerOnly`'s to decide, on the card.
|
|
22
|
+
*
|
|
23
|
+
* A stored token is reported as such even while the broker is unreachable:
|
|
24
|
+
* what is stored still works, and the card withholds Connect and Reconnect
|
|
25
|
+
* instead (see `canStartSignIn`). The `connected` state means a token is
|
|
26
|
+
* STORED, the same claim every sign-in row on the Connect page makes, and the
|
|
27
|
+
* card says "Signed in" for it; "Connected" is the word for a call that
|
|
28
|
+
* worked, which is proved elsewhere.
|
|
29
|
+
*/
|
|
30
|
+
export type ManagedCardState = 'unavailable' | 'owner-only' | 'ready' | 'connected' | 'needs-reconnect';
|
|
31
|
+
|
|
32
|
+
export function managedCardState(o: ManagedToolOAuth): ManagedCardState {
|
|
33
|
+
if (o.authorized) return o.needsReauth ? 'needs-reconnect' : 'connected';
|
|
34
|
+
if (!canStartSignIn(o)) return 'unavailable';
|
|
35
|
+
if (o.ownerOnly) return 'owner-only';
|
|
36
|
+
return 'ready';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether a sign-in can be opened from this deployment. A personal one goes
|
|
41
|
+
* through the broker, or through an owner's own app pinned in its place. A
|
|
42
|
+
* WORKSPACE connection goes through the broker alone: an owner's own app
|
|
43
|
+
* would sign the owner in to their own row, which nobody reads for it, so
|
|
44
|
+
* that combination is not offered (the server refuses it too).
|
|
45
|
+
*
|
|
46
|
+
* The one rule for WHETHER a start can be opened here, shared by every
|
|
47
|
+
* surface that offers Connect, Reconnect or Sign in on a managed sign-in
|
|
48
|
+
* (the Connect page's card, the tool page's row). It does not say WHO may
|
|
49
|
+
* make it: each surface also checks that (`ownerOnly`, `mayAct`), and a
|
|
50
|
+
* reader of an available workspace connection passes this rule and is
|
|
51
|
+
* refused the start all the same.
|
|
52
|
+
*/
|
|
53
|
+
export function canStartSignIn(o: { managed: ManagedSignIn }): boolean {
|
|
54
|
+
if (o.managed.tokenScope === 'shared') return o.managed.available && !o.managed.ownApp;
|
|
55
|
+
return o.managed.ownApp || o.managed.available;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether "use our own app" is offered: a writer, on a personal connection (see `canStartSignIn`). */
|
|
59
|
+
export function canBringOwnApp(o: ManagedToolOAuth): boolean {
|
|
60
|
+
return o.canWrite === true && o.managed.tokenScope === 'user';
|
|
61
|
+
}
|
|
@@ -65,8 +65,12 @@ describe('isRootFolderSuggestion', () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('holds back names the save would refuse: dot-folders and the reserved roots', () => {
|
|
68
|
-
for (const name of ['.github', '.bevel', 'Data', 'agents', '
|
|
68
|
+
for (const name of ['.github', '.bevel', 'Data', 'agents', 'WORKFLOWS']) {
|
|
69
69
|
expect(isRootFolderSuggestion(name)).toBe(false);
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
it('offers Pipelines, a name core no longer reserves', () => {
|
|
74
|
+
expect(isRootFolderSuggestion('Pipelines')).toBe(true);
|
|
75
|
+
});
|
|
72
76
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AGENTS_DIR, DATA_DIR,
|
|
1
|
+
import { AGENTS_DIR, DATA_DIR, WORKFLOWS_DIR, validateKbRootName } from '@bevel-software/platform-shared';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What the repository holds for one configured root folder, judged against
|
|
@@ -34,7 +34,7 @@ export function rootFolderState(configured: string, rootFolders: readonly string
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const RESERVED_ROOTS = [DATA_DIR, AGENTS_DIR,
|
|
37
|
+
const RESERVED_ROOTS = [DATA_DIR, AGENTS_DIR, WORKFLOWS_DIR].map((name) => name.toLowerCase());
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Whether a listed folder may be offered as a root name: one the save would
|
|
@@ -608,7 +608,14 @@ export function ExternalAgentAccessPage() {
|
|
|
608
608
|
<div className="flex-1 min-w-0">
|
|
609
609
|
<div className="font-medium truncate">{k.label}</div>
|
|
610
610
|
<div className="text-[11px] text-ink-muted">
|
|
611
|
-
|
|
611
|
+
{/* Only a key made as an agent says so; Everything is what a key
|
|
612
|
+
is unless it says otherwise, and needs no tag. */}
|
|
613
|
+
{k.agentPath && (
|
|
614
|
+
<>
|
|
615
|
+
<span title={k.agentPath}>As {connectedAsLabel(k.agentPath)}</span> ·{' '}
|
|
616
|
+
</>
|
|
617
|
+
)}
|
|
618
|
+
Created{' '}
|
|
612
619
|
{formatRelative(k.createdAt)} · Last used {formatRelative(k.lastUsedAt)}
|
|
613
620
|
{/* A key an admin took is not one you can reconnect — say so,
|
|
614
621
|
or people try. Your own disconnect keeps its word. */}
|
|
@@ -57,7 +57,7 @@ export function Toolbar() {
|
|
|
57
57
|
// own: the branch switcher is an enterprise contribution scoped (by the
|
|
58
58
|
// item itself, via useActiveAppId) to the Knowledge app — the git module
|
|
59
59
|
// still ships the component, the core shell just doesn't mount it.
|
|
60
|
-
// (Share/Discard buttons retired with the
|
|
60
|
+
// (Share/Discard buttons retired with the version-control migration: lock release
|
|
61
61
|
// auto-commits + pushes, so there is no separate "share" step.)
|
|
62
62
|
const toolbarItems = useMemo(
|
|
63
63
|
() =>
|
|
@@ -34,25 +34,35 @@ const { listMock, createMock, instructionsMock, facadeMock, registrationMock, ad
|
|
|
34
34
|
adminState: { isAdmin: false },
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
// The other modules this page reaches, replaced at their entries: that is
|
|
38
|
+
// where the page imports them from, and the one surface a mock may stand in
|
|
39
|
+
// for. Only the hook is replaced on `admin`; `AdminContext` itself stays real,
|
|
40
|
+
// because the instructions card below reads the context directly rather than
|
|
41
|
+
// through the hook; a whole-module mock left it undefined and every case here
|
|
42
|
+
// threw.
|
|
43
|
+
vi.mock('../../../admin', async (importOriginal) => ({
|
|
44
|
+
...(await importOriginal<typeof import('../../../admin')>()),
|
|
42
45
|
useAdmin: () => ({ isAdmin: adminState.isAdmin }),
|
|
43
46
|
}));
|
|
44
47
|
|
|
45
|
-
// The registration state the Cowork drawer reads
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
vi.mock('../../../settings/services/github-facade.api', () => ({
|
|
49
|
-
fetchGitHubFacade: facadeMock,
|
|
48
|
+
// The registration state the Cowork drawer reads.
|
|
49
|
+
vi.mock('../../../settings', async (importOriginal) => ({
|
|
50
|
+
...(await importOriginal<typeof import('../../../settings')>()),
|
|
50
51
|
fetchMarketplaceRegistration: registrationMock,
|
|
51
52
|
}));
|
|
52
53
|
|
|
54
|
+
// The admin credentials endpoint this page must never call. It is reached
|
|
55
|
+
// inside the settings module, by `ClaudeConnectionCard`, which the toolbar's
|
|
56
|
+
// registration steps import by file rather than through the entry, so the
|
|
57
|
+
// guard sits on the file too until that import moves.
|
|
58
|
+
vi.mock('../../../settings/services/github-facade.api', async (importOriginal) => ({
|
|
59
|
+
...(await importOriginal<typeof import('../../../settings/services/github-facade.api')>()),
|
|
60
|
+
fetchGitHubFacade: facadeMock,
|
|
61
|
+
}));
|
|
62
|
+
|
|
53
63
|
// The agents a key may be minted as ("Connect as").
|
|
54
|
-
vi.mock('../../../agents
|
|
55
|
-
...(await importOriginal<typeof import('../../../agents
|
|
64
|
+
vi.mock('../../../agents', async (importOriginal) => ({
|
|
65
|
+
...(await importOriginal<typeof import('../../../agents')>()),
|
|
56
66
|
listAgentChoices: agentChoicesMock,
|
|
57
67
|
}));
|
|
58
68
|
|
|
@@ -817,6 +827,21 @@ describe('minting a key as an agent ("Connect as")', () => {
|
|
|
817
827
|
expect(ops).not.toBeChecked();
|
|
818
828
|
});
|
|
819
829
|
|
|
830
|
+
it('asks nothing when there is no agent to mint as: the key is Everything’s, as it always was', async () => {
|
|
831
|
+
agentChoicesMock.mockResolvedValue([]);
|
|
832
|
+
const user = userEvent.setup();
|
|
833
|
+
mount(PUBLIC_URL);
|
|
834
|
+
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
835
|
+
await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'CI');
|
|
836
|
+
// Create key is enabled only once the agents answered, so the choice had its chance to appear.
|
|
837
|
+
const create = screen.getByRole('button', { name: 'Create key' });
|
|
838
|
+
expect(create).toBeEnabled();
|
|
839
|
+
expect(screen.queryByRole('group', { name: 'Connect as' })).toBeNull();
|
|
840
|
+
expect(screen.queryByText(/Connect as/)).toBeNull();
|
|
841
|
+
await user.click(create);
|
|
842
|
+
expect(createMock).toHaveBeenLastCalledWith('CI', null);
|
|
843
|
+
});
|
|
844
|
+
|
|
820
845
|
it('mints as Everything unless an agent is picked, and as the agent when one is', async () => {
|
|
821
846
|
agentChoicesMock.mockResolvedValue([OPS]);
|
|
822
847
|
const user = userEvent.setup();
|
|
@@ -876,7 +901,8 @@ describe('minting a key as an agent ("Connect as")', () => {
|
|
|
876
901
|
await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
|
|
877
902
|
await screen.findByText('Pipeline');
|
|
878
903
|
const rowOf = (label: string) => screen.getByText(label).closest('li') as HTMLElement;
|
|
879
|
-
|
|
904
|
+
// Everything is what a key is unless it says otherwise: no tag.
|
|
905
|
+
expect(rowOf('Laptop')).not.toHaveTextContent('As ');
|
|
880
906
|
expect(rowOf('Pipeline')).toHaveTextContent('As ops');
|
|
881
907
|
});
|
|
882
908
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { act, renderHook } from '@testing-library/react';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
|
-
import type { FileLock,
|
|
4
|
+
import type { FileLock, VersionControlEvent } from '@bevel-software/platform-shared';
|
|
5
5
|
|
|
6
6
|
// The lock endpoints are the hook's only side effects; each test decides what
|
|
7
7
|
// they answer. The sentences stay real — they are what the person reads.
|
|
@@ -17,7 +17,7 @@ vi.mock('../../services/lock.api', async (importOriginal) => ({
|
|
|
17
17
|
...api,
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
|
-
// The hook and its sentence come through
|
|
20
|
+
// The hook and its sentence come through version control's public entry point, as
|
|
21
21
|
// other modules see them.
|
|
22
22
|
import { useFileLock, SELF_HOLD_MESSAGE } from '../..';
|
|
23
23
|
import { EventBusContext, type EventBusContextValue } from '../../state/event-bus.context';
|
|
@@ -39,18 +39,18 @@ function lockHeldBy(holderUserId: string, holderName: string, expiresInMs = 60_0
|
|
|
39
39
|
|
|
40
40
|
/** A bus the test can publish `lock-*` events on. */
|
|
41
41
|
function makeBus() {
|
|
42
|
-
const handlers = new Map<string, Set<(e:
|
|
42
|
+
const handlers = new Map<string, Set<(e: VersionControlEvent) => void>>();
|
|
43
43
|
const bus: EventBusContextValue = {
|
|
44
44
|
subscribe: (kind, handler) => {
|
|
45
45
|
const set = handlers.get(kind) ?? new Set();
|
|
46
|
-
set.add(handler as (e:
|
|
46
|
+
set.add(handler as (e: VersionControlEvent) => void);
|
|
47
47
|
handlers.set(kind, set);
|
|
48
|
-
return () => set.delete(handler as (e:
|
|
48
|
+
return () => set.delete(handler as (e: VersionControlEvent) => void);
|
|
49
49
|
},
|
|
50
50
|
setFocus: () => {},
|
|
51
51
|
watchWorkspace: () => () => {},
|
|
52
52
|
};
|
|
53
|
-
const publish = (e:
|
|
53
|
+
const publish = (e: VersionControlEvent) => handlers.get(e.kind)?.forEach((h) => h(e));
|
|
54
54
|
return { bus, publish };
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -201,7 +201,7 @@ describe('useFileLock — the notice clears when the hold ends', () => {
|
|
|
201
201
|
expect(result.current.externalLock).not.toBeNull();
|
|
202
202
|
|
|
203
203
|
await act(async () => {
|
|
204
|
-
publish({ kind: 'lock-released', workspaceId: 'ws', branch: 'main', path: 'kb/Knowledge/Foo.md' } as
|
|
204
|
+
publish({ kind: 'lock-released', workspaceId: 'ws', branch: 'main', path: 'kb/Knowledge/Foo.md' } as VersionControlEvent);
|
|
205
205
|
});
|
|
206
206
|
|
|
207
207
|
expect(result.current.externalLock).toBeNull();
|
|
@@ -224,7 +224,7 @@ describe('useFileLock — the notice clears when the hold ends', () => {
|
|
|
224
224
|
path: 'kb/Knowledge/Foo.md',
|
|
225
225
|
holderUserId: 'u-dana',
|
|
226
226
|
holderName: 'Dana',
|
|
227
|
-
} as
|
|
227
|
+
} as VersionControlEvent);
|
|
228
228
|
});
|
|
229
229
|
expect(result.current.externalLock?.holderName).toBe('Dana');
|
|
230
230
|
|
|
@@ -443,7 +443,7 @@ describe('useFileLock — a live hold of the viewer\'s own is shown on open', ()
|
|
|
443
443
|
publish({
|
|
444
444
|
kind: 'lock-acquired', workspaceId: 'ws', branch: 'main', path: 'kb/Knowledge/Foo.md',
|
|
445
445
|
holderUserId: ME, holderName: 'Juan',
|
|
446
|
-
} as
|
|
446
|
+
} as VersionControlEvent);
|
|
447
447
|
});
|
|
448
448
|
|
|
449
449
|
expect(result.current.externalLockIsMine).toBe(true);
|
|
@@ -464,7 +464,7 @@ describe('useFileLock — a live hold of the viewer\'s own is shown on open', ()
|
|
|
464
464
|
publish({
|
|
465
465
|
kind: 'lock-acquired', workspaceId: 'ws', branch: 'main', path: 'kb/Knowledge/Foo.md',
|
|
466
466
|
holderUserId: ME, holderName: 'Juan',
|
|
467
|
-
} as
|
|
467
|
+
} as VersionControlEvent);
|
|
468
468
|
});
|
|
469
469
|
expect(result.current.externalLock).toBeNull();
|
|
470
470
|
|