dsh-share-html 0.2.1 → 0.3.1

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 CHANGED
@@ -52,10 +52,53 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
52
52
  | **过程** | 再加思考、工具调用、检索结果 | 展示推理过程 |
53
53
  | **完整** | 再加工具结果全文、附件、模型信息 | 完整存档、复盘 |
54
54
 
55
- 三档严格递增。档位只是起点 —— 下面的开关(思考过程 / 检索结果 / 工具调用 / 工具结果 / 附件 / 深度研究 / 模型信息)每一项都能单独开关。
55
+ 三档严格递增。档位只是起点 —— 下面的开关(思考过程 / 工具调用 / 工具结果 / 附件 / 模型信息)每一项都能单独开关。
56
56
 
57
57
  **手动改过任一开关后,档位会标为「自定义」**,并且不再高亮任何一档,这样就不会出现「明明改了,顶上还显示对话」的错觉。再点任一档位即恢复该档默认。
58
58
 
59
+ ### 每个开关控制什么
60
+
61
+ | 开关 | 关闭时 | 打开时 |
62
+ |---|---|---|
63
+ | **思考过程** | 完全看不到模型推理 | 折叠的「思考过程」块,点开可见推理原文 |
64
+ | **工具调用** | 整段工具交互消失 | 折叠的「工具名 + 参数摘要」 |
65
+ | **工具结果** | 只留一行摘要(`共 3 行 / 52 字符`) | 结果正文全文 |
66
+ | **附件** | 不显示文件条目 | 文件名 + 类型 + 大小(不含内容)|
67
+ | **模型信息** | 轮次头只显示状态与耗时 | 轮次头多一个模型名 |
68
+
69
+ > **关于「检索结果」和「深度研究」**:这两个开关曾经存在,v0.3.1 起已从界面上移除。
70
+ > 它们的渲染与裁剪逻辑都已写好,但 DSH 的事件流里没有对应的结构化事件 ——
71
+ > 检索结果目前表现为普通的工具结果,深研过程也没有独立事件(DESIGN 记为待确认项 O2)。
72
+ > 摆一个拨动后毫无变化的开关,比不摆更让人困惑,所以先收起;
73
+ > 契约层仍然接受这两个字段(老客户端传过来不会报错),等 DSH 补上事件形态后加回界面即可。
74
+
75
+ ### 想看三档的实际差别
76
+
77
+ 打开 [示例对比页](docs/example-compare.html):同一段会话(排查订单服务超时)用三档各导一次,并排展示。
78
+
79
+ 也可以单独打开:
80
+
81
+ - [对话档](docs/example-conversation.html) —— 只有两轮问答
82
+ - [过程档](docs/example-process.html) —— 多出思考、工具调用、附件;工具结果只剩一行摘要
83
+ - [完整档](docs/example-full.html) —— 工具结果全文,轮次头带模型名
84
+
85
+ > 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
86
+ > 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
87
+
88
+ ### 轮次头
89
+
90
+ 每轮的助手输出带一个可折叠的头,与 DSH 原会话一致:
91
+
92
+ ```
93
+ 已完成,用时 9分52秒 ⌄
94
+ ```
95
+
96
+ - 状态来自 `turn/end` 的 `reason.kind`(已完成 / 已中止 / 失败 / 已取消)
97
+ - 耗时是该轮从开始到结束的实际时长
98
+ - 点击头部可折叠整轮,箭头随状态旋转
99
+ - **默认展开**:导出的是一份要读的记录,不是要点开才知道内容的折叠板
100
+ - 没有 `turn/end` 的会话不显示这一行,也不会留空行
101
+
59
102
  ### 选择轮次
60
103
 
61
104
  会话很长时,可以只导出其中几轮。展开「导出轮次」后按轮勾选:
