dsh-share-html 0.6.0 → 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/README.md CHANGED
@@ -4,38 +4,112 @@
4
4
 
5
5
  存档复盘、交付会话、贴进 wiki,都不用再截图拼接。
6
6
 
7
- ![导出的 HTML 效果](assets/screenshot-export.png)
7
+ ---
8
8
 
9
- ## 为什么用它
9
+ ## 它解决什么问题
10
10
 
11
- - **单文件、真离线** —— 产物里零 `<script>`、零外链、零网络请求。发邮件、传网盘、放进任何地方都能打开。
12
- - **观感对齐 DSH** —— 不是自己画一套样式,而是把 DSH 主题包的设计令牌抽成字面值内联进去,浅色/深色跟随系统。
13
- - **按需裁剪** —— 三档粒度:只要问答、带上思考与工具调用、或连工具结果全文一起导出。
14
- - **默认脱敏** —— API Key、令牌、私钥、邮箱、内网 IP 自动打码,支持不可逆哈希。
15
- - **零依赖安装** —— 发布物是预构建 JS,装的时候不需要构建,也不需要批准安装脚本。
11
+ 日常用 DSH 排查问题、做分析、写方案,结果往往散在会话里。要把一次会话留存或交付出去时,常见做法都不太合适:
16
12
 
17
- ## 安装
13
+ | 常见做法 | 问题 |
14
+ |---|---|
15
+ | **截图** | 长会话要拼十几张图,还截不到折叠内容 |
16
+ | **复制粘贴** | Markdown 粘出去格式全丢,表格和代码块散架 |
17
+ | **共享会话链接** | 查看方也得登录 DSH,还得有对应权限 |
18
+
19
+ 装了本插件,点一下「分享」,拿到**一个 `.html` 文件**:
20
+
21
+ - 可以归档,也可以直接发出去,**双击就能打开**
22
+ - 对方**不用装任何东西,不用联网**
23
+ - 排版、深浅色、代码高亮,跟原会话一模一样
24
+ - API Key、邮箱、内网 IP **默认自动打码**
25
+
26
+ ---
27
+
28
+ ## 安装完是什么样
29
+
30
+ 装好并**重启 `dsh web`** 后,打开任意会话,顶部工具栏会多出一个 **「分享」** 按钮:
31
+
32
+ ![分享按钮的位置](assets/install-share-button.png)
33
+
34
+ 点它就会弹出导出面板,选好参数后直接下载。
35
+
36
+ ---
37
+
38
+ ## 导出来长什么样
39
+
40
+ 导出的文件用浏览器打开就是这个样子。下面是真实导出(1 轮 / 9 条消息 / 13 次工具调用,选「完整」档):
41
+
42
+ ![导出效果](assets/screenshot-export.png)
43
+
44
+ 从这张图能看出几个关键设计:
45
+
46
+ | 位置 | 说明 |
47
+ |---|---|
48
+ | **顶部摘要** | 轮次、消息数、工具调用数、导出时间、粒度、脱敏处数 —— 一眼知道文件里有什么 |
49
+ | **右侧气泡** | 你的提问,原样保留,不解析 Markdown |
50
+ | **左侧正文** | 模型回答,排版与 DSH 一致 |
51
+ | **模型名** | 每条回答上方显示所用模型 |
52
+ | **`bash` / `read` / `grep` 行** | 工具调用折成一行,**默认收起**,点开才看参数与结果 |
53
+ | **表格与代码块** | Markdown 完整渲染,不丢格式 |
54
+
55
+ 工具调用默认收起这点很关键:上图那次会话有 13 次工具调用,收起后正文始终连贯可读;想查某个命令具体跑了什么,再点开那一行。
56
+
57
+ ### 一轮折叠:先看结论,需要时再展开
58
+
59
+ 每轮对话的顶部有一条折叠头,显示状态和耗时。默认收起 —— 长会话里你看到的始终是干净的正文:
60
+
61
+ ![折叠态:已完成,用时 14秒](assets/turn-collapsed.png)
62
+
63
+ 点一下,过程(思考、工具调用)就地展开,正文不动:
64
+
65
+ ![展开态:工具调用逐条列出](assets/turn-expanded.png)
66
+
67
+ ### 文件改动:点开右侧看 diff
68
+
69
+ 轮次末尾会有一张「已编辑 N 个文件 +x −y」的卡片:
70
+
71
+ ![改动卡片](assets/diff-drawer-closed.png)
72
+
73
+ 点文件名,右侧滑出改动抽屉,逐行显示增删:
18
74
 
