dsh-colophon 0.2.2 → 0.2.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/README.md +16 -0
- package/client.js +379 -205
- package/index.js +4 -2
- package/lib/api.js +42 -3
- package/lib/app.js +9 -5
- package/lib/digest.js +73 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.2.4(摘要区块可配置 + 明亮摘要面板)
|
|
2
|
+
|
|
3
|
+
- 摘要内容改为**区块制**,可在设置页逐项开关:目标 / 结论 / 决策 / 涉及文件 / 完成情况 / 下一步 / 风险与注意 / 关键词 / 待确认问题(默认只开目标、结论、决策、下一步、风险与注意,不再输出中间的已完成动作)。
|
|
4
|
+
- 摘要面板改用主题变量配色(浅色主题下为明亮白底),按区块显示带标题的内容,不再是整段黑色等宽文本。
|
|
5
|
+
- 对话输入框上方改为明确的「生成卷末摘要」按钮,面板标题栏内直接提供「立即生成 / 重新生成」主按钮。
|
|
6
|
+
- 短对话也支持总结:默认门槛降为 2 条消息 / 100 token;阈值仍可在设置页调整。
|
|
7
|
+
- 本地规则引擎补上关键词与待确认问题的抽取;API 引擎按所选区块生成对应小节。
|
|
8
|
+
|
|
1
9
|
# Colophon(卷末)
|
|
2
10
|
|
|
3
11
|
> 旧书卷末的那一笔,记录这本书由谁写成、在哪一页收束。
|
|
@@ -103,6 +111,14 @@ usage.jsonl API 调用账本(rules 引擎不写)
|
|
|
103
111
|
- 摘要面板新增「下载 Markdown」按钮(直接保存为 `.md` 文件)
|
|
104
112
|
- 版本号 0.2.0;测试 38 项全绿
|
|
105
113
|
|
|
114
|
+
## 0.2.2(设置界面统一设计规范)
|
|
115
|
+
|
|
116
|
+
- 一套配色贯穿所有控件:文字/弱化/提示三级灰阶,唯一操作色 `#6d97ff`,状态色只用于状态(绿/琥珀/红)。
|
|
117
|
+
- 警示提示改为「深底 + 琥珀文字 + 边框」的低饱和样式,不再出现黄色看不清的问题;崩溃提示条改为中性深色。
|
|
118
|
+
- 摘要引擎改为分段控件(本地规则 / API 摘要),两种模式的选择一目了然。
|
|
119
|
+
- 所有数值设置都带单位:个会话 / 条 / tokens / 元 / 百万 token;批量上限只在开启「关闭时批量生成」时出现,并紧跟提示。
|
|
120
|
+
- 设置页统一为「行式表单 + 发丝分隔线 + 卡片标题竖条」的结构,左下角固定「保存修改」主按钮。
|
|
121
|
+
|
|
106
122
|
## 0.2.1(设置界面可读性)
|
|
107
123
|
|
|
108
124
|
- 设置页重做:渐变标题卡 + 状态胶囊、强调条卡片、整行可点的开关(带滑动圆钮)、蓝底主按钮「保存修改」、描边次按钮「处理队列」/「查询」
|
package/client.js
CHANGED
|
@@ -23,8 +23,8 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const DICT = {
|
|
24
24
|
zh: {
|
|
25
25
|
chip: '卷末',
|
|
26
|
-
chipReady: '
|
|
27
|
-
chipEmpty: '
|
|
26
|
+
chipReady: '卷末摘要',
|
|
27
|
+
chipEmpty: '生成卷末摘要',
|
|
28
28
|
panelTitle: '卷末',
|
|
29
29
|
empty: '这条会话还没有卷末:对话太短,或者还没生成。',
|
|
30
30
|
generate: '立即生成',
|
|
@@ -37,7 +37,7 @@ window.__ModuleLoader__.load({
|
|
|
37
37
|
failed: '读取失败:{message}',
|
|
38
38
|
crash: '上次 DSH 没有正常退出,卷末已在本地恢复(0 token)。',
|
|
39
39
|
crashAck: '知道了',
|
|
40
|
-
settingsLabel: '
|
|
40
|
+
settingsLabel: '卷末摘要',
|
|
41
41
|
settingsIntro: '规则引擎只读本地日志,不调用模型、不花 token;API 摘要为可选项。',
|
|
42
42
|
engine: '摘要引擎',
|
|
43
43
|
engineRules: '本地规则',
|
|
@@ -87,6 +87,13 @@ window.__ModuleLoader__.load({
|
|
|
87
87
|
queueRun: '队列已处理',
|
|
88
88
|
apiUnavailable: '当前环境没有可用的模型服务(llm):API 引擎会回退到本地 rules 摘要,并把它放进待确认队列。',
|
|
89
89
|
statusFailed: '状态读取失败',
|
|
90
|
+
sectionsTitle: '摘要区块',
|
|
91
|
+
sectionsHint: '总结里会出现哪些区块,按需勾选;区块越多,内容越长。',
|
|
92
|
+
secGoal: '目标', secConclusion: '结论', secDecisions: '决策', secFiles: '涉及文件',
|
|
93
|
+
secProgress: '完成情况', secNextSteps: '下一步', secRisks: '风险与注意', secKeywords: '关键词', secQuestions: '待确认问题',
|
|
94
|
+
secGoalHint: '用户最终想要什么', secConclusionHint: '当前状态与结论', secDecisionsHint: '关键决定及理由',
|
|
95
|
+
secFilesHint: '被修改的文件', secProgressHint: '已确认完成的事(中间动作)', secNextStepsHint: '还没做完的事',
|
|
96
|
+
secRisksHint: '报错、限制与未验证假设', secKeywordsHint: '便于检索的短词', secQuestionsHint: '仍需确认的问题',
|
|
90
97
|
basicTitle: '基本设置',
|
|
91
98
|
statusOn: '已启用',
|
|
92
99
|
statusOff: '已暂停',
|
|
@@ -118,8 +125,8 @@ window.__ModuleLoader__.load({
|
|
|
118
125
|
},
|
|
119
126
|
en: {
|
|
120
127
|
chip: 'Colophon',
|
|
121
|
-
chipReady: 'Colophon
|
|
122
|
-
chipEmpty: '
|
|
128
|
+
chipReady: 'Colophon summary',
|
|
129
|
+
chipEmpty: 'Generate summary',
|
|
123
130
|
panelTitle: 'Colophon',
|
|
124
131
|
empty: 'No digest yet for this session: the conversation is short or nothing was generated.',
|
|
125
132
|
generate: 'Generate now',
|
|
@@ -182,6 +189,13 @@ window.__ModuleLoader__.load({
|
|
|
182
189
|
queueRun: 'Queue processed',
|
|
183
190
|
apiUnavailable: 'No model service (llm) is available here: the API engine falls back to local rules digests and queues the session for confirmation.',
|
|
184
191
|
statusFailed: 'Status unavailable',
|
|
192
|
+
sectionsTitle: 'Summary blocks',
|
|
193
|
+
sectionsHint: 'Pick the blocks that appear in the digest; more blocks make it longer.',
|
|
194
|
+
secGoal: 'Goal', secConclusion: 'Conclusion', secDecisions: 'Decisions', secFiles: 'Files',
|
|
195
|
+
secProgress: 'Progress', secNextSteps: 'Next steps', secRisks: 'Risks', secKeywords: 'Keywords', secQuestions: 'Open questions',
|
|
196
|
+
secGoalHint: 'what the user ultimately wants', secConclusionHint: 'current state and result', secDecisionsHint: 'key decisions and why',
|
|
197
|
+
secFilesHint: 'files that were changed', secProgressHint: 'confirmed completed work', secNextStepsHint: 'what is left to do',
|
|
198
|
+
secRisksHint: 'errors, limits, unverified guesses', secKeywordsHint: 'short search terms', secQuestionsHint: 'questions needing confirmation',
|
|
185
199
|
basicTitle: 'Basics',
|
|
186
200
|
statusOn: 'Enabled',
|
|
187
201
|
statusOff: 'Paused',
|
|
@@ -239,21 +253,33 @@ window.__ModuleLoader__.load({
|
|
|
239
253
|
|
|
240
254
|
const styles = {
|
|
241
255
|
chip: {
|
|
242
|
-
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '
|
|
243
|
-
border: '1px solid rgba(
|
|
244
|
-
|
|
256
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '0 12px', height: 28,
|
|
257
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.14))', borderRadius: 8,
|
|
258
|
+
background: 'var(--dsw-alias-bg-layer-2, #f2f3f5)',
|
|
259
|
+
color: 'var(--dsw-alias-label-primary, #1f2329)', cursor: 'pointer', fontSize: 13, fontWeight: 500,
|
|
260
|
+
},
|
|
261
|
+
chipOn: {
|
|
262
|
+
border: '1px solid var(--dsw-alias-button-primary-fill, #4d6bfe)',
|
|
263
|
+
background: 'color-mix(in srgb, var(--dsw-alias-button-primary-fill, #4d6bfe) 12%, transparent)',
|
|
245
264
|
},
|
|
246
265
|
dot: { width: 7, height: 7, borderRadius: 999, background: '#4cc38a', display: 'inline-block' },
|
|
247
266
|
dotEmpty: { width: 7, height: 7, borderRadius: 999, background: 'rgba(255,255,255,0.35)', display: 'inline-block' },
|
|
248
267
|
panel: {
|
|
249
268
|
position: 'fixed', right: 16, bottom: 96, width: 380, maxWidth: 'calc(100vw - 32px)',
|
|
250
269
|
maxHeight: '62vh', overflow: 'auto', zIndex: 60, padding: 14,
|
|
251
|
-
background: '
|
|
252
|
-
|
|
253
|
-
|
|
270
|
+
background: 'var(--dsw-alias-bg-layer-2, #ffffff)',
|
|
271
|
+
color: 'var(--dsw-alias-label-primary, #1f2329)',
|
|
272
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))', borderRadius: 12,
|
|
273
|
+
boxShadow: '0 12px 40px rgba(0,0,0,0.22)', fontSize: 13, lineHeight: 1.55,
|
|
274
|
+
},
|
|
275
|
+
panelHead: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 },
|
|
276
|
+
title: { fontSize: 15, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #1f2329)' },
|
|
277
|
+
digestTitle: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #4e5969)', marginBottom: 4 },
|
|
278
|
+
digestBlock: { marginTop: 4, paddingTop: 12, borderTop: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,0.07))' },
|
|
279
|
+
digestBody: {
|
|
280
|
+
whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontFamily: 'inherit',
|
|
281
|
+
fontSize: 13, lineHeight: 1.65, color: 'var(--dsw-alias-label-primary, #1f2329)',
|
|
254
282
|
},
|
|
255
|
-
panelHead: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 },
|
|
256
|
-
title: { fontSize: 13, fontWeight: 600 },
|
|
257
283
|
pre: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontFamily: 'var(--dsh-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)', fontSize: 11, lineHeight: 1.6 },
|
|
258
284
|
actions: { display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' },
|
|
259
285
|
button: {
|
|
@@ -417,6 +443,26 @@ window.__ModuleLoader__.load({
|
|
|
417
443
|
}, tr('crashAck')))
|
|
418
444
|
}
|
|
419
445
|
|
|
446
|
+
/** Split a rendered digest Markdown into titled blocks. */
|
|
447
|
+
function parseDigestBlocks(markdown) {
|
|
448
|
+
const out = []
|
|
449
|
+
let current = null
|
|
450
|
+
for (const raw of String(markdown ?? '').split('\n')) {
|
|
451
|
+
const line = raw.trimEnd()
|
|
452
|
+
if (line.startsWith('#')) {
|
|
453
|
+
const heading = line.replace(/^#+\s*/, '').trim()
|
|
454
|
+
if (!heading) continue
|
|
455
|
+
current = { heading, body: [] }
|
|
456
|
+
out.push(current)
|
|
457
|
+
continue
|
|
458
|
+
}
|
|
459
|
+
if (current) current.body.push(line)
|
|
460
|
+
}
|
|
461
|
+
return out
|
|
462
|
+
.map(block => ({ heading: block.heading, body: block.body.join('\n').trim() }))
|
|
463
|
+
.filter(block => block.body !== '' || /^(卷末|Colophon)/i.test(block.heading) === false)
|
|
464
|
+
}
|
|
465
|
+
|
|
420
466
|
/** The chip + floating digest panel above the composer. */
|
|
421
467
|
function ColophonDock(props) {
|
|
422
468
|
const sessionId = props.sessionId
|
|
@@ -483,24 +529,29 @@ window.__ModuleLoader__.load({
|
|
|
483
529
|
if (variant === 'hero' || !sessionId) return null
|
|
484
530
|
|
|
485
531
|
const chip = h('button', {
|
|
486
|
-
style: styles.chip,
|
|
532
|
+
style: digest ? { ...styles.chip, ...styles.chipOn } : styles.chip,
|
|
487
533
|
title: tr('panelTitle'),
|
|
488
534
|
onClick: () => setOpen(current => !current),
|
|
489
535
|
},
|
|
490
536
|
h('span', { style: digest ? styles.dot : styles.dotEmpty }),
|
|
491
537
|
h('span', null, digest ? tr('chipReady') : tr('chipEmpty')))
|
|
492
538
|
|
|
539
|
+
const blocks = digest?.markdown ? parseDigestBlocks(digest.markdown) : []
|
|
540
|
+
|
|
493
541
|
const panel = open ? h('div', { style: styles.panel, role: 'dialog', 'aria-label': tr('panelTitle') },
|
|
494
542
|
h('div', { style: styles.panelHead },
|
|
495
543
|
h('span', { style: styles.title }, tr('panelTitle')),
|
|
496
|
-
h('span', { style: styles.muted }, digest?.updatedAt ? new Date(digest.updatedAt).toLocaleString() : '')
|
|
544
|
+
h('span', { style: { ...styles.muted, marginRight: 'auto' } }, digest?.updatedAt ? new Date(digest.updatedAt).toLocaleString() : ''),
|
|
545
|
+
h('button', { style: { ...styles.buttonPrimary, minWidth: 92 }, onClick: () => void generate(), disabled: loading },
|
|
546
|
+
digest ? tr('regenerate') : tr('generate'))),
|
|
497
547
|
loading ? h('div', { style: styles.muted }, tr('loading'))
|
|
498
548
|
: error ? h('div', { style: styles.warn }, tr('failed', { message: error }))
|
|
499
|
-
:
|
|
549
|
+
: blocks.length > 0
|
|
550
|
+
? h('div', null, blocks.map((block, index) => h('div', { key: index, style: index === 0 ? null : styles.digestBlock },
|
|
551
|
+
h('div', { style: styles.digestTitle }, block.heading),
|
|
552
|
+
h('div', { style: styles.digestBody }, block.body))))
|
|
500
553
|
: h('div', { style: styles.muted }, tr('empty')),
|
|
501
554
|
h('div', { style: styles.actions },
|
|
502
|
-
h('button', { style: styles.buttonPrimary, onClick: () => void generate(), disabled: loading },
|
|
503
|
-
digest ? tr('regenerate') : tr('generate')),
|
|
504
555
|
digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
|
|
505
556
|
digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void download() }, tr('download')) : null,
|
|
506
557
|
h('button', { style: styles.buttonSecondary, onClick: () => setOpen(false) }, tr('close')))) : null
|
|
@@ -509,109 +560,244 @@ window.__ModuleLoader__.load({
|
|
|
509
560
|
}
|
|
510
561
|
|
|
511
562
|
/** A labelled row: text block on the left, control on the right. */
|
|
512
|
-
|
|
513
|
-
|
|
563
|
+
// ---- Settings page look: mirrors DSH's own settings design language ----
|
|
564
|
+
// Colors come from the shell's design tokens, so every theme (including the
|
|
565
|
+
// whale-dream skins) keeps readable contrast without hardcoded values.
|
|
566
|
+
const ui = {
|
|
567
|
+
page: {
|
|
568
|
+
display: 'flex', flexDirection: 'column', maxWidth: 760, padding: '2px 0 96px',
|
|
569
|
+
color: 'var(--dsw-alias-label-primary, #e9edf3)', lineHeight: 1.55,
|
|
570
|
+
},
|
|
571
|
+
header: { display: 'flex', flexDirection: 'column', gap: 6, padding: '2px 0 6px' },
|
|
572
|
+
headerRow: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' },
|
|
573
|
+
title: { fontSize: 19, fontWeight: 650, letterSpacing: '-0.01em' },
|
|
574
|
+
subtitle: { fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-tertiary, #8b93a1)', maxWidth: 620 },
|
|
575
|
+
meta: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', fontSize: 12, color: 'var(--dsw-alias-label-quaternary, #6d7686)' },
|
|
576
|
+
group: { display: 'flex', flexDirection: 'column' },
|
|
577
|
+
groupHead: { display: 'flex', alignItems: 'center', gap: 8, padding: '22px 0 2px' },
|
|
578
|
+
groupTitle: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #b7bec9)' },
|
|
579
|
+
groupMeta: { marginLeft: 'auto', fontSize: 12, color: 'var(--dsw-alias-label-quaternary, #6d7686)' },
|
|
580
|
+
row: {
|
|
581
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 24,
|
|
582
|
+
padding: '16px 0', minHeight: 46, boxSizing: 'border-box',
|
|
583
|
+
borderBottom: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.07))',
|
|
584
|
+
},
|
|
585
|
+
rowLast: { borderBottom: 'none' },
|
|
586
|
+
labelBlock: { display: 'flex', flexDirection: 'column', gap: 4, flex: '1 1 auto', minWidth: 0 },
|
|
587
|
+
label: { fontSize: 15, fontWeight: 500, color: 'var(--dsw-alias-label-primary, #e9edf3)' },
|
|
588
|
+
hint: { fontSize: 13, lineHeight: 1.55, color: 'var(--dsw-alias-label-tertiary, #8b93a1)' },
|
|
589
|
+
control: { display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto', flexWrap: 'wrap', justifyContent: 'flex-end' },
|
|
590
|
+
input: {
|
|
591
|
+
height: 32, boxSizing: 'border-box', padding: '0 10px', outline: 'none',
|
|
592
|
+
borderRadius: 'var(--dsw-radius-sm, 8px)',
|
|
593
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.10))',
|
|
594
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(255,255,255,0.05))',
|
|
595
|
+
color: 'var(--dsw-alias-label-primary, #e9edf3)', fontSize: 13,
|
|
596
|
+
},
|
|
597
|
+
inputNum: { width: 96, textAlign: 'right', fontVariantNumeric: 'tabular-nums' },
|
|
598
|
+
inputText: { width: 180 },
|
|
599
|
+
unit: { fontSize: 13, color: 'var(--dsw-alias-label-quaternary, #6d7686)', whiteSpace: 'nowrap' },
|
|
600
|
+
selectWrap: { display: 'inline-flex', alignItems: 'center' },
|
|
601
|
+
select: {
|
|
602
|
+
appearance: 'none', WebkitAppearance: 'none', height: 32, boxSizing: 'border-box',
|
|
603
|
+
padding: '0 28px 0 10px', borderRadius: 'var(--dsw-radius-sm, 8px)', cursor: 'pointer', outline: 'none',
|
|
604
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.10))',
|
|
605
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(255,255,255,0.05))',
|
|
606
|
+
color: 'var(--dsw-alias-label-primary, #e9edf3)', fontSize: 13,
|
|
607
|
+
},
|
|
608
|
+
chevron: { position: 'absolute', right: 10, pointerEvents: 'none', fontSize: 9, color: 'var(--dsw-alias-label-quaternary, #6d7686)' },
|
|
609
|
+
segmented: {
|
|
610
|
+
display: 'inline-flex', padding: 2, gap: 2, borderRadius: 'var(--dsw-radius-sm, 8px)',
|
|
611
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(255,255,255,0.05))',
|
|
612
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.08))',
|
|
613
|
+
},
|
|
614
|
+
segItem: {
|
|
615
|
+
appearance: 'none', border: 0, background: 'transparent', cursor: 'pointer', borderRadius: 6,
|
|
616
|
+
padding: '4px 12px', display: 'inline-flex', flexDirection: 'column', alignItems: 'flex-start', gap: 1,
|
|
617
|
+
minWidth: 92, textAlign: 'left', color: 'var(--dsw-alias-label-tertiary, #8b93a1)',
|
|
618
|
+
},
|
|
619
|
+
segItemOn: {
|
|
620
|
+
background: 'var(--dsw-alias-interactive-bg-hover, rgba(255,255,255,0.10))',
|
|
621
|
+
color: 'var(--dsw-alias-label-primary, #e9edf3)',
|
|
622
|
+
boxShadow: 'inset 0 0 0 1px var(--dsw-alias-border-l2, rgba(255,255,255,0.12))',
|
|
623
|
+
},
|
|
624
|
+
segTitle: { fontSize: 13, fontWeight: 550, lineHeight: 1.35 },
|
|
625
|
+
segHint: { fontSize: 11, lineHeight: 1.3, color: 'var(--dsw-alias-label-quaternary, #6d7686)', fontWeight: 400 },
|
|
626
|
+
switchRow: { cursor: 'pointer' },
|
|
627
|
+
switchTrack: {
|
|
628
|
+
position: 'relative', flex: '0 0 auto', width: 38, height: 22, borderRadius: 999,
|
|
629
|
+
background: 'var(--dsw-alias-border-l2, rgba(255,255,255,0.20))', transition: 'background 140ms ease',
|
|
630
|
+
},
|
|
631
|
+
switchTrackOn: { background: 'var(--dsw-alias-state-business-primary, #4d6bfe)' },
|
|
632
|
+
switchKnob: {
|
|
633
|
+
position: 'absolute', top: 3, left: 3, width: 16, height: 16, borderRadius: 999,
|
|
634
|
+
background: '#fff', transition: 'transform 140ms ease', boxShadow: '0 1px 2px rgba(0,0,0,0.35)',
|
|
635
|
+
},
|
|
636
|
+
switchKnobOn: { transform: 'translateX(16px)' },
|
|
637
|
+
callout: {
|
|
638
|
+
display: 'flex', gap: 8, alignItems: 'flex-start', margin: '10px 0 14px', padding: '10px 12px',
|
|
639
|
+
borderRadius: 'var(--dsw-radius-sm, 8px)', fontSize: 13, lineHeight: 1.55,
|
|
640
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.08))',
|
|
641
|
+
background: 'var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.04))',
|
|
642
|
+
color: 'var(--dsw-alias-label-secondary, #b7bec9)',
|
|
643
|
+
},
|
|
644
|
+
calloutWarn: {
|
|
645
|
+
borderColor: 'var(--dsw-alias-state-warn-secondary, #6b5836)',
|
|
646
|
+
background: 'color-mix(in srgb, var(--dsw-alias-state-warn-primary, #e6c07a) 12%, transparent)',
|
|
647
|
+
color: 'var(--dsw-alias-state-warn-label, #e8c98f)',
|
|
648
|
+
},
|
|
649
|
+
calloutError: {
|
|
650
|
+
borderColor: 'var(--dsw-alias-state-error-secondary, #5c2b2b)',
|
|
651
|
+
background: 'rgba(239,103,92,0.10)', color: 'var(--dsw-alias-state-error-primary, #ef675c)',
|
|
652
|
+
},
|
|
653
|
+
calloutOk: {
|
|
654
|
+
borderColor: 'var(--dsw-alias-state-success-secondary, #2f5140)',
|
|
655
|
+
background: 'rgba(110,216,137,0.10)', color: 'var(--dsw-alias-state-success-primary, #6ed889)',
|
|
656
|
+
},
|
|
657
|
+
calloutDot: { width: 6, height: 6, borderRadius: 999, marginTop: 6, flex: '0 0 auto' },
|
|
658
|
+
calloutLabel: { fontWeight: 600, marginRight: 4 },
|
|
659
|
+
pill: { display: 'inline-flex', alignItems: 'center', gap: 6, height: 22, padding: '0 9px', borderRadius: 999, fontSize: 12, fontWeight: 500, whiteSpace: 'nowrap', border: '1px solid transparent' },
|
|
660
|
+
pillOn: { background: 'rgba(110,216,137,0.12)', color: 'var(--dsw-alias-state-success-primary, #6ed889)', borderColor: 'rgba(110,216,137,0.30)' },
|
|
661
|
+
pillOff: { background: 'var(--dsw-alias-bg-layer-2, rgba(255,255,255,0.05))', color: 'var(--dsw-alias-label-tertiary, #8b93a1)', borderColor: 'var(--dsw-alias-border-l1, rgba(255,255,255,0.08))' },
|
|
662
|
+
pillCount: { background: 'rgba(77,107,254,0.14)', color: 'var(--dsw-alias-label-primary, #e9edf3)', borderColor: 'rgba(77,107,254,0.34)' },
|
|
663
|
+
pillDot: { width: 6, height: 6, borderRadius: 999, display: 'inline-block' },
|
|
664
|
+
buttonPrimary: {
|
|
665
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center', height: 34, minWidth: 108,
|
|
666
|
+
padding: '0 18px', borderRadius: 'var(--dsw-radius-sm, 8px)', cursor: 'pointer', boxSizing: 'border-box',
|
|
667
|
+
border: '1px solid var(--dsw-alias-button-primary-fill, #4d6bfe)',
|
|
668
|
+
background: 'var(--dsw-alias-button-primary-fill, #4d6bfe)',
|
|
669
|
+
color: 'var(--dsw-alias-label-on-color, #fff)', fontSize: 13, fontWeight: 600,
|
|
670
|
+
},
|
|
671
|
+
buttonSecondary: {
|
|
672
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center', height: 32, minWidth: 84,
|
|
673
|
+
padding: '0 14px', borderRadius: 'var(--dsw-radius-sm, 8px)', cursor: 'pointer', boxSizing: 'border-box',
|
|
674
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(255,255,255,0.14))',
|
|
675
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(255,255,255,0.05))',
|
|
676
|
+
color: 'var(--dsw-alias-label-primary, #e9edf3)', fontSize: 13, fontWeight: 500,
|
|
677
|
+
},
|
|
678
|
+
buttonDisabled: { opacity: 0.4, cursor: 'not-allowed' },
|
|
679
|
+
footer: {
|
|
680
|
+
display: 'flex', alignItems: 'center', gap: 12, marginTop: 24, paddingTop: 14,
|
|
681
|
+
borderTop: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.07))',
|
|
682
|
+
},
|
|
683
|
+
footerText: { flex: '1 1 auto', fontSize: 13, color: 'var(--dsw-alias-label-quaternary, #6d7686)', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
684
|
+
statGrid: { display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 10, padding: '12px 0 4px' },
|
|
685
|
+
statCard: {
|
|
686
|
+
display: 'flex', flexDirection: 'column', gap: 2, padding: '12px 14px',
|
|
687
|
+
borderRadius: 'var(--dsw-radius-sm, 8px)',
|
|
688
|
+
background: 'var(--dsw-alias-card-fill, var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.04)))',
|
|
689
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.07))',
|
|
690
|
+
},
|
|
691
|
+
statLabel: { fontSize: 12, color: 'var(--dsw-alias-label-tertiary, #8b93a1)' },
|
|
692
|
+
statValue: { fontSize: 16, fontWeight: 600, fontVariantNumeric: 'tabular-nums', letterSpacing: '-0.01em', marginTop: 2 },
|
|
693
|
+
statMeta: { fontSize: 12, color: 'var(--dsw-alias-label-quaternary, #6d7686)' },
|
|
694
|
+
queueList: { display: 'flex', flexDirection: 'column' },
|
|
695
|
+
queueRow: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', padding: '10px 0', borderBottom: '1px solid var(--dsw-alias-border-l1, rgba(255,255,255,0.06))', fontSize: 13 },
|
|
696
|
+
emptyBox: { padding: '14px 0', fontSize: 13, color: 'var(--dsw-alias-label-quaternary, #6d7686)' },
|
|
697
|
+
rangeRow: { display: 'flex', alignItems: 'flex-end', gap: 10, flexWrap: 'wrap', padding: '12px 0 2px' },
|
|
698
|
+
field: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12, color: 'var(--dsw-alias-label-tertiary, #8b93a1)' },
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/** A labelled row: text block on the left, control on the right. */
|
|
702
|
+
function Row({ children, last, onClick }) {
|
|
703
|
+
return h('div', { style: last ? { ...ui.row, ...ui.rowLast } : ui.row, onClick }, children)
|
|
514
704
|
}
|
|
515
705
|
|
|
516
706
|
function LabelBlock({ label, hint }) {
|
|
517
|
-
return h('div', { style:
|
|
518
|
-
h('
|
|
519
|
-
hint ? h('
|
|
707
|
+
return h('div', { style: ui.labelBlock },
|
|
708
|
+
h('div', { style: ui.label }, label),
|
|
709
|
+
hint ? h('div', { style: ui.hint }, hint) : null)
|
|
520
710
|
}
|
|
521
711
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
712
|
+
function Group({ title, meta, children }) {
|
|
713
|
+
return h('div', { style: ui.group },
|
|
714
|
+
title
|
|
715
|
+
? h('div', { style: ui.groupHead },
|
|
716
|
+
h('span', { style: ui.groupTitle }, title),
|
|
717
|
+
meta ? h('span', { style: ui.groupMeta }, meta) : null)
|
|
718
|
+
: null,
|
|
528
719
|
children)
|
|
529
720
|
}
|
|
530
721
|
|
|
531
|
-
/** A full-row toggle: the whole row is the click target, the knob is obvious. */
|
|
532
722
|
function SwitchRow({ label, hint, checked, onChange, last }) {
|
|
533
|
-
const on = checked === true
|
|
534
|
-
const toggle = () => onChange(!on)
|
|
535
723
|
return h('div', {
|
|
536
|
-
|
|
537
|
-
'aria-checked':
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
h('span', { style: styles.label }, label),
|
|
545
|
-
hint ? h('span', { style: styles.hint }, hint) : null),
|
|
546
|
-
h('div', { style: on ? { ...styles.switchTrack, ...styles.switchTrackOn } : styles.switchTrack },
|
|
547
|
-
h('div', { style: on ? { ...styles.switchKnob, ...styles.switchKnobOn } : styles.switchKnob })))
|
|
724
|
+
style: last ? { ...ui.row, ...ui.rowLast, ...ui.switchRow } : { ...ui.row, ...ui.switchRow },
|
|
725
|
+
role: 'switch', 'aria-checked': checked, tabIndex: 0,
|
|
726
|
+
onClick: () => onChange(!checked),
|
|
727
|
+
onKeyDown: event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onChange(!checked) } },
|
|
728
|
+
},
|
|
729
|
+
h(LabelBlock, { label, hint }),
|
|
730
|
+
h('div', { style: { ...ui.switchTrack, ...(checked ? ui.switchTrackOn : null) } },
|
|
731
|
+
h('div', { style: { ...ui.switchKnob, ...(checked ? ui.switchKnobOn : null) } })))
|
|
548
732
|
}
|
|
549
733
|
|
|
550
|
-
/** Two-option (or N-option) segmented control, used instead of native selects for the mode fields. */
|
|
551
734
|
function Segmented({ options, value, onChange }) {
|
|
552
|
-
return h('div', { style:
|
|
553
|
-
options.map(option => {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
},
|
|
560
|
-
h('span', { style: styles.segTitle }, option.label),
|
|
561
|
-
option.hint ? h('span', { style: on ? { ...styles.segHint, ...styles.segHintOn } : styles.segHint }, option.hint) : null)
|
|
562
|
-
}))
|
|
735
|
+
return h('div', { style: ui.segmented },
|
|
736
|
+
options.map(option => h('button', {
|
|
737
|
+
key: option.value, type: 'button',
|
|
738
|
+
style: option.value === value ? { ...ui.segItem, ...ui.segItemOn } : ui.segItem,
|
|
739
|
+
onClick: () => onChange(option.value),
|
|
740
|
+
},
|
|
741
|
+
h('span', { style: ui.segTitle }, option.label),
|
|
742
|
+
option.hint ? h('span', { style: ui.segHint }, option.hint) : null)))
|
|
563
743
|
}
|
|
564
744
|
|
|
565
|
-
function Select({ value, onChange,
|
|
566
|
-
return h('
|
|
567
|
-
h('select', { style: { ...
|
|
568
|
-
h('span', { style:
|
|
745
|
+
function Select({ value, onChange, width, children }) {
|
|
746
|
+
return h('span', { style: ui.selectWrap },
|
|
747
|
+
h('select', { style: { ...ui.select, width: width || 160 }, value, onChange: event => onChange(event.target.value) }, children),
|
|
748
|
+
h('span', { style: ui.chevron }, '▾'))
|
|
569
749
|
}
|
|
570
750
|
|
|
571
|
-
/** Exactly one numeric input with a trailing unit; used by every numeric setting. */
|
|
572
751
|
function NumberRow({ label, hint, value, onChange, step, unit, last }) {
|
|
573
752
|
return h(Row, { last },
|
|
574
753
|
h(LabelBlock, { label, hint }),
|
|
575
|
-
h('div', { style:
|
|
754
|
+
h('div', { style: ui.control },
|
|
576
755
|
h('input', {
|
|
577
|
-
style: { ...
|
|
756
|
+
style: { ...ui.input, ...ui.inputNum }, type: 'number', step: step || 1,
|
|
578
757
|
value: value ?? '', onChange: event => onChange(Number(event.target.value)),
|
|
579
758
|
}),
|
|
580
|
-
unit ? h('span', { style:
|
|
759
|
+
unit ? h('span', { style: ui.unit }, unit) : null))
|
|
581
760
|
}
|
|
582
761
|
|
|
583
762
|
function TextRow({ label, hint, value, onChange, placeholder, width, last }) {
|
|
584
763
|
return h(Row, { last },
|
|
585
764
|
h(LabelBlock, { label, hint }),
|
|
586
|
-
h('div', { style:
|
|
765
|
+
h('div', { style: ui.control },
|
|
587
766
|
h('input', {
|
|
588
|
-
style: { ...
|
|
589
|
-
|
|
767
|
+
style: { ...ui.input, width: width || 180 }, type: 'text', value: value ?? '', placeholder,
|
|
768
|
+
onChange: event => onChange(event.target.value),
|
|
590
769
|
})))
|
|
591
770
|
}
|
|
592
771
|
|
|
593
|
-
/** Inline status message with one consistent shape: a colored dot + readable text. */
|
|
594
772
|
function Callout({ tone = 'info', label, children }) {
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}[tone] || [styles.calloutInfo, '#6d97ff']
|
|
601
|
-
return h('div', { style: { ...styles.callout, ...palette[0] }, role: tone === 'error' ? 'alert' : 'status' },
|
|
602
|
-
h('span', { style: { ...styles.calloutDot, background: palette[1] } }),
|
|
603
|
-
h('span', { style: { minWidth: 0 } },
|
|
604
|
-
label ? h('span', { style: styles.calloutLabel }, label) : null,
|
|
773
|
+
const toneStyle = tone === 'warn' ? ui.calloutWarn : tone === 'error' ? ui.calloutError : tone === 'ok' ? ui.calloutOk : null
|
|
774
|
+
return h('div', { style: toneStyle ? { ...ui.callout, ...toneStyle } : ui.callout, role: 'note' },
|
|
775
|
+
h('span', { style: { ...ui.calloutDot, background: 'currentColor' } }),
|
|
776
|
+
h('span', null,
|
|
777
|
+
label ? h('span', { style: ui.calloutLabel }, label) : null,
|
|
605
778
|
children))
|
|
606
779
|
}
|
|
607
780
|
|
|
608
|
-
function StatusPill({ on, onText, offText }) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
on ?
|
|
781
|
+
function StatusPill({ on, onText, offText, count }) {
|
|
782
|
+
const style = count ? { ...ui.pill, ...ui.pillCount } : on ? { ...ui.pill, ...ui.pillOn } : { ...ui.pill, ...ui.pillOff }
|
|
783
|
+
return h('span', { style },
|
|
784
|
+
h('span', { style: { ...ui.pillDot, background: 'currentColor', opacity: on || count ? 1 : 0.6 } }),
|
|
785
|
+
count ? onText : on ? onText : offText)
|
|
612
786
|
}
|
|
787
|
+
/** Digest blocks the user can include, in presentation order. */
|
|
788
|
+
const SECTION_META = [
|
|
789
|
+
['goal', 'secGoal', 'secGoalHint'],
|
|
790
|
+
['conclusion', 'secConclusion', 'secConclusionHint'],
|
|
791
|
+
['decisions', 'secDecisions', 'secDecisionsHint'],
|
|
792
|
+
['files', 'secFiles', 'secFilesHint'],
|
|
793
|
+
['progress', 'secProgress', 'secProgressHint'],
|
|
794
|
+
['nextSteps', 'secNextSteps', 'secNextStepsHint'],
|
|
795
|
+
['risks', 'secRisks', 'secRisksHint'],
|
|
796
|
+
['keywords', 'secKeywords', 'secKeywordsHint'],
|
|
797
|
+
['questions', 'secQuestions', 'secQuestionsHint'],
|
|
798
|
+
]
|
|
613
799
|
|
|
614
|
-
/** Settings page
|
|
800
|
+
/** Settings page: native DSH layout (rows + hairlines) and token colors. */
|
|
615
801
|
function ColophonSettings() {
|
|
616
802
|
const [form, setForm] = useState(null)
|
|
617
803
|
const [status, setStatus] = useState(null)
|
|
@@ -648,17 +834,25 @@ window.__ModuleLoader__.load({
|
|
|
648
834
|
setMessage('')
|
|
649
835
|
}
|
|
650
836
|
|
|
837
|
+
const toggleSection = (id) => {
|
|
838
|
+
setForm(current => {
|
|
839
|
+
if (!current) return current
|
|
840
|
+
const list = Array.isArray(current.sections) ? current.sections : []
|
|
841
|
+
const next = list.includes(id) ? list.filter(item => item !== id) : [...list, id]
|
|
842
|
+
return { ...current, sections: next }
|
|
843
|
+
})
|
|
844
|
+
setMessage('')
|
|
845
|
+
}
|
|
846
|
+
|
|
651
847
|
const save = async () => {
|
|
652
848
|
if (!form) return
|
|
653
849
|
setSaving(true)
|
|
654
850
|
setFailed('')
|
|
655
851
|
try {
|
|
656
852
|
const patch = {
|
|
657
|
-
enabled: form.enabled,
|
|
658
|
-
|
|
659
|
-
api: form.api,
|
|
660
|
-
triggers: form.triggers,
|
|
661
|
-
filter: form.filter,
|
|
853
|
+
enabled: form.enabled, engine: form.engine,
|
|
854
|
+
sections: form.sections,
|
|
855
|
+
api: form.api, triggers: form.triggers, filter: form.filter,
|
|
662
856
|
}
|
|
663
857
|
const value = await callHost('config', { method: 'POST', body: { patch } })
|
|
664
858
|
setForm(value.config)
|
|
@@ -683,52 +877,48 @@ window.__ModuleLoader__.load({
|
|
|
683
877
|
const from = Date.parse(range.from)
|
|
684
878
|
const to = range.to === '' ? Date.now() : Date.parse(range.to)
|
|
685
879
|
if (!Number.isFinite(from) || !Number.isFinite(to) || from > to) {
|
|
686
|
-
setFailed(tr('rangeInvalid'))
|
|
687
|
-
setMessage('')
|
|
688
|
-
return
|
|
880
|
+
setFailed(tr('rangeInvalid')); setMessage(''); return
|
|
689
881
|
}
|
|
690
|
-
setFailed('')
|
|
691
|
-
setCustom(null)
|
|
692
|
-
void loadCustom(from, to)
|
|
882
|
+
setFailed(''); setCustom(null); void loadCustom(from, to)
|
|
693
883
|
}
|
|
694
884
|
|
|
885
|
+
const usage = status?.usage ?? {}
|
|
886
|
+
const usageCard = (label, slot, key) => h('div', { key, style: ui.statCard },
|
|
887
|
+
h('div', { style: ui.statLabel }, label),
|
|
888
|
+
h('div', { style: ui.statValue }, money(slot?.costCNY)),
|
|
889
|
+
h('div', { style: ui.statMeta }, tr('tokensLabel', { tokens: integer(slot?.tokens) }), ' · ', tr('calls', { count: slot?.calls ?? 0 })))
|
|
890
|
+
|
|
695
891
|
if (!form) {
|
|
696
|
-
return h('div', { style:
|
|
892
|
+
return h('div', { style: ui.page },
|
|
697
893
|
h(CrashBanner),
|
|
698
|
-
h('div', { style:
|
|
894
|
+
h('div', { style: ui.hint }, failed || tr('loading')))
|
|
699
895
|
}
|
|
700
896
|
|
|
701
|
-
const usage = status?.usage ?? {}
|
|
702
|
-
const usageCard = (label, slot) => h('div', { style: styles.usageCard },
|
|
703
|
-
h('div', { style: styles.usageLabel }, label),
|
|
704
|
-
h('div', { style: styles.usageValue }, money(slot?.costCNY)),
|
|
705
|
-
h('div', { style: styles.usageMeta }, tr('tokensLabel', { tokens: integer(slot?.tokens) }), ' · ', tr('calls', { count: slot?.calls ?? 0 })))
|
|
706
|
-
|
|
707
897
|
const queueItems = status?.queueItems ?? []
|
|
708
898
|
const queueCount = Number(status?.queueCount ?? status?.queue ?? 0) || 0
|
|
709
899
|
const enabled = form.enabled === true
|
|
710
900
|
const apiOn = form.engine === 'api'
|
|
711
901
|
const batchOn = form.triggers.closeBatch === true
|
|
712
902
|
|
|
713
|
-
return h('div', { style:
|
|
903
|
+
return h('div', { style: ui.page },
|
|
714
904
|
h(CrashBanner),
|
|
715
|
-
h('div', { style:
|
|
716
|
-
h('div', { style:
|
|
717
|
-
h('span', { style:
|
|
905
|
+
h('div', { style: ui.header },
|
|
906
|
+
h('div', { style: ui.headerRow },
|
|
907
|
+
h('span', { style: ui.title }, '卷末 Colophon'),
|
|
718
908
|
h(StatusPill, { on: enabled, onText: tr('statusOn'), offText: tr('statusOff') })),
|
|
719
|
-
h('div', { style:
|
|
720
|
-
h('div', { style:
|
|
721
|
-
h('span',
|
|
722
|
-
status ? h('span',
|
|
909
|
+
h('div', { style: ui.subtitle }, tr('settingsSubtitle')),
|
|
910
|
+
h('div', { style: ui.meta },
|
|
911
|
+
h('span', null, tr('saveHint')),
|
|
912
|
+
status ? h('span', null, tr('dataRoot'), ':', status.dataRoot) : null)),
|
|
723
913
|
|
|
724
|
-
h(
|
|
914
|
+
h(Group, { title: tr('basicTitle') },
|
|
725
915
|
h(SwitchRow, {
|
|
726
|
-
label: tr('enabled'), hint: tr('enabledHint'), checked: enabled,
|
|
727
|
-
onChange: value => updateTop('enabled', value),
|
|
916
|
+
label: tr('enabled'), hint: tr('enabledHint'), checked: enabled, last: true,
|
|
917
|
+
onChange: value => updateTop('enabled', value),
|
|
728
918
|
}),
|
|
729
919
|
h(Row, { last: true },
|
|
730
920
|
h(LabelBlock, { label: tr('engine'), hint: tr('engineHint') }),
|
|
731
|
-
h('div', { style:
|
|
921
|
+
h('div', { style: ui.control },
|
|
732
922
|
h(Segmented, {
|
|
733
923
|
value: form.engine,
|
|
734
924
|
onChange: value => updateTop('engine', value),
|
|
@@ -738,7 +928,19 @@ window.__ModuleLoader__.load({
|
|
|
738
928
|
],
|
|
739
929
|
})))),
|
|
740
930
|
|
|
741
|
-
h(
|
|
931
|
+
h(Group, { title: tr('sectionsTitle'), meta: `${(form.sections ?? []).length}/${SECTION_META.length}` },
|
|
932
|
+
h('div', { style: { paddingBottom: 4 } },
|
|
933
|
+
h('div', null,
|
|
934
|
+
SECTION_META.map(([id, labelKey, hintKey], index) => h(SwitchRow, {
|
|
935
|
+
key: id,
|
|
936
|
+
label: tr(labelKey),
|
|
937
|
+
hint: tr(hintKey),
|
|
938
|
+
checked: (form.sections ?? []).includes(id),
|
|
939
|
+
last: index === SECTION_META.length - 1,
|
|
940
|
+
onChange: () => toggleSection(id),
|
|
941
|
+
}))))),
|
|
942
|
+
|
|
943
|
+
h(Group, { title: tr('triggers') },
|
|
742
944
|
h(SwitchRow, {
|
|
743
945
|
label: tr('onIdle'), hint: tr('onIdleHint'), checked: form.triggers.onIdle === true,
|
|
744
946
|
onChange: value => update('triggers', 'onIdle', value),
|
|
@@ -751,42 +953,24 @@ window.__ModuleLoader__.load({
|
|
|
751
953
|
label: tr('closeBatch'), checked: batchOn, last: !batchOn,
|
|
752
954
|
onChange: value => update('triggers', 'closeBatch', value),
|
|
753
955
|
}),
|
|
754
|
-
batchOn ? h(
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
h(Callout, { tone: 'info' }, tr('apiNote')),
|
|
956
|
+
batchOn ? h(NumberRow, {
|
|
957
|
+
label: tr('closeBatchMax'), unit: tr('unitSessions'), step: 1,
|
|
958
|
+
value: form.triggers.closeBatchMaxSessions, last: true,
|
|
959
|
+
onChange: value => update('triggers', 'closeBatchMaxSessions', value),
|
|
960
|
+
}) : null,
|
|
961
|
+
batchOn ? h(Callout, { tone: 'warn', label: tr('note') }, tr('closeBatchWarn')) : null),
|
|
962
|
+
|
|
963
|
+
h(Group, { title: tr('apiSection'), meta: apiOn ? tr('apiOn') : tr('apiOff') },
|
|
964
|
+
h(Callout, null, tr('apiNote')),
|
|
764
965
|
h(TextRow, { label: tr('provider'), hint: 'deepseek-official', value: form.api.provider, width: 200, onChange: value => update('api', 'provider', value) }),
|
|
765
966
|
h(TextRow, { label: tr('model'), hint: 'deepseek-chat', value: form.api.model, width: 200, onChange: value => update('api', 'model', value) }),
|
|
766
|
-
h(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
style: { ...styles.input, ...styles.inputNum }, type: 'number', step: 0.1,
|
|
771
|
-
value: form.api.priceInCNYPerM ?? '', onChange: event => update('api', 'priceInCNYPerM', Number(event.target.value)),
|
|
772
|
-
}),
|
|
773
|
-
h('span', { style: styles.unit }, '元')),
|
|
774
|
-
),
|
|
775
|
-
h(NumberRow, {
|
|
776
|
-
label: tr('priceOut'), hint: tr('unitPrice'), step: 0.1, unit: '元',
|
|
777
|
-
value: form.api.priceOutCNYPerM, onChange: value => update('api', 'priceOutCNYPerM', value),
|
|
778
|
-
}),
|
|
779
|
-
h(NumberRow, {
|
|
780
|
-
label: tr('perSummaryCap'), hint: tr('perSummaryCapHint'), step: 0.01, unit: '元',
|
|
781
|
-
value: form.api.maxCostPerSummaryCNY, onChange: value => update('api', 'maxCostPerSummaryCNY', value),
|
|
782
|
-
}),
|
|
783
|
-
h(NumberRow, {
|
|
784
|
-
label: tr('dailyBudget'), hint: tr('dailyBudgetHint'), step: 1000, unit: 'tokens',
|
|
785
|
-
value: form.api.dailyTokenBudget, onChange: value => update('api', 'dailyTokenBudget', value),
|
|
786
|
-
}),
|
|
967
|
+
h(NumberRow, { label: tr('priceIn'), hint: tr('unitPrice'), step: 0.1, unit: '元', value: form.api.priceInCNYPerM, onChange: value => update('api', 'priceInCNYPerM', value) }),
|
|
968
|
+
h(NumberRow, { label: tr('priceOut'), hint: tr('unitPrice'), step: 0.1, unit: '元', value: form.api.priceOutCNYPerM, onChange: value => update('api', 'priceOutCNYPerM', value) }),
|
|
969
|
+
h(NumberRow, { label: tr('perSummaryCap'), hint: tr('perSummaryCapHint'), step: 0.01, unit: '元', value: form.api.maxCostPerSummaryCNY, onChange: value => update('api', 'maxCostPerSummaryCNY', value) }),
|
|
970
|
+
h(NumberRow, { label: tr('dailyBudget'), hint: tr('dailyBudgetHint'), step: 1000, unit: 'tokens', value: form.api.dailyTokenBudget, onChange: value => update('api', 'dailyTokenBudget', value) }),
|
|
787
971
|
h(Row, { last: !(apiOn && status && status.apiAvailable === false) },
|
|
788
972
|
h(LabelBlock, { label: tr('overCap'), hint: tr('overCapHint') }),
|
|
789
|
-
h('div', { style:
|
|
973
|
+
h('div', { style: ui.control },
|
|
790
974
|
h(Segmented, {
|
|
791
975
|
value: form.api.overCap,
|
|
792
976
|
onChange: value => update('api', 'overCap', value),
|
|
@@ -799,69 +983,59 @@ window.__ModuleLoader__.load({
|
|
|
799
983
|
? h(Callout, { tone: 'warn', label: tr('note') }, tr('apiUnavailable'))
|
|
800
984
|
: null),
|
|
801
985
|
|
|
802
|
-
h(
|
|
803
|
-
h(NumberRow, {
|
|
804
|
-
|
|
805
|
-
value: form.filter.minMessages, onChange: value => update('filter', 'minMessages', value),
|
|
806
|
-
}),
|
|
807
|
-
h(NumberRow, {
|
|
808
|
-
label: tr('minTokens'), hint: tr('minTokensHint'), unit: 'tokens', step: 500, last: true,
|
|
809
|
-
value: form.filter.minTokens, onChange: value => update('filter', 'minTokens', value),
|
|
810
|
-
})),
|
|
986
|
+
h(Group, { title: tr('filter') },
|
|
987
|
+
h(NumberRow, { label: tr('minMessages'), hint: tr('minMessagesHint'), unit: tr('unitMessages'), value: form.filter.minMessages, onChange: value => update('filter', 'minMessages', value) }),
|
|
988
|
+
h(NumberRow, { label: tr('minTokens'), hint: tr('minTokensHint'), unit: 'tokens', step: 500, last: true, value: form.filter.minTokens, onChange: value => update('filter', 'minTokens', value) })),
|
|
811
989
|
|
|
812
|
-
h(
|
|
813
|
-
h('div', { style: { ...styles.hint, padding: '10px 14px 2px' } }, tr('queueHint')),
|
|
990
|
+
h(Group, { title: tr('queueTitle'), meta: queueCount > 0 ? String(queueCount) : tr('queueEmpty') },
|
|
814
991
|
queueItems.length === 0
|
|
815
|
-
? h('div', { style:
|
|
816
|
-
: h('div', { style:
|
|
817
|
-
queueItems.map(item => h('div', { key: item.sessionId, style:
|
|
992
|
+
? h('div', { style: ui.emptyBox }, tr('queueEmpty'))
|
|
993
|
+
: h('div', { style: ui.queueList },
|
|
994
|
+
queueItems.map(item => h('div', { key: item.sessionId, style: ui.queueRow },
|
|
818
995
|
h('span', { style: { fontWeight: 600 } }, String(item.sessionId).slice(0, 14)),
|
|
819
|
-
h('span', { style:
|
|
820
|
-
h('span', { style: { ...
|
|
821
|
-
h(
|
|
822
|
-
h('
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
h(
|
|
838
|
-
h('div', { style:
|
|
839
|
-
usageCard(tr('usageHour'), usage.hour),
|
|
840
|
-
usageCard(tr('usageDay'), usage.day),
|
|
841
|
-
usageCard(tr('usageWeek'), usage.week),
|
|
842
|
-
usageCard(tr('usageMonth'), usage.month)),
|
|
843
|
-
custom ? h('div', { style: { ...
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
h('
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
h('div', { style: { padding: '0 14px 12px' } }, h('span', { style: styles.unit }, tr('rangeEmptyHint')))),
|
|
857
|
-
|
|
858
|
-
h('div', { style: styles.footer },
|
|
996
|
+
h('span', { style: ui.hint }, tr('queueReason', { reason: item.reason })),
|
|
997
|
+
h('span', { style: { ...ui.hint, marginLeft: 'auto' } }, new Date(item.at).toLocaleString())))),
|
|
998
|
+
h(Row, { last: true },
|
|
999
|
+
h('div', { style: ui.hint }, tr('queueHint')),
|
|
1000
|
+
h('div', { style: ui.control },
|
|
1001
|
+
h('button', {
|
|
1002
|
+
style: queueCount === 0 ? { ...ui.buttonSecondary, ...ui.buttonDisabled } : ui.buttonSecondary,
|
|
1003
|
+
disabled: queueCount === 0,
|
|
1004
|
+
onClick: async () => {
|
|
1005
|
+
setFailed('')
|
|
1006
|
+
try {
|
|
1007
|
+
await callHost('queue/run', { method: 'POST', body: {} })
|
|
1008
|
+
setStatus(await callHost('status'))
|
|
1009
|
+
setMessage(tr('queueRun'))
|
|
1010
|
+
} catch (cause) { setFailed(String(cause?.message ?? cause)) }
|
|
1011
|
+
},
|
|
1012
|
+
}, tr('queueProcess'))))),
|
|
1013
|
+
|
|
1014
|
+
h(Group, { title: tr('usage'), meta: tr('localZero') },
|
|
1015
|
+
h('div', { style: ui.statGrid },
|
|
1016
|
+
usageCard(tr('usageHour'), usage.hour, 'hour'),
|
|
1017
|
+
usageCard(tr('usageDay'), usage.day, 'day'),
|
|
1018
|
+
usageCard(tr('usageWeek'), usage.week, 'week'),
|
|
1019
|
+
usageCard(tr('usageMonth'), usage.month, 'month')),
|
|
1020
|
+
custom ? h('div', { style: { ...ui.statGrid, gridTemplateColumns: '1fr' } }, usageCard(tr('usageCustom'), custom, 'custom')) : null,
|
|
1021
|
+
h('div', { style: ui.rangeRow },
|
|
1022
|
+
h('label', { style: ui.field },
|
|
1023
|
+
h('span', null, tr('from')),
|
|
1024
|
+
h('input', { style: ui.input, type: 'datetime-local', value: range.from, onChange: event => setRange(current => ({ ...current, from: event.target.value })) })),
|
|
1025
|
+
h('label', { style: ui.field },
|
|
1026
|
+
h('span', null, tr('to')),
|
|
1027
|
+
h('input', { style: ui.input, type: 'datetime-local', value: range.to, onChange: event => setRange(current => ({ ...current, to: event.target.value })) })),
|
|
1028
|
+
h('button', { style: ui.buttonSecondary, onClick: () => void applyRange() }, tr('apply')),
|
|
1029
|
+
h('span', { style: { ...ui.unit, paddingBottom: 6 } }, tr('customHint'))),
|
|
1030
|
+
h('div', { style: { paddingBottom: 6 } }, h('span', { style: ui.unit }, tr('rangeEmptyHint')))),
|
|
1031
|
+
|
|
1032
|
+
h('div', { style: ui.footer },
|
|
859
1033
|
failed
|
|
860
|
-
? h('span', { style: { ...
|
|
1034
|
+
? h('span', { style: { ...ui.footerText, color: 'var(--dsw-alias-state-error-primary, #ef675c)' } }, failed)
|
|
861
1035
|
: message
|
|
862
|
-
? h('span', { style: { ...
|
|
863
|
-
: h('span', { style:
|
|
864
|
-
h('button', { style: saving ? { ...
|
|
1036
|
+
? h('span', { style: { ...ui.footerText, color: 'var(--dsw-alias-state-success-primary, #6ed889)' } }, message)
|
|
1037
|
+
: h('span', { style: ui.footerText }, tr('saveHint')),
|
|
1038
|
+
h('button', { style: saving ? { ...ui.buttonPrimary, opacity: 0.7, cursor: 'wait' } : ui.buttonPrimary, disabled: saving, onClick: () => void save() },
|
|
865
1039
|
saving ? tr('saving') : tr('save'))))
|
|
866
1040
|
}
|
|
867
1041
|
|
package/index.js
CHANGED
|
@@ -42,9 +42,11 @@ export const Config = Schema.object({
|
|
|
42
42
|
closeBatch: Schema.boolean().default(false),
|
|
43
43
|
closeBatchMaxSessions: Schema.number().default(10),
|
|
44
44
|
}),
|
|
45
|
+
/** Blocks shown in the digest, in the order the settings page lists them. */
|
|
46
|
+
sections: Schema.array(Schema.string()).default(['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']),
|
|
45
47
|
filter: Schema.object({
|
|
46
|
-
minMessages: Schema.number().default(
|
|
47
|
-
minTokens: Schema.number().default(
|
|
48
|
+
minMessages: Schema.number().default(2),
|
|
49
|
+
minTokens: Schema.number().default(100),
|
|
48
50
|
maxAgeDays: Schema.number().default(30),
|
|
49
51
|
sessionTypes: Schema.array(Schema.string()).default(['root']),
|
|
50
52
|
}),
|
package/lib/api.js
CHANGED
|
@@ -9,6 +9,19 @@ import { bullets, clip, estimateTokens, lastParagraph, redactSecrets, section, w
|
|
|
9
9
|
import { costCNY } from './usage.js'
|
|
10
10
|
import { renderDigest } from './digest.js'
|
|
11
11
|
|
|
12
|
+
/** Per-block instructions; only the user-selected blocks are requested. */
|
|
13
|
+
export const SECTION_PROMPTS = {
|
|
14
|
+
goal: ['## 目标', '一段话,说明用户最终想要什么。'],
|
|
15
|
+
conclusion: ['## 结论', '一段话,说明现在处于什么状态、结论是什么;没有结论就写“尚无结论”。'],
|
|
16
|
+
decisions: ['## 决策', '- 条目列表(最多 4 条),列出关键决定及一句话理由;没有就省略该小节。'],
|
|
17
|
+
files: ['## 涉及文件', '- 条目列表(最多 8 条),列出被修改的文件路径;没有就省略该小节。'],
|
|
18
|
+
progress: ['## 完成情况', '- 条目列表(最多 8 条),只列已确认完成的事。'],
|
|
19
|
+
nextSteps: ['## 下一步', '- 条目列表(最多 5 条),来自未完成项;没有就省略该小节。'],
|
|
20
|
+
risks: ['## 风险与注意', '- 条目列表(最多 4 条),来自报错、限制、未验证的假设;没有就省略该小节。'],
|
|
21
|
+
keywords: ['## 关键词', '- 3 到 6 个短词,便于检索;没有就省略该小节。'],
|
|
22
|
+
questions: ['## 待确认问题', '- 条目列表(最多 4 条),列出仍需用户确认的问题;没有就省略该小节。'],
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
/** Instruction sent to the summarizer. Short by design: the tail carries the facts. */
|
|
13
26
|
export const API_PROMPT = [
|
|
14
27
|
'你是「卷末」撰写器:为一个即将结束的编码会话写一份最终交接摘要。',
|
|
@@ -29,6 +42,23 @@ export const API_PROMPT = [
|
|
|
29
42
|
'保持中文、简洁、可执行;不要复述整段对话。',
|
|
30
43
|
].join('\n')
|
|
31
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Build the instruction for the blocks the user enabled.
|
|
47
|
+
* @param {string[]} [sections] enabled block ids.
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function buildApiPrompt(sections) {
|
|
51
|
+
const ids = Array.isArray(sections) && sections.length > 0 ? sections.filter(id => SECTION_PROMPTS[id]) : ['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']
|
|
52
|
+
const lines = [
|
|
53
|
+
'你是「卷末」撰写器:为一个即将结束的编码会话写一份最终交接摘要。',
|
|
54
|
+
'只依据用户消息、最后一条助手回复和工具足迹,不要编造未发生的事。',
|
|
55
|
+
'输出严格使用以下小节(不要输出未列出的小节,也不要在小节前加任何前言):',
|
|
56
|
+
]
|
|
57
|
+
for (const id of ids) lines.push(...SECTION_PROMPTS[id])
|
|
58
|
+
lines.push('保持中文、简洁、可执行;不要复述整段对话。')
|
|
59
|
+
return lines.join('\n')
|
|
60
|
+
}
|
|
61
|
+
|
|
32
62
|
/**
|
|
33
63
|
* Compose the summarizer messages for one checkpoint.
|
|
34
64
|
* @param {ReturnType<import('./collect.js').SessionTail['snapshot']>} checkpoint session tail.
|
|
@@ -63,12 +93,13 @@ export function buildApiMessages(checkpoint, config) {
|
|
|
63
93
|
parts.push(`工具错误:\n${errors.slice(0, 6).map(error => `- ${clip(error?.name ?? 'tool', 60)}${error?.reason ? `:${clip(error.reason, 120)}` : ''}`).join('\n')}`)
|
|
64
94
|
}
|
|
65
95
|
const userText = parts.join('\n\n')
|
|
96
|
+
const system = buildApiPrompt(Array.isArray(config?.sections) ? config.sections : undefined)
|
|
66
97
|
const messages = [
|
|
67
|
-
{ role: /** @type {const} */ ('system'), content:
|
|
98
|
+
{ role: /** @type {const} */ ('system'), content: system },
|
|
68
99
|
{ role: /** @type {const} */ ('user'), content: userText },
|
|
69
100
|
]
|
|
70
|
-
const inputTokens = estimateTokens(
|
|
71
|
-
return { system
|
|
101
|
+
const inputTokens = estimateTokens(system) + estimateTokens(userText)
|
|
102
|
+
return { system, messages, inputTokens, userText }
|
|
72
103
|
}
|
|
73
104
|
|
|
74
105
|
/**
|
|
@@ -121,6 +152,11 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
|
|
|
121
152
|
}
|
|
122
153
|
}
|
|
123
154
|
}
|
|
155
|
+
const keywords = toList(fromJson?.keywords, 6, 40)
|
|
156
|
+
if (keywords.length === 0) keywords.push(...bullets(reply, /(关键词|keywords)/iu, 6, 40))
|
|
157
|
+
const questions = toList(fromJson?.questions, 4, 140)
|
|
158
|
+
if (questions.length === 0) questions.push(...bullets(reply, /(待确认|问题|questions)/iu, 4, 140))
|
|
159
|
+
const sections = Array.isArray(meta.sections) && meta.sections.length > 0 ? meta.sections : ['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']
|
|
124
160
|
const usage = meta.usage ?? {}
|
|
125
161
|
const digest = {
|
|
126
162
|
v: 1,
|
|
@@ -141,6 +177,9 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
|
|
|
141
177
|
done,
|
|
142
178
|
nextSteps,
|
|
143
179
|
risks,
|
|
180
|
+
keywords,
|
|
181
|
+
questions,
|
|
182
|
+
sections,
|
|
144
183
|
tokens: {
|
|
145
184
|
input: Number(usage.inputTokens) || 0,
|
|
146
185
|
output: Number(usage.outputTokens) || 0,
|
package/lib/app.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ensureDir } from './files.js'
|
|
|
9
9
|
import { dataRoot } from './files.js'
|
|
10
10
|
import { Collector, SessionTail } from './collect.js'
|
|
11
11
|
import { buildApiMessages, estimateCost, parseApiDigest } from './api.js'
|
|
12
|
-
import { RULES_VERSION, buildDigest, shouldSummarize } from './digest.js'
|
|
12
|
+
import { DEFAULT_SECTIONS, RULES_VERSION, SECTION_IDS, buildDigest, shouldSummarize } from './digest.js'
|
|
13
13
|
import { Store } from './store.js'
|
|
14
14
|
import { UsageLedger, costCNY } from './usage.js'
|
|
15
15
|
import { estimateTokens } from './text.js'
|
|
@@ -99,6 +99,10 @@ export function sanitizeSettings(patch) {
|
|
|
99
99
|
if (max !== undefined) triggers.closeBatchMaxSessions = Math.max(1, Math.min(50, Math.round(max)))
|
|
100
100
|
if (Object.keys(triggers).length > 0) out.triggers = triggers
|
|
101
101
|
}
|
|
102
|
+
if (Array.isArray(patch.sections)) {
|
|
103
|
+
const sections = [...new Set(patch.sections.filter(id => typeof id === 'string' && SECTION_IDS.includes(id)))]
|
|
104
|
+
out.sections = sections.length > 0 ? sections : [...DEFAULT_SECTIONS]
|
|
105
|
+
}
|
|
102
106
|
if (patch.filter && typeof patch.filter === 'object') {
|
|
103
107
|
const filter = {}
|
|
104
108
|
for (const key of ['minMessages', 'minTokens', 'maxAgeDays']) {
|
|
@@ -292,7 +296,7 @@ export function install(ctx, rawConfig) {
|
|
|
292
296
|
const checkpoint = tail.snapshot()
|
|
293
297
|
if (!shouldSummarize(checkpoint, config.filter).ok) { recovery.skipped += 1; continue }
|
|
294
298
|
await store.saveCheckpoint(checkpoint)
|
|
295
|
-
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now() }))
|
|
299
|
+
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections }))
|
|
296
300
|
recovery.created += 1
|
|
297
301
|
log(`recovered digest for ${sessionId}`)
|
|
298
302
|
} catch (error) {
|
|
@@ -320,7 +324,7 @@ export function install(ctx, rawConfig) {
|
|
|
320
324
|
const digest = await tryApiDigest(sessionId, checkpoint, trigger)
|
|
321
325
|
if (digest) return digest
|
|
322
326
|
}
|
|
323
|
-
const digest = buildDigest(checkpoint, { engine: 'rules', now: Date.now() })
|
|
327
|
+
const digest = buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections })
|
|
324
328
|
await store.saveDigest(digest)
|
|
325
329
|
return digest
|
|
326
330
|
}
|
|
@@ -388,7 +392,7 @@ export function install(ctx, rawConfig) {
|
|
|
388
392
|
} catch (error) {
|
|
389
393
|
warn(`usage record failed for ${sessionId}: ${String(error)}`)
|
|
390
394
|
}
|
|
391
|
-
const digest = parseApiDigest(text, checkpoint, { model: api.model, usage: real, now: Date.now() })
|
|
395
|
+
const digest = parseApiDigest(text, checkpoint, { model: api.model, usage: real, now: Date.now(), sections: config.sections })
|
|
392
396
|
await store.saveDigest(digest)
|
|
393
397
|
store.dequeueJob(sessionId)
|
|
394
398
|
await store.persist()
|
|
@@ -442,7 +446,7 @@ export function install(ctx, rawConfig) {
|
|
|
442
446
|
continue
|
|
443
447
|
}
|
|
444
448
|
if (config.engine !== 'api') {
|
|
445
|
-
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now() }))
|
|
449
|
+
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections }))
|
|
446
450
|
store.dequeueJob(sessionId)
|
|
447
451
|
await store.persist()
|
|
448
452
|
results.push({ sessionId, ok: true, engine: 'rules' })
|
package/lib/digest.js
CHANGED
|
@@ -7,10 +7,18 @@
|
|
|
7
7
|
import { bullets, clip, lastParagraph, redactSecrets, section, withoutTrailingFence } from './text.js'
|
|
8
8
|
|
|
9
9
|
/** Bump when summary extraction rules change; startup backfill rebuilds stale rules digests. */
|
|
10
|
-
export const RULES_VERSION =
|
|
10
|
+
export const RULES_VERSION = 4
|
|
11
11
|
|
|
12
12
|
/** Defaults for the length filter (also mirrored in the Config schema). */
|
|
13
|
-
export const FILTER_DEFAULTS = Object.freeze({ minMessages:
|
|
13
|
+
export const FILTER_DEFAULTS = Object.freeze({ minMessages: 2, minTokens: 100 })
|
|
14
|
+
|
|
15
|
+
/** Every block a digest can contain; the settings page lets users pick. */
|
|
16
|
+
export const SECTION_IDS = Object.freeze(['goal', 'conclusion', 'decisions', 'files', 'progress', 'nextSteps', 'risks', 'keywords', 'questions'])
|
|
17
|
+
|
|
18
|
+
/** Blocks shown when the user has not chosen anything (no intermediate actions). */
|
|
19
|
+
export const DEFAULT_SECTIONS = Object.freeze(['goal', 'conclusion', 'decisions', 'nextSteps', 'risks'])
|
|
20
|
+
|
|
21
|
+
const STOPWORDS = new Set(['这个', '那个', '我们', '你们', '他们', '可以', '需要', '现在', '就是', '因为', '所以', '如果', '然后', '并且', '或者', '一个', '没有', '已经', '还是', '这样', '那样', '这里', '那里', '什么', '怎么', '如何', 'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'will', 'should', 'would', 'could'])
|
|
14
22
|
|
|
15
23
|
const CONCLUSION_HEADING = /(结论|总结|完成情况|conclusion|summary|outcome)/iu
|
|
16
24
|
const NEXT_HEADING = /(下一步|后续|待办|next step|next steps|todo|follow[- ]?up)/iu
|
|
@@ -141,6 +149,20 @@ export function buildDigest(checkpoint, options = {}) {
|
|
|
141
149
|
const goal = redactSecrets(typeof checkpoint.goal === 'string' && checkpoint.goal !== '' ? checkpoint.goal : '(未捕捉到目标)')
|
|
142
150
|
const conclusion = conclusionOf(assistantText) || (checkpoint.messageCount === 0 ? '(空会话)' : '(本次对话没有留下文字结论)')
|
|
143
151
|
|
|
152
|
+
const keywords = extractKeywords(`${checkpoint.title ?? ''} ${goal} ${conclusion}`)
|
|
153
|
+
const questions = []
|
|
154
|
+
for (const line of assistantText.split('\n')) {
|
|
155
|
+
const item = line.replace(/^[#>*\-\s`]+/u, '').trim()
|
|
156
|
+
if (item === '' || item.length > 160) continue
|
|
157
|
+
if (!/[??]|是否|要不要|待确认/u.test(item)) continue
|
|
158
|
+
const question = clip(redactSecrets(item), 140)
|
|
159
|
+
if (!questions.includes(question)) questions.push(question)
|
|
160
|
+
if (questions.length >= 4) break
|
|
161
|
+
}
|
|
162
|
+
const sections = Array.isArray(options.sections) && options.sections.length > 0
|
|
163
|
+
? options.sections.filter(id => SECTION_IDS.includes(id))
|
|
164
|
+
: [...DEFAULT_SECTIONS]
|
|
165
|
+
|
|
144
166
|
const digest = {
|
|
145
167
|
v: 1,
|
|
146
168
|
rulesVersion: RULES_VERSION,
|
|
@@ -161,66 +183,75 @@ export function buildDigest(checkpoint, options = {}) {
|
|
|
161
183
|
done,
|
|
162
184
|
nextSteps,
|
|
163
185
|
risks,
|
|
186
|
+
keywords,
|
|
187
|
+
questions,
|
|
188
|
+
sections,
|
|
164
189
|
params: { minMessages: FILTER_DEFAULTS.minMessages, minTokens: FILTER_DEFAULTS.minTokens },
|
|
165
190
|
}
|
|
166
191
|
digest.markdown = renderDigest(digest)
|
|
167
192
|
return digest
|
|
168
193
|
}
|
|
169
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Pick up to six salient terms for the keyword block.
|
|
197
|
+
* @param {string} text combined title/goal/conclusion.
|
|
198
|
+
* @returns {string[]}
|
|
199
|
+
*/
|
|
200
|
+
export function extractKeywords(text) {
|
|
201
|
+
const seen = new Set()
|
|
202
|
+
const out = []
|
|
203
|
+
for (const raw of String(text ?? '').split(/[^\p{L}\p{N}_\-+.]+/u)) {
|
|
204
|
+
const token = raw.trim()
|
|
205
|
+
if (token.length < 2 || token.length > 32) continue
|
|
206
|
+
const key = token.toLowerCase()
|
|
207
|
+
if (STOPWORDS.has(key) || seen.has(key)) continue
|
|
208
|
+
seen.add(key)
|
|
209
|
+
out.push(token)
|
|
210
|
+
if (out.length >= 6) break
|
|
211
|
+
}
|
|
212
|
+
return out
|
|
213
|
+
}
|
|
214
|
+
|
|
170
215
|
/**
|
|
171
216
|
* Render a digest as the Markdown block a user reads (and can paste).
|
|
217
|
+
* Only the sections selected in the config are rendered; intermediate tool
|
|
218
|
+
* actions are never part of the default set.
|
|
172
219
|
* @param {object} digest a digest record.
|
|
173
220
|
* @returns {string}
|
|
174
221
|
*/
|
|
175
222
|
export function renderDigest(digest) {
|
|
223
|
+
const enabled = Array.isArray(digest.sections) && digest.sections.length > 0
|
|
224
|
+
? digest.sections.filter(id => SECTION_IDS.includes(id))
|
|
225
|
+
: [...DEFAULT_SECTIONS]
|
|
226
|
+
const has = id => enabled.includes(id)
|
|
176
227
|
const lines = []
|
|
177
228
|
lines.push(`# 卷末 · ${digest.title ?? digest.sessionId}`)
|
|
178
229
|
lines.push('')
|
|
179
|
-
const meta = [
|
|
180
|
-
`会话 \`${digest.sessionId}\``,
|
|
181
|
-
`引擎 ${digest.engine}`,
|
|
182
|
-
`更新 ${new Date(digest.updatedAt).toISOString().replace('T', ' ').slice(0, 19)}`,
|
|
183
|
-
]
|
|
230
|
+
const meta = [digest.engine === 'api' ? 'API 摘要' : '本地规则', `更新 ${new Date(digest.updatedAt).toISOString().replace('T', ' ').slice(0, 16)}`]
|
|
184
231
|
if (digest.messageCount) meta.push(`${digest.messageCount} 条消息`)
|
|
185
232
|
lines.push(`> ${meta.join(' · ')}`)
|
|
186
233
|
lines.push('')
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
lines.push('## 结论')
|
|
192
|
-
lines.push('')
|
|
193
|
-
lines.push(digest.conclusion)
|
|
194
|
-
if (Array.isArray(digest.decisions) && digest.decisions.length > 0) {
|
|
195
|
-
lines.push('')
|
|
196
|
-
lines.push('## 决策')
|
|
197
|
-
lines.push('')
|
|
198
|
-
for (const item of digest.decisions) lines.push(`- ${item}`)
|
|
199
|
-
}
|
|
200
|
-
if (Array.isArray(digest.writes) && digest.writes.length > 0) {
|
|
201
|
-
lines.push('')
|
|
202
|
-
lines.push('## 涉及文件')
|
|
203
|
-
lines.push('')
|
|
204
|
-
for (const item of digest.writes) lines.push(`- ${item}`)
|
|
205
|
-
}
|
|
206
|
-
if (Array.isArray(digest.done) && digest.done.length > 0) {
|
|
207
|
-
lines.push('')
|
|
208
|
-
lines.push('## 已完成')
|
|
209
|
-
lines.push('')
|
|
210
|
-
for (const item of digest.done) lines.push(`- ${item}`)
|
|
211
|
-
}
|
|
212
|
-
if (digest.nextSteps.length > 0) {
|
|
213
|
-
lines.push('')
|
|
214
|
-
lines.push('## 下一步')
|
|
215
|
-
lines.push('')
|
|
216
|
-
for (const item of digest.nextSteps) lines.push(`- ${item}`)
|
|
217
|
-
}
|
|
218
|
-
if (digest.risks.length > 0) {
|
|
234
|
+
|
|
235
|
+
const block = (heading, body) => {
|
|
236
|
+
if (body === '' || body === undefined || body === null) return
|
|
237
|
+
lines.push(`## ${heading}`)
|
|
219
238
|
lines.push('')
|
|
220
|
-
|
|
239
|
+
if (Array.isArray(body)) {
|
|
240
|
+
for (const item of body) lines.push(`- ${item}`)
|
|
241
|
+
} else {
|
|
242
|
+
lines.push(body)
|
|
243
|
+
}
|
|
221
244
|
lines.push('')
|
|
222
|
-
for (const item of digest.risks) lines.push(`- ${item}`)
|
|
223
245
|
}
|
|
224
|
-
|
|
246
|
+
|
|
247
|
+
if (has('goal')) block('目标', digest.goal)
|
|
248
|
+
if (has('conclusion')) block('结论', digest.conclusion)
|
|
249
|
+
if (has('decisions')) block('决策', Array.isArray(digest.decisions) && digest.decisions.length > 0 ? digest.decisions : '')
|
|
250
|
+
if (has('files')) block('涉及文件', Array.isArray(digest.writes) && digest.writes.length > 0 ? digest.writes : '')
|
|
251
|
+
if (has('progress')) block('完成情况', Array.isArray(digest.done) && digest.done.length > 0 ? digest.done : '')
|
|
252
|
+
if (has('nextSteps')) block('下一步', Array.isArray(digest.nextSteps) && digest.nextSteps.length > 0 ? digest.nextSteps : '')
|
|
253
|
+
if (has('risks')) block('风险与注意', Array.isArray(digest.risks) && digest.risks.length > 0 ? digest.risks : '')
|
|
254
|
+
if (has('keywords')) block('关键词', Array.isArray(digest.keywords) && digest.keywords.length > 0 ? digest.keywords : '')
|
|
255
|
+
if (has('questions')) block('待确认问题', Array.isArray(digest.questions) && digest.questions.length > 0 ? digest.questions : '')
|
|
225
256
|
return `${lines.join('\n')}\n`
|
|
226
257
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-colophon",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Colophon(卷末)— keep a local, token-free conclusion digest for every conversation, so reopening an old session starts from its final state instead of its full history.",
|
|
5
5
|
"documentation": "README.md",
|
|
6
6
|
"license": "MIT",
|