dsh-share-html 0.5.1 → 0.7.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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  // src/host/model.ts
6
6
  function emptyDropped() {
7
- return { systemMessages: 0, injectedUserContext: 0, attachmentBytes: 0, unknownEvents: 0 };
7
+ return { systemMessages: 0, injectedUserContext: 0, attachmentBytes: 0, unknownEvents: 0, pendingToolCalls: 0 };
8
8
  }
9
9
 
10
10
  // src/host/events.ts
@@ -30,8 +30,15 @@ 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) => {
34
- const turn = { index: turns.length + 1, user, assistants: [] };
33
+ const openTurn = (user, at) => {
34
+ const turn = {
35
+ index: turns.length + 1,
36
+ user,
37
+ assistants: [],
38
+ // 默认 open:只有真的收到 turn/end 才算结束
39
+ status: "open"
40
+ };
41
+ if (at !== void 0) turn.startedAt = at;
35
42
  turns.push(turn);
36
43
  current = turn;
37
44
  return turn;
@@ -44,7 +51,7 @@ function project(events, options = {}) {
44
51
  const existing = assistantSlot.get(key);
45
52
  if (existing) return existing;
46
53
  const turn = ensureTurn();
47
- const msg = { id: `a-${turnNo}-${stepNo}-${turn.assistants.length}`, role: "assistant", blocks: [] };
54
+ const msg = { id: `a-${turnNo}-${stepNo}-${turn.assistants.length}`, role: "assistant", blocks: [], step: stepNo };
48
55
  if (at !== void 0) msg.at = at;
49
56
  turn.assistants.push(msg);
50
57
  assistantSlot.set(key, msg);
@@ -82,7 +89,7 @@ function project(events, options = {}) {
82
89
  }
83
90
  const user = projectUserMessage(msg, at, dropped);
84
91
  if (!user) break;
85
- openTurn(user);
92
+ openTurn(user, at);
86
93
  clearStepSlots();
87
94
  break;
88
95
  }
@@ -111,6 +118,10 @@ function project(events, options = {}) {
111
118
  if (argsText !== void 0) block.args = argsText;
112
119
  const fields = argsToFields(rawArgs);
113
120
  if (fields.length) block.argsFields = fields;
121
+ if (name === "ask_user_question" || name === "request_user_input") {
122
+ const questions = parseAskedQuestions(rawArgs);
123
+ if (questions.length) block.questions = questions;
124
+ }
114
125
  owner.blocks.push(block);
115
126
  if (callId) {
116
127
  pendingCalls.set(callId, block);
@@ -130,10 +141,26 @@ function project(events, options = {}) {
130
141
  const text = partsToText(msg.content);
131
142
  const isError = msg.isError === true || asRecord(data)?.isError === true;
132
143
  applyResult(block, text, isError, options.maxToolResultChars);
144
+ const resultImages = extractImages(msg.content);
145
+ if (resultImages.length) block.resultImages = resultImages;
146
+ if (block.questions?.length) {
147
+ const answers = parseAskedAnswers(text);
148
+ if (answers.length) block.answers = answers;
149
+ }
150
+ break;
151
+ }
152
+ // ---- 轮次与步骤边界 -----------------------------------------------
153
+ case "turn/start": {
154
+ if (current !== null && current.startedAt === void 0 && at !== void 0) current.startedAt = at;
133
155
  break;
134
156
  }
135
- // ---- 轮次与步骤边界(只影响归并) -----------------------------------
136
157
  case "turn/end": {
158
+ if (current !== null) {
159
+ current.status = "closed";
160
+ if (at !== void 0) current.endedAt = at;
161
+ const reasonKind = asString(asRecord(data.reason)?.kind);
162
+ current.endReason = reasonKind === "aborted" || reasonKind === "interrupted" || reasonKind === "error" ? reasonKind : "completed";
163
+ }
137
164
  current = null;
138
165
  clearStepSlots();
139
166
  break;
@@ -157,6 +184,30 @@ function project(events, options = {}) {
157
184
  }
158
185
  break;
159
186
  }
187
+ // ---- 交付文件卡片 -----------------------------------------------
188
+ // AI 生成/修改完文件后主动交付的东西。DSH 在轮末渲染成文件卡片,
189
+ // 带一句面向读者的说明。旧实现完全没处理这个事件,所以产出的文件不显示。
190
+ case "deliverables/presented": {
191
+ const list = Array.isArray(data.files) ? data.files : [];
192
+ const files = list.map((item) => {
193
+ const rec = asRecord(item);
194
+ const path = asString(rec?.path);
195
+ if (!path) return null;
196
+ const description = asString(rec?.description);
197
+ const file = { path };
198
+ if (description && description.trim()) file.description = description.trim();
199
+ return file;
200
+ }).filter((f) => f !== null);
201
+ if (!files.length) break;
202
+ const turn = current;
203
+ if (!turn) break;
204
+ turn.assistants.push({
205
+ id: `deliverables-${turn.index}-${raw.seq ?? 0}`,
206
+ role: "assistant",
207
+ blocks: [{ kind: "deliverables", files }]
208
+ });
209
+ break;
210
+ }
160
211
  case "step/end":
161
212
  break;
162
213
  default: {
@@ -164,6 +215,64 @@ function project(events, options = {}) {
164
215
  }
165
216
  }
166
217
  }
218
+ for (const turn of turns) {
219
+ for (let i = 0; i < turn.assistants.length; i += 1) {
220
+ const msg = turn.assistants[i];
221
+ if (!msg) continue;
222
+ const kept = msg.blocks.filter((b) => !(b.kind === "tool" && b.status === "pending" && b.questions === void 0));
223
+ if (kept.length === msg.blocks.length) continue;
224
+ dropped.pendingToolCalls += msg.blocks.length - kept.length;
225
+ turn.assistants[i] = { ...msg, blocks: kept };
226
+ }
227
+ }
228
+ for (const turn of turns) {
229
+ turn.answerStep = latestAnswerStep(turn);
230
+ }
231
+ const rawImages = options.images;
232
+ const imageMap = rawImages instanceof Map ? rawImages : void 0;
233
+ const lookup = (ref) => ref === void 0 ? void 0 : imageMap?.get(ref.attachmentId);
234
+ const rawDeliverable = options.deliverableImages;
235
+ const deliverableMap = rawDeliverable instanceof Map ? rawDeliverable : void 0;
236
+ for (const turn of turns) {
237
+ if (turn.user) {
238
+ const userImages = [];
239
+ const keptBlocks = [];
240
+ for (const block of turn.user.blocks) {
241
+ if (block.kind !== "files") {
242
+ keptBlocks.push(block);
243
+ continue;
244
+ }
245
+ const kept = [];
246
+ for (const f of block.files) {
247
+ const img = lookup(f.image);
248
+ if (img) userImages.push({ ...img, ...f.name ? { name: f.name } : {} });
249
+ else kept.push(f);
250
+ }
251
+ if (kept.length) keptBlocks.push({ kind: "files", files: kept });
252
+ }
253
+ if (userImages.length) keptBlocks.push({ kind: "images", images: userImages });
254
+ turn.user.blocks = keptBlocks;
255
+ }
256
+ for (const msg of turn.assistants) {
257
+ for (const block of msg.blocks) {
258
+ if (block.kind === "tool" && block.resultImages?.length) {
259
+ const imgs = block.resultImages.map(lookup).filter((i) => i !== void 0);
260
+ if (imgs.length) block.resultImageData = imgs;
261
+ }
262
+ if (block.kind === "deliverables" && deliverableMap) {
263
+ for (const file of block.files) {
264
+ const img = deliverableMap.get(file.path);
265
+ if (img) file.image = img;
266
+ }
267
+ }
268
+ if (block.kind === "images") {
269
+ const refs = block.imageRefs ?? [];
270
+ const imgs = refs.map(lookup).filter((i) => i !== void 0);
271
+ if (imgs.length) block.images = imgs;
272
+ }
273
+ }
274
+ }
275
+ }
167
276
  const model = {
168
277
  id: sessionId ?? "",
169
278
  title: options.title?.trim() || sessionTitle || DEFAULT_TITLE,
@@ -197,6 +306,8 @@ function projectUserMessage(msg, at, dropped) {
197
306
  };
198
307
  const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
199
308
  if (bytes !== void 0) meta.bytes = bytes;
309
+ const image = asImageRef(a);
310
+ if (image) meta.image = image;
200
311
  files.push(meta);
201
312
  break;
202
313
  }
@@ -250,6 +361,11 @@ function collectAssistantBlocks(msg, target, dropped) {
250
361
  break;
251
362
  }
252
363
  case "image": {
364
+ const a = asRecord(p.attachment);
365
+ const image = asImageRef(a);
366
+ if (image) {
367
+ target.blocks.push({ kind: "images", images: [], imageRefs: [image] });
368
+ }
253
369
  dropped.attachmentBytes += 1;
254
370
  break;
255
371
  }
@@ -284,6 +400,34 @@ function applyResult(block, text, isError, maxChars) {
284
400
  }
285
401
  block.result = value;
286
402
  }
403
+ function extractImages(content) {
404
+ if (!Array.isArray(content)) return [];
405
+ const out = [];
406
+ for (const part of content) {
407
+ const rec = asRecord(part);
408
+ if (rec?.type !== "image") continue;
409
+ const ref = asImageRef(rec.attachment);
410
+ if (ref) out.push(ref);
411
+ }
412
+ return out;
413
+ }
414
+ function asImageRef(value) {
415
+ const rec = asRecord(value);
416
+ if (!rec) return null;
417
+ const attachmentId = asString(rec.attachmentId);
418
+ const mediaType = asString(rec.mediaType);
419
+ if (!attachmentId || !mediaType || !mediaType.startsWith("image/")) return null;
420
+ const ref = { attachmentId, mediaType };
421
+ const bytes = asNumber(rec.bytes);
422
+ if (bytes !== void 0) ref.bytes = bytes;
423
+ const width = asNumber(rec.width);
424
+ if (width !== void 0) ref.width = width;
425
+ const height = asNumber(rec.height);
426
+ if (height !== void 0) ref.height = height;
427
+ const name = asString(rec.name);
428
+ if (name) ref.name = name;
429
+ return ref;
430
+ }
287
431
  function partsToText(content) {
288
432
  if (typeof content === "string") return content;
289
433
  if (!Array.isArray(content)) return "";
@@ -297,6 +441,81 @@ function partsToText(content) {
297
441
  }
298
442
  return out.join("\n");
299
443
  }
444
+ function parseAskedQuestions(rawArgs) {
445
+ let parsed = rawArgs;
446
+ if (typeof rawArgs === "string") {
447
+ try {
448
+ parsed = JSON.parse(rawArgs);
449
+ } catch {
450
+ return [];
451
+ }
452
+ }
453
+ const rec = asRecord(parsed);
454
+ const list = Array.isArray(rec?.questions) ? rec.questions : null;
455
+ if (!list) return [];
456
+ const out = [];
457
+ for (const item of list) {
458
+ const q = asRecord(item);
459
+ if (!q) continue;
460
+ const text = asString(q.question);
461
+ if (!text) continue;
462
+ const question = { id: asString(q.id) ?? String(out.length), question: text };
463
+ const header = asString(q.header);
464
+ if (header) question.header = header;
465
+ if (Array.isArray(q.options)) {
466
+ const options = [];
467
+ for (const opt of q.options) {
468
+ const o = asRecord(opt);
469
+ const label = asString(o?.label);
470
+ if (!label) continue;
471
+ const description = asString(o?.description);
472
+ options.push(description ? { label, description } : { label });
473
+ }
474
+ if (options.length) question.options = options;
475
+ }
476
+ const multi = q.multi_select === true || q.multiSelect === true;
477
+ if (multi) question.multiSelect = true;
478
+ out.push(question);
479
+ }
480
+ return out;
481
+ }
482
+ function parseAskedAnswers(text) {
483
+ const trimmed = text.trim();
484
+ if (!trimmed) return [];
485
+ let parsed;
486
+ try {
487
+ parsed = JSON.parse(trimmed);
488
+ } catch {
489
+ return [];
490
+ }
491
+ const rec = asRecord(parsed);
492
+ const list = Array.isArray(rec?.answers) ? rec.answers : null;
493
+ if (!list) return [];
494
+ const out = [];
495
+ for (const item of list) {
496
+ const a = asRecord(item);
497
+ if (!a) continue;
498
+ const id = asString(a.id);
499
+ if (!id) continue;
500
+ const selected = Array.isArray(a.selected) ? a.selected.map((v) => asString(v)).filter((v) => typeof v === "string" && v !== "") : [];
501
+ const custom = asString(a.custom);
502
+ const answer = { id, selected };
503
+ if (custom && custom.trim()) answer.custom = custom;
504
+ out.push(answer);
505
+ }
506
+ return out;
507
+ }
508
+ function latestAnswerStep(turn) {
509
+ const last = turn.assistants[turn.assistants.length - 1];
510
+ if (!last || last.step === void 0) return null;
511
+ const hasReply = last.blocks.some((b) => {
512
+ if (b.kind === "text") return b.md.trim() !== "";
513
+ return b.kind === "reasoning" && b.text.trim() !== "";
514
+ });
515
+ if (!hasReply) return null;
516
+ if (last.blocks.some((b) => b.kind === "tool")) return null;
517
+ return last.step;
518
+ }
300
519
  function argsToFields(rawArgs) {
301
520
  let parsed = rawArgs;
302
521
  if (typeof rawArgs === "string") {
@@ -417,7 +636,10 @@ function presetInclude(preset) {
417
636
  files: false,
418
637
  fileBytes: false,
419
638
  deepResearch: false,
420
- modelMeta: false
639
+ modelMeta: false,
640
+ finalAnswerOnly: true,
641
+ foldProcess: false,
642
+ images: true
421
643
  };
422
644
  case "process":
423
645
  return {
@@ -431,7 +653,10 @@ function presetInclude(preset) {
431
653
  files: true,
432
654
  fileBytes: false,
433
655
  deepResearch: true,
434
- modelMeta: false
656
+ modelMeta: false,
657
+ finalAnswerOnly: false,
658
+ foldProcess: false,
659
+ images: true
435
660
  };
436
661
  case "full":
437
662
  return {
@@ -444,7 +669,10 @@ function presetInclude(preset) {
444
669
  files: true,
445
670
  fileBytes: false,
446
671
  deepResearch: true,
447
- modelMeta: true
672
+ modelMeta: true,
673
+ finalAnswerOnly: false,
674
+ foldProcess: true,
675
+ images: true
448
676
  };
449
677
  }
450
678
  }
@@ -526,14 +754,19 @@ function pruneBlock(block, include, stats) {
526
754
  case "files":
527
755
  if (!include.files) return null;
528
756
  return { kind: "files", files: block.files };
757
+ case "images":
758
+ return include.images ? block : null;
759
+ case "deliverables":
760
+ return block;
529
761
  case "changes":
530
- return include.toolCalls ? block : null;
762
+ return block;
531
763
  case "research":
532
764
  return include.deepResearch ? block : null;
533
765
  case "tool": {
766
+ const base = { ...block };
767
+ if (block.questions?.length) return base;
534
768
  if (!include.toolCalls) return null;
535
- const out = { kind: "tool", name: block.name, status: block.status };
536
- if (block.callId) out.callId = block.callId;
769
+ const out = { ...base };
537
770
  if (block.args !== void 0) {
538
771
  const cut = clip(block.args, include.toolArgumentChars);
539
772
  out.args = cut.text;
@@ -713,6 +946,20 @@ function redactBlock(block, options, hits) {
713
946
  kind: "files",
714
947
  files: block.files.map((f) => ({ ...f, name: redactText(f.name, options, hits) }))
715
948
  };
949
+ case "images":
950
+ return {
951
+ ...block,
952
+ images: block.images.map((img) => img.name === void 0 ? img : { ...img, name: redactText(img.name, options, hits) })
953
+ };
954
+ case "deliverables":
955
+ return {
956
+ ...block,
957
+ files: block.files.map((f) => {
958
+ const next = { ...f, path: redactText(f.path, options, hits) };
959
+ if (f.description !== void 0) next.description = redactText(f.description, options, hits);
960
+ return next;
961
+ })
962
+ };
716
963
  case "changes":
717
964
  return {
718
965
  ...block,
@@ -1502,7 +1749,7 @@ html { -webkit-text-size-adjust: 100%; }
1502
1749
 
1503
1750
  body {
1504
1751
  margin: 0;
1505
- background: var(--dsh-bg-base);
1752
+ background: var(--dsh-input-major);
1506
1753
  color: var(--dsh-label-primary);
1507
1754
  font-family: var(--dsh-font-text);
1508
1755
  font-size: 14px;
@@ -1762,197 +2009,825 @@ details.changes > summary .chg-deleted { flex: none; font-size: 12px; }
1762
2009
 
1763
2010
  .chg-more { color: var(--dsh-label-tertiary); font-style: italic; }
1764
2011
 
1765
- /* ---------- \u6298\u53E0\u5757\uFF08\u601D\u8003 / \u5DE5\u5177 / \u68C0\u7D22 / \u6DF1\u7814\uFF09 ---------- */
1766
-
1767
- details.process {
1768
- margin: 2px 0;
2012
+ /* \u53EF\u70B9\u7684\u6587\u4EF6\u884C\uFF1A\u6574\u884C\u662F\u4E00\u6761\u6307\u5411\u62BD\u5C49\u7684\u94FE\u63A5 */
2013
+ .chg-row .chg-link,
2014
+ .chg-link {
2015
+ display: flex;
2016
+ align-items: center;
2017
+ gap: 12px;
2018
+ flex: 1 1 auto;
2019
+ min-width: 0;
2020
+ padding: 3px 0;
2021
+ color: inherit;
2022
+ text-decoration: none;
1769
2023
  border-radius: var(--dsh-radius-sm);
2024
+ transition: background 100ms ease;
1770
2025
  }
1771
2026
 
1772
- details.process > summary {
1773
- display: flex;
1774
- align-items: center;
1775
- gap: 8px;
1776
- min-height: 28px;
1777
- padding: 2px 0;
1778
- cursor: pointer;
1779
- color: var(--dsh-label-tertiary);
1780
- font-size: 13px;
1781
- line-height: 20px;
1782
- list-style: none;
1783
- user-select: none;
2027
+ .chg-link:hover { background: var(--dsh-markdown-tag); }
2028
+
2029
+ .chg-link .chg-path {
2030
+ text-decoration: underline;
2031
+ text-decoration-color: transparent;
2032
+ text-underline-offset: 2px;
2033
+ transition: text-decoration-color 100ms ease;
1784
2034
  }
1785
2035
 
1786
- details.process > summary::-webkit-details-marker { display: none; }
2036
+ .chg-link:hover .chg-path { text-decoration-color: currentColor; }
1787
2037
 
1788
- details.process > summary::after {
1789
- content: "";
1790
- flex: none;
1791
- width: 6px;
1792
- height: 6px;
1793
- margin-right: 2px;
1794
- border-right: 1.5px solid currentColor;
1795
- border-bottom: 1.5px solid currentColor;
1796
- transform: rotate(-45deg);
1797
- transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
2038
+ /* \u6CA1\u6709 diff \u7684\u884C\u4E0D\u53EF\u70B9 */
2039
+ .chg-row[data-no-diff] .chg-path { text-decoration: none; }
2040
+
2041
+ .chg-note-line {
2042
+ margin: 8px 14px 0;
2043
+ color: var(--dsh-label-tertiary);
2044
+ font-size: 12px;
2045
+ line-height: 18px;
1798
2046
  }
1799
2047
 
1800
- details.process[open] > summary::after { transform: rotate(45deg); }
2048
+ /* ---------- diff \u53F3\u4FA7\u62BD\u5C49\uFF08\u7EAF CSS :target\uFF0C\u96F6 JS\uFF09 ---------- */
1801
2049
 
1802
- @media (hover: hover) {
1803
- details.process > summary:hover { color: var(--dsh-label-secondary); }
2050
+ /*
2051
+ * \u70B9\u51FB\u6587\u4EF6\u884C \u2192 \u6D4F\u89C8\u5668\u8DF3\u5230 #diff-N-M \u2192 \u8BE5\u62BD\u5C49\u5339\u914D :target \u2192 \u6ED1\u5165\u3002
2052
+ * \u5173\u95ED\u6309\u94AE\u6307\u5411\u4E0D\u5B58\u5728\u7684\u951A\u70B9 #diff-closed\uFF0C\u70B9\u51FB\u540E :target \u5931\u914D \u2192 \u6ED1\u51FA\u3002
2053
+ * \u62BD\u5C49\u56FA\u5B9A\u5728\u53F3\u4FA7\u3001\u59CB\u7EC8\u5360\u636E\u6587\u6863\u4F46\u9ED8\u8BA4\u79FB\u51FA\u5C4F\u5E55\uFF0C\u6240\u4EE5\u4E0D\u5F71\u54CD\u6B63\u6587\u6392\u7248\u3002
2054
+ */
2055
+ .dif-drawer {
2056
+ position: fixed;
2057
+ top: 0;
2058
+ right: 0;
2059
+ z-index: 40;
2060
+ display: flex;
2061
+ flex-direction: column;
2062
+ width: min(560px, 92vw);
2063
+ height: 100vh;
2064
+ border-left: .5px solid var(--dsh-border-l2);
2065
+ background: var(--dsh-bg-base);
2066
+ box-shadow: -8px 0 24px rgba(0, 0, 0, .08);
2067
+ transform: translateX(102%);
2068
+ visibility: hidden;
2069
+ transition: transform .18s ease, visibility .18s ease;
1804
2070
  }
1805
2071
 
1806
- details.process > summary:focus-visible {
1807
- outline: 1.5px solid var(--dsh-link);
1808
- outline-offset: 2px;
1809
- border-radius: var(--dsh-radius-xs);
2072
+ .dif-drawer:target {
2073
+ transform: translateX(0);
2074
+ visibility: visible;
1810
2075
  }
1811
2076
 
1812
- .sum-name {
2077
+ .dif-head {
2078
+ display: flex;
2079
+ align-items: center;
2080
+ gap: 10px;
1813
2081
  flex: none;
1814
- color: var(--dsh-label-secondary);
1815
- font-family: var(--dsh-font-code);
1816
- font-size: 12px;
2082
+ padding: 12px 16px;
2083
+ border-bottom: .5px solid var(--dsh-border-l2);
1817
2084
  }
1818
2085
 
1819
- .sum-text {
2086
+ .dif-path {
2087
+ flex: 1 1 auto;
1820
2088
  min-width: 0;
1821
2089
  overflow: hidden;
1822
2090
  text-overflow: ellipsis;
1823
2091
  white-space: nowrap;
2092
+ color: var(--dsh-label-primary);
2093
+ font-family: var(--dsh-font-code);
2094
+ font-size: 13px;
1824
2095
  }
1825
2096
 
1826
- .sum-dot {
1827
- flex: none;
1828
- width: 2px;
1829
- height: 2px;
1830
- border-radius: 1px;
1831
- background: var(--dsh-label-caption);
1832
- }
2097
+ .dif-stat { flex: none; display: inline-flex; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
1833
2098
 
1834
- .sum-state {
2099
+ .dif-close {
1835
2100
  flex: none;
1836
- font-size: 12px;
1837
- display: inline-flex;
1838
- align-items: center;
1839
- gap: 5px;
2101
+ display: grid;
2102
+ place-items: center;
2103
+ width: 24px;
2104
+ height: 24px;
2105
+ border-radius: var(--dsh-radius-sm);
2106
+ color: var(--dsh-label-tertiary);
2107
+ font-size: 18px;
2108
+ line-height: 1;
2109
+ text-decoration: none;
1840
2110
  }
1841
2111
 
1842
- .sum-state::before {
1843
- content: "";
1844
- width: 6px;
1845
- height: 6px;
1846
- border-radius: 50%;
1847
- background: var(--dsh-state-success-primary);
1848
- }
2112
+ .dif-close:hover { background: var(--dsh-markdown-tag); color: var(--dsh-label-primary); }
1849
2113
 
1850
- .sum-state[data-status="error"] { color: var(--dsh-state-error-primary); }
1851
- .sum-state[data-status="error"]::before { background: var(--dsh-state-error-primary); }
1852
- .sum-state[data-status="pending"] { color: var(--dsh-label-tertiary); }
1853
- .sum-state[data-status="pending"]::before { background: var(--dsh-state-warn-primary); }
2114
+ .dif-body {
2115
+ flex: 1 1 auto;
2116
+ min-height: 0;
2117
+ overflow: auto;
2118
+ padding: 8px 0 24px;
2119
+ }
1854
2120
 
1855
- .process-body {
1856
- margin: 4px 0 8px 22px;
2121
+ .dif-empty {
2122
+ margin: 12px 16px;
1857
2123
  color: var(--dsh-label-tertiary);
1858
2124
  font-size: 13px;
1859
- line-height: 22px;
1860
- overflow-wrap: anywhere;
2125
+ line-height: 20px;
1861
2126
  }
1862
2127
 
1863
- .process-body > *:first-child { margin-top: 0; }
1864
- .process-body > *:last-child { margin-bottom: 0; }
1865
-
1866
- .kv {
1867
- display: grid;
1868
- grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
1869
- gap: 2px 14px;
1870
- margin: 0 0 8px;
2128
+ .dif-hunk {
2129
+ border-collapse: collapse;
2130
+ width: 100%;
2131
+ font-family: var(--dsh-font-code);
2132
+ font-size: 12px;
2133
+ line-height: 18px;
1871
2134
  }
1872
2135
 
1873
- .kv dt {
2136
+ .dif-no {
2137
+ width: 1%;
2138
+ padding: 0 8px;
1874
2139
  color: var(--dsh-label-caption);
1875
- font-family: var(--dsh-font-code);
1876
- font-size: 11px;
1877
- line-height: 20px;
2140
+ text-align: right;
2141
+ font-variant-numeric: tabular-nums;
2142
+ white-space: nowrap;
2143
+ vertical-align: top;
2144
+ user-select: none;
1878
2145
  }
1879
2146
 
1880
- .kv dd {
1881
- margin: 0;
1882
- color: var(--dsh-label-secondary);
1883
- font-family: var(--dsh-font-code);
1884
- font-size: 11px;
1885
- line-height: 20px;
2147
+ .dif-text {
2148
+ padding: 0 16px 0 8px;
1886
2149
  white-space: pre-wrap;
1887
2150
  overflow-wrap: anywhere;
2151
+ color: var(--dsh-label-primary);
2152
+ vertical-align: top;
1888
2153
  }
1889
2154
 
1890
- pre.out {
1891
- margin: 8px 0 0;
1892
- padding: 8px 12px;
1893
- max-height: 260px;
1894
- overflow: auto;
1895
- border-radius: var(--dsh-radius-sm);
1896
- background: var(--dsh-markdown-code-block);
1897
- border: .5px solid var(--dsh-border-l1);
1898
- font-family: var(--dsh-font-code);
1899
- font-size: 11px;
1900
- line-height: 19px;
1901
- color: var(--dsh-label-secondary);
1902
- white-space: pre-wrap;
1903
- overflow-wrap: anywhere;
2155
+ .dif-mark { display: inline-block; width: 1ch; color: inherit; opacity: .5; }
2156
+
2157
+ /* \u589E\u5220\u884C\u7684\u5E95\u8272\uFF0C\u6DF1\u6D45\u4E3B\u9898\u90FD\u53EF\u7528 color-mix */
2158
+ .dif-line[data-kind="add"] { background: color-mix(in srgb, var(--dsh-state-success-primary) 12%, transparent); }
2159
+ .dif-line[data-kind="del"] { background: color-mix(in srgb, var(--dsh-state-error-primary) 12%, transparent); }
2160
+ .dif-line[data-kind="ctx"] { color: var(--dsh-label-secondary); }
2161
+
2162
+ @media (prefers-reduced-motion: reduce) {
2163
+ .dif-drawer { transition: none; }
1904
2164
  }
1905
2165
 
1906
- .trunc-note {
1907
- margin-top: 6px;
1908
- display: inline-flex;
1909
- align-items: center;
1910
- gap: 5px;
1911
- font-size: 12px;
1912
- color: var(--dsh-label-tertiary);
2166
+ /* \u6253\u5370\u65F6\u62BD\u5C49\u4E0D\u5360\u4F4D */
2167
+ @media print {
2168
+ .dif-drawer { display: none; }
1913
2169
  }
1914
2170
 
1915
- /* ---------- \u68C0\u7D22\u7ED3\u679C ---------- */
1916
2171
 
1917
- .results { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
2172
+ /* ---------- \u8FD0\u884C\u4E2D\u8F6E\u6B21\u7684\u6A2A\u5E45 ---------- */
1918
2173
 
1919
- .result {
1920
- padding: 8px 12px;
1921
- border: .5px solid var(--dsh-border-l1);
2174
+ /*
2175
+ * \u5BFC\u51FA\u4EA7\u7269\u4EE5\u300C\u5DF2\u5B8C\u6210\u300D\u6001\u4E3A\u57FA\u51C6\uFF1B\u4F1A\u8BDD\u4ECD\u5728\u8DD1\u65F6\u8FD9\u4E00\u8F6E\u6CA1\u6709 turn/end\uFF0C
2176
+ * \u4E0D\u80FD\u7ED9\u300C\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 X\u300D\uFF0C\u6539\u4E3A\u660E\u786E\u6807\u6CE8\u8FD9\u662F\u5FEB\u7167\u3002
2177
+ */
2178
+ .turn-open {
2179
+ display: flex;
2180
+ align-items: center;
2181
+ gap: 8px;
2182
+ margin: 2px 0 6px;
2183
+ padding: 6px 12px;
2184
+ border: .5px solid var(--dsh-border-l2);
1922
2185
  border-radius: var(--dsh-radius-sm);
1923
- background: var(--dsh-markdown-citation);
2186
+ background: var(--dsh-markdown-tag);
2187
+ color: var(--dsh-label-tertiary);
2188
+ font-size: 13px;
2189
+ line-height: 20px;
1924
2190
  }
1925
2191
 
1926
- .result-title { font-size: 13px; line-height: 20px; color: var(--dsh-label-primary); font-weight: 500; }
1927
- .result-title a { font-weight: 500; }
1928
- .result-site { font-size: 11px; line-height: 16px; color: var(--dsh-label-tertiary); margin-top: 2px; }
1929
- .result-snippet { font-size: 12px; line-height: 20px; color: var(--dsh-label-secondary); margin-top: 4px; }
2192
+ .open-dot {
2193
+ flex: none;
2194
+ width: 7px;
2195
+ height: 7px;
2196
+ border-radius: 50%;
2197
+ background: var(--dsh-state-warn-primary);
2198
+ }
1930
2199
 
1931
- /* ---------- Markdown \u6B63\u6587 ---------- */
2200
+ .open-text { color: var(--dsh-label-secondary); }
1932
2201
 
1933
- .md {
1934
- min-width: 0;
1935
- overflow-wrap: anywhere;
1936
- font-size: 14px;
1937
- line-height: 24px;
1938
- color: var(--dsh-label-primary);
1939
- }
2202
+ .open-elapsed { font-variant-numeric: tabular-nums; }
1940
2203
 
1941
- .md > *:first-child { margin-top: 0 !important; }
1942
- .md > *:last-child { margin-bottom: 0 !important; }
2204
+ .open-note { margin-left: auto; font-size: 12px; }
1943
2205
 
1944
- .md h1 { font-size: 21px; line-height: 30px; font-weight: 700; margin: 32px 0 16px; }
1945
- .md h2 { font-size: 19px; line-height: 28px; font-weight: 700; margin: 32px 0 16px; }
1946
- .md h3 { font-size: 18px; line-height: 26px; font-weight: 700; margin: 32px 0 16px; }
1947
- .md h4 { font-size: 14px; line-height: 24px; font-weight: 600; margin: 16px 0; }
1948
- .md h5, .md h6 { font-size: 14px; line-height: 24px; font-weight: 600; margin: 16px 0; color: var(--dsh-label-secondary); }
1949
- .md h1 strong, .md h2 strong, .md h3 strong, .md h4 strong { font-weight: inherit; }
1950
- .md h1 code, .md h2 code, .md h3 code, .md h4 code { font: inherit; font-family: var(--dsh-font-code); }
2206
+ /* ---------- \u63D0\u95EE\uFF08ask_user_question\uFF09 ---------- */
1951
2207
 
1952
- .md p { margin: 16px 0; }
1953
- .md strong { font-weight: 600; }
2208
+ /*
2209
+ * \u7ED3\u6784\u5BF9\u9F50 DSH \u7684 QuestionToolRow\uFF1A
2210
+ * \u884C\uFF1A\u56FE\u6807 16px + \u300C\u63D0\u95EE\u300D13/24 + 2\xD72 \u5706\u70B9 + \u6458\u8981 13/24 \u622A\u65AD + \u7BAD\u5934
2211
+ * \u4F53\uFF1AAskQuestionCard\uFF0Cdt \u95EE\u9898 tertiary \u7070 / dd \u56DE\u7B54 primary
2212
+ * \u884C\u4E0E\u5176\u5B83\u5DE5\u5177\u884C\u540C\u4E00\u5957\u89C6\u89C9\uFF08\u5C0F\u578B\u7070\u8272\u53EF\u70B9\u51FB\u6587\u5B57\uFF09\uFF0C\u9ED8\u8BA4\u6536\u8D77\u3002
2213
+ */
1954
2214
 
1955
- .md ul, .md ol { margin: 16px 0; padding-left: 18px; }
2215
+ .ask-row { display: flex; flex-direction: column; }
2216
+
2217
+ .ask-disclosure { margin: 2px 0; }
2218
+
2219
+ .ask-disclosure > summary {
2220
+ display: flex;
2221
+ align-items: center;
2222
+ gap: 6px;
2223
+ min-height: 28px;
2224
+ padding: 2px 0;
2225
+ list-style: none;
2226
+ cursor: pointer;
2227
+ color: var(--dsh-label-tertiary);
2228
+ font-size: 13px;
2229
+ line-height: 24px;
2230
+ transition: color 100ms ease;
2231
+ }
2232
+
2233
+ .ask-disclosure > summary::-webkit-details-marker { display: none; }
2234
+ .ask-disclosure > summary:hover { color: var(--dsh-label-secondary); }
2235
+
2236
+ /* \u95EE\u53F7\u56FE\u6807\uFF1ADSH \u7528 IconQuestionOutlineRegular\uFF0C\u9759\u6001\u4EA7\u7269\u7528\u7EAF CSS \u753B */
2237
+ .ask-icon {
2238
+ position: relative;
2239
+ flex: none;
2240
+ width: 16px;
2241
+ height: 16px;
2242
+ border: 1px solid currentColor;
2243
+ border-radius: 50%;
2244
+ opacity: .75;
2245
+ }
2246
+
2247
+ .ask-icon::after {
2248
+ content: "?";
2249
+ position: absolute;
2250
+ inset: 0;
2251
+ display: grid;
2252
+ place-items: center;
2253
+ font-size: 10px;
2254
+ line-height: 1;
2255
+ }
2256
+
2257
+ .ask-title { flex: none; font-weight: 400; }
2258
+
2259
+ /* 2\xD72 \u5706\u70B9\u5206\u9694\u7B26\uFF1ADSH \u7684 .sep */
2260
+ .ask-sep {
2261
+ flex: none;
2262
+ width: 2px;
2263
+ height: 2px;
2264
+ margin: 0 8px 0 -2px;
2265
+ border-radius: 1px;
2266
+ background: var(--dsh-label-caption);
2267
+ }
2268
+
2269
+ .ask-summary {
2270
+ flex: 1 1 auto;
2271
+ min-width: 0;
2272
+ overflow: hidden;
2273
+ text-overflow: ellipsis;
2274
+ white-space: nowrap;
2275
+ font-size: 13px;
2276
+ line-height: 24px;
2277
+ }
2278
+
2279
+ .ask-chevron {
2280
+ flex: none;
2281
+ width: 0;
2282
+ height: 0;
2283
+ margin-left: 4px;
2284
+ border-top: 4px solid transparent;
2285
+ border-bottom: 4px solid transparent;
2286
+ border-left: 5px solid currentColor;
2287
+ opacity: .7;
2288
+ transition: transform 100ms ease;
2289
+ }
2290
+
2291
+ .ask-disclosure[open] > summary .ask-chevron { transform: rotate(90deg); }
2292
+
2293
+ /* ---- AskQuestionCard ---- */
2294
+
2295
+ .ask-body { padding: 4px 0 2px; }
2296
+
2297
+ .ask-card {
2298
+ display: flex;
2299
+ flex-direction: column;
2300
+ gap: 16px;
2301
+ max-height: 360px;
2302
+ margin: 4px 0 4px 4px;
2303
+ padding: 16px 20px;
2304
+ overflow-y: auto;
2305
+ border: .5px solid var(--dsh-border-l1);
2306
+ border-radius: var(--dsh-radius-lg);
2307
+ background: var(--dsh-input-major);
2308
+ }
2309
+
2310
+ .ask-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
2311
+
2312
+ .ask-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
2313
+
2314
+ .ask-dt,
2315
+ .ask-dd { margin: 0; }
2316
+
2317
+ .ask-header {
2318
+ display: block;
2319
+ color: var(--dsh-label-tertiary);
2320
+ font-size: 14px;
2321
+ line-height: 24px;
2322
+ }
2323
+
2324
+ /* \u95EE\u9898\uFF1Atertiary \u7070\uFF0C\u4E0E\u56DE\u7B54\u5F62\u6210\u5C42\u7EA7\u5DEE */
2325
+ .ask-question {
2326
+ display: block;
2327
+ margin: 0;
2328
+ color: var(--dsh-label-tertiary);
2329
+ font-size: 14px;
2330
+ line-height: 24px;
2331
+ white-space: pre-wrap;
2332
+ overflow-wrap: anywhere;
2333
+ }
2334
+
2335
+ /* \u56DE\u7B54\uFF1Aprimary \u767D\uFF0C\u4E00\u6574\u884C */
2336
+ .ask-dd {
2337
+ color: var(--dsh-label-primary);
2338
+ font-size: 14px;
2339
+ line-height: 24px;
2340
+ white-space: pre-wrap;
2341
+ overflow-wrap: anywhere;
2342
+ }
2343
+
2344
+ .ask-answer-line { display: block; }
2345
+
2346
+ .ask-skipped { color: var(--dsh-label-tertiary); }
2347
+
2348
+ /* \u672A\u56DE\u7B54\u6001\uFF1A\u4E00\u53E5\u7ED3\u8BBA + \u95EE\u9898\u5217\u8868 */
2349
+ .ask-verdict {
2350
+ margin: 0;
2351
+ color: var(--dsh-label-primary);
2352
+ font-size: 14px;
2353
+ line-height: 24px;
2354
+ }
2355
+
2356
+ .ask-question-list {
2357
+ display: flex;
2358
+ flex-direction: column;
2359
+ gap: 8px;
2360
+ margin: 0;
2361
+ padding-left: 20px;
2362
+ color: var(--dsh-label-tertiary);
2363
+ font-size: 14px;
2364
+ line-height: 24px;
2365
+ }
2366
+
2367
+ .ask-list-item { white-space: pre-wrap; overflow-wrap: anywhere; }
2368
+
2369
+ /* ---------- \u4E00\u8F6E\u7684\u8FC7\u7A0B\u6298\u53E0\uFF08\u300C\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 2\u520626\u79D2\u300D\uFF09 ---------- */
2370
+
2371
+ /*
2372
+ * \u7ED3\u6784\uFF08\u5BF9\u9F50 DSH \u7684\u5E73\u7EA7\u6A21\u578B\uFF09\uFF1A
2373
+ *
2374
+ * details.turn-process \u6298\u53E0\u5934\uFF0C\u72EC\u7ACB\u5757
2375
+ * div.turn-flow \u5185\u5BB9\u533A\uFF0C\u662F\u6298\u53E0\u5934\u7684\u76F8\u90BB\u5144\u5F1F
2376
+ * div.turn-run \u8FC7\u7A0B\u7EC4 \u2014\u2014 \u53D7\u6298\u53E0\u5934\u63A7\u5236
2377
+ * div.turn-reply \u4E2D\u95F4\u56DE\u590D \u2014\u2014 \u6C38\u8FDC\u53EF\u89C1
2378
+ * div.turn-run \u8FC7\u7A0B\u7EC4
2379
+ * div.turn-answer \u6700\u7EC8\u7B54\u6848 \u2014\u2014 \u6C38\u8FDC\u53EF\u89C1
2380
+ *
2381
+ * \u4E0D\u8981\u7ED9 details \u8BBE display\uFF08\u4F1A\u7834\u574F\u6536\u8D77\u65F6\u7684\u5185\u5BB9\u9690\u85CF\uFF09\uFF1B
2382
+ * \u4E5F\u4E0D\u8981\u8BA9\u5B83\u5305\u88F9\u5185\u5BB9\u533A\uFF08\u90A3\u4F1A\u628A\u56DE\u590D\u4E00\u8D77\u85CF\u6389\uFF09\u3002
2383
+ */
2384
+ details.turn-process {
2385
+ margin: 2px 0 0;
2386
+ }
2387
+
2388
+ details.turn-process > summary {
2389
+ display: flex;
2390
+ align-items: center;
2391
+ gap: 6px;
2392
+ min-height: 33px;
2393
+ padding: 0 0 8px;
2394
+ list-style: none;
2395
+ cursor: pointer;
2396
+ color: var(--dsh-label-tertiary);
2397
+ font-size: 14px;
2398
+ line-height: 24px;
2399
+ border-bottom: .5px solid var(--dsh-border-l2);
2400
+ transition: color 100ms ease;
2401
+ }
2402
+
2403
+ details.turn-process > summary::-webkit-details-marker { display: none; }
2404
+ details.turn-process > summary:hover { color: var(--dsh-label-secondary); }
2405
+
2406
+ .tp-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2407
+
2408
+ .tp-num {
2409
+ font-family: var(--dsh-font-code);
2410
+ font-variant-numeric: tabular-nums;
2411
+ }
2412
+
2413
+ .tp-chevron {
2414
+ flex: none;
2415
+ width: 0;
2416
+ height: 0;
2417
+ margin-left: 4px;
2418
+ border-top: 4px solid transparent;
2419
+ border-bottom: 4px solid transparent;
2420
+ border-left: 5px solid currentColor;
2421
+ transition: transform 100ms ease;
2422
+ }
2423
+
2424
+ details.turn-process[open] > summary .tp-chevron { transform: rotate(90deg); }
2425
+
2426
+ .turn-flow {
2427
+ display: flex;
2428
+ flex-direction: column;
2429
+ gap: 4px;
2430
+ padding-top: 8px;
2431
+ }
2432
+
2433
+ .turn-run {
2434
+ display: flex;
2435
+ flex-direction: column;
2436
+ gap: 4px;
2437
+ }
2438
+
2439
+ /*
2440
+ * \u6536\u8D77\u65F6\u53EA\u9690\u85CF\u8FC7\u7A0B\u7EC4\u3002\u9009\u62E9\u5668\u8981\u6C42 details \u4E0E .turn-flow \u662F\u76F8\u90BB\u5144\u5F1F\uFF0C
2441
+ * \u4E0E HTML \u7ED3\u6784\u4E00\u4E00\u5BF9\u5E94\uFF1B.turn-reply / .turn-answer \u4E0D\u5728\u5339\u914D\u8303\u56F4\uFF0C
2442
+ * \u6240\u4EE5\u56DE\u590D\u4E0E\u6700\u7EC8\u7B54\u6848\u6C38\u8FDC\u53EF\u89C1 \u2014\u2014 \u8FD9\u6B63\u662F DSH \u7684 foldedReplies: 'all'\u3002
2443
+ */
2444
+ details.turn-process:not([open]) + .turn-flow > .turn-run { display: none; }
2445
+
2446
+ .turn-reply,
2447
+ .turn-answer,
2448
+ .turn-ask {
2449
+ display: flex;
2450
+ flex-direction: column;
2451
+ gap: 4px;
2452
+ }
2453
+
2454
+ /* ---------- \u56FE\u7247\u7F29\u7565\u56FE\u4E0E\u653E\u5927\u5C42 ---------- */
2455
+
2456
+ /* \u7F29\u7565\u56FE\uFF1A320px \u5BBD\u4E0A\u9650\uFF0C\u4FDD\u6301\u6BD4\u4F8B\uFF0C\u591A\u56FE\u6A2A\u6392\u6362\u884C */
2457
+ .images {
2458
+ display: flex;
2459
+ flex-wrap: wrap;
2460
+ gap: 8px;
2461
+ margin: 8px 0 2px;
2462
+ }
2463
+
2464
+ .img-thumb {
2465
+ display: block;
2466
+ max-width: 320px;
2467
+ border: .5px solid var(--dsh-border-l2);
2468
+ border-radius: var(--dsh-radius-md);
2469
+ overflow: hidden;
2470
+ line-height: 0;
2471
+ transition: border-color 120ms ease;
2472
+ }
2473
+
2474
+ .img-thumb:hover { border-color: var(--dsh-label-tertiary); }
2475
+
2476
+ .img-thumb img {
2477
+ display: block;
2478
+ width: auto;
2479
+ max-width: 100%;
2480
+ height: auto;
2481
+ max-height: 320px;
2482
+ object-fit: contain;
2483
+ }
2484
+
2485
+ /*
2486
+ * \u653E\u5927\u5C42\uFF1A\u9ED8\u8BA4\u4E0D\u663E\u793A\uFF0C:target \u547D\u4E2D\u624D\u94FA\u6EE1\u89C6\u53E3\u3002
2487
+ * \u7528 fixed + \u534A\u900F\u660E\u5E95\uFF0C\u628A\u5168\u56FE\u5C45\u4E2D\uFF1B\u5173\u95ED\u6309\u94AE\u6307\u5411\u4E0D\u5B58\u5728\u7684\u951A\u70B9\u8BA9 :target \u5931\u914D\u3002
2488
+ */
2489
+ .img-lightbox {
2490
+ position: fixed;
2491
+ inset: 0;
2492
+ z-index: 60;
2493
+ display: none;
2494
+ align-items: center;
2495
+ justify-content: center;
2496
+ padding: 48px 32px;
2497
+ background: rgba(0, 0, 0, .82);
2498
+ }
2499
+
2500
+ .img-lightbox:target { display: flex; }
2501
+
2502
+ .img-lightbox img {
2503
+ max-width: 100%;
2504
+ max-height: 100%;
2505
+ object-fit: contain;
2506
+ border-radius: var(--dsh-radius-sm);
2507
+ box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
2508
+ }
2509
+
2510
+ .lb-close {
2511
+ position: absolute;
2512
+ top: 16px;
2513
+ right: 20px;
2514
+ display: grid;
2515
+ place-items: center;
2516
+ width: 36px;
2517
+ height: 36px;
2518
+ border-radius: 50%;
2519
+ background: rgba(255, 255, 255, .12);
2520
+ color: #fff;
2521
+ font-size: 24px;
2522
+ line-height: 1;
2523
+ text-decoration: none;
2524
+ }
2525
+
2526
+ .lb-close:hover { background: rgba(255, 255, 255, .24); }
2527
+
2528
+ .lb-caption {
2529
+ position: absolute;
2530
+ bottom: 16px;
2531
+ left: 50%;
2532
+ transform: translateX(-50%);
2533
+ max-width: 80vw;
2534
+ overflow: hidden;
2535
+ color: rgba(255, 255, 255, .75);
2536
+ font-size: 12px;
2537
+ line-height: 18px;
2538
+ text-overflow: ellipsis;
2539
+ white-space: nowrap;
2540
+ }
2541
+
2542
+ @media print {
2543
+ .img-lightbox { display: none !important; }
2544
+ }
2545
+
2546
+ /* ---------- \u4EA4\u4ED8\u6587\u4EF6\u5361\u7247\uFF08deliverables/presented\uFF09 ---------- */
2547
+
2548
+ .deliverables {
2549
+ display: flex;
2550
+ flex-direction: column;
2551
+ gap: 8px;
2552
+ margin: 8px 0 2px;
2553
+ }
2554
+
2555
+ /* \u5BF9\u9F50 DSH \u7684 PresentedFileCard\uFF1A60px \u9AD8\u3001\u56FE\u6807 40px\u3001\u5706\u89D2 16px */
2556
+ .dl-card {
2557
+ display: flex;
2558
+ align-items: center;
2559
+ gap: 10px;
2560
+ min-width: 0;
2561
+ height: 60px;
2562
+ padding: 8px 10px;
2563
+ border: .5px solid var(--dsh-border-l1);
2564
+ border-radius: var(--dsh-radius-lg);
2565
+ background: var(--dsh-bg-base);
2566
+ }
2567
+
2568
+ .dl-icon {
2569
+ flex: none;
2570
+ display: grid;
2571
+ place-items: center;
2572
+ width: 40px;
2573
+ height: 40px;
2574
+ border: .5px solid var(--dsh-border-l1);
2575
+ border-radius: 10px;
2576
+ background: var(--dsh-markdown-tag);
2577
+ color: var(--dsh-label-secondary);
2578
+ font-family: var(--dsh-font-code);
2579
+ font-size: 10px;
2580
+ font-weight: 600;
2581
+ letter-spacing: -.02em;
2582
+ }
2583
+
2584
+ .dl-body { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
2585
+
2586
+ .dl-name {
2587
+ overflow: hidden;
2588
+ text-overflow: ellipsis;
2589
+ white-space: nowrap;
2590
+ color: var(--dsh-label-primary);
2591
+ font-size: 13px;
2592
+ font-weight: 500;
2593
+ line-height: 20px;
2594
+ }
2595
+
2596
+ .dl-desc {
2597
+ overflow: hidden;
2598
+ text-overflow: ellipsis;
2599
+ white-space: nowrap;
2600
+ color: var(--dsh-label-tertiary);
2601
+ font-size: 10px;
2602
+ line-height: 16px;
2603
+ }
2604
+
2605
+ /* \u56FE\u7247\u7C7B\u4EA4\u4ED8\uFF1A\u6574\u5F20\u5361\u7247\u53EF\u70B9\uFF0C\u5DE6\u4FA7\u6362\u6210\u7F29\u7565\u56FE */
2606
+ .dl-card-image {
2607
+ color: inherit;
2608
+ text-decoration: none;
2609
+ cursor: pointer;
2610
+ transition: border-color 120ms ease;
2611
+ }
2612
+
2613
+ .dl-card-image:hover { border-color: var(--dsh-label-tertiary); }
2614
+
2615
+ .dl-thumb {
2616
+ flex: none;
2617
+ display: grid;
2618
+ place-items: center;
2619
+ width: 40px;
2620
+ height: 40px;
2621
+ overflow: hidden;
2622
+ border: .5px solid var(--dsh-border-l1);
2623
+ border-radius: 10px;
2624
+ background: var(--dsh-markdown-tag);
2625
+ }
2626
+
2627
+ .dl-thumb img {
2628
+ width: 100%;
2629
+ height: 100%;
2630
+ object-fit: cover;
2631
+ }
2632
+
2633
+ /* \u56FE\u7247\u8BFB\u4E0D\u5230\u65F6\u7684\u8BF4\u660E\uFF08\u6587\u4EF6\u5DF2\u5220\u9664/\u8FC7\u5927\uFF09 */
2634
+ .dl-missing {
2635
+ color: var(--dsh-state-warn-primary);
2636
+ font-size: 10px;
2637
+ line-height: 16px;
2638
+ }
2639
+
2640
+ /* ---------- \u6298\u53E0\u5757\uFF08\u601D\u8003 / \u5DE5\u5177 / \u68C0\u7D22 / \u6DF1\u7814\uFF09 ---------- */
2641
+
2642
+ details.process {
2643
+ margin: 2px 0;
2644
+ border-radius: var(--dsh-radius-sm);
2645
+ }
2646
+
2647
+ details.process > summary {
2648
+ display: flex;
2649
+ align-items: center;
2650
+ gap: 8px;
2651
+ min-height: 28px;
2652
+ padding: 2px 0;
2653
+ cursor: pointer;
2654
+ color: var(--dsh-label-tertiary);
2655
+ font-size: 13px;
2656
+ line-height: 20px;
2657
+ list-style: none;
2658
+ user-select: none;
2659
+ }
2660
+
2661
+ details.process > summary::-webkit-details-marker { display: none; }
2662
+
2663
+ details.process > summary::after {
2664
+ content: "";
2665
+ flex: none;
2666
+ width: 6px;
2667
+ height: 6px;
2668
+ margin-right: 2px;
2669
+ border-right: 1.5px solid currentColor;
2670
+ border-bottom: 1.5px solid currentColor;
2671
+ transform: rotate(-45deg);
2672
+ transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
2673
+ }
2674
+
2675
+ details.process[open] > summary::after { transform: rotate(45deg); }
2676
+
2677
+ @media (hover: hover) {
2678
+ details.process > summary:hover { color: var(--dsh-label-secondary); }
2679
+ }
2680
+
2681
+ details.process > summary:focus-visible {
2682
+ outline: 1.5px solid var(--dsh-link);
2683
+ outline-offset: 2px;
2684
+ border-radius: var(--dsh-radius-xs);
2685
+ }
2686
+
2687
+ .sum-name {
2688
+ flex: none;
2689
+ color: var(--dsh-label-secondary);
2690
+ font-family: var(--dsh-font-code);
2691
+ font-size: 12px;
2692
+ }
2693
+
2694
+ .sum-text {
2695
+ min-width: 0;
2696
+ overflow: hidden;
2697
+ text-overflow: ellipsis;
2698
+ white-space: nowrap;
2699
+ }
2700
+
2701
+ .sum-dot {
2702
+ flex: none;
2703
+ width: 2px;
2704
+ height: 2px;
2705
+ border-radius: 1px;
2706
+ background: var(--dsh-label-caption);
2707
+ }
2708
+
2709
+ .sum-state {
2710
+ flex: none;
2711
+ font-size: 12px;
2712
+ display: inline-flex;
2713
+ align-items: center;
2714
+ gap: 5px;
2715
+ }
2716
+
2717
+ .sum-state::before {
2718
+ content: "";
2719
+ width: 6px;
2720
+ height: 6px;
2721
+ border-radius: 50%;
2722
+ background: var(--dsh-state-success-primary);
2723
+ }
2724
+
2725
+ .sum-state[data-status="error"] { color: var(--dsh-state-error-primary); }
2726
+ .sum-state[data-status="error"]::before { background: var(--dsh-state-error-primary); }
2727
+ .sum-state[data-status="pending"] { color: var(--dsh-label-tertiary); }
2728
+ .sum-state[data-status="pending"]::before { background: var(--dsh-state-warn-primary); }
2729
+
2730
+ .process-body {
2731
+ margin: 4px 0 8px 22px;
2732
+ color: var(--dsh-label-tertiary);
2733
+ font-size: 13px;
2734
+ line-height: 22px;
2735
+ overflow-wrap: anywhere;
2736
+ }
2737
+
2738
+ .process-body > *:first-child { margin-top: 0; }
2739
+ .process-body > *:last-child { margin-bottom: 0; }
2740
+
2741
+ .kv {
2742
+ display: grid;
2743
+ grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
2744
+ gap: 2px 14px;
2745
+ margin: 0 0 8px;
2746
+ }
2747
+
2748
+ .kv dt {
2749
+ color: var(--dsh-label-caption);
2750
+ font-family: var(--dsh-font-code);
2751
+ font-size: 11px;
2752
+ line-height: 20px;
2753
+ }
2754
+
2755
+ .kv dd {
2756
+ margin: 0;
2757
+ color: var(--dsh-label-secondary);
2758
+ font-family: var(--dsh-font-code);
2759
+ font-size: 11px;
2760
+ line-height: 20px;
2761
+ white-space: pre-wrap;
2762
+ overflow-wrap: anywhere;
2763
+ }
2764
+
2765
+ pre.out {
2766
+ margin: 8px 0 0;
2767
+ padding: 8px 12px;
2768
+ max-height: 260px;
2769
+ overflow: auto;
2770
+ border-radius: var(--dsh-radius-sm);
2771
+ background: var(--dsh-markdown-code-block);
2772
+ border: .5px solid var(--dsh-border-l1);
2773
+ font-family: var(--dsh-font-code);
2774
+ font-size: 11px;
2775
+ line-height: 19px;
2776
+ color: var(--dsh-label-secondary);
2777
+ white-space: pre-wrap;
2778
+ overflow-wrap: anywhere;
2779
+ }
2780
+
2781
+ .trunc-note {
2782
+ margin-top: 6px;
2783
+ display: inline-flex;
2784
+ align-items: center;
2785
+ gap: 5px;
2786
+ font-size: 12px;
2787
+ color: var(--dsh-label-tertiary);
2788
+ }
2789
+
2790
+ /* ---------- \u68C0\u7D22\u7ED3\u679C ---------- */
2791
+
2792
+ .results { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
2793
+
2794
+ .result {
2795
+ padding: 8px 12px;
2796
+ border: .5px solid var(--dsh-border-l1);
2797
+ border-radius: var(--dsh-radius-sm);
2798
+ background: var(--dsh-markdown-citation);
2799
+ }
2800
+
2801
+ .result-title { font-size: 13px; line-height: 20px; color: var(--dsh-label-primary); font-weight: 500; }
2802
+ .result-title a { font-weight: 500; }
2803
+ .result-site { font-size: 11px; line-height: 16px; color: var(--dsh-label-tertiary); margin-top: 2px; }
2804
+ .result-snippet { font-size: 12px; line-height: 20px; color: var(--dsh-label-secondary); margin-top: 4px; }
2805
+
2806
+ /* ---------- Markdown \u6B63\u6587 ---------- */
2807
+
2808
+ .md {
2809
+ min-width: 0;
2810
+ overflow-wrap: anywhere;
2811
+ font-size: 14px;
2812
+ line-height: 24px;
2813
+ color: var(--dsh-label-primary);
2814
+ }
2815
+
2816
+ .md > *:first-child { margin-top: 0 !important; }
2817
+ .md > *:last-child { margin-bottom: 0 !important; }
2818
+
2819
+ .md h1 { font-size: 21px; line-height: 30px; font-weight: 700; margin: 32px 0 16px; }
2820
+ .md h2 { font-size: 19px; line-height: 28px; font-weight: 700; margin: 32px 0 16px; }
2821
+ .md h3 { font-size: 18px; line-height: 26px; font-weight: 700; margin: 32px 0 16px; }
2822
+ .md h4 { font-size: 14px; line-height: 24px; font-weight: 600; margin: 16px 0; }
2823
+ .md h5, .md h6 { font-size: 14px; line-height: 24px; font-weight: 600; margin: 16px 0; color: var(--dsh-label-secondary); }
2824
+ .md h1 strong, .md h2 strong, .md h3 strong, .md h4 strong { font-weight: inherit; }
2825
+ .md h1 code, .md h2 code, .md h3 code, .md h4 code { font: inherit; font-family: var(--dsh-font-code); }
2826
+
2827
+ .md p { margin: 16px 0; }
2828
+ .md strong { font-weight: 600; }
2829
+
2830
+ .md ul, .md ol { margin: 16px 0; padding-left: 18px; }
1956
2831
  .md li:not(:first-child) { margin-top: 6px; }
1957
2832
  .md li > ul, .md li > ol { margin-top: 4px; }
1958
2833
  .md li::marker { color: var(--dsh-label-secondary); line-height: 24px; }
@@ -2142,21 +3017,107 @@ function renderHtml(model, meta = {}) {
2142
3017
  stats.messages += 1;
2143
3018
  body.push(renderUserMessage(turn.user));
2144
3019
  }
2145
- const assistantBlocks = [];
2146
3020
  const turnModels = [];
2147
3021
  for (const msg of turn.assistants) {
2148
3022
  stats.messages += 1;
2149
3023
  stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
2150
3024
  if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
2151
- assistantBlocks.push(renderAssistantMessage(msg));
2152
3025
  }
2153
- if (assistantBlocks.length) {
2154
- const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
3026
+ if (!turn.assistants.length) continue;
3027
+ const answerStep = turn.answerStep ?? null;
3028
+ const rows = [];
3029
+ const tailRows = [];
3030
+ let run = null;
3031
+ const ensureRun = () => run ??= { parts: [], tools: [] };
3032
+ const flushRun = () => {
3033
+ if (run === null) return;
3034
+ const { parts, tools } = run;
3035
+ run = null;
3036
+ if (!parts.length && !tools.length) return;
3037
+ rows.push({ kind: "process", html: parts.join("\n"), tools });
3038
+ };
3039
+ for (const msg of turn.assistants) {
3040
+ const isAnswer = answerStep !== null && msg.step !== void 0 && msg.step >= answerStep;
3041
+ const replies = msg.blocks.filter((b) => b.kind === "text" && b.md.trim() !== "");
3042
+ const thinks = msg.blocks.filter((b) => b.kind === "reasoning" && b.text.trim() !== "");
3043
+ const tools = msg.blocks.filter((b) => b.kind === "tool");
3044
+ const changeBlocks = msg.blocks.filter((b) => b.kind === "changes");
3045
+ const deliverableBlocks = msg.blocks.filter(
3046
+ (b) => b.kind === "deliverables"
3047
+ );
3048
+ const assistantImages = msg.blocks.filter(
3049
+ (b) => b.kind === "images" && b.images.length > 0
3050
+ );
3051
+ const others = msg.blocks.filter(
3052
+ (b) => b.kind !== "text" && b.kind !== "reasoning" && b.kind !== "tool" && b.kind !== "changes" && b.kind !== "deliverables" && b.kind !== "images"
3053
+ );
3054
+ const asks = tools.filter((t) => t.questions !== void 0);
3055
+ const plainTools = tools.filter((t) => t.questions === void 0);
3056
+ for (const ask of asks) {
3057
+ flushRun();
3058
+ rows.push({ kind: "ask", html: renderTool(ask) });
3059
+ }
3060
+ if (thinks.length || others.length) {
3061
+ const r = ensureRun();
3062
+ for (const b of thinks) r.parts.push(renderBlock(b));
3063
+ for (const b of others) r.parts.push(renderBlock(b));
3064
+ }
3065
+ if (plainTools.length) ensureRun().tools.push(...plainTools);
3066
+ if (replies.length) {
3067
+ flushRun();
3068
+ const html2 = replies.map((b) => renderBlock(b)).join("\n");
3069
+ rows.push({ kind: isAnswer ? "answer" : "reply", html: html2 });
3070
+ } else if (isAnswer) {
3071
+ flushRun();
3072
+ }
3073
+ for (const ib of assistantImages) {
3074
+ flushRun();
3075
+ rows.push({ kind: "answer", html: renderBlock(ib) });
3076
+ }
3077
+ for (const cb of changeBlocks) tailRows.push({ kind: "changes", html: renderBlock(cb) });
3078
+ for (const db of deliverableBlocks) tailRows.push({ kind: "changes", html: renderBlock(db) });
3079
+ }
3080
+ flushRun();
3081
+ rows.push(...tailRows);
3082
+ const visibleRows = meta.finalAnswerOnly === true ? rows.filter((r) => r.kind === "answer" || r.kind === "ask" || r.kind === "changes") : rows;
3083
+ const processRows = visibleRows.filter((r) => r.kind === "process");
3084
+ const toolCount = processRows.reduce((n, r) => n + r.tools.length, 0);
3085
+ const hasProcess = processRows.length > 0;
3086
+ const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
2155
3087
  ` : "";
2156
- body.push(`<article class="msg" data-role="assistant">
2157
- ${head}${assistantBlocks.join("\n")}
3088
+ const attrs = turn.status === "open" ? ' data-status="open"' : "";
3089
+ const banner = turn.status === "open" ? renderOpenBanner(turn, meta.exportedAt) : "";
3090
+ const renderRun = (row) => {
3091
+ const toolHtml = row.tools.map((t) => renderTool(t)).join("\n");
3092
+ const inner = [row.html, toolHtml].filter(Boolean).join("\n");
3093
+ return inner ? `<div class="turn-run">${inner}</div>` : "";
3094
+ };
3095
+ const renderRow = (row) => {
3096
+ if (row.kind === "process") return renderRun(row);
3097
+ const cls = row.kind === "answer" ? "turn-answer" : row.kind === "ask" ? "turn-ask" : row.kind === "changes" ? "turn-changes" : "turn-reply";
3098
+ return `<div class="${cls}">${row.html}</div>`;
3099
+ };
3100
+ if (meta.foldProcess !== true) {
3101
+ const flat = visibleRows.map(renderRow).filter(Boolean).join("\n");
3102
+ if (flat) body.push(`<article class="msg" data-role="assistant"${attrs}>
3103
+ ${head}${banner}${flat}
3104
+ </article>`);
3105
+ continue;
3106
+ }
3107
+ if (!hasProcess) {
3108
+ const only = visibleRows.map(renderRow).filter(Boolean).join("\n");
3109
+ if (only) body.push(`<article class="msg" data-role="assistant"${attrs}>
3110
+ ${head}${banner}${only}
2158
3111
  </article>`);
3112
+ continue;
2159
3113
  }
3114
+ const flow = visibleRows.map((row) => row.kind === "process" ? renderRun(row) : renderRow(row)).filter(Boolean).join("\n");
3115
+ body.push(`<article class="msg" data-role="assistant"${attrs}>
3116
+ ${head}${banner}${renderTurnProcessHeader(turn, toolCount, processRows.length)}
3117
+ <div class="turn-flow">
3118
+ ${flow}
3119
+ </div>
3120
+ </article>`);
2160
3121
  }
2161
3122
  if (!body.length) {
2162
3123
  body.push('<p class="empty-note">\u8FD9\u4E2A\u4F1A\u8BDD\u5728\u6240\u9009\u7C92\u5EA6\u4E0B\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684\u5185\u5BB9\u3002</p>');
@@ -2244,29 +3205,79 @@ function buildFooter(input) {
2244
3205
  lines.push(`<p>\u7EDF\u8BA1\uFF1A${esc(String(stats.turns))} \u8F6E / ${esc(String(stats.messages))} \u6761\u6D88\u606F / ${esc(String(stats.toolCalls))} \u6B21\u5DE5\u5177\u8C03\u7528\u3002</p>`);
2245
3206
  return lines.join("\n");
2246
3207
  }
3208
+ function renderOpenBanner(turn, now) {
3209
+ const elapsed = turn.startedAt !== void 0 && now !== void 0 && now > turn.startedAt ? formatElapsed(now - turn.startedAt) : void 0;
3210
+ const time = elapsed === void 0 ? "" : `<span class="open-elapsed">\u5DF2\u7528 ${esc(elapsed)}</span>`;
3211
+ return `<div class="turn-open" role="note"><span class="open-dot"></span><span class="open-text">\u8FDB\u884C\u4E2D</span>${time}<span class="open-note">\u5BFC\u51FA\u65F6\u7684\u5FEB\u7167</span></div>
3212
+ `;
3213
+ }
3214
+ function formatElapsed(ms) {
3215
+ const total = Math.max(0, Math.floor(ms / 1e3));
3216
+ const minutes = Math.floor(total / 60);
3217
+ const seconds = total % 60;
3218
+ return minutes > 0 ? `${minutes} \u5206 ${seconds} \u79D2` : `${seconds} \u79D2`;
3219
+ }
3220
+ function renderTurnProcessHeader(turn, toolCount, runCount) {
3221
+ const stopped = turn.endReason === "aborted" || turn.endReason === "interrupted";
3222
+ const failed = turn.endReason === "error";
3223
+ const elapsed = turn.startedAt !== void 0 && turn.endedAt !== void 0 ? Math.max(1e3, turn.endedAt - turn.startedAt) : void 0;
3224
+ const duration = elapsed === void 0 || stopped || failed ? void 0 : formatDuration(elapsed);
3225
+ const label = [];
3226
+ if (stopped) label.push("\u5DF2\u4E2D\u65AD");
3227
+ else if (failed) label.push("\u51FA\u9519");
3228
+ else if (duration === void 0) label.push("\u5DF2\u5B8C\u6210");
3229
+ else {
3230
+ label.push("\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 ");
3231
+ for (const part of duration) {
3232
+ label.push(part.numeric ? `<span class="tp-num">${esc(part.text)}</span>` : esc(part.text));
3233
+ }
3234
+ }
3235
+ const forced = turn.status === "open" || stopped || failed;
3236
+ const openAttr = forced ? " open" : "";
3237
+ const status = stopped ? "stopped" : failed ? "failed" : turn.status === "open" ? "open" : "completed";
3238
+ const dataAttrs = [
3239
+ ` data-status="${status}"`,
3240
+ toolCount > 0 ? ` data-tools="${toolCount}"` : "",
3241
+ runCount > 1 ? ` data-runs="${runCount}"` : ""
3242
+ ].join("");
3243
+ return `<details class="turn-process"${dataAttrs}${openAttr}>
3244
+ <summary><span class="tp-label">${label.join("")}</span><span class="tp-chevron"></span></summary>
3245
+ </details>`;
3246
+ }
3247
+ function formatDuration(ms) {
3248
+ const total = Math.max(0, Math.floor(ms / 1e3));
3249
+ const hours = Math.floor(total / 3600);
3250
+ const minutes = Math.floor(total / 60) % 60;
3251
+ const seconds = total % 60;
3252
+ const parts = [];
3253
+ if (hours > 0) parts.push({ text: String(hours), numeric: true }, { text: "\u5C0F\u65F6", numeric: false });
3254
+ if (total >= 60) parts.push({ text: String(minutes), numeric: true }, { text: "\u5206", numeric: false });
3255
+ parts.push({ text: String(seconds), numeric: true }, { text: "\u79D2", numeric: false });
3256
+ return parts;
3257
+ }
2247
3258
  function renderUserMessage(msg) {
2248
3259
  const parts = [];
2249
- const fileBlocks = msg.blocks.filter((b) => b.kind === "files");
2250
3260
  const textBlocks = msg.blocks.filter((b) => b.kind === "text");
2251
- for (const block of fileBlocks) {
2252
- if (block.kind === "files") parts.push(renderFiles(block.files));
2253
- }
3261
+ const fileBlocks = msg.blocks.filter((b) => b.kind === "files");
3262
+ const imageBlocks = msg.blocks.filter((b) => b.kind === "images");
2254
3263
  for (const block of textBlocks) {
2255
3264
  if (block.kind === "text") {
2256
3265
  parts.push(`<div class="bubble">${esc(block.md)}</div>`);
2257
3266
  }
2258
3267
  }
3268
+ for (const block of imageBlocks) {
3269
+ if (block.kind === "images") {
3270
+ const html = renderImages(block.images);
3271
+ if (html) parts.push(`<div class="user-media">${html}</div>`);
3272
+ }
3273
+ }
3274
+ for (const block of fileBlocks) {
3275
+ if (block.kind === "files") parts.push(renderFiles(block.files));
3276
+ }
2259
3277
  return `<article class="msg" data-role="user">
2260
3278
  ${parts.join("\n")}
2261
3279
  </article>`;
2262
3280
  }
2263
- function renderAssistantMessage(msg) {
2264
- const parts = [];
2265
- for (const block of msg.blocks) {
2266
- parts.push(renderBlock(block));
2267
- }
2268
- return parts.filter(Boolean).join("\n");
2269
- }
2270
3281
  function renderBlock(block) {
2271
3282
  switch (block.kind) {
2272
3283
  case "text":
@@ -2293,6 +3304,10 @@ function renderBlock(block) {
2293
3304
  return renderFiles(block.files);
2294
3305
  case "changes":
2295
3306
  return renderChanges(block);
3307
+ case "deliverables":
3308
+ return renderDeliverables(block);
3309
+ case "images":
3310
+ return renderImages(block.images);
2296
3311
  }
2297
3312
  }
2298
3313
  function renderDetails(input) {
@@ -2312,6 +3327,7 @@ function statusDot(status) {
2312
3327
  return "";
2313
3328
  }
2314
3329
  function renderTool(block) {
3330
+ if (block.questions?.length) return renderAskedQuestions(block);
2315
3331
  const summaryText = toolSummary(block);
2316
3332
  const body = [];
2317
3333
  if (block.argsFields?.length) {
@@ -2333,13 +3349,50 @@ function renderTool(block) {
2333
3349
  body.push('<div class="trunc-note">\u4F1A\u8BDD\u5BFC\u51FA\u65F6\u8BE5\u8C03\u7528\u5C1A\u672A\u8FD4\u56DE</div>');
2334
3350
  }
2335
3351
  const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
3352
+ const imageHtml = block.resultImageData?.length ? renderImages(block.resultImageData) : "";
2336
3353
  return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
2337
3354
  <summary><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>` : ""}</summary>
2338
3355
  <div class="process-body">
2339
3356
  ${body.join("\n")}
3357
+ ${imageHtml}
2340
3358
  </div>
2341
3359
  </details>`;
2342
3360
  }
3361
+ function renderAskedQuestions(block) {
3362
+ const questions = block.questions ?? [];
3363
+ const answers = new Map((block.answers ?? []).map((a) => [a.id, a]));
3364
+ const head = questions[0];
3365
+ const summaryText = head === void 0 ? "" : questions.length === 1 ? head.question ?? "" : head.header ?? head.question ?? "";
3366
+ const interrupted = block.status === "error";
3367
+ const pending = block.answers === void 0 && !interrupted;
3368
+ const state = interrupted ? "interrupted" : pending ? "pending" : "answered";
3369
+ const items = questions.map((q) => {
3370
+ const a = answers.get(q.id);
3371
+ const chosen = a === void 0 ? [] : a.selected;
3372
+ const lines = [];
3373
+ if (a?.custom !== void 0) lines.push(a.custom);
3374
+ for (const label of chosen) lines.push(label);
3375
+ const dd = lines.length ? lines.map((line) => `<span class="ask-answer-line">${esc(line)}</span>`).join("") : `<span class="ask-skipped">\u672A\u56DE\u7B54</span>`;
3376
+ const dt = q.header ? `<span class="ask-header">${esc(q.header)}</span><span class="ask-question">${esc(q.question)}</span>` : `<span class="ask-question">${esc(q.question)}</span>`;
3377
+ return `<div class="ask-item"><dt class="ask-dt">${dt}</dt><dd class="ask-dd">${dd}</dd></div>`;
3378
+ }).join("\n");
3379
+ const body = pending || interrupted ? `<p class="ask-verdict">${interrupted ? "\u672C\u8F6E\u5DF2\u4E2D\u65AD\uFF0C\u672A\u63D0\u4EA4\u56DE\u7B54" : "\u7B49\u5F85\u56DE\u7B54"}</p>
3380
+ <ul class="ask-question-list">
3381
+ ${questions.map((q) => `<li class="ask-list-item">${esc(q.question)}</li>`).join("\n")}
3382
+ </ul>` : `<dl class="ask-list">
3383
+ ${items}
3384
+ </dl>`;
3385
+ return `<div class="ask-row" data-tool="ask_user_question" data-state="${state}">
3386
+ <details class="ask-disclosure">
3387
+ <summary><span class="ask-icon" aria-hidden="true"></span><span class="ask-title">\u63D0\u95EE</span><span class="ask-sep" aria-hidden="true"></span><span class="ask-summary">${esc(summaryText)}</span><span class="ask-chevron"></span></summary>
3388
+ <div class="ask-body">
3389
+ <div class="ask-card">
3390
+ ${body}
3391
+ </div>
3392
+ </div>
3393
+ </details>
3394
+ </div>`;
3395
+ }
2343
3396
  function toolSummary(block) {
2344
3397
  const fields = block.argsFields ?? [];
2345
3398
  const preferred = ["description", "command", "file_path", "path", "pattern", "query", "url", "name", "prompt", "code"];
@@ -2382,15 +3435,73 @@ function renderFiles(files) {
2382
3435
  }).join("");
2383
3436
  return `<div class="files">${cards}</div>`;
2384
3437
  }
3438
+ function renderImages(images) {
3439
+ if (!images.length) return "";
3440
+ const ids = [];
3441
+ const thumbs = images.map((img) => {
3442
+ const id = nextImageId();
3443
+ ids.push(id);
3444
+ const ratio = img.width > 0 ? img.height / img.width : 1;
3445
+ const w = img.width;
3446
+ const h = Math.max(1, Math.round(w * ratio));
3447
+ const alt = img.name ? esc(img.name) : "\u56FE\u7247";
3448
+ return `<a class="img-thumb" href="#${id}" title="${alt}"><img src="${img.thumb}" width="${w}" height="${h}" alt="${alt}" loading="lazy"></a>`;
3449
+ }).join("\n");
3450
+ const lightboxes = images.map((img, index) => {
3451
+ const src = img.full ?? img.thumb;
3452
+ const label = img.name ? esc(img.name) : `\u56FE\u7247 ${String(index + 1)}`;
3453
+ return `<div class="img-lightbox" id="${ids[index]}"><a class="lb-close" href="#img-closed" aria-label="\u5173\u95ED">\xD7</a><img src="${src}" alt="${label}"><div class="lb-caption">${label}</div></div>`;
3454
+ }).join("\n");
3455
+ return `<div class="images">
3456
+ ${thumbs}
3457
+ </div>
3458
+ ${lightboxes}`;
3459
+ }
3460
+ var imageCounter = 0;
3461
+ function nextImageId() {
3462
+ imageCounter += 1;
3463
+ return `img-${String(imageCounter)}`;
3464
+ }
3465
+ function renderDeliverables(block) {
3466
+ const lightboxes = [];
3467
+ const cards = block.files.map((f) => {
3468
+ const name = basename(f.path);
3469
+ const ext = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toUpperCase().slice(0, 8) : "FILE";
3470
+ const desc = f.description ? `<span class="dl-desc">${esc(f.description)}</span>` : "";
3471
+ const missing = f.imageMissing ? `<span class="dl-missing">${esc(f.imageMissing)}</span>` : "";
3472
+ const body = `<span class="dl-body"><span class="dl-name">${esc(name)}</span>${desc}${missing}</span>`;
3473
+ if (f.image) {
3474
+ const id = nextImageId();
3475
+ lightboxes.push(
3476
+ `<div class="img-lightbox" id="${esc(id)}"><a class="lb-close" href="#img-closed" aria-label="\u5173\u95ED">\xD7</a><img src="${f.image.full ?? f.image.thumb}" alt="${esc(name)}"><div class="lb-caption">${esc(name)}</div></div>`
3477
+ );
3478
+ return `<a class="dl-card dl-card-image" href="#${esc(id)}" title="${esc(f.path)}"><span class="dl-thumb"><img src="${f.image.thumb}" alt="${esc(name)}" loading="lazy"></span>${body}</a>`;
3479
+ }
3480
+ return `<div class="dl-card" title="${esc(f.path)}"><span class="dl-icon">${esc(ext)}</span>${body}</div>`;
3481
+ }).join("\n");
3482
+ return `<div class="deliverables">
3483
+ ${cards}
3484
+ </div>
3485
+ ${lightboxes.join("\n")}`;
3486
+ }
2385
3487
  function renderChanges(block) {
2386
3488
  const counts = `<span class="chg-added">+${block.added}</span><span class="chg-deleted">-${block.deleted}</span>`;
2387
3489
  const single = block.total === 1 ? block.files[0] : void 0;
2388
3490
  const title = single ? `\u5DF2\u7F16\u8F91 ${basename(single.display)}` : `\u5DF2\u7F16\u8F91 ${block.total} \u4E2A\u6587\u4EF6`;
2389
- const rows = block.files.map((f) => {
2390
- const stat = f.binary === true ? '<span class="chg-note">\u4E8C\u8FDB\u5236</span>' : f.oversized === true ? '<span class="chg-note">\u8FC7\u5927</span>' : `<span class="chg-added">+${f.added}</span><span class="chg-deleted">-${f.deleted}</span>`;
2391
- return `<li class="chg-row"><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></li>`;
3491
+ const uid = `diff-${changeCounter++}`;
3492
+ const drawers = [];
3493
+ const rows = block.files.map((f, index) => {
3494
+ const stat2 = f.binary === true ? '<span class="chg-note">\u4E8C\u8FDB\u5236</span>' : f.oversized === true ? '<span class="chg-note">\u8FC7\u5927</span>' : `<span class="chg-added">+${f.added}</span><span class="chg-deleted">-${f.deleted}</span>`;
3495
+ const diff = block.diffs?.get(index);
3496
+ if (!diff) {
3497
+ return `<li class="chg-row" data-no-diff><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat2}</span></li>`;
3498
+ }
3499
+ const id = `${uid}-${index}`;
3500
+ drawers.push(renderDiffDrawer(id, f, diff));
3501
+ return `<li class="chg-row"><a class="chg-link" href="#${esc(id)}"><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat2}</span></a></li>`;
2392
3502
  }).join("\n");
2393
3503
  const more = block.total > block.files.length ? `<li class="chg-row chg-more">\u53E6\u6709 ${block.total - block.files.length} \u4E2A\u6587\u4EF6\u672A\u5217\u51FA</li>` : "";
3504
+ const missingNote = block.files.length > 0 && drawers.length === 0 && block.diffs === void 0 ? '<p class="chg-note-line">diff \u660E\u7EC6\u672A\u968F\u4F1A\u8BDD\u4FDD\u7559\uFF08DSH \u91CD\u542F\u540E\u65E7\u4F1A\u8BDD\u7684\u6539\u52A8\u8BB0\u5F55\u4F1A\u4E22\u5931\uFF09\uFF0C\u53EA\u80FD\u770B\u5230\u589E\u5220\u884C\u6570\u3002</p>' : block.files.length > drawers.length ? '<p class="chg-note-line">\u90E8\u5206\u6587\u4EF6\u6CA1\u6709 diff \u660E\u7EC6\uFF0C\u70B9\u51FB\u65E0\u9884\u89C8\u3002</p>' : "";
2394
3505
  return `<details class="changes">
2395
3506
  <summary><span class="chg-title">${esc(title)}</span>${counts}</summary>
2396
3507
  <div class="chg-body">
@@ -2398,8 +3509,59 @@ function renderChanges(block) {
2398
3509
  ${rows}
2399
3510
  ${more}
2400
3511
  </ul>
3512
+ ${missingNote}
2401
3513
  </div>
2402
- </details>`;
3514
+ </details>
3515
+ ${drawers.join("\n")}`;
3516
+ }
3517
+ var changeCounter = 0;
3518
+ function renderDiffDrawer(id, file, diff) {
3519
+ const closeHref = "#diff-closed";
3520
+ let body;
3521
+ if (diff.kind === "binary") {
3522
+ body = '<p class="dif-empty">\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u65E0\u6CD5\u9010\u884C\u5BF9\u6BD4\u3002</p>';
3523
+ } else if (diff.kind === "oversized") {
3524
+ body = '<p class="dif-empty">\u6587\u4EF6\u8FC7\u5927\uFF0C\u672A\u505A\u9010\u884C\u5BF9\u6BD4\u3002</p>';
3525
+ } else if (!diff.hunks?.length) {
3526
+ body = diff.before === false ? '<p class="dif-empty">\u65B0\u589E\u6587\u4EF6\uFF08\u5185\u5BB9\u4E3A\u7A7A\u6216\u65E0\u6CD5\u5BF9\u6BD4\uFF09\u3002</p>' : diff.after === false ? '<p class="dif-empty">\u5220\u9664\u8BE5\u6587\u4EF6\uFF08\u5185\u5BB9\u4E3A\u7A7A\u6216\u65E0\u6CD5\u5BF9\u6BD4\uFF09\u3002</p>' : '<p class="dif-empty">\u4E24\u4FA7\u5185\u5BB9\u76F8\u540C\uFF0C\u6CA1\u6709\u5DEE\u5F02\u3002</p>';
3527
+ } else {
3528
+ body = renderHunks(diff.hunks, diff.coarse === true);
3529
+ }
3530
+ const stat2 = diff.kind === "text" ? `<span class="chg-added">+${file.added}</span><span class="chg-deleted">-${file.deleted}</span>` : "";
3531
+ return `<aside class="dif-drawer" id="${esc(id)}" role="dialog" aria-label="${esc(file.display)} \u7684\u6539\u52A8">
3532
+ <div class="dif-head">
3533
+ <span class="dif-path">${esc(file.display)}</span>
3534
+ <span class="dif-stat">${stat2}</span>
3535
+ <a class="dif-close" href="${closeHref}" aria-label="\u5173\u95ED">\xD7</a>
3536
+ </div>
3537
+ <div class="dif-body">
3538
+ ${body}
3539
+ </div>
3540
+ </aside>`;
3541
+ }
3542
+ function renderHunks(hunks, coarse) {
3543
+ const parts = [];
3544
+ for (const hunk of hunks) {
3545
+ let oldNo = hunk.oldStart;
3546
+ let newNo = hunk.newStart;
3547
+ const rows = hunk.lines.map((line) => {
3548
+ const mark = line.charAt(0);
3549
+ const text = line.slice(1);
3550
+ const isAdd = mark === "+";
3551
+ const isDel = mark === "-";
3552
+ const oldCell = isAdd ? "" : String(oldNo);
3553
+ const newCell = isDel ? "" : String(newNo);
3554
+ if (!isAdd) oldNo += 1;
3555
+ if (!isDel) newNo += 1;
3556
+ const kind = isAdd ? "add" : isDel ? "del" : "ctx";
3557
+ return `<tr class="dif-line" data-kind="${kind}"><td class="dif-no">${oldCell}</td><td class="dif-no">${newCell}</td><td class="dif-text"><span class="dif-mark">${esc(mark === " " ? "" : mark)}</span>${esc(text)}</td></tr>`;
3558
+ }).join("\n");
3559
+ parts.push(`<table class="dif-hunk"><tbody>
3560
+ ${rows}
3561
+ </tbody></table>`);
3562
+ }
3563
+ const note = coarse ? '<p class="dif-empty">\u9010\u884C\u5BF9\u6BD4\u8D85\u65F6\uFF0C\u4EE5\u4E0B\u6309\u6574\u6587\u4EF6\u66FF\u6362\u5C55\u793A\u3002</p>' : "";
3564
+ return `${note}${parts.join("\n")}`;
2403
3565
  }
2404
3566
  function basename(name) {
2405
3567
  const parts = name.split(/[\\/]/).filter(Boolean);
@@ -2487,7 +3649,7 @@ function filenameStamp(epochMs, timeZone) {
2487
3649
  }
2488
3650
 
2489
3651
  // src/host/index.ts
2490
- var VERSION = "0.5.1";
3652
+ var VERSION = "0.7.0";
2491
3653
  function exportSession(input) {
2492
3654
  const preset = input.preset ?? "conversation";
2493
3655
  const opts = shareOptions(preset, input.options ?? {});
@@ -2509,7 +3671,9 @@ function exportSession(input) {
2509
3671
  redactions: redacted.stats.total,
2510
3672
  redacted: opts.redact,
2511
3673
  exportedAt,
2512
- warnings
3674
+ warnings,
3675
+ finalAnswerOnly: opts.include.finalAnswerOnly,
3676
+ foldProcess: opts.include.foldProcess
2513
3677
  });
2514
3678
  return {
2515
3679
  html: render.html,
@@ -2522,6 +3686,9 @@ function exportSession(input) {
2522
3686
  };
2523
3687
  }
2524
3688
 
3689
+ // src/host/session.ts
3690
+ import { readFile, stat } from "node:fs/promises";
3691
+
2525
3692
  // src/host/contract.ts
2526
3693
  var PRESETS = ["conversation", "process", "full"];
2527
3694
  var ContractError = class extends Error {
@@ -2565,7 +3732,8 @@ var INCLUDE_KEYS = [
2565
3732
  "toolResultChars",
2566
3733
  "files",
2567
3734
  "deepResearch",
2568
- "modelMeta"
3735
+ "modelMeta",
3736
+ "images"
2569
3737
  ];
2570
3738
  var REQUEST_KEYS = [
2571
3739
  "sessionId",
@@ -2622,6 +3790,8 @@ function parseRenderRequest(raw) {
2622
3790
  if (argChars !== void 0) include.toolArgumentChars = argChars;
2623
3791
  const resChars = optionalCount("include", raw.include, "toolResultChars", MAX_ARG_CHARS);
2624
3792
  if (resChars !== void 0) include.toolResultChars = resChars;
3793
+ const images = optionalBoolean("include", raw.include, "images");
3794
+ if (images !== void 0) include.images = images;
2625
3795
  }
2626
3796
  const redact2 = optionalBoolean("\u8BF7\u6C42", raw, "redact");
2627
3797
  const redactEmail = optionalBoolean("\u8BF7\u6C42", raw, "redactEmail");
@@ -2681,7 +3851,24 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
2681
3851
  if (truncatedEvents.length < events.length) {
2682
3852
  warnings.push(`\u4F1A\u8BDD\u4E8B\u4EF6\u8FC7\u591A\uFF0C\u4EC5\u5BFC\u51FA\u524D ${MAX_EVENTS} \u6761\uFF08\u5171 ${events.length} \u6761\uFF09`);
2683
3853
  }
2684
- const changes = collectChanges(ctx, request.sessionId, truncatedEvents);
3854
+ const changes = await collectChanges(ctx, request.sessionId, truncatedEvents);
3855
+ const wantImages = request.include?.images !== false;
3856
+ let images = [];
3857
+ let deliverableImages = /* @__PURE__ */ new Map();
3858
+ if (wantImages) {
3859
+ const preview = project(truncatedEvents, {});
3860
+ const refs = collectImageRefs(preview);
3861
+ if (refs.length) images = await collectImages(ctx, refs);
3862
+ const deliverableBlocks = [...iterDeliverables(preview)];
3863
+ if (deliverableBlocks.length) {
3864
+ await attachDeliverableImages(ctx, deliverableBlocks);
3865
+ for (const block of deliverableBlocks) {
3866
+ for (const file of block.files) {
3867
+ if (file.image) deliverableImages.set(file.path, file.image);
3868
+ }
3869
+ }
3870
+ }
3871
+ }
2685
3872
  const shareOptions2 = {};
2686
3873
  if (request.turns !== void 0) shareOptions2.turns = request.turns;
2687
3874
  if (request.include) shareOptions2.include = { ...presetInclude(request.preset), ...request.include };
@@ -2698,6 +3885,10 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
2698
3885
  projectOptions: {
2699
3886
  sessionId: request.sessionId,
2700
3887
  ...title ? { title } : {},
3888
+ // images 是数组,projectOptions.images 要的是 Map —— 这里必须转换。
3889
+ // 直接传数组会让 project 里的 imageMap.get() 抛 TypeError。
3890
+ ...images.length ? { images: new Map(images.map((i) => [i.key, i])) } : {},
3891
+ ...deliverableImages.size ? { deliverableImages } : {},
2701
3892
  ...changes.size ? { changes } : {}
2702
3893
  },
2703
3894
  meta: { timeZone },
@@ -2803,7 +3994,7 @@ function toRawEvents(snapshot) {
2803
3994
  }
2804
3995
  return out;
2805
3996
  }
2806
- function collectChanges(ctx, sessionId, events) {
3997
+ async function collectChanges(ctx, sessionId, events) {
2807
3998
  const out = /* @__PURE__ */ new Map();
2808
3999
  const service = ctx.workspaceChanges;
2809
4000
  if (!service) return out;
@@ -2819,23 +4010,259 @@ function collectChanges(ctx, sessionId, events) {
2819
4010
  continue;
2820
4011
  }
2821
4012
  if (!summary || !Array.isArray(summary.files)) continue;
4013
+ const files = summary.files.map((f) => ({
4014
+ path: f.path,
4015
+ display: f.display,
4016
+ added: f.added,
4017
+ deleted: f.deleted,
4018
+ ...f.binary === true ? { binary: true } : {},
4019
+ ...f.oversized === true ? { oversized: true } : {}
4020
+ }));
4021
+ const diffs = await collectDiffs(ctx, service, sessionId, seq, files.length);
2822
4022
  out.set(seq, {
2823
4023
  kind: "changes",
2824
- files: summary.files.map((f) => ({
2825
- path: f.path,
2826
- display: f.display,
2827
- added: f.added,
2828
- deleted: f.deleted,
2829
- ...f.binary === true ? { binary: true } : {},
2830
- ...f.oversized === true ? { oversized: true } : {}
2831
- })),
4024
+ files,
2832
4025
  total: summary.total,
2833
4026
  added: summary.added,
2834
- deleted: summary.deleted
4027
+ deleted: summary.deleted,
4028
+ ...diffs.size ? { diffs } : {}
2835
4029
  });
2836
4030
  }
2837
4031
  return out;
2838
4032
  }
4033
+ var DIFF_CONCURRENCY = 4;
4034
+ async function collectDiffs(ctx, service, sessionId, seq, count) {
4035
+ const out = /* @__PURE__ */ new Map();
4036
+ if (count === 0) return out;
4037
+ const take = async (index) => {
4038
+ const controller = new AbortController();
4039
+ try {
4040
+ const diff = await service.diff(sessionId, seq, index, controller.signal);
4041
+ if (!diff) return;
4042
+ const file = { kind: diff.kind };
4043
+ if (diff.kind === "text") {
4044
+ if (diff.before !== void 0) file.before = diff.before;
4045
+ if (diff.after !== void 0) file.after = diff.after;
4046
+ if (diff.coarse === true) file.coarse = true;
4047
+ file.hunks = (diff.hunks ?? []).map((h) => ({
4048
+ oldStart: h.oldStart,
4049
+ oldLines: h.oldLines,
4050
+ newStart: h.newStart,
4051
+ newLines: h.newLines,
4052
+ lines: Array.isArray(h.lines) ? h.lines.map((l) => String(l)) : []
4053
+ }));
4054
+ }
4055
+ out.set(index, file);
4056
+ } catch (error) {
4057
+ ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6 diff \u5931\u8D25\uFF08seq=%s index=%s\uFF09\uFF1A%s", seq, index, String(error));
4058
+ }
4059
+ };
4060
+ let next = 0;
4061
+ const workers = [];
4062
+ for (let w = 0; w < Math.min(DIFF_CONCURRENCY, count); w += 1) {
4063
+ workers.push((async () => {
4064
+ for (; ; ) {
4065
+ const index = next;
4066
+ next += 1;
4067
+ if (index >= count) return;
4068
+ await take(index);
4069
+ }
4070
+ })());
4071
+ }
4072
+ await Promise.all(workers);
4073
+ return out;
4074
+ }
4075
+ function collectImageRefs(model) {
4076
+ const seen = /* @__PURE__ */ new Set();
4077
+ const out = [];
4078
+ const push = (ref) => {
4079
+ if (!ref || seen.has(ref.attachmentId)) return;
4080
+ seen.add(ref.attachmentId);
4081
+ out.push(ref);
4082
+ };
4083
+ for (const turn of model.turns) {
4084
+ if (turn.user) {
4085
+ for (const block of turn.user.blocks) {
4086
+ if (block.kind !== "files") continue;
4087
+ for (const f of block.files) push(f.image);
4088
+ }
4089
+ }
4090
+ for (const msg of turn.assistants) {
4091
+ for (const block of msg.blocks) {
4092
+ if (block.kind === "tool") {
4093
+ for (const ref of block.resultImages ?? []) push(ref);
4094
+ }
4095
+ if (block.kind === "images") {
4096
+ for (const ref of block.imageRefs ?? []) push(ref);
4097
+ }
4098
+ }
4099
+ }
4100
+ }
4101
+ return out;
4102
+ }
4103
+ function* iterDeliverables(model) {
4104
+ for (const turn of model.turns) {
4105
+ for (const msg of turn.assistants) {
4106
+ for (const block of msg.blocks) {
4107
+ if (block.kind === "deliverables") yield block;
4108
+ }
4109
+ }
4110
+ }
4111
+ }
4112
+ var DELIVERABLE_IMAGE_RE = /\.(png|jpe?g|webp|gif)$/i;
4113
+ var DELIVERABLE_IMAGE_MAX_BYTES = 8 * 1024 * 1024;
4114
+ async function attachDeliverableImages(ctx, blocks) {
4115
+ if (!blocks.length) return;
4116
+ const service = ctx.attachments;
4117
+ for (const block of blocks) {
4118
+ for (const file of block.files) {
4119
+ if (!DELIVERABLE_IMAGE_RE.test(file.path)) continue;
4120
+ try {
4121
+ const info = await stat(file.path);
4122
+ if (!info.isFile()) {
4123
+ file.imageMissing = "\u4E0D\u662F\u6587\u4EF6";
4124
+ continue;
4125
+ }
4126
+ if (info.size > DELIVERABLE_IMAGE_MAX_BYTES) {
4127
+ file.imageMissing = "\u6587\u4EF6\u8FC7\u5927\uFF08>8MB\uFF09\uFF0C\u672A\u5185\u5D4C";
4128
+ continue;
4129
+ }
4130
+ const bytes = await readFile(file.path);
4131
+ if (service) {
4132
+ const meta2 = probeImageSize(bytes);
4133
+ if (meta2) {
4134
+ const target = {
4135
+ width: THUMB_MAX_WIDTH,
4136
+ height: Math.max(1, Math.round(THUMB_MAX_WIDTH * (meta2.height / meta2.width))),
4137
+ maxBytes: THUMB_MAX_BYTES
4138
+ };
4139
+ try {
4140
+ const thumb = await service.readImageRequest(
4141
+ { attachmentId: `file:${file.path}`, mediaType: meta2.mediaType, bytes: bytes.length, width: meta2.width, height: meta2.height },
4142
+ target,
4143
+ new AbortController().signal
4144
+ );
4145
+ if (thumb?.data?.length) {
4146
+ file.image = {
4147
+ key: file.path,
4148
+ thumb: toDataUri(thumb.data, thumb.mediaType),
4149
+ width: thumb.width,
4150
+ height: thumb.height,
4151
+ thumbBytes: thumb.bytes,
4152
+ ...file.description ? { name: file.description } : {}
4153
+ };
4154
+ continue;
4155
+ }
4156
+ } catch {
4157
+ }
4158
+ }
4159
+ }
4160
+ const meta = probeImageSize(bytes);
4161
+ const mime = meta?.mediaType ?? (() => {
4162
+ const ext = DELIVERABLE_IMAGE_RE.exec(file.path)?.[1]?.toLowerCase();
4163
+ return ext === "jpg" || ext === "jpeg" ? "image/jpeg" : ext === "webp" ? "image/webp" : ext === "gif" ? "image/gif" : "image/png";
4164
+ })();
4165
+ file.image = {
4166
+ key: file.path,
4167
+ thumb: toDataUri(bytes, mime),
4168
+ width: meta?.width ?? 0,
4169
+ height: meta?.height ?? 0,
4170
+ thumbBytes: bytes.length,
4171
+ ...file.description ? { name: file.description } : {}
4172
+ };
4173
+ } catch (error) {
4174
+ file.imageMissing = "\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25";
4175
+ ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6\u4EA4\u4ED8\u56FE\u7247\u5931\u8D25\uFF08%s\uFF09\uFF1A%s", file.path, String(error));
4176
+ }
4177
+ }
4178
+ }
4179
+ }
4180
+ function probeImageSize(data) {
4181
+ if (data.length > 24 && data[0] === 137 && data[1] === 80) {
4182
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
4183
+ return { width: view.getUint32(16), height: view.getUint32(20), mediaType: "image/png" };
4184
+ }
4185
+ if (data.length > 10 && data[0] === 71 && data[1] === 73 && data[2] === 70) {
4186
+ const width = data[6] | data[7] << 8;
4187
+ const height = data[8] | data[9] << 8;
4188
+ return { width, height, mediaType: "image/gif" };
4189
+ }
4190
+ if (data.length > 4 && data[0] === 255 && data[1] === 216) {
4191
+ let i = 2;
4192
+ while (i < data.length - 9) {
4193
+ if (data[i] !== 255) {
4194
+ i += 1;
4195
+ continue;
4196
+ }
4197
+ const marker = data[i + 1];
4198
+ const length = data[i + 2] << 8 | data[i + 3];
4199
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
4200
+ const height = data[i + 5] << 8 | data[i + 6];
4201
+ const width = data[i + 7] << 8 | data[i + 8];
4202
+ return { width, height, mediaType: "image/jpeg" };
4203
+ }
4204
+ i += 2 + length;
4205
+ }
4206
+ }
4207
+ if (data.length > 30 && data[0] === 82 && data[1] === 73 && data[8] === 87) {
4208
+ return { width: 0, height: 0, mediaType: "image/webp" };
4209
+ }
4210
+ return void 0;
4211
+ }
4212
+ var THUMB_MAX_WIDTH = 320;
4213
+ var THUMB_MAX_BYTES = 48 * 1024;
4214
+ var FULL_IMAGE_BUDGET = 2 * 1024 * 1024;
4215
+ async function collectImages(ctx, refs) {
4216
+ const service = ctx.attachments;
4217
+ if (!service || !refs.length) return [];
4218
+ const out = [];
4219
+ let fullBudget = FULL_IMAGE_BUDGET;
4220
+ for (const ref of refs) {
4221
+ const full = { ...ref, bytes: ref.bytes ?? 0, width: ref.width ?? 0, height: ref.height ?? 0 };
4222
+ try {
4223
+ const longSide = THUMB_MAX_WIDTH;
4224
+ const ratio = full.width > 0 && full.height > 0 ? full.height / full.width : 1;
4225
+ const thumbTarget = {
4226
+ width: longSide,
4227
+ height: Math.max(1, Math.round(longSide * ratio)),
4228
+ maxBytes: THUMB_MAX_BYTES
4229
+ };
4230
+ const thumb = await service.readImageRequest(full, thumbTarget, new AbortController().signal);
4231
+ if (!thumb?.data?.length) continue;
4232
+ const thumbUri = toDataUri(thumb.data, thumb.mediaType);
4233
+ const image = {
4234
+ key: ref.attachmentId,
4235
+ thumb: thumbUri,
4236
+ width: thumb.width,
4237
+ height: thumb.height,
4238
+ thumbBytes: thumb.bytes
4239
+ };
4240
+ if (ref.name) image.name = ref.name;
4241
+ if (fullBudget > 0 && full.bytes > 0 && full.bytes <= fullBudget) {
4242
+ try {
4243
+ const fullImage = await service.readImageRequest(full, {
4244
+ width: full.width || full.bytes,
4245
+ height: full.height || full.bytes,
4246
+ maxBytes: full.bytes
4247
+ }, new AbortController().signal);
4248
+ if (fullImage?.data?.length && fullImage.bytes <= fullBudget) {
4249
+ image.full = toDataUri(fullImage.data, fullImage.mediaType);
4250
+ image.fullBytes = fullImage.bytes;
4251
+ fullBudget -= fullImage.bytes;
4252
+ }
4253
+ } catch {
4254
+ }
4255
+ }
4256
+ out.push(image);
4257
+ } catch (error) {
4258
+ ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6\u56FE\u7247\u5931\u8D25\uFF08%s\uFF09\uFF1A%s", ref.attachmentId, String(error));
4259
+ }
4260
+ }
4261
+ return out;
4262
+ }
4263
+ function toDataUri(data, mediaType) {
4264
+ return `data:${mediaType};base64,${Buffer.from(data).toString("base64")}`;
4265
+ }
2839
4266
  function defaultTimeZone() {
2840
4267
  try {
2841
4268
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -2861,12 +4288,19 @@ function createHandlers(ctx, options = {}) {
2861
4288
  };
2862
4289
  }
2863
4290
  export {
4291
+ FULL_IMAGE_BUDGET,
2864
4292
  MAX_EVENTS,
2865
4293
  MAX_HTML_BYTES,
4294
+ THUMB_MAX_WIDTH,
4295
+ attachDeliverableImages,
2866
4296
  capabilitiesForRequest,
2867
4297
  collectChanges,
4298
+ collectImageRefs,
4299
+ collectImages,
2868
4300
  createHandlers,
4301
+ probeImageSize,
2869
4302
  renderForRequest,
4303
+ toDataUri,
2870
4304
  toRawEvents,
2871
4305
  turnSummariesForRequest
2872
4306
  };