19
- > 完整安装指引(含排错、与同类插件的对比)见 **[INSTALL.md](INSTALL.md)**。
75
+ ![diff 抽屉](assets/diff-drawer-open.png)
20
76
 
77
+ 抽屉是纯 CSS `:target` 实现的 —— **没有一行 JavaScript**,所以离线打开、进企业邮件网关都不受影响。
78
+
79
+ 想看完整一屏的效果:
80
+
81
+ <details>
82
+ <summary>展开查看整页(1280 × 3800)</summary>
83
+
84
+ <br>
85
+
86
+ <img src="assets/screenshot-export-full.png" alt="整页效果" width="760">
87
+
88
+ </details>
89
+
90
+ ---
91
+
92
+ ## 安装
21
93
 
22
94
  ```bash
23
- dsh plugin --profile web add dsh-share-html
95
+ dsh plugin --profile web add dsh-share-html --config.minimumReleaseAge=0
24
96
  ```
25
97
 
26
- 装完**重启 `dsh web`**,打开任意会话,header 上会出现「分享」按钮。
98
+ 装完**重启 `dsh web`**,打开任意会话,header 上就会出现「分享」按钮。
99
+
100
+ > **`--config.minimumReleaseAge=0` 建议带上。** pnpm 默认会跳过「刚发布不久」的版本,
101
+ > 不带这个参数可能装到上一个版本。详见 [INSTALL.md 的「装到旧版怎么办」](INSTALL.md)。
27
102
 
28
103
  <details>
29
104
  <summary>其他安装方式</summary>
30
105
 
31
- 从 GitHub Release(预构建 tarball,不依赖 npm):
106
+ **从 GitHub Release 装**(预构建 tarball,不依赖 npm):
32
107
 
33
108
  ```bash
34
- # 把 <版本> 换成 releases 页上的最新 tag,例如 v0.1.1
35
- dsh plugin --profile web add https://github.com/unknown3310v0/dsh-share-html/releases/download/<版本>/dsh-share-html-<版本去掉v>.tgz
109
+ dsh plugin --profile web add https://github.com/unknown3310v0/dsh-share-html/releases/latest/download/dsh-share-html.tgz
36
110
  ```
37
111
 
38
- 可以直接从源码:
112
+ **从源码装**:
39
113
 
