dsh-ppt 0.12.1 → 0.14.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/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@
4
4
 
5
5
  [历史英文记录](docs/CHANGELOG.en.md)
6
6
 
7
+ ## 0.14.0(2026-10-22)
8
+
9
+ - 成品页新增按需开启的 AI 预审与人机模拟答辩,复用宿主已有模型,不影响直接交付。
10
+ - 预审区分表达、逻辑与证据问题;引用必须匹配所提供的原文。仅表达建议可选中改稿,新增数字没有匹配来源时不提供采纳按钮。
11
+ - 采纳所选修改或备用问答页时另存副本,原稿保留,副本可撤销。旧修订的报告可查看,禁止继续调用和套用。
12
+ - 提供中英文配置、回答输入、取消与提前结束、报告历史和 Markdown 问答 / 材料清单。预审最多 3 次插件调用,答辩最多 5 题、6 次调用;失败不自动重试。
13
+ - 演练只发送选定页面的文字、图表数据、备注及用户补充材料,不带工具或图片文件。验收范围见 [0.14.0 验证记录](docs/validation-0.14.0.md)。
14
+ - PPT 工作台使用当前 DSH 的主题变量,修复深色主题下仍显示浅色面板的问题。
15
+
16
+ ## 0.13.0(2026-10-20)
17
+
18
+ - **设置面板体验**:新增 Ctrl/⌘+S 保存、Esc 取消或返回、Alt+←/→ 切换页面;HTML 预览 iframe 内同样生效。
19
+ - **未保存保护**:标题旁显示「未保存」徽标;刷新/关闭页面前提示;Esc 取消修改前先确认。
20
+ - **错误恢复**:错误提示旁新增「重试」按钮;空状态支持一键复制示例提示词。
21
+ - **无障碍**:补充 aria-busy、aria-keyshortcuts、role=status;焦点在 SELECT 上时不再劫持 Esc。
22
+ - 中英文案与 README 同步;131 项测试通过。
7
23
  ## 0.12.1(2026-10-20)
8
24
 
9
25
  - 修复 #4:记录 HTML / PPTX 的 SHA-256;检测外部修改或旧工程缺少记录时拒绝覆盖,新增「另存副本」与 `ppt_edit.saveAs`,原文件保留。副本从 JSON 重建,不导入 Office 手工修改。
package/README.en.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  Turn source material into an HTML slideshow, editable PPTX and a reusable project.
8
8
 
