dsh-skillmart 0.0.0-stage → 0.3.1

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,978 @@
1
+ /**
2
+ * 技能市场 —— Client 半边。
3
+ *
4
+ * 左侧栏放一个入口,打开了就在主区域显示技能列表:按分类和关键词浏览 SkillHub,
5
+ * 卡片展示图标、名称、简介、作者与下载量,点一下装进本机技能目录。
6
+ * 所有取数与写盘都走本包 Host 半边注册的 /local-view-25e475c1/skillhub 路由。
7
+ */
8
+ window.__ModuleLoader__.load({
9
+ id: '@dsh-local/view-25e475c1-3ab1-47c1-bb94-8947498c3bed',
10
+ factory: (require) => {
11
+ var module = { exports: {} }
12
+ var exports = module.exports
13
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
14
+
15
+ const React = require('react')
16
+ const h = React.createElement
17
+
18
+ const NS = 'skillMarketPanel'
19
+ const PANEL_ID = 'skill-market'
20
+ const PANEL_ORDER = 5
21
+ const API = '/local-view-25e475c1/skillhub'
22
+ const PAGE_SIZE = 24
23
+
24
+ const ZH = {
25
+ 'panel.title': '技能市场',
26
+ 'panel.subtitle': '浏览 SkillHub 上的技能,点一下就装进本机技能目录',
27
+ 'search.placeholder': '搜技能名称或用途,回车搜索',
28
+ 'search.action': '搜索',
29
+ 'category.all': '全部',
30
+ 'metric.installed': '已装 {count}',
31
+ 'action.refresh': '刷新',
32
+ 'action.install': '安装',
33
+ 'action.installing': '安装中…',
34
+ 'action.installed': '已安装',
35
+ 'action.uninstall': '卸载',
36
+ 'action.uninstalling': '卸载中…',
37
+ 'action.confirmUninstall': '再点一下确认卸载',
38
+ 'action.uninstallHint': '把这个技能从本机技能目录删掉',
39
+ 'action.tryIt': '去试试',
40
+ 'action.close': '关闭',
41
+ 'detail.overview': '概述',
42
+ 'detail.version': '版本 {version}',
43
+ 'detail.downloadsUnknown': '下载量未知',
44
+ 'detail.categoryUnknown': '未分类',
45
+ 'detail.noContent': '本机没有这个技能的说明文件(SKILL.md)。',
46
+ 'notice.copied': '已复制「使用 {name} 技能:」,去对话里粘贴,再补上你要做的事',
47
+ 'notice.copyFailed': '复制没成功,请在新对话里直接说「用 {name} 技能帮我…」',
48
+ 'meta.downloads': '{count} 次下载',
49
+ 'meta.author': '作者 {name}',
50
+ 'meta.localAuthor': '本机',
51
+ 'state.loading': '正在读取技能列表…',
52
+ 'state.empty': '没有找到匹配的技能,换个关键词或分类试试',
53
+ 'state.total': '共 {count} 个技能',
54
+ 'state.installedTotal': '共 {count} 个已装技能',
55
+ 'state.installedAt': '已装于 {time}',
56
+ 'state.noInstalled': '还没有装过技能,点回全部挑一个试试',
57
+ 'action.toggleInstalled': '点一下只看已装,再点回全部',
58
+ 'notice.installed': '已装好「{name}」',
59
+ 'notice.uninstalled': '已卸载「{name}」',
60
+ 'notice.uninstallFailed': '卸载没成功:{message}',
61
+ 'notice.installFailed': '安装没成功:{message}',
62
+ 'notice.dismiss': '知道了',
63
+ 'pager.prev': '上一页',
64
+ 'pager.next': '下一页',
65
+ 'pager.info': '第 {page} / {pages} 页',
66
+ 'error.list': '技能列表没取回来:{message}',
67
+ 'error.categories': '分类没取回来:{message}',
68
+ 'error.installed': '本机已装清单没读出来:{message}',
69
+ }
70
+
71
+ const EN = {
72
+ 'panel.title': 'Skill Market',
73
+ 'panel.subtitle': 'Browse skills on SkillHub and install one into the local skills folder',
74
+ 'search.placeholder': 'Search skills, press Enter',
75
+ 'search.action': 'Search',
76
+ 'category.all': 'All',
77
+ 'metric.installed': '{count} installed',
78
+ 'action.refresh': 'Refresh',
79
+ 'action.install': 'Install',
80
+ 'action.installing': 'Installing…',
81
+ 'action.installed': 'Installed',
82
+ 'action.uninstall': 'Remove',
83
+ 'action.uninstalling': 'Removing…',
84
+ 'action.confirmUninstall': 'Click again to remove',
85
+ 'action.uninstallHint': 'Delete this skill from the local skills folder',
86
+ 'action.tryIt': 'Try it',
87
+ 'action.close': 'Close',
88
+ 'detail.overview': 'Overview',
89
+ 'detail.version': 'Version {version}',
90
+ 'detail.downloadsUnknown': 'Downloads unknown',
91
+ 'detail.categoryUnknown': 'Uncategorized',
92
+ 'detail.noContent': 'No SKILL.md for this skill on this machine.',
93
+ 'notice.copied': 'Copied the skill call phrase — paste it in a chat and add what you need',
94
+ 'notice.copyFailed': 'Copy failed — just say the skill name in a new chat',
95
+ 'meta.downloads': '{count} downloads',
96
+ 'meta.author': 'by {name}',
97
+ 'meta.localAuthor': 'local',
98
+ 'state.loading': 'Loading skills…',
99
+ 'state.empty': 'No matching skill; try another keyword or category',
100
+ 'state.total': '{count} skills',
101
+ 'state.installedTotal': '{count} installed skills',
102
+ 'state.installedAt': 'Installed {time}',
103
+ 'state.noInstalled': 'Nothing installed yet; switch back to all skills',
104
+ 'action.toggleInstalled': 'Click to show only installed, click again for all',
105
+ 'notice.installed': 'Installed “{name}”',
106
+ 'notice.uninstalled': 'Removed “{name}”',
107
+ 'notice.uninstallFailed': 'Remove failed: {message}',
108
+ 'notice.installFailed': 'Install failed: {message}',
109
+ 'notice.dismiss': 'Dismiss',
110
+ 'pager.prev': 'Previous',
111
+ 'pager.next': 'Next',
112
+ 'pager.info': 'Page {page} / {pages}',
113
+ 'error.list': 'Could not load skills: {message}',
114
+ 'error.categories': 'Could not load categories: {message}',
115
+ 'error.installed': 'Could not read installed skills: {message}',
116
+ }
117
+
118
+ function interpolate(text, vars) {
119
+ if (vars === undefined || vars === null) return text
120
+ return text.replace(/\{(\w+)\}/gu, (match, key) => {
121
+ const value = vars[key]
122
+ return value === undefined || value === null ? match : String(value)
123
+ })
124
+ }
125
+
126
+ function fallbackTranslate(key, vars) {
127
+ return interpolate(ZH[key] ?? key, vars)
128
+ }
129
+
130
+ /** 优先用宿主给的 t;拿不到真字典时退回内置中文。 */
131
+ function translate(props) {
132
+ const provided = props !== null && typeof props === 'object' ? props.t : undefined
133
+ return (key, vars) => {
134
+ if (typeof provided === 'function') {
135
+ try {
136
+ const value = provided(key, vars)
137
+ if (typeof value === 'string' && value !== '' && value !== key && value.indexOf(NS) < 0) return interpolate(value, vars)
138
+ } catch {
139
+ // 忽略,用内置字典。
140
+ }
141
+ }
142
+ return fallbackTranslate(key, vars)
143
+ }
144
+ }
145
+
146
+ function messageOf(error) {
147
+ if (error instanceof Error && error.message !== '') return error.message
148
+ return String(error)
149
+ }
150
+
151
+ function formatCount(value) {
152
+ const number = Number.isFinite(value) ? value : 0
153
+ if (number >= 100000000) return `${(number / 100000000).toFixed(1).replace(/\.0$/u, '')}亿`
154
+ if (number >= 10000) return `${(number / 10000).toFixed(1).replace(/\.0$/u, '')}万`
155
+ return String(number)
156
+ }
157
+
158
+ async function getJson(path, signal) {
159
+ const response = await fetch(path, { signal, headers: { accept: 'application/json' } })
160
+ const payload = await response.json().catch(() => null)
161
+ if (!response.ok) {
162
+ const reason = payload !== null && typeof payload === 'object' && typeof payload.error === 'string' ? payload.error : `HTTP ${response.status}`
163
+ throw new Error(reason)
164
+ }
165
+ if (payload === null || typeof payload !== 'object') throw new Error('返回内容不是 JSON')
166
+ if (payload.ok === false) throw new Error(typeof payload.error === 'string' ? payload.error : '返回失败')
167
+ return payload
168
+ }
169
+
170
+ const ICON_SIZE = 36
171
+
172
+ /** 没有图标时按名字取一个稳定的色相,字母底就不会一片灰。 */
173
+ function avatarHue(seed) {
174
+ const text = String(seed || '?')
175
+ let hash = 0
176
+ for (let index = 0; index < text.length; index += 1) {
177
+ hash = (hash * 31 + text.charCodeAt(index)) % 360
178
+ }
179
+ return hash
180
+ }
181
+
182
+ function Avatar(props) {
183
+ const { skill } = props
184
+ const initial = (skill.name || skill.slug || '?').slice(0, 1).toUpperCase()
185
+ const hue = avatarHue(skill.name || skill.slug)
186
+ return h(
187
+ 'span',
188
+ {
189
+ className: 'sm-avatar',
190
+ 'aria-hidden': 'true',
191
+ style: { '--sm-hue': String(hue) },
192
+ },
193
+ h('span', { className: 'sm-avatar-letter' }, initial),
194
+ skill.iconUrl === ''
195
+ ? null
196
+ : h('img', {
197
+ className: 'sm-avatar-img',
198
+ src: skill.iconUrl,
199
+ alt: '',
200
+ loading: 'lazy',
201
+ referrerPolicy: 'no-referrer',
202
+ onError: (event) => {
203
+ event.currentTarget.style.visibility = 'hidden'
204
+ },
205
+ }),
206
+ )
207
+ }
208
+
209
+ function DownloadGlyph() {
210
+ return h(
211
+ 'svg',
212
+ { width: 12, height: 12, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true' },
213
+ h('path', { d: 'M12 4v11' }),
214
+ h('path', { d: 'm7 11 5 5 5-5' }),
215
+ h('path', { d: 'M5 20h14' }),
216
+ )
217
+ }
218
+
219
+ function SkillCard(props) {
220
+ const { skill, installed, busy, onInstall, onUninstall, uninstalling, pendingSlug, t } = props
221
+ const isBusy = busy === skill.slug
222
+ const isInstalled = installed[skill.slug] === true
223
+ const isUninstalling = uninstalling === skill.slug
224
+ const isPending = pendingSlug === skill.slug
225
+ const rawAuthor = typeof skill.author === 'string' ? skill.author : ''
226
+ const localAuthor = t('meta.localAuthor')
227
+ const sourceTag =
228
+ rawAuthor === '' || rawAuthor === localAuthor
229
+ ? ''
230
+ : rawAuthor.replace(/^user_/, '').replace(/^org-/, '').slice(0, 8)
231
+ const action = isInstalled
232
+ ? h(
233
+ 'button',
234
+ {
235
+ type: 'button',
236
+ className: isPending ? 'sm-uninstall sm-uninstall-armed' : 'sm-uninstall',
237
+ disabled: isUninstalling,
238
+ title: t('action.uninstallHint'),
239
+ onClick: (event) => {
240
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
241
+ onUninstall(skill)
242
+ },
243
+ },
244
+ isUninstalling
245
+ ? t('action.uninstalling')
246
+ : isPending
247
+ ? t('action.confirmUninstall')
248
+ : t('action.uninstall'),
249
+ )
250
+ : h(
251
+ 'button',
252
+ {
253
+ type: 'button',
254
+ className: 'sm-install',
255
+ disabled: isBusy,
256
+ onClick: (event) => {
257
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
258
+ onInstall(skill)
259
+ },
260
+ },
261
+ isBusy ? t('action.installing') : t('action.install'),
262
+ )
263
+ return h(
264
+ 'article',
265
+ {
266
+ className: 'sm-card sm-card-clickable',
267
+ role: 'button',
268
+ tabIndex: 0,
269
+ onClick: () => {
270
+ if (typeof props.onOpen === 'function') props.onOpen(skill)
271
+ },
272
+ onKeyDown: (event) => {
273
+ if (event && event.key === 'Enter' && typeof props.onOpen === 'function') props.onOpen(skill)
274
+ },
275
+ },
276
+ h(
277
+ 'div',
278
+ { className: 'sm-card-head' },
279
+ h(Avatar, { skill }),
280
+ h(
281
+ 'div',
282
+ { className: 'sm-card-titles' },
283
+ h(
284
+ 'div',
285
+ { className: 'sm-card-name', title: skill.name },
286
+ skill.name,
287
+ sourceTag === '' ? null : h('span', { className: 'sm-card-source' }, ' · ' + sourceTag),
288
+ ),
289
+ h('div', { className: 'sm-card-author' }, t('meta.author', { name: skill.author })),
290
+ ),
291
+ ),
292
+ h('p', { className: 'sm-card-desc' }, skill.description === '' ? '—' : skill.description),
293
+ h(
294
+ 'div',
295
+ { className: 'sm-card-foot' },
296
+ h('span', { className: 'sm-metric' }, skill.downloads === null ? skill.version : h(DownloadGlyph, {}), skill.downloads === null ? '' : t('meta.downloads', { count: formatCount(skill.downloads) })),
297
+ action,
298
+ ),
299
+ )
300
+ }
301
+
302
+ function DetailPanel(props) {
303
+ const { skill, content, loading, t, installed, onClose, onTry, onInstall, onUninstall } = props
304
+ const isInstalled = installed[skill.slug] === true
305
+ return h(
306
+ 'div',
307
+ {
308
+ className: 'sm-mask',
309
+ onClick: () => {
310
+ onClose()
311
+ },
312
+ },
313
+ h(
314
+ 'div',
315
+ {
316
+ className: 'sm-modal',
317
+ onClick: (event) => {
318
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
319
+ },
320
+ },
321
+ h(
322
+ 'div',
323
+ { className: 'sm-modal-head' },
324
+ h(Avatar, { skill }),
325
+ h(
326
+ 'div',
327
+ { className: 'sm-modal-titles' },
328
+ h('h2', { className: 'sm-modal-name' }, skill.name),
329
+ h('div', { className: 'sm-modal-author' }, t('meta.author', { name: skill.author })),
330
+ ),
331
+ h(
332
+ 'button',
333
+ {
334
+ type: 'button',
335
+ className: 'sm-modal-close',
336
+ 'aria-label': t('action.close'),
337
+ onClick: () => {
338
+ onClose()
339
+ },
340
+ },
341
+ '\u00d7',
342
+ ),
343
+ ),
344
+ h(
345
+ 'div',
346
+ { className: 'sm-modal-actions' },
347
+ h(
348
+ 'button',
349
+ {
350
+ type: 'button',
351
+ className: 'sm-try',
352
+ onClick: () => {
353
+ onTry(skill)
354
+ },
355
+ },
356
+ t('action.tryIt'),
357
+ ),
358
+ isInstalled
359
+ ? h(
360
+ 'button',
361
+ {
362
+ type: 'button',
363
+ className: 'sm-ghost',
364
+ onClick: () => {
365
+ onUninstall(skill)
366
+ },
367
+ },
368
+ t('action.uninstall'),
369
+ )
370
+ : h(
371
+ 'button',
372
+ {
373
+ type: 'button',
374
+ className: 'sm-ghost',
375
+ onClick: () => {
376
+ onInstall(skill)
377
+ },
378
+ },
379
+ t('action.install'),
380
+ ),
381
+ ),
382
+ h(
383
+ 'div',
384
+ { className: 'sm-modal-meta' },
385
+ h('span', null, t('detail.version', { version: skill.version === '' ? '—' : skill.version })),
386
+ h(
387
+ 'span',
388
+ null,
389
+ skill.downloads === null ? t('detail.downloadsUnknown') : t('meta.downloads', { count: formatCount(skill.downloads) }),
390
+ ),
391
+ h('span', null, skill.category === '' ? t('detail.categoryUnknown') : skill.category),
392
+ ),
393
+ h('p', { className: 'sm-modal-desc' }, skill.description === '' ? '—' : skill.description),
394
+ h(
395
+ 'div',
396
+ { className: 'sm-modal-section' },
397
+ h('h3', { className: 'sm-modal-h3' }, t('detail.overview')),
398
+ loading
399
+ ? h('p', { className: 'sm-modal-hint' }, t('state.loading'))
400
+ : h('pre', { className: 'sm-modal-pre' }, content === '' ? t('detail.noContent') : content),
401
+ ),
402
+ h('div', { className: 'sm-modal-id' }, 'ID: ' + skill.slug),
403
+ ),
404
+ )
405
+ }
406
+
407
+ function MarketPage(props) {
408
+ const t = translate(props)
409
+ const [input, setInput] = React.useState('')
410
+ const [keyword, setKeyword] = React.useState('')
411
+ const [category, setCategory] = React.useState('')
412
+ const [page, setPage] = React.useState(1)
413
+ const [skills, setSkills] = React.useState([])
414
+ const [total, setTotal] = React.useState(0)
415
+ const [loading, setLoading] = React.useState(true)
416
+ const [listError, setListError] = React.useState('')
417
+ const [categories, setCategories] = React.useState([])
418
+ const [categoryError, setCategoryError] = React.useState('')
419
+ const [installed, setInstalled] = React.useState({})
420
+ const [installedError, setInstalledError] = React.useState('')
421
+ const [busy, setBusy] = React.useState('')
422
+ const [notice, setNotice] = React.useState(null)
423
+ const [revision, setRevision] = React.useState(0)
424
+ const [showInstalled, setShowInstalled] = React.useState(false)
425
+ const [installedItems, setInstalledItems] = React.useState([])
426
+ const [uninstalling, setUninstalling] = React.useState('')
427
+ const [pendingSlug, setPendingSlug] = React.useState('')
428
+ const [detail, setDetail] = React.useState(null)
429
+ const [detailContent, setDetailContent] = React.useState('')
430
+ const [detailLoading, setDetailLoading] = React.useState(false)
431
+
432
+ React.useEffect(() => {
433
+ const controller = new AbortController()
434
+ getJson(`${API}/categories`, controller.signal)
435
+ .then((payload) => {
436
+ const list = Array.isArray(payload.categories) ? payload.categories : []
437
+ setCategories(list.filter((item) => item !== null && typeof item === 'object' && typeof item.key === 'string'))
438
+ setCategoryError('')
439
+ })
440
+ .catch((error) => {
441
+ if (controller.signal.aborted) return
442
+ setCategoryError(messageOf(error))
443
+ })
444
+ return () => controller.abort()
445
+ }, [revision])
446
+
447
+ React.useEffect(() => {
448
+ const controller = new AbortController()
449
+ getJson(`${API}/installed?_=${Date.now()}`, controller.signal)
450
+ .then((payload) => {
451
+ const list = Array.isArray(payload.skills) ? payload.skills : []
452
+ const next = {}
453
+ for (const item of list) {
454
+ if (item !== null && typeof item === 'object' && typeof item.slug === 'string') next[item.slug] = true
455
+ }
456
+ setInstalled(next)
457
+ setInstalledItems(
458
+ list.filter((item) => item !== null && typeof item === 'object' && typeof item.slug === 'string'),
459
+ )
460
+ setInstalledError('')
461
+ })
462
+ .catch((error) => {
463
+ if (controller.signal.aborted) return
464
+ setInstalledError(messageOf(error))
465
+ })
466
+ return () => controller.abort()
467
+ }, [revision])
468
+
469
+ React.useEffect(() => {
470
+ const controller = new AbortController()
471
+ setLoading(true)
472
+ const query = new URLSearchParams({ page: String(page), pageSize: String(PAGE_SIZE) })
473
+ if (keyword !== '') query.set('keyword', keyword)
474
+ if (category !== '') query.set('category', category)
475
+ getJson(`${API}/skills?${query.toString()}`, controller.signal)
476
+ .then((payload) => {
477
+ const list = Array.isArray(payload.skills) ? payload.skills : []
478
+ setSkills(list.filter((item) => item !== null && typeof item === 'object' && typeof item.slug === 'string'))
479
+ setTotal(Number.isFinite(payload.total) ? payload.total : list.length)
480
+ setListError('')
481
+ setLoading(false)
482
+ })
483
+ .catch((error) => {
484
+ if (controller.signal.aborted) return
485
+ setSkills([])
486
+ setTotal(0)
487
+ setListError(messageOf(error))
488
+ setLoading(false)
489
+ })
490
+ return () => controller.abort()
491
+ }, [keyword, category, page, revision])
492
+
493
+ const submitSearch = (event) => {
494
+ event.preventDefault()
495
+ setPage(1)
496
+ setKeyword(input.trim())
497
+ }
498
+
499
+ const pickCategory = (key) => {
500
+ setPage(1)
501
+ setCategory(key)
502
+ }
503
+
504
+ const install = async (skill) => {
505
+ setBusy(skill.slug)
506
+ setNotice(null)
507
+ try {
508
+ const response = await fetch(`${API}/install`, {
509
+ method: 'POST',
510
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
511
+ body: JSON.stringify({ slug: skill.slug, name: skill.name, version: skill.version, iconUrl: skill.iconUrl }),
512
+ })
513
+ const payload = await response.json().catch(() => null)
514
+ const failed = !response.ok || (payload !== null && typeof payload === 'object' && payload.ok === false)
515
+ if (failed) {
516
+ const reason =
517
+ payload !== null && typeof payload === 'object' && typeof payload.error === 'string'
518
+ ? payload.error
519
+ : `HTTP ${response.status}`
520
+ throw new Error(reason)
521
+ }
522
+ setNotice({ kind: 'ok', text: t('notice.installed', { name: skill.name }) })
523
+ setRevision((value) => value + 1)
524
+ } catch (error) {
525
+ setNotice({ kind: 'error', text: t('notice.installFailed', { message: messageOf(error) }) })
526
+ } finally {
527
+ setBusy('')
528
+ }
529
+ }
530
+
531
+ const uninstall = async (skill) => {
532
+ if (pendingSlug !== skill.slug) {
533
+ setPendingSlug(skill.slug)
534
+ window.setTimeout(() => {
535
+ setPendingSlug((current) => (current === skill.slug ? '' : current))
536
+ }, 4000)
537
+ return
538
+ }
539
+ setPendingSlug('')
540
+ setUninstalling(skill.slug)
541
+ setNotice(null)
542
+ try {
543
+ const response = await fetch(`${API}/uninstall`, {
544
+ method: 'POST',
545
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
546
+ body: JSON.stringify({ slug: skill.slug }),
547
+ })
548
+ const payload = await response.json().catch(() => null)
549
+ const failed = !response.ok || (payload !== null && typeof payload === 'object' && payload.ok === false)
550
+ if (failed) {
551
+ const reason =
552
+ payload !== null && typeof payload === 'object' && typeof payload.error === 'string'
553
+ ? payload.error
554
+ : `HTTP ${response.status}`
555
+ throw new Error(reason)
556
+ }
557
+ setNotice({ kind: 'ok', text: t('notice.uninstalled', { name: skill.name }) })
558
+ setRevision((value) => value + 1)
559
+ } catch (error) {
560
+ setNotice({ kind: 'error', text: t('notice.uninstallFailed', { message: messageOf(error) }) })
561
+ } finally {
562
+ setUninstalling('')
563
+ }
564
+ }
565
+
566
+ const openDetail = React.useCallback((skill) => {
567
+ setDetail(skill)
568
+ setDetailContent('')
569
+ setDetailLoading(true)
570
+ const controller = new AbortController()
571
+ getJson(`${API}/content?slug=${encodeURIComponent(skill.slug)}`, controller.signal)
572
+ .then((payload) => {
573
+ setDetailContent(typeof payload.content === 'string' ? payload.content : '')
574
+ })
575
+ .catch(() => {
576
+ setDetailContent('')
577
+ })
578
+ .finally(() => {
579
+ setDetailLoading(false)
580
+ })
581
+ }, [])
582
+
583
+ const trySkill = async (skill) => {
584
+ const text = `使用「${skill.name}」技能:`
585
+ try {
586
+ await navigator.clipboard.writeText(text)
587
+ setNotice({ kind: 'ok', text: t('notice.copied', { name: skill.name }) })
588
+ setDetail(null)
589
+ } catch {
590
+ setNotice({ kind: 'error', text: t('notice.copyFailed') })
591
+ }
592
+ }
593
+
594
+ const installedCount = Object.keys(installed).length
595
+ const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE))
596
+ const chips = [{ key: '', label: t('category.all') }].concat(
597
+ categories.map((item) => ({ key: item.key, label: typeof item.name === 'string' && item.name !== '' ? item.name : item.key })),
598
+ )
599
+
600
+ const header = h(
601
+ 'header',
602
+ { className: 'sm-header' },
603
+ h(
604
+ 'div',
605
+ { className: 'sm-header-text' },
606
+ h('h2', { className: 'sm-title' }, t('panel.title')),
607
+ h('p', { className: 'sm-subtitle' }, t('panel.subtitle')),
608
+ ),
609
+ h(
610
+ 'div',
611
+ { className: 'sm-header-side' },
612
+ h(
613
+ 'button',
614
+ {
615
+ type: 'button',
616
+ className: showInstalled ? 'sm-pill sm-pill-on' : 'sm-pill',
617
+ 'aria-pressed': showInstalled,
618
+ title: t('action.toggleInstalled'),
619
+ onClick: () => {
620
+ setShowInstalled((value) => !value)
621
+ setPage(1)
622
+ },
623
+ },
624
+ t('metric.installed', { count: installedCount }),
625
+ ),
626
+ h(
627
+ 'button',
628
+ {
629
+ type: 'button',
630
+ className: 'sm-ghost',
631
+ onClick: () => {
632
+ setRevision((value) => value + 1)
633
+ },
634
+ },
635
+ t('action.refresh'),
636
+ ),
637
+ ),
638
+ )
639
+
640
+ const toolbar = h(
641
+ 'div',
642
+ { className: 'sm-toolbar' },
643
+ h(
644
+ 'form',
645
+ { className: 'sm-search', onSubmit: submitSearch },
646
+ h('input', {
647
+ className: 'sm-search-input',
648
+ type: 'search',
649
+ value: input,
650
+ placeholder: t('search.placeholder'),
651
+ 'aria-label': t('search.action'),
652
+ onChange: (event) => setInput(event.currentTarget.value),
653
+ }),
654
+ h('button', { className: 'sm-search-button', type: 'submit' }, t('search.action')),
655
+ ),
656
+ h(
657
+ 'div',
658
+ { className: 'sm-chips' },
659
+ chips.map((chip) =>
660
+ h(
661
+ 'button',
662
+ {
663
+ key: chip.key === '' ? '__all__' : chip.key,
664
+ type: 'button',
665
+ className: chip.key === category ? 'sm-chip sm-chip-active' : 'sm-chip',
666
+ 'aria-pressed': chip.key === category,
667
+ onClick: () => pickCategory(chip.key),
668
+ },
669
+ chip.label,
670
+ ),
671
+ ),
672
+ ),
673
+ )
674
+
675
+ const notices = []
676
+ if (notice !== null) {
677
+ notices.push(
678
+ h(
679
+ 'div',
680
+ { key: 'notice', className: notice.kind === 'ok' ? 'sm-notice sm-notice-ok' : 'sm-notice sm-notice-error' },
681
+ h('span', { className: 'sm-notice-text' }, notice.text),
682
+ h('button', { type: 'button', className: 'sm-link', onClick: () => setNotice(null) }, t('notice.dismiss')),
683
+ ),
684
+ )
685
+ }
686
+ if (categoryError !== '') {
687
+ notices.push(h('div', { key: 'category-error', className: 'sm-notice sm-notice-error' }, t('error.categories', { message: categoryError })))
688
+ }
689
+ if (installedError !== '') {
690
+ notices.push(h('div', { key: 'installed-error', className: 'sm-notice sm-notice-warn' }, t('error.installed', { message: installedError })))
691
+ }
692
+
693
+ const installedList = []
694
+ const seenSlugs = new Set()
695
+ for (const entry of installedItems) {
696
+ if (entry === null || typeof entry !== 'object' || typeof entry.slug !== 'string') continue
697
+ if (seenSlugs.has(entry.slug)) continue
698
+ if (installed[entry.slug] !== true) continue
699
+ seenSlugs.add(entry.slug)
700
+ installedList.push(entry)
701
+ }
702
+ let body
703
+ if (showInstalled) {
704
+ body =
705
+ installedList.length === 0
706
+ ? h('div', { className: 'sm-state' }, t('state.noInstalled'))
707
+ : h(
708
+ 'div',
709
+ { className: 'sm-grid' },
710
+ installedList.map((item) =>
711
+ h(SkillCard, {
712
+ key: item.slug,
713
+ skill: {
714
+ slug: item.slug,
715
+ name: typeof item.name === 'string' && item.name !== '' ? item.name : item.slug,
716
+ author:
717
+ typeof item.author === 'string' && item.author !== '' ? item.author : t('meta.localAuthor'),
718
+ description: typeof item.description === 'string' ? item.description : '',
719
+ downloads: typeof item.downloads === 'number' ? item.downloads : null,
720
+ version: typeof item.version === 'string' ? item.version : '',
721
+ iconUrl: typeof item.iconUrl === 'string' ? item.iconUrl : '',
722
+ },
723
+ installed,
724
+ busy: '',
725
+ onInstall: install,
726
+ onUninstall: uninstall,
727
+ uninstalling,
728
+ pendingSlug,
729
+ onOpen: openDetail,
730
+ t,
731
+ }),
732
+ ),
733
+ )
734
+ } else if (loading) {
735
+ body = h('div', { className: 'sm-state' }, t('state.loading'))
736
+ } else if (listError !== '') {
737
+ body = h('div', { className: 'sm-state sm-state-error' }, t('error.list', { message: listError }))
738
+ } else if (skills.length === 0) {
739
+ body = h('div', { className: 'sm-state' }, t('state.empty'))
740
+ } else {
741
+ const uniqueSkills = []
742
+ const seenSkillSlugs = new Set()
743
+ for (const item of skills) {
744
+ if (item === null || typeof item !== 'object' || typeof item.slug !== 'string') continue
745
+ if (seenSkillSlugs.has(item.slug)) continue
746
+ seenSkillSlugs.add(item.slug)
747
+ uniqueSkills.push(item)
748
+ }
749
+ body = h(
750
+ 'div',
751
+ { className: 'sm-grid' },
752
+ uniqueSkills.map((skill) => h(SkillCard, { key: skill.slug, skill, installed, busy, onInstall: install, onUninstall: uninstall, uninstalling, pendingSlug, onOpen: openDetail, t })),
753
+ )
754
+ }
755
+
756
+ const pager =
757
+ showInstalled || loading || listError !== '' || total <= PAGE_SIZE
758
+ ? null
759
+ : h(
760
+ 'footer',
761
+ { className: 'sm-pager' },
762
+ h(
763
+ 'button',
764
+ {
765
+ type: 'button',
766
+ className: 'sm-ghost',
767
+ disabled: page <= 1,
768
+ onClick: () => setPage((value) => Math.max(1, value - 1)),
769
+ },
770
+ t('pager.prev'),
771
+ ),
772
+ h('span', { className: 'sm-pager-info' }, t('pager.info', { page, pages: pageCount })),
773
+ h(
774
+ 'button',
775
+ {
776
+ type: 'button',
777
+ className: 'sm-ghost',
778
+ disabled: page >= pageCount,
779
+ onClick: () => setPage((value) => Math.min(pageCount, value + 1)),
780
+ },
781
+ t('pager.next'),
782
+ ),
783
+ )
784
+
785
+ const countLine = showInstalled
786
+ ? h('div', { className: 'sm-count' }, t('state.installedTotal', { count: installedList.length }))
787
+ : listError !== '' || (loading && total === 0)
788
+ ? null
789
+ : h('div', { className: 'sm-count' }, t('state.total', { count: formatCount(total) }))
790
+
791
+ return h(
792
+ 'div',
793
+ { className: 'sm-root' },
794
+ header,
795
+ toolbar,
796
+ notices.length === 0 ? null : h('div', { className: 'sm-notices' }, notices),
797
+ countLine,
798
+ body,
799
+ pager,
800
+ detail === null
801
+ ? null
802
+ : h(DetailPanel, {
803
+ skill: detail,
804
+ content: detailContent,
805
+ loading: detailLoading,
806
+ t,
807
+ installed,
808
+ onClose: () => {
809
+ setDetail(null)
810
+ },
811
+ onTry: trySkill,
812
+ onInstall: install,
813
+ onUninstall: uninstall,
814
+ }),
815
+ )
816
+ }
817
+
818
+ function SidebarIcon(props) {
819
+ const size = props !== null && typeof props === 'object' && Number.isFinite(props.size) ? props.size : 20
820
+ return h(
821
+ 'svg',
822
+ {
823
+ className: 'sm-side-icon',
824
+ width: size,
825
+ height: size,
826
+ viewBox: '0 0 24 24',
827
+ fill: 'none',
828
+ stroke: 'currentColor',
829
+ strokeWidth: 1.6,
830
+ strokeLinecap: 'round',
831
+ strokeLinejoin: 'round',
832
+ 'aria-hidden': 'true',
833
+ },
834
+ h('path', { d: 'M4.2 9.4h15.6l-.9 9.2a2 2 0 0 1-2 1.8H7.1a2 2 0 0 1-2-1.8z' }),
835
+ h('path', { d: 'M8.6 9.4V7.6a3.4 3.4 0 0 1 6.8 0v1.8' }),
836
+ h('path', { d: 'M9.4 13.4h5.2' }),
837
+ )
838
+ }
839
+
840
+ const CSS = `
841
+ .sm-root{box-sizing:border-box;display:flex;flex-direction:column;gap:14px;height:100%;padding:24px 28px 28px;overflow-y:auto;color:var(--dsw-alias-label-primary);font-size:14px;line-height:22px}
842
+ .sm-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;flex-wrap:wrap}
843
+ .sm-header-text{display:flex;flex-direction:column;gap:2px;min-width:0}
844
+ .sm-title{margin:0;font-size:20px;line-height:28px;font-weight:600}
845
+ .sm-subtitle{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
846
+ .sm-header-side{display:flex;align-items:center;gap:8px}
847
+ .sm-pill{border:none;cursor:pointer;font:inherit;border-radius:999px;padding:3px 10px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-module-platform)}
848
+ .sm-pill:hover{color:var(--dsw-alias-label-primary)}
849
+ .sm-pill-on{color:var(--dsw-alias-label-primary);box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-selected)}
850
+ .sm-toolbar{display:flex;flex-direction:column;gap:10px}
851
+ .sm-search{display:flex;gap:8px;max-width:560px}
852
+ .sm-search-input{flex:1;min-width:0;box-sizing:border-box;height:34px;padding:0 12px;border-radius:var(--dsw-radius-sm);border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;outline:none}
853
+ .sm-search-input::placeholder{color:var(--dsw-alias-label-caption)}
854
+ .sm-search-input:focus{border-color:var(--dsw-alias-border-selected)}
855
+ .sm-search-button{height:34px;padding:0 14px;border-radius:var(--dsw-radius-sm);border:none;cursor:pointer;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-module-platform)}
856
+ .sm-chips{display:flex;flex-wrap:wrap;gap:6px}
857
+ .sm-chip{box-sizing:border-box;height:28px;padding:0 12px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l4);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;font-size:12px;line-height:26px}
858
+ .sm-chip:hover{border-color:var(--dsw-alias-border-selected);color:var(--dsw-alias-label-primary)}
859
+ .sm-chip-active{border-color:var(--dsw-alias-border-selected);background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);font-weight:500}
860
+ .sm-notices{display:flex;flex-direction:column;gap:6px}
861
+ .sm-notice{display:flex;align-items:center;gap:12px;justify-content:space-between;border-radius:var(--dsw-radius-sm);padding:8px 12px;font-size:12px;line-height:18px;border:.5px solid var(--dsw-alias-border-l2)}
862
+ .sm-notice-ok{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}
863
+ .sm-notice-warn{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary)}
864
+ .sm-notice-error{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}
865
+ .sm-notice-text{min-width:0;overflow:hidden;text-overflow:ellipsis}
866
+ .sm-link{border:none;background:transparent;cursor:pointer;font:inherit;font-size:12px;color:var(--dsw-alias-label-tertiary);padding:0}
867
+ .sm-link:hover{color:var(--dsw-alias-label-primary)}
868
+ .sm-count{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
869
+ .sm-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(248px,1fr));gap:12px}
870
+ .sm-card{box-sizing:border-box;display:flex;flex-direction:column;gap:10px;padding:14px;border-radius:var(--dsw-radius-md);border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1)}
871
+ .sm-card:hover{border-color:var(--dsw-alias-border-l4)}
872
+ .sm-card-head{display:flex;align-items:center;gap:10px;min-width:0}
873
+ .sm-avatar{position:relative;flex:none;width:${ICON_SIZE}px;height:${ICON_SIZE}px;border-radius:var(--dsw-radius-sm);background:linear-gradient(135deg,hsl(var(--sm-hue) 58% 52%),hsl(calc(var(--sm-hue) + 42) 62% 42%));display:flex;align-items:center;justify-content:center;overflow:hidden}
874
+ .sm-avatar-letter{font-size:15px;font-weight:600;color:#fff}
875
+ .sm-avatar-img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border-radius:inherit;background:var(--dsw-alias-bg-module-platform)}
876
+ .sm-card-titles{display:flex;flex-direction:column;min-width:0;gap:1px}
877
+ .sm-card-name{font-size:13px;line-height:20px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
878
+ .sm-card-source{margin-left:2px;font-size:11px;font-weight:400;color:var(--dsw-alias-label-caption)}
879
+ .sm-card-author{font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
880
+ .sm-card-desc{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:36px}
881
+ .sm-card-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:auto}
882
+ .sm-metric{display:inline-flex;align-items:center;gap:4px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}
883
+ .sm-install{height:26px;padding:0 12px;border-radius:999px;border:none;cursor:pointer;font:inherit;font-size:12px;line-height:26px;color:var(--dsw-alias-bg-layer-1);background:var(--dsw-alias-label-primary)}
884
+ .sm-install:disabled{opacity:.55;cursor:default}
885
+ .sm-tag{height:26px;padding:0 10px;border-radius:999px;font-size:12px;line-height:26px;color:var(--dsw-alias-label-tertiary);background:var(--dsw-alias-bg-module-platform)}
886
+ .sm-uninstall{height:26px;padding:0 12px;border-radius:999px;cursor:pointer;font:inherit;font-size:12px;line-height:24px;color:var(--dsw-alias-label-secondary);background:transparent;border:.5px solid var(--dsw-alias-border-l2)}
887
+ .sm-uninstall:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l3)}
888
+ .sm-uninstall:disabled{opacity:.55;cursor:default}
889
+ .sm-uninstall-armed{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary)}
890
+ .sm-state{padding:40px 0;text-align:center;font-size:13px;color:var(--dsw-alias-label-tertiary)}
891
+ .sm-state-error{color:var(--dsw-alias-label-primary)}
892
+ .sm-pager{display:flex;align-items:center;justify-content:center;gap:14px;padding:4px 0 8px}
893
+ .sm-pager-info{font-size:12px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}
894
+ .sm-ghost{height:30px;padding:0 14px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l4);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;font-size:12px;line-height:28px}
895
+ .sm-ghost:hover:not(:disabled){border-color:var(--dsw-alias-border-selected);color:var(--dsw-alias-label-primary)}
896
+ .sm-ghost:disabled{opacity:.45;cursor:default}
897
+ .sm-side-icon{display:block}
898
+ .sm-card-clickable{cursor:pointer;transition:box-shadow .16s ease,transform .16s ease}
899
+ .sm-card-clickable:hover{box-shadow:0 0 0 .5px var(--dsw-alias-border-selected),0 6px 18px rgba(0,0,0,.12)}
900
+ .sm-mask{position:fixed;inset:0;z-index:60;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.45)}
901
+ .sm-modal{box-sizing:border-box;display:flex;flex-direction:column;gap:14px;width:min(680px,100%);max-height:min(760px,90vh);overflow-y:auto;padding:22px 24px 20px;border-radius:16px;background:var(--dsw-alias-bg-module-platform);box-shadow:0 18px 50px rgba(0,0,0,.35)}
902
+ .sm-modal-head{display:flex;align-items:center;gap:12px}
903
+ .sm-modal-titles{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}
904
+ .sm-modal-name{margin:0;font-size:17px;line-height:24px;font-weight:600}
905
+ .sm-modal-author{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
906
+ .sm-modal-close{border:none;background:transparent;cursor:pointer;font-size:20px;line-height:20px;color:var(--dsw-alias-label-tertiary);padding:4px 6px;border-radius:8px}
907
+ .sm-modal-close:hover{color:var(--dsw-alias-label-primary)}
908
+ .sm-modal-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
909
+ .sm-try{border:none;cursor:pointer;font:inherit;border-radius:999px;padding:7px 18px;font-size:13px;font-weight:500;color:#fff;background:linear-gradient(135deg,#2f7cf6,#5b5bd6)}
910
+ .sm-try:hover{filter:brightness(1.06)}
911
+ .sm-modal-meta{display:flex;align-items:center;gap:18px;flex-wrap:wrap;padding:10px 0;border-top:.5px solid var(--dsw-alias-border-secondary);border-bottom:.5px solid var(--dsw-alias-border-secondary);font-size:12px;color:var(--dsw-alias-label-secondary)}
912
+ .sm-modal-desc{margin:0;font-size:13px;line-height:21px;color:var(--dsw-alias-label-secondary)}
913
+ .sm-modal-section{display:flex;flex-direction:column;gap:8px}
914
+ .sm-modal-h3{margin:0;font-size:13px;line-height:20px;font-weight:600;color:var(--dsw-alias-label-primary)}
915
+ .sm-modal-hint{margin:0;font-size:12px;color:var(--dsw-alias-label-tertiary)}
916
+ .sm-modal-pre{margin:0;padding:14px 16px;border-radius:10px;background:var(--dsw-alias-bg-base);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:19px;white-space:pre-wrap;word-break:break-word;max-height:320px;overflow:auto;color:var(--dsw-alias-label-secondary)}
917
+ .sm-modal-id{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;color:var(--dsw-alias-label-tertiary);word-break:break-all}
918
+ `
919
+
920
+ function ensureStyles() {
921
+ if (typeof document === 'undefined') return () => {}
922
+ const marker = 'skill-market-panel'
923
+ const existing = document.querySelector(`style[data-plugin-css="${marker}"]`)
924
+ if (existing !== null) return () => {}
925
+ const tag = document.createElement('style')
926
+ tag.dataset.plugin = '@dsh-local/view-25e475c1-3ab1-47c1-bb94-8947498c3bed'
927
+ tag.dataset.pluginCss = marker
928
+ tag.textContent = CSS
929
+ document.head.appendChild(tag)
930
+ return () => {
931
+ tag.remove()
932
+ }
933
+ }
934
+
935
+ const inject = ['locale', 'slots']
936
+
937
+ function apply(ctx) {
938
+ ctx.effect(ensureStyles, 'skill-market: styles')
939
+ ctx.effect(
940
+ () => ctx.locale.register(NS, { zh: ZH, en: EN }),
941
+ 'skill-market: dictionaries',
942
+ )
943
+ const sidebarLabel = () => {
944
+ try {
945
+ const value = ctx.locale.bind(NS)('panel.title')
946
+ if (typeof value === 'string' && value !== '' && value !== 'panel.title' && value.indexOf(NS) < 0) return value
947
+ } catch {
948
+ // 落到内置中文。
949
+ }
950
+ return ZH['panel.title']
951
+ }
952
+ ctx.effect(
953
+ () =>
954
+ ctx.slots.inject('main', () =>
955
+ ctx.slots.register(
956
+ { name: 'main', key: PANEL_ID, locale: NS, inject: () => ({ t: ctx.locale.bind(NS) }) },
957
+ MarketPage,
958
+ ),
959
+ ),
960
+ 'skill-market: main panel',
961
+ )
962
+ ctx.effect(
963
+ () =>
964
+ ctx.slots.inject('sidebar.panellist', () =>
965
+ ctx.slots.register(
966
+ { name: 'sidebar.panellist', id: PANEL_ID, order: PANEL_ORDER, label: sidebarLabel, locale: NS },
967
+ SidebarIcon,
968
+ ),
969
+ ),
970
+ 'skill-market: sidebar entry',
971
+ )
972
+ }
973
+
974
+ exports.inject = inject
975
+ exports.apply = apply
976
+ return module.exports
977
+ },
978
+ })