40
114
  ```bash
41
115
  dsh plugin --profile web add github:unknown3310v0/dsh-share-html
@@ -43,6 +117,24 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
43
117
 
44
118
  </details>
45
119
 
120
+ 完整安装指引(含内网源、离线包、排错)见 **[INSTALL.md](INSTALL.md)**。
121
+
122
+ ---
123
+
124
+ ## 为什么用它
125
+
126
+ - **单文件、真离线** —— 产物里零 `<script>`、零外链、零网络请求。发邮件、传网盘、放进任何地方都能打开。
127
+ - **观感对齐 DSH** —— 不是自己画一套样式,而是把 DSH 主题包的设计令牌抽成字面值内联进去,浅色/深色跟随系统。
128
+ - **按需裁剪** —— 三档粒度:只要问答、带上思考与工具调用、或连工具结果全文一起导出。
129
+ - **默认脱敏** —— API Key、令牌、私钥、邮箱、内网 IP 自动打码,支持不可逆哈希。
130
+ - **零依赖安装** —— 发布物是预构建 JS,装的时候不需要构建,也不需要批准安装脚本。
131
+
132
+ ### 和同类 HTML 分享插件比
133
+
134
+ 同类插件大多带 `<script>` 或引 CDN 资源,本插件两者都没有 —— 这不只是"更快",而是决定了文件能不能进得去:邮件网关、内网文档系统、终端安全软件都会拦带脚本的 HTML 附件。详细对比见 [INSTALL.md](INSTALL.md)。
135
+
136
+ ---
137
+
46
138
  ## 使用
47
139
 
48
140
  点会话 header 的「分享」按钮,弹窗里选粒度、勾选要包含的内容,右侧实时预览,确认后下载。
@@ -66,7 +158,7 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
66
158
  | **思考过程** | 完全看不到模型推理 | 折叠的「思考过程」块,点开可见推理原文 |
67
159
  | **工具调用** | 整段工具交互消失 | 折叠的「工具名 + 参数摘要」 |
68
160
  | **工具结果** | 只留一行摘要(`共 3 行 / 52 字符`) | 结果正文全文 |
69
- | **附件** | 不显示文件条目 | 文件名 + 类型 + 大小(不含内容)|
161
+ | **附件** | 不显示文件条目 | 文件名 + 类型 + 大小(不含内容) |
70
162
  | **模型信息** | 消息头部不显示模型名 | 消息头部左侧显示模型名 |
71
163
 
72
164
  > **关于「检索结果」和「深度研究」**:这两个开关曾经存在,v0.3.1 起已从界面上移除。
@@ -75,19 +167,6 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
75
167
  > 摆一个拨动后毫无变化的开关,比不摆更让人困惑,所以先收起;
76
168
  > 契约层仍然接受这两个字段(老客户端传过来不会报错),等 DSH 补上事件形态后加回界面即可。
77
169
 
78
- ### 想看三档的实际差别
79
-
80
- 打开 [示例对比页](docs/example-compare.html):同一段会话(排查订单服务超时)用三档各导一次,并排展示。
81
-
82
- 也可以单独打开:
83
-
84
- - [对话档](docs/example-conversation.html) —— 只有两轮问答
85
- - [过程档](docs/example-process.html) —— 多出思考、工具调用、附件;工具结果只剩一行摘要
86
- - [完整档](docs/example-full.html) —— 工具结果全文,消息头带模型名
87
-
88
- > 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
89
- > 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
90
-
91
170
  ### 选择轮次
92
171
 
93
172
  会话很长时,可以只导出其中几轮。展开「导出轮次」后按轮勾选:
@@ -113,14 +192,31 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
113
192
 
114
193
  关闭脱敏时,产物 meta 与页脚都会标记 `unredacted`,并且在弹窗里需要二次确认。
115
194
 
195
+ ### 想看三档的实际差别
196
+
197
+ 打开 **[示例对比页](docs/example-compare.html)**:同一段会话(排查订单服务超时)用三档各导一次,并排展示。
198
+
199
+ 也可以单独打开:
200
+
201
+ - [对话档](docs/example-conversation.html) —— 只有两轮问答
202
+ - [过程档](docs/example-process.html) —— 多出思考、工具调用、附件;工具结果只剩一行摘要
203
+ - [完整档](docs/example-full.html) —— 工具结果全文,消息头带模型名
204
+
205
+ > 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
206
+ > 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
207
+
208
+ ---
209
+
116
210
  ## 产物长什么样
117
211
 
118
212
  - 单个 `.html` 文件,文件名 `share-{标题slug}-{id8}-{yyyymmdd-HHmm}.html`
119
213
  - 无 `<script>`、无 `<link>`、无 `<img>` 外链
120
214
  - 深浅主题跟随系统偏好
121
- - 文件附件只显示名称/类型/大小,不含字节内容
215
+ - 文件附件只显示名称 / 类型 / 大小,不含字节内容
122
216
  - 每轮末尾的「已编辑 N 个文件 +x −y」摘要可展开查看逐文件行数(受上面的限制影响)
123
217
 
218
+ ---
219
+
124
220
  ## 已知限制
125
221
 
126
222
  - **仅 Web**:`dsh.client.platform` 为 `web`,暂不支持其他端。
@@ -128,12 +224,14 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
128
224
  - **体积**:「完整」档产物中约 90% 是工具结果原文(这本就是该档的定义)。几十轮带大量工具调用的会话可到数百 KB;只要结论请选「对话」档。
129
225
  - **文件改动摘要受限于 Host 内存**:DSH 的 `workspace/changes` 事件只记录轮次号,改动明细缓存在 Host 进程内存里。重启 DSH 后再导出旧会话,这一块拿不到(此时不显示,而不是显示成「没有改动」)。
130
226
 
227
+ ---
228
+
131
229
  ## 开发
132
230
 
133
231
  ```bash
