@deepslacker/dsh-task-progress 0.0.0-stage → 0.5.13
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/CHANGELOG.md +101 -0
- package/LICENSE +21 -0
- package/README.en.md +177 -0
- package/README.md +180 -2
- package/client.js +1515 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +106 -0
- package/docs/DETAIL.zh.md +106 -0
- package/docs/images/scene-completed.png +0 -0
- package/docs/images/scene-progress.png +0 -0
- package/docs/mockups/README.md +8 -0
- package/docs/mockups/scenes.html +408 -0
- package/icon.svg +1 -0
- package/index.js +435 -0
- package/lib/judge.js +168 -0
- package/lib/progress.js +213 -0
- package/lib/steps.js +87 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +57 -4
package/client.js
ADDED
|
@@ -0,0 +1,1515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-task-progress — browser half.
|
|
3
|
+
*
|
|
4
|
+
* Two occupants over the Host's `taskProgress` session projection:
|
|
5
|
+
* - `conversation.input.dock`: the running task's bar, phase, and next node
|
|
6
|
+
* above the composer, visible only while the task runs (plus a short
|
|
7
|
+
* completion hold). The bar shows the open turn's own 0–100%; every
|
|
8
|
+
* milestone the evaluator names during that turn becomes a node, and the
|
|
9
|
+
* milestone the page is showing right now is the outlined node at the head.
|
|
10
|
+
* - `sidebar.session.row.trailing`: a small progress ring on the session row,
|
|
11
|
+
* visible only for a running session and never for a finished one.
|
|
12
|
+
*
|
|
13
|
+
* Both read the projection the Host already publishes: the dock through the
|
|
14
|
+
* session-scoped `useProjection` hook, the row through the session list's
|
|
15
|
+
* projection store. The milestone rail arrives on the same read-only route as
|
|
16
|
+
* the evaluator's estimates. No polling per component, no session-log folding
|
|
17
|
+
* on the Client.
|
|
18
|
+
*/
|
|
19
|
+
window.__ModuleLoader__.load({
|
|
20
|
+
id: '@deepslacker/dsh-task-progress',
|
|
21
|
+
factory(require) {
|
|
22
|
+
const React = require('react')
|
|
23
|
+
const h = React.createElement
|
|
24
|
+
|
|
25
|
+
const NS = 'task-progress'
|
|
26
|
+
/** A task is "stale" after this long without a new checkpoint while running. */
|
|
27
|
+
const STALE_MS = 90_000
|
|
28
|
+
/** How long the finished state stays on screen after the turn ends. */
|
|
29
|
+
const LINGER_MS = 1500
|
|
30
|
+
/** Before this long with no checkpoint the strip stays hidden instead of flashing. */
|
|
31
|
+
const EVALUATING_AFTER_MS = 12_000
|
|
32
|
+
/** A checkpoint from the working model younger than this outranks the evaluator. */
|
|
33
|
+
const MODEL_FRESH_MS = 180_000
|
|
34
|
+
/** Poll period of the evaluator store. */
|
|
35
|
+
const JUDGE_POLL_MS = 2_000
|
|
36
|
+
/** Host route serving the evaluator's estimates and the milestone rail. */
|
|
37
|
+
const JUDGE_URL = '/api/dsh-task-progress/judgements'
|
|
38
|
+
|
|
39
|
+
const DICT = {
|
|
40
|
+
zh: {
|
|
41
|
+
'phase.plan': '规划',
|
|
42
|
+
'phase.execute': '执行',
|
|
43
|
+
'phase.verify': '验证',
|
|
44
|
+
'phase.deliver': '交付',
|
|
45
|
+
'done': '已完成',
|
|
46
|
+
'progress.aria': '任务进度',
|
|
47
|
+
'progress.eta': '约 {n} 分钟',
|
|
48
|
+
'progress.estimated': '按待办估算',
|
|
49
|
+
'progress.next': '下一步:{x}',
|
|
50
|
+
'progress.done': '任务已完成',
|
|
51
|
+
'progress.evaluating': '评估中',
|
|
52
|
+
'progress.elapsed': '已进行 {t}',
|
|
53
|
+
'progress.analyzing': '正在分析本轮进展',
|
|
54
|
+
'step.index': '节点 {n}',
|
|
55
|
+
'step.node': '节点 {n}:{x},耗时 {t}',
|
|
56
|
+
'step.duration': '耗时 {t}',
|
|
57
|
+
'step.finished': '{t} 完成',
|
|
58
|
+
'step.running': '进行中',
|
|
59
|
+
'step.elapsed': '已用 {t}',
|
|
60
|
+
'list.title': '节点',
|
|
61
|
+
'tab.title': '节点',
|
|
62
|
+
'tab.heading': '本次任务节点',
|
|
63
|
+
'tab.count': '{n} 个节点',
|
|
64
|
+
'tab.empty': '本轮还没有节点记录。',
|
|
65
|
+
'footer.view': '查看本次任务节点',
|
|
66
|
+
'list.expand': '展开节点列表',
|
|
67
|
+
'list.collapse': '收起节点列表',
|
|
68
|
+
'list.aria': '节点列表',
|
|
69
|
+
'list.colon': ':',
|
|
70
|
+
'duration.sec': '{n} 秒',
|
|
71
|
+
'duration.min': '{n} 分钟',
|
|
72
|
+
'duration.minSec': '{m} 分 {s} 秒',
|
|
73
|
+
'duration.hour': '{n} 小时',
|
|
74
|
+
'duration.hourMin': '{h} 小时 {m} 分',
|
|
75
|
+
'settings.title': '任务进度',
|
|
76
|
+
'settings.lead': '进度条显示在输入框上方,这里调整它的外观;未改动的项跟随主题。',
|
|
77
|
+
'settings.height': '进度条高度',
|
|
78
|
+
'settings.height.desc': '2–24 像素,默认 6。',
|
|
79
|
+
'settings.color': '进度条颜色',
|
|
80
|
+
'settings.color.desc': '支持 #hex、rgb()、var(--xxx);清空则跟随主题强调色。',
|
|
81
|
+
'settings.color.value': '颜色值',
|
|
82
|
+
'settings.color.auto': '跟随主题',
|
|
83
|
+
'settings.font': '说明文字字号',
|
|
84
|
+
'settings.font.desc': '进度条下方说明行的字号,9–24 像素,默认 12。',
|
|
85
|
+
'settings.listFont': '节点列表字号',
|
|
86
|
+
'settings.listFont.desc': '展开列表的行字号,9–24 像素,默认 11。',
|
|
87
|
+
'settings.preview': '预览:执行中 · 接入事件 · 下一步:打磨',
|
|
88
|
+
'settings.preview.done': '预览:节点已完成',
|
|
89
|
+
'settings.preview.live': '预览:正在调整外观',
|
|
90
|
+
'settings.preview.next': '检查节点详情卡',
|
|
91
|
+
'settings.reset': '恢复默认',
|
|
92
|
+
},
|
|
93
|
+
en: {
|
|
94
|
+
'phase.plan': 'Planning',
|
|
95
|
+
'phase.execute': 'Executing',
|
|
96
|
+
'phase.verify': 'Verifying',
|
|
97
|
+
'phase.deliver': 'Delivering',
|
|
98
|
+
'done': 'Done',
|
|
99
|
+
'progress.aria': 'Task progress',
|
|
100
|
+
'progress.eta': '~{n} min left',
|
|
101
|
+
'progress.estimated': 'estimated from todos',
|
|
102
|
+
'progress.next': 'Next: {x}',
|
|
103
|
+
'progress.done': 'Task complete',
|
|
104
|
+
'progress.evaluating': 'Evaluating',
|
|
105
|
+
'progress.elapsed': '{t} elapsed',
|
|
106
|
+
'progress.analyzing': 'Reviewing this turn',
|
|
107
|
+
'step.index': 'Node {n}',
|
|
108
|
+
'step.node': 'Node {n}: {x}, took {t}',
|
|
109
|
+
'step.duration': 'took {t}',
|
|
110
|
+
'step.finished': 'finished {t}',
|
|
111
|
+
'step.running': 'In progress',
|
|
112
|
+
'step.elapsed': '{t} elapsed',
|
|
113
|
+
'list.title': 'Nodes',
|
|
114
|
+
'tab.title': 'Nodes',
|
|
115
|
+
'tab.heading': 'Nodes for this task',
|
|
116
|
+
'tab.count': '{n} nodes',
|
|
117
|
+
'tab.empty': 'No nodes recorded for this turn yet.',
|
|
118
|
+
'footer.view': "View this task's nodes",
|
|
119
|
+
'list.expand': 'Expand node list',
|
|
120
|
+
'list.collapse': 'Collapse node list',
|
|
121
|
+
'list.aria': 'Node list',
|
|
122
|
+
'list.colon': ': ',
|
|
123
|
+
'duration.sec': '{n}s',
|
|
124
|
+
'duration.min': '{n} min',
|
|
125
|
+
'duration.minSec': '{m}m {s}s',
|
|
126
|
+
'duration.hour': '{n} h',
|
|
127
|
+
'duration.hourMin': '{h} h {m} min',
|
|
128
|
+
'settings.title': 'Task progress',
|
|
129
|
+
'settings.lead': 'The progress strip sits above the composer; adjust its appearance here. Untouched fields follow the theme.',
|
|
130
|
+
'settings.height': 'Bar height',
|
|
131
|
+
'settings.height.desc': '2–24 px, default 6.',
|
|
132
|
+
'settings.color': 'Bar color',
|
|
133
|
+
'settings.color.desc': 'Accepts #hex, rgb(), var(--x); clear it to use the theme accent.',
|
|
134
|
+
'settings.color.value': 'Color value',
|
|
135
|
+
'settings.color.auto': 'Theme accent',
|
|
136
|
+
'settings.font': 'Explanation size',
|
|
137
|
+
'settings.font.desc': 'Font size of the line under the bar, 9–24 px, default 12.',
|
|
138
|
+
'settings.listFont': 'Node list font size',
|
|
139
|
+
'settings.listFont.desc': 'Font size of the expanded list rows, 9–24 px, default 11.',
|
|
140
|
+
'settings.preview': 'Preview: executing · wiring events · next: polish',
|
|
141
|
+
'settings.preview.done': 'Preview: node finished',
|
|
142
|
+
'settings.preview.live': 'Preview: tuning the appearance',
|
|
143
|
+
'settings.preview.next': 'Check the node card',
|
|
144
|
+
'settings.reset': 'Reset to defaults',
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Current UI language, used only when the slot hands no translator. */
|
|
149
|
+
function language() {
|
|
150
|
+
const lang = String(
|
|
151
|
+
(typeof document !== 'undefined' && document.documentElement && document.documentElement.lang) || 'en',
|
|
152
|
+
).toLowerCase()
|
|
153
|
+
return lang.indexOf('zh') === 0 ? 'zh' : 'en'
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Translate through the slot translator, falling back to this module's dictionary. */
|
|
157
|
+
function tt(t, key, params) {
|
|
158
|
+
if (typeof t === 'function') {
|
|
159
|
+
const text = t(key, params)
|
|
160
|
+
if (typeof text === 'string' && text !== key) return text
|
|
161
|
+
}
|
|
162
|
+
const dict = DICT[language()] || DICT.en
|
|
163
|
+
const template = dict[key] !== undefined ? dict[key] : key
|
|
164
|
+
if (params === undefined) return template
|
|
165
|
+
return template.replace(/\{(\w+)\}/gu, (whole, name) => (params[name] === undefined ? whole : String(params[name])))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Keep a completed bar on screen briefly, then hide it. */
|
|
169
|
+
function useLinger(active, ms) {
|
|
170
|
+
const [held, setHeld] = React.useState(false)
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
if (active) setHeld(true)
|
|
173
|
+
}, [active])
|
|
174
|
+
React.useEffect(() => {
|
|
175
|
+
if (active) return undefined
|
|
176
|
+
const timer = setTimeout(() => setHeld(false), ms)
|
|
177
|
+
return () => clearTimeout(timer)
|
|
178
|
+
}, [active, ms])
|
|
179
|
+
return active || held
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A coarse clock, ticking only while something is visible. */
|
|
183
|
+
function useNow(enabled) {
|
|
184
|
+
const [now, setNow] = React.useState(() => Date.now())
|
|
185
|
+
React.useEffect(() => {
|
|
186
|
+
if (!enabled) return undefined
|
|
187
|
+
setNow(Date.now())
|
|
188
|
+
const timer = setInterval(() => setNow(Date.now()), 1000)
|
|
189
|
+
return () => clearInterval(timer)
|
|
190
|
+
}, [enabled])
|
|
191
|
+
return now
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const DOCK_CSS = [
|
|
195
|
+
// Two rows on the composer's own width axis: the bar owns the first row,
|
|
196
|
+
// the explanation the second. The width/centering formula is copied from
|
|
197
|
+
// the host's dock cards (TodoPanel) so the strip lines up with the
|
|
198
|
+
// conversation text column and follows the width handle exactly.
|
|
199
|
+
'.dtp-dock{display:flex;flex-direction:column;gap:3px;box-sizing:border-box;',
|
|
200
|
+
'width:calc(100% - var(--dsh-composer-side-clearance,16px) - var(--dsh-composer-side-clearance,16px)',
|
|
201
|
+
' - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px)',
|
|
202
|
+
' - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px));',
|
|
203
|
+
'max-width:calc(var(--dsh-composer-card-max-width,100%)',
|
|
204
|
+
' - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px)',
|
|
205
|
+
' - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px));',
|
|
206
|
+
'margin:0 auto;padding:2px 0 4px;font-size:12px;line-height:16px;',
|
|
207
|
+
'color:var(--dsw-alias-label-secondary);}',
|
|
208
|
+
'.dtp-dock[data-stale]{opacity:.72}',
|
|
209
|
+
'.dtp-row{display:flex;align-items:center;gap:8px;min-width:0;width:100%;}',
|
|
210
|
+
'.dtp-meta{font-size:var(--dtp-font-size,12px);line-height:1.45;}',
|
|
211
|
+
// The wrapper owns a taller hover target than the 6px rail itself, and
|
|
212
|
+
// negative margins keep the row's layout height unchanged while the
|
|
213
|
+
// track grows vertically on hover.
|
|
214
|
+
'.dtp-bar{position:relative;flex:1 1 auto;min-width:0;display:flex;align-items:center;',
|
|
215
|
+
'padding-block:7px;margin-block:-7px;}',
|
|
216
|
+
'.dtp-track{position:relative;flex:1 1 auto;min-width:0;width:100%;height:var(--dtp-bar-height,6px);',
|
|
217
|
+
'border-radius:999px;background:var(--dsw-alias-interactive-bg-hover);overflow:hidden;',
|
|
218
|
+
'transform-origin:center;transition:transform .2s cubic-bezier(.2,.7,.3,1),box-shadow .2s ease;}',
|
|
219
|
+
'.dtp-bar:hover .dtp-track{transform:scaleY(1.9);',
|
|
220
|
+
'box-shadow:0 0 0 1px color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 22%,transparent),',
|
|
221
|
+
'0 2px 12px -2px color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 55%,transparent);}',
|
|
222
|
+
'.dtp-fill{position:absolute;inset-block:0;inset-inline-start:0;border-radius:999px;',
|
|
223
|
+
'background:var(--dtp-bar-color,var(--dsw-alias-state-business-primary));transition:width .45s ease;}',
|
|
224
|
+
'.dtp-dock[data-stale] .dtp-fill{animation:dtp-pulse 1.6s ease-in-out infinite;}',
|
|
225
|
+
'.dtp-dock[data-evaluating] .dtp-fill{animation:dtp-pulse 1.6s ease-in-out infinite;}',
|
|
226
|
+
'.dtp-scan{position:absolute;inset-block:0;inset-inline-start:0;width:34%;pointer-events:none;',
|
|
227
|
+
'border-radius:999px;opacity:.45;',
|
|
228
|
+
'background:linear-gradient(90deg,transparent,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)),transparent);',
|
|
229
|
+
'animation:dtp-slide 1.6s ease-in-out infinite;}',
|
|
230
|
+
// Milestone nodes are a sibling overlay, so the track can keep its own
|
|
231
|
+
// overflow clip for the fill.
|
|
232
|
+
'.dtp-nodes{position:absolute;inset:0;pointer-events:none;}',
|
|
233
|
+
'.dtp-node{position:absolute;top:50%;width:16px;height:16px;margin:-8px 0 0 -8px;padding:0;',
|
|
234
|
+
'border:0;background:transparent;border-radius:50%;pointer-events:auto;cursor:pointer;',
|
|
235
|
+
'display:inline-flex;align-items:center;justify-content:center;color:inherit;}',
|
|
236
|
+
'.dtp-node:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px;}',
|
|
237
|
+
'.dtp-node-dot{display:block;width:8px;height:8px;border-radius:50%;box-sizing:border-box;',
|
|
238
|
+
'background:var(--dtp-bar-color,var(--dsw-alias-state-business-primary));',
|
|
239
|
+
'box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base,#fff));',
|
|
240
|
+
'transition:transform .15s ease;}',
|
|
241
|
+
'.dtp-node-current{z-index:2}',
|
|
242
|
+
'.dtp-node-current .dtp-node-dot{width:9px;height:9px;',
|
|
243
|
+
'background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-1,#fff));',
|
|
244
|
+
'border:2px solid var(--dtp-bar-color,var(--dsw-alias-state-business-primary));}',
|
|
245
|
+
'.dtp-node:hover .dtp-node-dot,.dtp-node:focus-visible .dtp-node-dot{transform:scale(1.35);}',
|
|
246
|
+
'.dtp-tip{position:absolute;bottom:calc(100% + 8px);left:50%;transform:translateX(-50%);',
|
|
247
|
+
'display:flex;flex-direction:column;gap:3px;width:max-content;max-width:280px;padding:8px 10px;',
|
|
248
|
+
'border-radius:10px;border:0.5px solid var(--dsw-alias-border-l1);',
|
|
249
|
+
'background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-1,#fff));',
|
|
250
|
+
'box-shadow:0 8px 28px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary);',
|
|
251
|
+
'font-size:12px;line-height:1.5;pointer-events:none;z-index:20;text-align:left;white-space:normal;}',
|
|
252
|
+
'.dtp-node[data-edge="start"] .dtp-tip{left:-4px;transform:none;}',
|
|
253
|
+
'.dtp-node[data-edge="end"] .dtp-tip{left:auto;right:-4px;transform:none;}',
|
|
254
|
+
'.dtp-tip-head{display:flex;align-items:center;gap:6px;font-size:11px;',
|
|
255
|
+
'color:var(--dsw-alias-label-tertiary);}',
|
|
256
|
+
'.dtp-tip-badge{flex:none;padding:0 5px;border-radius:999px;font-size:10px;line-height:16px;',
|
|
257
|
+
'background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#16a34a) 14%,transparent);',
|
|
258
|
+
'color:var(--dsw-alias-state-success-primary,#16a34a);}',
|
|
259
|
+
'.dtp-tip-badge-live{background:color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 14%,transparent);',
|
|
260
|
+
'color:var(--dtp-bar-color,var(--dsw-alias-state-business-primary));}',
|
|
261
|
+
'.dtp-tip-main{font-size:13px;line-height:1.45;font-weight:600;overflow-wrap:anywhere;}',
|
|
262
|
+
'.dtp-tip-sub{font-size:11px;line-height:1.45;color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere;}',
|
|
263
|
+
'.dtp-tip-meta{font-size:11px;line-height:1.45;color:var(--dsw-alias-label-secondary);',
|
|
264
|
+
'font-variant-numeric:tabular-nums;}',
|
|
265
|
+
'.dtp-pct{flex:none;color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;}',
|
|
266
|
+
'.dtp-phase{flex:none;padding:0 7px;border:1px solid var(--dsw-alias-border-l1);border-radius:999px;',
|
|
267
|
+
'font-size:calc(var(--dtp-font-size,12px) - 1px);line-height:1.35;color:var(--dsw-alias-label-tertiary);}',
|
|
268
|
+
'.dtp-text{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
269
|
+
'.dtp-eta{flex:none;margin-inline-start:auto;color:var(--dsw-alias-label-tertiary);',
|
|
270
|
+
'font-variant-numeric:tabular-nums;}',
|
|
271
|
+
'.dtp-expand{flex:none;display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 6px;',
|
|
272
|
+
'border:0.5px solid var(--dsw-alias-border-l1);border-radius:999px;background:transparent;',
|
|
273
|
+
'color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;font-size:11px;line-height:18px;',
|
|
274
|
+
'font-variant-numeric:tabular-nums;}',
|
|
275
|
+
'.dtp-expand:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);}',
|
|
276
|
+
'.dtp-expand:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px;}',
|
|
277
|
+
'.dtp-expand-arrow{font-size:10px;line-height:1;color:var(--dsw-alias-label-tertiary);}',
|
|
278
|
+
'.dtp-expand-badge{min-width:16px;padding:0 4px;border-radius:999px;text-align:center;',
|
|
279
|
+
'background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 14%,transparent);',
|
|
280
|
+
'color:var(--dsw-alias-state-business-primary);font-size:10px;line-height:16px;}',
|
|
281
|
+
'.dtp-list{margin-top:2px;border:0.5px solid var(--dsw-alias-border-l1);border-radius:8px;',
|
|
282
|
+
'background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base,#fff));padding:3px 0;',
|
|
283
|
+
'box-sizing:border-box;height:180px;overflow:auto;',
|
|
284
|
+
'font-size:var(--dtp-list-font-size,11px);line-height:1.5;}',
|
|
285
|
+
'.dtp-list-row{display:flex;align-items:baseline;gap:5px;padding:2px 8px;min-width:0;}',
|
|
286
|
+
'.dtp-list-row-live{background:color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 6%,transparent);}',
|
|
287
|
+
'.dtp-list-index{flex:none;color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;}',
|
|
288
|
+
'.dtp-list-badge{flex:none;padding:0 5px;border-radius:999px;',
|
|
289
|
+
'font-size:calc(var(--dtp-list-font-size,11px) - 1px);line-height:1.4;',
|
|
290
|
+
'background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#16a34a) 14%,transparent);',
|
|
291
|
+
'color:var(--dsw-alias-state-success-primary,#16a34a);}',
|
|
292
|
+
'.dtp-list-badge-live{background:color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 14%,transparent);',
|
|
293
|
+
'color:var(--dtp-bar-color,var(--dsw-alias-state-business-primary));}',
|
|
294
|
+
'.dtp-list-colon{flex:none;color:var(--dsw-alias-label-tertiary);}',
|
|
295
|
+
'.dtp-list-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;',
|
|
296
|
+
'color:var(--dsw-alias-label-secondary);}',
|
|
297
|
+
'.dtp-list-meta{flex:none;color:var(--dsw-alias-label-tertiary);',
|
|
298
|
+
'font-size:calc(var(--dtp-list-font-size,11px) - 1px);font-variant-numeric:tabular-nums;white-space:nowrap;}',
|
|
299
|
+
'.dtp-list-rule{height:1px;margin:3px 8px;background:var(--dsw-alias-border-l1);}',
|
|
300
|
+
'@keyframes dtp-pulse{0%,100%{opacity:1}50%{opacity:.5}}',
|
|
301
|
+
'@keyframes dtp-slide{0%{transform:translateX(-110%)}100%{transform:translateX(300%)}}',
|
|
302
|
+
'@media (prefers-reduced-motion:reduce){',
|
|
303
|
+
'.dtp-track,.dtp-node-dot{transition:none}',
|
|
304
|
+
'.dtp-dock[data-stale] .dtp-fill,.dtp-dock[data-evaluating] .dtp-fill,.dtp-scan{animation:none}}',
|
|
305
|
+
].join('')
|
|
306
|
+
|
|
307
|
+
/** Short clock for the evaluating state (`m:ss`). */
|
|
308
|
+
function clock(ms) {
|
|
309
|
+
const total = Math.max(0, Math.floor(ms / 1000))
|
|
310
|
+
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, '0')}`
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Human duration of one milestone. */
|
|
314
|
+
function durationText(t, ms) {
|
|
315
|
+
const total = Math.max(0, Math.round((Number(ms) || 0) / 1000))
|
|
316
|
+
if (total < 60) return tt(t, 'duration.sec', { n: total })
|
|
317
|
+
const minutes = Math.floor(total / 60)
|
|
318
|
+
const seconds = total % 60
|
|
319
|
+
if (minutes < 60) {
|
|
320
|
+
return seconds === 0
|
|
321
|
+
? tt(t, 'duration.min', { n: minutes })
|
|
322
|
+
: tt(t, 'duration.minSec', { m: minutes, s: seconds })
|
|
323
|
+
}
|
|
324
|
+
const hours = Math.floor(minutes / 60)
|
|
325
|
+
const rest = minutes % 60
|
|
326
|
+
return rest === 0
|
|
327
|
+
? tt(t, 'duration.hour', { n: hours })
|
|
328
|
+
: tt(t, 'duration.hourMin', { h: hours, m: rest })
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Wall-clock `HH:MM` of a completion timestamp, or `''` when unknown. */
|
|
332
|
+
function timeText(ts) {
|
|
333
|
+
if (!(Number(ts) > 0)) return ''
|
|
334
|
+
try {
|
|
335
|
+
return new Intl.DateTimeFormat(language() === 'zh' ? 'zh-CN' : 'en-US', {
|
|
336
|
+
hour: '2-digit',
|
|
337
|
+
minute: '2-digit',
|
|
338
|
+
hour12: false,
|
|
339
|
+
}).format(new Date(ts))
|
|
340
|
+
} catch {
|
|
341
|
+
return ''
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** A node's horizontal position, kept inside the rounded rail. */
|
|
346
|
+
function railPosition(value) {
|
|
347
|
+
const number = Number(value)
|
|
348
|
+
if (!Number.isFinite(number)) return 0
|
|
349
|
+
return Math.max(0, Math.min(99, Math.round(number * 10) / 10))
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The open turn's milestone rail from the polled Host value. */
|
|
353
|
+
function railStepsOf(store, sessionId, turn) {
|
|
354
|
+
if (store === null || store === undefined || store.rails === null || store.rails === undefined) return []
|
|
355
|
+
const rail = store.rails[sessionId]
|
|
356
|
+
if (rail === null || rail === undefined || rail.turn !== turn || !Array.isArray(rail.steps)) return []
|
|
357
|
+
return rail.steps
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The plugin's task-progress glyph (the same paths as icon.svg), tinted by CSS. */
|
|
361
|
+
const GLYPH_PATHS = [
|
|
362
|
+
'M394.88 844.16a349.44 349.44 0 0 1-117.44-69.76 32 32 0 0 0-42.56 47.68 413.76 413.76 0 0 0 138.88 82.24 32 32 0 0 0 10.56 1.92 32 32 0 0 0 10.56-62.08zM489.28 873.28A32 32 0 0 0 480 896a32 32 0 0 0 2.56 12.16 37.12 37.12 0 0 0 6.72 10.56 36.8 36.8 0 0 0 10.56 6.72 30.08 30.08 0 0 0 24.32 0 28.8 28.8 0 0 0 17.28-17.28A32 32 0 0 0 544 896a32 32 0 0 0-54.72-22.72z',
|
|
363
|
+
'M512 32v64A416 416 0 0 0 151.68 720a32 32 0 1 0 55.36-32A352 352 0 0 1 512 160v64a288 288 0 0 1 288 288h64a352 352 0 0 1-234.56 332.16 32 32 0 1 0 21.44 60.16A416 416 0 0 0 928 512h64A480 480 0 0 0 512 32z',
|
|
364
|
+
]
|
|
365
|
+
|
|
366
|
+
function ProgressGlyph({ size = 16, className }) {
|
|
367
|
+
return h(
|
|
368
|
+
'svg',
|
|
369
|
+
{
|
|
370
|
+
className,
|
|
371
|
+
width: size,
|
|
372
|
+
height: size,
|
|
373
|
+
viewBox: '0 0 1024 1024',
|
|
374
|
+
fill: 'currentColor',
|
|
375
|
+
'aria-hidden': 'true',
|
|
376
|
+
focusable: 'false',
|
|
377
|
+
},
|
|
378
|
+
GLYPH_PATHS.map((d, index) => h('path', { key: index, d })),
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Polled store of the Host evaluator's estimates and milestone rails,
|
|
384
|
+
* keyed by session id. It only polls while something subscribes and the
|
|
385
|
+
* page is visible.
|
|
386
|
+
*/
|
|
387
|
+
function createJudgementStore(url) {
|
|
388
|
+
let snapshot = { sessions: {}, rails: {}, style: null }
|
|
389
|
+
let timer = null
|
|
390
|
+
let inFlight = false
|
|
391
|
+
const listeners = new Set()
|
|
392
|
+
const emit = () => { for (const listener of listeners) listener() }
|
|
393
|
+
const poll = async () => {
|
|
394
|
+
if (inFlight) return
|
|
395
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
|
396
|
+
inFlight = true
|
|
397
|
+
try {
|
|
398
|
+
const response = await fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store' })
|
|
399
|
+
if (!response.ok) return
|
|
400
|
+
const body = await response.json()
|
|
401
|
+
const value = body !== null && typeof body === 'object' && body.ok === true
|
|
402
|
+
&& body.value !== null && typeof body.value === 'object' ? body.value : undefined
|
|
403
|
+
if (value === undefined) return
|
|
404
|
+
const sessions = value.sessions !== null && typeof value.sessions === 'object' ? value.sessions : {}
|
|
405
|
+
const rails = value.rails !== null && typeof value.rails === 'object' ? value.rails : {}
|
|
406
|
+
const style = value.style !== null && typeof value.style === 'object' ? value.style : null
|
|
407
|
+
const next = { sessions, rails, style }
|
|
408
|
+
if (JSON.stringify(next) === JSON.stringify(snapshot)) return
|
|
409
|
+
snapshot = next
|
|
410
|
+
emit()
|
|
411
|
+
} catch {
|
|
412
|
+
// A failing endpoint degrades to the projection's own value.
|
|
413
|
+
} finally {
|
|
414
|
+
inFlight = false
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
getSnapshot: () => snapshot,
|
|
419
|
+
subscribe(listener) {
|
|
420
|
+
listeners.add(listener)
|
|
421
|
+
if (timer === null) {
|
|
422
|
+
void poll()
|
|
423
|
+
timer = setInterval(() => { void poll() }, JUDGE_POLL_MS)
|
|
424
|
+
}
|
|
425
|
+
return () => {
|
|
426
|
+
listeners.delete(listener)
|
|
427
|
+
if (listeners.size === 0 && timer !== null) {
|
|
428
|
+
clearInterval(timer)
|
|
429
|
+
timer = null
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Defaults when neither the settings page, the Host row config, nor CSS set a knob. */
|
|
437
|
+
const STYLE_DEFAULTS = Object.freeze({ barHeight: 6, barColor: '', textFontSize: 12, listFontSize: 11 })
|
|
438
|
+
/** localStorage key of the appearance overrides edited in Settings. */
|
|
439
|
+
const STYLE_KEY = 'dsh-task-progress.style.v1'
|
|
440
|
+
|
|
441
|
+
/** Read the saved appearance overrides, discarding anything unusable. */
|
|
442
|
+
function readStyleOverrides() {
|
|
443
|
+
try {
|
|
444
|
+
const raw = window.localStorage.getItem(STYLE_KEY)
|
|
445
|
+
if (raw === null || raw === undefined || raw === '') return {}
|
|
446
|
+
const parsed = JSON.parse(raw)
|
|
447
|
+
if (parsed === null || typeof parsed !== 'object') return {}
|
|
448
|
+
const out = {}
|
|
449
|
+
if (Number.isFinite(parsed.barHeight) && parsed.barHeight > 0) out.barHeight = Math.min(24, Math.round(parsed.barHeight))
|
|
450
|
+
if (typeof parsed.barColor === 'string' && parsed.barColor !== '') out.barColor = parsed.barColor.slice(0, 40)
|
|
451
|
+
if (Number.isFinite(parsed.textFontSize) && parsed.textFontSize > 0) out.textFontSize = Math.min(24, Math.round(parsed.textFontSize))
|
|
452
|
+
if (Number.isFinite(parsed.listFontSize) && parsed.listFontSize > 0) out.listFontSize = Math.min(24, Math.max(9, Math.round(parsed.listFontSize)))
|
|
453
|
+
return out
|
|
454
|
+
} catch {
|
|
455
|
+
return {}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** Observable store of the appearance overrides edited in Settings. */
|
|
460
|
+
function createStyleStore() {
|
|
461
|
+
let snapshot = readStyleOverrides()
|
|
462
|
+
const listeners = new Set()
|
|
463
|
+
const emit = () => { for (const listener of listeners) listener() }
|
|
464
|
+
const persist = () => {
|
|
465
|
+
try {
|
|
466
|
+
if (Object.keys(snapshot).length === 0) window.localStorage.removeItem(STYLE_KEY)
|
|
467
|
+
else window.localStorage.setItem(STYLE_KEY, JSON.stringify(snapshot))
|
|
468
|
+
} catch {
|
|
469
|
+
// Storage can be blocked; the in-memory value still applies.
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
getSnapshot: () => snapshot,
|
|
474
|
+
subscribe(listener) {
|
|
475
|
+
listeners.add(listener)
|
|
476
|
+
return () => { listeners.delete(listener) }
|
|
477
|
+
},
|
|
478
|
+
set(patch) {
|
|
479
|
+
const next = { ...snapshot }
|
|
480
|
+
for (const key of Object.keys(patch)) {
|
|
481
|
+
const value = patch[key]
|
|
482
|
+
if (value === undefined || value === null || value === '' || value === 0) delete next[key]
|
|
483
|
+
else next[key] = value
|
|
484
|
+
}
|
|
485
|
+
snapshot = next
|
|
486
|
+
persist()
|
|
487
|
+
emit()
|
|
488
|
+
},
|
|
489
|
+
reset() {
|
|
490
|
+
snapshot = {}
|
|
491
|
+
persist()
|
|
492
|
+
emit()
|
|
493
|
+
},
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Merge the three layers of one presentation knob.
|
|
499
|
+
* Settings (local) > Host row config > theme default. The `explicit*`
|
|
500
|
+
* flags say whether a layer set the knob, so the strip only overrides the
|
|
501
|
+
* CSS variable it actually owns and everything else keeps the theme.
|
|
502
|
+
*/
|
|
503
|
+
function resolveStyle(host, local) {
|
|
504
|
+
const h = host !== null && host !== undefined ? host : {}
|
|
505
|
+
const l = local !== null && local !== undefined ? local : {}
|
|
506
|
+
const height = l.barHeight > 0 ? l.barHeight : h.barHeight > 0 ? h.barHeight : 0
|
|
507
|
+
const font = l.textFontSize > 0 ? l.textFontSize : h.textFontSize > 0 ? h.textFontSize : 0
|
|
508
|
+
const listFont = l.listFontSize > 0 ? l.listFontSize : h.listFontSize > 0 ? h.listFontSize : 0
|
|
509
|
+
const color = typeof l.barColor === 'string' && l.barColor !== ''
|
|
510
|
+
? l.barColor
|
|
511
|
+
: typeof h.barColor === 'string' ? h.barColor : ''
|
|
512
|
+
return {
|
|
513
|
+
barHeight: height > 0 ? height : STYLE_DEFAULTS.barHeight,
|
|
514
|
+
barColor: color,
|
|
515
|
+
textFontSize: font > 0 ? font : STYLE_DEFAULTS.textFontSize,
|
|
516
|
+
listFontSize: listFont > 0 ? listFont : STYLE_DEFAULTS.listFontSize,
|
|
517
|
+
explicitHeight: height > 0,
|
|
518
|
+
explicitColor: color !== '',
|
|
519
|
+
explicitFont: font > 0,
|
|
520
|
+
explicitListFont: listFont > 0,
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Overlay the evaluator's estimate on the projection value.
|
|
526
|
+
* @param progress - the session's `taskProgress` projection value.
|
|
527
|
+
* @param judgement - this session's evaluator entry, if any.
|
|
528
|
+
* @param now - wall clock used for the freshness rule.
|
|
529
|
+
* @returns the value the UI should show.
|
|
530
|
+
*/
|
|
531
|
+
function mergeJudgement(progress, judgement, now) {
|
|
532
|
+
if (progress === undefined || progress === null || progress.turn <= 0) return progress
|
|
533
|
+
if (progress.done === true) return progress
|
|
534
|
+
// The working model's own checkpoint is the best signal while it is fresh.
|
|
535
|
+
if (progress.source === 'model' && now - progress.updatedAt < MODEL_FRESH_MS) return progress
|
|
536
|
+
if (judgement === undefined || judgement === null || judgement.turn !== progress.turn) return progress
|
|
537
|
+
// An estimate computed before this turn began describes the previous task,
|
|
538
|
+
// even if a sweep raced it onto the new turn number.
|
|
539
|
+
const at = typeof judgement.at === 'number' ? judgement.at : 0
|
|
540
|
+
if (at < progress.startedAt) return progress
|
|
541
|
+
if (!(judgement.percent >= 0)) return progress
|
|
542
|
+
return {
|
|
543
|
+
...progress,
|
|
544
|
+
percent: judgement.percent,
|
|
545
|
+
source: 'judge',
|
|
546
|
+
phase: judgement.phase || progress.phase,
|
|
547
|
+
milestone: judgement.milestone || progress.milestone,
|
|
548
|
+
next: judgement.next || progress.next,
|
|
549
|
+
etaMin: judgement.etaMin > 0 ? judgement.etaMin : progress.etaMin,
|
|
550
|
+
updatedAt: Math.max(progress.updatedAt, judgement.at || 0),
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The running task's strip above the composer.
|
|
556
|
+
* @param useJudgements - hook over the evaluator/rail store.
|
|
557
|
+
* @param useStyle - hook over the appearance overrides.
|
|
558
|
+
*/
|
|
559
|
+
function makeProgressDock(useJudgements, useStyle) {
|
|
560
|
+
return function ProgressDock(props) {
|
|
561
|
+
const t = props.t
|
|
562
|
+
const raw = props.useProjection('taskProgress')
|
|
563
|
+
const store = useJudgements()
|
|
564
|
+
// Every hook must run before the first early return: the strip mounts
|
|
565
|
+
// hidden and becomes visible later, so a hook added below a `return`
|
|
566
|
+
// would change the hook count between renders and crash the slot.
|
|
567
|
+
const local = useStyle()
|
|
568
|
+
const [hovered, setHovered] = React.useState(null)
|
|
569
|
+
const [listOpen, setListOpen] = React.useState(false)
|
|
570
|
+
const entries = store !== null && store !== undefined && store.sessions !== null && store.sessions !== undefined
|
|
571
|
+
? store.sessions : {}
|
|
572
|
+
const sessionId = props.session !== undefined && props.session !== null ? props.session.sessionId : undefined
|
|
573
|
+
const progress = mergeJudgement(
|
|
574
|
+
raw,
|
|
575
|
+
sessionId !== undefined ? entries[sessionId] : undefined,
|
|
576
|
+
Date.now(),
|
|
577
|
+
)
|
|
578
|
+
const running = props.session !== undefined && props.session !== null && props.session.running === true
|
|
579
|
+
// A finished task stops counting as active immediately: the linger below
|
|
580
|
+
// keeps the completed bar for a moment, then hides it even while the
|
|
581
|
+
// session itself stays busy with background work.
|
|
582
|
+
const active = running && progress !== undefined && progress !== null && progress.turn > 0 && progress.done !== true
|
|
583
|
+
const visible = useLinger(active, LINGER_MS)
|
|
584
|
+
const now = useNow(visible)
|
|
585
|
+
if (!visible || progress === undefined || progress === null || progress.turn === 0) return null
|
|
586
|
+
const done = progress.done === true
|
|
587
|
+
const known = progress.percent >= 0
|
|
588
|
+
// A long first step (or a long tool batch) has no checkpoint yet: the
|
|
589
|
+
// model is blocked and cannot report. Show that a task is under
|
|
590
|
+
// evaluation instead of leaving the row blank or inventing a number.
|
|
591
|
+
const evaluating = !done && !known && progress.startedAt > 0
|
|
592
|
+
&& now - progress.startedAt >= EVALUATING_AFTER_MS
|
|
593
|
+
if (!done && !known && !evaluating) return null
|
|
594
|
+
const percent = done ? 100 : known ? progress.percent : 0
|
|
595
|
+
const stale = running && !done && known && progress.updatedAt > 0 && now - progress.updatedAt > STALE_MS
|
|
596
|
+
const phase = done ? tt(t, 'done') : known ? tt(t, `phase.${progress.phase}`) : tt(t, 'progress.evaluating')
|
|
597
|
+
const next = progress.next || ''
|
|
598
|
+
const elapsed = progress.startedAt > 0 ? now - progress.startedAt : 0
|
|
599
|
+
const detailParts = []
|
|
600
|
+
if (progress.milestone !== '') detailParts.push(progress.milestone)
|
|
601
|
+
if (next !== '') detailParts.push(tt(t, 'progress.next', { x: next }))
|
|
602
|
+
const detail = evaluating ? tt(t, 'progress.analyzing') : detailParts.join(' · ')
|
|
603
|
+
// Configured presentation rides CSS variables on the strip itself, so it
|
|
604
|
+
// only overrides what the owner actually set; unset knobs keep the theme.
|
|
605
|
+
const tuned = resolveStyle(
|
|
606
|
+
store !== null && store !== undefined ? store.style : null,
|
|
607
|
+
local,
|
|
608
|
+
)
|
|
609
|
+
const styleVars = {}
|
|
610
|
+
if (tuned.explicitHeight) styleVars['--dtp-bar-height'] = `${tuned.barHeight}px`
|
|
611
|
+
if (tuned.explicitColor) styleVars['--dtp-bar-color'] = tuned.barColor
|
|
612
|
+
if (tuned.explicitFont) styleVars['--dtp-font-size'] = `${tuned.textFontSize}px`
|
|
613
|
+
if (tuned.explicitListFont) styleVars['--dtp-list-font-size'] = `${tuned.listFontSize}px`
|
|
614
|
+
const fill = Math.max(2, evaluating ? 0 : Math.min(100, percent))
|
|
615
|
+
// The rail is per turn: a milestone the evaluator superseded is a
|
|
616
|
+
// completed node; the milestone on screen now is the outlined head.
|
|
617
|
+
const steps = sessionId !== undefined ? railStepsOf(store, sessionId, progress.turn) : []
|
|
618
|
+
const allEntries = steps
|
|
619
|
+
.map((step, index) => ({ step, index }))
|
|
620
|
+
.filter(entry => entry.step !== null && typeof entry.step === 'object')
|
|
621
|
+
const closedEntries = allEntries.filter(entry => entry.step.endedAt > 0)
|
|
622
|
+
const currentPercent = known ? Math.max(0, Math.min(100, progress.percent)) : 100
|
|
623
|
+
// Every completed node stays on the rail, in completion order. The
|
|
624
|
+
// evaluator can re-estimate a task downward, so a later node may carry a
|
|
625
|
+
// lower percentage than an earlier one; positions are therefore made
|
|
626
|
+
// monotonic (a later node never sits left of an earlier one) and capped
|
|
627
|
+
// at the fill head (a node from an earlier, higher estimate moves to the
|
|
628
|
+
// head instead of disappearing). Otherwise the rail can show node 9 as
|
|
629
|
+
// the last completed node while the badge already counts node 18.
|
|
630
|
+
const ceiling = done ? 100 : currentPercent
|
|
631
|
+
const placed = []
|
|
632
|
+
let floor = 0
|
|
633
|
+
for (const entry of closedEntries) {
|
|
634
|
+
const value = Number(entry.step.percent)
|
|
635
|
+
const raw = Number.isFinite(value) ? Math.max(0, Math.min(100, value)) : floor
|
|
636
|
+
const position = Math.min(ceiling, Math.max(floor, raw))
|
|
637
|
+
placed.push({ ...entry, position, lifted: raw < position })
|
|
638
|
+
floor = position
|
|
639
|
+
}
|
|
640
|
+
// A run of nodes lifted by a re-estimate keeps its order but spreads into
|
|
641
|
+
// the space before the next real position, so it does not pile on one dot.
|
|
642
|
+
for (let start = 0; start < placed.length;) {
|
|
643
|
+
if (!placed[start].lifted) { start += 1; continue }
|
|
644
|
+
let end = start
|
|
645
|
+
while (end + 1 < placed.length && placed[end + 1].lifted && placed[end + 1].position === placed[start].position) {
|
|
646
|
+
end += 1
|
|
647
|
+
}
|
|
648
|
+
const from = placed[start].position
|
|
649
|
+
const next = end + 1 < placed.length ? placed[end + 1].position : ceiling
|
|
650
|
+
const count = end - start + 1
|
|
651
|
+
for (let step = 0; step < count; step += 1) {
|
|
652
|
+
placed[start + step] = { ...placed[start + step], position: from + ((next - from) * (step + 1)) / (count + 1) }
|
|
653
|
+
}
|
|
654
|
+
start = end + 1
|
|
655
|
+
}
|
|
656
|
+
// The bar is spatial, but node numbers stay chronological so the card and
|
|
657
|
+
// the expanded list agree on which node is which.
|
|
658
|
+
const closed = placed
|
|
659
|
+
const open = steps.length > 0 && steps[steps.length - 1] !== null && typeof steps[steps.length - 1] === 'object'
|
|
660
|
+
? { step: steps[steps.length - 1], index: steps.length - 1 }
|
|
661
|
+
: undefined
|
|
662
|
+
const currentIndex = open !== undefined ? open.index : steps.length
|
|
663
|
+
const currentLabel = progress.milestone || ''
|
|
664
|
+
const currentSince = open !== undefined && open.step.endedAt === 0 && open.step.label === currentLabel
|
|
665
|
+
? open.step.at
|
|
666
|
+
: (progress.updatedAt > 0 ? progress.updatedAt : progress.startedAt)
|
|
667
|
+
const showCurrent = !done && !evaluating && known && currentLabel !== ''
|
|
668
|
+
const listCurrentLabel = currentLabel !== ''
|
|
669
|
+
? currentLabel
|
|
670
|
+
: (open !== undefined && open.step.endedAt === 0 ? open.step.label : '')
|
|
671
|
+
const listCurrent = !done && listCurrentLabel !== ''
|
|
672
|
+
? {
|
|
673
|
+
index: currentIndex,
|
|
674
|
+
label: listCurrentLabel,
|
|
675
|
+
phase: currentLabel !== '' ? progress.phase : (open !== undefined ? open.step.phase : progress.phase),
|
|
676
|
+
since: currentSince,
|
|
677
|
+
}
|
|
678
|
+
: undefined
|
|
679
|
+
const listDone = closedEntries
|
|
680
|
+
const listTotal = listDone.length + (listCurrent !== undefined ? 1 : 0)
|
|
681
|
+
const bucketKey = value => Math.round(Number(value || 0) * 2) / 2
|
|
682
|
+
const buckets = new Map()
|
|
683
|
+
for (const entry of closed) {
|
|
684
|
+
const key = bucketKey(entry.position)
|
|
685
|
+
const bucket = buckets.get(key)
|
|
686
|
+
if (bucket === undefined) buckets.set(key, [entry])
|
|
687
|
+
else bucket.push(entry)
|
|
688
|
+
}
|
|
689
|
+
const currentKey = bucketKey(currentPercent)
|
|
690
|
+
const nodeOffset = entry => {
|
|
691
|
+
const key = bucketKey(entry.position)
|
|
692
|
+
const bucket = buckets.get(key) ?? []
|
|
693
|
+
const rank = bucket.indexOf(entry)
|
|
694
|
+
let offset = (rank - (bucket.length - 1) / 2) * 16
|
|
695
|
+
if (showCurrent && key === currentKey) offset -= 16
|
|
696
|
+
return offset
|
|
697
|
+
}
|
|
698
|
+
const nodes = []
|
|
699
|
+
const edge = position => (position < 16 ? 'start' : position > 84 ? 'end' : undefined)
|
|
700
|
+
for (const entry of closed) {
|
|
701
|
+
const { step, index } = entry
|
|
702
|
+
const position = railPosition(entry.position)
|
|
703
|
+
const label = step.label || ''
|
|
704
|
+
const took = durationText(t, step.durationMs)
|
|
705
|
+
const finished = timeText(step.endedAt)
|
|
706
|
+
const meta = [tt(t, `phase.${step.phase}`)]
|
|
707
|
+
meta.push(tt(t, 'step.duration', { t: took }))
|
|
708
|
+
if (finished !== '') meta.push(tt(t, 'step.finished', { t: finished }))
|
|
709
|
+
const key = `step-${index}`
|
|
710
|
+
const activeNode = hovered === key
|
|
711
|
+
nodes.push(h(
|
|
712
|
+
'button',
|
|
713
|
+
{
|
|
714
|
+
key,
|
|
715
|
+
type: 'button',
|
|
716
|
+
className: 'dtp-node',
|
|
717
|
+
style: {
|
|
718
|
+
left: `${position}%`,
|
|
719
|
+
transform: nodeOffset(entry) === 0 ? undefined : `translateX(${nodeOffset(entry)}px)`,
|
|
720
|
+
},
|
|
721
|
+
'data-edge': edge(position),
|
|
722
|
+
'aria-label': tt(t, 'step.node', { n: index, x: label, t: took }),
|
|
723
|
+
onMouseDown: event => event.preventDefault(),
|
|
724
|
+
onMouseEnter: () => setHovered(key),
|
|
725
|
+
onMouseLeave: () => setHovered(value => (value === key ? null : value)),
|
|
726
|
+
onFocus: () => setHovered(key),
|
|
727
|
+
onBlur: () => setHovered(value => (value === key ? null : value)),
|
|
728
|
+
},
|
|
729
|
+
h('span', { className: 'dtp-node-dot' }),
|
|
730
|
+
activeNode
|
|
731
|
+
? h(
|
|
732
|
+
'span',
|
|
733
|
+
{ className: 'dtp-tip', role: 'tooltip' },
|
|
734
|
+
h(
|
|
735
|
+
'span',
|
|
736
|
+
{ className: 'dtp-tip-head' },
|
|
737
|
+
h('span', null, tt(t, 'step.index', { n: index })),
|
|
738
|
+
h('span', { className: 'dtp-tip-badge' }, tt(t, 'done')),
|
|
739
|
+
),
|
|
740
|
+
h('span', { className: 'dtp-tip-main' }, label),
|
|
741
|
+
h('span', { className: 'dtp-tip-meta' }, meta.join(' · ')),
|
|
742
|
+
)
|
|
743
|
+
: null,
|
|
744
|
+
))
|
|
745
|
+
}
|
|
746
|
+
if (showCurrent) {
|
|
747
|
+
const index = currentIndex
|
|
748
|
+
const position = railPosition(progress.percent)
|
|
749
|
+
const took = durationText(t, Math.max(0, now - currentSince))
|
|
750
|
+
const key = 'current'
|
|
751
|
+
const activeNode = hovered === key
|
|
752
|
+
const meta = [tt(t, `phase.${progress.phase}`), tt(t, 'step.elapsed', { t: took })]
|
|
753
|
+
nodes.push(h(
|
|
754
|
+
'button',
|
|
755
|
+
{
|
|
756
|
+
key,
|
|
757
|
+
type: 'button',
|
|
758
|
+
className: 'dtp-node dtp-node-current',
|
|
759
|
+
style: { left: `${position}%` },
|
|
760
|
+
'data-edge': edge(position),
|
|
761
|
+
'aria-label': tt(t, 'step.node', { n: index, x: currentLabel, t: took }),
|
|
762
|
+
onMouseDown: event => event.preventDefault(),
|
|
763
|
+
onMouseEnter: () => setHovered(key),
|
|
764
|
+
onMouseLeave: () => setHovered(value => (value === key ? null : value)),
|
|
765
|
+
onFocus: () => setHovered(key),
|
|
766
|
+
onBlur: () => setHovered(value => (value === key ? null : value)),
|
|
767
|
+
},
|
|
768
|
+
h('span', { className: 'dtp-node-dot' }),
|
|
769
|
+
activeNode
|
|
770
|
+
? h(
|
|
771
|
+
'span',
|
|
772
|
+
{ className: 'dtp-tip', role: 'tooltip' },
|
|
773
|
+
h(
|
|
774
|
+
'span',
|
|
775
|
+
{ className: 'dtp-tip-head' },
|
|
776
|
+
h('span', null, tt(t, 'step.index', { n: index })),
|
|
777
|
+
h('span', { className: 'dtp-tip-badge dtp-tip-badge-live' }, tt(t, 'step.running')),
|
|
778
|
+
),
|
|
779
|
+
h('span', { className: 'dtp-tip-main' }, currentLabel),
|
|
780
|
+
next !== '' ? h('span', { className: 'dtp-tip-sub' }, tt(t, 'progress.next', { x: next })) : null,
|
|
781
|
+
h('span', { className: 'dtp-tip-meta' }, meta.join(' · ')),
|
|
782
|
+
)
|
|
783
|
+
: null,
|
|
784
|
+
))
|
|
785
|
+
}
|
|
786
|
+
return h(
|
|
787
|
+
React.Fragment,
|
|
788
|
+
null,
|
|
789
|
+
h('style', { key: 'dtp-style' }, DOCK_CSS),
|
|
790
|
+
h(
|
|
791
|
+
'div',
|
|
792
|
+
{
|
|
793
|
+
className: 'dtp-dock',
|
|
794
|
+
style: styleVars,
|
|
795
|
+
'data-stale': stale ? '' : undefined,
|
|
796
|
+
'data-evaluating': evaluating ? '' : undefined,
|
|
797
|
+
},
|
|
798
|
+
// Row 1: the task's bar and its milestone rail.
|
|
799
|
+
h(
|
|
800
|
+
'div',
|
|
801
|
+
{ className: 'dtp-row' },
|
|
802
|
+
h(
|
|
803
|
+
'div',
|
|
804
|
+
{ className: 'dtp-bar' },
|
|
805
|
+
h(
|
|
806
|
+
'div',
|
|
807
|
+
{
|
|
808
|
+
className: 'dtp-track',
|
|
809
|
+
role: 'progressbar',
|
|
810
|
+
'aria-label': tt(t, 'progress.aria'),
|
|
811
|
+
'aria-valuemin': 0,
|
|
812
|
+
'aria-valuemax': 100,
|
|
813
|
+
'aria-valuenow': evaluating ? undefined : percent,
|
|
814
|
+
'aria-busy': evaluating ? true : undefined,
|
|
815
|
+
},
|
|
816
|
+
h('div', {
|
|
817
|
+
className: 'dtp-fill',
|
|
818
|
+
style: { width: `${fill}%` },
|
|
819
|
+
}),
|
|
820
|
+
evaluating ? h('div', { className: 'dtp-scan' }) : null,
|
|
821
|
+
),
|
|
822
|
+
nodes.length > 0 ? h('div', { className: 'dtp-nodes' }, nodes) : null,
|
|
823
|
+
),
|
|
824
|
+
evaluating
|
|
825
|
+
? null
|
|
826
|
+
: h(
|
|
827
|
+
'span',
|
|
828
|
+
{ className: 'dtp-pct' },
|
|
829
|
+
`${!done && progress.source === 'todo' ? '≈' : ''}${percent}%`,
|
|
830
|
+
),
|
|
831
|
+
),
|
|
832
|
+
// Row 2: what the number means — phase, current node, next node, time.
|
|
833
|
+
h(
|
|
834
|
+
'div',
|
|
835
|
+
{ className: 'dtp-row dtp-meta' },
|
|
836
|
+
listTotal > 0
|
|
837
|
+
? h(
|
|
838
|
+
'button',
|
|
839
|
+
{
|
|
840
|
+
type: 'button',
|
|
841
|
+
className: 'dtp-expand',
|
|
842
|
+
'aria-expanded': listOpen,
|
|
843
|
+
'aria-controls': 'dtp-node-list',
|
|
844
|
+
title: listOpen ? tt(t, 'list.collapse') : tt(t, 'list.expand'),
|
|
845
|
+
onClick: () => setListOpen(value => !value),
|
|
846
|
+
},
|
|
847
|
+
h('span', { className: 'dtp-expand-arrow' }, listOpen ? '▾' : '▸'),
|
|
848
|
+
h('span', { className: 'dtp-expand-label' }, tt(t, 'list.title')),
|
|
849
|
+
h('span', { className: 'dtp-expand-badge' }, String(listTotal)),
|
|
850
|
+
)
|
|
851
|
+
: null,
|
|
852
|
+
h('span', { className: 'dtp-phase' }, phase),
|
|
853
|
+
detail === '' ? null : h('span', { className: 'dtp-text', title: detail }, detail),
|
|
854
|
+
evaluating
|
|
855
|
+
? h('span', { className: 'dtp-eta' }, tt(t, 'progress.elapsed', { t: clock(elapsed) }))
|
|
856
|
+
: !done && progress.etaMin > 0
|
|
857
|
+
? h('span', { className: 'dtp-eta' }, tt(t, 'progress.eta', { n: progress.etaMin }))
|
|
858
|
+
: null,
|
|
859
|
+
),
|
|
860
|
+
listOpen && listTotal > 0
|
|
861
|
+
? h(
|
|
862
|
+
'div',
|
|
863
|
+
{ className: 'dtp-list', id: 'dtp-node-list', role: 'region', 'aria-label': tt(t, 'list.aria') },
|
|
864
|
+
listCurrent !== undefined
|
|
865
|
+
? h(
|
|
866
|
+
'div',
|
|
867
|
+
{ className: 'dtp-list-row dtp-list-row-live' },
|
|
868
|
+
h('span', { className: 'dtp-list-index' }, tt(t, 'step.index', { n: listCurrent.index })),
|
|
869
|
+
h('span', { className: 'dtp-list-badge dtp-list-badge-live' }, tt(t, 'step.running')),
|
|
870
|
+
h('span', { className: 'dtp-list-colon' }, tt(t, 'list.colon')),
|
|
871
|
+
h('span', { className: 'dtp-list-label', title: listCurrent.label }, listCurrent.label),
|
|
872
|
+
h('span', { className: 'dtp-list-meta' },
|
|
873
|
+
`${tt(t, `phase.${listCurrent.phase}`)} · ${tt(t, 'step.elapsed', { t: durationText(t, Math.max(0, now - listCurrent.since)) })}`),
|
|
874
|
+
)
|
|
875
|
+
: null,
|
|
876
|
+
listCurrent !== undefined && listDone.length > 0
|
|
877
|
+
? h('div', { className: 'dtp-list-rule', key: 'rule' })
|
|
878
|
+
: null,
|
|
879
|
+
listDone.map(({ step, index }) => {
|
|
880
|
+
const finished = timeText(step.endedAt)
|
|
881
|
+
const meta = [
|
|
882
|
+
tt(t, `phase.${step.phase}`),
|
|
883
|
+
tt(t, 'step.duration', { t: durationText(t, step.durationMs) }),
|
|
884
|
+
]
|
|
885
|
+
if (finished !== '') meta.push(tt(t, 'step.finished', { t: finished }))
|
|
886
|
+
return h(
|
|
887
|
+
'div',
|
|
888
|
+
{ className: 'dtp-list-row', key: `list-${index}` },
|
|
889
|
+
h('span', { className: 'dtp-list-index' }, tt(t, 'step.index', { n: index })),
|
|
890
|
+
h('span', { className: 'dtp-list-badge' }, tt(t, 'done')),
|
|
891
|
+
h('span', { className: 'dtp-list-colon' }, tt(t, 'list.colon')),
|
|
892
|
+
h('span', { className: 'dtp-list-label', title: step.label }, step.label),
|
|
893
|
+
h('span', { className: 'dtp-list-meta' }, meta.join(' · ')),
|
|
894
|
+
)
|
|
895
|
+
}),
|
|
896
|
+
)
|
|
897
|
+
: null,
|
|
898
|
+
),
|
|
899
|
+
)
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* The ring beside the session row's time label.
|
|
905
|
+
* @param sessions - client sessions service (list store).
|
|
906
|
+
* @param useJudgements - hook over the evaluator store.
|
|
907
|
+
*/
|
|
908
|
+
function makeRowTrailing(sessions, useJudgements, useStyle) {
|
|
909
|
+
return function RowTrailing(props) {
|
|
910
|
+
const t = props.t
|
|
911
|
+
const judgements = useJudgements()
|
|
912
|
+
// Hooks stay above every early return (the row mounts only for some
|
|
913
|
+
// sessions), so the ring can reuse the same appearance overrides.
|
|
914
|
+
const local = useStyle()
|
|
915
|
+
const state = React.useSyncExternalStore(
|
|
916
|
+
listener => sessions.list.subscribe(listener),
|
|
917
|
+
() => sessions.list.getSnapshot(),
|
|
918
|
+
)
|
|
919
|
+
const summary = state !== null && state !== undefined && state.byId !== undefined
|
|
920
|
+
? state.byId[props.sessionId]
|
|
921
|
+
: undefined
|
|
922
|
+
if (summary === undefined || summary === null) return null
|
|
923
|
+
if (summary.blank === true || summary.running !== true) return null
|
|
924
|
+
if (summary.parentSessionId !== undefined || summary.origin === 'subagent') return null
|
|
925
|
+
const live = state.projectionsBySession !== undefined && state.projectionsBySession[props.sessionId] !== undefined
|
|
926
|
+
? state.projectionsBySession[props.sessionId].values
|
|
927
|
+
: undefined
|
|
928
|
+
const raw = live !== undefined && live.taskProgress !== undefined
|
|
929
|
+
? live.taskProgress
|
|
930
|
+
: summary.projectionValues !== undefined ? summary.projectionValues.taskProgress : undefined
|
|
931
|
+
const progress = mergeJudgement(
|
|
932
|
+
raw,
|
|
933
|
+
judgements !== null && judgements !== undefined && judgements.sessions !== null && judgements.sessions !== undefined
|
|
934
|
+
? judgements.sessions[props.sessionId]
|
|
935
|
+
: undefined,
|
|
936
|
+
Date.now(),
|
|
937
|
+
)
|
|
938
|
+
if (progress === undefined || progress === null || progress.turn === 0) return null
|
|
939
|
+
if (progress.done === true || !(progress.percent >= 0)) return null
|
|
940
|
+
const percent = progress.percent
|
|
941
|
+
// The ring follows the same configured color as the composer bar.
|
|
942
|
+
const tuned = resolveStyle(
|
|
943
|
+
judgements !== null && judgements !== undefined ? judgements.style : null,
|
|
944
|
+
local,
|
|
945
|
+
)
|
|
946
|
+
const size = 13
|
|
947
|
+
const stroke = 1.75
|
|
948
|
+
const radius = (size - stroke) / 2
|
|
949
|
+
const length = 2 * Math.PI * radius
|
|
950
|
+
const tip = progress.milestone === ''
|
|
951
|
+
? tt(t, `phase.${progress.phase}`)
|
|
952
|
+
: `${tt(t, `phase.${progress.phase}`)} · ${progress.milestone}`
|
|
953
|
+
return h(
|
|
954
|
+
'span',
|
|
955
|
+
{
|
|
956
|
+
title: `${tip} · ${percent}%`,
|
|
957
|
+
style: {
|
|
958
|
+
display: 'inline-flex',
|
|
959
|
+
alignItems: 'center',
|
|
960
|
+
gap: '4px',
|
|
961
|
+
marginInlineStart: '6px',
|
|
962
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
963
|
+
fontSize: '11px',
|
|
964
|
+
lineHeight: '14px',
|
|
965
|
+
fontVariantNumeric: 'tabular-nums',
|
|
966
|
+
pointerEvents: 'none',
|
|
967
|
+
...(tuned.explicitColor ? { '--dtp-bar-color': tuned.barColor } : {}),
|
|
968
|
+
},
|
|
969
|
+
},
|
|
970
|
+
h(
|
|
971
|
+
'svg',
|
|
972
|
+
{ width: size, height: size, viewBox: `0 0 ${size} ${size}`, 'aria-hidden': true, style: { display: 'block' } },
|
|
973
|
+
h('circle', {
|
|
974
|
+
cx: size / 2, cy: size / 2, r: radius, fill: 'none',
|
|
975
|
+
stroke: 'currentColor', strokeOpacity: 0.22, strokeWidth: stroke,
|
|
976
|
+
}),
|
|
977
|
+
h('circle', {
|
|
978
|
+
cx: size / 2, cy: size / 2, r: radius, fill: 'none',
|
|
979
|
+
stroke: 'var(--dtp-bar-color,var(--dsw-alias-state-business-primary))', strokeWidth: stroke, strokeLinecap: 'round',
|
|
980
|
+
strokeDasharray: `${length} ${length}`,
|
|
981
|
+
strokeDashoffset: length * (1 - percent / 100),
|
|
982
|
+
transform: `rotate(-90 ${size / 2} ${size / 2})`,
|
|
983
|
+
style: { transition: 'stroke-dashoffset .4s ease' },
|
|
984
|
+
}),
|
|
985
|
+
),
|
|
986
|
+
h('span', null, `${percent}%`),
|
|
987
|
+
)
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/** Settings-section styles, mirroring the host's row rhythm. */
|
|
992
|
+
const SETTINGS_CSS = [
|
|
993
|
+
'.dtp-set{display:flex;flex-direction:column;width:100%;max-width:680px;color:var(--dsw-alias-label-primary);}',
|
|
994
|
+
'.dtp-set-heading{margin:0 0 2px;font-size:14px;font-weight:600;line-height:22px;}',
|
|
995
|
+
'.dtp-set-lead{margin:0 0 8px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);}',
|
|
996
|
+
'.dtp-set-row{display:flex;align-items:center;gap:8px;padding:14px 0;',
|
|
997
|
+
'border-bottom:0.5px solid var(--dsw-alias-border-l2);}',
|
|
998
|
+
'.dtp-set-text{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px;padding-right:24px;}',
|
|
999
|
+
'.dtp-set-title{font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary);}',
|
|
1000
|
+
'.dtp-set-desc{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);}',
|
|
1001
|
+
'.dtp-set-control{display:flex;align-items:center;gap:6px;flex:none;}',
|
|
1002
|
+
'.dtp-set-num{width:78px;height:30px;box-sizing:border-box;padding:0 8px;border-radius:8px;',
|
|
1003
|
+
'border:0.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);',
|
|
1004
|
+
'font:inherit;font-size:13px;font-variant-numeric:tabular-nums;}',
|
|
1005
|
+
'.dtp-set-num:focus-visible,.dtp-set-text-input:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px;}',
|
|
1006
|
+
'.dtp-set-unit{font-size:12px;color:var(--dsw-alias-label-tertiary);}',
|
|
1007
|
+
'.dtp-set-color{width:34px;height:30px;padding:2px;border-radius:8px;cursor:pointer;',
|
|
1008
|
+
'border:0.5px solid var(--dsw-alias-border-l2);background:transparent;}',
|
|
1009
|
+
'.dtp-set-text-input{width:150px;height:30px;box-sizing:border-box;padding:0 8px;border-radius:8px;',
|
|
1010
|
+
'border:0.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);',
|
|
1011
|
+
'font:inherit;font-size:13px;}',
|
|
1012
|
+
'.dtp-set-preview{display:flex;flex-direction:column;gap:4px;padding:14px 0;',
|
|
1013
|
+
'border-bottom:0.5px solid var(--dsw-alias-border-l2);}',
|
|
1014
|
+
'.dtp-set-track{position:relative;width:100%;border-radius:999px;',
|
|
1015
|
+
'background:var(--dsw-alias-interactive-bg-hover);overflow:hidden;}',
|
|
1016
|
+
'.dtp-set-fill{position:absolute;inset-block:0;inset-inline-start:0;border-radius:999px;}',
|
|
1017
|
+
'.dtp-set-preview-bar{position:relative;display:flex;align-items:center;',
|
|
1018
|
+
'padding-block:7px;margin-block:-7px;}',
|
|
1019
|
+
'.dtp-set-preview-bar .dtp-set-track{flex:1 1 auto;width:100%;transform-origin:center;',
|
|
1020
|
+
'transition:transform .2s cubic-bezier(.2,.7,.3,1),box-shadow .2s ease;}',
|
|
1021
|
+
'.dtp-set-preview-bar:hover .dtp-set-track{transform:scaleY(1.9);',
|
|
1022
|
+
'box-shadow:0 0 0 1px color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 22%,transparent),',
|
|
1023
|
+
'0 2px 12px -2px color-mix(in srgb,var(--dtp-bar-color,var(--dsw-alias-state-business-primary)) 55%,transparent);}',
|
|
1024
|
+
'.dtp-set-nodes{position:absolute;inset:0;pointer-events:none;}',
|
|
1025
|
+
'@media (prefers-reduced-motion:reduce){.dtp-set-preview-bar .dtp-set-track{transition:none}}',
|
|
1026
|
+
'.dtp-set-caption{color:var(--dsw-alias-label-secondary);}',
|
|
1027
|
+
'.dtp-set-actions{display:flex;justify-content:flex-end;gap:8px;padding-top:14px;}',
|
|
1028
|
+
'.dtp-set-btn{height:30px;padding:0 14px;border-radius:8px;cursor:pointer;font:inherit;font-size:13px;',
|
|
1029
|
+
'border:0.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);}',
|
|
1030
|
+
'.dtp-set-btn:hover:enabled{background:var(--dsw-alias-interactive-bg-hover);}',
|
|
1031
|
+
'.dtp-set-btn:disabled{opacity:.45;cursor:default;}',
|
|
1032
|
+
].join('')
|
|
1033
|
+
|
|
1034
|
+
const PANEL_CSS = [
|
|
1035
|
+
'.dtp-panel{display:flex;flex-direction:column;gap:10px;height:100%;min-height:100%;',
|
|
1036
|
+
'box-sizing:border-box;padding:12px;overflow:auto;font-size:12px;line-height:1.5;}',
|
|
1037
|
+
'.dtp-panel-head{display:flex;align-items:center;justify-content:space-between;gap:8px;}',
|
|
1038
|
+
'.dtp-panel-title{font-weight:600;color:var(--dsw-alias-label-primary);}',
|
|
1039
|
+
'.dtp-panel-count{flex:none;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;}',
|
|
1040
|
+
'.dtp-cards{display:flex;flex-direction:column;gap:8px;}',
|
|
1041
|
+
'.dtp-card{display:flex;gap:9px;padding:9px 10px;border:0.5px solid var(--dsw-alias-border-l1);',
|
|
1042
|
+
'border-radius:10px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base,#fff));}',
|
|
1043
|
+
'.dtp-card-live{border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary) 45%,var(--dsw-alias-border-l1));',
|
|
1044
|
+
'background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 5%,var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base,#fff)));}',
|
|
1045
|
+
'.dtp-card-rail{flex:none;width:16px;display:flex;flex-direction:column;align-items:center;}',
|
|
1046
|
+
'.dtp-card-dot{width:8px;height:8px;margin-top:5px;border-radius:50%;',
|
|
1047
|
+
'background:var(--dsw-alias-state-success-primary,#16a34a);',
|
|
1048
|
+
'box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-success-primary,#16a34a) 18%,transparent);}',
|
|
1049
|
+
'.dtp-card-live .dtp-card-dot{background:var(--dsw-alias-state-business-primary);',
|
|
1050
|
+
'box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-business-primary) 18%,transparent);}',
|
|
1051
|
+
'.dtp-card-line{flex:1;width:1px;min-height:10px;margin-top:3px;background:var(--dsw-alias-border-l1);}',
|
|
1052
|
+
'.dtp-card-body{flex:1;min-width:0;}',
|
|
1053
|
+
'.dtp-card-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap;}',
|
|
1054
|
+
'.dtp-card-index{color:var(--dsw-alias-label-tertiary);font-size:11px;font-variant-numeric:tabular-nums;}',
|
|
1055
|
+
'.dtp-card-badge{padding:0 6px;border-radius:999px;font-size:10px;line-height:16px;',
|
|
1056
|
+
'background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#16a34a) 14%,transparent);',
|
|
1057
|
+
'color:var(--dsw-alias-state-success-primary,#16a34a);}',
|
|
1058
|
+
'.dtp-card-badge-live{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 14%,transparent);',
|
|
1059
|
+
'color:var(--dsw-alias-state-business-primary);}',
|
|
1060
|
+
'.dtp-card-duration{margin-inline-start:auto;color:var(--dsw-alias-label-tertiary);',
|
|
1061
|
+
'font-size:10px;font-variant-numeric:tabular-nums;}',
|
|
1062
|
+
'.dtp-card-label{margin-top:3px;color:var(--dsw-alias-label-primary);word-break:break-word;}',
|
|
1063
|
+
'.dtp-card-meta{margin-top:2px;color:var(--dsw-alias-label-tertiary);font-size:11px;}',
|
|
1064
|
+
'.dtp-panel-empty{padding:18px 4px;text-align:center;color:var(--dsw-alias-label-tertiary);}',
|
|
1065
|
+
].join('')
|
|
1066
|
+
|
|
1067
|
+
const FOOTER_CSS = [
|
|
1068
|
+
'.dtp-footer-action{flex:none;width:28px;height:28px;padding:6px;border:0;',
|
|
1069
|
+
'border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-tertiary);',
|
|
1070
|
+
'cursor:pointer;display:inline-flex;align-items:center;justify-content:center;}',
|
|
1071
|
+
'.dtp-footer-action:hover{background:var(--dsw-alias-interactive-bg-hover);',
|
|
1072
|
+
'color:var(--dsw-alias-label-secondary);}',
|
|
1073
|
+
'.dtp-footer-action:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);',
|
|
1074
|
+
'outline-offset:1px;}',
|
|
1075
|
+
'.dtp-footer-action svg{width:17px;height:17px;}',
|
|
1076
|
+
].join('')
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* The Settings section: four rows plus a live preview.
|
|
1080
|
+
* @param store - appearance override store (set/reset).
|
|
1081
|
+
* @param useStyle - hook over the overrides.
|
|
1082
|
+
* @param useJudgements - hook over the evaluator store (carries the Host config).
|
|
1083
|
+
*/
|
|
1084
|
+
function makeSettingsPage(store, useStyle, useJudgements) {
|
|
1085
|
+
return function TaskProgressSettings(props) {
|
|
1086
|
+
const t = props.t
|
|
1087
|
+
const [hoveredPreview, setHoveredPreview] = React.useState(null)
|
|
1088
|
+
const local = useStyle()
|
|
1089
|
+
const judgements = useJudgements()
|
|
1090
|
+
const tuned = resolveStyle(
|
|
1091
|
+
judgements !== null && judgements !== undefined ? judgements.style : null,
|
|
1092
|
+
local,
|
|
1093
|
+
)
|
|
1094
|
+
const overridden = Object.keys(local !== null && local !== undefined ? local : {}).length > 0
|
|
1095
|
+
const commitNumber = (key, min, max) => event => {
|
|
1096
|
+
const parsed = Math.round(Number(event.target.value))
|
|
1097
|
+
const value = Number.isFinite(parsed) ? Math.min(max, Math.max(min, parsed)) : 0
|
|
1098
|
+
store.set({ [key]: value })
|
|
1099
|
+
}
|
|
1100
|
+
const commitColor = event => store.set({ barColor: String(event.target.value).slice(0, 40) })
|
|
1101
|
+
const blurOnEnter = event => { if (event.key === 'Enter') event.currentTarget.blur() }
|
|
1102
|
+
const color = tuned.barColor === '' ? 'var(--dsw-alias-state-business-primary)' : tuned.barColor
|
|
1103
|
+
const row = (title, desc, control) => h('div', { className: 'dtp-set-row', key: title },
|
|
1104
|
+
h('div', { className: 'dtp-set-text' },
|
|
1105
|
+
h('div', { className: 'dtp-set-title' }, title),
|
|
1106
|
+
h('div', { className: 'dtp-set-desc' }, desc),
|
|
1107
|
+
),
|
|
1108
|
+
h('div', { className: 'dtp-set-control' }, control),
|
|
1109
|
+
)
|
|
1110
|
+
const previewDuration = seconds => tt(t, 'duration.minSec', { m: Math.floor(seconds / 60), s: seconds % 60 })
|
|
1111
|
+
const previewNode = (index, left, live) => {
|
|
1112
|
+
const key = `preview-${index}`
|
|
1113
|
+
const active = hoveredPreview === key
|
|
1114
|
+
const label = tt(t, live ? 'settings.preview.live' : 'settings.preview.done')
|
|
1115
|
+
const elapsed = previewDuration(live ? 65 : 130)
|
|
1116
|
+
const meta = live
|
|
1117
|
+
? `${tt(t, 'phase.execute')} · ${tt(t, 'step.elapsed', { t: elapsed })}`
|
|
1118
|
+
: `${tt(t, 'phase.execute')} · ${tt(t, 'step.duration', { t: elapsed })} · ${tt(t, 'step.finished', { t: '14:32' })}`
|
|
1119
|
+
return h(
|
|
1120
|
+
'button',
|
|
1121
|
+
{
|
|
1122
|
+
key,
|
|
1123
|
+
type: 'button',
|
|
1124
|
+
className: live ? 'dtp-node dtp-node-current' : 'dtp-node',
|
|
1125
|
+
style: { left },
|
|
1126
|
+
'aria-label': tt(t, 'step.node', { n: index, x: label, t: elapsed }),
|
|
1127
|
+
onMouseDown: event => event.preventDefault(),
|
|
1128
|
+
onMouseEnter: () => setHoveredPreview(key),
|
|
1129
|
+
onMouseLeave: () => setHoveredPreview(value => (value === key ? null : value)),
|
|
1130
|
+
onFocus: () => setHoveredPreview(key),
|
|
1131
|
+
onBlur: () => setHoveredPreview(value => (value === key ? null : value)),
|
|
1132
|
+
},
|
|
1133
|
+
h('span', { className: 'dtp-node-dot' }),
|
|
1134
|
+
active
|
|
1135
|
+
? h(
|
|
1136
|
+
'span',
|
|
1137
|
+
{ className: 'dtp-tip', role: 'tooltip' },
|
|
1138
|
+
h(
|
|
1139
|
+
'span',
|
|
1140
|
+
{ className: 'dtp-tip-head' },
|
|
1141
|
+
h('span', null, tt(t, 'step.index', { n: index })),
|
|
1142
|
+
h('span', { className: live ? 'dtp-tip-badge dtp-tip-badge-live' : 'dtp-tip-badge' }, tt(t, live ? 'step.running' : 'done')),
|
|
1143
|
+
),
|
|
1144
|
+
h('span', { className: 'dtp-tip-main' }, label),
|
|
1145
|
+
live ? h('span', { className: 'dtp-tip-sub' }, tt(t, 'progress.next', { x: tt(t, 'settings.preview.next') })) : null,
|
|
1146
|
+
h('span', { className: 'dtp-tip-meta' }, meta),
|
|
1147
|
+
)
|
|
1148
|
+
: null,
|
|
1149
|
+
)
|
|
1150
|
+
}
|
|
1151
|
+
return h(
|
|
1152
|
+
React.Fragment,
|
|
1153
|
+
null,
|
|
1154
|
+
h('style', { key: 'dtp-set-style' }, DOCK_CSS + SETTINGS_CSS),
|
|
1155
|
+
h('div', { className: 'dtp-set' },
|
|
1156
|
+
h('h2', { className: 'dtp-set-heading' }, tt(t, 'settings.title')),
|
|
1157
|
+
h('p', { className: 'dtp-set-lead' }, tt(t, 'settings.lead')),
|
|
1158
|
+
row(tt(t, 'settings.height'), tt(t, 'settings.height.desc'), [
|
|
1159
|
+
h('input', {
|
|
1160
|
+
key: `h${tuned.barHeight}`, className: 'dtp-set-num', type: 'number',
|
|
1161
|
+
min: 2, max: 24, step: 1, defaultValue: tuned.barHeight,
|
|
1162
|
+
'aria-label': tt(t, 'settings.height'),
|
|
1163
|
+
onBlur: commitNumber('barHeight', 2, 24), onKeyDown: blurOnEnter,
|
|
1164
|
+
}),
|
|
1165
|
+
h('span', { key: 'u', className: 'dtp-set-unit' }, 'px'),
|
|
1166
|
+
]),
|
|
1167
|
+
row(tt(t, 'settings.color'), tt(t, 'settings.color.desc'), [
|
|
1168
|
+
h('input', {
|
|
1169
|
+
key: 'swatch', className: 'dtp-set-color', type: 'color',
|
|
1170
|
+
value: /^#[0-9a-fA-F]{6}$/u.test(tuned.barColor) ? tuned.barColor : '#2f6df6',
|
|
1171
|
+
'aria-label': tt(t, 'settings.color'),
|
|
1172
|
+
onChange: event => store.set({ barColor: event.target.value }),
|
|
1173
|
+
}),
|
|
1174
|
+
h('input', {
|
|
1175
|
+
key: `c${tuned.barColor}`, className: 'dtp-set-text-input', type: 'text', spellCheck: false,
|
|
1176
|
+
defaultValue: tuned.barColor, placeholder: tt(t, 'settings.color.auto'),
|
|
1177
|
+
'aria-label': tt(t, 'settings.color.value'),
|
|
1178
|
+
onBlur: commitColor, onKeyDown: blurOnEnter,
|
|
1179
|
+
}),
|
|
1180
|
+
]),
|
|
1181
|
+
row(tt(t, 'settings.font'), tt(t, 'settings.font.desc'), [
|
|
1182
|
+
h('input', {
|
|
1183
|
+
key: `f${tuned.textFontSize}`, className: 'dtp-set-num', type: 'number',
|
|
1184
|
+
min: 9, max: 24, step: 1, defaultValue: tuned.textFontSize,
|
|
1185
|
+
'aria-label': tt(t, 'settings.font'),
|
|
1186
|
+
onBlur: commitNumber('textFontSize', 9, 24), onKeyDown: blurOnEnter,
|
|
1187
|
+
}),
|
|
1188
|
+
h('span', { key: 'u', className: 'dtp-set-unit' }, 'px'),
|
|
1189
|
+
]),
|
|
1190
|
+
row(tt(t, 'settings.listFont'), tt(t, 'settings.listFont.desc'), [
|
|
1191
|
+
h('input', {
|
|
1192
|
+
key: `l${tuned.listFontSize}`, className: 'dtp-set-num', type: 'number',
|
|
1193
|
+
min: 9, max: 24, step: 1, defaultValue: tuned.listFontSize,
|
|
1194
|
+
'aria-label': tt(t, 'settings.listFont'),
|
|
1195
|
+
onBlur: commitNumber('listFontSize', 9, 24), onKeyDown: blurOnEnter,
|
|
1196
|
+
}),
|
|
1197
|
+
h('span', { key: 'u', className: 'dtp-set-unit' }, 'px'),
|
|
1198
|
+
]),
|
|
1199
|
+
h('div', { className: 'dtp-set-preview' },
|
|
1200
|
+
h(
|
|
1201
|
+
'div',
|
|
1202
|
+
{ className: 'dtp-set-preview-bar', style: { '--dtp-bar-color': color } },
|
|
1203
|
+
h('div', { className: 'dtp-set-track', style: { height: `${tuned.barHeight}px` } },
|
|
1204
|
+
h('div', {
|
|
1205
|
+
className: 'dtp-set-fill',
|
|
1206
|
+
style: { width: '74%', background: color },
|
|
1207
|
+
}),
|
|
1208
|
+
),
|
|
1209
|
+
h('div', { className: 'dtp-set-nodes' },
|
|
1210
|
+
previewNode(0, '33.33%', false),
|
|
1211
|
+
previewNode(1, '74%', true),
|
|
1212
|
+
),
|
|
1213
|
+
),
|
|
1214
|
+
h('div', { className: 'dtp-set-caption', style: { fontSize: `${tuned.textFontSize}px` } },
|
|
1215
|
+
tt(t, 'settings.preview')),
|
|
1216
|
+
),
|
|
1217
|
+
h('div', { className: 'dtp-set-actions' },
|
|
1218
|
+
h('button', {
|
|
1219
|
+
type: 'button', className: 'dtp-set-btn', disabled: !overridden,
|
|
1220
|
+
onClick: () => store.reset(),
|
|
1221
|
+
}, tt(t, 'settings.reset')),
|
|
1222
|
+
),
|
|
1223
|
+
),
|
|
1224
|
+
)
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
/** The right Sidebar tab: every node of the completed turn as a card, in time order. */
|
|
1229
|
+
function makeNodePanel(useJudgements, sessions) {
|
|
1230
|
+
return function NodePanel(props) {
|
|
1231
|
+
const t = props.t
|
|
1232
|
+
const sessionId = props.sessionId
|
|
1233
|
+
const judgements = useJudgements()
|
|
1234
|
+
const state = React.useSyncExternalStore(
|
|
1235
|
+
listener => (sessions !== null && sessions !== undefined && sessions.list !== null
|
|
1236
|
+
&& sessions.list !== undefined && typeof sessions.list.subscribe === 'function'
|
|
1237
|
+
? sessions.list.subscribe(listener)
|
|
1238
|
+
: () => {}),
|
|
1239
|
+
() => (sessions !== null && sessions !== undefined && sessions.list !== null
|
|
1240
|
+
&& sessions.list !== undefined && typeof sessions.list.getSnapshot === 'function'
|
|
1241
|
+
? sessions.list.getSnapshot()
|
|
1242
|
+
: undefined),
|
|
1243
|
+
)
|
|
1244
|
+
const rail = sessionId !== undefined && judgements !== null && judgements !== undefined
|
|
1245
|
+
&& judgements.rails !== null && judgements.rails !== undefined
|
|
1246
|
+
? judgements.rails[sessionId]
|
|
1247
|
+
: undefined
|
|
1248
|
+
const summary = state !== null && state !== undefined && state.byId !== undefined
|
|
1249
|
+
? state.byId[sessionId]
|
|
1250
|
+
: undefined
|
|
1251
|
+
const current = state !== null && state !== undefined && state.projectionsBySession !== undefined
|
|
1252
|
+
&& state.projectionsBySession[sessionId] !== undefined
|
|
1253
|
+
? state.projectionsBySession[sessionId].values
|
|
1254
|
+
: undefined
|
|
1255
|
+
const raw = current !== undefined && current.taskProgress !== undefined
|
|
1256
|
+
? current.taskProgress
|
|
1257
|
+
: summary !== undefined && summary.projectionValues !== undefined
|
|
1258
|
+
? summary.projectionValues.taskProgress
|
|
1259
|
+
: undefined
|
|
1260
|
+
const progress = mergeJudgement(
|
|
1261
|
+
raw,
|
|
1262
|
+
judgements !== null && judgements !== undefined && judgements.sessions !== undefined
|
|
1263
|
+
? judgements.sessions[sessionId]
|
|
1264
|
+
: undefined,
|
|
1265
|
+
Date.now(),
|
|
1266
|
+
)
|
|
1267
|
+
// The Host closes the last node on its next sweep; the completed
|
|
1268
|
+
// turn's card should not read "in progress" in the meantime.
|
|
1269
|
+
const done = progress !== undefined && progress !== null && progress.done === true
|
|
1270
|
+
&& rail !== null && rail !== undefined && progress.turn === rail.turn
|
|
1271
|
+
const doneAt = done ? (progress.updatedAt > 0 ? progress.updatedAt : Date.now()) : 0
|
|
1272
|
+
const steps = rail !== null && rail !== undefined && Array.isArray(rail.steps)
|
|
1273
|
+
? rail.steps.filter(step => step !== null && typeof step === 'object')
|
|
1274
|
+
: []
|
|
1275
|
+
const cards = steps.map((step, index) => {
|
|
1276
|
+
const closed = step.endedAt > 0
|
|
1277
|
+
const live = !closed && !done
|
|
1278
|
+
const ended = closed ? step.endedAt : (done ? Math.max(step.at, doneAt) : 0)
|
|
1279
|
+
const took = closed ? step.durationMs : (live ? Math.max(0, Date.now() - step.at) : Math.max(0, ended - step.at))
|
|
1280
|
+
const meta = [tt(t, `phase.${step.phase}`)]
|
|
1281
|
+
if (!live) {
|
|
1282
|
+
const finished = timeText(ended)
|
|
1283
|
+
if (finished !== '') meta.push(tt(t, 'step.finished', { t: finished }))
|
|
1284
|
+
}
|
|
1285
|
+
return h(
|
|
1286
|
+
'div',
|
|
1287
|
+
{ className: live ? 'dtp-card dtp-card-live' : 'dtp-card', key: `card-${index}` },
|
|
1288
|
+
h(
|
|
1289
|
+
'div',
|
|
1290
|
+
{ className: 'dtp-card-rail' },
|
|
1291
|
+
h('span', { className: 'dtp-card-dot' }),
|
|
1292
|
+
h('span', { className: 'dtp-card-line' }),
|
|
1293
|
+
),
|
|
1294
|
+
h(
|
|
1295
|
+
'div',
|
|
1296
|
+
{ className: 'dtp-card-body' },
|
|
1297
|
+
h(
|
|
1298
|
+
'div',
|
|
1299
|
+
{ className: 'dtp-card-head' },
|
|
1300
|
+
h('span', { className: 'dtp-card-index' }, tt(t, 'step.index', { n: index })),
|
|
1301
|
+
h(
|
|
1302
|
+
'span',
|
|
1303
|
+
{ className: live ? 'dtp-card-badge dtp-card-badge-live' : 'dtp-card-badge' },
|
|
1304
|
+
tt(t, live ? 'step.running' : 'done'),
|
|
1305
|
+
),
|
|
1306
|
+
h(
|
|
1307
|
+
'span',
|
|
1308
|
+
{ className: 'dtp-card-duration' },
|
|
1309
|
+
live
|
|
1310
|
+
? tt(t, 'step.elapsed', { t: durationText(t, took) })
|
|
1311
|
+
: tt(t, 'step.duration', { t: durationText(t, took) }),
|
|
1312
|
+
),
|
|
1313
|
+
),
|
|
1314
|
+
h('div', { className: 'dtp-card-label' }, step.label),
|
|
1315
|
+
h('div', { className: 'dtp-card-meta' }, meta.join(' · ')),
|
|
1316
|
+
),
|
|
1317
|
+
)
|
|
1318
|
+
})
|
|
1319
|
+
return h(
|
|
1320
|
+
React.Fragment,
|
|
1321
|
+
null,
|
|
1322
|
+
h('style', { key: 'dtp-panel-style' }, PANEL_CSS),
|
|
1323
|
+
h(
|
|
1324
|
+
'div',
|
|
1325
|
+
{ className: 'dtp-panel' },
|
|
1326
|
+
h(
|
|
1327
|
+
'div',
|
|
1328
|
+
{ className: 'dtp-panel-head' },
|
|
1329
|
+
h('span', { className: 'dtp-panel-title' }, tt(t, 'tab.heading')),
|
|
1330
|
+
h('span', { className: 'dtp-panel-count' }, tt(t, 'tab.count', { n: steps.length })),
|
|
1331
|
+
),
|
|
1332
|
+
steps.length === 0
|
|
1333
|
+
? h('div', { className: 'dtp-panel-empty' }, tt(t, 'tab.empty'))
|
|
1334
|
+
: h('div', { className: 'dtp-cards' }, cards),
|
|
1335
|
+
),
|
|
1336
|
+
)
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
/** The tab chip's icon and label. */
|
|
1341
|
+
function NodeTabTitle(props) {
|
|
1342
|
+
return h(
|
|
1343
|
+
'span',
|
|
1344
|
+
{ style: { display: 'inline-flex', alignItems: 'center', gap: '5px', minWidth: 0 } },
|
|
1345
|
+
h(ProgressGlyph, { size: 14 }),
|
|
1346
|
+
h('span', null, tt(props.t, 'tab.title')),
|
|
1347
|
+
)
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/** The section icon in DSH Settings, addressed by the matching settings.section id. */
|
|
1351
|
+
function SettingsIcon(props) {
|
|
1352
|
+
const size = props !== null && props !== undefined && Number.isFinite(Number(props.size))
|
|
1353
|
+
? Number(props.size) : 16
|
|
1354
|
+
return h(ProgressGlyph, {
|
|
1355
|
+
size,
|
|
1356
|
+
className: props !== null && props !== undefined ? props.className : undefined,
|
|
1357
|
+
})
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* The progress glyph in a completed turn's action row. It is shown only
|
|
1362
|
+
* after the reply is final, only on the latest turn, and sits after the
|
|
1363
|
+
* context action and before the branch action (a high slot order).
|
|
1364
|
+
*/
|
|
1365
|
+
function makeFooterNodeAction(useJudgements, sessions, openNodes) {
|
|
1366
|
+
return function FooterNodeAction(props) {
|
|
1367
|
+
const t = props.t
|
|
1368
|
+
const sessionId = props.sessionId
|
|
1369
|
+
const judgements = useJudgements()
|
|
1370
|
+
const state = React.useSyncExternalStore(
|
|
1371
|
+
listener => (sessions !== null && sessions !== undefined && sessions.list !== null
|
|
1372
|
+
&& sessions.list !== undefined && typeof sessions.list.subscribe === 'function'
|
|
1373
|
+
? sessions.list.subscribe(listener)
|
|
1374
|
+
: () => {}),
|
|
1375
|
+
() => (sessions !== null && sessions !== undefined && sessions.list !== null
|
|
1376
|
+
&& sessions.list !== undefined && typeof sessions.list.getSnapshot === 'function'
|
|
1377
|
+
? sessions.list.getSnapshot()
|
|
1378
|
+
: undefined),
|
|
1379
|
+
)
|
|
1380
|
+
const [turn, setTurn] = React.useState(null)
|
|
1381
|
+
const anchor = React.useCallback(node => {
|
|
1382
|
+
if (node === null || node === undefined) return
|
|
1383
|
+
const holder = typeof node.closest === 'function' ? node.closest('[data-turn-tail]') : null
|
|
1384
|
+
setTurn(holder !== null ? holder.getAttribute('data-turn-tail') : null)
|
|
1385
|
+
}, [])
|
|
1386
|
+
const summary = state !== null && state !== undefined && state.byId !== undefined
|
|
1387
|
+
? state.byId[sessionId]
|
|
1388
|
+
: undefined
|
|
1389
|
+
const live = state !== null && state !== undefined && state.projectionsBySession !== undefined
|
|
1390
|
+
&& state.projectionsBySession[sessionId] !== undefined
|
|
1391
|
+
? state.projectionsBySession[sessionId].values
|
|
1392
|
+
: undefined
|
|
1393
|
+
const raw = live !== undefined && live.taskProgress !== undefined
|
|
1394
|
+
? live.taskProgress
|
|
1395
|
+
: summary !== undefined && summary.projectionValues !== undefined
|
|
1396
|
+
? summary.projectionValues.taskProgress
|
|
1397
|
+
: undefined
|
|
1398
|
+
const progress = mergeJudgement(
|
|
1399
|
+
raw,
|
|
1400
|
+
judgements !== null && judgements !== undefined && judgements.sessions !== undefined
|
|
1401
|
+
? judgements.sessions[sessionId]
|
|
1402
|
+
: undefined,
|
|
1403
|
+
Date.now(),
|
|
1404
|
+
)
|
|
1405
|
+
const known = sessionId !== undefined && progress !== undefined && progress !== null
|
|
1406
|
+
&& progress.done === true && turn !== null && String(turn) === String(progress.turn)
|
|
1407
|
+
return h(
|
|
1408
|
+
React.Fragment,
|
|
1409
|
+
null,
|
|
1410
|
+
h('style', { key: 'dtp-footer-style' }, FOOTER_CSS),
|
|
1411
|
+
h(
|
|
1412
|
+
'button',
|
|
1413
|
+
{
|
|
1414
|
+
key: 'dtp-footer-node',
|
|
1415
|
+
ref: anchor,
|
|
1416
|
+
type: 'button',
|
|
1417
|
+
className: 'dtp-footer-action',
|
|
1418
|
+
style: known ? undefined : { display: 'none' },
|
|
1419
|
+
'aria-label': tt(t, 'footer.view'),
|
|
1420
|
+
title: tt(t, 'footer.view'),
|
|
1421
|
+
onClick: event => {
|
|
1422
|
+
event.preventDefault()
|
|
1423
|
+
event.stopPropagation()
|
|
1424
|
+
openNodes(sessionId)
|
|
1425
|
+
},
|
|
1426
|
+
},
|
|
1427
|
+
h(ProgressGlyph, { size: 17 }),
|
|
1428
|
+
),
|
|
1429
|
+
)
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
return {
|
|
1434
|
+
inject: ['slots', 'locale', 'sessions', 'sidebarRightTabs', 'sidebarRight', 'layout'],
|
|
1435
|
+
apply(ctx) {
|
|
1436
|
+
ctx.effect(() => ctx.locale.register(NS, DICT), 'dsh-task-progress: dictionaries')
|
|
1437
|
+
const judgements = createJudgementStore(JUDGE_URL)
|
|
1438
|
+
const useJudgements = () => React.useSyncExternalStore(judgements.subscribe, judgements.getSnapshot)
|
|
1439
|
+
const styleStore = createStyleStore()
|
|
1440
|
+
const useStyle = () => React.useSyncExternalStore(styleStore.subscribe, styleStore.getSnapshot)
|
|
1441
|
+
const t = typeof ctx.locale.bind === 'function' ? ctx.locale.bind(NS) : (key, params) => tt(null, key, params)
|
|
1442
|
+
const ProgressDock = makeProgressDock(useJudgements, useStyle)
|
|
1443
|
+
const RowTrailing = makeRowTrailing(ctx.sessions, useJudgements, useStyle)
|
|
1444
|
+
const SettingsPage = makeSettingsPage(styleStore, useStyle, useJudgements)
|
|
1445
|
+
const NodePanel = makeNodePanel(useJudgements, ctx.sessions)
|
|
1446
|
+
const openNodePanel = sessionId => {
|
|
1447
|
+
try { ctx.layout.openRightbar(true, false) } catch {}
|
|
1448
|
+
let attempts = 0
|
|
1449
|
+
const tryOpen = () => {
|
|
1450
|
+
try { ctx.sidebarRight.openTabIn(sessionId, 'task-progress', {}) } catch {}
|
|
1451
|
+
attempts += 1
|
|
1452
|
+
const tabs = ctx.sidebarRight.openTabs !== undefined
|
|
1453
|
+
&& typeof ctx.sidebarRight.openTabs.getSnapshot === 'function'
|
|
1454
|
+
? ctx.sidebarRight.openTabs.getSnapshot()
|
|
1455
|
+
: []
|
|
1456
|
+
const opened = Array.isArray(tabs) && tabs.some(tab => tab !== null && tab !== undefined
|
|
1457
|
+
&& tab.sessionId === sessionId && tab.kind === 'task-progress')
|
|
1458
|
+
if (!opened && attempts < 6) setTimeout(tryOpen, 120)
|
|
1459
|
+
}
|
|
1460
|
+
tryOpen()
|
|
1461
|
+
}
|
|
1462
|
+
const FooterNodeAction = makeFooterNodeAction(useJudgements, ctx.sessions, openNodePanel)
|
|
1463
|
+
ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({
|
|
1464
|
+
name: 'conversation.input.dock',
|
|
1465
|
+
id: 'task-progress',
|
|
1466
|
+
order: 10,
|
|
1467
|
+
locale: NS,
|
|
1468
|
+
}, ProgressDock))
|
|
1469
|
+
ctx.slots.inject('sidebar.session.row.trailing', () => ctx.slots.register({
|
|
1470
|
+
name: 'sidebar.session.row.trailing',
|
|
1471
|
+
id: 'task-progress',
|
|
1472
|
+
order: 50,
|
|
1473
|
+
locale: NS,
|
|
1474
|
+
}, RowTrailing))
|
|
1475
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1476
|
+
name: 'settings.section',
|
|
1477
|
+
id: 'task-progress',
|
|
1478
|
+
order: 60,
|
|
1479
|
+
label: () => tt(null, 'settings.title'),
|
|
1480
|
+
locale: NS,
|
|
1481
|
+
}, SettingsPage))
|
|
1482
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
1483
|
+
id: 'task-progress',
|
|
1484
|
+
kind: 'task-progress',
|
|
1485
|
+
title: () => tt(t, 'tab.title'),
|
|
1486
|
+
keepMounted: true,
|
|
1487
|
+
}), 'dsh-task-progress: node tab type')
|
|
1488
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
1489
|
+
name: 'sidebar.right.pane.tab',
|
|
1490
|
+
key: 'task-progress',
|
|
1491
|
+
locale: NS,
|
|
1492
|
+
inject: sessionId => ({ sessionId }),
|
|
1493
|
+
}, NodePanel))
|
|
1494
|
+
ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
1495
|
+
name: 'sidebar.right.pane.tab.title',
|
|
1496
|
+
key: 'task-progress',
|
|
1497
|
+
locale: NS,
|
|
1498
|
+
}, NodeTabTitle))
|
|
1499
|
+
ctx.slots.inject('conversation.chat.assistant-actions', () => ctx.slots.register({
|
|
1500
|
+
name: 'conversation.chat.assistant-actions',
|
|
1501
|
+
id: 'task-progress',
|
|
1502
|
+
order: 1000,
|
|
1503
|
+
locale: NS,
|
|
1504
|
+
inject: sessionId => ({ sessionId }),
|
|
1505
|
+
}, FooterNodeAction))
|
|
1506
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
1507
|
+
name: 'settings.section.icon',
|
|
1508
|
+
id: 'task-progress',
|
|
1509
|
+
order: 60,
|
|
1510
|
+
locale: NS,
|
|
1511
|
+
}, SettingsIcon))
|
|
1512
|
+
},
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
})
|