dsh-remote-plugin 0.8.0-rc.2 → 0.8.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +325 -38
- package/index.mjs +24 -0
- package/package.json +3 -1
- package/peak-reminders.mjs +47 -0
- package/public/activity.js +126 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +8 -0
- package/public/app.js +572 -247
- package/public/build.json +5 -0
- package/public/desktop/desktop.css +10 -10
- package/public/desktop/desktop.html +36 -9
- package/public/desktop/desktop.js +287 -95
- package/public/diagnostics.js +109 -0
- package/public/extensions.js +7 -4
- package/public/history.js +44 -16
- package/public/image-preview.js +132 -0
- package/public/index.html +50 -11
- package/public/md.js +41 -1
- package/public/network.js +30 -6
- package/public/operations.js +1 -1
- package/public/relay-settings.js +19 -10
- package/public/styles.css +15 -15
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/teams.js +76 -0
- package/public/turn-results.js +119 -0
- package/public/update.json +4 -4
- package/public/version.json +1 -1
- package/public/workflow.css +216 -1
- package/public/workflow.js +91 -9
- package/teams.mjs +53 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.subagent-page{position:fixed;inset:0;box-sizing:border-box;width:100%;height:100%;height:100dvh;max-width:none;max-height:none;margin:0;padding:0;border:0;border-radius:0;background:var(--dsr-bg);color:var(--dsr-text);overflow:hidden}
|
|
2
|
+
.subagent-page[open]{display:flex;flex-direction:column}.subagent-page::backdrop{background:var(--dsr-bg)}
|
|
3
|
+
.subagent-page-head{flex:none;display:flex;align-items:center;gap:22px;padding:max(16px,var(--dsr-safe-top,0px)) max(24px,env(safe-area-inset-right)) 16px max(24px,env(safe-area-inset-left));border-bottom:1px solid var(--dsr-line);background:var(--dsr-panel)}
|
|
4
|
+
.subagent-page-heading{min-width:0}.subagent-page-head h2{margin:5px 0 0;font-size:19px;font-weight:650;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
5
|
+
.subagent-page-back,.subtree button{font:inherit;cursor:pointer;color:inherit}
|
|
6
|
+
.subagent-page-back{flex:none;min-height:44px;border:1px solid var(--dsr-line);border-radius:10px;background:var(--dsr-bg-2);padding:8px 13px;font-size:13px}
|
|
7
|
+
.subagent-page-content{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:24px max(24px,env(safe-area-inset-right)) max(24px,var(--dsr-safe-b,0px)) max(24px,env(safe-area-inset-left))}
|
|
8
|
+
.subtree{max-width:1280px;margin-inline:auto;font-size:13px;line-height:1.5}
|
|
9
|
+
.subtree-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:12px}
|
|
10
|
+
.subtree-search{flex:1 1 240px;min-width:0;max-width:400px;box-sizing:border-box;min-height:44px;border:1px solid var(--dsr-line);border-radius:10px;padding:10px 13px;background:var(--dsr-panel);color:var(--dsr-text);font:inherit;font-size:14px}
|
|
11
|
+
.subtree-search::placeholder{color:var(--dsr-muted)}
|
|
12
|
+
.subtree-filters{display:flex;gap:3px;padding:3px;border:1px solid var(--dsr-line);border-radius:11px;background:var(--dsr-bg-2)}
|
|
13
|
+
.subtree-filters button{min-height:38px;border:0;border-radius:7px;background:transparent;padding:7px 12px;color:var(--dsr-muted);font-size:12px}
|
|
14
|
+
.subtree-filters button[aria-pressed=true]{background:var(--dsr-accent-soft);color:var(--dsr-accent-strong);box-shadow:inset 0 0 0 1px var(--dsr-accent-line)}
|
|
15
|
+
.subtree-toolbar-actions{display:flex;align-items:center;gap:8px;margin-inline-start:auto}
|
|
16
|
+
.subtree-quiet,.subtree-action{min-height:44px;padding:9px 12px;border:1px solid var(--dsr-line);border-radius:9px;background:var(--dsr-panel);font-size:12px!important}
|
|
17
|
+
.subtree button:disabled{opacity:.6;cursor:default}
|
|
18
|
+
.subtree-summary{display:flex;flex-wrap:wrap;gap:6px 18px;margin:15px 0;color:var(--dsr-muted);font-size:12px;font-variant-numeric:tabular-nums}
|
|
19
|
+
.subtree-layout{display:grid;grid-template-columns:minmax(0,1fr) 320px;align-items:start;gap:24px}
|
|
20
|
+
.subtree-outline{min-width:0;padding:20px 16px;background:var(--dsr-bg-2);border:1px solid var(--dsr-line);border-radius:16px}
|
|
21
|
+
.subtree-list{list-style:none;padding:0 0 0 22px;margin:0 0 0 21px;border-inline-start:1px solid var(--dsr-divider)}
|
|
22
|
+
.subtree-root-list{padding:0;margin:0;border:0}.subtree-list>li{position:relative;padding-block:6px}
|
|
23
|
+
.subtree-list:not(.subtree-root-list)>li::before{content:'';position:absolute;inset-inline-start:-22px;top:37px;width:22px;border-top:1px solid var(--dsr-divider)}
|
|
24
|
+
.subtree-row{display:flex;align-items:center;gap:4px;min-width:0}
|
|
25
|
+
.subtree-disclosure,.subtree-leaf{flex:none;display:flex;align-items:center;justify-content:center;width:36px;min-height:44px;border:0;border-radius:8px;background:transparent;font-size:22px!important;color:var(--dsr-muted)!important}
|
|
26
|
+
.subtree-node{display:block;flex:1;min-width:0;width:100%;text-align:start;border:1px solid var(--dsr-line);border-radius:11px;padding:11px 13px;background:var(--dsr-panel);transition:border-color .15s,background .15s}
|
|
27
|
+
.subtree-node:hover{border-color:var(--dsr-accent-line);background:var(--dsr-panel-2)}
|
|
28
|
+
.subtree-node[aria-pressed=true]{border-color:var(--dsr-accent);background:var(--dsr-accent-soft);box-shadow:0 0 0 1px var(--dsr-accent-line)}
|
|
29
|
+
.subtree-node-head{display:flex;align-items:center;justify-content:space-between;gap:10px;min-width:0}
|
|
30
|
+
.subtree-node-head strong{min-width:0;font-size:14px;font-weight:600;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
31
|
+
.subtree-node-meta{display:flex;flex-wrap:wrap;gap:3px 12px;margin-top:5px;font-size:11px;color:var(--dsr-muted)}
|
|
32
|
+
.subtree-badge{display:inline-flex;align-items:center;gap:5px;flex:none;white-space:nowrap;border-radius:6px;padding:3px 7px;background:var(--dsr-panel-2);color:var(--dsr-muted);font-size:11px;font-weight:500}
|
|
33
|
+
.subtree-badge::before{content:'·';font-size:18px;line-height:10px}.subtree-badge[data-activity=running]{color:var(--dsr-accent-strong);background:var(--dsr-accent-soft)}
|
|
34
|
+
.subtree-badge[data-activity=waiting],.subtree-badge[data-activity=diagnostic]{color:var(--dsr-warning);background:var(--dsr-warning-soft)}
|
|
35
|
+
.subtree-badge[data-activity=diagnostic]::before{content:'!';font-size:11px}
|
|
36
|
+
.subtree-detail{position:sticky;top:0;min-width:0;padding:21px;border:1px solid var(--dsr-line);border-radius:16px;background:var(--dsr-panel)}
|
|
37
|
+
.subtree-eyebrow{font-size:11px;color:var(--dsr-muted);letter-spacing:.06em}.subtree-detail h3{font-size:18px;line-height:1.4;margin:9px 0 12px;overflow-wrap:anywhere}
|
|
38
|
+
.subtree-detail-badges{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:20px}.subtree-kind{font-size:11px;color:var(--dsr-muted)}
|
|
39
|
+
.subtree-field-label{margin-top:16px;font-size:11px;color:var(--dsr-muted)}.subtree-path{font-size:12px;line-height:1.7;margin:5px 0 0;overflow-wrap:anywhere}
|
|
40
|
+
.subtree-id{display:block;font-size:11px;line-height:1.6;margin-top:6px;padding:8px;border-radius:7px;background:var(--dsr-code-bg);overflow-wrap:anywhere;user-select:text}
|
|
41
|
+
.subtree-parent{max-width:100%;min-width:44px;min-height:44px;text-align:start;overflow-wrap:anywhere;padding:4px 0;border:0;background:transparent;color:var(--dsr-accent-strong)!important;font-size:12px!important}
|
|
42
|
+
.subtree-detail-actions{display:flex;flex-direction:column;gap:9px;margin-top:22px}.subtree-action{text-align:center}
|
|
43
|
+
.subtree-primary{background:var(--dsr-accent)!important;color:var(--dsr-on-accent)!important;border-color:var(--dsr-accent)!important;font-weight:650!important}
|
|
44
|
+
.subtree-danger{color:var(--dsr-warning)!important;border-color:var(--dsr-warning-line)!important;background:var(--dsr-warning-soft)!important}
|
|
45
|
+
.subtree-note{font-size:11px;color:var(--dsr-muted);line-height:1.7;margin:13px 0 0;overflow-wrap:anywhere}
|
|
46
|
+
.subtree-notice{padding:12px;border:1px solid var(--dsr-warning-line);border-radius:9px;background:var(--dsr-warning-soft);color:var(--dsr-warning);font-size:12px;line-height:1.65}
|
|
47
|
+
.subtree-reason{font-size:11px;color:var(--dsr-muted);display:block;margin-bottom:16px;overflow-wrap:anywhere}
|
|
48
|
+
.subtree-feedback{list-style:none;padding:18px!important;margin:8px 0;border:1px dashed var(--dsr-divider);border-radius:10px;color:var(--dsr-muted);font-size:12px;overflow-wrap:anywhere}
|
|
49
|
+
.subtree-feedback strong{font-size:13px;color:var(--dsr-text);font-weight:500}.subtree-feedback p{margin:7px 0 10px}.subtree-warning{border-color:var(--dsr-warning-line);background:var(--dsr-warning-soft)}
|
|
50
|
+
.subtree-depth{color:var(--dsr-accent-strong)}.subtree :is(button,input):focus-visible,.subagent-page-back:focus-visible{outline:2px solid var(--dsr-accent);outline-offset:3px}.subtree-detail h3:focus{outline:none}
|
|
51
|
+
.subtree-back-to-tree{display:none}
|
|
52
|
+
.subagents-entry{flex:none;font:inherit;font-size:12px;color:var(--dsr-text);background:transparent;border:1px solid var(--dsr-line);border-radius:9px;min-height:44px;padding:6px 9px;cursor:pointer}
|
|
53
|
+
body.viewing-subagent .composer-wrap,body.viewing-subagent .ds-composer,body.viewing-subagent #btn-session-more,body.viewing-subagent #btn-rename-session,body.viewing-subagent #btn-archive-session,body.viewing-subagent #btn-cancel,body.viewing-subagent [data-goal],body.viewing-subagent #queue-dock{display:none!important}
|
|
54
|
+
@media(max-width:800px){.subtree-layout{grid-template-columns:minmax(0,1fr);gap:16px}.subtree-detail{position:static}.subtree-search{max-width:none}.subtree-outline{padding:12px 8px}.subtree-disclosure,.subtree-leaf{width:32px}.subtree-node{padding:10px}.subtree-node-head{align-items:start;flex-wrap:wrap;gap:5px}.subtree-node-head strong{flex:1 1 120px}.subtree-detail-actions{flex-direction:row;flex-wrap:wrap}.subtree-detail-actions>*{flex:1 1 160px}.subtree .subtree-filters button{min-height:44px}.subtree .subtree-disclosure{min-width:44px}.subtree-list .subtree-list .subtree-list .subtree-list{padding-inline-start:0;margin-inline-start:8px;border-color:transparent}.subtree-list .subtree-list .subtree-list .subtree-list>li::before{display:none}}
|
|
55
|
+
@media(max-width:480px){.subagent-page-head{gap:12px;padding:max(12px,var(--dsr-safe-top,0px)) 12px 12px}.subagent-page-head h2{font-size:16px}.subagent-page-content{padding:16px 12px max(16px,var(--dsr-safe-b,0px))}.subtree-toolbar{gap:10px}.subtree-search{flex-basis:100%}.subtree-toolbar-actions{gap:4px}.subtree-quiet{padding-inline:9px}.subtree-filters button{padding-inline:10px}.subtree-summary{gap:5px 12px}.subtree-list{padding-inline-start:12px;margin-inline-start:14px}.subtree-list:not(.subtree-root-list)>li::before{inset-inline-start:-12px;width:12px}.subtree-root-list{padding:0;margin:0}.subtree-node-head strong{flex-basis:100px}.subtree-detail{padding:18px}}
|
|
56
|
+
@media(prefers-reduced-motion:reduce){.subtree-node{transition:none}}
|
|
57
|
+
@media(max-width:800px){.subtree-back-to-tree{display:block;margin-bottom:8px}}
|
|
58
|
+
@media(max-width:800px){.subtree-leaf{min-width:44px}}
|
|
59
|
+
@media(max-width:800px){.subtree-search{font-size:16px}}
|
|
60
|
+
.subtree-list .subtree-list .subtree-list .subtree-list .subtree-list .subtree-list{padding-inline-start:0;margin-inline-start:10px;border-color:transparent}
|
|
61
|
+
.subtree-list .subtree-list .subtree-list .subtree-list .subtree-list .subtree-list>li::before{display:none}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/* Shared, dependency-free subagent browser. Only explicit disclosure reads a new level. */
|
|
2
|
+
(function (root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
let view = null, page = null, pageBody = null, pageTitle = null
|
|
5
|
+
const memories = new Map()
|
|
6
|
+
const text = (cn, en) => String(root.I18N?.lang || 'zh').startsWith('en') ? en : cn
|
|
7
|
+
function node(tag, label, cls) {
|
|
8
|
+
const el = document.createElement(tag)
|
|
9
|
+
if (label !== undefined) el.textContent = label
|
|
10
|
+
if (cls) el.className = cls
|
|
11
|
+
return el
|
|
12
|
+
}
|
|
13
|
+
function button(label, action, cls, key) {
|
|
14
|
+
const el = node('button', label, cls)
|
|
15
|
+
el.type = 'button'
|
|
16
|
+
if (key) el.dataset.subFocus = key
|
|
17
|
+
el.addEventListener('click', action)
|
|
18
|
+
return el
|
|
19
|
+
}
|
|
20
|
+
const valid = v => view === v && !v.paused && v.options.valid()
|
|
21
|
+
const modeLabel = mode => mode === 'one-shot' ? text('单次任务', 'One-shot task') : mode === 'continuable' ? text('可续接任务', 'Continuable task') : text('模式未知', 'Unknown mode')
|
|
22
|
+
const activityLabel = activity => activity === 'running' ? text('运行中', 'Running') : activity === 'waiting' ? text('等待中', 'Waiting') : activity === 'inactive' ? text('未运行', 'Inactive') : text('状态未知', 'Unknown status')
|
|
23
|
+
function reasonLabel(reason) {
|
|
24
|
+
if (reason === 'migration-required') return text('请先在 DSH 中打开原会话完成迁移,再刷新目录', 'Open the source session in DSH to complete migration, then refresh the catalog')
|
|
25
|
+
if (reason === 'external') return text('这是外部代理任务,请在 DSH 中查看', 'This is an external-agent task. View it in DSH')
|
|
26
|
+
return ({ unsupported: text('当前版本无法识别此任务类型', 'This task type is not supported by the current version'), unavailable: text('记录暂时无法读取,可刷新重试', 'Record unavailable. Refresh to try again'), corrupt: text('任务信息不一致,暂不能打开', 'Task information is inconsistent. This record cannot be opened'), cycle: text('目录关系重复或形成循环', 'The catalog contains a repeated or circular relationship') })[reason] || text('此目录项暂时不可用', 'This catalog entry is unavailable')
|
|
27
|
+
}
|
|
28
|
+
function status(entry, diagnostic) {
|
|
29
|
+
const value = diagnostic ? 'diagnostic' : ['running', 'waiting', 'inactive'].includes(entry.activity) ? entry.activity : 'unknown'
|
|
30
|
+
const el = node('span', diagnostic ? text('目录异常', 'Catalog issue') : activityLabel(value), 'subtree-badge')
|
|
31
|
+
el.dataset.activity = value
|
|
32
|
+
return el
|
|
33
|
+
}
|
|
34
|
+
function model(v) {
|
|
35
|
+
const rootItem = { key: 'root', id: v.id, label: v.options.title || v.id, parent: null, depth: 0, entry: { activity: v.options.activity }, children: [] }
|
|
36
|
+
const byKey = new Map([['root', rootItem]])
|
|
37
|
+
let count = 0, running = 0, issues = 0, limited = false
|
|
38
|
+
function visit(parent, ancestors) {
|
|
39
|
+
const cached = v.cache.get(parent.id)
|
|
40
|
+
for (const entry of cached?.value?.entries || []) {
|
|
41
|
+
if (byKey.size > 300) { limited = true; break }
|
|
42
|
+
const diagnostic = entry.kind === 'diagnostic' || !entry.id || ancestors.has(entry.id)
|
|
43
|
+
const item = { key: parent.key + '/' + (entry.id ? encodeURIComponent(entry.id) : 'unknown-' + parent.children.length), id: entry.id || '', label: entry.label || entry.id?.slice(0, 12) || text('异常条目', 'Catalog issue'), entry, parent, depth: parent.depth + 1, diagnostic, reason: ancestors.has(entry.id) ? 'cycle' : entry.reason, children: [] }
|
|
44
|
+
byKey.set(item.key, item); parent.children.push(item)
|
|
45
|
+
if (diagnostic) issues++
|
|
46
|
+
else {
|
|
47
|
+
count++; if (entry.activity === 'running') running++
|
|
48
|
+
if (item.depth < 16) visit(item, new Set([...ancestors, item.id]))
|
|
49
|
+
else if (entry.hasChildren !== false) limited = true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
visit(rootItem, new Set([v.id]))
|
|
54
|
+
return { rootItem, byKey, count, running, issues, limited }
|
|
55
|
+
}
|
|
56
|
+
async function read(v, id, force = false) {
|
|
57
|
+
if (!valid(v)) return
|
|
58
|
+
const previous = v.cache.get(id)
|
|
59
|
+
if (previous?.loading || (!force && (previous?.value || previous?.error))) return
|
|
60
|
+
const item = { ...previous, loading: true, error: '' }
|
|
61
|
+
v.cache.set(id, item); paint(v)
|
|
62
|
+
try {
|
|
63
|
+
const value = await v.options.read(id)
|
|
64
|
+
if (!valid(v)) { v.cache.delete(id); return }
|
|
65
|
+
if (!Array.isArray(value?.entries)) throw new Error(text('未能读取子代理目录', 'Subagent catalog unavailable'))
|
|
66
|
+
item.value = value; item.updatedAt = Date.now()
|
|
67
|
+
const ancestors = new Set([v.id, id])
|
|
68
|
+
let parent = [...model(v).byKey.values()].find(item => !item.diagnostic && item.id === id)
|
|
69
|
+
for (; parent; parent = parent.parent) ancestors.add(parent.id)
|
|
70
|
+
for (const entry of value.entries) if (entry.kind !== 'diagnostic' && entry.id && !ancestors.has(entry.id)) v.options.remember(entry, id)
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!valid(v)) { v.cache.delete(id); return }
|
|
73
|
+
item.error = String(error.message || error)
|
|
74
|
+
} finally { item.loading = false; if (valid(v)) paint(v) }
|
|
75
|
+
}
|
|
76
|
+
async function refresh(v) {
|
|
77
|
+
if (!valid(v) || v.refreshing) return
|
|
78
|
+
v.refreshing = true; paint(v)
|
|
79
|
+
const seen = new Set()
|
|
80
|
+
async function visit(id, depth) {
|
|
81
|
+
if (!valid(v) || seen.has(id) || seen.size >= 300 || depth > 16) return
|
|
82
|
+
seen.add(id); await read(v, id, true)
|
|
83
|
+
if (!valid(v) || !v.expanded.has(id)) return
|
|
84
|
+
for (const entry of v.cache.get(id)?.value?.entries || []) {
|
|
85
|
+
if (entry.kind !== 'diagnostic' && entry.id && v.expanded.has(entry.id)) await visit(entry.id, depth + 1)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try { await visit(v.id, 0) } finally { v.refreshing = false; if (valid(v)) paint(v) }
|
|
89
|
+
}
|
|
90
|
+
function shell(v) {
|
|
91
|
+
const el = v.el = node('section', undefined, 'subtree')
|
|
92
|
+
const toolbar = node('div', undefined, 'subtree-toolbar')
|
|
93
|
+
const search = v.search = node('input', undefined, 'subtree-search')
|
|
94
|
+
search.type = 'search'; search.placeholder = text('查找已读取的名称或 ID', 'Find a loaded name or ID')
|
|
95
|
+
search.setAttribute('aria-label', search.placeholder)
|
|
96
|
+
search.addEventListener('input', () => { v.query = search.value; paint(v) })
|
|
97
|
+
const filters = node('div', undefined, 'subtree-filters')
|
|
98
|
+
filters.setAttribute('aria-label', text('按状态筛选', 'Filter by status'))
|
|
99
|
+
v.filters = []
|
|
100
|
+
for (const [key, label] of [['all', text('全部', 'All')], ['running', text('运行中', 'Running')], ['diagnostic', text('异常', 'Issues')]]) {
|
|
101
|
+
const b = button(label, () => { v.filter = key; paint(v) }, '', 'filter:' + key)
|
|
102
|
+
filters.append(b); v.filters.push([key, b])
|
|
103
|
+
}
|
|
104
|
+
toolbar.append(search, filters)
|
|
105
|
+
const actions = node('div', undefined, 'subtree-toolbar-actions')
|
|
106
|
+
const collapse = button(text('收起分支', 'Collapse branches'), () => { v.expanded.clear(); v.expanded.add(v.id); paint(v) }, 'subtree-quiet', 'collapse')
|
|
107
|
+
v.collapseButton = collapse
|
|
108
|
+
const refreshButton = v.refreshButton = button(text('刷新', 'Refresh'), () => void refresh(v), 'subtree-quiet', 'refresh')
|
|
109
|
+
actions.append(collapse, refreshButton); toolbar.append(actions)
|
|
110
|
+
v.summary = node('div', undefined, 'subtree-summary'); v.summary.setAttribute('role', 'status')
|
|
111
|
+
const layout = node('div', undefined, 'subtree-layout')
|
|
112
|
+
v.tree = node('div', undefined, 'subtree-outline'); v.tree.setAttribute('aria-label', text('子代理层级', 'Subagent hierarchy'))
|
|
113
|
+
v.detail = node('aside', undefined, 'subtree-detail'); v.detail.setAttribute('aria-label', text('所选节点详情', 'Selected node details'))
|
|
114
|
+
layout.append(v.tree, v.detail); el.append(toolbar, v.summary, layout)
|
|
115
|
+
}
|
|
116
|
+
function select(v, item) {
|
|
117
|
+
v.selected = item.key; paint(v)
|
|
118
|
+
if (root.matchMedia?.('(max-width:800px)').matches) v.detail.scrollIntoView({ behavior: root.matchMedia('(prefers-reduced-motion:reduce)').matches ? 'auto' : 'smooth', block: 'start' })
|
|
119
|
+
v.detailTitle?.focus({ preventScroll: true })
|
|
120
|
+
}
|
|
121
|
+
function details(v, item, outsideFilter) {
|
|
122
|
+
const box = v.detail; box.replaceChildren()
|
|
123
|
+
box.append(button(text('↑ 返回层级', '↑ Back to hierarchy'), () => {
|
|
124
|
+
const card = v.cards.get(item.key) || v.cards.get('root')
|
|
125
|
+
card?.scrollIntoView({ block: 'center' }); card?.focus({ preventScroll: true })
|
|
126
|
+
}, 'subtree-parent subtree-back-to-tree', 'back-to-tree'))
|
|
127
|
+
box.append(node('div', text('节点详情', 'Node details'), 'subtree-eyebrow'))
|
|
128
|
+
const title = v.detailTitle = node('h3', item.label); title.tabIndex = -1; box.append(title)
|
|
129
|
+
if (outsideFilter) box.append(node('p', text('此选中节点不在当前筛选结果中。', 'This selected node is outside the current filter.'), 'subtree-note'))
|
|
130
|
+
const badges = node('div', undefined, 'subtree-detail-badges')
|
|
131
|
+
if (item.key === 'root') badges.append(node('span', text('当前会话', 'Current session'), 'subtree-kind'))
|
|
132
|
+
else badges.append(node('span', item.diagnostic ? text('不可打开', 'Unavailable') : modeLabel(item.entry.mode), 'subtree-kind'))
|
|
133
|
+
badges.append(status(item.entry, item.diagnostic)); box.append(badges)
|
|
134
|
+
const path = []; for (let p = item; p; p = p.parent) path.unshift(p.label)
|
|
135
|
+
box.append(node('div', text('所在分支', 'Branch'), 'subtree-field-label'), node('p', path.join(' › '), 'subtree-path'))
|
|
136
|
+
if (item.parent) {
|
|
137
|
+
box.append(node('div', text('直接父会话', 'Direct parent'), 'subtree-field-label'))
|
|
138
|
+
box.append(button(item.parent.label, () => select(v, item.parent), 'subtree-parent', 'parent:' + item.key))
|
|
139
|
+
}
|
|
140
|
+
box.append(node('div', text('会话 ID', 'Session ID'), 'subtree-field-label'), node('code', item.id || '—', 'subtree-id'))
|
|
141
|
+
if (item.diagnostic) {
|
|
142
|
+
box.append(node('p', reasonLabel(item.reason), 'subtree-notice'))
|
|
143
|
+
if (item.reason) box.append(node('code', item.reason, 'subtree-reason'))
|
|
144
|
+
box.append(button(text('刷新目录', 'Refresh catalog'), () => void read(v, item.parent.id, true), 'subtree-action', 'retry-detail')); return
|
|
145
|
+
}
|
|
146
|
+
const cached = v.cache.get(item.id)
|
|
147
|
+
if (cached?.value) box.append(node('p', text(`已读取 ${item.children.filter(c => !c.diagnostic).length} 个直接子代理`, `${item.children.filter(c => !c.diagnostic).length} direct subagents loaded`), 'subtree-note'))
|
|
148
|
+
else if (item.entry.hasChildren !== false && item.key !== 'root') box.append(node('p', text('展开节点前的箭头,读取下一层任务。', 'Expand the node arrow to load the next level.'), 'subtree-note'))
|
|
149
|
+
const actions = node('div', undefined, 'subtree-detail-actions')
|
|
150
|
+
actions.append(button(item.key === 'root' ? text('返回当前对话', 'Back to current chat') : text('打开只读记录 ↗', 'Open read-only record ↗'), () => {
|
|
151
|
+
if (!valid(v)) return
|
|
152
|
+
root.DshSubagents.close(); if (item.parent) void v.options.open(item.entry, item.parent.id)
|
|
153
|
+
}, 'subtree-action subtree-primary', 'open:' + item.key))
|
|
154
|
+
const parentCatalog = item.parent && v.cache.get(item.parent.id)?.value
|
|
155
|
+
if (item.entry.mode === 'continuable' && item.entry.activity === 'running' && parentCatalog?.parentAvailable !== false) {
|
|
156
|
+
actions.append(button(text('中断任务', 'Interrupt task'), () => { if (valid(v)) void v.options.interrupt(item.id, item.parent.id) }, 'subtree-action subtree-danger', 'interrupt:' + item.key))
|
|
157
|
+
}
|
|
158
|
+
box.append(actions, node('p', item.parent ? text('打开记录后,返回会进入它的直接父会话。', 'From a record, Back opens its direct parent session.') : text('选择树中的子代理,查看任务详情。', 'Select a subagent in the tree to inspect its details.'), 'subtree-note'))
|
|
159
|
+
}
|
|
160
|
+
function paint(v) {
|
|
161
|
+
if (!valid(v)) return
|
|
162
|
+
const focused = document.activeElement?.dataset?.subFocus
|
|
163
|
+
const m = model(v), query = v.query.trim().toLocaleLowerCase(), filtering = !!query || v.filter !== 'all'
|
|
164
|
+
const matches = new Set()
|
|
165
|
+
function match(item) {
|
|
166
|
+
const own = (!query || `${item.label} ${item.id}`.toLocaleLowerCase().includes(query)) && (v.filter === 'all' || (v.filter === 'diagnostic' ? item.diagnostic : !item.diagnostic && item.entry.activity === 'running'))
|
|
167
|
+
const descendant = item.children.map(match).some(Boolean)
|
|
168
|
+
if (own || descendant) matches.add(item.key)
|
|
169
|
+
return own || descendant
|
|
170
|
+
}
|
|
171
|
+
m.rootItem.children.forEach(match)
|
|
172
|
+
v.refreshButton.disabled = !!v.refreshing; v.refreshButton.textContent = v.refreshing ? text('刷新中…', 'Refreshing…') : text('刷新', 'Refresh')
|
|
173
|
+
v.collapseButton.disabled = filtering
|
|
174
|
+
v.collapseButton.title = filtering ? text('清除筛选后可收起分支', 'Clear filters to collapse branches') : ''
|
|
175
|
+
for (const [key, b] of v.filters) b.setAttribute('aria-pressed', String(key === v.filter))
|
|
176
|
+
const labels = [text(`已读取 ${m.count} 个子代理`, `${m.count} subagents loaded`), text(`${m.running} 个运行中`, `${m.running} running`), text(`${m.issues} 个目录异常`, `${m.issues} catalog issues`)]
|
|
177
|
+
if (v.summarySignature !== labels.join('|')) {
|
|
178
|
+
v.summarySignature = labels.join('|'); v.summary.replaceChildren()
|
|
179
|
+
for (const label of labels) v.summary.append(node('span', label))
|
|
180
|
+
}
|
|
181
|
+
v.tree.replaceChildren()
|
|
182
|
+
v.cards = new Map()
|
|
183
|
+
function feedback(parent, list) {
|
|
184
|
+
const cached = v.cache.get(parent.id)
|
|
185
|
+
if (cached?.error) {
|
|
186
|
+
const warning = node('li', undefined, 'subtree-feedback subtree-warning')
|
|
187
|
+
warning.append(node('strong', cached.value ? text('刷新失败,保留上次目录', 'Refresh failed. Showing the last catalog') : text('暂时无法读取目录', 'Catalog unavailable')), node('p', cached.error))
|
|
188
|
+
warning.append(button(text('重试', 'Retry'), () => void read(v, parent.id, true), 'subtree-action', 'retry:' + parent.key)); list.append(warning)
|
|
189
|
+
}
|
|
190
|
+
if (cached?.loading) list.append(node('li', text('正在读取这一层…', 'Loading this level…'), 'subtree-feedback'))
|
|
191
|
+
if (cached?.value && !cached.value.entries.length && !cached.error) {
|
|
192
|
+
const empty = node('li', undefined, 'subtree-feedback')
|
|
193
|
+
empty.append(node('strong', text('暂无子代理', 'No subagents')), node('p', text('此会话还没有子代理记录。产生新任务后可刷新查看。', 'This session has no subagent records yet. Refresh after new tasks are created.'))); list.append(empty)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function row(item) {
|
|
197
|
+
const li = node('li'), line = node('div', undefined, 'subtree-row')
|
|
198
|
+
const cached = v.cache.get(item.id), expanded = v.expanded.has(item.id)
|
|
199
|
+
const canExpand = !item.diagnostic && item.depth < 16 && (cached?.value ? cached.value.entries.length > 0 : item.key === 'root' || item.entry.hasChildren !== false)
|
|
200
|
+
if (canExpand) {
|
|
201
|
+
const toggle = button(expanded ? '⌄' : '›', () => {
|
|
202
|
+
if (expanded) v.expanded.delete(item.id)
|
|
203
|
+
else { v.expanded.add(item.id); void read(v, item.id) }
|
|
204
|
+
paint(v)
|
|
205
|
+
}, 'subtree-disclosure', 'toggle:' + item.key)
|
|
206
|
+
toggle.setAttribute('aria-expanded', String(expanded)); toggle.setAttribute('aria-label', (expanded ? text('收起 ', 'Collapse ') : text('展开 ', 'Expand ')) + item.label); line.append(toggle)
|
|
207
|
+
} else line.append(node('span', '·', 'subtree-leaf'))
|
|
208
|
+
const card = button(undefined, () => select(v, item), 'subtree-node', 'select:' + item.key)
|
|
209
|
+
v.cards.set(item.key, card)
|
|
210
|
+
card.setAttribute('aria-pressed', String(item.key === v.selected)); card.title = item.id
|
|
211
|
+
const head = node('span', undefined, 'subtree-node-head'); head.append(node('strong', item.label), status(item.entry, item.diagnostic))
|
|
212
|
+
const meta = node('span', undefined, 'subtree-node-meta')
|
|
213
|
+
meta.append(node('span', item.key === 'root' ? text('当前会话 · 树的起点', 'Current session · Tree root') : item.diagnostic ? reasonLabel(item.reason) : modeLabel(item.entry.mode)))
|
|
214
|
+
if (item.depth >= 4) meta.append(node('span', text(`第 ${item.depth} 层`, `Level ${item.depth}`), 'subtree-depth'))
|
|
215
|
+
if (!item.diagnostic && cached?.value && item.children.length) meta.append(node('span', text(`${item.children.length} 个下级条目`, `${item.children.length} child entries`)))
|
|
216
|
+
card.append(head, meta); line.append(card); li.append(line)
|
|
217
|
+
if (!item.diagnostic && (expanded || filtering)) {
|
|
218
|
+
const list = node('ul', undefined, 'subtree-list')
|
|
219
|
+
for (const child of item.children) if (!filtering || matches.has(child.key)) list.append(row(child))
|
|
220
|
+
if (!filtering || cached?.loading || cached?.error) feedback(item, list)
|
|
221
|
+
if (list.children.length) li.append(list)
|
|
222
|
+
}
|
|
223
|
+
return li
|
|
224
|
+
}
|
|
225
|
+
const treeList = node('ul', undefined, 'subtree-list subtree-root-list'); treeList.append(row(m.rootItem)); v.tree.append(treeList)
|
|
226
|
+
if (filtering && v.cache.get(v.id)?.value && !v.cache.get(v.id)?.loading && !m.rootItem.children.some(c => matches.has(c.key))) {
|
|
227
|
+
const empty = node('div', undefined, 'subtree-feedback')
|
|
228
|
+
empty.append(node('strong', text('已读取目录中没有匹配项', 'No matches in the loaded catalog')), node('p', text('筛选仅检查已读取的节点,不会自动加载其他分支。', 'Filters only inspect loaded nodes and do not load other branches.')))
|
|
229
|
+
empty.append(button(text('清除筛选', 'Clear filters'), () => { v.query = ''; v.search.value = ''; v.filter = 'all'; paint(v) }, 'subtree-action', 'clear')); v.tree.append(empty)
|
|
230
|
+
}
|
|
231
|
+
if (m.limited) v.tree.append(node('p', text('目录较大,打开子代理记录可继续查看更深层。', 'Open a child record to explore more of this large catalog.'), 'subtree-note'))
|
|
232
|
+
const selected = m.byKey.get(v.selected) || m.rootItem
|
|
233
|
+
v.selected = selected.key; details(v, selected, filtering && selected.key !== 'root' && !matches.has(selected.key))
|
|
234
|
+
if (focused) for (const el of v.el.querySelectorAll('[data-sub-focus]')) if (el.dataset.subFocus === focused) el.focus({ preventScroll: true })
|
|
235
|
+
}
|
|
236
|
+
root.DshSubagents = {
|
|
237
|
+
configure(entry, options) {
|
|
238
|
+
if (!entry) return
|
|
239
|
+
entry.onclick = () => { if (options.valid()) root.DshSubagents.show(options) }
|
|
240
|
+
if (page?.open) { if (view?.id === options.sessionId) root.DshSubagents.mount(pageBody, options); else root.DshSubagents.close() }
|
|
241
|
+
},
|
|
242
|
+
show(options) {
|
|
243
|
+
if (!options.valid()) return
|
|
244
|
+
if (!page) {
|
|
245
|
+
page = node('dialog', undefined, 'subagent-page'); page.id = 'subagent-page'; page.setAttribute('aria-labelledby', 'subagent-page-title')
|
|
246
|
+
const head = node('header', undefined, 'subagent-page-head')
|
|
247
|
+
const back = button(text('‹ 返回对话', '‹ Back to chat'), () => root.DshSubagents.close(), 'subagent-page-back')
|
|
248
|
+
const titleBlock = node('div', undefined, 'subagent-page-heading'); titleBlock.append(node('span', text('会话 / 子代理', 'Conversation / Subagents'), 'subtree-eyebrow'))
|
|
249
|
+
pageTitle = node('h2'); pageTitle.id = 'subagent-page-title'; titleBlock.append(pageTitle); head.append(back, titleBlock)
|
|
250
|
+
pageBody = node('div', undefined, 'subagent-page-content'); page.append(head, pageBody)
|
|
251
|
+
page.addEventListener('close', () => { if (view?.options.valid()) view.options.onClose?.(); root.DshSubagents.pause() }); document.body.append(page)
|
|
252
|
+
}
|
|
253
|
+
pageTitle.textContent = options.title || options.sessionId
|
|
254
|
+
if (!page.open) { page.showModal(); options.onShow?.() }
|
|
255
|
+
if (!view || view.id !== options.sessionId || !view.options.valid()) {
|
|
256
|
+
const expanded = memories.get(options.sessionId) || new Set(); expanded.add(options.sessionId); memories.set(options.sessionId, expanded)
|
|
257
|
+
}
|
|
258
|
+
pageBody.replaceChildren(); root.DshSubagents.mount(pageBody, options)
|
|
259
|
+
},
|
|
260
|
+
close() { if (page?.open) { page.close(); root.DshSubagents.pause() } },
|
|
261
|
+
mount(target, options) {
|
|
262
|
+
if (!target || !options.valid()) return
|
|
263
|
+
if (!view || view.id !== options.sessionId || !view.options.valid()) {
|
|
264
|
+
if (view) memories.set(view.id, view.expanded)
|
|
265
|
+
if (memories.size > 20) memories.delete(memories.keys().next().value)
|
|
266
|
+
view = { id: options.sessionId, options, expanded: memories.get(options.sessionId) || new Set([options.sessionId]), cache: new Map(), paused: false, query: '', filter: 'all', selected: 'root' }; shell(view)
|
|
267
|
+
}
|
|
268
|
+
view.options = options; view.paused = false; target.append(view.el); paint(view)
|
|
269
|
+
const cached = view.cache.get(view.id)
|
|
270
|
+
if (cached?.value && Date.now() - cached.updatedAt >= 10000) void refresh(view); else void read(view, view.id)
|
|
271
|
+
},
|
|
272
|
+
pause() { if (view) view.paused = true },
|
|
273
|
+
reset() { root.DshSubagents.close(); view = null; memories.clear() },
|
|
274
|
+
}
|
|
275
|
+
})(window)
|
package/public/teams.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* AgentTeams view: reads only; scheduling remains owned by the host plugin. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root) {
|
|
4
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
5
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
6
|
+
let current
|
|
7
|
+
function status(value) {
|
|
8
|
+
const names = { staged: ['待确认计划','Plan awaiting review'], running: ['运行中','Running'], working: ['工作中','Working'], idle: ['未运行','Idle'], unknown: ['未知','Unknown'],
|
|
9
|
+
open: ['待执行','Open'], blocked: ['受阻','Blocked'], completed: ['已完成','Completed'], failed: ['失败','Failed'], cancelled: ['已取消','Cancelled'], in_progress: ['执行中','In progress'], removed: ['已移除','Removed'] }
|
|
10
|
+
return names[value] ? text(...names[value]) : value || text('未知','Unknown')
|
|
11
|
+
}
|
|
12
|
+
function teamHtml(team, index, archived) {
|
|
13
|
+
const button = (label, member = '') => `<button type="button" data-team-open="${index}"${member ? ` data-team-member="${esc(member)}"` : ''}>${esc(label)}</button>`
|
|
14
|
+
const members = (team.members || []).map(member => `<li><div><strong>${esc(member.name)}</strong> · ${esc(status(member.activity))} · ${esc(status(member.status))}</div><p>${esc(member.role)}</p><small>${esc([member.provider,member.model].filter(Boolean).join('/'))} ${esc(member.currentTask)}</small>${!archived && member.id ? button(text('打开成员记录','Open member record'), member.id) : ''}</li>`).join('')
|
|
15
|
+
const tasks = (team.tasks || []).map(task => `<li><strong>${esc(task.id)} · ${esc(task.subject)}</strong><span class="teams-state">${esc(status(task.state || task.status))}</span><p>${esc(task.description)}</p><small>${esc(text('负责人','Assignee'))}:${esc(task.assignee || '—')} · ${esc(text('依赖','Depends on'))}:${esc((task.dependencies || []).join(', ') || '—')}</small>${task.verdictStale ? `<p class="teams-error">${esc(task.verdictStale)}</p>` : ''}</li>`).join('')
|
|
16
|
+
const delivery = team.deliverable === true && team.delivery?.ok === true ? text('插件报告可交付','Plugin reports deliverable') : text('交付尚未确认','Delivery not confirmed')
|
|
17
|
+
return `<article class="teams-card"><header><h3>${esc(team.name)}</h3><span>${esc(archived ? text('已归档','Archived') : team.halted ? text('已暂停调度','Scheduling halted') : status(team.phase))}</span></header><p>${esc(team.description)}</p><p>${esc(delivery)}</p>${team.delivery?.blockers?.length ? `<ul>${team.delivery.blockers.map(v => `<li>${esc(v)}</li>`).join('')}</ul>` : ''}${button(text('打开队长会话','Open captain session'))}<details open data-team-detail="members:${esc(team.teamId)}"><summary>${esc(text('成员','Members'))} · ${(team.members || []).length}${team.membersTruncated ? '+' : ''}</summary><ul>${members || `<li>${esc(text('暂无成员','No members'))}</li>`}</ul></details><details data-team-detail="tasks:${esc(team.teamId)}"><summary>${esc(text('任务与依赖','Tasks and dependencies'))} · ${(team.tasks || []).length}${team.tasksTruncated ? '+' : ''}</summary><ul>${tasks || `<li>${esc(text('暂无任务','No tasks'))}</li>`}</ul></details><details data-team-detail="messages:${esc(team.teamId)}"><summary>${esc(text('队长未读消息预览','Unread captain messages'))} · ${team.messageCount ?? '—'}</summary>${(team.captainInbox || []).map(row => `<p><strong>${esc(row.from)}</strong>:${esc(row.content)}</p>`).join('') || `<p>${esc(text('暂无预览消息','No message previews'))}</p>`}</details></article>`
|
|
18
|
+
}
|
|
19
|
+
function close() { if (current) { current.controller.abort(); clearInterval(current.timer); current = null } }
|
|
20
|
+
async function mount(config, target) {
|
|
21
|
+
close()
|
|
22
|
+
const s = { config, target, controller: new AbortController(), request: 0, data: null, workspaceId: '', archived: false, expanded: new Map() }
|
|
23
|
+
current = s
|
|
24
|
+
const valid = () => current === s && config.valid()
|
|
25
|
+
const workspaces = (config.getWorkspaces?.() || []).filter(w => w?.workspaceId)
|
|
26
|
+
s.workspaceId = workspaces.some(w => w.workspaceId === config.getWorkspaceId?.()) ? config.getWorkspaceId() : workspaces[0]?.workspaceId || ''
|
|
27
|
+
target.innerHTML = `<section class="teams-page"><h2>${esc(text('智能体团队','Agent teams'))}</h2><p>${esc(text('查看当前工作区的团队、成员、任务依赖与消息。','Teams, members, dependencies and messages in the selected workspace.'))}</p><div class="teams-controls"><label>${esc(text('工作区','Workspace'))}<select data-teams-workspace>${workspaces.map(w => `<option value="${esc(w.workspaceId)}">${esc(w.title || w.path || w.workspaceId)}</option>`).join('')}</select></label><label><input type="checkbox" data-teams-archived> ${esc(text('查看归档团队','Archived teams'))}</label><button type="button" data-teams-refresh>${esc(text('刷新','Refresh'))}</button></div><p data-teams-status role="status" aria-live="polite"></p><div data-teams-content></div></section>`
|
|
28
|
+
const selector = target.querySelector('[data-teams-workspace]'), content = target.querySelector('[data-teams-content]'), note = target.querySelector('[data-teams-status]')
|
|
29
|
+
selector.value = s.workspaceId
|
|
30
|
+
function render(data) {
|
|
31
|
+
for (const detail of content.querySelectorAll('details[data-team-detail]')) s.expanded.set(detail.dataset.teamDetail, detail.open)
|
|
32
|
+
content.innerHTML = data.teams.length ? data.teams.map((team, index) => teamHtml(team, index, s.archived)).join('') : `<p>${esc(text('此工作区暂无团队。','No teams in this workspace.'))}</p>`
|
|
33
|
+
for (const detail of content.querySelectorAll('details[data-team-detail]')) if (s.expanded.has(detail.dataset.teamDetail)) detail.open = s.expanded.get(detail.dataset.teamDetail)
|
|
34
|
+
}
|
|
35
|
+
async function load(clear = false) {
|
|
36
|
+
if (!valid()) { if (current === s) close(); return }
|
|
37
|
+
s.readController?.abort()
|
|
38
|
+
s.readController = new AbortController()
|
|
39
|
+
const request = ++s.request
|
|
40
|
+
if (clear) { s.data = null; s.expanded.clear(); content.replaceChildren() }
|
|
41
|
+
if (!s.workspaceId) { note.textContent = text('请先登记一个 DSH 工作区。','Register a DSH workspace first.'); return }
|
|
42
|
+
note.textContent = text('正在读取团队…','Loading teams…')
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(config.url('/remote/api/teams?workspaceId=' + encodeURIComponent(s.workspaceId) + '&archived=' + (s.archived ? '1' : '0')), { headers: config.headers, signal: AbortSignal.any([s.controller.signal, s.readController.signal, AbortSignal.timeout(20000)]) })
|
|
45
|
+
const body = await response.text()
|
|
46
|
+
if (!valid() || request !== s.request) return
|
|
47
|
+
if (body.length > 2 * 1024 * 1024) throw Error('large')
|
|
48
|
+
const data = JSON.parse(body)
|
|
49
|
+
if (!response.ok || data.ok !== true || data.schema !== 1 || data.available !== false && (!Array.isArray(data.teams) || data.workspaceId !== s.workspaceId)) throw Error('schema')
|
|
50
|
+
if (data.available === false) { s.data = null; content.replaceChildren(); note.textContent = text('主机未提供兼容的智能体团队接口。','No compatible AgentTeams endpoint on this host.'); return }
|
|
51
|
+
render(data); s.data = data
|
|
52
|
+
note.textContent = data.truncated ? text('团队较多,仅显示前 40 个。','Showing the first 40 teams.') : text('已更新','Updated')
|
|
53
|
+
} catch {
|
|
54
|
+
if (valid() && request === s.request) note.textContent = s.data ? text('刷新失败,保留上次结果,可重试。','Refresh failed. Showing the previous result; retry is available.') : text('读取失败,请检查插件状态后重试。','Unable to load. Check plugin status and retry.')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
selector.addEventListener('change', () => { s.workspaceId = selector.value; void load(true) })
|
|
58
|
+
target.querySelector('[data-teams-archived]').addEventListener('change', event => { s.archived = event.target.checked; void load(true) })
|
|
59
|
+
target.querySelector('[data-teams-refresh]').addEventListener('click', () => void load())
|
|
60
|
+
content.addEventListener('click', async event => {
|
|
61
|
+
const button = event.target.closest?.('[data-team-open]')
|
|
62
|
+
if (!button || !valid() || !s.data) return
|
|
63
|
+
const team = s.data.teams[Number(button.dataset.teamOpen)], member = button.dataset.teamMember
|
|
64
|
+
if (!team || !team.captainSessionId) return
|
|
65
|
+
button.disabled = true
|
|
66
|
+
try { if (member) await config.openTeamMember?.(member, team.captainSessionId); else await config.openTeamCaptain?.(team.captainSessionId) }
|
|
67
|
+
catch { if (valid()) note.textContent = text('会话暂不可读,请刷新后重试。','Session unavailable. Refresh and retry.') }
|
|
68
|
+
finally { if (valid()) button.disabled = false }
|
|
69
|
+
})
|
|
70
|
+
s.timer = setInterval(() => { if (!document.hidden) void load() }, 15000)
|
|
71
|
+
await load()
|
|
72
|
+
}
|
|
73
|
+
const api = { mount, close, teamHtml }
|
|
74
|
+
root.DshTeams = api
|
|
75
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
76
|
+
})(typeof window === 'undefined' ? globalThis : window)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* Completed-turn actions derived from durable events. No dependencies. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root) {
|
|
4
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
5
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
6
|
+
const keys = ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens']
|
|
7
|
+
const count = n => typeof n === 'number' && Number.isFinite(n) && n >= 0
|
|
8
|
+
function messageText(event) {
|
|
9
|
+
const data = event.data || {}, blocks = data.message?.content ?? data.content
|
|
10
|
+
if (Array.isArray(blocks)) return blocks.filter(b => b?.type === 'text').map(b => String(b.text ?? '')).join('\n\n').trim()
|
|
11
|
+
return typeof data.text === 'string' ? data.text.trim() : ''
|
|
12
|
+
}
|
|
13
|
+
function summarize(entries, sessionId) {
|
|
14
|
+
const results = new Map(), seen = new Set()
|
|
15
|
+
let turn = null
|
|
16
|
+
const fresh = (id, started = false) => ({ id, started, messages: 0, missing: false, samples: 0, total: 0, usage: Object.fromEntries(keys.map(k => [k, 0])), text: '' })
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const event = entry.event || {}, data = event.data || {}, id = data.turn
|
|
19
|
+
if (!Number.isSafeInteger(entry.seq) || seen.has(entry.seq)) continue
|
|
20
|
+
seen.add(entry.seq)
|
|
21
|
+
if (event.type === 'turn/start') { turn = fresh(id, true); continue }
|
|
22
|
+
if (event.type === 'user/message') {
|
|
23
|
+
const source = data.source ?? data.message?.source
|
|
24
|
+
if ((!source || source.kind === 'user') && (!turn || !turn.started)) turn = fresh(id)
|
|
25
|
+
}
|
|
26
|
+
if (event.type === 'assistant/message') {
|
|
27
|
+
if (!turn || id != null && turn.id != null && id !== turn.id) turn = fresh(id)
|
|
28
|
+
if (turn.id == null) turn.id = id
|
|
29
|
+
turn.messages++
|
|
30
|
+
const body = messageText(event)
|
|
31
|
+
if (body) turn.text = body
|
|
32
|
+
const u = data.usage
|
|
33
|
+
if (u && (count(u.totalTokens) || count(u.inputTokens) && count(u.outputTokens))) {
|
|
34
|
+
for (const k of keys) if (count(u[k])) turn.usage[k] += u[k]
|
|
35
|
+
// DSH counters are disjoint. Reasoning is already included in output.
|
|
36
|
+
turn.total += count(u.totalTokens) ? u.totalTokens : keys.reduce((n, k) => n + (count(u[k]) ? u[k] : 0), 0)
|
|
37
|
+
turn.samples++
|
|
38
|
+
} else turn.missing = true
|
|
39
|
+
}
|
|
40
|
+
if (event.type !== 'turn/end') continue
|
|
41
|
+
if (turn?.messages && (id == null || turn.id == null || id === turn.id)) {
|
|
42
|
+
const time = typeof event.time === 'number' ? event.time : Date.parse(event.time)
|
|
43
|
+
results.set(entry.seq, { sessionId, atSeq: entry.seq, text: turn.text,
|
|
44
|
+
time: Number.isFinite(time) && time > 0 ? time : null,
|
|
45
|
+
total: turn.samples ? turn.total : null, usage: turn.usage,
|
|
46
|
+
partial: !turn.started || turn.missing })
|
|
47
|
+
}
|
|
48
|
+
turn = null
|
|
49
|
+
}
|
|
50
|
+
return results
|
|
51
|
+
}
|
|
52
|
+
function decorate(prepared, entries, options = {}) {
|
|
53
|
+
const results = summarize(entries, options.sessionId)
|
|
54
|
+
return prepared.map(entry => results.has(entry.seq) && entry.event?.type === 'turn/end'
|
|
55
|
+
? { ...entry, view: { ...entry.view, turnResult: { ...results.get(entry.seq), canFork: options.canFork === true } } }
|
|
56
|
+
: entry)
|
|
57
|
+
}
|
|
58
|
+
const paths = {
|
|
59
|
+
copy: '<rect x="8" y="8" width="12" height="13" rx="2"/><path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/>',
|
|
60
|
+
fork: '<circle cx="6" cy="12" r="3"/><circle cx="18" cy="5" r="3"/><circle cx="18" cy="19" r="3"/><path d="m9 11 6-4m-6 6 6 4"/>',
|
|
61
|
+
usage: '<ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v14c0 4 16 4 16 0V5M4 12c0 4 16 4 16 0"/>'
|
|
62
|
+
}
|
|
63
|
+
const icon = name => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths[name]}</svg>`
|
|
64
|
+
function formatTokens(n) {
|
|
65
|
+
for (const [size, suffix] of [[1e9, 'B'], [1e6, 'M'], [1e3, 'K']]) if (n >= size) return (n / size).toFixed(1).replace(/\.0$/, '') + suffix
|
|
66
|
+
return String(n)
|
|
67
|
+
}
|
|
68
|
+
function html(result) {
|
|
69
|
+
const button = (action, label, disabled = false) => `<button type="button" data-turn-action="${action}" title="${esc(label)}" aria-label="${esc(label)}"${disabled ? ' disabled' : ''}>${icon(action)}<span>${esc(label)}</span></button>`
|
|
70
|
+
const total = result.total == null ? '—' : formatTokens(result.total) + ' tok'
|
|
71
|
+
const label = text(result.partial && result.total != null ? '已知用量' : '用量', result.partial && result.total != null ? 'Known usage' : 'Usage')
|
|
72
|
+
const u = result.usage
|
|
73
|
+
const detail = result.total == null ? text('主机未提供该回合的用量。', 'The host did not report usage for this turn.')
|
|
74
|
+
: `${text('输入', 'Input')} ${u.inputTokens} · ${text('输出', 'Output')} ${u.outputTokens} · ${text('缓存读取', 'Cache read')} ${u.cacheReadTokens} · ${text('缓存写入', 'Cache write')} ${u.cacheWriteTokens} · ${text('合计', 'Total')} ${result.total}` + (result.partial ? text('(记录未加载完整或部分调用未报告用量)', ' (history incomplete or some calls did not report usage)') : '')
|
|
75
|
+
const date = result.time == null ? null : new Date(result.time)
|
|
76
|
+
const stamp = date ? date.toLocaleString(root.I18N?.lang === 'en' ? 'en-US' : 'zh-CN', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false }) : text('时间未知', 'Time unavailable')
|
|
77
|
+
const labels = [text('输入', 'Input'), text('输出', 'Output'), text('缓存读取', 'Cache read'), text('缓存写入', 'Cache write')]
|
|
78
|
+
const breakdown = result.total == null ? `<p>${esc(detail)}</p>` : `<dl>${keys.map((key, index) => `<div><dt>${esc(labels[index])}</dt><dd>${u[key].toLocaleString()} tok</dd></div>`).join('')}<div><dt>${esc(text('合计', 'Total'))}</dt><dd>${result.total.toLocaleString()} tok</dd></div></dl>${result.partial ? `<p>${esc(text('记录未加载完整,或部分调用未报告用量。', 'History is incomplete, or some calls did not report usage.'))}</p>` : ''}`
|
|
79
|
+
return `<div class="turn-result" data-turn-seq="${result.atSeq}" data-turn-session="${esc(result.sessionId)}" role="group" aria-label="${esc(text('回合结果', 'Turn result'))}">${button('copy', text('复制结果', 'Copy result'), !result.text)}${result.canFork ? button('fork', text('从此处分支', 'Branch from here')) : ''}<details class="turn-result-usage" data-activity-key="turn-usage:${result.atSeq}"><summary title="${esc(detail)}">${icon('usage')}${esc(label)} ${esc(total)}</summary><div class="turn-result-breakdown">${breakdown}</div></details><time${date ? ` datetime="${date.toISOString()}" title="${esc(date.toLocaleString())}"` : ''}>${esc(stamp)}</time><span class="turn-result-status" role="status" aria-live="polite"></span></div>`
|
|
80
|
+
}
|
|
81
|
+
// Delegate on the stable history container so paging/redraws need no new listeners.
|
|
82
|
+
function bind(box, host) {
|
|
83
|
+
if (!box || box.dataset.turnResultsBound) return
|
|
84
|
+
box.dataset.turnResultsBound = '1'
|
|
85
|
+
const pending = new Set()
|
|
86
|
+
box.addEventListener('click', async event => {
|
|
87
|
+
const button = event.target.closest?.('[data-turn-action]'), row = button?.closest('.turn-result')
|
|
88
|
+
if (!row || !box.contains(row)) return
|
|
89
|
+
const context = host.capture(), atSeq = Number(row.dataset.turnSeq)
|
|
90
|
+
if (context.sessionId !== row.dataset.turnSession || !context.valid()) return
|
|
91
|
+
const result = summarize(context.entries, context.sessionId).get(atSeq)
|
|
92
|
+
if (!result) return
|
|
93
|
+
const key = context.key + ':' + context.sessionId + ':' + atSeq + ':' + button.dataset.turnAction
|
|
94
|
+
if (pending.has(key)) return
|
|
95
|
+
const status = row.querySelector('.turn-result-status')
|
|
96
|
+
pending.add(key); button.disabled = true
|
|
97
|
+
try {
|
|
98
|
+
if (button.dataset.turnAction === 'copy') {
|
|
99
|
+
if (!result.text || !await host.copy(result.text)) throw Error(text('复制失败,请重试', 'Copy failed. Please retry.'))
|
|
100
|
+
if (context.valid()) status.textContent = text('已复制', 'Copied')
|
|
101
|
+
} else if (button.dataset.turnAction === 'fork' && context.canFork) {
|
|
102
|
+
// No prompt is sent to the child. Unknown write receipts are never replayed.
|
|
103
|
+
const child = await host.fork({ sessionId: context.sessionId, atSeq })
|
|
104
|
+
if (!context.valid()) return
|
|
105
|
+
if (!child?.sessionId) throw Error(text('主机未返回分支会话', 'The host did not return a branch session'))
|
|
106
|
+
await host.open(child.sessionId, context)
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (context.valid()) status.textContent = error.message || text('操作失败', 'Action failed')
|
|
110
|
+
} finally {
|
|
111
|
+
pending.delete(key)
|
|
112
|
+
if (context.valid()) button.disabled = false
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
const api = { summarize, decorate, html, bind }
|
|
117
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
118
|
+
else root.DshTurnResults = api
|
|
119
|
+
})(typeof window === 'undefined' ? globalThis : window)
|
package/public/update.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.0-rc.
|
|
2
|
+
"version": "0.8.0-rc.4",
|
|
3
3
|
"apkUrl": "dsh-remote.apk",
|
|
4
|
-
"sha256": "
|
|
5
|
-
"releasedAt": "2026-10-
|
|
6
|
-
"notes": "0.8.0
|
|
4
|
+
"sha256": "317014a140e50fe7eec4835995c6819dcaac29ad7f42419a280fc68f04e5e6d6",
|
|
5
|
+
"releasedAt": "2026-10-18T11:53:28.027Z",
|
|
6
|
+
"notes": "0.8.0-rc.4:修复 Desktop 状态探测、重启恢复与 WebSocket 重连,避免切换主机后状态串线;修复会话历史空白、返回阻塞及缓存异常后的恢复,支持异常记录隔离和重试;新增回复结果复制、分支、用量与时间显示,修复普通分支会话隐藏;公告支持填空、多选及混合问卷,适配智能体团队查看;恢复按 dsh-cost-meter 规则发送的 Android 峰谷提醒,补齐后台状态诊断;新增仅保存在用户设备的操作日志,支持预览、复制、导出与清除。",
|
|
7
7
|
"history": [
|
|
8
8
|
{
|
|
9
9
|
"version": "0.7.6",
|
package/public/version.json
CHANGED