@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.8
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 +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1784 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +71 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1548 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1494 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +739 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +409 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/* Conversation context cards. Original nodes and their action handlers stay in place. */
|
|
2
|
+
;(function (root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const priority = { approval: 0, question: 1, file: 2, queue: 3, goal: 4, todos: 5 }
|
|
5
|
+
function createSelection() {
|
|
6
|
+
let rows = [], selected = '', scope = '', scopeSet = false
|
|
7
|
+
const remembered = new Map()
|
|
8
|
+
return {
|
|
9
|
+
get rows() { return rows }, get index() { return rows.findIndex(row => row.key === selected) },
|
|
10
|
+
sync(next, nextScope) {
|
|
11
|
+
const previousIndex = this.index, previousKind = rows[previousIndex]?.kind, changed = !scopeSet || scope !== nextScope
|
|
12
|
+
if (changed) {
|
|
13
|
+
if (scopeSet && selected) remembered.set(scope, selected)
|
|
14
|
+
while (remembered.size > 12) remembered.delete(remembered.keys().next().value)
|
|
15
|
+
scope = nextScope; scopeSet = true; selected = remembered.get(scope) || ''
|
|
16
|
+
}
|
|
17
|
+
rows = next
|
|
18
|
+
if (!rows.some(row => row.key === selected)) {
|
|
19
|
+
const sameKind = !changed && rows.find(row => row.kind === previousKind)
|
|
20
|
+
const preferred = changed || previousIndex < 0 ? [...rows].sort((a, b) => priority[a.kind] - priority[b.kind])[0] : rows[Math.min(previousIndex, rows.length - 1)]
|
|
21
|
+
selected = (sameKind || preferred)?.key || ''
|
|
22
|
+
}
|
|
23
|
+
return this.index
|
|
24
|
+
},
|
|
25
|
+
select(index) { if (rows.length) selected = rows[Math.max(0, Math.min(index, rows.length - 1))].key; return this.index },
|
|
26
|
+
reset() { rows = []; selected = ''; scope = ''; scopeSet = false; remembered.clear() },
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
30
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
|
31
|
+
const goalState = phase => ({ active: text('进行中', 'In progress'), paused: text('已暂停', 'Paused'), blocked: text('等待处理', 'Blocked'), complete: text('已完成', 'Complete') })[phase] || String(phase || text('状态未知', 'Unknown state'))
|
|
32
|
+
function taskView(items) {
|
|
33
|
+
const done = items.filter(item => item.status === 'completed').length
|
|
34
|
+
return { done, total: items.length, current: items.find(item => item.status === 'in_progress') || items.find(item => item.status !== 'completed') }
|
|
35
|
+
}
|
|
36
|
+
function taskHtml(items) {
|
|
37
|
+
const view = taskView(items), status = value => ({ completed: text('已完成', 'Done'), in_progress: text('进行中', 'In progress'), pending: text('待开始', 'Pending') })[value] || value
|
|
38
|
+
return `<div class="deck-context-head"><strong>${view.done}/${view.total} ${text('已完成', 'done')}</strong></div><div class="deck-summary-text">${view.current ? esc((view.current.status === 'in_progress' ? text('正在:', 'Now: ') : text('下一步:', 'Next: ')) + (view.current.content || text('未命名任务', 'Untitled task'))) : text('全部任务已完成', 'All tasks completed')}</div><details class="deck-more" data-deck-details="tasks"><summary>${text('全部任务', 'All tasks')}</summary><div class="deck-full-content">${items.map(item => `<p><span class="deck-task-state">${esc(status(item.status))}</span>${esc(item.content || '')}</p>`).join('')}</div></details>`
|
|
39
|
+
}
|
|
40
|
+
function approvalHtml(item, fullDetail) {
|
|
41
|
+
const info = root.DshApprovalRecords?.summary(item) || { kind: 'request', text: item.reason || '' }
|
|
42
|
+
const reason = info.kind === 'auto' && root.I18N?.lang !== 'en' ? root.DshApprovalRecords?.chineseReference(info.text) || info.text : info.text
|
|
43
|
+
const permission = info.target ? ({ 'danger-full-access': text('完整访问', 'Full access'), 'workspace-write': text('工作区写入', 'Workspace write'), 'read-only': text('只读', 'Read only') })[info.target] || info.target : ''
|
|
44
|
+
const badge = info.kind === 'auto' ? text('审查未通过', 'Review denied') : info.kind === 'escalation' ? text('申请:', 'Request: ') + permission : ''
|
|
45
|
+
const args = item.arguments
|
|
46
|
+
let preview = ''
|
|
47
|
+
if (args && typeof args === 'object') {
|
|
48
|
+
for (const key of ['command', 'cmd', 'script', 'path', 'file_path', 'url']) if (typeof args[key] === 'string' && args[key]) { preview = (['command', 'cmd', 'script'].includes(key) ? text('命令', 'Command') : key === 'url' ? text('地址', 'URL') : text('路径', 'Path')) + ': ' + args[key]; break }
|
|
49
|
+
} else if (typeof args === 'string') preview = args
|
|
50
|
+
return `<div class="deck-review-head"><strong>${esc(item.toolName || text('工具调用', 'Tool call'))}</strong>${badge ? `<span class="deck-review-badge">${esc(badge)}</span>` : ''}</div><p class="deck-review-reason">${esc(reason || text('主机未提供申请原因', 'The host provided no reason'))}</p>${preview ? `<div class="deck-argument-preview" title="${esc(preview)}">${esc(preview)}</div>` : ''}${root.DshApprovalSummary?.html(item) || ''}<div class="deck-review-footer"><button type="button" class="deck-decision primary" data-session-approve="1">${text('允许一次', 'Allow once')}</button><button type="button" class="deck-decision" data-session-approve="0">${text('拒绝', 'Reject')}</button><details class="deck-more" data-deck-details="approval"><summary>${text('完整请求', 'Full request')}</summary><pre class="deck-full-content">${esc(text('工具:', 'Tool: ') + (item.toolName || '') + '\n' + fullDetail)}</pre></details></div>`
|
|
51
|
+
}
|
|
52
|
+
let instance
|
|
53
|
+
function mount(config) {
|
|
54
|
+
if (instance || !root.document) return instance
|
|
55
|
+
const doc = root.document, deck = doc.getElementById('session-deck')
|
|
56
|
+
if (!deck) return
|
|
57
|
+
const stage = deck.querySelector('.session-deck-stage'), sources = ['session-cards', 'queue-dock', 'session-pending', 'file-inbox-session'].map(id => doc.getElementById(id)).filter(Boolean)
|
|
58
|
+
const selection = createSelection(), labels = () => ({ goal: text('目标', 'Goal'), todos: text('任务', 'Tasks'), approval: text('审批', 'Approvals'), question: text('提问', 'Questions'), file: text('文件', 'Files'), queue: text('队列', 'Queue') })
|
|
59
|
+
const make = (tag, cls, value) => { const el = doc.createElement(tag); el.className = cls; if (value != null) el.textContent = value; return el }
|
|
60
|
+
const control = (name, value, fn) => { const el = make('button', 'session-deck-control', value); el.type = 'button'; el.setAttribute('aria-label', name); el.addEventListener('click', fn); return el }
|
|
61
|
+
const header = make('div', 'session-deck-head'), tabs = make('div', 'session-deck-tabs'), controls = make('div', 'session-deck-controls'), count = make('span', 'session-deck-position')
|
|
62
|
+
const notice = make('span', 'session-deck-sr'); notice.setAttribute('role', 'status'); notice.setAttribute('aria-live', 'polite')
|
|
63
|
+
tabs.setAttribute('role', 'group'); tabs.setAttribute('aria-label', text('会话卡片分类', 'Conversation card categories'))
|
|
64
|
+
const previous = control(text('上一张卡片', 'Previous card'), '‹', () => move(-1)), next = control(text('下一张卡片', 'Next card'), '›', () => move(1))
|
|
65
|
+
const fold = control(text('收起卡片', 'Collapse cards'), '⌃', () => { folded = !folded; paint() }); fold.setAttribute('aria-controls', 'session-deck-stage')
|
|
66
|
+
controls.append(previous, count, next, fold); header.append(tabs, controls); deck.prepend(header, notice)
|
|
67
|
+
deck.setAttribute('role', 'region'); deck.setAttribute('aria-label', text('会话卡片,可左右切换', 'Conversation cards, switch left or right')); stage.tabIndex = 0
|
|
68
|
+
let folded = false, lastScope = '', lastTabs = '', destroyed = false, queued = false, gesture = null, suppressClickUntil = 0
|
|
69
|
+
const disclosures = new Map()
|
|
70
|
+
const visibleSource = el => el && !el.hidden && !el.classList.contains('hidden')
|
|
71
|
+
function collect() {
|
|
72
|
+
const rows = []
|
|
73
|
+
const add = (el, kind, id) => rows.push({ el, kind, key: kind + ':' + id })
|
|
74
|
+
const cards = doc.getElementById('session-cards')
|
|
75
|
+
for (const el of cards?.children || []) add(el, el.dataset.deckKind || 'todos', el.dataset.deckKind || 'todos')
|
|
76
|
+
const pending = doc.getElementById('session-pending')
|
|
77
|
+
if (visibleSource(pending)) for (const el of pending.querySelectorAll('[data-session-approval],[data-session-question]')) {
|
|
78
|
+
const approval = el.dataset.sessionApproval
|
|
79
|
+
add(el, approval != null ? 'approval' : 'question', approval ?? el.dataset.sessionQuestion)
|
|
80
|
+
}
|
|
81
|
+
const files = doc.getElementById('file-inbox-session')
|
|
82
|
+
if (visibleSource(files)) for (const el of files.querySelectorAll('[data-transfer-id]')) add(el, 'file', el.dataset.transferId)
|
|
83
|
+
const queue = doc.getElementById('queue-dock')
|
|
84
|
+
if (visibleSource(queue) && queue.children.length) { add(queue, 'queue', 'queue'); rows[rows.length - 1].count = queue.querySelectorAll('[data-queue-steer]').length || 1 }
|
|
85
|
+
return rows
|
|
86
|
+
}
|
|
87
|
+
function refresh() {
|
|
88
|
+
if (destroyed) return
|
|
89
|
+
const context = config.context()
|
|
90
|
+
if (!context.inChat || !context.sessionId) { deck.hidden = true; return }
|
|
91
|
+
const changed = lastScope !== context.sessionId
|
|
92
|
+
if (changed) { folded = false; lastScope = context.sessionId; cancelGesture() }
|
|
93
|
+
const rows = collect(); selection.sync(rows, context.sessionId)
|
|
94
|
+
deck.hidden = !rows.length
|
|
95
|
+
if (rows.length) paint()
|
|
96
|
+
}
|
|
97
|
+
function paint() {
|
|
98
|
+
const rows = selection.rows, index = selection.index, names = labels(), counts = {}
|
|
99
|
+
for (const [i, row] of rows.entries()) {
|
|
100
|
+
row.el.dataset.deckCard = row.key
|
|
101
|
+
row.el.toggleAttribute('data-deck-active', i === index)
|
|
102
|
+
row.el.inert = i !== index || folded
|
|
103
|
+
row.el.setAttribute('aria-hidden', String(i !== index || folded))
|
|
104
|
+
for (const detail of row.el.querySelectorAll('details[data-deck-details]')) detail.open = disclosures.has(lastScope + ':' + row.key + ':' + detail.dataset.deckDetails)
|
|
105
|
+
counts[row.kind] = (counts[row.kind] || 0) + (row.count || 1)
|
|
106
|
+
}
|
|
107
|
+
deck.dataset.folded = String(folded); stage.hidden = folded; deck.dataset.multiple = String(rows.length > 1)
|
|
108
|
+
previous.disabled = index <= 0; next.disabled = index >= rows.length - 1
|
|
109
|
+
count.textContent = rows.length ? (index + 1) + '/' + rows.length : ''
|
|
110
|
+
fold.textContent = folded ? '⌄' : '⌃'; fold.setAttribute('aria-expanded', String(!folded)); fold.setAttribute('aria-label', folded ? text('展开卡片', 'Expand cards') : text('收起卡片', 'Collapse cards'))
|
|
111
|
+
const signature = JSON.stringify([counts, rows[index]?.kind, root.I18N?.lang])
|
|
112
|
+
if (signature !== lastTabs) {
|
|
113
|
+
const focused = tabs.contains(doc.activeElement) ? doc.activeElement?.dataset.deckTab : ''
|
|
114
|
+
tabs.replaceChildren()
|
|
115
|
+
for (const kind of ['approval', 'question', 'file', 'goal', 'todos', 'queue']) if (counts[kind]) {
|
|
116
|
+
const el = control(names[kind], '', () => { folded = false; select(selection.rows.findIndex(row => row.kind === kind)) })
|
|
117
|
+
el.className = 'session-deck-tab' + (priority[kind] < 3 ? ' needs-action' : ''); el.dataset.deckTab = kind
|
|
118
|
+
el.setAttribute('aria-pressed', String(rows[index]?.kind === kind)); el.append(make('span', '', names[kind]))
|
|
119
|
+
if (priority[kind] < 3 || kind === 'queue') el.append(make('small', '', String(counts[kind])))
|
|
120
|
+
tabs.append(el)
|
|
121
|
+
}
|
|
122
|
+
tabs.querySelectorAll('[data-deck-tab]').forEach(el => { if (el.dataset.deckTab === focused) el.focus({ preventScroll: true }) })
|
|
123
|
+
lastTabs = signature
|
|
124
|
+
}
|
|
125
|
+
notice.textContent = Object.entries(counts).filter(([kind]) => priority[kind] < 3).map(([kind, n]) => names[kind] + ' ' + n).join(',')
|
|
126
|
+
}
|
|
127
|
+
function select(index) { cancelGesture(); selection.select(index); paint() }
|
|
128
|
+
function move(delta) { folded = false; select(selection.index + delta) }
|
|
129
|
+
function cancelGesture() { gesture = null; stage.style.removeProperty('--deck-drag') }
|
|
130
|
+
function down(event) {
|
|
131
|
+
if (selection.rows.length < 2 || event.isPrimary === false || event.button > 0 || event.target.closest('input,textarea,select,a,[contenteditable="true"]')) return
|
|
132
|
+
gesture = { id: event.pointerId, x: event.clientX, y: event.clientY, dx: 0, claimed: false }
|
|
133
|
+
}
|
|
134
|
+
function drag(event) {
|
|
135
|
+
if (!gesture || event.pointerId !== gesture.id) return
|
|
136
|
+
const dx = event.clientX - gesture.x, dy = event.clientY - gesture.y
|
|
137
|
+
if (!gesture.claimed) {
|
|
138
|
+
if (Math.abs(dy) > 10 && Math.abs(dy) >= Math.abs(dx)) { cancelGesture(); return }
|
|
139
|
+
if (Math.abs(dx) < 10 || Math.abs(dx) < Math.abs(dy) * 1.2) return
|
|
140
|
+
gesture.claimed = true; stage.setPointerCapture?.(event.pointerId)
|
|
141
|
+
}
|
|
142
|
+
gesture.dx = dx
|
|
143
|
+
if (event.cancelable) event.preventDefault()
|
|
144
|
+
stage.style.setProperty('--deck-drag', Math.max(-72, Math.min(72, dx)) + 'px')
|
|
145
|
+
}
|
|
146
|
+
function up(event) {
|
|
147
|
+
if (!gesture || event.pointerId !== gesture.id) return
|
|
148
|
+
const { dx, claimed } = gesture
|
|
149
|
+
cancelGesture()
|
|
150
|
+
if (stage.hasPointerCapture?.(event.pointerId)) stage.releasePointerCapture(event.pointerId)
|
|
151
|
+
if (claimed) { suppressClickUntil = Date.now() + 400; if (Math.abs(dx) >= 42) move(dx < 0 ? 1 : -1) }
|
|
152
|
+
}
|
|
153
|
+
function click(event) { if (Date.now() < suppressClickUntil) { event.preventDefault(); event.stopPropagation() } }
|
|
154
|
+
function disclosure(event) {
|
|
155
|
+
const detail = event.target, card = detail.closest('[data-deck-card]')
|
|
156
|
+
if (!detail.dataset.deckDetails || !card) return
|
|
157
|
+
const key = lastScope + ':' + card.dataset.deckCard + ':' + detail.dataset.deckDetails
|
|
158
|
+
if (detail.open) disclosures.set(key, true); else disclosures.delete(key)
|
|
159
|
+
while (disclosures.size > 64) disclosures.delete(disclosures.keys().next().value)
|
|
160
|
+
}
|
|
161
|
+
function key(event) {
|
|
162
|
+
if (event.target !== stage && !tabs.contains(event.target)) return
|
|
163
|
+
const index = event.key === 'ArrowLeft' ? selection.index - 1 : event.key === 'ArrowRight' ? selection.index + 1 : event.key === 'Home' ? 0 : event.key === 'End' ? selection.rows.length - 1 : null
|
|
164
|
+
if (index != null) { event.preventDefault(); folded = false; select(index) }
|
|
165
|
+
}
|
|
166
|
+
const observer = new root.MutationObserver(() => { if (!queued) { queued = true; root.queueMicrotask(() => { queued = false; refresh() }) } })
|
|
167
|
+
for (const source of sources) observer.observe(source, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', 'class'], characterData: true })
|
|
168
|
+
stage.addEventListener('pointerdown', down); stage.addEventListener('pointermove', drag); stage.addEventListener('pointerup', up); stage.addEventListener('pointercancel', cancelGesture); stage.addEventListener('click', click, true); stage.addEventListener('toggle', disclosure, true); deck.addEventListener('keydown', key)
|
|
169
|
+
deck.dataset.mounted = 'true'
|
|
170
|
+
instance = { refresh, reset() { selection.reset(); disclosures.clear(); lastScope = ''; lastTabs = ''; folded = false; cancelGesture(); deck.hidden = true }, destroy() {
|
|
171
|
+
destroyed = true; observer.disconnect(); cancelGesture(); header.remove(); notice.remove(); delete deck.dataset.mounted
|
|
172
|
+
for (const row of selection.rows) { delete row.el.dataset.deckCard; delete row.el.dataset.deckActive; row.el.inert = false; row.el.removeAttribute('aria-hidden') }
|
|
173
|
+
for (const [name, handler] of [['pointerdown', down], ['pointermove', drag], ['pointerup', up], ['pointercancel', cancelGesture]]) stage.removeEventListener(name, handler)
|
|
174
|
+
stage.removeEventListener('click', click, true); stage.removeEventListener('toggle', disclosure, true); deck.removeEventListener('keydown', key); stage.hidden = false; instance = null
|
|
175
|
+
} }
|
|
176
|
+
refresh(); return instance
|
|
177
|
+
}
|
|
178
|
+
root.DshSessionDeck = { createSelection, goalState, taskView, taskHtml, approvalHtml, mount, refresh: () => instance?.refresh(), reset: () => instance?.reset() }
|
|
179
|
+
if (typeof module !== 'undefined') module.exports = root.DshSessionDeck
|
|
180
|
+
})(typeof window !== 'undefined' ? window : globalThis)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* Host-provided Agent conversation types. No guessed presets or saved defaults. */
|
|
2
|
+
'use strict'
|
|
3
|
+
;(function(root) {
|
|
4
|
+
const records = new WeakMap()
|
|
5
|
+
const en = () => root.I18N?.lang === 'en'
|
|
6
|
+
const label = (zh, english) => en() ? english : zh
|
|
7
|
+
function option(select, value, name, disabled = false) {
|
|
8
|
+
const el = document.createElement('option')
|
|
9
|
+
el.value = value; el.textContent = name; el.disabled = disabled; select.append(el)
|
|
10
|
+
}
|
|
11
|
+
async function open({select, hint, rpc, connection, rendered = () => {}}) {
|
|
12
|
+
if (select.labels?.[0]) select.labels[0].textContent = label('对话类型', 'Conversation type')
|
|
13
|
+
const record = {connection, rows:[], ready:false}
|
|
14
|
+
records.set(select, record)
|
|
15
|
+
select.replaceChildren(); option(select, '', label('跟随主机默认', 'Use host default'))
|
|
16
|
+
select.value = ''; select.disabled = true
|
|
17
|
+
hint.textContent = label('正在读取主机的对话类型…', 'Reading conversation types from the host…')
|
|
18
|
+
rendered()
|
|
19
|
+
try {
|
|
20
|
+
const result = await rpc('agentPresets.list', {}, 10000)
|
|
21
|
+
if (records.get(select) !== record || !connection.valid()) return
|
|
22
|
+
if (!Array.isArray(result?.presets)) throw new Error('unsupported')
|
|
23
|
+
const seen = new Set()
|
|
24
|
+
record.rows = result.presets.slice(0,100).filter(row => typeof row?.id === 'string' && row.id.length > 0 && row.id.length <= 200 && !seen.has(row.id) && seen.add(row.id))
|
|
25
|
+
for (const row of record.rows) option(select, row.id, (row.name || row.id) + (row.isDefault ? label('(主机默认)',' (host default)') : '') + (row.broken ? label(' · 暂不可用', ' · unavailable') : ''), !!row.broken)
|
|
26
|
+
record.ready = true
|
|
27
|
+
select.disabled = !record.rows.some(row=>!row.broken)
|
|
28
|
+
const describe = () => {
|
|
29
|
+
const row = record.rows.find(row=>row.id === select.value) || record.rows.find(row=>row.isDefault)
|
|
30
|
+
hint.textContent = select.value ? String(row?.description || label('仅用于这次新对话。','Applies to this new conversation only.')).slice(0,600) : label('创建时使用主机当前默认类型;不会修改主机默认设置。', 'Use the host default at creation time. This does not change the host default.')
|
|
31
|
+
}
|
|
32
|
+
select.onchange = describe; describe()
|
|
33
|
+
} catch {
|
|
34
|
+
if (records.get(select) !== record || !connection.valid()) return
|
|
35
|
+
hint.textContent = label('主机暂未提供可选类型,将使用主机默认。', 'Conversation types are unavailable; the host default will be used.')
|
|
36
|
+
}
|
|
37
|
+
if (records.get(select) === record && connection.valid()) rendered()
|
|
38
|
+
}
|
|
39
|
+
function selection(select) {
|
|
40
|
+
const record = records.get(select)
|
|
41
|
+
if (!record?.connection.valid()) return {valid:false, payload:{}}
|
|
42
|
+
if (!select.value) return {valid:true, payload:{}}
|
|
43
|
+
const row = record.rows.find(row=>row.id === select.value && !row.broken)
|
|
44
|
+
return row && record.ready ? {valid:true, payload:{agentPreset:row.id}} : {valid:false, payload:{}}
|
|
45
|
+
}
|
|
46
|
+
root.DshSessionPresets = {open, selection, staleMessage:()=>label('连接或类型已变化,请重新打开新建对话。','The connection or type has changed. Reopen the new conversation form.')}
|
|
47
|
+
})(window)
|
package/public/setup.css
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.remote-setup { margin: 0 0 14px; padding: 16px; border: 1px solid var(--dsr-accent-line); border-radius: 16px; background: var(--dsr-panel); color: var(--dsr-text); font-size: 13px; line-height: 1.6; }
|
|
2
|
+
.remote-setup summary { cursor: pointer; font-weight: 750; min-height: 32px; }
|
|
3
|
+
.remote-setup p { margin: 6px 0 10px; color: var(--dsr-muted); }
|
|
4
|
+
.remote-setup ol { list-style: none; padding: 0; margin: 8px 0 0; counter-reset: setup; }
|
|
5
|
+
.remote-setup li { counter-increment: setup; border-top: 1px solid var(--dsr-line); padding: 12px 0; }
|
|
6
|
+
.remote-setup h3 { font-size: 13px; margin: 0; }
|
|
7
|
+
.remote-setup h3::before { content: counter(setup); display: inline-grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; margin-right: 8px; color: var(--dsr-accent-strong); background: var(--dsr-accent-soft); }
|
|
8
|
+
.remote-setup-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
|
|
9
|
+
.remote-setup button, .remote-setup a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 7px 12px; border: 1px solid var(--dsr-line); border-radius: 10px; background: var(--dsr-bg-2); color: var(--dsr-text); font: inherit; cursor: pointer; text-decoration: none; }
|
|
10
|
+
.remote-setup .setup-primary { background: var(--dsr-accent-strong); color: var(--dsr-on-accent); border-color: var(--dsr-accent-strong); font-weight: 650; }
|
|
11
|
+
.remote-setup button:disabled { opacity: .55; cursor: default; }
|
|
12
|
+
.remote-setup :focus-visible { outline: 2px solid var(--dsr-accent); outline-offset: 3px; }
|
|
13
|
+
.remote-setup select { width: 100%; min-height: 44px; margin: 6px 0 10px; padding: 8px; border-radius: 8px; border: 1px solid var(--dsr-line); background: var(--dsr-bg-2); color: var(--dsr-text); font: inherit; }
|
|
14
|
+
.remote-setup .setup-qr { margin: 12px 0; overflow-wrap: anywhere; }
|
|
15
|
+
.remote-setup .setup-qr svg { display: block; width: 180px; height: 180px; max-width: 100%; padding: 8px; background: white; border-radius: 10px; }
|
|
16
|
+
.remote-setup .setup-url { display: block; margin-top: 8px; user-select: all; font-size: 12px; }
|
|
17
|
+
.remote-setup .setup-message { overflow-wrap: anywhere; }
|
|
18
|
+
.remote-setup [hidden] { display: none !important; }
|
package/public/setup.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/* 首次使用:插件抽屉和管理页共用。仅检查本机包,下载进度交给浏览器。 */
|
|
2
|
+
'use strict'
|
|
3
|
+
;(function () {
|
|
4
|
+
const words = {
|
|
5
|
+
zh: {
|
|
6
|
+
title: '连接你的第一台手机', again: '安装 App 与连接手机', intro: '电脑保持 DSH 运行,按下面三步开始。已有 App 可直接进行第 3 步。', next: '我已安装,继续配对', back: '返回下载',
|
|
7
|
+
service: '准备电脑端', ready: '网关已运行。首次连接请让手机和电脑处于同一 Wi-Fi。', standalone: '网关当前未就绪,请检查主机上的网关进程。',
|
|
8
|
+
down: '网关尚未就绪。插件已包含网关,可在此启动。', auth: '网关认证异常,请打开控制台查看诊断。', upstream: '网关已运行,但 DSH 暂不可达。可先安装 App,再到控制台检查连接。',
|
|
9
|
+
attention: '网关进程已运行,但尚未能读取管理状态。请到控制台检查。',
|
|
10
|
+
start: '启动网关', console: '打开控制台', diagnose: '检查连接', app: '安装 Android App', checking: '正在检查插件内的安装包…',
|
|
11
|
+
package: '当前主机安装包', version: '版本', missing: '当前插件未附带可下载的 APK,或请求失败。可重试,或打开发行页手动下载。',
|
|
12
|
+
download: '下载到当前设备', retry: '重新检查安装包', releases: '发行页(备用下载)', scanDownload: '用手机扫码下载',
|
|
13
|
+
downloadHint: '电脑上打开此页时,推荐用手机相机扫描下载码。安装包由这台电脑提供,无需访问 GitHub。仅适用于 Android;其他设备可使用浏览器版。',
|
|
14
|
+
requested: '已请求浏览器下载,请在下载列表查看进度。下载完成后,在 Android 手机打开 APK;如系统询问,请允许此次来源的安装,再返回 App。',
|
|
15
|
+
install: '手机下载后打开 APK,按系统提示允许此次来源的安装。随后打开 DSH Remote,进入「设置 → 服务器 → 扫码连接」,点击「实时扫码」。',
|
|
16
|
+
connect: '在 App 中扫码连接', pair: '显示连接二维码', key: '添加设备并配对',
|
|
17
|
+
pairHint: '安装后,在 App 的「设置 → 服务器」中扫码。连接码含访问凭据,请勿分享。下载码不能用于连接。',
|
|
18
|
+
online: '已检测到手机或浏览器在线,可以开始使用。', waiting: '等待手机连接;仅下载或打开安装包不会视为连接成功。',
|
|
19
|
+
noHost: '暂无手机可访问的地址。请先启动网关;若仍无地址,在控制台的「主机 IP 地址」中添加宿主地址。',
|
|
20
|
+
localOnly: '网关仅监听本机,手机无法访问。请在主机配置可供局域网访问的监听地址,再重启网关。',
|
|
21
|
+
host: '手机访问的电脑地址', network: '手机需能访问所选地址。扫码打不开时,检查同一 Wi-Fi、VPN 和电脑防火墙;可在控制台诊断。',
|
|
22
|
+
downloadCode: '下载二维码 · 用手机相机扫描', pairCode: '连接二维码 · 用 DSH Remote 扫描', qrError: '二维码暂不可用,请使用下方地址或打开控制台。',
|
|
23
|
+
unavailable: '状态暂不可用,请稍后重试或打开控制台。', browser: '先用手机版网页', browserHint: '在手机浏览器打开下方地址,再输入控制台中的令牌。', browserKeyHint: '在控制台「添加设备」创建专用密钥;手机浏览器打开下方地址后,输入该设备的令牌。'
|
|
24
|
+
},
|
|
25
|
+
en: {
|
|
26
|
+
title: 'Connect your first phone', again: 'Install the app and connect a phone', intro: 'Keep DSH running on your computer. Follow these three steps, or skip to step 3 if the app is installed.', next: 'App installed — pair now', back: 'Back to download',
|
|
27
|
+
service: 'Prepare your computer', ready: 'The gateway is running. For your first connection, use the same Wi-Fi on both devices.', standalone: 'The gateway is not ready. Check its process on the host.',
|
|
28
|
+
down: 'The gateway is not ready. It is included with the plugin; start it here.', auth: 'Gateway authentication needs attention. Open the console for diagnostics.', upstream: 'The gateway is running, but DSH is unreachable. You can install the app first, then check the console.',
|
|
29
|
+
attention: 'The gateway process is running, but its management state is unavailable. Check the console.',
|
|
30
|
+
start: 'Start gateway', console: 'Open console', diagnose: 'Check connection', app: 'Install the Android app', checking: 'Checking the package included with this plugin…',
|
|
31
|
+
package: 'Package on this host', version: 'Version', missing: 'This plugin has no downloadable APK, or the request failed. Retry or download manually from the releases page.',
|
|
32
|
+
download: 'Download on this device', retry: 'Check package again', releases: 'Releases (backup download)', scanDownload: 'Scan to download on phone',
|
|
33
|
+
downloadHint: 'On a computer, use your phone camera to scan the download code. The package comes from this computer without GitHub access. Android only; other devices can use the web client.',
|
|
34
|
+
requested: 'Browser download requested. Check its downloads list for progress. Open the APK on Android when finished, allow installation from this source if prompted, then return to the app.',
|
|
35
|
+
install: 'Open the downloaded APK on your phone and allow installation from this source if prompted. In DSH Remote, go to Settings → Servers → Scan to pair, then tap Live scan.',
|
|
36
|
+
connect: 'Scan in the app to connect', pair: 'Show connection QR', key: 'Add a device to pair', pairHint: 'After installing, scan under Settings → Servers. The connection code contains credentials; keep it private. The download code is only for downloading.',
|
|
37
|
+
online: 'A phone or web client is online. You are ready to use Remote.', waiting: 'Waiting for a phone. Downloading a package does not confirm a connection.',
|
|
38
|
+
noHost: 'No address accessible to your phone. Start the gateway, then add a host address under “Host IP addresses” in the console if needed.',
|
|
39
|
+
localOnly: 'The gateway listens on loopback only. Configure a LAN listening address on the host and restart the gateway.',
|
|
40
|
+
host: 'Computer address accessible to your phone', network: 'Your phone must reach this address. If scanning fails, check Wi-Fi, VPN and the computer firewall, or open console diagnostics.',
|
|
41
|
+
downloadCode: 'Download QR · scan with your phone camera', pairCode: 'Connection QR · scan in DSH Remote', qrError: 'QR unavailable. Use the address below or open the console.',
|
|
42
|
+
unavailable: 'Status unavailable. Retry later or open the console.', browser: 'Try the mobile web client', browserHint: 'Open this address in your phone browser, then enter the token from the console.', browserKeyHint: 'Create a dedicated key with Add device in the console, then open this address on your phone and enter that device’s token.'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function mount(root, options) {
|
|
46
|
+
if (!root) return { update() {} }
|
|
47
|
+
const lang = () => window.I18N?.lang === 'en' ? 'en' : 'zh'
|
|
48
|
+
const t = key => words[lang()][key]
|
|
49
|
+
const labels = []
|
|
50
|
+
const node = (tag, label, className) => {
|
|
51
|
+
const el = document.createElement(tag)
|
|
52
|
+
if (label) { el.textContent = t(label); labels.push([el, label]) }
|
|
53
|
+
if (className) el.className = className
|
|
54
|
+
return el
|
|
55
|
+
}
|
|
56
|
+
const details = node('details', '', 'remote-setup')
|
|
57
|
+
const summary = node('summary', 'title')
|
|
58
|
+
details.append(summary, node('p', 'intro'))
|
|
59
|
+
const stepNav = node('div', '', 'setup-step-nav')
|
|
60
|
+
stepNav.setAttribute('aria-label', lang() === 'zh' ? '连接步骤' : 'Connection steps')
|
|
61
|
+
details.append(stepNav)
|
|
62
|
+
const list = node('ol'); details.append(list); root.append(details)
|
|
63
|
+
const steps = [], stepButtons = []
|
|
64
|
+
let currentStep = 1, stepSelected = false
|
|
65
|
+
function step(title) {
|
|
66
|
+
const el = node('li'); el.append(node('h3', title)); list.append(el); steps.push(el); return el
|
|
67
|
+
}
|
|
68
|
+
function button(parent, label, action, primary = false) {
|
|
69
|
+
const el = node('button', label, primary ? 'setup-primary' : '')
|
|
70
|
+
el.type = 'button'; el.addEventListener('click', action); parent.append(el); return el
|
|
71
|
+
}
|
|
72
|
+
const first = step('service'), service = node('p')
|
|
73
|
+
first.append(service)
|
|
74
|
+
const serviceAction = button(first, 'console', () => {
|
|
75
|
+
if (canStart()) options.start()
|
|
76
|
+
else options.console()
|
|
77
|
+
})
|
|
78
|
+
const second = step('app'), packageInfo = node('p')
|
|
79
|
+
packageInfo.setAttribute('role', 'status'); second.append(packageInfo)
|
|
80
|
+
const actions = node('div', '', 'remote-setup-actions')
|
|
81
|
+
const download = node('a', 'download')
|
|
82
|
+
download.href = options.base + 'dsh-remote.apk'; download.download = 'dsh-remote.apk'; download.hidden = true
|
|
83
|
+
const message = node('p', '', 'setup-message'); message.setAttribute('role', 'status')
|
|
84
|
+
download.addEventListener('click', () => { message.textContent = t('requested') })
|
|
85
|
+
actions.append(download)
|
|
86
|
+
const retry = button(actions, 'retry', () => void checkPackage())
|
|
87
|
+
const releases = node('a', 'releases'); releases.href = 'https://github.com/Blank-not-black/dsh-Remote/releases'; releases.target = '_blank'; releases.rel = 'noopener noreferrer'; actions.append(releases)
|
|
88
|
+
second.append(node('p', 'downloadHint'), message)
|
|
89
|
+
const addressLabel = node('label'), select = node('select')
|
|
90
|
+
select.setAttribute('aria-label', t('host')); addressLabel.append(node('span', 'host'), select); second.append(addressLabel)
|
|
91
|
+
const phoneDownload = button(second, 'scanDownload', () => showCode('download'), true)
|
|
92
|
+
second.append(actions)
|
|
93
|
+
const downloadQr = node('div', '', 'setup-qr'); downloadQr.hidden = true; second.append(downloadQr, node('p', 'install'))
|
|
94
|
+
const third = step('connect'), connection = node('p', 'waiting'); connection.setAttribute('role', 'status'); third.append(connection)
|
|
95
|
+
const pair = button(third, 'pair', () => {
|
|
96
|
+
if (state?.deviceKeys?.enabled) options.deviceKey()
|
|
97
|
+
else showCode('pair')
|
|
98
|
+
}, true)
|
|
99
|
+
const pairQr = node('div', '', 'setup-qr'); pairQr.hidden = true; third.append(pairQr, node('p', 'pairHint'))
|
|
100
|
+
button(third, 'browser', () => showCode('browser'))
|
|
101
|
+
const browserQr = node('div', '', 'setup-qr'); browserQr.hidden = true; third.append(browserQr)
|
|
102
|
+
const network = node('p', 'network'); third.append(network)
|
|
103
|
+
for (const [index,title] of ['service','app','connect'].entries()) {
|
|
104
|
+
const control = button(stepNav,title,()=>chooseStep(index))
|
|
105
|
+
stepButtons.push(control)
|
|
106
|
+
}
|
|
107
|
+
const stepActions = node('div','','setup-step-actions')
|
|
108
|
+
const previous = button(stepActions,'back',()=>chooseStep(1))
|
|
109
|
+
const next = button(stepActions,'next',()=>chooseStep(2),true)
|
|
110
|
+
details.append(stepActions)
|
|
111
|
+
function chooseStep(index,manual=true) {
|
|
112
|
+
currentStep = Math.max(0,Math.min(2,index))
|
|
113
|
+
if (manual) stepSelected = true
|
|
114
|
+
steps.forEach((el,i)=>{el.hidden=i!==currentStep})
|
|
115
|
+
if (currentStep===2) third.insertBefore(addressLabel,pair)
|
|
116
|
+
else second.insertBefore(addressLabel,phoneDownload)
|
|
117
|
+
stepButtons.forEach((el,i)=>el.setAttribute('aria-current',i===currentStep?'step':'false'))
|
|
118
|
+
previous.hidden=currentStep!==2
|
|
119
|
+
next.hidden=currentStep!==1
|
|
120
|
+
}
|
|
121
|
+
chooseStep(1,false)
|
|
122
|
+
let state = null, initialized = false, packageReady = false, checking = false
|
|
123
|
+
let packageVersion = '', packageSize = 0, downloadRequested = false
|
|
124
|
+
const shownCodes = new Set(), codeSignatures = new Map()
|
|
125
|
+
const running = () => state?.mode === 'gateway' && !state.gatewayAuthError
|
|
126
|
+
const canStart = () => state && !state.gatewayRunning && state.mode !== 'gateway' && !state.gatewayAuthError && state.gatewayInstalled !== false && options.canStart !== false
|
|
127
|
+
function bases() {
|
|
128
|
+
if (!running() || /^(127\.|localhost$|\[?::1\]?$)/i.test(state.host || '')) return []
|
|
129
|
+
const hosts = options.hosts ? options.hosts(state) : state.lanIPs || []
|
|
130
|
+
const port = Number(state.port)
|
|
131
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) return []
|
|
132
|
+
return [...new Set(hosts)].filter(host => typeof host === 'string' && /^[a-z0-9.-]+$/i.test(host)
|
|
133
|
+
&& !/^(127\.|0\.0\.0\.0$|localhost$)/i.test(host)).map(host => `http://${host}:${port}`)
|
|
134
|
+
}
|
|
135
|
+
function showCode(kind) {
|
|
136
|
+
shownCodes.add(kind)
|
|
137
|
+
const box = kind === 'download' ? downloadQr : kind === 'pair' ? pairQr : browserQr
|
|
138
|
+
const base = select.value
|
|
139
|
+
if (!bases().includes(base) || (kind === 'download' && !packageReady)
|
|
140
|
+
|| (kind === 'pair' && (!state?.token || state.deviceKeys?.enabled))) { box.hidden = true; box.replaceChildren(); return }
|
|
141
|
+
let url = base + (kind === 'download' ? '/dsh-remote.apk' : '/')
|
|
142
|
+
if (kind === 'pair') url = 'dshremote://pair?' + new URLSearchParams({ token: state.token, server: base })
|
|
143
|
+
const signature = lang() + '|' + url + '|' + !!state.deviceKeys?.enabled
|
|
144
|
+
if (!box.hidden && codeSignatures.get(kind) === signature) return
|
|
145
|
+
codeSignatures.set(kind, signature)
|
|
146
|
+
box.replaceChildren()
|
|
147
|
+
const caption = node('p'); caption.textContent = t(kind === 'download' ? 'downloadCode' : kind === 'pair' ? 'pairCode' : state.deviceKeys?.enabled ? 'browserKeyHint' : 'browserHint'); box.append(caption)
|
|
148
|
+
try {
|
|
149
|
+
const qr = window.qrcode(0, 'M'); qr.addData(url); qr.make()
|
|
150
|
+
const image = node('div'); image.innerHTML = qr.createSvgTag({ cellSize: 4, margin: 2, scalable: true }); box.append(image)
|
|
151
|
+
} catch { const error = node('p'); error.textContent = t('qrError'); box.append(error) }
|
|
152
|
+
// 配对凭据只在主动显示连接码后呈现,不写 URL/日志/存储。
|
|
153
|
+
if (kind !== 'pair') {
|
|
154
|
+
const link = node('a', '', 'setup-url'); link.textContent = url; link.href = url; link.target = '_blank'; link.rel = 'noopener noreferrer'; box.append(link)
|
|
155
|
+
}
|
|
156
|
+
box.hidden = false
|
|
157
|
+
}
|
|
158
|
+
function update(next) {
|
|
159
|
+
state = next
|
|
160
|
+
for (const [el, key] of labels) el.textContent = t(key)
|
|
161
|
+
stepButtons.forEach((el,i)=>{el.textContent=(i+1)+' '+t(['service','app','connect'][i])})
|
|
162
|
+
select.setAttribute('aria-label', t('host'))
|
|
163
|
+
packageInfo.textContent = checking ? t('checking') : packageReady
|
|
164
|
+
? `${t('package')}${packageVersion ? ' · ' + t('version') + ' ' + packageVersion : ''} · ${(packageSize / 1048576).toFixed(1)} MB` : t('missing')
|
|
165
|
+
if (downloadRequested) message.textContent = t('requested')
|
|
166
|
+
const online = (state?.devices || []).some(d => d.online && (d.kind === 'app' || d.kind === 'web'))
|
|
167
|
+
if (!initialized) { details.open = !online; initialized = !!state }
|
|
168
|
+
if (state && !stepSelected) chooseStep(state.mode === 'gateway' ? 1 : 0,false)
|
|
169
|
+
summary.textContent = t(online ? 'again' : 'title')
|
|
170
|
+
service.textContent = t(!state ? 'unavailable' : state.gatewayAuthError ? 'auth' : !running() ? state.gatewayRunning ? 'attention' : options.canStart === false ? 'standalone' : 'down' : state.upstream?.reachable === false ? 'upstream' : 'ready')
|
|
171
|
+
serviceAction.textContent = t(canStart() ? 'start' : options.inConsole ? 'diagnose' : 'console')
|
|
172
|
+
connection.textContent = t(online ? 'online' : 'waiting')
|
|
173
|
+
pair.textContent = t(state?.deviceKeys?.enabled ? 'key' : 'pair')
|
|
174
|
+
const previous = select.value, urls = bases()
|
|
175
|
+
if (Array.from(select.options).map(o => o.value).join('|') !== urls.join('|')) {
|
|
176
|
+
select.replaceChildren(...urls.map(url => { const el = node('option'); el.value = url; el.textContent = url; return el }))
|
|
177
|
+
if (urls.includes(previous)) select.value = previous
|
|
178
|
+
}
|
|
179
|
+
select.hidden = addressLabel.hidden = !urls.length
|
|
180
|
+
phoneDownload.disabled = !packageReady || !urls.length
|
|
181
|
+
pair.disabled = !urls.length || !running() || (!state?.deviceKeys?.enabled && !state?.token)
|
|
182
|
+
network.textContent = t(urls.length ? 'network' : /^(127\.|localhost$|\[?::1\]?$)/i.test(state?.host || '') && running() ? 'localOnly' : 'noHost')
|
|
183
|
+
for (const kind of shownCodes) showCode(kind)
|
|
184
|
+
}
|
|
185
|
+
select.addEventListener('change', () => { for (const kind of shownCodes) showCode(kind) })
|
|
186
|
+
async function checkPackage() {
|
|
187
|
+
if (checking) return
|
|
188
|
+
checking = true; retry.disabled = true; download.hidden = true; packageReady = false
|
|
189
|
+
packageInfo.textContent = t('checking'); update(state)
|
|
190
|
+
try {
|
|
191
|
+
const [head, metadata] = await Promise.all([
|
|
192
|
+
fetch(options.base + 'dsh-remote.apk', { method: 'HEAD', cache: 'no-store', credentials: 'same-origin', signal: AbortSignal.timeout(10000) }),
|
|
193
|
+
fetch(options.base + 'update.json?local=setup', { cache: 'no-store', credentials: 'same-origin', signal: AbortSignal.timeout(10000) }).then(r => r.ok ? r.json() : null).catch(() => null)
|
|
194
|
+
])
|
|
195
|
+
const size = Number(head.headers.get('content-length'))
|
|
196
|
+
if (!head.ok || !(size > 0) || !/android.package-archive|octet-stream/i.test(head.headers.get('content-type') || '')) throw Error('APK unavailable')
|
|
197
|
+
packageVersion = typeof metadata?.version === 'string' ? metadata.version.slice(0, 60) : ''
|
|
198
|
+
packageSize = size
|
|
199
|
+
packageReady = true; download.hidden = false
|
|
200
|
+
} catch { packageInfo.textContent = t('missing') }
|
|
201
|
+
finally { checking = false; retry.disabled = false; update(state) }
|
|
202
|
+
}
|
|
203
|
+
void checkPackage()
|
|
204
|
+
download.addEventListener('click', () => { downloadRequested = true })
|
|
205
|
+
function conceal() {
|
|
206
|
+
shownCodes.clear(); codeSignatures.clear()
|
|
207
|
+
for (const box of [downloadQr,pairQr,browserQr]) { box.hidden=true; box.replaceChildren() }
|
|
208
|
+
}
|
|
209
|
+
details.addEventListener('toggle',()=>{if(!details.open)conceal()})
|
|
210
|
+
return { update, conceal, show(step=1) { chooseStep(typeof step === 'number'?step:1); details.open = true; details.scrollIntoView?.({ behavior: 'smooth', block: 'start' }) } }
|
|
211
|
+
}
|
|
212
|
+
window.DshSetup = { mount }
|
|
213
|
+
})()
|
package/public/sha256.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* 纯 JS SHA-256(零依赖,二进制安全)
|
|
2
|
+
* 上传大文件时逐块喂入 4MB slice,最后与网关计算的 SHA-256 比对,防坏包。
|
|
3
|
+
*/
|
|
4
|
+
'use strict'
|
|
5
|
+
|
|
6
|
+
function SHA256() {
|
|
7
|
+
this.h = new Uint32Array([
|
|
8
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
9
|
+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
10
|
+
])
|
|
11
|
+
this.buf = new Uint8Array(64)
|
|
12
|
+
this.bufLen = 0
|
|
13
|
+
this.total = 0
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
SHA256.prototype._process = function (block) {
|
|
17
|
+
const w = new Uint32Array(64)
|
|
18
|
+
for (let i = 0; i < 16; i++) {
|
|
19
|
+
w[i] = (block[i * 4] << 24) | (block[i * 4 + 1] << 16) | (block[i * 4 + 2] << 8) | block[i * 4 + 3]
|
|
20
|
+
}
|
|
21
|
+
for (let i = 16; i < 64; i++) {
|
|
22
|
+
const s0 = ((w[i - 15] >>> 7) | (w[i - 15] << 25)) ^ ((w[i - 15] >>> 18) | (w[i - 15] << 14)) ^ (w[i - 15] >>> 3)
|
|
23
|
+
const s1 = ((w[i - 2] >>> 17) | (w[i - 2] << 15)) ^ ((w[i - 2] >>> 19) | (w[i - 2] << 13)) ^ (w[i - 2] >>> 10)
|
|
24
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0
|
|
25
|
+
}
|
|
26
|
+
let a = this.h[0], b = this.h[1], c = this.h[2], d = this.h[3]
|
|
27
|
+
let e = this.h[4], f = this.h[5], g = this.h[6], h = this.h[7]
|
|
28
|
+
for (let i = 0; i < 64; i++) {
|
|
29
|
+
const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7))
|
|
30
|
+
const ch = (e & f) ^ (~e & g)
|
|
31
|
+
const t1 = (h + S1 + ch + K[i] + w[i]) >>> 0
|
|
32
|
+
const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10))
|
|
33
|
+
const maj = (a & b) ^ (a & c) ^ (b & c)
|
|
34
|
+
const t2 = (S0 + maj) >>> 0
|
|
35
|
+
h = g; g = f; f = e; e = (d + t1) >>> 0
|
|
36
|
+
d = c; c = b; b = a; a = (t1 + t2) >>> 0
|
|
37
|
+
}
|
|
38
|
+
this.h[0] = (this.h[0] + a) >>> 0
|
|
39
|
+
this.h[1] = (this.h[1] + b) >>> 0
|
|
40
|
+
this.h[2] = (this.h[2] + c) >>> 0
|
|
41
|
+
this.h[3] = (this.h[3] + d) >>> 0
|
|
42
|
+
this.h[4] = (this.h[4] + e) >>> 0
|
|
43
|
+
this.h[5] = (this.h[5] + f) >>> 0
|
|
44
|
+
this.h[6] = (this.h[6] + g) >>> 0
|
|
45
|
+
this.h[7] = (this.h[7] + h) >>> 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
SHA256.prototype.update = function (bytes) {
|
|
49
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)
|
|
50
|
+
this.total += data.length
|
|
51
|
+
let i = 0
|
|
52
|
+
if (this.bufLen > 0) {
|
|
53
|
+
const need = 64 - this.bufLen
|
|
54
|
+
const n = Math.min(need, data.length)
|
|
55
|
+
this.buf.set(data.subarray(0, n), this.bufLen)
|
|
56
|
+
this.bufLen += n
|
|
57
|
+
i = n
|
|
58
|
+
if (this.bufLen === 64) {
|
|
59
|
+
this._process(this.buf)
|
|
60
|
+
this.bufLen = 0
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
while (i + 64 <= data.length) {
|
|
64
|
+
this._process(data.subarray(i, i + 64))
|
|
65
|
+
i += 64
|
|
66
|
+
}
|
|
67
|
+
if (i < data.length) {
|
|
68
|
+
this.buf.set(data.subarray(i), 0)
|
|
69
|
+
this.bufLen = data.length - i
|
|
70
|
+
}
|
|
71
|
+
return this
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
SHA256.prototype.clone = function () {
|
|
75
|
+
const c = new SHA256()
|
|
76
|
+
c.h.set(this.h)
|
|
77
|
+
c.buf.set(this.buf)
|
|
78
|
+
c.bufLen = this.bufLen
|
|
79
|
+
c.total = this.total
|
|
80
|
+
return c
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
SHA256.prototype.hex = function () {
|
|
84
|
+
const lenBits = this.total * 8
|
|
85
|
+
const pad = new Uint8Array(72)
|
|
86
|
+
pad[0] = 0x80
|
|
87
|
+
const tail = (this.total + 9) % 64
|
|
88
|
+
const zero = tail === 0 ? 0 : 64 - tail
|
|
89
|
+
const padLen = 1 + zero + 8
|
|
90
|
+
// 长度 64 位大端: 高位 32 位 + 低位 32 位
|
|
91
|
+
const hi = Math.floor(lenBits / 0x100000000)
|
|
92
|
+
const lo = lenBits >>> 0
|
|
93
|
+
pad[padLen - 8] = (hi >>> 24) & 0xff
|
|
94
|
+
pad[padLen - 7] = (hi >>> 16) & 0xff
|
|
95
|
+
pad[padLen - 6] = (hi >>> 8) & 0xff
|
|
96
|
+
pad[padLen - 5] = hi & 0xff
|
|
97
|
+
pad[padLen - 4] = (lo >>> 24) & 0xff
|
|
98
|
+
pad[padLen - 3] = (lo >>> 16) & 0xff
|
|
99
|
+
pad[padLen - 2] = (lo >>> 8) & 0xff
|
|
100
|
+
pad[padLen - 1] = lo & 0xff
|
|
101
|
+
this.update(pad.subarray(0, padLen))
|
|
102
|
+
const out = []
|
|
103
|
+
for (let i = 0; i < 8; i++) {
|
|
104
|
+
const v = this.h[i]
|
|
105
|
+
out.push((v >>> 24).toString(16).padStart(2, '0'), ((v >>> 16) & 0xff).toString(16).padStart(2, '0'), ((v >>> 8) & 0xff).toString(16).padStart(2, '0'), (v & 0xff).toString(16).padStart(2, '0'))
|
|
106
|
+
}
|
|
107
|
+
return out.join('')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const K = new Uint32Array([
|
|
111
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
112
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
113
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
114
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
115
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
116
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
117
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
118
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
119
|
+
])
|