9
+ Optional **AI review** and **rehearsal** reuse models configured in DSH. Both are off by default: download the finished presentation directly, or explicitly start a bounded rehearsal. Compare proposed wording edits, save selected changes and backup Q&A slides to an undoable copy, and export Q&A with an evidence checklist. See [the rehearsal guide](docs/COACHING.md#english). AI suggestions are not fact checks.
10
+
9
11
  [![npm](https://img.shields.io/npm/v/dsh-ppt)](https://www.npmjs.com/package/dsh-ppt) [![downloads](https://raw.githubusercontent.com/STARDUSTLC666/dsh-suite/npm-downloads/assets/dsh-ppt-downloads.svg)](https://www.npmjs.com/package/dsh-ppt)
10
12
 
11
13
  Feedback and contributions are welcome: report [issues](https://github.com/STARDUSTLC666/dsh-ppt/issues) or submit [pull requests](https://github.com/STARDUSTLC666/dsh-ppt/pulls).
@@ -16,6 +18,7 @@ Feedback and contributions are welcome: report [issues](https://github.com/STARD
16
18
  - Edit text and images in Settings, reorder, duplicate or delete slides, and undo changes.
17
19
  - Check quality and optionally render the final PPTX as images or PDF.
18
20
  - Download Markdown speaker notes with each slide's current title and notes.
21
+ - Keyboard support: Ctrl/⌘+S save, Esc cancel or go back, Alt+←/→ switch slides; leaving with unsaved edits prompts first.
19
22
 
20
23
  ## Install
21
24
 
package/README.md CHANGED
@@ -16,6 +16,8 @@
16
16
  - 在设置页编辑文字和图片、调整顺序、复制或删除页面,并支持撤销。
17
17
  - 提供质量检查与可选的最终 PPTX 图片 / PDF 渲染。
18
18
  - 下载按页整理的 Markdown 讲稿,保留当前版本的标题与演讲备注。
19
+ - 可选 AI 预审与模拟答辩:复用 DSH 已配置模型,按需提问、比较改稿、另存可撤销副本,并导出问答与待补充材料清单。默认关闭,直接下载成品无需预审。
20
+ - 键盘操作:Ctrl/⌘+S 保存、Esc 取消或返回、Alt+←/→ 切换页面;有未保存修改时离开会提示。
19
21
 
20
22
  ## 安装
21
23
 
@@ -33,6 +35,8 @@ dsh plugin --profile desktop add dsh-ppt
33
35
 
34
36
  Office 中的修改不会同步回 JSON。插件检测到成品在外部修改,或旧工程没有校验记录时,会拒绝直接覆盖;可用面板「另存副本」或 `ppt_edit(saveAs:true)` 从 JSON 生成新文件,保留原成品。副本不包含 Office 手工修改。
35
37
 
38
+ 成品页下方可主动开启「AI 预审」或「模拟答辩」。前者根据材料模拟质疑与回答,后者由 AI 一次问一题、你来回答。可以先选模型、听众、强度和范围,再决定是否发送。具体流程与调用上限见[演练说明](docs/COACHING.md)。AI 建议不等于事实核验;普通成品生成、编辑和下载仍不要求配置模型。
39
+
36
40
  ## 依赖与配置
37
41
 
38
42
  普通生成不需要 Office。最终 PPTX 渲染使用可选的官方 LibreOffice Kit;依赖版本、字体环境和安装方法见使用说明。
@@ -0,0 +1,44 @@
1
+ # 可选 AI 预审与模拟答辩
2
+
3
+ 常规流程仍是「提供材料 → 生成 HTML、可编辑 PPTX 和工程 → 预览与下载」。演练不是交付前置条件,也不会自动启动。
4
+
5
+ 在「设置 → 演示文稿」打开工程,成品下载区下方有两个次级入口:
6
+
7
+ | 入口 | 适合做什么 | 调用上限 |
8
+ | --- | --- | --- |
9
+ | AI 预审 | AI 根据所给材料模拟质疑与回答,整理最多 5 条值得处理的问题 | 选择 1–3 轮,最多 3 次插件调用 |
10
+ | 模拟答辩 | AI 一次提一个问题,用户回答后获取反馈及下一题 | 选择 1–5 题,首次出题加每题反馈,最多 6 次插件调用 |
11
+
12
+ 先选择 DSH 已配置的文字模型、听众、温和 / 普通 / 严格的提问强度,以及整个工程或当前页。需要时粘贴补充材料,或导入 TXT / Markdown(最多 20,000 字符,文件最多 100 KB)。开始按钮说明将发送哪些内容和最多调用几次;点击后才发起生成。可用时优先选中生成工程时的模型;旧工程需要自行核对模型。
13
+
14
+ 只发送所选页面的文字、表格 / 图表数据、备注及主动提供的补充材料,不发送图片文件、密钥或工作区文件。模型调用不附带文件、终端等工具。请在开始前检查输入是否适合交给所选模型服务。供应商自身的重试和计费规则仍然适用,次数上限指插件主动发起的调用。
15
+
16
+ ## 如何使用结果
17
+
18
+ - **表达建议**:查看对应页、材料原文和修改前后比较,自行勾选采纳。程序核对原文引用,并阻止缺少数字来源的表达改稿;这不证明内容真实,也不能保证 AI 保留了所有含义。
19
+ - **逻辑问题与证据缺口**:作为待办整理,不会由 AI 自动填入杜撰的实验、数据或引用。请补充真实材料后重跑。
20
+ - **模拟答辩**:输入你的回答,再提交下一步。难度只影响提问方式,不能预测真实评委或客户会如何提问。
21
+ - **备用问答页**:自行选中需要的问答,追加到新副本末尾。页面及备注标明来自演练、需要核对;不会默默扩充原稿。
22
+ - **下载问答与材料清单**:输出 Markdown,包含问题、回答、建议、来源、缺口及模型和调用次数,不导出全部补充材料。
23
+
24
+ 采纳总是另存新副本,原 HTML / PPTX / JSON 的字节保持原样。在副本点击「撤销上次修改」,可一次撤回本次采纳和新增备用页。副本从工程 JSON 生成,不包含 Office 中的手动编辑。
25
+
26
+ ## 取消、历史与恢复
27
+
28
+ 点击「停止」会向模型发送取消信号,保留已完成的结果。被停止或失败的尝试仍占本次调用额度,也可能已产生费用;插件不会自动重试。模型生成最长等待 120 秒。答辩可以点击「结束并整理已有结果」,该操作不调用模型。
29
+
30
+ 报告保存在当前 `DSH_HOME/plugins/dsh-ppt/rehearsals/`,绑定本机工程、稳定页面 ID 和修订内容。每个工程最多保留 20 次,本机共 200 次;到上限后请在历史中删除旧记录,不会自动删除。工程修改后旧报告仍保留,可重新打开最新工程后导出;不能继续旧演练或套用旧建议。丢失响应时可从历史重新打开记录。删除记录不会删除幻灯片成品。
31
+
32
+ 未配置模型时显示配置引导,普通生成与下载照常可用。模型不输出有效 JSON、尝试调用工具、超出输出上限或被中断时,本次记录会暂停,已完成结果保留。历史文件损坏时不覆盖它,其他可读报告仍可访问。
33
+
34
+ ## English
35
+
36
+ Finished files remain the primary output. AI review and rehearsal are optional and never start automatically.
37
+
38
+ Choose a configured DSH text model, audience, difficulty, scope and optional supporting material. Click Start to send selected slide text, table/chart data, notes and the supplied material; image files are excluded. No file or shell tools are offered to the model. No additional account is needed beyond the chosen DSH provider.
39
+
40
+ Review makes up to three plugin calls. Practice asks one question at a time and accepts human answers: one initial question plus feedback for up to five questions, at most six plugin calls. Provider retries and billing rules still apply. You can stop a call or finish early; stopping may still incur a charge, and failed attempts use the current budget. There is no automatic retry.
41
+
42
+ Compare source quotes and proposed edits before adopting them. Only eligible expression suggestions can directly change wording; logic and evidence gaps remain preparation tasks. Exact quote and numeric checks are limited safeguards, not factual certification. Save selected edits and Q&A backup slides to a new copy; the original artifacts remain intact and Undo restores the copy to its pre-adoption content. Copies are generated from JSON and do not import Office edits.
43
+
44
+ Export Q&A, feedback and the evidence checklist as Markdown. Local reports are bound to the source revision. Changed presentations require a new rehearsal; old reports remain readable and exportable after reopening the current project. Keep up to 20 reports per project and 200 total, then delete old reports explicitly. Deleting a report keeps the presentation files.
@@ -6,6 +6,8 @@
6
6
 
7
7
  ## 最新记录
8
8
 
9
+ [0.14.0 可选 AI 预审与答辩验收](validation-0.14.0.md):151 项测试、真实 DSH Web 及原生模拟模型、复制 / 撤销 / 下载 / 取消 / 旧修订保护、中文与英文深色窄屏。真实模型效果、桌面原生窗口和完整 Office 视觉比对本次未测。
10
+
9
11
  [0.8.0 Windows 与浏览器操作验收](validation/0.8.0.md):113 项测试、编辑/冲突恢复、三种实际下载、五页官方引擎渲染及 390px 布局。桌面窗口内的新功能逐项操作待验收。
10
12
 
11
13
  ## 原中文记录
@@ -0,0 +1,24 @@
1
+ # 0.14.0 验证记录
2
+
3
+ 日期:2026-10-22。平台:Windows;宿主:官方 npm `@deepseek-ai/dsh@0.2.1-rc.2`。
4
+
5
+ ## 已通过
6
+
7
+ - 151 项自动测试(包含 20 项新增演练回归)、TypeScript 构建、浏览器脚本语法及 diff 空白检查。
8
+ - 隔离 DSH Web profile 的真实启动与认证:未认证 401、启动令牌换取会话 303、认证后接口 200。PPT 通过真实工具调用登记到工程索引。
9
+ - Chrome 后台浏览器实际点击:打开工程、直接下载成品 ZIP;该流程生成模型调用为 0,两个可选面板默认收起。
10
+ - 原生 `llm` 服务注册模拟文字模型适配器,通过正式流式接口完成预审和答辩;没有前端接口替身。记录确认工具列表为空、当前页范围只有一页、最多三轮预审恰好三次调用。
11
+ - 比较表达改稿、选中修改及备用页、另存副本;原三件套逐字节保留,副本一次撤销同时还原标题和页数。问答 / 待补充材料清单实际下载。
12
+ - 答辩提问 → 用户回答 → 反馈与下一题;提前结束不新增模型调用。单题答辩完成、未提交回答切换模式前确认并可取消。
13
+ - 三轮预审中途停止:仅发生第一轮调用,记录暂停、后续轮次不发起;成品下载仍可用。无效模型 JSON 暂停且不自动重试。
14
+ - TXT / Markdown 实际导入;修改幻灯片后,未保存状态和旧修订均阻止采纳;旧报告可导出并标明基于旧修订。
15
+ - 中文浅色与英文深色控件、错误提示分别显示;390px 窄屏单列配置,无横向溢出。修复原工作台不跟随深色主题的问题。浏览器运行时异常为 0。
16
+ - 回归覆盖虚构引用 / 数字不能形成可采纳改稿、持久化建议再次校验、其他工程隔离、调用重入、挂起流取消、损坏报告保留、追加页上限与普通交付无 AI 依赖。
17
+
18
+ ## 明确未测
19
+
20
+ - 本次模型响应由原生服务中的可控模拟适配器生成,没有消耗真实模型 API。上述结果证明宿主调用链、输入范围、状态和操作行为,不证明真实模型输出质量或抗提示注入能力。
21
+ - 未逐项操作 Windows 桌面应用窗口;Web 验收不等于桌面原生窗口验收。
22
+ - 新增功能没有改变渲染器;本次未重复进行 PowerPoint / WPS / LibreOffice 的完整视觉比对。AI 演练也不替代最终成品排版检查和事实核验。
23
+
24
+ 临时 profile、测试模型、输入材料、截图和下载均限定在工作区的独立验收目录,完成发布验收后清理;保留源码中的回归测试。
package/lib/client.js CHANGED
@@ -167,6 +167,14 @@ const EN = Object.freeze({
167
167
  "成品包包含 PPTX、HTML 和工程文件。请先保存修改,再下载最新版本。": "The bundle includes the PPTX, HTML and project file. Save your edits before downloading the latest version.",
168
168
  "下载 HTML": "Download HTML",
169
169
  "备份工程": "Back up project",
170
+ "快捷键:Ctrl/⌘+S 保存 · Esc 取消或返回 · Alt+←/→ 切换页面": "Shortcuts: Ctrl/⌘+S save · Esc cancel or go back · Alt+←/→ switch slides",
171
+ "未保存": "Unsaved",
172
+ "有未保存修改,确定取消吗?": "Discard unsaved changes?",
173
+ "已取消未保存的修改。": "Unsaved changes discarded.",
174
+ "有未保存修改,离开页面会丢失。": "You have unsaved changes that will be lost.",
175
+ "重试": "Retry",
176
+ "复制示例": "Copy example",
177
+ "已复制示例": "Example copied",
170
178
  "演示文稿": "Presentations"
171
179
  });
172
180
  function languageOf(locale = localeService) {
@@ -187,7 +195,7 @@ function useLanguage(locale) {
187
195
  const ROUTE = 'api/dsh-ppt/workbench';
188
196
  const fields = [['title', '标题'], ['subtitle', '副标题'], ['kicker', '眉题'], ['text', '正文'], ['bullets', '要点(每行一条)'], ['notes', '演讲备注']];
189
197
  const css = `
190
- .pptw {color:var(--fg,#27354b);font:14px/1.6 system-ui,sans-serif;min-width:0;max-width:1140px;margin:0 auto;padding:8px}
198
+ .pptw {--fg:var(--dsw-alias-label-primary,#27354b);--fg-muted:var(--dsw-alias-label-tertiary,#66768a);--bg:var(--dsw-alias-bg-layer-1,#fff);--bg-surface:var(--dsw-alias-bg-layer-2,#fff);--border:var(--dsw-alias-border-l3,#ccd8e5);color:var(--fg);font:14px/1.6 system-ui,sans-serif;min-width:0;max-width:1140px;margin:0 auto;padding:8px}
191
199
  .pptw *{box-sizing:border-box}.pptw h2{font-size:22px;margin:0}.pptw h3{font-size:16px;margin:12px 0 6px}
192
200
  .pptw .muted{color:var(--fg-muted,#66768a);font-size:13px}.pptw .tools{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0;align-items:center}
193
201
  .pptw button{font:inherit;border:1px solid var(--border,#ccd8e5);border-radius:9px;background:var(--bg-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;text-align:left;white-space:normal}
@@ -197,13 +205,20 @@ function useLanguage(locale) {
197
205
  .pptw .pages{display:flex;flex-direction:column;gap:5px;max-height:480px;overflow:auto}.pptw .pages button[aria-current=true]{background:#245ee9;color:#fff}
198
206
  .pptw .preview{border:1px solid var(--border,#ced8e6);border-radius:12px;overflow:hidden;background:#f0f4fa;aspect-ratio:16/9;position:relative}
199
207
  .pptw iframe{position:absolute;inset:0;width:100%;height:100%;border:0}.pptw .render-page{width:100%;display:block}
200
- .pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background:#edf4ff;color:#17408e;overflow-wrap:anywhere}.pptw .error{background:#fff1ef;color:#922d20}
208
+ .pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background:color-mix(in srgb,#5686fe 12%,var(--bg-surface));color:var(--fg);overflow-wrap:anywhere}.pptw .error{background:color-mix(in srgb,#f25a5a 14%,var(--bg-surface))}
201
209
  .pptw .card{border:1px solid var(--border,#d5dfeb);border-radius:12px;padding:12px;margin:10px 0;background:var(--bg-surface,#fff)}
210
+ .pptw .coaching{margin-top:24px}.pptw .coaching-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 14px}
211
+ .pptw .coaching label.choice{display:flex;gap:8px;align-items:flex-start}.pptw .coaching input[type=checkbox]{width:auto;flex:none;margin-top:5px}
212
+ .pptw .coaching pre{white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;margin:6px 0}.pptw .coaching blockquote{margin:8px 0;padding-left:12px;border-left:3px solid var(--border,#ccd8e5);overflow-wrap:anywhere}
213
+ .pptw .coaching .card{overflow-wrap:anywhere}.pptw .coaching .before-after{display:grid;grid-template-columns:1fr 1fr;gap:12px}
202
214
  .pptw .project-list{display:flex;flex-direction:column;gap:8px}.pptw .project-list button{display:block;width:100%}
203
215
  .pptw .file{font-size:12px;overflow-wrap:anywhere}.pptw .image-preview{width:100%;max-height:160px;object-fit:contain;background:#edf2f8;border-radius:8px}
204
216
  .pptw :focus-visible{outline:3px solid #78a8ff;outline-offset:2px}.pptw .dirty{color:#986114;font-size:13px}
217
+ .pptw .badge-dirty{color:#986114;font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;background:rgba(245,158,11,.14);border:1px solid rgba(245,158,11,.35);margin-left:4px}
218
+ .pptw .notice button{margin-left:8px;padding:2px 9px;border-radius:6px;border:1px solid currentColor;background:transparent;color:inherit;font-size:12px;cursor:pointer}
205
219
  [role=dialog]:has(.pptw){width:min(1200px,calc(100vw - 48px))!important;max-width:1200px!important}
206
220
  @media(max-width:700px){.pptw .layout{grid-template-columns:1fr}.pptw .pages{max-height:180px}.pptw .preview{min-height:190px}.pptw{padding:3px}
221
+ .pptw .coaching-grid,.pptw .coaching .before-after{grid-template-columns:1fr}
207
222
  [role=dialog]:has(.pptw){width:100%!important;max-width:100%!important;flex-direction:column!important}
208
223
  [role=dialog]:has(.pptw)>nav+div{min-width:0;width:100%}
209
224
  [role=dialog]:has(.pptw)>nav+div>div:has(.pptw){padding:12px!important;min-width:0}
@@ -226,7 +241,13 @@ function useLanguage(locale) {
226
241
  function editorHtml(html, nonce) {
227
242
  const bridge = `<style>#hud,#delivery-bar,#review-panel,#progress,#notes-panel,#help-panel,#toast,#blank{display:none!important}.slide-frame{pointer-events:none!important}.slide-frame .slide{pointer-events:auto!important}</style><script>(function(){const nonce=${JSON.stringify(nonce)};
228
243
  function tell(field){parent.postMessage({type:'dsh-ppt-select',nonce:nonce,field:field},'*')}
229
- document.addEventListener('keydown',function(e){e.stopImmediatePropagation();if(e.key!=='Tab')e.preventDefault()},true);
244
+ document.addEventListener('keydown',function(e){
245
+ var mod=e.ctrlKey||e.metaKey;
246
+ if(mod&&(e.key==='s'||e.key==='S')){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:'save'},'*');return}
247
+ if(e.key==='Escape'){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:'escape'},'*');return}
248
+ if(e.altKey&&(e.key==='ArrowLeft'||e.key==='ArrowRight')){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:e.key==='ArrowLeft'?'prev':'next'},'*');return}
249
+ e.stopImmediatePropagation();if(e.key!=='Tab')e.preventDefault()
250
+ },true);
230
251
  document.addEventListener('touchstart',function(e){e.stopImmediatePropagation()},true);
231
252
  document.addEventListener('touchend',function(e){e.stopImmediatePropagation()},true);
232
253
  document.addEventListener('wheel',function(e){e.stopImmediatePropagation()},{capture:true,passive:true});
@@ -257,6 +278,192 @@ function useLanguage(locale) {
257
278
  },
258
279
  };
