dsh-project-mcp 0.2.0 → 0.4.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/README.md +108 -47
- package/lib/client.d.ts +77 -0
- package/lib/client.js +10127 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +3785 -0
- package/lib/index.js +7563 -0
- package/lib/index.js.map +1 -0
- package/package.json +31 -34
- package/src/activation.ts +170 -44
- package/src/client/design-fixtures.ts +96 -1
- package/src/client/design.ts +64 -51
- package/src/client/index.ts +74 -133
- package/src/client/locales/ui.ts +54 -20
- package/src/client/plugin-config.ts +9 -9
- package/src/client/settings.ts +2 -2
- package/src/client/sidebar-tab.ts +521 -0
- package/src/client/view.ts +780 -80
- package/src/index.ts +18 -3
- package/src/runtime.ts +185 -8
- package/src/shared.ts +9 -3
- package/src/types.ts +65 -0
- package/src/ui.ts +61 -3
package/src/client/view.ts
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* Browser half of the panel: the tab shows one surface for the project of the
|
|
3
3
|
* session it is open in — the session's declared servers, the sessions that read
|
|
4
4
|
* differently from the project, what the model sees, and the problems and the
|
|
5
|
-
* event ring under their own disclosures — while the
|
|
6
|
-
* keeps the whole picture across every project with a
|
|
7
|
-
* Settings page
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* event ring under their own disclosures — while the settings popup, opened from
|
|
6
|
+
* the tab's actions menu, keeps the whole picture across every project with a
|
|
7
|
+
* live session. The native Settings page (`settings.section`, see
|
|
8
|
+
* `./settings.ts`) is the third surface and shares this module's fetch/poll path,
|
|
9
|
+
* status colours and storage helpers.
|
|
10
10
|
*
|
|
11
|
-
* Data comes from the host over `/project-mcp/*` (see `src/ui.ts`):
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Data comes from the host over `/project-mcp/*` (see `src/ui.ts`): the browser
|
|
12
|
+
* half has nothing to call in process. The host half's types are imported
|
|
13
|
+
* type-only, which the bundler erases — the client bundle stays free of host
|
|
14
|
+
* code.
|
|
15
15
|
*
|
|
16
16
|
* @module dsh-project-mcp/client/view
|
|
17
17
|
*/
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { createElement as h, useCallback, useEffect, useState } from 'react'
|
|
20
20
|
import type { CSSProperties, ReactNode } from 'react'
|
|
21
21
|
import { ROUTE_ACTIONS, ROUTE_PREFIX, TAB_ID } from '../shared.ts'
|
|
22
|
-
import type { LogEvent, McpSnapshot, ProjectSnapshot, ServerRow, ServerStatus, SessionTools, SnapshotChange, ToolMode, ToolPolicy } from '../types.ts'
|
|
22
|
+
import type { LogEvent, McpSnapshot, ProjectSnapshot, ServerRow, ServerStatus, SessionTools, SnapshotChange, ToolFacts, ToolField, ToolMode, ToolPolicy, ToolReason } from '../types.ts'
|
|
23
23
|
import { hostTranslate, resolveHost } from './locales/host.ts'
|
|
24
24
|
import { operatorBody, pinBody, policyOf } from './policy.ts'
|
|
25
25
|
import { MCP_TOOL_PREFIX, idleOf, serverOfToolName, toolCalls } from './usage-view.ts'
|
|
@@ -124,16 +124,34 @@ export const en = {
|
|
|
124
124
|
idleDay: 'idle {count}d',
|
|
125
125
|
idleHour: 'idle {count}h',
|
|
126
126
|
idleMinute: 'idle {count}m',
|
|
127
|
-
// One tool row's detail block: the
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
127
|
+
// One tool row's detail block (F-56): the server the name was registered
|
|
128
|
+
// under with the state it is in, the tier said as a sentence, the two counter
|
|
129
|
+
// readings apart, and then what only the host can answer — the definition's
|
|
130
|
+
// own description, its fields, and why a hidden name is not in the request.
|
|
131
|
+
// The name, the clock and the step stay in the header, and the block prints
|
|
132
|
+
// them again in its own fact line because the contract's own probe reads the
|
|
133
|
+
// full `mcp__<server>__<tool>`, the step and the clock out of the open body
|
|
134
|
+
// (`contracts/surfaces.md` §1.5) — see the `idea` row that parks that question
|
|
135
|
+
// in `docs/features.md`. The host publishes no size for a single tool, so the
|
|
136
|
+
// budget estimate stays in the group line above — the only figure the reason
|
|
137
|
+
// line prints is a measurement the host sent it.
|
|
131
138
|
toolServer: 'server {server}',
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
toolServerState: '{server} · {state}',
|
|
140
|
+
toolTierPinned: 'pinned — always in the request',
|
|
141
|
+
toolTierSession: 'offered by this session',
|
|
142
|
+
toolTierContext: 'offered by the context ranking',
|
|
143
|
+
showTool: 'show this tool’s server, description, fields and how it was offered',
|
|
144
|
+
hideTool: 'hide this tool’s detail',
|
|
145
|
+
toolCallsSession: '{count} this session',
|
|
146
|
+
toolLoading: 'reading this definition from the host…',
|
|
147
|
+
toolFailed: 'the host did not answer for this definition',
|
|
148
|
+
toolFieldsLabel: 'takes',
|
|
149
|
+
toolFieldRequiredHint: 'required field',
|
|
150
|
+
toolReasonBudget: 'not offered: {chars} chars over the {budget}-char budget',
|
|
151
|
+
toolReasonChars: '{chars} chars',
|
|
152
|
+
toolReasonBudgetOnly: '{budget}-char budget',
|
|
153
|
+
toolReasonUsed: '{used} already offered',
|
|
154
|
+
toolReason: 'not offered',
|
|
137
155
|
// The errors and logs blocks, under their own disclosures: the event ring is
|
|
138
156
|
// the plugin's own, one project at a time.
|
|
139
157
|
errorsSection: 'Problems',
|
|
@@ -241,10 +259,13 @@ export const en = {
|
|
|
241
259
|
toastFailed: '{server} failed',
|
|
242
260
|
toastReleased: '{server} released',
|
|
243
261
|
toastDetail: '{project} · {detail}',
|
|
244
|
-
// The
|
|
245
|
-
//
|
|
262
|
+
// The poll interval's row in the settings panel, read live through the seat
|
|
263
|
+
// on every render.
|
|
246
264
|
refreshTitle: 'Refresh interval',
|
|
247
265
|
refreshDesc: 'How often the panel re-reads the host snapshot',
|
|
266
|
+
// The tab's actions menu (the chip's own menu): the row that opens the
|
|
267
|
+
// settings popup, which used to be the sidebar's side card.
|
|
268
|
+
settingsMenuItem: 'Panel settings…',
|
|
248
269
|
// The design stand's own tab title and description (design.ts).
|
|
249
270
|
designTitle: 'Project MCP · design ({variant})',
|
|
250
271
|
designDesc: 'design mode: the {variant} fixture, no host behind it',
|
|
@@ -276,9 +297,20 @@ export function fallbackTranslate(key: string, params?: Record<string, unknown>)
|
|
|
276
297
|
)
|
|
277
298
|
}
|
|
278
299
|
|
|
279
|
-
/**
|
|
300
|
+
/** Name of the poll interval inside {@link REFRESH_STORAGE_KEY}. */
|
|
280
301
|
export const REFRESH_KEY = 'refreshMs'
|
|
281
302
|
|
|
303
|
+
/**
|
|
304
|
+
* `localStorage` key the poll interval is persisted under.
|
|
305
|
+
*
|
|
306
|
+
* The interval used to ride the side card's own settings blob
|
|
307
|
+
* (`prefs.pluginSettings[TAB_ID]` of `dsh-better-sidebar`). That surface is gone
|
|
308
|
+
* with the dependency, so the interval is a browser-local preference beside the
|
|
309
|
+
* view, the log filters and the Clear mark — same lifetime, same hostile-storage
|
|
310
|
+
* rule, one less service to read it from.
|
|
311
|
+
*/
|
|
312
|
+
export const REFRESH_STORAGE_KEY = `${TAB_ID}:${REFRESH_KEY}`
|
|
313
|
+
|
|
282
314
|
/** Poll interval used until the setting is read. */
|
|
283
315
|
export const DEFAULT_REFRESH_MS = 5_000
|
|
284
316
|
|
|
@@ -557,6 +589,30 @@ export const STYLE = {
|
|
|
557
589
|
cursor: 'pointer',
|
|
558
590
|
} satisfies CSSProperties,
|
|
559
591
|
error: { padding: 8, color: STATUS_COLOR.error } satisfies CSSProperties,
|
|
592
|
+
/**
|
|
593
|
+
* The poll interval's row in the settings panel: a label that stacks the
|
|
594
|
+
* toggle's own title and hint, the field it points at, and the unit beside it.
|
|
595
|
+
* Laid out as one row so the panel reads like the side card the row came from.
|
|
596
|
+
*/
|
|
597
|
+
settingRow: {
|
|
598
|
+
display: 'flex',
|
|
599
|
+
alignItems: 'center',
|
|
600
|
+
gap: 8,
|
|
601
|
+
padding: '8px 8px 0',
|
|
602
|
+
} satisfies CSSProperties,
|
|
603
|
+
settingLabel: { display: 'flex', flexDirection: 'column', gap: 2, flex: 1 } satisfies CSSProperties,
|
|
604
|
+
settingTitle: { fontSize: 12 } satisfies CSSProperties,
|
|
605
|
+
settingDesc: { fontSize: 11, color: TONE.tertiary } satisfies CSSProperties,
|
|
606
|
+
settingInput: {
|
|
607
|
+
width: 72,
|
|
608
|
+
padding: '2px 6px',
|
|
609
|
+
borderRadius: 4,
|
|
610
|
+
border: BORDER,
|
|
611
|
+
background: 'transparent',
|
|
612
|
+
color: 'inherit',
|
|
613
|
+
font: 'inherit',
|
|
614
|
+
} satisfies CSSProperties,
|
|
615
|
+
settingUnit: { fontSize: 11, color: TONE.tertiary } satisfies CSSProperties,
|
|
560
616
|
/**
|
|
561
617
|
* One disclosure of the single surface (F-26): a block of the scrolling body
|
|
562
618
|
* whose head is a button and whose body exists only while it is open. The
|
|
@@ -610,14 +666,30 @@ export const STYLE = {
|
|
|
610
666
|
textAlign: 'left',
|
|
611
667
|
} satisfies CSSProperties,
|
|
612
668
|
/**
|
|
613
|
-
* The open detail of one tool:
|
|
614
|
-
* the
|
|
615
|
-
*
|
|
669
|
+
* The open detail of one tool (F-56): the server it was registered under with
|
|
670
|
+
* the state it is in, the tier as a sentence, the counter readings this row does
|
|
671
|
+
* not show, and then the host's own on-demand answer about the definition — its
|
|
672
|
+
* description, the fields it takes, and why a hidden name is not in the request.
|
|
673
|
+
* One rung in from the row, like every other body of a disclosure.
|
|
616
674
|
*/
|
|
617
675
|
toolDetail: {
|
|
618
676
|
flexBasis: '100%',
|
|
619
677
|
padding: '2px 0 4px 12px',
|
|
620
678
|
} satisfies CSSProperties,
|
|
679
|
+
/** One accepted field of a definition: its mono name, type, marker and description. */
|
|
680
|
+
field: {
|
|
681
|
+
display: 'flex',
|
|
682
|
+
flexWrap: 'wrap',
|
|
683
|
+
alignItems: 'baseline',
|
|
684
|
+
gap: 5,
|
|
685
|
+
padding: '1px 0',
|
|
686
|
+
overflowWrap: 'anywhere',
|
|
687
|
+
} satisfies CSSProperties,
|
|
688
|
+
fieldName: {
|
|
689
|
+
fontFamily: 'var(--dsw-font-mono, ui-monospace, monospace)',
|
|
690
|
+
overflowWrap: 'anywhere',
|
|
691
|
+
} satisfies CSSProperties,
|
|
692
|
+
fieldDesc: { color: TONE.secondary, opacity: 0.75 } satisfies CSSProperties,
|
|
621
693
|
group: {
|
|
622
694
|
opacity: 0.6,
|
|
623
695
|
fontSize: '0.8em',
|
|
@@ -1009,6 +1081,77 @@ export function storeString(
|
|
|
1009
1081
|
}
|
|
1010
1082
|
}
|
|
1011
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* Read the poll interval out of browser-local storage.
|
|
1086
|
+
*
|
|
1087
|
+
* A missing, unreadable or nonsensical value is not an error: the panel falls
|
|
1088
|
+
* back to {@link DEFAULT_REFRESH_MS}, exactly as it did when the value arrived
|
|
1089
|
+
* in an untyped plugin-settings blob.
|
|
1090
|
+
* @param storage - storage to read; defaults to the browser's own.
|
|
1091
|
+
* @returns the stored interval in milliseconds, or the default.
|
|
1092
|
+
*/
|
|
1093
|
+
export function storedRefreshMs(storage: PanelStorage | undefined = browserStorage()): number {
|
|
1094
|
+
const raw = storedString(REFRESH_STORAGE_KEY, storage)
|
|
1095
|
+
if (raw === undefined) return DEFAULT_REFRESH_MS
|
|
1096
|
+
const value = Number(raw)
|
|
1097
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULT_REFRESH_MS
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* The poll interval as a live preference.
|
|
1102
|
+
*
|
|
1103
|
+
* Two surfaces read it — the panel it paces and the settings that change it —
|
|
1104
|
+
* and they are not in one tree (the settings live in the tab's actions menu), so
|
|
1105
|
+
* the value needs a seat both can subscribe to. The store is the same shape the
|
|
1106
|
+
* toast stack uses: a value, a setter, and listeners for whoever renders it.
|
|
1107
|
+
* Writes go to browser storage first, so a reload keeps the interval even when
|
|
1108
|
+
* no surface is left to re-render.
|
|
1109
|
+
*/
|
|
1110
|
+
export interface RefreshStore {
|
|
1111
|
+
/** The current interval in milliseconds. */
|
|
1112
|
+
get(): number
|
|
1113
|
+
/** Persist and publish a new interval; a value the surface cannot render is the caller's business. */
|
|
1114
|
+
set(value: number): void
|
|
1115
|
+
/** Subscribe to changes; the returned function unsubscribes. */
|
|
1116
|
+
subscribe(listener: () => void): () => void
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Build a {@link RefreshStore} on top of browser storage.
|
|
1121
|
+
* @param storage - storage to read and write; defaults to the browser's own.
|
|
1122
|
+
* @returns the store, seeded from what is already persisted.
|
|
1123
|
+
*/
|
|
1124
|
+
export function createRefreshStore(
|
|
1125
|
+
storage: PanelStorage | undefined = browserStorage(),
|
|
1126
|
+
): RefreshStore {
|
|
1127
|
+
let value = storedRefreshMs(storage)
|
|
1128
|
+
const listeners = new Set<() => void>()
|
|
1129
|
+
return {
|
|
1130
|
+
get: () => value,
|
|
1131
|
+
set: (next: number): void => {
|
|
1132
|
+
if (!Number.isFinite(next) || next <= 0 || next === value) return
|
|
1133
|
+
value = next
|
|
1134
|
+
storeString(REFRESH_STORAGE_KEY, String(next), storage)
|
|
1135
|
+
for (const listener of listeners) listener()
|
|
1136
|
+
},
|
|
1137
|
+
subscribe: (listener: () => void): (() => void) => {
|
|
1138
|
+
listeners.add(listener)
|
|
1139
|
+
return () => listeners.delete(listener)
|
|
1140
|
+
},
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Read the store as a re-rendering hook.
|
|
1146
|
+
* @param store - the store to follow.
|
|
1147
|
+
* @returns the current interval, re-read after every change.
|
|
1148
|
+
*/
|
|
1149
|
+
export function useRefreshMs(store: RefreshStore): number {
|
|
1150
|
+
const [value, setValue] = useState(() => store.get())
|
|
1151
|
+
useEffect(() => store.subscribe(() => setValue(store.get())), [store])
|
|
1152
|
+
return value
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1012
1155
|
/**
|
|
1013
1156
|
* Which sessions the Logs tab reads: the tab's own session, or every session of
|
|
1014
1157
|
* the project. The mockup offers exactly these two.
|
|
@@ -1167,6 +1310,152 @@ export async function fetchLogs(
|
|
|
1167
1310
|
}
|
|
1168
1311
|
}
|
|
1169
1312
|
|
|
1313
|
+
/**
|
|
1314
|
+
* What one opened row's definition costs to answer, and what is already known
|
|
1315
|
+
* about it: the one place a `GET tool` answer is held (F-56).
|
|
1316
|
+
*
|
|
1317
|
+
* One cache for the module, keyed by the route's own three parameters, rather
|
|
1318
|
+
* than one per mount. The answer is a fact about the name, not about a render —
|
|
1319
|
+
* folding a row and opening it again must not re-read the host, and the design
|
|
1320
|
+
* stand seeds this map directly instead of mounting a host to fake one. The key
|
|
1321
|
+
* carries the project and the session because the route takes them and two
|
|
1322
|
+
* surfaces of the panel may read different ones in one process.
|
|
1323
|
+
*
|
|
1324
|
+
* An entry is written **only** by answers that arrived: a fetch in flight is in
|
|
1325
|
+
* {@link toolFactsPending} and a failed one in {@link toolFactsFailed}, so a
|
|
1326
|
+
* mount that skipped the tool routes pulls in no fixture code and draws no
|
|
1327
|
+
* invented answer.
|
|
1328
|
+
*/
|
|
1329
|
+
interface ToolFactsEntry {
|
|
1330
|
+
readonly projectRoot: string
|
|
1331
|
+
readonly sessionId: string
|
|
1332
|
+
readonly name: string
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
const TOOL_FACTS_SEPARATOR = '\u0000'
|
|
1336
|
+
const toolFacts = new Map<string, ToolFacts>()
|
|
1337
|
+
const toolFactsPending = new Set<string>()
|
|
1338
|
+
const toolFactsFailed = new Set<string>()
|
|
1339
|
+
|
|
1340
|
+
/** The cache key of one `GET tool` answer. */
|
|
1341
|
+
function toolFactsKey(projectRoot: string, sessionId: string, name: string): string {
|
|
1342
|
+
return [projectRoot, sessionId, name].join(TOOL_FACTS_SEPARATOR)
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/** Build the `GET tool` query for one opened row's definition. */
|
|
1346
|
+
function toolFactsQuery(projectRoot: string, sessionId: string, name: string): URLSearchParams {
|
|
1347
|
+
return new URLSearchParams({ projectRoot, sessionId, name })
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Read one tool's facts over the contract's `GET tool` route.
|
|
1352
|
+
*
|
|
1353
|
+
* The snapshot carries no definition, and cannot: a description and a schema are
|
|
1354
|
+
* the expensive part of a tool, while every change frame and every poll carries
|
|
1355
|
+
* the whole snapshot. This route is therefore read once per row the reader
|
|
1356
|
+
* opens, exactly as `GET logs` is read once per page — and it answers a
|
|
1357
|
+
* **deferred** name the same way as an offered one, because the definition is
|
|
1358
|
+
* read from the scope the bridge registered it in and not from the offer.
|
|
1359
|
+
* Unknown names answer `ok: false` and are indistinguishable here from a refusal,
|
|
1360
|
+
* which is the route's own decision: the panel draws its one failure line.
|
|
1361
|
+
* @param projectRoot - project the definition belongs to.
|
|
1362
|
+
* @param sessionId - session the row is open in; the host scopes the read to it.
|
|
1363
|
+
* @param name - public registry name, eg `mcp__tglider__workspace`.
|
|
1364
|
+
* @param fetchImpl - `fetch` to use; defaults to the browser's.
|
|
1365
|
+
* @returns the facts, or `undefined` when the host refused or the answer was unreadable.
|
|
1366
|
+
*/
|
|
1367
|
+
export async function fetchToolFacts(
|
|
1368
|
+
projectRoot: string,
|
|
1369
|
+
sessionId: string,
|
|
1370
|
+
name: string,
|
|
1371
|
+
fetchImpl: typeof fetch | undefined = (globalThis as { fetch?: typeof fetch }).fetch,
|
|
1372
|
+
): Promise<ToolFacts | undefined> {
|
|
1373
|
+
if (fetchImpl === undefined) return undefined
|
|
1374
|
+
// Read out of the shared registry like `logs`, so a build whose contract has
|
|
1375
|
+
// no `tool` action asks for nothing rather than for a route nobody serves.
|
|
1376
|
+
const action = (ROUTE_ACTIONS as Record<string, string | undefined>).tool
|
|
1377
|
+
if (action === undefined) return undefined
|
|
1378
|
+
try {
|
|
1379
|
+
const query = toolFactsQuery(projectRoot, sessionId, name)
|
|
1380
|
+
const response = await fetchImpl(`${ROUTE_PREFIX}/${action}?${query.toString()}`)
|
|
1381
|
+
const payload = (await response.json()) as Envelope<ToolFacts>
|
|
1382
|
+
if (payload.ok !== true || payload.value === undefined) return undefined
|
|
1383
|
+
// A host that answered the envelope with something that is not a record is
|
|
1384
|
+
// as unreadable as a refusal: caching it under the row's key would put a
|
|
1385
|
+
// shape the body cannot draw on screen, so the panel takes the failure line
|
|
1386
|
+
// instead of an invented definition.
|
|
1387
|
+
const value = payload.value as Partial<ToolFacts>
|
|
1388
|
+
if (typeof value.name !== 'string' || !Array.isArray(value.fields)) return undefined
|
|
1389
|
+
return payload.value
|
|
1390
|
+
} catch {
|
|
1391
|
+
return undefined
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* The facts known about one name, asked for at most once per route.
|
|
1397
|
+
*
|
|
1398
|
+
* Called from the render of a row that is open — the only moment the answer is
|
|
1399
|
+
* wanted — so a folded row costs nothing. A synchronous answer already in the
|
|
1400
|
+
* map is returned now; otherwise the read starts once and the caller draws
|
|
1401
|
+
* {@link toolFactsLoading}'s line until the promise settles and re-renders. The
|
|
1402
|
+
* name-only entry is read first because that is where a seeded stand writes, and
|
|
1403
|
+
* a definition is the same record whichever panel asked for it.
|
|
1404
|
+
* @param entry - the route's own parameters.
|
|
1405
|
+
* @returns the facts while they are held; `undefined` while the read is on its way.
|
|
1406
|
+
*/
|
|
1407
|
+
function toolFactsOf(entry: ToolFactsEntry): ToolFacts | undefined {
|
|
1408
|
+
const seeded = toolFacts.get(entry.name)
|
|
1409
|
+
if (seeded !== undefined) return seeded
|
|
1410
|
+
const key = toolFactsKey(entry.projectRoot, entry.sessionId, entry.name)
|
|
1411
|
+
const held = toolFacts.get(key)
|
|
1412
|
+
if (held !== undefined || toolFactsPending.has(key) || toolFactsFailed.has(key)) return held
|
|
1413
|
+
toolFactsPending.add(key)
|
|
1414
|
+
void fetchToolFacts(entry.projectRoot, entry.sessionId, entry.name).then((facts) => {
|
|
1415
|
+
toolFactsPending.delete(key)
|
|
1416
|
+
if (facts === undefined) toolFactsFailed.add(key)
|
|
1417
|
+
else toolFacts.set(key, facts)
|
|
1418
|
+
})
|
|
1419
|
+
return undefined
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
/** `true` once the host refused to answer for this name. */
|
|
1423
|
+
function toolFactsUnreadable(entry: ToolFactsEntry): boolean {
|
|
1424
|
+
return toolFactsFailed.has(toolFactsKey(entry.projectRoot, entry.sessionId, entry.name))
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Publish one definition into the panel's cache, as the design mode's own host
|
|
1429
|
+
* would answer.
|
|
1430
|
+
*
|
|
1431
|
+
* The stand renders the same components with no host at all, so the body of an
|
|
1432
|
+
* opened row would sit on a read that never resolves. Seeding the very map the
|
|
1433
|
+
* product reads — rather than a second "fixture mode" branch inside the row —
|
|
1434
|
+
* is what keeps the product's drawing and the stand's one drawing: `view.ts`
|
|
1435
|
+
* has no code path that knows whether the answer came from a socket. The entry is
|
|
1436
|
+
* written under the name alone, which is the key a row with no route of its own
|
|
1437
|
+
* looks up; a panel that does hold one looks there first, for the same reason.
|
|
1438
|
+
* @param name - the public registry name the record answers about.
|
|
1439
|
+
* @param facts - the record the fixture host publishes for that name.
|
|
1440
|
+
*/
|
|
1441
|
+
export function seedToolFacts(name: string, facts: ToolFacts): void {
|
|
1442
|
+
toolFacts.set(name, facts)
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* Forget every held definition.
|
|
1447
|
+
*
|
|
1448
|
+
* Exported for the specs: one process renders several panels for several
|
|
1449
|
+
* projects, and an answer held for one of them must not decide another's body.
|
|
1450
|
+
* The product never calls this — a definition does not change while a panel is
|
|
1451
|
+
* mounted.
|
|
1452
|
+
*/
|
|
1453
|
+
export function clearToolFacts(): void {
|
|
1454
|
+
toolFacts.clear()
|
|
1455
|
+
toolFactsPending.clear()
|
|
1456
|
+
toolFactsFailed.clear()
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1170
1459
|
/**
|
|
1171
1460
|
* The events one session's ring holds, as the logs disclosure's badge counts them.
|
|
1172
1461
|
*
|
|
@@ -1541,7 +1830,15 @@ export function tabBody(props: TabBodyProps): ReactNode {
|
|
|
1541
1830
|
return [
|
|
1542
1831
|
rows.length === 0
|
|
1543
1832
|
? emptyState(t('noServersDeclared'), declaredHint(project, t), 'servers')
|
|
1544
|
-
: h(ServersBlock, {
|
|
1833
|
+
: h(ServersBlock, {
|
|
1834
|
+
key: 'servers',
|
|
1835
|
+
rows,
|
|
1836
|
+
usage: project.usage,
|
|
1837
|
+
t,
|
|
1838
|
+
hostT: props.hostT,
|
|
1839
|
+
onRetry: props.onRetry,
|
|
1840
|
+
busy: props.busy,
|
|
1841
|
+
}),
|
|
1545
1842
|
// The F-24 disagreement view. The merged project rows are no longer drawn
|
|
1546
1843
|
// here — the block above is this session's own reading — but `Release` for a
|
|
1547
1844
|
// single session still lives only in this section.
|
|
@@ -2263,12 +2560,17 @@ export function budgetLine(tools: SessionTools, t: Translate): ReactNode {
|
|
|
2263
2560
|
}
|
|
2264
2561
|
|
|
2265
2562
|
/**
|
|
2266
|
-
* What one tool row's detail block is opened with (F-26).
|
|
2563
|
+
* What one tool row's detail block is opened with (F-26, F-56).
|
|
2267
2564
|
*
|
|
2268
2565
|
* The block prints only what the host published about this one name. `SessionTools`
|
|
2269
2566
|
* measures the whole set (`surfaceChars` / `visibleChars` / `deferredChars`), not
|
|
2270
2567
|
* a single tool, so there is no per-tool size here to print and none is derived:
|
|
2271
2568
|
* the group's own budget line is where an estimate is real.
|
|
2569
|
+
*
|
|
2570
|
+
* What F-56 removed from the block is what the header already carries: the
|
|
2571
|
+
* registry name, the clock and the step. The tier stays here, but as the one
|
|
2572
|
+
* thing the header's dot cannot say while nobody hovers — and it reads as a
|
|
2573
|
+
* sentence rather than as the wire word.
|
|
2272
2574
|
*/
|
|
2273
2575
|
export interface ToolDetail {
|
|
2274
2576
|
/** Tier that offered the name: the pin list, this session, or context ranking. */
|
|
@@ -2281,35 +2583,294 @@ export interface ToolDetail {
|
|
|
2281
2583
|
open: boolean
|
|
2282
2584
|
/** Toggle this row's detail block. */
|
|
2283
2585
|
onToggle: () => void
|
|
2586
|
+
/**
|
|
2587
|
+
* The session's own declared rows, read for the serving server's state — the
|
|
2588
|
+
* same {@link ServerRow} the block above draws. Absent on a surface that has no
|
|
2589
|
+
* servers to hand down (a unit test of the row, the design stand's own rows),
|
|
2590
|
+
* and then the state is simply not printed: the panel never guesses a status.
|
|
2591
|
+
*/
|
|
2592
|
+
rows?: readonly ServerRow[] | undefined
|
|
2593
|
+
/**
|
|
2594
|
+
* Both counter readings the row's header was seeded with, so the block can
|
|
2595
|
+
* print the two of them apart: the header keeps the lead figure
|
|
2596
|
+
* ({@link callsLabel}'s choice) and the body adds the reading the header had no
|
|
2597
|
+
* room for. Absent where the host published no record for the row's server.
|
|
2598
|
+
*/
|
|
2599
|
+
calls?: ToolCalls | undefined
|
|
2600
|
+
/**
|
|
2601
|
+
* Project the definition belongs to — the route's own first parameter.
|
|
2602
|
+
*
|
|
2603
|
+
* Absent together with {@link ToolDetail.sessionId} on a surface that is not
|
|
2604
|
+
* reading a host at all (the design stand's fixtures are seeded straight into
|
|
2605
|
+
* the cache, and a unit test of the row composes it without a route): the body
|
|
2606
|
+
* then draws no line rather than asking an address it was never given.
|
|
2607
|
+
*/
|
|
2608
|
+
projectRoot?: string | undefined
|
|
2609
|
+
/** Session the row is open in — the route's own second parameter. */
|
|
2610
|
+
sessionId?: string | undefined
|
|
2284
2611
|
}
|
|
2285
2612
|
|
|
2286
2613
|
/**
|
|
2287
|
-
* The
|
|
2614
|
+
* The state of the server one registry name was registered under, as the row's
|
|
2615
|
+
* own block prints it.
|
|
2288
2616
|
*
|
|
2289
|
-
* The
|
|
2290
|
-
*
|
|
2291
|
-
*
|
|
2292
|
-
*
|
|
2293
|
-
* server is printed rather than a guessed one.
|
|
2617
|
+
* The rows handed down are the session's declared ones — `sessionRowsOf`'s list
|
|
2618
|
+
* — so a name whose server the host never declared gets no status, and neither
|
|
2619
|
+
* does a name without the `mcp__` prefix. "The server is not in the list" and
|
|
2620
|
+
* "the server is idle" are different facts, and only the second is printable.
|
|
2294
2621
|
* @param name - the registry name on the row.
|
|
2295
|
-
* @param
|
|
2622
|
+
* @param rows - the session's declared rows; absent draws no state at all.
|
|
2296
2623
|
* @param t - translate seat.
|
|
2297
|
-
* @returns the
|
|
2624
|
+
* @returns the sentence, or `undefined` when there is no server row to read.
|
|
2298
2625
|
*/
|
|
2299
|
-
export function
|
|
2626
|
+
export function toolServerState(
|
|
2627
|
+
name: string,
|
|
2628
|
+
rows: readonly ServerRow[] | undefined,
|
|
2629
|
+
t: Translate,
|
|
2630
|
+
): string | undefined {
|
|
2300
2631
|
const server = serverOfToolName(name)
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2632
|
+
if (server === undefined) return undefined
|
|
2633
|
+
const row = (rows ?? []).find((entry) => entry.name === server)
|
|
2634
|
+
if (row === undefined) return undefined
|
|
2635
|
+
return t('toolServerState', { server, state: t(STATUS_KEYS[row.status]) })
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
/** The tier one row was offered by, said as a sentence (F-56). */
|
|
2639
|
+
export function toolTierSentence(via: ToolDetail['via'], t: Translate): string {
|
|
2640
|
+
return via === 'pin'
|
|
2641
|
+
? t('toolTierPinned')
|
|
2642
|
+
: via === 'session'
|
|
2643
|
+
? t('toolTierSession')
|
|
2644
|
+
: t('toolTierContext')
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
/**
|
|
2648
|
+
* The two counter readings of one row's block (F-56), one line, each figure
|
|
2649
|
+
* labelled by what it counts.
|
|
2650
|
+
*
|
|
2651
|
+
* The block no longer repeats what the header shows — the header keeps the lead
|
|
2652
|
+
* figure, `callsLabel`'s own choice — so the project's total comes back only when
|
|
2653
|
+
* the host published it, and the session's own only when the session's slice
|
|
2654
|
+
* exists. A server the host never recorded draws nothing at all: this is the same
|
|
2655
|
+
* "no data, no label" rule the row obeys, one level down.
|
|
2656
|
+
* @param calls - the two readings, absent when the host published no record.
|
|
2657
|
+
* @param t - translate seat.
|
|
2658
|
+
* @returns the line, or `undefined` when there is no figure to print.
|
|
2659
|
+
*/
|
|
2660
|
+
export function toolCallsLine(calls: ToolCalls | undefined, t: Translate): string | undefined {
|
|
2661
|
+
if (calls === undefined || !calls.recorded) return undefined
|
|
2662
|
+
const project = calls.project
|
|
2663
|
+
const session = calls.session
|
|
2664
|
+
const parts = [
|
|
2665
|
+
project === undefined ? undefined : t('callsProject', { count: project }),
|
|
2666
|
+
session === undefined ? undefined : t('toolCallsSession', { count: session }),
|
|
2667
|
+
].filter((part): part is string => part !== undefined)
|
|
2668
|
+
return parts.length === 0 ? undefined : parts.join(' · ')
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
/**
|
|
2672
|
+
* Why one name is not in this session's request, in the host's own figures
|
|
2673
|
+
* (F-56).
|
|
2674
|
+
*
|
|
2675
|
+
* Every number here arrived in `ToolFacts.reason`; a figure the host did not
|
|
2676
|
+
* measure leaves its phrase out rather than printing a zero, which is the same
|
|
2677
|
+
* discipline as contract C2's step tag. The whole sentence uses the complete
|
|
2678
|
+
* template while all three figures are there, so a reader of any language gets
|
|
2679
|
+
* its own grammar; a shorter answer falls back to the phrases that did arrive.
|
|
2680
|
+
* @param reason - the host's reason, or `undefined` for an offered name.
|
|
2681
|
+
* @param t - translate seat.
|
|
2682
|
+
* @returns the sentence, or `undefined` when there is nothing to print.
|
|
2683
|
+
*/
|
|
2684
|
+
export function toolReasonLine(reason: ToolReason | undefined, t: Translate): string | undefined {
|
|
2685
|
+
if (reason === undefined) return undefined
|
|
2686
|
+
const { chars, budget, used } = reason
|
|
2687
|
+
if (chars !== undefined && budget !== undefined && used !== undefined) {
|
|
2688
|
+
return t('toolReasonBudget', { chars, budget, used })
|
|
2689
|
+
}
|
|
2690
|
+
return [
|
|
2691
|
+
chars === undefined ? undefined : t('toolReasonChars', { chars }),
|
|
2692
|
+
budget === undefined ? undefined : t('toolReasonBudgetOnly', { budget }),
|
|
2693
|
+
used === undefined ? undefined : t('toolReasonUsed', { used }),
|
|
2694
|
+
].filter((part): part is string => part !== undefined)
|
|
2695
|
+
.join(', ') || t('toolReason')
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
/**
|
|
2699
|
+
* The view model one opened row's body is drawn from.
|
|
2700
|
+
*
|
|
2701
|
+
* `loading` is the state of a read that has started and not landed, and it is
|
|
2702
|
+
* drawn as its own muted line rather than as an empty body: the answer is on its
|
|
2703
|
+
* way, and a block that drew nothing would read as "there is nothing to say".
|
|
2704
|
+
* `failure` is the host's refusal — an unknown name, or an older host without the
|
|
2705
|
+
* route — and it is drawn as a muted line too. Neither state invents a fact.
|
|
2706
|
+
*/
|
|
2707
|
+
export interface ToolFactsView {
|
|
2708
|
+
readonly state: 'loading' | 'failure' | 'facts'
|
|
2709
|
+
readonly facts?: ToolFacts | undefined
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
/**
|
|
2713
|
+
* What one opened row currently knows, read from the module's own cache.
|
|
2714
|
+
*
|
|
2715
|
+
* This is the **only** place the row's body asks for the definition: one call per
|
|
2716
|
+
* open row, from the row's own render, so a folded row costs nothing and a
|
|
2717
|
+
* refolded one is answered from {@link toolFacts}. A row with no route to ask —
|
|
2718
|
+
* the stand's seeded rows carry one, a unit test's may not — still reads the
|
|
2719
|
+
* cache, so a seeded answer is answered synchronously and an unseeded one draws
|
|
2720
|
+
* the loading line instead of contacting an address nobody gave.
|
|
2721
|
+
* @param name - the registry name on the row.
|
|
2722
|
+
* @param detail - the row's disclosure state and the session's own rows.
|
|
2723
|
+
* @returns the view model for the body; `loading` while the read is in flight.
|
|
2724
|
+
*/
|
|
2725
|
+
export function toolFactsView(name: string, detail: ToolDetail): ToolFactsView {
|
|
2726
|
+
const { projectRoot, sessionId } = detail
|
|
2727
|
+
// No route to ask: read what the cache already holds and start nothing. This
|
|
2728
|
+
// is the design stand's and a unit test's own path — a seeded answer is drawn,
|
|
2729
|
+
// an unseeded one waits, and neither opens a connection nobody asked for.
|
|
2730
|
+
if (projectRoot === undefined || sessionId === undefined) {
|
|
2731
|
+
// With no route in hand the panel reads the cache the way the seeded stand
|
|
2732
|
+
// does: a name is looked up as itself, so "no route" costs a definition
|
|
2733
|
+
// nothing rather than hiding it behind parameters nobody has.
|
|
2734
|
+
const failed = toolFactsFailed.has(name)
|
|
2735
|
+
const held = failed ? undefined : toolFacts.get(name)
|
|
2736
|
+
if (held !== undefined) return { state: 'facts', facts: held }
|
|
2737
|
+
return failed ? { state: 'failure' } : { state: 'loading' }
|
|
2738
|
+
}
|
|
2739
|
+
const entry: ToolFactsEntry = { projectRoot, sessionId, name }
|
|
2740
|
+
const held = toolFactsOf(entry)
|
|
2741
|
+
if (held !== undefined) return { state: 'facts', facts: held }
|
|
2742
|
+
return toolFactsUnreadable(entry) ? { state: 'failure' } : { state: 'loading' }
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
/** One accepted field, as the block lists it: mono name, type, marker, description. */
|
|
2746
|
+
function fieldLine(field: ToolField, index: number, t: Translate): ReactNode {
|
|
2747
|
+
return h(
|
|
2748
|
+
'div',
|
|
2749
|
+
{ key: `${field.name}-${String(index)}`, style: STYLE.field },
|
|
2750
|
+
// The marker rides with the type rather than with the name: `name*` reads as
|
|
2751
|
+
// part of the identifier, and a `*` the schema did not mean would be a
|
|
2752
|
+
// requirement the tool never declared.
|
|
2753
|
+
h('span', { style: STYLE.fieldName }, field.name),
|
|
2754
|
+
h('span', { style: STYLE.muted }, field.type),
|
|
2755
|
+
field.required ? h('span', { title: t('toolFieldRequiredHint') }, '*') : null,
|
|
2756
|
+
field.description === undefined
|
|
2757
|
+
? null
|
|
2758
|
+
: h('span', { style: STYLE.fieldDesc }, `— ${field.description}`),
|
|
2759
|
+
)
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
/**
|
|
2763
|
+
* The one line that says where the definition is coming from: the read on its
|
|
2764
|
+
* way, or the host's own refusal. Nothing at all once the record is in hand —
|
|
2765
|
+
* the record draws itself.
|
|
2766
|
+
* @param view - what the cache holds for this name right now.
|
|
2767
|
+
* @param t - translate seat.
|
|
2768
|
+
* @returns the read's own line, or `null` while there is nothing to say.
|
|
2769
|
+
*/
|
|
2770
|
+
function toolFactsReadLine(view: ToolFactsView, t: Translate): ReactNode {
|
|
2771
|
+
if (view.state === 'facts') return null
|
|
2772
|
+
const copy = view.state === 'failure' ? t('toolFailed') : t('toolLoading')
|
|
2773
|
+
return h('div', { key: 'read', style: STYLE.dim }, copy)
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
/**
|
|
2777
|
+
* The row's own fact line: the server the name was registered under — carrying
|
|
2778
|
+
* the state the session's declared rows give that server, when they name it —
|
|
2779
|
+
* the tier as a sentence, and the step and the clock only while the host
|
|
2780
|
+
* published them. A name without the `mcp__` prefix names no server and gets no
|
|
2781
|
+
* server phrase rather than an invented one.
|
|
2782
|
+
* @param name - the registry name on the row.
|
|
2783
|
+
* @param detail - the tier, the step, the clock and the session's own rows.
|
|
2784
|
+
* @param t - translate seat.
|
|
2785
|
+
* @returns the facts joined as one line, in the contract's order.
|
|
2786
|
+
*/
|
|
2787
|
+
function toolFactsLine(name: string, detail: ToolDetail, t: Translate): string {
|
|
2788
|
+
const server = serverOfToolName(name)
|
|
2789
|
+
const state = toolServerState(name, detail.rows, t)
|
|
2307
2790
|
return [
|
|
2308
|
-
server === undefined ? undefined : t('toolServer', { server }),
|
|
2309
|
-
|
|
2791
|
+
server === undefined ? undefined : t('toolServer', { server: state ?? server }),
|
|
2792
|
+
toolTierSentence(detail.via, t),
|
|
2310
2793
|
detail.step === undefined ? undefined : t('toolsStep', { step: detail.step }),
|
|
2311
2794
|
detail.at === undefined ? undefined : toolTime(detail.at),
|
|
2312
|
-
]
|
|
2795
|
+
]
|
|
2796
|
+
.filter((part): part is string => part !== undefined)
|
|
2797
|
+
.join(' · ')
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
/**
|
|
2801
|
+
* The body of one opened tool row: the facts the header does not hold.
|
|
2802
|
+
*
|
|
2803
|
+
* A row that reads a host shows the full registry name, then one fact line —
|
|
2804
|
+
* the serving server with its state, the tier as a sentence, the step and the
|
|
2805
|
+
* clock, each only while the host published it — then the two counter readings,
|
|
2806
|
+
* and then the host's own answer about the definition: its model-facing
|
|
2807
|
+
* description verbatim, the fields it accepts, and the reason a hidden name is
|
|
2808
|
+
* not in the request. Empty groups are not printed, which is this file's rule
|
|
2809
|
+
* everywhere: no fields, no field list.
|
|
2810
|
+
*
|
|
2811
|
+
* A row composed without a route (a unit test's own row, a surface that never
|
|
2812
|
+
* read a host) has no address to ask and no declared rows to name: its body is
|
|
2813
|
+
* the read's own line alone, never a name and a fact line the block would then
|
|
2814
|
+
* have to invent.
|
|
2815
|
+
*
|
|
2816
|
+
* The reason leads the definition for a **hidden** row: there, it is the answer
|
|
2817
|
+
* to the question the reader opened the row with, while for an offered name the
|
|
2818
|
+
* same block is a definition rather than an apology.
|
|
2819
|
+
* @param name - the registry name on the row.
|
|
2820
|
+
* @param detail - the tier, the disclosure state and the session's own rows.
|
|
2821
|
+
* @param view - what the cache holds for this name right now.
|
|
2822
|
+
* @param t - translate seat.
|
|
2823
|
+
* @returns the body's lines, in order.
|
|
2824
|
+
*/
|
|
2825
|
+
export function toolFactsBody(
|
|
2826
|
+
name: string,
|
|
2827
|
+
detail: ToolDetail,
|
|
2828
|
+
view: ToolFactsView,
|
|
2829
|
+
t: Translate,
|
|
2830
|
+
): ReactNode {
|
|
2831
|
+
const read = toolFactsReadLine(view, t)
|
|
2832
|
+
if (detail.projectRoot === undefined || detail.sessionId === undefined) return read
|
|
2833
|
+
const facts = view.state === 'facts' ? view.facts : undefined
|
|
2834
|
+
const calls = toolCallsLine(detail.calls, t)
|
|
2835
|
+
const reason = facts === undefined ? undefined : toolReasonLine(toolReasonOf(name, facts), t)
|
|
2836
|
+
const fieldsLabel = t('toolFieldsLabel')
|
|
2837
|
+
return [
|
|
2838
|
+
h('div', { key: 'name', style: STYLE.name }, name),
|
|
2839
|
+
h('div', { key: 'facts', style: STYLE.detail }, toolFactsLine(name, detail, t)),
|
|
2840
|
+
...(calls === undefined ? [] : [h('div', { key: 'calls', style: STYLE.muted }, calls)]),
|
|
2841
|
+
// The reason leads a hidden row's body: there it is the answer to the
|
|
2842
|
+
// question the reader opened the row with, while for an offered name the same
|
|
2843
|
+
// block is a definition rather than an apology.
|
|
2844
|
+
...(reason === undefined ? [] : [h('div', { key: 'reason', style: STYLE.muted }, reason)]),
|
|
2845
|
+
read,
|
|
2846
|
+
...(facts?.description === undefined
|
|
2847
|
+
? []
|
|
2848
|
+
: [
|
|
2849
|
+
// The host's own model-facing text, exactly as it arrived: not
|
|
2850
|
+
// translated, not shortened, and not passed through a dictionary.
|
|
2851
|
+
h('div', { key: 'description', style: STYLE.detail }, facts.description),
|
|
2852
|
+
]),
|
|
2853
|
+
...(facts === undefined || facts.fields.length === 0
|
|
2854
|
+
? []
|
|
2855
|
+
: [
|
|
2856
|
+
h('div', { key: 'fields', style: STYLE.group }, fieldsLabel),
|
|
2857
|
+
...facts.fields.map((field, index) => fieldLine(field, index, t)),
|
|
2858
|
+
]),
|
|
2859
|
+
]
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
/**
|
|
2863
|
+
* The host's reason for one name, read from the record the row is holding.
|
|
2864
|
+
*
|
|
2865
|
+
* A record whose `name` is not the row's own is a host bug, and the panel draws
|
|
2866
|
+
* no reason rather than another tool's: the fact belongs to the definition the
|
|
2867
|
+
* body was asked about.
|
|
2868
|
+
* @param name - the registry name on the row.
|
|
2869
|
+
* @param facts - the record the cache holds.
|
|
2870
|
+
* @returns the reason, or `undefined` for an offered name.
|
|
2871
|
+
*/
|
|
2872
|
+
function toolReasonOf(name: string, facts: ToolFacts): ToolReason | undefined {
|
|
2873
|
+
return facts.name === name ? facts.reason : undefined
|
|
2313
2874
|
}
|
|
2314
2875
|
|
|
2315
2876
|
/**
|
|
@@ -2337,6 +2898,11 @@ export function toolRow(
|
|
|
2337
2898
|
): ReactNode {
|
|
2338
2899
|
const open = detail.open
|
|
2339
2900
|
const calls = callsLabel(row.calls, t)
|
|
2901
|
+
// Read once, and only while this row is the open one (F-56): the host route
|
|
2902
|
+
// answers one definition at a time, and a folded row asks for nothing.
|
|
2903
|
+
const facts = open
|
|
2904
|
+
? toolFactsBody(row.name, { ...detail, calls: row.calls }, toolFactsView(row.name, detail), t)
|
|
2905
|
+
: null
|
|
2340
2906
|
return h(
|
|
2341
2907
|
'div',
|
|
2342
2908
|
{ key: row.name, style: STYLE.tool },
|
|
@@ -2370,10 +2936,12 @@ export function toolRow(
|
|
|
2370
2936
|
? h(
|
|
2371
2937
|
'div',
|
|
2372
2938
|
{ style: STYLE.toolDetail },
|
|
2373
|
-
//
|
|
2374
|
-
//
|
|
2375
|
-
|
|
2376
|
-
|
|
2939
|
+
// What the header cannot hold (F-56): the full registry name, the fact
|
|
2940
|
+
// line — the server with its state, the tier as a sentence, the step and
|
|
2941
|
+
// the clock only while the host published them — the counter readings
|
|
2942
|
+
// apart, and then the host's own answer about the definition, read once,
|
|
2943
|
+
// on demand, while this row is the one that is open.
|
|
2944
|
+
facts,
|
|
2377
2945
|
)
|
|
2378
2946
|
: null,
|
|
2379
2947
|
)
|
|
@@ -2405,6 +2973,13 @@ export function ServersBlock(props: {
|
|
|
2405
2973
|
t: Translate
|
|
2406
2974
|
/** Host-namespace seat for the rows' coded details (F-48). */
|
|
2407
2975
|
hostT?: Translate | undefined
|
|
2976
|
+
/**
|
|
2977
|
+
* The project's retry, handed down to the failing rows so a broken server can
|
|
2978
|
+
* be pressed where it shows instead of behind the errors disclosure (F-55).
|
|
2979
|
+
*/
|
|
2980
|
+
onRetry?: (() => void) | undefined
|
|
2981
|
+
/** `true` while a host action is in flight; the row button goes still with it. */
|
|
2982
|
+
busy?: boolean | undefined
|
|
2408
2983
|
}): ReactNode {
|
|
2409
2984
|
const { rows, t } = props
|
|
2410
2985
|
if (rows.length === 0) return null
|
|
@@ -2431,6 +3006,9 @@ export function ServersBlock(props: {
|
|
|
2431
3006
|
// The host's own record of this server; a row the counters never saw has
|
|
2432
3007
|
// no `lastUsedAt` to read and the quiet word is simply not drawn.
|
|
2433
3008
|
const idle = idleNote(row.status, props.usage?.[row.name]?.lastUsedAt, t)
|
|
3009
|
+
// The one job a row here can carry: a failing server gets the project's
|
|
3010
|
+
// retry, at the row's right edge, and nothing else does.
|
|
3011
|
+
const retry = row.status === 'error' ? props.onRetry : undefined
|
|
2434
3012
|
return h(
|
|
2435
3013
|
'div',
|
|
2436
3014
|
{
|
|
@@ -2450,6 +3028,8 @@ export function ServersBlock(props: {
|
|
|
2450
3028
|
row.transport === undefined
|
|
2451
3029
|
? null
|
|
2452
3030
|
: h('span', { style: STYLE.tag }, shortTransport(row.transport)),
|
|
3031
|
+
retry === undefined ? null : h('span', { style: { flex: 1 } }),
|
|
3032
|
+
retryButton(t, retry, props.busy),
|
|
2453
3033
|
)
|
|
2454
3034
|
}),
|
|
2455
3035
|
)
|
|
@@ -2498,6 +3078,25 @@ export function HiddenTier(props: {
|
|
|
2498
3078
|
pins?: readonly string[] | undefined
|
|
2499
3079
|
/** `true` while a pin write is in flight, so the buttons stay still. */
|
|
2500
3080
|
pending: boolean
|
|
3081
|
+
/**
|
|
3082
|
+
* The one name of this tier whose body is open (F-56), as {@link ToolsView}
|
|
3083
|
+
* holds it, plus the writer that toggles it.
|
|
3084
|
+
*
|
|
3085
|
+
* Until F-56 every row here was handed `onToggle: () => undefined`: the tier
|
|
3086
|
+
* drew a disclosure that had nothing to disclose. The very reason a name is
|
|
3087
|
+
* hidden is what its body now prints, so the press that opens it is real.
|
|
3088
|
+
*/
|
|
3089
|
+
openTool?: string | undefined
|
|
3090
|
+
/** Toggle one row's body. */
|
|
3091
|
+
onToggleTool?: ((name: string) => void) | undefined
|
|
3092
|
+
/**
|
|
3093
|
+
* The project the definitions belong to and the session the tier is read in —
|
|
3094
|
+
* the `GET tool` route's own two parameters, handed down by {@link ToolsView}.
|
|
3095
|
+
*/
|
|
3096
|
+
projectRoot?: string | undefined
|
|
3097
|
+
sessionId?: string | undefined
|
|
3098
|
+
/** The session's own declared rows, for each open body's server state. */
|
|
3099
|
+
rows?: readonly ServerRow[] | undefined
|
|
2501
3100
|
t: Translate
|
|
2502
3101
|
}): ReactNode {
|
|
2503
3102
|
const { t } = props
|
|
@@ -2556,8 +3155,9 @@ export function HiddenTier(props: {
|
|
|
2556
3155
|
),
|
|
2557
3156
|
// One row per name, the full `mcp__<server>__<tool>` the registry
|
|
2558
3157
|
// carries, with the pin that moves it into the always-offered list.
|
|
2559
|
-
//
|
|
2560
|
-
//
|
|
3158
|
+
// Since F-56 the row is a real disclosure: its body carries the
|
|
3159
|
+
// reason the name is not in the request, which is the question this
|
|
3160
|
+
// list is open to answer.
|
|
2561
3161
|
...entry.names.map((name) =>
|
|
2562
3162
|
toolRow(
|
|
2563
3163
|
{ name },
|
|
@@ -2568,7 +3168,14 @@ export function HiddenTier(props: {
|
|
|
2568
3168
|
disabled: props.pending,
|
|
2569
3169
|
},
|
|
2570
3170
|
'hidden',
|
|
2571
|
-
{
|
|
3171
|
+
{
|
|
3172
|
+
via: 'pin',
|
|
3173
|
+
open: props.openTool === name,
|
|
3174
|
+
onToggle: () => props.onToggleTool?.(name),
|
|
3175
|
+
rows: props.rows,
|
|
3176
|
+
projectRoot: props.projectRoot,
|
|
3177
|
+
sessionId: props.sessionId,
|
|
3178
|
+
},
|
|
2572
3179
|
t,
|
|
2573
3180
|
),
|
|
2574
3181
|
),
|
|
@@ -2714,7 +3321,11 @@ export function ToolsView(props: {
|
|
|
2714
3321
|
}): ReactNode {
|
|
2715
3322
|
const { t } = props
|
|
2716
3323
|
const tools = sessionToolsOf(props.project, props.sessionId)
|
|
2717
|
-
/**
|
|
3324
|
+
/**
|
|
3325
|
+
* One row's disclosure state: the tier, the host's own step and time, this
|
|
3326
|
+
* session's declared rows (so the open body can name the serving server's
|
|
3327
|
+
* state) and the route the body's definition is read from (F-56).
|
|
3328
|
+
*/
|
|
2718
3329
|
const detailOf = (
|
|
2719
3330
|
name: string,
|
|
2720
3331
|
via: ToolDetail['via'],
|
|
@@ -2726,7 +3337,13 @@ export function ToolsView(props: {
|
|
|
2726
3337
|
at,
|
|
2727
3338
|
open: props.openTool === name,
|
|
2728
3339
|
onToggle: () => props.onToggleTool?.(name),
|
|
3340
|
+
rows: serverRows,
|
|
3341
|
+
projectRoot: props.project.projectRoot,
|
|
3342
|
+
sessionId: props.sessionId,
|
|
2729
3343
|
})
|
|
3344
|
+
// This session's own declared rows, read once for the open body's server state
|
|
3345
|
+
// — the same list `tabBody` draws above this block (`sessionRowsOf`).
|
|
3346
|
+
const serverRows = sessionRowsOf(props.project, props.sessionId)
|
|
2730
3347
|
// `tools` absent is the host's only "not mounted yet" signal: a session with a
|
|
2731
3348
|
// published offer that happens to be empty has real zeroes to print, and the
|
|
2732
3349
|
// two states must not be conflated. The declared servers of the session are not
|
|
@@ -3009,6 +3626,14 @@ export function ToolsView(props: {
|
|
|
3009
3626
|
onPinServer: props.onPinServer,
|
|
3010
3627
|
pins: policy.pins,
|
|
3011
3628
|
pending: props.pending === true,
|
|
3629
|
+
// One open body at a time across the whole block (F-56), and the
|
|
3630
|
+
// route its definition is read from: the hidden list's own rows are
|
|
3631
|
+
// rows of this same surface, so they open on the same writer.
|
|
3632
|
+
openTool: props.openTool,
|
|
3633
|
+
onToggleTool: props.onToggleTool,
|
|
3634
|
+
projectRoot: props.project.projectRoot,
|
|
3635
|
+
sessionId: props.sessionId,
|
|
3636
|
+
rows: serverRows,
|
|
3012
3637
|
t,
|
|
3013
3638
|
}),
|
|
3014
3639
|
],
|
|
@@ -3384,10 +4009,19 @@ export function LogsView(props: {
|
|
|
3384
4009
|
)
|
|
3385
4010
|
}
|
|
3386
4011
|
|
|
3387
|
-
/**
|
|
4012
|
+
/**
|
|
4013
|
+
* Side card settings panel: the poll interval, the declaration detail and
|
|
4014
|
+
* per-project release.
|
|
4015
|
+
*
|
|
4016
|
+
* The interval row used to be drawn by the sidebar itself, out of the tab
|
|
4017
|
+
* descriptor's `pluginToggles`; the surface that drew it went with
|
|
4018
|
+
* `dsh-better-sidebar`, so the row is part of this panel now, next to the state
|
|
4019
|
+
* it paces. Everywhere else the panel is read-only.
|
|
4020
|
+
*/
|
|
3388
4021
|
export function ProjectMcpSettings(props: {
|
|
3389
|
-
|
|
3390
|
-
|
|
4022
|
+
refreshMs: number
|
|
4023
|
+
/** Write a new interval; absent makes the row read-only (the design stand). */
|
|
4024
|
+
onRefreshMs?: ((value: number) => void) | undefined
|
|
3391
4025
|
onClose?: (() => void) | undefined
|
|
3392
4026
|
/** Translate seat; the popup follows the shell's language when it is given one. */
|
|
3393
4027
|
t?: Translate | undefined
|
|
@@ -3395,7 +4029,7 @@ export function ProjectMcpSettings(props: {
|
|
|
3395
4029
|
hostT?: Translate | undefined
|
|
3396
4030
|
}): ReactNode {
|
|
3397
4031
|
const t = translateOf(props.t)
|
|
3398
|
-
const { snapshot, error, busy, run } = useSnapshot(true,
|
|
4032
|
+
const { snapshot, error, busy, run } = useSnapshot(true, props.refreshMs)
|
|
3399
4033
|
const projects = snapshot?.projects ?? []
|
|
3400
4034
|
return h(
|
|
3401
4035
|
'div',
|
|
@@ -3415,6 +4049,7 @@ export function ProjectMcpSettings(props: {
|
|
|
3415
4049
|
? null
|
|
3416
4050
|
: h('button', { style: STYLE.button, onClick: () => props.onClose?.() }, t('close')),
|
|
3417
4051
|
),
|
|
4052
|
+
h(RefreshRow, { refreshMs: props.refreshMs, onRefreshMs: props.onRefreshMs, t }),
|
|
3418
4053
|
error === undefined ? null : h('div', { style: STYLE.error }, error),
|
|
3419
4054
|
h(
|
|
3420
4055
|
'div',
|
|
@@ -3434,6 +4069,58 @@ export function ProjectMcpSettings(props: {
|
|
|
3434
4069
|
)
|
|
3435
4070
|
}
|
|
3436
4071
|
|
|
4072
|
+
/** Bounds the row offers, the steps a press moves it by, and the unit it prints. */
|
|
4073
|
+
export const REFRESH_MIN_MS = 1_000
|
|
4074
|
+
export const REFRESH_MAX_MS = 60_000
|
|
4075
|
+
export const REFRESH_STEP_MS = 500
|
|
4076
|
+
/** The unit symbol beside the field; a symbol, not copy, so it is not translated. */
|
|
4077
|
+
export const REFRESH_UNIT = 'ms'
|
|
4078
|
+
/** The field's id, so the row's label can point at it. */
|
|
4079
|
+
export const REFRESH_INPUT_ID = 'dsh-project-mcp-refresh-ms'
|
|
4080
|
+
|
|
4081
|
+
/**
|
|
4082
|
+
* The poll interval as one labelled row: the copy the sidebar's toggle used,
|
|
4083
|
+
* the number field that replaces it, and the unit beside it.
|
|
4084
|
+
*
|
|
4085
|
+
* One implementation for both renderers — the product's settings panel and the
|
|
4086
|
+
* design stand's popup draw this same row — so the two cannot drift. Without a
|
|
4087
|
+
* writer the field is `readOnly` rather than absent: the stand shows the control
|
|
4088
|
+
* the product shows, it just does not pretend a press changed anything.
|
|
4089
|
+
*/
|
|
4090
|
+
export function RefreshRow(props: {
|
|
4091
|
+
refreshMs: number
|
|
4092
|
+
onRefreshMs?: ((value: number) => void) | undefined
|
|
4093
|
+
t?: Translate | undefined
|
|
4094
|
+
}): ReactNode {
|
|
4095
|
+
const t = translateOf(props.t)
|
|
4096
|
+
return h(
|
|
4097
|
+
'div',
|
|
4098
|
+
{ style: STYLE.settingRow },
|
|
4099
|
+
h(
|
|
4100
|
+
'label',
|
|
4101
|
+
{ style: STYLE.settingLabel, htmlFor: REFRESH_INPUT_ID },
|
|
4102
|
+
h('span', { style: STYLE.settingTitle }, t('refreshTitle')),
|
|
4103
|
+
h('span', { style: STYLE.settingDesc }, t('refreshDesc')),
|
|
4104
|
+
),
|
|
4105
|
+
h('input', {
|
|
4106
|
+
id: REFRESH_INPUT_ID,
|
|
4107
|
+
style: STYLE.settingInput,
|
|
4108
|
+
type: 'number',
|
|
4109
|
+
min: REFRESH_MIN_MS,
|
|
4110
|
+
max: REFRESH_MAX_MS,
|
|
4111
|
+
step: REFRESH_STEP_MS,
|
|
4112
|
+
value: props.refreshMs,
|
|
4113
|
+
readOnly: props.onRefreshMs === undefined,
|
|
4114
|
+
'aria-label': t('refreshTitle'),
|
|
4115
|
+
onChange: (event: { target: { value: string } }) => {
|
|
4116
|
+
const next = Number(event.target.value)
|
|
4117
|
+
if (Number.isFinite(next)) props.onRefreshMs?.(next)
|
|
4118
|
+
},
|
|
4119
|
+
}),
|
|
4120
|
+
h('span', { style: STYLE.settingUnit }, REFRESH_UNIT),
|
|
4121
|
+
)
|
|
4122
|
+
}
|
|
4123
|
+
|
|
3437
4124
|
/**
|
|
3438
4125
|
* One project block: the merged rows (what the project as a whole reports) plus
|
|
3439
4126
|
* the per-session breakdown underneath — but only for the sessions whose own
|
|
@@ -3971,6 +4658,41 @@ export function callsLabel(calls: ToolCalls | undefined, t: Translate = translat
|
|
|
3971
4658
|
return adds ? `${figure} · ${t('callsProject', { count: project })}` : figure
|
|
3972
4659
|
}
|
|
3973
4660
|
|
|
4661
|
+
/**
|
|
4662
|
+
* The one `Retry` a failing server row carries.
|
|
4663
|
+
*
|
|
4664
|
+
* Two surfaces draw a server row — the errors disclosure's {@link serverRow} and
|
|
4665
|
+
* the tab's own {@link ServersBlock} — and both offer the same action: the host
|
|
4666
|
+
* route drops this project's failed mounts and re-mounts them. The button is
|
|
4667
|
+
* built here once, so its label, its hint and the `disabled` flag that keeps
|
|
4668
|
+
* every press still while one host action is in flight cannot drift apart
|
|
4669
|
+
* between them. A surface that hands no action down gets no button at all,
|
|
4670
|
+
* which is what makes a read-only panel read-only instead of drawing a dead
|
|
4671
|
+
* press.
|
|
4672
|
+
* @param t - translate seat.
|
|
4673
|
+
* @param onRetry - the project's retry, or undefined where nothing can be written.
|
|
4674
|
+
* @param busy - `true` while a host action is in flight.
|
|
4675
|
+
* @returns the button, or `null` where there is no action to press.
|
|
4676
|
+
*/
|
|
4677
|
+
function retryButton(
|
|
4678
|
+
t: Translate,
|
|
4679
|
+
onRetry: (() => void) | undefined,
|
|
4680
|
+
busy: boolean | undefined,
|
|
4681
|
+
): ReactNode {
|
|
4682
|
+
return onRetry === undefined
|
|
4683
|
+
? null
|
|
4684
|
+
: h(
|
|
4685
|
+
'button',
|
|
4686
|
+
{
|
|
4687
|
+
style: STYLE.button,
|
|
4688
|
+
title: t('retryHint'),
|
|
4689
|
+
disabled: busy === true,
|
|
4690
|
+
onClick: onRetry,
|
|
4691
|
+
},
|
|
4692
|
+
t('retry'),
|
|
4693
|
+
)
|
|
4694
|
+
}
|
|
4695
|
+
|
|
3974
4696
|
/**
|
|
3975
4697
|
* One server, as the tab draws it.
|
|
3976
4698
|
*
|
|
@@ -4021,18 +4743,7 @@ export function serverRow(
|
|
|
4021
4743
|
quiet ? h('span', { style: { ...STYLE.tag, ...STYLE.tagQuiet } }, t(STATUS_KEYS[row.status])) : null,
|
|
4022
4744
|
idle === undefined ? null : h('span', { style: STYLE.dim }, idle),
|
|
4023
4745
|
h('span', { style: { flex: 1 } }),
|
|
4024
|
-
row.status === 'error'
|
|
4025
|
-
? h(
|
|
4026
|
-
'button',
|
|
4027
|
-
{
|
|
4028
|
-
style: STYLE.button,
|
|
4029
|
-
title: t('retryHint'),
|
|
4030
|
-
disabled: options.busy === true,
|
|
4031
|
-
onClick: options.onRetry,
|
|
4032
|
-
},
|
|
4033
|
-
t('retry'),
|
|
4034
|
-
)
|
|
4035
|
-
: null,
|
|
4746
|
+
retryButton(t, row.status === 'error' ? options.onRetry : undefined, options.busy),
|
|
4036
4747
|
),
|
|
4037
4748
|
// A quiet row's detail ("not mounted yet — this session has not started a
|
|
4038
4749
|
// turn") is a fact about a *normal* state, and the mockup draws `idle` as a
|
|
@@ -4107,14 +4818,3 @@ export function basename(path: string): string {
|
|
|
4107
4818
|
function messageOf(error: unknown): string {
|
|
4108
4819
|
return error instanceof Error ? error.message : String(error)
|
|
4109
4820
|
}
|
|
4110
|
-
|
|
4111
|
-
/** Read the persisted poll interval out of a plugin settings blob. */
|
|
4112
|
-
export function refreshMsOf(settings: Record<string, unknown>): number {
|
|
4113
|
-
const value = settings[REFRESH_KEY]
|
|
4114
|
-
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : DEFAULT_REFRESH_MS
|
|
4115
|
-
}
|
|
4116
|
-
|
|
4117
|
-
/** Read the settings blob of this descriptor from the sidebar snapshot. */
|
|
4118
|
-
export function pluginSettingsOf(snapshot: { prefs: { pluginSettings?: Record<string, Record<string, unknown>> } }): Record<string, unknown> {
|
|
4119
|
-
return snapshot.prefs.pluginSettings?.[TAB_ID] ?? {}
|
|
4120
|
-
}
|