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/app.js
CHANGED
|
@@ -103,7 +103,7 @@ const state = {
|
|
|
103
103
|
wbArchived: [],
|
|
104
104
|
wbOpen: false,
|
|
105
105
|
wbOpenProjects: {},
|
|
106
|
-
|
|
106
|
+
subagentSessions: {}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Increment on every identity transition, including A -> B -> A and token edits.
|
|
@@ -120,7 +120,7 @@ for (const key of ['server', 'token']) {
|
|
|
120
120
|
state.sessions = []; state.byId.clear(); state.pendingProjections.clear()
|
|
121
121
|
state.hostInfo = null
|
|
122
122
|
if(typeof closeStream==='function'&&typeof streamMeta!=='undefined'){closeStream('mux');closeStream('host')}
|
|
123
|
-
state.current = null; state.history = emptyHistory()
|
|
123
|
+
state.current = null; state.history = emptyHistory(); state.subagentSessions = {}; window.DshSubagents?.reset()
|
|
124
124
|
state.models = { loaded: false, loading: false, groups: [], current: null, failures: [] }
|
|
125
125
|
state.modelSettings = { status: 'idle', error: '', writable: false, hasDocument: false, providers: [], namespaces: [], credentials: {} }; state.modelEditor = null
|
|
126
126
|
state.goalEdit = null; state.goalEditContext = null
|
|
@@ -523,7 +523,8 @@ async function rpc(method, payload = {}, timeoutMs = 45000) {
|
|
|
523
523
|
if (!full?.result) throw new Error(t('err.badResponse'))
|
|
524
524
|
if (!full.result.ok) {
|
|
525
525
|
const err = full.result.error || {}
|
|
526
|
-
const error = new Error(err.message || t('err.dshError'))
|
|
526
|
+
const error = new Error(err.code === 'session/migration-required' ? t('session.migrationRequired') : err.message || t('err.dshError'))
|
|
527
|
+
error.code = err.code
|
|
527
528
|
error.rpcRejected = true
|
|
528
529
|
throw error
|
|
529
530
|
}
|
|
@@ -854,6 +855,7 @@ function renderGroupSelect() {
|
|
|
854
855
|
const menu = $('group-select-menu')
|
|
855
856
|
if (!label || !menu) return
|
|
856
857
|
label.textContent = state.activeGroup
|
|
858
|
+
$('group-select-btn')?.setAttribute('aria-label', t('groups.currentLabel', { group: state.activeGroup }))
|
|
857
859
|
menu.innerHTML = state.groups.map(g =>
|
|
858
860
|
`<button type="button" class="group-option ${g === state.activeGroup ? 'current' : ''}" data-group-option="${esc(g)}">${esc(g)}${g === state.activeGroup ? ' ✓' : ''}</button>`).join('')
|
|
859
861
|
menu.querySelectorAll('[data-group-option]').forEach(b =>
|
|
@@ -955,7 +957,7 @@ function renderServers() {
|
|
|
955
957
|
const activeManual = state.groupActive[g] || ''
|
|
956
958
|
return `<div class="srv-group" data-group="${esc(g)}">
|
|
957
959
|
<div class="srv-group-head">
|
|
958
|
-
<button class="srv-group-name" data-group-name="${esc(g)}">${g === state.activeGroup ? '▾' : '▸'} ${esc(g)}
|
|
960
|
+
<button class="srv-group-name" data-group-name="${esc(g)}"><span class="srv-group-label">${g === state.activeGroup ? '▾' : '▸'} ${esc(g)}</span><span class="srv-group-count">${list.length}</span></button>
|
|
959
961
|
<button class="srv-group-speed mini-btn" data-speed-group="${esc(g)}" title="${t('groups.speedTest')}">⚡</button>
|
|
960
962
|
<label class="switch small" title="${t('groups.autoSelect')}">
|
|
961
963
|
<input type="checkbox" data-auto-group="${esc(g)}" ${auto ? 'checked' : ''}>
|
|
@@ -966,14 +968,17 @@ function renderServers() {
|
|
|
966
968
|
<div class="srv-group-body ${g === state.activeGroup ? '' : 'hidden'}">
|
|
967
969
|
${list.map(s => {
|
|
968
970
|
const ms = state.serverLatency[serverKey(s)]
|
|
969
|
-
let badge = `<span class="server-badge">${t('servers.untested')}</span>`
|
|
970
971
|
const active = s.url === state.server && serverToken(s) === state.token
|
|
971
|
-
|
|
972
|
+
// 只显示一条最有用的状态,避免地址被状态文案挤成竖排。
|
|
973
|
+
let badge = `<span class="server-badge">${t('servers.untested')}</span>`
|
|
974
|
+
if (!s.token) badge = `<span class="server-badge bad">${t('servers.tokenMissing')}</span>`
|
|
975
|
+
else if (Number.isFinite(ms)) badge = `<span class="server-badge ${active ? 'good' : ''}">${ms}ms${active ? t('servers.current') : ''}</span>`
|
|
972
976
|
else if (ms !== undefined) badge = '<span class="server-badge bad">' + t('servers.unreachable') + '</span>'
|
|
977
|
+
else if (active) badge = `<span class="server-badge good">${t('servers.currentOnly')}</span>`
|
|
973
978
|
const activeInGroup = auto ? active : s.id === activeManual
|
|
974
979
|
return `<div class="server-row ${activeInGroup ? 'active' : ''}" data-use-server="${esc(s.id)}">
|
|
975
|
-
<span class="server-main"><span class="server-note">${esc(serverTitle(s))}</span>${s.note ? `<span class="server-url">${esc(s.url)}</span>` : ''}
|
|
976
|
-
<button class="server-edit" data-edit-server="${esc(s.id)}" title="${t('servers.edit')}">✎</button>
|
|
980
|
+
<span class="server-main"><span class="server-note" title="${esc(serverTitle(s))}">${esc(serverTitle(s))}</span>${s.note ? `<span class="server-url">${esc(s.url)}</span>` : ''}</span>${badge}
|
|
981
|
+
<button class="server-edit" data-edit-server="${esc(s.id)}" title="${t('servers.edit')}" aria-label="${t('servers.edit')}">✎</button>
|
|
977
982
|
<button class="server-del" data-del-server="${esc(s.id)}" aria-label="${t('servers.delete')}">✕</button>
|
|
978
983
|
</div>`
|
|
979
984
|
}).join('') || '<div class="server-empty">' + t('groups.noServer') + '</div>'}
|
|
@@ -1031,7 +1036,7 @@ function renderServers() {
|
|
|
1031
1036
|
const curGroup = cur ? cur.group : state.activeGroup
|
|
1032
1037
|
const curMs = cur ? state.serverLatency[serverKey(cur)] : undefined
|
|
1033
1038
|
$('server-desc').textContent = state.server
|
|
1034
|
-
? t('servers.currentDescGroup', { group: curGroup, url: curNote
|
|
1039
|
+
? t('servers.currentDescGroup', { group: curGroup, url: curNote }) + (Number.isFinite(curMs) ? ' · ' + curMs + 'ms' : '')
|
|
1035
1040
|
: (CAP?.isNativePlatform?.() ? t('servers.notSet') : t('servers.defaultDesc'))
|
|
1036
1041
|
updateConn()
|
|
1037
1042
|
}
|
|
@@ -1727,6 +1732,12 @@ async function refreshSessions() {
|
|
|
1727
1732
|
}
|
|
1728
1733
|
state.sessions = v.items || []
|
|
1729
1734
|
state.byId = new Map(state.sessions.map(s => [s.sessionId, s]))
|
|
1735
|
+
for (const [id, child] of Object.entries(state.subagentSessions || {})) {
|
|
1736
|
+
const listed = state.byId.get(id)
|
|
1737
|
+
const merged = listed ? { ...child, ...listed, parentSessionId: child.parentSessionId, subagentMode: child.subagentMode, origin: 'subagent' } : child
|
|
1738
|
+
state.byId.set(id, merged)
|
|
1739
|
+
state.subagentSessions[id] = merged
|
|
1740
|
+
}
|
|
1730
1741
|
applyPendingProjections()
|
|
1731
1742
|
cacheWrite(CACHE.sessions, state.sessions.slice(0, 80))
|
|
1732
1743
|
renderSessions()
|
|
@@ -1785,9 +1796,15 @@ function hydrateSessionProjections(sessionId, projections) {
|
|
|
1785
1796
|
if (!s || !projections || typeof projections !== 'object') return
|
|
1786
1797
|
const incomingSeq = Number(projections.asOfSeq) || 0
|
|
1787
1798
|
const current = s.projections || { asOfSeq: 0, values: {} }
|
|
1799
|
+
if (projections.kind === 'cached' && current.kind === 'sequenced') return
|
|
1800
|
+
if (current.kind === 'cached' || projections.kind === 'cached') {
|
|
1801
|
+
s.projections = { ...projections, asOfSeq: incomingSeq, kind: projections.kind || 'sequenced', values: { ...(current.values || {}), ...(projections.values || {}) } }
|
|
1802
|
+
return
|
|
1803
|
+
}
|
|
1788
1804
|
const currentSeq = Number(current.asOfSeq) || 0
|
|
1789
1805
|
if (incomingSeq < currentSeq) return
|
|
1790
1806
|
s.projections = {
|
|
1807
|
+
kind: projections.kind || current.kind || 'sequenced',
|
|
1791
1808
|
asOfSeq: Math.max(currentSeq, incomingSeq),
|
|
1792
1809
|
values: { ...(current.values || {}), ...(projections.values || {}) }
|
|
1793
1810
|
}
|
|
@@ -1808,6 +1825,7 @@ function applyProjection(sessionId, key, value, seq) {
|
|
|
1808
1825
|
state.pendingProjections.set(sessionId, pending)
|
|
1809
1826
|
return
|
|
1810
1827
|
}
|
|
1828
|
+
if (s.projections?.kind === 'cached') s.projections = { kind: 'sequenced', asOfSeq: 0, values: { ...(s.projections.values || {}) } }
|
|
1811
1829
|
const currentSeq = Number(s.projections?.asOfSeq) || 0
|
|
1812
1830
|
if (seq && seq < currentSeq) return
|
|
1813
1831
|
s.projections = s.projections || { asOfSeq: 0, values: {} }
|
|
@@ -2316,6 +2334,7 @@ const emptySessionCleanup = new Set()
|
|
|
2316
2334
|
async function archiveEmptySessionOnLeave(sessionId, leaving = false) {
|
|
2317
2335
|
const base = state.server, connection=captureConnection()
|
|
2318
2336
|
const protectedSession = () => !connection.valid() || state.server !== base || (!leaving && state.current !== sessionId)
|
|
2337
|
+
|| !!state.byId.get(sessionId)?.parentSessionId || state.byId.get(sessionId)?.origin === 'subagent'
|
|
2319
2338
|
|| !state.byId.has(sessionId) || state.byId.get(sessionId)?.running
|
|
2320
2339
|
|| state.sessionActivity?.has(sessionId) || state.pendingPrompts?.has(sessionId)
|
|
2321
2340
|
|| (state.queues[sessionId] || []).length > 0
|
|
@@ -2347,6 +2366,7 @@ async function openSession(id) {
|
|
|
2347
2366
|
$('btn-archive-session').classList.toggle('hidden', (state.wbArchived || []).includes(id))
|
|
2348
2367
|
$('session-cards').innerHTML = ''
|
|
2349
2368
|
renderSessionTitle(); renderSessionSub(); updateCancelBtn(); updateSessionStatus()
|
|
2369
|
+
renderSessionCards()
|
|
2350
2370
|
$('history').innerHTML = '<div class="empty">' + t('history.loading') + '</div>'
|
|
2351
2371
|
renderQueue()
|
|
2352
2372
|
renderSessionPending()
|
|
@@ -2381,6 +2401,11 @@ async function closeSession() {
|
|
|
2381
2401
|
if (closeSession.pending) return closeSession.pending
|
|
2382
2402
|
const sessionId = state.current
|
|
2383
2403
|
if (!sessionId) return
|
|
2404
|
+
const parentId = state.byId.get(sessionId)?.parentSessionId
|
|
2405
|
+
if (parentId && parentId !== sessionId) {
|
|
2406
|
+
setComposerFullscreen(false);clearComposerImages();hideComposerMenu()
|
|
2407
|
+
return openSession(parentId)
|
|
2408
|
+
}
|
|
2384
2409
|
const task = (async () => {
|
|
2385
2410
|
const discard = await shouldDiscardEmptySession(sessionId) && await archiveEmptySessionOnLeave(sessionId)
|
|
2386
2411
|
if (state.current !== sessionId) return
|
|
@@ -2412,13 +2437,24 @@ function bindNativeBack() {
|
|
|
2412
2437
|
CAP.Plugins?.App?.addListener?.('backButton', () => {
|
|
2413
2438
|
if ($('composer-wrap')?.classList.contains('fs')) { setComposerFullscreen(false); return }
|
|
2414
2439
|
if (customSelectCurrent) { closeCustomSelect(); return }
|
|
2440
|
+
if (groupDrawerOpen()) { closeGroupDrawer(); return }
|
|
2441
|
+
if (typeof window !== 'undefined' && window.DshImagePreview?.isOpen?.()) { window.DshImagePreview.close(); return }
|
|
2442
|
+
const dialog = document.querySelector('dialog[open]')
|
|
2443
|
+
if (dialog) { dialog.close(); return }
|
|
2415
2444
|
const openModal = [...document.querySelectorAll('.modal')].find(m => !m.classList.contains('hidden'))
|
|
2416
2445
|
if (openModal) { if (openModal.id === 'modal-notes') closeNotesModal(); else if (openModal.id === 'modal-archive') closeArchiveConfirm(); else if (openModal.id === 'modal-rename') closeRenameSession(); else if (openModal.id === 'modal-app-version-warning') closeAppVersionWarning(false); else if (openModal.id === 'modal-scan-live') closeLiveScan(''); else openModal.classList.add('hidden'); return } // 先关弹窗
|
|
2446
|
+
if (!$('view-settings').classList.contains('hidden')) {
|
|
2447
|
+
if ($('settings-home').classList.contains('hidden')) showSettingsHome()
|
|
2448
|
+
else showView('view-home')
|
|
2449
|
+
return
|
|
2450
|
+
}
|
|
2451
|
+
if (!$('view-plugins').classList.contains('hidden')) { showView('view-settings'); return }
|
|
2417
2452
|
if (document.body.classList.contains('in-session')) { void closeSession(); return } // 会话页 → 回主页
|
|
2418
2453
|
if (!$('view-files').classList.contains('hidden')) { // 文件页 → 上级目录 → 主页
|
|
2419
2454
|
if (state.fs.path && state.fs.initial && state.fs.path !== state.fs.initial) { fsUp(); return }
|
|
2420
2455
|
showView('view-home'); return
|
|
2421
2456
|
}
|
|
2457
|
+
if ($('view-home').classList.contains('hidden')) { showView('view-home'); return }
|
|
2422
2458
|
try { CAP.Plugins?.App?.exitApp?.() } catch {} // 主页再返回 → 退出(与系统一致)
|
|
2423
2459
|
})
|
|
2424
2460
|
} catch {}
|
|
@@ -2543,7 +2579,9 @@ function applyReasoningStreamEvent(event) {
|
|
|
2543
2579
|
}
|
|
2544
2580
|
|
|
2545
2581
|
let reasoningRenderTimer = null
|
|
2582
|
+
function weakStreamTrim() { return !!window.DshNetwork?.streamTrimmed?.() }
|
|
2546
2583
|
function scheduleReasoningRender() {
|
|
2584
|
+
if (weakStreamTrim()) return
|
|
2547
2585
|
if (reasoningRenderTimer) return
|
|
2548
2586
|
reasoningRenderTimer = setTimeout(() => {
|
|
2549
2587
|
reasoningRenderTimer = null
|
|
@@ -2553,10 +2591,11 @@ function scheduleReasoningRender() {
|
|
|
2553
2591
|
}
|
|
2554
2592
|
|
|
2555
2593
|
function partialReasoningHtml() {
|
|
2594
|
+
if (weakStreamTrim()) return ''
|
|
2556
2595
|
return [...state.history.partialReasoning.values()]
|
|
2557
2596
|
.filter(item => item.text)
|
|
2558
2597
|
.sort((a, b) => (a.turn ?? 0) - (b.turn ?? 0) || (a.step ?? 0) - (b.step ?? 0) || (a.index ?? 0) - (b.index ?? 0))
|
|
2559
|
-
.map(item => `<div class="msg assistant reasoning-live"><div class="role">${esc(t('role.dsh'))}</div><details class="tool" open><summary>${esc(t('block.thinkingLive'))}</summary><div class="tool-text">${esc(truncate(item.text, 12000))}</div></details></div>`)
|
|
2598
|
+
.map(item => window.DshActivity ? window.DshActivity.reasoning({text:item.text,live:true,key:window.DshActivity.reasoningKey(item,item.index,'live-reasoning')}) : `<div class="msg assistant reasoning-live"><div class="role">${esc(t('role.dsh'))}</div><details class="tool" open><summary>${esc(t('block.thinkingLive'))}</summary><div class="tool-text">${esc(truncate(item.text, 12000))}</div></details></div>`)
|
|
2560
2599
|
.join('')
|
|
2561
2600
|
}
|
|
2562
2601
|
|
|
@@ -2577,7 +2616,7 @@ function getConversationView() {
|
|
|
2577
2616
|
if(!conversationView)conversationView=new window.DshHistory.HistoryView($('history'),{
|
|
2578
2617
|
html:entry=>eventHtml(entry, {toolNames:state.history.toolNames}),
|
|
2579
2618
|
older:()=>loadHistory(false),olderLabel:()=>t('history.earlier'),loadingLabel:()=>t('history.loadingEarlier'),live:partialReasoningHtml,
|
|
2580
|
-
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end
|
|
2619
|
+
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end;const latest=$('btn-history-latest');if(latest){latest.classList.toggle('hidden',view.atBottom&&view.unread===0&&!state.history.tailEvicted);latest.textContent=t('history.latest')+(view.unread?' ('+view.unread+')':view.hasPending?' · '+(I18N.lang==='en'?'New content':'有新内容'):'')}updateRail(view.domChanged)},
|
|
2581
2620
|
scrolled:()=>{updateRail()}
|
|
2582
2621
|
})
|
|
2583
2622
|
return conversationView
|
|
@@ -2622,6 +2661,8 @@ async function loadHistory(reset = true) {
|
|
|
2622
2661
|
if(reset){if(hadContent)historySource('syncing');else setSessionRecovery('loading')}
|
|
2623
2662
|
const network=window.DshNetwork?.profile() || {historyPageSize:60,readTimeout:45000}
|
|
2624
2663
|
const payload={sessionId:id,maxMessages:network.historyPageSize}
|
|
2664
|
+
const child=state.subagentSessions?.[id] || state.byId.get(id)
|
|
2665
|
+
if(child?.origin==='subagent' && child.parentSessionId) Object.assign(payload,{parentSessionId:child.parentSessionId,subagentMode:child.subagentMode || 'unknown'})
|
|
2625
2666
|
if(!reset&&Number.isFinite(history.minSeq))payload.beforeSeq=history.minSeq
|
|
2626
2667
|
getConversationView().more.disabled=true
|
|
2627
2668
|
getConversationView().more.textContent=getConversationView().options.loadingLabel()
|
|
@@ -2681,6 +2722,19 @@ function insertLiveEvent(event) {
|
|
|
2681
2722
|
|
|
2682
2723
|
function isToolEvent(type) { return type === 'tool/call' || type === 'tool/result' }
|
|
2683
2724
|
|
|
2725
|
+
/** One collapsed row for a turn's tools and reasoning, matching the desktop conversation rhythm. */
|
|
2726
|
+
function activityGroupHtml(group, ctx) {
|
|
2727
|
+
const items = group.items || []
|
|
2728
|
+
if (!items.length) return ''
|
|
2729
|
+
const tools = items.filter(item => item.kind === 'tool').map(item => item.entry)
|
|
2730
|
+
const running = !!group.running
|
|
2731
|
+
const failed = tools.some(entry => entry.view?.toolActivity?.error || entry.event?.data?.error)
|
|
2732
|
+
const body = items.map(item => item.kind === 'reasoning'
|
|
2733
|
+
? window.DshActivity.reasoning({ text: item.text, key: item.key })
|
|
2734
|
+
: eventHtml(item.entry, ctx)).join('')
|
|
2735
|
+
return `<details class="chat-activity-group${failed ? ' is-error' : ''}${running ? ' is-running' : ''}" data-activity-key="activity-group:${items[0]?.seq ?? ''}"><summary><span class="activity-group-title">${esc(t('activity.group', { n: items.length }))}</span>${running ? `<span class="activity-group-live"><i aria-hidden="true"></i>${esc(t('activity.groupRunning'))}</span>` : ''}<span class="activity-chevron" aria-hidden="true"></span></summary><div class="activity-group-body">${body}</div></details>`
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2684
2738
|
function filteredEntries() {
|
|
2685
2739
|
const showTools = LS.get('showTools', '1') !== '0'
|
|
2686
2740
|
const f = state.history.visible.filter(e => showTools || !isToolEvent(e.event?.type))
|
|
@@ -2693,8 +2747,23 @@ function renderHistory(reset=false,mode='auto') {
|
|
|
2693
2747
|
for(const entry of state.history.visible){const d=entry.event?.data;if(entry.event?.type==='tool/call'&&d?.callId&&d.name)toolNames.set(d.callId,d.name)}
|
|
2694
2748
|
state.history.toolNames=toolNames
|
|
2695
2749
|
$('history-hint').textContent=t('history.count',{n:state.history.visible.length})
|
|
2696
|
-
|
|
2697
|
-
|
|
2750
|
+
let prepared=window.DshActivity?.prepare(filtered)||filtered
|
|
2751
|
+
// 弱网精简:尚未返回的调用在完成前不展示,只留已完成的消息与工具结果。
|
|
2752
|
+
if(weakStreamTrim())prepared=prepared.filter(entry=>entry.event?.type!=='tool/call'||entry.view?.toolActivity)
|
|
2753
|
+
// DSH 0.2.1 also embeds tool blocks in messages; the separated events own the grouped rows.
|
|
2754
|
+
state.history.suppressBlockTools = state.history.visible.some(entry => entry.event?.type === 'tool/call')
|
|
2755
|
+
if(window.DshActivity?.group)prepared=window.DshActivity.group(prepared)
|
|
2756
|
+
// Running is a property of the session's current turn, not of an unpaired call:
|
|
2757
|
+
// a finished turn may keep an unmatched call after an interrupt, and the model may be
|
|
2758
|
+
// thinking between tools while the last group is still the active one.
|
|
2759
|
+
const sessionRunning = !!state.byId.get(state.current)?.running
|
|
2760
|
+
const groups = prepared.filter(entry => entry.view?.activityGroup)
|
|
2761
|
+
const activeGroup = groups.at(-1)
|
|
2762
|
+
if (activeGroup) activeGroup.view.activityGroup.running = sessionRunning
|
|
2763
|
+
getConversationView().set(prepared,{reset,follow:mode==='bottom',live:partialReasoningHtml(),hasMore:state.history.hasMore,loading:state.history.loading,emptyLabel:t('history.empty')})
|
|
2764
|
+
window.DshImagePreview?.hydrate?.($('history'))
|
|
2765
|
+
}
|
|
2766
|
+
window.applyStreamPreference=()=>{if(state.current)renderHistory(false,'auto')}
|
|
2698
2767
|
|
|
2699
2768
|
/* 右侧导航条: 用户发言节点 + 拖动快速定位 */
|
|
2700
2769
|
let historyRailLayout=null
|
|
@@ -2789,7 +2858,9 @@ function eventHtml(entry, ctx = {}) {
|
|
|
2789
2858
|
const ev = entry.event || {}
|
|
2790
2859
|
const data = ev.data || {}
|
|
2791
2860
|
const type = ev.type || 'event'
|
|
2861
|
+
if (entry.view?.activityGroup) return activityGroupHtml(entry.view.activityGroup, ctx)
|
|
2792
2862
|
if (!shouldShowEvent(type, ev)) return ''
|
|
2863
|
+
if (window.DshActivity && isToolEvent(type)) return window.DshActivity.toolEvent(entry)
|
|
2793
2864
|
let inner = ''
|
|
2794
2865
|
|
|
2795
2866
|
if (type === 'user/message' || type === 'assistant/message') {
|
|
@@ -2802,7 +2873,11 @@ function eventHtml(entry, ctx = {}) {
|
|
|
2802
2873
|
} else if (type === 'user/message' && !isHumanUserMessage(ev)) {
|
|
2803
2874
|
return ''
|
|
2804
2875
|
} else {
|
|
2805
|
-
|
|
2876
|
+
const body = blocks.map((block,index)=>blockHtml(block,index,{...data,seq,suppressBlockTools:state.history.suppressBlockTools})).join('')
|
|
2877
|
+
// Inline tool blocks duplicate the separated tool events; when those events exist the
|
|
2878
|
+
// calls live in the activity group, so an assistant message with nothing else disappears.
|
|
2879
|
+
if (!body) return ''
|
|
2880
|
+
inner = `<div class="msg ${esc(role)}" data-seq="${seq}"><div class="role">${esc(role === 'user' ? t('role.me') : t('role.dsh'))}</div>${body}</div>`
|
|
2806
2881
|
}
|
|
2807
2882
|
} else if (type === 'tool/call') {
|
|
2808
2883
|
const name = data.name || data.toolName || t('tool.default')
|
|
@@ -2826,13 +2901,21 @@ function eventHtml(entry, ctx = {}) {
|
|
|
2826
2901
|
return inner
|
|
2827
2902
|
}
|
|
2828
2903
|
|
|
2829
|
-
function blockHtml(b) {
|
|
2904
|
+
function blockHtml(b,index=0,context={}) {
|
|
2830
2905
|
if (!b || typeof b !== 'object') return `<p>${esc(String(b))}</p>`
|
|
2831
|
-
if ((b.type === 'tool-call' || b.type === 'tool-result') && LS.get('showTools', '1') === '0') return ''
|
|
2906
|
+
if ((b.type === 'tool-call' || b.type === 'tool-result') && (context.suppressBlockTools || LS.get('showTools', '1') === '0')) return ''
|
|
2907
|
+
if (typeof window !== 'undefined' && window.DshActivity) {
|
|
2908
|
+
const key='block:'+context.seq+':'+index
|
|
2909
|
+
if (b.type==='thinking'||b.type==='reasoning') return window.DshActivity.reasoning({text:b.text??b.content??'',key:window.DshActivity.reasoningKey(context,index,key)})
|
|
2910
|
+
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)})})
|
|
2911
|
+
}
|
|
2832
2912
|
switch (b.type) {
|
|
2833
|
-
case 'text': return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true }) : esc(b.text ?? '')}</div>`
|
|
2913
|
+
case 'text': return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true, imageLabel: t('block.image') }) : esc(b.text ?? '')}</div>`
|
|
2834
2914
|
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>`
|
|
2835
|
-
case 'image':
|
|
2915
|
+
case 'image': {
|
|
2916
|
+
const alt = b.name || b.filename || t('block.image')
|
|
2917
|
+
return `<button type="button" class="chat-image" data-chat-image aria-label="${esc(t('block.image'))}"><img alt="${esc(alt)}" src="data:${esc(b.mediaType || 'image/png')};base64,${esc(b.data || '')}" draggable="false"></button>`
|
|
2918
|
+
}
|
|
2836
2919
|
case 'thinking':
|
|
2837
2920
|
case 'reasoning':
|
|
2838
2921
|
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>`
|
|
@@ -2872,11 +2955,29 @@ function statsHtml(s) {
|
|
|
2872
2955
|
}
|
|
2873
2956
|
|
|
2874
2957
|
let sessionSubagentsJob = null
|
|
2958
|
+
function rememberSubagent(entry, parentId) {
|
|
2959
|
+
const childId = entry.id
|
|
2960
|
+
const child = state.byId.get(childId) || { sessionId: childId, cwd: state.byId.get(parentId)?.cwd || '' }
|
|
2961
|
+
Object.assign(child, { parentSessionId: parentId, origin: 'subagent', subagentMode: entry.mode || child.subagentMode || 'unknown' })
|
|
2962
|
+
if (entry.label && !child.projections?.values?.title) {
|
|
2963
|
+
child.projections ||= { values: {} }
|
|
2964
|
+
child.projections.values ||= {}
|
|
2965
|
+
child.projections.values.title = entry.label
|
|
2966
|
+
}
|
|
2967
|
+
state.byId.set(childId, child)
|
|
2968
|
+
state.subagentSessions ||= {}
|
|
2969
|
+
state.subagentSessions[childId] = child
|
|
2970
|
+
}
|
|
2971
|
+
async function openSubagentSession(childId, parentId, entry = {}, rootId = parentId) {
|
|
2972
|
+
if (!childId || childId === parentId || state.current !== rootId) return
|
|
2973
|
+
rememberSubagent({ ...entry, id: childId }, parentId)
|
|
2974
|
+
await openSession(childId)
|
|
2975
|
+
}
|
|
2875
2976
|
async function loadSessionSubagents(sessionId) {
|
|
2876
2977
|
if (sessionSubagentsJob?.sessionId === sessionId && sessionSubagentsJob.connection.valid()) return sessionSubagentsJob.promise
|
|
2877
2978
|
const connection = captureConnection(), job = { sessionId, connection }
|
|
2878
2979
|
job.promise = (async () => {
|
|
2879
|
-
const value = await
|
|
2980
|
+
const value = await rpc('subagent.list', { parentSessionId: sessionId })
|
|
2880
2981
|
return connection.valid() ? value : null
|
|
2881
2982
|
})()
|
|
2882
2983
|
sessionSubagentsJob = job
|
|
@@ -2937,30 +3038,15 @@ async function renderSessionCards() {
|
|
|
2937
3038
|
}))
|
|
2938
3039
|
|
|
2939
3040
|
// 子代理
|
|
2940
|
-
const sub = await loadSessionSubagents(sessionId)
|
|
2941
3041
|
if (!connection.valid() || renderGeneration !== sessionCardsRenderGeneration || state.current !== sessionId) return
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
}).join('')
|
|
2951
|
-
const subagentClosedIcon = 'M7 10l5 5 5-5'
|
|
2952
|
-
const subagentOpenIcon = 'M7 14l5-5 5 5'
|
|
2953
|
-
const subagentIcon = expanded ? subagentOpenIcon : subagentClosedIcon
|
|
2954
|
-
box.insertAdjacentHTML('beforeend', `<div class="card subagent-card"><button type="button" class="subagent-toggle" data-subagent-toggle aria-expanded="${expanded}" aria-label="${esc(toggleLabel)}" title="${esc(toggleLabel)}"><span class="card-title">${esc(t('subagent.count', { n: sub.entries.length }))}</span><span class="subagent-toggle-icon" aria-hidden="true"><morph-icon data-morph-state="${expanded ? 'open' : 'closed'}" data-morph-closed="${subagentClosedIcon}" data-morph-open="${subagentOpenIcon}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${subagentIcon}"/></svg></morph-icon></span></button><div class="subagent-list${expanded ? '' : ' hidden'}">${rows}</div></div>`)
|
|
2955
|
-
box.querySelector('[data-subagent-toggle]')?.addEventListener('click', () => {
|
|
2956
|
-
const icon = box.querySelector('[data-subagent-toggle] morph-icon')
|
|
2957
|
-
if (icon) icon.setAttribute('data-morph-state', expanded ? 'closed' : 'open')
|
|
2958
|
-
state.subagentExpandedSession = expanded ? '' : sessionId
|
|
2959
|
-
setTimeout(() => renderSessionCards(), 240)
|
|
2960
|
-
})
|
|
2961
|
-
box.querySelectorAll('[data-sub-interrupt]').forEach(btn =>
|
|
2962
|
-
btn.addEventListener('click', () => interruptSubagent(btn.dataset.subInterrupt)))
|
|
2963
|
-
}
|
|
3042
|
+
window.DshSubagents?.configure($('btn-subagents'), {
|
|
3043
|
+
sessionId, title: titleOf(s), activity: s.running === true ? 'running' : s.running === false ? 'inactive' : 'unknown', parentId: s.origin === 'subagent' ? s.parentSessionId : null,
|
|
3044
|
+
valid: () => connection.valid() && state.current === sessionId,
|
|
3045
|
+
read: loadSessionSubagents, remember: rememberSubagent,
|
|
3046
|
+
onShow: () => conversationView?.pause(), onClose: () => conversationView?.resume(),
|
|
3047
|
+
open: (entry, parentId) => openSubagentSession(entry.id, parentId, entry, sessionId),
|
|
3048
|
+
interrupt: interruptSubagent,
|
|
3049
|
+
})
|
|
2964
3050
|
}
|
|
2965
3051
|
|
|
2966
3052
|
function setGoalPhaseLocal(phase) {
|
|
@@ -2994,10 +3080,11 @@ async function goalAction(kind) {
|
|
|
2994
3080
|
scheduleRefresh()
|
|
2995
3081
|
}
|
|
2996
3082
|
|
|
2997
|
-
async function interruptSubagent(childId) {
|
|
3083
|
+
async function interruptSubagent(childId, parentId = state.current) {
|
|
3084
|
+
const connection = captureConnection(), rootId = state.current
|
|
2998
3085
|
if (!confirm(t('subagent.confirmInterrupt'))) return
|
|
2999
|
-
const result = await safeRpc('subagent.interrupt', { parentSessionId:
|
|
3000
|
-
if (result == null) return
|
|
3086
|
+
const result = await safeRpc('subagent.interrupt', { parentSessionId: parentId, childSessionId: childId, mode: 'continuable' }, t('subagent.interruptFailed'))
|
|
3087
|
+
if (result == null || !connection.valid() || state.current !== rootId) return
|
|
3001
3088
|
toast(t('subagent.interruptSubmitted'), 'ok')
|
|
3002
3089
|
setTimeout(renderSessionCards, 600)
|
|
3003
3090
|
}
|
|
@@ -3320,6 +3407,7 @@ function bindComposerSend(button) {
|
|
|
3320
3407
|
}
|
|
3321
3408
|
|
|
3322
3409
|
async function sendSessionContent(text, images, requestedMode = 'queue') {
|
|
3410
|
+
if (state.byId.get(state.current)?.origin === 'subagent') { toast('子代理记录为只读 / Subagent records are read only'); return false }
|
|
3323
3411
|
const clean = String(text || '').trim()
|
|
3324
3412
|
if ((!clean && !images.length) || !state.current || composerSending) return false
|
|
3325
3413
|
const sessionId = state.current
|
|
@@ -4278,6 +4366,18 @@ function fsApiUrl(sub, params = {}) {
|
|
|
4278
4366
|
return u.href
|
|
4279
4367
|
}
|
|
4280
4368
|
|
|
4369
|
+
/** 对话里 Markdown 图片的本地路径:相对路径按当前会话工作区解析,读取走 /fs/file。 */
|
|
4370
|
+
function chatImageRequest(pathValue) {
|
|
4371
|
+
const value = String(pathValue || '').trim()
|
|
4372
|
+
if (!value) return null
|
|
4373
|
+
let target = value
|
|
4374
|
+
if (!/^(?:[A-Za-z]:[\\/]|\\\\|\/|~[\\/])/.test(value)) {
|
|
4375
|
+
const root = state.byId.get(state.current)?.cwd || ''
|
|
4376
|
+
if (root) target = root.replace(/[\\/]+$/, '') + (root.includes('\\') ? '\\' : '/') + value.replace(/^\.?[\\/]+/, '')
|
|
4377
|
+
}
|
|
4378
|
+
return { url: fsApiUrl('/file', { path: target }), headers: fsHeaders() }
|
|
4379
|
+
}
|
|
4380
|
+
|
|
4281
4381
|
function fsAuthError(status) {
|
|
4282
4382
|
if (status === 401) authFailure()
|
|
4283
4383
|
}
|
|
@@ -5215,11 +5315,11 @@ async function fetchAnnouncements() {
|
|
|
5215
5315
|
state.announcements = normalized.sort((a, b) => Number(b.publishedAt || 0) - Number(a.publishedAt || 0))
|
|
5216
5316
|
storeAnnouncementHistory(normalized)
|
|
5217
5317
|
renderAnnouncementBoard()
|
|
5218
|
-
if (window.DshWorkflow?.isMounted()) return false
|
|
5219
5318
|
const seen = readSeenAnnouncements()
|
|
5220
5319
|
const items = normalized.filter(item => !seen[item.id])
|
|
5221
5320
|
.sort((a, b) => b.publishedAt - a.publishedAt)
|
|
5222
|
-
|
|
5321
|
+
// 新旧界面均提示未读公告;拉取期间新出现的版本提醒仍优先展示。
|
|
5322
|
+
if (!items.length || state.announcement || isAppVersionWarningOpen()) return false
|
|
5223
5323
|
openAnnouncementModal(items)
|
|
5224
5324
|
return true
|
|
5225
5325
|
} catch { return false }
|
|
@@ -5407,6 +5507,7 @@ function finishUpdateDownload() {
|
|
|
5407
5507
|
clearInterval(updateDownloadTimer)
|
|
5408
5508
|
updateDownloadTimer = null
|
|
5409
5509
|
$('btn-download-update').disabled = false
|
|
5510
|
+
const forceButton=$('btn-force-download-update');if(forceButton)forceButton.disabled=false
|
|
5410
5511
|
}
|
|
5411
5512
|
|
|
5412
5513
|
async function verifyUpdateApk(info, url) {
|
|
@@ -5417,7 +5518,7 @@ async function verifyUpdateApk(info, url) {
|
|
|
5417
5518
|
const resetTimeout = () => { clearTimeout(timer); timer = setTimeout(() => controller.abort(), 60000) }
|
|
5418
5519
|
try {
|
|
5419
5520
|
resetTimeout()
|
|
5420
|
-
const res = await fetch(url, { signal: controller.signal })
|
|
5521
|
+
const res = await fetch(url, { signal: controller.signal, cache: 'no-store' })
|
|
5421
5522
|
if (!res.ok) return { ok: false, status: res.status }
|
|
5422
5523
|
total = Number(res.headers.get('content-length')) || 0
|
|
5423
5524
|
const chunks = []
|
|
@@ -5448,23 +5549,36 @@ async function verifyUpdateApk(info, url) {
|
|
|
5448
5549
|
finally { clearTimeout(timer); clearInterval(progressTimer) }
|
|
5449
5550
|
}
|
|
5450
5551
|
|
|
5451
|
-
async function downloadUpdate() {
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
const
|
|
5456
|
-
if (!/^[0-9a-f]{64}$/.test(sha256)) {
|
|
5457
|
-
// 无 SHA-256 的更新包一律不下载、不安装
|
|
5458
|
-
updateDownloadProgress({ phase: 'error', error: t('update.hashMissing') })
|
|
5459
|
-
return
|
|
5460
|
-
}
|
|
5552
|
+
async function downloadUpdate(force = false) {
|
|
5553
|
+
if (updateDownloadBusy || (force !== true && !state.updateInfo)) return
|
|
5554
|
+
const base=updateBase()
|
|
5555
|
+
if(!base){toast(t('update.needServer'),'err');return}
|
|
5556
|
+
const connection=captureConnection()
|
|
5461
5557
|
updateDownloadBusy = true
|
|
5462
5558
|
updateDownloadSample = null
|
|
5463
5559
|
$('btn-download-update').disabled = true
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5560
|
+
const forceButton=$('btn-force-download-update');if(forceButton)forceButton.disabled=true
|
|
5561
|
+
let nativePending=false
|
|
5562
|
+
try {
|
|
5563
|
+
let info=state.updateInfo
|
|
5564
|
+
if(force===true){
|
|
5565
|
+
updateDownloadProgress({phase:'checking',received:0,total:0})
|
|
5566
|
+
// Same-version patches deliberately bypass only version comparison. Both
|
|
5567
|
+
// metadata and APK bytes are fetched afresh; hash verification still applies.
|
|
5568
|
+
const response=await fetch(base+'/update.json?t='+Date.now()+'&local='+encodeURIComponent(state.localVersion||''),{cache:'no-store',signal:AbortSignal.timeout(15000)})
|
|
5569
|
+
if(!response.ok)throw new Error('HTTP '+response.status)
|
|
5570
|
+
info=await response.json()
|
|
5571
|
+
}
|
|
5572
|
+
if(!connection.valid())return
|
|
5573
|
+
const sha256=String(info?.sha256||'').trim().toLowerCase()
|
|
5574
|
+
if(!/^[0-9a-f]{64}$/.test(sha256))throw new Error(t('update.hashMissing'))
|
|
5575
|
+
const target=new URL(info.apkUrl||'dsh-remote.apk',base+'/')
|
|
5576
|
+
if(force===true)target.searchParams.set('dshPatch',Date.now().toString(36)+'-'+sha256.slice(0,16))
|
|
5577
|
+
const url=target.href
|
|
5578
|
+
updateDownloadProgress({ phase: 'downloading', received: 0, total: 0 })
|
|
5579
|
+
if (CAP?.isNativePlatform?.() && window.NativeUpdate?.downloadVerifiedAndInstall && window.NativeUpdate?.getDownloadStatus) {
|
|
5467
5580
|
if (!window.NativeUpdate.downloadVerifiedAndInstall(url, sha256)) throw new Error(t('update.busy'))
|
|
5581
|
+
nativePending=true
|
|
5468
5582
|
const poll = () => {
|
|
5469
5583
|
try {
|
|
5470
5584
|
const value = JSON.parse(window.NativeUpdate.getDownloadStatus())
|
|
@@ -5474,12 +5588,11 @@ async function downloadUpdate() {
|
|
|
5474
5588
|
}
|
|
5475
5589
|
updateDownloadTimer = setInterval(poll, 500)
|
|
5476
5590
|
poll()
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
}
|
|
5480
|
-
try {
|
|
5591
|
+
return
|
|
5592
|
+
}
|
|
5481
5593
|
const result = await verifyUpdateApk(info, url)
|
|
5482
|
-
if
|
|
5594
|
+
if(!connection.valid())return
|
|
5595
|
+
if (!result.ok) throw new Error(result.corrupted ? t(force===true?'update.patchMismatch':'update.corrupted') : result.status ? t('update.serverFileMissing') : result.msg || t('fs.networkError'))
|
|
5483
5596
|
{
|
|
5484
5597
|
// 无校验的原生安装入口已移除: 新旧壳统一走下方"下载并本地校验"路径。
|
|
5485
5598
|
const objectUrl = URL.createObjectURL(result.blob)
|
|
@@ -5492,8 +5605,8 @@ async function downloadUpdate() {
|
|
|
5492
5605
|
setTimeout(() => URL.revokeObjectURL(objectUrl), 60000)
|
|
5493
5606
|
updateDownloadProgress({ phase: 'complete', received: result.blob.size, total: result.blob.size })
|
|
5494
5607
|
}
|
|
5495
|
-
} catch (error) { updateDownloadProgress({ phase: 'error', error: error.message }) }
|
|
5496
|
-
finally { finishUpdateDownload() }
|
|
5608
|
+
} catch (error) { if(connection.valid())updateDownloadProgress({ phase: 'error', error: error.message }) }
|
|
5609
|
+
finally { if(!nativePending)finishUpdateDownload() }
|
|
5497
5610
|
}
|
|
5498
5611
|
|
|
5499
5612
|
|
|
@@ -5719,8 +5832,7 @@ function deletePreset(id) {
|
|
|
5719
5832
|
toast(t('presets.deleted'), 'ok')
|
|
5720
5833
|
}
|
|
5721
5834
|
|
|
5722
|
-
/* ----------------
|
|
5723
|
-
function peakRemindOn() { return LS.get('peakRemind', '0') === '1' }
|
|
5835
|
+
/* ---------------- 旧峰谷提醒清理(现由 dsh-cost-meter 管理) ---------------- */
|
|
5724
5836
|
const LEGACY_PEAK_NOTIFICATION_IDS = [8801, 8802, 8803, 8804]
|
|
5725
5837
|
|
|
5726
5838
|
async function cancelLegacyPeakNotifications() {
|
|
@@ -5736,32 +5848,21 @@ async function cancelLegacyPeakNotifications() {
|
|
|
5736
5848
|
}
|
|
5737
5849
|
}
|
|
5738
5850
|
|
|
5739
|
-
async function schedulePeakReminders({ legacyCleaned = false } = {}) {
|
|
5740
|
-
if (!CAP?.isNativePlatform?.()) return false
|
|
5741
|
-
if (!legacyCleaned && !await cancelLegacyPeakNotifications()) return false
|
|
5742
|
-
const b = bgBridge()
|
|
5743
|
-
if (!b?.startPeakReminder) return false
|
|
5744
|
-
try {
|
|
5745
|
-
return b.startPeakReminder() !== false
|
|
5746
|
-
} catch { return false }
|
|
5747
|
-
}
|
|
5748
|
-
|
|
5749
5851
|
async function cancelPeakReminders() {
|
|
5750
5852
|
if (!CAP?.isNativePlatform?.()) return false
|
|
5853
|
+
const legacyCleaned = await cancelLegacyPeakNotifications()
|
|
5751
5854
|
const b = bgBridge()
|
|
5752
5855
|
if (!b?.stopPeakReminder) return false
|
|
5753
5856
|
try {
|
|
5754
5857
|
const stopped = b.stopPeakReminder() !== false
|
|
5755
|
-
const legacyCleaned = await cancelLegacyPeakNotifications()
|
|
5756
5858
|
return stopped && legacyCleaned
|
|
5757
5859
|
} catch { return false }
|
|
5758
5860
|
}
|
|
5759
5861
|
|
|
5760
5862
|
async function restorePeakReminders() {
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
if (peakRemindOn() && legacyCleaned) await schedulePeakReminders({ legacyCleaned: true })
|
|
5863
|
+
// dsh-cost-meter owns reminders. Retire both legacy scheduling mechanisms.
|
|
5864
|
+
LS.del('peakRemind')
|
|
5865
|
+
await cancelPeakReminders()
|
|
5765
5866
|
}
|
|
5766
5867
|
|
|
5767
5868
|
/* ---------------- 模型设置 ---------------- */
|
|
@@ -6317,6 +6418,8 @@ async function openModelConfigDocument() {
|
|
|
6317
6418
|
}
|
|
6318
6419
|
/* ---------------- 视图切换 ---------------- */
|
|
6319
6420
|
function showView(id) {
|
|
6421
|
+
if (id !== 'view-session') window.DshSubagents?.close()
|
|
6422
|
+
document.body?.classList.toggle('viewing-subagent', id === 'view-session' && state.byId.get(state.current)?.origin === 'subagent')
|
|
6320
6423
|
window.DshWorkflow?.close()
|
|
6321
6424
|
if (window.DshWorkflow?.isMounted() && id === 'view-activity') id = 'view-home'
|
|
6322
6425
|
if (id !== 'view-session') conversationView?.pause()
|
|
@@ -7468,7 +7571,8 @@ function bindUi() {
|
|
|
7468
7571
|
$('btn-dsh-start')?.addEventListener('click', () => controlDsh('start'))
|
|
7469
7572
|
$('btn-dsh-restart')?.addEventListener('click', () => controlDsh('restart'))
|
|
7470
7573
|
$('btn-check-update').addEventListener('click', () => checkUpdate(false))
|
|
7471
|
-
$('btn-download-update').addEventListener('click', downloadUpdate)
|
|
7574
|
+
$('btn-download-update').addEventListener('click', () => void downloadUpdate())
|
|
7575
|
+
$('btn-force-download-update').addEventListener('click', () => void downloadUpdate(true))
|
|
7472
7576
|
$('btn-update-expand').addEventListener('click', toggleUpdateExpand)
|
|
7473
7577
|
$('app-version-later').addEventListener('click', () => closeAppVersionWarning(false))
|
|
7474
7578
|
$('app-version-update').addEventListener('click', () => closeAppVersionWarning(true))
|
|
@@ -7511,34 +7615,9 @@ function bindUi() {
|
|
|
7511
7615
|
LS.set('notify', e.target.checked ? '1' : '0')
|
|
7512
7616
|
window.NativeBackground?.setPendingNotificationsEnabled?.(e.target.checked)
|
|
7513
7617
|
})
|
|
7514
|
-
$('opt-peak-remind').checked = peakRemindOn()
|
|
7515
|
-
$('opt-peak-remind').addEventListener('change', async (e) => {
|
|
7516
|
-
if (e.target.checked) {
|
|
7517
|
-
if (!CAP?.isNativePlatform?.()) {
|
|
7518
|
-
e.target.checked = false
|
|
7519
|
-
return toast(t('peakRemind.browserOnly'), 'err')
|
|
7520
|
-
}
|
|
7521
|
-
const ok = await ensureNotify()
|
|
7522
|
-
if (!ok) { e.target.checked = false; return toast(t('settings.notifyDenied')) }
|
|
7523
|
-
const started = await schedulePeakReminders()
|
|
7524
|
-
if (!started) {
|
|
7525
|
-
e.target.checked = false
|
|
7526
|
-
return toast(t('peakRemind.failed'), 'err')
|
|
7527
|
-
}
|
|
7528
|
-
toast(t('peakRemind.on'), 'ok')
|
|
7529
|
-
} else {
|
|
7530
|
-
const stopped = await cancelPeakReminders()
|
|
7531
|
-
if (!stopped) {
|
|
7532
|
-
e.target.checked = true
|
|
7533
|
-
return toast(t('peakRemind.failed'), 'err')
|
|
7534
|
-
}
|
|
7535
|
-
toast(t('peakRemind.off'), 'ok')
|
|
7536
|
-
}
|
|
7537
|
-
LS.set('peakRemind', e.target.checked ? '1' : '0')
|
|
7538
|
-
})
|
|
7539
7618
|
$('btn-test-notify').addEventListener('click', sendTestNotification)
|
|
7540
7619
|
$('btn-announcement-history').addEventListener('click', openAnnouncementHistory)
|
|
7541
|
-
//
|
|
7620
|
+
// 启动时清理旧版 LocalNotifications 和前台提醒服务,提醒交给 dsh-cost-meter。
|
|
7542
7621
|
restorePeakReminders()
|
|
7543
7622
|
applyBgConfigFromNative()
|
|
7544
7623
|
$('opt-bg-poll').addEventListener('change', async (e) => {
|
|
@@ -7591,6 +7670,7 @@ function bindUi() {
|
|
|
7591
7670
|
bindFsPullRefresh()
|
|
7592
7671
|
|
|
7593
7672
|
bindRail()
|
|
7673
|
+
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest })
|
|
7594
7674
|
|
|
7595
7675
|
for (const id of ['history', 'question-body']) window.DshChatFiles?.bind($(id), () => {
|
|
7596
7676
|
const c=captureConnection(),sessionId=id==='history'?state.current:state.questionModal?.sessionId
|
|
@@ -7677,6 +7757,7 @@ function mountWorkflow() {
|
|
|
7677
7757
|
},
|
|
7678
7758
|
command: runSlashCommand, refresh: refreshAll, retry: () => { startOverviewDetection(true); void refreshAll() },
|
|
7679
7759
|
operations: () => { const connection=captureConnection(); return { url:apiUrl,headers:{authorization:'Bearer '+connection.token},valid:connection.valid } },
|
|
7760
|
+
relay: () => { const connection=captureConnection(); return { url:()=>adminApiUrl('/admin/api/relay'),headers:{authorization:'Bearer '+connection.token},valid:connection.valid,connected:!!connection.token } },
|
|
7680
7761
|
discover: () => { if (confirm('登记当前绑定目录下的子目录为工作区?')) void refreshWorkbench({ discover: true }) },
|
|
7681
7762
|
files: () => {
|
|
7682
7763
|
const workspace = workspaceForSession(state.byId.get(state.current))
|
|
@@ -7687,7 +7768,7 @@ function mountWorkflow() {
|
|
|
7687
7768
|
},
|
|
7688
7769
|
clear: clearWorkflowData,
|
|
7689
7770
|
admin: () => {
|
|
7690
|
-
const url = new URL(
|
|
7771
|
+
const url = new URL(adminApiUrl('/admin/'), location.href)
|
|
7691
7772
|
// Open authenticated management through its own login flow. No credential
|
|
7692
7773
|
// in a newly created URL, browser history, or referrer.
|
|
7693
7774
|
window.open(url.href, '_blank', 'noopener,noreferrer')
|
|
@@ -7737,6 +7818,7 @@ function openPluginPage(route = 'manage') {
|
|
|
7737
7818
|
}
|
|
7738
7819
|
window.DshExtensions.mount({
|
|
7739
7820
|
connection, getSession: () => state.byId.get(state.current), getTitle: () => sessionTitleValue(state.byId.get(state.current)),
|
|
7821
|
+
back: () => showView('view-settings'),
|
|
7740
7822
|
openContext: () => void openInsights('context', true),
|
|
7741
7823
|
returnToSession: () => showView('view-session'), scrollTop: () => window.scrollTo(0,0),
|
|
7742
7824
|
url: path => connection.server + path,
|