dsh-remote-plugin 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +29 -48
- package/README.md +29 -48
- package/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +147 -77
- package/index.mjs +52 -9
- package/package.json +4 -2
- package/plugin-center.mjs +126 -26
- package/public/admin.js +15 -2
- package/public/app.js +249 -96
- package/public/chat-files.js +17 -0
- package/public/desktop/desktop.css +5 -0
- package/public/desktop/desktop.html +17 -2
- package/public/desktop/desktop.js +269 -100
- package/public/extensions.css +1 -0
- package/public/extensions.js +103 -0
- package/public/history.js +42 -14
- package/public/index.html +11 -1
- package/public/insights.css +2 -0
- package/public/insights.js +50 -23
- package/public/md.js +13 -12
- package/public/network.js +56 -0
- package/public/plugin-center.css +7 -3
- package/public/plugin-center.js +76 -18
- package/public/plugin.js +8 -1
- package/public/skills.css +81 -0
- package/public/skills.js +191 -0
- package/public/styles.css +7 -0
- package/public/theme-vars.css +5 -0
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/session-file.mjs +34 -0
- package/skills.mjs +53 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* Small transport policy and independent fallback channels. No dependencies. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
let measuredLatency=0
|
|
5
|
+
function mode(){try{return ['auto','weak','normal'].includes(root.localStorage.getItem('dshNetworkModeV1'))?root.localStorage.getItem('dshNetworkModeV1'):'auto'}catch{return 'auto'}}
|
|
6
|
+
function profile(){
|
|
7
|
+
const selected=mode(),connection=root.navigator?.connection
|
|
8
|
+
const weak=selected==='weak'||selected==='auto'&&(!!connection?.saveData||/^(slow-2g|2g|3g)$/.test(connection?.effectiveType||'')||connection?.rtt>=500||connection?.downlink>0&&connection.downlink<0.8||measuredLatency>=800)
|
|
9
|
+
return {weak,historyPageSize:weak?20:60,readTimeout:weak?90000:45000,pingTimeout:weak?12000:6000,pollTimeout:weak?45000:30000}
|
|
10
|
+
}
|
|
11
|
+
function setMode(value){if(!['auto','weak','normal'].includes(value))return;try{root.localStorage.setItem('dshNetworkModeV1',value)}catch{};return profile()}
|
|
12
|
+
class PollLoop {
|
|
13
|
+
constructor(options){this.options=options;this.jobs={};this.setTimer=options.setTimer||setTimeout;this.clearTimer=options.clearTimer||clearTimeout}
|
|
14
|
+
stop(){for(const job of Object.values(this.jobs)){job.controller.abort();this.clearTimer(job.timer)}this.jobs={}}
|
|
15
|
+
tick(){
|
|
16
|
+
if(!this.options.active()){this.stop();return Promise.resolve()}
|
|
17
|
+
const pending=[]
|
|
18
|
+
for(const kind of ['mux','host']){
|
|
19
|
+
const previous=this.jobs[kind]
|
|
20
|
+
if(previous?.identity.valid())continue
|
|
21
|
+
previous?.controller.abort();this.clearTimer(previous?.timer)
|
|
22
|
+
const job={identity:this.options.capture(),controller:new AbortController(),failures:0}
|
|
23
|
+
this.jobs[kind]=job;pending.push(this.run(kind,job))
|
|
24
|
+
}
|
|
25
|
+
return Promise.all(pending)
|
|
26
|
+
}
|
|
27
|
+
async run(kind,job){
|
|
28
|
+
let delay
|
|
29
|
+
try{delay=await this.options.read(kind,job.controller.signal)}catch{}
|
|
30
|
+
if(this.jobs[kind]!==job||!job.identity.valid()||!this.options.active()||job.controller.signal.aborted)return
|
|
31
|
+
if(Number.isFinite(delay)){job.failures=0;delay=Math.max(100,delay)}
|
|
32
|
+
else{job.failures++;delay=Math.min(30000,4000*2**Math.min(job.failures-1,3))}
|
|
33
|
+
job.timer=this.setTimer(()=>{job.timer=null;if(this.jobs[kind]===job&&job.identity.valid()&&this.options.active())void this.run(kind,job)},delay)
|
|
34
|
+
job.timer?.unref?.()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function preferences(){
|
|
38
|
+
const panel=root.document?.getElementById('settings-page-general');if(!panel)return
|
|
39
|
+
let row=root.document.getElementById('network-preferences')
|
|
40
|
+
if(!row){
|
|
41
|
+
row=root.document.createElement('div');row.id='network-preferences';row.className=panel.classList.contains('ds-settings')?'ds-setting-row':'setting-row'
|
|
42
|
+
const copy=root.document.createElement('div'),title=root.document.createElement('div'),detail=root.document.createElement('div'),select=root.document.createElement('select')
|
|
43
|
+
title.dataset.networkTitle='';detail.dataset.networkDetail='';detail.className='muted';select.id='network-mode';select.className='setting-select'
|
|
44
|
+
for(const value of ['auto','weak','normal']){const option=root.document.createElement('option');option.value=value;select.append(option)}
|
|
45
|
+
copy.append(title,detail);row.append(copy,select);panel.append(row)
|
|
46
|
+
select.addEventListener('change',()=>{setMode(select.value);root.enhanceCustomSelect?.(select)})
|
|
47
|
+
}
|
|
48
|
+
const english=root.I18N?.lang==='en'
|
|
49
|
+
row.querySelector('[data-network-title]').textContent=english?'Network mode':'网络模式'
|
|
50
|
+
row.querySelector('[data-network-detail]').textContent=english?'Weak mode loads fewer history entries and allows longer read waits. Sending is never retried automatically.':'弱网模式减少每页历史条数、延长读取等待;发送操作不会自动重试。'
|
|
51
|
+
const select=row.querySelector('select');select.setAttribute('aria-label',english?'Network mode':'网络模式');['auto','weak','normal'].forEach((v,i)=>select.options[i].textContent=(english?['Automatic','Weak network','Standard']:['自动判断','弱网优先','标准模式'])[i]);select.value=mode();root.enhanceCustomSelect?.(select);root.syncCustomSelect?.(select)
|
|
52
|
+
}
|
|
53
|
+
const api={profile,setMode,PollLoop,observeLatency:ms=>{if(Number.isFinite(ms))measuredLatency=ms},preferences}
|
|
54
|
+
if(typeof module!=='undefined'&&module.exports)module.exports=api
|
|
55
|
+
else{root.DshNetwork=api;root.document.addEventListener('DOMContentLoaded',()=>{preferences();new MutationObserver(preferences).observe(root.document.documentElement,{attributes:true,attributeFilter:['lang']})})}
|
|
56
|
+
})(typeof window==='undefined'?globalThis:window)
|
package/public/plugin-center.css
CHANGED
|
@@ -52,8 +52,9 @@
|
|
|
52
52
|
.pc-toggle::after{content:'';position:absolute;top:4px;left:4px;width:16px;height:16px;border-radius:50%;background:var(--dsr-muted,#a7b0bc);transition:transform .15s}
|
|
53
53
|
.pc-dialog .pc-toggle[aria-checked=true]{background:var(--dsr-accent,#58a6ff);border-color:var(--dsr-accent,#58a6ff)}
|
|
54
54
|
.pc-toggle[aria-checked=true]::after{transform:translateX(16px);background:var(--dsr-on-accent,#07111f)}
|
|
55
|
-
.pc-card-actions{display:flex;align-items:center;gap:6px;border-top:1px solid var(--dsr-line,#30363d);padding-top:12px;margin-top:auto}
|
|
56
|
-
.pc-card-actions button{border-color:transparent;background:transparent;font-size:12px;padding:8px 10px}
|
|
55
|
+
.pc-card-actions{display:flex;flex-wrap:wrap;align-items:center;gap:6px;border-top:1px solid var(--dsr-line,#30363d);padding-top:12px;margin-top:auto}
|
|
56
|
+
.pc-card-actions button{flex-shrink:0;white-space:nowrap;border-color:transparent;background:transparent;font-size:12px;padding:8px 10px}
|
|
57
|
+
.pc-card-actions .pc-open-feature{flex:1 0 100%;border-color:var(--dsr-accent-line,#58a6ff66);background:var(--dsr-accent-soft,#58a6ff1f);color:var(--dsr-accent-strong,#79c0ff);margin-bottom:4px}
|
|
57
58
|
.pc-card-actions .pc-detail-button{background:var(--dsr-accent-soft,#58a6ff1f);color:var(--dsr-accent-strong,#79c0ff);margin-right:auto}
|
|
58
59
|
.pc-card-actions .pc-danger-button{color:var(--dsr-muted,#a7b0bc)}
|
|
59
60
|
.pc-card-actions .pc-danger-button:hover{background:var(--dsr-error-soft,#ff8f6b24);color:var(--dsr-error,#ff8f6b);border-color:transparent}
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
.pc-dialog{padding:18px}.pc-page{padding:6px 0 24px}.pc-dialog h2{font-size:24px}
|
|
81
82
|
.pc-context{align-items:flex-start;flex-direction:column;gap:10px;margin:18px 0}.pc-summary{gap:24px}
|
|
82
83
|
.pc-controls{padding:10px;margin-bottom:16px}.pc-toolbar{gap:4px}.pc-tabs{flex:1}
|
|
83
|
-
.pc-tabs button{flex:1;padding:9px
|
|
84
|
+
.pc-tabs button{flex:1;padding:9px 6px;font-size:12px}.pc-tabs{overflow-x:auto}
|
|
84
85
|
.pc-filters:not([hidden]),.pc-market-tools:not([hidden]){gap:7px}
|
|
85
86
|
.pc-dialog input,.pc-dialog select{font-size:12px;padding:11px 9px}
|
|
86
87
|
.pc-card{padding:16px}.pc-card-actions button{min-height:40px;padding:9px 10px}
|
|
@@ -98,3 +99,6 @@
|
|
|
98
99
|
|
|
99
100
|
.pc-list { align-items:start; }
|
|
100
101
|
.pc-inline-detail button,.pc-card-actions button { min-height:44px; }
|
|
102
|
+
.pc-progress:not([hidden]) { border:1px solid var(--dsr-accent-line,#58a6ff66); border-radius:12px; padding:12px 14px; margin-bottom:16px; background:var(--dsr-accent-soft,#58a6ff1f); overflow-wrap:anywhere; }
|
|
103
|
+
.pc-progress p { margin:8px 0 0; font-size:13px; }
|
|
104
|
+
.pc-job-progress { color:var(--dsr-muted,#a7b0bc); }
|
package/public/plugin-center.js
CHANGED
|
@@ -3,8 +3,21 @@
|
|
|
3
3
|
window.DshPluginCenter = (() => {
|
|
4
4
|
let dialog, connection, snapshot, timer, generation = 0, pending = false, tab = 'installed', offset = 0, searchSequence = 0, detailSequence = 0
|
|
5
5
|
const expandedDetails = new Map()
|
|
6
|
-
let renderedInstalled = '', renderedJobs = '', filter = '', statusFilter = 'all', refreshSequence = 0
|
|
6
|
+
let renderedInstalled = '', renderedJobs = '', filter = '', statusFilter = 'all', refreshSequence = 0, trackedOperation = ''
|
|
7
7
|
const labels = { install: '安装', update: '更新', remove: '卸载', enable: '启用', disable: '停用', queued: '等待执行', running: '执行中', complete: '已完成', failed: '失败', interrupted: '已中断', active: '运行中', pending: '等待依赖', loading: '加载中', disposed: '未运行', unloading: '卸载中', inactive: '未运行' }
|
|
8
|
+
const stages = { queued: '等待主机启动', backup: '备份配置', 'profile-lock': '检查配置锁', cli: '执行插件命令', verify: '保存并核验', complete: '完成' }
|
|
9
|
+
function jobProgress(job) {
|
|
10
|
+
const active = ['queued', 'running'].includes(job.phase), now = Date.now()
|
|
11
|
+
const elapsed = Math.max(0, Math.floor(((active ? now : job.endedAt || now) - job.startedAt) / 1000))
|
|
12
|
+
const parts = [stages[job.stage] || labels[job.phase] || job.phase, '耗时 ' + elapsed + ' 秒']
|
|
13
|
+
if (active && job.updatedAt && now - job.updatedAt > 15000) parts.push('主机任务状态超过 15 秒未更新,正在重新核对进程')
|
|
14
|
+
if (active && job.stage === 'cli') {
|
|
15
|
+
const silence = Math.max(0, Math.floor((now - (job.lastOutputAt || job.startedAt)) / 1000))
|
|
16
|
+
parts.push(job.lastOutputAt ? '最近输出在 ' + silence + ' 秒前' : '等待首次输出')
|
|
17
|
+
if (silence >= 30) parts.push('暂无新输出,命令仍待结束;请展开日志检查网络或锁占用')
|
|
18
|
+
}
|
|
19
|
+
return parts.join(' · ')
|
|
20
|
+
}
|
|
8
21
|
function node(tag, text, className) {
|
|
9
22
|
const el = document.createElement(tag)
|
|
10
23
|
if (text != null) el.textContent = text
|
|
@@ -46,10 +59,10 @@ window.DshPluginCenter = (() => {
|
|
|
46
59
|
function renderInstalled() {
|
|
47
60
|
const list = dialog.querySelector('.pc-list'), restore = preserveListPosition(list); list.replaceChildren()
|
|
48
61
|
if (!snapshot) { list.append(node('p', '尚未读取插件状态,请点击刷新。')); return }
|
|
49
|
-
const rows = snapshot.items.filter(item => tab === 'builtin' ? !item.managed : item.managed)
|
|
62
|
+
const rows = snapshot.items.filter(item => tab === 'builtin' ? !item.managed && item.name !== 'dsh-remote-plugin' : item.managed || item.name === 'dsh-remote-plugin')
|
|
50
63
|
.filter(item => [item.name, item.displayName, item.description].join(' ').toLowerCase().includes(filter.toLowerCase()))
|
|
51
64
|
.filter(item => statusFilter === 'all' || (statusFilter === 'enabled' ? item.enabled : !item.enabled))
|
|
52
|
-
if (!rows.length) list.append(node('p', filter || statusFilter !== 'all' ? '没有匹配的插件。' : tab === 'builtin' ? '暂无内置插件。' : '
|
|
65
|
+
if (!rows.length) list.append(node('p', filter || statusFilter !== 'all' ? '没有匹配的插件。' : tab === 'builtin' ? '暂无内置插件。' : '当前主机没有其他已安装插件。第三方插件可按需选择。', 'pc-empty'))
|
|
53
66
|
for (const item of rows) {
|
|
54
67
|
const el = card(item.displayName || item.name, item.description)
|
|
55
68
|
el.append(node('small', item.name, 'pc-package'))
|
|
@@ -75,7 +88,16 @@ window.DshPluginCenter = (() => {
|
|
|
75
88
|
}
|
|
76
89
|
const remove = button('卸载', () => mutate('remove', item.name)); remove.className = 'pc-danger-button'; actions.append(remove)
|
|
77
90
|
for (const action of actions.children) if (action !== detail) action.disabled = pending || snapshot.busy
|
|
91
|
+
} else if (item.selfUpdate && snapshot.writable) {
|
|
92
|
+
const update = button('更新 Remote', () => showDetails(item.name, '', area, detail, true))
|
|
93
|
+
update.disabled = snapshot.busy || pending; actions.append(update)
|
|
78
94
|
} else actions.append(node('small', '主机维护 · 只读'))
|
|
95
|
+
if (connection.onFeature) {
|
|
96
|
+
for (const feature of window.DshExtensions?.featuresFor(snapshot, item, !!connection.getSession?.()?.sessionId) || []) {
|
|
97
|
+
const action = button(feature.label, () => connection.onFeature(feature.id))
|
|
98
|
+
action.className = 'pc-open-feature'; actions.prepend(action)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
79
101
|
el.dataset.plugin = item.name
|
|
80
102
|
detail.setAttribute('aria-controls', area.id)
|
|
81
103
|
renderInline(area, detail, item)
|
|
@@ -140,7 +162,7 @@ window.DshPluginCenter = (() => {
|
|
|
140
162
|
area.append(input, button('查看此版本', () => showDetails(entry.name, input.value.trim(), area, control, true)))
|
|
141
163
|
const row = snapshot?.items.find(row => row.name === item.name), action = row ? 'update' : 'install'
|
|
142
164
|
const install = button(labels[action] + ' ' + item.version, () => mutate(action, item.name, item.version))
|
|
143
|
-
install.disabled = !item.bundle || item.protected || !snapshot?.writable || snapshot.busy || pending || row?.version === item.version
|
|
165
|
+
install.disabled = !item.bundle || item.protected && !(row?.selfUpdate && action === 'update') || !snapshot?.writable || snapshot.busy || pending || row?.version === item.version
|
|
144
166
|
area.append(install)
|
|
145
167
|
}
|
|
146
168
|
function installedDetails(item, area, control) {
|
|
@@ -160,6 +182,12 @@ window.DshPluginCenter = (() => {
|
|
|
160
182
|
try { data = await api('/state') } catch (error) { if (sequence === refreshSequence) throw error; return }
|
|
161
183
|
if (sequence !== refreshSequence) return
|
|
162
184
|
snapshot = data
|
|
185
|
+
window.DshExtensions?.remember(connection, snapshot)
|
|
186
|
+
const tracked = snapshot.operations.find(job => job.id === trackedOperation)
|
|
187
|
+
if (tracked && !['queued', 'running'].includes(tracked.phase)) {
|
|
188
|
+
message((labels[tracked.phase] || tracked.phase) + ':' + tracked.name + '。' + (tracked.message || '请查看操作记录。'))
|
|
189
|
+
trackedOperation = ''
|
|
190
|
+
}
|
|
163
191
|
const recovery = dialog.querySelector('.pc-recovery'); recovery.replaceChildren()
|
|
164
192
|
if (snapshot.recovery) {
|
|
165
193
|
recovery.append(node('p', snapshot.recovery.reason))
|
|
@@ -175,24 +203,33 @@ window.DshPluginCenter = (() => {
|
|
|
175
203
|
dialog.querySelector('.pc-status').textContent = snapshot.reason || (snapshot.pendingRestart ? '插件配置已变更,重启 DSH 后生效。' : '安装到当前连接的 DSH 主机。')
|
|
176
204
|
dialog.querySelector('.pc-status').hidden = !snapshot.reason && !snapshot.pendingRestart
|
|
177
205
|
const summary = dialog.querySelector('.pc-summary'); summary.replaceChildren()
|
|
178
|
-
for (const [count, title] of [[snapshot.items.filter(item => item.managed).length, '已安装'], [snapshot.items.filter(item => item.managed && item.enabled).length, '配置启用']]) {
|
|
206
|
+
for (const [count, title] of [[snapshot.items.filter(item => item.managed || item.name === 'dsh-remote-plugin').length, '已安装'], [snapshot.items.filter(item => (item.managed || item.name === 'dsh-remote-plugin') && item.enabled).length, '配置启用']]) {
|
|
179
207
|
const stat = node('span', null, 'pc-stat'); stat.append(node('strong', String(count)), node('span', title)); summary.append(stat)
|
|
180
208
|
}
|
|
181
209
|
if (snapshot.busy) summary.append(node('span', '任务执行中', 'pc-badge'))
|
|
182
|
-
const
|
|
183
|
-
|
|
210
|
+
const progress = dialog.querySelector('.pc-progress'); progress.replaceChildren()
|
|
211
|
+
const activeJob = snapshot.operations.find(job => ['queued', 'running'].includes(job.phase))
|
|
212
|
+
if (activeJob) progress.append(node('strong', (labels[activeJob.action] || activeJob.action) + ' ' + activeJob.name), node('p', jobProgress(activeJob)), node('p', activeJob.message || '任务在主机执行,可关闭窗口后回来查看。'))
|
|
213
|
+
if (snapshot.busyReason) progress.append(node('p', snapshot.busyReason))
|
|
214
|
+
if (snapshot.profileLock) progress.append(node('p', snapshot.profileLock.message))
|
|
215
|
+
progress.hidden = !progress.children.length
|
|
216
|
+
const installedKey = JSON.stringify([snapshot.items, snapshot.runtime, snapshot.runtimeAvailable, snapshot.pendingRestart, snapshot.busy, snapshot.writable, pending, tab, filter, statusFilter])
|
|
217
|
+
if (['installed', 'builtin'].includes(tab) && installedKey !== renderedInstalled) { renderInstalled(); renderedInstalled = installedKey }
|
|
184
218
|
renderTabs()
|
|
185
|
-
const jobsKey = JSON.stringify(snapshot.operations)
|
|
219
|
+
const jobsKey = JSON.stringify(snapshot.operations.map(job => [job, jobProgress(job)]))
|
|
186
220
|
if (jobsKey === renderedJobs) return
|
|
187
221
|
renderedJobs = jobsKey
|
|
188
222
|
const jobs = dialog.querySelector('.pc-jobs')
|
|
223
|
+
const knownJobs = new Set([...jobs.children].map(el => el.dataset.id))
|
|
224
|
+
if (activeJob && !knownJobs.has(activeJob.id)) dialog.querySelector('.pc-history').open = true
|
|
189
225
|
const expanded = new Set([...jobs.querySelectorAll('details[open]')].map(el => el.dataset.id))
|
|
190
226
|
jobs.replaceChildren()
|
|
191
227
|
for (const job of snapshot.operations) {
|
|
192
228
|
const el = node('details')
|
|
193
|
-
el.dataset.id = job.id; el.open = expanded.has(job.id)
|
|
229
|
+
el.dataset.id = job.id; el.open = expanded.has(job.id) || !knownJobs.has(job.id) && ['queued', 'running'].includes(job.phase)
|
|
194
230
|
el.append(node('summary', (labels[job.action] || job.action) + ' ' + job.name + (job.version ? '@' + job.version : '') + ' · ' + (labels[job.phase] || job.phase)))
|
|
195
231
|
el.append(node('small', new Date(job.startedAt).toLocaleString()))
|
|
232
|
+
el.append(node('p', jobProgress(job), 'pc-job-progress'))
|
|
196
233
|
el.append(node('p', job.message || '任务在主机端执行,可关闭窗口后回来查看。'))
|
|
197
234
|
if (job.log) el.append(node('pre', job.log))
|
|
198
235
|
jobs.append(el)
|
|
@@ -244,9 +281,11 @@ window.DshPluginCenter = (() => {
|
|
|
244
281
|
// LAN HTTP is not a secure context; an idempotency key does not need WebCrypto.
|
|
245
282
|
const id = globalThis.crypto?.randomUUID?.() || `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`
|
|
246
283
|
const body = { id, action, name, ...(version ? { version } : {}), revision: snapshot.revision }
|
|
284
|
+
if (name === 'dsh-remote-plugin' && action === 'update') body.confirmSelfUpdate = true
|
|
247
285
|
const area = dialog.querySelector('.pc-detail')
|
|
248
286
|
const review = card('确认' + labels[action], name + (version ? '@' + version : ''))
|
|
249
287
|
review.append(node('p', '目标环境:' + snapshot.profile + '。配置修改后需要重启 DSH;不会自动重启。'))
|
|
288
|
+
if (body.confirmSelfUpdate) review.append(node('p', '更新当前主机的 Remote 插件本体,先备份配置与旧包,后台执行。重启 DSH 后新版本生效,连接可能短暂中断;此操作不会升级手机 App。'))
|
|
250
289
|
const confirm = button('确认' + labels[action], () => executeMutation(body)); confirm.className = action === 'remove' ? 'pc-danger-confirm' : 'pc-primary'
|
|
251
290
|
review.append(confirm, button('取消', () => area.replaceChildren()))
|
|
252
291
|
area.replaceChildren(review); area.scrollIntoView({ block: 'nearest' })
|
|
@@ -255,9 +294,12 @@ window.DshPluginCenter = (() => {
|
|
|
255
294
|
if (pending) return
|
|
256
295
|
const current = generation
|
|
257
296
|
pending = true
|
|
297
|
+
if (tab !== 'market') { renderInstalled(); renderedInstalled = '' }
|
|
298
|
+
for (const control of dialog.querySelector('.pc-detail').querySelectorAll('button')) control.disabled = true
|
|
258
299
|
try {
|
|
259
300
|
message('正在提交…')
|
|
260
301
|
await api(endpoint, body)
|
|
302
|
+
if (endpoint === '/operations') trackedOperation = body.id
|
|
261
303
|
message('已受理,可在操作记录查看结果。')
|
|
262
304
|
dialog.querySelector('.pc-detail').replaceChildren()
|
|
263
305
|
} catch (error) {
|
|
@@ -268,12 +310,30 @@ window.DshPluginCenter = (() => {
|
|
|
268
310
|
} finally { if (current === generation) { pending = false; await refresh() } }
|
|
269
311
|
}
|
|
270
312
|
function close() {
|
|
313
|
+
window.DshSkillsCenter?.close()
|
|
271
314
|
generation++; searchSequence++; detailSequence++; clearTimeout(timer); expandedDetails.clear()
|
|
272
315
|
if (!dialog) return
|
|
273
316
|
if (dialog.tagName === 'DIALOG') dialog.close()
|
|
274
317
|
else { dialog.open = false; dialog.remove() }
|
|
275
318
|
dialog = null
|
|
276
319
|
}
|
|
320
|
+
function startPolling() {
|
|
321
|
+
clearTimeout(timer)
|
|
322
|
+
const current = generation
|
|
323
|
+
async function poll() {
|
|
324
|
+
if (current !== generation || !dialog?.open) return
|
|
325
|
+
try { await refresh() } catch (error) { if (current === generation) message(error.message) }
|
|
326
|
+
if (current === generation && dialog?.open) timer = setTimeout(poll, 4000)
|
|
327
|
+
}
|
|
328
|
+
timer = setTimeout(poll, 4000)
|
|
329
|
+
}
|
|
330
|
+
function pause() { generation++; refreshSequence++; clearTimeout(timer); if (dialog) dialog.open = false }
|
|
331
|
+
async function resume() {
|
|
332
|
+
if (!dialog || !connection.valid()) return
|
|
333
|
+
dialog.open = true; const current = ++generation
|
|
334
|
+
try { await refresh() } catch (error) { if (current === generation) message(error.message) }
|
|
335
|
+
if (current === generation && dialog?.open) startPolling()
|
|
336
|
+
}
|
|
277
337
|
async function open(config, target) {
|
|
278
338
|
close()
|
|
279
339
|
if (!dialog) {
|
|
@@ -285,6 +345,7 @@ window.DshPluginCenter = (() => {
|
|
|
285
345
|
const toolbar = node('div', null, 'pc-tabs')
|
|
286
346
|
for (const [value, title] of [['installed', '已安装'], ['market', '添加插件'], ['builtin', '内置插件']]) {
|
|
287
347
|
const control = button(title, () => {
|
|
348
|
+
window.DshSkillsCenter?.close()
|
|
288
349
|
tab = value; detailSequence++; expandedDetails.clear(); renderedInstalled = ''; dialog.querySelector('.pc-detail').replaceChildren()
|
|
289
350
|
renderTabs(); message('')
|
|
290
351
|
dialog.querySelector('.pc-market-tools').hidden = value !== 'market'; dialog.querySelector('.pc-filters').hidden = value === 'market'
|
|
@@ -311,18 +372,20 @@ window.DshPluginCenter = (() => {
|
|
|
311
372
|
search().catch(error => { if (current === generation) message(error.message) })
|
|
312
373
|
})
|
|
313
374
|
const jobs = node('details', null, 'pc-history'); jobs.append(node('summary', '操作记录'), node('div', null, 'pc-jobs'))
|
|
375
|
+
const progress = node('section', null, 'pc-progress'); progress.hidden = true; progress.setAttribute('role', 'status'); progress.setAttribute('aria-live', 'polite')
|
|
314
376
|
const alert = node('p', null, 'pc-message'); alert.setAttribute('role', 'status')
|
|
315
377
|
const context = node('div', null, 'pc-context'); context.append(node('p', null, 'pc-profile'), node('div', null, 'pc-summary'))
|
|
316
378
|
controls.append(toolbarRow, filters, market)
|
|
317
|
-
dialog.append(heading, context, node('p', null, 'pc-status'), controls, alert, node('div', null, 'pc-recovery'), node('div', null, 'pc-detail'), node('div', null, 'pc-list'), jobs)
|
|
379
|
+
dialog.append(heading, context, node('p', null, 'pc-status'), controls, alert, progress, node('div', null, 'pc-recovery'), node('div', null, 'pc-detail'), node('div', null, 'pc-list'), jobs)
|
|
318
380
|
const surface = dialog
|
|
319
381
|
dialog.addEventListener('close', () => {
|
|
320
382
|
if (dialog !== surface) return
|
|
383
|
+
window.DshSkillsCenter?.close()
|
|
321
384
|
generation++; clearTimeout(timer); dialog = null; surface.remove()
|
|
322
385
|
})
|
|
323
386
|
;(target || document.body).append(dialog)
|
|
324
387
|
}
|
|
325
|
-
generation++; searchSequence++; detailSequence++; connection = config; tab = 'installed'; pending = false; snapshot = null; filter = ''; statusFilter = 'all'
|
|
388
|
+
generation++; searchSequence++; detailSequence++; connection = config; tab = 'installed'; pending = false; snapshot = null; filter = ''; statusFilter = 'all'; trackedOperation = ''
|
|
326
389
|
const current = generation
|
|
327
390
|
renderedInstalled = ''; renderedJobs = ''
|
|
328
391
|
dialog.querySelector('.pc-market-tools').hidden = true
|
|
@@ -332,12 +395,7 @@ window.DshPluginCenter = (() => {
|
|
|
332
395
|
message('正在读取插件状态…')
|
|
333
396
|
try { await refresh(); message('') } catch (error) { if (current === generation) message(error.message) }
|
|
334
397
|
if (current !== generation) return
|
|
335
|
-
|
|
336
|
-
if (current !== generation || !dialog?.open) return
|
|
337
|
-
try { await refresh() } catch (error) { if (current === generation) message(error.message) }
|
|
338
|
-
if (current === generation && dialog?.open) timer = setTimeout(poll, 4000)
|
|
339
|
-
}
|
|
340
|
-
timer = setTimeout(poll, 4000)
|
|
398
|
+
startPolling()
|
|
341
399
|
}
|
|
342
|
-
return { open, mount: (config, target) => open(config, target), close }
|
|
400
|
+
return { open, mount: (config, target) => open(config, target), close, pause, resume }
|
|
343
401
|
})()
|
package/public/plugin.js
CHANGED
|
@@ -121,9 +121,16 @@ function render(st) {
|
|
|
121
121
|
$('plugin-error').classList.add('hidden')
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
let stateLoadPromise = null
|
|
124
125
|
async function load() {
|
|
126
|
+
if (stateLoadPromise) return stateLoadPromise
|
|
127
|
+
stateLoadPromise = readState().finally(() => { stateLoadPromise = null })
|
|
128
|
+
return stateLoadPromise
|
|
129
|
+
}
|
|
130
|
+
async function readState() {
|
|
125
131
|
try {
|
|
126
|
-
const res = await fetch(`${API}/state`, { headers: { 'x-dsh-remote-client': 'plugin' }
|
|
132
|
+
const res = await fetch(`${API}/state`, { headers: { 'x-dsh-remote-client': 'plugin' },
|
|
133
|
+
signal: typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(10000) : undefined })
|
|
127
134
|
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
128
135
|
render(await res.json())
|
|
129
136
|
} catch (e) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* Read-only library: shared theme and deliberate wrapping. */
|
|
2
|
+
.sc-shell { grid-column:1/-1; min-width:0; color:var(--dsr-text,#f0f6fc); container-type:inline-size; container-name:skills; }
|
|
3
|
+
.sc-heading { margin-bottom:20px; }
|
|
4
|
+
.sc-heading h3 { margin:0; font-size:22px; line-height:1.3; }
|
|
5
|
+
.sc-intro,.sc-updated,.sc-source,.sc-meta { color:var(--dsr-muted,#a7b0bc); font-size:13px; line-height:1.6; }
|
|
6
|
+
.sc-intro { margin:8px 0 0!important; }.sc-source { display:block; }
|
|
7
|
+
.sc-filters { display:grid; grid-template-columns:minmax(220px,1fr) minmax(130px,.5fr) minmax(155px,.6fr) auto; gap:10px; align-items:center; }
|
|
8
|
+
.sc-filters input,.sc-filters select,.sc-filters button,.sc-reading-tools input,.sc-reading-tools select,.sc-reading-tools button,.sc-page button {
|
|
9
|
+
box-sizing:border-box; min-width:0; min-height:46px; max-width:100%; margin:0; padding:11px 12px;
|
|
10
|
+
border:1px solid var(--dsr-line,#30363d); border-radius:12px; background:var(--dsr-panel,#161b22);
|
|
11
|
+
color:var(--dsr-text,#f0f6fc); font:inherit; font-size:14px; line-height:1.4;
|
|
12
|
+
}
|
|
13
|
+
.sc-filters input,.sc-filters select,.sc-reading-tools input,.sc-reading-tools select { width:100%; }
|
|
14
|
+
.sc-filters input::placeholder,.sc-reading-tools input::placeholder { color:var(--dsr-muted,#a7b0bc); opacity:1; }
|
|
15
|
+
.sc-filters select,.sc-reading-tools select { padding-right:28px; text-overflow:ellipsis; }
|
|
16
|
+
.sc-filters button,.sc-reading-tools button,.sc-page button { white-space:nowrap; cursor:pointer; }
|
|
17
|
+
.sc-filters button { min-width:88px; }
|
|
18
|
+
.sc-shell :is(input,select,button):focus-visible { outline:2px solid var(--dsr-accent,#58a6ff); outline-offset:3px; }
|
|
19
|
+
.sc-summary { display:flex; align-items:baseline; justify-content:space-between; flex-wrap:wrap; gap:4px 16px; margin:20px 0 16px; font-size:13px; }
|
|
20
|
+
.sc-count,.sc-updated { white-space:nowrap; }
|
|
21
|
+
.sc-notice:not(:empty) { margin-top:12px!important; padding:12px 14px; border:1px solid var(--dsr-warning-line,#ff9e6466); border-radius:12px; font-size:13px; line-height:1.6; }
|
|
22
|
+
.sc-notice:empty { display:none; }
|
|
23
|
+
.sc-body { display:grid; grid-template-columns:minmax(240px,1fr) minmax(0,1.5fr); gap:20px; align-items:start; }
|
|
24
|
+
.sc-list { display:grid; gap:14px; max-height:68dvh; overflow:auto; }
|
|
25
|
+
.sc-card,.sc-detail { min-width:0; border:1px solid var(--dsr-line,#30363d); border-radius:18px; background:var(--dsr-panel,#161b22); padding:20px; overflow-wrap:break-word; word-break:normal; line-break:strict; }
|
|
26
|
+
.sc-card { display:flex; flex-direction:column; align-items:stretch; }
|
|
27
|
+
.sc-card.is-selected { border-color:var(--dsr-accent,#58a6ff); background:var(--dsr-accent-soft,#58a6ff1f); }
|
|
28
|
+
.sc-card h3 { margin:8px 0 10px!important; font-size:18px; line-height:1.45; overflow-wrap:break-word; word-break:normal; }
|
|
29
|
+
.sc-description { margin:0!important; font-size:14px; line-height:1.7; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; }
|
|
30
|
+
.sc-description,.sc-intro,.sc-detail p { text-wrap:pretty; }
|
|
31
|
+
.sc-flags { display:flex; flex-wrap:wrap; align-items:flex-start; gap:8px; margin:16px 0; }
|
|
32
|
+
.sc-flags .pc-badge { max-width:100%; min-width:0; white-space:normal; line-height:1.5; overflow-wrap:break-word; }
|
|
33
|
+
.sc-flags .sc-status { white-space:nowrap; }
|
|
34
|
+
.sc-card > button { min-height:44px; width:100%; margin-top:auto; border-radius:12px; font-size:14px; }
|
|
35
|
+
.sc-detail { position:sticky; top:12px; }.sc-detail[hidden] { display:none; }
|
|
36
|
+
.sc-card .sc-detail { margin-top:16px; padding:16px 0 0; border:0; border-top:1px solid var(--dsr-line,#30363d); border-radius:0; background:transparent; }
|
|
37
|
+
.sc-detail h3 { font-size:20px; line-height:1.4; margin:16px 0 10px; }
|
|
38
|
+
.sc-detail h4 { margin:24px 0 10px; font-size:15px; line-height:1.5; }
|
|
39
|
+
.sc-detail p { margin-top:10px!important; font-size:14px; line-height:1.75; }
|
|
40
|
+
.sc-detail .sc-content { max-height:58dvh; margin:0; padding:16px; border:1px solid var(--dsr-line,#30363d); border-radius:14px; white-space:pre-wrap; overflow-wrap:break-word; word-break:normal; overflow:auto; font:13px/1.8 ui-monospace,monospace; background:var(--dsr-bg,#0d1117); }
|
|
41
|
+
.sc-page .sc-filters { grid-template-columns:minmax(220px,1fr) minmax(130px,.45fr) minmax(155px,.55fr) minmax(105px,.35fr) auto; }
|
|
42
|
+
.sc-page .sc-body { display:block; }
|
|
43
|
+
.sc-page .sc-list { max-height:none; overflow:visible; grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr)); align-items:stretch; }
|
|
44
|
+
.sc-page .sc-detail { position:static; padding:24px; }.sc-page .sc-content { max-height:none; overflow:visible; }
|
|
45
|
+
.sc-reading-tools { display:grid; grid-template-columns:minmax(200px,1fr) minmax(150px,auto) auto; gap:10px; margin:18px 0 10px; align-items:center; }
|
|
46
|
+
.sc-markdown { font-family:inherit!important; white-space:normal!important; line-height:1.8; }
|
|
47
|
+
.sc-markdown :is(p,li) { max-width:75ch; }
|
|
48
|
+
.sc-markdown :is(h1,h2,h3,h4) { line-height:1.4; overflow-wrap:break-word; }
|
|
49
|
+
.sc-markdown h1 { font-size:23px; }.sc-markdown h2 { font-size:20px; }
|
|
50
|
+
.sc-markdown pre { max-width:100%; overflow-x:auto; white-space:pre; }
|
|
51
|
+
.sc-markdown table { display:block; max-width:100%; overflow-x:auto; }
|
|
52
|
+
.sc-content mark { background:var(--dsr-accent-soft,#ffd16670); color:inherit; }.sc-page [hidden] { display:none!important; }
|
|
53
|
+
@media(max-width:1100px) {
|
|
54
|
+
.sc-filters,.sc-page .sc-filters { grid-template-columns:repeat(3,minmax(0,1fr)) auto; }
|
|
55
|
+
.sc-filters input { grid-column:1/-1; }
|
|
56
|
+
}
|
|
57
|
+
@media(max-width:620px) {
|
|
58
|
+
.sc-heading { margin-bottom:16px; }.sc-heading h3 { font-size:21px; }
|
|
59
|
+
.sc-filters,.sc-page .sc-filters { grid-template-columns:repeat(2,minmax(0,1fr)); }.sc-filters input { grid-column:1/-1; }
|
|
60
|
+
.sc-body { grid-template-columns:1fr; }.sc-detail { position:static; }.sc-list { max-height:none; overflow-anchor:none; }
|
|
61
|
+
.sc-page .sc-list { grid-template-columns:1fr; }.sc-card { padding:18px; }.sc-page .sc-detail { padding:18px; }
|
|
62
|
+
.sc-detail .sc-content { max-height:45dvh; padding:14px; }.sc-page .sc-content { max-height:none; }
|
|
63
|
+
.sc-reading-tools { grid-template-columns:minmax(0,1fr) auto; }.sc-reading-tools input { grid-column:1/-1; }
|
|
64
|
+
.sc-summary { margin:16px 0; }.sc-updated { font-size:12px; }
|
|
65
|
+
}
|
|
66
|
+
@media(max-width:360px) {
|
|
67
|
+
.sc-card,.sc-page .sc-detail { padding:16px; }.sc-filters { gap:8px; }
|
|
68
|
+
.sc-filters :is(input,select,button),.sc-reading-tools :is(input,select,button) { font-size:13px; }
|
|
69
|
+
.sc-card h3 { font-size:17px; }.sc-detail h3 { font-size:19px; }
|
|
70
|
+
}
|
|
71
|
+
/* A wide window can still contain a narrow reading pane. */
|
|
72
|
+
@container skills (max-width:1000px) {
|
|
73
|
+
.sc-filters,.sc-page .sc-filters { grid-template-columns:repeat(3,minmax(0,1fr)) auto; }
|
|
74
|
+
.sc-filters input { grid-column:1/-1; }
|
|
75
|
+
}
|
|
76
|
+
@container skills (max-width:620px) {
|
|
77
|
+
.sc-filters,.sc-page .sc-filters { grid-template-columns:repeat(2,minmax(0,1fr)); }
|
|
78
|
+
.sc-page .sc-list { grid-template-columns:1fr; }
|
|
79
|
+
.sc-reading-tools { grid-template-columns:minmax(0,1fr) auto; }
|
|
80
|
+
.sc-reading-tools input { grid-column:1/-1; }
|
|
81
|
+
}
|
package/public/skills.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/* Shared read-only skill center. Skill text is displayed as text, never executed. */
|
|
2
|
+
'use strict';
|
|
3
|
+
window.DshSkillsCenter = (() => {
|
|
4
|
+
let current
|
|
5
|
+
const sourceNames = { 'project-dsh': '项目 · DSH', 'project-agents': '项目 · Agents', custom: '自定义目录', 'user-dsh': '用户 · DSH', 'user-agents': '用户 · Agents', runtime: '插件注册', bundled: '内置技能' }
|
|
6
|
+
const errors = { 'not-installed': '当前主机暂未提供技能中心,请返回插件列表核对状态。', unsupported: '主机技能中心接口不兼容,请核对插件版本。', 'host-denied': '主机拒绝读取技能,请检查主机认证状态。', 'skill-changed': '技能已变化,请刷新列表后重新选择。', 'skills-unavailable': '暂时无法读取主机技能,请重试。' }
|
|
7
|
+
function node(tag, text, cls) { const el = document.createElement(tag); if (text != null) el.textContent = text; if (cls) el.className = cls; return el }
|
|
8
|
+
function button(label, fn) { const el = node('button', label); el.type = 'button'; el.addEventListener('click', fn); return el }
|
|
9
|
+
function close() { if (current) { current.controller.abort(); current = null } }
|
|
10
|
+
function live(s) { return current === s && s.connection.valid() }
|
|
11
|
+
function placeDetail(s) {
|
|
12
|
+
const selected = s.cards.get(s.selected)
|
|
13
|
+
if (s.dedicated) {
|
|
14
|
+
s.detail.hidden = !s.detailOpen
|
|
15
|
+
s.body.hidden = s.detailOpen
|
|
16
|
+
for (const part of s.listParts) part.hidden = s.detailOpen
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
s.detail.hidden = s.mobile.matches && !selected
|
|
20
|
+
const parent = s.mobile.matches && selected ? selected.card : s.body
|
|
21
|
+
if (s.detail.parentNode !== parent) parent.append(s.detail)
|
|
22
|
+
for (const [id, { card, action }] of s.cards) {
|
|
23
|
+
const open = id === s.selected
|
|
24
|
+
card.className = 'sc-card' + (open ? ' is-selected' : '')
|
|
25
|
+
action.textContent = open ? '收起技能' : '查看技能'
|
|
26
|
+
action.setAttribute('aria-pressed', String(open))
|
|
27
|
+
action.setAttribute('aria-expanded', String(open))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function scrollParent(el) {
|
|
31
|
+
for (let parent = el.parentElement; parent; parent = parent.parentElement) {
|
|
32
|
+
if (parent.scrollHeight > parent.clientHeight && /auto|scroll/.test(getComputedStyle(parent).overflowY)) return parent
|
|
33
|
+
}
|
|
34
|
+
return document.scrollingElement
|
|
35
|
+
}
|
|
36
|
+
async function api(s, route) {
|
|
37
|
+
if (!live(s)) throw new Error('连接已切换,请重新打开技能中心。')
|
|
38
|
+
const response = await fetch(s.connection.url('/remote/api/skills' + route), { headers: s.connection.headers,
|
|
39
|
+
signal: AbortSignal.any([s.controller.signal, AbortSignal.timeout(25000)]) })
|
|
40
|
+
if (!live(s)) throw new Error('连接已切换,请重新打开技能中心。')
|
|
41
|
+
let data
|
|
42
|
+
try { data = await response.json() } catch { throw new Error('主机 Remote 尚不支持技能中心,请更新主机插件。') }
|
|
43
|
+
if (!live(s)) throw new Error('连接已切换,请重新打开技能中心。')
|
|
44
|
+
if (!response.ok || data.ok === false || data.available === false) throw new Error(errors[data.code] || '请求失败,请检查连接后重试。')
|
|
45
|
+
return data
|
|
46
|
+
}
|
|
47
|
+
function renderList(s) {
|
|
48
|
+
const q = s.search.value.trim().toLowerCase(), source = s.sources.value, status = s.status.value
|
|
49
|
+
const rows = s.items.filter(row => (!source || row.source === source) && (!status || (status === 'on' ? row.modelInvocable === true : row.modelInvocable === false)))
|
|
50
|
+
.filter(row => [row.name, row.description, row.whenToUse, row.workspace].join(' ').toLowerCase().includes(q))
|
|
51
|
+
if (s.sort) rows.sort((a,b) => (s.sort.value === 'source' ? a.source.localeCompare(b.source) : 0) || a.name.localeCompare(b.name))
|
|
52
|
+
if (s.selected && !rows.some(row => row.id === s.selected)) {
|
|
53
|
+
s.selected = ''; ++s.detailSequence
|
|
54
|
+
s.detail.replaceChildren(node('h3', '技能详情'), node('p', '选择一个技能,查看适用场景和正文。'))
|
|
55
|
+
}
|
|
56
|
+
s.count.textContent = rows.length + ' / ' + s.items.length + ' 个技能'
|
|
57
|
+
s.list.replaceChildren()
|
|
58
|
+
s.cards.clear()
|
|
59
|
+
if (!rows.length) s.list.append(node('p', s.items.length ? '没有匹配的技能,试试更改筛选条件。' : '主机没有提供可显示的技能。', 'sc-empty'))
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
const card = node('article', null, 'sc-card' + (s.selected === row.id ? ' is-selected' : ''))
|
|
62
|
+
card.append(node('small', sourceNames[row.source] || row.source, 'sc-source'), node('h3', row.name), node('p', row.description || '未提供说明', 'sc-description'))
|
|
63
|
+
const flags = node('div', null, 'sc-flags')
|
|
64
|
+
flags.append(node('span', row.modelInvocable == null ? '模型调用状态未知' : row.modelInvocable ? '模型可调用' : '模型调用已停用', 'pc-badge sc-status' + (row.modelInvocable ? ' is-active' : '')))
|
|
65
|
+
if (row.workspace) flags.append(node('span', row.workspace, 'pc-badge'))
|
|
66
|
+
card.append(flags)
|
|
67
|
+
const action = button('查看技能', () => select(s, row)); card.append(action)
|
|
68
|
+
s.cards.set(row.id, { card, action })
|
|
69
|
+
s.list.append(card)
|
|
70
|
+
}
|
|
71
|
+
placeDetail(s)
|
|
72
|
+
}
|
|
73
|
+
async function select(s, row) {
|
|
74
|
+
if (!live(s)) return
|
|
75
|
+
const action = s.cards.get(row.id)?.action
|
|
76
|
+
const scroller = !s.dedicated && s.mobile.matches && action ? scrollParent(action) : null
|
|
77
|
+
const top = scroller ? action.getBoundingClientRect().top : 0
|
|
78
|
+
const collapse = !s.dedicated && s.selected === row.id
|
|
79
|
+
if (s.dedicated) {
|
|
80
|
+
if (!s.detailOpen) { s.returnScroller = scrollParent(s.shell); s.returnScroll = s.returnScroller?.scrollTop || 0 }
|
|
81
|
+
s.detailOpen = true
|
|
82
|
+
}
|
|
83
|
+
s.selected = collapse ? '' : row.id; const sequence = ++s.detailSequence
|
|
84
|
+
s.detail.replaceChildren(node('h3', collapse ? '技能详情' : row.name), node('p', collapse ? '选择一个技能,查看适用场景和正文。' : '正在读取技能…'))
|
|
85
|
+
placeDetail(s)
|
|
86
|
+
if (s.dedicated && s.returnScroller) s.returnScroller.scrollTop = 0
|
|
87
|
+
if (s.dedicated) s.detail.prepend(button('← 返回技能列表', () => back(s)))
|
|
88
|
+
if (scroller) scroller.scrollTop += action.getBoundingClientRect().top - top
|
|
89
|
+
if (collapse) return
|
|
90
|
+
try {
|
|
91
|
+
const data = await api(s, '/read?id=' + encodeURIComponent(row.id))
|
|
92
|
+
if (!live(s) || sequence !== s.detailSequence) return
|
|
93
|
+
const item = data.item || row
|
|
94
|
+
s.detail.replaceChildren(node('small', sourceNames[item.source] || item.source, 'sc-source'), node('h3', item.name), node('p', item.description || '未提供说明'))
|
|
95
|
+
if (item.whenToUse) s.detail.append(node('h4', '适用场景'), node('p', item.whenToUse))
|
|
96
|
+
s.detail.append(node('p', '模型调用:' + (item.modelInvocable == null ? '未知' : item.modelInvocable ? '允许' : '已停用') + ' · 手动调用:' + (item.userInvocable == null ? '未知' : item.userInvocable ? '允许' : '已停用'), 'sc-meta'), node('h4', '技能正文'))
|
|
97
|
+
s.detail.append(data.content == null ? node('p', '此技能未提供可读取的文件正文。') : node('pre', data.content || '正文为空。', 'sc-content'))
|
|
98
|
+
if (data.truncated) s.detail.append(node('p', '正文较长,当前显示前 100,000 个字符。', 'sc-notice'))
|
|
99
|
+
if (s.dedicated) {
|
|
100
|
+
s.detail.prepend(button('← 返回技能列表', () => back(s)))
|
|
101
|
+
if (data.content != null) readingTools(s, data.content)
|
|
102
|
+
s.detail.querySelector('button')?.focus({ preventScroll: true })
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (live(s) && sequence === s.detailSequence) s.detail.replaceChildren(node('h3', row.name), node('p', error.message), button('重试读取', () => { s.selected = ''; void select(s, row) }))
|
|
106
|
+
if (live(s) && s.dedicated && sequence === s.detailSequence) s.detail.prepend(button('← 返回技能列表', () => back(s)))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function back(s = current) {
|
|
110
|
+
if (!s || !live(s) || !s.detailOpen) return false
|
|
111
|
+
++s.detailSequence; s.detailOpen = false; placeDetail(s)
|
|
112
|
+
if (s.returnScroller) s.returnScroller.scrollTop = s.returnScroll
|
|
113
|
+
s.cards.get(s.selected)?.action.focus({ preventScroll: true })
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
function readingTools(s, content) {
|
|
117
|
+
const tools = node('div', null, 'sc-reading-tools'), search = node('input'), mode = node('select'), feedback = node('p', '', 'sc-meta')
|
|
118
|
+
search.placeholder = '搜索技能正文'; search.setAttribute('aria-label', '搜索技能正文')
|
|
119
|
+
for (const [value,label] of [['text','纯文本'],['markdown','Markdown 阅读']]) { const option=node('option',label); option.value=value; mode.append(option) }
|
|
120
|
+
mode.value = 'text'; mode.setAttribute('aria-label','正文显示方式')
|
|
121
|
+
const body = s.detail.querySelector('.sc-content')
|
|
122
|
+
const render = () => {
|
|
123
|
+
const query = search.value.trim()
|
|
124
|
+
if (!query && mode.value === 'markdown' && typeof window.mdToHtml === 'function') { body.className = 'sc-content sc-markdown'; body.innerHTML = window.mdToHtml(content); feedback.textContent=''; return }
|
|
125
|
+
body.className = 'sc-content'; body.replaceChildren()
|
|
126
|
+
let cursor=0,count=0,index; const lower=content.toLowerCase(),needle=query.toLowerCase()
|
|
127
|
+
while (needle && count<500 && (index=lower.indexOf(needle,cursor))>=0) {
|
|
128
|
+
body.append(document.createTextNode(content.slice(cursor,index)),node('mark',content.slice(index,index+query.length)));cursor=index+query.length;count++
|
|
129
|
+
}
|
|
130
|
+
body.append(document.createTextNode(content.slice(cursor))); feedback.textContent = query ? `找到 ${count}${count===500?'+' : ''} 处匹配 · 搜索时显示纯文本` : ''
|
|
131
|
+
}
|
|
132
|
+
search.addEventListener('input',render); mode.addEventListener('change',render)
|
|
133
|
+
const copy = button('复制正文',async()=>{ try { if (typeof window.copyText === 'function') { if (!await window.copyText(content)) throw new Error() } else await navigator.clipboard.writeText(content);feedback.textContent='正文已复制' } catch {feedback.textContent='复制失败,请选择正文后复制。'} })
|
|
134
|
+
tools.append(search,mode,copy); body.before(tools,feedback)
|
|
135
|
+
}
|
|
136
|
+
async function refresh() {
|
|
137
|
+
const s = current
|
|
138
|
+
if (!s || !live(s)) return
|
|
139
|
+
const sequence = ++s.listSequence; ++s.detailSequence
|
|
140
|
+
s.message.textContent = '正在读取主机技能…'; s.reload.disabled = true
|
|
141
|
+
try {
|
|
142
|
+
const data = await api(s, '/list')
|
|
143
|
+
if (!live(s) || sequence !== s.listSequence) return
|
|
144
|
+
if (data.schema !== 1 || !Array.isArray(data.items)) throw new Error(errors.unsupported)
|
|
145
|
+
s.items = data.items; s.selected = ''
|
|
146
|
+
const previous = s.sources.value
|
|
147
|
+
s.sources.replaceChildren(node('option', '全部来源'))
|
|
148
|
+
s.sources.children[0].value = ''
|
|
149
|
+
for (const key of [...new Set(s.items.map(row => row.source))]) { const option = node('option', (sourceNames[key] || key) + ' · ' + s.items.filter(row=>row.source===key).length); option.value = key; s.sources.append(option) }
|
|
150
|
+
s.sources.value = [...s.sources.children].some(option => option.value === previous) ? previous : ''
|
|
151
|
+
s.message.textContent = (data.complete === false ? '主机技能扫描尚不完整。' : '') + (data.truncated ? '当前显示前 500 个技能。' : '')
|
|
152
|
+
s.updated.textContent = '更新于 ' + new Date(data.generatedAt).toLocaleTimeString()
|
|
153
|
+
s.detail.replaceChildren(node('h3', '技能详情'), node('p', '选择一个技能,查看适用场景和正文。'))
|
|
154
|
+
renderList(s)
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (live(s) && sequence === s.listSequence) { s.message.textContent = error.message; s.updated.textContent = s.items.length ? '保留上次读取结果' : ''; if (!s.items.length) s.list.replaceChildren() }
|
|
157
|
+
} finally { if (live(s) && sequence === s.listSequence) s.reload.disabled = false }
|
|
158
|
+
}
|
|
159
|
+
async function mount(connection, target, options = {}) {
|
|
160
|
+
close()
|
|
161
|
+
const s = { connection, controller: new AbortController(), items: [], selected: '', cards: new Map(), listSequence: 0, detailSequence: 0,
|
|
162
|
+
dedicated: options.dedicated === true, detailOpen: false, mobile: window.matchMedia?.('(max-width:620px)') || { matches: false } }
|
|
163
|
+
current = s
|
|
164
|
+
const shell = node('section', null, 'sc-shell'), heading = node('div', null, 'sc-heading')
|
|
165
|
+
s.shell = shell; if (s.dedicated) shell.className += ' sc-page'
|
|
166
|
+
heading.append(node('h3', '技能中心'), node('p', '浏览主机技能、适用场景与调用状态。', 'sc-intro'))
|
|
167
|
+
const filters = node('div', null, 'sc-filters')
|
|
168
|
+
s.search = node('input'); s.search.value = ''; s.search.placeholder = '搜索技能名称、说明或适用场景'; s.search.setAttribute('aria-label', '搜索技能')
|
|
169
|
+
s.sources = node('select'); s.sources.setAttribute('aria-label', '技能来源')
|
|
170
|
+
s.status = node('select'); s.status.setAttribute('aria-label', '模型调用状态')
|
|
171
|
+
for (const [value, label] of [['', '全部调用状态'], ['on', '模型可调用'], ['off', '模型调用已停用']]) { const option = node('option', label); option.value = value; s.status.append(option) }
|
|
172
|
+
s.status.value = ''; s.sources.value = ''
|
|
173
|
+
for (const el of [s.search, s.sources, s.status]) el.addEventListener(el === s.search ? 'input' : 'change', () => { if (live(s)) renderList(s) })
|
|
174
|
+
s.reload = button('刷新技能', refresh); filters.append(s.search, s.sources, s.status)
|
|
175
|
+
if (s.dedicated) { s.sort=node('select');s.sort.setAttribute('aria-label','技能排序');for(const [value,label] of [['name','按名称'],['source','按来源']]){const option=node('option',label);option.value=value;s.sort.append(option)}s.sort.value='name';s.sort.addEventListener('change',()=>{if(live(s))renderList(s)});filters.append(s.sort) }
|
|
176
|
+
filters.append(s.reload)
|
|
177
|
+
s.message = node('p', '', 'sc-notice'); s.message.setAttribute('role', 'status')
|
|
178
|
+
s.count = node('strong', '', 'sc-count'); s.updated = node('small', '', 'sc-updated')
|
|
179
|
+
const summary = node('div', null, 'sc-summary'); summary.append(s.count, s.updated)
|
|
180
|
+
s.list = node('div', null, 'sc-list'); s.detail = node('section', null, 'sc-detail'); s.detail.setAttribute('aria-label', '技能详情')
|
|
181
|
+
const body = node('div', null, 'sc-body'); s.body = body; body.append(s.list); if(!s.dedicated) body.append(s.detail)
|
|
182
|
+
s.listParts = [heading, filters, s.message, summary]
|
|
183
|
+
const resize = () => { if (live(s)) placeDetail(s) }
|
|
184
|
+
s.mobile.addEventListener?.('change', resize)
|
|
185
|
+
s.controller.signal.addEventListener('abort', () => s.mobile.removeEventListener?.('change', resize), { once: true })
|
|
186
|
+
shell.append(heading, filters, s.message, summary, body); target.replaceChildren(shell)
|
|
187
|
+
if(s.dedicated)shell.append(s.detail)
|
|
188
|
+
await refresh()
|
|
189
|
+
}
|
|
190
|
+
return { mount, close, refresh, back }
|
|
191
|
+
})()
|
package/public/styles.css
CHANGED
|
@@ -1337,3 +1337,10 @@ html[lang="en"] .overview-status { min-block-size:2.5em; }
|
|
|
1337
1337
|
.overview-pulse-card.status-checking .pulse-sweep { opacity:.4; }
|
|
1338
1338
|
.overview-pulse-card .pulse-text-echo { display:none; }
|
|
1339
1339
|
}
|
|
1340
|
+
/* Compact conversation chrome; full title and workspace remain in session info. */
|
|
1341
|
+
body.in-session .session-head { padding-top:calc(var(--dsr-safe-top) + 4px); padding-bottom:4px; }
|
|
1342
|
+
.session-head #session-title { display:block; white-space:nowrap; text-overflow:ellipsis; overflow:hidden; line-height:44px; -webkit-line-clamp:unset; }
|
|
1343
|
+
body.in-session #session-sub { min-height:32px; padding:4px 2px; }
|
|
1344
|
+
.chat-file { display:flex; flex-wrap:wrap; align-items:center; gap:8px 12px; padding:12px; border:1px solid var(--dsr-line); border-radius:12px; margin:8px 0; }
|
|
1345
|
+
.chat-file-name { min-width:0; flex:1; overflow-wrap:break-word; }.chat-file small { color:var(--dsr-muted); }
|
|
1346
|
+
.chat-file button { flex-shrink:0; min-height:44px; padding:8px 12px; border:1px solid var(--dsr-accent-line); border-radius:10px; color:var(--dsr-accent-strong); background:var(--dsr-accent-soft); font:inherit; cursor:pointer; }
|
package/public/theme-vars.css
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
--dsr-safe-top: max(env(safe-area-inset-top, 0px), var(--native-top, 0px));
|
|
9
9
|
--dsr-safe-b: max(env(safe-area-inset-bottom, 0px), var(--native-bottom, 0px));
|
|
10
10
|
}
|
|
11
|
+
/* Native geometry already subtracts any system padding consumed by the WebView. */
|
|
12
|
+
html[data-native-insets="overlap"] {
|
|
13
|
+
--dsr-safe-top: var(--native-top, 0px);
|
|
14
|
+
--dsr-safe-b: var(--native-bottom, 0px);
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
html,
|
|
13
18
|
html[data-theme="default"],
|