134
232
  npm install # 只有一个 devDependency:esbuild
135
233
  npm run build # 把 src/host 打包成 lib/kernel.js
136
- npm test # 211 条测试
234
+ npm test # 230 条测试
137
235
  ```
138
236
 
139
237
  测试只需 Node 内置 `node:test`,但 `build` 需要 esbuild。
@@ -156,21 +254,28 @@ lib/
156
254
  index.js Host 半:注册 /api/share-html/* 路由
157
255
  kernel.js 构建产物(勿手改)
158
256
  client.js 浏览器半:header 按钮 + 弹窗 + 下载
159
- test/ 197 条测试
257
+ test/ 230 条测试
160
258
  scripts/
161
259
  build.mjs 内核打包
162
260
  snapshot-tokens.mjs 从 DSH 主题包抽取设计令牌
163
261
  replay.ts 拿真实会话日志回放
262
+ publish-npm.sh 发 npm 并校验 registry 上的包
263
+ release.sh 建 GitHub Release,资产取 npm 上那一份
164
264
  ```
165
265
 
166
266
  ⚠️ `lib/kernel.js` 是构建产物,改逻辑要改 `src/host/` 再重新 build。
167
267
 
168
268
  </details>
169
269
 
270
+ ---
271
+
170
272
  ## 相关文档
171
273
 
274
+ - [INSTALL.md](./INSTALL.md) —— 安装指引:三种装法、排错、版本说明
172
275
  - [DESIGN.md](./DESIGN.md) —— 设计文档:需求、数据模型、阶段划分
173
- - [HANDOFF.md](./HANDOFF.md) —— 发布交接:路线、市场规则、已知缺口
276
+ - [DEV.md](./DEV.md) —— 本地开发、热更新、发版流程
277
+ - [CONVENTIONS.md](./CONVENTIONS.md) —— 提交与发版约定、踩坑记录
278
+ - [KNOWN-ISSUES.md](./KNOWN-ISSUES.md) —— 已知问题清单
174
279
 
175
280
  ## 许可
176
281
 
package/lib/index.js CHANGED
@@ -44,9 +44,23 @@ export function apply(ctx) {
44
44
  workspaceChanges = undefined
45
45
  }
46
46
 
47
+ // attachments 同样是可选服务。导出时用它把图片重编码成缩略图 ——
48
+ // DSH 内部用 sharp 做解码/缩放/压缩,插件因此不需要任何图像库依赖。
49
+ // 漏接这个服务会让所有图片退化成 IMG 文字卡片(曾经就是这样)。
50
+ let attachments
51
+ try {
52
+ attachments = typeof ctx.get === "function" ? ctx.get("attachments") : undefined
53
+ } catch {
54
+ attachments = undefined
55
+ }
56
+ if (!attachments) {
57
+ log("[dsh-share-html] attachments service unavailable — images will render as placeholders")
58
+ }
59
+
47
60
  const handlers = createHandlers({
48
61
  sessionQuery: ctx.sessionQuery,
49
62
  ...(workspaceChanges ? { workspaceChanges } : {}),
63
+ ...(attachments ? { attachments } : {}),
50
64
  ...(logger ? { logger } : {}),
51
65
  })
52
66
 
