@yangyangyuyu/dsh-inventory-panel 0.0.0-stage → 1.0.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/client.js ADDED
@@ -0,0 +1,894 @@
1
+ window.__ModuleLoader__.load({
2
+ id: '@yangyangyuyu/dsh-inventory-panel',
3
+ factory(require) {
4
+ const React = require('react');
5
+ const h = React.createElement;
6
+
7
+ const API = '/api/dsh-inventory/list';
8
+ const SAVE_API = '/api/dsh-inventory/skill/save';
9
+ const TOGGLE_API = '/api/dsh-inventory/skill/enable';
10
+ const DELETE_API = '/api/dsh-inventory/skill/delete';
11
+ const IMPORT_API = '/api/dsh-inventory/skill/import';
12
+ const KIND_LABEL = { plugin: '插件', skill: '技能', builtin: '内置' };
13
+
14
+ /** Plain-language notes: what it does, when to reach for it, how to use it. */
15
+ const PLUGIN_NOTES = {
16
+ dshmarket: {
17
+ what: '一个装插件的地方:像应用商店一样搜索、安装、更新插件,顺带还能换主题。',
18
+ when: '想给 DSH 加新功能,或想看看别人做了什么插件的时候。',
19
+ how: ['侧边栏打开「插件市场」→ 搜插件名 → 安装', '已装的插件在「插件」页里可以关掉或更新', '装完一般不用重启,刷新页面即可']
20
+ },
21
+ 'dsh-context': {
22
+ what: '一块仪表盘:告诉你每次对话花了多少 Token、上下文里装了什么、多个 Agent 各自在忙什么。',
23
+ when: '对话变慢、费用变高,或想搞清楚模型到底看到了什么的时候。',
24
+ how: ['侧边栏「上下文洞察」:用量概览与会话卡片', '对话里输入 /context:当前上下文构成', '右侧栏选 Context:聊天旁的实时面板']
25
+ },
26
+ 'dsh-pet': {
27
+ what: '一只住在界面里的桌面宠物:会自己溜达、打盹、跟你唠叨,也能被你拖着甩来甩去。',
28
+ when: '想给工作界面添点生气的时候;不想看它就在「插件」页关掉。',
29
+ how: ['装好后自动出现,可以拖着走', '设置在其插件详情页', '不想要时在「插件」页关掉它']
30
+ },
31
+ 'dsh-ops': {
32
+ what: '一套更省 Token 的工具替身:用更精简的文件与命令工具顶替内置工具,返回更短、报错更好读。',
33
+ when: '长任务里想省钱、少绕弯的时候;默认已经开着,一般不用管它。',
34
+ how: ['自动生效,无需操作', '插件详情页可切换工具模式(标准 / 精简 / PTC)', '提供 ops_bash、ops_glob、ops_grep、ops_inspect_local_file 等工具']
35
+ },
36
+ '@vectorize-io/hindsight-coding-agents': {
37
+ what: '长期记忆:把每个项目的关键决定和讨论存起来,换新会话时还能想起「当初为什么这么定」。',
38
+ when: '跨好几天做同一个项目,或需要回头翻旧决定的时候。',
39
+ how: ['自动运行,会话顶部会显示 memory bank', '想说「记住这件事」时直接告诉助手', '问「之前为什么这么定」会去记忆里找答案']
40
+ },
41
+ '@tt-a1i/archify-dsh': {
42
+ what: '一个画图技能包:把系统、流程、时序、表结构画成能点开的网页图,也能把一段回答做成一页解释页。它自己没有任何界面。',
43
+ when: '要把一件复杂的事讲清楚、要画架构图或流程图的时候。',
44
+ how: ['直接说「画一张架构图 / 时序图 / ERD」', '或「把这段做成一页」', '产物是一个可以打开的 HTML 文件']
45
+ },
46
+ '@linxin666/dsh-client-ui-skill-explorer': {
47
+ what: '技能中心:把本机所有技能列出来,能开关、能新建、能删,还能从文件夹或压缩包批量导入。',
48
+ when: '想管理技能、临时关掉某个技能,或自己写一个新技能的时候。',
49
+ how: ['侧边栏「技能中心」→ 技能 / 导入 / 创建 / 编辑', '顶部搜索按名称或描述过滤', '开关控制模型能否自动调用该技能']
50
+ },
51
+ 'dsh-inventory-panel': {
52
+ what: '就是你现在看的这个面板:列出插件与技能,说明每项是干嘛的、什么时候用、怎么用,并且能直接管理技能(启停、编辑、新建、删除)。',
53
+ when: '想知道「我到底装了什么」,或要调整某个技能的时候。',
54
+ how: ['搜索框找条目;点「怎么用」展开步骤', '技能卡上可直接启停、编辑、删除', '右上角刷新按钮重新扫描']
55
+ }
56
+ };
57
+
58
+ /** Plain-language notes for skills: what the capability is, when to ask for it, how to trigger it. */
59
+ const SKILL_NOTES = {
60
+ archify: {
61
+ what: '一个画图技能:架构图、流程图、时序图、数据流、ERD、类图、时间线都能画成可交互网页,也能把回答做成一页说明。',
62
+ when: '需要把系统讲清楚、需要图、需要一页可分享的说明时。',
63
+ how: ['说「画一张架构图 / 流程图 / 时序图」', '说「做成一页」「用页面讲」', '也能给它 Mermaid 文本']
64
+ },
65
+ 'hindsight-coding-agent': {
66
+ what: '解释本机长期记忆是怎么工作的,并在记忆记错、没生效时带你排查。',
67
+ when: '想搞懂记忆机制,或觉得它记错了的时候。',
68
+ how: ['问「记忆 / 页面是什么」', '说「存到 hindsight」', '记忆看起来不对时让它排查']
69
+ },
70
+ 'dsh-doc': {
71
+ what: 'DSH 自己的说明书兼开发顾问:功能怎么用、设置在哪、插件怎么开发、版本怎么升级。',
72
+ when: '问 DSH 自身的事,或要动手写插件、装 bundle 的时候。',
73
+ how: ['问「DSH 这个功能怎么用」', '要写插件或装 bundle 时', '要看当前安装版本的文档时']
74
+ },
75
+ office: {
76
+ what: 'Office 文件总入口:创建和修改 Word / Excel / PPT,也能检查已有文件和 PDF、重算表格公式。',
77
+ when: '要交付文档、表格、幻灯片,或要读一份 PDF 的时候。',
78
+ how: ['要出 docx / xlsx / pptx 时', '要看 PDF 或重算表格时']
79
+ },
80
+ 'office-docx': { what: '专门做 Word:读、写、改、校验 .docx 文档。', when: '要合同、报告、说明书这类 Word 交付时。', how: ['要合同、报告、说明书时'] },
81
+ 'office-pptx': { what: '专门做 PPT:读、写、改、校验 .pptx 演示文稿。', when: '要做汇报幻灯片、产品介绍 deck 时。', how: ['要做汇报幻灯片时'] },
82
+ 'office-xlsx': { what: '专门做表格:读、写、改、校验 .xlsx,支持数据与公式。', when: '要做表、算数、清洗数据、加公式或图表时。', how: ['要做表、算数、清洗数据时'] },
83
+ 'diagnose-windows-sandbox-acl': {
84
+ what: 'Windows 上「拒绝访问」的侦探:检查目录权限,并修复 DSH 沙箱写入或读取失败的问题。',
85
+ when: '工作区写不进去、本该能读的文件读不了的时候。',
86
+ how: ['工作区写不进去时', '本该能读的文件读不了时']
87
+ }
88
+ };
89
+
90
+ const FALLBACK_PLUGIN_WHAT = '这个插件没有写说明;可以点开它的项目主页看看,或到「插件」页查看详情。';
91
+ const FALLBACK_SKILL_WHAT = '这个技能没有写说明;可以在对话里直接说出相关任务,看它是否被自动加载。';
92
+ const FALLBACK_PLUGIN_HOW = ['在「插件」页打开它的详情,能看到说明与设置', '需要时用右上角的刷新按钮', '具体用法看它的项目主页'];
93
+ const FALLBACK_SKILL_HOW = ['在对话里描述和它相关的任务,命中时会自动加载', '也可以直接点名这个技能', '来源标签说明了它从哪来'];
94
+
95
+ function sourceLabel(source) {
96
+ if (!source) return '来源未知';
97
+ if (source === 'bundled') return 'DSH 内置';
98
+ if (source.indexOf('project') === 0) return '项目技能';
99
+ if (source.indexOf('user') === 0) return '用户技能';
100
+ if (source === 'runtime') return '插件提供';
101
+ if (source.indexOf('custom') === 0) return '自定义目录';
102
+ return source;
103
+ }
104
+
105
+ function clock(iso) {
106
+ if (!iso) return '';
107
+ const date = new Date(iso);
108
+ if (isNaN(date.getTime())) return '';
109
+ const two = (value) => String(value).padStart(2, '0');
110
+ return two(date.getHours()) + ':' + two(date.getMinutes()) + ':' + two(date.getSeconds());
111
+ }
112
+
113
+ function glyphOf(item) {
114
+ if (item.kind === 'builtin') return '@';
115
+ return String(item.name || '?').replace(/^@[^/]+\//, '').slice(0, 1).toUpperCase();
116
+ }
117
+
118
+ function postJson(url, body) {
119
+ return fetch(url, {
120
+ method: 'POST',
121
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
122
+ body: JSON.stringify(body)
123
+ }).then((response) => response.json().then((json) => {
124
+ if (!response.ok || (json && json.error)) throw new Error((json && json.error) || 'HTTP ' + response.status);
125
+ return json;
126
+ }));
127
+ }
128
+
129
+ const CSS = `
130
+ .dshinv{--bt-accent:var(--dsw-alias-brand-primary,#0071e3);
131
+ --bt-ink:var(--dsw-alias-label-primary,currentColor);
132
+ --bt-muted:var(--dsw-alias-label-tertiary,color-mix(in srgb,currentColor 55%,transparent));
133
+ --bt-line:var(--dsw-alias-border-secondary,color-mix(in srgb,currentColor 12%,transparent));
134
+ --bt-r:20px;--bt-gap:16px;
135
+ height:100%;min-height:100%;overflow:auto;box-sizing:border-box;padding:40px 40px 96px;
136
+ color:var(--bt-ink);
137
+ font:15px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;
138
+ -webkit-font-smoothing:antialiased}
139
+ .dshinv *{box-sizing:border-box}
140
+ .dshinv h1{margin:0;font-size:40px;line-height:1.08;font-weight:600;letter-spacing:-.03em}
141
+ .btgrid{display:grid;grid-template-columns:repeat(12,1fr);gap:var(--bt-gap);grid-auto-flow:dense}
142
+ .bt-tile{grid-column:span 12;border-radius:var(--bt-r);padding:24px;background:color-mix(in srgb,currentColor 3%,transparent);
143
+ display:flex;flex-direction:column;gap:12px;min-width:0}
144
+ .bt-hero{grid-column:span 8;background:color-mix(in srgb,var(--bt-accent) 9%,transparent)}
145
+ .bt-eyebrow{font-size:10.5px;letter-spacing:.16em;text-transform:uppercase;color:var(--bt-muted)}
146
+ .bt-deck{margin:0;font-size:15px;line-height:1.6;max-width:46ch}
147
+ .bt-toolbar{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin-top:auto;padding-top:6px}
148
+ .bt-live{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--bt-muted)}
149
+ .bt-livedot{width:6px;height:6px;border-radius:50%;background:var(--bt-accent)}
150
+ .bt-cta{appearance:none;margin-left:auto;border:0;border-radius:14px;padding:9px 18px;
151
+ background:var(--bt-accent);color:#fff;font:inherit;font-size:13px;font-weight:500;cursor:pointer;
152
+ transition:filter .18s ease,transform .18s ease}
153
+ .bt-cta:hover{filter:brightness(1.08);transform:translateY(-1px)}
154
+ .bt-stats{grid-column:span 4;justify-content:space-between}
155
+ .bt-statrow{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;align-items:end;height:100%}
156
+ .bt-stat{display:flex;flex-direction:column;gap:2px}
157
+ .bt-stat b{font-size:34px;line-height:1;font-weight:600;letter-spacing:-.03em;font-variant-numeric:tabular-nums}
158
+ .bt-stat span{font-size:11.5px;color:var(--bt-muted)}
159
+ .bt-guide{grid-column:span 12;background:color-mix(in srgb,var(--bt-accent) 6%,transparent)}
160
+ .bt-guidehead{display:flex;align-items:center;gap:10px;background:none;border:0;padding:0;
161
+ font:inherit;color:inherit;cursor:pointer;text-align:left;width:100%}
162
+ .bt-guidehead svg{transition:transform .18s ease}
163
+ .bt-guidehead[aria-expanded="true"] svg{transform:rotate(90deg)}
164
+ .bt-guidetitle{font-size:18px;font-weight:600;letter-spacing:-.01em}
165
+ .bt-guidegrid{margin:4px 0 0;padding:0;list-style:none;display:grid;gap:16px 24px;
166
+ grid-template-columns:repeat(2,minmax(0,1fr))}
167
+ .bt-guidegrid li{display:flex;gap:10px;font-size:13.5px;line-height:1.6;color:var(--bt-muted)}
168
+ .bt-guidenum{flex:none;width:22px;height:22px;border-radius:8px;display:grid;place-items:center;
169
+ background:color-mix(in srgb,var(--bt-accent) 16%,transparent);color:var(--bt-accent);font-size:11px;font-weight:600}
170
+ .bt-sec{margin:80px 0 0}
171
+ .bt-sechead{display:flex;align-items:baseline;gap:12px;margin:0 0 16px}
172
+ .bt-sectitle{margin:0;font-size:12px;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:var(--bt-muted)}
173
+ .bt-seccount{font-size:12px;color:var(--bt-muted);font-variant-numeric:tabular-nums}
174
+ .bt-secsub{margin-left:auto;font-size:12.5px;color:var(--bt-muted)}
175
+ .bt-cards{display:grid;grid-template-columns:repeat(12,1fr);gap:var(--bt-gap);grid-auto-flow:dense}
176
+ .bt-card{grid-column:span 4;border-radius:var(--bt-r);padding:22px 24px;min-width:0;
177
+ background:color-mix(in srgb,currentColor 3%,transparent);display:flex;flex-direction:column;gap:14px;
178
+ transition:transform .18s ease,box-shadow .18s ease,background .18s ease}
179
+ .bt-card:hover{transform:translateY(-2px);box-shadow:0 12px 32px rgba(0,0,0,.08)}
180
+ .bt-card[data-kind="skill"]{background:color-mix(in srgb,var(--bt-accent) 4%,transparent)}
181
+ .bt-card[data-kind="builtin"]{background:color-mix(in srgb,currentColor 2%,transparent)}
182
+ .bt-card--featured{grid-column:span 12;background:color-mix(in srgb,var(--bt-accent) 8%,transparent)}
183
+ .bt-card--featured .bt-name{font-size:24px;letter-spacing:-.02em}
184
+ .bt-card--featured .bt-glyph{width:46px;height:46px;border-radius:14px;font-size:18px}
185
+ .bt-card--featured .bt-what{font-size:16px;-webkit-line-clamp:4}
186
+ .bt-cardhead{display:flex;align-items:flex-start;gap:12px;min-width:0}
187
+ .bt-glyph{flex:none;width:38px;height:38px;border-radius:12px;display:grid;place-items:center;
188
+ background:color-mix(in srgb,var(--bt-accent) 14%,transparent);color:var(--bt-accent);font-size:15px;font-weight:600}
189
+ .bt-card[data-kind="builtin"] .bt-glyph{background:color-mix(in srgb,currentColor 8%,transparent);color:var(--bt-muted)}
190
+ .bt-titles{display:flex;flex-direction:column;gap:2px;min-width:0}
191
+ .bt-name{font-size:18px;font-weight:600;line-height:1.3;letter-spacing:-.015em;overflow-wrap:anywhere;
192
+ display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
193
+ .bt-meta{font-size:11.5px;color:var(--bt-muted);display:flex;gap:6px;flex-wrap:wrap;align-items:center}
194
+ .bt-state{display:inline-flex;align-items:center;gap:5px}
195
+ .bt-statedot{width:5px;height:5px;border-radius:50%;background:var(--bt-accent)}
196
+ .bt-state[data-state="off"]{color:color-mix(in srgb,currentColor 55%,transparent)}
197
+ .bt-state[data-state="off"] .bt-statedot{background:var(--bt-line)}
198
+ .bt-fact{display:flex;flex-direction:column;gap:4px}
199
+ .bt-label{font-size:10.5px;letter-spacing:.12em;text-transform:uppercase;color:var(--bt-muted)}
200
+ .bt-what{margin:0;font-size:15px;line-height:1.65;overflow-wrap:anywhere;
201
+ display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden}
202
+ .bt-when{margin:0;font-size:13.5px;line-height:1.6;color:var(--bt-muted);overflow-wrap:anywhere}
203
+ .bt-toggle{display:inline-flex;align-items:center;gap:6px;align-self:flex-start;border:0;background:none;padding:0;
204
+ font:inherit;font-size:12.5px;font-weight:500;color:var(--bt-accent);cursor:pointer;line-height:1.5}
205
+ .bt-toggle:hover{text-decoration:underline;text-underline-offset:3px}
206
+ .bt-toggle svg{transition:transform .18s ease;flex:none}
207
+ .bt-toggle[aria-expanded="true"] svg{transform:rotate(90deg)}
208
+ .bt-how{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:8px;font-size:13.5px;line-height:1.6}
209
+ .bt-how li{display:flex;gap:8px;align-items:flex-start}
210
+ .bt-how li::before{content:"";flex:none;width:5px;height:5px;margin-top:.62em;border-radius:2px;
211
+ background:color-mix(in srgb,var(--bt-accent) 60%,transparent)}
212
+ .bt-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:auto;
213
+ padding-top:12px;border-top:1px solid var(--bt-line)}
214
+ .bt-actions .bt-toggle{margin-top:0}
215
+ .bt-switch{display:inline-flex;align-items:center;gap:8px;border:0;background:none;padding:0;font:inherit;
216
+ font-size:12px;color:var(--bt-muted);cursor:pointer}
217
+ .bt-track{position:relative;width:32px;height:18px;border-radius:999px;background:var(--bt-line);transition:background .18s ease}
218
+ .bt-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:#fff;
219
+ box-shadow:0 1px 2px rgba(0,0,0,.25);transition:transform .18s ease}
220
+ .bt-switch[aria-checked="true"] .bt-track{background:var(--bt-accent)}
221
+ .bt-switch[aria-checked="true"] .bt-knob{transform:translateX(14px)}
222
+ .bt-link{appearance:none;border:0;background:none;padding:0;font:inherit;font-size:12px;color:var(--bt-accent);cursor:pointer}
223
+ .bt-link:hover{text-decoration:underline;text-underline-offset:3px}
224
+ .bt-link[data-tone="danger"]{color:var(--dsw-alias-state-error-primary,#b42318)}
225
+ .bt-readonly{font-size:11.5px;color:var(--bt-muted)}
226
+ .bt-path{display:flex;gap:8px;align-items:baseline;padding-top:10px;border-top:1px solid var(--bt-line);
227
+ font-size:11px;color:var(--bt-muted);min-width:0}
228
+ .bt-pathlabel{flex:none;font-size:10px;letter-spacing:.1em;text-transform:uppercase}
229
+ .bt-path code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;min-width:0;
230
+ white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
231
+ .bt-empty{padding:56px 4px;font-size:14px;color:var(--bt-muted);display:flex;flex-wrap:wrap;gap:16px;align-items:center}
232
+ .bt-notice{border-radius:14px;padding:16px 18px;margin:0 0 24px;font-size:13px;line-height:1.7;
233
+ background:color-mix(in srgb,currentColor 3%,transparent);color:var(--bt-muted)}
234
+ .bt-notice[data-tone="error"]{color:var(--dsw-alias-state-error-primary,#b42318);
235
+ background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#b42318) 7%,transparent)}
236
+ .bt-toolbar2{display:flex;flex-wrap:wrap;gap:14px;align-items:center;margin:32px 0 0}
237
+ .bt-input{flex:1 1 240px;min-width:180px;padding:11px 16px;border-radius:14px;font:inherit;font-size:14px;
238
+ border:1px solid var(--bt-line);background:color-mix(in srgb,currentColor 2%,transparent);color:inherit;outline:none;
239
+ transition:border-color .18s ease,box-shadow .18s ease}
240
+ .bt-input::placeholder{color:var(--bt-muted)}
241
+ .bt-input:focus{border-color:var(--bt-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--bt-accent) 18%,transparent)}
242
+ .bt-chips{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
243
+ .bt-chip{appearance:none;border:1px solid transparent;border-radius:10px;padding:6px 12px;background:none;
244
+ font:inherit;font-size:12.5px;color:var(--bt-muted);cursor:pointer}
245
+ .bt-chip:hover{background:color-mix(in srgb,currentColor 5%,transparent);color:var(--bt-ink)}
246
+ .bt-chip[data-on="true"]{background:color-mix(in srgb,var(--bt-accent) 12%,transparent);color:var(--bt-accent)}
247
+ .bt-count{font-size:11.5px;color:var(--bt-muted);font-variant-numeric:tabular-nums;margin-left:auto}
248
+ .bt-foot{margin-top:72px;padding-top:20px;border-top:1px solid var(--bt-line);font-size:11.5px;line-height:1.9;color:var(--bt-muted)}
249
+ .bt-modal{position:fixed;inset:0;z-index:60;display:grid;place-items:center;padding:24px;
250
+ background:rgba(0,0,0,.32)}
251
+ .bt-panel{width:min(720px,100%);max-height:min(84vh,760px);overflow:auto;border-radius:22px;padding:26px;
252
+ background:var(--dsw-alias-bg-primary,#fff);color:var(--bt-ink);box-shadow:0 24px 80px rgba(0,0,0,.28);
253
+ display:flex;flex-direction:column;gap:14px}
254
+ .bt-paneltitle{font-size:20px;font-weight:600;letter-spacing:-.02em}
255
+ .bt-field{display:flex;flex-direction:column;gap:6px}
256
+ .bt-field label{font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--bt-muted)}
257
+ .bt-field input,.bt-field select,.bt-field textarea{width:100%;padding:10px 14px;border-radius:12px;font:inherit;
258
+ font-size:13.5px;border:1px solid var(--bt-line);background:color-mix(in srgb,currentColor 2%,transparent);
259
+ color:inherit;outline:none}
260
+ .bt-field textarea{min-height:220px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;
261
+ font-size:12.5px;line-height:1.6}
262
+ .bt-field input:focus,.bt-field select:focus,.bt-field textarea:focus{border-color:var(--bt-accent);
263
+ box-shadow:0 0 0 3px color-mix(in srgb,var(--bt-accent) 16%,transparent)}
264
+ .bt-field input:disabled{opacity:.6}
265
+ .bt-panelrow{display:flex;align-items:center;gap:10px;margin-top:4px}
266
+ .bt-panelrow .bt-cta{margin-left:0}
267
+ .bt-secondary{appearance:none;border:1px solid var(--bt-line);background:none;border-radius:14px;padding:9px 16px;
268
+ font:inherit;font-size:13px;color:var(--bt-ink);cursor:pointer}
269
+ .bt-secondary:hover{background:color-mix(in srgb,currentColor 5%,transparent)}
270
+ .bt-danger{appearance:none;border:0;background:var(--dsw-alias-state-error-primary,#b42318);border-radius:14px;
271
+ padding:9px 16px;font:inherit;font-size:13px;color:#fff;cursor:pointer}
272
+ .bt-err{color:var(--dsw-alias-state-error-primary,#b42318);font-size:12.5px}
273
+ .bt-hintmuted{font-size:11.5px;color:var(--bt-muted)}
274
+ @media (max-width:1100px){.bt-hero{grid-column:span 12}.bt-stats{grid-column:span 12}.bt-card{grid-column:span 6}}
275
+ @media (max-width:820px){.dshinv{padding:24px 20px 64px}.dshinv h1{font-size:30px}
276
+ .bt-card{grid-column:span 12}.bt-guidegrid{grid-template-columns:1fr}.bt-sec{margin-top:48px}}
277
+ `;
278
+
279
+ function InventoryIcon() {
280
+ return h('svg', {
281
+ width: 16, height: 16, viewBox: '0 0 16 16', 'aria-hidden': true,
282
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1.2
283
+ },
284
+ h('rect', { x: 1.6, y: 2.4, width: 12.8, height: 3.2, rx: 1 }),
285
+ h('rect', { x: 1.6, y: 6.4, width: 12.8, height: 3.2, rx: 1 }),
286
+ h('rect', { x: 1.6, y: 10.4, width: 12.8, height: 3.2, rx: 1 }));
287
+ }
288
+
289
+ function Chevron() {
290
+ return h('svg', { width: 11, height: 11, viewBox: '0 0 12 12', 'aria-hidden': true, fill: 'none' },
291
+ h('path', { d: 'M4.5 2.5 8 6l-3.5 3.5', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }));
292
+ }
293
+
294
+ function itemKey(item) {
295
+ return item.kind + ':' + item.name;
296
+ }
297
+
298
+ function SkillEditor({ dialog, onClose, onSaved }) {
299
+ const editing = dialog.mode === 'edit';
300
+ const [name, setName] = React.useState(editing ? dialog.skill.name : '');
301
+ const [description, setDescription] = React.useState(editing ? (dialog.skill.description || '') : '');
302
+ const [whenToUse, setWhenToUse] = React.useState(editing ? (dialog.skill.whenToUse || '') : '');
303
+ const [body, setBody] = React.useState('');
304
+ const [root, setRoot] = React.useState(dialog.roots[0] ? dialog.roots[0].id : '');
305
+ const [busy, setBusy] = React.useState(false);
306
+ const [failure, setFailure] = React.useState('');
307
+ const [loaded, setLoaded] = React.useState(!editing);
308
+
309
+ React.useEffect(() => {
310
+ if (!editing) return undefined;
311
+ let alive = true;
312
+ fetch('/api/dsh-inventory/skill?path=' + encodeURIComponent(dialog.skill.path), { headers: { accept: 'application/json' } })
313
+ .then((response) => response.json().then((json) => {
314
+ if (!response.ok || (json && json.error)) throw new Error((json && json.error) || 'HTTP ' + response.status);
315
+ return json;
316
+ }))
317
+ .then((json) => {
318
+ if (!alive) return;
319
+ setDescription(json.description || '');
320
+ setWhenToUse(json.whenToUse || '');
321
+ setBody(json.body || '');
322
+ setLoaded(true);
323
+ })
324
+ .catch((cause) => {
325
+ if (alive) setFailure(cause && cause.message ? cause.message : String(cause));
326
+ });
327
+ return () => {
328
+ alive = false;
329
+ };
330
+ }, [dialog.skill, editing]);
331
+
332
+ const submit = () => {
333
+ setBusy(true);
334
+ setFailure('');
335
+ const payload = editing
336
+ ? { path: dialog.skill.path, description, whenToUse, body }
337
+ : { name, description, whenToUse, body, root };
338
+ postJson(SAVE_API, payload)
339
+ .then(() => onSaved())
340
+ .catch((cause) => setFailure(cause && cause.message ? cause.message : String(cause)))
341
+ .finally(() => setBusy(false));
342
+ };
343
+
344
+ return h('div', { className: 'bt-modal', role: 'dialog', 'aria-modal': 'true', onClick: onClose },
345
+ h('div', { className: 'bt-panel', onClick: (event) => event.stopPropagation() },
346
+ h('div', { className: 'bt-paneltitle' }, editing ? '编辑技能 · ' + dialog.skill.name : '新建技能'),
347
+ editing
348
+ ? h('div', { className: 'bt-hintmuted' }, '文件:' + dialog.skill.path)
349
+ : null,
350
+ !editing
351
+ ? h('div', { className: 'bt-field' },
352
+ h('label', null, '技能名(小写字母、数字、连字符)'),
353
+ h('input', {
354
+ value: name,
355
+ placeholder: 'my-skill',
356
+ onChange: (event) => setName(event.target.value.trim())
357
+ }))
358
+ : null,
359
+ h('div', { className: 'bt-field' },
360
+ h('label', null, '一句话说明:它是干嘛的'),
361
+ h('input', {
362
+ value: description,
363
+ placeholder: '例如:把一段回答做成一页可分享的说明页',
364
+ onChange: (event) => setDescription(event.target.value)
365
+ })),
366
+ h('div', { className: 'bt-field' },
367
+ h('label', null, '什么时候用'),
368
+ h('input', {
369
+ value: whenToUse,
370
+ placeholder: '例如:需要把复杂结论讲清楚时',
371
+ onChange: (event) => setWhenToUse(event.target.value)
372
+ })),
373
+ h('div', { className: 'bt-field' },
374
+ h('label', null, '正文(Markdown)'),
375
+ h('textarea', {
376
+ value: body,
377
+ placeholder: loaded ? '# 技能名\n\n写清楚什么时候用、怎么做。' : '正在读取…',
378
+ disabled: !loaded,
379
+ onChange: (event) => setBody(event.target.value)
380
+ })),
381
+ !editing
382
+ ? h('div', { className: 'bt-field' },
383
+ h('label', null, '保存到'),
384
+ h('select', { value: root, onChange: (event) => setRoot(event.target.value) },
385
+ dialog.roots.map((option) => h('option', { key: option.id, value: option.id }, option.label + ' · ' + option.dir))))
386
+ : null,
387
+ failure ? h('div', { className: 'bt-err', role: 'alert' }, failure) : null,
388
+ h('div', { className: 'bt-panelrow' },
389
+ h('button', { type: 'button', className: 'bt-cta', disabled: busy || !loaded, onClick: submit },
390
+ busy ? '保存中…' : (editing ? '保存修改' : '创建技能')),
391
+ h('button', { type: 'button', className: 'bt-secondary', onClick: onClose }, '取消')));
392
+ }
393
+
394
+ function fileToBase64(file) {
395
+ return file.arrayBuffer().then((buffer) => {
396
+ const bytes = new Uint8Array(buffer);
397
+ let binary = '';
398
+ const chunk = 0x8000;
399
+ for (let index = 0; index < bytes.length; index += chunk) {
400
+ binary += String.fromCharCode.apply(null, bytes.subarray(index, index + chunk));
401
+ }
402
+ return btoa(binary);
403
+ });
404
+ }
405
+
406
+ function ImportDialog({ roots, onClose, onDone }) {
407
+ const [root, setRoot] = React.useState(roots[0] ? roots[0].id : '');
408
+ const [kind, setKind] = React.useState('directory');
409
+ const [dir, setDir] = React.useState('');
410
+ const [file, setFile] = React.useState(null);
411
+ const [busy, setBusy] = React.useState(false);
412
+ const [failure, setFailure] = React.useState('');
413
+ const [result, setResult] = React.useState(null);
414
+
415
+ const submit = () => {
416
+ setBusy(true);
417
+ setFailure('');
418
+ const task = kind === 'directory'
419
+ ? postJson(IMPORT_API, { kind: 'directory', path: dir, root })
420
+ : (file === null
421
+ ? Promise.reject(new Error('请先选择一个 zip 文件'))
422
+ : fileToBase64(file).then((data) => postJson(IMPORT_API, { kind: 'archive', data: data, root: root })));
423
+ task
424
+ .then((json) => {
425
+ setResult(json);
426
+ if (onDone) onDone(json);
427
+ })
428
+ .catch((cause) => setFailure(cause && cause.message ? cause.message : String(cause)))
429
+ .finally(() => setBusy(false));
430
+ };
431
+
432
+ return h('div', { className: 'bt-modal', role: 'dialog', 'aria-modal': 'true', onClick: onClose },
433
+ h('div', { className: 'bt-panel', onClick: (event) => event.stopPropagation() },
434
+ h('div', { className: 'bt-paneltitle' }, '导入技能'),
435
+ h('div', { className: 'bt-hintmuted' },
436
+ '每个技能是一个含 SKILL.md 的文件夹;只新建,不覆盖同名技能。'),
437
+ h('div', { className: 'bt-field' },
438
+ h('label', null, '来源'),
439
+ h('select', { value: kind, onChange: (event) => setKind(event.target.value) },
440
+ h('option', { value: 'directory' }, '本机目录(含 SKILL.md 的文件夹)'),
441
+ h('option', { value: 'archive' }, 'zip 压缩包'))),
442
+ kind === 'directory'
443
+ ? h('div', { className: 'bt-field' },
444
+ h('label', null, '目录路径'),
445
+ h('input', {
446
+ value: dir,
447
+ placeholder: 'E:\\skills-to-import',
448
+ onChange: (event) => setDir(event.target.value)
449
+ }))
450
+ : h('div', { className: 'bt-field' },
451
+ h('label', null, 'zip 文件(≤ 20 MB)'),
452
+ h('input', {
453
+ type: 'file',
454
+ accept: '.zip',
455
+ onChange: (event) => setFile(event.target.files && event.target.files[0] ? event.target.files[0] : null)
456
+ })),
457
+ h('div', { className: 'bt-field' },
458
+ h('label', null, '导入到'),
459
+ h('select', { value: root, onChange: (event) => setRoot(event.target.value) },
460
+ roots.map((option) => h('option', { key: option.id, value: option.id }, option.label + ' · ' + option.dir)))),
461
+ failure ? h('div', { className: 'bt-err', role: 'alert' }, failure) : null,
462
+ result
463
+ ? h('div', { className: 'bt-hintmuted' },
464
+ '成功 ' + result.imported.length + ' 个' +
465
+ (result.skipped.length > 0 ? ',跳过 ' + result.skipped.length + ' 个:' +
466
+ result.skipped.map((entry) => entry.name + '(' + entry.reason + ')').join('、') : '') +
467
+ (result.imported.length > 0 ? '。已导入:' + result.imported.join('、') : ''))
468
+ : null,
469
+ h('div', { className: 'bt-panelrow' },
470
+ h('button', { type: 'button', className: 'bt-cta', disabled: busy, onClick: submit },
471
+ busy ? '导入中…' : '开始导入'),
472
+ h('button', { type: 'button', className: 'bt-secondary', onClick: onClose }, '关闭')));
473
+ }
474
+
475
+ function Card({ item, featured, open, onToggle, actions }) {
476
+ const key = itemKey(item);
477
+ const steps = item.how || [];
478
+ const expanded = !!open;
479
+ const children = [
480
+ h('div', { className: 'bt-cardhead', key: 'head' },
481
+ h('span', { className: 'bt-glyph' }, glyphOf(item)),
482
+ h('div', { className: 'bt-titles' },
483
+ h('span', { className: 'bt-name' }, item.name),
484
+ h('span', { className: 'bt-meta' },
485
+ item.ver ? h('span', null, 'v' + item.ver) : null,
486
+ h('span', { className: 'bt-state', 'data-state': item.state || 'on' },
487
+ h('span', { className: 'bt-statedot' }),
488
+ item.stateText || (item.state === 'off' ? '已停用' : '已启用')),
489
+ item.tag ? h('span', null, '·') : null,
490
+ item.tag ? h('span', null, item.tag) : null,
491
+ h('span', null, '· ' + (KIND_LABEL[item.kind] || '条目'))))),
492
+ h('div', { className: 'bt-fact', key: 'what' },
493
+ h('span', { className: 'bt-label' }, '它是干嘛的'),
494
+ h('p', { className: 'bt-what', title: item.what }, item.what)),
495
+ item.when
496
+ ? h('div', { className: 'bt-fact', key: 'when' },
497
+ h('span', { className: 'bt-label' }, '什么时候用'),
498
+ h('p', { className: 'bt-when' }, item.when))
499
+ : null,
500
+ steps.length
501
+ ? h('button', {
502
+ key: 'toggle',
503
+ type: 'button',
504
+ className: 'bt-toggle',
505
+ 'aria-expanded': expanded ? 'true' : 'false',
506
+ 'aria-controls': 'bt-how-' + key,
507
+ onClick: () => onToggle(key)
508
+ },
509
+ h(Chevron, null),
510
+ '怎么用',
511
+ h('span', null, '· ' + steps.length + ' 步'))
512
+ : null,
513
+ expanded && steps.length
514
+ ? h('ul', { className: 'bt-how', key: 'how', id: 'bt-how-' + key },
515
+ steps.map((line, i) => h('li', { key: i }, line)))
516
+ : null,
517
+ actions
518
+ ? h('div', { className: 'bt-actions', key: 'actions' }, actions)
519
+ : null,
520
+ item.path
521
+ ? h('div', { className: 'bt-path', key: 'path', title: item.path },
522
+ h('span', { className: 'bt-pathlabel' }, '路径'),
523
+ h('code', null, item.path))
524
+ : null
525
+ ];
526
+ return h('article', {
527
+ className: 'bt-card' + (featured ? ' bt-card--featured' : ''),
528
+ 'data-kind': item.kind,
529
+ key: key
530
+ }, children);
531
+ }
532
+
533
+ function matches(item, q, filter) {
534
+ if (filter !== 'all' && item.kind !== filter) return false;
535
+ if (!q) return true;
536
+ const hay = (item.name + ' ' + (item.ver || '') + ' ' + (item.tag || '') + ' ' +
537
+ (item.stateText || '') + ' ' + item.what + ' ' + (item.when || '') + ' ' +
538
+ (item.how || []).join(' ') + ' ' + (item.path || '')).toLowerCase();
539
+ return hay.indexOf(q) !== -1;
540
+ }
541
+
542
+ function toItems(payload) {
543
+ const plugins = (payload.plugins || []).map((plugin) => {
544
+ const note = PLUGIN_NOTES[plugin.name] || {};
545
+ return {
546
+ kind: 'plugin',
547
+ name: plugin.name,
548
+ ver: plugin.version || '',
549
+ tag: '',
550
+ state: plugin.enabled ? 'on' : 'off',
551
+ stateText: plugin.enabled ? '已启用' : '已停用',
552
+ what: note.what || plugin.summary || plugin.description || FALLBACK_PLUGIN_WHAT,
553
+ when: note.when || '',
554
+ how: note.how || FALLBACK_PLUGIN_HOW,
555
+ path: plugin.path || ''
556
+ };
557
+ });
558
+
559
+ const skills = (payload.skills || []).map((skill) => {
560
+ const note = SKILL_NOTES[skill.name] || {};
561
+ return {
562
+ kind: 'skill',
563
+ name: skill.name,
564
+ ver: '',
565
+ tag: sourceLabel(skill.source),
566
+ state: skill.modelInvocable ? 'on' : 'off',
567
+ stateText: skill.modelInvocable ? '可自动调用' : '仅手动',
568
+ what: note.what || skill.description || skill.whenToUse || FALLBACK_SKILL_WHAT,
569
+ when: note.when || skill.whenToUse || '',
570
+ how: note.how || FALLBACK_SKILL_HOW,
571
+ path: skill.path || '',
572
+ writable: skill.writable === true,
573
+ raw: skill
574
+ };
575
+ });
576
+
577
+ const bundles = (payload.bundles || []).map((bundle) => ({
578
+ kind: 'builtin',
579
+ name: bundle.name,
580
+ ver: bundle.version || '',
581
+ tag: '随 DSH 自带',
582
+ state: 'on',
583
+ stateText: '已加载',
584
+ what: 'DSH 自带的 bundle,构成 DSH 本身(界面、核心循环等),不需要单独安装,也不能卸载。',
585
+ when: '想搞清楚 DSH 的某个底层能力来自哪里的时候。',
586
+ how: ['自动加载,无需操作', '要改它的行为请用插件或 Profile patch'],
587
+ path: ''
588
+ }));
589
+
590
+ return { plugins, skills, bundles };
591
+ }
592
+
593
+ const SECTIONS = [
594
+ { kind: 'plugin', title: '插件', sub: '用户安装,随 Profile 加载' },
595
+ { kind: 'skill', title: 'SKILL', sub: '命中任务时自动加载' },
596
+ { kind: 'builtin', title: '内置 bundle', sub: '构成 DSH 本体' }
597
+ ];
598
+
599
+ function Panel() {
600
+ const [payload, setPayload] = React.useState(null);
601
+ const [error, setError] = React.useState('');
602
+ const [loading, setLoading] = React.useState(true);
603
+ const [updated, setUpdated] = React.useState('');
604
+ const [query, setQuery] = React.useState('');
605
+ const [filter, setFilter] = React.useState('all');
606
+ const [open, setOpen] = React.useState({});
607
+ const [allOpen, setAllOpen] = React.useState(false);
608
+ const [guideOpen, setGuideOpen] = React.useState(true);
609
+ const [dialog, setDialog] = React.useState(null);
610
+
611
+ const load = React.useCallback((quiet) => {
612
+ if (!quiet) setLoading(true);
613
+ return fetch(API, { headers: { accept: 'application/json' } })
614
+ .then((response) => {
615
+ if (!response.ok) throw new Error('HTTP ' + response.status);
616
+ return response.json();
617
+ })
618
+ .then((json) => {
619
+ if (json && json.error) throw new Error(String(json.error));
620
+ setPayload(json);
621
+ setError('');
622
+ setUpdated(clock(json && json.generatedAt));
623
+ })
624
+ .catch((cause) => setError(cause && cause.message ? cause.message : String(cause)))
625
+ .finally(() => setLoading(false));
626
+ }, []);
627
+
628
+ React.useEffect(() => {
629
+ load(false);
630
+ }, [load]);
631
+
632
+ React.useEffect(() => {
633
+ const onFocus = () => load(true);
634
+ const onVisibility = () => {
635
+ if (document.visibilityState === 'visible') load(true);
636
+ };
637
+ window.addEventListener('focus', onFocus);
638
+ document.addEventListener('visibilitychange', onVisibility);
639
+ const timer = setInterval(() => {
640
+ if (document.visibilityState === 'visible') load(true);
641
+ }, 30000);
642
+ return () => {
643
+ window.removeEventListener('focus', onFocus);
644
+ document.removeEventListener('visibilitychange', onVisibility);
645
+ clearInterval(timer);
646
+ };
647
+ }, [load]);
648
+
649
+ const items = toItems(payload || {});
650
+ const all = items.plugins.concat(items.skills, items.bundles);
651
+ const roots = (payload && Array.isArray(payload.roots) ? payload.roots : []).filter((root) => root.dir);
652
+
653
+ const q = query.trim().toLowerCase();
654
+ const visibleTotal = all.filter((item) => matches(item, q, filter)).length;
655
+ const anyOpen = allOpen || Object.keys(open).some((key) => open[key]);
656
+
657
+ const toggle = (key) => {
658
+ if (allOpen) {
659
+ const next = {};
660
+ for (const item of all) {
661
+ const other = itemKey(item);
662
+ if (other !== key) next[other] = true;
663
+ }
664
+ setAllOpen(false);
665
+ setOpen(next);
666
+ return;
667
+ }
668
+ setOpen((prev) => {
669
+ const next = Object.assign({}, prev);
670
+ if (next[key]) delete next[key];
671
+ else next[key] = true;
672
+ return next;
673
+ });
674
+ };
675
+
676
+ const toggleAll = () => {
677
+ if (anyOpen) {
678
+ setAllOpen(false);
679
+ setOpen({});
680
+ } else {
681
+ setAllOpen(true);
682
+ setOpen({});
683
+ }
684
+ };
685
+
686
+ const toggleSkill = (item) => {
687
+ postJson(TOGGLE_API, { path: item.path, enabled: item.state === 'off' })
688
+ .then(() => load(true))
689
+ .catch((cause) => setError(cause && cause.message ? cause.message : String(cause)));
690
+ };
691
+
692
+ const removeSkill = (item) => {
693
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function') {
694
+ const ok = window.confirm('把「' + item.name + '」移到回收站(.trash)?可以手动移回来。');
695
+ if (!ok) return;
696
+ }
697
+ postJson(DELETE_API, { path: item.path })
698
+ .then(() => load(true))
699
+ .catch((cause) => setError(cause && cause.message ? cause.message : String(cause)));
700
+ };
701
+
702
+ const chips = [['all', '全部']].concat(
703
+ SECTIONS.map((section) => [section.kind, KIND_LABEL[section.kind]])
704
+ ).map(([value, text]) =>
705
+ h('button', {
706
+ key: value,
707
+ type: 'button',
708
+ className: 'bt-chip',
709
+ 'data-on': filter === value ? 'true' : 'false',
710
+ 'aria-pressed': filter === value ? 'true' : 'false',
711
+ onClick: () => setFilter(value === filter && value !== 'all' ? 'all' : value)
712
+ }, text));
713
+
714
+ const countTile = h('section', { className: 'bt-tile bt-stats', key: 'stats' },
715
+ h('span', { className: 'bt-eyebrow' }, '本机概览'),
716
+ h('div', { className: 'bt-statrow' },
717
+ h('div', { className: 'bt-stat' }, h('b', null, String(items.plugins.length)), h('span', null, '插件')),
718
+ h('div', { className: 'bt-stat' }, h('b', null, String(items.skills.length)), h('span', null, '技能')),
719
+ h('div', { className: 'bt-stat' }, h('b', null, String(items.bundles.length)), h('span', null, '内置'))),
720
+ h('span', { className: 'bt-live' },
721
+ h('span', { className: 'bt-livedot' }),
722
+ loading ? '正在读取…' : updated ? '实时数据 · 更新于 ' + updated : '实时数据'));
723
+
724
+ const heroTile = h('section', { className: 'bt-tile bt-hero', key: 'hero' },
725
+ h('span', { className: 'bt-eyebrow' }, 'DSH · 本机插件与技能'),
726
+ h('h1', null, '插件与技能'),
727
+ h('p', { className: 'bt-deck' },
728
+ '这里回答三件事:每个插件或技能是干嘛的、什么时候用得上、具体怎么用;技能还能直接在这里启停、编辑、新建、删除。'),
729
+ h('div', { className: 'bt-toolbar' },
730
+ h('span', { className: 'bt-live' }, '数据自本机实时读取,打开面板、切回窗口时自动刷新'),
731
+ h('button', {
732
+ type: 'button',
733
+ className: 'bt-cta',
734
+ onClick: () => load(false),
735
+ title: '重新扫描本机插件与技能'
736
+ }, '刷新')));
737
+
738
+ const guideTile = h('section', { className: 'bt-tile bt-guide', key: 'guide' },
739
+ h('button', {
740
+ type: 'button',
741
+ className: 'bt-guidehead',
742
+ 'aria-expanded': guideOpen ? 'true' : 'false',
743
+ onClick: () => setGuideOpen(!guideOpen)
744
+ },
745
+ h(Chevron, null),
746
+ h('span', { className: 'bt-guidetitle' }, '新手看这里')),
747
+ guideOpen
748
+ ? h('ul', { className: 'bt-guidegrid' },
749
+ h('li', null, h('span', { className: 'bt-guidenum' }, '1'),
750
+ h('span', null, '插件是装在 DSH 里的功能,技能是助手可以调用的专门能力;两者都列在下面。')),
751
+ h('li', null, h('span', { className: 'bt-guidenum' }, '2'),
752
+ h('span', null, '每张卡先读「它是干嘛的」,再看「什么时候用」判断要不要用,最后才点「怎么用」看步骤。')),
753
+ h('li', null, h('span', { className: 'bt-guidenum' }, '3'),
754
+ h('span', null, '技能卡上有开关:关掉后模型不会自动调用它;「编辑」「删除」直接改本机 SKILL.md,删除是移到 .trash。')),
755
+ h('li', null, h('span', { className: 'bt-guidenum' }, '4'),
756
+ h('span', null, '插件装完后这里会自动更新;也可以点右上角「刷新」立刻重新扫描。')))
757
+ : null);
758
+
759
+ const bodies = [];
760
+ for (const section of SECTIONS) {
761
+ const list = items[section.kind === 'plugin' ? 'plugins' : section.kind === 'skill' ? 'skills' : 'bundles']
762
+ .filter((item) => matches(item, q, filter));
763
+ if (list.length === 0) continue;
764
+ bodies.push(h('section', { className: 'bt-sec', key: section.kind, 'data-kind': section.kind },
765
+ h('div', { className: 'bt-sechead' },
766
+ h('h2', { className: 'bt-sectitle' }, section.title),
767
+ h('span', { className: 'bt-seccount' }, String(list.length)),
768
+ section.kind === 'skill'
769
+ ? h(React.Fragment, { key: 'skill-actions' },
770
+ h('button', {
771
+ type: 'button',
772
+ className: 'bt-chip',
773
+ onClick: () => setDialog({ mode: 'create', roots: roots, skill: null })
774
+ }, '新建技能'),
775
+ h('button', {
776
+ type: 'button',
777
+ className: 'bt-chip',
778
+ onClick: () => setDialog({ mode: 'import', roots: roots })
779
+ }, '导入技能'))
780
+ : null,
781
+ h('span', { className: 'bt-secsub' }, section.sub)),
782
+ h('div', { className: 'bt-cards' },
783
+ list.map((item, index) => h(Card, {
784
+ key: itemKey(item),
785
+ item: item,
786
+ featured: index === 0,
787
+ open: allOpen || !!open[itemKey(item)],
788
+ onToggle: toggle,
789
+ actions: item.kind === 'skill' && item.writable
790
+ ? [
791
+ h('button', {
792
+ key: 'switch',
793
+ type: 'button',
794
+ className: 'bt-switch',
795
+ role: 'switch',
796
+ 'aria-checked': item.state === 'on' ? 'true' : 'false',
797
+ onClick: () => toggleSkill(item),
798
+ title: item.state === 'on' ? '关闭自动调用' : '开启自动调用'
799
+ },
800
+ h('span', { className: 'bt-track' }, h('span', { className: 'bt-knob' })),
801
+ h('span', null, item.state === 'on' ? '自动调用:开' : '自动调用:关')),
802
+ h('button', {
803
+ key: 'edit',
804
+ type: 'button',
805
+ className: 'bt-link',
806
+ onClick: () => setDialog({ mode: 'edit', skill: item, roots: roots })
807
+ }, '编辑'),
808
+ h('button', {
809
+ key: 'delete',
810
+ type: 'button',
811
+ className: 'bt-link',
812
+ 'data-tone': 'danger',
813
+ onClick: () => removeSkill(item)
814
+ }, '删除')
815
+ ]
816
+ : (item.kind === 'skill'
817
+ ? [h('span', { key: 'ro', className: 'bt-readonly' }, '插件提供 · 只读')]
818
+ : null)
819
+ })))));
820
+ }
821
+
822
+ return h('div', { className: 'dshinv' },
823
+ h('style', null, CSS),
824
+ h('div', { className: 'btgrid' }, heroTile, countTile, guideTile),
825
+ error
826
+ ? h('div', { className: 'bt-notice', 'data-tone': 'error', role: 'alert' },
827
+ '读取插件列表失败:' + error + '。点「刷新」重试;若一直失败,请完全退出 DSH 再打开一次(Host 需要重新加载插件模块)。')
828
+ : null,
829
+ h('div', { className: 'bt-toolbar2' },
830
+ h('input', {
831
+ className: 'bt-input',
832
+ type: 'search',
833
+ value: query,
834
+ placeholder: '搜索名称、作用或关键词(Esc 清空)',
835
+ 'aria-label': '搜索插件与技能',
836
+ onChange: (event) => setQuery(event.target.value),
837
+ onKeyDown: (event) => {
838
+ if (event.key === 'Escape') setQuery('');
839
+ }
840
+ }),
841
+ h('div', { className: 'bt-chips' },
842
+ chips,
843
+ h('button', { type: 'button', className: 'bt-chip', onClick: toggleAll },
844
+ anyOpen ? '收起用法' : '展开用法')),
845
+ h('span', { className: 'bt-count', role: 'status', 'aria-live': 'polite' },
846
+ visibleTotal + ' / ' + all.length + ' 条')),
847
+ bodies.length
848
+ ? h('div', null, bodies)
849
+ : loading && !payload
850
+ ? h('div', { className: 'bt-notice' }, '正在读取本机的插件与技能…')
851
+ : h('div', { className: 'bt-empty', role: 'status' },
852
+ '没有匹配的条目。',
853
+ q ? h('button', { type: 'button', className: 'bt-chip', onClick: () => setQuery('') }, '清空搜索') : null,
854
+ filter !== 'all' ? h('button', { type: 'button', className: 'bt-chip', onClick: () => setFilter('all') }, '显示全部类型') : null),
855
+ h('div', { className: 'bt-foot' },
856
+ '数据来自本机实时扫描:/api/dsh-inventory/list;技能的启停/编辑/新建/删除通过同一插件的本机接口完成。',
857
+ h('br'),
858
+ '删除是移入技能目录下的 .trash,可以手动还原;编辑只允许修改本机技能目录里已有的技能。'),
859
+ dialog && dialog.mode === 'import'
860
+ ? h(ImportDialog, {
861
+ roots: dialog.roots,
862
+ onClose: () => setDialog(null),
863
+ onDone: () => load(true)
864
+ })
865
+ : dialog
866
+ ? h(SkillEditor, {
867
+ dialog: dialog,
868
+ onClose: () => setDialog(null),
869
+ onSaved: () => {
870
+ setDialog(null);
871
+ load(true);
872
+ }
873
+ })
874
+ : null);
875
+ }
876
+
877
+ return {
878
+ inject: ['slots'],
879
+ apply(ctx) {
880
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
881
+ name: 'sidebar.panellist',
882
+ id: 'dsh-inventory-panel',
883
+ order: 60,
884
+ label: () => '插件与技能'
885
+ }, InventoryIcon));
886
+
887
+ ctx.slots.inject('main', () => ctx.slots.register({
888
+ name: 'main',
889
+ key: 'dsh-inventory-panel'
890
+ }, Panel));
891
+ }
892
+ };
893
+ }
894
+ });