259
280
  }
281
+ function CoachingPanel({ project, selected, blocked, onAdopt, onChoose }) {
282
+ const L = (zh, en) => languageOf() === 'en' ? en : zh;
283
+ const [mode, setMode] = useState(''), [routes, setRoutes] = useState([]), [route, setRoute] = useState('');
284
+ const [difficulty, setDifficulty] = useState('normal'), [audience, setAudience] = useState('general'), [limit, setLimit] = useState(1);
285
+ const [scope, setScope] = useState('all'), [material, setMaterial] = useState(''), [run, setRun] = useState(null), [history, setHistory] = useState([]);
286
+ const [answer, setAnswer] = useState(''), [patches, setPatches] = useState([]), [backups, setBackups] = useState([]);
287
+ const [busy, setBusy] = useState(false), [error, setError] = useState(''), [notice, setNotice] = useState('');
288
+ const active = useRef(null), alive = useRef(true), current = useRef(null), runRef = useRef(null), reading = useRef(0);
289
+ current.current = { project, selected, blocked }; runRef.current = run;
290
+ const stale = !!run && (run.stale || run.revision !== project.revision);
291
+ const maxCalls = mode === 'review' ? limit : limit + 1;
292
+ const modeName = value => value === 'review' ? L('AI 预审', 'AI review') : L('模拟答辩', 'Rehearsal');
293
+ const statusName = value => ({ ready: L('等待下一步', 'Ready'), busy: L('正在调用模型', 'Calling model'), paused: L('已暂停', 'Paused'), complete: L('已结束', 'Finished') })[value] || value;
294
+ const kindName = value => ({ expression: L('表达建议', 'Expression'), logic: L('逻辑问题', 'Logic'), evidence: L('证据缺口', 'Missing evidence') })[value];
295
+ function accept(value) { if (alive.current) { runRef.current = value; setRun(value); } }
296
+ const request = (operation, data = {}, signal) => action({ operation: 'coach-' + operation, id: current.current.project.id, expectedRevision: current.current.project.revision, ...data }, signal);
297
+ async function refresh(signal) { const value = await request('list', {}, signal); if (alive.current) setHistory(value.runs); }
298
+ useEffect(() => {
299
+ alive.current = true;
300
+ return () => {
301
+ alive.current = false; reading.current++;
302
+ if (active.current) {
303
+ active.current.abort();
304
+ const item = runRef.current;
305
+ if (item) void request('stop', { runId: item.id }).catch(() => {});
306
+ }
307
+ };
308
+ }, []);
309
+ useEffect(() => {
310
+ if (!run || run.status !== 'busy' || busy) return;
311
+ const controller = new AbortController();
312
+ const timer = setInterval(() => { void request('get', { runId: run.id }, controller.signal).then(value => { if (!controller.signal.aborted) accept(value.run); }).catch(() => {}); }, 750);
313
+ return () => { clearInterval(timer); controller.abort(); };
314
+ }, [run?.id, run?.status, busy]);
315
+ async function task(work) {
316
+ if (active.current) return;
317
+ const controller = new AbortController(); active.current = controller;
318
+ setBusy(true); setError(''); setNotice('');
319
+ try { await work(controller.signal); }
320
+ catch (e) {
321
+ if (!alive.current) return;
322
+ if (!controller.signal.aborted) setError(e.message || L('操作失败', 'Operation failed'));
323
+ const item = runRef.current;
324
+ if (item) { try { accept((await request('get', { runId: item.id })).run); } catch { /* Keep visible results. */ } }
325
+ } finally {
326
+ if (active.current === controller) active.current = null;
327
+ if (alive.current) setBusy(false);
328
+ }
329
+ }
330
+ function configure(value) {
331
+ if (active.current || !canLeave()) return;
332
+ setMode(value); setLimit(value === 'review' ? 1 : 3); accept(null); setPatches([]); setBackups([]); setAnswer('');
333
+ return task(async signal => {
334
+ const results = await Promise.allSettled([request('options', {}, signal), refresh(signal)]);
335
+ if (signal.aborted || !alive.current) return;
336
+ const available = results[0];
337
+ if (available.status === 'rejected') throw available.reason;
338
+ const models = available.value.routes;
339
+ setRoutes(models);
340
+ const preferred = models.findIndex(r => r.provider === project.modelRoute?.provider && r.model === project.modelRoute?.model);
341
+ setRoute(models.length ? String(Math.max(0, preferred)) : '');
342
+ if (!models.length) setNotice(L('先在 DSH 的模型设置中配置可用模型,再点“刷新模型”。成品仍可直接下载。', 'Configure a model in DSH, then refresh models. Your finished files remain available.'));
343
+ if (results[1].status === 'rejected') throw results[1].reason;
344
+ });
345
+ }
346
+ function canLeave() {
347
+ const item = runRef.current, question = item?.questions.at(-1);
348
+ return !(item?.mode === 'practice' && question && !question.feedback && answer.trim() && answer.trim() !== (question.answer || '')) || window.confirm(L('当前回答尚未提交,离开会丢失。继续吗?', 'Your answer has not been submitted and will be lost. Continue?'));
349
+ }
350
+ async function advance(item, signal, response) {
351
+ let next = (await request('step', { runId: item.id, confirmed: true, ...(response === undefined ? {} : { answer: response }) }, signal)).run;
352
+ accept(next);
353
+ // Only this explicit Start click authorizes the configured review rounds.
354
+ while (next.mode === 'review' && next.status === 'ready' && !next.stale && !signal.aborted && current.current.project.revision === next.revision) {
355
+ next = (await request('step', { runId: next.id, confirmed: true }, signal)).run; accept(next);
356
+ }
357
+ await refresh(signal);
358
+ if (alive.current && response !== undefined) setAnswer('');
359
+ }
360
+ function start() {
361
+ if (current.current.blocked) return;
362
+ return task(async signal => {
363
+ const model = routes[Number(route)]; if (!model) throw new Error(L('请选择模型', 'Choose a model'));
364
+ reading.current++;
365
+ const item = (await request('create', { confirmed: true, mode, ...model, difficulty, audience, limit, material,
366
+ language: languageOf(), ...(scope === 'current' ? { slideId: current.current.selected } : {}) }, signal)).run;
367
+ accept(item); await advance(item, signal);
368
+ });
369
+ }
370
+ function stop() {
371
+ active.current?.abort();
372
+ if (runRef.current) void request('stop', { runId: runRef.current.id }).then(value => accept(value.run)).catch(e => { if (alive.current) setError(e.message); });
373
+ setNotice(L('已请求停止。已完成的结果保留,本次调用仍可能计费。', 'Stop requested. Completed results are kept; the current call may still be billed.'));
374
+ }
375
+ function finish() { return task(async signal => { accept((await request('finish', { runId: run.id }, signal)).run); await refresh(signal); }); }
376
+ function openReport(id) { if (!canLeave()) return; return task(async signal => { const value = (await request('get', { runId: id }, signal)).run; accept(value); setMode(value.mode); setAnswer(value.questions.at(-1)?.answer || ''); setPatches([]); setBackups([]); }); }
377
+ function removeReport() {
378
+ if (!window.confirm(L('删除这次本地演练记录?幻灯片成品不受影响。', 'Delete this local rehearsal record? Presentation files are kept.'))) return;
379
+ return task(async signal => { await request('delete', { runId: run.id }, signal); accept(null); await refresh(signal); });
380
+ }
381
+ function exportReport() {
382
+ const url = new URL('api/dsh-ppt/download', document.baseURI);
383
+ for (const [key, value] of Object.entries({ id: project.id, kind: 'coaching', revision: project.revision, run: run.id })) url.searchParams.set(key, String(value));
384
+ const link = document.createElement('a'); link.href = url.href; link.download = ''; link.hidden = true; document.body.append(link); link.click(); link.remove();
385
+ }
386
+ function applySelected() {
387
+ if (current.current.blocked || stale) return;
388
+ return task(async signal => {
389
+ const value = await request('apply', { runId: run.id, confirmed: true, selected: patches, backup: backups }, signal);
390
+ if (alive.current) onAdopt(value.project);
391
+ });
392
+ }
393
+ async function uploadMaterial(event) {
394
+ const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
395
+ const ticket = ++reading.current;
396
+ if (!/\.(txt|md)$/i.test(file.name) || file.size > 100000) { setError(L('请选择 100 KB 以内的 TXT / Markdown 文件。', 'Choose a TXT / Markdown file up to 100 KB.')); return; }
397
+ try {
398
+ const value = await file.text();
399
+ if (!alive.current || ticket !== reading.current) return;
400
+ if (value.length > 20000) throw new Error(L('补充材料最多 20000 字符。', 'Supporting material: up to 20,000 characters.'));
401
+ setMaterial(value); setError('');
402
+ } catch (e) { if (alive.current && ticket === reading.current) setError(e.message); }
403
+ }
404
+ function toggle(set, values, id) { set(values.includes(id) ? values.filter(v => v !== id) : [...values, id]); }
405
+ function pageButton(id) {
406
+ const index = project.slides.findIndex(s => s.id === id);
407
+ return h('button', { disabled: blocked || index < 0, onClick: () => onChoose(id) }, L('查看第 ' + (index + 1) + ' 页', 'View slide ' + (index + 1)));
408
+ }
409
+ function source(card) { return card.reference ? h('blockquote', null, h('small', { className: 'muted' }, card.reference === 'material' ? L('补充材料中的原文', 'Quote from supporting material') : L('幻灯片中的原文', 'Quote from slides')), h('pre', null, card.quote)) : h('p', { className: 'muted' }, L('未匹配到材料原文,请核对或补充依据。', 'No matching source quote. Verify or add supporting evidence.')); }
410
+ const last = run?.questions.at(-1);
411
+ useEffect(() => {
412
+ if (!last || last.feedback || !answer.trim() || answer.trim() === (last.answer || '')) return;
413
+ const warn = event => { event.preventDefault(); event.returnValue = ''; };
414
+ window.addEventListener('beforeunload', warn); return () => window.removeEventListener('beforeunload', warn);
415
+ }, [run?.id, last?.id, last?.feedback, last?.answer, answer]);
416
+ return h('section', { className: 'card coaching', 'aria-label': L('可选演练', 'Optional rehearsal'), onKeyDown: e => { if (e.key === 'Escape' || (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') { e.stopPropagation(); if (e.key.toLowerCase() === 's') e.preventDefault(); } } },
417
+ h('h3', null, L('想再准备充分一点?', 'Want to prepare further?')),
418
+ h('p', { className: 'muted' }, L('成品已可下载。以下两项按需开启,不影响直接交付。', 'Your files are ready to download. Both options below are optional.')),
419
+ h('div', { className: 'tools' }, h('button', { disabled: busy, 'aria-pressed': mode === 'review', onClick: () => configure('review') }, L('AI 预审', 'AI review')), h('button', { disabled: busy, 'aria-pressed': mode === 'practice', onClick: () => configure('practice') }, L('模拟答辩', 'Rehearsal')),
420
+ mode && h('button', { disabled: busy, onClick: () => { if (canLeave()) { setMode(''); accept(null); setAnswer(''); } } }, L('收起', 'Collapse'))),
421
+ mode && h(React.Fragment, null,
422
+ error && h('div', { role: 'alert', className: 'notice error' }, error),
423
+ notice && h('div', { role: 'status', className: 'notice' }, notice),
424
+ busy && h('div', { role: 'status', className: 'tools' }, L('正在处理…可以继续预览或下载成品。', 'Working… You can still preview or download your presentation.'), h('button', { onClick: stop }, L('停止', 'Stop'))),
425
+ !run && h(React.Fragment, null,
426
+ h('p', null, mode === 'review' ? L('AI 根据材料模拟质疑与回答,最多保留 5 个值得改进的问题。', 'AI simulates questions and answers based on your material, keeping up to five useful findings.') : L('AI 一次问一题,你来回答;可随时结束并整理已完成的问答。', 'AI asks one question at a time. You answer and can finish at any point.')),
427
+ h('div', { className: 'coaching-grid' },
428
+ h('label', null, L('模型', 'Model'), h('select', { 'aria-label': L('演练模型', 'Rehearsal model'), value: route, disabled: busy, onChange: e => setRoute(e.target.value) }, !routes.length && h('option', { value: '' }, L('暂无可用模型', 'No configured model')), routes.map((r, i) => h('option', { key: i, value: i }, r.label)))),
429
+ h('label', null, L('听众', 'Audience'), h('select', { 'aria-label': L('听众', 'Audience'), value: audience, disabled: busy, onChange: e => setAudience(e.target.value) }, [['general', L('一般听众', 'General audience')], ['management', L('管理层 / 客户', 'Management / clients')], ['academic', L('答辩评委', 'Academic panel')]].map(([v, label]) => h('option', { key: v, value: v }, label)))),
430
+ h('label', null, L('提问强度', 'Difficulty'), h('select', { 'aria-label': L('提问强度', 'Difficulty'), value: difficulty, disabled: busy, onChange: e => setDifficulty(e.target.value) }, [['gentle', L('温和', 'Gentle')], ['normal', L('普通', 'Normal')], ['strict', L('严格', 'Strict')]].map(([v, label]) => h('option', { key: v, value: v }, label)))),
431
+ h('label', null, mode === 'review' ? L('预审轮数', 'Review rounds') : L('答辩题数', 'Questions'), h('select', { 'aria-label': mode === 'review' ? L('预审轮数', 'Review rounds') : L('答辩题数', 'Questions'), value: limit, disabled: busy, onChange: e => setLimit(Number(e.target.value)) }, Array.from({ length: mode === 'review' ? 3 : 5 }, (_, i) => h('option', { key: i, value: i + 1 }, String(i + 1))))),
432
+ h('label', null, L('检查范围', 'Scope'), h('select', { 'aria-label': L('检查范围', 'Scope'), value: scope, disabled: busy, onChange: e => setScope(e.target.value) }, h('option', { value: 'all' }, L('整个工程', 'Whole presentation')), h('option', { value: 'current' }, L('当前页', 'Current slide'))))),
433
+ h('label', { htmlFor: 'ppt-coach-material' }, L('补充材料(可选)', 'Supporting material (optional)')),
434
+ h('textarea', { id: 'ppt-coach-material', rows: 3, maxLength: 20000, value: material, disabled: busy, onChange: e => { reading.current++; setMaterial(e.target.value); } }),
435
+ h('label', null, L('或导入 TXT / Markdown', 'Or import TXT / Markdown'), h('input', { type: 'file', accept: '.txt,.md,text/plain,text/markdown', disabled: busy, onChange: uploadMaterial })),
436
+ h('p', { className: 'muted' }, L('将所选页面的文字、图表数据、备注及补充材料发送给所选 DSH 模型,不发送图片文件。最多 ' + maxCalls + ' 次插件调用;模型服务自身的重试与计费规则仍适用。', 'Sends selected slide text, chart data, notes and supporting material to the chosen DSH model. Image files are excluded. Up to ' + maxCalls + ' plugin calls; provider retry and billing rules still apply.')),
437
+ h('div', { className: 'tools' }, h('button', { disabled: busy || blocked || !routes.length, onClick: start }, mode === 'review' ? L('开始 AI 预审', 'Start AI review') : L('开始模拟答辩', 'Start rehearsal')), h('button', { disabled: busy, onClick: () => configure(mode) }, L('刷新模型', 'Refresh models'))),
438
+ blocked && h('p', { className: 'muted' }, L('请先保存或取消幻灯片修改。', 'Save or cancel slide edits first.'))),
439
+ run && h(React.Fragment, null,
440
+ h('h3', null, modeName(run.mode) + ' · ' + statusName(run.status)),
441
+ h('p', { className: 'muted' }, L('修订 ', 'Revision ') + run.revision + ' · ' + run.route.provider + ' / ' + run.route.model + ' · ' + L('调用 ', 'Calls ') + run.usedCalls + '/' + run.maxCalls),
442
+ h('p', { className: 'muted' }, L('AI 意见不等于事实核验,也不代表真实听众的评价。请先看原文与改动,再决定是否采纳。', 'AI suggestions are not fact checks or predictions of audience feedback. Compare sources and edits before adopting them.')),
443
+ stale && h('div', { role: 'alert', className: 'notice' }, L('工程已经修改。旧报告仍可导出,但不能继续调用或采纳;请重新开始。', 'The presentation changed. You can export this report, but cannot continue or apply it. Start a new rehearsal.')),
444
+ run.error && h('p', { className: 'muted' }, languageOf() === 'en' ? run.error.split(' / ').at(-1) : run.error.split(' / ')[0]),
445
+ run.findings.map(f => {
446
+ const slide = project.slides.find(s => s.id === f.slideId);
447
+ return h('article', { key: f.id, className: 'card' }, h('strong', null, kindName(f.kind) + ' · ' + f.issue), h('div', { className: 'tools' }, pageButton(f.slideId)),
448
+ h('p', null, f.question), h('p', null, f.answer), h('p', null, f.suggestion), source(f),
449
+ f.patch && h(React.Fragment, null, h('details', null, h('summary', null, L('比较原文和建议', 'Compare before and after')), Object.entries(f.patch).map(([key, value]) => h('div', { key }, h('strong', null, t(fields.find(([name]) => name === key)?.[1] || key)), h('div', { className: 'before-after' }, h('div', null, h('small', null, L('原文', 'Before')), h('pre', null, Array.isArray(slide?.[key]) ? slide[key].join('\n') : slide?.[key] || '')), h('div', null, h('small', null, L('建议', 'After')), h('pre', null, Array.isArray(value) ? value.join('\n') : value)))))),
450
+ h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: patches.includes(f.id), onChange: () => toggle(setPatches, patches, f.id) }), L('采纳这项表达修改', 'Adopt this expression edit'))),
451
+ h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: backups.includes(f.id), onChange: () => toggle(setBackups, backups, f.id) }), L('选为备用问答页', 'Add as a backup Q&A slide')));
452
+ }),
453
+ run.mode === 'review' && run.status === 'complete' && !run.findings.length && h('p', null, L('本次未提出明显问题。仍建议检查事实、字体和最终 PPTX。', 'No findings this time. Still check facts, fonts and the final PPTX.')),
454
+ run.questions.map((q, i) => h('article', { key: q.id, className: 'card' }, h('strong', null, (i + 1) + '. ' + q.question), h('div', { className: 'tools' }, pageButton(q.slideId)), q.answer && h('p', null, L('你的回答:', 'Your answer: ') + q.answer), q.feedback && h('p', null, q.feedback), q.needsEvidence && h('p', { className: 'muted' }, L('待补充依据', 'Evidence needed')), source(q),
455
+ q.answer && h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: backups.includes(q.id), onChange: () => toggle(setBackups, backups, q.id) }), L('选为备用问答页', 'Add as a backup Q&A slide')))),
456
+ run.mode === 'practice' && last && !last.feedback && run.status !== 'complete' && !stale && h(React.Fragment, null,
457
+ h('label', { htmlFor: 'ppt-coach-answer' }, L('你的回答', 'Your answer')), h('textarea', { id: 'ppt-coach-answer', maxLength: 4000, rows: 4, value: answer, disabled: busy, onChange: e => setAnswer(e.target.value) }),
458
+ h('button', { disabled: busy || blocked || !answer.trim() || run.usedCalls >= run.maxCalls, onClick: () => task(signal => advance(run, signal, answer)) }, L('提交回答,继续', 'Submit answer and continue'))),
459
+ h('div', { className: 'tools' }, h('button', { disabled: busy, onClick: exportReport }, L('下载问答与材料清单', 'Download Q&A and evidence checklist')),
460
+ h('button', { disabled: busy || blocked || stale || !(patches.length + backups.length), onClick: applySelected }, L('将所选内容保存为副本', 'Save selected changes as a copy')),
461
+ run.status !== 'complete' && h('button', { disabled: busy || run.status === 'busy', onClick: finish }, L('结束并整理已有结果', 'Finish with current results')),
462
+ h('button', { disabled: busy, onClick: () => configure(run.mode) }, L('重新开始', 'Start again')),
463
+ h('button', { disabled: busy || run.status === 'busy', onClick: removeReport }, L('删除本次记录', 'Delete this record'))),
464
+ h('p', { className: 'muted' }, L('采纳后会生成新副本,原稿保留;副本中可“撤销上次修改”。备用页包含 AI 演练标记,请核对后再对外展示。', 'Adoption creates a copy and keeps the original. Undo last change also works in the copy. Backup slides identify AI rehearsal content; verify before presenting.'))),
465
+ history.length > 0 && h('details', null, h('summary', null, L('本机历史记录(', 'Local history (') + history.length + L(')', ')')), h('div', { className: 'project-list' }, history.map(item => h('button', { key: item.id, disabled: busy, onClick: () => openReport(item.id) }, modeName(item.mode) + ' · ' + L('修订 ', 'Revision ') + item.revision + ' · ' + new Date(item.createdAt).toLocaleString(languageOf() === 'en' ? 'en-US' : 'zh-CN')))))));
466
+ }
260
467
  function Workbench({ locale } = {}) {
261
468
  useLanguage(locale);
262
469
  const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
@@ -267,6 +474,7 @@ function useLanguage(locale) {
267
474
  const frame = useRef(null), previewBox = useRef(null), fieldRefs = useRef({}), alive = useRef(true), operations = useRef(new Set());
268
475
  const imageLoader = useRef(null);
269
476
  if (!imageLoader.current) imageLoader.current = createImageLoader();
477
+ const imagePending = imageLoader.current.pending;
270
478
  const nonce = useRef(crypto.randomUUID());
271
479
  const previewDocument = useMemo(() => project?.html ? editorHtml(project.html, nonce.current) : '', [project?.html]);
272
480
  const index = project ? Math.max(0, project.slides.findIndex(s => s.id === selected)) : 0;
@@ -293,13 +501,15 @@ function useLanguage(locale) {
293
501
  }, []);
294
502
  useEffect(() => {
295
503
  function receive(event) {
296
- if (event.source !== frame.current?.contentWindow || event.data?.nonce !== nonce.current || event.data.type !== 'dsh-ppt-select' || mode !== 'html') return;
504
+ if (event.source !== frame.current?.contentWindow || event.data?.nonce !== nonce.current || mode !== 'html') return;
505
+ if (event.data.type === 'dsh-ppt-shortcut') { handleShortcut(event.data.key); return; }
506
+ if (event.data.type !== 'dsh-ppt-select') return;
297
507
  const key = event.data.field;
298
508
  const field = fields.find(([field]) => field === key);
299
509
  if (field) { fieldRefs.current[key]?.focus(); fieldRefs.current[key]?.scrollIntoView({ block: 'nearest' }); setMessage(t("已定位到") + t(field[1]) + t(",在字段中修改后保存。")); }
300
510
  }
301
511
  window.addEventListener('message', receive); return () => window.removeEventListener('message', receive);
302
- }, [mode]);
512
+ }, [mode, project, dirty, busy, imagePending, index, selected, draft, image]);
303
513
  useEffect(() => {
304
514
  if (mode !== 'html' || !project || !previewBox.current) return;
305
515
  // Align iframe edges/dimensions when the host uses fractional text metrics.
@@ -322,6 +532,51 @@ function useLanguage(locale) {
322
532
  action({ operation: 'page', id: project.id, page: index + 1 }, abort.signal).then(value => setRaster(value.data)).catch(e => { if (!abort.signal.aborted) setError(e.message) });
323
533
  return () => abort.abort();
324
534
  }, [mode, index, project?.revision]);
535
+ function handleShortcut(key) {
536
+ if (key === 'save') { if (project && dirty && !busy && !imagePending) save(); return; }
537
+ if (key === 'escape') {
538
+ if (!project || busy || imagePending) return;
539
+ if (dirty) {
540
+ if (!window.confirm(t("有未保存修改,确定取消吗?"))) return;
541
+ setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(t("已取消未保存的修改。"));
542
+ } else {
543
+ imageLoader.current.cancel(); setProject(null); refreshList();
544
+ }
545
+ return;
546
+ }
547
+ if (key === 'prev' || key === 'next') {
548
+ if (!project || busy || dirty || imagePending) return;
549
+ const next = index + (key === 'next' ? 1 : -1);
550
+ if (next >= 0 && next < project.slides.length) choose(project.slides[next]);
551
+ }
552
+ }
553
+ useEffect(() => {
554
+ function onKey(event) {
555
+ if (event.isComposing || event.defaultPrevented) return;
556
+ if (event.key === 'Escape' && event.target && event.target.tagName === 'SELECT') return;
557
+ const mod = event.ctrlKey || event.metaKey;
558
+ if (mod && (event.key === 's' || event.key === 'S')) {
559
+ if (!project) return;
560
+ event.preventDefault(); handleShortcut('save'); return;
561
+ }
562
+ if (event.key === 'Escape') {
563
+ if (!project || busy || imagePending) return;
564
+ event.preventDefault(); handleShortcut('escape'); return;
565
+ }
566
+ if (event.altKey && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
567
+ if (!project || busy || dirty || imagePending) return;
568
+ event.preventDefault(); handleShortcut(event.key === 'ArrowRight' ? 'next' : 'prev');
569
+ }
570
+ }
571
+ document.addEventListener('keydown', onKey);
572
+ return () => document.removeEventListener('keydown', onKey);
573
+ }, [project, dirty, busy, imagePending, index, selected, draft, image]);
574
+ useEffect(() => {
575
+ if (!dirty) return;
576
+ function warn(event) { event.preventDefault(); event.returnValue = t("有未保存修改,离开页面会丢失。"); }
577
+ window.addEventListener('beforeunload', warn);
578
+ return () => window.removeEventListener('beforeunload', warn);
579
+ }, [dirty]);
325
580
  function open(id) { return perform(signal => action({ operation: 'open', id }, signal), value => { adopt(value.project); setMessage(t("点击预览里的文字,或在下方修改字段。")); }); }
326
581
  function keepInputsAndReload() {
327
582
  const original = draftFor(slide), keys = fields.filter(([key]) => draft[key] !== original[key]).map(([key]) => key), pending = { ...draft }, pendingImage = image;
@@ -366,6 +621,10 @@ function useLanguage(locale) {
366
621
  link.hidden = true; document.body.append(link); link.click(); link.remove();
367
622
  setMessage(t("已请求下载,请查看浏览器的下载列表。"));
368
623
  }
624
+ function copyExample() {
625
+ const text = t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。");
626
+ try { navigator.clipboard?.writeText(text).then(() => setMessage(t("已复制示例"))).catch(() => {}); } catch (_) { /* ignore */ }
627
+ }
369
628
  function upload(event) {
370
629
  const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
371
630
  imageLoader.current.cancel(); setMessage(''); setError('');
@@ -378,19 +637,19 @@ function useLanguage(locale) {
378
637
  if (imageLoader.current.pending) setMessage(t("正在读取图片,切换页面会取消本次读取。"));
379
638
  }
380
639
  const currentImage = image?.src || (slide?.image?.assetId && project.assets[slide.image.assetId]?.data);
381
- const imagePending = imageLoader.current.pending;
382
- return h('div', { className: 'pptw' }, h('style', null, css),
640
+ return h('div', { className: 'pptw', 'aria-busy': busy ? 'true' : undefined }, h('style', null, css),
383
641
  h('h2', null, t("演示文稿编辑")), h('p', { className: 'muted' }, t("修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。")),
384
- error && h('div', { role: 'alert', className: 'notice error' }, error),
642
+ h('p', { className: 'muted' }, t("快捷键:Ctrl/⌘+S 保存 · Esc 取消或返回 · Alt+←/→ 切换页面")),
643
+ error && h('div', { role: 'alert', className: 'notice error' }, error, ' ', h('button', { disabled: busy, onClick: () => project ? open(project.id) : refreshList() }, t("重试"))),
385
644
  conflict && project && h('button', { disabled: busy, onClick: keepInputsAndReload }, t("载入最新版本,保留我的输入")),
386
645
  message && h('div', { role: 'status', className: 'notice' }, message),
387
646
  busy && h('div', { role: 'status', className: 'muted' }, job),
388
647
  !project ? h(React.Fragment, null,
389
648
  h('div', { className: 'tools' }, h('button', { onClick: refreshList, disabled: busy }, t("刷新项目"))),
390
649
  projects.length ? h('div', { className: 'project-list' }, projects.map(row => h('button', { key: row.id, onClick: () => open(row.id), disabled: busy }, h('strong', null, row.title), h('div', { className: 'file muted' }, row.path)))) :
391
- h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")))
650
+ h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")), h('div', { className: 'tools' }, h('button', { onClick: copyExample }, t("复制示例"))))
392
651
  ) : h(React.Fragment, null,
393
- h('div', { className: 'tools' }, h('button', { disabled: busy || dirty, onClick: () => { imageLoader.current.cancel(); setImage(null); setProject(null); refreshList(); } }, t("返回项目")), h('strong', null, project.title), h('span', { className: 'muted' }, project.slides.length + t(" 页 · 修订 ") + project.revision)),
652
+ h('div', { className: 'tools' }, h('button', { disabled: busy || dirty, onClick: () => { imageLoader.current.cancel(); setImage(null); setProject(null); refreshList(); } }, t("返回项目")), h('strong', null, project.title), dirty && h('span', { className: 'badge-dirty', role: 'status' }, t("未保存")), h('span', { className: 'muted' }, project.slides.length + t(" 页 · 修订 ") + project.revision)),
394
653
  h('div', { className: 'layout' },
395
654
  h('div', null, h('h3', null, t("页面")), h('div', { className: 'pages' }, project.slides.map((row, i) => h('button', { key: row.id, 'aria-current': row.id === selected ? 'true' : undefined, disabled: busy || dirty, onClick: () => choose(row) }, (i + 1) + '. ' + (row.title || t("未命名页"))))),
396
655
  h('div', { className: 'tools' }, h('button', { disabled: busy || dirty || imagePending || index === 0, onClick: () => move(-1) }, t("上移")), h('button', { disabled: busy || dirty || imagePending || index === project.slides.length - 1, onClick: () => move(1) }, t("下移")),
@@ -411,10 +670,13 @@ function useLanguage(locale) {
411
670
  h('input', { id: 'pptw-image', type: 'file', accept: 'image/png,image/jpeg', disabled: busy, onChange: upload }),
412
671
  currentImage && h('img', { className: 'image-preview', src: currentImage, alt: image?.alt || slide.image?.alt || t("当前图片") }),
413
672
  image && h(React.Fragment, null, h('p', { className: 'muted' }, t("已选择:") + image.name), h('label', { htmlFor: 'pptw-alt' }, t("图片说明")), h('input', { id: 'pptw-alt', value: image.alt, disabled: busy, onChange: e => setImage({ ...image, alt: e.target.value }) }), h('label', { htmlFor: 'pptw-fit' }, t("图片适应方式")), h('select', { id: 'pptw-fit', value: image.fit, disabled: busy, onChange: e => setImage({ ...image, fit: e.target.value }) }, h('option', { value: 'contain' }, t("完整显示")), h('option', { value: 'cover' }, t("填满并裁切")))),
414
- h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || imagePending || !dirty, onClick: () => save() }, t("保存此页")), h('button', { disabled: busy || imagePending, onClick: () => save(true) }, t("另存副本")), h('button', { disabled: busy || (!dirty && !imagePending), onClick: () => { imageLoader.current.cancel(); setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(''); setConflict(false); setOverlaps([]); } }, t("取消修改")), h('button', { disabled: busy || dirty || imagePending || !project.undoAvailable, onClick: undo }, t("撤销上次修改")))),
673
+ h('div', { className: 'tools' }, h('button', { className: 'primary', 'aria-keyshortcuts': 'Control+S Meta+S', disabled: busy || imagePending || !dirty, onClick: () => save() }, t("保存此页")), h('button', { 'aria-keyshortcuts': 'Control+Shift+S Meta+Shift+S', disabled: busy || imagePending, onClick: () => save(true) }, t("另存副本")), h('button', { 'aria-keyshortcuts': 'Escape', disabled: busy || (!dirty && !imagePending), onClick: () => { imageLoader.current.cancel(); setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(''); setConflict(false); setOverlaps([]); } }, t("取消修改")), h('button', { disabled: busy || dirty || imagePending || !project.undoAvailable, onClick: undo }, t("撤销上次修改")))),
415
674
  h('details', { className: 'card' }, h('summary', null, t("质量提醒(") + (project.quality.warningCount + project.quality.errorCount) + (languageOf() === 'en' ? ')' : ')')), (project.quality.issues || []).map((issue, i) => h('p', { key: i }, (issue.slide > 0 ? t("第 ") + issue.slide + t(" 页:") : "") + (languageOf() === 'en' ? issue.messageEn : issue.message) + (languageOf() === 'en' ? ' ' : ';') + (languageOf() === 'en' ? issue.suggestionEn : issue.suggestion)))),
416
675
  h('p', { className: 'muted' }, t("成品包包含 PPTX、HTML 和工程文件。请先保存修改,再下载最新版本。")),
417
- h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty || imagePending, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('notes') }, t("下载讲稿 Markdown")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('json') }, t("备份工程")))
676
+ h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty || imagePending, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('notes') }, t("下载讲稿 Markdown")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('json') }, t("备份工程"))),
677
+ h(CoachingPanel, { key: project.id, project, selected, blocked: busy || dirty || imagePending,
678
+ onChoose: id => { choose(project.slides.find(s => s.id === id)); previewBox.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); },
679
+ onAdopt: next => { adopt(next, selected); setMessage(languageOf() === 'en' ? 'Saved to a new copy. The original is kept; you can undo the adopted changes in this copy.' : '已保存为新副本,原稿保留;可在当前副本中撤销采纳的修改。'); } })
418
680
  )
419
681
  )
420
682
  )
@@ -0,0 +1,12 @@
1
+ /** Bounded, tool-free calls through the official DSH llm service. */
2
+ export interface ModelRoute {
3
+ provider: string;
4
+ model: string;
5
+ }
6
+ export interface CoachingModel {
7
+ routes(signal?: AbortSignal): Promise<Array<ModelRoute & {
8
+ label: string;
9
+ }>>;
10
+ generate(route: ModelRoute, system: string, input: string, signal: AbortSignal): Promise<string>;
11
+ }
12
+ export declare function nativeCoachingModel(llm: any): CoachingModel;