@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.
Files changed (35) hide show
  1. package/THIRD-PARTY-NOTICES.md +416 -418
  2. package/package.json +2 -2
  3. package/src/lib/__tests__/utils.test.ts +43 -0
  4. package/src/lib/utils.ts +15 -7
  5. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -0
  6. package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
  7. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
  8. package/src/modules/library/__tests__/ToolPage.test.tsx +164 -3
  9. package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
  10. package/src/modules/library/__tests__/status.test.ts +84 -0
  11. package/src/modules/library/components/LibraryCard.tsx +7 -1
  12. package/src/modules/library/components/skill-page/SkillPage.tsx +5 -1
  13. package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
  14. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
  15. package/src/modules/library/components/tool-page/ToolPage.tsx +103 -1
  16. package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
  17. package/src/modules/library/hooks/useToolPage.ts +28 -11
  18. package/src/modules/library/hooks/useToolSource.ts +77 -0
  19. package/src/modules/library/utils/status.ts +99 -10
  20. package/src/modules/onboarding/__tests__/onboarding.test.tsx +760 -730
  21. package/src/modules/onboarding/agent-clients.ts +9 -3
  22. package/src/modules/onboarding/components/WelcomePage.tsx +9 -7
  23. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
  24. package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
  25. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
  26. package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
  27. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +6 -10
  28. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +34 -12
  29. package/src/shared/mcp/ChatGptInstallLink.tsx +45 -0
  30. package/src/shared/mcp/ClaudeInstallLink.tsx +3 -3
  31. package/src/shared/mcp/ConnectionInstructions.tsx +17 -11
  32. package/src/shared/mcp/__tests__/ChatGptInstallLink.test.tsx +34 -0
  33. package/src/shared/mcp/__tests__/connect-snippets.test.ts +49 -13
  34. package/src/shared/mcp/connect-snippets.ts +41 -6
  35. package/src/shared/mcp/index.ts +4 -0
@@ -41,6 +41,12 @@ export interface ToolPageState {
41
41
  skillsLoaded: boolean;
42
42
  /** Skills whose `allowed-tools` reach this tool. */
43
43
  poweredSkills: LibrarySkillSummary[];
44
+ /**
45
+ * Bumped by every `reload()`. A same-slug reload no longer remounts the page,
46
+ * so a child that fetches its own data on `[slug]` would never refetch —
47
+ * this is the signal it puts in its dependency list instead.
48
+ */
49
+ revision: number;
44
50
  reload(): void;
45
51
  }
46
52
 
