dsh-remote-plugin 0.8.0-rc.2 → 0.8.0-rc.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/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +21 -6
- package/package.json +1 -1
- package/public/activity.js +126 -0
- package/public/announcements.json +8 -0
- package/public/app.js +195 -113
- package/public/desktop/desktop.css +10 -10
- package/public/desktop/desktop.html +25 -9
- package/public/desktop/desktop.js +133 -47
- package/public/extensions.js +3 -2
- package/public/history.js +32 -11
- package/public/image-preview.js +132 -0
- package/public/index.html +32 -10
- package/public/md.js +41 -1
- package/public/network.js +29 -5
- package/public/relay-settings.js +19 -10
- package/public/styles.css +15 -15
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/update.json +4 -4
- package/public/version.json +1 -1
- package/public/workflow.css +177 -1
- package/public/workflow.js +88 -8
package/public/history.js
CHANGED
|
@@ -24,17 +24,20 @@
|
|
|
24
24
|
}
|
|
25
25
|
class HistoryView {
|
|
26
26
|
constructor(box, options) {
|
|
27
|
-
this.box=box; this.options=options; this.entries=[]; this.start=0; this.end=0; this.nodes=new Map(); this.reading=false; this.suppress=false; this.frame=0; this.pendingOlder=false
|
|
27
|
+
this.box=box; this.options=options; this.entries=[]; this.start=0; this.end=0; this.nodes=new Map(); this.disclosures=new Map(); this.reading=false; this.suppress=false; this.frame=0; this.pendingOlder=false
|
|
28
28
|
this.more=document.createElement('button'); this.more.type='button'; this.more.className='history-page-control'; this.more.textContent=options.olderLabel()
|
|
29
29
|
this.more.addEventListener('click',()=>this.older())
|
|
30
30
|
this.empty=document.createElement('div'); this.empty.className='history-empty'
|
|
31
31
|
this.live=document.createElement('div'); this.live.className='history-live'
|
|
32
|
+
box.addEventListener('toggle',event=>{const detail=event.target;if(detail?.dataset?.activityKey)this.rememberDisclosure(detail)},true)
|
|
32
33
|
const intent=()=>{this.intentUntil=Date.now()+1200}
|
|
33
34
|
const hold=()=>{intent();this.reading=true;this.options.changed?.(this)}
|
|
34
35
|
box.addEventListener('wheel',event=>{intent();if(event.deltaY<0)hold()},{passive:true})
|
|
35
36
|
box.addEventListener('touchstart',event=>{this.touchY=event.touches?.[0]?.clientY;this.lastScrollTop=box.scrollTop},{passive:true})
|
|
36
37
|
box.addEventListener('touchmove',event=>{const y=event.touches?.[0]?.clientY;intent();if(y>this.touchY)hold();this.touchY=y},{passive:true})
|
|
37
|
-
|
|
38
|
+
// Pressing a card or selecting text pauses following, but only when actually
|
|
39
|
+
// scrolled away from the tail: tapping at the bottom must not fake "new content".
|
|
40
|
+
box.addEventListener('pointerdown',()=>{this.lastScrollTop=box.scrollTop;this.intentUntil=0;if(!this.atBottom)this.reading=true;this.options.changed?.(this)},{passive:true})
|
|
38
41
|
box.addEventListener('keydown',event=>{if(['ArrowUp','PageUp','Home'].includes(event.key))hold();else if(['ArrowDown','PageDown','End'].includes(event.key))intent()})
|
|
39
42
|
box.addEventListener('scroll',()=>{
|
|
40
43
|
if(this.suppress || this.frame)return
|
|
@@ -48,8 +51,14 @@
|
|
|
48
51
|
}
|
|
49
52
|
get unread() {return Math.max(0,this.entries.length-this.end)}
|
|
50
53
|
get hasPending() {return this.unread>0||(this.pendingLive||'')!==(this.liveHtml||'')}
|
|
54
|
+
/** Real viewport position, not an intent flag: a stale `reading` must never keep the jump button up at the bottom. */
|
|
55
|
+
get atBottom() {const box=this.box;return box.scrollHeight-box.scrollTop-box.clientHeight<=24}
|
|
51
56
|
set(entries, {reset=false, follow=false, live='', hasMore=false, loading=false, emptyLabel=''}={}) {
|
|
52
57
|
if(this.paused){this.pending={entries:entries.slice(),options:{reset,follow,live,hasMore,loading,emptyLabel}};return}
|
|
58
|
+
// A stale flag is cleaned up only when no gesture is in progress: while the user is
|
|
59
|
+
// actively scrolling up from the bottom a stream update must not clear `reading`,
|
|
60
|
+
// otherwise every chunk snaps the view back to the tail.
|
|
61
|
+
if(this.reading&&Date.now()>(this.intentUntil||0)&&this.atBottom&&this.end>=this.entries.length)this.reading=false
|
|
53
62
|
this.pendingLive=live
|
|
54
63
|
// Reading is explicit user intent. A stream update never changes it by proximity.
|
|
55
64
|
if(this.reading&&!reset)live=this.liveHtml||''
|
|
@@ -70,15 +79,26 @@
|
|
|
70
79
|
this.liveHtml=this.reading&&!reset ? this.liveHtml||'' : this.end===entries.length?live:''
|
|
71
80
|
this.render(anchor,reset || (!this.reading && this.end===entries.length))
|
|
72
81
|
}
|
|
82
|
+
rememberDisclosure(detail) {
|
|
83
|
+
const key=detail.dataset.activityKey;if(!key)return
|
|
84
|
+
this.disclosures.delete(key);this.disclosures.set(key,!!detail.open)
|
|
85
|
+
if(this.disclosures.size>512)this.disclosures.delete(this.disclosures.keys().next().value)
|
|
86
|
+
}
|
|
87
|
+
captureDisclosures(node) {for(const detail of node.querySelectorAll('details[data-activity-key]'))this.rememberDisclosure(detail)}
|
|
88
|
+
restoreDisclosures(node) {for(const detail of node.querySelectorAll('details[data-activity-key]'))if(this.disclosures.has(detail.dataset.activityKey))detail.open=this.disclosures.get(detail.dataset.activityKey)}
|
|
73
89
|
render(anchor, bottom=false) {
|
|
74
90
|
const box=this.box, slice=this.entries.slice(this.start,Math.min(this.end,this.start+WINDOW_SIZE)), desired=[]
|
|
91
|
+
this.captureDisclosures(box)
|
|
75
92
|
this.end=this.start+slice.length
|
|
76
93
|
const rangeKey=this.start+':'+this.end
|
|
77
94
|
let changed=rangeKey!==this.lastRange || this.live.innerHTML!==this.liveHtml
|
|
78
95
|
this.lastRange=rangeKey
|
|
79
96
|
for(const entry of slice) {
|
|
97
|
+
// Hidden events render an empty string; keeping their node would leave dead gaps.
|
|
98
|
+
const html=this.options.html(entry)
|
|
99
|
+
if(!html){if(this.nodes.delete(entry.seq))changed=true;continue}
|
|
80
100
|
const key=signature(entry);let cached=this.nodes.get(entry.seq)
|
|
81
|
-
if(!cached || cached.key!==key){changed=true;const node=document.createElement('div');node.className='history-entry';node.dataset.historySeq=String(entry.seq);node.innerHTML=this.
|
|
101
|
+
if(!cached || cached.key!==key){changed=true;const node=document.createElement('div');node.className='history-entry';node.dataset.historySeq=String(entry.seq);node.innerHTML=html;this.restoreDisclosures(node);cached={key,node};this.nodes.set(entry.seq,cached)}
|
|
82
102
|
desired.push(cached.node)
|
|
83
103
|
}
|
|
84
104
|
this.more.hidden=this.start===0&&!this.hasMore
|
|
@@ -89,7 +109,7 @@
|
|
|
89
109
|
let cursor=this.more.nextSibling
|
|
90
110
|
for(const node of desired){if(node===cursor)cursor=cursor.nextSibling;else box.insertBefore(node,cursor)}
|
|
91
111
|
if(!slice.length && !this.liveHtml){if(this.empty.parentNode!==box)box.append(this.empty)}else this.empty.remove()
|
|
92
|
-
if(this.live.innerHTML!==this.liveHtml)this.live.innerHTML=this.liveHtml
|
|
112
|
+
if(this.live.innerHTML!==this.liveHtml){this.live.innerHTML=this.liveHtml;this.restoreDisclosures(this.live)}
|
|
93
113
|
if(this.live.parentNode!==box)box.append(this.live)
|
|
94
114
|
if(bottom)box.scrollTop=box.scrollHeight
|
|
95
115
|
else if(anchor){const current=this.nodes.get(anchor.seq)?.node;if(current?.parentNode===box)box.scrollTop+=current.getBoundingClientRect().top-anchor.top}
|
|
@@ -100,14 +120,15 @@
|
|
|
100
120
|
this.options.changed?.(this)
|
|
101
121
|
}
|
|
102
122
|
onScroll() {
|
|
103
|
-
const box=this.box
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
123
|
+
const box=this.box, atBottom=this.atBottom
|
|
124
|
+
// Position wins over the intent flag: reaching the bottom always resumes following,
|
|
125
|
+
// no matter whether the scroll came from a wheel, a drag, a rail jump or momentum.
|
|
126
|
+
if(atBottom)this.reading=false
|
|
127
|
+
else if(Date.now()<this.intentUntil&&box.scrollTop<(this.lastScrollTop??box.scrollTop))this.reading=true
|
|
108
128
|
this.lastScrollTop=box.scrollTop
|
|
109
129
|
if(box.scrollTop<80 && Date.now()<this.intentUntil)this.older()
|
|
110
|
-
else if(box.scrollHeight-box.scrollTop-box.clientHeight<120 && this.end<this.entries.length && Date.now()<this.intentUntil){const anchor=this.anchor();this.end=Math.min(this.entries.length,this.end+WINDOW_STEP);this.start=Math.max(0,this.end-WINDOW_SIZE);this.liveHtml=this.end===this.entries.length?this.pendingLive||'':'';this.render(anchor)}
|
|
130
|
+
else if(box.scrollHeight-box.scrollTop-box.clientHeight<120 && this.end<this.entries.length && Date.now()<this.intentUntil){const anchor=this.anchor();this.end=Math.min(this.entries.length,this.end+WINDOW_STEP);this.start=Math.max(0,this.end-WINDOW_SIZE);this.liveHtml=this.end===this.entries.length?this.pendingLive||'':'';this.render(anchor,atBottom)}
|
|
131
|
+
else if(atBottom&&this.end>=this.entries.length&&this.liveHtml!==(this.pendingLive||'')){this.liveHtml=this.pendingLive||'';this.render(null,true)}
|
|
111
132
|
this.options.scrolled?.(this)
|
|
112
133
|
this.domChanged=false
|
|
113
134
|
this.options.changed?.(this)
|
|
@@ -127,7 +148,7 @@
|
|
|
127
148
|
this.paused=false;this.box.scrollTop=this.savedScroll||0
|
|
128
149
|
const pending=this.pending;this.pending=null;if(pending)this.set(pending.entries,pending.options)
|
|
129
150
|
}
|
|
130
|
-
reset() {cancelAnimationFrame(this.frame);cancelAnimationFrame(this.releaseFrame);this.frame=0;this.entries=[];this.start=this.end=this.previousLength=0;this.lastRange='';this.nodes.clear();this.reading=false;this.pendingOlder=false;this.suppress=false;this.intentUntil=0;this.pendingLive='';this.pending=null;this.paused=false;this.lastScrollTop=0;this.box.replaceChildren()}
|
|
151
|
+
reset() {cancelAnimationFrame(this.frame);cancelAnimationFrame(this.releaseFrame);this.frame=0;this.entries=[];this.start=this.end=this.previousLength=0;this.lastRange='';this.nodes.clear();this.disclosures.clear();this.reading=false;this.pendingOlder=false;this.suppress=false;this.intentUntil=0;this.pendingLive='';this.pending=null;this.paused=false;this.lastScrollTop=0;this.box.replaceChildren()}
|
|
131
152
|
}
|
|
132
153
|
let cacheEpoch=0
|
|
133
154
|
let database
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* Shared chat image lightbox. No dependencies, mobile and desktop. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
const english=()=>root.I18N?.lang==='en'
|
|
5
|
+
let lightbox=null,stage=null,image=null,closeButton=null,hint=null,opener=null
|
|
6
|
+
let resolver=null,observer=null,mutation=null
|
|
7
|
+
function labels(){
|
|
8
|
+
if(!lightbox)return
|
|
9
|
+
lightbox.setAttribute('aria-label',english()?'Image preview':'图片预览')
|
|
10
|
+
if(closeButton)closeButton.setAttribute('aria-label',english()?'Close':'关闭')
|
|
11
|
+
if(hint)hint.textContent=isZoomed()?(english()?'Double-tap to fit · tap outside to close':'双击还原 · 点空白处关闭'):(english()?'Double-tap to zoom · tap outside to close':'双击放大 · 点空白处关闭')
|
|
12
|
+
}
|
|
13
|
+
function isZoomed(){return !!lightbox?.classList.contains('is-zoomed')}
|
|
14
|
+
function setZoom(on){
|
|
15
|
+
if(!lightbox)return
|
|
16
|
+
lightbox.classList.toggle('is-zoomed',!!on)
|
|
17
|
+
if(image){
|
|
18
|
+
if(on&&image.naturalWidth){image.style.width=image.naturalWidth*2+'px';image.style.height=image.naturalHeight*2+'px'}
|
|
19
|
+
else{image.style.width='';image.style.height=''}
|
|
20
|
+
}
|
|
21
|
+
if(on&&stage)root.requestAnimationFrame?.(()=>{stage.scrollLeft=(stage.scrollWidth-stage.clientWidth)/2;stage.scrollTop=(stage.scrollHeight-stage.clientHeight)/2})
|
|
22
|
+
labels()
|
|
23
|
+
}
|
|
24
|
+
function toggleZoom(){setZoom(!isZoomed())}
|
|
25
|
+
function isOpen(){return !!lightbox&&!lightbox.classList.contains('hidden')}
|
|
26
|
+
function open(src,alt=''){
|
|
27
|
+
if(!src||!elements())return
|
|
28
|
+
opener=root.document.activeElement||null
|
|
29
|
+
image.src=src
|
|
30
|
+
image.alt=alt||(english()?'Image':'图片')
|
|
31
|
+
lightbox.classList.remove('hidden')
|
|
32
|
+
root.document.body?.classList.add('image-preview-open')
|
|
33
|
+
setZoom(false)
|
|
34
|
+
root.requestAnimationFrame?.(()=>lightbox.focus?.({preventScroll:true}))
|
|
35
|
+
}
|
|
36
|
+
function close(){
|
|
37
|
+
if(!lightbox||lightbox.classList.contains('hidden'))return
|
|
38
|
+
setZoom(false)
|
|
39
|
+
lightbox.classList.add('hidden')
|
|
40
|
+
root.document.body?.classList.remove('image-preview-open')
|
|
41
|
+
image.removeAttribute?.('src')
|
|
42
|
+
const target=opener;opener=null
|
|
43
|
+
target?.focus?.({preventScroll:true})
|
|
44
|
+
}
|
|
45
|
+
// Markdown images may point at a local file. The host shell supplies an authenticated
|
|
46
|
+
// request for that path; load lazily and swap the placeholder for a real previewable image.
|
|
47
|
+
function configure(options={}){
|
|
48
|
+
if(typeof options.resolvePath==='function')resolver=options.resolvePath
|
|
49
|
+
if(!mutation&&typeof root.MutationObserver==='function'&&root.document?.body){
|
|
50
|
+
// History renders (paging, streaming, cache restore) replace nodes without a full render call.
|
|
51
|
+
mutation=new root.MutationObserver(records=>{
|
|
52
|
+
for(const record of records)for(const node of record.addedNodes)if(node?.nodeType===1)hydrate(node)
|
|
53
|
+
})
|
|
54
|
+
mutation.observe(root.document.body,{childList:true,subtree:true})
|
|
55
|
+
}
|
|
56
|
+
hydrate(root.document)
|
|
57
|
+
}
|
|
58
|
+
function watcher(){
|
|
59
|
+
if(observer)return observer
|
|
60
|
+
if(typeof root.IntersectionObserver!=='function')return null
|
|
61
|
+
observer=new root.IntersectionObserver(entries=>{
|
|
62
|
+
for(const entry of entries){
|
|
63
|
+
if(!entry.isIntersecting)continue
|
|
64
|
+
observer.unobserve(entry.target)
|
|
65
|
+
void loadPathImage(entry.target)
|
|
66
|
+
}
|
|
67
|
+
},{rootMargin:'320px'})
|
|
68
|
+
return observer
|
|
69
|
+
}
|
|
70
|
+
function hydrate(scope){
|
|
71
|
+
if(!resolver||!scope?.querySelectorAll)return
|
|
72
|
+
const candidates=[...(scope.matches?.('[data-chat-image][data-chat-image-path]')?[scope]:[]),...scope.querySelectorAll('[data-chat-image][data-chat-image-path]')]
|
|
73
|
+
for(const button of candidates){
|
|
74
|
+
if(button.dataset.chatImageLoading||button.dataset.chatImageLoaded)continue
|
|
75
|
+
button.dataset.chatImageLoading='1'
|
|
76
|
+
const watch=watcher()
|
|
77
|
+
if(watch)watch.observe(button)
|
|
78
|
+
else void loadPathImage(button)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function loadPathImage(button){
|
|
82
|
+
const path=button.dataset.chatImagePath
|
|
83
|
+
if(!path||!resolver)return
|
|
84
|
+
try{
|
|
85
|
+
const source=await resolver(path)
|
|
86
|
+
const request=typeof source==='string'?{url:source}:source||{}
|
|
87
|
+
const response=await (root.fetch||fetch)(request.url,{headers:request.headers||{}})
|
|
88
|
+
if(!response.ok)throw new Error('HTTP '+response.status)
|
|
89
|
+
const blob=await response.blob()
|
|
90
|
+
if(!blob||!blob.size)throw new Error('empty image')
|
|
91
|
+
const url=root.URL?.createObjectURL?root.URL.createObjectURL(blob):''
|
|
92
|
+
if(!url)throw new Error('no blob url')
|
|
93
|
+
const node=root.document.createElement('img')
|
|
94
|
+
node.src=url;node.alt=button.dataset.chatImageAlt||'';node.draggable=false;node.loading='lazy'
|
|
95
|
+
node.addEventListener('error',()=>pathImageFailed(button))
|
|
96
|
+
node.addEventListener('load',()=>{button.classList.remove('is-loading');button.classList.add('is-loaded')})
|
|
97
|
+
button.replaceChildren(node)
|
|
98
|
+
button.dataset.chatImageLoaded='1'
|
|
99
|
+
delete button.dataset.chatImagePath
|
|
100
|
+
}catch(error){pathImageFailed(button)}
|
|
101
|
+
}
|
|
102
|
+
function pathImageFailed(button){
|
|
103
|
+
button.classList.remove('is-loading')
|
|
104
|
+
button.classList.add('is-error')
|
|
105
|
+
const status=button.querySelector?.('.chat-image-status')
|
|
106
|
+
if(status)status.textContent=english()?'Image unavailable':'图片无法加载'
|
|
107
|
+
}
|
|
108
|
+
function elements(){
|
|
109
|
+
if(lightbox)return lightbox
|
|
110
|
+
lightbox=root.document?.getElementById('image-lightbox')
|
|
111
|
+
if(!lightbox)return null
|
|
112
|
+
stage=lightbox.querySelector('[data-image-lightbox-stage]')
|
|
113
|
+
image=lightbox.querySelector('[data-image-lightbox-img]')
|
|
114
|
+
closeButton=lightbox.querySelector('[data-image-lightbox-close]')
|
|
115
|
+
hint=lightbox.querySelector('[data-image-lightbox-hint]')
|
|
116
|
+
closeButton?.addEventListener('click',close)
|
|
117
|
+
lightbox.addEventListener('click',event=>{const target=event.target;if(target===lightbox||target===stage)close()})
|
|
118
|
+
stage?.addEventListener('click',event=>{if(event.target===stage)close()})
|
|
119
|
+
image?.addEventListener('dblclick',event=>{event.preventDefault?.();toggleZoom()})
|
|
120
|
+
root.document.addEventListener('keydown',event=>{if(event.key==='Escape'&&isOpen()){event.preventDefault?.();close()}})
|
|
121
|
+
// Chat images live inside rendered history: delegate instead of rebinding per message.
|
|
122
|
+
root.document.addEventListener('click',event=>{
|
|
123
|
+
const trigger=event.target?.closest?.('[data-chat-image]')
|
|
124
|
+
if(!trigger)return
|
|
125
|
+
const img=trigger.querySelector?.('img')
|
|
126
|
+
if(img?.src)open(img.src,img.alt||'')
|
|
127
|
+
})
|
|
128
|
+
return lightbox
|
|
129
|
+
}
|
|
130
|
+
root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate}
|
|
131
|
+
root.document?.addEventListener('DOMContentLoaded',()=>{elements();hydrate(root.document)})
|
|
132
|
+
})(typeof window==='undefined'?globalThis:window)
|
package/public/index.html
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
<link rel="stylesheet" href="insights.css">
|
|
20
20
|
<link rel="stylesheet" href="workflow.css">
|
|
21
21
|
<link rel="stylesheet" href="relay-settings.css">
|
|
22
|
+
<link rel="stylesheet" href="subagents.css">
|
|
22
23
|
</head>
|
|
23
24
|
<body>
|
|
24
25
|
<header class="topbar">
|
|
@@ -115,6 +116,7 @@
|
|
|
115
116
|
<button id="session-title" class="session-title" type="button" aria-haspopup="dialog" aria-controls="session-info" data-i18n="session.loading">加载中…</button>
|
|
116
117
|
|
|
117
118
|
</div>
|
|
119
|
+
<button id="btn-subagents" class="subagents-entry" type="button" aria-haspopup="dialog" aria-controls="subagent-page" data-i18n="subagent.title">子代理</button>
|
|
118
120
|
<button id="btn-session-more" class="icon-btn" type="button" aria-haspopup="dialog" aria-controls="session-actions" data-i18n-aria="session.more">⋯</button>
|
|
119
121
|
<button id="btn-fs-send" class="session-send-btn hidden" type="button">发送</button>
|
|
120
122
|
|
|
@@ -443,8 +445,7 @@
|
|
|
443
445
|
<label class="switch"><input type="checkbox" id="opt-notify"><span class="slider"></span></label>
|
|
444
446
|
</div>
|
|
445
447
|
<div class="setting-row">
|
|
446
|
-
<div><div class="setting-name" data-i18n="settings.peakRemindTitle"
|
|
447
|
-
<label class="switch"><input type="checkbox" id="opt-peak-remind"><span class="slider"></span></label>
|
|
448
|
+
<div><div class="setting-name" data-i18n="settings.peakRemindTitle">峰谷计费提醒 · dsh-cost-meter</div><div class="setting-desc" data-i18n="settings.peakRemindDesc">由 dsh-cost-meter 统一管理,请在 DSH「设置 → 费用 → 峰谷计价」配置。提醒由 DSH 页面触发,Remote 不再独立后台计时。</div></div>
|
|
448
449
|
</div>
|
|
449
450
|
<div class="setting-row">
|
|
450
451
|
<div><div class="setting-name" data-i18n="settings.testNotifyTitle">测试通知</div><div class="setting-desc" data-i18n="settings.testNotifyDesc">立即排一条 3 秒后的本地通知,用于排查系统通知限制</div></div>
|
|
@@ -514,6 +515,8 @@
|
|
|
514
515
|
<div class="setting-row">
|
|
515
516
|
<div><div class="setting-name" data-i18n="settings.updateTitle">检查更新</div><div class="setting-desc" id="update-desc" data-i18n="settings.updateLoading">加载中…</div>
|
|
516
517
|
<button id="btn-download-update" class="mini-btn hidden" style="margin-top:6px" data-i18n="settings.downloadUpdate">下载并安装更新</button>
|
|
518
|
+
<button id="btn-force-download-update" class="mini-btn" style="margin-top:6px" data-i18n="settings.redownloadApk">重新下载安装包</button>
|
|
519
|
+
<div class="setting-desc expanded" data-i18n="settings.redownloadApkDesc">同版本补丁也可重新下载,以当前主机提供的安装包为准。</div>
|
|
517
520
|
<div id="update-download-progress" class="update-download-progress hidden">
|
|
518
521
|
<div id="update-download-status" role="status" aria-live="polite"></div>
|
|
519
522
|
<progress id="update-download-bar" max="100" aria-label="APK download progress"></progress>
|
|
@@ -734,6 +737,14 @@
|
|
|
734
737
|
</div>
|
|
735
738
|
</div>
|
|
736
739
|
|
|
740
|
+
<div id="image-lightbox" class="image-lightbox hidden" role="dialog" aria-modal="true" aria-label="图片预览" tabindex="-1">
|
|
741
|
+
<button id="image-lightbox-close" class="image-lightbox-close" type="button" data-image-lightbox-close aria-label="关闭">×</button>
|
|
742
|
+
<div class="image-lightbox-stage" data-image-lightbox-stage>
|
|
743
|
+
<img data-image-lightbox-img alt="" draggable="false">
|
|
744
|
+
</div>
|
|
745
|
+
<div class="image-lightbox-hint" data-image-lightbox-hint>双击放大 · 点空白处关闭</div>
|
|
746
|
+
</div>
|
|
747
|
+
|
|
737
748
|
<div id="modal-archive" class="modal hidden" role="dialog" aria-modal="true">
|
|
738
749
|
<div class="modal-card archive-modal-card">
|
|
739
750
|
<div class="modal-title" data-i18n="session.archiveTitle">确认归档会话</div>
|
|
@@ -965,16 +976,16 @@
|
|
|
965
976
|
'speed.switched': '已切换到最快服务器:{url}({ms}ms)', 'speed.alreadyBest': '当前已是最快:{url}({ms}ms)',
|
|
966
977
|
'speed.allDown': '全部服务器不可达',
|
|
967
978
|
'servers.empty': '未添加备用服务器 · 默认使用当前页面地址', 'servers.untested': '未测速',
|
|
968
|
-
'servers.current': ' · 当前', 'servers.unreachable': '不可达', 'servers.delete': '删除服务器', 'servers.tokenSet': '令牌已配置', 'servers.tokenMissing': '未配置令牌',
|
|
979
|
+
'servers.current': ' · 当前', 'servers.currentOnly': '当前', 'servers.unreachable': '不可达', 'servers.delete': '删除服务器', 'servers.tokenSet': '令牌已配置', 'servers.tokenMissing': '未配置令牌',
|
|
969
980
|
'servers.currentDesc': '当前: {url}', 'servers.notSet': '未设置服务器', 'servers.defaultDesc': '默认 = 当前页面地址',
|
|
970
981
|
'servers.needAddress': '请输入服务器地址', 'servers.badProtocol': '地址需以 http:// 或 https:// 开头',
|
|
971
982
|
'servers.duplicate': '相同地址和令牌已在列表中', 'servers.added': '已添加服务器', 'servers.removedActive': '已删除当前服务器,重新测速…',
|
|
972
|
-
'servers.currentDescGroup': '当前:{group} · {url}
|
|
983
|
+
'servers.currentDescGroup': '当前:{group} · {url}',
|
|
973
984
|
'servers.edit': '编辑', 'servers.manualSelected': '已切换至:{url}',
|
|
974
985
|
'servers.promptNote': '服务器备注(可留空):', 'servers.promptEditNote': '编辑备注({url}):', 'servers.promptEditToken': '编辑服务器令牌(留空保持不变):',
|
|
975
986
|
'servers.promptEditUrl': '编辑服务器地址:', 'servers.promptEditGroup': '所属组:', 'servers.edited': '服务器已更新',
|
|
976
987
|
'speed.switchedOrigin': '已切换到当前页面(同源)', 'speed.manualUsing': '手动模式:{url}({ms})',
|
|
977
|
-
'groups.current': '当前组', 'groups.add': '+ 组', 'groups.noServer': '组内暂无服务器',
|
|
988
|
+
'groups.current': '当前组', 'groups.currentLabel': '当前组:{group}', 'groups.add': '+ 组', 'groups.noServer': '组内暂无服务器',
|
|
978
989
|
'groups.speedTest': '测速', 'groups.autoSelect': '自动选择最快', 'groups.delete': '删除组',
|
|
979
990
|
'groups.autoOn': '{group} 已切换为自动选择', 'groups.autoOff': '{group} 已切换为手动选择',
|
|
980
991
|
'groups.switched': '已切换到组:{group}', 'groups.switchHint': '点击切换当前组,双击重命名', 'groups.promptAdd': '新组名:', 'groups.duplicate': '组名已存在',
|
|
@@ -997,6 +1008,7 @@
|
|
|
997
1008
|
'event.taskStart': '▶ 任务开始', 'event.taskEnd': '■ 任务结束',
|
|
998
1009
|
'event.systemReminder': '系统提示',
|
|
999
1010
|
'block.image': '图片', 'block.thinking': '🧠 思考过程', 'block.thinkingLive': '🧠 思考中…', 'block.toolCall': '工具调用', 'block.toolResult': '工具结果', 'block.unknown': '块 · {type}',
|
|
1011
|
+
'activity.group': '工具与思考 · {n} 项', 'activity.groupRunning': '运行中',
|
|
1000
1012
|
'truncated': '…(截断)',
|
|
1001
1013
|
'insights.title': '上下文与费用',
|
|
1002
1014
|
'insights.contextTitle': '上下文分析',
|
|
@@ -1010,6 +1022,7 @@
|
|
|
1010
1022
|
'goal.actionFailed': '目标操作失败', 'goal.actionSubmitted': '目标操作已提交',
|
|
1011
1023
|
'goal.cannotEmpty': '目标不能为空', 'goal.updateFailed': '更新失败', 'goal.updated': '目标已更新',
|
|
1012
1024
|
'todos.title': '任务清单',
|
|
1025
|
+
'session.migrationRequired': '请先在 DSH 中打开原会话完成迁移,然后刷新。',
|
|
1013
1026
|
'subagent.title': '子代理', 'subagent.count': '子代理 · {n} 个', 'subagent.expand': '展开子代理', 'subagent.collapse': '收起子代理', 'subagent.diagnostic': '诊断项', 'subagent.running': '· 运行中', 'subagent.interrupt': '中断',
|
|
1014
1027
|
'subagent.confirmInterrupt': '中断这个子代理当前回合?', 'subagent.interruptFailed': '中断失败', 'subagent.interruptSubmitted': '中断请求已提交',
|
|
1015
1028
|
'queue.title': '排队消息', 'queue.steer': '插话', 'queue.steerUnavailable': '仅运行中可插话', 'queue.steerSubmitted': '插话请求已提交', 'queue.steerFailed': '插话失败:{msg}', 'queue.image': '图片消息',
|
|
@@ -1057,6 +1070,8 @@
|
|
|
1057
1070
|
'update.checkFailedDesc': '检查失败:{msg}', 'update.checkFailed': '检查更新失败:{msg}',
|
|
1058
1071
|
'update.phase.downloading': '正在下载…', 'update.phase.verifying': '正在校验安装包…', 'update.phase.complete': '下载完成', 'update.phase.legacy': '系统正在下载安装包;安装新版后可显示完整进度', 'update.busy': '已有更新下载正在进行',
|
|
1059
1072
|
'update.downloadStarted': '开始下载,完成后会弹出安装页', 'update.downloadFailed': '无法启动下载:{msg}',
|
|
1073
|
+
'update.phase.checking': '正在获取主机安装包信息…', 'settings.redownloadApk': '重新下载安装包', 'settings.redownloadApkDesc': '同版本补丁也可重新下载,以当前主机提供的安装包为准。',
|
|
1074
|
+
'update.patchMismatch': '安装包与校验信息不一致,请同步主机安装包后重试。',
|
|
1060
1075
|
'update.corrupted': '下载文件损坏,请重试', 'update.serverFileMissing': '服务器上还没有对应版本的文件,请稍后再试',
|
|
1061
1076
|
'update.hashMissing': '更新包缺少 SHA-256 校验值,已取消下载',
|
|
1062
1077
|
'update.installUnsupported': '当前版本不支持 App 内安装,已转浏览器下载',
|
|
@@ -1098,7 +1113,7 @@
|
|
|
1098
1113
|
'settings.notifyTitle': '通知', 'settings.notifyDesc': '收到审批/提问时推送', 'settings.announcementHistoryTitle': '历史公告', 'settings.announcementHistoryDesc': '查看以前收到的公告', 'settings.announcementHistory': '查看记录',
|
|
1099
1114
|
'settings.testNotifyTitle': '测试通知', 'settings.testNotifyDesc': '立即排一条 3 秒后的本地通知,用于排查系统通知限制', 'settings.testNotify': '发送测试通知',
|
|
1100
1115
|
'settings.testNotifySent': '测试通知已排定,3 秒后到达', 'settings.testNotifyFailed': '发送测试通知失败:{msg}', 'settings.testNotifyUnavailable': '测试通知仅在 App 内可用',
|
|
1101
|
-
'settings.peakRemindTitle': '峰谷计费提醒', 'settings.peakRemindDesc': '
|
|
1116
|
+
'settings.peakRemindTitle': '峰谷计费提醒 · dsh-cost-meter', 'settings.peakRemindDesc': '由 dsh-cost-meter 统一管理,请在 DSH「设置 → 费用 → 峰谷计价」配置。提醒由 DSH 页面触发,Remote 不再独立后台计时。',
|
|
1102
1117
|
'peakRemind.enterPeak': '已进入高峰计费时段', 'peakRemind.enterOff': '已进入空闲计费时段',
|
|
1103
1118
|
'peakRemind.peak0912': '高峰 9:00-12:00', 'peakRemind.off1214': '空闲 12:00-14:00',
|
|
1104
1119
|
'peakRemind.peak1418': '高峰 14:00-18:00', 'peakRemind.off1809': '空闲 18:00-次日 9:00',
|
|
@@ -1206,16 +1221,16 @@
|
|
|
1206
1221
|
'speed.switched': 'Switched to fastest server: {url} ({ms}ms)', 'speed.alreadyBest': 'Already on fastest: {url} ({ms}ms)',
|
|
1207
1222
|
'speed.allDown': 'All servers unreachable',
|
|
1208
1223
|
'servers.empty': 'No backup servers · using the current page URL', 'servers.untested': 'Untested',
|
|
1209
|
-
'servers.current': ' · current', 'servers.unreachable': 'Unreachable', 'servers.delete': 'Remove server', 'servers.tokenSet': 'Token set', 'servers.tokenMissing': 'No token',
|
|
1224
|
+
'servers.current': ' · current', 'servers.currentOnly': 'Current', 'servers.unreachable': 'Unreachable', 'servers.delete': 'Remove server', 'servers.tokenSet': 'Token set', 'servers.tokenMissing': 'No token',
|
|
1210
1225
|
'servers.currentDesc': 'Current: {url}', 'servers.notSet': 'No server set', 'servers.defaultDesc': 'Default = current page URL',
|
|
1211
1226
|
'servers.needAddress': 'Enter a server address', 'servers.badProtocol': 'Address must start with http:// or https://',
|
|
1212
1227
|
'servers.duplicate': 'The same address and token is already in the list', 'servers.added': 'Server added', 'servers.removedActive': 'Removed active server, re-testing…',
|
|
1213
|
-
'servers.currentDescGroup': 'Current: {group} · {url}
|
|
1228
|
+
'servers.currentDescGroup': 'Current: {group} · {url}',
|
|
1214
1229
|
'servers.edit': 'Edit', 'servers.manualSelected': 'Switched to: {url}',
|
|
1215
1230
|
'servers.promptNote': 'Server note (optional):', 'servers.promptEditNote': 'Edit note ({url}):', 'servers.promptEditToken': 'Edit server token (blank keeps the current token):',
|
|
1216
1231
|
'servers.promptEditUrl': 'Edit server URL:', 'servers.promptEditGroup': 'Group:', 'servers.edited': 'Server updated',
|
|
1217
1232
|
'speed.switchedOrigin': 'Switched to current page (same origin)', 'speed.manualUsing': 'Manual mode: {url} ({ms})',
|
|
1218
|
-
'groups.current': 'Current group', 'groups.add': '+ Group', 'groups.noServer': 'No servers in this group',
|
|
1233
|
+
'groups.current': 'Current group', 'groups.currentLabel': 'Current group: {group}', 'groups.add': '+ Group', 'groups.noServer': 'No servers in this group',
|
|
1219
1234
|
'groups.speedTest': 'Speed test', 'groups.autoSelect': 'Auto-select fastest', 'groups.delete': 'Delete group',
|
|
1220
1235
|
'groups.autoOn': '{group} is now auto-select', 'groups.autoOff': '{group} is now manual',
|
|
1221
1236
|
'groups.switched': 'Switched to group: {group}', 'groups.switchHint': 'Click to switch group, double-click to rename', 'groups.promptAdd': 'New group name:', 'groups.duplicate': 'Group already exists',
|
|
@@ -1238,6 +1253,7 @@
|
|
|
1238
1253
|
'event.taskStart': '▶ Task started', 'event.taskEnd': '■ Task finished',
|
|
1239
1254
|
'event.systemReminder': 'System reminder',
|
|
1240
1255
|
'block.image': 'Image', 'block.thinking': '🧠 Thinking', 'block.thinkingLive': '🧠 Thinking…', 'block.toolCall': 'Tool call', 'block.toolResult': 'Tool result', 'block.unknown': 'Block · {type}',
|
|
1256
|
+
'activity.group': 'Tools and thinking · {n}', 'activity.groupRunning': 'Running',
|
|
1241
1257
|
'truncated': '…(truncated)',
|
|
1242
1258
|
'insights.title': 'Context & costs',
|
|
1243
1259
|
'insights.contextTitle': 'Context analysis',
|
|
@@ -1251,6 +1267,7 @@
|
|
|
1251
1267
|
'goal.actionFailed': 'Goal action failed', 'goal.actionSubmitted': 'Goal action submitted',
|
|
1252
1268
|
'goal.cannotEmpty': 'Goal cannot be empty', 'goal.updateFailed': 'Update failed', 'goal.updated': 'Goal updated',
|
|
1253
1269
|
'todos.title': 'Todos',
|
|
1270
|
+
'session.migrationRequired': 'Open the source session in DSH to complete migration, then refresh.',
|
|
1254
1271
|
'subagent.title': 'Subagents', 'subagent.count': 'Subagents · {n}', 'subagent.expand': 'Expand subagents', 'subagent.collapse': 'Collapse subagents', 'subagent.diagnostic': 'Diagnostic', 'subagent.running': '· running', 'subagent.interrupt': 'Interrupt',
|
|
1255
1272
|
'subagent.confirmInterrupt': 'Interrupt this subagent\'s current turn?', 'subagent.interruptFailed': 'Interrupt failed', 'subagent.interruptSubmitted': 'Interrupt requested',
|
|
1256
1273
|
'queue.title': 'Queued messages', 'queue.steer': 'Interject', 'queue.steerUnavailable': 'Only available while running', 'queue.steerSubmitted': 'Interjection requested', 'queue.steerFailed': 'Interjection failed: {msg}', 'queue.image': 'Image message',
|
|
@@ -1298,6 +1315,8 @@
|
|
|
1298
1315
|
'update.checkFailedDesc': 'Check failed: {msg}', 'update.checkFailed': 'Update check failed: {msg}',
|
|
1299
1316
|
'update.phase.downloading': 'Downloading…', 'update.phase.verifying': 'Verifying APK…', 'update.phase.complete': 'Download complete', 'update.phase.legacy': 'System download started; install this update for full progress', 'update.busy': 'An update is already downloading',
|
|
1300
1317
|
'update.downloadStarted': 'Downloading, the install page will open when ready', 'update.downloadFailed': 'Could not start download: {msg}',
|
|
1318
|
+
'update.phase.checking': 'Fetching the host package information…', 'settings.redownloadApk': 'Download package again', 'settings.redownloadApkDesc': 'Download same-version patches too. The package comes from the current host.',
|
|
1319
|
+
'update.patchMismatch': 'Package checksum mismatch. Refresh the package on the host, then try again.',
|
|
1301
1320
|
'update.corrupted': 'Downloaded file is corrupted, please retry', 'update.serverFileMissing': 'The file for this version is not on the server yet, please try again later',
|
|
1302
1321
|
'update.hashMissing': 'The update package has no SHA-256 checksum; download cancelled',
|
|
1303
1322
|
'update.installUnsupported': 'This version cannot install in-app, opening browser download',
|
|
@@ -1339,7 +1358,7 @@
|
|
|
1339
1358
|
'settings.notifyTitle': 'Notifications', 'settings.notifyDesc': 'Push on approvals / questions', 'settings.announcementHistoryTitle': 'Announcement history', 'settings.announcementHistoryDesc': 'Review announcements you received before', 'settings.announcementHistory': 'View history',
|
|
1340
1359
|
'settings.testNotifyTitle': 'Test notification', 'settings.testNotifyDesc': 'Schedule a local notification in 3 seconds to verify the notification pipeline', 'settings.testNotify': 'Send test notification',
|
|
1341
1360
|
'settings.testNotifySent': 'Test notification scheduled, arriving in 3s', 'settings.testNotifyFailed': 'Failed to send test notification: {msg}', 'settings.testNotifyUnavailable': 'Test notification is only available in the app',
|
|
1342
|
-
'settings.peakRemindTitle': 'Peak/off-peak reminders', 'settings.peakRemindDesc': '
|
|
1361
|
+
'settings.peakRemindTitle': 'Peak/off-peak reminders · dsh-cost-meter', 'settings.peakRemindDesc': 'Managed by dsh-cost-meter. Configure in DSH Settings → Cost → Peak pricing. Alerts require the DSH page; Remote no longer runs a separate background timer.',
|
|
1343
1362
|
'peakRemind.enterPeak': 'Peak pricing period started', 'peakRemind.enterOff': 'Off-peak pricing period started',
|
|
1344
1363
|
'peakRemind.peak0912': 'Peak 9:00-12:00', 'peakRemind.off1214': 'Off-peak 12:00-14:00',
|
|
1345
1364
|
'peakRemind.peak1418': 'Peak 14:00-18:00', 'peakRemind.off1809': 'Off-peak 18:00-9:00 next day',
|
|
@@ -1416,11 +1435,14 @@
|
|
|
1416
1435
|
<script src="insights.js"></script>
|
|
1417
1436
|
<script src="extensions.js"></script>
|
|
1418
1437
|
<script src="history.js"></script>
|
|
1438
|
+
<script src="activity.js"></script>
|
|
1439
|
+
<script src="image-preview.js"></script>
|
|
1419
1440
|
<script src="link-check.js"></script>
|
|
1420
1441
|
<script src="network.js"></script>
|
|
1421
1442
|
<script src="operations.js"></script>
|
|
1422
1443
|
<script src="workflow.js"></script>
|
|
1423
1444
|
<script src="relay-settings.js"></script>
|
|
1445
|
+
<script src="subagents.js"></script>
|
|
1424
1446
|
<script src="app.js"></script>
|
|
1425
1447
|
</body>
|
|
1426
1448
|
</html>
|
package/public/md.js
CHANGED
|
@@ -23,7 +23,46 @@
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function decodeEntities(s) {
|
|
27
|
+
const entities = { '&': '&', '"': '"', ''': "'", '<': '<', '>': '>' }
|
|
28
|
+
return String(s).replace(/&(?:amp|quot|lt|gt|#39);/g, entity => entities[entity])
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let imageLabel = '图片'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Markdown images become preview buttons. Remote/data URLs can load directly;
|
|
35
|
+
* local paths are placeholders that the client resolves through the authenticated file API.
|
|
36
|
+
* Returns null when the target is neither an image URL nor a local path.
|
|
37
|
+
*/
|
|
38
|
+
function imageHtml(altEscaped, urlEscaped, fileLinks) {
|
|
39
|
+
let raw = String(urlEscaped || '').trim()
|
|
40
|
+
if (raw.startsWith('<') && raw.endsWith('>')) raw = raw.slice(4, -4)
|
|
41
|
+
let target = decodeEntities(raw)
|
|
42
|
+
if (/^file:/i.test(target) && files?.pathOf) target = files.pathOf(target) || target
|
|
43
|
+
const alt = decodeEntities(String(altEscaped || '')).replace(/<[^>]*>/g, '').trim()
|
|
44
|
+
const label = escapeHtml(alt || imageLabel)
|
|
45
|
+
if (/^(?:data:image\/|https?:\/\/|\/api\/)/i.test(target)) {
|
|
46
|
+
return '<button type="button" class="chat-image" data-chat-image aria-label="' + label + '">' +
|
|
47
|
+
'<img src="' + escapeHtml(target) + '" alt="' + label + '" loading="lazy" draggable="false"></button>'
|
|
48
|
+
}
|
|
49
|
+
if (!fileLinks) return null
|
|
50
|
+
const local = /^(?:[A-Za-z]:[\\/]|\\\\|\/|\.{1,2}[\\/]|[^:\s]+[\\/])/.test(target)
|
|
51
|
+
|| /^[^:\s]+\.(?:png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(target)
|
|
52
|
+
if (!local) return null
|
|
53
|
+
return '<button type="button" class="chat-image is-loading" data-chat-image data-chat-image-path="' + escapeHtml(target) +
|
|
54
|
+
'" data-chat-image-alt="' + label + '" aria-label="' + label + '"><span class="chat-image-status">' + label + '</span></button>'
|
|
55
|
+
}
|
|
56
|
+
|
|
26
57
|
function inline(s, fileLinks) {
|
|
58
|
+
// Pull images out before inline emphasis/link rules so alt text and URLs stay intact.
|
|
59
|
+
const images = []
|
|
60
|
+
s = s.replace(/!\[([^\]]*)\]\(([^)\n]+)\)/g, function (m, alt, url) {
|
|
61
|
+
const html = imageHtml(alt, url, fileLinks)
|
|
62
|
+
if (!html) return m
|
|
63
|
+
images.push(html)
|
|
64
|
+
return '\u0000IMAGE' + (images.length - 1) + '\u0000'
|
|
65
|
+
})
|
|
27
66
|
s = s.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
28
67
|
s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
29
68
|
s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1<em>$2</em>')
|
|
@@ -40,7 +79,7 @@
|
|
|
40
79
|
if (!/^https?:\/\//i.test(url) || /\s/.test(url)) return m
|
|
41
80
|
return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + text + '</a>'
|
|
42
81
|
})
|
|
43
|
-
return s
|
|
82
|
+
return images.length ? s.replace(/\u0000IMAGE(\d+)\u0000/g, (m, index) => images[Number(index)] || '') : s
|
|
44
83
|
}
|
|
45
84
|
|
|
46
85
|
function tableCells(line) {
|
|
@@ -172,6 +211,7 @@
|
|
|
172
211
|
}
|
|
173
212
|
|
|
174
213
|
function mdToHtml(text, options) {
|
|
214
|
+
if (options?.imageLabel) imageLabel = String(options.imageLabel)
|
|
175
215
|
var raw = String(text == null ? '' : text)
|
|
176
216
|
var parts = raw.split(/```/)
|
|
177
217
|
var out = ''
|
package/public/network.js
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
return {weak,historyPageSize:weak?20:60,readTimeout:weak?90000:45000,pingTimeout:weak?12000:6000,pollTimeout:weak?45000:30000}
|
|
16
16
|
}
|
|
17
17
|
function setMode(value){if(!['auto','weak','normal'].includes(value))return;try{root.localStorage.setItem('dshNetworkModeV1',value)}catch{};return profile()}
|
|
18
|
+
// 弱网下可选关闭流式输出:只保留已完成的消息与工具结果。
|
|
19
|
+
const STREAM_KEY='dshWeakStreamOff'
|
|
20
|
+
function streamSetting(){try{return root.localStorage.getItem(STREAM_KEY)!=='0'}catch{return true}}
|
|
21
|
+
function streamTrimmed(){return streamSetting()&&profile().weak}
|
|
18
22
|
class PollLoop {
|
|
19
23
|
constructor(options){this.options=options;this.jobs={};this.setTimer=options.setTimer||setTimeout;this.clearTimer=options.clearTimer||clearTimeout}
|
|
20
24
|
stop(){for(const job of Object.values(this.jobs)){job.controller.abort();this.clearTimer(job.timer)}this.jobs={}}
|
|
@@ -42,21 +46,41 @@
|
|
|
42
46
|
}
|
|
43
47
|
function preferences(){
|
|
44
48
|
const panel=root.document?.getElementById('settings-page-general');if(!panel)return
|
|
49
|
+
const desktop=panel.classList.contains('ds-settings')
|
|
45
50
|
let row=root.document.getElementById('network-preferences')
|
|
46
51
|
if(!row){
|
|
47
|
-
row=root.document.createElement('div');row.id='network-preferences';row.className=
|
|
52
|
+
row=root.document.createElement('div');row.id='network-preferences';row.className=desktop?'ds-setting-row':'setting-row'
|
|
48
53
|
const copy=root.document.createElement('div'),title=root.document.createElement('div'),detail=root.document.createElement('div'),select=root.document.createElement('select')
|
|
49
|
-
title.dataset.networkTitle='';detail.dataset.networkDetail='';detail.className='
|
|
54
|
+
title.dataset.networkTitle='';detail.dataset.networkDetail='';title.className=desktop?'ds-setting-name':'setting-name';detail.className=desktop?'ds-setting-desc':'setting-desc';select.id='network-mode';select.className='setting-select'
|
|
50
55
|
for(const value of ['auto','weak','normal']){const option=root.document.createElement('option');option.value=value;select.append(option)}
|
|
51
|
-
copy.append(title,detail);row.append(copy,select)
|
|
52
|
-
|
|
56
|
+
copy.append(title,detail);row.append(copy,select)
|
|
57
|
+
const target=panel.querySelector('[data-workflow-settings-slot="input"]')||panel
|
|
58
|
+
target.append(row)
|
|
59
|
+
const section=target.closest?.('.workflow-settings-section');if(section)section.hidden=false
|
|
60
|
+
select.addEventListener('change',()=>{setMode(select.value);root.applyStreamPreference?.();root.enhanceCustomSelect?.(select)})
|
|
61
|
+
}
|
|
62
|
+
let streamRow=root.document.getElementById('network-stream-preferences')
|
|
63
|
+
if(!streamRow){
|
|
64
|
+
streamRow=root.document.createElement('div');streamRow.id='network-stream-preferences';streamRow.className=desktop?'ds-setting-row':'setting-row'
|
|
65
|
+
const copy=root.document.createElement('div'),title=root.document.createElement('div'),detail=root.document.createElement('div'),label=root.document.createElement('label'),input=root.document.createElement('input'),slider=root.document.createElement('span')
|
|
66
|
+
title.dataset.streamTitle='';detail.dataset.streamDetail='';title.className=desktop?'ds-setting-name':'setting-name';detail.className=desktop?'ds-setting-desc':'setting-desc'
|
|
67
|
+
input.type='checkbox';input.id='opt-weak-stream-off';label.className=desktop?'ds-switch':'switch';slider.className=desktop?'ds-slider':'slider'
|
|
68
|
+
label.append(input,slider);copy.append(title,detail);streamRow.append(copy,label)
|
|
69
|
+
const target=panel.querySelector('[data-workflow-settings-slot="input"]')||panel
|
|
70
|
+
target.append(streamRow)
|
|
71
|
+
const section=target.closest?.('.workflow-settings-section');if(section)section.hidden=false
|
|
72
|
+
input.addEventListener('change',()=>{try{root.localStorage.setItem(STREAM_KEY,input.checked?'1':'0')}catch{};root.applyStreamPreference?.()})
|
|
53
73
|
}
|
|
54
74
|
const english=root.I18N?.lang==='en'
|
|
55
75
|
row.querySelector('[data-network-title]').textContent=english?'Network mode':'网络模式'
|
|
56
76
|
row.querySelector('[data-network-detail]').textContent=english?'Weak mode loads fewer history entries and allows longer read waits. Sending is never retried automatically.':'弱网模式减少每页历史条数、延长读取等待;发送操作不会自动重试。'
|
|
57
77
|
const select=row.querySelector('select');select.setAttribute('aria-label',english?'Network mode':'网络模式');['auto','weak','normal'].forEach((v,i)=>select.options[i].textContent=(english?['Automatic','Weak network','Standard']:['自动判断','弱网优先','标准模式'])[i]);select.value=mode();root.enhanceCustomSelect?.(select);root.syncCustomSelect?.(select)
|
|
78
|
+
const streamInput=streamRow.querySelector('input');if(streamInput){streamInput.checked=streamSetting();streamInput.setAttribute('aria-label',english?'Disable streaming on weak networks':'弱网时关闭流式输出')}
|
|
79
|
+
const streamTitle=streamRow.querySelector('[data-stream-title]'),streamDetail=streamRow.querySelector('[data-stream-detail]')
|
|
80
|
+
if(streamTitle)streamTitle.textContent=english?'No streaming on weak networks':'弱网时关闭流式输出'
|
|
81
|
+
if(streamDetail)streamDetail.textContent=english?'Show only finished messages and tool results on weak networks; live thinking and calls that have not returned stay hidden.':'弱网下只显示已完成的消息和工具结果,隐藏流式思考和尚未返回的工具调用;标准网络不受影响。'
|
|
58
82
|
}
|
|
59
|
-
const api={profile,setMode,PollLoop,shareRead,observeLatency:ms=>{if(Number.isFinite(ms))measuredLatency=ms},preferences}
|
|
83
|
+
const api={profile,setMode,PollLoop,shareRead,observeLatency:ms=>{if(Number.isFinite(ms))measuredLatency=ms},preferences,streamTrimmed}
|
|
60
84
|
if(typeof module!=='undefined'&&module.exports)module.exports=api
|
|
61
85
|
else{root.DshNetwork=api;root.document.addEventListener('DOMContentLoaded',()=>{preferences();new MutationObserver(preferences).observe(root.document.documentElement,{attributes:true,attributeFilter:['lang']})})}
|
|
62
86
|
})(typeof window==='undefined'?globalThis:window)
|