dsh-plugin-slim 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +95 -2
- package/client.js +524 -0
- package/cordis.patch.yml +6 -0
- package/icon.svg +8 -0
- package/lib/attribution.js +627 -0
- package/lib/checkup.js +338 -0
- package/lib/footprint.js +134 -0
- package/lib/host.js +846 -0
- package/lib/http.js +231 -0
- package/lib/index.js +153 -0
- package/lib/patch.js +797 -0
- package/lib/routes.js +493 -0
- package/lib/usage.js +116 -0
- package/package.json +73 -4
package/client.js
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 轻装 · Plugin Slim — DSH browser panel.
|
|
3
|
+
* Plain ES2020, no build step, no JSX and no third-party UI runtime.
|
|
4
|
+
*/
|
|
5
|
+
(function () {
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
var PANEL_ID = 'plugin-slim'
|
|
9
|
+
var STYLE_MARKER = 'data-plugin-slim-style'
|
|
10
|
+
var API_BASE = 'api/plugin-slim/'
|
|
11
|
+
var SLOT_PANEL_LIST = 'sidebar.panellist'
|
|
12
|
+
var SLOT_MAIN = 'main'
|
|
13
|
+
|
|
14
|
+
var STATUS = {
|
|
15
|
+
'idle-heavy': { label: '建议休眠', className: 'warning' },
|
|
16
|
+
'heavy-unknown': { label: '用量未知', className: 'neutral' },
|
|
17
|
+
'active-heavy': { label: '常用', className: 'info' },
|
|
18
|
+
sleeping: { label: '已休眠', className: 'muted' },
|
|
19
|
+
'zero-burden': { label: '零工具负担 · 放心留着', className: 'success' },
|
|
20
|
+
protected: { label: '受保护', className: 'muted' },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var FILTERS = [
|
|
24
|
+
{ id: 'all', label: '全部' },
|
|
25
|
+
{ id: 'idle', label: '建议休眠' },
|
|
26
|
+
{ id: 'active', label: '常用工具' },
|
|
27
|
+
{ id: 'zero', label: '零负担' },
|
|
28
|
+
{ id: 'sleeping', label: '已休眠' },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
var STYLE_TEXT = `
|
|
32
|
+
.ps-root{--ps-f-bg:#f6f8f7;--ps-f-card:#fff;--ps-f-soft:#f0f4f1;--ps-f-text:#1c2923;--ps-f-text2:#5b6b63;--ps-f-text3:#819087;--ps-f-border:#dce4df;--ps-f-accent:#287854;--ps-f-accent2:#1f6244;--ps-f-onaccent:#fff;--ps-f-focus:#3b956d;--ps-f-warn:#9a5a08;--ps-f-warnbg:#fff6e5;--ps-f-warnline:#eed8ae;--ps-f-info:#326c9b;--ps-f-infobg:#eef6fc;--ps-f-success:#23724d;--ps-f-successbg:#edf8f1;--ps-f-danger:#a13f3f;--ps-f-dangerbg:#fff2f1;--ps-bg:var(--bg-primary,var(--dsw-alias-bg-base,var(--ps-f-bg)));--ps-card:var(--bg-secondary,var(--ps-f-card));--ps-soft:var(--bg-tertiary,var(--ps-f-soft));--ps-text:var(--text-primary,var(--dsw-alias-label-primary,var(--ps-f-text)));--ps-text2:var(--text-secondary,var(--dsw-alias-label-secondary,var(--ps-f-text2)));--ps-text3:var(--text-tertiary,var(--dsw-alias-label-tertiary,var(--ps-f-text3)));--ps-border:var(--border-color,var(--dsw-alias-border-l2,var(--ps-f-border)));--ps-accent:var(--accent-color,var(--dsw-alias-state-business-primary,var(--ps-f-accent)));--ps-focus:var(--focus-ring-color,var(--ps-f-focus));display:flex;flex-direction:column;gap:16px;box-sizing:border-box;width:100%;max-width:1120px;min-width:0;min-height:100%;margin:0 auto;padding:22px 24px 28px;color:var(--ps-text);background:var(--ps-bg);font:13px/1.55 var(--font-family,var(--dsw-font-family,-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif));container-type:inline-size;container-name:plugin-slim;overflow-x:hidden}
|
|
33
|
+
:root[data-theme="dark"] .ps-root,:root.dark .ps-root,.ps-root[data-theme="dark"]{--ps-f-bg:#111713;--ps-f-card:#18201b;--ps-f-soft:#202a23;--ps-f-text:#e5ede8;--ps-f-text2:#a8b8ae;--ps-f-text3:#819288;--ps-f-border:#344239;--ps-f-accent:#79c9a1;--ps-f-accent2:#9bdcb9;--ps-f-onaccent:#10271b;--ps-f-focus:#8fd7b2;--ps-f-warn:#efbe6a;--ps-f-warnbg:#302719;--ps-f-warnline:#66502a;--ps-f-info:#8abde4;--ps-f-infobg:#1b2a36;--ps-f-success:#8bd2ac;--ps-f-successbg:#1b2d23;--ps-f-danger:#efa3a0;--ps-f-dangerbg:#352220}
|
|
34
|
+
@media(prefers-color-scheme:dark){:root:not([data-theme="light"]):not(.light) .ps-root{--ps-f-bg:#111713;--ps-f-card:#18201b;--ps-f-soft:#202a23;--ps-f-text:#e5ede8;--ps-f-text2:#a8b8ae;--ps-f-text3:#819288;--ps-f-border:#344239;--ps-f-accent:#79c9a1;--ps-f-accent2:#9bdcb9;--ps-f-onaccent:#10271b;--ps-f-focus:#8fd7b2;--ps-f-warn:#efbe6a;--ps-f-warnbg:#302719;--ps-f-warnline:#66502a;--ps-f-info:#8abde4;--ps-f-infobg:#1b2a36;--ps-f-success:#8bd2ac;--ps-f-successbg:#1b2d23;--ps-f-danger:#efa3a0;--ps-f-dangerbg:#352220}}
|
|
35
|
+
.ps-root *{box-sizing:border-box}.ps-root button,.ps-root input{font:inherit}.ps-root button{cursor:pointer}.ps-root button:disabled{cursor:not-allowed;opacity:.55}.ps-root button:focus-visible,.ps-root input:focus-visible,.ps-root summary:focus-visible,.ps-root a:focus-visible{outline:2px solid var(--ps-focus);outline-offset:2px}.ps-root a{color:var(--ps-accent);text-decoration:none}.ps-root a:hover{text-decoration:underline}.ps-root .ps-icon{display:block;flex:0 0 auto}.ps-root .ps-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}.ps-root .ps-brand{display:flex;align-items:flex-start;gap:11px;min-width:0}.ps-root .ps-brandmark{display:grid;place-items:center;width:38px;height:38px;flex:0 0 38px;border:1px solid var(--ps-border);border-radius:12px;color:var(--ps-accent);background:var(--ps-card)}.ps-root .ps-titleline{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.ps-root h1{margin:0;font-size:21px;line-height:1.25;letter-spacing:.02em}.ps-root .ps-subtitle{margin:4px 0 0;color:var(--ps-text2);font-size:12px}.ps-root .ps-zerobadge{display:inline-flex;align-items:center;gap:5px;padding:2px 8px;border-radius:999px;color:var(--ps-f-success);background:var(--ps-f-successbg);font-size:11px;font-weight:650}.ps-root .ps-zerobadge:before{content:"";width:5px;height:5px;border-radius:50%;background:currentColor}.ps-root .ps-headactions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}.ps-root .ps-btn{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:36px;padding:7px 13px;border:1px solid var(--ps-border);border-radius:9px;color:var(--ps-text);background:var(--ps-card);font-weight:600;line-height:1.35;transition:background .16s ease,border-color .16s ease,transform .16s ease}.ps-root .ps-btn:hover:not(:disabled){background:var(--ps-soft);border-color:var(--ps-f-text3)}.ps-root .ps-btn:active:not(:disabled){transform:translateY(1px)}.ps-root .ps-btn-primary{border-color:var(--ps-accent);color:var(--ps-f-onaccent);background:var(--ps-accent)}.ps-root .ps-btn-primary:hover:not(:disabled){border-color:var(--ps-f-accent2);background:var(--ps-f-accent2)}.ps-root .ps-btn-quiet{border-color:transparent;background:transparent;color:var(--ps-text2)}.ps-root .ps-btn-small{min-height:30px;padding:5px 10px;font-size:12px}.ps-root .ps-hero{overflow:hidden;border:1px solid var(--ps-border);border-radius:16px;background:var(--ps-card);box-shadow:0 8px 26px rgba(24,48,35,.045)}.ps-root .ps-herobody{padding:22px}.ps-root .ps-eyebrow{display:flex;align-items:center;gap:7px;margin-bottom:7px;color:var(--ps-accent);font-size:11px;font-weight:700;letter-spacing:.12em}.ps-root .ps-conclusion{max-width:850px;margin:0;font-size:17px;line-height:1.65;font-weight:650;letter-spacing:.01em}.ps-root .ps-heronote{margin:8px 0 0;color:var(--ps-text2);font-size:12px}.ps-root .ps-stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-top:19px}.ps-root .ps-stat{min-width:0;padding:13px 14px;border:1px solid var(--ps-border);border-radius:11px;background:var(--ps-soft)}.ps-root .ps-statlabel{color:var(--ps-text2);font-size:11px}.ps-root .ps-statvalue{margin-top:3px;font-size:23px;line-height:1.35;font-weight:720;font-variant-numeric:tabular-nums;letter-spacing:-.02em}.ps-root .ps-statvalue small{font-size:12px;font-weight:550;letter-spacing:0}.ps-root .ps-statnote{margin-top:4px;color:var(--ps-text2);font-size:11px;line-height:1.5;overflow-wrap:anywhere}.ps-root .ps-primaryaction{margin-top:17px}.ps-root .ps-confirm{padding:16px 20px;border-top:1px solid var(--ps-f-warnline);background:var(--ps-f-warnbg)}.ps-root .ps-confirm-title{margin:0 0 5px;color:var(--ps-f-warn);font-weight:700}.ps-root .ps-confirm p{margin:0;color:var(--ps-text2);font-size:12px}.ps-root .ps-confirmlist{display:flex;gap:7px;flex-wrap:wrap;margin:12px 0}.ps-root .ps-confirmitem{padding:5px 9px;border:1px solid var(--ps-f-warnline);border-radius:7px;background:var(--ps-card);color:var(--ps-text);font-size:12px}.ps-root .ps-confirmactions{display:flex;gap:8px;flex-wrap:wrap}.ps-root .ps-banner{display:flex;align-items:flex-start;gap:9px;padding:11px 13px;border:1px solid var(--ps-border);border-radius:11px;background:var(--ps-card);color:var(--ps-text2)}.ps-root .ps-banner-success{border-color:var(--ps-border);background:var(--ps-f-successbg)}.ps-root .ps-banner-error{border-color:var(--ps-f-danger);background:var(--ps-f-dangerbg);color:var(--ps-f-danger)}.ps-root .ps-banner-body{flex:1;min-width:0}.ps-root .ps-banner-title{color:var(--ps-text);font-weight:650}.ps-root .ps-banner-error .ps-banner-title{color:var(--ps-f-danger)}.ps-root .ps-banner-hint{margin-top:2px;font-size:12px;overflow-wrap:anywhere}.ps-root .ps-banner .ps-btn{flex:0 0 auto}.ps-root .ps-warninglist{margin:0;padding-left:20px;color:var(--ps-f-warn);font-size:12px}.ps-root .ps-listhead{display:flex;align-items:flex-end;justify-content:space-between;gap:12px;margin-top:2px}.ps-root .ps-sectiontitle{margin:0;font-size:15px}.ps-root .ps-sectionnote{margin:3px 0 0;color:var(--ps-text2);font-size:11px}.ps-root .ps-search{position:relative;flex:0 1 260px;min-width:180px}.ps-root .ps-search .ps-icon{position:absolute;left:11px;top:50%;transform:translateY(-50%);color:var(--ps-text3);pointer-events:none}.ps-root .ps-search input{width:100%;height:36px;padding:7px 11px 7px 34px;border:1px solid var(--ps-border);border-radius:9px;color:var(--ps-text);background:var(--ps-card);outline:none}.ps-root .ps-search input::placeholder{color:var(--ps-text3)}.ps-root .ps-search input:focus{border-color:var(--ps-focus)}.ps-root .ps-tabs{display:flex;gap:6px;flex-wrap:wrap;padding:4px;border:1px solid var(--ps-border);border-radius:11px;background:var(--ps-soft)}.ps-root .ps-tab{min-height:30px;padding:5px 10px;border:0;border-radius:7px;background:transparent;color:var(--ps-text2);font-size:12px}.ps-root .ps-tab:hover{background:var(--ps-card);color:var(--ps-text)}.ps-root .ps-tab[aria-selected="true"]{background:var(--ps-card);color:var(--ps-text);font-weight:650;box-shadow:0 1px 4px rgba(20,40,28,.08)}.ps-root .ps-count{display:inline-block;margin-left:4px;color:var(--ps-text3);font-variant-numeric:tabular-nums}.ps-root .ps-plugins{display:flex;flex-direction:column;gap:9px}.ps-root .ps-plugin{overflow:hidden;border:1px solid var(--ps-border);border-radius:12px;background:var(--ps-card)}.ps-root .ps-plugin-main{display:flex;align-items:center;gap:16px;padding:15px 16px}.ps-root .ps-plugin-info{flex:1;min-width:0}.ps-root .ps-plugin-topline{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.ps-root .ps-plugin-name{margin:0;font-size:14px;font-weight:680;overflow-wrap:anywhere}.ps-root .ps-version{color:var(--ps-text3);font-size:11px;font-variant-numeric:tabular-nums}.ps-root .ps-status{display:inline-flex;align-items:center;min-height:21px;padding:2px 7px;border-radius:999px;font-size:10px;font-weight:650;white-space:nowrap}.ps-root .ps-status-warning{color:var(--ps-f-warn);background:var(--ps-f-warnbg)}.ps-root .ps-status-neutral{color:var(--ps-text2);background:var(--ps-soft)}.ps-root .ps-status-info{color:var(--ps-f-info);background:var(--ps-f-infobg)}.ps-root .ps-status-muted{color:var(--ps-text2);background:var(--ps-soft)}.ps-root .ps-status-success{color:var(--ps-f-success);background:var(--ps-f-successbg)}.ps-root .ps-description{margin:6px 0 0;color:var(--ps-text2);font-size:12px;overflow-wrap:anywhere}.ps-root .ps-metrics{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-top:8px;color:var(--ps-text2);font-size:11px;font-variant-numeric:tabular-nums}.ps-root .ps-metricsep{color:var(--ps-text3)}.ps-root .ps-plugin-actions{display:flex;align-items:center;gap:6px;flex:0 0 auto}.ps-root .ps-plugin-actions .ps-btn{min-width:66px}.ps-root .ps-tooltoggle{display:inline-flex;align-items:center;gap:4px;margin-top:9px;padding:0;border:0;background:none;color:var(--ps-accent);font-size:11px}.ps-root .ps-tooltoggle .ps-icon{transition:transform .16s ease}.ps-root .ps-tooltoggle[aria-expanded="true"] .ps-icon{transform:rotate(180deg)}.ps-root .ps-tools{border-top:1px solid var(--ps-border);background:var(--ps-soft);padding:5px 16px}.ps-root .ps-tool{display:flex;align-items:center;gap:10px;padding:10px 0;border-bottom:1px solid var(--ps-border)}.ps-root .ps-tool:last-child{border-bottom:0}.ps-root .ps-tool-main{flex:1;min-width:0}.ps-root .ps-tool-name{display:block;font:12px/1.45 var(--font-family-code,ui-monospace,SFMono-Regular,Consolas,monospace);overflow-wrap:anywhere}.ps-root .ps-tool-desc{margin-top:2px;color:var(--ps-text2);font-size:11px;overflow-wrap:anywhere}.ps-root .ps-tool-meta{display:flex;align-items:center;justify-content:flex-end;gap:7px;flex-wrap:wrap;color:var(--ps-text2);font-size:10px;text-align:right}.ps-root .ps-loadbadge{padding:2px 6px;border:1px solid var(--ps-border);border-radius:5px;white-space:nowrap}.ps-root .ps-empty{padding:30px 18px;border:1px dashed var(--ps-border);border-radius:12px;text-align:center;color:var(--ps-text2);background:var(--ps-card)}.ps-root .ps-empty strong{display:block;margin-bottom:4px;color:var(--ps-text)}.ps-root .ps-details{overflow:hidden;border:1px solid var(--ps-border);border-radius:11px;background:var(--ps-card)}.ps-root .ps-details summary{display:flex;align-items:center;gap:8px;padding:12px 14px;cursor:pointer;color:var(--ps-text2);list-style:none}.ps-root .ps-details summary::-webkit-details-marker{display:none}.ps-root .ps-details summary:after{content:"›";margin-left:auto;transform:rotate(90deg);transition:transform .16s ease}.ps-root .ps-details:not([open]) summary:after{transform:rotate(0deg)}.ps-root .ps-details-body{padding:0 14px 12px;color:var(--ps-text2);font-size:12px}.ps-root .ps-protectedrow{display:flex;align-items:flex-start;gap:8px;padding:8px 0;border-top:1px solid var(--ps-border)}.ps-root .ps-protectedname{flex:0 1 46%;color:var(--ps-text);overflow-wrap:anywhere}.ps-root .ps-protectreason{flex:1;min-width:0;overflow-wrap:anywhere}.ps-root .ps-unattributed{display:flex;gap:6px;flex-wrap:wrap}.ps-root .ps-unattributed code{padding:2px 5px;border-radius:4px;background:var(--ps-soft);color:var(--ps-text2);font-size:10px}.ps-root .ps-footer{padding-top:2px;color:var(--ps-text3);font-size:11px;line-height:1.75}.ps-root .ps-footer p{margin:0}.ps-root .ps-footerlinks{display:flex;gap:12px;flex-wrap:wrap;margin-top:5px}.ps-root .ps-skeleton{position:relative;overflow:hidden;background:var(--ps-soft);border-radius:7px;color:transparent!important}.ps-root .ps-skeleton:after{content:"";position:absolute;inset:0;transform:translateX(-100%);background:linear-gradient(90deg,transparent,rgba(255,255,255,.32),transparent);animation:ps-shimmer 1.4s infinite}.ps-root .ps-skeleton-title{width:min(90%,620px);height:52px}.ps-root .ps-skeleton-stat{height:105px}.ps-root .ps-loadingnote{margin-top:14px;color:var(--ps-text2);font-size:12px}@keyframes ps-shimmer{to{transform:translateX(100%)}}@media(prefers-reduced-motion:reduce){.ps-root *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
|
|
36
|
+
@container plugin-slim (max-width:650px){.ps-root{padding:16px 14px 22px;gap:13px}.ps-root .ps-header{flex-direction:column;gap:12px}.ps-root .ps-headactions{width:100%;justify-content:flex-start}.ps-root .ps-herobody{padding:17px 15px}.ps-root .ps-conclusion{font-size:15px}.ps-root .ps-stats{grid-template-columns:1fr;gap:7px}.ps-root .ps-stat{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;padding:10px 12px}.ps-root .ps-statvalue{grid-row:1/3;grid-column:2;margin:0 0 0 10px;font-size:20px;text-align:right}.ps-root .ps-statnote{margin-top:2px}.ps-root .ps-listhead{align-items:stretch;flex-direction:column}.ps-root .ps-search{flex:auto;min-width:0;width:100%}.ps-root .ps-tabs{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:thin}.ps-root .ps-tab{flex:0 0 auto}.ps-root .ps-plugin-main{align-items:flex-start;gap:12px;padding:13px}.ps-root .ps-plugin-actions{flex-direction:column-reverse;align-items:stretch}.ps-root .ps-plugin-actions .ps-btn{min-width:60px;padding-left:9px;padding-right:9px}.ps-root .ps-tool{align-items:flex-start;flex-direction:column;gap:6px}.ps-root .ps-tool-meta{justify-content:flex-start;text-align:left}.ps-root .ps-confirm{padding:14px}.ps-root .ps-protectedrow{flex-direction:column;gap:3px}.ps-root .ps-protectedname{flex:auto}.ps-root .ps-banner{flex-wrap:wrap}.ps-root .ps-banner .ps-btn{margin-left:25px}}
|
|
37
|
+
`
|
|
38
|
+
|
|
39
|
+
function ensureStyle() {
|
|
40
|
+
if (typeof document === 'undefined' || !document.head) return
|
|
41
|
+
if (document.querySelector('style[' + STYLE_MARKER + ']') !== null) return
|
|
42
|
+
var style = document.createElement('style')
|
|
43
|
+
style.setAttribute(STYLE_MARKER, '')
|
|
44
|
+
style.textContent = STYLE_TEXT
|
|
45
|
+
document.head.appendChild(style)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readableError(error) {
|
|
49
|
+
if (error && typeof error.message === 'string' && error.message) return error.message
|
|
50
|
+
return '网络连接失败,请确认 DSH 正在运行后再试。'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function request(path, options) {
|
|
54
|
+
var init = options || {}
|
|
55
|
+
var headers = { Accept: 'application/json' }
|
|
56
|
+
if (init.body) headers['Content-Type'] = 'application/json'
|
|
57
|
+
return fetch(API_BASE + path, {
|
|
58
|
+
method: init.method || 'GET',
|
|
59
|
+
headers: headers,
|
|
60
|
+
body: init.body,
|
|
61
|
+
cache: 'no-store',
|
|
62
|
+
credentials: 'same-origin',
|
|
63
|
+
}).then(function (response) {
|
|
64
|
+
return response.json().catch(function () {
|
|
65
|
+
throw new Error('服务返回了无法识别的内容,请重新体检。')
|
|
66
|
+
}).then(function (data) {
|
|
67
|
+
if (!response.ok || (data && data.ok === false)) {
|
|
68
|
+
throw new Error(data && data.error ? data.error : '操作未完成(HTTP ' + response.status + '),请稍后重试。')
|
|
69
|
+
}
|
|
70
|
+
return data
|
|
71
|
+
})
|
|
72
|
+
}, function () {
|
|
73
|
+
throw new Error('无法连接轻装服务,请确认 DSH 正在运行,或稍后重试。')
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function number(value) {
|
|
78
|
+
return typeof value === 'number' && isFinite(value) ? value : 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function formatNumber(value) {
|
|
82
|
+
try {
|
|
83
|
+
return new Intl.NumberFormat('zh-CN').format(number(value))
|
|
84
|
+
} catch (_) {
|
|
85
|
+
return String(number(value))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function formatTokens(value) {
|
|
90
|
+
return '~' + formatNumber(value) + ' tokens'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function createIcon(React) {
|
|
94
|
+
var h = React.createElement
|
|
95
|
+
return function Icon() {
|
|
96
|
+
return h('svg', {
|
|
97
|
+
className: 'ps-icon', width: 22, height: 22, viewBox: '0 0 24 24',
|
|
98
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.7,
|
|
99
|
+
strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true',
|
|
100
|
+
},
|
|
101
|
+
h('path', { d: 'M18.5 3.8C12 3.8 6.7 7.4 5.1 12.8c-.8 2.7-.5 5.2-1 7.3 2.1-.5 4.6-.2 7.3-1 5.4-1.6 8.6-6.9 8.6-12.4 0-1.6-.5-2.9-1.5-2.9Z' }),
|
|
102
|
+
h('path', { d: 'M4.2 20c2.8-3.4 6.3-6.8 11.2-10.4' }),
|
|
103
|
+
h('path', { d: 'M2.8 13.4h4.4M2 17.2h3.2', opacity: 0.65 }))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function createPage(React) {
|
|
108
|
+
var h = React.createElement
|
|
109
|
+
var useState = React.useState
|
|
110
|
+
var useEffect = React.useEffect
|
|
111
|
+
var useMemo = React.useMemo
|
|
112
|
+
var useRef = React.useRef
|
|
113
|
+
|
|
114
|
+
function glyph(name, size) {
|
|
115
|
+
var paths = []
|
|
116
|
+
if (name === 'refresh') {
|
|
117
|
+
paths = [h('path', { key: 'a', d: 'M19 12a7 7 0 1 1-2.05-4.95' }), h('path', { key: 'b', d: 'M19 4v5h-5' })]
|
|
118
|
+
} else if (name === 'undo') {
|
|
119
|
+
paths = [h('path', { key: 'a', d: 'M9 7 4 12l5 5' }), h('path', { key: 'b', d: 'M5 12h8a6 6 0 0 1 6 6v1' })]
|
|
120
|
+
} else if (name === 'search') {
|
|
121
|
+
paths = [h('circle', { key: 'a', cx: 10.5, cy: 10.5, r: 6.5 }), h('path', { key: 'b', d: 'm16 16 4 4' })]
|
|
122
|
+
} else if (name === 'chevron') {
|
|
123
|
+
paths = [h('path', { key: 'a', d: 'm7 10 5 5 5-5' })]
|
|
124
|
+
} else if (name === 'lock') {
|
|
125
|
+
paths = [h('rect', { key: 'a', x: 5, y: 10, width: 14, height: 10, rx: 2 }), h('path', { key: 'b', d: 'M8 10V7a4 4 0 0 1 8 0v3' })]
|
|
126
|
+
} else if (name === 'check') {
|
|
127
|
+
paths = [h('path', { key: 'a', d: 'm5 12 4 4L19 6' })]
|
|
128
|
+
} else if (name === 'spark') {
|
|
129
|
+
paths = [h('path', { key: 'a', d: 'm12 3 1.7 5.3L19 10l-5.3 1.7L12 17l-1.7-5.3L5 10l5.3-1.7L12 3Z' }), h('path', { key: 'b', d: 'm19 16 .7 2.3L22 19l-2.3.7L19 22l-.7-2.3L16 19l2.3-.7L19 16Z' })]
|
|
130
|
+
}
|
|
131
|
+
return h('svg', {
|
|
132
|
+
className: 'ps-icon', width: size || 15, height: size || 15, viewBox: '0 0 24 24',
|
|
133
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.7,
|
|
134
|
+
strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true',
|
|
135
|
+
}, paths)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function statusBadge(status) {
|
|
139
|
+
var meta = STATUS[status] || { label: status || '状态未知', className: 'neutral' }
|
|
140
|
+
return h('span', { className: 'ps-status ps-status-' + meta.className }, meta.label)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function usageText(value) {
|
|
144
|
+
return value === null || typeof value === 'undefined' ? '近 30 天用量未知' : '近 30 天 ' + formatNumber(value) + ' 次'
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function Header(report, loading, busy, onRefresh, onUndo) {
|
|
148
|
+
var snapshot = report && report.latestSnapshot
|
|
149
|
+
return h('header', { className: 'ps-header' },
|
|
150
|
+
h('div', { className: 'ps-brand' },
|
|
151
|
+
h('div', { className: 'ps-brandmark' },
|
|
152
|
+
h('svg', { className: 'ps-icon', width: 24, height: 24, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true' },
|
|
153
|
+
h('path', { d: 'M18.5 3.8C12 3.8 6.7 7.4 5.1 12.8c-.8 2.7-.5 5.2-1 7.3 2.1-.5 4.6-.2 7.3-1 5.4-1.6 8.6-6.9 8.6-12.4 0-1.6-.5-2.9-1.5-2.9Z' }),
|
|
154
|
+
h('path', { d: 'M4.2 20c2.8-3.4 6.3-6.8 11.2-10.4' }))),
|
|
155
|
+
h('div', null,
|
|
156
|
+
h('div', { className: 'ps-titleline' }, h('h1', null, '轻装'), h('span', { className: 'ps-zerobadge' }, '0 常驻工具')),
|
|
157
|
+
h('p', { className: 'ps-subtitle' }, '插件上下文体检与一键休眠'))),
|
|
158
|
+
h('div', { className: 'ps-headactions' },
|
|
159
|
+
snapshot ? h('button', {
|
|
160
|
+
type: 'button', className: 'ps-btn ps-btn-small', onClick: onUndo,
|
|
161
|
+
disabled: loading || Boolean(busy), title: snapshot.summary || '撤销最近一次配置修改',
|
|
162
|
+
}, glyph('undo', 14), busy === 'undo' ? '撤销中…' : '撤销上次操作') : null,
|
|
163
|
+
h('button', { type: 'button', className: 'ps-btn ps-btn-small', onClick: onRefresh, disabled: loading || Boolean(busy) },
|
|
164
|
+
glyph('refresh', 14), loading ? '体检中…' : '重新体检')))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function LoadingHero() {
|
|
168
|
+
return h('section', { className: 'ps-hero', 'aria-label': '正在体检', 'aria-busy': 'true' },
|
|
169
|
+
h('div', { className: 'ps-herobody' },
|
|
170
|
+
h('div', { className: 'ps-eyebrow' }, glyph('spark', 14), '正在读取插件与工具定义'),
|
|
171
|
+
h('div', { className: 'ps-skeleton ps-skeleton-title' }, '正在生成体检结论'),
|
|
172
|
+
h('div', { className: 'ps-stats' },
|
|
173
|
+
h('div', { className: 'ps-skeleton ps-skeleton-stat' }),
|
|
174
|
+
h('div', { className: 'ps-skeleton ps-skeleton-stat' }),
|
|
175
|
+
h('div', { className: 'ps-skeleton ps-skeleton-stat' })),
|
|
176
|
+
h('div', { className: 'ps-loadingnote' }, '第一次体检需要读取本机插件信息,请稍候。')))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function Hero(report, confirmOpen, busy, onOpenConfirm, onCancelConfirm, onConfirm) {
|
|
180
|
+
var summary = report.summary || {}
|
|
181
|
+
var plugins = Array.isArray(report.plugins) ? report.plugins : []
|
|
182
|
+
var idle = plugins.filter(function (plugin) { return plugin.status === 'idle-heavy' && plugin.enabled && plugin.canToggle !== false })
|
|
183
|
+
var conclusion
|
|
184
|
+
var note = '体积只估算常驻工具的定义,不含系统提示词与对话正文。'
|
|
185
|
+
if (summary.usageKnown === false) {
|
|
186
|
+
conclusion = '当前无法读取历史调用记录,已保留用量未知插件不被误判;仍可按每轮工具定义体积决定是否休眠。'
|
|
187
|
+
note = '未知不等于没用过,因此不会把用量未知插件列为「建议休眠」。'
|
|
188
|
+
} else if (number(summary.idleHeavyPlugins) > 0) {
|
|
189
|
+
conclusion = '每轮对话固定携带 ' + formatNumber(summary.alwaysLoadedTools) + ' 个常驻工具(定义体积估算约 ' + formatNumber(summary.alwaysLoadedTokens) + ' tokens)。其中 ' + formatNumber(summary.idleHeavyPlugins) + ' 个吃灰插件近 30 天未调用,休眠它们可减少约 ' + formatNumber(summary.reduciblePercent) + '% 工具上下文负担。'
|
|
190
|
+
} else {
|
|
191
|
+
conclusion = '当前常驻工具很清爽,近 30 天未发现高负担吃灰插件。'
|
|
192
|
+
}
|
|
193
|
+
return h('section', { className: 'ps-hero', 'aria-labelledby': 'ps-conclusion' },
|
|
194
|
+
h('div', { className: 'ps-herobody' },
|
|
195
|
+
h('div', { className: 'ps-eyebrow' }, glyph('spark', 14), '本次体检结论'),
|
|
196
|
+
h('p', { className: 'ps-conclusion', id: 'ps-conclusion' }, conclusion),
|
|
197
|
+
h('p', { className: 'ps-heronote' }, note),
|
|
198
|
+
h('div', { className: 'ps-stats' },
|
|
199
|
+
h('div', { className: 'ps-stat' },
|
|
200
|
+
h('div', { className: 'ps-statlabel' }, '常驻工具'),
|
|
201
|
+
h('div', { className: 'ps-statvalue' }, formatNumber(summary.alwaysLoadedTools), ' ', h('small', null, '个')),
|
|
202
|
+
h('div', { className: 'ps-statnote' }, '另有 ' + formatNumber(summary.deferredTools) + ' 个延迟加载,不占每轮上下文')),
|
|
203
|
+
h('div', { className: 'ps-stat' },
|
|
204
|
+
h('div', { className: 'ps-statlabel' }, '每轮定义体积'),
|
|
205
|
+
h('div', { className: 'ps-statvalue' }, '~' + formatNumber(summary.alwaysLoadedTokens), ' ', h('small', null, 'tokens')),
|
|
206
|
+
h('div', { className: 'ps-statnote' }, formatNumber(summary.alwaysLoadedChars) + ' 字符 · 仅工具定义估算')),
|
|
207
|
+
h('div', { className: 'ps-stat' },
|
|
208
|
+
h('div', { className: 'ps-statlabel' }, '吃灰可减负'),
|
|
209
|
+
summary.usageKnown === false
|
|
210
|
+
? h('div', { className: 'ps-statvalue' }, '用量未知')
|
|
211
|
+
: h('div', { className: 'ps-statvalue' }, formatNumber(summary.idleHeavyPlugins), ' ', h('small', null, '个插件 / 约 ' + formatNumber(summary.reduciblePercent) + '%')),
|
|
212
|
+
h('div', { className: 'ps-statnote' }, summary.usageKnown === false ? '历史调用记录不可用,不做吃灰推断' : '只统计明确近 30 天未调用的常驻工具插件'))),
|
|
213
|
+
number(summary.idleHeavyPlugins) > 0 && idle.length > 0 ? h('div', { className: 'ps-primaryaction' },
|
|
214
|
+
h('button', { type: 'button', className: 'ps-btn ps-btn-primary', onClick: onOpenConfirm, disabled: Boolean(busy) || summary.patchWritable === false },
|
|
215
|
+
'一键休眠 ' + idle.length + ' 个吃灰插件'),
|
|
216
|
+
summary.patchWritable === false ? h('p', { className: 'ps-heronote' }, '当前补丁配置不可写,请检查文件权限后再试。') : null) : null),
|
|
217
|
+
confirmOpen && idle.length > 0 ? h('div', { className: 'ps-confirm', role: 'group', 'aria-label': '确认批量休眠' },
|
|
218
|
+
h('p', { className: 'ps-confirm-title' }, '确认让这 ' + idle.length + ' 个插件暂时休息?'),
|
|
219
|
+
h('p', null, '不会卸载插件。写入前自动备份;想恢复时,逐个点「唤醒」或撤销整批操作即可。'),
|
|
220
|
+
h('div', { className: 'ps-confirmlist' }, idle.map(function (plugin) {
|
|
221
|
+
return h('span', { className: 'ps-confirmitem', key: plugin.entryId }, plugin.name + ' · ' + formatNumber(plugin.alwaysLoadedTools) + ' 个工具')
|
|
222
|
+
})),
|
|
223
|
+
h('div', { className: 'ps-confirmactions' },
|
|
224
|
+
h('button', { type: 'button', className: 'ps-btn ps-btn-primary', onClick: function () { onConfirm(idle) }, disabled: Boolean(busy) }, busy === 'sleep-idle' ? '正在休眠…' : '确认休眠(自动备份,随时可恢复)'),
|
|
225
|
+
h('button', { type: 'button', className: 'ps-btn', onClick: onCancelConfirm, disabled: Boolean(busy) }, '取消'))) : null)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function ToolList(plugin) {
|
|
229
|
+
var tools = Array.isArray(plugin.tools) ? plugin.tools : []
|
|
230
|
+
return h('div', { className: 'ps-tools' }, tools.map(function (tool, index) {
|
|
231
|
+
return h('div', { className: 'ps-tool', key: tool.name || index },
|
|
232
|
+
h('div', { className: 'ps-tool-main' },
|
|
233
|
+
h('code', { className: 'ps-tool-name' }, tool.name || '未命名工具'),
|
|
234
|
+
tool.description ? h('div', { className: 'ps-tool-desc' }, tool.description) : null),
|
|
235
|
+
h('div', { className: 'ps-tool-meta' },
|
|
236
|
+
h('span', { className: 'ps-loadbadge' }, tool.deferred === true ? '延迟加载' : '常驻'),
|
|
237
|
+
h('span', null, formatNumber(tool.chars) + ' 字符 / ~' + formatNumber(tool.estimatedTokens) + ' tokens'),
|
|
238
|
+
h('span', null, tool.used30d === null || typeof tool.used30d === 'undefined' ? '近 30 天:未知' : '近 30 天:' + formatNumber(tool.used30d) + ' 次')))
|
|
239
|
+
}))
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function PluginCard(plugin, busy, expanded, onToggle, onExpand, patchWritable) {
|
|
243
|
+
var enabled = plugin.enabled === true
|
|
244
|
+
var toolCount = Array.isArray(plugin.tools) ? plugin.tools.length : 0
|
|
245
|
+
var busyThis = busy === 'toggle:' + plugin.entryId
|
|
246
|
+
return h('article', { className: 'ps-plugin', key: plugin.entryId || plugin.name },
|
|
247
|
+
h('div', { className: 'ps-plugin-main' },
|
|
248
|
+
h('div', { className: 'ps-plugin-info' },
|
|
249
|
+
h('div', { className: 'ps-plugin-topline' },
|
|
250
|
+
h('h3', { className: 'ps-plugin-name' }, plugin.name || plugin.entryId),
|
|
251
|
+
plugin.version ? h('span', { className: 'ps-version' }, 'v' + plugin.version) : null,
|
|
252
|
+
statusBadge(plugin.status)),
|
|
253
|
+
h('p', { className: 'ps-description' }, plugin.description || '这个插件没有填写简介。'),
|
|
254
|
+
h('div', { className: 'ps-metrics' },
|
|
255
|
+
h('span', null, formatNumber(plugin.alwaysLoadedTools) + ' 个常驻工具'),
|
|
256
|
+
h('span', { className: 'ps-metricsep', 'aria-hidden': 'true' }, '·'),
|
|
257
|
+
h('span', null, formatTokens(plugin.alwaysLoadedTokens) + '/轮'),
|
|
258
|
+
h('span', { className: 'ps-metricsep', 'aria-hidden': 'true' }, '·'),
|
|
259
|
+
h('span', null, usageText(plugin.used30d))),
|
|
260
|
+
toolCount > 0 ? h('button', { type: 'button', className: 'ps-tooltoggle', onClick: onExpand, 'aria-expanded': expanded ? 'true' : 'false' },
|
|
261
|
+
glyph('chevron', 13), expanded ? '收起工具详情' : '查看 ' + toolCount + ' 个工具') : null),
|
|
262
|
+
h('div', { className: 'ps-plugin-actions' },
|
|
263
|
+
h('button', {
|
|
264
|
+
type: 'button', className: 'ps-btn' + (enabled && plugin.status === 'idle-heavy' ? ' ps-btn-primary' : ''),
|
|
265
|
+
onClick: onToggle, disabled: Boolean(busy) || plugin.canToggle === false || patchWritable === false,
|
|
266
|
+
title: plugin.canToggle === false ? '此组件由宿主锁定,不能切换' : patchWritable === false ? '补丁配置不可写,请先检查文件权限' : enabled ? '暂时停用,不卸载;之后可随时唤醒' : '恢复这个插件',
|
|
267
|
+
}, busyThis ? (enabled ? '休眠中…' : '唤醒中…') : enabled ? '休眠' : '唤醒'))),
|
|
268
|
+
expanded && toolCount > 0 ? ToolList(plugin) : null)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function ProtectedDetails(report) {
|
|
272
|
+
var plugins = Array.isArray(report.plugins) ? report.plugins : []
|
|
273
|
+
var protectedPlugins = plugins.filter(function (plugin) { return plugin.protected === true || plugin.status === 'protected' })
|
|
274
|
+
var unattributed = Array.isArray(report.unattributedTools) ? report.unattributedTools : []
|
|
275
|
+
return h(React.Fragment, null,
|
|
276
|
+
protectedPlugins.length > 0 ? h('details', { className: 'ps-details' },
|
|
277
|
+
h('summary', null, glyph('lock', 14), '宿主核心与受保护组件(' + protectedPlugins.length + ' 个,已锁定防误关)'),
|
|
278
|
+
h('div', { className: 'ps-details-body' }, protectedPlugins.map(function (plugin, index) {
|
|
279
|
+
return h('div', { className: 'ps-protectedrow', key: plugin.entryId || index },
|
|
280
|
+
h('span', { className: 'ps-protectedname' }, plugin.name || plugin.entryId),
|
|
281
|
+
h('span', { className: 'ps-protectreason' }, plugin.protectReason || '宿主核心或轻装自保护,已锁定'))
|
|
282
|
+
}))) : null,
|
|
283
|
+
unattributed.length > 0 ? h('details', { className: 'ps-details' },
|
|
284
|
+
h('summary', null, '另有 ' + unattributed.length + ' 个未归因工具(多为宿主内置工具)'),
|
|
285
|
+
h('div', { className: 'ps-details-body' },
|
|
286
|
+
h('p', null, '它们无法可靠对应到某个已安装插件,因此单列说明,不参与「吃灰插件」建议。'),
|
|
287
|
+
h('div', { className: 'ps-unattributed' }, unattributed.map(function (tool, index) {
|
|
288
|
+
return h('code', { key: tool.name || index, title: tool.description || tool.name }, tool.name || '未命名工具')
|
|
289
|
+
})))) : null)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function Footer() {
|
|
293
|
+
return h('footer', { className: 'ps-footer' },
|
|
294
|
+
h('p', null, '估算仅计常驻工具 schema 定义体积,不含系统提示词与对话正文;所有修改自动备份,可随时撤销。'),
|
|
295
|
+
h('div', { className: 'ps-footerlinks' },
|
|
296
|
+
h('span', null, '如需按工作流整理能力包,可使用完整版「归置 dsh-guizhi」。'),
|
|
297
|
+
h('a', { href: 'https://github.com/fanyingnie2163663/dsh-plugin-slim/issues', target: '_blank', rel: 'noreferrer' }, '问题反馈 ↗')))
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return function Page() {
|
|
301
|
+
var reportState = useState(null)
|
|
302
|
+
var report = reportState[0]
|
|
303
|
+
var setReport = reportState[1]
|
|
304
|
+
var loadingState = useState(true)
|
|
305
|
+
var loading = loadingState[0]
|
|
306
|
+
var setLoading = loadingState[1]
|
|
307
|
+
var errorState = useState('')
|
|
308
|
+
var loadError = errorState[0]
|
|
309
|
+
var setLoadError = errorState[1]
|
|
310
|
+
var actionErrorState = useState('')
|
|
311
|
+
var actionError = actionErrorState[0]
|
|
312
|
+
var setActionError = actionErrorState[1]
|
|
313
|
+
var busyState = useState('')
|
|
314
|
+
var busy = busyState[0]
|
|
315
|
+
var setBusy = busyState[1]
|
|
316
|
+
var feedbackState = useState(null)
|
|
317
|
+
var feedback = feedbackState[0]
|
|
318
|
+
var setFeedback = feedbackState[1]
|
|
319
|
+
var confirmState = useState(false)
|
|
320
|
+
var confirmOpen = confirmState[0]
|
|
321
|
+
var setConfirmOpen = confirmState[1]
|
|
322
|
+
var filterState = useState('all')
|
|
323
|
+
var filter = filterState[0]
|
|
324
|
+
var setFilter = filterState[1]
|
|
325
|
+
var queryState = useState('')
|
|
326
|
+
var query = queryState[0]
|
|
327
|
+
var setQuery = queryState[1]
|
|
328
|
+
var expandedState = useState({})
|
|
329
|
+
var expanded = expandedState[0]
|
|
330
|
+
var setExpanded = expandedState[1]
|
|
331
|
+
var alive = useRef(true)
|
|
332
|
+
var requestSerial = useRef(0)
|
|
333
|
+
|
|
334
|
+
function loadReport() {
|
|
335
|
+
var serial = ++requestSerial.current
|
|
336
|
+
setLoading(true)
|
|
337
|
+
setLoadError('')
|
|
338
|
+
request('report').then(function (data) {
|
|
339
|
+
if (!alive.current || serial !== requestSerial.current) return
|
|
340
|
+
setReport(data)
|
|
341
|
+
setLoading(false)
|
|
342
|
+
setConfirmOpen(false)
|
|
343
|
+
setActionError('')
|
|
344
|
+
}).catch(function (error) {
|
|
345
|
+
if (!alive.current || serial !== requestSerial.current) return
|
|
346
|
+
setLoadError(readableError(error))
|
|
347
|
+
setLoading(false)
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
useEffect(function () {
|
|
352
|
+
alive.current = true
|
|
353
|
+
loadReport()
|
|
354
|
+
return function () { alive.current = false }
|
|
355
|
+
}, [])
|
|
356
|
+
|
|
357
|
+
function refresh() {
|
|
358
|
+
setFeedback(null)
|
|
359
|
+
loadReport()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function operate(kind, payload, busyKey) {
|
|
363
|
+
if (busy) return
|
|
364
|
+
setBusy(busyKey)
|
|
365
|
+
setActionError('')
|
|
366
|
+
request(kind, { method: 'POST', body: JSON.stringify(payload) }).then(function (data) {
|
|
367
|
+
if (!alive.current) return
|
|
368
|
+
if (data.report) setReport(data.report)
|
|
369
|
+
var message = data.message || '操作已完成'
|
|
370
|
+
if (kind === 'toggle' && data.applied) {
|
|
371
|
+
message = data.changed === false
|
|
372
|
+
? data.applied.name + ' 的状态没有变化'
|
|
373
|
+
: data.applied.name + (data.applied.disabled ? ' 已休眠' : ' 已唤醒')
|
|
374
|
+
} else if (kind === 'sleep-idle') {
|
|
375
|
+
message = '已休眠 ' + formatNumber(data.count) + ' 个吃灰插件'
|
|
376
|
+
}
|
|
377
|
+
setFeedback({
|
|
378
|
+
kind: kind,
|
|
379
|
+
message: message,
|
|
380
|
+
hint: data.hotReloadHint || '',
|
|
381
|
+
snapshotId: kind === 'undo' ? null : data.snapshotId || null,
|
|
382
|
+
})
|
|
383
|
+
setConfirmOpen(false)
|
|
384
|
+
setBusy('')
|
|
385
|
+
}).catch(function (error) {
|
|
386
|
+
if (!alive.current) return
|
|
387
|
+
setActionError(readableError(error))
|
|
388
|
+
setBusy('')
|
|
389
|
+
})
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function undo(snapshotId) {
|
|
393
|
+
operate('undo', snapshotId ? { snapshotId: snapshotId } : {}, 'undo')
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
var manageable = useMemo(function () {
|
|
397
|
+
if (!report || !Array.isArray(report.plugins)) return []
|
|
398
|
+
return report.plugins.filter(function (plugin) { return plugin.protected !== true && plugin.status !== 'protected' })
|
|
399
|
+
}, [report])
|
|
400
|
+
|
|
401
|
+
var counts = useMemo(function () {
|
|
402
|
+
return {
|
|
403
|
+
all: manageable.length,
|
|
404
|
+
idle: manageable.filter(function (p) { return p.status === 'idle-heavy' }).length,
|
|
405
|
+
active: manageable.filter(function (p) { return p.status === 'active-heavy' || p.status === 'heavy-unknown' }).length,
|
|
406
|
+
zero: manageable.filter(function (p) { return p.status === 'zero-burden' }).length,
|
|
407
|
+
sleeping: manageable.filter(function (p) { return p.status === 'sleeping' }).length,
|
|
408
|
+
}
|
|
409
|
+
}, [manageable])
|
|
410
|
+
|
|
411
|
+
var visible = useMemo(function () {
|
|
412
|
+
var needle = query.trim().toLocaleLowerCase()
|
|
413
|
+
return manageable.filter(function (plugin) {
|
|
414
|
+
var inFilter = filter === 'all'
|
|
415
|
+
|| (filter === 'idle' && plugin.status === 'idle-heavy')
|
|
416
|
+
|| (filter === 'active' && (plugin.status === 'active-heavy' || plugin.status === 'heavy-unknown'))
|
|
417
|
+
|| (filter === 'zero' && plugin.status === 'zero-burden')
|
|
418
|
+
|| (filter === 'sleeping' && plugin.status === 'sleeping')
|
|
419
|
+
if (!inFilter) return false
|
|
420
|
+
if (!needle) return true
|
|
421
|
+
var tools = Array.isArray(plugin.tools) ? plugin.tools.map(function (tool) { return tool.name || '' }).join(' ') : ''
|
|
422
|
+
return String(plugin.name || '').toLocaleLowerCase().indexOf(needle) !== -1
|
|
423
|
+
|| String(plugin.description || '').toLocaleLowerCase().indexOf(needle) !== -1
|
|
424
|
+
|| tools.toLocaleLowerCase().indexOf(needle) !== -1
|
|
425
|
+
})
|
|
426
|
+
}, [manageable, filter, query])
|
|
427
|
+
|
|
428
|
+
var initialFailure = !report && !loading && loadError
|
|
429
|
+
return h('main', { className: 'ps-root' },
|
|
430
|
+
Header(report, loading, busy, refresh, function () { undo(null) }),
|
|
431
|
+
loadError && report ? h('div', { className: 'ps-banner ps-banner-error', role: 'alert' },
|
|
432
|
+
h('div', { className: 'ps-banner-body' }, h('div', { className: 'ps-banner-title' }, '重新体检失败'), h('div', { className: 'ps-banner-hint' }, loadError)),
|
|
433
|
+
h('button', { type: 'button', className: 'ps-btn ps-btn-small', onClick: refresh }, '重试')) : null,
|
|
434
|
+
actionError ? h('div', { className: 'ps-banner ps-banner-error', role: 'alert' },
|
|
435
|
+
h('div', { className: 'ps-banner-body' }, h('div', { className: 'ps-banner-title' }, '这次操作没有完成'), h('div', { className: 'ps-banner-hint' }, actionError + ';可点击「重新体检」确认当前状态。')),
|
|
436
|
+
h('button', { type: 'button', className: 'ps-btn ps-btn-small', onClick: function () { setActionError('') } }, '知道了')) : null,
|
|
437
|
+
feedback ? h('div', { className: 'ps-banner ps-banner-success', role: 'status' },
|
|
438
|
+
glyph('check', 17),
|
|
439
|
+
h('div', { className: 'ps-banner-body' }, h('div', { className: 'ps-banner-title' }, feedback.message), feedback.hint ? h('div', { className: 'ps-banner-hint' }, feedback.hint) : null),
|
|
440
|
+
feedback.snapshotId ? h('button', { type: 'button', className: 'ps-btn ps-btn-small', onClick: function () { undo(feedback.snapshotId) }, disabled: Boolean(busy) }, busy === 'undo' ? '撤销中…' : '撤销') : null) : null,
|
|
441
|
+
loading && !report ? LoadingHero() : null,
|
|
442
|
+
initialFailure ? h('section', { className: 'ps-hero' }, h('div', { className: 'ps-herobody' },
|
|
443
|
+
h('div', { className: 'ps-eyebrow' }, '暂时无法完成体检'),
|
|
444
|
+
h('p', { className: 'ps-conclusion' }, '轻装没有拿到插件报告,未对你的配置做任何修改。'),
|
|
445
|
+
h('p', { className: 'ps-heronote' }, loadError),
|
|
446
|
+
h('div', { className: 'ps-primaryaction' }, h('button', { type: 'button', className: 'ps-btn ps-btn-primary', onClick: refresh }, '重试')))) : null,
|
|
447
|
+
report ? h(React.Fragment, null,
|
|
448
|
+
Hero(report, confirmOpen, busy, function () { setConfirmOpen(true) }, function () { setConfirmOpen(false) }, function (idle) {
|
|
449
|
+
operate('sleep-idle', { entryIds: idle.map(function (plugin) { return plugin.entryId }) }, 'sleep-idle')
|
|
450
|
+
}),
|
|
451
|
+
report.summary && report.summary.patchWritable === false ? h('div', { className: 'ps-banner ps-banner-error' }, '当前补丁配置不可写,休眠与唤醒暂不可用;请先检查配置文件的写入权限。') : null,
|
|
452
|
+
Array.isArray(report.warnings) && report.warnings.length > 0 ? h('div', { className: 'ps-banner' }, h('ul', { className: 'ps-warninglist' }, report.warnings.map(function (warning, index) { return h('li', { key: index }, String(warning)) }))) : null,
|
|
453
|
+
h('section', { 'aria-labelledby': 'ps-list-title' },
|
|
454
|
+
h('div', { className: 'ps-listhead' },
|
|
455
|
+
h('div', null, h('h2', { className: 'ps-sectiontitle', id: 'ps-list-title' }, '插件清单'), h('p', { className: 'ps-sectionnote' }, '只列可管理插件;受保护核心已默认折叠并锁定。')),
|
|
456
|
+
h('label', { className: 'ps-search' }, glyph('search', 15), h('input', { type: 'search', value: query, placeholder: '搜索插件、简介或工具', 'aria-label': '搜索插件、简介或工具', onChange: function (event) { setQuery(event.target.value) } }))),
|
|
457
|
+
h('div', { className: 'ps-tabs', role: 'tablist', 'aria-label': '按状态筛选插件' }, FILTERS.map(function (item) {
|
|
458
|
+
return h('button', { key: item.id, type: 'button', className: 'ps-tab', role: 'tab', 'aria-selected': filter === item.id ? 'true' : 'false', onClick: function () { setFilter(item.id) } }, item.label, h('span', { className: 'ps-count' }, counts[item.id]))
|
|
459
|
+
})),
|
|
460
|
+
h('div', { className: 'ps-plugins', role: 'tabpanel', style: { marginTop: '10px' } }, visible.length > 0 ? visible.map(function (plugin) {
|
|
461
|
+
return PluginCard(plugin, busy, expanded[plugin.entryId] === true, function () {
|
|
462
|
+
operate('toggle', { entryId: plugin.entryId, disabled: plugin.enabled === true }, 'toggle:' + plugin.entryId)
|
|
463
|
+
}, function () {
|
|
464
|
+
var next = Object.assign({}, expanded)
|
|
465
|
+
next[plugin.entryId] = !next[plugin.entryId]
|
|
466
|
+
setExpanded(next)
|
|
467
|
+
}, report.summary && report.summary.patchWritable)
|
|
468
|
+
}) : h('div', { className: 'ps-empty' }, h('strong', null, query ? '没有找到匹配的插件' : '这个分类现在是空的'), query ? '换个关键词试试,或清空搜索。' : '可以切到「全部」查看其他插件。'))),
|
|
469
|
+
ProtectedDetails(report),
|
|
470
|
+
Footer()) : null)
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function createPanelPlugin(React) {
|
|
475
|
+
var Icon = createIcon(React)
|
|
476
|
+
var Page = createPage(React)
|
|
477
|
+
return {
|
|
478
|
+
name: 'dsh-plugin-slim',
|
|
479
|
+
inject: ['slots'],
|
|
480
|
+
apply: function (ctx) {
|
|
481
|
+
if (!ctx || !ctx.slots || typeof ctx.slots.inject !== 'function') {
|
|
482
|
+
console.warn('[plugin-slim] slots service missing')
|
|
483
|
+
return
|
|
484
|
+
}
|
|
485
|
+
ensureStyle()
|
|
486
|
+
var disposers = []
|
|
487
|
+
try {
|
|
488
|
+
disposers.push(ctx.slots.inject(SLOT_PANEL_LIST, function () {
|
|
489
|
+
return ctx.slots.register({
|
|
490
|
+
name: SLOT_PANEL_LIST, id: PANEL_ID, order: 21,
|
|
491
|
+
label: function () { return '轻装' },
|
|
492
|
+
}, Icon)
|
|
493
|
+
}))
|
|
494
|
+
disposers.push(ctx.slots.inject(SLOT_MAIN, function () {
|
|
495
|
+
return ctx.slots.register({ name: SLOT_MAIN, key: PANEL_ID }, Page)
|
|
496
|
+
}))
|
|
497
|
+
} catch (error) {
|
|
498
|
+
console.warn('[plugin-slim] panel registration failed', error)
|
|
499
|
+
}
|
|
500
|
+
if (typeof ctx.effect === 'function') {
|
|
501
|
+
ctx.effect(function () {
|
|
502
|
+
return function () {
|
|
503
|
+
disposers.forEach(function (dispose) {
|
|
504
|
+
if (typeof dispose === 'function') {
|
|
505
|
+
try { dispose() } catch (_) { /* Host cleanup must stay isolated. */ }
|
|
506
|
+
}
|
|
507
|
+
})
|
|
508
|
+
disposers.length = 0
|
|
509
|
+
}
|
|
510
|
+
})
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (typeof window !== 'undefined' && window.__ModuleLoader__ && typeof window.__ModuleLoader__.load === 'function') {
|
|
517
|
+
window.__ModuleLoader__.load({
|
|
518
|
+
id: 'dsh-plugin-slim',
|
|
519
|
+
factory: function (require) {
|
|
520
|
+
return createPanelPlugin(require('react'))
|
|
521
|
+
},
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
})()
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="轻装 Plugin Slim">
|
|
2
|
+
<rect width="128" height="128" rx="28" fill="#182722"/>
|
|
3
|
+
<g fill="none" stroke-linecap="round" stroke-linejoin="round">
|
|
4
|
+
<path d="M90 30C68 30 48 44 42 66c-3 11-2 22-4 32 10-2 21-1 32-4 22-6 36-26 36-48 0-8-7-16-16-16z" stroke="#8fd1b0" stroke-width="5"/>
|
|
5
|
+
<path d="M38 98c12-12 28-28 48-44" stroke="#d8ece1" stroke-width="4.5"/>
|
|
6
|
+
<path d="M26 76h24M22 92h18" stroke="#8fd1b0" stroke-width="4" opacity=".75"/>
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|