dsh-mcp-skills-controller 0.1.2 → 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 +15 -11
- package/client.js +465 -73
- package/icon.svg +7 -5
- package/index.js +392 -23
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -4
- package/src/frozen-registry.js +171 -151
- package/src/masks.js +182 -37
- package/src/mcp-catalog.js +39 -15
- package/src/mcp-effective.js +55 -0
- package/src/merge.js +405 -127
- package/src/rpc.js +84 -11
- package/src/session-gc.js +62 -0
- package/src/shadows.js +1 -1
- package/src/skill-catalog.js +0 -10
- package/src/skill-origin.js +82 -0
- package/src/skill-path.js +21 -0
- package/src/views.js +155 -88
package/client.js
CHANGED
|
@@ -17,6 +17,8 @@ window.__ModuleLoader__.load({
|
|
|
17
17
|
const NS = 'mcp-skills-controller'
|
|
18
18
|
const API = '/mcp-skills-controller/api'
|
|
19
19
|
const TOKEN_META = 'dsh-mcp-skills-controller'
|
|
20
|
+
// 设置页 skills 展示分组顺序;项目级只属于会话,不进入全局面板。
|
|
21
|
+
const SKILL_GROUP_ORDER = ['user', 'plugin', 'preset', 'other']
|
|
20
22
|
|
|
21
23
|
// settings.section 槽位按契约不声明 locale 字段,拿不到槽注入的 t;
|
|
22
24
|
// apply 时绑定一份模块级兜底,GlobalPanel 内 `props.t ?? boundT`。
|
|
@@ -30,10 +32,16 @@ window.__ModuleLoader__.load({
|
|
|
30
32
|
'scope.session': '仅本会话生效',
|
|
31
33
|
'scope.default': '将用于之后新建的会话',
|
|
32
34
|
'scope.project': '项目',
|
|
35
|
+
'group.user': '用户',
|
|
36
|
+
'group.plugin': '插件',
|
|
37
|
+
'group.preset': '预设',
|
|
38
|
+
'group.other': '其他',
|
|
33
39
|
'action.followAll': '跟随全局',
|
|
34
40
|
'action.followItem': '恢复跟随全局默认',
|
|
35
41
|
'action.allOn': '全部开',
|
|
36
42
|
'action.allOff': '全部关',
|
|
43
|
+
'action.groupOn': '分组开',
|
|
44
|
+
'action.groupOff': '分组关',
|
|
37
45
|
'state.loading': '读取中…',
|
|
38
46
|
'state.failed': '读取失败',
|
|
39
47
|
'state.retry': '重试',
|
|
@@ -49,6 +57,7 @@ window.__ModuleLoader__.load({
|
|
|
49
57
|
'mcp.disconnected': '未连接',
|
|
50
58
|
'mcp.connected': '已连接',
|
|
51
59
|
'mcp.tools': '个工具',
|
|
60
|
+
'mcp.toolGroup': '工具',
|
|
52
61
|
'skills.empty': '没有可见的 skills',
|
|
53
62
|
'skills.incomplete': '清单可能不完整',
|
|
54
63
|
'settings.title': 'MCP & Skills 全局默认',
|
|
@@ -56,6 +65,12 @@ window.__ModuleLoader__.load({
|
|
|
56
65
|
'section.mcp': 'MCP 服务器',
|
|
57
66
|
'section.skills': 'Skills',
|
|
58
67
|
'action.refresh': '刷新',
|
|
68
|
+
'action.orphans': '清理孤立覆盖',
|
|
69
|
+
'action.orphansClean': '确认清理',
|
|
70
|
+
'action.cancel': '取消',
|
|
71
|
+
'orphans.confirm': '将清理孤立会话覆盖:',
|
|
72
|
+
'orphans.none': '没有孤立会话覆盖',
|
|
73
|
+
'orphans.cleaned': '已清理孤立会话覆盖',
|
|
59
74
|
'action.expand': '展开详情',
|
|
60
75
|
'action.collapse': '收起详情',
|
|
61
76
|
'action.reveal': '所在目录',
|
|
@@ -63,6 +78,7 @@ window.__ModuleLoader__.load({
|
|
|
63
78
|
'reveal.unknownSkill': '技能已不存在',
|
|
64
79
|
'reveal.noPath': '该技能没有文件位置',
|
|
65
80
|
'reveal.missingDirectory': '目录已不存在',
|
|
81
|
+
'reveal.packed': '该技能打包在应用内,没有可打开的本地目录',
|
|
66
82
|
'reveal.failed': '打开目录失败',
|
|
67
83
|
}
|
|
68
84
|
|
|
@@ -72,10 +88,16 @@ window.__ModuleLoader__.load({
|
|
|
72
88
|
'scope.session': 'This conversation only',
|
|
73
89
|
'scope.default': 'Applies to new conversations from here',
|
|
74
90
|
'scope.project': 'Project',
|
|
91
|
+
'group.user': 'Users',
|
|
92
|
+
'group.plugin': 'Plugins',
|
|
93
|
+
'group.preset': 'Preset',
|
|
94
|
+
'group.other': 'Other',
|
|
75
95
|
'action.followAll': 'Follow global',
|
|
76
96
|
'action.followItem': 'Follow global default',
|
|
77
97
|
'action.allOn': 'All on',
|
|
78
98
|
'action.allOff': 'All off',
|
|
99
|
+
'action.groupOn': 'Group on',
|
|
100
|
+
'action.groupOff': 'Group off',
|
|
79
101
|
'state.loading': 'Loading…',
|
|
80
102
|
'state.failed': 'Load failed',
|
|
81
103
|
'state.retry': 'Retry',
|
|
@@ -91,6 +113,7 @@ window.__ModuleLoader__.load({
|
|
|
91
113
|
'mcp.disconnected': 'not connected',
|
|
92
114
|
'mcp.connected': 'Connected',
|
|
93
115
|
'mcp.tools': 'tools',
|
|
116
|
+
'mcp.toolGroup': 'Tools',
|
|
94
117
|
'skills.empty': 'No skills are visible',
|
|
95
118
|
'skills.incomplete': 'The skill list may be incomplete',
|
|
96
119
|
'settings.title': 'MCP & Skills defaults',
|
|
@@ -98,6 +121,12 @@ window.__ModuleLoader__.load({
|
|
|
98
121
|
'section.mcp': 'MCP servers',
|
|
99
122
|
'section.skills': 'Skills',
|
|
100
123
|
'action.refresh': 'Refresh',
|
|
124
|
+
'action.orphans': 'Clean orphan overrides',
|
|
125
|
+
'action.orphansClean': 'Clean',
|
|
126
|
+
'action.cancel': 'Cancel',
|
|
127
|
+
'orphans.confirm': 'Overrides to remove:',
|
|
128
|
+
'orphans.none': 'No orphaned session overrides',
|
|
129
|
+
'orphans.cleaned': 'Orphaned overrides removed',
|
|
101
130
|
'action.expand': 'Show details',
|
|
102
131
|
'action.collapse': 'Hide details',
|
|
103
132
|
'action.reveal': 'Folder',
|
|
@@ -105,6 +134,7 @@ window.__ModuleLoader__.load({
|
|
|
105
134
|
'reveal.unknownSkill': 'The skill no longer exists',
|
|
106
135
|
'reveal.noPath': 'This skill has no file location',
|
|
107
136
|
'reveal.missingDirectory': 'The folder no longer exists',
|
|
137
|
+
'reveal.packed': 'This skill is packaged inside the app and has no local folder to open',
|
|
108
138
|
'reveal.failed': 'Could not open the folder',
|
|
109
139
|
}
|
|
110
140
|
|
|
@@ -282,8 +312,8 @@ window.__ModuleLoader__.load({
|
|
|
282
312
|
return React.createElement(SpriteIcon, { name: 'skill-outline', size })
|
|
283
313
|
}
|
|
284
314
|
|
|
285
|
-
/** 小箭头:官方 chevron-down-outline
|
|
286
|
-
function Caret({ size =
|
|
315
|
+
/** 小箭头:官方 chevron-down-outline;14px / caption 色,不随菜单旋转,对齐 agent preset seat。 */
|
|
316
|
+
function Caret({ size = 14, className }) {
|
|
287
317
|
return React.createElement(SpriteIcon, { name: 'chevron-down-outline', size, className })
|
|
288
318
|
}
|
|
289
319
|
|
|
@@ -295,11 +325,12 @@ window.__ModuleLoader__.load({
|
|
|
295
325
|
// #endregion
|
|
296
326
|
|
|
297
327
|
// 会话级按钮与浮层:逐值照抄官方基准 ——
|
|
298
|
-
// · trigger
|
|
299
|
-
// padding 0
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
328
|
+
// · trigger 对齐 ui-agent-preset 的 seat(28px 高、radius-sm 8px、
|
|
329
|
+
// 13px/20px、padding 0 8px、gap 4px)+ ghost 交互填充(hover 与
|
|
330
|
+
// 打开态都用 interactive-bg-hover,无 :active 高亮、disabled 0.4);
|
|
331
|
+
// caret 取官方 14px chevron-down-outline、label-caption 色,不随菜单旋转;
|
|
332
|
+
// 状态词「全开/n/m」是普通次级文字,不加徽标底 —— 对齐「2 个子智能体」
|
|
333
|
+
// 的纯文字排布。
|
|
303
334
|
// · 浮层容器取 MenuSurface + SubagentCatalog.menu:radius-lg 16px、
|
|
304
335
|
// menu-surface-fill 半透明底 + blur(40px) saturate(150%) 毛玻璃、
|
|
305
336
|
// elevation-prominent 描边阴影(0.5px 发丝描边画在 box-shadow 里)、
|
|
@@ -314,18 +345,17 @@ window.__ModuleLoader__.load({
|
|
|
314
345
|
.msc-wrap { position: relative; display: inline-flex; flex: none; align-self: center; }
|
|
315
346
|
.msc-trigger {
|
|
316
347
|
box-sizing: border-box; display: inline-flex; align-items: center; gap: 4px;
|
|
317
|
-
min-height: 28px; padding: 0
|
|
348
|
+
min-height: 28px; padding: 0 8px; max-width: 240px;
|
|
318
349
|
border: none; border-radius: var(--dsw-radius-sm); outline: none;
|
|
319
350
|
background: transparent; color: var(--dsw-alias-label-primary);
|
|
320
|
-
font-family: var(--dsw-font-family); font-size:
|
|
351
|
+
font-family: var(--dsw-font-family); font-size: 13px; line-height: 20px; font-weight: 500;
|
|
321
352
|
white-space: nowrap; cursor: pointer;
|
|
322
353
|
}
|
|
323
354
|
@media (hover: hover) {
|
|
324
355
|
.msc-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
325
356
|
}
|
|
326
|
-
.msc-trigger:active:not(:disabled) { background: var(--dsw-alias-interactive-bg-active); }
|
|
327
357
|
.msc-trigger[data-open="true"] {
|
|
328
|
-
background: var(--dsw-alias-interactive-bg-
|
|
358
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
329
359
|
color: var(--dsw-alias-label-primary);
|
|
330
360
|
}
|
|
331
361
|
.msc-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
@@ -336,15 +366,14 @@ window.__ModuleLoader__.load({
|
|
|
336
366
|
.msc-trigger[data-none="true"] .msc-state { color: var(--dsw-alias-label-caption); }
|
|
337
367
|
.msc-caret {
|
|
338
368
|
flex: none; display: inline-flex; align-items: center;
|
|
339
|
-
color: var(--dsw-alias-label-
|
|
340
|
-
transition: transform 120ms ease;
|
|
369
|
+
color: var(--dsw-alias-label-caption);
|
|
341
370
|
}
|
|
342
|
-
.msc-trigger[data-open="true"] .msc-caret { transform: rotate(180deg); }
|
|
343
371
|
/* 浮层:MenuSurface 材质(毛玻璃 + prominent 阴影)+ subagent 菜单几何。 */
|
|
344
372
|
.msc-menu {
|
|
345
373
|
position: absolute; top: calc(100% + 5px); right: 0; z-index: 100;
|
|
346
374
|
box-sizing: border-box;
|
|
347
375
|
width: 360px; max-height: min(560px, calc(100dvh - 140px)); overflow-y: auto;
|
|
376
|
+
overscroll-behavior: contain;
|
|
348
377
|
padding: 6px;
|
|
349
378
|
border-radius: var(--dsw-radius-lg);
|
|
350
379
|
background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay));
|
|
@@ -353,6 +382,15 @@ window.__ModuleLoader__.load({
|
|
|
353
382
|
font-size: 12px; line-height: 17px;
|
|
354
383
|
color: var(--dsw-alias-label-primary);
|
|
355
384
|
}
|
|
385
|
+
/* 浮层内部滚动但不显示滚动条:360px 的窄面板里滚动条会挤压内容,也破坏
|
|
386
|
+
毛玻璃边缘;滚轮 / 触控板 / 键盘(PageUp/PageDown)仍可正常滚动。 */
|
|
387
|
+
.msc-menu {
|
|
388
|
+
scrollbar-width: none;
|
|
389
|
+
-ms-overflow-style: none;
|
|
390
|
+
}
|
|
391
|
+
.msc-menu::-webkit-scrollbar { width: 0; height: 0; display: none; }
|
|
392
|
+
/* hero 在视口底部附近时向上开,max-height 由 measureMenu 实时写入 inline style。 */
|
|
393
|
+
.msc-menu[data-side="top"] { top: auto; bottom: calc(100% + 5px); }
|
|
356
394
|
.msc-head {
|
|
357
395
|
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
358
396
|
flex-wrap: wrap;
|
|
@@ -400,6 +438,16 @@ window.__ModuleLoader__.load({
|
|
|
400
438
|
.msc-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
401
439
|
}
|
|
402
440
|
.msc-item[data-busy="true"] { opacity: .4; }
|
|
441
|
+
/* 会话行外层:主行 + 可选展开的工具组,两者纵向排列。 */
|
|
442
|
+
.msc-itemWrap { display: flex; flex-direction: column; min-width: 0; }
|
|
443
|
+
.msc-itemActions { display: inline-flex; align-items: center; gap: 4px; flex: none; align-self: center; }
|
|
444
|
+
/* 行内开关容器:只做事件隔离,不改变布局。 */
|
|
445
|
+
.msc-itemSwitch { display: inline-flex; align-items: center; }
|
|
446
|
+
/* 可展开的会话行:整行可点(三角、连接点、标题都算),开关区除外。 */
|
|
447
|
+
.msc-item[data-expandable="true"] { cursor: pointer; }
|
|
448
|
+
/* 会话行展开的工具组:缩进到服务器名下方,与主行留出一点间距。 */
|
|
449
|
+
.msc-itemTools { display: flex; flex-direction: column; padding: 0 6px 6px 30px; min-width: 0; }
|
|
450
|
+
.msc-itemTools .msc-toolRow { padding: 2px 0; }
|
|
403
451
|
.msc-itemSlot {
|
|
404
452
|
display: inline-flex; flex: none;
|
|
405
453
|
align-items: center; justify-content: center;
|
|
@@ -482,6 +530,12 @@ window.__ModuleLoader__.load({
|
|
|
482
530
|
.msc-page { box-sizing: border-box; display: flex; flex-direction: column; gap: 24px; max-width: 720px; color: var(--dsw-alias-label-primary); }
|
|
483
531
|
.msc-pageHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
484
532
|
.msc-pageHeaderText { display: flex; flex-direction: column; gap: 4px; }
|
|
533
|
+
.msc-pageActions { display: flex; flex: none; align-items: center; gap: 8px; }
|
|
534
|
+
.msc-orphanBar {
|
|
535
|
+
display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
|
|
536
|
+
margin-top: 8px; font-size: 13px; line-height: 20px;
|
|
537
|
+
color: var(--dsw-alias-label-secondary);
|
|
538
|
+
}
|
|
485
539
|
.msc-pageTitle { margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
486
540
|
.msc-intro { margin: 0; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-tertiary); }
|
|
487
541
|
.msc-section { display: flex; flex-direction: column; }
|
|
@@ -492,11 +546,15 @@ window.__ModuleLoader__.load({
|
|
|
492
546
|
border-radius: var(--dsw-radius-xl);
|
|
493
547
|
padding: 2px 14px;
|
|
494
548
|
}
|
|
495
|
-
.msc-sectionHead { display: flex; align-items: center; gap: 12px; margin-bottom:
|
|
549
|
+
.msc-sectionHead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 0 14px; }
|
|
496
550
|
/* 动作按钮组:间距取 models 的 .rowActions(gap 4px)。 */
|
|
497
|
-
.msc-sectionActions { display: inline-flex; align-items: center; gap: 4px; flex: none; }
|
|
498
551
|
.msc-sectionTitle { margin: 0; font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
|
|
499
552
|
.msc-spacer { flex: 1; }
|
|
553
|
+
/* 设置页 skills 分组:组头(标签 + 三态开关)与组卡片分开;组与组之间留出呼吸。 */
|
|
554
|
+
.msc-group { display: flex; flex-direction: column; gap: 8px; }
|
|
555
|
+
.msc-group + .msc-group { margin-top: 20px; }
|
|
556
|
+
.msc-groupHead { display: flex; align-items: center; gap: 12px; padding: 0 14px; }
|
|
557
|
+
.msc-groupTitle { margin: 0; font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
|
|
500
558
|
/* 动作按钮:逐值照抄 ui-settings-models 的紧凑 secondary 按钮
|
|
501
559
|
(提供方行的紧凑 secondary 按钮)——box-sizing、28px 高、0 10px、radius-sm、
|
|
502
560
|
12px/18px、0.5px border-l3 描边、透明底、label-primary;hover 用
|
|
@@ -543,7 +601,8 @@ window.__ModuleLoader__.load({
|
|
|
543
601
|
color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 18px;
|
|
544
602
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
545
603
|
}
|
|
546
|
-
|
|
604
|
+
/* 未连接徽标(服务器行)。工具组样式见下方 .msc-tool*。 */
|
|
605
|
+
.msc-tag {
|
|
547
606
|
flex: none; display: inline-flex; align-items: center;
|
|
548
607
|
padding: 1px 6px;
|
|
549
608
|
border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-xs, 4px);
|
|
@@ -560,6 +619,8 @@ window.__ModuleLoader__.load({
|
|
|
560
619
|
}
|
|
561
620
|
.msc-detailsChevron { transition: transform 160ms ease; }
|
|
562
621
|
.msc-row[data-open="true"] .msc-detailsChevron { transform: rotate(180deg); }
|
|
622
|
+
/* 会话行的展开三角走同一个类名,但外层是 .msc-item。 */
|
|
623
|
+
.msc-item[data-open="true"] .msc-detailsChevron { transform: rotate(180deg); }
|
|
563
624
|
/* 展开详情:与主行同宽;描述允许换行,路径允许任意位置折行。 */
|
|
564
625
|
.msc-rowDetail { display: flex; flex-direction: column; gap: 6px; padding: 0 0 12px; }
|
|
565
626
|
.msc-detailDesc {
|
|
@@ -568,8 +629,27 @@ window.__ModuleLoader__.load({
|
|
|
568
629
|
}
|
|
569
630
|
.msc-detailMeta { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }
|
|
570
631
|
.msc-detailEmpty { color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
571
|
-
|
|
572
|
-
|
|
632
|
+
/* 工具组:设置页展开区与会话浮层共用。组头一行(小标题 + 恢复跟随 + 三态开关),
|
|
633
|
+
下面是逐工具行:裸名 + 单行描述 + 三态控件(设置页右侧同款开关)。 */
|
|
634
|
+
.msc-toolHead { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
|
|
635
|
+
.msc-toolHeadTitle {
|
|
636
|
+
font-size: 11px; line-height: 16px; font-weight: 500;
|
|
637
|
+
color: var(--dsw-alias-label-tertiary);
|
|
638
|
+
}
|
|
639
|
+
.msc-toolRows { display: flex; flex-direction: column; gap: 2px; }
|
|
640
|
+
.msc-toolRow { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 3px 0; }
|
|
641
|
+
.msc-toolBody { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
|
|
642
|
+
.msc-toolName {
|
|
643
|
+
font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-primary);
|
|
644
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
645
|
+
}
|
|
646
|
+
.msc-toolDesc {
|
|
647
|
+
font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary);
|
|
648
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
649
|
+
}
|
|
650
|
+
.msc-pathRow { display: flex; align-items: flex-start; gap: 10px; margin-top: 2px; }
|
|
651
|
+
/* 长路径会折行;动作按钮不参与收缩,避免「所在目录」被压成两行。 */
|
|
652
|
+
.msc-pathRow .msc-actionButton { flex: none; white-space: nowrap; }
|
|
573
653
|
.msc-path {
|
|
574
654
|
flex: 1 1 auto; min-width: 0;
|
|
575
655
|
color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px;
|
|
@@ -599,6 +679,22 @@ window.__ModuleLoader__.load({
|
|
|
599
679
|
}
|
|
600
680
|
.msc-switch[aria-checked="false"]::after { background: var(--dsw-alias-switch-thumb); }
|
|
601
681
|
.msc-switch[aria-checked="true"]::after { transform: translateX(16px); }
|
|
682
|
+
/* 部分开启:保持开关的滑块结构——轨道同「开」态,滑块居中,内部一道
|
|
683
|
+
轨道色横杠(减号),表示「既非全开也非全关」。比起空心圈 + 实心点,
|
|
684
|
+
它仍然读作一个开关,而不是两个圆点。 */
|
|
685
|
+
.msc-switch[aria-checked="mixed"] { background: var(--dsw-alias-brand-primary); }
|
|
686
|
+
.msc-switch[aria-checked="mixed"]::after {
|
|
687
|
+
transform: translateX(8px);
|
|
688
|
+
background: var(--dsw-alias-label-primary-foreground);
|
|
689
|
+
}
|
|
690
|
+
.msc-switch[aria-checked="mixed"]::before {
|
|
691
|
+
content: ""; position: absolute; z-index: 1;
|
|
692
|
+
left: 50%; top: 50%;
|
|
693
|
+
width: 6px; height: 2px;
|
|
694
|
+
transform: translate(-50%, -50%);
|
|
695
|
+
border-radius: 1px;
|
|
696
|
+
background: var(--dsw-alias-brand-primary);
|
|
697
|
+
}
|
|
602
698
|
@media (prefers-reduced-motion: reduce) { .msc-switch::after { transition: none; } }
|
|
603
699
|
.msc-emptyCard {
|
|
604
700
|
padding: 12px;
|
|
@@ -620,14 +716,25 @@ window.__ModuleLoader__.load({
|
|
|
620
716
|
return React.createElement(SpriteIcon, { name: 'refresh-outline', size })
|
|
621
717
|
}
|
|
622
718
|
|
|
623
|
-
/**
|
|
624
|
-
function
|
|
719
|
+
/** 一组布尔值的聚合:全开 true、全关 false、混合 'mixed';空组按 false。 */
|
|
720
|
+
function bulkState(values) {
|
|
721
|
+
if (values.length === 0) return false
|
|
722
|
+
if (values.every((value) => value === true)) return true
|
|
723
|
+
if (values.every((value) => value !== true)) return false
|
|
724
|
+
return 'mixed'
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** 官方 Switch 外观的通用按钮:会话行、设置页行、区块头与组头共用。
|
|
728
|
+
* checked 为 true / false / 'mixed';mixed(部分开启)挂 aria-checked 的第三态。 */
|
|
729
|
+
function SwitchButton({ checked, label, disabled, onClick, title }) {
|
|
730
|
+
const ariaChecked = checked === 'mixed' ? 'mixed' : checked === true ? 'true' : 'false'
|
|
625
731
|
return React.createElement('button', {
|
|
626
732
|
type: 'button',
|
|
627
733
|
className: 'msc-switch',
|
|
628
734
|
role: 'switch',
|
|
629
|
-
'aria-checked':
|
|
735
|
+
'aria-checked': ariaChecked,
|
|
630
736
|
'aria-label': label,
|
|
737
|
+
title,
|
|
631
738
|
disabled: disabled === true,
|
|
632
739
|
onClick,
|
|
633
740
|
})
|
|
@@ -652,6 +759,49 @@ window.__ModuleLoader__.load({
|
|
|
652
759
|
}, React.createElement(RestoreGlyph)))
|
|
653
760
|
}
|
|
654
761
|
|
|
762
|
+
/** 工具行:裸名 + 单行描述 + 三态控件。设置页与会话浮层共用。
|
|
763
|
+
* valueKey:全局视图传 'enabled',会话视图传 'effective'——两者都是「当前
|
|
764
|
+
* 实际状态」,控件显示它;显式覆盖时另出现 ↺ 恢复跟随。 */
|
|
765
|
+
function ToolRow({ tool, valueKey, busy, onSet, t }) {
|
|
766
|
+
const name = tool.rawName ?? tool.name
|
|
767
|
+
return React.createElement('div', { className: 'msc-toolRow', 'data-busy': String(busy) },
|
|
768
|
+
React.createElement('div', { className: 'msc-toolBody' },
|
|
769
|
+
React.createElement('div', { className: 'msc-toolName', title: tool.name }, name),
|
|
770
|
+
tool.description
|
|
771
|
+
? React.createElement('div', { className: 'msc-toolDesc', title: tool.description }, tool.description)
|
|
772
|
+
: null),
|
|
773
|
+
React.createElement(ModeControl, {
|
|
774
|
+
checked: tool[valueKey] === true,
|
|
775
|
+
name,
|
|
776
|
+
busy: busy === true,
|
|
777
|
+
followable: tool.mode !== 'follow',
|
|
778
|
+
onFollow: () => { onSet(tool, 'follow') },
|
|
779
|
+
onChange: (mode) => { onSet(tool, mode) },
|
|
780
|
+
t,
|
|
781
|
+
}))
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/** 工具组头:只显示「工具 on/total」。整组开关由服务器开关承担(点击会清掉
|
|
785
|
+
* 该服务器的工具级例外),这里不再放第二个「全开」开关,避免语义重叠。 */
|
|
786
|
+
function ToolGroupSummary({ tools, valueKey, t }) {
|
|
787
|
+
const on = tools.filter((tool) => tool[valueKey] === true).length
|
|
788
|
+
return React.createElement('div', { className: 'msc-toolHead' },
|
|
789
|
+
React.createElement('span', { className: 'msc-toolHeadTitle' },
|
|
790
|
+
`${t('mcp.toolGroup')} ${on}/${tools.length}`))
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* 服务器行的显示状态:以工具聚合为准。没有工具时退回服务器层;
|
|
795
|
+
* 全开 true / 全关 false / 部分开启 'mixed'(= 存在工具级例外)。
|
|
796
|
+
*/
|
|
797
|
+
function serverStateOf(row, valueKey) {
|
|
798
|
+
const stats = row?.toolStats
|
|
799
|
+
if (stats === undefined || stats.total === 0) return row?.[valueKey] === true
|
|
800
|
+
if (stats.on === stats.total) return true
|
|
801
|
+
if (stats.on === 0) return false
|
|
802
|
+
return 'mixed'
|
|
803
|
+
}
|
|
804
|
+
|
|
655
805
|
/** skills 行共用的悬停摘要:来源、provider 与调用面只进 title,不占版面。 */
|
|
656
806
|
function skillTip(item) {
|
|
657
807
|
const inv = item.invocation
|
|
@@ -679,6 +829,7 @@ window.__ModuleLoader__.load({
|
|
|
679
829
|
/** reveal 失败原因 → 本地化文案;未知原因回退通用提示。 */
|
|
680
830
|
function revealFailureText(reason, t) {
|
|
681
831
|
if (reason === 'no-path') return t('reveal.noPath')
|
|
832
|
+
if (reason === 'packed') return t('reveal.packed')
|
|
682
833
|
if (reason === 'missing-directory') return t('reveal.missingDirectory')
|
|
683
834
|
if (reason === 'unknown-skill') return t('reveal.unknownSkill')
|
|
684
835
|
return t('reveal.failed')
|
|
@@ -700,10 +851,38 @@ window.__ModuleLoader__.load({
|
|
|
700
851
|
const { sessionId, kind, t, glyph, title, renderRow, renderEmpty, foot } = props
|
|
701
852
|
|
|
702
853
|
const [open, setOpen] = React.useState(false)
|
|
854
|
+
// 展开到工具行的服务器名集合:纯 UI 状态,不写 RPC、不落盘,刷新不重置。
|
|
855
|
+
const [toolsOpen, setToolsOpen] = React.useState(() => new Set())
|
|
856
|
+
// 浮层相对触发器的放置:hero 靠近视口底部时向上开,并按可用高度实时限高,
|
|
857
|
+
// 避免绝对定位的菜单把整页撑出滚动条。
|
|
858
|
+
const [menu, setMenu] = React.useState({ side: 'bottom', maxHeight: 560 })
|
|
703
859
|
// 正在写入的项:'all' 或 '<kind>:<name>';只有该行(或全部)置灰,不锁整组。
|
|
704
860
|
const [busyKey, setBusyKey] = React.useState()
|
|
705
861
|
const rootRef = React.useRef(null)
|
|
706
862
|
|
|
863
|
+
/**
|
|
864
|
+
* 按触发器在视口中的位置选上下方向,并把菜单限高到可用空间。
|
|
865
|
+
* 可用空间不足时,内容在菜单内部滚动,而不是把整个页面撑出滚动条。
|
|
866
|
+
*/
|
|
867
|
+
const measureMenu = React.useCallback(() => {
|
|
868
|
+
const root = rootRef.current
|
|
869
|
+
const trigger = root?.firstElementChild
|
|
870
|
+
if (!(trigger instanceof Element)) return
|
|
871
|
+
const rect = trigger.getBoundingClientRect()
|
|
872
|
+
const viewport = window.innerHeight
|
|
873
|
+
const gap = 5
|
|
874
|
+
const margin = 12
|
|
875
|
+
const below = viewport - rect.bottom - gap - margin
|
|
876
|
+
const above = rect.top - gap - margin
|
|
877
|
+
const side = below >= above ? 'bottom' : 'top'
|
|
878
|
+
const available = Math.max(0, side === 'bottom' ? below : above)
|
|
879
|
+
// 至少保留一个可用高度;正常情况下选中的一侧有半个视口以上。
|
|
880
|
+
const maxHeight = Math.max(120, Math.min(560, available))
|
|
881
|
+
setMenu((current) => (current.side === side && current.maxHeight === maxHeight
|
|
882
|
+
? current
|
|
883
|
+
: { side, maxHeight }))
|
|
884
|
+
}, [])
|
|
885
|
+
|
|
707
886
|
// 覆盖按会话 id 保存;槽还没给出会话时没有可写的键。
|
|
708
887
|
const scoped = sessionId !== undefined && sessionId !== null && String(sessionId) !== ''
|
|
709
888
|
const sessionKey = scoped ? String(sessionId) : ''
|
|
@@ -748,6 +927,22 @@ window.__ModuleLoader__.load({
|
|
|
748
927
|
const items = kind === 'mcp' ? group?.servers ?? [] : group?.skills ?? []
|
|
749
928
|
const effectiveCount = items.reduce((sum, item) => sum + (item.effective === true ? 1 : 0), 0)
|
|
750
929
|
|
|
930
|
+
// 打开时、清单长度变化、展开工具组或窗口缩放/滚动时重新量一次。
|
|
931
|
+
React.useLayoutEffect(() => {
|
|
932
|
+
if (open) measureMenu()
|
|
933
|
+
}, [open, measureMenu, items.length, toolsOpen.size])
|
|
934
|
+
|
|
935
|
+
React.useEffect(() => {
|
|
936
|
+
if (!open) return undefined
|
|
937
|
+
const update = () => measureMenu()
|
|
938
|
+
window.addEventListener('resize', update)
|
|
939
|
+
window.addEventListener('scroll', update, true)
|
|
940
|
+
return () => {
|
|
941
|
+
window.removeEventListener('resize', update)
|
|
942
|
+
window.removeEventListener('scroll', update, true)
|
|
943
|
+
}
|
|
944
|
+
}, [open, measureMenu])
|
|
945
|
+
|
|
751
946
|
// 徽标只放短状态:全开 / 全关 / n/m;无条目或会话未知用 '—',
|
|
752
947
|
// 读取中用 '…'。完整说明留在浮层里,长句会把 220px 触发器撑破。
|
|
753
948
|
const label = !scoped
|
|
@@ -806,6 +1001,16 @@ window.__ModuleLoader__.load({
|
|
|
806
1001
|
})
|
|
807
1002
|
}
|
|
808
1003
|
|
|
1004
|
+
/** 展开 / 收起某个服务器的工具组(纯 UI 状态)。 */
|
|
1005
|
+
const toggleTools = (name) => {
|
|
1006
|
+
setToolsOpen((current) => {
|
|
1007
|
+
const next = new Set(current)
|
|
1008
|
+
if (next.has(name)) next.delete(name)
|
|
1009
|
+
else next.add(name)
|
|
1010
|
+
return next
|
|
1011
|
+
})
|
|
1012
|
+
}
|
|
1013
|
+
|
|
809
1014
|
return React.createElement('div', { className: 'msc-wrap', ref: rootRef },
|
|
810
1015
|
React.createElement('button', {
|
|
811
1016
|
type: 'button',
|
|
@@ -828,6 +1033,8 @@ window.__ModuleLoader__.load({
|
|
|
828
1033
|
className: 'msc-menu',
|
|
829
1034
|
role: 'dialog',
|
|
830
1035
|
'aria-label': title,
|
|
1036
|
+
'data-side': menu.side,
|
|
1037
|
+
style: { maxHeight: `${menu.maxHeight}px` },
|
|
831
1038
|
},
|
|
832
1039
|
React.createElement('div', { className: 'msc-head' },
|
|
833
1040
|
React.createElement('span', null, scoped ? t('scope.session') : t('scope.default')),
|
|
@@ -867,8 +1074,12 @@ window.__ModuleLoader__.load({
|
|
|
867
1074
|
items.map((item) => renderRow({
|
|
868
1075
|
item,
|
|
869
1076
|
busy: busyKey === 'all' || busyKey === `${kind}:${item.name}`,
|
|
1077
|
+
busyKey,
|
|
870
1078
|
setMode,
|
|
871
1079
|
t,
|
|
1080
|
+
// 只有 MCP 行用到:展开工具组的纯 UI 状态与切换回调。
|
|
1081
|
+
toolsOpen: toolsOpen.has(item.name),
|
|
1082
|
+
onToggleTools: () => { toggleTools(item.name) },
|
|
872
1083
|
})),
|
|
873
1084
|
|
|
874
1085
|
error !== undefined && React.createElement('div', { className: 'msc-err', role: 'alert' }, error),
|
|
@@ -877,17 +1088,24 @@ window.__ModuleLoader__.load({
|
|
|
877
1088
|
foot?.(group)))
|
|
878
1089
|
}
|
|
879
1090
|
|
|
880
|
-
/** MCP 会话行:CatalogTree 行基准 ——
|
|
881
|
-
|
|
1091
|
+
/** MCP 会话行:CatalogTree 行基准 —— 连接点 + 标题/副行 + 展开三角 + 三态控件。
|
|
1092
|
+
* 服务器控件以工具聚合为准:全开 / 全关 / 部分(有工具级例外)。 */
|
|
1093
|
+
function renderMcpRow({ item, busy, busyKey, setMode, t, toolsOpen, onToggleTools }) {
|
|
882
1094
|
// 副标题只放能一眼比较的短信息;完整 target 塞进 title(长命令被截断反而难辨认)。
|
|
883
1095
|
const toolsPart = typeof item.tools === 'number' ? `${item.tools} ${t('mcp.tools')}` : ''
|
|
884
1096
|
const meta = [toolsPart, item.transport]
|
|
885
1097
|
.filter((part) => part !== undefined && part !== null && part !== '')
|
|
886
1098
|
.join(' · ')
|
|
887
|
-
|
|
888
|
-
|
|
1099
|
+
const toolRows = Array.isArray(item.toolRows) ? item.toolRows : []
|
|
1100
|
+
const serverState = serverStateOf(item, 'effective')
|
|
1101
|
+
return React.createElement('div', { key: item.name, className: 'msc-itemWrap' },
|
|
1102
|
+
React.createElement('div', {
|
|
889
1103
|
className: 'msc-item',
|
|
890
1104
|
'data-busy': String(busy),
|
|
1105
|
+
'data-open': String(toolsOpen),
|
|
1106
|
+
'data-expandable': 'true',
|
|
1107
|
+
// 整行(连接点、标题、三角)都是展开目标;只有开关区阻止冒泡。
|
|
1108
|
+
onClick: onToggleTools,
|
|
891
1109
|
title: item.target ? `${item.name} — ${item.target}` : item.name,
|
|
892
1110
|
},
|
|
893
1111
|
// StateDot 语义:连接=success 绿点、未连接=error 红点(对照子代理行的运行/停止)。
|
|
@@ -898,24 +1116,58 @@ window.__ModuleLoader__.load({
|
|
|
898
1116
|
role: 'img',
|
|
899
1117
|
'aria-label': item.connected === true ? t('mcp.connected') : t('mcp.disconnected'),
|
|
900
1118
|
})),
|
|
901
|
-
React.createElement('div', {
|
|
1119
|
+
React.createElement('div', {
|
|
1120
|
+
className: 'msc-itemBody',
|
|
1121
|
+
role: 'button',
|
|
1122
|
+
tabIndex: 0,
|
|
1123
|
+
'aria-expanded': String(toolsOpen),
|
|
1124
|
+
onKeyDown: (event) => {
|
|
1125
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
1126
|
+
event.preventDefault()
|
|
1127
|
+
onToggleTools()
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
902
1130
|
React.createElement('div', { className: 'msc-itemLabel' },
|
|
903
1131
|
React.createElement('span', { className: 'msc-itemName' }, item.name)),
|
|
904
1132
|
React.createElement('div', { className: 'msc-itemSecondary' },
|
|
905
1133
|
React.createElement('span', { className: 'msc-itemSecondaryMain' }, meta),
|
|
906
1134
|
React.createElement('span', { className: 'msc-itemSecondaryGlob' },
|
|
907
1135
|
item.global === true ? t('global.on') : t('global.off')))),
|
|
1136
|
+
React.createElement('div', { className: 'msc-itemActions' },
|
|
1137
|
+
React.createElement(ExpandIndicator, { open: toolsOpen, t }),
|
|
1138
|
+
React.createElement('span', {
|
|
1139
|
+
className: 'msc-itemSwitch',
|
|
1140
|
+
// 开关与 ↺ 是行内独立动作:不让它们触发整行的展开/收起。
|
|
1141
|
+
onClick: (event) => { event.stopPropagation() },
|
|
1142
|
+
},
|
|
908
1143
|
React.createElement(ModeControl, {
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
checked:
|
|
1144
|
+
// 服务器控件显示工具聚合值:部分开启 = 有工具级例外;点击即整组重置
|
|
1145
|
+
// (宿主会清掉该服务器的工具例外),所以这里不另设工具组开关。
|
|
1146
|
+
checked: serverState,
|
|
912
1147
|
name: item.name,
|
|
913
1148
|
busy,
|
|
914
1149
|
followable: item.mode !== 'follow',
|
|
915
1150
|
onFollow: () => { void setMode(item, 'follow') },
|
|
916
1151
|
onChange: (mode) => { void setMode(item, mode) },
|
|
917
1152
|
t,
|
|
918
|
-
}))
|
|
1153
|
+
})))),
|
|
1154
|
+
toolsOpen && React.createElement('div', { className: 'msc-itemTools' },
|
|
1155
|
+
toolRows.length === 0
|
|
1156
|
+
? React.createElement('div', { className: 'msc-foot' }, t('mcp.noTools'))
|
|
1157
|
+
: React.createElement('div', { className: 'msc-toolRows' },
|
|
1158
|
+
React.createElement(ToolGroupSummary, {
|
|
1159
|
+
tools: toolRows,
|
|
1160
|
+
valueKey: 'effective',
|
|
1161
|
+
t,
|
|
1162
|
+
}),
|
|
1163
|
+
toolRows.map((tool) => React.createElement(ToolRow, {
|
|
1164
|
+
key: tool.name,
|
|
1165
|
+
tool,
|
|
1166
|
+
valueKey: 'effective',
|
|
1167
|
+
busy: busyKey === 'all' || busyKey === `mcp:${tool.name}`,
|
|
1168
|
+
onSet: (entry, mode) => { setMode({ name: entry.name }, mode) },
|
|
1169
|
+
t,
|
|
1170
|
+
})))))
|
|
919
1171
|
}
|
|
920
1172
|
|
|
921
1173
|
/** Skills 会话行:标题=skill 名(项目级带「项目」标签),副行=描述单行省略。 */
|
|
@@ -998,6 +1250,9 @@ window.__ModuleLoader__.load({
|
|
|
998
1250
|
const [expanded, setExpanded] = React.useState(() => new Set())
|
|
999
1251
|
// 正在打开目录的技能名;只禁用对应按钮,不阻塞开关。
|
|
1000
1252
|
const [revealing, setRevealing] = React.useState()
|
|
1253
|
+
// 孤立会话覆盖:undefined 表示没有待确认清单;数组为只读预览结果。
|
|
1254
|
+
const [orphans, setOrphans] = React.useState()
|
|
1255
|
+
const [orphanBusy, setOrphanBusy] = React.useState(false)
|
|
1001
1256
|
|
|
1002
1257
|
// 全局默认快照:挂载与每次手动刷新都读。
|
|
1003
1258
|
const snapshot = useSnapshot(
|
|
@@ -1015,18 +1270,60 @@ window.__ModuleLoader__.load({
|
|
|
1015
1270
|
const stateWarning = data?.stateWarning
|
|
1016
1271
|
const skillsIncomplete = data?.skills?.complete === false
|
|
1017
1272
|
|
|
1018
|
-
/**
|
|
1019
|
-
const
|
|
1273
|
+
/** 旧宿主兼容:缺 group 时按 origin 兜底;两者都没有则归其他。 */
|
|
1274
|
+
const groupOfSkill = (skill) => {
|
|
1275
|
+
if (typeof skill.group === 'string') return skill.group
|
|
1276
|
+
if (skill.origin === 'user') return 'user'
|
|
1277
|
+
if (skill.origin === 'package' || skill.origin === 'custom') return 'preset'
|
|
1278
|
+
if (skill.origin === 'plugin') return 'plugin'
|
|
1279
|
+
return 'other'
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/** 按固定顺序分组;空组不渲染,避免出现没有行的标题。 */
|
|
1283
|
+
const skillGroups = SKILL_GROUP_ORDER
|
|
1284
|
+
.map((group) => ({ group, rows: skills.filter((skill) => groupOfSkill(skill) === group) }))
|
|
1285
|
+
.filter((entry) => entry.rows.length > 0)
|
|
1286
|
+
|
|
1287
|
+
/** 写全局默认;item 省略表示整组。group 只在 item 省略时生效:
|
|
1288
|
+
* 指定后由宿主按分类挑选该组技能,客户端不传名字列表。 */
|
|
1289
|
+
const setGlobal = (kind, item, enabled, group) => {
|
|
1290
|
+
if (busyKey !== undefined) return
|
|
1291
|
+
const all = item === undefined
|
|
1292
|
+
const busy = all
|
|
1293
|
+
? (group === undefined ? `all:${kind}` : `group:${kind}:${group}`)
|
|
1294
|
+
: `${kind}:${item}`
|
|
1295
|
+
const payload = all
|
|
1296
|
+
? { kind, enabled, ...(group === undefined ? {} : { group }) }
|
|
1297
|
+
: { kind, item, enabled }
|
|
1298
|
+
void runMutation({
|
|
1299
|
+
requestRef,
|
|
1300
|
+
setBusyKey,
|
|
1301
|
+
setError,
|
|
1302
|
+
setNotice,
|
|
1303
|
+
busy,
|
|
1304
|
+
run: () => api(all ? '/global/all' : '/global/set', {
|
|
1305
|
+
method: 'POST',
|
|
1306
|
+
payload,
|
|
1307
|
+
}),
|
|
1308
|
+
onSuccess: (payload) => {
|
|
1309
|
+
setState({ phase: 'ready', data: payload })
|
|
1310
|
+
if (payload.persisted === false) setNotice(t('state.unsaved'))
|
|
1311
|
+
},
|
|
1312
|
+
})
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/** 写工具层全局三态(/global/set + mode;_follow_ 删除工具记录)。 */
|
|
1316
|
+
const setGlobalTool = (tool, mode) => {
|
|
1020
1317
|
if (busyKey !== undefined) return
|
|
1021
1318
|
void runMutation({
|
|
1022
1319
|
requestRef,
|
|
1023
1320
|
setBusyKey,
|
|
1024
1321
|
setError,
|
|
1025
1322
|
setNotice,
|
|
1026
|
-
busy:
|
|
1027
|
-
run: () => api(
|
|
1323
|
+
busy: `mcp:${tool.name}`,
|
|
1324
|
+
run: () => api('/global/set', {
|
|
1028
1325
|
method: 'POST',
|
|
1029
|
-
payload:
|
|
1326
|
+
payload: { kind: 'mcp', item: tool.name, mode },
|
|
1030
1327
|
}),
|
|
1031
1328
|
onSuccess: (payload) => {
|
|
1032
1329
|
setState({ phase: 'ready', data: payload })
|
|
@@ -1035,9 +1332,51 @@ window.__ModuleLoader__.load({
|
|
|
1035
1332
|
})
|
|
1036
1333
|
}
|
|
1037
1334
|
|
|
1335
|
+
/** 只读预览孤立会话覆盖;有结果时进入确认条,不直接删除。 */
|
|
1336
|
+
const checkOrphans = async () => {
|
|
1337
|
+
if (orphanBusy) return
|
|
1338
|
+
setOrphanBusy(true)
|
|
1339
|
+
setError(undefined)
|
|
1340
|
+
setNotice(undefined)
|
|
1341
|
+
try {
|
|
1342
|
+
const payload = await api('/maintenance/orphans', {})
|
|
1343
|
+
const rows = Array.isArray(payload.orphans) ? payload.orphans : []
|
|
1344
|
+
if (rows.length === 0) {
|
|
1345
|
+
setOrphans(undefined)
|
|
1346
|
+
setNotice(t('orphans.none'))
|
|
1347
|
+
} else {
|
|
1348
|
+
setOrphans(rows)
|
|
1349
|
+
}
|
|
1350
|
+
} catch (reason) {
|
|
1351
|
+
setError(reason instanceof Error ? reason.message : String(reason))
|
|
1352
|
+
} finally {
|
|
1353
|
+
setOrphanBusy(false)
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** 确认后清理;宿主重新校验会话存在性,返回最新全局快照。 */
|
|
1358
|
+
const cleanOrphans = async () => {
|
|
1359
|
+
if (orphanBusy || orphans === undefined) return
|
|
1360
|
+
setOrphanBusy(true)
|
|
1361
|
+
setError(undefined)
|
|
1362
|
+
setNotice(undefined)
|
|
1363
|
+
try {
|
|
1364
|
+
const payload = await api('/maintenance/orphans/clean', { method: 'POST' })
|
|
1365
|
+
setState({ phase: 'ready', data: payload })
|
|
1366
|
+
setOrphans(undefined)
|
|
1367
|
+
const count = Array.isArray(payload.removed) ? payload.removed.length : 0
|
|
1368
|
+
setNotice(payload.persisted === false
|
|
1369
|
+
? t('state.unsaved')
|
|
1370
|
+
: `${t('orphans.cleaned')} ${count}`)
|
|
1371
|
+
} catch (reason) {
|
|
1372
|
+
setError(reason instanceof Error ? reason.message : String(reason))
|
|
1373
|
+
} finally {
|
|
1374
|
+
setOrphanBusy(false)
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1038
1378
|
/** 展开 / 收起某一行;刷新数据不会重置展开状态。 */
|
|
1039
|
-
const toggleExpanded = (kind, name) => {
|
|
1040
|
-
setExpanded((current) => {
|
|
1379
|
+
const toggleExpanded = (kind, name) => { setExpanded((current) => {
|
|
1041
1380
|
const next = new Set(current)
|
|
1042
1381
|
const key = `${kind}:${name}`
|
|
1043
1382
|
if (next.has(key)) next.delete(key)
|
|
@@ -1077,32 +1416,33 @@ window.__ModuleLoader__.load({
|
|
|
1077
1416
|
}
|
|
1078
1417
|
}
|
|
1079
1418
|
|
|
1080
|
-
/**
|
|
1081
|
-
const renderSectionHead = (titleKey, kind) =>
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
className: 'msc-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}, t('action.allOff'))))
|
|
1419
|
+
/** 区块头:标题 + 与条目开关右缘对齐的三态开关(无条目时不显示)。 */
|
|
1420
|
+
const renderSectionHead = (titleKey, kind) => {
|
|
1421
|
+
const rows = kind === 'mcp' ? mcpServers : skills
|
|
1422
|
+
const state = bulkState(rows.map((row) => row.enabled === true))
|
|
1423
|
+
const action = state === true ? t('action.allOff') : t('action.allOn')
|
|
1424
|
+
return React.createElement('div', { className: 'msc-sectionHead' },
|
|
1425
|
+
React.createElement('h3', { className: 'msc-sectionTitle' }, t(titleKey)),
|
|
1426
|
+
React.createElement('span', { className: 'msc-spacer' }),
|
|
1427
|
+
rows.length > 0 && React.createElement(SwitchButton, {
|
|
1428
|
+
checked: state,
|
|
1429
|
+
label: t(titleKey),
|
|
1430
|
+
title: `${t(titleKey)} — ${action}`,
|
|
1431
|
+
disabled: busyKey !== undefined,
|
|
1432
|
+
onClick: () => { void setGlobal(kind, undefined, state !== true) },
|
|
1433
|
+
}))
|
|
1434
|
+
}
|
|
1097
1435
|
|
|
1098
|
-
/** 全局 MCP 行:主行(题 + 说明 + 展开/开关)+
|
|
1436
|
+
/** 全局 MCP 行:主行(题 + 说明 + 展开/开关)+ 展开后的工具行。
|
|
1437
|
+
* 服务器开关以工具聚合为准,点击整组重置(宿主清掉工具例外)。 */
|
|
1099
1438
|
const renderMcpRow = (server) => {
|
|
1100
1439
|
const open = isExpanded('mcp', server.name)
|
|
1101
1440
|
const toolsPart = typeof server.tools === 'number' ? `${server.tools} ${t('mcp.tools')}` : ''
|
|
1102
1441
|
const meta = [toolsPart, server.transport]
|
|
1103
1442
|
.filter((part) => part !== undefined && part !== null && part !== '')
|
|
1104
1443
|
.join(' · ')
|
|
1105
|
-
const
|
|
1444
|
+
const toolRows = Array.isArray(server.toolRows) ? server.toolRows : []
|
|
1445
|
+
const serverState = serverStateOf(server, 'enabled')
|
|
1106
1446
|
return React.createElement('div', {
|
|
1107
1447
|
key: server.name,
|
|
1108
1448
|
className: 'msc-row',
|
|
@@ -1130,31 +1470,40 @@ window.__ModuleLoader__.load({
|
|
|
1130
1470
|
React.createElement('div', { className: 'msc-rowActions' },
|
|
1131
1471
|
React.createElement(ExpandIndicator, { open, t }),
|
|
1132
1472
|
React.createElement(SwitchButton, {
|
|
1133
|
-
checked:
|
|
1473
|
+
checked: serverState,
|
|
1134
1474
|
label: server.name,
|
|
1135
1475
|
disabled: busyKey !== undefined,
|
|
1136
1476
|
onClick: (event) => {
|
|
1137
1477
|
// 开关是行内独立动作:阻止冒泡,避免点开关时同时展开/收起详情。
|
|
1138
1478
|
event.stopPropagation()
|
|
1139
|
-
|
|
1479
|
+
// 部分开启(有工具例外)视作「未全开」,点一下整组打开。
|
|
1480
|
+
void setGlobal('mcp', server.name, serverState !== true)
|
|
1140
1481
|
},
|
|
1141
1482
|
}))),
|
|
1142
1483
|
open && React.createElement('div', { className: 'msc-rowDetail' },
|
|
1143
|
-
|
|
1484
|
+
toolRows.length === 0
|
|
1144
1485
|
? React.createElement('div', { className: 'msc-detailEmpty' }, t('mcp.noTools'))
|
|
1145
|
-
: React.createElement('div', { className: 'msc-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1486
|
+
: React.createElement('div', { className: 'msc-toolRows' },
|
|
1487
|
+
React.createElement(ToolGroupSummary, {
|
|
1488
|
+
tools: toolRows,
|
|
1489
|
+
valueKey: 'enabled',
|
|
1490
|
+
t,
|
|
1491
|
+
}),
|
|
1492
|
+
toolRows.map((tool) => React.createElement(ToolRow, {
|
|
1493
|
+
key: tool.name,
|
|
1494
|
+
tool,
|
|
1495
|
+
valueKey: 'enabled',
|
|
1496
|
+
busy: busyKey === `mcp:${tool.name}`,
|
|
1497
|
+
onSet: (entry, mode) => { setGlobalTool(entry, mode) },
|
|
1498
|
+
t,
|
|
1499
|
+
})))))
|
|
1152
1500
|
}
|
|
1153
1501
|
|
|
1154
1502
|
/** 全局 Skills 行:主行(描述单行省略 + 展开/开关)+ 展开后的完整描述与位置。 */
|
|
1155
1503
|
const renderSkillRow = (skill) => {
|
|
1156
1504
|
const open = isExpanded('skills', skill.name)
|
|
1157
1505
|
const path = typeof skill.path === 'string' && skill.path.length > 0 ? skill.path : undefined
|
|
1506
|
+
const packed = skill.packed === true
|
|
1158
1507
|
const meta = [skill.source, skill.provider]
|
|
1159
1508
|
.filter((part) => part !== undefined && part !== null && part !== '')
|
|
1160
1509
|
.join(' · ')
|
|
@@ -1193,10 +1542,11 @@ window.__ModuleLoader__.load({
|
|
|
1193
1542
|
open && React.createElement('div', { className: 'msc-rowDetail' },
|
|
1194
1543
|
React.createElement('div', { className: 'msc-detailDesc' }, skill.description ?? ''),
|
|
1195
1544
|
meta !== '' && React.createElement('div', { className: 'msc-detailMeta' }, meta),
|
|
1196
|
-
//
|
|
1545
|
+
// 虚拟技能没有指令文件,展开区不显示位置行;asar 内的路径不可被文件管理器打开,
|
|
1546
|
+
// 只显示路径,不给出必然失败的动作按钮。
|
|
1197
1547
|
path !== undefined && React.createElement('div', { className: 'msc-pathRow' },
|
|
1198
1548
|
React.createElement('span', { className: 'msc-path' }, path),
|
|
1199
|
-
React.createElement('button', {
|
|
1549
|
+
!packed && React.createElement('button', {
|
|
1200
1550
|
type: 'button',
|
|
1201
1551
|
className: 'msc-actionButton',
|
|
1202
1552
|
disabled: revealing === skill.name,
|
|
@@ -1204,17 +1554,59 @@ window.__ModuleLoader__.load({
|
|
|
1204
1554
|
}, t('action.reveal')))))
|
|
1205
1555
|
}
|
|
1206
1556
|
|
|
1557
|
+
/** 单个来源分组:组头标签 + 三态开关(开 / 关 / 部分开启)。 */
|
|
1558
|
+
const renderSkillGroup = ({ group, rows }) => {
|
|
1559
|
+
const label = t(`group.${group}`)
|
|
1560
|
+
const state = bulkState(rows.map((row) => row.enabled === true))
|
|
1561
|
+
const action = state === true ? t('action.groupOff') : t('action.groupOn')
|
|
1562
|
+
return React.createElement('div', { key: group, className: 'msc-group' },
|
|
1563
|
+
React.createElement('div', { className: 'msc-groupHead' },
|
|
1564
|
+
React.createElement('h4', { className: 'msc-groupTitle' }, label),
|
|
1565
|
+
React.createElement('span', { className: 'msc-spacer' }),
|
|
1566
|
+
React.createElement(SwitchButton, {
|
|
1567
|
+
checked: state,
|
|
1568
|
+
label,
|
|
1569
|
+
title: `${label} — ${action}`,
|
|
1570
|
+
disabled: busyKey !== undefined,
|
|
1571
|
+
onClick: () => { void setGlobal('skills', undefined, state !== true, group) },
|
|
1572
|
+
})),
|
|
1573
|
+
React.createElement('div', { className: 'msc-card' }, rows.map(renderSkillRow)))
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1207
1576
|
return React.createElement('div', { className: 'msc-page' },
|
|
1208
1577
|
React.createElement('div', { className: 'msc-pageHead' },
|
|
1209
1578
|
React.createElement('div', { className: 'msc-pageHeaderText' },
|
|
1210
1579
|
React.createElement('h2', { className: 'msc-pageTitle' }, t('settings.title')),
|
|
1211
1580
|
React.createElement('p', { className: 'msc-intro' }, t('settings.note'))),
|
|
1581
|
+
React.createElement('div', { className: 'msc-pageActions' },
|
|
1582
|
+
React.createElement('button', {
|
|
1583
|
+
type: 'button',
|
|
1584
|
+
className: 'msc-actionButton',
|
|
1585
|
+
disabled: orphanBusy,
|
|
1586
|
+
onClick: () => { void checkOrphans() },
|
|
1587
|
+
}, t('action.orphans')),
|
|
1212
1588
|
React.createElement('button', {
|
|
1213
1589
|
type: 'button',
|
|
1214
1590
|
className: 'msc-actionButton',
|
|
1215
1591
|
disabled: busyKey !== undefined,
|
|
1216
1592
|
onClick: retry,
|
|
1217
|
-
}, t('action.refresh'))),
|
|
1593
|
+
}, t('action.refresh')))),
|
|
1594
|
+
|
|
1595
|
+
orphans !== undefined && React.createElement('div', { className: 'msc-orphanBar', role: 'status' },
|
|
1596
|
+
React.createElement('span', null, t('orphans.confirm'), ' ',
|
|
1597
|
+
React.createElement('strong', null, orphans.length)),
|
|
1598
|
+
React.createElement('button', {
|
|
1599
|
+
type: 'button',
|
|
1600
|
+
className: 'msc-actionButton',
|
|
1601
|
+
disabled: orphanBusy,
|
|
1602
|
+
onClick: () => { void cleanOrphans() },
|
|
1603
|
+
}, t('action.orphansClean')),
|
|
1604
|
+
React.createElement('button', {
|
|
1605
|
+
type: 'button',
|
|
1606
|
+
className: 'msc-actionButton',
|
|
1607
|
+
disabled: orphanBusy,
|
|
1608
|
+
onClick: () => setOrphans(undefined),
|
|
1609
|
+
}, t('action.cancel'))),
|
|
1218
1610
|
|
|
1219
1611
|
state.phase === 'loading' && React.createElement('p', { className: 'msc-statusText', role: 'status' }, t('state.loading')),
|
|
1220
1612
|
state.phase === 'failed' && React.createElement('div', { className: 'msc-pageHead' },
|
|
@@ -1240,10 +1632,10 @@ window.__ModuleLoader__.load({
|
|
|
1240
1632
|
: mcpServers.map(renderMcpRow))),
|
|
1241
1633
|
React.createElement('section', { className: 'msc-section' },
|
|
1242
1634
|
renderSectionHead('section.skills', 'skills'),
|
|
1243
|
-
React.createElement('div', { className: 'msc-card' },
|
|
1244
1635
|
skills.length === 0
|
|
1245
|
-
? React.createElement('div', { className: 'msc-
|
|
1246
|
-
|
|
1636
|
+
? React.createElement('div', { className: 'msc-card' },
|
|
1637
|
+
React.createElement('div', { className: 'msc-emptyCard' }, t('skills.empty')))
|
|
1638
|
+
: skillGroups.map(renderSkillGroup),
|
|
1247
1639
|
skillsIncomplete && React.createElement('p', {
|
|
1248
1640
|
className: 'msc-statusText',
|
|
1249
1641
|
'data-tone': 'warn',
|