dsh-remote-plugin 0.8.7 → 0.9.0
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 +16 -5
- package/README.md +15 -4
- package/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +659 -130
- package/index.mjs +33 -1
- package/package.json +8 -3
- package/public/activity.js +196 -52
- package/public/admin.html +34 -32
- package/public/admin.js +11 -2
- package/public/app.js +1341 -223
- package/public/bc-integration.css +81 -0
- package/public/build.json +2 -2
- package/public/composer-tools.css +184 -0
- package/public/composer-tools.js +888 -0
- package/public/desktop/desktop.html +104 -76
- package/public/desktop/desktop.js +668 -101
- package/public/diagnostics.js +30 -4
- package/public/e2ee-transport.js +154 -7
- package/public/file-inbox.js +77 -18
- package/public/genui.css +10 -0
- package/public/genui.js +22 -4
- package/public/history.js +15 -2
- package/public/host-queue.js +232 -0
- package/public/host-schedule.js +301 -0
- package/public/host-state.css +19 -0
- package/public/index.html +347 -140
- package/public/md.js +21 -1
- package/public/network.js +33 -1
- package/public/onboarding.js +3 -3
- package/public/operations.js +26 -12
- package/public/plan-review.css +297 -0
- package/public/plan-review.js +621 -0
- package/public/plugin.html +29 -27
- package/public/relay-autopair.js +25 -10
- package/public/relay-settings.css +11 -0
- package/public/relay-settings.js +350 -28
- package/public/session-management.css +61 -0
- package/public/session-management.js +742 -0
- package/public/session-search.css +137 -0
- package/public/session-search.js +977 -0
- package/public/skins/blue-fish/preview.html +3 -3
- package/public/skins/bocchi/preview.html +5 -5
- package/public/skins/kita/preview.html +6 -6
- package/public/skins/miku/SOURCES.json +10 -0
- package/public/skins/miku/chibi.png +0 -0
- package/public/skins/miku/preview.html +33 -0
- package/public/skins/miku/skin.css +82 -0
- package/public/skins/nijika/preview.html +6 -6
- package/public/skins/penguin/preview.html +3 -3
- package/public/skins/penguin-logistics/cargo.svg +4 -0
- package/public/skins/penguin-logistics/console.svg +4 -0
- package/public/skins/penguin-logistics/mark.svg +4 -0
- package/public/skins/penguin-logistics/radio.svg +4 -0
- package/public/skins/penguin-logistics/skin.css +292 -0
- package/public/skins/penguin-logistics/standing.png +0 -0
- package/public/skins/ryo/preview.html +6 -6
- package/public/slash-suggestions.css +43 -0
- package/public/slash-suggestions.js +196 -0
- package/public/sponsor-entry.js +11 -3
- package/public/styles.css +141 -21
- package/public/subagents.css +7 -0
- package/public/subagents.js +83 -10
- package/public/theme-vars.css +102 -3
- package/public/theme.js +7 -4
- package/public/turn-diff.css +323 -0
- package/public/turn-diff.js +778 -0
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/public/workflow.css +322 -43
- package/public/workflow.js +148 -44
|
@@ -39,7 +39,9 @@ const THEME_META = [
|
|
|
39
39
|
{ id: 'bocchi', sw: ['#FFD9E8', '#FFFFFF', '#D0105A'] },
|
|
40
40
|
{ id: 'nijika', sw: ['#FFF3D5', '#FFFFFF', '#94600C'] },
|
|
41
41
|
{ id: 'ryo', sw: ['#E9F1FA', '#FFFFFF', '#315D91'] },
|
|
42
|
-
{ id: 'kita', sw: ['#FFE9E5', '#FFFFFF', '#B6373C'] }
|
|
42
|
+
{ id: 'kita', sw: ['#FFE9E5', '#FFFFFF', '#B6373C'] },
|
|
43
|
+
{ id: 'penguin-logistics', sw: ['#12161B', '#1D252E', '#E9B66F'] },
|
|
44
|
+
{ id: 'miku', sw: ['#F3FFFC', '#FFFFFF', '#126D69'] }
|
|
43
45
|
]
|
|
44
46
|
function themeGet() {
|
|
45
47
|
const v = LS.get('dshTheme', '')
|
|
@@ -87,7 +89,6 @@ const state = {
|
|
|
87
89
|
questions: [],
|
|
88
90
|
queues: {},
|
|
89
91
|
sessionActivity: new Set(),
|
|
90
|
-
queueSteering: {},
|
|
91
92
|
compactionBootAt: Date.now(),
|
|
92
93
|
compactions: {},
|
|
93
94
|
pendingCommands: {},
|
|
@@ -108,6 +109,7 @@ const state = {
|
|
|
108
109
|
workspaces: [],
|
|
109
110
|
wb: { bound: false, path: '', title: '', expanded: false, projects: null, open: null, apiMissing: false },
|
|
110
111
|
archivedIds: [],
|
|
112
|
+
pinnedIds: [],
|
|
111
113
|
view: 'sessions',
|
|
112
114
|
subagentSessions: {}
|
|
113
115
|
}
|
|
@@ -123,6 +125,7 @@ for (const key of ['server', 'token']) {
|
|
|
123
125
|
if (next === value) return
|
|
124
126
|
cancelHistoryLoad()
|
|
125
127
|
value = next; connectionGeneration++
|
|
128
|
+
window.DshSlashSuggestions?.close()
|
|
126
129
|
window.DshImagePreview?.reset?.()
|
|
127
130
|
clearTimeout(state.refreshTimer); state.refreshTimer = null
|
|
128
131
|
state.sessions = []; state.byId.clear(); state.pendingProjections.clear(); state.runtimeErrors = new Map()
|
|
@@ -131,10 +134,10 @@ for (const key of ['server', 'token']) {
|
|
|
131
134
|
state.current = null; state.history = emptyDesktopHistory(); state.subagentSessions = {}; window.DshSubagents?.reset()
|
|
132
135
|
state.models = { loaded: false, loading: false, groups: [], current: null, failures: [] }
|
|
133
136
|
state.approvals = []; state.questions = []; state.questionModal = null
|
|
134
|
-
state.queues = {}; state.
|
|
137
|
+
state.queues = {}; state.compactions = {}; state.compactionTerminals = {}; state.compactionSeqs = {}; state.compactionBootAt = Date.now(); state.pendingCommands = {}; state.sessionTurnTimes = {}
|
|
135
138
|
state.sessionActivity = new Set()
|
|
136
139
|
state.fs.path = null; state.fs.initial = null; state.fs.loaded = false; state.fs.roots = []; state.fs.rootIndex = 0
|
|
137
|
-
state.workspaces = []; state.archivedIds = []; state.wb = { bound: false, path: '', projects: null }
|
|
140
|
+
state.workspaces = []; state.archivedIds = []; state.pinnedIds = []; state.wb = { bound: false, path: '', projects: null }
|
|
138
141
|
window.DshPluginCenter?.close()
|
|
139
142
|
window.DshInsights?.close()
|
|
140
143
|
window.DshExtensions?.close()
|
|
@@ -301,7 +304,10 @@ function toggleCmdMenuDesktop() {
|
|
|
301
304
|
const menu = $('cmd-menu')
|
|
302
305
|
if (!menu) return
|
|
303
306
|
const willOpen = menu.classList.contains('hidden')
|
|
304
|
-
if (willOpen)
|
|
307
|
+
if (willOpen) {
|
|
308
|
+
void window.DshSlashSuggestions?.openPanel()
|
|
309
|
+
void refreshPermissionPresetsDesktop()
|
|
310
|
+
}
|
|
305
311
|
menu.classList.toggle('hidden', !willOpen)
|
|
306
312
|
}
|
|
307
313
|
|
|
@@ -758,19 +764,20 @@ async function rpc(method, payload = {}, timeoutMs = 45000, cancellation = null)
|
|
|
758
764
|
else if (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') {
|
|
759
765
|
opts.signal = AbortSignal.timeout(timeoutMs)
|
|
760
766
|
}
|
|
761
|
-
const operation = window.DshOperations?.supports(method) && activeGatewayCapability('operations') === true
|
|
767
|
+
const operation = window.DshOperations?.supports(method) && (window.DshOperations.requiresReceipt?.(method) || activeGatewayCapability('operations') === true)
|
|
762
768
|
const connection = operation ? captureConnection() : null
|
|
763
769
|
const receipt = operation ? await window.DshOperations.execute({ method, payload, url: apiUrl, headers: opts.headers, valid: () => connection.valid() }) : null
|
|
764
770
|
const res = receipt ? { status: 200, ok: true, json: async () => receipt } : await fetch(apiUrl('/api/' + method), opts)
|
|
765
771
|
diagnostic?.end({phase:'response',httpStatus:res.status})
|
|
766
772
|
if (res.status === 401) throw new Error('AUTH')
|
|
767
|
-
if (!res.ok)
|
|
773
|
+
if (!res.ok) { const error = new Error('HTTP ' + res.status); error.status = res.status; throw error }
|
|
768
774
|
const full = await res.json()
|
|
769
775
|
if (!full?.result) throw new Error('bad response')
|
|
770
776
|
if (!full.result.ok) {
|
|
771
777
|
const err = full.result.error || {}
|
|
772
778
|
const error = new Error(err.code === 'session/migration-required' ? t('session.migrationRequired') : err.message || 'dsh error')
|
|
773
779
|
error.code = err.code
|
|
780
|
+
error.rpcRejected = true
|
|
774
781
|
throw error
|
|
775
782
|
}
|
|
776
783
|
diagnostic?.end({phase:'complete'})
|
|
@@ -947,22 +954,15 @@ function serverCandidates() {
|
|
|
947
954
|
if (location.origin && !list.some(s => s.url === location.origin)) list.push({ id: 'origin', url: location.origin, token: state.token, origin: true })
|
|
948
955
|
return list
|
|
949
956
|
}
|
|
950
|
-
|
|
957
|
+
function pingServer(base, token) {
|
|
951
958
|
const u = String(base || '').replace(/\/+$/, '')
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const timer = setTimeout(() => ctrl.abort(), 3500)
|
|
956
|
-
try {
|
|
957
|
-
const res = await fetch(u + '/health?probe=live&t=' + Date.now(), { signal: ctrl.signal, cache: 'no-store' })
|
|
958
|
-
if (!res.ok) return Infinity
|
|
959
|
-
const health = await res.json().catch(() => null)
|
|
960
|
-
if (health && typeof health === 'object') {
|
|
959
|
+
return DshNetwork.probeGateway(u, {
|
|
960
|
+
headers: token === undefined ? undefined : { authorization: token ? 'Bearer ' + token : '', 'x-dsh-remote-client': 'web', ...clientIdHeaders() },
|
|
961
|
+
onHealth: health => {
|
|
961
962
|
state.gatewayHealth[u] = health
|
|
962
963
|
renderOverviewDesktop()
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
} catch { return Infinity } finally { clearTimeout(timer) }
|
|
964
|
+
},
|
|
965
|
+
})
|
|
966
966
|
}
|
|
967
967
|
function activeGatewayCapability(name) {
|
|
968
968
|
const capabilities = activeGatewayHealth()?.capabilities
|
|
@@ -995,7 +995,7 @@ async function selectFastestServer({ silent = false, reconnect = true } = {}) {
|
|
|
995
995
|
let best = null
|
|
996
996
|
let ms = Infinity
|
|
997
997
|
if (state.autoSelect[state.activeGroup] !== false) {
|
|
998
|
-
const measured = await Promise.all(candidates.map(async
|
|
998
|
+
const measured = await Promise.all(candidates.map(async server => [server, await pingServer(server.url, server.token)]))
|
|
999
999
|
if (!valid()) return null
|
|
1000
1000
|
for (const [server, latency] of measured) state.serverLatency[serverKey(server)] = latency
|
|
1001
1001
|
best = candidates.filter(server => Number.isFinite(state.serverLatency[serverKey(server)])).sort((a, b) => state.serverLatency[serverKey(a)] - state.serverLatency[serverKey(b)])[0] || null
|
|
@@ -1613,6 +1613,7 @@ setInterval(sessionSyncTick, 15000)
|
|
|
1613
1613
|
function onMuxFrame(full) {
|
|
1614
1614
|
const f = full.payload
|
|
1615
1615
|
if (!f) return
|
|
1616
|
+
if (typeof planReviewController !== 'undefined') planReviewController?.handleFrame?.(full)
|
|
1616
1617
|
if (f.type === 'session/reasoning') {
|
|
1617
1618
|
if (f.sessionId === state.current) { applyReasoningBaseline(f.partialReasoning); scheduleReasoningRender() }
|
|
1618
1619
|
return
|
|
@@ -1629,22 +1630,37 @@ function onMuxFrame(full) {
|
|
|
1629
1630
|
if (f.type === 'question/requested') {
|
|
1630
1631
|
state.questions = state.questions.filter(q => q.rpcId !== full.rpcId)
|
|
1631
1632
|
state.questions.push({ ...f, rpcId: full.rpcId })
|
|
1632
|
-
renderNotifStack()
|
|
1633
|
+
renderNotifStack(); if (typeof refreshPlanReview === 'function') refreshPlanReview()
|
|
1633
1634
|
return
|
|
1634
1635
|
}
|
|
1635
1636
|
if (f.type === 'question/resolved') {
|
|
1636
1637
|
state.questions = state.questions.filter(q => q.rpcId !== f.questionRpcId)
|
|
1637
1638
|
if (state.questionModal?.rpcId === f.questionRpcId) { $('modal-question').classList.add('hidden'); state.questionModal = null }
|
|
1638
|
-
renderNotifStack(); return
|
|
1639
|
+
renderNotifStack(); if (typeof refreshPlanReview === 'function') refreshPlanReview(); return
|
|
1640
|
+
}
|
|
1641
|
+
if (f.type === 'session/queue') {
|
|
1642
|
+
if (hostQueue?.accept(f.sessionId, f.seq) !== false) state.queues[f.sessionId] = f.items || []
|
|
1643
|
+
renderQueue(); return
|
|
1644
|
+
}
|
|
1645
|
+
if (f.type === 'session/projection') {
|
|
1646
|
+
applyProjection(f.sessionId, f.key, f.value, f.seq)
|
|
1647
|
+
if (f.key === 'plan' && f.sessionId === state.current && typeof refreshPlanReview === 'function') refreshPlanReview()
|
|
1648
|
+
if (f.key === 'conversationContinuation' && f.sessionId === state.current) renderHistory()
|
|
1649
|
+
if (f.key === 'agentTeam') window.DshSubagents?.updateTeam?.(f.sessionId, f.value, f.seq)
|
|
1650
|
+
return
|
|
1639
1651
|
}
|
|
1640
|
-
if (f.type === 'session/queue') { state.queues[f.sessionId] = f.items || []; renderQueue(); return }
|
|
1641
|
-
if (f.type === 'session/projection') { applyProjection(f.sessionId, f.key, f.value, f.seq); return }
|
|
1642
1652
|
if (f.type === 'stream/error') toast(f.error?.message || 'stream error', 'err')
|
|
1643
1653
|
if (f.type === 'session/stream-error' && f.sessionId === state.current) { const message=f.error?.code==='session/migration-required'?t('session.migrationRequired'):f.error?.message;setSessionRecovery('error',message);toast(message,'err') }
|
|
1644
1654
|
}
|
|
1645
1655
|
function onHostFrame(full) {
|
|
1646
1656
|
const f = full.payload
|
|
1647
1657
|
if (!f) return
|
|
1658
|
+
if (f.type === 'schedule/changed') { void hostSchedule?.refresh(true); return }
|
|
1659
|
+
if (f.type === 'host/pinned-sessions-changed') {
|
|
1660
|
+
state.pinnedIds = Array.isArray(f.pinnedSessionIds) ? f.pinnedSessionIds : []
|
|
1661
|
+
renderSessions()
|
|
1662
|
+
return
|
|
1663
|
+
}
|
|
1648
1664
|
if (['host/session-added', 'host/session-removed', 'host/workspace-changed', 'host/workspace-removed', 'host/workspace-order-changed', 'host/archived-sessions-changed'].includes(f.type)) scheduleSessionsRefresh()
|
|
1649
1665
|
if (f.type === 'host/session-activity') {
|
|
1650
1666
|
const session = state.byId.get(f.sessionId)
|
|
@@ -1861,8 +1877,10 @@ function rememberRuntimeError(sessionId, message) {
|
|
|
1861
1877
|
if (sessionId === state.current) { renderHistory(); scheduleSessionSync(sessionId) }
|
|
1862
1878
|
}
|
|
1863
1879
|
function resyncAfterStreamOpen() {
|
|
1880
|
+
if (typeof hostSchedule !== 'undefined') void hostSchedule?.refresh(true)
|
|
1864
1881
|
if (!state.current || Date.now() - state.lastStreamResyncAt < 1200) return
|
|
1865
1882
|
state.lastStreamResyncAt = Date.now()
|
|
1883
|
+
if (typeof hostQueue !== 'undefined') hostQueue?.reconnect()
|
|
1866
1884
|
void refreshSessions().then(() => resyncCurrentSession())
|
|
1867
1885
|
}
|
|
1868
1886
|
function proj(s, key, d) { return s?.projections?.values?.[key] ?? d }
|
|
@@ -1945,6 +1963,8 @@ function setGoalCollapsed(sessionId, goal, collapsed) {
|
|
|
1945
1963
|
LS.set(COLLAPSED_GOALS_KEY, JSON.stringify(next.slice(-100)))
|
|
1946
1964
|
}
|
|
1947
1965
|
function onSessionEvent(sessionId, event, meta = {}) {
|
|
1966
|
+
if (typeof planReviewController !== 'undefined') planReviewController?.handleEvent?.(sessionId, event)
|
|
1967
|
+
if (typeof turnDiffController !== 'undefined') turnDiffController?.handleEvent?.(sessionId, event)
|
|
1948
1968
|
if (collectApprovalEvent(sessionId, event)) renderApprovalRecordsDesktop()
|
|
1949
1969
|
observeCompactionEvent(sessionId, event, meta)
|
|
1950
1970
|
const failedSession = state.byId.get(sessionId)
|
|
@@ -2011,6 +2031,7 @@ async function refreshSessions() {
|
|
|
2011
2031
|
renderSessions()
|
|
2012
2032
|
scheduleWorkbenchRefresh()
|
|
2013
2033
|
renderOverviewDesktop()
|
|
2034
|
+
if (typeof sessionManager !== 'undefined') sessionManager?.hydrate?.()
|
|
2014
2035
|
}
|
|
2015
2036
|
function sessionCwd(s) { return typeof s?.cwd === 'string' ? s.cwd.trim() : '' }
|
|
2016
2037
|
function sessionWorkspaceLabel(s) {
|
|
@@ -2043,15 +2064,19 @@ function workspaceDisplayName(label) {
|
|
|
2043
2064
|
}
|
|
2044
2065
|
function sortedSessions() {
|
|
2045
2066
|
const items = topLevelSessions()
|
|
2067
|
+
const pinned = new Set(state.pinnedIds || [])
|
|
2068
|
+
const pinRank = session => pinned.has(session.sessionId) ? 0 : 1
|
|
2046
2069
|
if (state.sessionSort === 'workspace') {
|
|
2047
2070
|
return items.sort((a, b) => {
|
|
2071
|
+
const byPin = pinRank(a) - pinRank(b)
|
|
2072
|
+
if (byPin) return byPin
|
|
2048
2073
|
const aw = sessionCwd(a) || '\uffff'
|
|
2049
2074
|
const bw = sessionCwd(b) || '\uffff'
|
|
2050
2075
|
const byWorkspace = aw.localeCompare(bw, undefined, { numeric: true, sensitivity: 'base' })
|
|
2051
2076
|
return byWorkspace || (sessionSortTime(b) - sessionSortTime(a))
|
|
2052
2077
|
})
|
|
2053
2078
|
}
|
|
2054
|
-
return items.sort((a, b) => sessionSortTime(b) - sessionSortTime(a))
|
|
2079
|
+
return items.sort((a, b) => pinRank(a) - pinRank(b) || sessionSortTime(b) - sessionSortTime(a))
|
|
2055
2080
|
}
|
|
2056
2081
|
function renderSessions() {
|
|
2057
2082
|
const allItems = sortedSessions()
|
|
@@ -2059,6 +2084,7 @@ function renderSessions() {
|
|
|
2059
2084
|
if (state.wb.bound && state.wb.projects) for (const w of state.wb.projects) for (const id of (w.sessionIds || [])) wbIds.add(id)
|
|
2060
2085
|
const root = state.wb.bound ? state.wb.path : ''
|
|
2061
2086
|
const archivedSet = new Set(state.archivedIds || [])
|
|
2087
|
+
const pinnedSet = new Set(state.pinnedIds || [])
|
|
2062
2088
|
const visible = allItems.filter(s => {
|
|
2063
2089
|
if (!state.wb.bound) return true
|
|
2064
2090
|
if (archivedSet.has(s.sessionId)) return true
|
|
@@ -2072,7 +2098,7 @@ function renderSessions() {
|
|
|
2072
2098
|
const workspaceName = workspaceDisplayName(workspace)
|
|
2073
2099
|
const title = sessionLabelOf(s)
|
|
2074
2100
|
return `<button class="ds-session-item ${state.current === s.sessionId ? 'current' : ''}" data-id="${esc(s.sessionId)}">
|
|
2075
|
-
<span class="ds-session-title">${esc(title)}</span>
|
|
2101
|
+
<span class="ds-session-title">${pinnedSet.has(s.sessionId) ? '<span class="ds-session-pin" aria-label="' + esc(t('ds.pinnedSession')) + '">📌</span> ' : ''}${esc(title)}</span>
|
|
2076
2102
|
<span class="ds-session-workspace" title="${esc(workspace)}">⌂ ${esc(workspaceName)}</span>
|
|
2077
2103
|
<span class="ds-session-meta"><span class="ds-session-dot ${s.running ? 'running' : ''}"></span>${fmtTime(sessionSortTime(s))}</span>
|
|
2078
2104
|
</button>`
|
|
@@ -2156,6 +2182,8 @@ async function openSession(id) {
|
|
|
2156
2182
|
if (state.current && state.current !== id) void archiveEmptySessionOnLeave(state.current,true)
|
|
2157
2183
|
cancelHistoryLoad()
|
|
2158
2184
|
state.current = id
|
|
2185
|
+
if (typeof syncComposerToolsScope === 'function') syncComposerToolsScope()
|
|
2186
|
+
if (typeof planReviewController !== 'undefined') planReviewController?.setSession?.(id)
|
|
2159
2187
|
setSessionRecovery('loading')
|
|
2160
2188
|
state.history = emptyDesktopHistory()
|
|
2161
2189
|
const openingHistory=state.history, openingConnection=captureConnection()
|
|
@@ -2169,6 +2197,7 @@ async function openSession(id) {
|
|
|
2169
2197
|
renderSessionCards()
|
|
2170
2198
|
renderQueue()
|
|
2171
2199
|
renderSessionPendingDesktop()
|
|
2200
|
+
if (typeof hostQueue !== 'undefined') hostQueue?.reconnect()
|
|
2172
2201
|
updateComposerStatus()
|
|
2173
2202
|
void refreshCompactionStatus(id)
|
|
2174
2203
|
try { const restored=await restoreCachedHistory();globalThis.DshDiagnostics?.record('history.cache',{phase:restored?'hit':'miss',sessionId:id}) } catch(error) {
|
|
@@ -2193,6 +2222,10 @@ async function closeSession() {
|
|
|
2193
2222
|
cancelHistoryLoad()
|
|
2194
2223
|
const cleanup=sessionId&&!wasLoading&&state.history.loaded&&!state.history.loading&&!state.history.renderError
|
|
2195
2224
|
state.current = null
|
|
2225
|
+
if (typeof syncComposerToolsScope === 'function') syncComposerToolsScope()
|
|
2226
|
+
if (typeof planReviewController !== 'undefined') planReviewController?.setSession?.(null)
|
|
2227
|
+
if (typeof turnDiffController !== 'undefined') turnDiffController?.setSession?.(null)
|
|
2228
|
+
if (typeof planReviewHost !== 'undefined') planReviewHost?.classList.add('hidden')
|
|
2196
2229
|
setSessionRecovery('idle')
|
|
2197
2230
|
state.history = emptyDesktopHistory()
|
|
2198
2231
|
showView('view-sessions')
|
|
@@ -2350,11 +2383,12 @@ async function loadHistory(reset = true) {
|
|
|
2350
2383
|
|
|
2351
2384
|
const INTERESTING_EVENTS = new Set([
|
|
2352
2385
|
'turn/start', 'turn/end',
|
|
2353
|
-
'user/message', 'assistant/message', 'assistant/attempt', 'tool/call', 'tool/result',
|
|
2386
|
+
'user/message', 'assistant/message', 'assistant/attempt', 'tool/call', 'tool/result', 'tool/ptc-dispatch-start', 'tool/ptc-dispatch',
|
|
2354
2387
|
'agent/status', 'checkpoint/created', 'compaction/complete', 'compaction/summary',
|
|
2355
2388
|
'goal/created', 'goal/updated', 'goal/completed', 'goal/cleared',
|
|
2356
2389
|
'todo/updated', 'plan/updated', 'question/asked', 'question/resolved',
|
|
2357
|
-
'approval/asked', 'approval/resolved'
|
|
2390
|
+
'approval/asked', 'approval/resolved',
|
|
2391
|
+
'deliverables/presented', 'workspace/changes'
|
|
2358
2392
|
])
|
|
2359
2393
|
function messageSource(data) {
|
|
2360
2394
|
const source = data?.source ?? data?.message?.source
|
|
@@ -2461,30 +2495,21 @@ function systemReminderText(blocks) {
|
|
|
2461
2495
|
.map(b => String(b.text ?? ''))
|
|
2462
2496
|
.join('\n')
|
|
2463
2497
|
}
|
|
2464
|
-
function activityGroupHtml(group) {
|
|
2465
|
-
const items = group.items || []
|
|
2466
|
-
if (!items.length) return ''
|
|
2467
|
-
const tools = items.filter(item => item.kind === 'tool').map(item => item.entry)
|
|
2468
|
-
const running = !!group.running
|
|
2469
|
-
const failed = tools.some(entry => entry.view?.toolActivity?.error || entry.event?.data?.error)
|
|
2470
|
-
const body = items.map(item => item.kind === 'reasoning'
|
|
2471
|
-
? window.DshActivity.reasoning({ text: item.text, key: item.key })
|
|
2472
|
-
: eventHtml(item.entry)).join('')
|
|
2473
|
-
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('ds.activity.group', { n: items.length }))}</span>${running ? `<span class="activity-group-live"><i aria-hidden="true"></i>${esc(t('ds.activity.groupRunning'))}</span>` : ''}<span class="activity-chevron" aria-hidden="true"></span></summary><div class="activity-group-body">${body}</div></details>`
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
2498
|
function eventHtml(entry) {
|
|
2477
2499
|
if (entry.view?.failureGroup) return window.DshActivity.failureGroupHtml(entry.view.failureGroup, item => eventHtml(item))
|
|
2478
2500
|
const ev = entry.event || {}
|
|
2479
2501
|
const data = ev.data || {}
|
|
2480
2502
|
const type = ev.type || 'event'
|
|
2481
|
-
const failure = window.DshActivity?.failureHtml?.(window.DshActivity.failure(ev)) || ''
|
|
2503
|
+
const failure = window.DshActivity?.failureHtml?.(window.DshActivity.failure(ev), false, entry.view?.continuation) || ''
|
|
2482
2504
|
if (entry.view?.turnResult) return failure + window.DshTurnResults.html(entry.view.turnResult)
|
|
2483
|
-
if (type === 'turn/start'
|
|
2505
|
+
if (type === 'turn/start') return failure
|
|
2506
|
+
if (type === 'turn/end') return failure + (entry.view?.turnDiffHtml || '')
|
|
2507
|
+
if (type === 'deliverables/presented' || type === 'workspace/changes') return ''
|
|
2484
2508
|
if (type === 'assistant/attempt') return window.DshActivity?.attemptHtml?.(ev) || ''
|
|
2485
|
-
if (entry.view?.
|
|
2509
|
+
if (entry.view?.activityTurn) return window.DshActivity.turnHtml(entry.view.activityTurn)
|
|
2510
|
+
if (entry.view?.activityGroup) return window.DshActivity.groupHtml(entry.view.activityGroup, eventHtml)
|
|
2486
2511
|
if (!shouldShowEvent(type, ev)) return ''
|
|
2487
|
-
if (window.DshActivity
|
|
2512
|
+
if (window.DshActivity?.isToolEvent?.(type)) return window.DshActivity.toolEvent(entry)
|
|
2488
2513
|
if (type === 'user/message' || type === 'assistant/message') {
|
|
2489
2514
|
const msg = data.message || {}
|
|
2490
2515
|
const role = data.role || msg.role || (type.startsWith('user') ? 'user' : 'assistant')
|
|
@@ -2497,7 +2522,7 @@ function eventHtml(entry) {
|
|
|
2497
2522
|
if (type === 'user/message' && !isHumanUserMessage(ev)) return ''
|
|
2498
2523
|
const text = blocks.map((block,index)=>blockHtml(block,index,{...data,seq:entry.seq,suppressBlockTools:state.history.suppressBlockTools})).join('')
|
|
2499
2524
|
if (!text) return ''
|
|
2500
|
-
return `<div class="ds-msg ${esc(role)}"><div class="role">${esc(role === 'user' ? t('ds.role.me') : t('ds.role.dsh'))}</div>${text}</div>`
|
|
2525
|
+
return `<div class="ds-msg ${esc(role)}" data-seq="${esc(entry.seq)}"><div class="role">${esc(role === 'user' ? t('ds.role.me') : t('ds.role.dsh'))}</div>${text}</div>`
|
|
2501
2526
|
}
|
|
2502
2527
|
if (type === 'tool/call') {
|
|
2503
2528
|
const name = data.name || data.toolName || t('ds.toolDefault')
|
|
@@ -2541,6 +2566,7 @@ function bindTurnResultActions() {
|
|
|
2541
2566
|
if (!state.byId.has(id)) {
|
|
2542
2567
|
const branch = { ...parent, projections: parent?.projections ? { ...JSON.parse(JSON.stringify(parent.projections)), asOfSeq: 0 } : undefined,
|
|
2543
2568
|
sessionId: id, parentSessionId: context.sessionId, origin: 'fork', running: false, blank: false }
|
|
2569
|
+
if (branch.projections?.values) delete branch.projections.values.conversationContinuation
|
|
2544
2570
|
state.byId.set(id, branch)
|
|
2545
2571
|
state.sessions.unshift(branch)
|
|
2546
2572
|
renderSessions()
|
|
@@ -2554,21 +2580,47 @@ function renderHistory(reset=false, mode='auto') {
|
|
|
2554
2580
|
let prepared=window.DshActivity?.prepare(state.history.visible)||state.history.visible
|
|
2555
2581
|
if(weakStreamTrim())prepared=prepared.filter(entry=>entry.event?.type!=='tool/call'||entry.view?.toolActivity)
|
|
2556
2582
|
state.history.suppressBlockTools = state.history.visible.some(entry => entry.event?.type === 'tool/call')
|
|
2557
|
-
|
|
2558
|
-
const
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2583
|
+
const activity = window.DshActivity
|
|
2584
|
+
const groupLive = activity?.group && !weakStreamTrim()
|
|
2585
|
+
if(activity?.group)prepared=activity.group(prepared, {
|
|
2586
|
+
liveReasoning: groupLive ? [...state.history.partialReasoning.values()] : [],
|
|
2587
|
+
running: !!state.byId.get(state.current)?.running,
|
|
2588
|
+
suppressBlockTools: state.history.suppressBlockTools,
|
|
2589
|
+
})
|
|
2562
2590
|
if (window.DshTurnResults) {
|
|
2563
2591
|
prepared = window.DshTurnResults.decorate(prepared, state.history.visible, { sessionId: state.current, canFork: canForkTurnResult() })
|
|
2564
2592
|
bindTurnResultActions()
|
|
2565
2593
|
}
|
|
2594
|
+
if (typeof turnDiffController !== 'undefined' && turnDiffController) {
|
|
2595
|
+
turnDiffController.setLayout('desktop')
|
|
2596
|
+
turnDiffController.setSession(state.current)
|
|
2597
|
+
if (typeof turnDiffHtmlFor === 'function') prepared = prepared.map(entry => ({ ...entry, view: { ...entry.view, turnDiffHtml: turnDiffHtmlFor(entry) } }))
|
|
2598
|
+
}
|
|
2599
|
+
if (activity?.withContinuation && activeGatewayCapability('sessionContinuation') === true) {
|
|
2600
|
+
const sessionId = state.current, history = state.history, connection = captureConnection()
|
|
2601
|
+
const session = state.byId.get(sessionId)
|
|
2602
|
+
prepared = activity.withContinuation($('history'), prepared, {
|
|
2603
|
+
history, ending: session && session.origin !== 'subagent' && session.formatStatus !== 'migration-required'
|
|
2604
|
+
&& !(state.archivedIds || []).includes(sessionId)
|
|
2605
|
+
? proj(session, 'conversationContinuation') : undefined,
|
|
2606
|
+
valid: () => connection.valid() && state.current === sessionId && state.history === history,
|
|
2607
|
+
render: () => renderHistory(),
|
|
2608
|
+
submit: ending => rpc('session.continue', { sessionId, ending }),
|
|
2609
|
+
failed: error => {
|
|
2610
|
+
if (error.operationPending) notifyPendingOperation(error, connection)
|
|
2611
|
+
else if (connection.valid() && state.current === sessionId && state.history === history) {
|
|
2612
|
+
toast(error.message, 'err'); void resyncCurrentSession()
|
|
2613
|
+
}
|
|
2614
|
+
},
|
|
2615
|
+
})
|
|
2616
|
+
}
|
|
2566
2617
|
if(window.DshActivity?.groupFailures)prepared=window.DshActivity.groupFailures(prepared)
|
|
2567
2618
|
const hostError = state.runtimeErrors?.get(state.current)
|
|
2568
2619
|
const recordedError = state.history.visible.some(entry => window.DshActivity?.failure?.(entry.event)?.message === hostError)
|
|
2569
2620
|
const runtimeHtml = hostError && !recordedError ? window.DshActivity?.failureHtml?.(hostError) || '' : ''
|
|
2570
|
-
getConversationView().set(prepared,{reset,follow:mode==='bottom',live:partialReasoningHtml()+runtimeHtml,hasMore:state.history.hasMore,loading:state.history.loading,emptyLabel:t('ds.historyEmpty')})
|
|
2621
|
+
getConversationView().set(prepared,{reset,follow:mode==='bottom',live:(groupLive?'':partialReasoningHtml())+runtimeHtml,hasMore:state.history.hasMore,loading:state.history.loading,emptyLabel:t('ds.historyEmpty')})
|
|
2571
2622
|
window.DshImagePreview?.hydrate?.($('history'))
|
|
2623
|
+
if (typeof refreshPlanReview === 'function') refreshPlanReview()
|
|
2572
2624
|
}
|
|
2573
2625
|
window.applyStreamPreference=()=>{if(state.current)renderHistory(false,'auto')}
|
|
2574
2626
|
|
|
@@ -2710,7 +2762,7 @@ async function interruptSubagent(childId, parentId = state.current) {
|
|
|
2710
2762
|
const result = await safeRpc('subagent.interrupt', { parentSessionId: parentId, childSessionId: childId, mode: 'continuable' }, t('subagent.interruptFailed'))
|
|
2711
2763
|
if (result == null || !connection.valid() || state.current !== rootId) return
|
|
2712
2764
|
toast(t('subagent.interruptSubmitted'), 'ok')
|
|
2713
|
-
|
|
2765
|
+
return true
|
|
2714
2766
|
}
|
|
2715
2767
|
|
|
2716
2768
|
const NO_FALLBACK_SLASH_COMMANDS = new Set(['compact', 'export'])
|
|
@@ -2826,9 +2878,13 @@ async function waitCommandOperation(sessionId, initial, connection) {
|
|
|
2826
2878
|
}
|
|
2827
2879
|
|
|
2828
2880
|
async function sendMessage(requestedMode = 'queue') {
|
|
2881
|
+
if (typeof window !== 'undefined') window.DshSlashSuggestions?.close()
|
|
2829
2882
|
if (state.byId.get(state.current)?.origin === 'subagent') { toast('子代理记录为只读 / Subagent records are read only'); return false }
|
|
2830
2883
|
const input = $('composer')
|
|
2831
|
-
const originalText = input.value,
|
|
2884
|
+
const originalText = input.value, clean = originalText.trim()
|
|
2885
|
+
const quoted = clean && !clean.startsWith('/') && typeof composerTools !== 'undefined' ? composerTools?.quotes() || [] : []
|
|
2886
|
+
const quoteText = quoted.length ? window.DshComposerTools.formatQuotes(quoted) : ''
|
|
2887
|
+
const text = [quoteText, clean].filter(Boolean).join('\n\n')
|
|
2832
2888
|
if (!text || !state.current) return
|
|
2833
2889
|
const sessionId = state.current, connection = captureConnection(), history = state.history
|
|
2834
2890
|
const pending = sendMessage.pending ||= new Set()
|
|
@@ -2837,7 +2893,7 @@ async function sendMessage(requestedMode = 'queue') {
|
|
|
2837
2893
|
const valid = () => connection.valid() && state.current === sessionId && state.history === history
|
|
2838
2894
|
try {
|
|
2839
2895
|
state.sessionActivity.add(sessionId)
|
|
2840
|
-
if (await runSlashCommand(
|
|
2896
|
+
if (await runSlashCommand(clean)) { if (valid() && input.value === originalText) input.value = ''; return }
|
|
2841
2897
|
if (!valid()) return
|
|
2842
2898
|
setSessionRecovery('resuming')
|
|
2843
2899
|
const v = await safeRpc('session.prompt', {
|
|
@@ -2848,6 +2904,7 @@ async function sendMessage(requestedMode = 'queue') {
|
|
|
2848
2904
|
if (!valid()) return
|
|
2849
2905
|
if (v?.accepted) {
|
|
2850
2906
|
if (input.value === originalText) input.value = ''
|
|
2907
|
+
if (quoted.length) composerTools?.clearQuotes(quoted.map(quote => quote.id))
|
|
2851
2908
|
setSessionRecovery('ready'); noteSessionTurnTime(sessionId, Date.now()); renderSessions(); toast(t('ds.toastSent'), 'ok')
|
|
2852
2909
|
}
|
|
2853
2910
|
else setSessionRecovery('error')
|
|
@@ -2926,43 +2983,28 @@ function updateComposerStatus() {
|
|
|
2926
2983
|
: t('ds.composerRunning')
|
|
2927
2984
|
updateSessionActions()
|
|
2928
2985
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
if (
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2986
|
+
const hostAccess = connection => window.DshHostQueue.readAccess(connection, apiUrl)
|
|
2987
|
+
const hostQueue = window.DshHostQueue?.create({ rpc, access: hostAccess, capture: captureConnection, box: () => $('queue-dock'),
|
|
2988
|
+
session: () => state.current, items: () => state.queues[state.current], running: () => !!state.byId.get(state.current)?.running,
|
|
2989
|
+
apply(sessionId, snapshot) {
|
|
2990
|
+
state.queues[sessionId] = snapshot.items
|
|
2991
|
+
const session = state.byId.get(sessionId)
|
|
2992
|
+
if (session) session.running = snapshot.running
|
|
2993
|
+
},
|
|
2994
|
+
})
|
|
2995
|
+
const hostSchedule = window.DshHostSchedule?.create({ rpc, access: hostAccess, capture: captureConnection, box: () => $('view-schedule'),
|
|
2996
|
+
workspaces: workspaceItems,
|
|
2997
|
+
sessions: () => state.sessions.filter(row => row.origin !== 'subagent' && !state.archivedIds.includes(row.sessionId)).map(row => ({ id: row.sessionId, label: titleOf(row) })),
|
|
2998
|
+
async openSession(id) {
|
|
2999
|
+
const connection = captureConnection()
|
|
3000
|
+
await refreshSessions()
|
|
3001
|
+
if (!connection.valid()) return
|
|
3002
|
+
if (!state.byId.has(id)) return toast(t('ds.sessionUntitled'), 'err')
|
|
3003
|
+
await openSession(id)
|
|
3004
|
+
},
|
|
3005
|
+
})
|
|
2951
3006
|
function renderQueue() {
|
|
2952
|
-
|
|
2953
|
-
if (!box) return
|
|
2954
|
-
const sessionId = state.current
|
|
2955
|
-
const s = state.byId.get(sessionId)
|
|
2956
|
-
const items = (state.queues[sessionId] || []).filter(item => item?.placement === 'queued')
|
|
2957
|
-
box.classList.toggle('hidden', !items.length)
|
|
2958
|
-
box.innerHTML = items.length ? `<div class="ds-queue-dock-head"><span>⌁</span><span>${esc(t('queue.title'))} · ${items.length}</span></div><div class="ds-queue-dock-list">${items.map(item => {
|
|
2959
|
-
const key = `${sessionId}:${item.id}`
|
|
2960
|
-
const busy = !!state.queueSteering[key]
|
|
2961
|
-
return `<div class="ds-queue-dock-item"><span class="ds-queue-dock-preview" title="${esc(queuePreview(item))}">${esc(queuePreview(item))}</span><button type="button" class="ds-mini-btn ds-queue-dock-action" data-queue-steer="${esc(item.id)}" title="${esc(s?.running ? t('queue.steer') : t('queue.steerUnavailable'))}" ${s?.running && !busy ? '' : 'disabled'}>${busy ? '…' : esc(t('queue.steer'))}</button></div>`
|
|
2962
|
-
}).join('')}</div>` : ''
|
|
2963
|
-
box.querySelectorAll('[data-queue-steer]').forEach(button => {
|
|
2964
|
-
button.addEventListener('click', () => steerQueueItem(button.dataset.queueSteer))
|
|
2965
|
-
})
|
|
3007
|
+
hostQueue?.render()
|
|
2966
3008
|
updateComposerStatus()
|
|
2967
3009
|
}
|
|
2968
3010
|
|
|
@@ -3139,6 +3181,11 @@ function questionMarkup(item) {
|
|
|
3139
3181
|
|
|
3140
3182
|
function openQuestionModal(q) {
|
|
3141
3183
|
if (!q) return
|
|
3184
|
+
if (typeof isPlanReviewQuestion === 'function' && isPlanReviewQuestion(q)) {
|
|
3185
|
+
if (typeof refreshPlanReview === 'function') refreshPlanReview()
|
|
3186
|
+
if (typeof planReviewHost !== 'undefined') planReviewHost?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })
|
|
3187
|
+
return
|
|
3188
|
+
}
|
|
3142
3189
|
state.questionModal = q
|
|
3143
3190
|
$('question-body').innerHTML = q.questions.map((item, i) => `
|
|
3144
3191
|
<div class="ds-q-item">
|
|
@@ -3181,6 +3228,493 @@ async function submitQuestion() {
|
|
|
3181
3228
|
} else toast(t('ds.stale'), 'err')
|
|
3182
3229
|
}
|
|
3183
3230
|
|
|
3231
|
+
/* ---------------- B/C 输入、搜索与管理 ---------------- */
|
|
3232
|
+
let composerTools = null
|
|
3233
|
+
let sessionSearchController = null
|
|
3234
|
+
let sessionSearchMount = null
|
|
3235
|
+
let sessionManager = null
|
|
3236
|
+
let workspaceAdminMount = null
|
|
3237
|
+
let quoteSelectionButton = null
|
|
3238
|
+
let planReviewController = null
|
|
3239
|
+
let planReviewHost = null
|
|
3240
|
+
let turnDiffController = null
|
|
3241
|
+
let turnDiffRoot = null
|
|
3242
|
+
|
|
3243
|
+
function bcEnglish() { return I18N.lang === 'en' }
|
|
3244
|
+
function bcText(zh, en) { return bcEnglish() ? en : zh }
|
|
3245
|
+
|
|
3246
|
+
async function bcRpc(method, payload, options = {}) {
|
|
3247
|
+
return rpc(method, payload, Number.isFinite(options.timeoutMs) ? options.timeoutMs : 45000, options.signal || null)
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
function composerToolsHost() {
|
|
3251
|
+
return {
|
|
3252
|
+
scope: () => ({ key: JSON.stringify([connectionGeneration, state.current]), sessionId: state.current || '', connection: captureConnection() }),
|
|
3253
|
+
async listReferences(scope, query) {
|
|
3254
|
+
const sessionId = scope?.sessionId || state.current
|
|
3255
|
+
if (!sessionId) return null
|
|
3256
|
+
const [files, sessions] = await Promise.allSettled([
|
|
3257
|
+
bcRpc('fileReferences.list', { sessionId, query: String(query || '') }, { timeoutMs: 12000 }),
|
|
3258
|
+
bcRpc('sessionReferenceResolver.candidates', { sessionId, query: String(query || '') }, { timeoutMs: 12000 }),
|
|
3259
|
+
])
|
|
3260
|
+
if (files.status !== 'fulfilled' && sessions.status !== 'fulfilled') return null
|
|
3261
|
+
const references = []
|
|
3262
|
+
if (files.status === 'fulfilled' && Array.isArray(files.value)) {
|
|
3263
|
+
for (const row of files.value) {
|
|
3264
|
+
const insert = window.DshComposerTools.fileReferenceMention(row)
|
|
3265
|
+
if (!insert) continue
|
|
3266
|
+
references.push({
|
|
3267
|
+
insert,
|
|
3268
|
+
label: row?.kind === 'directory' ? String(row?.path || '') + '/' : String(row?.path || ''),
|
|
3269
|
+
detail: row?.kind === 'directory' ? bcText('目录', 'Directory') : bcText('文件', 'File'),
|
|
3270
|
+
kind: 'file',
|
|
3271
|
+
allowed: true,
|
|
3272
|
+
})
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
if (sessions.status === 'fulfilled' && Array.isArray(sessions.value)) {
|
|
3276
|
+
for (const row of sessions.value) {
|
|
3277
|
+
if (typeof row?.mention !== 'string' || !row.mention.startsWith('@')) continue
|
|
3278
|
+
references.push({
|
|
3279
|
+
insert: row.mention,
|
|
3280
|
+
label: row.displayTitle || row.label || row.sessionId || '',
|
|
3281
|
+
detail: row.cwd || '',
|
|
3282
|
+
kind: 'session',
|
|
3283
|
+
allowed: true,
|
|
3284
|
+
})
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
return { supported: true, references }
|
|
3288
|
+
},
|
|
3289
|
+
notice: (text, kind) => toast(text, kind === 'err' ? 'err' : ''),
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
function selectedMessageQuote() {
|
|
3294
|
+
const selection = window.getSelection?.()
|
|
3295
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null
|
|
3296
|
+
const range = selection.getRangeAt(0)
|
|
3297
|
+
const history = $('history')
|
|
3298
|
+
if (!history || !range.commonAncestorContainer) return null
|
|
3299
|
+
const startNode = range.startContainer.nodeType === 3 ? range.startContainer.parentElement : range.startContainer
|
|
3300
|
+
const endNode = range.endContainer.nodeType === 3 ? range.endContainer.parentElement : range.endContainer
|
|
3301
|
+
const startMessage = startNode?.closest?.('.ds-msg')
|
|
3302
|
+
const endMessage = endNode?.closest?.('.ds-msg')
|
|
3303
|
+
if (!startMessage || !endMessage || startMessage !== endMessage || !history.contains(startMessage)) return null
|
|
3304
|
+
const text = selection.toString().replace(/\r\n?/g, '\n').trim()
|
|
3305
|
+
if (!text) return null
|
|
3306
|
+
const role = startMessage.classList.contains('user') ? 'user' : startMessage.classList.contains('assistant') ? 'assistant' : ''
|
|
3307
|
+
return { text, role, messageId: startMessage.dataset.seq || '', rect: range.getBoundingClientRect() }
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
function hideQuoteSelectionButton() {
|
|
3311
|
+
if (!quoteSelectionButton) return
|
|
3312
|
+
quoteSelectionButton.hidden = true
|
|
3313
|
+
quoteSelectionButton.classList.add('hidden')
|
|
3314
|
+
}
|
|
3315
|
+
|
|
3316
|
+
function updateQuoteSelectionButton() {
|
|
3317
|
+
if (!quoteSelectionButton || !composerTools) return
|
|
3318
|
+
const selected = selectedMessageQuote()
|
|
3319
|
+
if (!selected) { hideQuoteSelectionButton(); return }
|
|
3320
|
+
const rect = selected.rect
|
|
3321
|
+
quoteSelectionButton.style.left = Math.max(8, Math.min(window.innerWidth - 150, rect.left + rect.width / 2 - 70)) + 'px'
|
|
3322
|
+
quoteSelectionButton.style.top = Math.max(8, Math.min(window.innerHeight - 56, rect.bottom + 8)) + 'px'
|
|
3323
|
+
quoteSelectionButton.hidden = false
|
|
3324
|
+
quoteSelectionButton.classList.remove('hidden')
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
function initQuoteSelection() {
|
|
3328
|
+
if (quoteSelectionButton) return
|
|
3329
|
+
quoteSelectionButton = document.createElement('button')
|
|
3330
|
+
quoteSelectionButton.type = 'button'
|
|
3331
|
+
quoteSelectionButton.className = 'ct-quote-pick hidden'
|
|
3332
|
+
quoteSelectionButton.hidden = true
|
|
3333
|
+
quoteSelectionButton.textContent = t('ds.quoteSelection')
|
|
3334
|
+
quoteSelectionButton.addEventListener('pointerdown', event => event.preventDefault())
|
|
3335
|
+
quoteSelectionButton.addEventListener('click', event => {
|
|
3336
|
+
event.preventDefault()
|
|
3337
|
+
const selected = selectedMessageQuote()
|
|
3338
|
+
hideQuoteSelectionButton()
|
|
3339
|
+
if (!selected || !composerTools) return
|
|
3340
|
+
composerTools.addQuote({ messageId: selected.messageId, role: selected.role, text: selected.text })
|
|
3341
|
+
window.getSelection?.()?.removeAllRanges?.()
|
|
3342
|
+
toast(t('ds.quoteAdded'), 'ok')
|
|
3343
|
+
})
|
|
3344
|
+
document.body.append(quoteSelectionButton)
|
|
3345
|
+
document.addEventListener('selectionchange', () => {
|
|
3346
|
+
if (document.activeElement === $('composer')) return
|
|
3347
|
+
updateQuoteSelectionButton()
|
|
3348
|
+
})
|
|
3349
|
+
window.addEventListener('scroll', hideQuoteSelectionButton, { passive: true })
|
|
3350
|
+
window.addEventListener('resize', hideQuoteSelectionButton)
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
function initComposerToolsUi() {
|
|
3354
|
+
if (composerTools || !window.DshComposerTools) return
|
|
3355
|
+
const input = $('composer')
|
|
3356
|
+
if (!input) return
|
|
3357
|
+
const anchor = document.createElement('div')
|
|
3358
|
+
anchor.className = 'ct-anchor'
|
|
3359
|
+
const menu = document.createElement('div')
|
|
3360
|
+
menu.id = 'composer-tools-menu'
|
|
3361
|
+
menu.className = 'ct-menu hidden'
|
|
3362
|
+
menu.hidden = true
|
|
3363
|
+
anchor.append(menu)
|
|
3364
|
+
const quotes = document.createElement('div')
|
|
3365
|
+
quotes.id = 'composer-tools-quotes'
|
|
3366
|
+
quotes.className = 'ct-quotes hidden'
|
|
3367
|
+
quotes.hidden = true
|
|
3368
|
+
const hint = document.createElement('p')
|
|
3369
|
+
hint.id = 'composer-tools-hint'
|
|
3370
|
+
hint.className = 'ct-hint hidden'
|
|
3371
|
+
hint.hidden = true
|
|
3372
|
+
input.before(anchor)
|
|
3373
|
+
input.before(quotes)
|
|
3374
|
+
input.before(hint)
|
|
3375
|
+
composerTools = window.DshComposerTools.create({
|
|
3376
|
+
input,
|
|
3377
|
+
menu,
|
|
3378
|
+
hint,
|
|
3379
|
+
quoteList: quotes,
|
|
3380
|
+
host: composerToolsHost(),
|
|
3381
|
+
commands: false,
|
|
3382
|
+
onChange: () => window.DshWorkflow?.update(),
|
|
3383
|
+
})
|
|
3384
|
+
initQuoteSelection()
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
function syncComposerToolsScope() {
|
|
3388
|
+
composerTools?.setScope?.({ key: JSON.stringify([connectionGeneration, state.current]), sessionId: state.current || '', connection: captureConnection() })
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
function initSessionSearchUi() {
|
|
3392
|
+
if (sessionSearchController || !window.DshSessionSearch) return
|
|
3393
|
+
const sort = $('session-sort')
|
|
3394
|
+
const list = $('session-list')
|
|
3395
|
+
if (!sort || !list) return
|
|
3396
|
+
const toggle = document.createElement('button')
|
|
3397
|
+
toggle.id = 'btn-session-search'
|
|
3398
|
+
toggle.type = 'button'
|
|
3399
|
+
toggle.className = 'ds-icon-btn dr-bc-search-toggle'
|
|
3400
|
+
toggle.textContent = '⌕'
|
|
3401
|
+
toggle.title = t('ds.searchSessions')
|
|
3402
|
+
toggle.setAttribute('aria-label', t('ds.searchSessions'))
|
|
3403
|
+
toggle.setAttribute('aria-expanded', 'false')
|
|
3404
|
+
sort.before(toggle)
|
|
3405
|
+
const host = document.createElement('section')
|
|
3406
|
+
host.id = 'session-search-host'
|
|
3407
|
+
host.className = 'hidden'
|
|
3408
|
+
list.before(host)
|
|
3409
|
+
sessionSearchController = window.DshSessionSearch.init({
|
|
3410
|
+
rpc: bcRpc,
|
|
3411
|
+
sessions: () => (state.sessions || []).filter(s => s && s.sessionId && s.origin !== 'subagent' && s.blank !== true),
|
|
3412
|
+
workspaces: () => workspaceItems(),
|
|
3413
|
+
archivedSessionIds: () => state.archivedIds || [],
|
|
3414
|
+
pinnedSessionIds: () => state.pinnedIds || [],
|
|
3415
|
+
titleOf: session => titleOf(session),
|
|
3416
|
+
historyRoot: () => $('history'),
|
|
3417
|
+
openSession: async (sessionId) => { toggleSessionSearch(false); await openSession(sessionId) },
|
|
3418
|
+
notice: message => toast(message),
|
|
3419
|
+
})
|
|
3420
|
+
sessionSearchMount = window.DshSessionSearch.mount(host, sessionSearchController, {
|
|
3421
|
+
onOpen: result => { if (result?.opened) toggleSessionSearch(false) },
|
|
3422
|
+
})
|
|
3423
|
+
toggle.addEventListener('click', () => toggleSessionSearch())
|
|
3424
|
+
updateBcControlLabels()
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
function toggleSessionSearch(force) {
|
|
3428
|
+
const host = $('session-search-host')
|
|
3429
|
+
const button = $('btn-session-search')
|
|
3430
|
+
if (!host || !button || !sessionSearchController) return
|
|
3431
|
+
const open = typeof force === 'boolean' ? force : host.classList.contains('hidden')
|
|
3432
|
+
host.classList.toggle('hidden', !open)
|
|
3433
|
+
button.classList.toggle('is-active', open)
|
|
3434
|
+
button.setAttribute('aria-expanded', String(open))
|
|
3435
|
+
if (open) {
|
|
3436
|
+
sessionSearchController.syncCatalog()
|
|
3437
|
+
sessionSearchMount?.refresh()
|
|
3438
|
+
requestAnimationFrame(() => host.querySelector('[data-dr-search-input]')?.focus())
|
|
3439
|
+
} else hideQuoteSelectionButton()
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
function workspaceRemovalConfirmation(request) {
|
|
3443
|
+
const impact = request?.impact || {}
|
|
3444
|
+
return window.confirm([
|
|
3445
|
+
bcText(`移除工作区登记「${request?.displayTitle || impact.name || ''}」?`, `Remove the workspace registration "${request?.displayTitle || impact.name || ''}"?`),
|
|
3446
|
+
bcText('只删除工作区登记,不删除磁盘目录、文件或会话历史。', 'Only the Workspace registration is removed; directories, files and conversation history stay on disk.'),
|
|
3447
|
+
bcText(`该工作区关联 ${impact.total || 0} 个会话。移除后不再按该工作区分组。`, `${impact.total || 0} conversation(s) are associated. Their Workspace grouping disappears after removal.`),
|
|
3448
|
+
].join('\n\n'))
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
function promptWorkspaceTitle({ workspace, current }) {
|
|
3452
|
+
const value = window.prompt(t('ds.workspaceRenamePrompt'), current || workspace?.title || '')
|
|
3453
|
+
return value == null ? null : String(value)
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
function initSessionManagementUi() {
|
|
3457
|
+
if (sessionManager || !window.DshSessionManagement) return
|
|
3458
|
+
sessionManager = window.DshSessionManagement.init({
|
|
3459
|
+
rpc: bcRpc,
|
|
3460
|
+
sessions: () => state.sessions,
|
|
3461
|
+
workspaces: () => workspaceItems(),
|
|
3462
|
+
archivedSessionIds: () => state.archivedIds || [],
|
|
3463
|
+
pinnedSessionIds: () => state.pinnedIds || [],
|
|
3464
|
+
titleOf: session => titleOf(session),
|
|
3465
|
+
refresh: async () => { await Promise.all([refreshWorkbench({ silent: true }), refreshSessions()]) },
|
|
3466
|
+
confirm: workspaceRemovalConfirmation,
|
|
3467
|
+
promptTitle: promptWorkspaceTitle,
|
|
3468
|
+
toast,
|
|
3469
|
+
})
|
|
3470
|
+
const create = $('btn-new-workspace')
|
|
3471
|
+
const manageButton = document.createElement('button')
|
|
3472
|
+
manageButton.id = 'btn-manage-workspaces'
|
|
3473
|
+
manageButton.type = 'button'
|
|
3474
|
+
manageButton.className = 'ds-icon-btn'
|
|
3475
|
+
manageButton.textContent = '⚙'
|
|
3476
|
+
manageButton.title = t('ds.manageWorkspaces')
|
|
3477
|
+
manageButton.setAttribute('aria-label', t('ds.manageWorkspaces'))
|
|
3478
|
+
create?.before(manageButton)
|
|
3479
|
+
manageButton.addEventListener('click', openWorkspaceAdmin)
|
|
3480
|
+
const dialog = $('session-actions')
|
|
3481
|
+
if (dialog) {
|
|
3482
|
+
const box = document.createElement('div')
|
|
3483
|
+
box.id = 'session-admin-actions'
|
|
3484
|
+
dialog.querySelector('#btn-archive-session')?.before(box)
|
|
3485
|
+
window.DshSessionManagement.bindWorkspaceAdmin(box, sessionManager, {
|
|
3486
|
+
onResult: result => { if (result?.ok) renderSessions() },
|
|
3487
|
+
})
|
|
3488
|
+
}
|
|
3489
|
+
updateBcControlLabels()
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
function ensureWorkspaceAdminModal() {
|
|
3493
|
+
let modal = $('modal-workspace-admin')
|
|
3494
|
+
if (modal) return modal
|
|
3495
|
+
modal = document.createElement('div')
|
|
3496
|
+
modal.id = 'modal-workspace-admin'
|
|
3497
|
+
modal.className = 'ds-modal hidden'
|
|
3498
|
+
modal.setAttribute('role', 'dialog')
|
|
3499
|
+
modal.setAttribute('aria-modal', 'true')
|
|
3500
|
+
modal.innerHTML = `<div class="ds-modal-card"><div class="ds-modal-title" id="workspace-admin-title"></div><div class="ds-modal-body" id="workspace-admin-host"></div><div class="ds-modal-actions"><button type="button" class="ds-btn" data-workspace-admin-close></button></div></div>`
|
|
3501
|
+
document.body.append(modal)
|
|
3502
|
+
modal.addEventListener('click', event => {
|
|
3503
|
+
if (event.target === modal || event.target.closest('[data-workspace-admin-close]')) modal.classList.add('hidden')
|
|
3504
|
+
})
|
|
3505
|
+
return modal
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
function openWorkspaceAdmin() {
|
|
3509
|
+
if (!sessionManager) return
|
|
3510
|
+
const modal = ensureWorkspaceAdminModal()
|
|
3511
|
+
sessionManager.hydrate()
|
|
3512
|
+
if (!workspaceAdminMount) {
|
|
3513
|
+
workspaceAdminMount = window.DshSessionManagement.mountWorkspaceAdmin($('workspace-admin-host'), sessionManager, {
|
|
3514
|
+
promptTitle: promptWorkspaceTitle,
|
|
3515
|
+
onResult: result => { if (result?.ok) { renderSessions(); workspaceAdminMount?.refresh() } },
|
|
3516
|
+
})
|
|
3517
|
+
} else workspaceAdminMount.refresh()
|
|
3518
|
+
updateBcControlLabels()
|
|
3519
|
+
modal.classList.remove('hidden')
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
function refreshSessionAdminActions() {
|
|
3523
|
+
const box = $('session-admin-actions')
|
|
3524
|
+
const session = state.byId.get(state.current)
|
|
3525
|
+
if (!box || !sessionManager || !session) return
|
|
3526
|
+
box.innerHTML = window.DshSessionManagement.renderSessionAdminActions(session, sessionManager.getState())
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
function updateBcControlLabels() {
|
|
3530
|
+
const search = $('btn-session-search')
|
|
3531
|
+
if (search) { search.title = t('ds.searchSessions'); search.setAttribute('aria-label', t('ds.searchSessions')) }
|
|
3532
|
+
const manage = $('btn-manage-workspaces')
|
|
3533
|
+
if (manage) { manage.title = t('ds.manageWorkspaces'); manage.setAttribute('aria-label', t('ds.manageWorkspaces')) }
|
|
3534
|
+
if (quoteSelectionButton) quoteSelectionButton.textContent = t('ds.quoteSelection')
|
|
3535
|
+
const modal = $('modal-workspace-admin')
|
|
3536
|
+
if (modal) {
|
|
3537
|
+
modal.querySelector('#workspace-admin-title').textContent = t('ds.manageWorkspaces')
|
|
3538
|
+
modal.querySelector('[data-workspace-admin-close]').textContent = t('ds.close')
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
function initBcFeatures() {
|
|
3543
|
+
initComposerToolsUi()
|
|
3544
|
+
initSessionSearchUi()
|
|
3545
|
+
initSessionManagementUi()
|
|
3546
|
+
initReviewFeatures()
|
|
3547
|
+
syncComposerToolsScope()
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
function isPlanReviewQuestion(question) {
|
|
3551
|
+
return !!window.DshPlanReview?.planReviewOf?.(question?.questions)
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
function planReviewSnapshot(sessionId) {
|
|
3555
|
+
const session = state.byId.get(sessionId)
|
|
3556
|
+
const plan = session?.projections?.values?.plan
|
|
3557
|
+
return {
|
|
3558
|
+
plan,
|
|
3559
|
+
questions: (state.questions || []).filter(frame => String(frame?.sessionId || '') === String(sessionId || '')),
|
|
3560
|
+
connected: !!state.streamsOk?.mux,
|
|
3561
|
+
readOnly: false,
|
|
3562
|
+
capability: plan === undefined ? undefined : true,
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
function updatePlanReviewVisibility(view) {
|
|
3567
|
+
if (!planReviewHost) return
|
|
3568
|
+
const visible = !!(view?.plan?.supported || view?.review || (Array.isArray(view?.plans) && view.plans.length)
|
|
3569
|
+
|| (state.current && state.history.loaded))
|
|
3570
|
+
planReviewHost.classList.toggle('hidden', !visible)
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
function refreshPlanReview() {
|
|
3574
|
+
if (!planReviewController) return
|
|
3575
|
+
let view = null
|
|
3576
|
+
try { view = planReviewController.render() } catch {}
|
|
3577
|
+
updatePlanReviewVisibility(view)
|
|
3578
|
+
return view
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
function turnDiffEnabled() {
|
|
3582
|
+
return LS.get('turnDiffEnabled', '0') === '1'
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
function turnDiffHtmlFor(entry) {
|
|
3586
|
+
if (!turnDiffController || !turnDiffController.isEnabled()) return ''
|
|
3587
|
+
if (entry?.event?.type !== 'turn/end') return ''
|
|
3588
|
+
const turnNumber = Number(entry.event?.data?.turn)
|
|
3589
|
+
if (!Number.isSafeInteger(turnNumber) || turnNumber < 1) return ''
|
|
3590
|
+
const full = turnDiffController.view()
|
|
3591
|
+
const turns = full.turns.filter(turn => turn.turn === turnNumber)
|
|
3592
|
+
if (!turns.length) return ''
|
|
3593
|
+
return `<div class="dr-diff-turn-slot" data-turn="${turnNumber}">${window.DshTurnDiff.viewHtml({ ...full, turns })}</div>`
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
async function fetchHostChangesJson(path, query) {
|
|
3597
|
+
const url = new URL(apiUrl(path), location.href)
|
|
3598
|
+
for (const [key, value] of Object.entries(query || {})) url.searchParams.set(key, String(value))
|
|
3599
|
+
const res = await fetch(url.href, {
|
|
3600
|
+
headers: { authorization: 'Bearer ' + state.token, 'x-dsh-remote-client': 'web', ...clientIdHeaders() },
|
|
3601
|
+
cache: 'no-store',
|
|
3602
|
+
signal: AbortSignal.timeout(45000),
|
|
3603
|
+
})
|
|
3604
|
+
if (res.status === 401) toast(t('ds.toastAuth'), 'err')
|
|
3605
|
+
let data = null
|
|
3606
|
+
try { data = await res.json() } catch {}
|
|
3607
|
+
return { ok: res.ok, status: res.status, data }
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
let turnDiffActionsBound = false
|
|
3611
|
+
function bindTurnDiffActions() {
|
|
3612
|
+
if (turnDiffActionsBound || !turnDiffController) return
|
|
3613
|
+
const container = $('history')
|
|
3614
|
+
if (!container) return
|
|
3615
|
+
turnDiffActionsBound = true
|
|
3616
|
+
container.addEventListener('click', event => {
|
|
3617
|
+
const button = event.target?.closest?.('[data-dr-diff-action]')
|
|
3618
|
+
if (!button || button.disabled) return
|
|
3619
|
+
const action = button.dataset?.drDiffAction || ''
|
|
3620
|
+
const turn = Number(button.dataset?.drDiffTurn)
|
|
3621
|
+
const index = Number(button.dataset?.drDiffFile)
|
|
3622
|
+
const delivery = Number(button.dataset?.drDiffDelivery)
|
|
3623
|
+
const run = {
|
|
3624
|
+
toggle: () => turnDiffController.toggleTurn(turn),
|
|
3625
|
+
file: () => turnDiffController.selectFile(turn, index),
|
|
3626
|
+
delivery: () => { turnDiffController.openDelivery(turn, delivery); return true },
|
|
3627
|
+
'retry-summary': () => turnDiffController.retrySummary(turn),
|
|
3628
|
+
'retry-diff': () => turnDiffController.retryDiff(turn, index),
|
|
3629
|
+
}[action]
|
|
3630
|
+
if (!run) return
|
|
3631
|
+
const finish = () => { if (state.current) renderHistory(false, 'keep') }
|
|
3632
|
+
try {
|
|
3633
|
+
const result = run()
|
|
3634
|
+
if (result && typeof result.then === 'function') result.then(finish, finish)
|
|
3635
|
+
else finish()
|
|
3636
|
+
} catch { finish() }
|
|
3637
|
+
})
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
function initReviewFeatures() {
|
|
3641
|
+
if (window.DshPlanReview && !planReviewController) {
|
|
3642
|
+
const anchor = $('session-cards')
|
|
3643
|
+
if (anchor) {
|
|
3644
|
+
planReviewHost = document.createElement('section')
|
|
3645
|
+
planReviewHost.id = 'plan-review-host'
|
|
3646
|
+
planReviewHost.className = 'plan-review-host hidden'
|
|
3647
|
+
planReviewHost.setAttribute('aria-live', 'polite')
|
|
3648
|
+
anchor.after(planReviewHost)
|
|
3649
|
+
planReviewController = window.DshPlanReview.create({
|
|
3650
|
+
command: async line => ({ executed: await runSlashCommand(line, true) }),
|
|
3651
|
+
respond: (rpcId, value) => respond(rpcId, value),
|
|
3652
|
+
state: {
|
|
3653
|
+
sessionId: () => state.current,
|
|
3654
|
+
snapshot: sessionId => planReviewSnapshot(sessionId),
|
|
3655
|
+
entries: sessionId => state.current === sessionId ? state.history.visible : [],
|
|
3656
|
+
},
|
|
3657
|
+
dom: { root: planReviewHost },
|
|
3658
|
+
onOpenPlan: () => {},
|
|
3659
|
+
notify: (message, kind) => { if (message) toast(message, kind === 'err' ? 'err' : '') },
|
|
3660
|
+
})
|
|
3661
|
+
updatePlanReviewVisibility(planReviewController.view())
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
if (window.DshTurnDiff && !turnDiffController) {
|
|
3665
|
+
turnDiffRoot = document.createElement('div')
|
|
3666
|
+
turnDiffRoot.hidden = true
|
|
3667
|
+
turnDiffController = window.DshTurnDiff.create({
|
|
3668
|
+
state: {
|
|
3669
|
+
sessionId: () => state.current,
|
|
3670
|
+
entries: sessionId => state.current === sessionId ? state.history.visible : [],
|
|
3671
|
+
},
|
|
3672
|
+
fetchJson: fetchHostChangesJson,
|
|
3673
|
+
dom: { root: turnDiffRoot },
|
|
3674
|
+
layout: 'desktop',
|
|
3675
|
+
enabled: turnDiffEnabled,
|
|
3676
|
+
onOpenFile: ({ path }) => {
|
|
3677
|
+
const name = String(path || '').split(/[\\/]/).pop() || ''
|
|
3678
|
+
if (path && name) openFsPreview(path, name)
|
|
3679
|
+
},
|
|
3680
|
+
notify: (message, kind) => { if (message) toast(message, kind === 'err' ? 'err' : '') },
|
|
3681
|
+
})
|
|
3682
|
+
turnDiffController.setEnabled(turnDiffEnabled())
|
|
3683
|
+
bindTurnDiffActions()
|
|
3684
|
+
}
|
|
3685
|
+
initTurnDiffSetting()
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
function initTurnDiffSetting() {
|
|
3689
|
+
const page = $('settings-page-general')
|
|
3690
|
+
if (!page || $('opt-turn-diff')) return
|
|
3691
|
+
const group = page.querySelector('[data-workflow-settings-slot="input"]')
|
|
3692
|
+
|| page.querySelector('[data-workflow-settings-slot]')
|
|
3693
|
+
|| page
|
|
3694
|
+
const row = document.createElement('div')
|
|
3695
|
+
row.className = 'ds-setting-row'
|
|
3696
|
+
row.innerHTML = `<div><div class="ds-setting-name"></div><div class="ds-setting-desc"></div></div><label class="switch"><input type="checkbox" id="opt-turn-diff"><span class="slider"></span></label>`
|
|
3697
|
+
row.querySelector('.ds-setting-name').textContent = t('ds.turnDiffTitle')
|
|
3698
|
+
row.querySelector('.ds-setting-desc').textContent = t('ds.turnDiffDesc')
|
|
3699
|
+
group.append(row)
|
|
3700
|
+
const checkbox = row.querySelector('#opt-turn-diff')
|
|
3701
|
+
checkbox.checked = turnDiffEnabled()
|
|
3702
|
+
checkbox.addEventListener('change', () => {
|
|
3703
|
+
LS.set('turnDiffEnabled', checkbox.checked ? '1' : '0')
|
|
3704
|
+
turnDiffController?.setEnabled(checkbox.checked)
|
|
3705
|
+
if (state.current) renderHistory(false, 'keep')
|
|
3706
|
+
})
|
|
3707
|
+
}
|
|
3708
|
+
|
|
3709
|
+
function updateTurnDiffSettingLabel() {
|
|
3710
|
+
const row = $('opt-turn-diff')?.closest('.ds-setting-row')
|
|
3711
|
+
if (!row) return
|
|
3712
|
+
const name = row.querySelector('.ds-setting-name')
|
|
3713
|
+
const desc = row.querySelector('.ds-setting-desc')
|
|
3714
|
+
if (name) name.textContent = t('ds.turnDiffTitle')
|
|
3715
|
+
if (desc) desc.textContent = t('ds.turnDiffDesc')
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3184
3718
|
/* ---------------- 文件传输 ---------------- */
|
|
3185
3719
|
function fsApiUrl(sub, params = {}) {
|
|
3186
3720
|
const u = new URL(apiUrl('/fs' + sub), location.href)
|
|
@@ -3208,6 +3742,11 @@ async function chatImageAttachment(attachment, sessionId) {
|
|
|
3208
3742
|
...(ref.height === undefined ? {} : { height: ref.height }),
|
|
3209
3743
|
...(ref.name ? { name: ref.name } : {}),
|
|
3210
3744
|
} }
|
|
3745
|
+
const session = state.byId?.get(sessionId)
|
|
3746
|
+
if (session?.origin === 'subagent' && session.parentSessionId) {
|
|
3747
|
+
payload.parentSessionId = session.parentSessionId
|
|
3748
|
+
payload.subagentMode = session.subagentMode || 'unknown'
|
|
3749
|
+
}
|
|
3211
3750
|
const result = await rpc('session.attachment', payload, 120000)
|
|
3212
3751
|
if (!connection.valid() || state.current !== sessionId) throw new Error('stale image')
|
|
3213
3752
|
return result
|
|
@@ -3513,7 +4052,9 @@ function orderedWorkspaceItems(items) {
|
|
|
3513
4052
|
}
|
|
3514
4053
|
function orderedWorkspaceSessions(workspaceId, items) {
|
|
3515
4054
|
const { value } = workbenchOrderScopeValue()
|
|
3516
|
-
|
|
4055
|
+
const pinned = new Set(state.pinnedIds || [])
|
|
4056
|
+
const ordered = orderedItems(items, value.sessionIds?.[String(workspaceId)], item => item.sessionId)
|
|
4057
|
+
return ordered.sort((a, b) => Number(pinned.has(b.sessionId)) - Number(pinned.has(a.sessionId)))
|
|
3517
4058
|
}
|
|
3518
4059
|
function saveWorkbenchOrder(mutator) {
|
|
3519
4060
|
const { store, value } = workbenchOrderScopeValue()
|
|
@@ -3555,6 +4096,7 @@ async function refreshWorkbench({ silent = false, discover = false } = {}) {
|
|
|
3555
4096
|
if (!valid()) return
|
|
3556
4097
|
if(wl){
|
|
3557
4098
|
state.archivedIds = Array.isArray(wl.archivedSessionIds) ? wl.archivedSessionIds : []
|
|
4099
|
+
state.pinnedIds = Array.isArray(wl.pinnedSessionIds) ? wl.pinnedSessionIds : []
|
|
3558
4100
|
state.workspaces = Array.isArray(wl.items) ? wl.items.slice() : []
|
|
3559
4101
|
}
|
|
3560
4102
|
if (!wb) { renderWorkbench(); renderSessions(); return }
|
|
@@ -4080,6 +4622,7 @@ function openDesktopPlugins(route = 'manage') {
|
|
|
4080
4622
|
}
|
|
4081
4623
|
|
|
4082
4624
|
function showView(id, pluginRoute = 'manage') {
|
|
4625
|
+
window.DshSlashSuggestions?.close()
|
|
4083
4626
|
window.DshExtensions?.closeShortcuts()
|
|
4084
4627
|
if (id !== 'view-chat') window.DshSubagents?.close()
|
|
4085
4628
|
document.body?.classList.toggle('viewing-subagent', id === 'view-chat' && state.byId.get(state.current)?.origin === 'subagent')
|
|
@@ -4087,16 +4630,18 @@ function showView(id, pluginRoute = 'manage') {
|
|
|
4087
4630
|
if (window.DshWorkflow?.isMounted() && id === 'view-overview') id = 'view-sessions'
|
|
4088
4631
|
if (id !== 'view-chat') conversationView?.pause()
|
|
4089
4632
|
if (state.view === 'view-chat' && id !== 'view-chat' && state.current) void archiveEmptySessionOnLeave(state.current)
|
|
4633
|
+
if (state.view === 'view-schedule' && id !== 'view-schedule') hostSchedule?.leave()
|
|
4090
4634
|
state.view = id
|
|
4091
4635
|
window.DshFileInbox?.render()
|
|
4092
4636
|
window.DshSessionDeck?.refresh()
|
|
4093
4637
|
document.body?.classList.toggle('workflow-at-start', !!window.DshWorkflow?.isMounted() && id === 'view-sessions')
|
|
4094
|
-
for (const v of ['view-overview', 'view-sessions', 'view-chat', 'view-files', 'view-plugins', 'view-settings']) $(v).classList.toggle('hidden', v !== id)
|
|
4638
|
+
for (const v of ['view-overview', 'view-sessions', 'view-chat', 'view-files', 'view-plugins', 'view-settings', 'view-schedule']) $(v).classList.toggle('hidden', v !== id)
|
|
4639
|
+
if (id === 'view-schedule') void hostSchedule?.refresh(true)
|
|
4095
4640
|
if (id === 'view-chat') conversationView?.resume()
|
|
4096
4641
|
document.querySelectorAll('.ds-nav-item').forEach(b => b.classList.toggle('active', b.dataset.view === id))
|
|
4097
4642
|
if (narrowSidebarQuery.matches) setMobileSidebar(false)
|
|
4098
4643
|
window.DshMotion?.view($(id))
|
|
4099
|
-
const titles = { 'view-overview': 'ds.overview', 'view-sessions': 'ds.sessions', 'view-chat': 'ds.sessions', 'view-files': 'ds.files', 'view-settings': 'ds.settings', 'view-plugins': 'ds.plugins' }
|
|
4644
|
+
const titles = { 'view-overview': 'ds.overview', 'view-sessions': 'ds.sessions', 'view-chat': 'ds.sessions', 'view-files': 'ds.files', 'view-settings': 'ds.settings', 'view-plugins': 'ds.plugins', 'view-schedule': 'hostSchedule.title' }
|
|
4100
4645
|
if (id === 'view-chat') { const s = state.byId.get(state.current); $('ds-title').textContent = s ? titleOf(s) : t('ds.sessions') }
|
|
4101
4646
|
else $('ds-title').textContent = t(titles[id])
|
|
4102
4647
|
if (id === 'view-overview') {startOverviewDetection(true);renderOverviewDesktop()}
|
|
@@ -4192,7 +4737,7 @@ function updateConn() {
|
|
|
4192
4737
|
|
|
4193
4738
|
function bindSessionDialogs() {
|
|
4194
4739
|
const actions=$('session-actions'), info=$('session-info');
|
|
4195
|
-
$('btn-session-more').addEventListener('click',()=>actions.showModal());
|
|
4740
|
+
$('btn-session-more').addEventListener('click',()=>{if(typeof refreshSessionAdminActions === 'function')refreshSessionAdminActions();actions.showModal()});
|
|
4196
4741
|
actions.addEventListener('click',e=>{if(e.target===actions)actions.close();else if(e.target.closest('button'))actions.close()},true);
|
|
4197
4742
|
const openInfo=()=>{const s=state.byId.get(state.current);if(!s)return; $('session-info-name').textContent=titleOf(s);$('session-info-path').textContent=s.cwd||t('ds.noWorkspace');$('session-info-id').textContent=s.sessionId;$('btn-copy-session-workspace').disabled=!s.cwd;info.showModal()};
|
|
4198
4743
|
$('ds-title').addEventListener('click',openInfo);
|
|
@@ -4275,8 +4820,24 @@ function bindUi() {
|
|
|
4275
4820
|
$('rename-confirm').addEventListener('click', confirmRenameSession)
|
|
4276
4821
|
$('rename-session-input').addEventListener('keydown', e => { if (e.key === 'Enter' && !e.isComposing) confirmRenameSession() })
|
|
4277
4822
|
$('modal-rename').addEventListener('click', e => { if (e.target === $('modal-rename')) closeRenameSession() })
|
|
4278
|
-
$('composer')
|
|
4279
|
-
|
|
4823
|
+
const composer = $('composer')
|
|
4824
|
+
window.DshSlashSuggestions?.mount({
|
|
4825
|
+
input: composer, t,
|
|
4826
|
+
panel: $('desktop-command-list'), chipClass: 'ds-action-item', chipAttribute: 'data-ds-cmd',
|
|
4827
|
+
context() {
|
|
4828
|
+
const connection = captureConnection(), sessionId = state.current, history = state.history
|
|
4829
|
+
if (!sessionId || state.byId.get(sessionId)?.origin === 'subagent') return null
|
|
4830
|
+
return {
|
|
4831
|
+
sessionId, url: path => connection.server + path,
|
|
4832
|
+
headers: { authorization: 'Bearer ' + connection.token, ...clientIdHeaders() },
|
|
4833
|
+
valid: () => connection.valid() && state.current === sessionId && state.history === history,
|
|
4834
|
+
}
|
|
4835
|
+
},
|
|
4836
|
+
readSkills: sessionId => rpc('skills.list', { sessionId }, 5000),
|
|
4837
|
+
})
|
|
4838
|
+
composer.addEventListener('keydown', (e) => {
|
|
4839
|
+
if (e.defaultPrevented || e.key !== 'Enter' || e.isComposing || composerTools?.keydown(e)) return
|
|
4840
|
+
if (!e.shiftKey) { e.preventDefault(); sendMessage() }
|
|
4280
4841
|
})
|
|
4281
4842
|
renderPresetMenuDesktop()
|
|
4282
4843
|
renderPresetSummary()
|
|
@@ -4284,9 +4845,13 @@ function bindUi() {
|
|
|
4284
4845
|
$('cmd-menu').addEventListener('click', (e) => {
|
|
4285
4846
|
const item = e.target.closest('[data-ds-cmd]')
|
|
4286
4847
|
if (item) {
|
|
4287
|
-
const
|
|
4288
|
-
|
|
4289
|
-
|
|
4848
|
+
const command = String(item.dataset.dsCmd || '').replace(/^\/+/, '')
|
|
4849
|
+
if (typeof composerTools === 'undefined' || !composerTools?.insertCommand?.(command)) {
|
|
4850
|
+
const input = $('composer')
|
|
4851
|
+
if (input.value.trim()) input.value = '/' + command + ' ' + input.value
|
|
4852
|
+
else input.value = '/' + command + ' '
|
|
4853
|
+
input.focus()
|
|
4854
|
+
}
|
|
4290
4855
|
$('cmd-menu').classList.add('hidden')
|
|
4291
4856
|
}
|
|
4292
4857
|
})
|
|
@@ -4409,7 +4974,7 @@ function bindUi() {
|
|
|
4409
4974
|
$('btn-lang').addEventListener('click', () => {
|
|
4410
4975
|
I18N.setLang(I18N.lang === 'zh' ? 'en' : 'zh')
|
|
4411
4976
|
$('btn-lang').textContent = I18N.lang === 'zh' ? 'EN' : '中文'
|
|
4412
|
-
renderServers(); renderSessions(); renderNotifStack(); renderOverviewDesktop(); updateConn(); themeApply(); void refreshInsightEntry()
|
|
4977
|
+
renderServers(); renderSessions(); renderNotifStack(); renderOverviewDesktop(); updateConn(); if(typeof updateBcControlLabels === 'function')updateBcControlLabels(); if(typeof updateTurnDiffSettingLabel === 'function')updateTurnDiffSettingLabel(); if (state.current) { if(typeof refreshPlanReview === 'function')refreshPlanReview(); renderHistory(true) }; themeApply(); void refreshInsightEntry()
|
|
4413
4978
|
})
|
|
4414
4979
|
$('fs-up').addEventListener('click', fsUp)
|
|
4415
4980
|
$('fs-root').addEventListener('change', (event) => {
|
|
@@ -4458,6 +5023,7 @@ async function start() {
|
|
|
4458
5023
|
}
|
|
4459
5024
|
$('token-desc').textContent = state.token ? '● ' + state.token.slice(0, 12) + '…' : t('ds.toastAuth')
|
|
4460
5025
|
bindUi()
|
|
5026
|
+
if (typeof initBcFeatures === 'function') initBcFeatures()
|
|
4461
5027
|
window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment, capture: captureChatImage })
|
|
4462
5028
|
if (!state.token) { showView('view-settings'); $('desktop-token-input').focus() }
|
|
4463
5029
|
renderWorkbench()
|
|
@@ -4472,6 +5038,7 @@ async function start() {
|
|
|
4472
5038
|
}
|
|
4473
5039
|
overviewStarting=false
|
|
4474
5040
|
renderOverviewDesktop()
|
|
5041
|
+
if (typeof initTurnDiffSetting === 'function') initTurnDiffSetting()
|
|
4475
5042
|
}
|
|
4476
5043
|
|
|
4477
5044
|
start()
|