dsh-project-mcp 0.2.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.
@@ -0,0 +1,410 @@
1
+ /**
2
+ * Design-only render mode: the browser half drawn from fixtures.
3
+ *
4
+ * This module exists so the interface can be reviewed **as the shell renders
5
+ * it** on a machine where nothing is mounted: no project, no MCP server, no host
6
+ * route. When the design flag is set (see {@link DESIGN_FLAG_KEY}) `./index.ts`
7
+ * registers *these* surfaces instead of the real ones, and every one of them
8
+ * renders the same components the product renders — `PanelHeader`, `tabBody`,
9
+ * `SettingsPage`, `ProjectBlock`, `ToastStack` — fed from `./design-fixtures.ts`.
10
+ *
11
+ * What the mode is not: it is not a second UI. There is no markup here that the
12
+ * real surfaces do not also produce; the only thing it swaps is where the
13
+ * picture comes from. The host half is untouched, so a profile that has this
14
+ * flag set still mounts whatever the project declares — the *drawing* is a
15
+ * fixture, the *runtime* is real.
16
+ *
17
+ * Turning it on, from the web client's own console:
18
+ *
19
+ * ```js
20
+ * localStorage.setItem('dsh-project-mcp:design', 'full') // or quiet | empty | …
21
+ * location.reload() // back to the product
22
+ * localStorage.removeItem('dsh-project-mcp:design')
23
+ * ```
24
+ *
25
+ * @module dsh-project-mcp/client/design
26
+ */
27
+
28
+ import { createElement as h, useState } from 'react'
29
+ import type { ReactNode } from 'react'
30
+ import type { Context } from '@deepseek-ai/cordis'
31
+ import type { BetterSidebarService, TabDescriptor } from 'dsh-better-sidebar'
32
+ import { TAB_ID } from '../shared.ts'
33
+ import { en, ru, zh } from './locales/ui.ts'
34
+ import { NS_HOST, en as hostEn, ru as hostRu, zh as hostZh, hostTranslate } from './locales/host.ts'
35
+ import {
36
+ DEFAULT_SETTINGS_VIEW,
37
+ NS,
38
+ SETTINGS_TAB_ID,
39
+ SETTINGS_TAB_ORDER,
40
+ SettingsPage,
41
+ registerSettingsTab,
42
+ useNarrowSettings,
43
+ } from './settings.ts'
44
+ import type { SettingsSlotServices, SettingsTabProps, SettingsView } from './settings.ts'
45
+ import { DEFAULT_SETTINGS_PAGE } from './settings-tools.ts'
46
+ import type { SettingsPageKey } from './settings-tools.ts'
47
+ import { localeServiceOf, tabTranslate, useTabTranslate } from './tab-locale.ts'
48
+ import type { TabLocale } from './tab-locale.ts'
49
+ import { TOASTS_ID, TOASTS_ORDER, TOASTS_SLOT, ToastStack, createToastStore } from './toasts.ts'
50
+ import type { ToastsServices } from './toasts.ts'
51
+ import {
52
+ PanelHeader,
53
+ ProjectBlock,
54
+ STYLE,
55
+ browserStorage,
56
+ sessionLogCount,
57
+ statusGroups,
58
+ storedString,
59
+ tabBody,
60
+ translateOf,
61
+ } from './view.ts'
62
+ import type { PanelStorage, Translate } from './view.ts'
63
+ import {
64
+ DESIGN_TOASTS,
65
+ designPicture,
66
+ designPolicy,
67
+ designProject,
68
+ designSessionId,
69
+ isDesignVariant,
70
+ } from './design-fixtures.ts'
71
+ import type { DesignVariant } from './design-fixtures.ts'
72
+
73
+ /**
74
+ * Where the design mode is asked for.
75
+ *
76
+ * A browser-local preference rather than a build flag, for the same reason the
77
+ * panel's own view and filters are: it must be switchable without a rebuild, and
78
+ * it must be readable by the bundle that is already loaded.
79
+ */
80
+ export const DESIGN_FLAG_KEY = 'dsh-project-mcp:design'
81
+
82
+ /** Values that mean "on" without naming a picture. */
83
+ const DESIGN_FLAG_ALIASES: readonly string[] = ['on', 'true', 'yes', '1']
84
+
85
+ /** How often the fixture stack repeats its three banners. */
86
+ const DESIGN_TOAST_ROTATE_MS = 2_500
87
+
88
+ /** A set that never changes, for the read-only props of the fixture settings page. */
89
+ const NO_PENDING: ReadonlySet<string> = new Set()
90
+
91
+ /** Do nothing: the fixture surfaces have no host to call. */
92
+ function noop(): void {
93
+ // Intentionally empty: a design surface answers no route.
94
+ }
95
+
96
+ /**
97
+ * The picture the flag asks for.
98
+ *
99
+ * The flag holds a variant name (`full`, `quiet`, …) or one of the plain "on"
100
+ * spellings, which mean the all-states picture. Anything else — including a
101
+ * value from a newer build — leaves the mode **off**, so a typo can never swap
102
+ * the real interface for a fixture.
103
+ * @param storage - storage to read; defaults to the browser's own.
104
+ * @returns the variant, or undefined when the mode is off.
105
+ */
106
+ export function designVariantOf(storage?: PanelStorage): DesignVariant | undefined {
107
+ const value = storedString(DESIGN_FLAG_KEY, storage)
108
+ if (value === undefined) return undefined
109
+ if (DESIGN_FLAG_ALIASES.includes(value)) return 'full'
110
+ return isDesignVariant(value) ? value : undefined
111
+ }
112
+
113
+ /**
114
+ * `true` when the flag names a picture the mode can draw.
115
+ * @param storage - storage to read; defaults to the browser's own.
116
+ * @returns whether the design surfaces should be registered instead of the real ones.
117
+ */
118
+ export function designModeEnabled(storage?: PanelStorage): boolean {
119
+ return designVariantOf(storage) !== undefined
120
+ }
121
+
122
+ /**
123
+ * The sidebar tab, drawn from a picture.
124
+ *
125
+ * The same two elements the real panel renders, in the same order: the toolbar
126
+ * and the one body of the single surface. Nothing here fetches, so nothing here
127
+ * needs the shell to be connected.
128
+ * @param props - the picture, the tab's session and the translate seat.
129
+ * @returns the panel element tree.
130
+ */
131
+ export function DesignPanel(props: {
132
+ variant: DesignVariant
133
+ sessionId: string | undefined
134
+ t?: Translate | undefined
135
+ /** Host-namespace seat for the fixtures' coded events (F-48). */
136
+ hostT?: Translate | undefined
137
+ }): ReactNode {
138
+ const t = translateOf(props.t)
139
+ const project = designProject(props.variant)
140
+ const sessionId = designSessionId(props.variant)
141
+ const groups = project === undefined ? [] : statusGroups(project.rows)
142
+ const session = (project?.sessions ?? []).find((entry) => entry.id === sessionId)
143
+ return h(
144
+ 'div',
145
+ { style: STYLE.root },
146
+ h(PanelHeader, {
147
+ project,
148
+ sessions: project?.sessionIds.length ?? 0,
149
+ busy: false,
150
+ onSync: noop,
151
+ t,
152
+ }),
153
+ h(
154
+ 'div',
155
+ { style: STYLE.body },
156
+ tabBody({
157
+ project,
158
+ sessionId,
159
+ groups,
160
+ busy: false,
161
+ policy: project === undefined ? undefined : designPolicy(props.variant),
162
+ onRelease: noop,
163
+ sessionLogCount: sessionLogCount(session),
164
+ t,
165
+ hostT: props.hostT,
166
+ }),
167
+ ),
168
+ )
169
+ }
170
+
171
+ /**
172
+ * The tab's own settings popover, drawn from a picture.
173
+ *
174
+ * Same shape as `ProjectMcpSettings`, minus the poll: the bar names the surface,
175
+ * counts the projects and offers `Sync`/`Close`, and the body renders one
176
+ * `ProjectBlock` per project — the product's own component, fed here.
177
+ * @param props - the picture, the close seat and the translate seat.
178
+ * @returns the popover element tree.
179
+ */
180
+ export function DesignPopup(props: {
181
+ variant: DesignVariant
182
+ onClose?: (() => void) | undefined
183
+ t?: Translate | undefined
184
+ /** Host-namespace seat for the fixtures' coded payload fields (F-48). */
185
+ hostT?: Translate | undefined
186
+ }): ReactNode {
187
+ const t = translateOf(props.t)
188
+ const projects = designPicture(props.variant).projects
189
+ return h(
190
+ 'div',
191
+ { style: STYLE.root },
192
+ h(
193
+ 'div',
194
+ { style: STYLE.bar },
195
+ h('span', { style: STYLE.name }, t('mountedPerProject')),
196
+ h('span', { style: STYLE.muted }, t('projectsCount', { count: projects.length })),
197
+ h('span', { style: { flex: 1 } }),
198
+ h('button', { style: STYLE.button, onClick: noop }, t('sync')),
199
+ props.onClose === undefined
200
+ ? null
201
+ : h('button', { style: STYLE.button, onClick: () => props.onClose?.() }, t('close')),
202
+ ),
203
+ h(
204
+ 'div',
205
+ { style: STYLE.body },
206
+ projects.length === 0
207
+ ? h('div', { style: { ...STYLE.muted, padding: 8 } }, t('nothingMounted'))
208
+ : projects.map((project) =>
209
+ h(ProjectBlock, {
210
+ key: project.projectRoot,
211
+ project,
212
+ busy: false,
213
+ onRelease: noop,
214
+ t: props.t,
215
+ hostT: props.hostT,
216
+ }),
217
+ ),
218
+ ),
219
+ )
220
+ }
221
+
222
+ /**
223
+ * The native Settings page, drawn from a picture.
224
+ *
225
+ * `SettingsPage` is a pure function of its props, so the design mode supplies
226
+ * the state the real `SettingsTab` owns — view, page, selection, JSON — and the
227
+ * fixture snapshot, and lets the page render itself. The editor's write path is
228
+ * the one thing the mode does not simulate: there is no host to write to, so the
229
+ * draft stays empty and `Save…` never becomes live.
230
+ * @param props - the picture and the translate seat.
231
+ * @returns the settings page element tree.
232
+ */
233
+ export function DesignSettingsTab(props: {
234
+ variant: DesignVariant
235
+ t?: Translate | undefined
236
+ /** The host namespace's seat, forwarded to the page like the product does. */
237
+ hostT?: Translate | undefined
238
+ }): ReactNode {
239
+ const t = translateOf(props.t)
240
+ const [view, setView] = useState<SettingsView>(DEFAULT_SETTINGS_VIEW)
241
+ const [page, setPage] = useState<SettingsPageKey>(DEFAULT_SETTINGS_PAGE)
242
+ const [selectedServer, setSelectedServer] = useState<string | undefined>(undefined)
243
+ const [json, setJson] = useState(false)
244
+ const narrow = useNarrowSettings()
245
+ const snapshot = designPicture(props.variant)
246
+ const project = snapshot.projects[0]
247
+ return h(SettingsPage, {
248
+ snapshot,
249
+ error: undefined,
250
+ busy: false,
251
+ view,
252
+ onView: setView,
253
+ page,
254
+ onPage: setPage,
255
+ onMode: noop,
256
+ modePending: NO_PENDING,
257
+ modeError: undefined,
258
+ selectedRoot: project?.projectRoot,
259
+ onSelectProject: noop,
260
+ selectedServer,
261
+ onSelectServer: setSelectedServer,
262
+ onSync: noop,
263
+ onRetry: noop,
264
+ json,
265
+ onJson: setJson,
266
+ draft: undefined,
267
+ confirming: false,
268
+ consent: false,
269
+ saveState: undefined,
270
+ saving: false,
271
+ onDraft: noop,
272
+ onDiscard: noop,
273
+ onAskSave: noop,
274
+ onCancelSave: noop,
275
+ onConsent: noop,
276
+ onConfirmSave: noop,
277
+ onReRead: noop,
278
+ narrow,
279
+ t,
280
+ hostT: props.hostT,
281
+ })
282
+ }
283
+
284
+ /**
285
+ * The tab panel with its translate seat, the way the real entry composes it.
286
+ * @param props - the picture, the session and the locale service.
287
+ * @returns the localized panel.
288
+ */
289
+ function LocalizedDesignPanel(props: {
290
+ locale: TabLocale | undefined
291
+ variant: DesignVariant
292
+ sessionId: string | undefined
293
+ }): ReactNode {
294
+ const t = useTabTranslate(props.locale)
295
+ const hostT = hostTranslate(props.locale)
296
+ return h(DesignPanel, { variant: props.variant, sessionId: props.sessionId, t, hostT })
297
+ }
298
+
299
+ /**
300
+ * The tab's popover with its translate seat.
301
+ * @param props - the picture, the close seat and the locale service.
302
+ * @returns the localized popover.
303
+ */
304
+ function LocalizedDesignPopup(props: {
305
+ locale: TabLocale | undefined
306
+ variant: DesignVariant
307
+ onClose?: (() => void) | undefined
308
+ }): ReactNode {
309
+ const t = useTabTranslate(props.locale)
310
+ // The stand's popover renders the same coded payloads the product does, so
311
+ // it binds the host seat too — an unregistered namespace echoes and the
312
+ // fixtures show their English, exactly like the product's fallback.
313
+ const hostT = hostTranslate(props.locale)
314
+ return h(DesignPopup, { variant: props.variant, onClose: props.onClose, t, hostT })
315
+ }
316
+
317
+ /**
318
+ * The frame-wide toast stack, repeating its three fixture banners.
319
+ *
320
+ * The product's stack reads a status channel; here the store is filled directly
321
+ * from {@link DESIGN_TOASTS} and refilled on a timer, because a banner lives
322
+ * three seconds and a design surface has to still be on screen when someone
323
+ * looks at it.
324
+ * @param services - the injected `slots` service, and the locale seat.
325
+ */
326
+ export function registerDesignToasts(services: ToastsServices): void {
327
+ const store = createToastStore()
328
+ services.slots.inject(TOASTS_SLOT, () => {
329
+ const entry = services.slots.register(
330
+ { name: TOASTS_SLOT, id: TOASTS_ID, order: TOASTS_ORDER },
331
+ () => h(ToastStack, { store, locale: services.locale }),
332
+ )
333
+ let index = 0
334
+ const push = (): void => {
335
+ const draft = DESIGN_TOASTS[index % DESIGN_TOASTS.length]
336
+ index += 1
337
+ if (draft !== undefined) store.push(draft)
338
+ }
339
+ push()
340
+ const timer = setInterval(push, DESIGN_TOAST_ROTATE_MS)
341
+ return () => {
342
+ clearInterval(timer)
343
+ entry()
344
+ }
345
+ })
346
+ }
347
+
348
+ /**
349
+ * Register the fixture surfaces on the browser half.
350
+ *
351
+ * Mirrors `apply`'s own wiring exactly — the tab behind `betterSidebar`, the
352
+ * settings page behind `slots` + `locale`, the toasts behind `slots` alone — so
353
+ * the design mode is a drop-in replacement for the real one and a composition
354
+ * missing a service behaves the same way in both.
355
+ * @param ctx - client root context.
356
+ * @param variant - the picture to draw; read from the flag when omitted.
357
+ */
358
+ export function registerDesignSurfaces(
359
+ ctx: Context,
360
+ variant: DesignVariant = designVariantOf(browserStorage()) ?? 'full',
361
+ ): void {
362
+ const locale = localeServiceOf(ctx)
363
+ const t = tabTranslate(locale)
364
+
365
+ ctx.inject(['betterSidebar'], (scope) => {
366
+ const betterSidebar = (scope as unknown as { betterSidebar: BetterSidebarService }).betterSidebar
367
+ scope.effect(() =>
368
+ betterSidebar.registerTab({
369
+ id: TAB_ID,
370
+ title: () => t('designTitle', { variant }),
371
+ description: () => t('designDesc', { variant }),
372
+ order: 55,
373
+ single: true,
374
+ settings: {
375
+ render: (
376
+ props: Parameters<NonNullable<NonNullable<TabDescriptor['settings']>['render']>>[0],
377
+ ) =>
378
+ h(LocalizedDesignPopup, { locale, variant, onClose: props.close }),
379
+ },
380
+ component: (props: Parameters<TabDescriptor['component']>[0]) =>
381
+ h(LocalizedDesignPanel, { locale, variant, sessionId: props.scope.sessionId }),
382
+ }),
383
+ )
384
+ })
385
+
386
+ ctx.inject(['slots', 'locale'], (scope) => {
387
+ const services = scope as unknown as SettingsSlotServices
388
+ // The same one call with all three tables as the product entry. No
389
+ // `addLanguage` of its own: `apply()` returns early in design mode, so
390
+ // the entry — the only place that names Russian to the shell — never runs
391
+ // in this mode. The registration alone is still valid: its `ru` keys are
392
+ // simply unused, and anything unresolved falls back to English.
393
+ services.effect(
394
+ () => services.locale.register(NS, { zh, en, ru }),
395
+ 'dsh-project-mcp: design settings dictionary',
396
+ )
397
+ services.effect(
398
+ // The host-code namespace, beside the UI one as in the product entry.
399
+ () => services.locale.register(NS_HOST, { zh: hostZh, en: hostEn, ru: hostRu }),
400
+ 'dsh-project-mcp: design host dictionary',
401
+ )
402
+ registerSettingsTab(services, (props: SettingsTabProps) =>
403
+ h(DesignSettingsTab, { variant, t: props.t, hostT: props.hostT }),
404
+ )
405
+ })
406
+
407
+ ctx.inject(['slots', 'locale'], (scope) => {
408
+ registerDesignToasts(scope as unknown as ToastsServices)
409
+ })
410
+ }
@@ -0,0 +1,255 @@
1
+ /**
2
+ * `dsh-project-mcp`, browser half: a DSH sidebar tab that shows which MCP
3
+ * servers each project declares and what is currently mounted for its sessions,
4
+ * its own settings panel in the side card settings popup, a page in DSH's
5
+ * native Settings listing every project with a live session, and a frame-wide
6
+ * toast stack for the servers that come up, fail or are released.
7
+ *
8
+ * Registered through the `dsh-better-sidebar` service and two browser-shell
9
+ * seats — the `settings.section` slot and the `shell.overlay` floating layer.
10
+ * Both seats exist in the browser half only. The
11
+ * host half publishes the same data over `/project-mcp/*` (see `src/ui.ts`), so
12
+ * this module never imports host code at runtime.
13
+ *
14
+ * @module dsh-project-mcp/client
15
+ */
16
+
17
+ import { createElement, useEffect, useState } from 'react'
18
+ import type { ReactNode } from 'react'
19
+ import type { BetterSidebarService, TabDescriptor } from 'dsh-better-sidebar'
20
+ import type { Context } from '@deepseek-ai/cordis'
21
+ import { PACKAGE_NAME, TAB_ID } from '../shared.ts'
22
+ import { designModeEnabled, registerDesignSurfaces } from './design.ts'
23
+ import { en, ru, zh } from './locales/ui.ts'
24
+ import { NS_HOST, en as hostEn, ru as hostRu, zh as hostZh, hostTranslate } from './locales/host.ts'
25
+ import { registerPluginConfigCard } from './plugin-config.ts'
26
+ import type { PluginConfigSlotServices } from './plugin-config.ts'
27
+ import { NS, registerSettingsTab } from './settings.ts'
28
+ import type { SettingsSlotServices } from './settings.ts'
29
+ import { localeServiceOf, tabTranslate, useTabTranslate } from './tab-locale.ts'
30
+ import type { TabLocale } from './tab-locale.ts'
31
+ import { registerToasts } from './toasts.ts'
32
+ import type { ToastsServices } from './toasts.ts'
33
+ import {
34
+ ProjectMcpPanel,
35
+ ProjectMcpSettings,
36
+ REFRESH_KEY,
37
+ pluginSettingsOf,
38
+ refreshMsOf,
39
+ } from './view.ts'
40
+
41
+ /** Plugin name: matches the package name and the host half. */
42
+ export const name = PACKAGE_NAME
43
+
44
+ /**
45
+ * Register the three surfaces, each behind the service it actually needs.
46
+ *
47
+ * No module-level dependency is declared, because the sidebar is optional: a
48
+ * module-level `inject` would leave this entry **pending** for good in a
49
+ * composition without `dsh-better-sidebar`, and DSH's web boot audit refuses to
50
+ * start while an entry is pending. `ctx.inject(name, …)` waits for the same
51
+ * service without gating the entry, so a composition without the sidebar keeps
52
+ * the native Settings page and the toast stack.
53
+ *
54
+ * A service this fiber did not declare must never be read as a property: Cordis
55
+ * throws `cannot get property "…" without inject`, and that throw fails the
56
+ * entry, which takes the whole web client boot down. Optional reads go through
57
+ * {@link Context.get}.
58
+ */
59
+ export const inject: string[] = []
60
+
61
+ /**
62
+ * Register the browser half's surfaces. `registerTab` returns a disposer and
63
+ * Cordis runs it on fiber disposal, which is what keeps HMR and plugin disabling
64
+ * free of "already registered" failures.
65
+ * @param ctx - client root context.
66
+ */
67
+ export function apply(ctx: Context): void {
68
+ // The design-only render mode: when the flag names a picture, the three
69
+ // surfaces below are registered from fixtures instead (`./design.ts`). It is a
70
+ // replacement, never an addition — two registrations of one tab id would fight
71
+ // over the same sidebar cell. The flag is a browser-local preference, so the
72
+ // product and the fixture mode are one bundle apart, not one build apart.
73
+ if (designModeEnabled()) {
74
+ registerDesignSurfaces(ctx)
75
+ return
76
+ }
77
+
78
+ // The tab is the one surface rendered outside the slot framework, so it is
79
+ // also the one that has to bind its own translate seat: the shell's locale
80
+ // service, read with `ctx.get` because this fiber does not declare it, with
81
+ // the plugin's dictionary registered below. Without a locale service the seat
82
+ // falls back to the merged English table composed in ./locales/ui.ts.
83
+ const locale = localeServiceOf(ctx)
84
+ const t = tabTranslate(locale)
85
+
86
+ // The sidebar tab. `ctx.inject` parks this callback until the service exists
87
+ // and re-runs it when the service is replaced, so a composition without the
88
+ // sidebar simply has no tab while everything below still registers.
89
+ ctx.inject(['betterSidebar'], (scope) => {
90
+ const betterSidebar = (scope as unknown as { betterSidebar: BetterSidebarService }).betterSidebar
91
+ scope.effect(() =>
92
+ betterSidebar.registerTab({
93
+ id: TAB_ID,
94
+ title: () => t('tab'),
95
+ description: () => t('tabDescription'),
96
+ order: 55,
97
+ single: true,
98
+ settings: {
99
+ pluginToggles: [
100
+ {
101
+ key: REFRESH_KEY,
102
+ // Live copy, the closure shape: the sidebar's `SidebarSettingToggle`
103
+ // declares `title`/`desc` as `string | (() => string)` ("i18n
104
+ // friendly", service.ts), exactly like the descriptor's own title
105
+ // above, so the row re-reads the seat on every render and no
106
+ // re-registration is needed. (The alternative — strings resolved
107
+ // at registration plus a re-register on locale change — would
108
+ // leave the row frozen until then.)
109
+ title: () => t('refreshTitle'),
110
+ desc: () => t('refreshDesc'),
111
+ type: 'number',
112
+ min: 1_000,
113
+ max: 60_000,
114
+ unit: 'ms',
115
+ },
116
+ ],
117
+ render: (props: Parameters<NonNullable<NonNullable<TabDescriptor['settings']>['render']>>[0]) =>
118
+ createElement(LocalizedSettings, {
119
+ pluginSettings: props.pluginSettings,
120
+ updatePluginSetting: props.updatePluginSetting,
121
+ onClose: props.close,
122
+ locale,
123
+ }),
124
+ },
125
+ // `LocalizedPanel` re-binds the seat when the shell's language changes:
126
+ // the descriptor's own title is read again by the sidebar on every render,
127
+ // and the panel below it subscribes to the same service.
128
+ component: (props: Parameters<TabDescriptor['component']>[0]) =>
129
+ createElement(LocalizedPanel, {
130
+ locale,
131
+ visible: props.visible,
132
+ sessionId: props.scope.sessionId,
133
+ refreshMs: refreshMsOf(pluginSettingsOf(betterSidebar.getSnapshot())),
134
+ }),
135
+ }),
136
+ )
137
+ })
138
+
139
+ // The native Settings page. `ctx.inject` runs this callback only once both
140
+ // services exist and unloads it when either goes away: a composition without
141
+ // the web settings shell keeps the sidebar tab above and the toast stack
142
+ // below, it just has no page to add.
143
+ ctx.inject(['slots', 'locale'], (scope) => {
144
+ const services = scope as unknown as SettingsSlotServices
145
+ // The shell ships only `zh` and `en`: Russian is added at runtime, and the
146
+ // add must precede the dictionary registration that uses it. `addLanguage`
147
+ // is read optionally — a shell whose locale service predates the method
148
+ // must still boot, with `ru` keys simply falling back to English.
149
+ services.effect(
150
+ () => services.locale.addLanguage?.({ id: 'ru', label: 'Русский', fallback: 'en' }),
151
+ 'dsh-project-mcp: ru language',
152
+ )
153
+ services.effect(
154
+ // One namespace for the whole plugin, one call carrying all three
155
+ // languages: the runtime throws when the same (namespace, locale) pair is
156
+ // registered twice, so three calls are not an option. The tables are the
157
+ // complete ones from ./locales/ui.ts — `en` is the merge of the panel's
158
+ // and the settings page's halves, composed there.
159
+ () => services.locale.register(NS, { zh, en, ru }),
160
+ 'dsh-project-mcp: settings dictionaries',
161
+ )
162
+ services.effect(
163
+ // The second namespace, beside the first: the host's coded messages
164
+ // (F-48). Same one-call shape — a duplicate (namespace, locale) pair
165
+ // throws, so the three languages ride a single registration.
166
+ () => services.locale.register(NS_HOST, { zh: hostZh, en: hostEn, ru: hostRu }),
167
+ 'dsh-project-mcp: host dictionaries',
168
+ )
169
+ registerSettingsTab(services)
170
+ })
171
+
172
+ // The plugin's own configuration card on the Plugins page (F-54), in an
173
+ // inject of its own: `configForms` is optional (DSH before the service's
174
+ // introduction, or a composition without it), and the settings tab above must
175
+ // not depend on it. `locale` rides along because the card declares the
176
+ // plugin's namespace — the dictionaries themselves stay registered by the
177
+ // settings block, whose inject list is a subset of this one's.
178
+ ctx.inject(['slots', 'locale', 'configForms'], (scope) => {
179
+ const services = scope as unknown as PluginConfigSlotServices
180
+ const forms = services.configForms
181
+ // A service that predates `get`/`whileServed` leaves the card absent
182
+ // rather than failing the entry — the same rule the whole file follows.
183
+ if (typeof forms?.get !== 'function' || typeof forms.whileServed !== 'function') return
184
+ registerPluginConfigCard(services)
185
+ })
186
+
187
+ // The frame-wide toast stack, in its own inject: a composition without the
188
+ // sidebar still floats banners, and one without the slot registry keeps every
189
+ // other surface. The locale service rides along so a language switch repaints
190
+ // the banners on screen; `shell.overlay` is declared by the layout frame, so
191
+ // `registerToasts` waits for it through `slots.inject` and simply has nothing
192
+ // to register in a shell without a frame.
193
+ ctx.inject(['slots', 'locale'], (scope) => {
194
+ registerToasts(scope as unknown as ToastsServices)
195
+ })
196
+ }
197
+
198
+ /**
199
+ * The sidebar panel with its translate seat.
200
+ *
201
+ * `useTabTranslate` binds the plugin's namespace to the shell's locale service
202
+ * and subscribes to the locale snapshot, so a language switch repaints the tab —
203
+ * the one thing the settings page gets from the slot framework for free.
204
+ * @param props - the panel's props plus the locale service, when there is one.
205
+ * @returns the panel element with its translator.
206
+ */
207
+ export function LocalizedPanel(props: {
208
+ locale: TabLocale | undefined
209
+ visible: boolean
210
+ sessionId: string | undefined
211
+ refreshMs: number
212
+ }): ReactNode {
213
+ const t = useTabTranslate(props.locale)
214
+ // The host namespace beside the UI one: the Logs tab renders the host's
215
+ // coded events (F-48), and the seat follows the active language the same way
216
+ // `t` does — the repaint rides on `t`'s re-bind.
217
+ const hostT = hostTranslate(props.locale)
218
+ return createElement(ProjectMcpPanel, {
219
+ visible: props.visible,
220
+ sessionId: props.sessionId,
221
+ refreshMs: props.refreshMs,
222
+ t,
223
+ hostT,
224
+ })
225
+ }
226
+
227
+ /**
228
+ * The side card settings popup with the same translate seat.
229
+ *
230
+ * The popup is rendered by the sidebar service too, so it needs the seat for the
231
+ * same reason the tab does: `ProjectMcpSettings` carries no hook of its own, and
232
+ * a language switch should repaint its chrome rather than wait for the next
233
+ * poll.
234
+ * @param props - the popup's props plus the locale service, when there is one.
235
+ * @returns the popup element with its translator.
236
+ */
237
+ export function LocalizedSettings(props: {
238
+ locale: TabLocale | undefined
239
+ pluginSettings: Record<string, unknown>
240
+ updatePluginSetting: (key: string, value: unknown) => void
241
+ onClose?: (() => void) | undefined
242
+ }): ReactNode {
243
+ const t = useTabTranslate(props.locale)
244
+ // The host namespace beside the UI one: the popup renders the host's coded
245
+ // payload fields (F-48), and the bound seat follows the active language the
246
+ // same way `t` does — the repaint still rides on `t`'s re-bind.
247
+ const hostT = hostTranslate(props.locale)
248
+ return createElement(ProjectMcpSettings, {
249
+ pluginSettings: props.pluginSettings,
250
+ updatePluginSetting: props.updatePluginSetting,
251
+ onClose: props.onClose,
252
+ t,
253
+ hostT,
254
+ })
255
+ }