package/lib/kernel.js CHANGED
@@ -141,6 +141,8 @@ function project(events, options = {}) {
141
141
  const text = partsToText(msg.content);
142
142
  const isError = msg.isError === true || asRecord(data)?.isError === true;
143
143
  applyResult(block, text, isError, options.maxToolResultChars);
144
+ const resultImages = extractImages(msg.content);
145
+ if (resultImages.length) block.resultImages = resultImages;
144
146
  if (block.questions?.length) {
145
147
  const answers = parseAskedAnswers(text);
146
148
  if (answers.length) block.answers = answers;
@@ -226,6 +228,51 @@ function project(events, options = {}) {
226
228
  for (const turn of turns) {
227
229
  turn.answerStep = latestAnswerStep(turn);
228
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
+ }
229
276
  const model = {
230
277
  id: sessionId ?? "",
231
278
  title: options.title?.trim() || sessionTitle || DEFAULT_TITLE,
@@ -259,6 +306,8 @@ function projectUserMessage(msg, at, dropped) {
259
306
  };
260
307
  const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
261
308
  if (bytes !== void 0) meta.bytes = bytes;
309
+ const image = asImageRef(a);
310
+ if (image) meta.image = image;
262
311
  files.push(meta);
263
312
  break;
264
313
  }
@@ -312,6 +361,11 @@ function collectAssistantBlocks(msg, target, dropped) {
312
361
  break;
313
362
  }
314
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
+ }
315
369
  dropped.attachmentBytes += 1;
316
370
  break;
317
371
  }
@@ -346,6 +400,34 @@ function applyResult(block, text, isError, maxChars) {
346
400
  }
347
401
  block.result = value;
348
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
+ }
349
431
  function partsToText(content) {
350
432
  if (typeof content === "string") return content;
351
433
  if (!Array.isArray(content)) return "";
@@ -556,7 +638,8 @@ function presetInclude(preset) {
556
638
  deepResearch: false,
557
639
  modelMeta: false,
558
640
  finalAnswerOnly: true,
559
- foldProcess: false
641
+ foldProcess: false,
642
+ images: true
560
643
  };
561
644
  case "process":
562
645
  return {
@@ -572,7 +655,8 @@ function presetInclude(preset) {
572
655
  deepResearch: true,
573
656
  modelMeta: false,
574
657
  finalAnswerOnly: false,
575
- foldProcess: false
658
+ foldProcess: false,
659
+ images: true
576
660
  };
577
661
  case "full":
578
662
  return {
@@ -587,7 +671,8 @@ function presetInclude(preset) {
587
671
  deepResearch: true,
588
672
  modelMeta: true,
589
673
  finalAnswerOnly: false,
590
- foldProcess: true
674
+ foldProcess: true,
675
+ images: true
591
676
  };
592
677
  }
593
678
  }
@@ -669,6 +754,8 @@ function pruneBlock(block, include, stats) {
669
754
  case "files":
670
755
  if (!include.files) return null;
671
756
  return { kind: "files", files: block.files };
757
+ case "images":
758
+ return include.images ? block : null;
672
759
  case "deliverables":
673
760
  return block;
674
761
  case "changes":
@@ -676,18 +763,10 @@ function pruneBlock(block, include, stats) {
676
763
  case "research":
677
764
  return include.deepResearch ? block : null;
678
765
  case "tool": {
679
- if (block.questions?.length) {
680
- const out2 = { kind: "tool", name: block.name, status: block.status };
681
- if (block.callId) out2.callId = block.callId;
682
- out2.questions = block.questions;
683
- if (block.answers) out2.answers = block.answers;
684
- return out2;
685
- }
766
+ const base = { ...block };
767
+ if (block.questions?.length) return base;
686
768
  if (!include.toolCalls) return null;
687
- const out = { kind: "tool", name: block.name, status: block.status };
688
- if (block.callId) out.callId = block.callId;
689
- if (block.questions) out.questions = block.questions;
690
- if (block.answers) out.answers = block.answers;
769
+ const out = { ...base };
691
770
  if (block.args !== void 0) {
692
771
  const cut = clip(block.args, include.toolArgumentChars);
693
772
  out.args = cut.text;
@@ -867,13 +946,19 @@ function redactBlock(block, options, hits) {
867
946
  kind: "files",
868
947
  files: block.files.map((f) => ({ ...f, name: redactText(f.name, options, hits) }))
869
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
+ };
870
954
  case "deliverables":
871
955
  return {
872
956
  ...block,
873
- files: block.files.map((f) => ({
874
- path: redactText(f.path, options, hits),
875
- ...f.description !== void 0 ? { description: redactText(f.description, options, hits) } : {}
876
- }))
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
+ })
877
962
  };
878
963
  case "changes":
879
964
  return {
@@ -2366,6 +2451,98 @@ details.turn-process:not([open]) + .turn-flow > .turn-run { display: none; }
2366
2451
  gap: 4px;
2367
2452
  }
2368
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
+
2369
2546
  /* ---------- \u4EA4\u4ED8\u6587\u4EF6\u5361\u7247\uFF08deliverables/presented\uFF09 ---------- */
2370
2547
 
2371
2548
  .deliverables {
@@ -2425,6 +2602,41 @@ details.turn-process:not([open]) + .turn-flow > .turn-run { display: none; }
2425
2602
  line-height: 16px;
2426
2603
  }
2427
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
+
2428
2640
  /* ---------- \u6298\u53E0\u5757\uFF08\u601D\u8003 / \u5DE5\u5177 / \u68C0\u7D22 / \u6DF1\u7814\uFF09 ---------- */
2429
2641
 
2430
2642
  details.process {
@@ -2833,8 +3045,11 @@ function renderHtml(model, meta = {}) {
2833
3045
  const deliverableBlocks = msg.blocks.filter(
2834
3046
  (b) => b.kind === "deliverables"
2835
3047
  );
3048
+ const assistantImages = msg.blocks.filter(
3049
+ (b) => b.kind === "images" && b.images.length > 0
3050
+ );
2836
3051
  const others = msg.blocks.filter(
2837
- (b) => b.kind !== "text" && b.kind !== "reasoning" && b.kind !== "tool" && b.kind !== "changes" && b.kind !== "deliverables"
3052
+ (b) => b.kind !== "text" && b.kind !== "reasoning" && b.kind !== "tool" && b.kind !== "changes" && b.kind !== "deliverables" && b.kind !== "images"
2838
3053
  );
2839
3054
  const asks = tools.filter((t) => t.questions !== void 0);
2840
3055
  const plainTools = tools.filter((t) => t.questions === void 0);
@@ -2855,6 +3070,10 @@ function renderHtml(model, meta = {}) {
2855
3070
  } else if (isAnswer) {
2856
3071
  flushRun();
2857
3072
  }
3073
+ for (const ib of assistantImages) {
3074
+ flushRun();
3075
+ rows.push({ kind: "answer", html: renderBlock(ib) });
3076
+ }
2858
3077
  for (const cb of changeBlocks) tailRows.push({ kind: "changes", html: renderBlock(cb) });
2859
3078
  for (const db of deliverableBlocks) tailRows.push({ kind: "changes", html: renderBlock(db) });
2860
3079
  }
@@ -3038,16 +3257,23 @@ function formatDuration(ms) {
3038
3257
  }
3039
3258
  function renderUserMessage(msg) {
3040
3259
  const parts = [];
3041
- const fileBlocks = msg.blocks.filter((b) => b.kind === "files");
3042
3260
  const textBlocks = msg.blocks.filter((b) => b.kind === "text");
3043
- for (const block of fileBlocks) {
3044
- if (block.kind === "files") parts.push(renderFiles(block.files));
3045
- }
3261
+ const fileBlocks = msg.blocks.filter((b) => b.kind === "files");
3262
+ const imageBlocks = msg.blocks.filter((b) => b.kind === "images");
3046
3263
  for (const block of textBlocks) {
3047
3264
  if (block.kind === "text") {
3048
3265
  parts.push(`<div class="bubble">${esc(block.md)}</div>`);
3049
3266
  }
3050
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
+ }
3051
3277
  return `<article class="msg" data-role="user">
3052
3278
  ${parts.join("\n")}
3053
3279
  </article>`;
@@ -3080,6 +3306,8 @@ function renderBlock(block) {
3080
3306
  return renderChanges(block);
3081
3307
  case "deliverables":
3082
3308
  return renderDeliverables(block);
3309
+ case "images":
3310
+ return renderImages(block.images);
3083
3311
  }
3084
3312
  }
3085
3313
  function renderDetails(input) {
@@ -3121,10 +3349,12 @@ function renderTool(block) {
3121
3349
  body.push('<div class="trunc-note">\u4F1A\u8BDD\u5BFC\u51FA\u65F6\u8BE5\u8C03\u7528\u5C1A\u672A\u8FD4\u56DE</div>');
3122
3350
  }
3123
3351
  const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
3352
+ const imageHtml = block.resultImageData?.length ? renderImages(block.resultImageData) : "";
3124
3353
  return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
3125
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>
3126
3355
  <div class="process-body">
3127
3356
  ${body.join("\n")}
3357
+ ${imageHtml}
3128
3358
  </div>
3129
3359
  </details>`;
3130
3360
  }
@@ -3205,16 +3435,54 @@ function renderFiles(files) {
3205
3435
  }).join("");
3206
3436
  return `<div class="files">${cards}</div>`;
3207
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
+ }
3208
3465
  function renderDeliverables(block) {
3466
+ const lightboxes = [];
3209
3467
  const cards = block.files.map((f) => {
3210
3468
  const name = basename(f.path);
3211
3469
  const ext = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toUpperCase().slice(0, 8) : "FILE";
3212
3470
  const desc = f.description ? `<span class="dl-desc">${esc(f.description)}</span>` : "";
3213
- return `<div class="dl-card" title="${esc(f.path)}"><span class="dl-icon">${esc(ext)}</span><span class="dl-body"><span class="dl-name">${esc(name)}</span>${desc}</span></div>`;
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>`;
3214
3481
  }).join("\n");
3215
3482
  return `<div class="deliverables">
3216
3483
  ${cards}
3217
- </div>`;
3484
+ </div>
3485
+ ${lightboxes.join("\n")}`;
3218
3486
  }
3219
3487
  function renderChanges(block) {
3220
3488
  const counts = `<span class="chg-added">+${block.added}</span><span class="chg-deleted">-${block.deleted}</span>`;
@@ -3223,14 +3491,14 @@ function renderChanges(block) {
3223
3491
  const uid = `diff-${changeCounter++}`;
3224
3492
  const drawers = [];
3225
3493
  const rows = block.files.map((f, index) => {
3226
- 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>`;
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>`;
3227
3495
  const diff = block.diffs?.get(index);
3228
3496
  if (!diff) {
3229
- return `<li class="chg-row" data-no-diff><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></li>`;
3497
+ return `<li class="chg-row" data-no-diff><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat2}</span></li>`;
3230
3498
  }
3231
3499
  const id = `${uid}-${index}`;
3232
3500
  drawers.push(renderDiffDrawer(id, f, diff));
3233
- return `<li class="chg-row"><a class="chg-link" href="#${esc(id)}"><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></a></li>`;
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>`;
3234
3502
  }).join("\n");
