dsh-remote-plugin 0.8.2 → 0.8.4
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/approval-summary.mjs +115 -0
- package/gateway.cjs +708 -70
- package/index.mjs +12 -0
- package/insights.mjs +6 -4
- package/market.mjs +4 -1
- package/package.json +2 -1
- package/plugin-center.mjs +208 -24
- package/plugin-transaction.mjs +29 -6
- package/public/admin.html +33 -34
- package/public/admin.js +12 -24
- package/public/announcements.json +31 -0
- package/public/app.js +99 -80
- package/public/approval-summary.js +78 -0
- package/public/build.json +2 -2
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/desktop/desktop.css +23 -34
- package/public/desktop/desktop.html +83 -96
- package/public/desktop/desktop.js +68 -51
- package/public/e2ee-transport.js +147 -0
- package/public/extensions.js +6 -6
- package/public/history.js +88 -6
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +48 -5
- package/public/index.html +86 -104
- package/public/md.js +39 -15
- package/public/motion.js +1 -1
- package/public/plugin-center.css +1 -0
- package/public/plugin-center.js +93 -12
- package/public/plugin.html +27 -20
- package/public/relay-devices.js +74 -0
- package/public/relay-settings.css +7 -0
- package/public/relay-settings.js +17 -9
- package/public/session-deck.css +7 -1
- package/public/session-deck.js +1 -1
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/preview.html +12 -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 +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 +29 -19
- package/public/teams.js +2 -2
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +532 -5
- package/public/theme.js +111 -3
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/public/workflow.css +2 -1
- package/public/workflow.js +27 -5
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +1 -1
- package/task-board.mjs +2 -2
- package/teams.mjs +7 -2
package/public/app.js
CHANGED
|
@@ -33,9 +33,9 @@ const CACHE = {
|
|
|
33
33
|
get sessions() { return connectionCacheKey('sessions') },
|
|
34
34
|
get history() { return connectionCacheKey('history') }
|
|
35
35
|
}
|
|
36
|
-
function connectionCacheKey(kind) {
|
|
36
|
+
function connectionCacheKey(kind, server=state.server, token=state.token) {
|
|
37
37
|
const hash = new SHA256()
|
|
38
|
-
hash.update(new TextEncoder().encode(JSON.stringify([
|
|
38
|
+
hash.update(new TextEncoder().encode(JSON.stringify([server || location.origin, token])))
|
|
39
39
|
return kind + 'CacheV2:' + hash.hex()
|
|
40
40
|
}
|
|
41
41
|
function cacheRead(key, d = null) {
|
|
@@ -120,6 +120,7 @@ for (const key of ['server', 'token']) {
|
|
|
120
120
|
if (next === value) return
|
|
121
121
|
cancelHistoryLoad()
|
|
122
122
|
value = next; connectionGeneration++
|
|
123
|
+
window.DshImagePreview?.reset?.()
|
|
123
124
|
clearTimeout(state.refreshTimer); state.refreshTimer = null
|
|
124
125
|
state.sessions = []; state.byId.clear(); state.pendingProjections.clear(); state.runtimeErrors = new Map()
|
|
125
126
|
state.hostInfo = null
|
|
@@ -139,6 +140,7 @@ for (const key of ['server', 'token']) {
|
|
|
139
140
|
window.DshExtensions?.invalidateCapabilities()
|
|
140
141
|
window.DshFileInbox?.reset()
|
|
141
142
|
window.DshSessionDeck?.reset()
|
|
143
|
+
window.DshApprovalSummary?.reset()
|
|
142
144
|
if (typeof document !== 'undefined') document.getElementById('btn-insights')?.classList.add('hidden')
|
|
143
145
|
if(typeof document!=='undefined') {
|
|
144
146
|
const identityGeneration=connectionGeneration
|
|
@@ -235,7 +237,6 @@ function customSelectOptionCopy(option) {
|
|
|
235
237
|
function openCustomSelect(select) {
|
|
236
238
|
const trigger = select?._customSelectTrigger
|
|
237
239
|
if (!select || !trigger || select.disabled) return
|
|
238
|
-
closeFeedbackSheet()
|
|
239
240
|
syncCustomSelect(select)
|
|
240
241
|
customSelectCurrent = { select, trigger }
|
|
241
242
|
const titleKey = CUSTOM_SELECT_TITLES[select.id]
|
|
@@ -313,12 +314,6 @@ function initCustomSelects() {
|
|
|
313
314
|
}
|
|
314
315
|
|
|
315
316
|
/* ---------------- 反馈 ---------------- */
|
|
316
|
-
const FEEDBACK_LINKS = {
|
|
317
|
-
githubIssues: 'https://github.com/Blank-not-black/dsh-Remote/issues',
|
|
318
|
-
giteeIssues: 'https://gitee.com/Blankneverfails/dsh-Remote/issues',
|
|
319
|
-
bili: 'https://space.bilibili.com/419009275/dynamic',
|
|
320
|
-
repo: 'https://github.com/Blank-not-black/dsh-Remote'
|
|
321
|
-
}
|
|
322
317
|
async function copyText(text) {
|
|
323
318
|
try { await navigator.clipboard.writeText(text); return true } catch {}
|
|
324
319
|
try {
|
|
@@ -329,22 +324,6 @@ async function copyText(text) {
|
|
|
329
324
|
ta.remove(); return ok
|
|
330
325
|
} catch { return false }
|
|
331
326
|
}
|
|
332
|
-
function openFeedbackSheet() {
|
|
333
|
-
window.DshExtensions?.closeShortcuts()
|
|
334
|
-
$('feedback-backdrop').classList.remove('hidden')
|
|
335
|
-
$('feedback-sheet').classList.remove('hidden')
|
|
336
|
-
$('btn-feedback').setAttribute('aria-expanded', 'true')
|
|
337
|
-
const first = $('feedback-sheet').querySelector('[role="menuitem"]')
|
|
338
|
-
if (first) first.focus()
|
|
339
|
-
}
|
|
340
|
-
function closeFeedbackSheet() {
|
|
341
|
-
$('feedback-backdrop').classList.add('hidden')
|
|
342
|
-
$('feedback-sheet').classList.add('hidden')
|
|
343
|
-
$('btn-feedback').setAttribute('aria-expanded', 'false')
|
|
344
|
-
}
|
|
345
|
-
function toggleFeedbackSheet() {
|
|
346
|
-
$('feedback-sheet').classList.contains('hidden') ? openFeedbackSheet() : closeFeedbackSheet()
|
|
347
|
-
}
|
|
348
327
|
function doctorEnvironment() {
|
|
349
328
|
let report = {}
|
|
350
329
|
try { report = globalThis.DshDiagnostics?.report?.() || {} } catch {}
|
|
@@ -362,7 +341,6 @@ function doctorEnvironment() {
|
|
|
362
341
|
}
|
|
363
342
|
}
|
|
364
343
|
function openDoctor() {
|
|
365
|
-
closeFeedbackSheet()
|
|
366
344
|
if (!window.DshDoctor) {
|
|
367
345
|
toast(t('feedback.submitFailed', { msg: 'doctor unavailable' }), 'err')
|
|
368
346
|
return
|
|
@@ -393,6 +371,7 @@ function openFeedbackModal(options = {}) {
|
|
|
393
371
|
$('fb-include-crashes').checked = false
|
|
394
372
|
$('fb-crash-details').open = false
|
|
395
373
|
}
|
|
374
|
+
updateFeedbackLength()
|
|
396
375
|
void loadCrashPreview()
|
|
397
376
|
$('modal-feedback').classList.remove('hidden')
|
|
398
377
|
setTimeout(() => $('fb-msg').focus(), 50)
|
|
@@ -404,7 +383,7 @@ function openFeedbackSuccess() {
|
|
|
404
383
|
}
|
|
405
384
|
function closeFeedbackSuccess() {
|
|
406
385
|
$('modal-feedback-success').classList.add('hidden')
|
|
407
|
-
$('btn-feedback')?.focus()
|
|
386
|
+
$('btn-feedback-open')?.focus()
|
|
408
387
|
}
|
|
409
388
|
async function loadCrashPreview() {
|
|
410
389
|
const generation=loadCrashPreview.generation=(loadCrashPreview.generation||0)+1
|
|
@@ -418,6 +397,12 @@ async function loadCrashPreview() {
|
|
|
418
397
|
if(crashes){const data=await read('/crash-logs');evidence.crashes=data.upload||data}
|
|
419
398
|
if(connection.valid()&&generation===loadCrashPreview.generation)preview.textContent=JSON.stringify(evidence,null,2)
|
|
420
399
|
}
|
|
400
|
+
function updateFeedbackLength() {
|
|
401
|
+
const length = $('fb-msg').value.trim().length, over = length > 20000
|
|
402
|
+
$('fb-length').textContent = I18N.lang === 'en' ? length + ' / 20000 characters' + (over ? ' — shorten before submitting; your text is preserved.' : '') : length + ' / 20000 字符' + (over ? ',请精简后提交;全文已保留。' : '')
|
|
403
|
+
$('fb-msg').setAttribute('aria-invalid', String(over))
|
|
404
|
+
$('fb-copy-draft').textContent = I18N.lang === 'en' ? 'Copy text' : '复制全文'
|
|
405
|
+
}
|
|
421
406
|
async function submitFeedback() {
|
|
422
407
|
const type = state.feedbackType || 'bug'
|
|
423
408
|
const message = $('fb-msg').value.trim()
|
|
@@ -426,7 +411,7 @@ async function submitFeedback() {
|
|
|
426
411
|
const includeCrashLogs = $('fb-include-crashes').checked
|
|
427
412
|
const clientDiagnostics=includeDiagnostics?globalThis.DshDiagnostics?.report():null
|
|
428
413
|
if (!message) { toast(t('feedback.empty'), 'err'); return }
|
|
429
|
-
if (message.length >
|
|
414
|
+
if (message.length > 20000) { toast(t('feedback.tooLong'), 'err'); return }
|
|
430
415
|
const btn = $('fb-submit')
|
|
431
416
|
btn.disabled = true
|
|
432
417
|
const diagnostic=globalThis.DshDiagnostics?.start('feedback.submit')
|
|
@@ -447,10 +432,15 @@ async function submitFeedback() {
|
|
|
447
432
|
status.classList.toggle('hidden',!clientDiagnostics)
|
|
448
433
|
}
|
|
449
434
|
else if (res.status === 429) { toast(json.retryAfter ? t('feedback.rateLimitedAt', { n: json.retryAfter }) : t('feedback.rateLimited'), 'err') }
|
|
435
|
+
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') }
|
|
436
|
+
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') }
|
|
437
|
+
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') }
|
|
438
|
+
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') }
|
|
439
|
+
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') }
|
|
450
440
|
else { toast(t('feedback.submitFailed', { msg: json.error || res.status }), 'err') }
|
|
451
441
|
} catch(error) {
|
|
452
442
|
diagnostic?.fail(error)
|
|
453
|
-
toast(
|
|
443
|
+
toast(I18N.lang === 'en' ? 'Delivery is unconfirmed; it may have been received. Your text is preserved. Check before resubmitting.' : '发送结果未确认,可能已收到。全文已保留,请先核对,勿重复提交。', 'err')
|
|
454
444
|
} finally {
|
|
455
445
|
btn.disabled = false
|
|
456
446
|
}
|
|
@@ -1184,6 +1174,8 @@ function editServer(id) {
|
|
|
1184
1174
|
function removeServer(id) {
|
|
1185
1175
|
const s = state.servers.find(x => x.id === id)
|
|
1186
1176
|
if (!s) return
|
|
1177
|
+
void window.DshImageCache?.clear(historyCacheScope(s.url,serverToken(s)))
|
|
1178
|
+
void window.DshHistory.cacheClear(historyCacheScope(s.url,serverToken(s)))
|
|
1187
1179
|
state.servers = state.servers.filter(x => x.id !== id)
|
|
1188
1180
|
const wasActive = state.server === s.url && state.token === serverToken(s)
|
|
1189
1181
|
// 清理该组手动指定
|
|
@@ -2785,7 +2777,11 @@ function restoreCachedSessionList() {
|
|
|
2785
2777
|
}
|
|
2786
2778
|
|
|
2787
2779
|
let conversationView = null
|
|
2788
|
-
function historyCacheScope() { return
|
|
2780
|
+
function historyCacheScope(server=state.server,token=state.token) { return connectionCacheKey('history',server,token) }
|
|
2781
|
+
function captureChatImage() {
|
|
2782
|
+
const connection=captureConnection(),sessionId=state.current
|
|
2783
|
+
return {scope:historyCacheScope(),valid:()=>connection.valid()&&state.current===sessionId}
|
|
2784
|
+
}
|
|
2789
2785
|
function historySource(value) {
|
|
2790
2786
|
state.history.source=value
|
|
2791
2787
|
const el=$('history-source')
|
|
@@ -2965,6 +2961,10 @@ function canForkTurnResult() {
|
|
|
2965
2961
|
return !!session && session.origin !== 'subagent' && session.formatStatus !== 'migration-required' && activeGatewayCapability('operations') === true
|
|
2966
2962
|
}
|
|
2967
2963
|
function bindTurnResultActions() {
|
|
2964
|
+
window.DshChatCopy?.bind($('history'), {
|
|
2965
|
+
capture: () => { const connection = captureConnection(), sessionId = state.current, history = state.history; return { history, valid: () => connection.valid() && state.current === sessionId && state.history === history } },
|
|
2966
|
+
copy: copyText, notice: toast,
|
|
2967
|
+
})
|
|
2968
2968
|
window.DshTurnResults.bind($('history'), {
|
|
2969
2969
|
capture: () => {
|
|
2970
2970
|
const connection = captureConnection(), sessionId = state.current, history = state.history
|
|
@@ -3177,7 +3177,7 @@ function blockHtml(b,index=0,context={}) {
|
|
|
3177
3177
|
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)})})
|
|
3178
3178
|
}
|
|
3179
3179
|
switch (b.type) {
|
|
3180
|
-
case '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>` : ''
|
|
3180
|
+
case 'text': return window.DshActivity.hasVisibleText(b.text) ? `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true, imageLabel: t('block.image'), copyCode: true, copyScope: window.DshChatCopy?.scope(state.history), copyCodeLabel: window.I18N?.lang === 'en' ? 'Copy code' : '复制代码' }) : esc(b.text ?? '')}</div>` : ''
|
|
3181
3181
|
case 'file': if (typeof window !== 'undefined' && window.DshChatFiles) return window.DshChatFiles.render(b); return `<div class="tool">📎 ${esc(b.attachment?.name || b.name || 'file')} <small>${esc(b.attachment?.bytes ?? b.bytes ?? '')} bytes</small></div>`
|
|
3182
3182
|
case 'image': {
|
|
3183
3183
|
if (b.attachment && window.DshImagePreview) return window.DshImagePreview.attachmentHtml(b.attachment, t('block.image'), state.current)
|
|
@@ -3187,7 +3187,7 @@ function blockHtml(b,index=0,context={}) {
|
|
|
3187
3187
|
case 'thinking':
|
|
3188
3188
|
case 'reasoning':
|
|
3189
3189
|
return `<details class="tool"><summary>${t('block.thinking')}</summary><div class="tool-text">${esc(truncate(String(b.text ?? b.content ?? safeJson(b)), 6000))}</div></details>`
|
|
3190
|
-
case 'code': return `<pre>${esc(b.content ?? b.code ?? '')}</pre>`
|
|
3190
|
+
case 'code': return window.DshChatCopy?.code(b.content ?? b.code ?? '', b.language || b.lang || '', { scope: window.DshChatCopy?.scope(state.history) }) || `<pre>${esc(b.content ?? b.code ?? '')}</pre>`
|
|
3191
3191
|
case 'tool-call':
|
|
3192
3192
|
return `<details class="tool"><summary>🔧 ${esc(b.name || b.toolName || t('block.toolCall'))}</summary><pre>${esc(truncate(safeJson(b.arguments ?? b), 4000))}</pre></details>`
|
|
3193
3193
|
case 'tool-result':
|
|
@@ -5424,6 +5424,8 @@ const ANNOUNCEMENTS_KEY = 'seenAnnouncementsV1'
|
|
|
5424
5424
|
const ANNOUNCEMENT_HISTORY_KEY = 'announcementHistoryV1'
|
|
5425
5425
|
const ANNOUNCEMENT_VOTES_KEY = 'announcementVotesV1'
|
|
5426
5426
|
const ANNOUNCEMENTS_POLL_MS = 30 * 1000
|
|
5427
|
+
const announcementDeferred = new Set()
|
|
5428
|
+
const announcementDeferralKey = item => updateBase() + ':' + item.id
|
|
5427
5429
|
let announcementCheckPromise = null
|
|
5428
5430
|
let announcementPollTimer = null
|
|
5429
5431
|
let announcementPollingStarted = false
|
|
@@ -5474,6 +5476,7 @@ function writeAnnouncementStorage(key, value) {
|
|
|
5474
5476
|
})
|
|
5475
5477
|
}
|
|
5476
5478
|
function resetAnnouncementStorage() {
|
|
5479
|
+
announcementDeferred.clear()
|
|
5477
5480
|
for (const key of [ANNOUNCEMENTS_KEY, ANNOUNCEMENT_HISTORY_KEY, ANNOUNCEMENT_VOTES_KEY]) {
|
|
5478
5481
|
LS.del(key)
|
|
5479
5482
|
clearAnnouncementFallback(key)
|
|
@@ -5821,6 +5824,11 @@ async function submitAnnouncementVote() {
|
|
|
5821
5824
|
}
|
|
5822
5825
|
function closeAnnouncement(markSeen) {
|
|
5823
5826
|
if (markSeen) markAnnouncementsSeen(state.announcementItems)
|
|
5827
|
+
else {
|
|
5828
|
+
for (const item of state.announcementItems) if (!item.force) announcementDeferred.add(announcementDeferralKey(item))
|
|
5829
|
+
// Deferral is session-only and bounded; unread/history state is unchanged.
|
|
5830
|
+
while (announcementDeferred.size > 200) announcementDeferred.delete(announcementDeferred.values().next().value)
|
|
5831
|
+
}
|
|
5824
5832
|
globalThis.DshDiagnostics?.record('announcement.close',{phase:markSeen?'acknowledged':'dismissed',announcementId:state.announcement?.id,count:state.announcementItems.length})
|
|
5825
5833
|
state.announcement = null
|
|
5826
5834
|
state.announcementItems = []
|
|
@@ -5846,6 +5854,7 @@ async function fetchAnnouncements() {
|
|
|
5846
5854
|
renderAnnouncementBoard()
|
|
5847
5855
|
const seen = readSeenAnnouncements()
|
|
5848
5856
|
const items = normalized.filter(item => !seen[item.id])
|
|
5857
|
+
.filter(item => item.force || !announcementDeferred.has(announcementDeferralKey(item)))
|
|
5849
5858
|
.sort((a, b) => b.publishedAt - a.publishedAt)
|
|
5850
5859
|
// 新旧界面均提示未读公告;拉取期间新出现的版本提醒仍优先展示。
|
|
5851
5860
|
if (!items.length || state.announcement || isAppVersionWarningOpen()) { diagnostic?.end({phase:'skipped',count:items.length,reason:state.announcement?'already-open':isAppVersionWarningOpen()?'version-warning':'already-read'}); return false }
|
|
@@ -7768,7 +7777,13 @@ const THEME_META = [
|
|
|
7768
7777
|
{ id: 'light', sw: ['#F5F7F8', '#FFFFFF', '#176B87'] },
|
|
7769
7778
|
{ id: 'neutral', sw: ['#EEF1E8', '#FAFBF6', '#47643C'] },
|
|
7770
7779
|
{ id: 'mono', sw: ['#050505', '#333333', '#F5F5F5'] },
|
|
7771
|
-
{ id: 'fish', sw: ['#EAF6FF', '#FFFFFF', '#2F52D0'] }
|
|
7780
|
+
{ id: 'fish', sw: ['#EAF6FF', '#FFFFFF', '#2F52D0'] },
|
|
7781
|
+
{ id: 'penguin', sw: ['#EDF3FA', '#FFFFFF', '#2B6CB0'] },
|
|
7782
|
+
{ id: 'penguin-night', sw: ['#10151B', '#1A222C', '#F2C230'] },
|
|
7783
|
+
{ id: 'bocchi', sw: ['#FFD9E8', '#FFFFFF', '#D0105A'] },
|
|
7784
|
+
{ id: 'nijika', sw: ['#FFF3D5', '#FFFFFF', '#94600C'] },
|
|
7785
|
+
{ id: 'ryo', sw: ['#E9F1FA', '#FFFFFF', '#315D91'] },
|
|
7786
|
+
{ id: 'kita', sw: ['#FFE9E5', '#FFFFFF', '#B6373C'] }
|
|
7772
7787
|
]
|
|
7773
7788
|
|
|
7774
7789
|
function renderThemeBtn() {
|
|
@@ -7776,28 +7791,11 @@ function renderThemeBtn() {
|
|
|
7776
7791
|
if (btn) btn.textContent = t('theme.' + window.DSHTheme.get())
|
|
7777
7792
|
}
|
|
7778
7793
|
|
|
7779
|
-
function renderThemeOptions() {
|
|
7780
|
-
const box = $('theme-options')
|
|
7781
|
-
if (!box) return
|
|
7782
|
-
const cur = window.DSHTheme.get()
|
|
7783
|
-
box.innerHTML = THEME_META.map(m => `
|
|
7784
|
-
<button type="button" class="theme-option ${m.id === cur ? 'current' : ''}" data-theme="${m.id}" aria-pressed="${m.id === cur}" title="${t('theme.' + m.id)}">
|
|
7785
|
-
<span class="theme-swatches">${m.sw.map(c => `<i style="background:${c}"></i>`).join('')}</span>
|
|
7786
|
-
<span class="theme-name">${t('theme.' + m.id)}</span>
|
|
7787
|
-
<span class="theme-check">${m.id === cur ? '✓' : ''}</span>
|
|
7788
|
-
</button>`).join('')
|
|
7789
|
-
box.querySelectorAll('.theme-option').forEach(btn =>
|
|
7790
|
-
btn.addEventListener('click', () => {
|
|
7791
|
-
window.DSHTheme.set(btn.dataset.theme)
|
|
7792
|
-
renderThemeBtn()
|
|
7793
|
-
renderThemeOptions()
|
|
7794
|
-
$('modal-theme').classList.add('hidden')
|
|
7795
|
-
}))
|
|
7796
|
-
}
|
|
7797
|
-
|
|
7798
7794
|
function openThemePanel() {
|
|
7799
|
-
|
|
7800
|
-
|
|
7795
|
+
window.DSHTheme.openPicker({
|
|
7796
|
+
themes: THEME_META, label: id => t('theme.' + id), lang: I18N.lang,
|
|
7797
|
+
onSelect: id => { window.DSHTheme.set(id); renderThemeBtn() }
|
|
7798
|
+
})
|
|
7801
7799
|
}
|
|
7802
7800
|
|
|
7803
7801
|
function openDonateModal() {
|
|
@@ -7851,8 +7849,6 @@ function bindUi() {
|
|
|
7851
7849
|
$('token-desc').textContent = state.token ? t('token.savedLocal') : t('token.notSet')
|
|
7852
7850
|
})
|
|
7853
7851
|
$('btn-theme').addEventListener('click', openThemePanel)
|
|
7854
|
-
$('theme-close').addEventListener('click', () => $('modal-theme').classList.add('hidden'))
|
|
7855
|
-
$('btn-donate').addEventListener('click', openDonateModal)
|
|
7856
7852
|
$('donate-close').addEventListener('click', () => $('modal-donate').classList.add('hidden'))
|
|
7857
7853
|
document.addEventListener('click', (e) => {
|
|
7858
7854
|
if (e.target.closest('[data-donate-open]')) openDonateModal()
|
|
@@ -7941,7 +7937,7 @@ function bindUi() {
|
|
|
7941
7937
|
$('conn-badge').addEventListener('click', () => { toast(t('common.refreshing')); openStreams(); void refreshAll() })
|
|
7942
7938
|
window.DshExtensions?.bindShortcuts({ trigger: $('btn-plugin-shortcuts'), menu: $('plugin-shortcuts-menu'),
|
|
7943
7939
|
config: () => optionalPluginConfig(), connected: () => !!state.token, hasSession: () => !!state.current,
|
|
7944
|
-
beforeOpen: () => {
|
|
7940
|
+
beforeOpen: () => { closeGroupDrawer({ restoreFocus: false }) },
|
|
7945
7941
|
open: route => { if (route === 'context') void openInsights('context', true); else showView('view-plugins', route) } })
|
|
7946
7942
|
$('overview-refresh').addEventListener('click', () => {
|
|
7947
7943
|
toast(t('common.refreshing'))
|
|
@@ -7949,21 +7945,11 @@ function bindUi() {
|
|
|
7949
7945
|
void Promise.all([refreshAll(), checkAnnouncements()])
|
|
7950
7946
|
})
|
|
7951
7947
|
// 反馈
|
|
7952
|
-
$('btn-feedback').addEventListener('click', (e) => { e.stopPropagation(); toggleFeedbackSheet() })
|
|
7953
|
-
$('feedback-backdrop').addEventListener('click', closeFeedbackSheet)
|
|
7954
|
-
$('feedback-sheet').addEventListener('click', (e) => {
|
|
7955
|
-
if (e.target.closest('a[role="menuitem"]')) closeFeedbackSheet()
|
|
7956
|
-
})
|
|
7957
|
-
$('btn-copy-link').addEventListener('click', async () => {
|
|
7958
|
-
const ok = await copyText(FEEDBACK_LINKS.repo)
|
|
7959
|
-
toast(t(ok ? 'feedback.copied' : 'feedback.copyFailed'), ok ? 'ok' : 'err')
|
|
7960
|
-
closeFeedbackSheet()
|
|
7961
|
-
})
|
|
7962
|
-
$('btn-write-feedback').addEventListener('click', () => { closeFeedbackSheet(); openFeedbackModal() })
|
|
7963
|
-
$('btn-doctor').addEventListener('click', openDoctor)
|
|
7964
7948
|
$('home-doctor').addEventListener('click', openDoctor)
|
|
7965
7949
|
$('fb-cancel').addEventListener('click', closeFeedbackModal)
|
|
7966
7950
|
$('fb-submit').addEventListener('click', submitFeedback)
|
|
7951
|
+
$('fb-msg').addEventListener('input', updateFeedbackLength)
|
|
7952
|
+
$('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') })
|
|
7967
7953
|
$('fb-include-diagnostics').addEventListener('change',()=>{void loadCrashPreview()})
|
|
7968
7954
|
$('fb-include-crashes').addEventListener('change',()=>{void loadCrashPreview()})
|
|
7969
7955
|
$('feedback-success-confirm').addEventListener('click', closeFeedbackSuccess)
|
|
@@ -7975,12 +7961,8 @@ function bindUi() {
|
|
|
7975
7961
|
state.feedbackType = btn.dataset.fbType
|
|
7976
7962
|
document.querySelectorAll('#fb-chips .fb-chip').forEach(b => b.classList.toggle('current', b === btn))
|
|
7977
7963
|
}))
|
|
7978
|
-
document.addEventListener('click', (e) => {
|
|
7979
|
-
if (!e.target.closest('#feedback-sheet') && !e.target.closest('#btn-feedback')) closeFeedbackSheet()
|
|
7980
|
-
})
|
|
7981
7964
|
document.addEventListener('keydown', (e) => {
|
|
7982
|
-
if (e.key === 'Escape' && !$('feedback-
|
|
7983
|
-
else if (e.key === 'Escape' && !$('modal-feedback-success').classList.contains('hidden')) closeFeedbackSuccess()
|
|
7965
|
+
if (e.key === 'Escape' && !$('modal-feedback-success').classList.contains('hidden')) closeFeedbackSuccess()
|
|
7984
7966
|
else if (e.key === 'Escape' && isAppVersionWarningOpen()) closeAppVersionWarning(false)
|
|
7985
7967
|
})
|
|
7986
7968
|
$('btn-new-session').addEventListener('click', newSession)
|
|
@@ -8220,6 +8202,7 @@ function bindUi() {
|
|
|
8220
8202
|
if (!confirm(t('settings.confirmReset'))) return
|
|
8221
8203
|
clearTimeout(scheduleHistoryCacheSave._t)
|
|
8222
8204
|
await window.DshHistory.cacheClear()
|
|
8205
|
+
await window.DshImageCache?.clear()
|
|
8223
8206
|
LS.del('token'); LS.del('notify'); LS.del('server'); LS.del('mobileEnterAction'); LS.del('steerSendingEnabled'); LS.del('busySendMode'); resetAnnouncementStorage()
|
|
8224
8207
|
if (bgBridge()?.saveBackgroundConfig) saveBgConfig(false)
|
|
8225
8208
|
location.reload()
|
|
@@ -8319,7 +8302,7 @@ function bindUi() {
|
|
|
8319
8302
|
bindFsPullRefresh()
|
|
8320
8303
|
|
|
8321
8304
|
bindRail()
|
|
8322
|
-
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment })
|
|
8305
|
+
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment, capture: captureChatImage })
|
|
8323
8306
|
|
|
8324
8307
|
for (const id of ['history', 'question-body']) window.DshChatFiles?.bind($(id), () => {
|
|
8325
8308
|
const c=captureConnection(),sessionId=id==='history'?state.current:state.questionModal?.sessionId
|
|
@@ -8394,6 +8377,7 @@ function mountWorkflow() {
|
|
|
8394
8377
|
settings: name => { showView('view-settings'); showSettingsPage(name) },
|
|
8395
8378
|
plugins: () => showView('view-plugins'), models: loadSessionModels, send: sendMessage,
|
|
8396
8379
|
feedback: openFeedbackModal,
|
|
8380
|
+
doctor: openDoctor,
|
|
8397
8381
|
browse: () => { closeNewSessionModal(); showView('view-files') },
|
|
8398
8382
|
register: async () => {
|
|
8399
8383
|
const connection=captureConnection(), path=state.fs.path
|
|
@@ -8408,6 +8392,17 @@ function mountWorkflow() {
|
|
|
8408
8392
|
command: runSlashCommand, refresh: refreshAll, retry: () => { startOverviewDetection(true); void refreshAll() },
|
|
8409
8393
|
operations: () => { const connection=captureConnection(); return { url:apiUrl,headers:{authorization:'Bearer '+connection.token},valid:connection.valid } },
|
|
8410
8394
|
relay: () => { const connection=captureConnection(); return { url:()=>adminApiUrl('/admin/api/relay'),headers:{authorization:'Bearer '+connection.token},valid:connection.valid,connected:!!connection.token } },
|
|
8395
|
+
e2eeConnect: (origin, connection) => {
|
|
8396
|
+
if (!connection.valid()) return
|
|
8397
|
+
const token = connection.headers.authorization.slice(7)
|
|
8398
|
+
closeStream('mux'); closeStream('host'); stopPolling(); state.wsTicket = null
|
|
8399
|
+
if (applyPairUrl('dshremote://pair?' + new URLSearchParams({ server: origin, token }).toString())) { void refreshAll(); openStreams() }
|
|
8400
|
+
},
|
|
8401
|
+
e2eeModeChange: (origin, connection) => {
|
|
8402
|
+
if (!connection.valid() || new URL(apiUrl('/relay'),location.href).origin !== origin) return
|
|
8403
|
+
closeStream('mux'); closeStream('host'); stopPolling(); state.wsTicket = null
|
|
8404
|
+
syncBgConfig(); void refreshAll(); openStreams()
|
|
8405
|
+
},
|
|
8411
8406
|
discover: () => { if (confirm('登记当前绑定目录下的子目录为工作区?')) void refreshWorkbench({ discover: true }) },
|
|
8412
8407
|
files: () => {
|
|
8413
8408
|
const workspace = workspaceForSession(state.byId.get(state.current))
|
|
@@ -8467,20 +8462,32 @@ function mountOnboarding() {
|
|
|
8467
8462
|
async function clearWorkflowData(kind) {
|
|
8468
8463
|
const english = window.I18N?.lang === 'en'
|
|
8469
8464
|
const messages = { history: english ? 'Clear cached conversation history on this device?' : '清除这台设备的会话历史缓存?主机记录保留。',
|
|
8470
|
-
|
|
8465
|
+
images: english ? 'Clear cached images on this device? Images will download again when viewed.' : '清除本机图片缓存?再次查看时会重新下载。',
|
|
8466
|
+
caches: english ? 'Clear history and image caches? Connections and preferences will be kept.' : '清除本机历史和图片缓存?保留连接、凭证与偏好设置。',
|
|
8467
|
+
connection: english ? 'Remove this connection, credential and its caches? Other connections will be kept.' : '移除当前地址、保存的凭证及其缓存?其他连接条目保留。',
|
|
8471
8468
|
all: english ? 'Clear all Remote settings and credentials on this device and stop background reminders?' : '清除本机全部 Remote 配置与凭证,并停止后台轮询和提醒?主机数据保留。' }
|
|
8472
8469
|
if (!confirm(messages[kind])) return
|
|
8473
|
-
if (
|
|
8470
|
+
if (['history','images','caches'].includes(kind)) {
|
|
8474
8471
|
clearTimeout(scheduleHistoryCacheSave._t)
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8472
|
+
if(kind!=='images')cancelHistoryLoad()
|
|
8473
|
+
const results=[]
|
|
8474
|
+
if(kind!=='images')results.push(await window.DshHistory.cacheClear())
|
|
8475
|
+
if(kind!=='history')results.push(await window.DshImageCache.clear())
|
|
8476
|
+
if(results.includes(false))return toast(english?'Some caches could not be cleared. Retry shortly.':'部分缓存未能清除,请稍后重试。','err')
|
|
8477
|
+
return toast(english ? 'Cache cleared' : '缓存已清除', 'ok')
|
|
8478
8478
|
}
|
|
8479
8479
|
window.NativeBackground?.saveBackgroundConfig?.(JSON.stringify({ enabled:false, base:'', token:'', clientId:'', intervalMin:1, notifyTaskDone:false }))
|
|
8480
8480
|
window.NativeBackground?.savePeakReminderConfig?.(JSON.stringify({ enabled:false }))
|
|
8481
8481
|
window.NativeBackground?.setPendingNotificationsEnabled?.(false)
|
|
8482
8482
|
if (kind === 'connection') {
|
|
8483
|
+
const connection=captureConnection(),scope=historyCacheScope()
|
|
8484
|
+
cancelHistoryLoad()
|
|
8485
|
+
await window.DshImageCache.clear(scope)
|
|
8486
|
+
await window.DshHistory.cacheClear(scope)
|
|
8487
|
+
if(!connection.valid())return
|
|
8483
8488
|
const current = currentServerEntry()
|
|
8489
|
+
const remaining = current ? state.servers.filter(server => server.id !== current.id) : state.servers
|
|
8490
|
+
if (!remaining.some(server => server.url === state.server) && window.NativeE2ee?.remove?.(state.server) === false) return toast(english ? 'Unable to remove encrypted pairing.' : '加密配对未能清理,请重试。','err')
|
|
8484
8491
|
if (current) state.servers = state.servers.filter(server => server.id !== current.id)
|
|
8485
8492
|
state.groupActive[state.activeGroup] = ''
|
|
8486
8493
|
state.token = ''; state.server = ''; LS.del('token'); LS.del('server'); saveServers()
|
|
@@ -8488,10 +8495,13 @@ async function clearWorkflowData(kind) {
|
|
|
8488
8495
|
return
|
|
8489
8496
|
}
|
|
8490
8497
|
await cancelPeakReminders()
|
|
8498
|
+
cancelHistoryLoad()
|
|
8491
8499
|
clearTimeout(scheduleHistoryCacheSave._t)
|
|
8492
8500
|
await window.DshHistory.cacheClear()
|
|
8501
|
+
await window.DshImageCache.clear()
|
|
8493
8502
|
resetAnnouncementStorage()
|
|
8494
8503
|
window.DshWorkflow.clearStorage()
|
|
8504
|
+
if (window.NativeE2ee?.clear?.() === false) return toast(english ? 'Encrypted pairing could not be cleared. Retry.' : '加密配对未能清理,请重试。','err')
|
|
8495
8505
|
location.reload()
|
|
8496
8506
|
}
|
|
8497
8507
|
|
|
@@ -8537,3 +8547,12 @@ globalThis.DshFileInbox?.mount({ capture: captureConnection, url: apiUrl,
|
|
|
8537
8547
|
headers: connection => ({ authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': CAP?.isNativePlatform?.() ? 'app' : 'web', ...clientIdHeaders() }),
|
|
8538
8548
|
native: () => CAP?.isNativePlatform?.() ? window.NativeFile : null })
|
|
8539
8549
|
globalThis.DshSessionDeck?.mount({ context: () => ({ sessionId: state.current, inChat: !$('view-session').classList.contains('hidden') }) })
|
|
8550
|
+
globalThis.DshApprovalSummary?.mount({ capture: captureConnection, items: () => state.approvals,
|
|
8551
|
+
url: (connection, path) => connection.server + path,
|
|
8552
|
+
headers: connection => ({ authorization: 'Bearer ' + connection.token, ...clientIdHeaders() }) })
|
|
8553
|
+
globalThis.DshCacheUpgrade?.mount({
|
|
8554
|
+
scopes:()=>state.servers.map(server=>historyCacheScope(server.url,serverToken(server))),
|
|
8555
|
+
safe:()=>!state.current&&!state.approvals.length&&!state.questions.length&&!composerSending
|
|
8556
|
+
&&![...document.querySelectorAll('textarea,input:not([type="checkbox"]):not([type="radio"])')].some(input=>input.getBoundingClientRect().width&&input.value)
|
|
8557
|
+
&&!document.querySelector('[data-transfer-id]')&&!state.sessions.some(session=>session.running)
|
|
8558
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* Explicit, cached explanations. No summary request is made during rendering. */
|
|
2
|
+
;(function (root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const cache = new Map()
|
|
5
|
+
let config, scope, mounted = false
|
|
6
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
7
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({ '&':'&', '<':'<', '>':'>', '"':'"', "'":''' }[c]))
|
|
8
|
+
function context() {
|
|
9
|
+
const connection = config?.capture()
|
|
10
|
+
if (scope && !scope.valid()) reset()
|
|
11
|
+
if (connection) scope = connection
|
|
12
|
+
return connection
|
|
13
|
+
}
|
|
14
|
+
const keyOf = item => JSON.stringify([item.sessionId, item.approvalId, item.callId || '', item.reason || ''])
|
|
15
|
+
const eligible = item => /^Auto review denied tool "[^"]+"(?::|$)/.test(item?.reason || '')
|
|
16
|
+
const current = item => config.items().some(value => keyOf(value) === keyOf(item))
|
|
17
|
+
function html(item) {
|
|
18
|
+
if (!eligible(item)) return ''
|
|
19
|
+
context()
|
|
20
|
+
const row = cache.get(keyOf(item))
|
|
21
|
+
const label = text('AI 中文总结(消耗 token)', 'AI Chinese summary (uses tokens)')
|
|
22
|
+
return '<section class="approval-ai" data-approval-ai="' + esc(item.approvalId) + '" data-ai-session="' + esc(item.sessionId) + '">'
|
|
23
|
+
+ '<button type="button" class="deck-summary-button" data-ai-generate' + (row ? ' disabled' : '') + '>' + (row?.phase === 'loading' ? text('正在生成…', 'Generating…') : label) + '</button>'
|
|
24
|
+
+ '<p class="approval-ai-copy" role="status">' + esc(row?.text || text('按需生成,仅供参考;请结合完整请求决定。', 'Optional reference; decide using the full request.')) + '</p></section>'
|
|
25
|
+
}
|
|
26
|
+
function update(item) {
|
|
27
|
+
for (const node of root.document?.querySelectorAll('[data-approval-ai]') || []) {
|
|
28
|
+
if (node.dataset.approvalAi !== item.approvalId || node.dataset.aiSession !== item.sessionId) continue
|
|
29
|
+
// Set text only; model output is never interpreted as HTML or Markdown.
|
|
30
|
+
const row = cache.get(keyOf(item)), button = node.querySelector('[data-ai-generate]'), copy = node.querySelector('[role="status"]')
|
|
31
|
+
if (button) { button.disabled = !!row; button.textContent = row?.phase === 'loading' ? text('正在生成…','Generating…') : text('AI 中文总结(消耗 token)','AI Chinese summary (uses tokens)') }
|
|
32
|
+
if (copy && row) copy.textContent = row.text
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function generate(item) {
|
|
36
|
+
const connection = context(), key = keyOf(item)
|
|
37
|
+
if (!connection?.valid() || !eligible(item) || cache.has(key) || !current(item)) return
|
|
38
|
+
if (!root.confirm(text('将此审批的工具名和审查理由交给当前会话配置的模型生成中文短摘要,会消耗 token;不发送完整对话或工具参数。摘要仅供参考,原始请求和审批决定保持不变。是否继续?',
|
|
39
|
+
'Send this approval’s tool name and review reason to the current session model for a Chinese summary? This uses tokens. Full conversation and tool arguments are excluded. The summary is only a reference; the request and approval decision remain unchanged.'))) return
|
|
40
|
+
if (!connection.valid() || !current(item)) return
|
|
41
|
+
while (cache.size >= 40) {
|
|
42
|
+
const old = [...cache].find(([, value]) => value.phase !== 'loading')
|
|
43
|
+
if (!old) return
|
|
44
|
+
cache.delete(old[0])
|
|
45
|
+
}
|
|
46
|
+
const controller = new AbortController(), row = { phase: 'loading', controller, text: text('正在生成,不影响允许或拒绝。','Generating; Allow and Reject remain available.') }
|
|
47
|
+
cache.set(key, row); update(item)
|
|
48
|
+
const timer = setTimeout(() => controller.abort(), 18_000)
|
|
49
|
+
try {
|
|
50
|
+
const response = await root.fetch(config.url(connection, '/remote/api/approval-summary'), { method: 'POST',
|
|
51
|
+
headers: { ...config.headers(connection), 'content-type':'application/json' },
|
|
52
|
+
body: JSON.stringify({ sessionId:item.sessionId, approvalId:item.approvalId, ...(item.callId ? { callId:item.callId } : {}), consent:true }),
|
|
53
|
+
signal:controller.signal })
|
|
54
|
+
const value = await response.json()
|
|
55
|
+
if (!response.ok || value.ok !== true || typeof value.summary !== 'string' || value.summary.length > 240) throw Error('unavailable')
|
|
56
|
+
row.phase = 'done'; row.text = text('AI 中文总结(仅供参考):','AI Chinese summary (reference only): ') + value.summary
|
|
57
|
+
} catch {
|
|
58
|
+
row.phase = 'error'; row.text = text('摘要未生成,可能已产生 token 消耗;请查看原始理由。本请求不会自动重试。','Summary unavailable; tokens may have been used. Read the original reason. This request will not retry automatically.')
|
|
59
|
+
} finally {
|
|
60
|
+
clearTimeout(timer)
|
|
61
|
+
if (connection.valid() && cache.get(key) === row && current(item)) update(item)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function reset() { for (const row of cache.values()) row.controller?.abort(); cache.clear(); scope = null }
|
|
65
|
+
function mount(value) {
|
|
66
|
+
config = value
|
|
67
|
+
if (mounted) return
|
|
68
|
+
mounted = true
|
|
69
|
+
root.document?.addEventListener('click', event => {
|
|
70
|
+
const button = event.target?.closest?.('[data-ai-generate]'), node = button?.closest('[data-approval-ai]')
|
|
71
|
+
if (!node) return
|
|
72
|
+
event.preventDefault(); event.stopPropagation()
|
|
73
|
+
const item = config.items().find(item => item.approvalId === node.dataset.approvalAi && item.sessionId === node.dataset.aiSession)
|
|
74
|
+
if (item) void generate(item)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
root.DshApprovalSummary = { html, mount, reset, generate }
|
|
78
|
+
})(window)
|
package/public/build.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* Trusted package/build identity and upgrade handling. Never clears credentials. */
|
|
2
|
+
;(function(root){
|
|
3
|
+
'use strict'
|
|
4
|
+
const HEX=/^[a-f0-9]{64}$/, loaded=root.document?.querySelector('meta[name="dsh-remote-build"]')?.content
|
|
5
|
+
const script=root.document?.currentScript?.src
|
|
6
|
+
let config,checking=false,banner,autoReloaded=false
|
|
7
|
+
const text=(zh,en)=>root.I18N?.lang==='en'?en:zh
|
|
8
|
+
async function check(){
|
|
9
|
+
if(checking||!config||!HEX.test(loaded||'')||!script)return
|
|
10
|
+
checking=true
|
|
11
|
+
try{
|
|
12
|
+
const url=new URL('build.json',script);url.searchParams.set('fresh',String(Date.now()))
|
|
13
|
+
const response=await root.fetch(url.href,{cache:'no-store',signal:AbortSignal.timeout(5000)})
|
|
14
|
+
if(!response.ok)return
|
|
15
|
+
const next=(await response.json()).buildId
|
|
16
|
+
if(!HEX.test(next||'')||next===loaded)return
|
|
17
|
+
if(!banner){
|
|
18
|
+
banner=root.document.createElement('aside');banner.className='cache-upgrade-notice';banner.setAttribute('role','status')
|
|
19
|
+
banner.style.cssText='position:fixed;z-index:39;top:8px;left:12px;right:12px;padding:12px;background:var(--dsr-panel,#fff);color:var(--dsr-text,#182331);border:1px solid var(--dsr-line,#778899);border-radius:12px;display:flex;gap:10px;align-items:center'
|
|
20
|
+
const copy=root.document.createElement('span'),button=root.document.createElement('button')
|
|
21
|
+
copy.textContent=text('新界面已就绪,重新载入即可更新;未发送内容会保留。','An updated interface is ready. Reload to update; unsent content is preserved.')
|
|
22
|
+
button.type='button';button.textContent=text('重新载入','Reload')
|
|
23
|
+
button.style.minHeight='44px'
|
|
24
|
+
button.addEventListener('click',()=>{if(config.safe())root.location.reload();else root.alert(text('请先处理当前审批、上传或未发送内容,再重新载入。','Finish pending approvals/uploads or save unsent content before reloading.'))})
|
|
25
|
+
banner.append(copy,button);root.document.body.append(banner)
|
|
26
|
+
}
|
|
27
|
+
// A running turn, draft, approval or upload must never be interrupted.
|
|
28
|
+
// One automatic reload per target build also prevents a bad cache loop.
|
|
29
|
+
const key='dshRemoteBuildReload:'+root.location.pathname
|
|
30
|
+
if(!autoReloaded&&config.safe()){
|
|
31
|
+
let saved
|
|
32
|
+
try{saved=root.sessionStorage.getItem(key)}catch{return}
|
|
33
|
+
if(saved===next)return
|
|
34
|
+
try{root.sessionStorage.setItem(key,next);if(root.sessionStorage.getItem(key)!==next)return}catch{return}
|
|
35
|
+
autoReloaded=true;root.location.reload()
|
|
36
|
+
}
|
|
37
|
+
}catch{}finally{checking=false}
|
|
38
|
+
}
|
|
39
|
+
async function migrate(){
|
|
40
|
+
try{const scopes=config?.scopes?.();if(scopes?.length)await root.DshHistory?.migrateLegacy?.(scopes)}catch{}
|
|
41
|
+
}
|
|
42
|
+
function mount(value){
|
|
43
|
+
if(config)return
|
|
44
|
+
config=value
|
|
45
|
+
const run=()=>{void check();void migrate()}
|
|
46
|
+
root.setTimeout(run,1500);root.setInterval(run,60_000)
|
|
47
|
+
root.document?.addEventListener('visibilitychange',()=>{if(!root.document.hidden)run()})
|
|
48
|
+
root.addEventListener?.('online',run)
|
|
49
|
+
}
|
|
50
|
+
root.DshCacheUpgrade={mount,check,migrate}
|
|
51
|
+
})(window)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* Clipboard actions belong to one displayed source block, never a whole reply. */
|
|
2
|
+
;(function(root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const scopes = new WeakMap(); let nextScope = 0
|
|
5
|
+
const resetTimers = new WeakMap()
|
|
6
|
+
const label = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
7
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
8
|
+
function scope(history) { if (!scopes.has(history)) scopes.set(history, String(++nextScope)); return scopes.get(history) }
|
|
9
|
+
function code(source, language = '', options = {}) {
|
|
10
|
+
const lang = /^[a-zA-Z0-9_+.-]{1,40}$/.test(String(language)) ? String(language) : ''
|
|
11
|
+
const markdown = /^(?:md|markdown)$/i.test(lang)
|
|
12
|
+
const name = markdown ? 'Markdown' : lang || label('代码', 'Code')
|
|
13
|
+
const action = markdown ? label('复制 Markdown', 'Copy Markdown') : options.label || label('复制代码', 'Copy code')
|
|
14
|
+
const scoped = options.scope == null ? '' : ` data-chat-copy-scope="${esc(options.scope)}"`
|
|
15
|
+
return `<div class="chat-code"><div class="chat-code-toolbar"><span class="chat-code-language">${esc(name)}</span><button type="button" class="chat-copy-button" data-chat-copy-code${scoped} aria-label="${esc(action)}" title="${esc(action)}"><svg class="chat-copy-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="8" y="8" width="12" height="12" rx="2"/><path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/></svg><svg class="chat-copy-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 4 4L19 6"/></svg><span class="chat-copy-status" aria-live="polite"></span></button></div><pre><code>${esc(source)}</code></pre></div>`
|
|
16
|
+
}
|
|
17
|
+
function bind(box, host) {
|
|
18
|
+
if (!box || box.dataset.chatCopyBound) return
|
|
19
|
+
box.dataset.chatCopyBound = '1'
|
|
20
|
+
box.addEventListener('click', async event => {
|
|
21
|
+
const button = event.target.closest?.('[data-chat-copy-code]')
|
|
22
|
+
if (!button || !box.contains(button) || button.disabled) return
|
|
23
|
+
const context = host.capture()
|
|
24
|
+
if (!context.valid()) return
|
|
25
|
+
if (context.history && button.dataset.chatCopyScope !== scope(context.history)) return
|
|
26
|
+
const source = button.closest('.chat-code')?.querySelector('pre code')?.textContent
|
|
27
|
+
if (source == null || source === '') return
|
|
28
|
+
event.preventDefault(); event.stopPropagation()
|
|
29
|
+
clearTimeout(resetTimers.get(button))
|
|
30
|
+
delete button.dataset.copyState
|
|
31
|
+
button.disabled = true
|
|
32
|
+
const original = button.getAttribute('aria-label')
|
|
33
|
+
const status = button.querySelector('.chat-copy-status')
|
|
34
|
+
if (status) status.textContent = ''
|
|
35
|
+
try {
|
|
36
|
+
const ok = await host.copy(source)
|
|
37
|
+
if (context.valid() && box.contains(button)) {
|
|
38
|
+
button.dataset.copyState = ok ? 'copied' : 'error'
|
|
39
|
+
const feedback = label(ok ? '已复制' : '复制失败,请重试', ok ? 'Copied' : 'Copy failed. Please retry.')
|
|
40
|
+
button.setAttribute('aria-label', feedback); button.title = feedback
|
|
41
|
+
if (status) status.textContent = ok ? feedback : ''
|
|
42
|
+
if (!ok) host.notice(feedback, 'err')
|
|
43
|
+
}
|
|
44
|
+
} catch { if (context.valid()) host.notice(label('复制失败,请重试', 'Copy failed. Please retry.'), 'err') }
|
|
45
|
+
finally {
|
|
46
|
+
button.disabled = false
|
|
47
|
+
resetTimers.set(button, setTimeout(() => {
|
|
48
|
+
delete button.dataset.copyState
|
|
49
|
+
resetTimers.delete(button)
|
|
50
|
+
if (status) status.textContent = ''
|
|
51
|
+
if (original) { button.setAttribute('aria-label', original); button.title = original }
|
|
52
|
+
}, 1600))
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
const api = { scope, code, bind }
|
|
57
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
58
|
+
else root.DshChatCopy = api
|
|
59
|
+
})(typeof window === 'undefined' ? globalThis : window)
|