package/lib/client.js CHANGED
@@ -305,13 +305,22 @@ window.__ModuleLoader__.load({
305
305
  { value: 'full', label: '完整', hint: '加上工具结果全文、文件与模型信息' },
306
306
  ]
307
307
 
308
+ // 界面上真正露出来的开关。
309
+ //
310
+ // 这里故意不含 retrieval / deepResearch:这两个块的渲染与裁剪都写好了,
311
+ // 但 DSH 的事件流里没有对应事件(检索结果目前就是普通工具结果,深研也没有
312
+ // 独立事件),所以拨动它们永远不会有可见变化。摆一个不生效的开关比不摆更糟。
313
+ // 契约层仍然接受这两个字段(见 contract.ts 的 INCLUDE_KEYS),因此老客户端
314
+ // 传过来不会报错;等 DSH 补上事件形态,把键加回这个对象即可。
315
+ var INCLUDE_ORDER = [
316
+ 'reasoning', 'toolCalls', 'toolResults', 'files', 'modelMeta',
317
+ ]
318
+
308
319
  var INCLUDE_LABELS = {
309
320
  reasoning: { label: '思考过程', hint: '模型的推理内容' },
310
- retrieval: { label: '检索结果', hint: '搜索结果条目' },
311
321
  toolCalls: { label: '工具调用', hint: '工具名与参数' },
312
322
  toolResults: { label: '工具结果', hint: '结果正文(关掉只留一行摘要)' },
313
323
  files: { label: '附件', hint: '只显示文件名与类型,不含内容' },
314
- deepResearch: { label: '深度研究', hint: '深研过程折叠展示' },
315
324
  modelMeta: { label: '模型信息', hint: '模型名与耗时' },
316
325
  }
317
326
 
@@ -648,7 +657,7 @@ window.__ModuleLoader__.load({
648
657
  ]),
649
658
 
650
659
  h('div', { key: 'i', style: { display: 'flex', flexDirection: 'column', gap: 2 } },
651
- Object.keys(INCLUDE_LABELS).map(function (key) {
660
+ INCLUDE_ORDER.map(function (key) {
652
661
  return h(Switch, {
653
662
  key: key,
654
663
  label: INCLUDE_LABELS[key].label,
package/lib/kernel.js CHANGED
@@ -30,10 +30,12 @@ function project(events, options = {}) {
30
30
  let lastModel;
31
31
  const pendingCalls = /* @__PURE__ */ new Map();
32
32
  const callOwner = /* @__PURE__ */ new Map();
33
- const openTurn = (user) => {
33
+ const turnStartedAt = /* @__PURE__ */ new Map();
34
+ const openTurn = (user, at) => {
34
35
  const turn = { index: turns.length + 1, user, assistants: [] };
35
36
  turns.push(turn);
36
37
  current = turn;
38
+ if (at !== void 0) turnStartedAt.set(turn.index, at);
37
39
  return turn;
38
40
  };
39
41
  const ensureTurn = () => current ?? openTurn(null);
@@ -82,7 +84,7 @@ function project(events, options = {}) {
82
84
  }
83
85
  const user = projectUserMessage(msg, at, dropped);
84
86
  if (!user) break;
85
- openTurn(user);
87
+ openTurn(user, at);
86
88
  clearStepSlots();
87
89
  break;
88
90
  }
@@ -133,7 +135,21 @@ function project(events, options = {}) {
133
135
  break;
134
136
  }
135
137
  // ---- 轮次与步骤边界(只影响归并) -----------------------------------
138
+ case "turn/start": {
139
+ if (!current) openTurn(null, at);
140
+ else if (at !== void 0 && !turnStartedAt.has(current.index)) turnStartedAt.set(current.index, at);
141
+ break;
142
+ }
136
143
  case "turn/end": {
144
+ if (current) {
145
+ const reason = asRecord(data.reason);
146
+ const kind = asString(reason?.kind);
147
+ if (kind) current.status = kind;
148
+ const startedAt = turnStartedAt.get(current.index);
149
+ if (startedAt !== void 0 && at !== void 0 && at >= startedAt) {
150
+ current.durationMs = at - startedAt;
151
+ }
152
+ }
137
153
  current = null;
138
154
  clearStepSlots();
139
155
  break;
@@ -1669,6 +1685,58 @@ details.process > summary::after {
1669
1685
 
1670
1686
  details.process[open] > summary::after { transform: rotate(45deg); }
1671
1687
 
1688
+ /* ---------- \u8F6E\u6B21\u5934\uFF08\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 9\u520652\u79D2\uFF09 ---------- */
1689
+
1690
+ /* \u4E0E .process \u540C\u4E00\u5957\u6298\u53E0\u624B\u611F\uFF1A\u540C\u4E00\u4E2A\u7BAD\u5934\u3001\u540C\u4E00\u5904\u5BF9\u9F50\u3001\u540C\u6837\u53EA\u5728\u60AC\u505C/tab \u65F6\u56DE\u5E94\u3002 */
1691
+ details.turn {
1692
+ margin: 2px 0;
1693
+ }
1694
+
1695
+ details.turn > summary.turn-head {
1696
+ display: flex;
1697
+ align-items: center;
1698
+ gap: 10px;
1699
+ min-height: 28px;
1700
+ padding: 2px 0;
1701
+ cursor: pointer;
1702
+ list-style: none;
1703
+ color: var(--dsh-label-tertiary);
1704
+ font-size: 12px;
1705
+ line-height: 18px;
1706
+ }
1707
+
1708
+ details.turn > summary.turn-head::-webkit-details-marker { display: none; }
1709
+
1710
+ details.turn > summary.turn-head::after {
1711
+ content: "";
1712
+ flex: none;
1713
+ width: 6px;
1714
+ height: 6px;
1715
+ border-right: 1.5px solid currentColor;
1716
+ border-bottom: 1.5px solid currentColor;
1717
+ transform: rotate(-45deg);
1718
+ transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
1719
+ }
1720
+
1721
+ details.turn[open] > summary.turn-head::after { transform: rotate(45deg); }
1722
+
1723
+ .turn-head .turn-meta { font-variant-numeric: tabular-nums; }
1724
+ .turn-head .msg-model { color: var(--dsh-label-caption); }
1725
+
1726
+ details.turn > summary.turn-head:focus-visible {
1727
+ outline: 1.5px solid var(--dsh-link);
1728
+ outline-offset: 2px;
1729
+ border-radius: var(--dsh-radius-sm);
1730
+ }
1731
+
1732
+ @media (hover: hover) {
1733
+ details.turn > summary.turn-head:hover { color: var(--dsh-label-secondary); }
1734
+ }
1735
+
1736
+ /* \u5C55\u5F00\u540E\u6B63\u6587\u4E0E\u5934\u90E8\u5DE6\u8FB9\u7F18\u5BF9\u9F50\uFF0C\u4E0D\u989D\u5916\u7F29\u8FDB\uFF08\u8FD9\u4E00\u5C42\u4E0D\u662F"\u8FC7\u7A0B"\u7684\u5B50\u9879\uFF09 */
1737
+ .turn-body { margin: 2px 0 0; }
1738
+ .turn-body > *:first-child { margin-top: 0; }
1739
+
1672
1740
  @media (hover: hover) {
1673
1741
  details.process > summary:hover { color: var(--dsh-label-secondary); }
1674
1742
  }
@@ -2021,11 +2089,7 @@ function renderHtml(model, meta = {}) {
2021
2089
  assistantBlocks.push(renderAssistantMessage(msg));
2022
2090
  }
2023
2091
  if (assistantBlocks.length) {
2024
- const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
2025
- ` : "";
2026
- body.push(`<article class="msg" data-role="assistant">
2027
- ${head}${assistantBlocks.join("\n")}
2028
- </article>`);
2092
+ body.push(renderTurnArticle(turn, assistantBlocks, turnModels));
2029
2093
  }
2030
2094
  }
2031
2095
  if (!body.length) {
@@ -2130,6 +2194,27 @@ function renderUserMessage(msg) {
2130
2194
  ${parts.join("\n")}
2131
2195
  </article>`;
2132
2196
  }
2197
+ function renderTurnArticle(turn, blocks, models) {
2198
+ const status = statusLabel(turn.status);
2199
+ const duration = turn.durationMs !== void 0 ? formatDuration(turn.durationMs) : "";
2200
+ const metaParts = [status, duration ? `\u7528\u65F6 ${duration}` : ""].filter(Boolean);
2201
+ const metaHtml = metaParts.length ? `<span class="turn-meta">${esc(metaParts.join("\uFF0C"))}</span>` : "";
2202
+ const modelHtml = models.length ? `<span class="msg-model">${models.map(esc).join(" \xB7 ")}</span>` : "";
2203
+ const head = metaHtml || modelHtml ? `<summary class="turn-head">${metaHtml}${modelHtml}</summary>
2204
+ ` : "";
2205
+ if (!head) {
2206
+ return `<article class="msg" data-role="assistant">
2207
+ ${blocks.join("\n")}
2208
+ </article>`;
2209
+ }
2210
+ return `<article class="msg" data-role="assistant">
2211
+ <details class="turn" open>
2212
+ ${head}<div class="turn-body">
2213
+ ${blocks.join("\n")}
2214
+ </div>
2215
+ </details>
2216
+ </article>`;
2217
+ }
2133
2218
  function renderAssistantMessage(msg) {
2134
2219
  const parts = [];
2135
2220
  for (const block of msg.blocks) {
@@ -2266,6 +2351,33 @@ function formatBytes(bytes) {
2266
2351
  }
2267
2352
  return `${value >= 10 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
2268
2353
  }
2354
+ function formatDuration(ms) {
2355
+ if (!Number.isFinite(ms) || ms < 0) return "";
2356
+ const totalSeconds = Math.floor(ms / 1e3);
2357
+ if (totalSeconds < 1) return "\u4E0D\u8DB31\u79D2";
2358
+ const hours = Math.floor(totalSeconds / 3600);
2359
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
2360
+ const seconds = totalSeconds % 60;
2361
+ if (hours > 0) return `${hours}\u5C0F\u65F6${minutes}\u5206${seconds}\u79D2`;
2362
+ if (minutes > 0) return `${minutes}\u5206${seconds}\u79D2`;
2363
+ return `${seconds}\u79D2`;
2364
+ }
2365
+ function statusLabel(status) {
2366
+ switch (status) {
2367
+ case "completed":
2368
+ return "\u5DF2\u5B8C\u6210";
2369
+ case "aborted":
2370
+ return "\u5DF2\u4E2D\u6B62";
2371
+ case "failed":
2372
+ return "\u5931\u8D25";
2373
+ case "cancelled":
2374
+ return "\u5DF2\u53D6\u6D88";
2375
+ case void 0:
2376
+ return "";
2377
+ default:
2378
+ return status;
2379
+ }
2380
+ }
2269
2381
  function presetLabel(preset) {
2270
2382
  switch (preset) {
2271
2383
  case "conversation":
@@ -2336,7 +2448,7 @@ function filenameStamp(epochMs, timeZone) {
2336
2448
  }
2337
2449
 
2338
2450
  // src/host/index.ts
2339
- var VERSION = "0.2.1";
2451
+ var VERSION = "0.3.1";
2340
2452
  function exportSession(input) {
2341
2453
  const preset = input.preset ?? "conversation";
2342
2454
  const opts = shareOptions(preset, input.options ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-share-html",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Export a DSH session as one self-contained, offline HTML file that looks like the original conversation: three detail presets, per-block switches, built-in redaction, zero scripts and zero external requests.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",