3235
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>` : "";
3236
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>' : "";
@@ -3259,11 +3527,11 @@ function renderDiffDrawer(id, file, diff) {
3259
3527
  } else {
3260
3528
  body = renderHunks(diff.hunks, diff.coarse === true);
3261
3529
  }
3262
- const stat = diff.kind === "text" ? `<span class="chg-added">+${file.added}</span><span class="chg-deleted">-${file.deleted}</span>` : "";
3530
+ const stat2 = diff.kind === "text" ? `<span class="chg-added">+${file.added}</span><span class="chg-deleted">-${file.deleted}</span>` : "";
3263
3531
  return `<aside class="dif-drawer" id="${esc(id)}" role="dialog" aria-label="${esc(file.display)} \u7684\u6539\u52A8">
3264
3532
  <div class="dif-head">
3265
3533
  <span class="dif-path">${esc(file.display)}</span>
3266
- <span class="dif-stat">${stat}</span>
3534
+ <span class="dif-stat">${stat2}</span>
3267
3535
  <a class="dif-close" href="${closeHref}" aria-label="\u5173\u95ED">\xD7</a>
3268
3536
  </div>
3269
3537
  <div class="dif-body">
@@ -3381,7 +3649,7 @@ function filenameStamp(epochMs, timeZone) {
3381
3649
  }
