dsh-remote-plugin 0.8.2 → 0.8.3
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.md +1 -1
- package/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +66 -54
- package/insights.mjs +5 -3
- package/market.mjs +4 -1
- package/package.json +1 -1
- package/plugin-center.mjs +120 -7
- package/plugin-transaction.mjs +10 -3
- package/public/admin.html +11 -14
- package/public/admin.js +11 -23
- package/public/app.js +63 -37
- package/public/build.json +2 -2
- package/public/chat-copy.js +46 -0
- package/public/desktop/desktop.css +10 -0
- package/public/desktop/desktop.html +24 -11
- package/public/desktop/desktop.js +57 -13
- package/public/history.js +41 -6
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +48 -5
- package/public/index.html +22 -21
- package/public/md.js +8 -2
- package/public/plugin-center.js +1 -1
- package/public/plugin.html +8 -2
- package/public/relay-settings.js +7 -6
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/preview.html +11 -289
- package/public/skins/blue-fish/skin.css +95 -585
- 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 +54 -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 +55 -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 +55 -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 +11 -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 +55 -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 +22 -0
- package/public/styles.css +10 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +532 -5
- package/public/theme.js +111 -3
- package/public/update.json +8 -8
- package/public/version.json +1 -1
- package/public/workflow.css +2 -1
- package/public/workflow.js +24 -1
|
@@ -33,7 +33,13 @@ const THEME_META = [
|
|
|
33
33
|
{ id: 'light', sw: ['#F5F7F8', '#FFFFFF', '#176B87'] },
|
|
34
34
|
{ id: 'neutral', sw: ['#EEF1E8', '#FAFBF6', '#47643C'] },
|
|
35
35
|
{ id: 'mono', sw: ['#050505', '#333333', '#F5F5F5'] },
|
|
36
|
-
{ id: 'fish', sw: ['#EAF6FF', '#FFFFFF', '#2F52D0'] }
|
|
36
|
+
{ id: 'fish', sw: ['#EAF6FF', '#FFFFFF', '#2F52D0'] },
|
|
37
|
+
{ id: 'penguin', sw: ['#EDF3FA', '#FFFFFF', '#2B6CB0'] },
|
|
38
|
+
{ id: 'penguin-night', sw: ['#10151B', '#1A222C', '#F2C230'] },
|
|
39
|
+
{ id: 'bocchi', sw: ['#FFD9E8', '#FFFFFF', '#D0105A'] },
|
|
40
|
+
{ id: 'nijika', sw: ['#FFF3D5', '#FFFFFF', '#94600C'] },
|
|
41
|
+
{ id: 'ryo', sw: ['#E9F1FA', '#FFFFFF', '#315D91'] },
|
|
42
|
+
{ id: 'kita', sw: ['#FFE9E5', '#FFFFFF', '#B6373C'] }
|
|
37
43
|
]
|
|
38
44
|
function themeGet() {
|
|
39
45
|
const v = LS.get('dshTheme', '')
|
|
@@ -117,6 +123,7 @@ for (const key of ['server', 'token']) {
|
|
|
117
123
|
if (next === value) return
|
|
118
124
|
cancelHistoryLoad()
|
|
119
125
|
value = next; connectionGeneration++
|
|
126
|
+
window.DshImagePreview?.reset?.()
|
|
120
127
|
clearTimeout(state.refreshTimer); state.refreshTimer = null
|
|
121
128
|
state.sessions = []; state.byId.clear(); state.pendingProjections.clear(); state.runtimeErrors = new Map()
|
|
122
129
|
state.hostInfo = null
|
|
@@ -527,6 +534,7 @@ function openFeedbackModal() {
|
|
|
527
534
|
$('fb-include-diagnostics').checked = false
|
|
528
535
|
$('fb-include-crashes').checked = false
|
|
529
536
|
$('fb-crash-details').open = false
|
|
537
|
+
updateFeedbackLength()
|
|
530
538
|
void loadCrashPreview()
|
|
531
539
|
$('modal-feedback').classList.remove('hidden')
|
|
532
540
|
setTimeout(() => $('fb-msg').focus(), 50)
|
|
@@ -662,6 +670,12 @@ async function loadCrashPreview() {
|
|
|
662
670
|
if(crashes){const data=await read('/crash-logs');evidence.crashes=data.upload||data}
|
|
663
671
|
if(connection.valid()&&generation===loadCrashPreview.generation)preview.textContent=JSON.stringify(evidence,null,2)
|
|
664
672
|
}
|
|
673
|
+
function updateFeedbackLength() {
|
|
674
|
+
const length = $('fb-msg').value.trim().length, over = length > 20000
|
|
675
|
+
$('fb-length').textContent = I18N.lang === 'en' ? length + ' / 20000 characters' + (over ? ' — shorten before submitting; your text is preserved.' : '') : length + ' / 20000 字符' + (over ? ',请精简后提交;全文已保留。' : '')
|
|
676
|
+
$('fb-msg').setAttribute('aria-invalid', String(over))
|
|
677
|
+
$('fb-copy-draft').textContent = I18N.lang === 'en' ? 'Copy text' : '复制全文'
|
|
678
|
+
}
|
|
665
679
|
async function submitFeedback() {
|
|
666
680
|
const type = document.querySelector('#fb-chips .ds-fb-chip.current')?.dataset.fbType || 'bug'
|
|
667
681
|
const message = $('fb-msg').value.trim()
|
|
@@ -670,7 +684,7 @@ async function submitFeedback() {
|
|
|
670
684
|
const includeCrashLogs = $('fb-include-crashes').checked
|
|
671
685
|
const clientDiagnostics=includeDiagnostics?globalThis.DshDiagnostics?.report():null
|
|
672
686
|
if (!message) { toast(t('ds.feedbackEmpty'), 'err'); return }
|
|
673
|
-
if (message.length >
|
|
687
|
+
if (message.length > 20000) { toast(t('ds.feedbackTooLong'), 'err'); return }
|
|
674
688
|
const btn = $('fb-submit')
|
|
675
689
|
btn.disabled = true
|
|
676
690
|
const diagnostic=globalThis.DshDiagnostics?.start('feedback.submit')
|
|
@@ -688,10 +702,15 @@ async function submitFeedback() {
|
|
|
688
702
|
toast(clientDiagnostics&&!saved?(I18N.lang==='en'?'Feedback received; complete diagnostic report not confirmed. Copy or export the local log.':'反馈已收到,但完整诊断日志未获保存确认,请复制或导出本地日志补充。'):t('ds.feedbackSubmitted'),clientDiagnostics&&!saved?'err':'ok')
|
|
689
703
|
}
|
|
690
704
|
else if (res.status === 429) { toast(t('ds.feedbackRateLimited'), 'err') }
|
|
705
|
+
else if (json.error === 'message too long' && Number.isSafeInteger(json.max)) { toast(I18N.lang === 'en' ? 'This gateway limits feedback to ' + json.max + ' characters. Your full text is preserved; update the host gateway.' : '当前网关正文上限为 ' + json.max + ' 字符,全文已保留;请更新主机网关。', 'err') }
|
|
706
|
+
else if (json.error === 'collector-message-limit') { toast(I18N.lang === 'en' ? 'The collector still limits feedback to ' + json.max + ' characters. Your full text is preserved; copy it before updating the collector.' : '收集器仍只支持 ' + json.max + ' 字符,全文已保留;可先复制全文,待收集器升级后再提交。', 'err') }
|
|
707
|
+
else if (json.error === 'collector-body-limit') { toast(I18N.lang === 'en' ? 'The collector rejected the request size. Your full text is preserved; copy it before updating the collector.' : '收集器请求体超限,全文已保留;请先复制,待收集器升级后再提交。', 'err') }
|
|
708
|
+
else if (json.error === 'feedback_service_unavailable') { toast(I18N.lang === 'en' ? 'Delivery is unconfirmed; it may have been received. Your text is preserved. Check before resubmitting.' : '发送结果未确认,可能已收到。全文已保留,请先核对,勿重复提交。', 'err') }
|
|
709
|
+
else if (json.error === 'feedback-content-unconfirmed') { toast(I18N.lang === 'en' ? 'The content receipt did not match. It may have been received; check before resubmitting. Your text is preserved.' : '正文保存回执不一致,可能已收到;请先核对,勿重复提交。全文已保留。', 'err') }
|
|
691
710
|
else { toast(t('ds.feedbackSubmitFailed', { msg: json.error || res.status }), 'err') }
|
|
692
711
|
} catch(error) {
|
|
693
712
|
diagnostic?.fail(error)
|
|
694
|
-
toast(
|
|
713
|
+
toast(I18N.lang === 'en' ? 'Delivery is unconfirmed; it may have been received. Your text is preserved. Check before resubmitting.' : '发送结果未确认,可能已收到。全文已保留,请先核对,勿重复提交。', 'err')
|
|
695
714
|
} finally {
|
|
696
715
|
btn.disabled = false
|
|
697
716
|
}
|
|
@@ -1236,6 +1255,8 @@ function editServer(id) {
|
|
|
1236
1255
|
function removeServer(id) {
|
|
1237
1256
|
const s = state.servers.find(x => x.id === id)
|
|
1238
1257
|
if (!s) return
|
|
1258
|
+
void window.DshImageCache?.clear(historyCacheScope(s.url,serverToken(s)))
|
|
1259
|
+
void window.DshHistory.cacheClear(historyCacheScope(s.url,serverToken(s)))
|
|
1239
1260
|
state.servers = state.servers.filter(x => x.id !== id)
|
|
1240
1261
|
const wasActive = state.server === s.url && state.token === serverToken(s)
|
|
1241
1262
|
for (const g of state.groups) if (state.groupActive[g] === id) state.groupActive[g] = ''
|
|
@@ -2196,7 +2217,11 @@ function restoreCachedSessionList() {
|
|
|
2196
2217
|
}
|
|
2197
2218
|
|
|
2198
2219
|
let conversationView = null
|
|
2199
|
-
function historyCacheScope() { const hash=new SHA256();hash.update(new TextEncoder().encode(JSON.stringify([
|
|
2220
|
+
function historyCacheScope(server=state.server,token=state.token) { const hash=new SHA256();hash.update(new TextEncoder().encode(JSON.stringify([server||location.origin,token])));return 'historyCacheV2:'+hash.hex() }
|
|
2221
|
+
function captureChatImage() {
|
|
2222
|
+
const connection=captureConnection(),sessionId=state.current
|
|
2223
|
+
return {scope:historyCacheScope(),valid:()=>connection.valid()&&state.current===sessionId}
|
|
2224
|
+
}
|
|
2200
2225
|
function historySource(value) {
|
|
2201
2226
|
state.history.source=value
|
|
2202
2227
|
const el=$('history-source')
|
|
@@ -2420,7 +2445,8 @@ function blockHtml(b,index=0,context={}) {
|
|
|
2420
2445
|
if (b.type==='thinking'||b.type==='reasoning') return window.DshActivity.reasoning({text:b.text??b.content??'',key:window.DshActivity.reasoningKey(context,index,key)})
|
|
2421
2446
|
if (b.type==='tool-call'||b.type==='tool-result') return window.DshActivity.tool({key,name:b.name||b.toolName,...(b.type==='tool-call'?{args:b.arguments??b.args??b.input}:{result:b.result??b.output??b.content??b,error:!!(b.error||b.ok===false||b.isError)})})
|
|
2422
2447
|
}
|
|
2423
|
-
if (b.type === 'text') return window.DshActivity.hasVisibleText(b.text) ? `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true, imageLabel: t('block.image') }) : esc(b.text ?? '')}</div>` : ''
|
|
2448
|
+
if (b.type === 'text') return window.DshActivity.hasVisibleText(b.text) ? `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true, imageLabel: t('block.image'), copyCode: true, copyCodeLabel: window.I18N?.lang === 'en' ? 'Copy code' : '复制代码' }) : esc(b.text ?? '')}</div>` : ''
|
|
2449
|
+
if (b.type === 'code') return window.DshChatCopy?.code(b.content ?? b.code ?? '') || `<pre><code>${esc(b.content ?? b.code ?? '')}</code></pre>`
|
|
2424
2450
|
if (b.type === 'file' && typeof window !== 'undefined' && window.DshChatFiles) return window.DshChatFiles.render(b)
|
|
2425
2451
|
if (b.type === 'file') return `<div class="ds-tool">📎 ${esc(b.attachment?.name || b.name || 'file')} <small>${esc(b.attachment?.bytes ?? b.bytes ?? '')} bytes</small></div>`
|
|
2426
2452
|
if (b.type === 'thinking' || b.type === 'reasoning') return `<details><summary>${esc(t('block.thinking'))}</summary><div style="opacity:.82">${esc(b.text ?? b.content ?? '')}</div></details>`
|
|
@@ -2476,7 +2502,7 @@ function eventHtml(entry) {
|
|
|
2476
2502
|
if (type === 'user/message' && !isHumanUserMessage(ev)) return ''
|
|
2477
2503
|
const text = blocks.map((block,index)=>blockHtml(block,index,{...data,seq:entry.seq,suppressBlockTools:state.history.suppressBlockTools})).join('')
|
|
2478
2504
|
if (!text) return ''
|
|
2479
|
-
return `<div class="ds-msg ${esc(role)}"><div class="role">${esc(role === 'user' ? t('ds.role.me') : t('ds.role.dsh'))}</div>${text}</div>`
|
|
2505
|
+
return `<div class="ds-msg ${esc(role)}"><div class="role">${esc(role === 'user' ? t('ds.role.me') : t('ds.role.dsh'))}${blocks.some(block => block?.type === 'text' && String(block.text ?? '').trim()) ? window.DshChatCopy?.button(entry.seq, state.history) || '' : ''}</div>${text}</div>`
|
|
2480
2506
|
}
|
|
2481
2507
|
if (type === 'tool/call') {
|
|
2482
2508
|
const name = data.name || data.toolName || t('ds.toolDefault')
|
|
@@ -2501,6 +2527,10 @@ function canForkTurnResult() {
|
|
|
2501
2527
|
return !!session && session.origin !== 'subagent' && session.formatStatus !== 'migration-required' && activeGatewayCapability('operations') === true
|
|
2502
2528
|
}
|
|
2503
2529
|
function bindTurnResultActions() {
|
|
2530
|
+
window.DshChatCopy?.bind($('history'), {
|
|
2531
|
+
capture: () => { const connection = captureConnection(), sessionId = state.current, history = state.history; return { history, valid: () => connection.valid() && state.current === sessionId && state.history === history } },
|
|
2532
|
+
copy: copyText, notice: toast,
|
|
2533
|
+
})
|
|
2504
2534
|
window.DshTurnResults.bind($('history'), {
|
|
2505
2535
|
capture: () => {
|
|
2506
2536
|
const connection = captureConnection(), sessionId = state.current, history = state.history
|
|
@@ -4305,6 +4335,8 @@ function bindUi() {
|
|
|
4305
4335
|
$('btn-doctor').addEventListener('click', openDoctor)
|
|
4306
4336
|
$('fb-cancel').addEventListener('click', closeFeedbackModal)
|
|
4307
4337
|
$('fb-submit').addEventListener('click', submitFeedback)
|
|
4338
|
+
$('fb-msg').addEventListener('input', updateFeedbackLength)
|
|
4339
|
+
$('fb-copy-draft').addEventListener('click', async () => { const ok = await copyText($('fb-msg').value); toast(I18N.lang === 'en' ? (ok ? 'Copied' : 'Copy failed') : (ok ? '已复制全文' : '复制失败,请重试'), ok ? 'ok' : 'err') })
|
|
4308
4340
|
$('fb-include-diagnostics').addEventListener('change',()=>{void loadCrashPreview()})
|
|
4309
4341
|
$('fb-include-crashes').addEventListener('change',()=>{void loadCrashPreview()})
|
|
4310
4342
|
document.querySelectorAll('#fb-chips .ds-fb-chip').forEach(btn =>
|
|
@@ -4370,9 +4402,10 @@ function bindUi() {
|
|
|
4370
4402
|
if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); void saveAccessTokenDesktop() }
|
|
4371
4403
|
})
|
|
4372
4404
|
$('btn-theme').addEventListener('click', () => {
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4405
|
+
window.DSHTheme.openPicker({
|
|
4406
|
+
themes: THEME_META, current: themeGet(), label: id => t('ds.theme.' + id),
|
|
4407
|
+
lang: I18N.lang, onSelect: themeSet
|
|
4408
|
+
})
|
|
4376
4409
|
})
|
|
4377
4410
|
$('btn-lang').addEventListener('click', () => {
|
|
4378
4411
|
I18N.setLang(I18N.lang === 'zh' ? 'en' : 'zh')
|
|
@@ -4426,7 +4459,7 @@ async function start() {
|
|
|
4426
4459
|
}
|
|
4427
4460
|
$('token-desc').textContent = state.token ? '● ' + state.token.slice(0, 12) + '…' : t('ds.toastAuth')
|
|
4428
4461
|
bindUi()
|
|
4429
|
-
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment })
|
|
4462
|
+
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment, capture: captureChatImage })
|
|
4430
4463
|
if (!state.token) { showView('view-settings'); $('desktop-token-input').focus() }
|
|
4431
4464
|
renderWorkbench()
|
|
4432
4465
|
updateConn()
|
|
@@ -4471,16 +4504,27 @@ function mountWorkflowDesktop() {
|
|
|
4471
4504
|
approvalRecords: renderApprovalRecordsDesktop,
|
|
4472
4505
|
clearApprovalRecords: resetApprovalRecords,
|
|
4473
4506
|
clear:async kind=>{
|
|
4474
|
-
const
|
|
4507
|
+
const en=window.I18N?.lang==='en'
|
|
4508
|
+
const messages={history:en?'Clear cached history? Host records will be kept.':'清除本机历史缓存?主机记录保留。',images:en?'Clear cached images? Images will download again when viewed.':'清除本机图片缓存?再次查看时会重新下载。',caches:en?'Clear history and image caches? Connections and preferences will be kept.':'清除本机历史和图片缓存?保留连接、凭证与偏好设置。',connection:en?'Remove this connection, credential and its caches?':'移除当前地址、保存的凭证及其缓存?其他连接条目保留。',all:en?'Clear all local Remote settings, credentials and caches?':'清除本机全部 Remote 配置、凭证与缓存?主机数据保留。'}
|
|
4509
|
+
const text=messages[kind]
|
|
4475
4510
|
if(!confirm(text))return
|
|
4476
4511
|
clearTimeout(scheduleHistoryCacheSave._t)
|
|
4477
4512
|
if(kind==='connection'){
|
|
4513
|
+
const connection=captureConnection(),scope=historyCacheScope()
|
|
4514
|
+
cancelHistoryLoad()
|
|
4515
|
+
await window.DshImageCache.clear(scope);await window.DshHistory.cacheClear(scope)
|
|
4516
|
+
if(!connection.valid())return
|
|
4478
4517
|
const current=currentServerEntry();if(current)state.servers=state.servers.filter(s=>s.id!==current.id)
|
|
4479
4518
|
state.groupActive[state.activeGroup]='';state.token='';state.server='';LS.del('token');LS.del('server');saveServers()
|
|
4480
4519
|
closeStream('mux');closeStream('host');stopPolling();renderServers();showView('view-settings');showSettingsPage('servers');return
|
|
4481
4520
|
}
|
|
4482
|
-
|
|
4483
|
-
if(kind
|
|
4521
|
+
const results=[]
|
|
4522
|
+
if(kind!=='images')cancelHistoryLoad()
|
|
4523
|
+
if(kind!=='images')results.push(await window.DshHistory.cacheClear())
|
|
4524
|
+
if(kind!=='history')results.push(await window.DshImageCache.clear())
|
|
4525
|
+
if(kind==='all'){window.DshWorkflow.clearStorage();location.reload()}
|
|
4526
|
+
else if(results.includes(false))toast(en?'Some caches could not be cleared. Retry shortly.':'部分缓存未能清除,请稍后重试。','err')
|
|
4527
|
+
else toast(en?'Cache cleared':'缓存已清除','ok')
|
|
4484
4528
|
},
|
|
4485
4529
|
recover:(row,receipt)=>{const value=receipt.result?.result?.value;if(row.method==='session.create'&&value?.sessionId)void openSession(value.sessionId);if(row.sessionId===state.current)void resyncCurrentSession()},
|
|
4486
4530
|
})
|
package/public/history.js
CHANGED
|
@@ -163,10 +163,13 @@
|
|
|
163
163
|
if(database)return database
|
|
164
164
|
database=new Promise(resolve=>{
|
|
165
165
|
if(typeof indexedDB==='undefined'){resolve(null);return}
|
|
166
|
-
|
|
166
|
+
let request,settled=false
|
|
167
|
+
const done=db=>{if(settled){db?.close();return}settled=true;clearTimeout(timer);resolve(db)}
|
|
168
|
+
const timer=setTimeout(()=>done(null),1500)
|
|
169
|
+
try{request=indexedDB.open('dshRemoteHistoryV1',1)}catch{done(null);return}
|
|
167
170
|
request.onupgradeneeded=()=>{const store=request.result.createObjectStore('history',{keyPath:'key'});store.createIndex('scopeTime',['scope','updatedAt'])}
|
|
168
|
-
request.onsuccess=()=>{
|
|
169
|
-
request.onerror=request.onblocked=()=>
|
|
171
|
+
request.onsuccess=()=>{request.result.onversionchange=()=>{request.result.close();database=null};done(request.result)}
|
|
172
|
+
request.onerror=request.onblocked=()=>done(null)
|
|
170
173
|
})
|
|
171
174
|
return database
|
|
172
175
|
}
|
|
@@ -200,9 +203,12 @@
|
|
|
200
203
|
if(epoch!==cacheEpoch)return false
|
|
201
204
|
if(db)try{const saved=await new Promise(resolve=>{
|
|
202
205
|
const tx=db.transaction('history','readwrite'),store=tx.objectStore('history');store.put(data)
|
|
206
|
+
let settled=false
|
|
207
|
+
const done=value=>{if(settled)return;settled=true;clearTimeout(timer);resolve(value)}
|
|
208
|
+
const timer=setTimeout(()=>{done(false);try{tx.abort()}catch{}},1500)
|
|
203
209
|
let count=0;const request=store.index('scopeTime').openKeyCursor(IDBKeyRange.bound([scope,0],[scope,Number.MAX_SAFE_INTEGER]),'prev')
|
|
204
210
|
request.onsuccess=()=>{const cursor=request.result;if(!cursor)return;if(++count>10)store.delete(cursor.primaryKey);cursor.continue()}
|
|
205
|
-
tx.oncomplete=()=>
|
|
211
|
+
tx.oncomplete=()=>done(true);tx.onabort=tx.onerror=()=>{globalThis.DshDiagnostics?.storageFailure(scope,tx.error||{name:'UnknownError'},'indexeddb');done(false)}
|
|
206
212
|
});if(saved)return true}catch(error){globalThis.DshDiagnostics?.storageFailure(scope,error,'indexeddb')}
|
|
207
213
|
if(epoch!==cacheEpoch)return false
|
|
208
214
|
try{
|
|
@@ -215,8 +221,37 @@
|
|
|
215
221
|
}catch{return false}
|
|
216
222
|
}
|
|
217
223
|
async function cacheRemove(scope,id) {const key=cacheKey(scope,id);try{localStorage.removeItem(key)}catch{};const db=await openDatabase();if(db)try{db.transaction('history','readwrite').objectStore('history').delete(key)}catch{}}
|
|
218
|
-
async function
|
|
219
|
-
|
|
224
|
+
async function cacheInspect(mode,action,fallback) {
|
|
225
|
+
const db=await openDatabase();if(!db)return fallback
|
|
226
|
+
return new Promise(resolve=>{
|
|
227
|
+
let tx,value=fallback,settled=false
|
|
228
|
+
const done=result=>{if(settled)return;settled=true;clearTimeout(timer);resolve(result)}
|
|
229
|
+
const timer=setTimeout(()=>{done(fallback);try{tx?.abort()}catch{}},1500)
|
|
230
|
+
try{tx=db.transaction('history',mode);tx.oncomplete=()=>done(value);tx.onabort=tx.onerror=()=>done(fallback);action(tx.objectStore('history'),result=>{value=result})}catch{done(fallback)}
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
async function cacheStats() {
|
|
234
|
+
const rows=new Map(),bytes=value=>{const text=JSON.stringify(value);return typeof TextEncoder==='function'?new TextEncoder().encode(text).length:text.length*2}
|
|
235
|
+
const available=await cacheInspect('readonly',(store,result)=>{
|
|
236
|
+
const request=store.openCursor()
|
|
237
|
+
request.onsuccess=()=>{const cursor=request.result;if(!cursor){result(true);return}rows.set(cursor.primaryKey,bytes(cursor.value));cursor.continue()}
|
|
238
|
+
},false)
|
|
239
|
+
try{for(const key of Object.keys(localStorage))if(key.includes(':session:')||/^(?:(?:history|sessions)Cache|dsh-remote-(?:sessions|history))/.test(key)){
|
|
240
|
+
if(key.endsWith(':cache-index'))continue
|
|
241
|
+
const text=localStorage.getItem(key);if(text&&!rows.has(key))rows.set(key,typeof TextEncoder==='function'?new TextEncoder().encode(text).length:text.length*2)
|
|
242
|
+
}}catch{}
|
|
243
|
+
return {available:available||typeof indexedDB==='undefined',count:rows.size,bytes:[...rows.values()].reduce((a,b)=>a+b,0)}
|
|
244
|
+
}
|
|
245
|
+
async function cacheClear(scope) {
|
|
246
|
+
cacheEpoch++
|
|
247
|
+
try{for(const key of Object.keys(localStorage))if(scope===undefined?(key.includes(':session:')||key.endsWith(':cache-index')||/^(?:(?:history|sessions)Cache|dsh-remote-(?:sessions|history))/.test(key)):(key===scope||key.startsWith(scope+':')||key===scope.replace(/^history/,'sessions')))localStorage.removeItem(key)}catch{}
|
|
248
|
+
return cacheInspect('readwrite',(store,result)=>{
|
|
249
|
+
if(scope===undefined){store.clear();result(true);return}
|
|
250
|
+
const request=store.openCursor()
|
|
251
|
+
request.onsuccess=()=>{const cursor=request.result;if(!cursor){result(true);return}if(cursor.value.scope===scope)cursor.delete();cursor.continue()}
|
|
252
|
+
},typeof indexedDB==='undefined')
|
|
253
|
+
}
|
|
254
|
+
const api={HistoryView,reconcile,insertSorted,signature,cacheLoad,cacheSave,cacheRemove,cacheClear,cacheStats,decodeLegacy,WINDOW_SIZE}
|
|
220
255
|
if(typeof module!=='undefined'&&module.exports)module.exports=api
|
|
221
256
|
else root.DshHistory=api
|
|
222
257
|
})(typeof window==='undefined'?globalThis:window)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* Persistent chat images. Native IndexedDB only; credentials never enter records. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
const LIMIT=200*1024*1024, ITEM_LIMIT=12*1024*1024, MAX_ITEMS=500, MAX_AGE=30*86400000, TIMEOUT=1500
|
|
5
|
+
let database, epoch=0
|
|
6
|
+
const pending=new Map(),scopeEpoch=new Map()
|
|
7
|
+
const versionOf=scope=>epoch+':'+(scopeEpoch.get(scope)||0)
|
|
8
|
+
const CONTROL='!cache-control',revisionOf=(control,scope)=>(control?.all||0)+':'+(control?.scopes?.[scope]||0)
|
|
9
|
+
function open(){
|
|
10
|
+
if(database)return database
|
|
11
|
+
database=new Promise(resolve=>{
|
|
12
|
+
let request,settled=false
|
|
13
|
+
const finish=db=>{if(settled){db?.close();return}settled=true;clearTimeout(timer);resolve(db)}
|
|
14
|
+
const timer=setTimeout(()=>finish(null),TIMEOUT)
|
|
15
|
+
try{
|
|
16
|
+
request=root.indexedDB.open('dshRemoteImagesV1',1)
|
|
17
|
+
request.onupgradeneeded=()=>request.result.createObjectStore('images',{keyPath:'key'}).createIndex('accessedAt','accessedAt')
|
|
18
|
+
request.onsuccess=()=>{const db=request.result;db.onversionchange=()=>{db.close();database=null};finish(db)}
|
|
19
|
+
request.onerror=request.onblocked=()=>finish(null)
|
|
20
|
+
}catch{finish(null)}
|
|
21
|
+
})
|
|
22
|
+
return database
|
|
23
|
+
}
|
|
24
|
+
async function transaction(mode,action,fallback){
|
|
25
|
+
const db=await open()
|
|
26
|
+
if(!db)return fallback
|
|
27
|
+
return new Promise(resolve=>{
|
|
28
|
+
let tx,value=fallback,settled=false
|
|
29
|
+
const finish=result=>{if(settled)return;settled=true;clearTimeout(timer);resolve(result)}
|
|
30
|
+
const timer=setTimeout(()=>{finish(fallback);try{tx?.abort()}catch{}},TIMEOUT)
|
|
31
|
+
try{
|
|
32
|
+
tx=db.transaction('images',mode)
|
|
33
|
+
tx.oncomplete=()=>finish(value);tx.onerror=tx.onabort=()=>finish(fallback)
|
|
34
|
+
action(tx.objectStore('images'),result=>{value=result})
|
|
35
|
+
}catch{finish(fallback);try{tx?.abort()}catch{}}
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
const keyOf=(scope,id)=>JSON.stringify([scope,id])
|
|
39
|
+
const usable=row=>row?.blob instanceof root.Blob && row.blob.size>0 && row.blob.size<=ITEM_LIMIT && /^image\/(?:png|jpeg|webp|gif|bmp|avif|svg\+xml)$/.test(row.blob.type)
|
|
40
|
+
async function read(key,scope){
|
|
41
|
+
return transaction('readwrite',(store,result)=>{
|
|
42
|
+
const snapshot={row:null,revision:'0:0'};result(snapshot)
|
|
43
|
+
const control=store.get(CONTROL)
|
|
44
|
+
control.onsuccess=()=>{snapshot.revision=revisionOf(control.result,scope)}
|
|
45
|
+
const request=store.get(key)
|
|
46
|
+
request.onsuccess=()=>{
|
|
47
|
+
const row=request.result
|
|
48
|
+
if(!usable(row)||!Number.isFinite(row.accessedAt)||Date.now()-row.accessedAt>MAX_AGE){if(row)store.delete(key);return}
|
|
49
|
+
row.accessedAt=Date.now();store.put(row);snapshot.row=row
|
|
50
|
+
}
|
|
51
|
+
},{row:null,revision:null})
|
|
52
|
+
}
|
|
53
|
+
async function save(row,version,valid,revision,retry=true){
|
|
54
|
+
if(revision===null||!usable(row)||version!==versionOf(row.scope)||!valid())return false
|
|
55
|
+
const saved=await transaction('readwrite',(store,result)=>{
|
|
56
|
+
if(version!==versionOf(row.scope)||!valid())return
|
|
57
|
+
const control=store.get(CONTROL)
|
|
58
|
+
control.onsuccess=()=>{
|
|
59
|
+
// A clear in another tab must also invalidate this outstanding download.
|
|
60
|
+
if(revision!==revisionOf(control.result,row.scope)){result('cleared');return}
|
|
61
|
+
store.put(row)
|
|
62
|
+
const rows=[];let bytes=0
|
|
63
|
+
const request=store.index('accessedAt').openCursor()
|
|
64
|
+
request.onsuccess=()=>{
|
|
65
|
+
const cursor=request.result
|
|
66
|
+
if(cursor){if(cursor.primaryKey===CONTROL){cursor.continue();return}const value=cursor.value;if(!usable(value)||!Number.isFinite(value.accessedAt)||Date.now()-value.accessedAt>MAX_AGE)cursor.delete();else{rows.push({key:cursor.primaryKey,size:value.blob.size});bytes+=value.blob.size}cursor.continue();return}
|
|
67
|
+
while(bytes>LIMIT||rows.length>MAX_ITEMS){const old=rows.shift();bytes-=old.size;store.delete(old.key)}
|
|
68
|
+
result(true)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},false)
|
|
72
|
+
if(saved||!retry||version!==versionOf(row.scope)||!valid())return saved
|
|
73
|
+
// Browser quota may be lower than our cap. Free oldest images and retry once.
|
|
74
|
+
const freed=await transaction('readwrite',(store,result)=>{
|
|
75
|
+
if(version!==versionOf(row.scope)||!valid())return
|
|
76
|
+
let bytes=0
|
|
77
|
+
const request=store.index('accessedAt').openCursor()
|
|
78
|
+
request.onsuccess=()=>{const cursor=request.result;if(!cursor||bytes>=row.blob.size){result(true);return}if(cursor.primaryKey!==CONTROL){bytes+=cursor.value.blob?.size||0;cursor.delete()}cursor.continue()}
|
|
79
|
+
},false)
|
|
80
|
+
return freed?save(row,version,valid,revision,false):false
|
|
81
|
+
}
|
|
82
|
+
async function load(scope,id,loader,{revalidate=false,valid=()=>true}={}){
|
|
83
|
+
if(!scope||!id)throw Error('Missing image identity')
|
|
84
|
+
const key=keyOf(scope,id),version=versionOf(scope)
|
|
85
|
+
const check=()=>{if(version!==versionOf(scope)||!valid())throw Error('stale image')}
|
|
86
|
+
check()
|
|
87
|
+
if(pending.has(key)){const value=await pending.get(key);check();return value}
|
|
88
|
+
const job=(async()=>{
|
|
89
|
+
const snapshot=await read(key,scope),cached=snapshot.row;check()
|
|
90
|
+
if(cached&&!revalidate)return cached
|
|
91
|
+
let value=cached
|
|
92
|
+
if(!cached||revalidate){
|
|
93
|
+
try{value=await loader(cached)}catch(error){
|
|
94
|
+
// Offline reuse is allowed, authentication or missing-file failures are not.
|
|
95
|
+
if(!cached||error.status||error.message==='stale image'){
|
|
96
|
+
if(cached&&error.status)await transaction('readwrite',store=>store.delete(key),false)
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
value=cached
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
check()
|
|
103
|
+
if(!(value?.blob instanceof root.Blob)||!value.blob.size||!/^image\/(?:png|jpeg|webp|gif|bmp|avif|svg\+xml)$/.test(value.blob.type))throw Error('Invalid image data')
|
|
104
|
+
const saved=await save({key,scope,blob:value.blob,etag:String(value.etag||'').slice(0,512),lastModified:String(value.lastModified||'').slice(0,128),accessedAt:Date.now()},version,valid,snapshot.revision)
|
|
105
|
+
if(saved==='cleared')throw Error('stale image')
|
|
106
|
+
check();return value
|
|
107
|
+
})()
|
|
108
|
+
pending.set(key,job)
|
|
109
|
+
try{return await job}finally{if(pending.get(key)===job)pending.delete(key)}
|
|
110
|
+
}
|
|
111
|
+
async function clear(scope){
|
|
112
|
+
if(scope===undefined){epoch++;pending.clear();scopeEpoch.clear()}
|
|
113
|
+
else{scopeEpoch.set(scope,(scopeEpoch.get(scope)||0)+1);for(const key of pending.keys())if(JSON.parse(key)[0]===scope)pending.delete(key)}
|
|
114
|
+
return transaction('readwrite',(store,result)=>{
|
|
115
|
+
const request=store.get(CONTROL)
|
|
116
|
+
request.onsuccess=()=>{
|
|
117
|
+
const control=request.result||{key:CONTROL,all:0,scopes:{}}
|
|
118
|
+
if(scope===undefined){control.all++;control.scopes={};store.clear();store.put(control);result(true);return}
|
|
119
|
+
control.scopes[scope]=(control.scopes[scope]||0)+1;store.put(control)
|
|
120
|
+
const rows=store.openCursor()
|
|
121
|
+
rows.onsuccess=()=>{const cursor=rows.result;if(!cursor){result(true);return}if(cursor.value.scope===scope)cursor.delete();cursor.continue()}
|
|
122
|
+
}
|
|
123
|
+
},false)
|
|
124
|
+
}
|
|
125
|
+
async function stats(){
|
|
126
|
+
return transaction('readwrite',(store,result)=>{
|
|
127
|
+
let count=0,bytes=0
|
|
128
|
+
const request=store.openCursor()
|
|
129
|
+
request.onsuccess=()=>{
|
|
130
|
+
const cursor=request.result
|
|
131
|
+
if(!cursor){result({available:true,count,bytes,limitBytes:LIMIT});return}
|
|
132
|
+
if(cursor.primaryKey===CONTROL){cursor.continue();return}
|
|
133
|
+
const row=cursor.value
|
|
134
|
+
if(!usable(row)||!Number.isFinite(row.accessedAt)||Date.now()-row.accessedAt>MAX_AGE)cursor.delete()
|
|
135
|
+
else{count++;bytes+=row.blob.size}
|
|
136
|
+
cursor.continue()
|
|
137
|
+
}
|
|
138
|
+
},{available:false,count:0,bytes:0,limitBytes:LIMIT})
|
|
139
|
+
}
|
|
140
|
+
root.DshImageCache={load,clear,stats,limitBytes:LIMIT,itemLimitBytes:ITEM_LIMIT}
|
|
141
|
+
})(typeof window==='undefined'?globalThis:window)
|
package/public/image-preview.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
;(function(root){
|
|
4
4
|
const english=()=>root.I18N?.lang==='en'
|
|
5
5
|
let lightbox=null,stage=null,image=null,closeButton=null,hint=null,opener=null
|
|
6
|
-
let resolver=null,attachmentResolver=null,observer=null,mutation=null
|
|
6
|
+
let resolver=null,attachmentResolver=null,capture=null,observer=null,mutation=null,generation=0
|
|
7
|
+
const objectUrls=new Map()
|
|
7
8
|
const escape=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
8
9
|
function attachmentHtml(attachment,label,sessionId){
|
|
9
10
|
if(!/^(?:sha256:)?[a-f0-9]{64}$/.test(attachment?.attachmentId||''))return '<span class="chat-image-status">'+escape(label)+'</span>'
|
|
@@ -53,10 +54,16 @@
|
|
|
53
54
|
function configure(options={}){
|
|
54
55
|
if(typeof options.resolvePath==='function')resolver=options.resolvePath
|
|
55
56
|
if(typeof options.resolveAttachment==='function')attachmentResolver=options.resolveAttachment
|
|
57
|
+
if(typeof options.capture==='function')capture=options.capture
|
|
56
58
|
if(!mutation&&typeof root.MutationObserver==='function'&&root.document?.body){
|
|
57
59
|
// History renders (paging, streaming, cache restore) replace nodes without a full render call.
|
|
58
60
|
mutation=new root.MutationObserver(records=>{
|
|
59
|
-
for(const record of records)
|
|
61
|
+
for(const record of records){
|
|
62
|
+
for(const node of record.addedNodes)if(node?.nodeType===1)hydrate(node)
|
|
63
|
+
if(record.removedNodes?.length)Promise.resolve().then(()=>{
|
|
64
|
+
for(const [button,url] of objectUrls)if(button.isConnected===false){root.URL?.revokeObjectURL?.(url);objectUrls.delete(button)}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
60
67
|
})
|
|
61
68
|
mutation.observe(root.document.body,{childList:true,subtree:true})
|
|
62
69
|
}
|
|
@@ -90,9 +97,40 @@
|
|
|
90
97
|
const path=button.dataset.chatImagePath
|
|
91
98
|
const attachmentId=button.dataset.chatImageAttachment
|
|
92
99
|
if(attachmentId?!attachmentResolver:(!path||!resolver))return
|
|
100
|
+
const identity=capture?.(),version=generation
|
|
101
|
+
const valid=()=>version===generation&&button.isConnected!==false&&(!identity||identity.valid())
|
|
93
102
|
try{
|
|
94
103
|
let url
|
|
95
|
-
if(
|
|
104
|
+
if(root.DshImageCache&&identity?.scope){
|
|
105
|
+
// Scope includes the connection credential hash; attachments are also session-scoped.
|
|
106
|
+
const request=attachmentId?null:await resolver(path)
|
|
107
|
+
if(!valid())return
|
|
108
|
+
const target=typeof request==='string'?{url:request}:request||{}
|
|
109
|
+
const id=attachmentId?JSON.stringify(['attachment',button.dataset.chatImageSession,attachmentId]):JSON.stringify(['path',target.url])
|
|
110
|
+
const value=await root.DshImageCache.load(identity.scope,id,async cached=>{
|
|
111
|
+
if(!valid())throw Error('stale image')
|
|
112
|
+
if(attachmentId){
|
|
113
|
+
const result=await attachmentResolver(attachmentId,button.dataset.chatImageSession)
|
|
114
|
+
if(result?.attachment?.attachmentId!==attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw Object.assign(Error('invalid image attachment'),{status:422})
|
|
115
|
+
const binary=root.atob(result.data),bytes=new Uint8Array(binary.length)
|
|
116
|
+
for(let i=0;i<binary.length;i++)bytes[i]=binary.charCodeAt(i)
|
|
117
|
+
return {blob:new root.Blob([bytes],{type:result.attachment.mediaType})}
|
|
118
|
+
}
|
|
119
|
+
const headers={...target.headers}
|
|
120
|
+
if(cached?.etag)headers['If-None-Match']=cached.etag
|
|
121
|
+
else if(cached?.lastModified)headers['If-Modified-Since']=cached.lastModified
|
|
122
|
+
const read=async signal=>{
|
|
123
|
+
const response=await (root.fetch||fetch)(target.url,{headers,signal,cache:'no-cache'})
|
|
124
|
+
if(response.status===304&&cached)return cached
|
|
125
|
+
if(!response.ok)throw Object.assign(Error('HTTP '+response.status),{status:response.status})
|
|
126
|
+
return {blob:await response.blob(),etag:response.headers?.get('etag'),lastModified:response.headers?.get('last-modified')}
|
|
127
|
+
}
|
|
128
|
+
return root.DshNetwork?.readWithDeadline?root.DshNetwork.readWithDeadline(read,45000):read(root.AbortSignal?.timeout?.(45000))
|
|
129
|
+
},{revalidate:!attachmentId,valid})
|
|
130
|
+
if(!valid())return
|
|
131
|
+
url=root.URL.createObjectURL(value.blob)
|
|
132
|
+
objectUrls.set(button,url)
|
|
133
|
+
}else if(attachmentId){
|
|
96
134
|
const result=await attachmentResolver(attachmentId,button.dataset.chatImageSession)
|
|
97
135
|
if(result?.attachment?.attachmentId!==attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw new Error('invalid image attachment')
|
|
98
136
|
url='data:'+result.attachment.mediaType+';base64,'+result.data
|
|
@@ -105,7 +143,9 @@
|
|
|
105
143
|
if(!blob||!blob.size)throw new Error('empty image')
|
|
106
144
|
url=root.URL?.createObjectURL?root.URL.createObjectURL(blob):''
|
|
107
145
|
if(!url)throw new Error('no blob url')
|
|
146
|
+
objectUrls.set(button,url)
|
|
108
147
|
}
|
|
148
|
+
if(!valid()){release(button);return}
|
|
109
149
|
const node=root.document.createElement('img')
|
|
110
150
|
node.src=url;node.alt=button.dataset.chatImageAlt||'';node.draggable=false;node.loading='lazy'
|
|
111
151
|
node.addEventListener('error',()=>pathImageFailed(button))
|
|
@@ -113,9 +153,12 @@
|
|
|
113
153
|
button.replaceChildren(node)
|
|
114
154
|
button.dataset.chatImageLoaded='1'
|
|
115
155
|
delete button.dataset.chatImagePath
|
|
116
|
-
}catch(error){pathImageFailed(button)}
|
|
156
|
+
}catch(error){if(valid())pathImageFailed(button)}
|
|
117
157
|
}
|
|
158
|
+
function release(button){const url=objectUrls.get(button);if(url)root.URL?.revokeObjectURL?.(url);objectUrls.delete(button)}
|
|
159
|
+
function reset(){generation++;close();for(const button of objectUrls.keys())release(button)}
|
|
118
160
|
function pathImageFailed(button){
|
|
161
|
+
release(button)
|
|
119
162
|
button.classList.remove('is-loading')
|
|
120
163
|
button.classList.add('is-error')
|
|
121
164
|
const status=button.querySelector?.('.chat-image-status')
|
|
@@ -143,6 +186,6 @@
|
|
|
143
186
|
})
|
|
144
187
|
return lightbox
|
|
145
188
|
}
|
|
146
|
-
root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate,attachmentHtml}
|
|
189
|
+
root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate,attachmentHtml,reset}
|
|
147
190
|
root.document?.addEventListener('DOMContentLoaded',()=>{elements();hydrate(root.document)})
|
|
148
191
|
})(typeof window==='undefined'?globalThis:window)
|
package/public/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
9
9
|
<title>DSH Remote</title>
|
|
10
10
|
<script>/* 统一入口: 桌面浏览器(宽屏且 UA 非移动)访问根地址自动切换到桌面端, 手机/窄窗口继续 App 界面 */ (function(){try{if(new URLSearchParams(location.search).get('layout')==='mobile'){sessionStorage.setItem('dshRemoteLayout','mobile');return}if(sessionStorage.getItem('dshRemoteLayout')==='mobile')return;var proto=location.protocol;var ua=navigator.userAgent||'';var mobile=/Android|iPhone|iPad|iPod|Mobile|Windows Phone/i.test(ua);if((proto==='http:'||proto==='https:')&&!mobile&&window.innerWidth>=1024){var p=location.pathname;if(p==='/'||/\/index\.html$/.test(p)){location.replace('desktop/desktop.html'+location.search)}}}catch(e){}})()</script>
|
|
11
|
-
<script>/* 首帧前应用皮肤, 避免闪白/闪黑 */ (function(){try{var t=localStorage.getItem('dshTheme');if(t!=='default'&&t!=='dark'&&t!=='light'&&t!=='neutral'&&t!=='mono'&&t!=='fish'){t='fish'}}catch(e){t='fish'}document.documentElement.setAttribute('data-theme',t)})()</script>
|
|
11
|
+
<script>/* 首帧前应用皮肤, 避免闪白/闪黑 */ (function(){try{var t=localStorage.getItem('dshTheme');if(t!=='default'&&t!=='dark'&&t!=='light'&&t!=='neutral'&&t!=='mono'&&t!=='fish'&&t!=='penguin'&&t!=='penguin-night'&&t!=='bocchi'&&t!=='nijika'&&t!=='ryo'&&t!=='kita'){t='fish'}}catch(e){t='fish'}document.documentElement.setAttribute('data-theme',t)})()</script>
|
|
12
12
|
<link rel="manifest" href="manifest.webmanifest">
|
|
13
13
|
<link rel="icon" href="icon.svg" type="image/svg+xml">
|
|
14
14
|
<link rel="stylesheet" href="styles.css">
|
|
@@ -23,6 +23,13 @@
|
|
|
23
23
|
<link rel="stylesheet" href="relay-settings.css">
|
|
24
24
|
<link rel="stylesheet" href="subagents.css">
|
|
25
25
|
<link rel="stylesheet" href="skins/blue-fish/skin.css">
|
|
26
|
+
<link rel="stylesheet" href="skins/penguin/skin.css">
|
|
27
|
+
<link rel="stylesheet" href="skins/bocchi/skin.css">
|
|
28
|
+
<link rel="stylesheet" href="skins/kessoku/skin.css">
|
|
29
|
+
<link rel="stylesheet" href="skins/nijika/skin.css">
|
|
30
|
+
<link rel="stylesheet" href="skins/ryo/skin.css">
|
|
31
|
+
<link rel="stylesheet" href="skins/kita/skin.css">
|
|
32
|
+
<link rel="stylesheet" href="theme-picker.css">
|
|
26
33
|
</head>
|
|
27
34
|
<body>
|
|
28
35
|
<header class="topbar">
|
|
@@ -670,7 +677,9 @@
|
|
|
670
677
|
<button class="fb-chip" data-fb-type="suggestion" data-i18n="feedback.typeSuggestion">建议</button>
|
|
671
678
|
<button class="fb-chip" data-fb-type="other" data-i18n="feedback.typeOther">其他</button>
|
|
672
679
|
</div>
|
|
673
|
-
<textarea id="fb-msg" class="fb-textarea" rows="5"
|
|
680
|
+
<textarea id="fb-msg" class="fb-textarea" rows="5" aria-describedby="fb-length" data-i18n-placeholder="feedback.messagePlaceholder" placeholder="请描述遇到的问题或建议(必填,最多 20000 字符)"></textarea>
|
|
681
|
+
<p id="fb-length" class="feedback-length" role="status" aria-live="polite"></p>
|
|
682
|
+
<button id="fb-copy-draft" type="button" class="btn subtle fb-copy-draft">复制全文</button>
|
|
674
683
|
<input id="fb-contact" class="fb-input" maxlength="200" data-i18n-placeholder="feedback.contactPlaceholder" placeholder="联系方式(可选):邮箱 / 微信 / B站 ID">
|
|
675
684
|
<label class="fb-diagnostics"><input id="fb-include-diagnostics" type="checkbox"> <span data-i18n="feedback.includeDiagnostics">附带客户端与网关诊断(可选)</span><small data-i18n="feedback.diagnosticsPrivacy">上传客户端操作与错误位置、存储占用、版本和网关链路状态;不含令牌、Cookie、对话正文、答案或完整路径。可在下方预览。</small></label>
|
|
676
685
|
<label class="fb-diagnostics"><input id="fb-include-crashes" type="checkbox"> <span data-i18n="feedback.includeCrashes">附带崩溃日志摘要(可选)</span><small data-i18n="feedback.crashPrivacy">默认仅在本机记录。勾选后上传最近 3 条退出、重启和错误位置摘要,不含对话、密钥或完整路径。</small></label>
|
|
@@ -846,18 +855,8 @@
|
|
|
846
855
|
</div>
|
|
847
856
|
</div>
|
|
848
857
|
|
|
849
|
-
<!-- 皮肤选择模态 -->
|
|
850
|
-
<div id="modal-theme" class="modal hidden" role="dialog" aria-modal="true">
|
|
851
|
-
<div class="modal-card">
|
|
852
|
-
<div class="modal-title" data-i18n="theme.panelTitle">选择配色</div>
|
|
853
|
-
<div id="theme-options" class="theme-panel-list"></div>
|
|
854
|
-
<div class="modal-actions">
|
|
855
|
-
<button id="theme-close" class="btn subtle" data-i18n="theme.close">关闭</button>
|
|
856
|
-
</div>
|
|
857
|
-
</div>
|
|
858
|
-
</div>
|
|
859
|
-
|
|
860
858
|
<!-- 赞赏支持模态 -->
|
|
859
|
+
<script src="sponsor-entry.js" defer></script>
|
|
861
860
|
<div id="modal-donate" class="modal hidden" role="dialog" aria-modal="true">
|
|
862
861
|
<div class="modal-card">
|
|
863
862
|
<div class="modal-title" data-i18n="settings.donate">赞赏支持</div>
|
|
@@ -1187,8 +1186,8 @@
|
|
|
1187
1186
|
'settings.toolsTitle': '显示工具调用', 'settings.toolsDesc': '关闭后隐藏 🔧/📦 工具调用与结果',
|
|
1188
1187
|
'settings.mobileEnterTitle': '手机回车行为', 'settings.mobileEnterDesc': '选择手机端按 Enter 时换行或直接发送', 'settings.mobileEnterNewline': '回车换行', 'settings.mobileEnterSend': '回车发送',
|
|
1189
1188
|
'settings.langTitle': '语言 / Language', 'settings.langDesc': '界面语言,跟随系统或手动切换',
|
|
1190
|
-
'settings.themeTitle': '皮肤', 'settings.themeDesc': '默认深空 / 落日 / 易北爱乐厅 / 草原孤塔 / 黑曜白 / 蓝色大肥鱼',
|
|
1191
|
-
'theme.default': '默认深空', 'theme.dark': '落日', 'theme.light': '易北爱乐厅', 'theme.neutral': '草原孤塔', 'theme.mono': '黑曜白', 'theme.fish': '蓝色大肥鱼',
|
|
1189
|
+
'settings.themeTitle': '皮肤', 'settings.themeDesc': '默认深空 / 落日 / 易北爱乐厅 / 草原孤塔 / 黑曜白 / 蓝色大肥鱼 / 企鹅女管·白昼 / 企鹅女管·极夜 / 波奇酱 / 伊地知虹夏 / 山田凉 / 喜多郁代',
|
|
1190
|
+
'theme.default': '默认深空', 'theme.dark': '落日', 'theme.light': '易北爱乐厅', 'theme.neutral': '草原孤塔', 'theme.mono': '黑曜白', 'theme.fish': '蓝色大肥鱼', 'theme.penguin': '企鹅女管·白昼', 'theme.penguin-night': '企鹅女管·极夜', 'theme.bocchi': '波奇酱', 'theme.nijika': '伊地知虹夏', 'theme.ryo': '山田凉', 'theme.kita': '喜多郁代',
|
|
1192
1191
|
'theme.panelTitle': '选择配色', 'theme.close': '关闭',
|
|
1193
1192
|
'settings.tokenTitle': '访问令牌', 'settings.change': '更换',
|
|
1194
1193
|
'settings.unknown': '未知', 'settings.dshRecovering': '正在等待网关恢复并核验操作结果…',
|
|
@@ -1208,10 +1207,10 @@
|
|
|
1208
1207
|
'feedback.copied': '项目链接已复制', 'feedback.copyFailed': '复制失败,请手动复制',
|
|
1209
1208
|
'feedback.write': '写反馈', 'feedback.writeDesc': 'App 内直接提交', 'feedback.modalTitle': '写反馈', 'feedback.includeDiagnostics': '附带客户端与网关诊断(可选)', 'feedback.diagnosticsPrivacy': '上传客户端操作与错误位置、存储占用、版本和网关链路状态;不含令牌、Cookie、对话正文、答案或完整路径。可在下方预览。', 'feedback.includeCrashes': '附带崩溃日志摘要(可选)', 'feedback.crashPrivacy': '默认仅在本机记录。勾选后上传最近 3 条退出、重启和错误位置摘要,不含对话、密钥或完整路径。', 'feedback.crashPreview': '查看拟上传的日志摘要', 'feedback.crashLoading': '读取本机日志…', 'feedback.crashUnavailable': '当前网关暂时无法读取日志,请更新网关或稍后重试。',
|
|
1210
1209
|
'feedback.typeBug': 'Bug', 'feedback.typeSuggestion': '建议', 'feedback.typeOther': '其他',
|
|
1211
|
-
'feedback.messagePlaceholder': '
|
|
1210
|
+
'feedback.messagePlaceholder': '请描述遇到的问题或建议(必填,最多 20000 字符)',
|
|
1212
1211
|
'feedback.contactPlaceholder': '联系方式(可选):邮箱 / 微信 / B站 ID',
|
|
1213
1212
|
'feedback.cancel': '取消', 'feedback.submit': '提交',
|
|
1214
|
-
'feedback.empty': '请填写描述内容', 'feedback.tooLong': '描述不能超过
|
|
1213
|
+
'feedback.empty': '请填写描述内容', 'feedback.tooLong': '描述不能超过 20000 字符,全文已保留',
|
|
1215
1214
|
'feedback.submitted': '已提交,感谢反馈',
|
|
1216
1215
|
'feedback.successTitle': '反馈发送成功', 'feedback.successBody': '服务器已确认收到这条反馈,感谢你的帮助。', 'feedback.successConfirm': '知道了',
|
|
1217
1216
|
'feedback.rateLimited': '提交太频繁,请稍后再试', 'feedback.rateLimitedAt': '提交太频繁,请 {n} 秒后再试', 'feedback.submitFailed': '提交失败:{msg}', 'feedback.networkError': '网络错误',
|
|
@@ -1452,8 +1451,8 @@
|
|
|
1452
1451
|
'settings.toolsTitle': 'Show tool calls', 'settings.toolsDesc': 'Hide 🔧/📦 tool calls and results when off',
|
|
1453
1452
|
'settings.mobileEnterTitle': 'Mobile Enter behavior', 'settings.mobileEnterDesc': 'Choose whether Enter inserts a newline or sends', 'settings.mobileEnterNewline': 'Enter = newline', 'settings.mobileEnterSend': 'Enter = send',
|
|
1454
1453
|
'settings.langTitle': 'Language / 语言', 'settings.langDesc': 'UI language, follows system or switch manually',
|
|
1455
|
-
'settings.themeTitle': 'Theme', 'settings.themeDesc': 'Deep Space / Sunset / Elbphilharmonie / Prairie Tower / Monochrome / Blue Fat Fish',
|
|
1456
|
-
'theme.default': 'Default', 'theme.dark': 'Sunset', 'theme.light': 'Elbphilharmonie', 'theme.neutral': 'Prairie Tower', 'theme.mono': 'Monochrome', 'theme.fish': 'Blue Fat Fish',
|
|
1454
|
+
'settings.themeTitle': 'Theme', 'settings.themeDesc': 'Deep Space / Sunset / Elbphilharmonie / Prairie Tower / Monochrome / Blue Fat Fish / Penguin Admin Day / Penguin Admin Night / Bocchi / Nijika / Ryo / Kita',
|
|
1455
|
+
'theme.default': 'Default', 'theme.dark': 'Sunset', 'theme.light': 'Elbphilharmonie', 'theme.neutral': 'Prairie Tower', 'theme.mono': 'Monochrome', 'theme.fish': 'Blue Fat Fish', 'theme.penguin': 'Penguin Admin Day', 'theme.penguin-night': 'Penguin Admin Night', 'theme.bocchi': 'Bocchi', 'theme.nijika': 'Nijika', 'theme.ryo': 'Ryo', 'theme.kita': 'Kita',
|
|
1457
1456
|
'theme.panelTitle': 'Choose theme', 'theme.close': 'Close',
|
|
1458
1457
|
'settings.tokenTitle': 'Access token', 'settings.change': 'Change',
|
|
1459
1458
|
'settings.unknown': 'Unknown', 'settings.dshRecovering': 'Waiting for the gateway and verifying the operation…',
|
|
@@ -1473,10 +1472,10 @@
|
|
|
1473
1472
|
'feedback.copied': 'Project link copied', 'feedback.copyFailed': 'Copy failed, copy manually',
|
|
1474
1473
|
'feedback.write': 'Write feedback', 'feedback.writeDesc': 'Submit from the app', 'feedback.modalTitle': 'Write feedback', 'feedback.includeDiagnostics': 'Include client and gateway diagnostics (optional)', 'feedback.diagnosticsPrivacy': 'Uploads operation stages, error locations, storage sizes, versions and gateway status. No credentials, conversation bodies, answers or full paths. Preview below.', 'feedback.includeCrashes': 'Include crash summary (optional)', 'feedback.crashPrivacy': 'Recorded locally by default. Opt in to upload up to 3 recent exit, restart and error-location records. No conversations, credentials or full paths.', 'feedback.crashPreview': 'Preview the log summary to upload', 'feedback.crashLoading': 'Reading local logs…', 'feedback.crashUnavailable': 'Logs are unavailable. Update the gateway or try again later.',
|
|
1475
1474
|
'feedback.typeBug': 'Bug', 'feedback.typeSuggestion': 'Suggestion', 'feedback.typeOther': 'Other',
|
|
1476
|
-
'feedback.messagePlaceholder': 'Describe the bug or suggestion (required,
|
|
1475
|
+
'feedback.messagePlaceholder': 'Describe the bug or suggestion (required, up to 20000 characters)',
|
|
1477
1476
|
'feedback.contactPlaceholder': 'Contact (optional): email / WeChat / Bilibili ID',
|
|
1478
1477
|
'feedback.cancel': 'Cancel', 'feedback.submit': 'Submit',
|
|
1479
|
-
'feedback.empty': 'Please fill in the description', 'feedback.tooLong': 'Description must be
|
|
1478
|
+
'feedback.empty': 'Please fill in the description', 'feedback.tooLong': 'Description must be within 20000 characters; your text is preserved',
|
|
1480
1479
|
'feedback.submitted': 'Submitted — thanks!',
|
|
1481
1480
|
'feedback.successTitle': 'Feedback sent', 'feedback.successBody': 'The server confirmed receipt of your feedback. Thank you for helping improve DSH Remote.', 'feedback.successConfirm': 'Got it',
|
|
1482
1481
|
'feedback.rateLimited': 'Too frequent, try again later', 'feedback.rateLimitedAt': 'Too frequent, try again in {n}s', 'feedback.submitFailed': 'Submit failed: {msg}', 'feedback.networkError': 'Network error',
|
|
@@ -1517,6 +1516,8 @@
|
|
|
1517
1516
|
<script src="announcement-forms.js"></script>
|
|
1518
1517
|
<script src="activity.js"></script>
|
|
1519
1518
|
<script src="turn-results.js"></script>
|
|
1519
|
+
<script src="image-cache.js"></script>
|
|
1520
|
+
<script src="chat-copy.js"></script>
|
|
1520
1521
|
<script src="image-preview.js"></script>
|
|
1521
1522
|
<script src="link-check.js"></script>
|
|
1522
1523
|
<script src="network.js"></script>
|