@bevel-software/platform-core-frontend 0.13.5 → 0.14.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/THIRD-PARTY-NOTICES.md +416 -418
- package/package.json +2 -2
- package/src/lib/__tests__/utils.test.ts +43 -0
- package/src/lib/utils.ts +15 -7
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -0
- package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
- package/src/modules/library/__tests__/ToolPage.test.tsx +164 -3
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
- package/src/modules/library/__tests__/status.test.ts +84 -0
- package/src/modules/library/components/LibraryCard.tsx +7 -1
- package/src/modules/library/components/skill-page/SkillPage.tsx +5 -1
- package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
- package/src/modules/library/components/tool-page/ToolPage.tsx +103 -1
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
- package/src/modules/library/hooks/useToolPage.ts +28 -11
- package/src/modules/library/hooks/useToolSource.ts +77 -0
- package/src/modules/library/utils/status.ts +99 -10
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +760 -730
- package/src/modules/onboarding/agent-clients.ts +9 -3
- package/src/modules/onboarding/components/WelcomePage.tsx +9 -7
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
- package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +6 -10
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +34 -12
- package/src/shared/mcp/ChatGptInstallLink.tsx +45 -0
- package/src/shared/mcp/ClaudeInstallLink.tsx +3 -3
- package/src/shared/mcp/ConnectionInstructions.tsx +17 -11
- package/src/shared/mcp/__tests__/ChatGptInstallLink.test.tsx +34 -0
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +49 -13
- package/src/shared/mcp/connect-snippets.ts +41 -6
- package/src/shared/mcp/index.ts +4 -0
|
@@ -24,6 +24,90 @@ function tool(overrides: Partial<ToolSecrets>): ToolSecrets {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The distinction this whole feature exists for: a STORED credential and a
|
|
29
|
+
* WORKING one are different claims, and the badge must not make the second on
|
|
30
|
+
* the evidence of the first.
|
|
31
|
+
*/
|
|
32
|
+
describe('toolStatus: stored vs working', () => {
|
|
33
|
+
const withKey = () =>
|
|
34
|
+
tool({
|
|
35
|
+
variables: [
|
|
36
|
+
{ name: 'API_KEY', scope: 'user', label: null, key: 'slack_API_KEY', adminConfigured: false, userConfigured: true },
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('says Key saved — not Connected — when a key is stored but never tested', () => {
|
|
41
|
+
// No verdict at all is the DEFAULT everywhere but the tool page: nothing is
|
|
42
|
+
// stored, so a list built from saved values can never earn "Connected".
|
|
43
|
+
const s = toolStatus(withKey());
|
|
44
|
+
expect(s.state).toBe('ok');
|
|
45
|
+
expect(s.text).toBe('Key saved');
|
|
46
|
+
// Green, because nothing needs a person; but the word claims only what is known.
|
|
47
|
+
expect(s.hint).toMatch(/not verified/i);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('says Key saved when the probe could not reach a verdict', () => {
|
|
51
|
+
const s = toolStatus(withKey(), { status: 'unverifiable', detail: 'Provider timed out.', checkedAt: new Date().toISOString() });
|
|
52
|
+
expect(s.state).toBe('ok');
|
|
53
|
+
expect(s.text).toBe('Key saved');
|
|
54
|
+
expect(s.hint).toBe('Provider timed out.');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('earns Connected only from a passing probe, and shows when it was checked', () => {
|
|
58
|
+
const s = toolStatus(withKey(), { status: 'ok', detail: null, checkedAt: new Date().toISOString() });
|
|
59
|
+
expect(s.state).toBe('ok');
|
|
60
|
+
expect(s.text).toBe('Connected');
|
|
61
|
+
expect(s.hint).toMatch(/^Checked /);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('goes red with the provider\'s own words when the credential is rejected', () => {
|
|
65
|
+
const s = toolStatus(withKey(), { status: 'failed', detail: 'Invalid API key.', checkedAt: new Date().toISOString() });
|
|
66
|
+
expect(s.state).toBe('err');
|
|
67
|
+
expect(s.text).toBe('Not working');
|
|
68
|
+
expect(s.hint).toBe('Invalid API key.');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('says Signed in rather than Key saved when the tool is oauth-backed', () => {
|
|
72
|
+
const s = toolStatus(
|
|
73
|
+
tool({
|
|
74
|
+
variables: [
|
|
75
|
+
{ name: 'SIGNIN', scope: 'user', label: null, key: 'slack_SIGNIN', adminConfigured: true, userConfigured: true, oauth: true, authorized: true },
|
|
76
|
+
],
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
expect(s.text).toBe('Signed in');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Setup outranks the verdict. A `failed` from before the key was entered must
|
|
84
|
+
* never displace the thing actually in the way — "Needs a key from you" is the
|
|
85
|
+
* sentence the reader can act on.
|
|
86
|
+
*/
|
|
87
|
+
it('names the missing key rather than a stale failure', () => {
|
|
88
|
+
const s = toolStatus(
|
|
89
|
+
tool({
|
|
90
|
+
variables: [
|
|
91
|
+
{ name: 'API_KEY', scope: 'user', label: null, key: 'slack_API_KEY', adminConfigured: false, userConfigured: false },
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
94
|
+
{ status: 'failed', detail: 'Invalid API key.', checkedAt: new Date().toISOString() },
|
|
95
|
+
);
|
|
96
|
+
expect(s.state).toBe('warn');
|
|
97
|
+
expect(s.text).toBe('Needs a key from you');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('says No key needed for a tool that asks for nothing', () => {
|
|
101
|
+
// "Key saved" would name a key the user was never asked for.
|
|
102
|
+
expect(toolStatus(tool({ variables: [] })).text).toBe('No key needed');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/** An unverified tool blocks nothing: it needs no person, so a skill is Ready. */
|
|
106
|
+
it('leaves a skill Ready when its tools are merely unverified', () => {
|
|
107
|
+
expect(skillStatus([withKey()]).state).toBe('ok');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
27
111
|
describe('toolStatus', () => {
|
|
28
112
|
it('is ok when every variable is satisfied', () => {
|
|
29
113
|
const t = tool({
|
|
@@ -166,7 +166,13 @@ export function LibraryCard({
|
|
|
166
166
|
</span>
|
|
167
167
|
)}
|
|
168
168
|
{footNote && (
|
|
169
|
-
|
|
169
|
+
/* `title` carries the evidence behind the word — what the provider
|
|
170
|
+
said, or when it was last checked. A card has room for one word;
|
|
171
|
+
the sentence that justifies it belongs on hover. */
|
|
172
|
+
<span
|
|
173
|
+
className={cn('flex items-center gap-1.5 font-semibold', STATUS_INK[footNote.state])}
|
|
174
|
+
title={footNote.hint}
|
|
175
|
+
>
|
|
170
176
|
<StatusDot state={footNote.state} />
|
|
171
177
|
{footNote.text}
|
|
172
178
|
</span>
|
|
@@ -832,7 +832,11 @@ function IntegrationsSection({
|
|
|
832
832
|
<div className="min-w-0">
|
|
833
833
|
<b className="block text-detail font-semibold text-ink">{t.name}</b>
|
|
834
834
|
<small className="block text-meta text-ink-faint">
|
|
835
|
-
{status.
|
|
835
|
+
{/* `status.text`, never a hardcoded "Connected": this list is
|
|
836
|
+
built from what is stored, and nothing here has probed
|
|
837
|
+
anything — so it says "Key saved"/"Signed in" and keeps the
|
|
838
|
+
reassurance that no action is needed. */}
|
|
839
|
+
{status.state === 'ok' ? `${status.text}. Nothing to do` : status.text}
|
|
836
840
|
</small>
|
|
837
841
|
</div>
|
|
838
842
|
<div className="ml-auto flex shrink-0 items-center gap-2">
|
|
@@ -32,12 +32,20 @@ import { pathForTool } from '../../routes/library-paths';
|
|
|
32
32
|
export function McpServerSection({
|
|
33
33
|
slug,
|
|
34
34
|
configuredCount,
|
|
35
|
+
reloadSignal,
|
|
35
36
|
onSaved,
|
|
36
37
|
onError,
|
|
37
38
|
}: {
|
|
38
39
|
slug: string;
|
|
39
40
|
/** Configured secrets + sign-ins under this server's name — what a rename disconnects. */
|
|
40
41
|
configuredCount: number;
|
|
42
|
+
/**
|
|
43
|
+
* Changes on every page reload, including one that keeps the same slug.
|
|
44
|
+
* Saving a server without renaming it leaves `slug` untouched, and the page
|
|
45
|
+
* no longer remounts on reload — so without this in the dependency list the
|
|
46
|
+
* fetch below never re-runs and the section renders its cleared view.
|
|
47
|
+
*/
|
|
48
|
+
reloadSignal: number;
|
|
41
49
|
/** Called after a save lands; the new slug when the server was renamed. */
|
|
42
50
|
onSaved(newSlug?: string): void;
|
|
43
51
|
onError(message: string): void;
|
|
@@ -74,7 +82,7 @@ export function McpServerSection({
|
|
|
74
82
|
return () => {
|
|
75
83
|
live = false;
|
|
76
84
|
};
|
|
77
|
-
}, [slug]);
|
|
85
|
+
}, [slug, reloadSignal]);
|
|
78
86
|
|
|
79
87
|
if (!server) return null;
|
|
80
88
|
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
2
|
import { Link, useNavigate } from 'react-router-dom';
|
|
3
3
|
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
4
4
|
import { Banner, Button, buttonClasses } from '../../../../shared/components';
|
|
5
5
|
import { useWorkspace } from '../../../workspace/state/workspace.context';
|
|
6
6
|
import { kbFileUrl } from '../../../workspace/routing/kb-routes';
|
|
7
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
checkToolConnection,
|
|
9
|
+
type ProbeVerdict,
|
|
10
|
+
type ToolSecrets,
|
|
11
|
+
} from '../../../secrets-vault/services/tool-secrets.api';
|
|
8
12
|
import { pathForTool } from '../../routes/library-paths';
|
|
9
|
-
import { toolVariableStatuses } from '../../utils/status';
|
|
13
|
+
import { toolStatus, toolVariableStatuses } from '../../utils/status';
|
|
10
14
|
import { ToolVarRow } from './ToolVarRow';
|
|
11
15
|
|
|
12
16
|
/**
|
|
@@ -24,16 +28,76 @@ import { ToolVarRow } from './ToolVarRow';
|
|
|
24
28
|
|
|
25
29
|
export interface ToolConnectionSectionProps {
|
|
26
30
|
tool: ToolSecrets;
|
|
31
|
+
/**
|
|
32
|
+
* Bumped whenever the tool's DEFINITION changes — today, an mcp.json server
|
|
33
|
+
* edit. A verdict describes the endpoint and headers it was probed against,
|
|
34
|
+
* so changing those makes it a statement about a server that is no longer
|
|
35
|
+
* configured; the badge must stop claiming it. Deliberately NOT bumped by a
|
|
36
|
+
* credential write: that path clears and re-probes on its own, and bumping
|
|
37
|
+
* here would discard the answer it is in the middle of fetching.
|
|
38
|
+
*/
|
|
39
|
+
configRevision: number;
|
|
27
40
|
/** A write landed — the caller refetches so the chips catch up. */
|
|
28
41
|
onChanged(): void;
|
|
29
42
|
onError(message: string): void;
|
|
30
43
|
}
|
|
31
44
|
|
|
32
|
-
export function ToolConnectionSection({
|
|
45
|
+
export function ToolConnectionSection({
|
|
46
|
+
tool,
|
|
47
|
+
configRevision,
|
|
48
|
+
onChanged,
|
|
49
|
+
onError,
|
|
50
|
+
}: ToolConnectionSectionProps) {
|
|
33
51
|
const navigate = useNavigate();
|
|
34
52
|
const { kbDirName } = useWorkspace();
|
|
35
53
|
/** `{varName, n}` — bumping `n` opens that variable's editor from the banner. */
|
|
36
54
|
const [edit, setEdit] = useState<{ name: string; n: number }>({ name: '', n: 0 });
|
|
55
|
+
/**
|
|
56
|
+
* The revision of the probe in flight, or null. `checking` is DERIVED: an
|
|
57
|
+
* in-flight probe owns the Test button only while the definition it dials
|
|
58
|
+
* is still the one on screen, so a config edit mid-probe re-enables the
|
|
59
|
+
* button for the new definition immediately instead of waiting for the
|
|
60
|
+
* orphan to settle.
|
|
61
|
+
*/
|
|
62
|
+
const [inFlight, setInFlight] = useState<{ rev: number } | null>(null);
|
|
63
|
+
const checking = inFlight !== null && inFlight.rev === configRevision;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A probe's TRANSPORT failure (network, access — not a verdict about the
|
|
67
|
+
* credential), held here rather than raised to the page's shared error
|
|
68
|
+
* banner. Page-level state outlived its subject twice over: another
|
|
69
|
+
* action's error could be cleared by a probe that happened to recover,
|
|
70
|
+
* and a probe of the PREVIOUS tool (this section is keyed by slug) could
|
|
71
|
+
* clear or raise it after unmount. Section state dies with the section,
|
|
72
|
+
* and the revision stamp makes it self-invalidating, exactly like the
|
|
73
|
+
* verdict: shown only while it describes the configuration on screen.
|
|
74
|
+
*/
|
|
75
|
+
const [probeError, setProbeError] = useState<{ rev: number; message: string } | null>(null);
|
|
76
|
+
const shownProbeError = probeError && probeError.rev === configRevision ? probeError.message : null;
|
|
77
|
+
/**
|
|
78
|
+
* The last probe's answer, and the ONLY place one exists.
|
|
79
|
+
*
|
|
80
|
+
* Nothing persists a verdict, so this state IS the evidence behind the word
|
|
81
|
+
* "Connected" — which is why the claim can be trusted: it cannot outlive the
|
|
82
|
+
* page that watched the call succeed.
|
|
83
|
+
*
|
|
84
|
+
* Stored WITH the config revision it was probed under, and read back only
|
|
85
|
+
* when that still matches. Comparing rather than clearing keeps it pure: an
|
|
86
|
+
* effect that cleared on change would race the probe it is meant to protect,
|
|
87
|
+
* since a credential save starts a probe and a refetch at the same moment.
|
|
88
|
+
*/
|
|
89
|
+
const [probed, setProbed] = useState<{ rev: number; value: ProbeVerdict } | null>(null);
|
|
90
|
+
const verdict = probed && probed.rev === configRevision ? probed.value : null;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Which probe is allowed to publish. Two saves in quick succession start two
|
|
94
|
+
* probes, and the first can answer last — so a result is applied only while
|
|
95
|
+
* it is still the newest one asked for. Without it the older credential's
|
|
96
|
+
* verdict wins by finishing late, which is the same stale-answer bug this
|
|
97
|
+
* whole feature exists to remove, one layer up.
|
|
98
|
+
*/
|
|
99
|
+
const probeSeq = useRef(0);
|
|
100
|
+
|
|
37
101
|
|
|
38
102
|
const setupKind = tool.setup?.kind ?? null;
|
|
39
103
|
// Not just "kind is oauth-manual": once the owner declares the provider and
|
|
@@ -92,15 +156,145 @@ export function ToolConnectionSection({ tool, onChanged, onError }: ToolConnecti
|
|
|
92
156
|
</Button>
|
|
93
157
|
) : null;
|
|
94
158
|
|
|
159
|
+
/**
|
|
160
|
+
* The health line, shown only once every variable is provided.
|
|
161
|
+
*
|
|
162
|
+
* While something is still missing, the amber banner above already names it,
|
|
163
|
+
* and a second line saying the connection is untested would be answering a
|
|
164
|
+
* question nobody has reached yet. Once nothing is missing, this is the only
|
|
165
|
+
* remaining question — and the one the badge used to answer by guessing.
|
|
166
|
+
*/
|
|
167
|
+
const health = toolStatus(tool, verdict);
|
|
168
|
+
// Every variable genuinely provided — NOT merely `missing.length === 0`, which
|
|
169
|
+
// excludes a pending sign-in on a configured provider. A tool nobody has
|
|
170
|
+
// signed into yet has no credential to test, and saying so would put a health
|
|
171
|
+
// line above a row that already says "Needs your sign-in".
|
|
172
|
+
// Vacuously true for a tool that declares no variables: a no-auth MCP server
|
|
173
|
+
// has nothing to set up and is still worth probing — its handshake is exactly
|
|
174
|
+
// the kind of thing that can be reachable one day and not the next.
|
|
175
|
+
//
|
|
176
|
+
// But `!setupUnfinished` first: an `oauth-manual` server whose sign-in nobody
|
|
177
|
+
// has declared YET also has no variables, and `every([])` would call that
|
|
178
|
+
// settled — offering Test connection and the words "No key needed" directly
|
|
179
|
+
// above a banner telling the owner to go configure OAuth.
|
|
180
|
+
const settled =
|
|
181
|
+
!setupUnfinished && toolVariableStatuses(tool).every(({ status }) => status.state === 'ok');
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Run a probe and keep its answer.
|
|
185
|
+
*
|
|
186
|
+
* `checking` lives here, beside the button it disables, so it is still true
|
|
187
|
+
* while the request is in flight — the reason a save no longer blanks the
|
|
188
|
+
* page (see `useToolPage`): a remount would drop both this flag and the
|
|
189
|
+
* verdict, leaving an enabled "Test connection" over a probe already running.
|
|
190
|
+
*/
|
|
191
|
+
async function runCheck() {
|
|
192
|
+
const mine = ++probeSeq.current;
|
|
193
|
+
const rev = configRevision;
|
|
194
|
+
setInFlight({ rev });
|
|
195
|
+
// A replacement probe makes the previous transport failure history the
|
|
196
|
+
// moment it starts — leaving the alert up while "Testing…" runs reads as
|
|
197
|
+
// the new attempt already having failed.
|
|
198
|
+
setProbeError(null);
|
|
199
|
+
try {
|
|
200
|
+
const value = await checkToolConnection(tool.slug);
|
|
201
|
+
// Newest-probe guard only: everything published is REVISION-STAMPED
|
|
202
|
+
// and compared at render, so a probe that raced a definition change
|
|
203
|
+
// stores state that simply never shows — no clock to synchronise, no
|
|
204
|
+
// ref to read mid-render.
|
|
205
|
+
if (probeSeq.current === mine) {
|
|
206
|
+
setProbed({ rev, value });
|
|
207
|
+
setProbeError(null);
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
// A rejected credential resolves with `status: 'failed'`; only a
|
|
211
|
+
// transport or access failure lands here, and that is not a verdict about
|
|
212
|
+
// the credential — so the badge keeps saying "untested" rather than
|
|
213
|
+
// inventing a result from our own network trouble.
|
|
214
|
+
// Inside the guard too: an older probe rejecting after a newer one has
|
|
215
|
+
// already answered would otherwise raise a transport error over a verdict
|
|
216
|
+
// that is currently correct.
|
|
217
|
+
if (probeSeq.current === mine) {
|
|
218
|
+
setProbed(null);
|
|
219
|
+
setProbeError({ rev, message: err instanceof Error ? err.message : "Couldn't test this connection." });
|
|
220
|
+
}
|
|
221
|
+
} finally {
|
|
222
|
+
// Only the newest probe releases the slot: an older one finishing late
|
|
223
|
+
// must not clear a newer probe's in-flight marker.
|
|
224
|
+
if (probeSeq.current === mine) setInFlight(null);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A credential write LANDED (save or delete, from the banner's editor or a
|
|
230
|
+
* row). Everything a pending probe could still say is about a credential
|
|
231
|
+
* that no longer exists in that form, so the write ORPHANS it outright —
|
|
232
|
+
* the sequence bump takes its voice (a delete starts no replacement probe,
|
|
233
|
+
* so nothing else would), the in-flight slot is released, and the old
|
|
234
|
+
* transport alert goes with them.
|
|
235
|
+
*/
|
|
236
|
+
function changed() {
|
|
237
|
+
probeSeq.current++;
|
|
238
|
+
setInFlight(null);
|
|
239
|
+
setProbeError(null);
|
|
240
|
+
// The VERDICT too: after a delete, “Connected” would otherwise keep
|
|
241
|
+
// describing a credential that no longer exists while the refetch is
|
|
242
|
+
// still in flight.
|
|
243
|
+
setProbed(null);
|
|
244
|
+
onChanged();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A credential was just SAVED: whatever the last probe concluded was about
|
|
249
|
+
* the key it replaced, so drop it and test the new one straight away —
|
|
250
|
+
* while the user still has it to hand, which is when a wrong key is
|
|
251
|
+
* cheapest to fix. (The row calls `changed` too, which orphans the old
|
|
252
|
+
* probe; the fresh `runCheck` claims the sequence for the new key.)
|
|
253
|
+
*/
|
|
254
|
+
function onSaved() {
|
|
255
|
+
setProbed(null);
|
|
256
|
+
void runCheck();
|
|
257
|
+
}
|
|
258
|
+
|
|
95
259
|
return (
|
|
96
260
|
<section className="mt-8">
|
|
97
261
|
<div className="mb-2.5 flex items-center justify-between gap-3">
|
|
98
262
|
<h2 className="text-label font-semibold uppercase text-ink-faint">Your connection</h2>
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
263
|
+
<div className="flex items-center gap-2">
|
|
264
|
+
{/* A healthy connection stays QUIET — this section's rule is that only
|
|
265
|
+
things needing a person get a banner, and a working tool needs
|
|
266
|
+
nobody. But it still has to be sayable: the word plus its evidence
|
|
267
|
+
on hover is how "Connected" stops being an assumption, and the
|
|
268
|
+
button is the only way to ask the question on demand. A REJECTED
|
|
269
|
+
credential does need a person, so it escalates to a banner below. */}
|
|
270
|
+
{settled && health.state !== 'err' && (
|
|
271
|
+
<span className="text-meta text-ink-faint" title={health.hint} data-testid="tool-health">
|
|
272
|
+
{health.text}
|
|
273
|
+
</span>
|
|
274
|
+
)}
|
|
275
|
+
{settled && (
|
|
276
|
+
<Button
|
|
277
|
+
variant="quiet"
|
|
278
|
+
size="tiny"
|
|
279
|
+
disabled={checking}
|
|
280
|
+
onClick={() => void runCheck()}
|
|
281
|
+
aria-label={`Test connection: ${tool.name}`}
|
|
282
|
+
>
|
|
283
|
+
{checking ? 'Testing…' : 'Test connection'}
|
|
284
|
+
</Button>
|
|
285
|
+
)}
|
|
286
|
+
<Link to="/secrets" className={buttonClasses({ variant: 'quiet', size: 'tiny' })}>
|
|
287
|
+
Open Secrets
|
|
288
|
+
</Link>
|
|
289
|
+
</div>
|
|
102
290
|
</div>
|
|
103
291
|
|
|
292
|
+
{shownProbeError && (
|
|
293
|
+
<Banner tone="danger" role="alert" className="mb-2.5" data-testid="tool-probe-error">
|
|
294
|
+
{shownProbeError}
|
|
295
|
+
</Banner>
|
|
296
|
+
)}
|
|
297
|
+
|
|
104
298
|
{setupUnfinished && (
|
|
105
299
|
<Banner tone="wait" role="status" className="mb-2.5">
|
|
106
300
|
{tool.canWrite && signInDeclared ? (
|
|
@@ -167,6 +361,22 @@ export function ToolConnectionSection({ tool, onChanged, onError }: ToolConnecti
|
|
|
167
361
|
</Banner>
|
|
168
362
|
)}
|
|
169
363
|
|
|
364
|
+
{/* The one health state that needs a person: the provider tested this
|
|
365
|
+
credential and refused it. Everything is configured, so no other
|
|
366
|
+
banner covers it, and the row below cannot know — only a real call
|
|
367
|
+
could tell us. `alert`, not `status`: this is the case the whole
|
|
368
|
+
feature exists to surface. */}
|
|
369
|
+
{settled && health.state === 'err' && (
|
|
370
|
+
<Banner tone="danger" role="alert" className="mb-2.5" data-testid="tool-health-failed">
|
|
371
|
+
<div className="flex items-center gap-3">
|
|
372
|
+
<span className="min-w-0 flex-1">
|
|
373
|
+
<span className="font-semibold">{health.text}.</span>
|
|
374
|
+
{health.hint && <span> {health.hint}</span>}
|
|
375
|
+
</span>
|
|
376
|
+
</div>
|
|
377
|
+
</Banner>
|
|
378
|
+
)}
|
|
379
|
+
|
|
170
380
|
{tool.variables.length === 0 ? (
|
|
171
381
|
<p className="text-body text-ink-muted">Nothing to set up</p>
|
|
172
382
|
) : (
|
|
@@ -180,7 +390,12 @@ export function ToolConnectionSection({ tool, onChanged, onError }: ToolConnecti
|
|
|
180
390
|
setupKind={setupKind}
|
|
181
391
|
returnTo={pathForTool(tool.slug)}
|
|
182
392
|
editSignal={edit.name === variable.name ? edit.n : undefined}
|
|
183
|
-
onChanged={
|
|
393
|
+
onChanged={changed}
|
|
394
|
+
// Test the moment a key is entered — while the user still has it
|
|
395
|
+
// to hand, which is when a typo is cheapest to fix. Waiting for
|
|
396
|
+
// an agent to trip over it is how the wrong key got to look
|
|
397
|
+
// connected in the first place.
|
|
398
|
+
onSaved={onSaved}
|
|
184
399
|
onError={onError}
|
|
185
400
|
/>
|
|
186
401
|
))}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { useEffect, useState, type ReactNode } from 'react';
|
|
1
|
+
import { useEffect, useId, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
3
|
+
import { ChevronRight } from 'lucide-react';
|
|
4
|
+
import { cn } from '../../../../lib/utils';
|
|
3
5
|
import { Banner, Button, buttonClasses } from '../../../../shared/components';
|
|
4
6
|
import { useToolPage } from '../../hooks/useToolPage';
|
|
7
|
+
import { useToolSource } from '../../hooks/useToolSource';
|
|
5
8
|
import { McpServerSection } from './McpServerSection';
|
|
6
9
|
import { libraryHomeForItemPath, LIBRARY_ROOT } from '../../routes/library-paths';
|
|
7
10
|
import { readOAuthFragment } from '../../utils/oauth-fragment';
|
|
@@ -47,6 +50,13 @@ export function ToolPage({
|
|
|
47
50
|
// `actionError` so a successful reload can't clear a callback failure.
|
|
48
51
|
const [oauthOutcome] = useState(readOAuthFragment);
|
|
49
52
|
const [actionError, setActionError] = useState<string | null>(null);
|
|
53
|
+
/**
|
|
54
|
+
* Bumped when the tool's DEFINITION changes — an mcp.json server edit. Lives
|
|
55
|
+
* here rather than in the connection section because the section is not the
|
|
56
|
+
* component that knows a server was edited, and a probe verdict about the old
|
|
57
|
+
* endpoint must not survive the change.
|
|
58
|
+
*/
|
|
59
|
+
const [serverRevision, setServerRevision] = useState(0);
|
|
50
60
|
|
|
51
61
|
useEffect(() => {
|
|
52
62
|
// Consume the OAuth `#…` fragment, KEEPING the query string: on an
|
|
@@ -140,8 +150,15 @@ export function ToolPage({
|
|
|
140
150
|
</Banner>
|
|
141
151
|
)}
|
|
142
152
|
|
|
153
|
+
{/* Keyed by slug: the section's probe verdict and `checking` flag are
|
|
154
|
+
component state about THIS tool. Navigating between two canonical
|
|
155
|
+
tools re-renders the same component instance, and without the key
|
|
156
|
+
the previous tool's "Connected" (or its failure banner) survives
|
|
157
|
+
under the next tool's heading. */}
|
|
143
158
|
<ToolConnectionSection
|
|
159
|
+
key={tool.slug}
|
|
144
160
|
tool={tool}
|
|
161
|
+
configRevision={serverRevision}
|
|
145
162
|
onChanged={() => {
|
|
146
163
|
setActionError(null);
|
|
147
164
|
page.reload();
|
|
@@ -157,8 +174,13 @@ export function ToolPage({
|
|
|
157
174
|
<McpServerSection
|
|
158
175
|
slug={tool.slug}
|
|
159
176
|
configuredCount={tool.variables.filter((v) => v.adminConfigured || v.userConfigured || v.authorized === true).length}
|
|
177
|
+
reloadSignal={page.revision}
|
|
160
178
|
onSaved={() => {
|
|
161
179
|
setActionError(null);
|
|
180
|
+
// The endpoint or headers may have just changed, so any verdict the
|
|
181
|
+
// connection section is holding describes a server that is no
|
|
182
|
+
// longer configured.
|
|
183
|
+
setServerRevision((r) => r + 1);
|
|
162
184
|
page.reload();
|
|
163
185
|
}}
|
|
164
186
|
onError={setActionError}
|
|
@@ -175,6 +197,10 @@ export function ToolPage({
|
|
|
175
197
|
Managed by the Admins.
|
|
176
198
|
</div>
|
|
177
199
|
|
|
200
|
+
{/* Last, and for EVERY type: `path` is the file the platform reads to
|
|
201
|
+
make this tool — the `.tool`, or the plugin `mcp.json` that declares
|
|
202
|
+
the server. */}
|
|
203
|
+
<SourceSection path={tool.path} />
|
|
178
204
|
</Article>
|
|
179
205
|
);
|
|
180
206
|
}
|
|
@@ -241,6 +267,82 @@ function PoweredSkillsSection({
|
|
|
241
267
|
);
|
|
242
268
|
}
|
|
243
269
|
|
|
270
|
+
/**
|
|
271
|
+
* The definition file, as text, behind a closed disclosure.
|
|
272
|
+
*
|
|
273
|
+
* A WINDOW, NOT AN EDITOR. The file is edited where files are edited; showing
|
|
274
|
+
* it here is what saves a developer the trip to the knowledge tree to answer
|
|
275
|
+
* "which template does this capability use" — and nothing in this section can
|
|
276
|
+
* change it.
|
|
277
|
+
*
|
|
278
|
+
* Closed by default is the mechanism, not just the default: the read hangs off
|
|
279
|
+
* the open state (`useToolSource`), so a reader who never opens the section
|
|
280
|
+
* never costs a file read, and everything above it renders the same whether
|
|
281
|
+
* the read succeeds, fails, or never happens.
|
|
282
|
+
*/
|
|
283
|
+
function SourceSection({ path }: { path: string }) {
|
|
284
|
+
const [open, setOpen] = useState(false);
|
|
285
|
+
const source = useToolSource(path, open);
|
|
286
|
+
const panelId = useId();
|
|
287
|
+
const buttonId = useId();
|
|
288
|
+
// Open and neither settled state: the read is in flight.
|
|
289
|
+
const loading = open && source.status !== 'loaded' && source.status !== 'error';
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<section className="mt-8">
|
|
293
|
+
<div className="flex flex-wrap items-baseline gap-x-2.5 gap-y-1">
|
|
294
|
+
<button
|
|
295
|
+
id={buttonId}
|
|
296
|
+
type="button"
|
|
297
|
+
onClick={() => setOpen((v) => !v)}
|
|
298
|
+
aria-expanded={open}
|
|
299
|
+
aria-controls={panelId}
|
|
300
|
+
className="flex items-center gap-1.5 text-label font-semibold uppercase text-ink-faint transition-colors hover:text-ink"
|
|
301
|
+
>
|
|
302
|
+
<ChevronRight
|
|
303
|
+
size={11}
|
|
304
|
+
className={cn('transition-transform duration-150', open && 'rotate-90')}
|
|
305
|
+
/>
|
|
306
|
+
Source
|
|
307
|
+
</button>
|
|
308
|
+
<span className="min-w-0 truncate font-mono text-meta text-ink-faint" title={path}>
|
|
309
|
+
{path}
|
|
310
|
+
</span>
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
{/* Always in the tree, so `aria-controls` never points at nothing; the
|
|
314
|
+
CONTENT is what is conditional, which is what keeps the read lazy.
|
|
315
|
+
|
|
316
|
+
A labelled region that is live and busy while the read runs: a
|
|
317
|
+
screen reader otherwise hears the button flip to "expanded" and
|
|
318
|
+
then nothing, because the content arrives a fetch later. `polite`
|
|
319
|
+
— the source is worth hearing, not worth interrupting for. */}
|
|
320
|
+
<div
|
|
321
|
+
id={panelId}
|
|
322
|
+
role="region"
|
|
323
|
+
aria-labelledby={buttonId}
|
|
324
|
+
aria-live="polite"
|
|
325
|
+
aria-busy={loading}
|
|
326
|
+
hidden={!open}
|
|
327
|
+
>
|
|
328
|
+
{open &&
|
|
329
|
+
(source.status === 'error' ? (
|
|
330
|
+
<p className="mt-2.5 text-detail text-ink-muted">Couldn't load the source.</p>
|
|
331
|
+
) : source.status === 'loaded' ? (
|
|
332
|
+
/* `whitespace-pre` and nothing else: the bytes are shown as the
|
|
333
|
+
platform stores them — no wrapping, reindenting or trimming.
|
|
334
|
+
Long lines scroll rather than fold. */
|
|
335
|
+
<pre className="mt-2.5 max-h-[32rem] select-text overflow-auto whitespace-pre rounded-lg border border-line bg-sunken p-3 font-mono text-meta leading-relaxed text-ink">
|
|
336
|
+
{source.content}
|
|
337
|
+
</pre>
|
|
338
|
+
) : (
|
|
339
|
+
<p className="mt-2.5 text-detail text-ink-faint">Loading the source…</p>
|
|
340
|
+
))}
|
|
341
|
+
</div>
|
|
342
|
+
</section>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
244
346
|
/** A malformed escape is a bad link, not a crash — fall back to the raw segment. */
|
|
245
347
|
function safeDecode(raw: string): string {
|
|
246
348
|
try {
|
|
@@ -50,6 +50,13 @@ export interface ToolVarRowProps {
|
|
|
50
50
|
*/
|
|
51
51
|
editSignal?: number;
|
|
52
52
|
onChanged(): void;
|
|
53
|
+
/**
|
|
54
|
+
* A credential was WRITTEN (not deleted) — a typed value or an owner's client
|
|
55
|
+
* secret. The one moment worth testing the connection, because it is the only
|
|
56
|
+
* one that can turn a broken tool into a working one. Deletes still call
|
|
57
|
+
* `onChanged`; they just have nothing to prove.
|
|
58
|
+
*/
|
|
59
|
+
onSaved?(): void;
|
|
53
60
|
onError(message: string): void;
|
|
54
61
|
}
|
|
55
62
|
|
|
@@ -63,6 +70,7 @@ export function ToolVarRow({
|
|
|
63
70
|
returnTo,
|
|
64
71
|
editSignal,
|
|
65
72
|
onChanged,
|
|
73
|
+
onSaved,
|
|
66
74
|
onError,
|
|
67
75
|
}: ToolVarRowProps) {
|
|
68
76
|
const [editor, setEditor] = useState<Editor>(null);
|
|
@@ -108,12 +116,13 @@ export function ToolVarRow({
|
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
/** Every write funnels through here so busy/close/report is identical. */
|
|
111
|
-
async function run(action: () => Promise<void
|
|
119
|
+
async function run(action: () => Promise<void>, saved = false) {
|
|
112
120
|
setBusy(true);
|
|
113
121
|
try {
|
|
114
122
|
await action();
|
|
115
123
|
close();
|
|
116
124
|
onChanged();
|
|
125
|
+
if (saved) onSaved?.();
|
|
117
126
|
} catch (err) {
|
|
118
127
|
onError(err instanceof Error ? err.message : String(err));
|
|
119
128
|
} finally {
|
|
@@ -152,8 +161,12 @@ export function ToolVarRow({
|
|
|
152
161
|
<Button key="reconnect" size="tiny" variant="quiet" disabled={busy} onClick={() => void signIn()}>
|
|
153
162
|
Reconnect
|
|
154
163
|
</Button>,
|
|
164
|
+
// "Signed in", not "Connected": at ROW level all we know is that a token
|
|
165
|
+
// exists. Whether it still works is the tool-level health line's claim,
|
|
166
|
+
// and it is the only place in the UI allowed to say "Connected" — one
|
|
167
|
+
// word, one meaning, backed by a real call.
|
|
155
168
|
<Badge key="chip" tone="ok">
|
|
156
|
-
|
|
169
|
+
Signed in
|
|
157
170
|
</Badge>,
|
|
158
171
|
);
|
|
159
172
|
if (mayEditClientSecret) {
|
|
@@ -242,8 +255,12 @@ export function ToolVarRow({
|
|
|
242
255
|
description = 'Each person sets their own';
|
|
243
256
|
if (variable.userConfigured) {
|
|
244
257
|
meta.push(
|
|
258
|
+
// "Key saved", not "Connected": a stored value is the whole of what
|
|
259
|
+
// this row knows. Whether it WORKS is the tool-level health line's
|
|
260
|
+
// claim, and letting a row make it was how a mistyped key came to
|
|
261
|
+
// render as a connection.
|
|
245
262
|
<Badge key="chip" tone="ok">
|
|
246
|
-
|
|
263
|
+
Key saved
|
|
247
264
|
</Badge>,
|
|
248
265
|
);
|
|
249
266
|
} else {
|
|
@@ -259,12 +276,17 @@ export function ToolVarRow({
|
|
|
259
276
|
const save = () => {
|
|
260
277
|
const secret = value;
|
|
261
278
|
if (isClientSecret) {
|
|
262
|
-
|
|
279
|
+
// Also a credential change: a replaced client secret can invalidate the
|
|
280
|
+
// tokens minted under the old one, so the tool's health is now unknown
|
|
281
|
+
// and worth re-testing — same as any other saved value.
|
|
282
|
+
return run(() => setOAuthClientSecret(slug, variable.name, secret), true);
|
|
263
283
|
}
|
|
264
|
-
return run(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
284
|
+
return run(
|
|
285
|
+
() =>
|
|
286
|
+
variable.scope === 'admin'
|
|
287
|
+
? setAdminVar(slug, variable.name, secret)
|
|
288
|
+
: setUserVar(slug, variable.name, secret),
|
|
289
|
+
true,
|
|
268
290
|
);
|
|
269
291
|
};
|
|
270
292
|
|