dsh-share-html 0.4.0 → 0.4.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 +24 -7
- package/lib/kernel.js +103 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,19 +85,36 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
|
|
|
85
85
|
> 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
|
|
86
86
|
> 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
|
|
87
87
|
|
|
88
|
-
###
|
|
88
|
+
### 轮次头与折叠
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
每轮的助手输出与 DSH 原会话结构一致:
|
|
91
91
|
|
|
92
92
|
```
|
|
93
|
-
已完成,用时 9分52秒 ⌄
|
|
93
|
+
已完成,用时 9分52秒 ⌄ ← 轮次头,默认展开
|
|
94
|
+
明白了:<details> 的容器边界搞错了… ← 正文,直接可见
|
|
95
|
+
▸ 调用 2 次工具 bash ← 工具调用,默认收起
|
|
96
|
+
根因找到了… ← 继续的正文,直接可见
|
|
97
|
+
▸ 调用 1 次工具 read
|
|
98
|
+
……
|
|
94
99
|
```
|
|
95
100
|
|
|
101
|
+
两层折叠,各管各的:
|
|
102
|
+
|
|
103
|
+
| 折叠项 | 默认 | 展开后 |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| **轮次头**(已完成,用时 X) | 展开 | 该轮的全部内容 |
|
|
106
|
+
| **调用 N 次工具** | 收起 | 每次调用的参数与结果 |
|
|
107
|
+
|
|
108
|
+
两条硬规则,都来自 DSH 的做法:
|
|
109
|
+
|
|
110
|
+
1. **助手回复永远不被折叠**。折叠的是过程,回复必须直接可见 ——
|
|
111
|
+
DSH 文档对它的几种展示模式都是这个约定("fold … while keeping every Assistant reply visible")。
|
|
112
|
+
收起轮次头是读者主动选择跳过这一轮,不是我们偷偷把回答藏起来。
|
|
113
|
+
2. **过程里不再套第三层**。同一段连续的工具调用聚合成一个「调用 N 次工具」,
|
|
114
|
+
展开就是参数和结果;不会出现「轮次 → 过程 → 工具」要点三次才看到一行输出。
|
|
115
|
+
|
|
96
116
|
- 状态来自 `turn/end` 的 `reason.kind`(已完成 / 已中止 / 失败 / 已取消)
|
|
97
|
-
-
|
|
98
|
-
- 点击头部可折叠整轮,箭头随状态旋转
|
|
99
|
-
- **默认展开**:导出的是一份要读的记录,不是要点开才知道内容的折叠板
|
|
100
|
-
- 没有 `turn/end` 的会话不显示这一行,也不会留空行
|
|
117
|
+
- 耗时是该轮从开始到结束的实际时长;没有 `turn/end` 的会话不显示轮次头
|
|
101
118
|
|
|
102
119
|
### 选择轮次
|
|
103
120
|
|
package/lib/kernel.js
CHANGED
|
@@ -1737,12 +1737,69 @@ details.turn > summary.turn-head:focus-visible {
|
|
|
1737
1737
|
.turn-body { margin: 2px 0 0; }
|
|
1738
1738
|
.turn-body > *:first-child { margin-top: 0; }
|
|
1739
1739
|
|
|
1740
|
-
/* ---------- \
|
|
1741
|
-
|
|
1742
|
-
|
|
1740
|
+
/* ---------- \u5DE5\u5177\u8C03\u7528\u7EC4\uFF08\u8C03\u7528 N \u6B21\u5DE5\u5177\uFF09 ---------- */
|
|
1741
|
+
|
|
1742
|
+
/* \u4E0E .process \u540C\u4E00\u5957\u6298\u53E0\u624B\u611F\uFF0C\u4F46\u6807\u9898\u662F\u5BBF\u4E3B\u90A3\u79CD"\u8C03\u7528 2 \u6B21\u5DE5\u5177"\u7684\u8BF4\u6CD5\u3002 */
|
|
1743
|
+
details.tool-group {
|
|
1744
|
+
margin: 6px 0;
|
|
1745
|
+
border-radius: var(--dsh-radius-sm);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
details.tool-group > summary {
|
|
1749
|
+
display: flex;
|
|
1750
|
+
align-items: center;
|
|
1751
|
+
gap: 8px;
|
|
1752
|
+
min-height: 26px;
|
|
1753
|
+
padding: 2px 0;
|
|
1754
|
+
cursor: pointer;
|
|
1755
|
+
list-style: none;
|
|
1756
|
+
font-size: 12px;
|
|
1757
|
+
line-height: 18px;
|
|
1758
|
+
color: var(--dsh-label-tertiary);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
details.tool-group > summary::-webkit-details-marker { display: none; }
|
|
1762
|
+
|
|
1763
|
+
details.tool-group > summary::after {
|
|
1764
|
+
content: "";
|
|
1765
|
+
flex: none;
|
|
1766
|
+
width: 6px;
|
|
1767
|
+
height: 6px;
|
|
1768
|
+
border-right: 1.5px solid currentColor;
|
|
1769
|
+
border-bottom: 1.5px solid currentColor;
|
|
1770
|
+
transform: rotate(-45deg);
|
|
1771
|
+
transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
details.tool-group[open] > summary::after { transform: rotate(45deg); }
|
|
1775
|
+
|
|
1776
|
+
details.tool-group > summary:focus-visible {
|
|
1777
|
+
outline: 1.5px solid var(--dsh-link);
|
|
1778
|
+
outline-offset: 2px;
|
|
1779
|
+
border-radius: var(--dsh-radius-sm);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
@media (hover: hover) {
|
|
1783
|
+
details.tool-group > summary:hover { color: var(--dsh-label-secondary); }
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
.tool-group .sum-names {
|
|
1787
|
+
color: var(--dsh-label-caption);
|
|
1788
|
+
font-family: var(--dsh-font-code);
|
|
1789
|
+
font-size: 11px;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
.tool-group-body {
|
|
1793
|
+
margin: 2px 0 4px 14px;
|
|
1794
|
+
padding-left: 10px;
|
|
1795
|
+
border-left: 1px solid var(--dsh-border-l2);
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/* ---------- \u5DE5\u5177\u8C03\u7528\u7684\u6241\u5E73\u5185\u5BB9 ---------- */
|
|
1799
|
+
/* \u5DF2\u7ECF\u5728\u300C\u8C03\u7528 N \u6B21\u5DE5\u5177\u300D\u91CC\u4E86\uFF0C\u5C31\u4E0D\u518D\u5957\u7B2C\u4E8C\u5C42 <details>\uFF1A
|
|
1800
|
+
\u5426\u5219\u8BFB\u4E00\u884C\u8F93\u51FA\u8981\u70B9\u4E24\u6B21\uFF08\u8F6E\u6B21 \u2192 \u5DE5\u5177\u7EC4 \u2192 \u5DE5\u5177\uFF09\u3002 */
|
|
1743
1801
|
.flat-block {
|
|
1744
1802
|
margin: 6px 0;
|
|
1745
|
-
padding-left: 22px;
|
|
1746
1803
|
}
|
|
1747
1804
|
|
|
1748
1805
|
.flat-head {
|
|
@@ -2110,21 +2167,17 @@ function renderHtml(model, meta = {}) {
|
|
|
2110
2167
|
stats.messages += 1;
|
|
2111
2168
|
body.push(renderUserMessage(turn.user));
|
|
2112
2169
|
}
|
|
2113
|
-
const
|
|
2114
|
-
const stepBlocks = [];
|
|
2170
|
+
const turnBlocks = [];
|
|
2115
2171
|
const turnModels = [];
|
|
2116
|
-
const
|
|
2117
|
-
for (const [i, msg] of turn.assistants.entries()) {
|
|
2172
|
+
for (const msg of turn.assistants) {
|
|
2118
2173
|
stats.messages += 1;
|
|
2119
2174
|
stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
|
|
2120
2175
|
if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
|
|
2121
|
-
const rendered = renderAssistantMessage(msg
|
|
2122
|
-
if (
|
|
2123
|
-
if (i === lastIndex) assistantBlocks.push(rendered);
|
|
2124
|
-
else if (rendered.trim()) stepBlocks.push(rendered);
|
|
2176
|
+
const rendered = renderAssistantMessage(msg);
|
|
2177
|
+
if (rendered.trim()) turnBlocks.push(rendered);
|
|
2125
2178
|
}
|
|
2126
|
-
if (
|
|
2127
|
-
body.push(renderTurnArticle(turn,
|
|
2179
|
+
if (turnBlocks.length) {
|
|
2180
|
+
body.push(renderTurnArticle(turn, turnBlocks, turnModels));
|
|
2128
2181
|
}
|
|
2129
2182
|
}
|
|
2130
2183
|
if (!body.length) {
|
|
@@ -2229,19 +2282,13 @@ function renderUserMessage(msg) {
|
|
|
2229
2282
|
${parts.join("\n")}
|
|
2230
2283
|
</article>`;
|
|
2231
2284
|
}
|
|
2232
|
-
function renderTurnArticle(turn,
|
|
2285
|
+
function renderTurnArticle(turn, blocks, models) {
|
|
2233
2286
|
const status = statusLabel(turn.status);
|
|
2234
2287
|
const duration = turn.durationMs !== void 0 ? formatDuration(turn.durationMs) : "";
|
|
2235
2288
|
const metaParts = [status, duration ? `\u7528\u65F6 ${duration}` : ""].filter(Boolean);
|
|
2236
2289
|
const metaHtml = metaParts.length ? `<span class="turn-meta">${esc(metaParts.join("\uFF0C"))}</span>` : "";
|
|
2237
2290
|
const modelHtml = models.length ? `<span class="msg-model">${models.map(esc).join(" \xB7 ")}</span>` : "";
|
|
2238
|
-
const
|
|
2239
|
-
kind: "steps",
|
|
2240
|
-
summary: `\u8FC7\u7A0B\uFF08${stepBlocks.length} \u6B65\uFF09`,
|
|
2241
|
-
body: stepBlocks.join("\n"),
|
|
2242
|
-
open: false
|
|
2243
|
-
}) : "";
|
|
2244
|
-
const inner = [processHtml, ...answerBlocks].filter(Boolean).join("\n");
|
|
2291
|
+
const inner = blocks.join("\n");
|
|
2245
2292
|
if (!metaHtml && !modelHtml) {
|
|
2246
2293
|
return `<article class="msg" data-role="assistant">
|
|
2247
2294
|
${inner}
|
|
@@ -2256,14 +2303,40 @@ ${inner}
|
|
|
2256
2303
|
</details>
|
|
2257
2304
|
</article>`;
|
|
2258
2305
|
}
|
|
2259
|
-
function renderAssistantMessage(msg
|
|
2306
|
+
function renderAssistantMessage(msg) {
|
|
2260
2307
|
const parts = [];
|
|
2308
|
+
let pendingTools = [];
|
|
2309
|
+
const flushTools = () => {
|
|
2310
|
+
if (!pendingTools.length) return;
|
|
2311
|
+
parts.push(renderToolGroup(pendingTools));
|
|
2312
|
+
pendingTools = [];
|
|
2313
|
+
};
|
|
2261
2314
|
for (const block of msg.blocks) {
|
|
2262
|
-
|
|
2315
|
+
if (block.kind === "tool") {
|
|
2316
|
+
pendingTools.push(block);
|
|
2317
|
+
continue;
|
|
2318
|
+
}
|
|
2319
|
+
flushTools();
|
|
2320
|
+
parts.push(renderBlock(block));
|
|
2263
2321
|
}
|
|
2322
|
+
flushTools();
|
|
2264
2323
|
return parts.filter(Boolean).join("\n");
|
|
2265
2324
|
}
|
|
2266
|
-
function
|
|
2325
|
+
function renderToolGroup(tools) {
|
|
2326
|
+
const n = tools.length;
|
|
2327
|
+
const failed = tools.filter((t) => t.status === "error").length;
|
|
2328
|
+
const label = n === 1 ? "\u8C03\u7528 1 \u6B21\u5DE5\u5177" : `\u8C03\u7528 ${n} \u6B21\u5DE5\u5177`;
|
|
2329
|
+
const names = [...new Set(tools.map((t) => t.name))].join(", ");
|
|
2330
|
+
const failBadge = failed ? `<span class="sum-state" data-status="error">${failed} \u4E2A\u5931\u8D25</span>` : "";
|
|
2331
|
+
const body = tools.map((t) => renderTool(t, true)).join("\n");
|
|
2332
|
+
return `<details class="tool-group" data-kind="tool-group">
|
|
2333
|
+
<summary><span class="sum-text">${esc(label)}</span><span class="sum-names">${esc(names)}</span>${failBadge}</summary>
|
|
2334
|
+
<div class="tool-group-body">
|
|
2335
|
+
${body}
|
|
2336
|
+
</div>
|
|
2337
|
+
</details>`;
|
|
2338
|
+
}
|
|
2339
|
+
function renderBlock(block) {
|
|
2267
2340
|
switch (block.kind) {
|
|
2268
2341
|
case "text":
|
|
2269
2342
|
return `<div class="md">${renderMarkdown(block.md)}</div>`;
|
|
@@ -2271,11 +2344,10 @@ function renderBlock(block, flat = false) {
|
|
|
2271
2344
|
return renderDetails({
|
|
2272
2345
|
kind: "reasoning",
|
|
2273
2346
|
summary: "\u601D\u8003\u8FC7\u7A0B",
|
|
2274
|
-
body: `<div class="md">${renderMarkdown(block.text)}</div
|
|
2275
|
-
open: flat
|
|
2347
|
+
body: `<div class="md">${renderMarkdown(block.text)}</div>`
|
|
2276
2348
|
});
|
|
2277
2349
|
case "tool":
|
|
2278
|
-
return renderTool(block
|
|
2350
|
+
return renderTool(block);
|
|
2279
2351
|
case "retrieval":
|
|
2280
2352
|
return renderRetrieval(block);
|
|
2281
2353
|
case "research":
|
|
@@ -2307,7 +2379,7 @@ function statusDot(status) {
|
|
|
2307
2379
|
if (status === "pending") return '<span class="sum-state" data-status="pending">\u672A\u5B8C\u6210</span>';
|
|
2308
2380
|
return "";
|
|
2309
2381
|
}
|
|
2310
|
-
function renderTool(block
|
|
2382
|
+
function renderTool(block) {
|
|
2311
2383
|
const summaryText = toolSummary(block);
|
|
2312
2384
|
const body = [];
|
|
2313
2385
|
if (block.argsFields?.length) {
|
|
@@ -2330,20 +2402,12 @@ function renderTool(block, flat = false) {
|
|
|
2330
2402
|
}
|
|
2331
2403
|
const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
|
|
2332
2404
|
const head = `<span class="sum-name">${esc(block.name)}</span><span class="sum-dot"></span><span class="sum-text">${esc(summaryText)}</span>${stateText ? `<span class="sum-state" data-status="${esc(block.status)}">${esc(stateText)}</span>` : ""}`;
|
|
2333
|
-
|
|
2334
|
-
return `<div class="flat-block" data-kind="tool" data-tool="${esc(block.name)}">
|
|
2405
|
+
return `<div class="flat-block" data-kind="tool" data-tool="${esc(block.name)}">
|
|
2335
2406
|
<div class="flat-head">${head}</div>
|
|
2336
2407
|
<div class="flat-body">
|
|
2337
2408
|
${body.join("\n")}
|
|
2338
2409
|
</div>
|
|
2339
2410
|
</div>`;
|
|
2340
|
-
}
|
|
2341
|
-
return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
|
|
2342
|
-
<summary>${head}</summary>
|
|
2343
|
-
<div class="process-body">
|
|
2344
|
-
${body.join("\n")}
|
|
2345
|
-
</div>
|
|
2346
|
-
</details>`;
|
|
2347
2411
|
}
|
|
2348
2412
|
function toolSummary(block) {
|
|
2349
2413
|
const fields = block.argsFields ?? [];
|
|
@@ -2500,7 +2564,7 @@ function filenameStamp(epochMs, timeZone) {
|
|
|
2500
2564
|
}
|
|
2501
2565
|
|
|
2502
2566
|
// src/host/index.ts
|
|
2503
|
-
var VERSION = "0.4.
|
|
2567
|
+
var VERSION = "0.4.1";
|
|
2504
2568
|
function exportSession(input) {
|
|
2505
2569
|
const preset = input.preset ?? "conversation";
|
|
2506
2570
|
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.4.
|
|
3
|
+
"version": "0.4.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",
|