3382
3650
 
3383
3651
  // src/host/index.ts
3384
- var VERSION = "0.6.0";
3652
+ var VERSION = "0.7.0";
3385
3653
  function exportSession(input) {
3386
3654
  const preset = input.preset ?? "conversation";
3387
3655
  const opts = shareOptions(preset, input.options ?? {});
@@ -3418,6 +3686,9 @@ function exportSession(input) {
3418
3686
  };
3419
3687
  }
3420
3688
 
3689
+ // src/host/session.ts
3690
+ import { readFile, stat } from "node:fs/promises";
3691
+
3421
3692
  // src/host/contract.ts
3422
3693
  var PRESETS = ["conversation", "process", "full"];
3423
3694
  var ContractError = class extends Error {
@@ -3461,7 +3732,8 @@ var INCLUDE_KEYS = [
3461
3732
  "toolResultChars",
3462
3733
  "files",
3463
3734
  "deepResearch",
3464
- "modelMeta"
3735
+ "modelMeta",
3736
+ "images"
3465
3737
  ];
3466
3738
  var REQUEST_KEYS = [
3467
3739
  "sessionId",
@@ -3518,6 +3790,8 @@ function parseRenderRequest(raw) {
3518
3790
  if (argChars !== void 0) include.toolArgumentChars = argChars;
3519
3791
  const resChars = optionalCount("include", raw.include, "toolResultChars", MAX_ARG_CHARS);
3520
3792
  if (resChars !== void 0) include.toolResultChars = resChars;
3793
+ const images = optionalBoolean("include", raw.include, "images");
3794
+ if (images !== void 0) include.images = images;
3521
3795
  }
3522
3796
  const redact2 = optionalBoolean("\u8BF7\u6C42", raw, "redact");
3523
3797
  const redactEmail = optionalBoolean("\u8BF7\u6C42", raw, "redactEmail");
@@ -3578,6 +3852,23 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
3578
3852
  warnings.push(`\u4F1A\u8BDD\u4E8B\u4EF6\u8FC7\u591A\uFF0C\u4EC5\u5BFC\u51FA\u524D ${MAX_EVENTS} \u6761\uFF08\u5171 ${events.length} \u6761\uFF09`);
3579
3853
  }
3580
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
+ }
3581
3872
  const shareOptions2 = {};
