dsh-remote-plugin 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +29 -48
- package/README.md +29 -48
- package/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +3 -1
- package/index.mjs +28 -0
- package/package.json +4 -2
- package/plugin-center.mjs +126 -26
- package/public/app.js +89 -26
- package/public/chat-files.js +17 -0
- package/public/desktop/desktop.css +5 -0
- package/public/desktop/desktop.html +9 -0
- package/public/desktop/desktop.js +82 -24
- package/public/extensions.css +1 -0
- package/public/extensions.js +103 -0
- package/public/history.js +31 -10
- package/public/index.html +10 -1
- package/public/insights.css +2 -0
- package/public/insights.js +50 -23
- package/public/md.js +13 -12
- package/public/plugin-center.css +7 -3
- package/public/plugin-center.js +76 -18
- package/public/skills.css +81 -0
- package/public/skills.js +191 -0
- package/public/styles.css +7 -0
- package/public/theme-vars.css +5 -0
- package/public/update.json +8 -8
- package/public/version.json +1 -1
- package/session-file.mjs +34 -0
- package/skills.mjs +53 -0
package/public/app.js
CHANGED
|
@@ -75,6 +75,7 @@ const state = {
|
|
|
75
75
|
questions: [], // 待处理提问
|
|
76
76
|
queues: {}, // sessionId -> queue items
|
|
77
77
|
queueSteering: {}, // sessionId:itemId -> pending steer request
|
|
78
|
+
compactionBootAt: Date.now(),
|
|
78
79
|
compactions: {}, // sessionId -> {active, phase, startedAt, message, source}
|
|
79
80
|
pendingCommands: {}, // sessionId -> command name; waits briefly before showing generic progress
|
|
80
81
|
compactionPollTimer: null,
|
|
@@ -124,12 +125,15 @@ for (const key of ['server', 'token']) {
|
|
|
124
125
|
state.modelSettings = { status: 'idle', error: '', writable: false, hasDocument: false, providers: [], namespaces: [], credentials: {} }; state.modelEditor = null
|
|
125
126
|
state.goalEdit = null; state.goalEditContext = null
|
|
126
127
|
state.approvals = []; state.questions = []; state.questionModal = null
|
|
127
|
-
state.queues = {}; state.jobs = {}; state.queueSteering = {}; state.compactions = {}; state.pendingCommands = {}; state.sessionTurnTimes = {}
|
|
128
|
+
state.queues = {}; state.jobs = {}; state.queueSteering = {}; state.compactions = {}; state.compactionTerminals = {}; state.compactionSeqs = {}; state.compactionBootAt = Date.now(); state.pendingCommands = {}; state.sessionTurnTimes = {}
|
|
128
129
|
state.sessionActivity = new Set(); state.pendingPrompts = new Set()
|
|
129
130
|
state.fs.path = null; state.fs.initial = null; state.fs.loaded = false; state.fs.roots = []; state.fs.rootIndex = 0
|
|
130
131
|
state.wb = null; state.wbProjects = []; state.wbArchived = []; state.workspaceFilter = ''; state.fs.workspaceId = ''; clearTimeout(scheduleHistoryCacheSave._t)
|
|
131
132
|
window.DshPluginCenter?.close()
|
|
132
133
|
window.DshInsights?.close()
|
|
134
|
+
window.DshExtensions?.close()
|
|
135
|
+
window.DshExtensions?.invalidateCapabilities()
|
|
136
|
+
if (typeof document !== 'undefined') document.getElementById('btn-insights')?.classList.add('hidden')
|
|
133
137
|
if(typeof document!=='undefined') {
|
|
134
138
|
const identityGeneration=connectionGeneration
|
|
135
139
|
queueMicrotask(()=>{if(identityGeneration===connectionGeneration&&typeof startOverviewDetection==='function')startOverviewDetection(true,true)})
|
|
@@ -1495,7 +1499,7 @@ function onMuxFrame(full) {
|
|
|
1495
1499
|
if (f.sessionId === state.current) { applyReasoningBaseline(f.partialReasoning); scheduleReasoningRender() }
|
|
1496
1500
|
return
|
|
1497
1501
|
}
|
|
1498
|
-
if (f.type === 'session/event') return onSessionEvent(f.sessionId, f.event)
|
|
1502
|
+
if (f.type === 'session/event') return onSessionEvent(f.sessionId, f.event, { replay: f.replay === true })
|
|
1499
1503
|
if (f.type === 'session/subscribed') return
|
|
1500
1504
|
if (f.type === 'approval/requested') {
|
|
1501
1505
|
state.approvals = state.approvals.filter(a => a.approvalId !== f.approvalId)
|
|
@@ -1552,6 +1556,7 @@ function compactElapsed(startedAt) {
|
|
|
1552
1556
|
}
|
|
1553
1557
|
|
|
1554
1558
|
function setCompactionStatus(sessionId, next) {
|
|
1559
|
+
state.compactionTerminals ||= {}
|
|
1555
1560
|
if (!sessionId) return
|
|
1556
1561
|
const previous = state.compactions[sessionId]
|
|
1557
1562
|
const active = next?.active === true
|
|
@@ -1563,10 +1568,15 @@ function setCompactionStatus(sessionId, next) {
|
|
|
1563
1568
|
startedAt: Number(next.startedAt) || previous?.startedAt || Date.now(),
|
|
1564
1569
|
message: String(next.message || ''),
|
|
1565
1570
|
source: next.source || previous?.source || 'event',
|
|
1571
|
+
compactionId: next.compactionId || previous?.compactionId || '',
|
|
1572
|
+
notify: next.notify ?? previous?.notify ?? (next.source === 'command'),
|
|
1566
1573
|
}
|
|
1567
1574
|
} else {
|
|
1568
1575
|
delete state.compactions[sessionId]
|
|
1569
1576
|
if (previous?.active) {
|
|
1577
|
+
state.compactionTerminals[sessionId] = { startedAt: previous.startedAt, compactionId: previous.compactionId }
|
|
1578
|
+
}
|
|
1579
|
+
if (previous?.active && previous.notify && next?.notify !== false && ['complete', 'failed'].includes(next?.phase)) {
|
|
1570
1580
|
const command = previous.command || 'compact'
|
|
1571
1581
|
if (next?.phase === 'failed') toast(command === 'compact'
|
|
1572
1582
|
? t('session.compactFailed', { msg: next.message || t('send.failed') })
|
|
@@ -1580,18 +1590,25 @@ function setCompactionStatus(sessionId, next) {
|
|
|
1580
1590
|
|
|
1581
1591
|
async function refreshCompactionStatus(sessionId = state.current) {
|
|
1582
1592
|
if (!sessionId) return
|
|
1593
|
+
const connection = captureConnection()
|
|
1583
1594
|
try {
|
|
1584
1595
|
const signal = typeof AbortSignal?.timeout === 'function' ? AbortSignal.timeout(8000) : undefined
|
|
1585
|
-
const url = new URL(
|
|
1596
|
+
const url = new URL(connection.server + '/remote/api/command-status', location.href)
|
|
1586
1597
|
url.searchParams.set('sessionId', sessionId)
|
|
1587
|
-
const res = await fetch(url, { headers: { authorization: 'Bearer ' +
|
|
1598
|
+
const res = await fetch(url, { headers: { authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': CAP?.isNativePlatform?.() ? 'app' : 'web', ...clientIdHeaders() }, ...(signal ? { signal } : {}) })
|
|
1599
|
+
if (!connection.valid()) return
|
|
1588
1600
|
if (res.status === 401) { authFailure(); return }
|
|
1589
1601
|
if (!res.ok) return
|
|
1602
|
+
if (!connection.valid()) return
|
|
1590
1603
|
const body = await res.json().catch(() => null)
|
|
1604
|
+
if (!connection.valid()) return
|
|
1591
1605
|
const operation = body?.operation || body?.compact
|
|
1592
1606
|
if (!operation) return
|
|
1607
|
+
if (operation.startedAt && activeCompaction(sessionId)?.startedAt > Number(operation.startedAt)) return
|
|
1593
1608
|
const pending = state.pendingCommands[sessionId]
|
|
1594
|
-
if (operation.active) {
|
|
1609
|
+
if (operation.active === true) {
|
|
1610
|
+
const terminal = state.compactionTerminals?.[sessionId]
|
|
1611
|
+
if (terminal && Number(operation.startedAt) <= terminal.startedAt) return
|
|
1595
1612
|
delete state.pendingCommands[sessionId]
|
|
1596
1613
|
setCompactionStatus(sessionId, { ...operation, source: 'status' })
|
|
1597
1614
|
} else if (activeCompaction(sessionId) && activeCompaction(sessionId).source !== 'event') {
|
|
@@ -1625,18 +1642,29 @@ function ensureCompactionMonitoring() {
|
|
|
1625
1642
|
}
|
|
1626
1643
|
}
|
|
1627
1644
|
|
|
1628
|
-
function observeCompactionEvent(sessionId, event) {
|
|
1629
|
-
if (event
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1645
|
+
function observeCompactionEvent(sessionId, event, meta = {}) {
|
|
1646
|
+
if (!event || !sessionId || !['compaction/start','compaction/end','session/end-seed'].includes(event.type)) return
|
|
1647
|
+
state.compactionSeqs ||= {}; state.compactionBootAt ||= Date.now()
|
|
1648
|
+
const seq = Number(event.seq), previous = activeCompaction(sessionId)
|
|
1649
|
+
if (seq > 0 && seq <= (state.compactionSeqs[sessionId] || 0)) return
|
|
1650
|
+
const id = event.data?.compactionId || ''
|
|
1651
|
+
if (event.type === 'compaction/end' && previous?.compactionId && previous.compactionId !== id) return
|
|
1652
|
+
if (seq > 0) state.compactionSeqs[sessionId] = seq
|
|
1653
|
+
const time = typeof event.time === 'number' ? event.time : Date.parse(event.time)
|
|
1654
|
+
if (event.type === 'compaction/start') {
|
|
1655
|
+
setCompactionStatus(sessionId, { active: true, phase: 'running', compactionId: id,
|
|
1656
|
+
startedAt: previous?.startedAt || (Number.isFinite(time) ? time : Date.now()), source: previous?.source || 'event',
|
|
1657
|
+
notify: meta.replay ? false : previous?.notify || Number.isFinite(time) && time >= state.compactionBootAt })
|
|
1658
|
+
} else {
|
|
1659
|
+
setCompactionStatus(sessionId, { active: false, phase: event.type === 'session/end-seed' ? 'interrupted' : event.data?.error ? 'failed' : 'complete',
|
|
1660
|
+
message: event.data?.error || '', ...(meta.replay || event.type === 'session/end-seed' ? { notify: false } : {}) })
|
|
1633
1661
|
}
|
|
1634
1662
|
}
|
|
1635
1663
|
|
|
1636
|
-
function onSessionEvent(sessionId, event) {
|
|
1664
|
+
function onSessionEvent(sessionId, event, meta = {}) {
|
|
1637
1665
|
if (!event) return
|
|
1638
1666
|
const s = state.byId.get(sessionId)
|
|
1639
|
-
observeCompactionEvent(sessionId, event)
|
|
1667
|
+
observeCompactionEvent(sessionId, event, meta)
|
|
1640
1668
|
if (event.type === 'turn/start' || event.type === 'turn/end') {
|
|
1641
1669
|
noteSessionTurnTime(sessionId, event)
|
|
1642
1670
|
renderSessions()
|
|
@@ -1707,9 +1735,37 @@ function removeLocalSessionRecord(sessionId) {
|
|
|
1707
1735
|
}
|
|
1708
1736
|
|
|
1709
1737
|
function proj(s, key, d) { return s?.projections?.values?.[key] ?? d }
|
|
1710
|
-
function
|
|
1711
|
-
|
|
1712
|
-
|
|
1738
|
+
function optionalPluginConfig(connection = captureConnection()) {
|
|
1739
|
+
return { connection, valid: connection.valid, url: path => connection.server + path,
|
|
1740
|
+
headers: { authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': CAP?.isNativePlatform?.() ? 'app' : 'web', ...clientIdHeaders() } }
|
|
1741
|
+
}
|
|
1742
|
+
function availableInsightTabs(capabilities, session) {
|
|
1743
|
+
const context = capabilities.context
|
|
1744
|
+
return [...(context ? ['context'] : []), ...(capabilities.cost ? ['cost'] : [])]
|
|
1745
|
+
}
|
|
1746
|
+
async function refreshInsightEntry() {
|
|
1747
|
+
const control = $('btn-insights'), id = state.current, connection = captureConnection()
|
|
1748
|
+
if (!control || !id || !connection.token || !window.DshExtensions) { control?.classList.add('hidden'); return }
|
|
1749
|
+
const capabilities = await window.DshExtensions.getCapabilities(optionalPluginConfig(connection))
|
|
1750
|
+
if (!connection.valid() || state.current !== id) return
|
|
1751
|
+
const tabs = availableInsightTabs(capabilities, state.byId.get(id))
|
|
1752
|
+
control.classList.toggle('hidden', !tabs.length)
|
|
1753
|
+
const label = t(tabs.length === 2 ? 'insights.title' : tabs[0] === 'cost' ? 'insights.costTitle' : 'insights.contextTitle')
|
|
1754
|
+
control.textContent = label; control.title = label; control.setAttribute('aria-label', label)
|
|
1755
|
+
}
|
|
1756
|
+
async function openInsights(tab = 'context', fullPage = false) {
|
|
1757
|
+
const connection = captureConnection(), id = state.current
|
|
1758
|
+
const capabilities = await window.DshExtensions.getCapabilities(optionalPluginConfig(connection))
|
|
1759
|
+
if (!connection.valid() || state.current !== id || !id) return
|
|
1760
|
+
const allowedTabs = availableInsightTabs(capabilities, state.byId.get(id))
|
|
1761
|
+
if (!allowedTabs.length) { void refreshInsightEntry(); return }
|
|
1762
|
+
window.DshInsights?.close()
|
|
1763
|
+
const view = fullPage ? getConversationView() : null, wasPaused = view?.paused
|
|
1764
|
+
view?.pause()
|
|
1765
|
+
window.DshInsights?.open({ tab, fullPage, allowedTabs, connection, url: path => connection.server + path,
|
|
1766
|
+
getSession: () => state.byId.get(state.current), getTitle: () => sessionTitleValue(state.byId.get(state.current)),
|
|
1767
|
+
onFullPage: selected => void openInsights(selected, true),
|
|
1768
|
+
onClose: () => { if (view && !wasPaused && connection.valid() && state.current === id) view.resume() } })
|
|
1713
1769
|
}
|
|
1714
1770
|
function hydrateSessionProjections(sessionId, projections) {
|
|
1715
1771
|
const s = state.byId.get(sessionId)
|
|
@@ -2472,9 +2528,7 @@ function scheduleReasoningRender() {
|
|
|
2472
2528
|
reasoningRenderTimer = setTimeout(() => {
|
|
2473
2529
|
reasoningRenderTimer = null
|
|
2474
2530
|
if (!state.current) return
|
|
2475
|
-
|
|
2476
|
-
const nearBottom = box.scrollHeight - box.scrollTop - box.clientHeight < 240
|
|
2477
|
-
renderHistory(false, nearBottom ? 'bottom' : 'fixed')
|
|
2531
|
+
renderHistory(false, 'fixed')
|
|
2478
2532
|
}, 80)
|
|
2479
2533
|
}
|
|
2480
2534
|
|
|
@@ -2503,7 +2557,7 @@ function getConversationView() {
|
|
|
2503
2557
|
if(!conversationView)conversationView=new window.DshHistory.HistoryView($('history'),{
|
|
2504
2558
|
html:entry=>eventHtml(entry, {toolNames:state.history.toolNames}),
|
|
2505
2559
|
older:()=>loadHistory(false),olderLabel:()=>t('history.earlier'),loadingLabel:()=>t('history.loadingEarlier'),live:partialReasoningHtml,
|
|
2506
|
-
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end;$('btn-history-latest')?.classList.toggle('hidden',!view.reading&&view.end>=view.entries.length&&!state.history.tailEvicted);updateRail(view.domChanged)},
|
|
2560
|
+
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end;$('btn-history-latest')?.classList.toggle('hidden',!view.reading&&view.end>=view.entries.length&&!state.history.tailEvicted);const latest=$('btn-history-latest');if(latest)latest.textContent=t('history.latest')+(view.unread?' ('+view.unread+')':view.hasPending?' · '+(I18N.lang==='en'?'New content':'有新内容'):'');updateRail(view.domChanged)},
|
|
2507
2561
|
scrolled:()=>{updateRail()}
|
|
2508
2562
|
})
|
|
2509
2563
|
return conversationView
|
|
@@ -2756,8 +2810,8 @@ function blockHtml(b) {
|
|
|
2756
2810
|
if (!b || typeof b !== 'object') return `<p>${esc(String(b))}</p>`
|
|
2757
2811
|
if ((b.type === 'tool-call' || b.type === 'tool-result') && LS.get('showTools', '1') === '0') return ''
|
|
2758
2812
|
switch (b.type) {
|
|
2759
|
-
case 'text': return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '') : esc(b.text ?? '')}</div>`
|
|
2760
|
-
case 'file': return `<div class="tool">📎 ${esc(b.attachment?.name || b.name || 'file')} <small>${esc(b.attachment?.bytes ?? b.bytes ?? '')} bytes</small></div>`
|
|
2813
|
+
case 'text': return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true }) : esc(b.text ?? '')}</div>`
|
|
2814
|
+
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>`
|
|
2761
2815
|
case 'image': return `<img alt="${t('block.image')}" src="data:${esc(b.mediaType || 'image/png')};base64,${esc(b.data || '')}">`
|
|
2762
2816
|
case 'thinking':
|
|
2763
2817
|
case 'reasoning':
|
|
@@ -2812,6 +2866,7 @@ let sessionCardsRenderGeneration = 0
|
|
|
2812
2866
|
async function renderSessionCards() {
|
|
2813
2867
|
const connection = captureConnection()
|
|
2814
2868
|
window.DshInsights?.update()
|
|
2869
|
+
void refreshInsightEntry()
|
|
2815
2870
|
const renderGeneration = ++sessionCardsRenderGeneration
|
|
2816
2871
|
const sessionId = state.current
|
|
2817
2872
|
const s = state.byId.get(sessionId)
|
|
@@ -4121,7 +4176,6 @@ async function createWorkspace() {
|
|
|
4121
4176
|
button.disabled = true
|
|
4122
4177
|
try {
|
|
4123
4178
|
const res = await fetch(fsApiUrl('/mkdir', { path: parent, name }), { method: 'POST', headers: fsHeaders() })
|
|
4124
|
-
if (!connection.valid()) return
|
|
4125
4179
|
if (res.status === 401) { fsAuthError(401); return }
|
|
4126
4180
|
const data = await res.json().catch(() => ({}))
|
|
4127
4181
|
if (!connection.valid()) return
|
|
@@ -6156,10 +6210,12 @@ async function openModelConfigDocument() {
|
|
|
6156
6210
|
}
|
|
6157
6211
|
/* ---------------- 视图切换 ---------------- */
|
|
6158
6212
|
function showView(id) {
|
|
6213
|
+
if (id !== 'view-session') conversationView?.pause()
|
|
6159
6214
|
if (id !== 'view-session' && document.body.classList.contains('in-session') && state.current) void archiveEmptySessionOnLeave(state.current)
|
|
6160
6215
|
for (const v of ['view-home', 'view-files', 'view-session', 'view-activity', 'view-plugins', 'view-settings']) $(v).classList.toggle('hidden', v !== id)
|
|
6161
6216
|
// 离开会话页必须清掉 in-session, 否则其他页面顶栏被 body 样式隐藏
|
|
6162
6217
|
document.body.classList.toggle('in-session', id === 'view-session')
|
|
6218
|
+
if (id === 'view-session') conversationView?.resume()
|
|
6163
6219
|
$('session-actions')?.close()
|
|
6164
6220
|
$('session-info')?.close()
|
|
6165
6221
|
document.querySelectorAll('.nav-btn').forEach(b => b.classList.toggle('active', b.dataset.view === id))
|
|
@@ -6172,7 +6228,7 @@ function showView(id) {
|
|
|
6172
6228
|
loadFs(workspace?.path || null, { silent: true, resetRoot: true })
|
|
6173
6229
|
}
|
|
6174
6230
|
if (id === 'view-plugins') openPluginPage()
|
|
6175
|
-
else window.
|
|
6231
|
+
else window.DshExtensions?.close()
|
|
6176
6232
|
if (id === 'view-settings') showSettingsHome()
|
|
6177
6233
|
if(id==='view-activity')startOverviewDetection(true);else {overviewDetector?.pause();overviewPulse?.pause()}
|
|
6178
6234
|
}
|
|
@@ -7419,6 +7475,7 @@ function bindUi() {
|
|
|
7419
7475
|
|
|
7420
7476
|
bindRail()
|
|
7421
7477
|
|
|
7478
|
+
window.DshChatFiles?.bind($('history'), () => { const c=captureConnection(); return { ...c,sessionId:state.current,cwd:sessionCwd(state.byId.get(state.current)),native:!!CAP?.isNativePlatform?.(),headers:{authorization:'Bearer '+c.token,...clientIdHeaders()},notice:toast } })
|
|
7422
7479
|
initCustomSelects()
|
|
7423
7480
|
|
|
7424
7481
|
$('btn-history-latest').addEventListener('click',()=>{getConversationView().latest();if(state.history.tailEvicted)void loadHistory(true)})
|
|
@@ -7431,11 +7488,14 @@ function applyNativeInsets() {
|
|
|
7431
7488
|
const raw = window.NativeUpdate?.getInsets?.()
|
|
7432
7489
|
if (!raw) return
|
|
7433
7490
|
const ins = JSON.parse(raw)
|
|
7491
|
+
if (ins.mode === 'overlap') document.documentElement.dataset.nativeInsets = 'overlap'
|
|
7434
7492
|
document.documentElement.style.setProperty('--native-top', (ins.top || 0) + 'px')
|
|
7435
7493
|
document.documentElement.style.setProperty('--native-bottom', (ins.bottom || 0) + 'px')
|
|
7436
7494
|
} catch {}
|
|
7437
7495
|
}
|
|
7438
7496
|
|
|
7497
|
+
window.addEventListener('dsh-native-insets', applyNativeInsets)
|
|
7498
|
+
|
|
7439
7499
|
async function boot() {
|
|
7440
7500
|
initToken()
|
|
7441
7501
|
bindUi()
|
|
@@ -7469,15 +7529,18 @@ async function boot() {
|
|
|
7469
7529
|
|
|
7470
7530
|
document.addEventListener('DOMContentLoaded', boot)
|
|
7471
7531
|
|
|
7472
|
-
function openPluginPage() {
|
|
7532
|
+
function openPluginPage(route = 'manage') {
|
|
7473
7533
|
const connection = captureConnection()
|
|
7474
7534
|
if (!connection.token) {
|
|
7475
7535
|
$('plugin-page').textContent = '请先在设置中连接 DSH 主机。'
|
|
7476
7536
|
return
|
|
7477
7537
|
}
|
|
7478
|
-
window.
|
|
7538
|
+
window.DshExtensions.mount({
|
|
7539
|
+
connection, getSession: () => state.byId.get(state.current), getTitle: () => sessionTitleValue(state.byId.get(state.current)),
|
|
7540
|
+
openContext: () => void openInsights('context', true),
|
|
7541
|
+
returnToSession: () => showView('view-session'), scrollTop: () => window.scrollTo(0,0),
|
|
7479
7542
|
url: path => connection.server + path,
|
|
7480
7543
|
headers: { authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': CAP?.isNativePlatform?.() ? 'app' : 'web', ...clientIdHeaders() },
|
|
7481
7544
|
valid: connection.valid,
|
|
7482
|
-
}, $('plugin-page'))
|
|
7545
|
+
}, $('plugin-page'), route)
|
|
7483
7546
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* Explicit user downloads only; attachment IDs never become filesystem paths. */
|
|
2
|
+
(function(root,factory){const api=factory(root);if(typeof module==='object')module.exports=api;root.DshChatFiles=api})(typeof window!=='undefined'?window:globalThis,(root)=>{
|
|
3
|
+
const esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
4
|
+
function pathOf(value,cwd='') {
|
|
5
|
+
if(typeof value!=='string'||value.length>4096||/[\x00-\x1f]/.test(value))return ''
|
|
6
|
+
let path=value.trim()
|
|
7
|
+
if(/^file:/i.test(path)){try{const u=new URL(path);if(u.hostname&&u.hostname!=='localhost')return '';path=decodeURIComponent(u.pathname);if(/^\/[a-z]:\//i.test(path))path=path.slice(1)}catch{return ''}}
|
|
8
|
+
if(/[\x00-\x1f]/.test(path))return ''
|
|
9
|
+
if(/^(?:[a-z]:[\\/]|\/(?!\/))/i.test(path))return path
|
|
10
|
+
if(/^\.{1,2}[\\/]/.test(path)){const base=pathOf(cwd);if(base)return base.replace(/[\\/]+$/,'')+'/'+path}
|
|
11
|
+
return ''
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function render(block){const a=block.attachment||block,path=pathOf(a.path||block.path)||(/^\.{1,2}[\\/]/.test(a.path||block.path||'')?(a.path||block.path):''),id=/^[a-f0-9]{64}$/.test(a.attachmentId||'')?a.attachmentId:'';const name=a.name||block.name||'file';return `<div class="chat-file"><span class="chat-file-name">📎 ${esc(name)} <small>${esc(a.bytes??block.bytes??'')} bytes</small></span>${id||path?`<button type="button" ${id?'data-dsh-attachment="'+esc(id)+'"':'data-dsh-file-path="'+esc(path)+'"'} data-dsh-file-name="${esc(name)}">下载文件</button>`:''}</div>`}
|
|
15
|
+
function bind(target,config){target.addEventListener('click',async event=>{const control=event.target.closest?.('[data-dsh-file-path],[data-dsh-attachment]');if(!control||!target.contains(control)||control.getAttribute('aria-busy')==='true')return;event.preventDefault();const c=config(),id=control.dataset.dshAttachment,path=pathOf(control.dataset.dshFilePath,c.cwd);if(!c.valid())return;if(!id&&!path){c.notice('无法定位文件,请核对当前会话的工作目录','err');return;}const name=(control.dataset.dshFileName||path.split(/[\\/]/).pop()||'download').replace(/[\\/\x00-\x1f]/g,'_');const url=new URL(c.server+(id?'/remote/api/session-file':'/fs/file'),root.location?.href);if(id){url.searchParams.set('sessionId',c.sessionId);url.searchParams.set('attachmentId',id)}else url.searchParams.set('path',path);control.setAttribute('aria-busy','true');try{const response=await fetch(url,{method:'HEAD',redirect:'error',headers:c.headers,signal:AbortSignal.timeout(15000)});if(!c.valid())return;if(!response.ok)throw Error(response.status===403?'主机不允许下载这个文件':response.status===404?'文件不存在或不属于当前会话':response.status===503?'主机版本暂不支持附件下载':'文件下载失败(HTTP '+response.status+')');if(c.native){if(!root.NativeFile?.downloadToDownloads)throw Error('当前 App 不支持系统下载');root.NativeFile.downloadToDownloads(url.href,name,c.token)}else{if(c.token)url.searchParams.set('token',c.token);const link=document.createElement('a');link.href=url.href;link.download=name;link.referrerPolicy='no-referrer';document.body.append(link);link.click();link.remove()}c.notice('已交给系统下载,请在下载目录查看','ok')}catch(error){if(c.valid())c.notice(error.message,'err')}finally{control.removeAttribute('aria-busy')}})}
|
|
16
|
+
return {pathOf,render,bind}
|
|
17
|
+
})
|
|
@@ -746,3 +746,8 @@ input:focus-visible, select:focus-visible, textarea:focus-visible {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
@media(max-width:600px) { .ds-system-pulse-ring { width:108px; height:108px; } .ds-overview-status { font-size:20px; } html[lang="en"] .ds-overview-status { min-block-size:2.5em; } }
|
|
749
|
+
#view-plugins{overflow-y:auto}
|
|
750
|
+
|
|
751
|
+
.chat-file { display:flex; flex-wrap:wrap; align-items:center; gap:8px 12px; padding:12px; border:1px solid var(--dsr-line); border-radius:12px; margin:8px 0; }
|
|
752
|
+
.chat-file-name { min-width:0; flex:1; overflow-wrap:break-word; }.chat-file small { color:var(--dsr-muted); }
|
|
753
|
+
.chat-file button { flex-shrink:0; min-height:44px; padding:8px 12px; border:1px solid var(--dsr-accent-line); border-radius:10px; color:var(--dsr-accent-strong); background:var(--dsr-accent-soft); font:inherit; cursor:pointer; }
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
<link rel="stylesheet" href="../theme-vars.css">
|
|
9
9
|
<link rel="stylesheet" href="desktop.css">
|
|
10
10
|
<link rel="stylesheet" href="../plugin-center.css">
|
|
11
|
+
<link rel="stylesheet" href="../skills.css">
|
|
12
|
+
<link rel="stylesheet" href="../extensions.css">
|
|
11
13
|
<link rel="stylesheet" href="../insights.css">
|
|
12
14
|
</head>
|
|
13
15
|
<body>
|
|
@@ -539,6 +541,8 @@
|
|
|
539
541
|
'ds.attention': '需要你处理', 'ds.runtime': '运行指标', 'ds.recentActivity': '近期活动', 'ds.dshVersion': 'DSH 版本', 'ds.gatewayStatus': '网关状态', 'ds.activeSessions': '活跃会话', 'ds.connectionMode': '连接模式', 'ds.liveWs': '实时 WS', 'ds.poll': '降级轮询', 'ds.running': '运行中', 'ds.noReason': '无说明', 'ds.noActivity': '暂无后台活动', 'ds.noSessions': '暂无会话', 'ds.refreshOverview': '刷新总览', 'ds.pendingCount': '{n} 项待处理', 'ds.activeCount': '{n} 个活跃会话', 'ds.nothingPending': '暂无事项', 'ds.action.openSession': '打开最近会话', 'ds.action.newSession': '新建会话', 'ds.action.attention': '处理待办', 'ds.action.connect': '去设置连接', 'ds.action.refresh': '重新检查连接',
|
|
540
542
|
'ds.sortLabel': '会话排序', 'ds.sortTime': '按时间', 'ds.sortWorkspace': '按工作区', 'ds.workspace': '工作区', 'ds.workspaceUnknown': '未指定工作区', 'ds.wbOrderSaved': '顺序已保存到当前设备',
|
|
541
543
|
'ds.insights': '上下文与费用',
|
|
544
|
+
'ds.insightsContext': '上下文分析',
|
|
545
|
+
'ds.insightsCost': '费用与额度',
|
|
542
546
|
'ds.files': '文件传输', 'ds.plugins': '插件', 'ds.settings': '设置', 'ds.stats': '统计', 'ds.menu': '导航',
|
|
543
547
|
'ds.send': '发送', 'ds.composerPlaceholder': '输入消息,Enter 发送…', 'ds.composerRunning': '运行中…', 'ds.presets': '预设', 'ds.sessionRename': '重命名会话', 'ds.sessionRenameTitle': '重命名会话', 'ds.sessionRenamePlaceholder': '输入新的会话名称', 'ds.sessionRenameConfirm': '保存', 'ds.sessionRenameFailed': '重命名失败', 'ds.sessionRenameEmpty': '会话名称不能为空', 'ds.sessionRenamed': '会话名称已更新', 'ds.sessionArchive': '归档', 'ds.sessionArchiveConfirm': '归档这个会话?归档后可在“显示已归档”中打开。', 'ds.sessionArchived': '会话已归档', 'ds.sessionStop': '停止本轮', 'ds.sessionStopConfirm': '停止当前回合?排队中的消息不会被删除。', 'ds.sessionStopFailed': '停止失败', 'ds.sessionStopRequested': '已请求停止本轮', 'ds.sessionRecovering': '恢复会话中…', 'ds.sessionReady': '会话已恢复', 'ds.sessionRecoveryFailed': '会话恢复失败',
|
|
544
548
|
'ds.commands': '指令',
|
|
@@ -646,6 +650,8 @@
|
|
|
646
650
|
'ds.attention': 'Needs attention', 'ds.runtime': 'Runtime metrics', 'ds.recentActivity': 'Recent activity', 'ds.dshVersion': 'DSH version', 'ds.gatewayStatus': 'Gateway status', 'ds.activeSessions': 'Active sessions', 'ds.connectionMode': 'Connection mode', 'ds.liveWs': 'Live WS', 'ds.poll': 'Degraded polling', 'ds.running': 'Running', 'ds.noReason': 'No reason given', 'ds.noActivity': 'No background activity', 'ds.noSessions': 'No sessions yet', 'ds.refreshOverview': 'Refresh overview', 'ds.pendingCount': '{n} pending', 'ds.activeCount': '{n} active sessions', 'ds.nothingPending': 'Nothing pending', 'ds.action.openSession': 'Open recent session', 'ds.action.newSession': 'New session', 'ds.action.attention': 'Review pending', 'ds.action.connect': 'Set up connection', 'ds.action.refresh': 'Check connection',
|
|
647
651
|
'ds.sortLabel': 'Session sort', 'ds.sortTime': 'By time', 'ds.sortWorkspace': 'By workspace', 'ds.workspace': 'Workspace', 'ds.workspaceUnknown': 'No workspace', 'ds.wbOrderSaved': 'Order saved on this device',
|
|
648
652
|
'ds.insights': 'Context & costs',
|
|
653
|
+
'ds.insightsContext': 'Context analysis',
|
|
654
|
+
'ds.insightsCost': 'Cost & quotas',
|
|
649
655
|
'ds.files': 'Files', 'ds.plugins': 'Plugins', 'ds.settings': 'Settings', 'ds.stats': 'Stats', 'ds.menu': 'Menu',
|
|
650
656
|
'ds.send': 'Send', 'ds.composerPlaceholder': 'Type a message, Enter to send…', 'ds.composerRunning': 'Running…', 'ds.presets': 'Presets', 'ds.sessionRename': 'Rename session', 'ds.sessionRenameTitle': 'Rename session', 'ds.sessionRenamePlaceholder': 'Enter a new session name', 'ds.sessionRenameConfirm': 'Save', 'ds.sessionRenameFailed': 'Rename failed', 'ds.sessionRenameEmpty': 'Session name cannot be empty', 'ds.sessionRenamed': 'Session name updated', 'ds.sessionArchive': 'Archive', 'ds.sessionArchiveConfirm': 'Archive this session? You can open it from “Show archived”.', 'ds.sessionArchived': 'Session archived', 'ds.sessionStop': 'Stop turn', 'ds.sessionStopConfirm': 'Stop the current turn? Queued messages will be kept.', 'ds.sessionStopFailed': 'Stop failed', 'ds.sessionStopRequested': 'Stop requested', 'ds.sessionRecovering': 'Restoring session…', 'ds.sessionReady': 'Session ready', 'ds.sessionRecoveryFailed': 'Session restore failed',
|
|
651
657
|
'ds.commands': 'Commands',
|
|
@@ -751,12 +757,15 @@
|
|
|
751
757
|
<script src="i18n.js"></script>
|
|
752
758
|
<link rel="stylesheet" href="../genui.css">
|
|
753
759
|
<script src="../genui.js"></script>
|
|
760
|
+
<script src="../chat-files.js"></script>
|
|
754
761
|
<script src="../md.js"></script>
|
|
755
762
|
<script src="../vendor/gsap/gsap.min.js"></script>
|
|
756
763
|
<script src="../motion.js"></script>
|
|
757
764
|
<script type="module" src="../morphicons-init.js"></script>
|
|
758
765
|
<script src="../plugin-center.js"></script>
|
|
766
|
+
<script src="../skills.js"></script>
|
|
759
767
|
<script src="../insights.js"></script>
|
|
768
|
+
<script src="../extensions.js"></script>
|
|
760
769
|
<script src="../sha256.js"></script>
|
|
761
770
|
<script src="../history.js"></script>
|
|
762
771
|
<script src="../link-check.js"></script>
|
|
@@ -80,6 +80,7 @@ const state = {
|
|
|
80
80
|
queues: {},
|
|
81
81
|
sessionActivity: new Set(),
|
|
82
82
|
queueSteering: {},
|
|
83
|
+
compactionBootAt: Date.now(),
|
|
83
84
|
compactions: {},
|
|
84
85
|
pendingCommands: {},
|
|
85
86
|
compactionPollTimer: null,
|
|
@@ -120,12 +121,15 @@ for (const key of ['server', 'token']) {
|
|
|
120
121
|
state.current = null; state.history = emptyDesktopHistory()
|
|
121
122
|
state.models = { loaded: false, loading: false, groups: [], current: null, failures: [] }
|
|
122
123
|
state.approvals = []; state.questions = []; state.questionModal = null
|
|
123
|
-
state.queues = {}; state.queueSteering = {}; state.compactions = {}; state.pendingCommands = {}; state.sessionTurnTimes = {}
|
|
124
|
+
state.queues = {}; state.queueSteering = {}; state.compactions = {}; state.compactionTerminals = {}; state.compactionSeqs = {}; state.compactionBootAt = Date.now(); state.pendingCommands = {}; state.sessionTurnTimes = {}
|
|
124
125
|
state.sessionActivity = new Set()
|
|
125
126
|
state.fs.path = null; state.fs.initial = null; state.fs.loaded = false; state.fs.roots = []; state.fs.rootIndex = 0
|
|
126
127
|
state.workspaces = []; state.archivedIds = []; state.wb = { bound: false, path: '', projects: null }
|
|
127
128
|
window.DshPluginCenter?.close()
|
|
128
129
|
window.DshInsights?.close()
|
|
130
|
+
window.DshExtensions?.close()
|
|
131
|
+
window.DshExtensions?.invalidateCapabilities()
|
|
132
|
+
if (typeof document !== 'undefined') document.getElementById('btn-insights')?.classList.add('hidden')
|
|
129
133
|
if(typeof document!=='undefined') {
|
|
130
134
|
const identityGeneration=connectionGeneration
|
|
131
135
|
queueMicrotask(()=>{if(identityGeneration===connectionGeneration&&typeof startOverviewDetection==='function')startOverviewDetection(true,true)})
|
|
@@ -1448,7 +1452,7 @@ function onMuxFrame(full) {
|
|
|
1448
1452
|
if (f.sessionId === state.current) { applyReasoningBaseline(f.partialReasoning); scheduleReasoningRender() }
|
|
1449
1453
|
return
|
|
1450
1454
|
}
|
|
1451
|
-
if (f.type === 'session/event') return onSessionEvent(f.sessionId, f.event)
|
|
1455
|
+
if (f.type === 'session/event') return onSessionEvent(f.sessionId, f.event, { replay: f.replay === true })
|
|
1452
1456
|
if (f.type === 'approval/requested') {
|
|
1453
1457
|
state.approvals = state.approvals.filter(a => a.approvalId !== f.approvalId)
|
|
1454
1458
|
state.approvals.push({ ...f, rpcId: full.rpcId })
|
|
@@ -1492,6 +1496,7 @@ function compactElapsed(startedAt) {
|
|
|
1492
1496
|
return minutes > 0 ? `${minutes}:${String(remain).padStart(2, '0')}` : `${remain}s`
|
|
1493
1497
|
}
|
|
1494
1498
|
function setCompactionStatus(sessionId, next) {
|
|
1499
|
+
state.compactionTerminals ||= {}
|
|
1495
1500
|
if (!sessionId) return
|
|
1496
1501
|
const previous = state.compactions[sessionId]
|
|
1497
1502
|
if (next?.active === true) {
|
|
@@ -1502,10 +1507,15 @@ function setCompactionStatus(sessionId, next) {
|
|
|
1502
1507
|
startedAt: Number(next.startedAt) || previous?.startedAt || Date.now(),
|
|
1503
1508
|
message: String(next.message || ''),
|
|
1504
1509
|
source: next.source || previous?.source || 'event',
|
|
1510
|
+
compactionId: next.compactionId || previous?.compactionId || '',
|
|
1511
|
+
notify: next.notify ?? previous?.notify ?? (next.source === 'command'),
|
|
1505
1512
|
}
|
|
1506
1513
|
} else {
|
|
1507
1514
|
delete state.compactions[sessionId]
|
|
1508
1515
|
if (previous?.active) {
|
|
1516
|
+
state.compactionTerminals[sessionId] = { startedAt: previous.startedAt, compactionId: previous.compactionId }
|
|
1517
|
+
}
|
|
1518
|
+
if (previous?.active && previous.notify && next?.notify !== false && ['complete', 'failed'].includes(next?.phase)) {
|
|
1509
1519
|
const command = previous.command || 'compact'
|
|
1510
1520
|
if (next?.phase === 'failed') toast(command === 'compact'
|
|
1511
1521
|
? t('ds.compactFailed', { msg: next.message || t('ds.sessionRecoveryFailed') })
|
|
@@ -1518,18 +1528,25 @@ function setCompactionStatus(sessionId, next) {
|
|
|
1518
1528
|
}
|
|
1519
1529
|
async function refreshCompactionStatus(sessionId = state.current) {
|
|
1520
1530
|
if (!sessionId) return
|
|
1531
|
+
const connection = captureConnection()
|
|
1521
1532
|
try {
|
|
1522
1533
|
const signal = typeof AbortSignal?.timeout === 'function' ? AbortSignal.timeout(8000) : undefined
|
|
1523
|
-
const url = new URL(
|
|
1534
|
+
const url = new URL(connection.server + '/remote/api/command-status', location.href)
|
|
1524
1535
|
url.searchParams.set('sessionId', sessionId)
|
|
1525
|
-
const res = await fetch(url, { headers: { authorization: 'Bearer ' +
|
|
1536
|
+
const res = await fetch(url, { headers: { authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': 'web', ...clientIdHeaders() }, ...(signal ? { signal } : {}) })
|
|
1537
|
+
if (!connection.valid()) return
|
|
1526
1538
|
if (res.status === 401) { toast(t('ds.toastAuth'), 'err'); return }
|
|
1527
1539
|
if (!res.ok) return
|
|
1540
|
+
if (!connection.valid()) return
|
|
1528
1541
|
const body = await res.json().catch(() => null)
|
|
1542
|
+
if (!connection.valid()) return
|
|
1529
1543
|
const operation = body?.operation || body?.compact
|
|
1530
1544
|
if (!operation) return
|
|
1545
|
+
if (operation.startedAt && activeCompaction(sessionId)?.startedAt > Number(operation.startedAt)) return
|
|
1531
1546
|
const pending = state.pendingCommands[sessionId]
|
|
1532
|
-
if (operation.active) {
|
|
1547
|
+
if (operation.active === true) {
|
|
1548
|
+
const terminal = state.compactionTerminals?.[sessionId]
|
|
1549
|
+
if (terminal && Number(operation.startedAt) <= terminal.startedAt) return
|
|
1533
1550
|
delete state.pendingCommands[sessionId]
|
|
1534
1551
|
setCompactionStatus(sessionId, { ...operation, source: 'status' })
|
|
1535
1552
|
} else if (activeCompaction(sessionId) && activeCompaction(sessionId).source !== 'event') {
|
|
@@ -1555,14 +1572,25 @@ function ensureCompactionMonitoring() {
|
|
|
1555
1572
|
if (compact && compact.source !== 'event') void refreshCompactionStatus()
|
|
1556
1573
|
}, 3000)
|
|
1557
1574
|
}
|
|
1558
|
-
function observeCompactionEvent(sessionId, event) {
|
|
1559
|
-
if (event
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1575
|
+
function observeCompactionEvent(sessionId, event, meta = {}) {
|
|
1576
|
+
if (!event || !sessionId || !['compaction/start','compaction/end','session/end-seed'].includes(event.type)) return
|
|
1577
|
+
state.compactionSeqs ||= {}; state.compactionBootAt ||= Date.now()
|
|
1578
|
+
const seq = Number(event.seq), previous = activeCompaction(sessionId)
|
|
1579
|
+
if (seq > 0 && seq <= (state.compactionSeqs[sessionId] || 0)) return
|
|
1580
|
+
const id = event.data?.compactionId || ''
|
|
1581
|
+
if (event.type === 'compaction/end' && previous?.compactionId && previous.compactionId !== id) return
|
|
1582
|
+
if (seq > 0) state.compactionSeqs[sessionId] = seq
|
|
1583
|
+
const time = typeof event.time === 'number' ? event.time : Date.parse(event.time)
|
|
1584
|
+
if (event.type === 'compaction/start') {
|
|
1585
|
+
setCompactionStatus(sessionId, { active: true, phase: 'running', compactionId: id,
|
|
1586
|
+
startedAt: previous?.startedAt || (Number.isFinite(time) ? time : Date.now()), source: previous?.source || 'event',
|
|
1587
|
+
notify: meta.replay ? false : previous?.notify || Number.isFinite(time) && time >= state.compactionBootAt })
|
|
1588
|
+
} else {
|
|
1589
|
+
setCompactionStatus(sessionId, { active: false, phase: event.type === 'session/end-seed' ? 'interrupted' : event.data?.error ? 'failed' : 'complete',
|
|
1590
|
+
message: event.data?.error || '', ...(meta.replay || event.type === 'session/end-seed' ? { notify: false } : {}) })
|
|
1564
1591
|
}
|
|
1565
1592
|
}
|
|
1593
|
+
|
|
1566
1594
|
function hydrateSessionProjections(sessionId, projections) {
|
|
1567
1595
|
const s = state.byId.get(sessionId)
|
|
1568
1596
|
if (!s || !projections || typeof projections !== 'object') return
|
|
@@ -1626,9 +1654,36 @@ function resyncAfterStreamOpen() {
|
|
|
1626
1654
|
void refreshSessions().then(() => resyncCurrentSession())
|
|
1627
1655
|
}
|
|
1628
1656
|
function proj(s, key, d) { return s?.projections?.values?.[key] ?? d }
|
|
1629
|
-
function
|
|
1630
|
-
|
|
1631
|
-
|
|
1657
|
+
function optionalPluginConfig(connection = captureConnection()) {
|
|
1658
|
+
return { connection, valid: connection.valid, url: path => connection.server + path,
|
|
1659
|
+
headers: { authorization: 'Bearer ' + connection.token, 'x-dsh-remote-client': 'web', ...clientIdHeaders() } }
|
|
1660
|
+
}
|
|
1661
|
+
function availableInsightTabs(capabilities) {
|
|
1662
|
+
return [...(capabilities.context ? ['context'] : []), ...(capabilities.cost ? ['cost'] : [])]
|
|
1663
|
+
}
|
|
1664
|
+
async function refreshInsightEntry() {
|
|
1665
|
+
const control = $('btn-insights'), id = state.current, connection = captureConnection()
|
|
1666
|
+
if (!control || !id || !connection.token || !window.DshExtensions) { control?.classList.add('hidden'); return }
|
|
1667
|
+
const capabilities = await window.DshExtensions.getCapabilities(optionalPluginConfig(connection))
|
|
1668
|
+
if (!connection.valid() || state.current !== id) return
|
|
1669
|
+
const tabs = availableInsightTabs(capabilities)
|
|
1670
|
+
control.classList.toggle('hidden', !tabs.length)
|
|
1671
|
+
const label = t(tabs.length === 2 ? 'ds.insights' : tabs[0] === 'cost' ? 'ds.insightsCost' : 'ds.insightsContext')
|
|
1672
|
+
control.textContent = label; control.title = label; control.setAttribute('aria-label', label)
|
|
1673
|
+
}
|
|
1674
|
+
async function openInsights(tab = 'context', fullPage = false) {
|
|
1675
|
+
const connection = captureConnection(), id = state.current
|
|
1676
|
+
const capabilities = await window.DshExtensions.getCapabilities(optionalPluginConfig(connection))
|
|
1677
|
+
if (!connection.valid() || state.current !== id || !id) return
|
|
1678
|
+
const allowedTabs = availableInsightTabs(capabilities)
|
|
1679
|
+
if (!allowedTabs.length) { void refreshInsightEntry(); return }
|
|
1680
|
+
window.DshInsights?.close()
|
|
1681
|
+
const view = fullPage ? conversationView : null, wasPaused = view?.paused
|
|
1682
|
+
view?.pause()
|
|
1683
|
+
window.DshInsights?.open({ tab, fullPage, allowedTabs, connection, url: path => connection.server + path,
|
|
1684
|
+
getSession: () => state.byId.get(state.current), getTitle: () => titleOf(state.byId.get(state.current)),
|
|
1685
|
+
onFullPage: selected => void openInsights(selected, true),
|
|
1686
|
+
onClose: () => { if (view && !wasPaused && connection.valid() && state.current === id && state.view === 'view-chat') view.resume() } })
|
|
1632
1687
|
}
|
|
1633
1688
|
function sessionTitleValue(s) {
|
|
1634
1689
|
const value = proj(s, 'title', '')
|
|
@@ -1676,8 +1731,8 @@ function setGoalCollapsed(sessionId, goal, collapsed) {
|
|
|
1676
1731
|
if (collapsed) next.push({ sessionId, goalId })
|
|
1677
1732
|
LS.set(COLLAPSED_GOALS_KEY, JSON.stringify(next.slice(-100)))
|
|
1678
1733
|
}
|
|
1679
|
-
function onSessionEvent(sessionId, event) {
|
|
1680
|
-
observeCompactionEvent(sessionId, event)
|
|
1734
|
+
function onSessionEvent(sessionId, event, meta = {}) {
|
|
1735
|
+
observeCompactionEvent(sessionId, event, meta)
|
|
1681
1736
|
if (event?.type === 'turn/start' || event?.type === 'turn/end') {
|
|
1682
1737
|
noteSessionTurnTime(sessionId, event)
|
|
1683
1738
|
renderSessions()
|
|
@@ -1919,7 +1974,7 @@ function getConversationView() {
|
|
|
1919
1974
|
if(!conversationView)conversationView=new window.DshHistory.HistoryView($('history'),{
|
|
1920
1975
|
html:entry=>eventHtml(entry),
|
|
1921
1976
|
older:()=>loadHistory(false),olderLabel:()=>t('ds.historyEarlier'),loadingLabel:()=>t('ds.historyLoadingEarlier'),live:partialReasoningHtml,
|
|
1922
|
-
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end
|
|
1977
|
+
changed:view=>{state.history.renderStart=view.start;state.history.renderEnd=view.end;const latest=$('btn-history-latest');if(latest){latest.classList.toggle('hidden',!view.reading&&view.end>=view.entries.length&&!state.history.tailEvicted);latest.textContent=t('ds.historyLatest')+(view.unread?' ('+view.unread+')':view.hasPending?' · '+(I18N.lang==='en'?'New content':'有新内容'):'');}},
|
|
1923
1978
|
scrolled:()=>{}
|
|
1924
1979
|
})
|
|
1925
1980
|
return conversationView
|
|
@@ -2086,7 +2141,8 @@ function partialReasoningHtml() {
|
|
|
2086
2141
|
function safeJson(v) { try { return JSON.stringify(v, null, 2) } catch { return String(v) } }
|
|
2087
2142
|
function blockHtml(b) {
|
|
2088
2143
|
if (!b) return ''
|
|
2089
|
-
if (b.type === 'text') return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '') : esc(b.text ?? '')}</div>`
|
|
2144
|
+
if (b.type === 'text') return `<div class="md">${window.mdToHtml ? window.mdToHtml(b.text ?? '', { fileLinks: true }) : esc(b.text ?? '')}</div>`
|
|
2145
|
+
if (b.type === 'file' && typeof window !== 'undefined' && window.DshChatFiles) return window.DshChatFiles.render(b)
|
|
2090
2146
|
if (b.type === 'file') return `<div class="ds-tool">📎 ${esc(b.attachment?.name || b.name || 'file')} <small>${esc(b.attachment?.bytes ?? b.bytes ?? '')} bytes</small></div>`
|
|
2091
2147
|
if (b.type === 'thinking' || b.type === 'reasoning') return `<details><summary>${esc(t('block.thinking'))}</summary><div style="opacity:.82">${esc(b.text ?? b.content ?? '')}</div></details>`
|
|
2092
2148
|
if (b.type === 'tool-call') return `<div>🔧 ${esc(b.name || '')}</div>`
|
|
@@ -2153,7 +2209,7 @@ let sessionCardsRenderGeneration = 0
|
|
|
2153
2209
|
async function renderSessionCards() {
|
|
2154
2210
|
const connection = captureConnection()
|
|
2155
2211
|
window.DshInsights?.update()
|
|
2156
|
-
|
|
2212
|
+
void refreshInsightEntry()
|
|
2157
2213
|
const renderGeneration = ++sessionCardsRenderGeneration
|
|
2158
2214
|
const sessionId = state.current
|
|
2159
2215
|
const box = $('session-cards')
|
|
@@ -2746,7 +2802,6 @@ async function createWorkspace() {
|
|
|
2746
2802
|
button.disabled = true
|
|
2747
2803
|
try {
|
|
2748
2804
|
const res = await fetch(fsApiUrl('/mkdir', { path: parent, name }), { method: 'POST', headers: fsHeaders() })
|
|
2749
|
-
if (!connection.valid()) return
|
|
2750
2805
|
if (res.status === 401) { toast(t('ds.toastAuth'), 'err'); return }
|
|
2751
2806
|
const data = await res.json().catch(() => ({}))
|
|
2752
2807
|
if (!connection.valid()) return
|
|
@@ -3476,16 +3531,18 @@ function setMobileSidebar(open) {
|
|
|
3476
3531
|
$('ds-app')?.classList.toggle('mobile-nav-open', visible)
|
|
3477
3532
|
}
|
|
3478
3533
|
|
|
3479
|
-
function openDesktopPlugins() {
|
|
3534
|
+
function openDesktopPlugins(route = 'manage') {
|
|
3480
3535
|
const connection=captureConnection()
|
|
3481
3536
|
if(!connection.token){$('desktop-plugin-page').textContent=t('ds.toastAuth');return}
|
|
3482
|
-
window.
|
|
3537
|
+
window.DshExtensions.mount({connection,getSession:()=>state.byId.get(state.current),getTitle:()=>titleOf(state.byId.get(state.current)),openContext:()=>void openInsights('context',true),scrollTop:()=>{$('view-plugins').scrollTop=0},url:path=>connection.server+path,headers:{authorization:'Bearer '+connection.token,'x-dsh-remote-client':'web',...clientIdHeaders()},valid:connection.valid},$('desktop-plugin-page'),route)
|
|
3483
3538
|
}
|
|
3484
3539
|
|
|
3485
3540
|
function showView(id) {
|
|
3541
|
+
if (id !== 'view-chat') conversationView?.pause()
|
|
3486
3542
|
if (state.view === 'view-chat' && id !== 'view-chat' && state.current) void archiveEmptySessionOnLeave(state.current)
|
|
3487
3543
|
state.view = id
|
|
3488
3544
|
for (const v of ['view-overview', 'view-sessions', 'view-chat', 'view-files', 'view-plugins', 'view-settings']) $(v).classList.toggle('hidden', v !== id)
|
|
3545
|
+
if (id === 'view-chat') conversationView?.resume()
|
|
3489
3546
|
document.querySelectorAll('.ds-nav-item').forEach(b => b.classList.toggle('active', b.dataset.view === id))
|
|
3490
3547
|
if (narrowSidebarQuery.matches) setMobileSidebar(false)
|
|
3491
3548
|
window.DshMotion?.view($(id))
|
|
@@ -3497,7 +3554,7 @@ function showView(id) {
|
|
|
3497
3554
|
if (id === 'view-files' && !state.fs.loaded) loadFs(null, true)
|
|
3498
3555
|
if (id === 'view-settings') showSettingsHome()
|
|
3499
3556
|
if (id === 'view-plugins') openDesktopPlugins()
|
|
3500
|
-
else window.
|
|
3557
|
+
else window.DshExtensions?.close()
|
|
3501
3558
|
updateSessionActions()
|
|
3502
3559
|
}
|
|
3503
3560
|
|
|
@@ -3700,6 +3757,7 @@ function bindUi() {
|
|
|
3700
3757
|
if (!e.target.closest('#model-menu') && !e.target.closest('#btn-model')) $('model-menu')?.classList.add('hidden')
|
|
3701
3758
|
})
|
|
3702
3759
|
$('btn-stats-top').addEventListener('click', toggleStatsDrawer)
|
|
3760
|
+
window.DshChatFiles?.bind($('history'), () => { const c=captureConnection(); return { ...c,sessionId:state.current,cwd:sessionCwd(state.byId.get(state.current)),native:false,headers:{authorization:'Bearer '+c.token,...clientIdHeaders()},notice:toast } })
|
|
3703
3761
|
$('btn-insights').addEventListener('click', () => openInsights())
|
|
3704
3762
|
$('stats-drawer-close').addEventListener('click', toggleStatsDrawer)
|
|
3705
3763
|
// 赞赏支持
|
|
@@ -3803,7 +3861,7 @@ function bindUi() {
|
|
|
3803
3861
|
$('btn-lang').addEventListener('click', () => {
|
|
3804
3862
|
I18N.setLang(I18N.lang === 'zh' ? 'en' : 'zh')
|
|
3805
3863
|
$('btn-lang').textContent = I18N.lang === 'zh' ? 'EN' : '中文'
|
|
3806
|
-
renderServers(); renderSessions(); renderNotifStack(); renderOverviewDesktop(); updateConn(); themeApply()
|
|
3864
|
+
renderServers(); renderSessions(); renderNotifStack(); renderOverviewDesktop(); updateConn(); themeApply(); void refreshInsightEntry()
|
|
3807
3865
|
})
|
|
3808
3866
|
$('fs-up').addEventListener('click', fsUp)
|
|
3809
3867
|
$('fs-root').addEventListener('change', (event) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ext-page{min-width:0;width:100%;padding:16px;color:var(--dsr-text)}.ext-page.is-manage{padding:0}.ext-header{display:flex;gap:14px;align-items:center;justify-content:space-between;margin-bottom:24px;flex-wrap:wrap}.ext-host{min-width:0;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--dsr-muted);font-size:13px;line-height:1.7}.ext-header button{flex-shrink:0;white-space:nowrap;color:var(--dsr-text);background:var(--dsr-panel);border:1px solid var(--dsr-line);border-radius:12px;font:inherit;min-height:44px;padding:10px 14px;cursor:pointer}.ext-header button:focus-visible{outline:2px solid var(--dsr-accent);outline-offset:3px}.ext-page [hidden]{display:none!important}@media(max-width:620px){.ext-page{padding:8px 0}.ext-header{margin-bottom:18px}}
|