dsh-share-html 0.3.1 → 0.4.0
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/lib/kernel.js +72 -20
- package/package.json +1 -1
package/lib/kernel.js
CHANGED
|
@@ -1737,6 +1737,36 @@ 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
|
+
/* ---------- \u8FC7\u7A0B\u5757\u5185\u7684\u6241\u5E73\u5185\u5BB9 ---------- */
|
|
1741
|
+
/* \u5DF2\u7ECF\u5728\u300C\u8FC7\u7A0B\u300D\u6298\u53E0\u91CC\u4E86\uFF0C\u5C31\u4E0D\u518D\u5957\u7B2C\u4E8C\u5C42 <details>\uFF1A
|
|
1742
|
+
\u5426\u5219\u8BFB\u4E00\u884C\u8F93\u51FA\u8981\u70B9\u4E09\u6B21\uFF08\u8F6E\u6B21 \u2192 \u8FC7\u7A0B \u2192 \u5DE5\u5177\uFF09\u3002 */
|
|
1743
|
+
.flat-block {
|
|
1744
|
+
margin: 6px 0;
|
|
1745
|
+
padding-left: 22px;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
.flat-head {
|
|
1749
|
+
display: flex;
|
|
1750
|
+
align-items: center;
|
|
1751
|
+
gap: 8px;
|
|
1752
|
+
font-size: 12px;
|
|
1753
|
+
line-height: 18px;
|
|
1754
|
+
color: var(--dsh-label-tertiary);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
.flat-head .sum-name {
|
|
1758
|
+
color: var(--dsh-label-secondary);
|
|
1759
|
+
font-family: var(--dsh-font-code);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
.flat-body {
|
|
1763
|
+
margin: 2px 0 0;
|
|
1764
|
+
overflow-wrap: anywhere;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
.flat-body > *:first-child { margin-top: 0; }
|
|
1768
|
+
.flat-body > *:last-child { margin-bottom: 0; }
|
|
1769
|
+
|
|
1740
1770
|
@media (hover: hover) {
|
|
1741
1771
|
details.process > summary:hover { color: var(--dsh-label-secondary); }
|
|
1742
1772
|
}
|
|
@@ -2081,15 +2111,20 @@ function renderHtml(model, meta = {}) {
|
|
|
2081
2111
|
body.push(renderUserMessage(turn.user));
|
|
2082
2112
|
}
|
|
2083
2113
|
const assistantBlocks = [];
|
|
2114
|
+
const stepBlocks = [];
|
|
2084
2115
|
const turnModels = [];
|
|
2085
|
-
|
|
2116
|
+
const lastIndex = turn.assistants.length - 1;
|
|
2117
|
+
for (const [i, msg] of turn.assistants.entries()) {
|
|
2086
2118
|
stats.messages += 1;
|
|
2087
2119
|
stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
|
|
2088
2120
|
if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
|
|
2089
|
-
|
|
2121
|
+
const rendered = renderAssistantMessage(msg, i !== lastIndex);
|
|
2122
|
+
if (!rendered) continue;
|
|
2123
|
+
if (i === lastIndex) assistantBlocks.push(rendered);
|
|
2124
|
+
else if (rendered.trim()) stepBlocks.push(rendered);
|
|
2090
2125
|
}
|
|
2091
|
-
if (assistantBlocks.length) {
|
|
2092
|
-
body.push(renderTurnArticle(turn, assistantBlocks, turnModels));
|
|
2126
|
+
if (assistantBlocks.length || stepBlocks.length) {
|
|
2127
|
+
body.push(renderTurnArticle(turn, stepBlocks, assistantBlocks, turnModels));
|
|
2093
2128
|
}
|
|
2094
2129
|
}
|
|
2095
2130
|
if (!body.length) {
|
|
@@ -2194,35 +2229,41 @@ function renderUserMessage(msg) {
|
|
|
2194
2229
|
${parts.join("\n")}
|
|
2195
2230
|
</article>`;
|
|
2196
2231
|
}
|
|
2197
|
-
function renderTurnArticle(turn,
|
|
2232
|
+
function renderTurnArticle(turn, stepBlocks, answerBlocks, models) {
|
|
2198
2233
|
const status = statusLabel(turn.status);
|
|
2199
2234
|
const duration = turn.durationMs !== void 0 ? formatDuration(turn.durationMs) : "";
|
|
2200
2235
|
const metaParts = [status, duration ? `\u7528\u65F6 ${duration}` : ""].filter(Boolean);
|
|
2201
2236
|
const metaHtml = metaParts.length ? `<span class="turn-meta">${esc(metaParts.join("\uFF0C"))}</span>` : "";
|
|
2202
2237
|
const modelHtml = models.length ? `<span class="msg-model">${models.map(esc).join(" \xB7 ")}</span>` : "";
|
|
2203
|
-
const
|
|
2204
|
-
|
|
2205
|
-
|
|
2238
|
+
const processHtml = stepBlocks.length ? renderDetails({
|
|
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");
|
|
2245
|
+
if (!metaHtml && !modelHtml) {
|
|
2206
2246
|
return `<article class="msg" data-role="assistant">
|
|
2207
|
-
${
|
|
2247
|
+
${inner}
|
|
2208
2248
|
</article>`;
|
|
2209
2249
|
}
|
|
2210
2250
|
return `<article class="msg" data-role="assistant">
|
|
2211
2251
|
<details class="turn" open>
|
|
2212
|
-
|
|
2213
|
-
|
|
2252
|
+
<summary class="turn-head">${metaHtml}${modelHtml}</summary>
|
|
2253
|
+
<div class="turn-body">
|
|
2254
|
+
${inner}
|
|
2214
2255
|
</div>
|
|
2215
2256
|
</details>
|
|
2216
2257
|
</article>`;
|
|
2217
2258
|
}
|
|
2218
|
-
function renderAssistantMessage(msg) {
|
|
2259
|
+
function renderAssistantMessage(msg, flat = false) {
|
|
2219
2260
|
const parts = [];
|
|
2220
2261
|
for (const block of msg.blocks) {
|
|
2221
|
-
parts.push(renderBlock(block));
|
|
2262
|
+
parts.push(renderBlock(block, flat));
|
|
2222
2263
|
}
|
|
2223
2264
|
return parts.filter(Boolean).join("\n");
|
|
2224
2265
|
}
|
|
2225
|
-
function renderBlock(block) {
|
|
2266
|
+
function renderBlock(block, flat = false) {
|
|
2226
2267
|
switch (block.kind) {
|
|
2227
2268
|
case "text":
|
|
2228
2269
|
return `<div class="md">${renderMarkdown(block.md)}</div>`;
|
|
@@ -2230,10 +2271,11 @@ function renderBlock(block) {
|
|
|
2230
2271
|
return renderDetails({
|
|
2231
2272
|
kind: "reasoning",
|
|
2232
2273
|
summary: "\u601D\u8003\u8FC7\u7A0B",
|
|
2233
|
-
body: `<div class="md">${renderMarkdown(block.text)}</div
|
|
2274
|
+
body: `<div class="md">${renderMarkdown(block.text)}</div>`,
|
|
2275
|
+
open: flat
|
|
2234
2276
|
});
|
|
2235
2277
|
case "tool":
|
|
2236
|
-
return renderTool(block);
|
|
2278
|
+
return renderTool(block, flat);
|
|
2237
2279
|
case "retrieval":
|
|
2238
2280
|
return renderRetrieval(block);
|
|
2239
2281
|
case "research":
|
|
@@ -2251,7 +2293,8 @@ function renderBlock(block) {
|
|
|
2251
2293
|
function renderDetails(input) {
|
|
2252
2294
|
const statusAttr = input.status ? ` data-status="${esc(input.status)}"` : "";
|
|
2253
2295
|
const nameHtml = input.name ? `<span class="sum-name">${esc(input.name)}</span>` : "";
|
|
2254
|
-
|
|
2296
|
+
const openAttr = input.open ? " open" : "";
|
|
2297
|
+
return `<details class="process" data-kind="${esc(input.kind)}"${openAttr}>
|
|
2255
2298
|
<summary><span class="sum-text">${esc(input.summary)}</span>${nameHtml}${statusDot(input.status)}</summary>
|
|
2256
2299
|
<div class="process-body">
|
|
2257
2300
|
${input.body}
|
|
@@ -2264,7 +2307,7 @@ function statusDot(status) {
|
|
|
2264
2307
|
if (status === "pending") return '<span class="sum-state" data-status="pending">\u672A\u5B8C\u6210</span>';
|
|
2265
2308
|
return "";
|
|
2266
2309
|
}
|
|
2267
|
-
function renderTool(block) {
|
|
2310
|
+
function renderTool(block, flat = false) {
|
|
2268
2311
|
const summaryText = toolSummary(block);
|
|
2269
2312
|
const body = [];
|
|
2270
2313
|
if (block.argsFields?.length) {
|
|
@@ -2286,8 +2329,17 @@ function renderTool(block) {
|
|
|
2286
2329
|
body.push('<div class="trunc-note">\u4F1A\u8BDD\u5BFC\u51FA\u65F6\u8BE5\u8C03\u7528\u5C1A\u672A\u8FD4\u56DE</div>');
|
|
2287
2330
|
}
|
|
2288
2331
|
const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
|
|
2332
|
+
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
|
+
if (flat) {
|
|
2334
|
+
return `<div class="flat-block" data-kind="tool" data-tool="${esc(block.name)}">
|
|
2335
|
+
<div class="flat-head">${head}</div>
|
|
2336
|
+
<div class="flat-body">
|
|
2337
|
+
${body.join("\n")}
|
|
2338
|
+
</div>
|
|
2339
|
+
</div>`;
|
|
2340
|
+
}
|
|
2289
2341
|
return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
|
|
2290
|
-
<summary
|
|
2342
|
+
<summary>${head}</summary>
|
|
2291
2343
|
<div class="process-body">
|
|
2292
2344
|
${body.join("\n")}
|
|
2293
2345
|
</div>
|
|
@@ -2448,7 +2500,7 @@ function filenameStamp(epochMs, timeZone) {
|
|
|
2448
2500
|
}
|
|
2449
2501
|
|
|
2450
2502
|
// src/host/index.ts
|
|
2451
|
-
var VERSION = "0.
|
|
2503
|
+
var VERSION = "0.4.0";
|
|
2452
2504
|
function exportSession(input) {
|
|
2453
2505
|
const preset = input.preset ?? "conversation";
|
|
2454
2506
|
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.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|