@@ -64,15 +70,23 @@ export function useToolPage(slug: string): ToolPageState {
64
70
  const [revision, setRevision] = useState(0);
65
71
  const requestRef = useRef(0);
66
72
 
67
- // Switching tools (or reloading) has to clear the PREVIOUS tool's spine and
68
- // detail, or the page paints stale content under the new slug's heading. That
69
- // reset is state derived from a changed input, so it happens during render
70
- // against the previous key rather than in the effect body — an effect resets
71
- // after paint, which is both a frame of the old tool showing through and the
72
- // synchronous setState that `react-hooks/set-state-in-effect` flags.
73
- // `useState(key)` seeds the key so a fresh mount, already holding LOADING,
74
- // does not reset itself on the first render.
75
- const key = `${slug}:${revision}`;
73
+ // Switching tools has to clear the PREVIOUS tool's spine and detail, or the
74
+ // page paints stale content under the new slug's heading. That reset is state
75
+ // derived from a changed input, so it happens during render against the
76
+ // previous key rather than in the effect body — an effect resets after paint,
77
+ // which is both a frame of the old tool showing through and the synchronous
78
+ // setState that `react-hooks/set-state-in-effect` flags. `useState(key)` seeds
79
+ // the key so a fresh mount, already holding LOADING, does not reset itself on
80
+ // the first render.
81
+ //
82
+ // Keyed on the SLUG ALONE, so a same-tool `reload()` refetches WITHOUT
83
+ // blanking the page. There is no stale-slug hazard when the slug hasn't
84
+ // changed, and blanking had a cost: it dropped the page to `loading`, which
85
+ // unmounts the whole tool page — taking with it the connection section's
86
+ // probe verdict, which is held in component state precisely because it is not
87
+ // stored anywhere. Saving a key and then being told nothing about whether it
88
+ // works is the outcome that made this worth fixing.
89
+ const key = slug;
76
90
  const [seenKey, setSeenKey] = useState(key);
77
91
  if (key !== seenKey) {
78
92
  setSeenKey(key);
@@ -106,7 +120,10 @@ export function useToolPage(slug: string): ToolPageState {
106
120
  if (current()) setDetail(d);
107
121
  })
108
122
  .catch(() => {
109
- // Degraded, not broken: no lede and no capabilities section.
123
+ // Degraded, not broken: no lede and no capabilities section — and on
124
+ // a same-slug reload, degraded NOW: the previous fetch's description
125
+ // must not stand in for one this fetch could not vouch for.
126
+ if (current()) setDetail(null);
110
127
  });
111
128
 
112
129
  listSkills()
@@ -141,5 +158,5 @@ export function useToolPage(slug: string): ToolPageState {
141
158
 
142
159
  const reload = useCallback(() => setRevision((r) => r + 1), []);
143
160
 
144
- return { ...spine, detail, skillsLoaded, poweredSkills, reload };
161
+ return { ...spine, detail, skillsLoaded, poweredSkills, revision, reload };
145
162
  }
@@ -0,0 +1,77 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
3
+ import { readFileOnBranch } from '../../change-requests/services/change-requests.api';
4
+
5
+ /**
6
+ * The raw bytes of a tool's definition file, read LAZILY — nothing is asked
7
+ * for until the caller says the source section is open.
8
+ *
9
+ * Why the official version and not the reader's current branch: the tool
10
+ * catalog is resolved against the default branch, so that is the file the
11
+ * platform actually runs AND the file whose read verdict admitted the tool to
12
+ * the page in the first place. Reading any other branch could 404 (or refuse)
13
+ * a file the listing just showed, and would show a draft as if it were live.
14
+ *
15
+ * Access needs no check here. `GET /api/workspace/:id/file` applies the same
16
+ * per-file read rule the tool listing filters on, against the same
17
+ * repo-relative path — so the endpoint is the authority, and a refusal simply
18
+ * lands as the error state.
19
+ *
20
+ * Not `useDefaultBranchFile`, which reads the same file from the same branch:
21
+ * that hook collapses "still reading" and "could not read" into one `null`,
22
+ * because its callers (a diff, an editor seed) render nothing either way. A
23
+ * disclosure must tell them apart — it owes the reader a visible answer when
24
+ * the read fails, and a silent spinner is not one.
25
+ */
26
+ export type ToolSourceStatus = 'idle' | 'loading' | 'loaded' | 'error';
27
+
28
+ export interface ToolSourceState {
29
+ status: ToolSourceStatus;
30
+ /** The file's text, verbatim — only on `loaded`. */
31
+ content: string | null;
32
+ }
33
+
34
+ const IDLE: ToolSourceState = { status: 'idle', content: null };
35
+ const LOADING: ToolSourceState = { status: 'loading', content: null };
36
+ const FAILED: ToolSourceState = { status: 'error', content: null };
37
+
38
+ export function useToolSource(path: string | null, open: boolean): ToolSourceState {
39
+ const [state, setState] = useState<ToolSourceState>(IDLE);
40
+ const requestRef = useRef(0);
41
+
42
+ /**
43
+ * `null` while closed, which is what makes the fetch lazy and what makes a
44
+ * close-then-reopen RETRY: the key changes on both edges, so a failed read is
45
+ * never cached as the section's permanent answer.
46
+ *
47
+ * Reset during render against the previous key, not in the effect — the same
48
+ * rule `useToolPage` follows. An effect would repaint the previous tool's
49
+ * source under the new heading for a frame, and the synchronous setState is
50
+ * what `react-hooks/set-state-in-effect` flags.
51
+ */
52
+ const key = open && path ? path : null;
53
+ const [seenKey, setSeenKey] = useState(key);
54
+ if (key !== seenKey) {
55
+ setSeenKey(key);
56
+ setState(key === null ? IDLE : LOADING);
57
+ }
58
+
59
+ useEffect(() => {
60
+ // Bumped on every pass, closes included, so an answer for a path the
61
+ // reader has already navigated (or closed) away from can never land.
62
+ const request = ++requestRef.current;
63
+ if (key === null) return;
64
+
65
+ readFileOnBranch(DEFAULT_BRANCH, key)
66
+ .then((content) => {
67
+ if (requestRef.current === request) setState({ status: 'loaded', content });
68
+ })
69
+ .catch(() => {
70
+ // Deliberately not the backend's message: a read refusal and a missing
71
+ // file must read the same, the way the page's not-found state does.
72
+ if (requestRef.current === request) setState(FAILED);
73
+ });
74
+ }, [key]);
75
+
76
+ return state;
77
+ }
@@ -1,4 +1,5 @@
1
- import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
1
+ import { formatRelativeTime } from '../../../lib/utils';
2
+ import type { ProbeVerdict, ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
3
 
3
4
  /**
4
5
  * Status derivation for the Library. Everything the cards, gems and loadout
@@ -25,15 +26,43 @@ export interface AttentionStatus {
25
26
  state: GemState;
26
27
  /** User-facing state line (glossary-compliant plain words). */
27
28
  text: string;
29
+ /**
30
+ * The sentence behind the word, for a tooltip: what the provider said, or why
31
+ * we couldn't ask. Absent when the word is the whole story.
32
+ *
33
+ * This is where a status EARNS its claim. "Connected" backed by "checked 2
34
+ * minutes ago" is a different assertion from "Connected" backed by nothing,
35
+ * and the difference is exactly what used to be missing.
36
+ */
37
+ hint?: string;
28
38
  }
29
39
 
40
+ /**
41
+ * Stored, and PROVEN to work by a real call.
42
+ *
43
+ * Reachable ONLY from a passing probe verdict. Nothing derived from what is
44
+ * merely stored may return this — that inference is the entire bug.
45
+ */
30
46
  const OK: AttentionStatus = { state: 'ok', text: 'Connected' };
31
47
 
48
+ /**
49
+ * In place, and untested — all a STORED value can ever support.
50
+ *
51
+ * Two words rather than one because they describe two different things the
52
+ * reader did. Green, because nothing here needs a person.
53
+ */
54
+ const SIGNED_IN: AttentionStatus = { state: 'ok', text: 'Signed in' };
55
+ const KEY_SAVED: AttentionStatus = { state: 'ok', text: 'Key saved' };
56
+
32
57
  /** Severity order for aggregation: broken sign-in beats anything merely unset. */
33
58
  const RANK: Record<GemState, number> = { ok: 0, warn: 1, err: 2 };
34
59
 
35
60
  /**
36
- * Two states, and the words for them: `Connected`, or `Needs <the thing>`.
61
+ * What ONE variable is: in place, or `Needs <the thing>`.
62
+ *
63
+ * Never `Connected`. This reads the vault, which knows only whether a value
64
+ * exists — so the strongest true statement it can make is that something was
65
+ * saved or signed into. Only a probe earns the other word.
37
66
  *
38
67
  * There is deliberately no middle. "Not set up yet", "Sign in again to keep
39
68
  * this working" and "Needs your sign-in" were three ways of saying one thing —
@@ -53,22 +82,82 @@ function varStatus(v: ToolVarStatus, canWrite: boolean): AttentionStatus {
53
82
  if (!v.adminConfigured) return notSetUp;
54
83
  if (v.authorized && v.needsReauth) return { state: 'err', text: 'Needs signing in again' };
55
84
  if (!v.authorized) return { state: 'warn', text: 'Needs your sign-in' };
56
- return OK;
85
+ return SIGNED_IN;
57
86
  }
58
87
  if (v.scope === 'user') {
59
- return v.userConfigured ? OK : { state: 'warn', text: 'Needs a key from you' };
88
+ return v.userConfigured ? KEY_SAVED : { state: 'warn', text: 'Needs a key from you' };
89
+ }
90
+ return v.adminConfigured ? KEY_SAVED : notSetUp;
91
+ }
92
+
93
+ /**
94
+ * The word for a tool that is fully SET UP, decided by whether the credential
95
+ * has actually been tested.
96
+ *
97
+ * Three outcomes, and the reason there are three: `Connected` is a claim we can
98
+ * back — something called the provider and it answered. `Key saved` is the
99
+ * narrower claim we can back when nothing tested it: a value is stored, and
100
+ * that is genuinely all we know. `Not working` is the provider's own verdict.
101
+ *
102
+ * `Key saved` stays GREEN. It is a complete, true statement about a tool that
103
+ * needs nothing from anybody, and painting it amber would put a permanent
104
+ * warning on every integration that simply has no way to be tested — which
105
+ * teaches people that amber means nothing.
106
+ *
107
+ * A tool whose vars are oauth-backed says `Signed in` instead: the user did not
108
+ * give us a key, they signed in, and telling them a key was saved is a small
109
+ * lie in a component whose entire job is to stop telling small lies.
110
+ */
111
+ function healthStatus(tool: ToolSecrets, verdict?: ProbeVerdict | null): AttentionStatus {
112
+ if (verdict?.status === 'ok') {
113
+ // The app's one relative-time formatter, not a local dialect of it. A
114
+ // verdict with no usable timestamp still just happened — it cannot outlive
115
+ // the component holding it — so "just now" is the honest fallback.
116
+ return { ...OK, hint: `Checked ${formatRelativeTime(verdict.checkedAt) || 'just now'}.` };
117
+ }
118
+ if (verdict?.status === 'failed') {
119
+ return {
120
+ state: 'err',
121
+ text: 'Not working',
122
+ hint: verdict.detail ?? 'The provider rejected this credential.',
123
+ };
60
124
  }
61
- return v.adminConfigured ? OK : notSetUp;
125
+ // The word has to match what the user actually did. A tool with no variables
126
+ // asked nothing of them, so "Key saved" would name a key that does not exist;
127
+ // an oauth-backed one got a sign-in, not a key. Same claim in all three cases
128
+ // — something is in place, nothing has tested it — said in the reader's terms.
129
+ const allOAuth = tool.variables.length > 0 && tool.variables.every((v) => v.oauth);
130
+ const text =
131
+ tool.variables.length === 0 ? 'No key needed' : allOAuth ? 'Signed in' : 'Key saved';
132
+ return {
133
+ state: 'ok',
134
+ text,
135
+ hint: verdict?.detail ?? "Not verified — this tool hasn't been tested yet.",
136
+ };
62
137
  }
63
138
 
64
- /** Aggregate connection state of one integration for the current user. */
65
- export function toolStatus(tool: ToolSecrets): AttentionStatus {
66
- let worst = OK;
139
+ /**
140
+ * Aggregate connection state of one integration for the current user.
141
+ *
142
+ * Setup comes FIRST: a tool still missing a key is `Needs a key from you`, never
143
+ * `Not working`. Both are unhealthy, but only one names something the user can
144
+ * act on, and a probe verdict from before the key was entered must not outrank
145
+ * the thing actually in the way. Only once every variable is provided does the
146
+ * question become whether what was provided works.
147
+ *
148
+ * `verdict` is the result of a probe the CALLER just ran and is holding, so only
149
+ * the tool page passes one. Every other surface — the library cards, the skill
150
+ * page's tool list — renders the untested green, because nothing there has
151
+ * tested anything: no verdict is stored, so claiming `Connected` on a list built
152
+ * from what is merely saved is the exact lie this module exists to stop.
153
+ */
154
+ export function toolStatus(tool: ToolSecrets, verdict?: ProbeVerdict | null): AttentionStatus {
155
+ let worst: AttentionStatus | null = null;
67
156
  for (const v of tool.variables) {
68
157
  const s = varStatus(v, tool.canWrite);
69
- if (RANK[s.state] > RANK[worst.state]) worst = s;
158
+ if (s.state !== 'ok' && (worst === null || RANK[s.state] > RANK[worst.state])) worst = s;
70
159
  }
71
- return worst;
160
+ return worst ?? healthStatus(tool, verdict);
72
161
  }
73
162
 
74
163
  /** Per-variable status rows for the integration detail dialog. */