3582
3873
  if (request.turns !== void 0) shareOptions2.turns = request.turns;
3583
3874
  if (request.include) shareOptions2.include = { ...presetInclude(request.preset), ...request.include };
@@ -3594,6 +3885,10 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
3594
3885
  projectOptions: {
3595
3886
  sessionId: request.sessionId,
3596
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 } : {},
3597
3892
  ...changes.size ? { changes } : {}
3598
3893
  },
3599
3894
  meta: { timeZone },
@@ -3777,6 +4072,197 @@ async function collectDiffs(ctx, service, sessionId, seq, count) {
3777
4072
  await Promise.all(workers);
3778
4073
  return out;
3779
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
+ }
3780
4266
  function defaultTimeZone() {
3781
4267
  try {
3782
4268
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -3802,12 +4288,19 @@ function createHandlers(ctx, options = {}) {
3802
4288
  };
3803
4289
  }
3804
4290
  export {
4291
+ FULL_IMAGE_BUDGET,
3805
4292
  MAX_EVENTS,
3806
4293
  MAX_HTML_BYTES,
4294
+ THUMB_MAX_WIDTH,
4295
+ attachDeliverableImages,
3807
4296
  capabilitiesForRequest,
3808
4297
  collectChanges,
4298
+ collectImageRefs,
4299
+ collectImages,
3809
4300
  createHandlers,
4301
+ probeImageSize,
3810
4302
  renderForRequest,
4303
+ toDataUri,
3811
4304
  toRawEvents,
3812
4305
  turnSummariesForRequest
3813
4306
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-share-html",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",